Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Interfaces to retrieve and set PDC Stable options (firmware) |
| 3 | * |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 4 | * Copyright (C) 2005-2006 Thibaut VARENE <varenet@parisc-linux.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Thibaut VARENE | a81dd18 | 2006-02-03 18:06:30 -0700 | [diff] [blame] | 7 | * it under the terms of the GNU General Public License, version 2, as |
| 8 | * published by the Free Software Foundation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 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. |
| 14 | * |
| 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 |
| 18 | * |
| 19 | * |
| 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." |
| 25 | * |
| 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 |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 28 | * following code can deal with just 96 bytes of Stable Storage, and all |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 31 | * One last word: there's one path we can always count on: the primary path. |
| 32 | * Anything above 224 bytes is used for 'osdep2' OS-dependent storage area. |
| 33 | * |
| 34 | * The first OS-dependent area should always be available. Obviously, this is |
| 35 | * not true for the other one. Also bear in mind that reading/writing from/to |
| 36 | * osdep2 is much more expensive than from/to osdep1. |
| 37 | * NOTE: We do not handle the 2 bytes OS-dep area at 0x5D, nor the first |
| 38 | * 2 bytes of storage available right after OSID. That's a total of 4 bytes |
| 39 | * sacrificed: -ETOOLAZY :P |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 40 | * |
| 41 | * The current policy wrt file permissions is: |
| 42 | * - write: root only |
| 43 | * - read: (reading triggers PDC calls) ? root only : everyone |
| 44 | * The rationale is that PDC calls could hog (DoS) the machine. |
| 45 | * |
| 46 | * TODO: |
| 47 | * - timer/fastsize write calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | */ |
| 49 | |
| 50 | #undef PDCS_DEBUG |
| 51 | #ifdef PDCS_DEBUG |
| 52 | #define DPRINTK(fmt, args...) printk(KERN_DEBUG fmt, ## args) |
| 53 | #else |
| 54 | #define DPRINTK(fmt, args...) |
| 55 | #endif |
| 56 | |
| 57 | #include <linux/module.h> |
| 58 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include <linux/kernel.h> |
| 60 | #include <linux/string.h> |
Randy.Dunlap | c59ede7 | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 61 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <linux/ctype.h> |
| 63 | #include <linux/sysfs.h> |
| 64 | #include <linux/kobject.h> |
| 65 | #include <linux/device.h> |
| 66 | #include <linux/errno.h> |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 67 | #include <linux/spinlock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #include <asm/pdc.h> |
| 70 | #include <asm/page.h> |
| 71 | #include <asm/uaccess.h> |
| 72 | #include <asm/hardware.h> |
| 73 | |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 74 | #define PDCS_VERSION "0.30" |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 75 | #define PDCS_PREFIX "PDC Stable Storage" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | #define PDCS_ADDR_PPRI 0x00 |
| 78 | #define PDCS_ADDR_OSID 0x40 |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 79 | #define PDCS_ADDR_OSD1 0x48 |
| 80 | #define PDCS_ADDR_DIAG 0x58 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #define PDCS_ADDR_FSIZ 0x5C |
| 82 | #define PDCS_ADDR_PCON 0x60 |
| 83 | #define PDCS_ADDR_PALT 0x80 |
| 84 | #define PDCS_ADDR_PKBD 0xA0 |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 85 | #define PDCS_ADDR_OSD2 0xE0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | MODULE_AUTHOR("Thibaut VARENE <varenet@parisc-linux.org>"); |
| 88 | MODULE_DESCRIPTION("sysfs interface to HP PDC Stable Storage data"); |
| 89 | MODULE_LICENSE("GPL"); |
| 90 | MODULE_VERSION(PDCS_VERSION); |
| 91 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 92 | /* holds Stable Storage size. Initialized once and for all, no lock needed */ |
Helge Deller | 8039de1 | 2006-01-10 20:35:03 -0500 | [diff] [blame] | 93 | static unsigned long pdcs_size __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 95 | /* holds OS ID. Initialized once and for all, hopefully to 0x0006 */ |
| 96 | static u16 pdcs_osid __read_mostly; |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* This struct defines what we need to deal with a parisc pdc path entry */ |
| 99 | struct pdcspath_entry { |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 100 | rwlock_t rw_lock; /* to protect path entry access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | short ready; /* entry record is valid if != 0 */ |
| 102 | unsigned long addr; /* entry address in stable storage */ |
| 103 | char *name; /* entry name */ |
| 104 | struct device_path devpath; /* device path in parisc representation */ |
| 105 | struct device *dev; /* corresponding device */ |
| 106 | struct kobject kobj; |
| 107 | }; |
| 108 | |
| 109 | struct pdcspath_attribute { |
| 110 | struct attribute attr; |
| 111 | ssize_t (*show)(struct pdcspath_entry *entry, char *buf); |
| 112 | ssize_t (*store)(struct pdcspath_entry *entry, const char *buf, size_t count); |
| 113 | }; |
| 114 | |
| 115 | #define PDCSPATH_ENTRY(_addr, _name) \ |
| 116 | struct pdcspath_entry pdcspath_entry_##_name = { \ |
| 117 | .ready = 0, \ |
| 118 | .addr = _addr, \ |
| 119 | .name = __stringify(_name), \ |
| 120 | }; |
| 121 | |
| 122 | #define PDCS_ATTR(_name, _mode, _show, _store) \ |
| 123 | struct subsys_attribute pdcs_attr_##_name = { \ |
| 124 | .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \ |
| 125 | .show = _show, \ |
| 126 | .store = _store, \ |
| 127 | }; |
| 128 | |
| 129 | #define PATHS_ATTR(_name, _mode, _show, _store) \ |
| 130 | struct pdcspath_attribute paths_attr_##_name = { \ |
| 131 | .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \ |
| 132 | .show = _show, \ |
| 133 | .store = _store, \ |
| 134 | }; |
| 135 | |
| 136 | #define to_pdcspath_attribute(_attr) container_of(_attr, struct pdcspath_attribute, attr) |
| 137 | #define to_pdcspath_entry(obj) container_of(obj, struct pdcspath_entry, kobj) |
| 138 | |
| 139 | /** |
| 140 | * pdcspath_fetch - This function populates the path entry structs. |
| 141 | * @entry: A pointer to an allocated pdcspath_entry. |
| 142 | * |
| 143 | * The general idea is that you don't read from the Stable Storage every time |
| 144 | * you access the files provided by the facilites. We store a copy of the |
| 145 | * content of the stable storage WRT various paths in these structs. We read |
| 146 | * these structs when reading the files, and we will write to these structs when |
| 147 | * writing to the files, and only then write them back to the Stable Storage. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 148 | * |
| 149 | * This function expects to be called with @entry->rw_lock write-hold. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | */ |
| 151 | static int |
| 152 | pdcspath_fetch(struct pdcspath_entry *entry) |
| 153 | { |
| 154 | struct device_path *devpath; |
| 155 | |
| 156 | if (!entry) |
| 157 | return -EINVAL; |
| 158 | |
| 159 | devpath = &entry->devpath; |
| 160 | |
| 161 | DPRINTK("%s: fetch: 0x%p, 0x%p, addr: 0x%lx\n", __func__, |
| 162 | entry, devpath, entry->addr); |
| 163 | |
| 164 | /* addr, devpath and count must be word aligned */ |
| 165 | if (pdc_stable_read(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) |
| 166 | return -EIO; |
| 167 | |
| 168 | /* Find the matching device. |
| 169 | NOTE: hardware_path overlays with device_path, so the nice cast can |
| 170 | be used */ |
| 171 | entry->dev = hwpath_to_device((struct hardware_path *)devpath); |
| 172 | |
| 173 | entry->ready = 1; |
| 174 | |
| 175 | DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * pdcspath_store - This function writes a path to stable storage. |
| 182 | * @entry: A pointer to an allocated pdcspath_entry. |
| 183 | * |
| 184 | * It can be used in two ways: either by passing it a preset devpath struct |
| 185 | * containing an already computed hardware path, or by passing it a device |
| 186 | * pointer, from which it'll find out the corresponding hardware path. |
| 187 | * For now we do not handle the case where there's an error in writing to the |
| 188 | * Stable Storage area, so you'd better not mess up the data :P |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 189 | * |
| 190 | * This function expects to be called with @entry->rw_lock write-hold. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 192 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | pdcspath_store(struct pdcspath_entry *entry) |
| 194 | { |
| 195 | struct device_path *devpath; |
| 196 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 197 | BUG_ON(!entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | devpath = &entry->devpath; |
| 200 | |
| 201 | /* We expect the caller to set the ready flag to 0 if the hardware |
| 202 | path struct provided is invalid, so that we know we have to fill it. |
| 203 | First case, we don't have a preset hwpath... */ |
| 204 | if (!entry->ready) { |
| 205 | /* ...but we have a device, map it */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 206 | BUG_ON(!entry->dev); |
| 207 | device_to_hwpath(entry->dev, (struct hardware_path *)devpath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | /* else, we expect the provided hwpath to be valid. */ |
| 210 | |
| 211 | DPRINTK("%s: store: 0x%p, 0x%p, addr: 0x%lx\n", __func__, |
| 212 | entry, devpath, entry->addr); |
| 213 | |
| 214 | /* addr, devpath and count must be word aligned */ |
| 215 | if (pdc_stable_write(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) { |
| 216 | printk(KERN_ERR "%s: an error occured when writing to PDC.\n" |
| 217 | "It is likely that the Stable Storage data has been corrupted.\n" |
| 218 | "Please check it carefully upon next reboot.\n", __func__); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 219 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 222 | /* kobject is already registered */ |
| 223 | entry->ready = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /** |
| 229 | * pdcspath_hwpath_read - This function handles hardware path pretty printing. |
| 230 | * @entry: An allocated and populated pdscpath_entry struct. |
| 231 | * @buf: The output buffer to write to. |
| 232 | * |
| 233 | * We will call this function to format the output of the hwpath attribute file. |
| 234 | */ |
| 235 | static ssize_t |
| 236 | pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf) |
| 237 | { |
| 238 | char *out = buf; |
| 239 | struct device_path *devpath; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 240 | short i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | if (!entry || !buf) |
| 243 | return -EINVAL; |
| 244 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 245 | read_lock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | devpath = &entry->devpath; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 247 | i = entry->ready; |
| 248 | read_unlock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 250 | if (!i) /* entry is not ready */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | return -ENODATA; |
| 252 | |
| 253 | for (i = 0; i < 6; i++) { |
| 254 | if (devpath->bc[i] >= 128) |
| 255 | continue; |
| 256 | out += sprintf(out, "%u/", (unsigned char)devpath->bc[i]); |
| 257 | } |
| 258 | out += sprintf(out, "%u\n", (unsigned char)devpath->mod); |
| 259 | |
| 260 | return out - buf; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * pdcspath_hwpath_write - This function handles hardware path modifying. |
| 265 | * @entry: An allocated and populated pdscpath_entry struct. |
| 266 | * @buf: The input buffer to read from. |
| 267 | * @count: The number of bytes to be read. |
| 268 | * |
| 269 | * We will call this function to change the current hardware path. |
| 270 | * Hardware paths are to be given '/'-delimited, without brackets. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 271 | * We make sure that the provided path actually maps to an existing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | * device, BUT nothing would prevent some foolish user to set the path to some |
| 273 | * PCI bridge or even a CPU... |
| 274 | * A better work around would be to make sure we are at the end of a device tree |
| 275 | * for instance, but it would be IMHO beyond the simple scope of that driver. |
| 276 | * The aim is to provide a facility. Data correctness is left to userland. |
| 277 | */ |
| 278 | static ssize_t |
| 279 | pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t count) |
| 280 | { |
| 281 | struct hardware_path hwpath; |
| 282 | unsigned short i; |
| 283 | char in[count+1], *temp; |
| 284 | struct device *dev; |
| 285 | |
| 286 | if (!entry || !buf || !count) |
| 287 | return -EINVAL; |
| 288 | |
| 289 | /* We'll use a local copy of buf */ |
| 290 | memset(in, 0, count+1); |
| 291 | strncpy(in, buf, count); |
| 292 | |
| 293 | /* Let's clean up the target. 0xff is a blank pattern */ |
| 294 | memset(&hwpath, 0xff, sizeof(hwpath)); |
| 295 | |
| 296 | /* First, pick the mod field (the last one of the input string) */ |
| 297 | if (!(temp = strrchr(in, '/'))) |
| 298 | return -EINVAL; |
| 299 | |
| 300 | hwpath.mod = simple_strtoul(temp+1, NULL, 10); |
| 301 | in[temp-in] = '\0'; /* truncate the remaining string. just precaution */ |
| 302 | DPRINTK("%s: mod: %d\n", __func__, hwpath.mod); |
| 303 | |
| 304 | /* Then, loop for each delimiter, making sure we don't have too many. |
| 305 | we write the bc fields in a down-top way. No matter what, we stop |
| 306 | before writing the last field. If there are too many fields anyway, |
| 307 | then the user is a moron and it'll be caught up later when we'll |
| 308 | check the consistency of the given hwpath. */ |
| 309 | for (i=5; ((temp = strrchr(in, '/'))) && (temp-in > 0) && (likely(i)); i--) { |
| 310 | hwpath.bc[i] = simple_strtoul(temp+1, NULL, 10); |
| 311 | in[temp-in] = '\0'; |
| 312 | DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]); |
| 313 | } |
| 314 | |
| 315 | /* Store the final field */ |
| 316 | hwpath.bc[i] = simple_strtoul(in, NULL, 10); |
| 317 | DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]); |
| 318 | |
| 319 | /* Now we check that the user isn't trying to lure us */ |
| 320 | if (!(dev = hwpath_to_device((struct hardware_path *)&hwpath))) { |
| 321 | printk(KERN_WARNING "%s: attempt to set invalid \"%s\" " |
| 322 | "hardware path: %s\n", __func__, entry->name, buf); |
| 323 | return -EINVAL; |
| 324 | } |
| 325 | |
| 326 | /* So far so good, let's get in deep */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 327 | write_lock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | entry->ready = 0; |
| 329 | entry->dev = dev; |
| 330 | |
| 331 | /* Now, dive in. Write back to the hardware */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 332 | pdcspath_store(entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
| 334 | /* Update the symlink to the real device */ |
| 335 | sysfs_remove_link(&entry->kobj, "device"); |
| 336 | sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 337 | write_unlock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 339 | printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" path to \"%s\"\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | entry->name, buf); |
| 341 | |
| 342 | return count; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing. |
| 347 | * @entry: An allocated and populated pdscpath_entry struct. |
| 348 | * @buf: The output buffer to write to. |
| 349 | * |
| 350 | * We will call this function to format the output of the layer attribute file. |
| 351 | */ |
| 352 | static ssize_t |
| 353 | pdcspath_layer_read(struct pdcspath_entry *entry, char *buf) |
| 354 | { |
| 355 | char *out = buf; |
| 356 | struct device_path *devpath; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 357 | short i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
| 359 | if (!entry || !buf) |
| 360 | return -EINVAL; |
| 361 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 362 | read_lock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | devpath = &entry->devpath; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 364 | i = entry->ready; |
| 365 | read_unlock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 367 | if (!i) /* entry is not ready */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | return -ENODATA; |
| 369 | |
| 370 | for (i = 0; devpath->layers[i] && (likely(i < 6)); i++) |
| 371 | out += sprintf(out, "%u ", devpath->layers[i]); |
| 372 | |
| 373 | out += sprintf(out, "\n"); |
| 374 | |
| 375 | return out - buf; |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * pdcspath_layer_write - This function handles extended layer modifying. |
| 380 | * @entry: An allocated and populated pdscpath_entry struct. |
| 381 | * @buf: The input buffer to read from. |
| 382 | * @count: The number of bytes to be read. |
| 383 | * |
| 384 | * We will call this function to change the current layer value. |
| 385 | * Layers are to be given '.'-delimited, without brackets. |
| 386 | * XXX beware we are far less checky WRT input data provided than for hwpath. |
| 387 | * Potential harm can be done, since there's no way to check the validity of |
| 388 | * the layer fields. |
| 389 | */ |
| 390 | static ssize_t |
| 391 | pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count) |
| 392 | { |
| 393 | unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */ |
| 394 | unsigned short i; |
| 395 | char in[count+1], *temp; |
| 396 | |
| 397 | if (!entry || !buf || !count) |
| 398 | return -EINVAL; |
| 399 | |
| 400 | /* We'll use a local copy of buf */ |
| 401 | memset(in, 0, count+1); |
| 402 | strncpy(in, buf, count); |
| 403 | |
| 404 | /* Let's clean up the target. 0 is a blank pattern */ |
| 405 | memset(&layers, 0, sizeof(layers)); |
| 406 | |
| 407 | /* First, pick the first layer */ |
| 408 | if (unlikely(!isdigit(*in))) |
| 409 | return -EINVAL; |
| 410 | layers[0] = simple_strtoul(in, NULL, 10); |
| 411 | DPRINTK("%s: layer[0]: %d\n", __func__, layers[0]); |
| 412 | |
| 413 | temp = in; |
| 414 | for (i=1; ((temp = strchr(temp, '.'))) && (likely(i<6)); i++) { |
| 415 | if (unlikely(!isdigit(*(++temp)))) |
| 416 | return -EINVAL; |
| 417 | layers[i] = simple_strtoul(temp, NULL, 10); |
| 418 | DPRINTK("%s: layer[%d]: %d\n", __func__, i, layers[i]); |
| 419 | } |
| 420 | |
| 421 | /* So far so good, let's get in deep */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 422 | write_lock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | /* First, overwrite the current layers with the new ones, not touching |
| 425 | the hardware path. */ |
| 426 | memcpy(&entry->devpath.layers, &layers, sizeof(layers)); |
| 427 | |
| 428 | /* Now, dive in. Write back to the hardware */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 429 | pdcspath_store(entry); |
| 430 | write_unlock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 432 | printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" layers to \"%s\"\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | entry->name, buf); |
| 434 | |
| 435 | return count; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * pdcspath_attr_show - Generic read function call wrapper. |
| 440 | * @kobj: The kobject to get info from. |
| 441 | * @attr: The attribute looked upon. |
| 442 | * @buf: The output buffer. |
| 443 | */ |
| 444 | static ssize_t |
| 445 | pdcspath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) |
| 446 | { |
| 447 | struct pdcspath_entry *entry = to_pdcspath_entry(kobj); |
| 448 | struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr); |
| 449 | ssize_t ret = 0; |
| 450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | if (pdcs_attr->show) |
| 452 | ret = pdcs_attr->show(entry, buf); |
| 453 | |
| 454 | return ret; |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * pdcspath_attr_store - Generic write function call wrapper. |
| 459 | * @kobj: The kobject to write info to. |
| 460 | * @attr: The attribute to be modified. |
| 461 | * @buf: The input buffer. |
| 462 | * @count: The size of the buffer. |
| 463 | */ |
| 464 | static ssize_t |
| 465 | pdcspath_attr_store(struct kobject *kobj, struct attribute *attr, |
| 466 | const char *buf, size_t count) |
| 467 | { |
| 468 | struct pdcspath_entry *entry = to_pdcspath_entry(kobj); |
| 469 | struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr); |
| 470 | ssize_t ret = 0; |
| 471 | |
| 472 | if (!capable(CAP_SYS_ADMIN)) |
| 473 | return -EACCES; |
| 474 | |
| 475 | if (pdcs_attr->store) |
| 476 | ret = pdcs_attr->store(entry, buf, count); |
| 477 | |
| 478 | return ret; |
| 479 | } |
| 480 | |
| 481 | static struct sysfs_ops pdcspath_attr_ops = { |
| 482 | .show = pdcspath_attr_show, |
| 483 | .store = pdcspath_attr_store, |
| 484 | }; |
| 485 | |
| 486 | /* These are the two attributes of any PDC path. */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 487 | static PATHS_ATTR(hwpath, 0644, pdcspath_hwpath_read, pdcspath_hwpath_write); |
| 488 | static PATHS_ATTR(layer, 0644, pdcspath_layer_read, pdcspath_layer_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | static struct attribute *paths_subsys_attrs[] = { |
| 491 | &paths_attr_hwpath.attr, |
| 492 | &paths_attr_layer.attr, |
| 493 | NULL, |
| 494 | }; |
| 495 | |
| 496 | /* Specific kobject type for our PDC paths */ |
| 497 | static struct kobj_type ktype_pdcspath = { |
| 498 | .sysfs_ops = &pdcspath_attr_ops, |
| 499 | .default_attrs = paths_subsys_attrs, |
| 500 | }; |
| 501 | |
| 502 | /* We hard define the 4 types of path we expect to find */ |
| 503 | static PDCSPATH_ENTRY(PDCS_ADDR_PPRI, primary); |
| 504 | static PDCSPATH_ENTRY(PDCS_ADDR_PCON, console); |
| 505 | static PDCSPATH_ENTRY(PDCS_ADDR_PALT, alternative); |
| 506 | static PDCSPATH_ENTRY(PDCS_ADDR_PKBD, keyboard); |
| 507 | |
| 508 | /* An array containing all PDC paths we will deal with */ |
| 509 | static struct pdcspath_entry *pdcspath_entries[] = { |
| 510 | &pdcspath_entry_primary, |
| 511 | &pdcspath_entry_alternative, |
| 512 | &pdcspath_entry_console, |
| 513 | &pdcspath_entry_keyboard, |
| 514 | NULL, |
| 515 | }; |
| 516 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 517 | |
| 518 | /* For more insight of what's going on here, refer to PDC Procedures doc, |
| 519 | * Section PDC_STABLE */ |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /** |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 522 | * pdcs_size_read - Stable Storage size output. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 523 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | * @buf: The output buffer to write to. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | */ |
| 526 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 527 | pdcs_size_read(struct kset *kset, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | char *out = buf; |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 530 | |
| 531 | if (!kset || !buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | return -EINVAL; |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | /* show the size of the stable storage */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 535 | out += sprintf(out, "%ld\n", pdcs_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 537 | return out - buf; |
| 538 | } |
| 539 | |
| 540 | /** |
| 541 | * pdcs_auto_read - Stable Storage autoboot/search flag output. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 542 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 543 | * @buf: The output buffer to write to. |
| 544 | * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag |
| 545 | */ |
| 546 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 547 | pdcs_auto_read(struct kset *kset, char *buf, int knob) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 548 | { |
| 549 | char *out = buf; |
| 550 | struct pdcspath_entry *pathentry; |
Helge Deller | 67a5a59 | 2006-03-27 19:52:14 +0000 | [diff] [blame] | 551 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 552 | if (!kset || !buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 553 | return -EINVAL; |
| 554 | |
| 555 | /* Current flags are stored in primary boot path entry */ |
| 556 | pathentry = &pdcspath_entry_primary; |
| 557 | |
| 558 | read_lock(&pathentry->rw_lock); |
| 559 | out += sprintf(out, "%s\n", (pathentry->devpath.flags & knob) ? |
| 560 | "On" : "Off"); |
| 561 | read_unlock(&pathentry->rw_lock); |
| 562 | |
| 563 | return out - buf; |
| 564 | } |
| 565 | |
| 566 | /** |
| 567 | * pdcs_autoboot_read - Stable Storage autoboot flag output. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 568 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 569 | * @buf: The output buffer to write to. |
| 570 | */ |
| 571 | static inline ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 572 | pdcs_autoboot_read(struct kset *kset, char *buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 573 | { |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 574 | return pdcs_auto_read(kset, buf, PF_AUTOBOOT); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /** |
| 578 | * pdcs_autosearch_read - Stable Storage autoboot flag output. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 579 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 580 | * @buf: The output buffer to write to. |
| 581 | */ |
| 582 | static inline ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 583 | pdcs_autosearch_read(struct kset *kset, char *buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 584 | { |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 585 | return pdcs_auto_read(kset, buf, PF_AUTOSEARCH); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /** |
| 589 | * pdcs_timer_read - Stable Storage timer count output (in seconds). |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 590 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 591 | * @buf: The output buffer to write to. |
| 592 | * |
| 593 | * The value of the timer field correponds to a number of seconds in powers of 2. |
| 594 | */ |
| 595 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 596 | pdcs_timer_read(struct kset *kset, char *buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 597 | { |
| 598 | char *out = buf; |
| 599 | struct pdcspath_entry *pathentry; |
| 600 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 601 | if (!kset || !buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 602 | return -EINVAL; |
| 603 | |
| 604 | /* Current flags are stored in primary boot path entry */ |
| 605 | pathentry = &pdcspath_entry_primary; |
| 606 | |
| 607 | /* print the timer value in seconds */ |
| 608 | read_lock(&pathentry->rw_lock); |
| 609 | out += sprintf(out, "%u\n", (pathentry->devpath.flags & PF_TIMER) ? |
| 610 | (1 << (pathentry->devpath.flags & PF_TIMER)) : 0); |
| 611 | read_unlock(&pathentry->rw_lock); |
| 612 | |
| 613 | return out - buf; |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * pdcs_osid_read - Stable Storage OS ID register output. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 618 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 619 | * @buf: The output buffer to write to. |
| 620 | */ |
| 621 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 622 | pdcs_osid_read(struct kset *kset, char *buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 623 | { |
| 624 | char *out = buf; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 625 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 626 | if (!kset || !buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 627 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
Kyle McMartin | 67a061a | 2006-06-25 16:58:57 +0000 | [diff] [blame] | 629 | out += sprintf(out, "%s dependent data (0x%.4x)\n", |
| 630 | os_id_to_string(pdcs_osid), pdcs_osid); |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 631 | |
| 632 | return out - buf; |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 637 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 638 | * @buf: The output buffer to write to. |
| 639 | * |
| 640 | * This can hold 16 bytes of OS-Dependent data. |
| 641 | */ |
| 642 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 643 | pdcs_osdep1_read(struct kset *kset, char *buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 644 | { |
| 645 | char *out = buf; |
| 646 | u32 result[4]; |
| 647 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 648 | if (!kset || !buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 649 | return -EINVAL; |
| 650 | |
| 651 | if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK) |
| 652 | return -EIO; |
| 653 | |
| 654 | out += sprintf(out, "0x%.8x\n", result[0]); |
| 655 | out += sprintf(out, "0x%.8x\n", result[1]); |
| 656 | out += sprintf(out, "0x%.8x\n", result[2]); |
| 657 | out += sprintf(out, "0x%.8x\n", result[3]); |
| 658 | |
| 659 | return out - buf; |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * pdcs_diagnostic_read - Stable Storage Diagnostic register output. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 664 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 665 | * @buf: The output buffer to write to. |
| 666 | * |
| 667 | * I have NFC how to interpret the content of that register ;-). |
| 668 | */ |
| 669 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 670 | pdcs_diagnostic_read(struct kset *kset, char *buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 671 | { |
| 672 | char *out = buf; |
| 673 | u32 result; |
| 674 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 675 | if (!kset || !buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 676 | return -EINVAL; |
| 677 | |
| 678 | /* get diagnostic */ |
| 679 | if (pdc_stable_read(PDCS_ADDR_DIAG, &result, sizeof(result)) != PDC_OK) |
| 680 | return -EIO; |
| 681 | |
| 682 | out += sprintf(out, "0x%.4x\n", (result >> 16)); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 683 | |
| 684 | return out - buf; |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * pdcs_fastsize_read - Stable Storage FastSize register output. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 689 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 690 | * @buf: The output buffer to write to. |
| 691 | * |
| 692 | * This register holds the amount of system RAM to be tested during boot sequence. |
| 693 | */ |
| 694 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 695 | pdcs_fastsize_read(struct kset *kset, char *buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 696 | { |
| 697 | char *out = buf; |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 698 | u32 result; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 699 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 700 | if (!kset || !buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 701 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
| 703 | /* get fast-size */ |
| 704 | if (pdc_stable_read(PDCS_ADDR_FSIZ, &result, sizeof(result)) != PDC_OK) |
| 705 | return -EIO; |
| 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | if ((result & 0x0F) < 0x0E) |
Randolph Chung | abff754 | 2005-10-21 22:57:13 -0400 | [diff] [blame] | 708 | out += sprintf(out, "%d kB", (1<<(result & 0x0F))*256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | else |
| 710 | out += sprintf(out, "All"); |
| 711 | out += sprintf(out, "\n"); |
| 712 | |
| 713 | return out - buf; |
| 714 | } |
| 715 | |
| 716 | /** |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 717 | * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 718 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 719 | * @buf: The output buffer to write to. |
| 720 | * |
| 721 | * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available. |
| 722 | */ |
| 723 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 724 | pdcs_osdep2_read(struct kset *kset, char *buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 725 | { |
| 726 | char *out = buf; |
| 727 | unsigned long size; |
| 728 | unsigned short i; |
| 729 | u32 result; |
| 730 | |
| 731 | if (unlikely(pdcs_size <= 224)) |
| 732 | return -ENODATA; |
| 733 | |
| 734 | size = pdcs_size - 224; |
| 735 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 736 | if (!kset || !buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 737 | return -EINVAL; |
| 738 | |
| 739 | for (i=0; i<size; i+=4) { |
| 740 | if (unlikely(pdc_stable_read(PDCS_ADDR_OSD2 + i, &result, |
| 741 | sizeof(result)) != PDC_OK)) |
| 742 | return -EIO; |
| 743 | out += sprintf(out, "0x%.8x\n", result); |
| 744 | } |
| 745 | |
| 746 | return out - buf; |
| 747 | } |
| 748 | |
| 749 | /** |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 750 | * pdcs_auto_write - This function handles autoboot/search flag modifying. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 751 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | * @buf: The input buffer to read from. |
| 753 | * @count: The number of bytes to be read. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 754 | * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | * |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 756 | * We will call this function to change the current autoboot flag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | * We expect a precise syntax: |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 758 | * \"n\" (n == 0 or 1) to toggle AutoBoot Off or On |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | */ |
| 760 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 761 | pdcs_auto_write(struct kset *kset, const char *buf, size_t count, int knob) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | { |
| 763 | struct pdcspath_entry *pathentry; |
| 764 | unsigned char flags; |
| 765 | char in[count+1], *temp; |
| 766 | char c; |
| 767 | |
| 768 | if (!capable(CAP_SYS_ADMIN)) |
| 769 | return -EACCES; |
| 770 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 771 | if (!kset || !buf || !count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | return -EINVAL; |
| 773 | |
| 774 | /* We'll use a local copy of buf */ |
| 775 | memset(in, 0, count+1); |
| 776 | strncpy(in, buf, count); |
| 777 | |
| 778 | /* Current flags are stored in primary boot path entry */ |
| 779 | pathentry = &pdcspath_entry_primary; |
| 780 | |
| 781 | /* Be nice to the existing flag record */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 782 | read_lock(&pathentry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | flags = pathentry->devpath.flags; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 784 | read_unlock(&pathentry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | DPRINTK("%s: flags before: 0x%X\n", __func__, flags); |
| 787 | |
| 788 | temp = in; |
| 789 | |
| 790 | while (*temp && isspace(*temp)) |
| 791 | temp++; |
| 792 | |
| 793 | c = *temp++ - '0'; |
| 794 | if ((c != 0) && (c != 1)) |
| 795 | goto parse_error; |
| 796 | if (c == 0) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 797 | flags &= ~knob; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | else |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 799 | flags |= knob; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
| 801 | DPRINTK("%s: flags after: 0x%X\n", __func__, flags); |
| 802 | |
| 803 | /* So far so good, let's get in deep */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 804 | write_lock(&pathentry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
| 806 | /* Change the path entry flags first */ |
| 807 | pathentry->devpath.flags = flags; |
| 808 | |
| 809 | /* Now, dive in. Write back to the hardware */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 810 | pdcspath_store(pathentry); |
| 811 | write_unlock(&pathentry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 813 | printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" to \"%s\"\n", |
| 814 | (knob & PF_AUTOBOOT) ? "autoboot" : "autosearch", |
| 815 | (flags & knob) ? "On" : "Off"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
| 817 | return count; |
| 818 | |
| 819 | parse_error: |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 820 | printk(KERN_WARNING "%s: Parse error: expect \"n\" (n == 0 or 1)\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | return -EINVAL; |
| 822 | } |
| 823 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 824 | /** |
| 825 | * pdcs_autoboot_write - This function handles autoboot flag modifying. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 826 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 827 | * @buf: The input buffer to read from. |
| 828 | * @count: The number of bytes to be read. |
| 829 | * |
| 830 | * We will call this function to change the current boot flags. |
| 831 | * We expect a precise syntax: |
| 832 | * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On |
| 833 | */ |
| 834 | static inline ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 835 | pdcs_autoboot_write(struct kset *kset, const char *buf, size_t count) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 836 | { |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 837 | return pdcs_auto_write(kset, buf, count, PF_AUTOBOOT); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | /** |
| 841 | * pdcs_autosearch_write - This function handles autosearch flag modifying. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 842 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 843 | * @buf: The input buffer to read from. |
| 844 | * @count: The number of bytes to be read. |
| 845 | * |
| 846 | * We will call this function to change the current boot flags. |
| 847 | * We expect a precise syntax: |
| 848 | * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On |
| 849 | */ |
| 850 | static inline ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 851 | pdcs_autosearch_write(struct kset *kset, const char *buf, size_t count) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 852 | { |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 853 | return pdcs_auto_write(kset, buf, count, PF_AUTOSEARCH); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 854 | } |
| 855 | |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 856 | /** |
| 857 | * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 858 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 859 | * @buf: The input buffer to read from. |
| 860 | * @count: The number of bytes to be read. |
| 861 | * |
| 862 | * This can store 16 bytes of OS-Dependent data. We use a byte-by-byte |
| 863 | * write approach. It's up to userspace to deal with it when constructing |
| 864 | * its input buffer. |
| 865 | */ |
| 866 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 867 | pdcs_osdep1_write(struct kset *kset, const char *buf, size_t count) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 868 | { |
| 869 | u8 in[16]; |
| 870 | |
| 871 | if (!capable(CAP_SYS_ADMIN)) |
| 872 | return -EACCES; |
| 873 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 874 | if (!kset || !buf || !count) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 875 | return -EINVAL; |
| 876 | |
Kyle McMartin | ec1fdc2 | 2006-06-21 19:27:29 +0000 | [diff] [blame] | 877 | if (unlikely(pdcs_osid != OS_ID_LINUX)) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 878 | return -EPERM; |
| 879 | |
| 880 | if (count > 16) |
| 881 | return -EMSGSIZE; |
| 882 | |
| 883 | /* We'll use a local copy of buf */ |
| 884 | memset(in, 0, 16); |
| 885 | memcpy(in, buf, count); |
| 886 | |
| 887 | if (pdc_stable_write(PDCS_ADDR_OSD1, &in, sizeof(in)) != PDC_OK) |
| 888 | return -EIO; |
| 889 | |
| 890 | return count; |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input. |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 895 | * @kset: An allocated and populated struct kset. We don't use it tho. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 896 | * @buf: The input buffer to read from. |
| 897 | * @count: The number of bytes to be read. |
| 898 | * |
| 899 | * This can store pdcs_size - 224 bytes of OS-Dependent data. We use a |
| 900 | * byte-by-byte write approach. It's up to userspace to deal with it when |
| 901 | * constructing its input buffer. |
| 902 | */ |
| 903 | static ssize_t |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 904 | pdcs_osdep2_write(struct kset *kset, const char *buf, size_t count) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 905 | { |
| 906 | unsigned long size; |
| 907 | unsigned short i; |
| 908 | u8 in[4]; |
| 909 | |
| 910 | if (!capable(CAP_SYS_ADMIN)) |
| 911 | return -EACCES; |
| 912 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 913 | if (!kset || !buf || !count) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 914 | return -EINVAL; |
| 915 | |
| 916 | if (unlikely(pdcs_size <= 224)) |
| 917 | return -ENOSYS; |
| 918 | |
Kyle McMartin | ec1fdc2 | 2006-06-21 19:27:29 +0000 | [diff] [blame] | 919 | if (unlikely(pdcs_osid != OS_ID_LINUX)) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 920 | return -EPERM; |
| 921 | |
| 922 | size = pdcs_size - 224; |
| 923 | |
| 924 | if (count > size) |
| 925 | return -EMSGSIZE; |
| 926 | |
| 927 | /* We'll use a local copy of buf */ |
| 928 | |
| 929 | for (i=0; i<count; i+=4) { |
| 930 | memset(in, 0, 4); |
| 931 | memcpy(in, buf+i, (count-i < 4) ? count-i : 4); |
| 932 | if (unlikely(pdc_stable_write(PDCS_ADDR_OSD2 + i, &in, |
| 933 | sizeof(in)) != PDC_OK)) |
| 934 | return -EIO; |
| 935 | } |
| 936 | |
| 937 | return count; |
| 938 | } |
| 939 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 940 | /* The remaining attributes. */ |
| 941 | static PDCS_ATTR(size, 0444, pdcs_size_read, NULL); |
| 942 | static PDCS_ATTR(autoboot, 0644, pdcs_autoboot_read, pdcs_autoboot_write); |
| 943 | static PDCS_ATTR(autosearch, 0644, pdcs_autosearch_read, pdcs_autosearch_write); |
| 944 | static PDCS_ATTR(timer, 0444, pdcs_timer_read, NULL); |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 945 | static PDCS_ATTR(osid, 0444, pdcs_osid_read, NULL); |
| 946 | static PDCS_ATTR(osdep1, 0600, pdcs_osdep1_read, pdcs_osdep1_write); |
| 947 | static PDCS_ATTR(diagnostic, 0400, pdcs_diagnostic_read, NULL); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 948 | static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL); |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 949 | static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
| 951 | static struct subsys_attribute *pdcs_subsys_attrs[] = { |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 952 | &pdcs_attr_size, |
| 953 | &pdcs_attr_autoboot, |
| 954 | &pdcs_attr_autosearch, |
| 955 | &pdcs_attr_timer, |
| 956 | &pdcs_attr_osid, |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 957 | &pdcs_attr_osdep1, |
| 958 | &pdcs_attr_diagnostic, |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 959 | &pdcs_attr_fastsize, |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 960 | &pdcs_attr_osdep2, |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 961 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | }; |
| 963 | |
| 964 | static decl_subsys(paths, &ktype_pdcspath, NULL); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 965 | static decl_subsys(stable, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
| 967 | /** |
| 968 | * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage. |
| 969 | * |
| 970 | * It creates kobjects corresponding to each path entry with nice sysfs |
| 971 | * links to the real device. This is where the magic takes place: when |
| 972 | * registering the subsystem attributes during module init, each kobject hereby |
| 973 | * created will show in the sysfs tree as a folder containing files as defined |
| 974 | * by path_subsys_attr[]. |
| 975 | */ |
| 976 | static inline int __init |
| 977 | pdcs_register_pathentries(void) |
| 978 | { |
| 979 | unsigned short i; |
| 980 | struct pdcspath_entry *entry; |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 981 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 983 | /* Initialize the entries rw_lock before anything else */ |
| 984 | for (i = 0; (entry = pdcspath_entries[i]); i++) |
| 985 | rwlock_init(&entry->rw_lock); |
| 986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | for (i = 0; (entry = pdcspath_entries[i]); i++) { |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 988 | write_lock(&entry->rw_lock); |
| 989 | err = pdcspath_fetch(entry); |
| 990 | write_unlock(&entry->rw_lock); |
| 991 | |
| 992 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | continue; |
| 994 | |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 995 | if ((err = kobject_set_name(&entry->kobj, "%s", entry->name))) |
| 996 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | kobj_set_kset_s(entry, paths_subsys); |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 998 | if ((err = kobject_register(&entry->kobj))) |
| 999 | return err; |
| 1000 | |
| 1001 | /* kobject is now registered */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1002 | write_lock(&entry->rw_lock); |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1003 | entry->ready = 2; |
| 1004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | /* Add a nice symlink to the real device */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1006 | if (entry->dev) |
| 1007 | sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); |
| 1008 | |
| 1009 | write_unlock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | /** |
| 1016 | * pdcs_unregister_pathentries - Routine called when unregistering the module. |
| 1017 | */ |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1018 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | pdcs_unregister_pathentries(void) |
| 1020 | { |
| 1021 | unsigned short i; |
| 1022 | struct pdcspath_entry *entry; |
| 1023 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1024 | for (i = 0; (entry = pdcspath_entries[i]); i++) { |
| 1025 | read_lock(&entry->rw_lock); |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1026 | if (entry->ready >= 2) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1027 | kobject_unregister(&entry->kobj); |
| 1028 | read_unlock(&entry->rw_lock); |
| 1029 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /* |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1033 | * For now we register the stable subsystem with the firmware subsystem |
| 1034 | * and the paths subsystem with the stable subsystem |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | */ |
| 1036 | static int __init |
| 1037 | pdc_stable_init(void) |
| 1038 | { |
| 1039 | struct subsys_attribute *attr; |
| 1040 | int i, rc = 0, error = 0; |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 1041 | u32 result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
| 1043 | /* find the size of the stable storage */ |
| 1044 | if (pdc_stable_get_size(&pdcs_size) != PDC_OK) |
| 1045 | return -ENODEV; |
| 1046 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1047 | /* make sure we have enough data */ |
| 1048 | if (pdcs_size < 96) |
| 1049 | return -ENODATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1051 | printk(KERN_INFO PDCS_PREFIX " facility v%s\n", PDCS_VERSION); |
| 1052 | |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 1053 | /* get OSID */ |
| 1054 | if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK) |
| 1055 | return -EIO; |
| 1056 | |
| 1057 | /* the actual result is 16 bits away */ |
| 1058 | pdcs_osid = (u16)(result >> 16); |
| 1059 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1060 | /* For now we'll register the stable subsys within this driver */ |
| 1061 | if ((rc = firmware_register(&stable_subsys))) |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1062 | goto fail_firmreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1064 | /* Don't forget the root entries */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | for (i = 0; (attr = pdcs_subsys_attrs[i]) && !error; i++) |
| 1066 | if (attr->show) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1067 | error = subsys_create_file(&stable_subsys, attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1069 | /* register the paths subsys as a subsystem of stable subsys */ |
| 1070 | kset_set_kset_s(&paths_subsys, stable_subsys); |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 1071 | if ((rc = subsystem_register(&paths_subsys))) |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1072 | goto fail_subsysreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
| 1074 | /* now we create all "files" for the paths subsys */ |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1075 | if ((rc = pdcs_register_pathentries())) |
| 1076 | goto fail_pdcsreg; |
| 1077 | |
| 1078 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1080 | fail_pdcsreg: |
| 1081 | pdcs_unregister_pathentries(); |
| 1082 | subsystem_unregister(&paths_subsys); |
| 1083 | |
| 1084 | fail_subsysreg: |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1085 | firmware_unregister(&stable_subsys); |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1086 | |
| 1087 | fail_firmreg: |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1088 | printk(KERN_INFO PDCS_PREFIX " bailing out\n"); |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1089 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | static void __exit |
| 1093 | pdc_stable_exit(void) |
| 1094 | { |
| 1095 | pdcs_unregister_pathentries(); |
| 1096 | subsystem_unregister(&paths_subsys); |
| 1097 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1098 | firmware_unregister(&stable_subsys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | |
| 1102 | module_init(pdc_stable_init); |
| 1103 | module_exit(pdc_stable_exit); |