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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * DEV NOTE: the PDC Procedures reference states that:
22 * "A minimum of 96 bytes of Stable Storage is required. Providing more than
23 * 96 bytes of Stable Storage is optional [...]. Failure to provide the
24 * optional locations from 96 to 192 results in the loss of certain
25 * functionality during boot."
27 * Since locations between 96 and 192 are the various paths, most (if not
28 * all) PA-RISC machines should have them. Anyway, for safety reasons, the
29 * following code can deal with just 96 bytes of Stable Storage, and all
30 * sizes between 96 and 192 bytes (provided they are multiple of struct
31 * device_path size, eg: 128, 160 and 192) to provide full information.
32 * The code makes no use of data above 192 bytes. One last word: there's one
33 * path we can always count on: the primary path.
35 * The current policy wrt file permissions is:
37 * - read: (reading triggers PDC calls) ? root only : everyone
38 * The rationale is that PDC calls could hog (DoS) the machine.
41 * - timer/fastsize write calls
46 #define DPRINTK(fmt, args...) printk(KERN_DEBUG fmt, ## args)
48 #define DPRINTK(fmt, args...)
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/kernel.h>
54 #include <linux/string.h>
55 #include <linux/capability.h>
56 #include <linux/ctype.h>
57 #include <linux/sysfs.h>
58 #include <linux/kobject.h>
59 #include <linux/device.h>
60 #include <linux/errno.h>
61 #include <linux/spinlock.h>
65 #include <asm/uaccess.h>
66 #include <asm/hardware.h>
68 #define PDCS_VERSION "0.22"
69 #define PDCS_PREFIX "PDC Stable Storage"
71 #define PDCS_ADDR_PPRI 0x00
72 #define PDCS_ADDR_OSID 0x40
73 #define PDCS_ADDR_FSIZ 0x5C
74 #define PDCS_ADDR_PCON 0x60
75 #define PDCS_ADDR_PALT 0x80
76 #define PDCS_ADDR_PKBD 0xA0
78 MODULE_AUTHOR("Thibaut VARENE <varenet@parisc-linux.org>");
79 MODULE_DESCRIPTION("sysfs interface to HP PDC Stable Storage data");
80 MODULE_LICENSE("GPL");
81 MODULE_VERSION(PDCS_VERSION
);
83 /* holds Stable Storage size. Initialized once and for all, no lock needed */
84 static unsigned long pdcs_size __read_mostly
;
86 /* This struct defines what we need to deal with a parisc pdc path entry */
87 struct pdcspath_entry
{
88 rwlock_t rw_lock
; /* to protect path entry access */
89 short ready
; /* entry record is valid if != 0 */
90 unsigned long addr
; /* entry address in stable storage */
91 char *name
; /* entry name */
92 struct device_path devpath
; /* device path in parisc representation */
93 struct device
*dev
; /* corresponding device */
97 struct pdcspath_attribute
{
98 struct attribute attr
;
99 ssize_t (*show
)(struct pdcspath_entry
*entry
, char *buf
);
100 ssize_t (*store
)(struct pdcspath_entry
*entry
, const char *buf
, size_t count
);
103 #define PDCSPATH_ENTRY(_addr, _name) \
104 struct pdcspath_entry pdcspath_entry_##_name = { \
107 .name = __stringify(_name), \
110 #define PDCS_ATTR(_name, _mode, _show, _store) \
111 struct subsys_attribute pdcs_attr_##_name = { \
112 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \
117 #define PATHS_ATTR(_name, _mode, _show, _store) \
118 struct pdcspath_attribute paths_attr_##_name = { \
119 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \
124 #define to_pdcspath_attribute(_attr) container_of(_attr, struct pdcspath_attribute, attr)
125 #define to_pdcspath_entry(obj) container_of(obj, struct pdcspath_entry, kobj)
128 * pdcspath_fetch - This function populates the path entry structs.
129 * @entry: A pointer to an allocated pdcspath_entry.
131 * The general idea is that you don't read from the Stable Storage every time
132 * you access the files provided by the facilites. We store a copy of the
133 * content of the stable storage WRT various paths in these structs. We read
134 * these structs when reading the files, and we will write to these structs when
135 * writing to the files, and only then write them back to the Stable Storage.
137 * This function expects to be called with @entry->rw_lock write-hold.
140 pdcspath_fetch(struct pdcspath_entry
*entry
)
142 struct device_path
*devpath
;
147 devpath
= &entry
->devpath
;
149 DPRINTK("%s: fetch: 0x%p, 0x%p, addr: 0x%lx\n", __func__
,
150 entry
, devpath
, entry
->addr
);
152 /* addr, devpath and count must be word aligned */
153 if (pdc_stable_read(entry
->addr
, devpath
, sizeof(*devpath
)) != PDC_OK
)
156 /* Find the matching device.
157 NOTE: hardware_path overlays with device_path, so the nice cast can
159 entry
->dev
= hwpath_to_device((struct hardware_path
*)devpath
);
163 DPRINTK("%s: device: 0x%p\n", __func__
, entry
->dev
);
169 * pdcspath_store - This function writes a path to stable storage.
170 * @entry: A pointer to an allocated pdcspath_entry.
172 * It can be used in two ways: either by passing it a preset devpath struct
173 * containing an already computed hardware path, or by passing it a device
174 * pointer, from which it'll find out the corresponding hardware path.
175 * For now we do not handle the case where there's an error in writing to the
176 * Stable Storage area, so you'd better not mess up the data :P
178 * This function expects to be called with @entry->rw_lock write-hold.
181 pdcspath_store(struct pdcspath_entry
*entry
)
183 struct device_path
*devpath
;
187 devpath
= &entry
->devpath
;
189 /* We expect the caller to set the ready flag to 0 if the hardware
190 path struct provided is invalid, so that we know we have to fill it.
191 First case, we don't have a preset hwpath... */
193 /* ...but we have a device, map it */
195 device_to_hwpath(entry
->dev
, (struct hardware_path
*)devpath
);
197 /* else, we expect the provided hwpath to be valid. */
199 DPRINTK("%s: store: 0x%p, 0x%p, addr: 0x%lx\n", __func__
,
200 entry
, devpath
, entry
->addr
);
202 /* addr, devpath and count must be word aligned */
203 if (pdc_stable_write(entry
->addr
, devpath
, sizeof(*devpath
)) != PDC_OK
) {
204 printk(KERN_ERR
"%s: an error occured when writing to PDC.\n"
205 "It is likely that the Stable Storage data has been corrupted.\n"
206 "Please check it carefully upon next reboot.\n", __func__
);
210 /* kobject is already registered */
213 DPRINTK("%s: device: 0x%p\n", __func__
, entry
->dev
);
217 * pdcspath_hwpath_read - This function handles hardware path pretty printing.
218 * @entry: An allocated and populated pdscpath_entry struct.
219 * @buf: The output buffer to write to.
221 * We will call this function to format the output of the hwpath attribute file.
224 pdcspath_hwpath_read(struct pdcspath_entry
*entry
, char *buf
)
227 struct device_path
*devpath
;
233 read_lock(&entry
->rw_lock
);
234 devpath
= &entry
->devpath
;
236 read_unlock(&entry
->rw_lock
);
238 if (!i
) /* entry is not ready */
241 for (i
= 0; i
< 6; i
++) {
242 if (devpath
->bc
[i
] >= 128)
244 out
+= sprintf(out
, "%u/", (unsigned char)devpath
->bc
[i
]);
246 out
+= sprintf(out
, "%u\n", (unsigned char)devpath
->mod
);
252 * pdcspath_hwpath_write - This function handles hardware path modifying.
253 * @entry: An allocated and populated pdscpath_entry struct.
254 * @buf: The input buffer to read from.
255 * @count: The number of bytes to be read.
257 * We will call this function to change the current hardware path.
258 * Hardware paths are to be given '/'-delimited, without brackets.
259 * We make sure that the provided path actually maps to an existing
260 * device, BUT nothing would prevent some foolish user to set the path to some
261 * PCI bridge or even a CPU...
262 * A better work around would be to make sure we are at the end of a device tree
263 * for instance, but it would be IMHO beyond the simple scope of that driver.
264 * The aim is to provide a facility. Data correctness is left to userland.
267 pdcspath_hwpath_write(struct pdcspath_entry
*entry
, const char *buf
, size_t count
)
269 struct hardware_path hwpath
;
271 char in
[count
+1], *temp
;
274 if (!entry
|| !buf
|| !count
)
277 /* We'll use a local copy of buf */
278 memset(in
, 0, count
+1);
279 strncpy(in
, buf
, count
);
281 /* Let's clean up the target. 0xff is a blank pattern */
282 memset(&hwpath
, 0xff, sizeof(hwpath
));
284 /* First, pick the mod field (the last one of the input string) */
285 if (!(temp
= strrchr(in
, '/')))
288 hwpath
.mod
= simple_strtoul(temp
+1, NULL
, 10);
289 in
[temp
-in
] = '\0'; /* truncate the remaining string. just precaution */
290 DPRINTK("%s: mod: %d\n", __func__
, hwpath
.mod
);
292 /* Then, loop for each delimiter, making sure we don't have too many.
293 we write the bc fields in a down-top way. No matter what, we stop
294 before writing the last field. If there are too many fields anyway,
295 then the user is a moron and it'll be caught up later when we'll
296 check the consistency of the given hwpath. */
297 for (i
=5; ((temp
= strrchr(in
, '/'))) && (temp
-in
> 0) && (likely(i
)); i
--) {
298 hwpath
.bc
[i
] = simple_strtoul(temp
+1, NULL
, 10);
300 DPRINTK("%s: bc[%d]: %d\n", __func__
, i
, hwpath
.bc
[i
]);
303 /* Store the final field */
304 hwpath
.bc
[i
] = simple_strtoul(in
, NULL
, 10);
305 DPRINTK("%s: bc[%d]: %d\n", __func__
, i
, hwpath
.bc
[i
]);
307 /* Now we check that the user isn't trying to lure us */
308 if (!(dev
= hwpath_to_device((struct hardware_path
*)&hwpath
))) {
309 printk(KERN_WARNING
"%s: attempt to set invalid \"%s\" "
310 "hardware path: %s\n", __func__
, entry
->name
, buf
);
314 /* So far so good, let's get in deep */
315 write_lock(&entry
->rw_lock
);
319 /* Now, dive in. Write back to the hardware */
320 pdcspath_store(entry
);
322 /* Update the symlink to the real device */
323 sysfs_remove_link(&entry
->kobj
, "device");
324 sysfs_create_link(&entry
->kobj
, &entry
->dev
->kobj
, "device");
325 write_unlock(&entry
->rw_lock
);
327 printk(KERN_INFO PDCS_PREFIX
": changed \"%s\" path to \"%s\"\n",
334 * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing.
335 * @entry: An allocated and populated pdscpath_entry struct.
336 * @buf: The output buffer to write to.
338 * We will call this function to format the output of the layer attribute file.
341 pdcspath_layer_read(struct pdcspath_entry
*entry
, char *buf
)
344 struct device_path
*devpath
;
350 read_lock(&entry
->rw_lock
);
351 devpath
= &entry
->devpath
;
353 read_unlock(&entry
->rw_lock
);
355 if (!i
) /* entry is not ready */
358 for (i
= 0; devpath
->layers
[i
] && (likely(i
< 6)); i
++)
359 out
+= sprintf(out
, "%u ", devpath
->layers
[i
]);
361 out
+= sprintf(out
, "\n");
367 * pdcspath_layer_write - This function handles extended layer modifying.
368 * @entry: An allocated and populated pdscpath_entry struct.
369 * @buf: The input buffer to read from.
370 * @count: The number of bytes to be read.
372 * We will call this function to change the current layer value.
373 * Layers are to be given '.'-delimited, without brackets.
374 * XXX beware we are far less checky WRT input data provided than for hwpath.
375 * Potential harm can be done, since there's no way to check the validity of
379 pdcspath_layer_write(struct pdcspath_entry
*entry
, const char *buf
, size_t count
)
381 unsigned int layers
[6]; /* device-specific info (ctlr#, unit#, ...) */
383 char in
[count
+1], *temp
;
385 if (!entry
|| !buf
|| !count
)
388 /* We'll use a local copy of buf */
389 memset(in
, 0, count
+1);
390 strncpy(in
, buf
, count
);
392 /* Let's clean up the target. 0 is a blank pattern */
393 memset(&layers
, 0, sizeof(layers
));
395 /* First, pick the first layer */
396 if (unlikely(!isdigit(*in
)))
398 layers
[0] = simple_strtoul(in
, NULL
, 10);
399 DPRINTK("%s: layer[0]: %d\n", __func__
, layers
[0]);
402 for (i
=1; ((temp
= strchr(temp
, '.'))) && (likely(i
<6)); i
++) {
403 if (unlikely(!isdigit(*(++temp
))))
405 layers
[i
] = simple_strtoul(temp
, NULL
, 10);
406 DPRINTK("%s: layer[%d]: %d\n", __func__
, i
, layers
[i
]);
409 /* So far so good, let's get in deep */
410 write_lock(&entry
->rw_lock
);
412 /* First, overwrite the current layers with the new ones, not touching
413 the hardware path. */
414 memcpy(&entry
->devpath
.layers
, &layers
, sizeof(layers
));
416 /* Now, dive in. Write back to the hardware */
417 pdcspath_store(entry
);
418 write_unlock(&entry
->rw_lock
);
420 printk(KERN_INFO PDCS_PREFIX
": changed \"%s\" layers to \"%s\"\n",
427 * pdcspath_attr_show - Generic read function call wrapper.
428 * @kobj: The kobject to get info from.
429 * @attr: The attribute looked upon.
430 * @buf: The output buffer.
433 pdcspath_attr_show(struct kobject
*kobj
, struct attribute
*attr
, char *buf
)
435 struct pdcspath_entry
*entry
= to_pdcspath_entry(kobj
);
436 struct pdcspath_attribute
*pdcs_attr
= to_pdcspath_attribute(attr
);
440 ret
= pdcs_attr
->show(entry
, buf
);
446 * pdcspath_attr_store - Generic write function call wrapper.
447 * @kobj: The kobject to write info to.
448 * @attr: The attribute to be modified.
449 * @buf: The input buffer.
450 * @count: The size of the buffer.
453 pdcspath_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
454 const char *buf
, size_t count
)
456 struct pdcspath_entry
*entry
= to_pdcspath_entry(kobj
);
457 struct pdcspath_attribute
*pdcs_attr
= to_pdcspath_attribute(attr
);
460 if (!capable(CAP_SYS_ADMIN
))
463 if (pdcs_attr
->store
)
464 ret
= pdcs_attr
->store(entry
, buf
, count
);
469 static struct sysfs_ops pdcspath_attr_ops
= {
470 .show
= pdcspath_attr_show
,
471 .store
= pdcspath_attr_store
,
474 /* These are the two attributes of any PDC path. */
475 static PATHS_ATTR(hwpath
, 0644, pdcspath_hwpath_read
, pdcspath_hwpath_write
);
476 static PATHS_ATTR(layer
, 0644, pdcspath_layer_read
, pdcspath_layer_write
);
478 static struct attribute
*paths_subsys_attrs
[] = {
479 &paths_attr_hwpath
.attr
,
480 &paths_attr_layer
.attr
,
484 /* Specific kobject type for our PDC paths */
485 static struct kobj_type ktype_pdcspath
= {
486 .sysfs_ops
= &pdcspath_attr_ops
,
487 .default_attrs
= paths_subsys_attrs
,
490 /* We hard define the 4 types of path we expect to find */
491 static PDCSPATH_ENTRY(PDCS_ADDR_PPRI
, primary
);
492 static PDCSPATH_ENTRY(PDCS_ADDR_PCON
, console
);
493 static PDCSPATH_ENTRY(PDCS_ADDR_PALT
, alternative
);
494 static PDCSPATH_ENTRY(PDCS_ADDR_PKBD
, keyboard
);
496 /* An array containing all PDC paths we will deal with */
497 static struct pdcspath_entry
*pdcspath_entries
[] = {
498 &pdcspath_entry_primary
,
499 &pdcspath_entry_alternative
,
500 &pdcspath_entry_console
,
501 &pdcspath_entry_keyboard
,
506 /* For more insight of what's going on here, refer to PDC Procedures doc,
507 * Section PDC_STABLE */
510 * pdcs_size_read - Stable Storage size output.
511 * @entry: An allocated and populated subsytem struct. We don't use it tho.
512 * @buf: The output buffer to write to.
515 pdcs_size_read(struct subsystem
*entry
, char *buf
)
522 /* show the size of the stable storage */
523 out
+= sprintf(out
, "%ld\n", pdcs_size
);
529 * pdcs_auto_read - Stable Storage autoboot/search flag output.
530 * @entry: An allocated and populated subsytem struct. We don't use it tho.
531 * @buf: The output buffer to write to.
532 * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
535 pdcs_auto_read(struct subsystem
*entry
, char *buf
, int knob
)
538 struct pdcspath_entry
*pathentry
;
543 /* Current flags are stored in primary boot path entry */
544 pathentry
= &pdcspath_entry_primary
;
546 read_lock(&pathentry
->rw_lock
);
547 out
+= sprintf(out
, "%s\n", (pathentry
->devpath
.flags
& knob
) ?
549 read_unlock(&pathentry
->rw_lock
);
555 * pdcs_autoboot_read - Stable Storage autoboot flag output.
556 * @entry: An allocated and populated subsytem struct. We don't use it tho.
557 * @buf: The output buffer to write to.
559 static inline ssize_t
560 pdcs_autoboot_read(struct subsystem
*entry
, char *buf
)
562 return pdcs_auto_read(entry
, buf
, PF_AUTOBOOT
);
566 * pdcs_autosearch_read - Stable Storage autoboot flag output.
567 * @entry: An allocated and populated subsytem struct. We don't use it tho.
568 * @buf: The output buffer to write to.
570 static inline ssize_t
571 pdcs_autosearch_read(struct subsystem
*entry
, char *buf
)
573 return pdcs_auto_read(entry
, buf
, PF_AUTOSEARCH
);
577 * pdcs_timer_read - Stable Storage timer count output (in seconds).
578 * @entry: An allocated and populated subsytem struct. We don't use it tho.
579 * @buf: The output buffer to write to.
581 * The value of the timer field correponds to a number of seconds in powers of 2.
584 pdcs_timer_read(struct subsystem
*entry
, char *buf
)
587 struct pdcspath_entry
*pathentry
;
592 /* Current flags are stored in primary boot path entry */
593 pathentry
= &pdcspath_entry_primary
;
595 /* print the timer value in seconds */
596 read_lock(&pathentry
->rw_lock
);
597 out
+= sprintf(out
, "%u\n", (pathentry
->devpath
.flags
& PF_TIMER
) ?
598 (1 << (pathentry
->devpath
.flags
& PF_TIMER
)) : 0);
599 read_unlock(&pathentry
->rw_lock
);
605 * pdcs_osid_read - Stable Storage OS ID register output.
606 * @entry: An allocated and populated subsytem struct. We don't use it tho.
607 * @buf: The output buffer to write to.
610 pdcs_osid_read(struct subsystem
*entry
, char *buf
)
620 if (pdc_stable_read(PDCS_ADDR_OSID
, &result
, sizeof(result
)) != PDC_OK
)
623 /* the actual result is 16 bits away */
624 switch (result
>> 16) {
625 case 0x0000: tmpstr
= "No OS-dependent data"; break;
626 case 0x0001: tmpstr
= "HP-UX dependent data"; break;
627 case 0x0002: tmpstr
= "MPE-iX dependent data"; break;
628 case 0x0003: tmpstr
= "OSF dependent data"; break;
629 case 0x0004: tmpstr
= "HP-RT dependent data"; break;
630 case 0x0005: tmpstr
= "Novell Netware dependent data"; break;
631 default: tmpstr
= "Unknown"; break;
633 out
+= sprintf(out
, "%s (0x%.4x)\n", tmpstr
, (result
>> 16));
639 * pdcs_fastsize_read - Stable Storage FastSize register output.
640 * @entry: An allocated and populated subsytem struct. We don't use it tho.
641 * @buf: The output buffer to write to.
643 * This register holds the amount of system RAM to be tested during boot sequence.
646 pdcs_fastsize_read(struct subsystem
*entry
, char *buf
)
655 if (pdc_stable_read(PDCS_ADDR_FSIZ
, &result
, sizeof(result
)) != PDC_OK
)
658 if ((result
& 0x0F) < 0x0E)
659 out
+= sprintf(out
, "%d kB", (1<<(result
& 0x0F))*256);
661 out
+= sprintf(out
, "All");
662 out
+= sprintf(out
, "\n");
668 * pdcs_auto_write - This function handles autoboot/search flag modifying.
669 * @entry: An allocated and populated subsytem struct. We don't use it tho.
670 * @buf: The input buffer to read from.
671 * @count: The number of bytes to be read.
672 * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
674 * We will call this function to change the current autoboot flag.
675 * We expect a precise syntax:
676 * \"n\" (n == 0 or 1) to toggle AutoBoot Off or On
679 pdcs_auto_write(struct subsystem
*entry
, const char *buf
, size_t count
, int knob
)
681 struct pdcspath_entry
*pathentry
;
683 char in
[count
+1], *temp
;
686 if (!capable(CAP_SYS_ADMIN
))
689 if (!entry
|| !buf
|| !count
)
692 /* We'll use a local copy of buf */
693 memset(in
, 0, count
+1);
694 strncpy(in
, buf
, count
);
696 /* Current flags are stored in primary boot path entry */
697 pathentry
= &pdcspath_entry_primary
;
699 /* Be nice to the existing flag record */
700 read_lock(&pathentry
->rw_lock
);
701 flags
= pathentry
->devpath
.flags
;
702 read_unlock(&pathentry
->rw_lock
);
704 DPRINTK("%s: flags before: 0x%X\n", __func__
, flags
);
708 while (*temp
&& isspace(*temp
))
712 if ((c
!= 0) && (c
!= 1))
719 DPRINTK("%s: flags after: 0x%X\n", __func__
, flags
);
721 /* So far so good, let's get in deep */
722 write_lock(&pathentry
->rw_lock
);
724 /* Change the path entry flags first */
725 pathentry
->devpath
.flags
= flags
;
727 /* Now, dive in. Write back to the hardware */
728 pdcspath_store(pathentry
);
729 write_unlock(&pathentry
->rw_lock
);
731 printk(KERN_INFO PDCS_PREFIX
": changed \"%s\" to \"%s\"\n",
732 (knob
& PF_AUTOBOOT
) ? "autoboot" : "autosearch",
733 (flags
& knob
) ? "On" : "Off");
738 printk(KERN_WARNING
"%s: Parse error: expect \"n\" (n == 0 or 1)\n", __func__
);
743 * pdcs_autoboot_write - This function handles autoboot flag modifying.
744 * @entry: An allocated and populated subsytem struct. We don't use it tho.
745 * @buf: The input buffer to read from.
746 * @count: The number of bytes to be read.
748 * We will call this function to change the current boot flags.
749 * We expect a precise syntax:
750 * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On
752 static inline ssize_t
753 pdcs_autoboot_write(struct subsystem
*entry
, const char *buf
, size_t count
)
755 return pdcs_auto_write(entry
, buf
, count
, PF_AUTOBOOT
);
759 * pdcs_autosearch_write - This function handles autosearch flag modifying.
760 * @entry: An allocated and populated subsytem struct. We don't use it tho.
761 * @buf: The input buffer to read from.
762 * @count: The number of bytes to be read.
764 * We will call this function to change the current boot flags.
765 * We expect a precise syntax:
766 * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On
768 static inline ssize_t
769 pdcs_autosearch_write(struct subsystem
*entry
, const char *buf
, size_t count
)
771 return pdcs_auto_write(entry
, buf
, count
, PF_AUTOSEARCH
);
774 /* The remaining attributes. */
775 static PDCS_ATTR(size
, 0444, pdcs_size_read
, NULL
);
776 static PDCS_ATTR(autoboot
, 0644, pdcs_autoboot_read
, pdcs_autoboot_write
);
777 static PDCS_ATTR(autosearch
, 0644, pdcs_autosearch_read
, pdcs_autosearch_write
);
778 static PDCS_ATTR(timer
, 0444, pdcs_timer_read
, NULL
);
779 static PDCS_ATTR(osid
, 0400, pdcs_osid_read
, NULL
);
780 static PDCS_ATTR(fastsize
, 0400, pdcs_fastsize_read
, NULL
);
782 static struct subsys_attribute
*pdcs_subsys_attrs
[] = {
785 &pdcs_attr_autosearch
,
792 static decl_subsys(paths
, &ktype_pdcspath
, NULL
);
793 static decl_subsys(stable
, NULL
, NULL
);
796 * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
798 * It creates kobjects corresponding to each path entry with nice sysfs
799 * links to the real device. This is where the magic takes place: when
800 * registering the subsystem attributes during module init, each kobject hereby
801 * created will show in the sysfs tree as a folder containing files as defined
802 * by path_subsys_attr[].
804 static inline int __init
805 pdcs_register_pathentries(void)
808 struct pdcspath_entry
*entry
;
811 /* Initialize the entries rw_lock before anything else */
812 for (i
= 0; (entry
= pdcspath_entries
[i
]); i
++)
813 rwlock_init(&entry
->rw_lock
);
815 for (i
= 0; (entry
= pdcspath_entries
[i
]); i
++) {
816 write_lock(&entry
->rw_lock
);
817 err
= pdcspath_fetch(entry
);
818 write_unlock(&entry
->rw_lock
);
823 if ((err
= kobject_set_name(&entry
->kobj
, "%s", entry
->name
)))
825 kobj_set_kset_s(entry
, paths_subsys
);
826 if ((err
= kobject_register(&entry
->kobj
)))
829 /* kobject is now registered */
830 write_lock(&entry
->rw_lock
);
833 /* Add a nice symlink to the real device */
835 sysfs_create_link(&entry
->kobj
, &entry
->dev
->kobj
, "device");
837 write_unlock(&entry
->rw_lock
);
844 * pdcs_unregister_pathentries - Routine called when unregistering the module.
847 pdcs_unregister_pathentries(void)
850 struct pdcspath_entry
*entry
;
852 for (i
= 0; (entry
= pdcspath_entries
[i
]); i
++) {
853 read_lock(&entry
->rw_lock
);
854 if (entry
->ready
>= 2)
855 kobject_unregister(&entry
->kobj
);
856 read_unlock(&entry
->rw_lock
);
861 * For now we register the stable subsystem with the firmware subsystem
862 * and the paths subsystem with the stable subsystem
865 pdc_stable_init(void)
867 struct subsys_attribute
*attr
;
868 int i
, rc
= 0, error
= 0;
870 /* find the size of the stable storage */
871 if (pdc_stable_get_size(&pdcs_size
) != PDC_OK
)
874 /* make sure we have enough data */
878 printk(KERN_INFO PDCS_PREFIX
" facility v%s\n", PDCS_VERSION
);
880 /* For now we'll register the stable subsys within this driver */
881 if ((rc
= firmware_register(&stable_subsys
)))
884 /* Don't forget the root entries */
885 for (i
= 0; (attr
= pdcs_subsys_attrs
[i
]) && !error
; i
++)
887 error
= subsys_create_file(&stable_subsys
, attr
);
889 /* register the paths subsys as a subsystem of stable subsys */
890 kset_set_kset_s(&paths_subsys
, stable_subsys
);
891 if ((rc
= subsystem_register(&paths_subsys
)))
894 /* now we create all "files" for the paths subsys */
895 if ((rc
= pdcs_register_pathentries()))
901 pdcs_unregister_pathentries();
902 subsystem_unregister(&paths_subsys
);
905 firmware_unregister(&stable_subsys
);
908 printk(KERN_INFO PDCS_PREFIX
" bailing out\n");
913 pdc_stable_exit(void)
915 pdcs_unregister_pathentries();
916 subsystem_unregister(&paths_subsys
);
918 firmware_unregister(&stable_subsys
);
922 module_init(pdc_stable_init
);
923 module_exit(pdc_stable_exit
);