11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Interfaces to retrieve and set PDC Stable options (firmware) 31da177e4SLinus Torvalds * 4c7428422SThibaut VARENE * Copyright (C) 2005-2006 Thibaut VARENE <varenet@parisc-linux.org> 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 7a81dd18eSThibaut VARENE * it under the terms of the GNU General Public License, version 2, as 8a81dd18eSThibaut VARENE * published by the Free Software Foundation. 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 111da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 121da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 131da177e4SLinus Torvalds * GNU General Public License for more details. 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 161da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 171da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * DEV NOTE: the PDC Procedures reference states that: 211da177e4SLinus Torvalds * "A minimum of 96 bytes of Stable Storage is required. Providing more than 221da177e4SLinus Torvalds * 96 bytes of Stable Storage is optional [...]. Failure to provide the 231da177e4SLinus Torvalds * optional locations from 96 to 192 results in the loss of certain 241da177e4SLinus Torvalds * functionality during boot." 251da177e4SLinus Torvalds * 261da177e4SLinus Torvalds * Since locations between 96 and 192 are the various paths, most (if not 271da177e4SLinus Torvalds * all) PA-RISC machines should have them. Anyway, for safety reasons, the 28c7428422SThibaut VARENE * following code can deal with just 96 bytes of Stable Storage, and all 291da177e4SLinus Torvalds * sizes between 96 and 192 bytes (provided they are multiple of struct 301da177e4SLinus Torvalds * device_path size, eg: 128, 160 and 192) to provide full information. 31*3f9edb53SThibaut Varene * One last word: there's one path we can always count on: the primary path. 32*3f9edb53SThibaut Varene * Anything above 224 bytes is used for 'osdep2' OS-dependent storage area. 33*3f9edb53SThibaut Varene * 34*3f9edb53SThibaut Varene * The first OS-dependent area should always be available. Obviously, this is 35*3f9edb53SThibaut Varene * not true for the other one. Also bear in mind that reading/writing from/to 36*3f9edb53SThibaut Varene * osdep2 is much more expensive than from/to osdep1. 37*3f9edb53SThibaut Varene * NOTE: We do not handle the 2 bytes OS-dep area at 0x5D, nor the first 38*3f9edb53SThibaut Varene * 2 bytes of storage available right after OSID. That's a total of 4 bytes 39*3f9edb53SThibaut Varene * sacrificed: -ETOOLAZY :P 40c7428422SThibaut VARENE * 41c7428422SThibaut VARENE * The current policy wrt file permissions is: 42c7428422SThibaut VARENE * - write: root only 43c7428422SThibaut VARENE * - read: (reading triggers PDC calls) ? root only : everyone 44c7428422SThibaut VARENE * The rationale is that PDC calls could hog (DoS) the machine. 45c7428422SThibaut VARENE * 46c7428422SThibaut VARENE * TODO: 47c7428422SThibaut VARENE * - timer/fastsize write calls 481da177e4SLinus Torvalds */ 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds #undef PDCS_DEBUG 511da177e4SLinus Torvalds #ifdef PDCS_DEBUG 521da177e4SLinus Torvalds #define DPRINTK(fmt, args...) printk(KERN_DEBUG fmt, ## args) 531da177e4SLinus Torvalds #else 541da177e4SLinus Torvalds #define DPRINTK(fmt, args...) 551da177e4SLinus Torvalds #endif 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds #include <linux/module.h> 581da177e4SLinus Torvalds #include <linux/init.h> 591da177e4SLinus Torvalds #include <linux/kernel.h> 601da177e4SLinus Torvalds #include <linux/string.h> 61c59ede7bSRandy.Dunlap #include <linux/capability.h> 621da177e4SLinus Torvalds #include <linux/ctype.h> 631da177e4SLinus Torvalds #include <linux/sysfs.h> 641da177e4SLinus Torvalds #include <linux/kobject.h> 651da177e4SLinus Torvalds #include <linux/device.h> 661da177e4SLinus Torvalds #include <linux/errno.h> 67c7428422SThibaut VARENE #include <linux/spinlock.h> 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds #include <asm/pdc.h> 701da177e4SLinus Torvalds #include <asm/page.h> 711da177e4SLinus Torvalds #include <asm/uaccess.h> 721da177e4SLinus Torvalds #include <asm/hardware.h> 731da177e4SLinus Torvalds 74*3f9edb53SThibaut Varene #define PDCS_VERSION "0.30" 75c7428422SThibaut VARENE #define PDCS_PREFIX "PDC Stable Storage" 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds #define PDCS_ADDR_PPRI 0x00 781da177e4SLinus Torvalds #define PDCS_ADDR_OSID 0x40 79*3f9edb53SThibaut Varene #define PDCS_ADDR_OSD1 0x48 80*3f9edb53SThibaut Varene #define PDCS_ADDR_DIAG 0x58 811da177e4SLinus Torvalds #define PDCS_ADDR_FSIZ 0x5C 821da177e4SLinus Torvalds #define PDCS_ADDR_PCON 0x60 831da177e4SLinus Torvalds #define PDCS_ADDR_PALT 0x80 841da177e4SLinus Torvalds #define PDCS_ADDR_PKBD 0xA0 85*3f9edb53SThibaut Varene #define PDCS_ADDR_OSD2 0xE0 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds MODULE_AUTHOR("Thibaut VARENE <varenet@parisc-linux.org>"); 881da177e4SLinus Torvalds MODULE_DESCRIPTION("sysfs interface to HP PDC Stable Storage data"); 891da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 901da177e4SLinus Torvalds MODULE_VERSION(PDCS_VERSION); 911da177e4SLinus Torvalds 92c7428422SThibaut VARENE /* holds Stable Storage size. Initialized once and for all, no lock needed */ 938039de10SHelge Deller static unsigned long pdcs_size __read_mostly; 941da177e4SLinus Torvalds 95*3f9edb53SThibaut Varene /* holds OS ID. Initialized once and for all, hopefully to 0x0006 */ 96*3f9edb53SThibaut Varene static u16 pdcs_osid __read_mostly; 97*3f9edb53SThibaut Varene 981da177e4SLinus Torvalds /* This struct defines what we need to deal with a parisc pdc path entry */ 991da177e4SLinus Torvalds struct pdcspath_entry { 100c7428422SThibaut VARENE rwlock_t rw_lock; /* to protect path entry access */ 1011da177e4SLinus Torvalds short ready; /* entry record is valid if != 0 */ 1021da177e4SLinus Torvalds unsigned long addr; /* entry address in stable storage */ 1031da177e4SLinus Torvalds char *name; /* entry name */ 1041da177e4SLinus Torvalds struct device_path devpath; /* device path in parisc representation */ 1051da177e4SLinus Torvalds struct device *dev; /* corresponding device */ 1061da177e4SLinus Torvalds struct kobject kobj; 1071da177e4SLinus Torvalds }; 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds struct pdcspath_attribute { 1101da177e4SLinus Torvalds struct attribute attr; 1111da177e4SLinus Torvalds ssize_t (*show)(struct pdcspath_entry *entry, char *buf); 1121da177e4SLinus Torvalds ssize_t (*store)(struct pdcspath_entry *entry, const char *buf, size_t count); 1131da177e4SLinus Torvalds }; 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds #define PDCSPATH_ENTRY(_addr, _name) \ 1161da177e4SLinus Torvalds struct pdcspath_entry pdcspath_entry_##_name = { \ 1171da177e4SLinus Torvalds .ready = 0, \ 1181da177e4SLinus Torvalds .addr = _addr, \ 1191da177e4SLinus Torvalds .name = __stringify(_name), \ 1201da177e4SLinus Torvalds }; 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds #define PDCS_ATTR(_name, _mode, _show, _store) \ 1231da177e4SLinus Torvalds struct subsys_attribute pdcs_attr_##_name = { \ 1241da177e4SLinus Torvalds .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \ 1251da177e4SLinus Torvalds .show = _show, \ 1261da177e4SLinus Torvalds .store = _store, \ 1271da177e4SLinus Torvalds }; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds #define PATHS_ATTR(_name, _mode, _show, _store) \ 1301da177e4SLinus Torvalds struct pdcspath_attribute paths_attr_##_name = { \ 1311da177e4SLinus Torvalds .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \ 1321da177e4SLinus Torvalds .show = _show, \ 1331da177e4SLinus Torvalds .store = _store, \ 1341da177e4SLinus Torvalds }; 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds #define to_pdcspath_attribute(_attr) container_of(_attr, struct pdcspath_attribute, attr) 1371da177e4SLinus Torvalds #define to_pdcspath_entry(obj) container_of(obj, struct pdcspath_entry, kobj) 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds /** 1401da177e4SLinus Torvalds * pdcspath_fetch - This function populates the path entry structs. 1411da177e4SLinus Torvalds * @entry: A pointer to an allocated pdcspath_entry. 1421da177e4SLinus Torvalds * 1431da177e4SLinus Torvalds * The general idea is that you don't read from the Stable Storage every time 1441da177e4SLinus Torvalds * you access the files provided by the facilites. We store a copy of the 1451da177e4SLinus Torvalds * content of the stable storage WRT various paths in these structs. We read 1461da177e4SLinus Torvalds * these structs when reading the files, and we will write to these structs when 1471da177e4SLinus Torvalds * writing to the files, and only then write them back to the Stable Storage. 148c7428422SThibaut VARENE * 149c7428422SThibaut VARENE * This function expects to be called with @entry->rw_lock write-hold. 1501da177e4SLinus Torvalds */ 1511da177e4SLinus Torvalds static int 1521da177e4SLinus Torvalds pdcspath_fetch(struct pdcspath_entry *entry) 1531da177e4SLinus Torvalds { 1541da177e4SLinus Torvalds struct device_path *devpath; 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds if (!entry) 1571da177e4SLinus Torvalds return -EINVAL; 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds devpath = &entry->devpath; 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds DPRINTK("%s: fetch: 0x%p, 0x%p, addr: 0x%lx\n", __func__, 1621da177e4SLinus Torvalds entry, devpath, entry->addr); 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds /* addr, devpath and count must be word aligned */ 1651da177e4SLinus Torvalds if (pdc_stable_read(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) 1661da177e4SLinus Torvalds return -EIO; 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds /* Find the matching device. 1691da177e4SLinus Torvalds NOTE: hardware_path overlays with device_path, so the nice cast can 1701da177e4SLinus Torvalds be used */ 1711da177e4SLinus Torvalds entry->dev = hwpath_to_device((struct hardware_path *)devpath); 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds entry->ready = 1; 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds return 0; 1781da177e4SLinus Torvalds } 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds /** 1811da177e4SLinus Torvalds * pdcspath_store - This function writes a path to stable storage. 1821da177e4SLinus Torvalds * @entry: A pointer to an allocated pdcspath_entry. 1831da177e4SLinus Torvalds * 1841da177e4SLinus Torvalds * It can be used in two ways: either by passing it a preset devpath struct 1851da177e4SLinus Torvalds * containing an already computed hardware path, or by passing it a device 1861da177e4SLinus Torvalds * pointer, from which it'll find out the corresponding hardware path. 1871da177e4SLinus Torvalds * For now we do not handle the case where there's an error in writing to the 1881da177e4SLinus Torvalds * Stable Storage area, so you'd better not mess up the data :P 189c7428422SThibaut VARENE * 190c7428422SThibaut VARENE * This function expects to be called with @entry->rw_lock write-hold. 1911da177e4SLinus Torvalds */ 192c7428422SThibaut VARENE static void 1931da177e4SLinus Torvalds pdcspath_store(struct pdcspath_entry *entry) 1941da177e4SLinus Torvalds { 1951da177e4SLinus Torvalds struct device_path *devpath; 1961da177e4SLinus Torvalds 197c7428422SThibaut VARENE BUG_ON(!entry); 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds devpath = &entry->devpath; 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds /* We expect the caller to set the ready flag to 0 if the hardware 2021da177e4SLinus Torvalds path struct provided is invalid, so that we know we have to fill it. 2031da177e4SLinus Torvalds First case, we don't have a preset hwpath... */ 2041da177e4SLinus Torvalds if (!entry->ready) { 2051da177e4SLinus Torvalds /* ...but we have a device, map it */ 206c7428422SThibaut VARENE BUG_ON(!entry->dev); 2071da177e4SLinus Torvalds device_to_hwpath(entry->dev, (struct hardware_path *)devpath); 2081da177e4SLinus Torvalds } 2091da177e4SLinus Torvalds /* else, we expect the provided hwpath to be valid. */ 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds DPRINTK("%s: store: 0x%p, 0x%p, addr: 0x%lx\n", __func__, 2121da177e4SLinus Torvalds entry, devpath, entry->addr); 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds /* addr, devpath and count must be word aligned */ 2151da177e4SLinus Torvalds if (pdc_stable_write(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) { 2161da177e4SLinus Torvalds printk(KERN_ERR "%s: an error occured when writing to PDC.\n" 2171da177e4SLinus Torvalds "It is likely that the Stable Storage data has been corrupted.\n" 2181da177e4SLinus Torvalds "Please check it carefully upon next reboot.\n", __func__); 219c7428422SThibaut VARENE WARN_ON(1); 2201da177e4SLinus Torvalds } 2211da177e4SLinus Torvalds 2224b991da7SThibaut VARENE /* kobject is already registered */ 2234b991da7SThibaut VARENE entry->ready = 2; 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); 2261da177e4SLinus Torvalds } 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds /** 2291da177e4SLinus Torvalds * pdcspath_hwpath_read - This function handles hardware path pretty printing. 2301da177e4SLinus Torvalds * @entry: An allocated and populated pdscpath_entry struct. 2311da177e4SLinus Torvalds * @buf: The output buffer to write to. 2321da177e4SLinus Torvalds * 2331da177e4SLinus Torvalds * We will call this function to format the output of the hwpath attribute file. 2341da177e4SLinus Torvalds */ 2351da177e4SLinus Torvalds static ssize_t 2361da177e4SLinus Torvalds pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf) 2371da177e4SLinus Torvalds { 2381da177e4SLinus Torvalds char *out = buf; 2391da177e4SLinus Torvalds struct device_path *devpath; 240c7428422SThibaut VARENE short i; 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds if (!entry || !buf) 2431da177e4SLinus Torvalds return -EINVAL; 2441da177e4SLinus Torvalds 245c7428422SThibaut VARENE read_lock(&entry->rw_lock); 2461da177e4SLinus Torvalds devpath = &entry->devpath; 247c7428422SThibaut VARENE i = entry->ready; 248c7428422SThibaut VARENE read_unlock(&entry->rw_lock); 2491da177e4SLinus Torvalds 250c7428422SThibaut VARENE if (!i) /* entry is not ready */ 2511da177e4SLinus Torvalds return -ENODATA; 2521da177e4SLinus Torvalds 2531da177e4SLinus Torvalds for (i = 0; i < 6; i++) { 2541da177e4SLinus Torvalds if (devpath->bc[i] >= 128) 2551da177e4SLinus Torvalds continue; 2561da177e4SLinus Torvalds out += sprintf(out, "%u/", (unsigned char)devpath->bc[i]); 2571da177e4SLinus Torvalds } 2581da177e4SLinus Torvalds out += sprintf(out, "%u\n", (unsigned char)devpath->mod); 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds return out - buf; 2611da177e4SLinus Torvalds } 2621da177e4SLinus Torvalds 2631da177e4SLinus Torvalds /** 2641da177e4SLinus Torvalds * pdcspath_hwpath_write - This function handles hardware path modifying. 2651da177e4SLinus Torvalds * @entry: An allocated and populated pdscpath_entry struct. 2661da177e4SLinus Torvalds * @buf: The input buffer to read from. 2671da177e4SLinus Torvalds * @count: The number of bytes to be read. 2681da177e4SLinus Torvalds * 2691da177e4SLinus Torvalds * We will call this function to change the current hardware path. 2701da177e4SLinus Torvalds * Hardware paths are to be given '/'-delimited, without brackets. 271c7428422SThibaut VARENE * We make sure that the provided path actually maps to an existing 2721da177e4SLinus Torvalds * device, BUT nothing would prevent some foolish user to set the path to some 2731da177e4SLinus Torvalds * PCI bridge or even a CPU... 2741da177e4SLinus Torvalds * A better work around would be to make sure we are at the end of a device tree 2751da177e4SLinus Torvalds * for instance, but it would be IMHO beyond the simple scope of that driver. 2761da177e4SLinus Torvalds * The aim is to provide a facility. Data correctness is left to userland. 2771da177e4SLinus Torvalds */ 2781da177e4SLinus Torvalds static ssize_t 2791da177e4SLinus Torvalds pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t count) 2801da177e4SLinus Torvalds { 2811da177e4SLinus Torvalds struct hardware_path hwpath; 2821da177e4SLinus Torvalds unsigned short i; 2831da177e4SLinus Torvalds char in[count+1], *temp; 2841da177e4SLinus Torvalds struct device *dev; 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds if (!entry || !buf || !count) 2871da177e4SLinus Torvalds return -EINVAL; 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds /* We'll use a local copy of buf */ 2901da177e4SLinus Torvalds memset(in, 0, count+1); 2911da177e4SLinus Torvalds strncpy(in, buf, count); 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds /* Let's clean up the target. 0xff is a blank pattern */ 2941da177e4SLinus Torvalds memset(&hwpath, 0xff, sizeof(hwpath)); 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds /* First, pick the mod field (the last one of the input string) */ 2971da177e4SLinus Torvalds if (!(temp = strrchr(in, '/'))) 2981da177e4SLinus Torvalds return -EINVAL; 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds hwpath.mod = simple_strtoul(temp+1, NULL, 10); 3011da177e4SLinus Torvalds in[temp-in] = '\0'; /* truncate the remaining string. just precaution */ 3021da177e4SLinus Torvalds DPRINTK("%s: mod: %d\n", __func__, hwpath.mod); 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds /* Then, loop for each delimiter, making sure we don't have too many. 3051da177e4SLinus Torvalds we write the bc fields in a down-top way. No matter what, we stop 3061da177e4SLinus Torvalds before writing the last field. If there are too many fields anyway, 3071da177e4SLinus Torvalds then the user is a moron and it'll be caught up later when we'll 3081da177e4SLinus Torvalds check the consistency of the given hwpath. */ 3091da177e4SLinus Torvalds for (i=5; ((temp = strrchr(in, '/'))) && (temp-in > 0) && (likely(i)); i--) { 3101da177e4SLinus Torvalds hwpath.bc[i] = simple_strtoul(temp+1, NULL, 10); 3111da177e4SLinus Torvalds in[temp-in] = '\0'; 3121da177e4SLinus Torvalds DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]); 3131da177e4SLinus Torvalds } 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds /* Store the final field */ 3161da177e4SLinus Torvalds hwpath.bc[i] = simple_strtoul(in, NULL, 10); 3171da177e4SLinus Torvalds DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]); 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds /* Now we check that the user isn't trying to lure us */ 3201da177e4SLinus Torvalds if (!(dev = hwpath_to_device((struct hardware_path *)&hwpath))) { 3211da177e4SLinus Torvalds printk(KERN_WARNING "%s: attempt to set invalid \"%s\" " 3221da177e4SLinus Torvalds "hardware path: %s\n", __func__, entry->name, buf); 3231da177e4SLinus Torvalds return -EINVAL; 3241da177e4SLinus Torvalds } 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds /* So far so good, let's get in deep */ 327c7428422SThibaut VARENE write_lock(&entry->rw_lock); 3281da177e4SLinus Torvalds entry->ready = 0; 3291da177e4SLinus Torvalds entry->dev = dev; 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds /* Now, dive in. Write back to the hardware */ 332c7428422SThibaut VARENE pdcspath_store(entry); 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds /* Update the symlink to the real device */ 3351da177e4SLinus Torvalds sysfs_remove_link(&entry->kobj, "device"); 3361da177e4SLinus Torvalds sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); 337c7428422SThibaut VARENE write_unlock(&entry->rw_lock); 3381da177e4SLinus Torvalds 339c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" path to \"%s\"\n", 3401da177e4SLinus Torvalds entry->name, buf); 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds return count; 3431da177e4SLinus Torvalds } 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds /** 3461da177e4SLinus Torvalds * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing. 3471da177e4SLinus Torvalds * @entry: An allocated and populated pdscpath_entry struct. 3481da177e4SLinus Torvalds * @buf: The output buffer to write to. 3491da177e4SLinus Torvalds * 3501da177e4SLinus Torvalds * We will call this function to format the output of the layer attribute file. 3511da177e4SLinus Torvalds */ 3521da177e4SLinus Torvalds static ssize_t 3531da177e4SLinus Torvalds pdcspath_layer_read(struct pdcspath_entry *entry, char *buf) 3541da177e4SLinus Torvalds { 3551da177e4SLinus Torvalds char *out = buf; 3561da177e4SLinus Torvalds struct device_path *devpath; 357c7428422SThibaut VARENE short i; 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds if (!entry || !buf) 3601da177e4SLinus Torvalds return -EINVAL; 3611da177e4SLinus Torvalds 362c7428422SThibaut VARENE read_lock(&entry->rw_lock); 3631da177e4SLinus Torvalds devpath = &entry->devpath; 364c7428422SThibaut VARENE i = entry->ready; 365c7428422SThibaut VARENE read_unlock(&entry->rw_lock); 3661da177e4SLinus Torvalds 367c7428422SThibaut VARENE if (!i) /* entry is not ready */ 3681da177e4SLinus Torvalds return -ENODATA; 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds for (i = 0; devpath->layers[i] && (likely(i < 6)); i++) 3711da177e4SLinus Torvalds out += sprintf(out, "%u ", devpath->layers[i]); 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds out += sprintf(out, "\n"); 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds return out - buf; 3761da177e4SLinus Torvalds } 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds /** 3791da177e4SLinus Torvalds * pdcspath_layer_write - This function handles extended layer modifying. 3801da177e4SLinus Torvalds * @entry: An allocated and populated pdscpath_entry struct. 3811da177e4SLinus Torvalds * @buf: The input buffer to read from. 3821da177e4SLinus Torvalds * @count: The number of bytes to be read. 3831da177e4SLinus Torvalds * 3841da177e4SLinus Torvalds * We will call this function to change the current layer value. 3851da177e4SLinus Torvalds * Layers are to be given '.'-delimited, without brackets. 3861da177e4SLinus Torvalds * XXX beware we are far less checky WRT input data provided than for hwpath. 3871da177e4SLinus Torvalds * Potential harm can be done, since there's no way to check the validity of 3881da177e4SLinus Torvalds * the layer fields. 3891da177e4SLinus Torvalds */ 3901da177e4SLinus Torvalds static ssize_t 3911da177e4SLinus Torvalds pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count) 3921da177e4SLinus Torvalds { 3931da177e4SLinus Torvalds unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */ 3941da177e4SLinus Torvalds unsigned short i; 3951da177e4SLinus Torvalds char in[count+1], *temp; 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds if (!entry || !buf || !count) 3981da177e4SLinus Torvalds return -EINVAL; 3991da177e4SLinus Torvalds 4001da177e4SLinus Torvalds /* We'll use a local copy of buf */ 4011da177e4SLinus Torvalds memset(in, 0, count+1); 4021da177e4SLinus Torvalds strncpy(in, buf, count); 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds /* Let's clean up the target. 0 is a blank pattern */ 4051da177e4SLinus Torvalds memset(&layers, 0, sizeof(layers)); 4061da177e4SLinus Torvalds 4071da177e4SLinus Torvalds /* First, pick the first layer */ 4081da177e4SLinus Torvalds if (unlikely(!isdigit(*in))) 4091da177e4SLinus Torvalds return -EINVAL; 4101da177e4SLinus Torvalds layers[0] = simple_strtoul(in, NULL, 10); 4111da177e4SLinus Torvalds DPRINTK("%s: layer[0]: %d\n", __func__, layers[0]); 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvalds temp = in; 4141da177e4SLinus Torvalds for (i=1; ((temp = strchr(temp, '.'))) && (likely(i<6)); i++) { 4151da177e4SLinus Torvalds if (unlikely(!isdigit(*(++temp)))) 4161da177e4SLinus Torvalds return -EINVAL; 4171da177e4SLinus Torvalds layers[i] = simple_strtoul(temp, NULL, 10); 4181da177e4SLinus Torvalds DPRINTK("%s: layer[%d]: %d\n", __func__, i, layers[i]); 4191da177e4SLinus Torvalds } 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds /* So far so good, let's get in deep */ 422c7428422SThibaut VARENE write_lock(&entry->rw_lock); 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds /* First, overwrite the current layers with the new ones, not touching 4251da177e4SLinus Torvalds the hardware path. */ 4261da177e4SLinus Torvalds memcpy(&entry->devpath.layers, &layers, sizeof(layers)); 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds /* Now, dive in. Write back to the hardware */ 429c7428422SThibaut VARENE pdcspath_store(entry); 430c7428422SThibaut VARENE write_unlock(&entry->rw_lock); 4311da177e4SLinus Torvalds 432c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" layers to \"%s\"\n", 4331da177e4SLinus Torvalds entry->name, buf); 4341da177e4SLinus Torvalds 4351da177e4SLinus Torvalds return count; 4361da177e4SLinus Torvalds } 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds /** 4391da177e4SLinus Torvalds * pdcspath_attr_show - Generic read function call wrapper. 4401da177e4SLinus Torvalds * @kobj: The kobject to get info from. 4411da177e4SLinus Torvalds * @attr: The attribute looked upon. 4421da177e4SLinus Torvalds * @buf: The output buffer. 4431da177e4SLinus Torvalds */ 4441da177e4SLinus Torvalds static ssize_t 4451da177e4SLinus Torvalds pdcspath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) 4461da177e4SLinus Torvalds { 4471da177e4SLinus Torvalds struct pdcspath_entry *entry = to_pdcspath_entry(kobj); 4481da177e4SLinus Torvalds struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr); 4491da177e4SLinus Torvalds ssize_t ret = 0; 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds if (pdcs_attr->show) 4521da177e4SLinus Torvalds ret = pdcs_attr->show(entry, buf); 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds return ret; 4551da177e4SLinus Torvalds } 4561da177e4SLinus Torvalds 4571da177e4SLinus Torvalds /** 4581da177e4SLinus Torvalds * pdcspath_attr_store - Generic write function call wrapper. 4591da177e4SLinus Torvalds * @kobj: The kobject to write info to. 4601da177e4SLinus Torvalds * @attr: The attribute to be modified. 4611da177e4SLinus Torvalds * @buf: The input buffer. 4621da177e4SLinus Torvalds * @count: The size of the buffer. 4631da177e4SLinus Torvalds */ 4641da177e4SLinus Torvalds static ssize_t 4651da177e4SLinus Torvalds pdcspath_attr_store(struct kobject *kobj, struct attribute *attr, 4661da177e4SLinus Torvalds const char *buf, size_t count) 4671da177e4SLinus Torvalds { 4681da177e4SLinus Torvalds struct pdcspath_entry *entry = to_pdcspath_entry(kobj); 4691da177e4SLinus Torvalds struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr); 4701da177e4SLinus Torvalds ssize_t ret = 0; 4711da177e4SLinus Torvalds 4721da177e4SLinus Torvalds if (!capable(CAP_SYS_ADMIN)) 4731da177e4SLinus Torvalds return -EACCES; 4741da177e4SLinus Torvalds 4751da177e4SLinus Torvalds if (pdcs_attr->store) 4761da177e4SLinus Torvalds ret = pdcs_attr->store(entry, buf, count); 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds return ret; 4791da177e4SLinus Torvalds } 4801da177e4SLinus Torvalds 4811da177e4SLinus Torvalds static struct sysfs_ops pdcspath_attr_ops = { 4821da177e4SLinus Torvalds .show = pdcspath_attr_show, 4831da177e4SLinus Torvalds .store = pdcspath_attr_store, 4841da177e4SLinus Torvalds }; 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds /* These are the two attributes of any PDC path. */ 487c7428422SThibaut VARENE static PATHS_ATTR(hwpath, 0644, pdcspath_hwpath_read, pdcspath_hwpath_write); 488c7428422SThibaut VARENE static PATHS_ATTR(layer, 0644, pdcspath_layer_read, pdcspath_layer_write); 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds static struct attribute *paths_subsys_attrs[] = { 4911da177e4SLinus Torvalds &paths_attr_hwpath.attr, 4921da177e4SLinus Torvalds &paths_attr_layer.attr, 4931da177e4SLinus Torvalds NULL, 4941da177e4SLinus Torvalds }; 4951da177e4SLinus Torvalds 4961da177e4SLinus Torvalds /* Specific kobject type for our PDC paths */ 4971da177e4SLinus Torvalds static struct kobj_type ktype_pdcspath = { 4981da177e4SLinus Torvalds .sysfs_ops = &pdcspath_attr_ops, 4991da177e4SLinus Torvalds .default_attrs = paths_subsys_attrs, 5001da177e4SLinus Torvalds }; 5011da177e4SLinus Torvalds 5021da177e4SLinus Torvalds /* We hard define the 4 types of path we expect to find */ 5031da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PPRI, primary); 5041da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PCON, console); 5051da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PALT, alternative); 5061da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PKBD, keyboard); 5071da177e4SLinus Torvalds 5081da177e4SLinus Torvalds /* An array containing all PDC paths we will deal with */ 5091da177e4SLinus Torvalds static struct pdcspath_entry *pdcspath_entries[] = { 5101da177e4SLinus Torvalds &pdcspath_entry_primary, 5111da177e4SLinus Torvalds &pdcspath_entry_alternative, 5121da177e4SLinus Torvalds &pdcspath_entry_console, 5131da177e4SLinus Torvalds &pdcspath_entry_keyboard, 5141da177e4SLinus Torvalds NULL, 5151da177e4SLinus Torvalds }; 5161da177e4SLinus Torvalds 517c7428422SThibaut VARENE 518c7428422SThibaut VARENE /* For more insight of what's going on here, refer to PDC Procedures doc, 519c7428422SThibaut VARENE * Section PDC_STABLE */ 520c7428422SThibaut VARENE 5211da177e4SLinus Torvalds /** 522c7428422SThibaut VARENE * pdcs_size_read - Stable Storage size output. 5231da177e4SLinus Torvalds * @entry: An allocated and populated subsytem struct. We don't use it tho. 5241da177e4SLinus Torvalds * @buf: The output buffer to write to. 5251da177e4SLinus Torvalds */ 5261da177e4SLinus Torvalds static ssize_t 527c7428422SThibaut VARENE pdcs_size_read(struct subsystem *entry, char *buf) 5281da177e4SLinus Torvalds { 5291da177e4SLinus Torvalds char *out = buf; 5301da177e4SLinus Torvalds 5311da177e4SLinus Torvalds if (!entry || !buf) 5321da177e4SLinus Torvalds return -EINVAL; 5331da177e4SLinus Torvalds 5341da177e4SLinus Torvalds /* show the size of the stable storage */ 535c7428422SThibaut VARENE out += sprintf(out, "%ld\n", pdcs_size); 5361da177e4SLinus Torvalds 537c7428422SThibaut VARENE return out - buf; 538c7428422SThibaut VARENE } 5391da177e4SLinus Torvalds 540c7428422SThibaut VARENE /** 541c7428422SThibaut VARENE * pdcs_auto_read - Stable Storage autoboot/search flag output. 542c7428422SThibaut VARENE * @entry: An allocated and populated subsytem struct. We don't use it tho. 543c7428422SThibaut VARENE * @buf: The output buffer to write to. 544c7428422SThibaut VARENE * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag 545c7428422SThibaut VARENE */ 546c7428422SThibaut VARENE static ssize_t 547c7428422SThibaut VARENE pdcs_auto_read(struct subsystem *entry, char *buf, int knob) 548c7428422SThibaut VARENE { 549c7428422SThibaut VARENE char *out = buf; 550c7428422SThibaut VARENE struct pdcspath_entry *pathentry; 551c7428422SThibaut VARENE 552c7428422SThibaut VARENE if (!entry || !buf) 553c7428422SThibaut VARENE return -EINVAL; 554c7428422SThibaut VARENE 555c7428422SThibaut VARENE /* Current flags are stored in primary boot path entry */ 556c7428422SThibaut VARENE pathentry = &pdcspath_entry_primary; 557c7428422SThibaut VARENE 558c7428422SThibaut VARENE read_lock(&pathentry->rw_lock); 559c7428422SThibaut VARENE out += sprintf(out, "%s\n", (pathentry->devpath.flags & knob) ? 560c7428422SThibaut VARENE "On" : "Off"); 561c7428422SThibaut VARENE read_unlock(&pathentry->rw_lock); 562c7428422SThibaut VARENE 563c7428422SThibaut VARENE return out - buf; 564c7428422SThibaut VARENE } 565c7428422SThibaut VARENE 566c7428422SThibaut VARENE /** 567c7428422SThibaut VARENE * pdcs_autoboot_read - Stable Storage autoboot flag output. 568c7428422SThibaut VARENE * @entry: An allocated and populated subsytem struct. We don't use it tho. 569c7428422SThibaut VARENE * @buf: The output buffer to write to. 570c7428422SThibaut VARENE */ 571c7428422SThibaut VARENE static inline ssize_t 572c7428422SThibaut VARENE pdcs_autoboot_read(struct subsystem *entry, char *buf) 573c7428422SThibaut VARENE { 574c7428422SThibaut VARENE return pdcs_auto_read(entry, buf, PF_AUTOBOOT); 575c7428422SThibaut VARENE } 576c7428422SThibaut VARENE 577c7428422SThibaut VARENE /** 578c7428422SThibaut VARENE * pdcs_autosearch_read - Stable Storage autoboot flag output. 579c7428422SThibaut VARENE * @entry: An allocated and populated subsytem struct. We don't use it tho. 580c7428422SThibaut VARENE * @buf: The output buffer to write to. 581c7428422SThibaut VARENE */ 582c7428422SThibaut VARENE static inline ssize_t 583c7428422SThibaut VARENE pdcs_autosearch_read(struct subsystem *entry, char *buf) 584c7428422SThibaut VARENE { 585c7428422SThibaut VARENE return pdcs_auto_read(entry, buf, PF_AUTOSEARCH); 586c7428422SThibaut VARENE } 587c7428422SThibaut VARENE 588c7428422SThibaut VARENE /** 589c7428422SThibaut VARENE * pdcs_timer_read - Stable Storage timer count output (in seconds). 590c7428422SThibaut VARENE * @entry: An allocated and populated subsytem struct. We don't use it tho. 591c7428422SThibaut VARENE * @buf: The output buffer to write to. 592c7428422SThibaut VARENE * 593c7428422SThibaut VARENE * The value of the timer field correponds to a number of seconds in powers of 2. 594c7428422SThibaut VARENE */ 595c7428422SThibaut VARENE static ssize_t 596c7428422SThibaut VARENE pdcs_timer_read(struct subsystem *entry, char *buf) 597c7428422SThibaut VARENE { 598c7428422SThibaut VARENE char *out = buf; 599c7428422SThibaut VARENE struct pdcspath_entry *pathentry; 600c7428422SThibaut VARENE 601c7428422SThibaut VARENE if (!entry || !buf) 602c7428422SThibaut VARENE return -EINVAL; 603c7428422SThibaut VARENE 604c7428422SThibaut VARENE /* Current flags are stored in primary boot path entry */ 605c7428422SThibaut VARENE pathentry = &pdcspath_entry_primary; 606c7428422SThibaut VARENE 607c7428422SThibaut VARENE /* print the timer value in seconds */ 608c7428422SThibaut VARENE read_lock(&pathentry->rw_lock); 609c7428422SThibaut VARENE out += sprintf(out, "%u\n", (pathentry->devpath.flags & PF_TIMER) ? 610c7428422SThibaut VARENE (1 << (pathentry->devpath.flags & PF_TIMER)) : 0); 611c7428422SThibaut VARENE read_unlock(&pathentry->rw_lock); 612c7428422SThibaut VARENE 613c7428422SThibaut VARENE return out - buf; 614c7428422SThibaut VARENE } 615c7428422SThibaut VARENE 616c7428422SThibaut VARENE /** 617c7428422SThibaut VARENE * pdcs_osid_read - Stable Storage OS ID register output. 618c7428422SThibaut VARENE * @entry: An allocated and populated subsytem struct. We don't use it tho. 619c7428422SThibaut VARENE * @buf: The output buffer to write to. 620c7428422SThibaut VARENE */ 621c7428422SThibaut VARENE static ssize_t 622c7428422SThibaut VARENE pdcs_osid_read(struct subsystem *entry, char *buf) 623c7428422SThibaut VARENE { 624c7428422SThibaut VARENE char *out = buf; 625c7428422SThibaut VARENE char *tmpstr = NULL; 626c7428422SThibaut VARENE 627c7428422SThibaut VARENE if (!entry || !buf) 628c7428422SThibaut VARENE return -EINVAL; 6291da177e4SLinus Torvalds 630*3f9edb53SThibaut Varene switch (pdcs_osid) { 6311da177e4SLinus Torvalds case 0x0000: tmpstr = "No OS-dependent data"; break; 6321da177e4SLinus Torvalds case 0x0001: tmpstr = "HP-UX dependent data"; break; 6331da177e4SLinus Torvalds case 0x0002: tmpstr = "MPE-iX dependent data"; break; 6341da177e4SLinus Torvalds case 0x0003: tmpstr = "OSF dependent data"; break; 6351da177e4SLinus Torvalds case 0x0004: tmpstr = "HP-RT dependent data"; break; 6361da177e4SLinus Torvalds case 0x0005: tmpstr = "Novell Netware dependent data"; break; 637*3f9edb53SThibaut Varene case 0x0006: tmpstr = "Linux dependent data"; break; 6381da177e4SLinus Torvalds default: tmpstr = "Unknown"; break; 6391da177e4SLinus Torvalds } 640*3f9edb53SThibaut Varene out += sprintf(out, "%s (0x%.4x)\n", tmpstr, pdcs_osid); 641*3f9edb53SThibaut Varene 642*3f9edb53SThibaut Varene return out - buf; 643*3f9edb53SThibaut Varene } 644*3f9edb53SThibaut Varene 645*3f9edb53SThibaut Varene /** 646*3f9edb53SThibaut Varene * pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output. 647*3f9edb53SThibaut Varene * @entry: An allocated and populated subsytem struct. We don't use it tho. 648*3f9edb53SThibaut Varene * @buf: The output buffer to write to. 649*3f9edb53SThibaut Varene * 650*3f9edb53SThibaut Varene * This can hold 16 bytes of OS-Dependent data. 651*3f9edb53SThibaut Varene */ 652*3f9edb53SThibaut Varene static ssize_t 653*3f9edb53SThibaut Varene pdcs_osdep1_read(struct subsystem *entry, char *buf) 654*3f9edb53SThibaut Varene { 655*3f9edb53SThibaut Varene char *out = buf; 656*3f9edb53SThibaut Varene u32 result[4]; 657*3f9edb53SThibaut Varene 658*3f9edb53SThibaut Varene if (!entry || !buf) 659*3f9edb53SThibaut Varene return -EINVAL; 660*3f9edb53SThibaut Varene 661*3f9edb53SThibaut Varene if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK) 662*3f9edb53SThibaut Varene return -EIO; 663*3f9edb53SThibaut Varene 664*3f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result[0]); 665*3f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result[1]); 666*3f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result[2]); 667*3f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result[3]); 668*3f9edb53SThibaut Varene 669*3f9edb53SThibaut Varene return out - buf; 670*3f9edb53SThibaut Varene } 671*3f9edb53SThibaut Varene 672*3f9edb53SThibaut Varene /** 673*3f9edb53SThibaut Varene * pdcs_diagnostic_read - Stable Storage Diagnostic register output. 674*3f9edb53SThibaut Varene * @entry: An allocated and populated subsytem struct. We don't use it tho. 675*3f9edb53SThibaut Varene * @buf: The output buffer to write to. 676*3f9edb53SThibaut Varene * 677*3f9edb53SThibaut Varene * I have NFC how to interpret the content of that register ;-). 678*3f9edb53SThibaut Varene */ 679*3f9edb53SThibaut Varene static ssize_t 680*3f9edb53SThibaut Varene pdcs_diagnostic_read(struct subsystem *entry, char *buf) 681*3f9edb53SThibaut Varene { 682*3f9edb53SThibaut Varene char *out = buf; 683*3f9edb53SThibaut Varene u32 result; 684*3f9edb53SThibaut Varene 685*3f9edb53SThibaut Varene if (!entry || !buf) 686*3f9edb53SThibaut Varene return -EINVAL; 687*3f9edb53SThibaut Varene 688*3f9edb53SThibaut Varene /* get diagnostic */ 689*3f9edb53SThibaut Varene if (pdc_stable_read(PDCS_ADDR_DIAG, &result, sizeof(result)) != PDC_OK) 690*3f9edb53SThibaut Varene return -EIO; 691*3f9edb53SThibaut Varene 692*3f9edb53SThibaut Varene out += sprintf(out, "0x%.4x\n", (result >> 16)); 693c7428422SThibaut VARENE 694c7428422SThibaut VARENE return out - buf; 695c7428422SThibaut VARENE } 696c7428422SThibaut VARENE 697c7428422SThibaut VARENE /** 698c7428422SThibaut VARENE * pdcs_fastsize_read - Stable Storage FastSize register output. 699c7428422SThibaut VARENE * @entry: An allocated and populated subsytem struct. We don't use it tho. 700c7428422SThibaut VARENE * @buf: The output buffer to write to. 701c7428422SThibaut VARENE * 702c7428422SThibaut VARENE * This register holds the amount of system RAM to be tested during boot sequence. 703c7428422SThibaut VARENE */ 704c7428422SThibaut VARENE static ssize_t 705c7428422SThibaut VARENE pdcs_fastsize_read(struct subsystem *entry, char *buf) 706c7428422SThibaut VARENE { 707c7428422SThibaut VARENE char *out = buf; 708*3f9edb53SThibaut Varene u32 result; 709c7428422SThibaut VARENE 710c7428422SThibaut VARENE if (!entry || !buf) 711c7428422SThibaut VARENE return -EINVAL; 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds /* get fast-size */ 7141da177e4SLinus Torvalds if (pdc_stable_read(PDCS_ADDR_FSIZ, &result, sizeof(result)) != PDC_OK) 7151da177e4SLinus Torvalds return -EIO; 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds if ((result & 0x0F) < 0x0E) 718abff7543SRandolph Chung out += sprintf(out, "%d kB", (1<<(result & 0x0F))*256); 7191da177e4SLinus Torvalds else 7201da177e4SLinus Torvalds out += sprintf(out, "All"); 7211da177e4SLinus Torvalds out += sprintf(out, "\n"); 7221da177e4SLinus Torvalds 7231da177e4SLinus Torvalds return out - buf; 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds 7261da177e4SLinus Torvalds /** 727*3f9edb53SThibaut Varene * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output. 728*3f9edb53SThibaut Varene * @entry: An allocated and populated subsytem struct. We don't use it tho. 729*3f9edb53SThibaut Varene * @buf: The output buffer to write to. 730*3f9edb53SThibaut Varene * 731*3f9edb53SThibaut Varene * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available. 732*3f9edb53SThibaut Varene */ 733*3f9edb53SThibaut Varene static ssize_t 734*3f9edb53SThibaut Varene pdcs_osdep2_read(struct subsystem *entry, char *buf) 735*3f9edb53SThibaut Varene { 736*3f9edb53SThibaut Varene char *out = buf; 737*3f9edb53SThibaut Varene unsigned long size; 738*3f9edb53SThibaut Varene unsigned short i; 739*3f9edb53SThibaut Varene u32 result; 740*3f9edb53SThibaut Varene 741*3f9edb53SThibaut Varene if (unlikely(pdcs_size <= 224)) 742*3f9edb53SThibaut Varene return -ENODATA; 743*3f9edb53SThibaut Varene 744*3f9edb53SThibaut Varene size = pdcs_size - 224; 745*3f9edb53SThibaut Varene 746*3f9edb53SThibaut Varene if (!entry || !buf) 747*3f9edb53SThibaut Varene return -EINVAL; 748*3f9edb53SThibaut Varene 749*3f9edb53SThibaut Varene for (i=0; i<size; i+=4) { 750*3f9edb53SThibaut Varene if (unlikely(pdc_stable_read(PDCS_ADDR_OSD2 + i, &result, 751*3f9edb53SThibaut Varene sizeof(result)) != PDC_OK)) 752*3f9edb53SThibaut Varene return -EIO; 753*3f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result); 754*3f9edb53SThibaut Varene } 755*3f9edb53SThibaut Varene 756*3f9edb53SThibaut Varene return out - buf; 757*3f9edb53SThibaut Varene } 758*3f9edb53SThibaut Varene 759*3f9edb53SThibaut Varene /** 760c7428422SThibaut VARENE * pdcs_auto_write - This function handles autoboot/search flag modifying. 7611da177e4SLinus Torvalds * @entry: An allocated and populated subsytem struct. We don't use it tho. 7621da177e4SLinus Torvalds * @buf: The input buffer to read from. 7631da177e4SLinus Torvalds * @count: The number of bytes to be read. 764c7428422SThibaut VARENE * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag 7651da177e4SLinus Torvalds * 766c7428422SThibaut VARENE * We will call this function to change the current autoboot flag. 7671da177e4SLinus Torvalds * We expect a precise syntax: 768c7428422SThibaut VARENE * \"n\" (n == 0 or 1) to toggle AutoBoot Off or On 7691da177e4SLinus Torvalds */ 7701da177e4SLinus Torvalds static ssize_t 771c7428422SThibaut VARENE pdcs_auto_write(struct subsystem *entry, const char *buf, size_t count, int knob) 7721da177e4SLinus Torvalds { 7731da177e4SLinus Torvalds struct pdcspath_entry *pathentry; 7741da177e4SLinus Torvalds unsigned char flags; 7751da177e4SLinus Torvalds char in[count+1], *temp; 7761da177e4SLinus Torvalds char c; 7771da177e4SLinus Torvalds 7781da177e4SLinus Torvalds if (!capable(CAP_SYS_ADMIN)) 7791da177e4SLinus Torvalds return -EACCES; 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds if (!entry || !buf || !count) 7821da177e4SLinus Torvalds return -EINVAL; 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds /* We'll use a local copy of buf */ 7851da177e4SLinus Torvalds memset(in, 0, count+1); 7861da177e4SLinus Torvalds strncpy(in, buf, count); 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds /* Current flags are stored in primary boot path entry */ 7891da177e4SLinus Torvalds pathentry = &pdcspath_entry_primary; 7901da177e4SLinus Torvalds 7911da177e4SLinus Torvalds /* Be nice to the existing flag record */ 792c7428422SThibaut VARENE read_lock(&pathentry->rw_lock); 7931da177e4SLinus Torvalds flags = pathentry->devpath.flags; 794c7428422SThibaut VARENE read_unlock(&pathentry->rw_lock); 7951da177e4SLinus Torvalds 7961da177e4SLinus Torvalds DPRINTK("%s: flags before: 0x%X\n", __func__, flags); 7971da177e4SLinus Torvalds 7981da177e4SLinus Torvalds temp = in; 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds while (*temp && isspace(*temp)) 8011da177e4SLinus Torvalds temp++; 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds c = *temp++ - '0'; 8041da177e4SLinus Torvalds if ((c != 0) && (c != 1)) 8051da177e4SLinus Torvalds goto parse_error; 8061da177e4SLinus Torvalds if (c == 0) 807c7428422SThibaut VARENE flags &= ~knob; 8081da177e4SLinus Torvalds else 809c7428422SThibaut VARENE flags |= knob; 8101da177e4SLinus Torvalds 8111da177e4SLinus Torvalds DPRINTK("%s: flags after: 0x%X\n", __func__, flags); 8121da177e4SLinus Torvalds 8131da177e4SLinus Torvalds /* So far so good, let's get in deep */ 814c7428422SThibaut VARENE write_lock(&pathentry->rw_lock); 8151da177e4SLinus Torvalds 8161da177e4SLinus Torvalds /* Change the path entry flags first */ 8171da177e4SLinus Torvalds pathentry->devpath.flags = flags; 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds /* Now, dive in. Write back to the hardware */ 820c7428422SThibaut VARENE pdcspath_store(pathentry); 821c7428422SThibaut VARENE write_unlock(&pathentry->rw_lock); 8221da177e4SLinus Torvalds 823c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" to \"%s\"\n", 824c7428422SThibaut VARENE (knob & PF_AUTOBOOT) ? "autoboot" : "autosearch", 825c7428422SThibaut VARENE (flags & knob) ? "On" : "Off"); 8261da177e4SLinus Torvalds 8271da177e4SLinus Torvalds return count; 8281da177e4SLinus Torvalds 8291da177e4SLinus Torvalds parse_error: 830c7428422SThibaut VARENE printk(KERN_WARNING "%s: Parse error: expect \"n\" (n == 0 or 1)\n", __func__); 8311da177e4SLinus Torvalds return -EINVAL; 8321da177e4SLinus Torvalds } 8331da177e4SLinus Torvalds 834c7428422SThibaut VARENE /** 835c7428422SThibaut VARENE * pdcs_autoboot_write - This function handles autoboot flag modifying. 836c7428422SThibaut VARENE * @entry: An allocated and populated subsytem struct. We don't use it tho. 837c7428422SThibaut VARENE * @buf: The input buffer to read from. 838c7428422SThibaut VARENE * @count: The number of bytes to be read. 839c7428422SThibaut VARENE * 840c7428422SThibaut VARENE * We will call this function to change the current boot flags. 841c7428422SThibaut VARENE * We expect a precise syntax: 842c7428422SThibaut VARENE * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On 843c7428422SThibaut VARENE */ 844c7428422SThibaut VARENE static inline ssize_t 845c7428422SThibaut VARENE pdcs_autoboot_write(struct subsystem *entry, const char *buf, size_t count) 846c7428422SThibaut VARENE { 847c7428422SThibaut VARENE return pdcs_auto_write(entry, buf, count, PF_AUTOBOOT); 848c7428422SThibaut VARENE } 849c7428422SThibaut VARENE 850c7428422SThibaut VARENE /** 851c7428422SThibaut VARENE * pdcs_autosearch_write - This function handles autosearch flag modifying. 852c7428422SThibaut VARENE * @entry: An allocated and populated subsytem struct. We don't use it tho. 853c7428422SThibaut VARENE * @buf: The input buffer to read from. 854c7428422SThibaut VARENE * @count: The number of bytes to be read. 855c7428422SThibaut VARENE * 856c7428422SThibaut VARENE * We will call this function to change the current boot flags. 857c7428422SThibaut VARENE * We expect a precise syntax: 858c7428422SThibaut VARENE * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On 859c7428422SThibaut VARENE */ 860c7428422SThibaut VARENE static inline ssize_t 861c7428422SThibaut VARENE pdcs_autosearch_write(struct subsystem *entry, const char *buf, size_t count) 862c7428422SThibaut VARENE { 863c7428422SThibaut VARENE return pdcs_auto_write(entry, buf, count, PF_AUTOSEARCH); 864c7428422SThibaut VARENE } 865c7428422SThibaut VARENE 866*3f9edb53SThibaut Varene /** 867*3f9edb53SThibaut Varene * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input. 868*3f9edb53SThibaut Varene * @entry: An allocated and populated subsytem struct. We don't use it tho. 869*3f9edb53SThibaut Varene * @buf: The input buffer to read from. 870*3f9edb53SThibaut Varene * @count: The number of bytes to be read. 871*3f9edb53SThibaut Varene * 872*3f9edb53SThibaut Varene * This can store 16 bytes of OS-Dependent data. We use a byte-by-byte 873*3f9edb53SThibaut Varene * write approach. It's up to userspace to deal with it when constructing 874*3f9edb53SThibaut Varene * its input buffer. 875*3f9edb53SThibaut Varene */ 876*3f9edb53SThibaut Varene static ssize_t 877*3f9edb53SThibaut Varene pdcs_osdep1_write(struct subsystem *entry, const char *buf, size_t count) 878*3f9edb53SThibaut Varene { 879*3f9edb53SThibaut Varene u8 in[16]; 880*3f9edb53SThibaut Varene 881*3f9edb53SThibaut Varene if (!capable(CAP_SYS_ADMIN)) 882*3f9edb53SThibaut Varene return -EACCES; 883*3f9edb53SThibaut Varene 884*3f9edb53SThibaut Varene if (!entry || !buf || !count) 885*3f9edb53SThibaut Varene return -EINVAL; 886*3f9edb53SThibaut Varene 887*3f9edb53SThibaut Varene if (unlikely(pdcs_osid != 0x0006)) 888*3f9edb53SThibaut Varene return -EPERM; 889*3f9edb53SThibaut Varene 890*3f9edb53SThibaut Varene if (count > 16) 891*3f9edb53SThibaut Varene return -EMSGSIZE; 892*3f9edb53SThibaut Varene 893*3f9edb53SThibaut Varene /* We'll use a local copy of buf */ 894*3f9edb53SThibaut Varene memset(in, 0, 16); 895*3f9edb53SThibaut Varene memcpy(in, buf, count); 896*3f9edb53SThibaut Varene 897*3f9edb53SThibaut Varene if (pdc_stable_write(PDCS_ADDR_OSD1, &in, sizeof(in)) != PDC_OK) 898*3f9edb53SThibaut Varene return -EIO; 899*3f9edb53SThibaut Varene 900*3f9edb53SThibaut Varene return count; 901*3f9edb53SThibaut Varene } 902*3f9edb53SThibaut Varene 903*3f9edb53SThibaut Varene /** 904*3f9edb53SThibaut Varene * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input. 905*3f9edb53SThibaut Varene * @entry: An allocated and populated subsytem struct. We don't use it tho. 906*3f9edb53SThibaut Varene * @buf: The input buffer to read from. 907*3f9edb53SThibaut Varene * @count: The number of bytes to be read. 908*3f9edb53SThibaut Varene * 909*3f9edb53SThibaut Varene * This can store pdcs_size - 224 bytes of OS-Dependent data. We use a 910*3f9edb53SThibaut Varene * byte-by-byte write approach. It's up to userspace to deal with it when 911*3f9edb53SThibaut Varene * constructing its input buffer. 912*3f9edb53SThibaut Varene */ 913*3f9edb53SThibaut Varene static ssize_t 914*3f9edb53SThibaut Varene pdcs_osdep2_write(struct subsystem *entry, const char *buf, size_t count) 915*3f9edb53SThibaut Varene { 916*3f9edb53SThibaut Varene unsigned long size; 917*3f9edb53SThibaut Varene unsigned short i; 918*3f9edb53SThibaut Varene u8 in[4]; 919*3f9edb53SThibaut Varene 920*3f9edb53SThibaut Varene if (!capable(CAP_SYS_ADMIN)) 921*3f9edb53SThibaut Varene return -EACCES; 922*3f9edb53SThibaut Varene 923*3f9edb53SThibaut Varene if (!entry || !buf || !count) 924*3f9edb53SThibaut Varene return -EINVAL; 925*3f9edb53SThibaut Varene 926*3f9edb53SThibaut Varene if (unlikely(pdcs_size <= 224)) 927*3f9edb53SThibaut Varene return -ENOSYS; 928*3f9edb53SThibaut Varene 929*3f9edb53SThibaut Varene if (unlikely(pdcs_osid != 0x0006)) 930*3f9edb53SThibaut Varene return -EPERM; 931*3f9edb53SThibaut Varene 932*3f9edb53SThibaut Varene size = pdcs_size - 224; 933*3f9edb53SThibaut Varene 934*3f9edb53SThibaut Varene if (count > size) 935*3f9edb53SThibaut Varene return -EMSGSIZE; 936*3f9edb53SThibaut Varene 937*3f9edb53SThibaut Varene /* We'll use a local copy of buf */ 938*3f9edb53SThibaut Varene 939*3f9edb53SThibaut Varene for (i=0; i<count; i+=4) { 940*3f9edb53SThibaut Varene memset(in, 0, 4); 941*3f9edb53SThibaut Varene memcpy(in, buf+i, (count-i < 4) ? count-i : 4); 942*3f9edb53SThibaut Varene if (unlikely(pdc_stable_write(PDCS_ADDR_OSD2 + i, &in, 943*3f9edb53SThibaut Varene sizeof(in)) != PDC_OK)) 944*3f9edb53SThibaut Varene return -EIO; 945*3f9edb53SThibaut Varene } 946*3f9edb53SThibaut Varene 947*3f9edb53SThibaut Varene return count; 948*3f9edb53SThibaut Varene } 949*3f9edb53SThibaut Varene 950c7428422SThibaut VARENE /* The remaining attributes. */ 951c7428422SThibaut VARENE static PDCS_ATTR(size, 0444, pdcs_size_read, NULL); 952c7428422SThibaut VARENE static PDCS_ATTR(autoboot, 0644, pdcs_autoboot_read, pdcs_autoboot_write); 953c7428422SThibaut VARENE static PDCS_ATTR(autosearch, 0644, pdcs_autosearch_read, pdcs_autosearch_write); 954c7428422SThibaut VARENE static PDCS_ATTR(timer, 0444, pdcs_timer_read, NULL); 955*3f9edb53SThibaut Varene static PDCS_ATTR(osid, 0444, pdcs_osid_read, NULL); 956*3f9edb53SThibaut Varene static PDCS_ATTR(osdep1, 0600, pdcs_osdep1_read, pdcs_osdep1_write); 957*3f9edb53SThibaut Varene static PDCS_ATTR(diagnostic, 0400, pdcs_diagnostic_read, NULL); 958c7428422SThibaut VARENE static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL); 959*3f9edb53SThibaut Varene static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write); 9601da177e4SLinus Torvalds 9611da177e4SLinus Torvalds static struct subsys_attribute *pdcs_subsys_attrs[] = { 962c7428422SThibaut VARENE &pdcs_attr_size, 963c7428422SThibaut VARENE &pdcs_attr_autoboot, 964c7428422SThibaut VARENE &pdcs_attr_autosearch, 965c7428422SThibaut VARENE &pdcs_attr_timer, 966c7428422SThibaut VARENE &pdcs_attr_osid, 967*3f9edb53SThibaut Varene &pdcs_attr_osdep1, 968*3f9edb53SThibaut Varene &pdcs_attr_diagnostic, 969c7428422SThibaut VARENE &pdcs_attr_fastsize, 970*3f9edb53SThibaut Varene &pdcs_attr_osdep2, 971c7428422SThibaut VARENE NULL, 9721da177e4SLinus Torvalds }; 9731da177e4SLinus Torvalds 9741da177e4SLinus Torvalds static decl_subsys(paths, &ktype_pdcspath, NULL); 975c7428422SThibaut VARENE static decl_subsys(stable, NULL, NULL); 9761da177e4SLinus Torvalds 9771da177e4SLinus Torvalds /** 9781da177e4SLinus Torvalds * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage. 9791da177e4SLinus Torvalds * 9801da177e4SLinus Torvalds * It creates kobjects corresponding to each path entry with nice sysfs 9811da177e4SLinus Torvalds * links to the real device. This is where the magic takes place: when 9821da177e4SLinus Torvalds * registering the subsystem attributes during module init, each kobject hereby 9831da177e4SLinus Torvalds * created will show in the sysfs tree as a folder containing files as defined 9841da177e4SLinus Torvalds * by path_subsys_attr[]. 9851da177e4SLinus Torvalds */ 9861da177e4SLinus Torvalds static inline int __init 9871da177e4SLinus Torvalds pdcs_register_pathentries(void) 9881da177e4SLinus Torvalds { 9891da177e4SLinus Torvalds unsigned short i; 9901da177e4SLinus Torvalds struct pdcspath_entry *entry; 9914b991da7SThibaut VARENE int err; 9921da177e4SLinus Torvalds 993c7428422SThibaut VARENE /* Initialize the entries rw_lock before anything else */ 994c7428422SThibaut VARENE for (i = 0; (entry = pdcspath_entries[i]); i++) 995c7428422SThibaut VARENE rwlock_init(&entry->rw_lock); 996c7428422SThibaut VARENE 9971da177e4SLinus Torvalds for (i = 0; (entry = pdcspath_entries[i]); i++) { 998c7428422SThibaut VARENE write_lock(&entry->rw_lock); 999c7428422SThibaut VARENE err = pdcspath_fetch(entry); 1000c7428422SThibaut VARENE write_unlock(&entry->rw_lock); 1001c7428422SThibaut VARENE 1002c7428422SThibaut VARENE if (err < 0) 10031da177e4SLinus Torvalds continue; 10041da177e4SLinus Torvalds 10054b991da7SThibaut VARENE if ((err = kobject_set_name(&entry->kobj, "%s", entry->name))) 10064b991da7SThibaut VARENE return err; 10071da177e4SLinus Torvalds kobj_set_kset_s(entry, paths_subsys); 10084b991da7SThibaut VARENE if ((err = kobject_register(&entry->kobj))) 10094b991da7SThibaut VARENE return err; 10104b991da7SThibaut VARENE 10114b991da7SThibaut VARENE /* kobject is now registered */ 1012c7428422SThibaut VARENE write_lock(&entry->rw_lock); 10134b991da7SThibaut VARENE entry->ready = 2; 10141da177e4SLinus Torvalds 10151da177e4SLinus Torvalds /* Add a nice symlink to the real device */ 1016c7428422SThibaut VARENE if (entry->dev) 10171da177e4SLinus Torvalds sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); 1018c7428422SThibaut VARENE 1019c7428422SThibaut VARENE write_unlock(&entry->rw_lock); 10201da177e4SLinus Torvalds } 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds return 0; 10231da177e4SLinus Torvalds } 10241da177e4SLinus Torvalds 10251da177e4SLinus Torvalds /** 10261da177e4SLinus Torvalds * pdcs_unregister_pathentries - Routine called when unregistering the module. 10271da177e4SLinus Torvalds */ 10284b991da7SThibaut VARENE static inline void 10291da177e4SLinus Torvalds pdcs_unregister_pathentries(void) 10301da177e4SLinus Torvalds { 10311da177e4SLinus Torvalds unsigned short i; 10321da177e4SLinus Torvalds struct pdcspath_entry *entry; 10331da177e4SLinus Torvalds 1034c7428422SThibaut VARENE for (i = 0; (entry = pdcspath_entries[i]); i++) { 1035c7428422SThibaut VARENE read_lock(&entry->rw_lock); 10364b991da7SThibaut VARENE if (entry->ready >= 2) 10371da177e4SLinus Torvalds kobject_unregister(&entry->kobj); 1038c7428422SThibaut VARENE read_unlock(&entry->rw_lock); 1039c7428422SThibaut VARENE } 10401da177e4SLinus Torvalds } 10411da177e4SLinus Torvalds 10421da177e4SLinus Torvalds /* 1043c7428422SThibaut VARENE * For now we register the stable subsystem with the firmware subsystem 1044c7428422SThibaut VARENE * and the paths subsystem with the stable subsystem 10451da177e4SLinus Torvalds */ 10461da177e4SLinus Torvalds static int __init 10471da177e4SLinus Torvalds pdc_stable_init(void) 10481da177e4SLinus Torvalds { 10491da177e4SLinus Torvalds struct subsys_attribute *attr; 10501da177e4SLinus Torvalds int i, rc = 0, error = 0; 1051*3f9edb53SThibaut Varene u32 result; 10521da177e4SLinus Torvalds 10531da177e4SLinus Torvalds /* find the size of the stable storage */ 10541da177e4SLinus Torvalds if (pdc_stable_get_size(&pdcs_size) != PDC_OK) 10551da177e4SLinus Torvalds return -ENODEV; 10561da177e4SLinus Torvalds 1057c7428422SThibaut VARENE /* make sure we have enough data */ 1058c7428422SThibaut VARENE if (pdcs_size < 96) 1059c7428422SThibaut VARENE return -ENODATA; 10601da177e4SLinus Torvalds 1061c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX " facility v%s\n", PDCS_VERSION); 1062c7428422SThibaut VARENE 1063*3f9edb53SThibaut Varene /* get OSID */ 1064*3f9edb53SThibaut Varene if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK) 1065*3f9edb53SThibaut Varene return -EIO; 1066*3f9edb53SThibaut Varene 1067*3f9edb53SThibaut Varene /* the actual result is 16 bits away */ 1068*3f9edb53SThibaut Varene pdcs_osid = (u16)(result >> 16); 1069*3f9edb53SThibaut Varene 1070c7428422SThibaut VARENE /* For now we'll register the stable subsys within this driver */ 1071c7428422SThibaut VARENE if ((rc = firmware_register(&stable_subsys))) 10724b991da7SThibaut VARENE goto fail_firmreg; 10731da177e4SLinus Torvalds 1074c7428422SThibaut VARENE /* Don't forget the root entries */ 10751da177e4SLinus Torvalds for (i = 0; (attr = pdcs_subsys_attrs[i]) && !error; i++) 10761da177e4SLinus Torvalds if (attr->show) 1077c7428422SThibaut VARENE error = subsys_create_file(&stable_subsys, attr); 10781da177e4SLinus Torvalds 1079c7428422SThibaut VARENE /* register the paths subsys as a subsystem of stable subsys */ 1080c7428422SThibaut VARENE kset_set_kset_s(&paths_subsys, stable_subsys); 10814b991da7SThibaut VARENE if ((rc = subsystem_register(&paths_subsys))) 10824b991da7SThibaut VARENE goto fail_subsysreg; 10831da177e4SLinus Torvalds 10841da177e4SLinus Torvalds /* now we create all "files" for the paths subsys */ 10854b991da7SThibaut VARENE if ((rc = pdcs_register_pathentries())) 10864b991da7SThibaut VARENE goto fail_pdcsreg; 10871da177e4SLinus Torvalds 10884b991da7SThibaut VARENE return rc; 10894b991da7SThibaut VARENE 10904b991da7SThibaut VARENE fail_pdcsreg: 10914b991da7SThibaut VARENE pdcs_unregister_pathentries(); 10924b991da7SThibaut VARENE subsystem_unregister(&paths_subsys); 10934b991da7SThibaut VARENE 10944b991da7SThibaut VARENE fail_subsysreg: 1095c7428422SThibaut VARENE firmware_unregister(&stable_subsys); 10964b991da7SThibaut VARENE 10974b991da7SThibaut VARENE fail_firmreg: 1098c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX " bailing out\n"); 10994b991da7SThibaut VARENE return rc; 11001da177e4SLinus Torvalds } 11011da177e4SLinus Torvalds 11021da177e4SLinus Torvalds static void __exit 11031da177e4SLinus Torvalds pdc_stable_exit(void) 11041da177e4SLinus Torvalds { 11051da177e4SLinus Torvalds pdcs_unregister_pathentries(); 11061da177e4SLinus Torvalds subsystem_unregister(&paths_subsys); 11071da177e4SLinus Torvalds 1108c7428422SThibaut VARENE firmware_unregister(&stable_subsys); 11091da177e4SLinus Torvalds } 11101da177e4SLinus Torvalds 11111da177e4SLinus Torvalds 11121da177e4SLinus Torvalds module_init(pdc_stable_init); 11131da177e4SLinus Torvalds module_exit(pdc_stable_exit); 1114