X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fparisc%2Fpdc_stable.c;h=ea1b7a63598e1c4fc87ee001a66293cb2fe92b37;hb=refs%2Fheads%2Fvserver;hp=67c8f3b44848d71fd7d35e55d8f484445346d379;hpb=4b659086703c3cfdabfc916b517590ad55d1ddfa;p=linux-2.6.git diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c index 67c8f3b44..ea1b7a635 100644 --- a/drivers/parisc/pdc_stable.c +++ b/drivers/parisc/pdc_stable.c @@ -1,12 +1,11 @@ /* * Interfaces to retrieve and set PDC Stable options (firmware) * - * Copyright (C) 2005 Thibaut VARENE + * Copyright (C) 2005-2006 Thibaut VARENE * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -26,11 +25,26 @@ * * Since locations between 96 and 192 are the various paths, most (if not * all) PA-RISC machines should have them. Anyway, for safety reasons, the - * following code can deal with only 96 bytes of Stable Storage, and all + * following code can deal with just 96 bytes of Stable Storage, and all * sizes between 96 and 192 bytes (provided they are multiple of struct * device_path size, eg: 128, 160 and 192) to provide full information. - * The code makes no use of data above 192 bytes. One last word: there's one - * path we can always count on: the primary path. + * One last word: there's one path we can always count on: the primary path. + * Anything above 224 bytes is used for 'osdep2' OS-dependent storage area. + * + * The first OS-dependent area should always be available. Obviously, this is + * not true for the other one. Also bear in mind that reading/writing from/to + * osdep2 is much more expensive than from/to osdep1. + * NOTE: We do not handle the 2 bytes OS-dep area at 0x5D, nor the first + * 2 bytes of storage available right after OSID. That's a total of 4 bytes + * sacrificed: -ETOOLAZY :P + * + * The current policy wrt file permissions is: + * - write: root only + * - read: (reading triggers PDC calls) ? root only : everyone + * The rationale is that PDC calls could hog (DoS) the machine. + * + * TODO: + * - timer/fastsize write calls */ #undef PDCS_DEBUG @@ -42,38 +56,48 @@ #include #include -#include /* for capable() */ #include #include +#include #include #include #include #include #include +#include #include #include #include #include -#define PDCS_VERSION "0.09" +#define PDCS_VERSION "0.30" +#define PDCS_PREFIX "PDC Stable Storage" #define PDCS_ADDR_PPRI 0x00 #define PDCS_ADDR_OSID 0x40 +#define PDCS_ADDR_OSD1 0x48 +#define PDCS_ADDR_DIAG 0x58 #define PDCS_ADDR_FSIZ 0x5C #define PDCS_ADDR_PCON 0x60 #define PDCS_ADDR_PALT 0x80 #define PDCS_ADDR_PKBD 0xA0 +#define PDCS_ADDR_OSD2 0xE0 MODULE_AUTHOR("Thibaut VARENE "); MODULE_DESCRIPTION("sysfs interface to HP PDC Stable Storage data"); MODULE_LICENSE("GPL"); MODULE_VERSION(PDCS_VERSION); -static unsigned long pdcs_size = 0; +/* holds Stable Storage size. Initialized once and for all, no lock needed */ +static unsigned long pdcs_size __read_mostly; + +/* holds OS ID. Initialized once and for all, hopefully to 0x0006 */ +static u16 pdcs_osid __read_mostly; /* This struct defines what we need to deal with a parisc pdc path entry */ struct pdcspath_entry { + rwlock_t rw_lock; /* to protect path entry access */ short ready; /* entry record is valid if != 0 */ unsigned long addr; /* entry address in stable storage */ char *name; /* entry name */ @@ -121,6 +145,8 @@ struct pdcspath_attribute paths_attr_##_name = { \ * content of the stable storage WRT various paths in these structs. We read * these structs when reading the files, and we will write to these structs when * writing to the files, and only then write them back to the Stable Storage. + * + * This function expects to be called with @entry->rw_lock write-hold. */ static int pdcspath_fetch(struct pdcspath_entry *entry) @@ -160,14 +186,15 @@ pdcspath_fetch(struct pdcspath_entry *entry) * pointer, from which it'll find out the corresponding hardware path. * For now we do not handle the case where there's an error in writing to the * Stable Storage area, so you'd better not mess up the data :P + * + * This function expects to be called with @entry->rw_lock write-hold. */ -static int +static void pdcspath_store(struct pdcspath_entry *entry) { struct device_path *devpath; - if (!entry) - return -EINVAL; + BUG_ON(!entry); devpath = &entry->devpath; @@ -176,10 +203,8 @@ pdcspath_store(struct pdcspath_entry *entry) First case, we don't have a preset hwpath... */ if (!entry->ready) { /* ...but we have a device, map it */ - if (entry->dev) - device_to_hwpath(entry->dev, (struct hardware_path *)devpath); - else - return -EINVAL; + BUG_ON(!entry->dev); + device_to_hwpath(entry->dev, (struct hardware_path *)devpath); } /* else, we expect the provided hwpath to be valid. */ @@ -191,14 +216,13 @@ pdcspath_store(struct pdcspath_entry *entry) printk(KERN_ERR "%s: an error occured when writing to PDC.\n" "It is likely that the Stable Storage data has been corrupted.\n" "Please check it carefully upon next reboot.\n", __func__); - return -EIO; + WARN_ON(1); } - entry->ready = 1; + /* kobject is already registered */ + entry->ready = 2; DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); - - return 0; } /** @@ -213,14 +237,17 @@ pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf) { char *out = buf; struct device_path *devpath; - unsigned short i; + short i; if (!entry || !buf) return -EINVAL; + read_lock(&entry->rw_lock); devpath = &entry->devpath; + i = entry->ready; + read_unlock(&entry->rw_lock); - if (!entry->ready) + if (!i) /* entry is not ready */ return -ENODATA; for (i = 0; i < 6; i++) { @@ -241,7 +268,7 @@ pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf) * * We will call this function to change the current hardware path. * Hardware paths are to be given '/'-delimited, without brackets. - * We take care to make sure that the provided path actually maps to an existing + * We make sure that the provided path actually maps to an existing * device, BUT nothing would prevent some foolish user to set the path to some * PCI bridge or even a CPU... * A better work around would be to make sure we are at the end of a device tree @@ -297,17 +324,19 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t coun } /* So far so good, let's get in deep */ + write_lock(&entry->rw_lock); entry->ready = 0; entry->dev = dev; /* Now, dive in. Write back to the hardware */ - WARN_ON(pdcspath_store(entry)); /* this warn should *NEVER* happen */ + pdcspath_store(entry); /* Update the symlink to the real device */ sysfs_remove_link(&entry->kobj, "device"); sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); + write_unlock(&entry->rw_lock); - printk(KERN_INFO "PDC Stable Storage: changed \"%s\" path to \"%s\"\n", + printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" path to \"%s\"\n", entry->name, buf); return count; @@ -325,14 +354,17 @@ pdcspath_layer_read(struct pdcspath_entry *entry, char *buf) { char *out = buf; struct device_path *devpath; - unsigned short i; + short i; if (!entry || !buf) return -EINVAL; + read_lock(&entry->rw_lock); devpath = &entry->devpath; + i = entry->ready; + read_unlock(&entry->rw_lock); - if (!entry->ready) + if (!i) /* entry is not ready */ return -ENODATA; for (i = 0; devpath->layers[i] && (likely(i < 6)); i++) @@ -387,15 +419,17 @@ pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count } /* So far so good, let's get in deep */ + write_lock(&entry->rw_lock); /* First, overwrite the current layers with the new ones, not touching the hardware path. */ memcpy(&entry->devpath.layers, &layers, sizeof(layers)); /* Now, dive in. Write back to the hardware */ - WARN_ON(pdcspath_store(entry)); /* this warn should *NEVER* happen */ + pdcspath_store(entry); + write_unlock(&entry->rw_lock); - printk(KERN_INFO "PDC Stable Storage: changed \"%s\" layers to \"%s\"\n", + printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" layers to \"%s\"\n", entry->name, buf); return count; @@ -414,9 +448,6 @@ pdcspath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr); ssize_t ret = 0; - if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - if (pdcs_attr->show) ret = pdcs_attr->show(entry, buf); @@ -453,8 +484,8 @@ static struct sysfs_ops pdcspath_attr_ops = { }; /* These are the two attributes of any PDC path. */ -static PATHS_ATTR(hwpath, 0600, pdcspath_hwpath_read, pdcspath_hwpath_write); -static PATHS_ATTR(layer, 0600, pdcspath_layer_read, pdcspath_layer_write); +static PATHS_ATTR(hwpath, 0644, pdcspath_hwpath_read, pdcspath_hwpath_write); +static PATHS_ATTR(layer, 0644, pdcspath_layer_read, pdcspath_layer_write); static struct attribute *paths_subsys_attrs[] = { &paths_attr_hwpath.attr, @@ -483,60 +514,198 @@ static struct pdcspath_entry *pdcspath_entries[] = { NULL, }; + +/* For more insight of what's going on here, refer to PDC Procedures doc, + * Section PDC_STABLE */ + /** - * pdcs_info_read - Pretty printing of the remaining useful data. + * pdcs_size_read - Stable Storage size output. * @entry: An allocated and populated subsytem struct. We don't use it tho. * @buf: The output buffer to write to. - * - * We will call this function to format the output of the 'info' attribute file. - * Please refer to PDC Procedures documentation, section PDC_STABLE to get a - * better insight of what we're doing here. */ static ssize_t -pdcs_info_read(struct subsystem *entry, char *buf) +pdcs_size_read(struct subsystem *entry, char *buf) { char *out = buf; - __u32 result; - struct device_path devpath; - char *tmpstr = NULL; if (!entry || !buf) return -EINVAL; /* show the size of the stable storage */ - out += sprintf(out, "Stable Storage size: %ld bytes\n", pdcs_size); + out += sprintf(out, "%ld\n", pdcs_size); + + return out - buf; +} + +/** + * pdcs_auto_read - Stable Storage autoboot/search flag output. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The output buffer to write to. + * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag + */ +static ssize_t +pdcs_auto_read(struct subsystem *entry, char *buf, int knob) +{ + char *out = buf; + struct pdcspath_entry *pathentry; + + if (!entry || !buf) + return -EINVAL; + + /* Current flags are stored in primary boot path entry */ + pathentry = &pdcspath_entry_primary; + + read_lock(&pathentry->rw_lock); + out += sprintf(out, "%s\n", (pathentry->devpath.flags & knob) ? + "On" : "Off"); + read_unlock(&pathentry->rw_lock); + + return out - buf; +} + +/** + * pdcs_autoboot_read - Stable Storage autoboot flag output. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The output buffer to write to. + */ +static inline ssize_t +pdcs_autoboot_read(struct subsystem *entry, char *buf) +{ + return pdcs_auto_read(entry, buf, PF_AUTOBOOT); +} + +/** + * pdcs_autosearch_read - Stable Storage autoboot flag output. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The output buffer to write to. + */ +static inline ssize_t +pdcs_autosearch_read(struct subsystem *entry, char *buf) +{ + return pdcs_auto_read(entry, buf, PF_AUTOSEARCH); +} + +/** + * pdcs_timer_read - Stable Storage timer count output (in seconds). + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The output buffer to write to. + * + * The value of the timer field correponds to a number of seconds in powers of 2. + */ +static ssize_t +pdcs_timer_read(struct subsystem *entry, char *buf) +{ + char *out = buf; + struct pdcspath_entry *pathentry; - /* deal with flags */ - if (pdc_stable_read(PDCS_ADDR_PPRI, &devpath, sizeof(devpath)) != PDC_OK) + if (!entry || !buf) + return -EINVAL; + + /* Current flags are stored in primary boot path entry */ + pathentry = &pdcspath_entry_primary; + + /* print the timer value in seconds */ + read_lock(&pathentry->rw_lock); + out += sprintf(out, "%u\n", (pathentry->devpath.flags & PF_TIMER) ? + (1 << (pathentry->devpath.flags & PF_TIMER)) : 0); + read_unlock(&pathentry->rw_lock); + + return out - buf; +} + +/** + * pdcs_osid_read - Stable Storage OS ID register output. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The output buffer to write to. + */ +static ssize_t +pdcs_osid_read(struct subsystem *entry, char *buf) +{ + char *out = buf; + + if (!entry || !buf) + return -EINVAL; + + out += sprintf(out, "%s dependent data (0x%.4x)\n", + os_id_to_string(pdcs_osid), pdcs_osid); + + return out - buf; +} + +/** + * pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The output buffer to write to. + * + * This can hold 16 bytes of OS-Dependent data. + */ +static ssize_t +pdcs_osdep1_read(struct subsystem *entry, char *buf) +{ + char *out = buf; + u32 result[4]; + + if (!entry || !buf) + return -EINVAL; + + if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK) return -EIO; - - out += sprintf(out, "Autoboot: %s\n", (devpath.flags & PF_AUTOBOOT) ? "On" : "Off"); - out += sprintf(out, "Autosearch: %s\n", (devpath.flags & PF_AUTOSEARCH) ? "On" : "Off"); - out += sprintf(out, "Timer: %u s\n", (devpath.flags & PF_TIMER) ? (1 << (devpath.flags & PF_TIMER)) : 0); - /* get OSID */ - if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK) + out += sprintf(out, "0x%.8x\n", result[0]); + out += sprintf(out, "0x%.8x\n", result[1]); + out += sprintf(out, "0x%.8x\n", result[2]); + out += sprintf(out, "0x%.8x\n", result[3]); + + return out - buf; +} + +/** + * pdcs_diagnostic_read - Stable Storage Diagnostic register output. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The output buffer to write to. + * + * I have NFC how to interpret the content of that register ;-). + */ +static ssize_t +pdcs_diagnostic_read(struct subsystem *entry, char *buf) +{ + char *out = buf; + u32 result; + + if (!entry || !buf) + return -EINVAL; + + /* get diagnostic */ + if (pdc_stable_read(PDCS_ADDR_DIAG, &result, sizeof(result)) != PDC_OK) return -EIO; - /* the actual result is 16 bits away */ - switch (result >> 16) { - case 0x0000: tmpstr = "No OS-dependent data"; break; - case 0x0001: tmpstr = "HP-UX dependent data"; break; - case 0x0002: tmpstr = "MPE-iX dependent data"; break; - case 0x0003: tmpstr = "OSF dependent data"; break; - case 0x0004: tmpstr = "HP-RT dependent data"; break; - case 0x0005: tmpstr = "Novell Netware dependent data"; break; - default: tmpstr = "Unknown"; break; - } - out += sprintf(out, "OS ID: %s (0x%.4x)\n", tmpstr, (result >> 16)); + out += sprintf(out, "0x%.4x\n", (result >> 16)); + + return out - buf; +} + +/** + * pdcs_fastsize_read - Stable Storage FastSize register output. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The output buffer to write to. + * + * This register holds the amount of system RAM to be tested during boot sequence. + */ +static ssize_t +pdcs_fastsize_read(struct subsystem *entry, char *buf) +{ + char *out = buf; + u32 result; + + if (!entry || !buf) + return -EINVAL; /* get fast-size */ if (pdc_stable_read(PDCS_ADDR_FSIZ, &result, sizeof(result)) != PDC_OK) return -EIO; - out += sprintf(out, "Memory tested: "); if ((result & 0x0F) < 0x0E) - out += sprintf(out, "%.3f MB", 0.256*(1<<(result & 0x0F))); + out += sprintf(out, "%d kB", (1<<(result & 0x0F))*256); else out += sprintf(out, "All"); out += sprintf(out, "\n"); @@ -545,22 +714,51 @@ pdcs_info_read(struct subsystem *entry, char *buf) } /** - * pdcs_info_write - This function handles boot flag modifying. + * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The output buffer to write to. + * + * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available. + */ +static ssize_t +pdcs_osdep2_read(struct subsystem *entry, char *buf) +{ + char *out = buf; + unsigned long size; + unsigned short i; + u32 result; + + if (unlikely(pdcs_size <= 224)) + return -ENODATA; + + size = pdcs_size - 224; + + if (!entry || !buf) + return -EINVAL; + + for (i=0; irw_lock); flags = pathentry->devpath.flags; + read_unlock(&pathentry->rw_lock); DPRINTK("%s: flags before: 0x%X\n", __func__, flags); @@ -594,50 +794,175 @@ pdcs_info_write(struct subsystem *entry, const char *buf, size_t count) if ((c != 0) && (c != 1)) goto parse_error; if (c == 0) - flags &= ~PF_AUTOBOOT; + flags &= ~knob; else - flags |= PF_AUTOBOOT; - - if (*temp++ != ' ') - goto parse_error; - - c = *temp++ - '0'; - if ((c != 0) && (c != 1)) - goto parse_error; - if (c == 0) - flags &= ~PF_AUTOSEARCH; - else - flags |= PF_AUTOSEARCH; + flags |= knob; DPRINTK("%s: flags after: 0x%X\n", __func__, flags); /* So far so good, let's get in deep */ + write_lock(&pathentry->rw_lock); /* Change the path entry flags first */ pathentry->devpath.flags = flags; /* Now, dive in. Write back to the hardware */ - WARN_ON(pdcspath_store(pathentry)); /* this warn should *NEVER* happen */ + pdcspath_store(pathentry); + write_unlock(&pathentry->rw_lock); - printk(KERN_INFO "PDC Stable Storage: changed flags to \"%s\"\n", buf); + printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" to \"%s\"\n", + (knob & PF_AUTOBOOT) ? "autoboot" : "autosearch", + (flags & knob) ? "On" : "Off"); return count; parse_error: - printk(KERN_WARNING "%s: Parse error: expect \"n n\" (n == 0 or 1) for AB and AS\n", __func__); + printk(KERN_WARNING "%s: Parse error: expect \"n\" (n == 0 or 1)\n", __func__); return -EINVAL; } -/* The last attribute (the 'root' one actually) with all remaining data. */ -static PDCS_ATTR(info, 0600, pdcs_info_read, pdcs_info_write); +/** + * pdcs_autoboot_write - This function handles autoboot flag modifying. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The input buffer to read from. + * @count: The number of bytes to be read. + * + * We will call this function to change the current boot flags. + * We expect a precise syntax: + * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On + */ +static inline ssize_t +pdcs_autoboot_write(struct subsystem *entry, const char *buf, size_t count) +{ + return pdcs_auto_write(entry, buf, count, PF_AUTOBOOT); +} + +/** + * pdcs_autosearch_write - This function handles autosearch flag modifying. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The input buffer to read from. + * @count: The number of bytes to be read. + * + * We will call this function to change the current boot flags. + * We expect a precise syntax: + * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On + */ +static inline ssize_t +pdcs_autosearch_write(struct subsystem *entry, const char *buf, size_t count) +{ + return pdcs_auto_write(entry, buf, count, PF_AUTOSEARCH); +} + +/** + * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The input buffer to read from. + * @count: The number of bytes to be read. + * + * This can store 16 bytes of OS-Dependent data. We use a byte-by-byte + * write approach. It's up to userspace to deal with it when constructing + * its input buffer. + */ +static ssize_t +pdcs_osdep1_write(struct subsystem *entry, const char *buf, size_t count) +{ + u8 in[16]; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (!entry || !buf || !count) + return -EINVAL; + + if (unlikely(pdcs_osid != OS_ID_LINUX)) + return -EPERM; + + if (count > 16) + return -EMSGSIZE; + + /* We'll use a local copy of buf */ + memset(in, 0, 16); + memcpy(in, buf, count); + + if (pdc_stable_write(PDCS_ADDR_OSD1, &in, sizeof(in)) != PDC_OK) + return -EIO; + + return count; +} + +/** + * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input. + * @entry: An allocated and populated subsytem struct. We don't use it tho. + * @buf: The input buffer to read from. + * @count: The number of bytes to be read. + * + * This can store pdcs_size - 224 bytes of OS-Dependent data. We use a + * byte-by-byte write approach. It's up to userspace to deal with it when + * constructing its input buffer. + */ +static ssize_t +pdcs_osdep2_write(struct subsystem *entry, const char *buf, size_t count) +{ + unsigned long size; + unsigned short i; + u8 in[4]; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (!entry || !buf || !count) + return -EINVAL; + + if (unlikely(pdcs_size <= 224)) + return -ENOSYS; + + if (unlikely(pdcs_osid != OS_ID_LINUX)) + return -EPERM; + + size = pdcs_size - 224; + + if (count > size) + return -EMSGSIZE; + + /* We'll use a local copy of buf */ + + for (i=0; irw_lock); - kobject_set_name(&entry->kobj, "%s", entry->name); - kobj_set_kset_s(entry, paths_subsys); - kobject_register(&entry->kobj); + for (i = 0; (entry = pdcspath_entries[i]); i++) { + write_lock(&entry->rw_lock); + err = pdcspath_fetch(entry); + write_unlock(&entry->rw_lock); - if (!entry->dev) + if (err < 0) continue; + if ((err = kobject_set_name(&entry->kobj, "%s", entry->name))) + return err; + kobj_set_kset_s(entry, paths_subsys); + if ((err = kobject_register(&entry->kobj))) + return err; + + /* kobject is now registered */ + write_lock(&entry->rw_lock); + entry->ready = 2; + /* Add a nice symlink to the real device */ - sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); + if (entry->dev) + sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); + + write_unlock(&entry->rw_lock); } return 0; @@ -675,50 +1015,78 @@ pdcs_register_pathentries(void) /** * pdcs_unregister_pathentries - Routine called when unregistering the module. */ -static inline void __exit +static inline void pdcs_unregister_pathentries(void) { unsigned short i; struct pdcspath_entry *entry; - for (i = 0; (entry = pdcspath_entries[i]); i++) - if (entry->ready) - kobject_unregister(&entry->kobj); + for (i = 0; (entry = pdcspath_entries[i]); i++) { + read_lock(&entry->rw_lock); + if (entry->ready >= 2) + kobject_unregister(&entry->kobj); + read_unlock(&entry->rw_lock); + } } /* - * For now we register the pdc subsystem with the firmware subsystem - * and the paths subsystem with the pdc subsystem + * For now we register the stable subsystem with the firmware subsystem + * and the paths subsystem with the stable subsystem */ static int __init pdc_stable_init(void) { struct subsys_attribute *attr; int i, rc = 0, error = 0; + u32 result; /* find the size of the stable storage */ if (pdc_stable_get_size(&pdcs_size) != PDC_OK) return -ENODEV; - printk(KERN_INFO "PDC Stable Storage facility v%s\n", PDCS_VERSION); + /* make sure we have enough data */ + if (pdcs_size < 96) + return -ENODATA; - /* For now we'll register the pdc subsys within this driver */ - if ((rc = firmware_register(&pdc_subsys))) - return rc; + printk(KERN_INFO PDCS_PREFIX " facility v%s\n", PDCS_VERSION); - /* Don't forget the info entry */ + /* get OSID */ + if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK) + return -EIO; + + /* the actual result is 16 bits away */ + pdcs_osid = (u16)(result >> 16); + + /* For now we'll register the stable subsys within this driver */ + if ((rc = firmware_register(&stable_subsys))) + goto fail_firmreg; + + /* Don't forget the root entries */ for (i = 0; (attr = pdcs_subsys_attrs[i]) && !error; i++) if (attr->show) - error = subsys_create_file(&pdc_subsys, attr); + error = subsys_create_file(&stable_subsys, attr); - /* register the paths subsys as a subsystem of pdc subsys */ - kset_set_kset_s(&paths_subsys, pdc_subsys); - subsystem_register(&paths_subsys); + /* register the paths subsys as a subsystem of stable subsys */ + kset_set_kset_s(&paths_subsys, stable_subsys); + if ((rc = subsystem_register(&paths_subsys))) + goto fail_subsysreg; /* now we create all "files" for the paths subsys */ - pdcs_register_pathentries(); + if ((rc = pdcs_register_pathentries())) + goto fail_pdcsreg; + + return rc; - return 0; +fail_pdcsreg: + pdcs_unregister_pathentries(); + subsystem_unregister(&paths_subsys); + +fail_subsysreg: + firmware_unregister(&stable_subsys); + +fail_firmreg: + printk(KERN_INFO PDCS_PREFIX " bailing out\n"); + return rc; } static void __exit @@ -727,7 +1095,7 @@ pdc_stable_exit(void) pdcs_unregister_pathentries(); subsystem_unregister(&paths_subsys); - firmware_unregister(&pdc_subsys); + firmware_unregister(&stable_subsys); }