2 * Interfaces to retrieve and set PDC Stable options (firmware)
4 * Copyright (C) 2005-2006 Thibaut VARENE <varenet@parisc-linux.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * DEV NOTE: the PDC Procedures reference states that:
21 * "A minimum of 96 bytes of Stable Storage is required. Providing more than
22 * 96 bytes of Stable Storage is optional [...]. Failure to provide the
23 * optional locations from 96 to 192 results in the loss of certain
24 * functionality during boot."
26 * Since locations between 96 and 192 are the various paths, most (if not
27 * all) PA-RISC machines should have them. Anyway, for safety reasons, the
28 * following code can deal with just 96 bytes of Stable Storage, and all
29 * sizes between 96 and 192 bytes (provided they are multiple of struct
30 * device_path size, eg: 128, 160 and 192) to provide full information.
31 * The code makes no use of data above 192 bytes. One last word: there's one
32 * path we can always count on: the primary path.
34 * The current policy wrt file permissions is:
36 * - read: (reading triggers PDC calls) ? root only : everyone
37 * The rationale is that PDC calls could hog (DoS) the machine.
40 * - timer/fastsize write calls
45 #define DPRINTK(fmt, args...) printk(KERN_DEBUG fmt, ## args)
47 #define DPRINTK(fmt, args...)
50 #include <linux/module.h>
51 #include <linux/init.h>
52 #include <linux/kernel.h>
53 #include <linux/string.h>
54 #include <linux/capability.h>
55 #include <linux/ctype.h>
56 #include <linux/sysfs.h>
57 #include <linux/kobject.h>
58 #include <linux/device.h>
59 #include <linux/errno.h>
60 #include <linux/spinlock.h>
64 #include <asm/uaccess.h>
65 #include <asm/hardware.h>
67 #define PDCS_VERSION "0.22"
68 #define PDCS_PREFIX "PDC Stable Storage"
70 #define PDCS_ADDR_PPRI 0x00
71 #define PDCS_ADDR_OSID 0x40
72 #define PDCS_ADDR_FSIZ 0x5C
73 #define PDCS_ADDR_PCON 0x60
74 #define PDCS_ADDR_PALT 0x80
75 #define PDCS_ADDR_PKBD 0xA0
77 MODULE_AUTHOR("Thibaut VARENE <varenet@parisc-linux.org>");
78 MODULE_DESCRIPTION("sysfs interface to HP PDC Stable Storage data");
79 MODULE_LICENSE("GPL");
80 MODULE_VERSION(PDCS_VERSION
);
82 /* holds Stable Storage size. Initialized once and for all, no lock needed */
83 static unsigned long pdcs_size __read_mostly
;
85 /* This struct defines what we need to deal with a parisc pdc path entry */
86 struct pdcspath_entry
{
87 rwlock_t rw_lock
; /* to protect path entry access */
88 short ready
; /* entry record is valid if != 0 */
89 unsigned long addr
; /* entry address in stable storage */
90 char *name
; /* entry name */
91 struct device_path devpath
; /* device path in parisc representation */
92 struct device
*dev
; /* corresponding device */
96 struct pdcspath_attribute
{
97 struct attribute attr
;
98 ssize_t (*show
)(struct pdcspath_entry
*entry
, char *buf
);
99 ssize_t (*store
)(struct pdcspath_entry
*entry
, const char *buf
, size_t count
);
102 #define PDCSPATH_ENTRY(_addr, _name) \
103 struct pdcspath_entry pdcspath_entry_##_name = { \
106 .name = __stringify(_name), \
109 #define PDCS_ATTR(_name, _mode, _show, _store) \
110 struct subsys_attribute pdcs_attr_##_name = { \
111 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \
116 #define PATHS_ATTR(_name, _mode, _show, _store) \
117 struct pdcspath_attribute paths_attr_##_name = { \
118 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \
123 #define to_pdcspath_attribute(_attr) container_of(_attr, struct pdcspath_attribute, attr)
124 #define to_pdcspath_entry(obj) container_of(obj, struct pdcspath_entry, kobj)
127 * pdcspath_fetch - This function populates the path entry structs.
128 * @entry: A pointer to an allocated pdcspath_entry.
130 * The general idea is that you don't read from the Stable Storage every time
131 * you access the files provided by the facilites. We store a copy of the
132 * content of the stable storage WRT various paths in these structs. We read
133 * these structs when reading the files, and we will write to these structs when
134 * writing to the files, and only then write them back to the Stable Storage.
136 * This function expects to be called with @entry->rw_lock write-hold.
139 pdcspath_fetch(struct pdcspath_entry
*entry
)
141 struct device_path
*devpath
;
146 devpath
= &entry
->devpath
;
148 DPRINTK("%s: fetch: 0x%p, 0x%p, addr: 0x%lx\n", __func__
,
149 entry
, devpath
, entry
->addr
);
151 /* addr, devpath and count must be word aligned */
152 if (pdc_stable_read(entry
->addr
, devpath
, sizeof(*devpath
)) != PDC_OK
)
155 /* Find the matching device.
156 NOTE: hardware_path overlays with device_path, so the nice cast can
158 entry
->dev
= hwpath_to_device((struct hardware_path
*)devpath
);
162 DPRINTK("%s: device: 0x%p\n", __func__
, entry
->dev
);
168 * pdcspath_store - This function writes a path to stable storage.
169 * @entry: A pointer to an allocated pdcspath_entry.
171 * It can be used in two ways: either by passing it a preset devpath struct
172 * containing an already computed hardware path, or by passing it a device
173 * pointer, from which it'll find out the corresponding hardware path.
174 * For now we do not handle the case where there's an error in writing to the
175 * Stable Storage area, so you'd better not mess up the data :P
177 * This function expects to be called with @entry->rw_lock write-hold.
180 pdcspath_store(struct pdcspath_entry
*entry
)
182 struct device_path
*devpath
;
186 devpath
= &entry
->devpath
;
188 /* We expect the caller to set the ready flag to 0 if the hardware
189 path struct provided is invalid, so that we know we have to fill it.
190 First case, we don't have a preset hwpath... */
192 /* ...but we have a device, map it */
194 device_to_hwpath(entry
->dev
, (struct hardware_path
*)devpath
);
196 /* else, we expect the provided hwpath to be valid. */
198 DPRINTK("%s: store: 0x%p, 0x%p, addr: 0x%lx\n", __func__
,
199 entry
, devpath
, entry
->addr
);
201 /* addr, devpath and count must be word aligned */
202 if (pdc_stable_write(entry
->addr
, devpath
, sizeof(*devpath
)) != PDC_OK
) {
203 printk(KERN_ERR
"%s: an error occured when writing to PDC.\n"
204 "It is likely that the Stable Storage data has been corrupted.\n"
205 "Please check it carefully upon next reboot.\n", __func__
);
209 /* kobject is already registered */
212 DPRINTK("%s: device: 0x%p\n", __func__
, entry
->dev
);
216 * pdcspath_hwpath_read - This function handles hardware path pretty printing.
217 * @entry: An allocated and populated pdscpath_entry struct.
218 * @buf: The output buffer to write to.
220 * We will call this function to format the output of the hwpath attribute file.
223 pdcspath_hwpath_read(struct pdcspath_entry
*entry
, char *buf
)
226 struct device_path
*devpath
;
232 read_lock(&entry
->rw_lock
);
233 devpath
= &entry
->devpath
;
235 read_unlock(&entry
->rw_lock
);
237 if (!i
) /* entry is not ready */
240 for (i
= 0; i
< 6; i
++) {
241 if (devpath
->bc
[i
] >= 128)
243 out
+= sprintf(out
, "%u/", (unsigned char)devpath
->bc
[i
]);
245 out
+= sprintf(out
, "%u\n", (unsigned char)devpath
->mod
);
251 * pdcspath_hwpath_write - This function handles hardware path modifying.
252 * @entry: An allocated and populated pdscpath_entry struct.
253 * @buf: The input buffer to read from.
254 * @count: The number of bytes to be read.
256 * We will call this function to change the current hardware path.
257 * Hardware paths are to be given '/'-delimited, without brackets.
258 * We make sure that the provided path actually maps to an existing
259 * device, BUT nothing would prevent some foolish user to set the path to some
260 * PCI bridge or even a CPU...
261 * A better work around would be to make sure we are at the end of a device tree
262 * for instance, but it would be IMHO beyond the simple scope of that driver.
263 * The aim is to provide a facility. Data correctness is left to userland.
266 pdcspath_hwpath_write(struct pdcspath_entry
*entry
, const char *buf
, size_t count
)
268 struct hardware_path hwpath
;
270 char in
[count
+1], *temp
;
273 if (!entry
|| !buf
|| !count
)
276 /* We'll use a local copy of buf */
277 memset(in
, 0, count
+1);
278 strncpy(in
, buf
, count
);
280 /* Let's clean up the target. 0xff is a blank pattern */
281 memset(&hwpath
, 0xff, sizeof(hwpath
));
283 /* First, pick the mod field (the last one of the input string) */
284 if (!(temp
= strrchr(in
, '/')))
287 hwpath
.mod
= simple_strtoul(temp
+1, NULL
, 10);
288 in
[temp
-in
] = '\0'; /* truncate the remaining string. just precaution */
289 DPRINTK("%s: mod: %d\n", __func__
, hwpath
.mod
);
291 /* Then, loop for each delimiter, making sure we don't have too many.
292 we write the bc fields in a down-top way. No matter what, we stop
293 before writing the last field. If there are too many fields anyway,
294 then the user is a moron and it'll be caught up later when we'll
295 check the consistency of the given hwpath. */
296 for (i
=5; ((temp
= strrchr(in
, '/'))) && (temp
-in
> 0) && (likely(i
)); i
--) {
297 hwpath
.bc
[i
] = simple_strtoul(temp
+1, NULL
, 10);
299 DPRINTK("%s: bc[%d]: %d\n", __func__
, i
, hwpath
.bc
[i
]);
302 /* Store the final field */
303 hwpath
.bc
[i
] = simple_strtoul(in
, NULL
, 10);
304 DPRINTK("%s: bc[%d]: %d\n", __func__
, i
, hwpath
.bc
[i
]);
306 /* Now we check that the user isn't trying to lure us */
307 if (!(dev
= hwpath_to_device((struct hardware_path
*)&hwpath
))) {
308 printk(KERN_WARNING
"%s: attempt to set invalid \"%s\" "
309 "hardware path: %s\n", __func__
, entry
->name
, buf
);
313 /* So far so good, let's get in deep */
314 write_lock(&entry
->rw_lock
);
318 /* Now, dive in. Write back to the hardware */
319 pdcspath_store(entry
);
321 /* Update the symlink to the real device */
322 sysfs_remove_link(&entry
->kobj
, "device");
323 sysfs_create_link(&entry
->kobj
, &entry
->dev
->kobj
, "device");
324 write_unlock(&entry
->rw_lock
);
326 printk(KERN_INFO PDCS_PREFIX
": changed \"%s\" path to \"%s\"\n",
333 * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing.
334 * @entry: An allocated and populated pdscpath_entry struct.
335 * @buf: The output buffer to write to.
337 * We will call this function to format the output of the layer attribute file.
340 pdcspath_layer_read(struct pdcspath_entry
*entry
, char *buf
)
343 struct device_path
*devpath
;
349 read_lock(&entry
->rw_lock
);
350 devpath
= &entry
->devpath
;
352 read_unlock(&entry
->rw_lock
);
354 if (!i
) /* entry is not ready */
357 for (i
= 0; devpath
->layers
[i
] && (likely(i
< 6)); i
++)
358 out
+= sprintf(out
, "%u ", devpath
->layers
[i
]);
360 out
+= sprintf(out
, "\n");
366 * pdcspath_layer_write - This function handles extended layer modifying.
367 * @entry: An allocated and populated pdscpath_entry struct.
368 * @buf: The input buffer to read from.
369 * @count: The number of bytes to be read.
371 * We will call this function to change the current layer value.
372 * Layers are to be given '.'-delimited, without brackets.
373 * XXX beware we are far less checky WRT input data provided than for hwpath.
374 * Potential harm can be done, since there's no way to check the validity of
378 pdcspath_layer_write(struct pdcspath_entry
*entry
, const char *buf
, size_t count
)
380 unsigned int layers
[6]; /* device-specific info (ctlr#, unit#, ...) */
382 char in
[count
+1], *temp
;
384 if (!entry
|| !buf
|| !count
)
387 /* We'll use a local copy of buf */
388 memset(in
, 0, count
+1);
389 strncpy(in
, buf
, count
);
391 /* Let's clean up the target. 0 is a blank pattern */
392 memset(&layers
, 0, sizeof(layers
));
394 /* First, pick the first layer */
395 if (unlikely(!isdigit(*in
)))
397 layers
[0] = simple_strtoul(in
, NULL
, 10);
398 DPRINTK("%s: layer[0]: %d\n", __func__
, layers
[0]);
401 for (i
=1; ((temp
= strchr(temp
, '.'))) && (likely(i
<6)); i
++) {
402 if (unlikely(!isdigit(*(++temp
))))
404 layers
[i
] = simple_strtoul(temp
, NULL
, 10);
405 DPRINTK("%s: layer[%d]: %d\n", __func__
, i
, layers
[i
]);
408 /* So far so good, let's get in deep */
409 write_lock(&entry
->rw_lock
);
411 /* First, overwrite the current layers with the new ones, not touching
412 the hardware path. */
413 memcpy(&entry
->devpath
.layers
, &layers
, sizeof(layers
));
415 /* Now, dive in. Write back to the hardware */
416 pdcspath_store(entry
);
417 write_unlock(&entry
->rw_lock
);
419 printk(KERN_INFO PDCS_PREFIX
": changed \"%s\" layers to \"%s\"\n",
426 * pdcspath_attr_show - Generic read function call wrapper.
427 * @kobj: The kobject to get info from.
428 * @attr: The attribute looked upon.
429 * @buf: The output buffer.
432 pdcspath_attr_show(struct kobject
*kobj
, struct attribute
*attr
, char *buf
)
434 struct pdcspath_entry
*entry
= to_pdcspath_entry(kobj
);
435 struct pdcspath_attribute
*pdcs_attr
= to_pdcspath_attribute(attr
);
439 ret
= pdcs_attr
->show(entry
, buf
);
445 * pdcspath_attr_store - Generic write function call wrapper.
446 * @kobj: The kobject to write info to.
447 * @attr: The attribute to be modified.
448 * @buf: The input buffer.
449 * @count: The size of the buffer.
452 pdcspath_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
453 const char *buf
, size_t count
)
455 struct pdcspath_entry
*entry
= to_pdcspath_entry(kobj
);
456 struct pdcspath_attribute
*pdcs_attr
= to_pdcspath_attribute(attr
);
459 if (!capable(CAP_SYS_ADMIN
))
462 if (pdcs_attr
->store
)
463 ret
= pdcs_attr
->store(entry
, buf
, count
);
468 static struct sysfs_ops pdcspath_attr_ops
= {
469 .show
= pdcspath_attr_show
,
470 .store
= pdcspath_attr_store
,
473 /* These are the two attributes of any PDC path. */
474 static PATHS_ATTR(hwpath
, 0644, pdcspath_hwpath_read
, pdcspath_hwpath_write
);
475 static PATHS_ATTR(layer
, 0644, pdcspath_layer_read
, pdcspath_layer_write
);
477 static struct attribute
*paths_subsys_attrs
[] = {
478 &paths_attr_hwpath
.attr
,
479 &paths_attr_layer
.attr
,
483 /* Specific kobject type for our PDC paths */
484 static struct kobj_type ktype_pdcspath
= {
485 .sysfs_ops
= &pdcspath_attr_ops
,
486 .default_attrs
= paths_subsys_attrs
,
489 /* We hard define the 4 types of path we expect to find */
490 static PDCSPATH_ENTRY(PDCS_ADDR_PPRI
, primary
);
491 static PDCSPATH_ENTRY(PDCS_ADDR_PCON
, console
);
492 static PDCSPATH_ENTRY(PDCS_ADDR_PALT
, alternative
);
493 static PDCSPATH_ENTRY(PDCS_ADDR_PKBD
, keyboard
);
495 /* An array containing all PDC paths we will deal with */
496 static struct pdcspath_entry
*pdcspath_entries
[] = {
497 &pdcspath_entry_primary
,
498 &pdcspath_entry_alternative
,
499 &pdcspath_entry_console
,
500 &pdcspath_entry_keyboard
,
505 /* For more insight of what's going on here, refer to PDC Procedures doc,
506 * Section PDC_STABLE */
509 * pdcs_size_read - Stable Storage size output.
510 * @entry: An allocated and populated subsytem struct. We don't use it tho.
511 * @buf: The output buffer to write to.
514 pdcs_size_read(struct subsystem
*entry
, char *buf
)
521 /* show the size of the stable storage */
522 out
+= sprintf(out
, "%ld\n", pdcs_size
);
528 * pdcs_auto_read - Stable Storage autoboot/search flag output.
529 * @entry: An allocated and populated subsytem struct. We don't use it tho.
530 * @buf: The output buffer to write to.
531 * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
534 pdcs_auto_read(struct subsystem
*entry
, char *buf
, int knob
)
537 struct pdcspath_entry
*pathentry
;
542 /* Current flags are stored in primary boot path entry */
543 pathentry
= &pdcspath_entry_primary
;
545 read_lock(&pathentry
->rw_lock
);
546 out
+= sprintf(out
, "%s\n", (pathentry
->devpath
.flags
& knob
) ?
548 read_unlock(&pathentry
->rw_lock
);
554 * pdcs_autoboot_read - Stable Storage autoboot flag output.
555 * @entry: An allocated and populated subsytem struct. We don't use it tho.
556 * @buf: The output buffer to write to.
558 static inline ssize_t
559 pdcs_autoboot_read(struct subsystem
*entry
, char *buf
)
561 return pdcs_auto_read(entry
, buf
, PF_AUTOBOOT
);
565 * pdcs_autosearch_read - Stable Storage autoboot flag output.
566 * @entry: An allocated and populated subsytem struct. We don't use it tho.
567 * @buf: The output buffer to write to.
569 static inline ssize_t
570 pdcs_autosearch_read(struct subsystem
*entry
, char *buf
)
572 return pdcs_auto_read(entry
, buf
, PF_AUTOSEARCH
);
576 * pdcs_timer_read - Stable Storage timer count output (in seconds).
577 * @entry: An allocated and populated subsytem struct. We don't use it tho.
578 * @buf: The output buffer to write to.
580 * The value of the timer field correponds to a number of seconds in powers of 2.
583 pdcs_timer_read(struct subsystem
*entry
, char *buf
)
586 struct pdcspath_entry
*pathentry
;
591 /* Current flags are stored in primary boot path entry */
592 pathentry
= &pdcspath_entry_primary
;
594 /* print the timer value in seconds */
595 read_lock(&pathentry
->rw_lock
);
596 out
+= sprintf(out
, "%u\n", (pathentry
->devpath
.flags
& PF_TIMER
) ?
597 (1 << (pathentry
->devpath
.flags
& PF_TIMER
)) : 0);
598 read_unlock(&pathentry
->rw_lock
);
604 * pdcs_osid_read - Stable Storage OS ID register output.
605 * @entry: An allocated and populated subsytem struct. We don't use it tho.
606 * @buf: The output buffer to write to.
609 pdcs_osid_read(struct subsystem
*entry
, char *buf
)
619 if (pdc_stable_read(PDCS_ADDR_OSID
, &result
, sizeof(result
)) != PDC_OK
)
622 /* the actual result is 16 bits away */
623 switch (result
>> 16) {
624 case 0x0000: tmpstr
= "No OS-dependent data"; break;
625 case 0x0001: tmpstr
= "HP-UX dependent data"; break;
626 case 0x0002: tmpstr
= "MPE-iX dependent data"; break;
627 case 0x0003: tmpstr
= "OSF dependent data"; break;
628 case 0x0004: tmpstr
= "HP-RT dependent data"; break;
629 case 0x0005: tmpstr
= "Novell Netware dependent data"; break;
630 default: tmpstr
= "Unknown"; break;
632 out
+= sprintf(out
, "%s (0x%.4x)\n", tmpstr
, (result
>> 16));
638 * pdcs_fastsize_read - Stable Storage FastSize register output.
639 * @entry: An allocated and populated subsytem struct. We don't use it tho.
640 * @buf: The output buffer to write to.
642 * This register holds the amount of system RAM to be tested during boot sequence.
645 pdcs_fastsize_read(struct subsystem
*entry
, char *buf
)
654 if (pdc_stable_read(PDCS_ADDR_FSIZ
, &result
, sizeof(result
)) != PDC_OK
)
657 if ((result
& 0x0F) < 0x0E)
658 out
+= sprintf(out
, "%d kB", (1<<(result
& 0x0F))*256);
660 out
+= sprintf(out
, "All");
661 out
+= sprintf(out
, "\n");
667 * pdcs_auto_write - This function handles autoboot/search flag modifying.
668 * @entry: An allocated and populated subsytem struct. We don't use it tho.
669 * @buf: The input buffer to read from.
670 * @count: The number of bytes to be read.
671 * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
673 * We will call this function to change the current autoboot flag.
674 * We expect a precise syntax:
675 * \"n\" (n == 0 or 1) to toggle AutoBoot Off or On
678 pdcs_auto_write(struct subsystem
*entry
, const char *buf
, size_t count
, int knob
)
680 struct pdcspath_entry
*pathentry
;
682 char in
[count
+1], *temp
;
685 if (!capable(CAP_SYS_ADMIN
))
688 if (!entry
|| !buf
|| !count
)
691 /* We'll use a local copy of buf */
692 memset(in
, 0, count
+1);
693 strncpy(in
, buf
, count
);
695 /* Current flags are stored in primary boot path entry */
696 pathentry
= &pdcspath_entry_primary
;
698 /* Be nice to the existing flag record */
699 read_lock(&pathentry
->rw_lock
);
700 flags
= pathentry
->devpath
.flags
;
701 read_unlock(&pathentry
->rw_lock
);
703 DPRINTK("%s: flags before: 0x%X\n", __func__
, flags
);
707 while (*temp
&& isspace(*temp
))
711 if ((c
!= 0) && (c
!= 1))
718 DPRINTK("%s: flags after: 0x%X\n", __func__
, flags
);
720 /* So far so good, let's get in deep */
721 write_lock(&pathentry
->rw_lock
);
723 /* Change the path entry flags first */
724 pathentry
->devpath
.flags
= flags
;
726 /* Now, dive in. Write back to the hardware */
727 pdcspath_store(pathentry
);
728 write_unlock(&pathentry
->rw_lock
);
730 printk(KERN_INFO PDCS_PREFIX
": changed \"%s\" to \"%s\"\n",
731 (knob
& PF_AUTOBOOT
) ? "autoboot" : "autosearch",
732 (flags
& knob
) ? "On" : "Off");
737 printk(KERN_WARNING
"%s: Parse error: expect \"n\" (n == 0 or 1)\n", __func__
);
742 * pdcs_autoboot_write - This function handles autoboot flag modifying.
743 * @entry: An allocated and populated subsytem struct. We don't use it tho.
744 * @buf: The input buffer to read from.
745 * @count: The number of bytes to be read.
747 * We will call this function to change the current boot flags.
748 * We expect a precise syntax:
749 * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On
751 static inline ssize_t
752 pdcs_autoboot_write(struct subsystem
*entry
, const char *buf
, size_t count
)
754 return pdcs_auto_write(entry
, buf
, count
, PF_AUTOBOOT
);
758 * pdcs_autosearch_write - This function handles autosearch flag modifying.
759 * @entry: An allocated and populated subsytem struct. We don't use it tho.
760 * @buf: The input buffer to read from.
761 * @count: The number of bytes to be read.
763 * We will call this function to change the current boot flags.
764 * We expect a precise syntax:
765 * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On
767 static inline ssize_t
768 pdcs_autosearch_write(struct subsystem
*entry
, const char *buf
, size_t count
)
770 return pdcs_auto_write(entry
, buf
, count
, PF_AUTOSEARCH
);
773 /* The remaining attributes. */
774 static PDCS_ATTR(size
, 0444, pdcs_size_read
, NULL
);
775 static PDCS_ATTR(autoboot
, 0644, pdcs_autoboot_read
, pdcs_autoboot_write
);
776 static PDCS_ATTR(autosearch
, 0644, pdcs_autosearch_read
, pdcs_autosearch_write
);
777 static PDCS_ATTR(timer
, 0444, pdcs_timer_read
, NULL
);
778 static PDCS_ATTR(osid
, 0400, pdcs_osid_read
, NULL
);
779 static PDCS_ATTR(fastsize
, 0400, pdcs_fastsize_read
, NULL
);
781 static struct subsys_attribute
*pdcs_subsys_attrs
[] = {
784 &pdcs_attr_autosearch
,
791 static decl_subsys(paths
, &ktype_pdcspath
, NULL
);
792 static decl_subsys(stable
, NULL
, NULL
);
795 * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
797 * It creates kobjects corresponding to each path entry with nice sysfs
798 * links to the real device. This is where the magic takes place: when
799 * registering the subsystem attributes during module init, each kobject hereby
800 * created will show in the sysfs tree as a folder containing files as defined
801 * by path_subsys_attr[].
803 static inline int __init
804 pdcs_register_pathentries(void)
807 struct pdcspath_entry
*entry
;
810 /* Initialize the entries rw_lock before anything else */
811 for (i
= 0; (entry
= pdcspath_entries
[i
]); i
++)
812 rwlock_init(&entry
->rw_lock
);
814 for (i
= 0; (entry
= pdcspath_entries
[i
]); i
++) {
815 write_lock(&entry
->rw_lock
);
816 err
= pdcspath_fetch(entry
);
817 write_unlock(&entry
->rw_lock
);
822 if ((err
= kobject_set_name(&entry
->kobj
, "%s", entry
->name
)))
824 kobj_set_kset_s(entry
, paths_subsys
);
825 if ((err
= kobject_register(&entry
->kobj
)))
828 /* kobject is now registered */
829 write_lock(&entry
->rw_lock
);
832 /* Add a nice symlink to the real device */
834 sysfs_create_link(&entry
->kobj
, &entry
->dev
->kobj
, "device");
836 write_unlock(&entry
->rw_lock
);
843 * pdcs_unregister_pathentries - Routine called when unregistering the module.
846 pdcs_unregister_pathentries(void)
849 struct pdcspath_entry
*entry
;
851 for (i
= 0; (entry
= pdcspath_entries
[i
]); i
++) {
852 read_lock(&entry
->rw_lock
);
853 if (entry
->ready
>= 2)
854 kobject_unregister(&entry
->kobj
);
855 read_unlock(&entry
->rw_lock
);
860 * For now we register the stable subsystem with the firmware subsystem
861 * and the paths subsystem with the stable subsystem
864 pdc_stable_init(void)
866 struct subsys_attribute
*attr
;
867 int i
, rc
= 0, error
= 0;
869 /* find the size of the stable storage */
870 if (pdc_stable_get_size(&pdcs_size
) != PDC_OK
)
873 /* make sure we have enough data */
877 printk(KERN_INFO PDCS_PREFIX
" facility v%s\n", PDCS_VERSION
);
879 /* For now we'll register the stable subsys within this driver */
880 if ((rc
= firmware_register(&stable_subsys
)))
883 /* Don't forget the root entries */
884 for (i
= 0; (attr
= pdcs_subsys_attrs
[i
]) && !error
; i
++)
886 error
= subsys_create_file(&stable_subsys
, attr
);
888 /* register the paths subsys as a subsystem of stable subsys */
889 kset_set_kset_s(&paths_subsys
, stable_subsys
);
890 if ((rc
= subsystem_register(&paths_subsys
)))
893 /* now we create all "files" for the paths subsys */
894 if ((rc
= pdcs_register_pathentries()))
900 pdcs_unregister_pathentries();
901 subsystem_unregister(&paths_subsys
);
904 firmware_unregister(&stable_subsys
);
907 printk(KERN_INFO PDCS_PREFIX
" bailing out\n");
912 pdc_stable_exit(void)
914 pdcs_unregister_pathentries();
915 subsystem_unregister(&paths_subsys
);
917 firmware_unregister(&stable_subsys
);
921 module_init(pdc_stable_init
);
922 module_exit(pdc_stable_exit
);