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> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 71 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) \ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 123 | struct kobj_attribute pdcs_attr_##_name = { \ |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 124 | .attr = {.name = __stringify(_name), .mode = _mode}, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | .show = _show, \ |
| 126 | .store = _store, \ |
| 127 | }; |
| 128 | |
| 129 | #define PATHS_ATTR(_name, _mode, _show, _store) \ |
| 130 | struct pdcspath_attribute paths_attr_##_name = { \ |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 131 | .attr = {.name = __stringify(_name), .mode = _mode}, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 144 | * you access the files provided by the facilities. We store a copy of the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Julia Lawall | 93c3e91 | 2012-11-03 10:58:36 +0000 | [diff] [blame] | 215 | if (pdc_stable_write(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) |
| 216 | WARN(1, KERN_ERR "%s: an error occurred when writing to PDC.\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | "It is likely that the Stable Storage data has been corrupted.\n" |
| 218 | "Please check it carefully upon next reboot.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 220 | /* kobject is already registered */ |
| 221 | entry->ready = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /** |
| 227 | * pdcspath_hwpath_read - This function handles hardware path pretty printing. |
| 228 | * @entry: An allocated and populated pdscpath_entry struct. |
| 229 | * @buf: The output buffer to write to. |
| 230 | * |
| 231 | * We will call this function to format the output of the hwpath attribute file. |
| 232 | */ |
| 233 | static ssize_t |
| 234 | pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf) |
| 235 | { |
| 236 | char *out = buf; |
| 237 | struct device_path *devpath; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 238 | short i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | if (!entry || !buf) |
| 241 | return -EINVAL; |
| 242 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 243 | read_lock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | devpath = &entry->devpath; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 245 | i = entry->ready; |
| 246 | read_unlock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 248 | if (!i) /* entry is not ready */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return -ENODATA; |
| 250 | |
| 251 | for (i = 0; i < 6; i++) { |
| 252 | if (devpath->bc[i] >= 128) |
| 253 | continue; |
| 254 | out += sprintf(out, "%u/", (unsigned char)devpath->bc[i]); |
| 255 | } |
| 256 | out += sprintf(out, "%u\n", (unsigned char)devpath->mod); |
| 257 | |
| 258 | return out - buf; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * pdcspath_hwpath_write - This function handles hardware path modifying. |
| 263 | * @entry: An allocated and populated pdscpath_entry struct. |
| 264 | * @buf: The input buffer to read from. |
| 265 | * @count: The number of bytes to be read. |
| 266 | * |
| 267 | * We will call this function to change the current hardware path. |
| 268 | * Hardware paths are to be given '/'-delimited, without brackets. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 269 | * We make sure that the provided path actually maps to an existing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | * device, BUT nothing would prevent some foolish user to set the path to some |
| 271 | * PCI bridge or even a CPU... |
| 272 | * A better work around would be to make sure we are at the end of a device tree |
| 273 | * for instance, but it would be IMHO beyond the simple scope of that driver. |
| 274 | * The aim is to provide a facility. Data correctness is left to userland. |
| 275 | */ |
| 276 | static ssize_t |
| 277 | pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t count) |
| 278 | { |
| 279 | struct hardware_path hwpath; |
| 280 | unsigned short i; |
Helge Deller | c735483 | 2014-09-21 22:31:08 +0200 | [diff] [blame] | 281 | char in[64], *temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | struct device *dev; |
Kyle McMartin | 26f0324 | 2007-10-18 00:04:06 -0700 | [diff] [blame] | 283 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | if (!entry || !buf || !count) |
| 286 | return -EINVAL; |
| 287 | |
| 288 | /* We'll use a local copy of buf */ |
Helge Deller | c735483 | 2014-09-21 22:31:08 +0200 | [diff] [blame] | 289 | count = min_t(size_t, count, sizeof(in)-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | strncpy(in, buf, count); |
Helge Deller | c735483 | 2014-09-21 22:31:08 +0200 | [diff] [blame] | 291 | in[count] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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"); |
Kyle McMartin | 26f0324 | 2007-10-18 00:04:06 -0700 | [diff] [blame] | 336 | ret = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); |
| 337 | WARN_ON(ret); |
| 338 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 339 | write_unlock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 341 | printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" path to \"%s\"\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | entry->name, buf); |
| 343 | |
| 344 | return count; |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing. |
| 349 | * @entry: An allocated and populated pdscpath_entry struct. |
| 350 | * @buf: The output buffer to write to. |
| 351 | * |
| 352 | * We will call this function to format the output of the layer attribute file. |
| 353 | */ |
| 354 | static ssize_t |
| 355 | pdcspath_layer_read(struct pdcspath_entry *entry, char *buf) |
| 356 | { |
| 357 | char *out = buf; |
| 358 | struct device_path *devpath; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 359 | short i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | if (!entry || !buf) |
| 362 | return -EINVAL; |
| 363 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 364 | read_lock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | devpath = &entry->devpath; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 366 | i = entry->ready; |
| 367 | read_unlock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 369 | if (!i) /* entry is not ready */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | return -ENODATA; |
| 371 | |
Roel Kluin | 447c233 | 2009-08-02 08:02:28 +0000 | [diff] [blame] | 372 | for (i = 0; i < 6 && devpath->layers[i]; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | out += sprintf(out, "%u ", devpath->layers[i]); |
| 374 | |
| 375 | out += sprintf(out, "\n"); |
| 376 | |
| 377 | return out - buf; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * pdcspath_layer_write - This function handles extended layer modifying. |
| 382 | * @entry: An allocated and populated pdscpath_entry struct. |
| 383 | * @buf: The input buffer to read from. |
| 384 | * @count: The number of bytes to be read. |
| 385 | * |
| 386 | * We will call this function to change the current layer value. |
| 387 | * Layers are to be given '.'-delimited, without brackets. |
| 388 | * XXX beware we are far less checky WRT input data provided than for hwpath. |
| 389 | * Potential harm can be done, since there's no way to check the validity of |
| 390 | * the layer fields. |
| 391 | */ |
| 392 | static ssize_t |
| 393 | pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count) |
| 394 | { |
| 395 | unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */ |
| 396 | unsigned short i; |
Helge Deller | c735483 | 2014-09-21 22:31:08 +0200 | [diff] [blame] | 397 | char in[64], *temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | if (!entry || !buf || !count) |
| 400 | return -EINVAL; |
| 401 | |
| 402 | /* We'll use a local copy of buf */ |
Helge Deller | c735483 | 2014-09-21 22:31:08 +0200 | [diff] [blame] | 403 | count = min_t(size_t, count, sizeof(in)-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | strncpy(in, buf, count); |
Helge Deller | c735483 | 2014-09-21 22:31:08 +0200 | [diff] [blame] | 405 | in[count] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | /* Let's clean up the target. 0 is a blank pattern */ |
| 408 | memset(&layers, 0, sizeof(layers)); |
| 409 | |
| 410 | /* First, pick the first layer */ |
| 411 | if (unlikely(!isdigit(*in))) |
| 412 | return -EINVAL; |
| 413 | layers[0] = simple_strtoul(in, NULL, 10); |
| 414 | DPRINTK("%s: layer[0]: %d\n", __func__, layers[0]); |
| 415 | |
| 416 | temp = in; |
| 417 | for (i=1; ((temp = strchr(temp, '.'))) && (likely(i<6)); i++) { |
| 418 | if (unlikely(!isdigit(*(++temp)))) |
| 419 | return -EINVAL; |
| 420 | layers[i] = simple_strtoul(temp, NULL, 10); |
| 421 | DPRINTK("%s: layer[%d]: %d\n", __func__, i, layers[i]); |
| 422 | } |
| 423 | |
| 424 | /* So far so good, let's get in deep */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 425 | write_lock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | /* First, overwrite the current layers with the new ones, not touching |
| 428 | the hardware path. */ |
| 429 | memcpy(&entry->devpath.layers, &layers, sizeof(layers)); |
| 430 | |
| 431 | /* Now, dive in. Write back to the hardware */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 432 | pdcspath_store(entry); |
| 433 | write_unlock(&entry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 435 | printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" layers to \"%s\"\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | entry->name, buf); |
| 437 | |
| 438 | return count; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * pdcspath_attr_show - Generic read function call wrapper. |
| 443 | * @kobj: The kobject to get info from. |
| 444 | * @attr: The attribute looked upon. |
| 445 | * @buf: The output buffer. |
| 446 | */ |
| 447 | static ssize_t |
| 448 | pdcspath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) |
| 449 | { |
| 450 | struct pdcspath_entry *entry = to_pdcspath_entry(kobj); |
| 451 | struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr); |
| 452 | ssize_t ret = 0; |
| 453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | if (pdcs_attr->show) |
| 455 | ret = pdcs_attr->show(entry, buf); |
| 456 | |
| 457 | return ret; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * pdcspath_attr_store - Generic write function call wrapper. |
| 462 | * @kobj: The kobject to write info to. |
| 463 | * @attr: The attribute to be modified. |
| 464 | * @buf: The input buffer. |
| 465 | * @count: The size of the buffer. |
| 466 | */ |
| 467 | static ssize_t |
| 468 | pdcspath_attr_store(struct kobject *kobj, struct attribute *attr, |
| 469 | const char *buf, size_t count) |
| 470 | { |
| 471 | struct pdcspath_entry *entry = to_pdcspath_entry(kobj); |
| 472 | struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr); |
| 473 | ssize_t ret = 0; |
| 474 | |
| 475 | if (!capable(CAP_SYS_ADMIN)) |
| 476 | return -EACCES; |
| 477 | |
| 478 | if (pdcs_attr->store) |
| 479 | ret = pdcs_attr->store(entry, buf, count); |
| 480 | |
| 481 | return ret; |
| 482 | } |
| 483 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 484 | static const struct sysfs_ops pdcspath_attr_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | .show = pdcspath_attr_show, |
| 486 | .store = pdcspath_attr_store, |
| 487 | }; |
| 488 | |
| 489 | /* These are the two attributes of any PDC path. */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 490 | static PATHS_ATTR(hwpath, 0644, pdcspath_hwpath_read, pdcspath_hwpath_write); |
| 491 | static PATHS_ATTR(layer, 0644, pdcspath_layer_read, pdcspath_layer_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | static struct attribute *paths_subsys_attrs[] = { |
| 494 | &paths_attr_hwpath.attr, |
| 495 | &paths_attr_layer.attr, |
| 496 | NULL, |
| 497 | }; |
| 498 | |
| 499 | /* Specific kobject type for our PDC paths */ |
| 500 | static struct kobj_type ktype_pdcspath = { |
| 501 | .sysfs_ops = &pdcspath_attr_ops, |
| 502 | .default_attrs = paths_subsys_attrs, |
| 503 | }; |
| 504 | |
| 505 | /* We hard define the 4 types of path we expect to find */ |
| 506 | static PDCSPATH_ENTRY(PDCS_ADDR_PPRI, primary); |
| 507 | static PDCSPATH_ENTRY(PDCS_ADDR_PCON, console); |
| 508 | static PDCSPATH_ENTRY(PDCS_ADDR_PALT, alternative); |
| 509 | static PDCSPATH_ENTRY(PDCS_ADDR_PKBD, keyboard); |
| 510 | |
| 511 | /* An array containing all PDC paths we will deal with */ |
| 512 | static struct pdcspath_entry *pdcspath_entries[] = { |
| 513 | &pdcspath_entry_primary, |
| 514 | &pdcspath_entry_alternative, |
| 515 | &pdcspath_entry_console, |
| 516 | &pdcspath_entry_keyboard, |
| 517 | NULL, |
| 518 | }; |
| 519 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 520 | |
| 521 | /* For more insight of what's going on here, refer to PDC Procedures doc, |
| 522 | * Section PDC_STABLE */ |
| 523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | /** |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 525 | * pdcs_size_read - Stable Storage size output. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | * @buf: The output buffer to write to. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 528 | static ssize_t pdcs_size_read(struct kobject *kobj, |
| 529 | struct kobj_attribute *attr, |
| 530 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
| 532 | char *out = buf; |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 533 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 534 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | return -EINVAL; |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* show the size of the stable storage */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 538 | out += sprintf(out, "%ld\n", pdcs_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 540 | return out - buf; |
| 541 | } |
| 542 | |
| 543 | /** |
| 544 | * pdcs_auto_read - Stable Storage autoboot/search flag output. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 545 | * @buf: The output buffer to write to. |
| 546 | * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag |
| 547 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 548 | static ssize_t pdcs_auto_read(struct kobject *kobj, |
| 549 | struct kobj_attribute *attr, |
| 550 | char *buf, int knob) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 551 | { |
| 552 | char *out = buf; |
| 553 | struct pdcspath_entry *pathentry; |
Helge Deller | 67a5a59 | 2006-03-27 19:52:14 +0000 | [diff] [blame] | 554 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 555 | if (!buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 556 | return -EINVAL; |
| 557 | |
| 558 | /* Current flags are stored in primary boot path entry */ |
| 559 | pathentry = &pdcspath_entry_primary; |
| 560 | |
| 561 | read_lock(&pathentry->rw_lock); |
| 562 | out += sprintf(out, "%s\n", (pathentry->devpath.flags & knob) ? |
| 563 | "On" : "Off"); |
| 564 | read_unlock(&pathentry->rw_lock); |
| 565 | |
| 566 | return out - buf; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * pdcs_autoboot_read - Stable Storage autoboot flag output. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 571 | * @buf: The output buffer to write to. |
| 572 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 573 | static ssize_t pdcs_autoboot_read(struct kobject *kobj, |
| 574 | struct kobj_attribute *attr, char *buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 575 | { |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 576 | return pdcs_auto_read(kobj, attr, buf, PF_AUTOBOOT); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /** |
| 580 | * pdcs_autosearch_read - Stable Storage autoboot flag output. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 581 | * @buf: The output buffer to write to. |
| 582 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 583 | static ssize_t pdcs_autosearch_read(struct kobject *kobj, |
| 584 | struct kobj_attribute *attr, char *buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 585 | { |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 586 | return pdcs_auto_read(kobj, attr, buf, PF_AUTOSEARCH); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | /** |
| 590 | * pdcs_timer_read - Stable Storage timer count output (in seconds). |
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 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 595 | static ssize_t pdcs_timer_read(struct kobject *kobj, |
| 596 | struct kobj_attribute *attr, 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 | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 601 | if (!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. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 618 | * @buf: The output buffer to write to. |
| 619 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 620 | static ssize_t pdcs_osid_read(struct kobject *kobj, |
| 621 | struct kobj_attribute *attr, char *buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 622 | { |
| 623 | char *out = buf; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 624 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 625 | if (!buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 626 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Kyle McMartin | 67a061a | 2006-06-25 16:58:57 +0000 | [diff] [blame] | 628 | out += sprintf(out, "%s dependent data (0x%.4x)\n", |
| 629 | os_id_to_string(pdcs_osid), pdcs_osid); |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 630 | |
| 631 | return out - buf; |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 636 | * @buf: The output buffer to write to. |
| 637 | * |
| 638 | * This can hold 16 bytes of OS-Dependent data. |
| 639 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 640 | static ssize_t pdcs_osdep1_read(struct kobject *kobj, |
| 641 | struct kobj_attribute *attr, char *buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 642 | { |
| 643 | char *out = buf; |
| 644 | u32 result[4]; |
| 645 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 646 | if (!buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 647 | return -EINVAL; |
| 648 | |
| 649 | if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK) |
| 650 | return -EIO; |
| 651 | |
| 652 | out += sprintf(out, "0x%.8x\n", result[0]); |
| 653 | out += sprintf(out, "0x%.8x\n", result[1]); |
| 654 | out += sprintf(out, "0x%.8x\n", result[2]); |
| 655 | out += sprintf(out, "0x%.8x\n", result[3]); |
| 656 | |
| 657 | return out - buf; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * pdcs_diagnostic_read - Stable Storage Diagnostic register output. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 662 | * @buf: The output buffer to write to. |
| 663 | * |
| 664 | * I have NFC how to interpret the content of that register ;-). |
| 665 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 666 | static ssize_t pdcs_diagnostic_read(struct kobject *kobj, |
| 667 | struct kobj_attribute *attr, char *buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 668 | { |
| 669 | char *out = buf; |
| 670 | u32 result; |
| 671 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 672 | if (!buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 673 | return -EINVAL; |
| 674 | |
| 675 | /* get diagnostic */ |
| 676 | if (pdc_stable_read(PDCS_ADDR_DIAG, &result, sizeof(result)) != PDC_OK) |
| 677 | return -EIO; |
| 678 | |
| 679 | out += sprintf(out, "0x%.4x\n", (result >> 16)); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 680 | |
| 681 | return out - buf; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * pdcs_fastsize_read - Stable Storage FastSize register output. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 686 | * @buf: The output buffer to write to. |
| 687 | * |
| 688 | * This register holds the amount of system RAM to be tested during boot sequence. |
| 689 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 690 | static ssize_t pdcs_fastsize_read(struct kobject *kobj, |
| 691 | struct kobj_attribute *attr, char *buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 692 | { |
| 693 | char *out = buf; |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 694 | u32 result; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 695 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 696 | if (!buf) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 697 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
| 699 | /* get fast-size */ |
| 700 | if (pdc_stable_read(PDCS_ADDR_FSIZ, &result, sizeof(result)) != PDC_OK) |
| 701 | return -EIO; |
| 702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | if ((result & 0x0F) < 0x0E) |
Randolph Chung | abff754 | 2005-10-21 22:57:13 -0400 | [diff] [blame] | 704 | out += sprintf(out, "%d kB", (1<<(result & 0x0F))*256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | else |
| 706 | out += sprintf(out, "All"); |
| 707 | out += sprintf(out, "\n"); |
| 708 | |
| 709 | return out - buf; |
| 710 | } |
| 711 | |
| 712 | /** |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 713 | * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 714 | * @buf: The output buffer to write to. |
| 715 | * |
| 716 | * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available. |
| 717 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 718 | static ssize_t pdcs_osdep2_read(struct kobject *kobj, |
| 719 | struct kobj_attribute *attr, char *buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 720 | { |
| 721 | char *out = buf; |
| 722 | unsigned long size; |
| 723 | unsigned short i; |
| 724 | u32 result; |
| 725 | |
| 726 | if (unlikely(pdcs_size <= 224)) |
| 727 | return -ENODATA; |
| 728 | |
| 729 | size = pdcs_size - 224; |
| 730 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 731 | if (!buf) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 732 | return -EINVAL; |
| 733 | |
| 734 | for (i=0; i<size; i+=4) { |
| 735 | if (unlikely(pdc_stable_read(PDCS_ADDR_OSD2 + i, &result, |
| 736 | sizeof(result)) != PDC_OK)) |
| 737 | return -EIO; |
| 738 | out += sprintf(out, "0x%.8x\n", result); |
| 739 | } |
| 740 | |
| 741 | return out - buf; |
| 742 | } |
| 743 | |
| 744 | /** |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 745 | * pdcs_auto_write - This function handles autoboot/search flag modifying. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | * @buf: The input buffer to read from. |
| 747 | * @count: The number of bytes to be read. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 748 | * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | * |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 750 | * We will call this function to change the current autoboot flag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | * We expect a precise syntax: |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 752 | * \"n\" (n == 0 or 1) to toggle AutoBoot Off or On |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 754 | static ssize_t pdcs_auto_write(struct kobject *kobj, |
| 755 | struct kobj_attribute *attr, const char *buf, |
| 756 | size_t count, int knob) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | { |
| 758 | struct pdcspath_entry *pathentry; |
| 759 | unsigned char flags; |
Rickard Strandqvist | 94c457d | 2014-09-14 18:02:12 +0200 | [diff] [blame] | 760 | char in[8], *temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | char c; |
| 762 | |
| 763 | if (!capable(CAP_SYS_ADMIN)) |
| 764 | return -EACCES; |
| 765 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 766 | if (!buf || !count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | return -EINVAL; |
| 768 | |
| 769 | /* We'll use a local copy of buf */ |
Helge Deller | c735483 | 2014-09-21 22:31:08 +0200 | [diff] [blame] | 770 | count = min_t(size_t, count, sizeof(in)-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | strncpy(in, buf, count); |
Rickard Strandqvist | 94c457d | 2014-09-14 18:02:12 +0200 | [diff] [blame] | 772 | in[count] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | /* Current flags are stored in primary boot path entry */ |
| 775 | pathentry = &pdcspath_entry_primary; |
| 776 | |
| 777 | /* Be nice to the existing flag record */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 778 | read_lock(&pathentry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | flags = pathentry->devpath.flags; |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 780 | read_unlock(&pathentry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| 782 | DPRINTK("%s: flags before: 0x%X\n", __func__, flags); |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 783 | |
| 784 | temp = skip_spaces(in); |
| 785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | c = *temp++ - '0'; |
| 787 | if ((c != 0) && (c != 1)) |
| 788 | goto parse_error; |
| 789 | if (c == 0) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 790 | flags &= ~knob; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | else |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 792 | flags |= knob; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
| 794 | DPRINTK("%s: flags after: 0x%X\n", __func__, flags); |
| 795 | |
| 796 | /* So far so good, let's get in deep */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 797 | write_lock(&pathentry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | /* Change the path entry flags first */ |
| 800 | pathentry->devpath.flags = flags; |
| 801 | |
| 802 | /* Now, dive in. Write back to the hardware */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 803 | pdcspath_store(pathentry); |
| 804 | write_unlock(&pathentry->rw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 806 | printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" to \"%s\"\n", |
| 807 | (knob & PF_AUTOBOOT) ? "autoboot" : "autosearch", |
| 808 | (flags & knob) ? "On" : "Off"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
| 810 | return count; |
| 811 | |
| 812 | parse_error: |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 813 | 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] | 814 | return -EINVAL; |
| 815 | } |
| 816 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 817 | /** |
| 818 | * pdcs_autoboot_write - This function handles autoboot flag modifying. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 819 | * @buf: The input buffer to read from. |
| 820 | * @count: The number of bytes to be read. |
| 821 | * |
| 822 | * We will call this function to change the current boot flags. |
| 823 | * We expect a precise syntax: |
| 824 | * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On |
| 825 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 826 | static ssize_t pdcs_autoboot_write(struct kobject *kobj, |
| 827 | struct kobj_attribute *attr, |
| 828 | const char *buf, size_t count) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 829 | { |
Joel Soete | ff451d7 | 2008-02-18 18:26:11 -0800 | [diff] [blame] | 830 | return pdcs_auto_write(kobj, attr, buf, count, PF_AUTOBOOT); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /** |
| 834 | * pdcs_autosearch_write - This function handles autosearch flag modifying. |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 835 | * @buf: The input buffer to read from. |
| 836 | * @count: The number of bytes to be read. |
| 837 | * |
| 838 | * We will call this function to change the current boot flags. |
| 839 | * We expect a precise syntax: |
| 840 | * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On |
| 841 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 842 | static ssize_t pdcs_autosearch_write(struct kobject *kobj, |
| 843 | struct kobj_attribute *attr, |
| 844 | const char *buf, size_t count) |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 845 | { |
Joel Soete | ff451d7 | 2008-02-18 18:26:11 -0800 | [diff] [blame] | 846 | return pdcs_auto_write(kobj, attr, buf, count, PF_AUTOSEARCH); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 849 | /** |
| 850 | * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 851 | * @buf: The input buffer to read from. |
| 852 | * @count: The number of bytes to be read. |
| 853 | * |
| 854 | * This can store 16 bytes of OS-Dependent data. We use a byte-by-byte |
| 855 | * write approach. It's up to userspace to deal with it when constructing |
| 856 | * its input buffer. |
| 857 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 858 | static ssize_t pdcs_osdep1_write(struct kobject *kobj, |
| 859 | struct kobj_attribute *attr, |
| 860 | const char *buf, size_t count) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 861 | { |
| 862 | u8 in[16]; |
| 863 | |
| 864 | if (!capable(CAP_SYS_ADMIN)) |
| 865 | return -EACCES; |
| 866 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 867 | if (!buf || !count) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 868 | return -EINVAL; |
| 869 | |
Kyle McMartin | ec1fdc2 | 2006-06-21 19:27:29 +0000 | [diff] [blame] | 870 | if (unlikely(pdcs_osid != OS_ID_LINUX)) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 871 | return -EPERM; |
| 872 | |
| 873 | if (count > 16) |
| 874 | return -EMSGSIZE; |
| 875 | |
| 876 | /* We'll use a local copy of buf */ |
| 877 | memset(in, 0, 16); |
| 878 | memcpy(in, buf, count); |
| 879 | |
| 880 | if (pdc_stable_write(PDCS_ADDR_OSD1, &in, sizeof(in)) != PDC_OK) |
| 881 | return -EIO; |
| 882 | |
| 883 | return count; |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input. |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 888 | * @buf: The input buffer to read from. |
| 889 | * @count: The number of bytes to be read. |
| 890 | * |
| 891 | * This can store pdcs_size - 224 bytes of OS-Dependent data. We use a |
| 892 | * byte-by-byte write approach. It's up to userspace to deal with it when |
| 893 | * constructing its input buffer. |
| 894 | */ |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 895 | static ssize_t pdcs_osdep2_write(struct kobject *kobj, |
| 896 | struct kobj_attribute *attr, |
| 897 | const char *buf, size_t count) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 898 | { |
| 899 | unsigned long size; |
| 900 | unsigned short i; |
| 901 | u8 in[4]; |
| 902 | |
| 903 | if (!capable(CAP_SYS_ADMIN)) |
| 904 | return -EACCES; |
| 905 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 906 | if (!buf || !count) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 907 | return -EINVAL; |
| 908 | |
| 909 | if (unlikely(pdcs_size <= 224)) |
| 910 | return -ENOSYS; |
| 911 | |
Kyle McMartin | ec1fdc2 | 2006-06-21 19:27:29 +0000 | [diff] [blame] | 912 | if (unlikely(pdcs_osid != OS_ID_LINUX)) |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 913 | return -EPERM; |
| 914 | |
| 915 | size = pdcs_size - 224; |
| 916 | |
| 917 | if (count > size) |
| 918 | return -EMSGSIZE; |
| 919 | |
| 920 | /* We'll use a local copy of buf */ |
| 921 | |
| 922 | for (i=0; i<count; i+=4) { |
| 923 | memset(in, 0, 4); |
| 924 | memcpy(in, buf+i, (count-i < 4) ? count-i : 4); |
| 925 | if (unlikely(pdc_stable_write(PDCS_ADDR_OSD2 + i, &in, |
| 926 | sizeof(in)) != PDC_OK)) |
| 927 | return -EIO; |
| 928 | } |
| 929 | |
| 930 | return count; |
| 931 | } |
| 932 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 933 | /* The remaining attributes. */ |
| 934 | static PDCS_ATTR(size, 0444, pdcs_size_read, NULL); |
| 935 | static PDCS_ATTR(autoboot, 0644, pdcs_autoboot_read, pdcs_autoboot_write); |
| 936 | static PDCS_ATTR(autosearch, 0644, pdcs_autosearch_read, pdcs_autosearch_write); |
| 937 | static PDCS_ATTR(timer, 0444, pdcs_timer_read, NULL); |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 938 | static PDCS_ATTR(osid, 0444, pdcs_osid_read, NULL); |
| 939 | static PDCS_ATTR(osdep1, 0600, pdcs_osdep1_read, pdcs_osdep1_write); |
| 940 | static PDCS_ATTR(diagnostic, 0400, pdcs_diagnostic_read, NULL); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 941 | static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL); |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 942 | static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 944 | static struct attribute *pdcs_subsys_attrs[] = { |
| 945 | &pdcs_attr_size.attr, |
| 946 | &pdcs_attr_autoboot.attr, |
| 947 | &pdcs_attr_autosearch.attr, |
| 948 | &pdcs_attr_timer.attr, |
| 949 | &pdcs_attr_osid.attr, |
| 950 | &pdcs_attr_osdep1.attr, |
| 951 | &pdcs_attr_diagnostic.attr, |
| 952 | &pdcs_attr_fastsize.attr, |
| 953 | &pdcs_attr_osdep2.attr, |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 954 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | }; |
| 956 | |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 957 | static struct attribute_group pdcs_attr_group = { |
| 958 | .attrs = pdcs_subsys_attrs, |
| 959 | }; |
| 960 | |
Greg Kroah-Hartman | c829a5b4 | 2007-11-07 13:56:19 -0800 | [diff] [blame] | 961 | static struct kobject *stable_kobj; |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 962 | static struct kset *paths_kset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
| 964 | /** |
| 965 | * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage. |
| 966 | * |
| 967 | * It creates kobjects corresponding to each path entry with nice sysfs |
| 968 | * links to the real device. This is where the magic takes place: when |
| 969 | * registering the subsystem attributes during module init, each kobject hereby |
| 970 | * created will show in the sysfs tree as a folder containing files as defined |
| 971 | * by path_subsys_attr[]. |
| 972 | */ |
| 973 | static inline int __init |
| 974 | pdcs_register_pathentries(void) |
| 975 | { |
| 976 | unsigned short i; |
| 977 | struct pdcspath_entry *entry; |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 978 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 980 | /* Initialize the entries rw_lock before anything else */ |
| 981 | for (i = 0; (entry = pdcspath_entries[i]); i++) |
| 982 | rwlock_init(&entry->rw_lock); |
| 983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | for (i = 0; (entry = pdcspath_entries[i]); i++) { |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 985 | write_lock(&entry->rw_lock); |
| 986 | err = pdcspath_fetch(entry); |
| 987 | write_unlock(&entry->rw_lock); |
| 988 | |
| 989 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | continue; |
| 991 | |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 992 | entry->kobj.kset = paths_kset; |
Greg Kroah-Hartman | 73f368c | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 993 | err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL, |
| 994 | "%s", entry->name); |
| 995 | if (err) |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 996 | return err; |
Greg Kroah-Hartman | 73f368c | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 997 | |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 998 | /* kobject is now registered */ |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 999 | write_lock(&entry->rw_lock); |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1000 | entry->ready = 2; |
| 1001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | /* Add a nice symlink to the real device */ |
Kyle McMartin | 26f0324 | 2007-10-18 00:04:06 -0700 | [diff] [blame] | 1003 | if (entry->dev) { |
| 1004 | err = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); |
| 1005 | WARN_ON(err); |
| 1006 | } |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1007 | |
| 1008 | write_unlock(&entry->rw_lock); |
Greg Kroah-Hartman | 73f368c | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 1009 | kobject_uevent(&entry->kobj, KOBJ_ADD); |
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) |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 1027 | kobject_put(&entry->kobj); |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 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 | { |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1039 | int rc = 0, error = 0; |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 1040 | u32 result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
| 1042 | /* find the size of the stable storage */ |
| 1043 | if (pdc_stable_get_size(&pdcs_size) != PDC_OK) |
| 1044 | return -ENODEV; |
| 1045 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1046 | /* make sure we have enough data */ |
| 1047 | if (pdcs_size < 96) |
| 1048 | return -ENODATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1050 | printk(KERN_INFO PDCS_PREFIX " facility v%s\n", PDCS_VERSION); |
| 1051 | |
Thibaut Varene | 3f9edb5 | 2006-05-04 18:43:34 -0600 | [diff] [blame] | 1052 | /* get OSID */ |
| 1053 | if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK) |
| 1054 | return -EIO; |
| 1055 | |
| 1056 | /* the actual result is 16 bits away */ |
| 1057 | pdcs_osid = (u16)(result >> 16); |
| 1058 | |
Greg Kroah-Hartman | c829a5b4 | 2007-11-07 13:56:19 -0800 | [diff] [blame] | 1059 | /* For now we'll register the directory at /sys/firmware/stable */ |
| 1060 | stable_kobj = kobject_create_and_add("stable", firmware_kobj); |
| 1061 | if (!stable_kobj) { |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1062 | rc = -ENOMEM; |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1063 | goto fail_firmreg; |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1064 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1066 | /* Don't forget the root entries */ |
Joel Soete | ff451d7 | 2008-02-18 18:26:11 -0800 | [diff] [blame] | 1067 | error = sysfs_create_group(stable_kobj, &pdcs_attr_group); |
Greg Kroah-Hartman | 7f54821 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1068 | |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1069 | /* register the paths kset as a child of the stable kset */ |
Greg Kroah-Hartman | c829a5b4 | 2007-11-07 13:56:19 -0800 | [diff] [blame] | 1070 | paths_kset = kset_create_and_add("paths", NULL, stable_kobj); |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1071 | if (!paths_kset) { |
| 1072 | rc = -ENOMEM; |
| 1073 | goto fail_ksetreg; |
| 1074 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1076 | /* now we create all "files" for the paths kset */ |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1077 | if ((rc = pdcs_register_pathentries())) |
| 1078 | goto fail_pdcsreg; |
| 1079 | |
| 1080 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1082 | fail_pdcsreg: |
| 1083 | pdcs_unregister_pathentries(); |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1084 | kset_unregister(paths_kset); |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1085 | |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1086 | fail_ksetreg: |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 1087 | kobject_put(stable_kobj); |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1088 | |
| 1089 | fail_firmreg: |
Thibaut VARENE | c742842 | 2006-01-11 13:59:53 -0700 | [diff] [blame] | 1090 | printk(KERN_INFO PDCS_PREFIX " bailing out\n"); |
Thibaut VARENE | 4b991da | 2006-01-10 20:48:01 -0500 | [diff] [blame] | 1091 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | static void __exit |
| 1095 | pdc_stable_exit(void) |
| 1096 | { |
| 1097 | pdcs_unregister_pathentries(); |
Greg Kroah-Hartman | 4443d07 | 2007-11-02 15:25:00 -0700 | [diff] [blame] | 1098 | kset_unregister(paths_kset); |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 1099 | kobject_put(stable_kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | |
| 1103 | module_init(pdc_stable_init); |
| 1104 | module_exit(pdc_stable_exit); |