145051539SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Interfaces to retrieve and set PDC Stable options (firmware) 41da177e4SLinus Torvalds * 5c7428422SThibaut VARENE * Copyright (C) 2005-2006 Thibaut VARENE <varenet@parisc-linux.org> 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * DEV NOTE: the PDC Procedures reference states that: 81da177e4SLinus Torvalds * "A minimum of 96 bytes of Stable Storage is required. Providing more than 91da177e4SLinus Torvalds * 96 bytes of Stable Storage is optional [...]. Failure to provide the 101da177e4SLinus Torvalds * optional locations from 96 to 192 results in the loss of certain 111da177e4SLinus Torvalds * functionality during boot." 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * Since locations between 96 and 192 are the various paths, most (if not 141da177e4SLinus Torvalds * all) PA-RISC machines should have them. Anyway, for safety reasons, the 15c7428422SThibaut VARENE * following code can deal with just 96 bytes of Stable Storage, and all 161da177e4SLinus Torvalds * sizes between 96 and 192 bytes (provided they are multiple of struct 1750f19697SHelge Deller * pdc_module_path size, eg: 128, 160 and 192) to provide full information. 183f9edb53SThibaut Varene * One last word: there's one path we can always count on: the primary path. 193f9edb53SThibaut Varene * Anything above 224 bytes is used for 'osdep2' OS-dependent storage area. 203f9edb53SThibaut Varene * 213f9edb53SThibaut Varene * The first OS-dependent area should always be available. Obviously, this is 223f9edb53SThibaut Varene * not true for the other one. Also bear in mind that reading/writing from/to 233f9edb53SThibaut Varene * osdep2 is much more expensive than from/to osdep1. 243f9edb53SThibaut Varene * NOTE: We do not handle the 2 bytes OS-dep area at 0x5D, nor the first 253f9edb53SThibaut Varene * 2 bytes of storage available right after OSID. That's a total of 4 bytes 263f9edb53SThibaut Varene * sacrificed: -ETOOLAZY :P 27c7428422SThibaut VARENE * 28c7428422SThibaut VARENE * The current policy wrt file permissions is: 29c7428422SThibaut VARENE * - write: root only 30c7428422SThibaut VARENE * - read: (reading triggers PDC calls) ? root only : everyone 31c7428422SThibaut VARENE * The rationale is that PDC calls could hog (DoS) the machine. 32c7428422SThibaut VARENE * 33c7428422SThibaut VARENE * TODO: 34c7428422SThibaut VARENE * - timer/fastsize write calls 351da177e4SLinus Torvalds */ 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds #undef PDCS_DEBUG 381da177e4SLinus Torvalds #ifdef PDCS_DEBUG 391da177e4SLinus Torvalds #define DPRINTK(fmt, args...) printk(KERN_DEBUG fmt, ## args) 401da177e4SLinus Torvalds #else 411da177e4SLinus Torvalds #define DPRINTK(fmt, args...) 421da177e4SLinus Torvalds #endif 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds #include <linux/module.h> 451da177e4SLinus Torvalds #include <linux/init.h> 461da177e4SLinus Torvalds #include <linux/kernel.h> 471da177e4SLinus Torvalds #include <linux/string.h> 48c59ede7bSRandy.Dunlap #include <linux/capability.h> 491da177e4SLinus Torvalds #include <linux/ctype.h> 501da177e4SLinus Torvalds #include <linux/sysfs.h> 511da177e4SLinus Torvalds #include <linux/kobject.h> 521da177e4SLinus Torvalds #include <linux/device.h> 531da177e4SLinus Torvalds #include <linux/errno.h> 54c7428422SThibaut VARENE #include <linux/spinlock.h> 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds #include <asm/pdc.h> 571da177e4SLinus Torvalds #include <asm/page.h> 587c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 591da177e4SLinus Torvalds #include <asm/hardware.h> 601da177e4SLinus Torvalds 613f9edb53SThibaut Varene #define PDCS_VERSION "0.30" 62c7428422SThibaut VARENE #define PDCS_PREFIX "PDC Stable Storage" 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds #define PDCS_ADDR_PPRI 0x00 651da177e4SLinus Torvalds #define PDCS_ADDR_OSID 0x40 663f9edb53SThibaut Varene #define PDCS_ADDR_OSD1 0x48 673f9edb53SThibaut Varene #define PDCS_ADDR_DIAG 0x58 681da177e4SLinus Torvalds #define PDCS_ADDR_FSIZ 0x5C 691da177e4SLinus Torvalds #define PDCS_ADDR_PCON 0x60 701da177e4SLinus Torvalds #define PDCS_ADDR_PALT 0x80 711da177e4SLinus Torvalds #define PDCS_ADDR_PKBD 0xA0 723f9edb53SThibaut Varene #define PDCS_ADDR_OSD2 0xE0 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds MODULE_AUTHOR("Thibaut VARENE <varenet@parisc-linux.org>"); 751da177e4SLinus Torvalds MODULE_DESCRIPTION("sysfs interface to HP PDC Stable Storage data"); 761da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 771da177e4SLinus Torvalds MODULE_VERSION(PDCS_VERSION); 781da177e4SLinus Torvalds 79c7428422SThibaut VARENE /* holds Stable Storage size. Initialized once and for all, no lock needed */ 808039de10SHelge Deller static unsigned long pdcs_size __read_mostly; 811da177e4SLinus Torvalds 823f9edb53SThibaut Varene /* holds OS ID. Initialized once and for all, hopefully to 0x0006 */ 833f9edb53SThibaut Varene static u16 pdcs_osid __read_mostly; 843f9edb53SThibaut Varene 851da177e4SLinus Torvalds /* This struct defines what we need to deal with a parisc pdc path entry */ 861da177e4SLinus Torvalds struct pdcspath_entry { 87c7428422SThibaut VARENE rwlock_t rw_lock; /* to protect path entry access */ 881da177e4SLinus Torvalds short ready; /* entry record is valid if != 0 */ 891da177e4SLinus Torvalds unsigned long addr; /* entry address in stable storage */ 901da177e4SLinus Torvalds char *name; /* entry name */ 9150f19697SHelge Deller struct pdc_module_path devpath; /* device path in parisc representation */ 921da177e4SLinus Torvalds struct device *dev; /* corresponding device */ 931da177e4SLinus Torvalds struct kobject kobj; 941da177e4SLinus Torvalds }; 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds struct pdcspath_attribute { 971da177e4SLinus Torvalds struct attribute attr; 981da177e4SLinus Torvalds ssize_t (*show)(struct pdcspath_entry *entry, char *buf); 991da177e4SLinus Torvalds ssize_t (*store)(struct pdcspath_entry *entry, const char *buf, size_t count); 1001da177e4SLinus Torvalds }; 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds #define PDCSPATH_ENTRY(_addr, _name) \ 1031da177e4SLinus Torvalds struct pdcspath_entry pdcspath_entry_##_name = { \ 1041da177e4SLinus Torvalds .ready = 0, \ 1051da177e4SLinus Torvalds .addr = _addr, \ 1061da177e4SLinus Torvalds .name = __stringify(_name), \ 1071da177e4SLinus Torvalds }; 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds #define PDCS_ATTR(_name, _mode, _show, _store) \ 1107f548217SGreg Kroah-Hartman struct kobj_attribute pdcs_attr_##_name = { \ 1117b595756STejun Heo .attr = {.name = __stringify(_name), .mode = _mode}, \ 1121da177e4SLinus Torvalds .show = _show, \ 1131da177e4SLinus Torvalds .store = _store, \ 1141da177e4SLinus Torvalds }; 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds #define PATHS_ATTR(_name, _mode, _show, _store) \ 1171da177e4SLinus Torvalds struct pdcspath_attribute paths_attr_##_name = { \ 1187b595756STejun Heo .attr = {.name = __stringify(_name), .mode = _mode}, \ 1191da177e4SLinus Torvalds .show = _show, \ 1201da177e4SLinus Torvalds .store = _store, \ 1211da177e4SLinus Torvalds }; 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds #define to_pdcspath_attribute(_attr) container_of(_attr, struct pdcspath_attribute, attr) 1241da177e4SLinus Torvalds #define to_pdcspath_entry(obj) container_of(obj, struct pdcspath_entry, kobj) 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds /** 1271da177e4SLinus Torvalds * pdcspath_fetch - This function populates the path entry structs. 1281da177e4SLinus Torvalds * @entry: A pointer to an allocated pdcspath_entry. 1291da177e4SLinus Torvalds * 1301da177e4SLinus Torvalds * The general idea is that you don't read from the Stable Storage every time 13125985edcSLucas De Marchi * you access the files provided by the facilities. We store a copy of the 1321da177e4SLinus Torvalds * content of the stable storage WRT various paths in these structs. We read 1331da177e4SLinus Torvalds * these structs when reading the files, and we will write to these structs when 1341da177e4SLinus Torvalds * writing to the files, and only then write them back to the Stable Storage. 135c7428422SThibaut VARENE * 136c7428422SThibaut VARENE * This function expects to be called with @entry->rw_lock write-hold. 1371da177e4SLinus Torvalds */ 1381da177e4SLinus Torvalds static int 1391da177e4SLinus Torvalds pdcspath_fetch(struct pdcspath_entry *entry) 1401da177e4SLinus Torvalds { 14150f19697SHelge Deller struct pdc_module_path *devpath; 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds if (!entry) 1441da177e4SLinus Torvalds return -EINVAL; 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds devpath = &entry->devpath; 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds DPRINTK("%s: fetch: 0x%p, 0x%p, addr: 0x%lx\n", __func__, 1491da177e4SLinus Torvalds entry, devpath, entry->addr); 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds /* addr, devpath and count must be word aligned */ 1521da177e4SLinus Torvalds if (pdc_stable_read(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) 1531da177e4SLinus Torvalds return -EIO; 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds /* Find the matching device. 15650f19697SHelge Deller NOTE: hardware_path overlays with pdc_module_path, so the nice cast can 1571da177e4SLinus Torvalds be used */ 1581da177e4SLinus Torvalds entry->dev = hwpath_to_device((struct hardware_path *)devpath); 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds entry->ready = 1; 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds return 0; 1651da177e4SLinus Torvalds } 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds /** 1681da177e4SLinus Torvalds * pdcspath_store - This function writes a path to stable storage. 1691da177e4SLinus Torvalds * @entry: A pointer to an allocated pdcspath_entry. 1701da177e4SLinus Torvalds * 1711da177e4SLinus Torvalds * It can be used in two ways: either by passing it a preset devpath struct 1721da177e4SLinus Torvalds * containing an already computed hardware path, or by passing it a device 1731da177e4SLinus Torvalds * pointer, from which it'll find out the corresponding hardware path. 1741da177e4SLinus Torvalds * For now we do not handle the case where there's an error in writing to the 1751da177e4SLinus Torvalds * Stable Storage area, so you'd better not mess up the data :P 176c7428422SThibaut VARENE * 177c7428422SThibaut VARENE * This function expects to be called with @entry->rw_lock write-hold. 1781da177e4SLinus Torvalds */ 179c7428422SThibaut VARENE static void 1801da177e4SLinus Torvalds pdcspath_store(struct pdcspath_entry *entry) 1811da177e4SLinus Torvalds { 18250f19697SHelge Deller struct pdc_module_path *devpath; 1831da177e4SLinus Torvalds 184c7428422SThibaut VARENE BUG_ON(!entry); 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds devpath = &entry->devpath; 1871da177e4SLinus Torvalds 1881da177e4SLinus Torvalds /* We expect the caller to set the ready flag to 0 if the hardware 1891da177e4SLinus Torvalds path struct provided is invalid, so that we know we have to fill it. 1901da177e4SLinus Torvalds First case, we don't have a preset hwpath... */ 1911da177e4SLinus Torvalds if (!entry->ready) { 1921da177e4SLinus Torvalds /* ...but we have a device, map it */ 193c7428422SThibaut VARENE BUG_ON(!entry->dev); 1941da177e4SLinus Torvalds device_to_hwpath(entry->dev, (struct hardware_path *)devpath); 1951da177e4SLinus Torvalds } 1961da177e4SLinus Torvalds /* else, we expect the provided hwpath to be valid. */ 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds DPRINTK("%s: store: 0x%p, 0x%p, addr: 0x%lx\n", __func__, 1991da177e4SLinus Torvalds entry, devpath, entry->addr); 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds /* addr, devpath and count must be word aligned */ 20293c3e913SJulia Lawall if (pdc_stable_write(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) 20393c3e913SJulia Lawall WARN(1, KERN_ERR "%s: an error occurred when writing to PDC.\n" 2041da177e4SLinus Torvalds "It is likely that the Stable Storage data has been corrupted.\n" 2051da177e4SLinus Torvalds "Please check it carefully upon next reboot.\n", __func__); 2061da177e4SLinus Torvalds 2074b991da7SThibaut VARENE /* kobject is already registered */ 2084b991da7SThibaut VARENE entry->ready = 2; 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds /** 2141da177e4SLinus Torvalds * pdcspath_hwpath_read - This function handles hardware path pretty printing. 2151da177e4SLinus Torvalds * @entry: An allocated and populated pdscpath_entry struct. 2161da177e4SLinus Torvalds * @buf: The output buffer to write to. 2171da177e4SLinus Torvalds * 2181da177e4SLinus Torvalds * We will call this function to format the output of the hwpath attribute file. 2191da177e4SLinus Torvalds */ 2201da177e4SLinus Torvalds static ssize_t 2211da177e4SLinus Torvalds pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf) 2221da177e4SLinus Torvalds { 2231da177e4SLinus Torvalds char *out = buf; 22450f19697SHelge Deller struct pdc_module_path *devpath; 225c7428422SThibaut VARENE short i; 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds if (!entry || !buf) 2281da177e4SLinus Torvalds return -EINVAL; 2291da177e4SLinus Torvalds 230c7428422SThibaut VARENE read_lock(&entry->rw_lock); 2311da177e4SLinus Torvalds devpath = &entry->devpath; 232c7428422SThibaut VARENE i = entry->ready; 233c7428422SThibaut VARENE read_unlock(&entry->rw_lock); 2341da177e4SLinus Torvalds 235c7428422SThibaut VARENE if (!i) /* entry is not ready */ 2361da177e4SLinus Torvalds return -ENODATA; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds for (i = 0; i < 6; i++) { 23950f19697SHelge Deller if (devpath->path.bc[i] < 0) 2401da177e4SLinus Torvalds continue; 24150f19697SHelge Deller out += sprintf(out, "%d/", devpath->path.bc[i]); 2421da177e4SLinus Torvalds } 24350f19697SHelge Deller out += sprintf(out, "%u\n", (unsigned char)devpath->path.mod); 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds return out - buf; 2461da177e4SLinus Torvalds } 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds /** 2491da177e4SLinus Torvalds * pdcspath_hwpath_write - This function handles hardware path modifying. 2501da177e4SLinus Torvalds * @entry: An allocated and populated pdscpath_entry struct. 2511da177e4SLinus Torvalds * @buf: The input buffer to read from. 2521da177e4SLinus Torvalds * @count: The number of bytes to be read. 2531da177e4SLinus Torvalds * 2541da177e4SLinus Torvalds * We will call this function to change the current hardware path. 2551da177e4SLinus Torvalds * Hardware paths are to be given '/'-delimited, without brackets. 256c7428422SThibaut VARENE * We make sure that the provided path actually maps to an existing 2571da177e4SLinus Torvalds * device, BUT nothing would prevent some foolish user to set the path to some 2581da177e4SLinus Torvalds * PCI bridge or even a CPU... 2591da177e4SLinus Torvalds * A better work around would be to make sure we are at the end of a device tree 2601da177e4SLinus Torvalds * for instance, but it would be IMHO beyond the simple scope of that driver. 2611da177e4SLinus Torvalds * The aim is to provide a facility. Data correctness is left to userland. 2621da177e4SLinus Torvalds */ 2631da177e4SLinus Torvalds static ssize_t 2641da177e4SLinus Torvalds pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t count) 2651da177e4SLinus Torvalds { 2661da177e4SLinus Torvalds struct hardware_path hwpath; 2671da177e4SLinus Torvalds unsigned short i; 268c735483dSHelge Deller char in[64], *temp; 2691da177e4SLinus Torvalds struct device *dev; 27026f03249SKyle McMartin int ret; 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds if (!entry || !buf || !count) 2731da177e4SLinus Torvalds return -EINVAL; 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds /* We'll use a local copy of buf */ 276c735483dSHelge Deller count = min_t(size_t, count, sizeof(in)-1); 277f2193bb2SXu Panda strscpy(in, buf, count + 1); 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds /* Let's clean up the target. 0xff is a blank pattern */ 2801da177e4SLinus Torvalds memset(&hwpath, 0xff, sizeof(hwpath)); 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds /* First, pick the mod field (the last one of the input string) */ 2831da177e4SLinus Torvalds if (!(temp = strrchr(in, '/'))) 2841da177e4SLinus Torvalds return -EINVAL; 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds hwpath.mod = simple_strtoul(temp+1, NULL, 10); 2871da177e4SLinus Torvalds in[temp-in] = '\0'; /* truncate the remaining string. just precaution */ 2881da177e4SLinus Torvalds DPRINTK("%s: mod: %d\n", __func__, hwpath.mod); 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds /* Then, loop for each delimiter, making sure we don't have too many. 2911da177e4SLinus Torvalds we write the bc fields in a down-top way. No matter what, we stop 2921da177e4SLinus Torvalds before writing the last field. If there are too many fields anyway, 2931da177e4SLinus Torvalds then the user is a moron and it'll be caught up later when we'll 2941da177e4SLinus Torvalds check the consistency of the given hwpath. */ 2951da177e4SLinus Torvalds for (i=5; ((temp = strrchr(in, '/'))) && (temp-in > 0) && (likely(i)); i--) { 2961da177e4SLinus Torvalds hwpath.bc[i] = simple_strtoul(temp+1, NULL, 10); 2971da177e4SLinus Torvalds in[temp-in] = '\0'; 29850f19697SHelge Deller DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.path.bc[i]); 2991da177e4SLinus Torvalds } 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds /* Store the final field */ 3021da177e4SLinus Torvalds hwpath.bc[i] = simple_strtoul(in, NULL, 10); 30350f19697SHelge Deller DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.path.bc[i]); 3041da177e4SLinus Torvalds 3051da177e4SLinus Torvalds /* Now we check that the user isn't trying to lure us */ 3061da177e4SLinus Torvalds if (!(dev = hwpath_to_device((struct hardware_path *)&hwpath))) { 3071da177e4SLinus Torvalds printk(KERN_WARNING "%s: attempt to set invalid \"%s\" " 3081da177e4SLinus Torvalds "hardware path: %s\n", __func__, entry->name, buf); 3091da177e4SLinus Torvalds return -EINVAL; 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds /* So far so good, let's get in deep */ 313c7428422SThibaut VARENE write_lock(&entry->rw_lock); 3141da177e4SLinus Torvalds entry->ready = 0; 3151da177e4SLinus Torvalds entry->dev = dev; 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds /* Now, dive in. Write back to the hardware */ 318c7428422SThibaut VARENE pdcspath_store(entry); 3191da177e4SLinus Torvalds 3201da177e4SLinus Torvalds /* Update the symlink to the real device */ 3211da177e4SLinus Torvalds sysfs_remove_link(&entry->kobj, "device"); 32293964fd4SJames Bottomley write_unlock(&entry->rw_lock); 32393964fd4SJames Bottomley 32426f03249SKyle McMartin ret = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); 32526f03249SKyle McMartin WARN_ON(ret); 32626f03249SKyle McMartin 327c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" path to \"%s\"\n", 3281da177e4SLinus Torvalds entry->name, buf); 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds return count; 3311da177e4SLinus Torvalds } 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds /** 3341da177e4SLinus Torvalds * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing. 3351da177e4SLinus Torvalds * @entry: An allocated and populated pdscpath_entry struct. 3361da177e4SLinus Torvalds * @buf: The output buffer to write to. 3371da177e4SLinus Torvalds * 3381da177e4SLinus Torvalds * We will call this function to format the output of the layer attribute file. 3391da177e4SLinus Torvalds */ 3401da177e4SLinus Torvalds static ssize_t 3411da177e4SLinus Torvalds pdcspath_layer_read(struct pdcspath_entry *entry, char *buf) 3421da177e4SLinus Torvalds { 3431da177e4SLinus Torvalds char *out = buf; 34450f19697SHelge Deller struct pdc_module_path *devpath; 345c7428422SThibaut VARENE short i; 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds if (!entry || !buf) 3481da177e4SLinus Torvalds return -EINVAL; 3491da177e4SLinus Torvalds 350c7428422SThibaut VARENE read_lock(&entry->rw_lock); 3511da177e4SLinus Torvalds devpath = &entry->devpath; 352c7428422SThibaut VARENE i = entry->ready; 353c7428422SThibaut VARENE read_unlock(&entry->rw_lock); 3541da177e4SLinus Torvalds 355c7428422SThibaut VARENE if (!i) /* entry is not ready */ 3561da177e4SLinus Torvalds return -ENODATA; 3571da177e4SLinus Torvalds 358447c233dSRoel Kluin for (i = 0; i < 6 && devpath->layers[i]; i++) 3591da177e4SLinus Torvalds out += sprintf(out, "%u ", devpath->layers[i]); 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds out += sprintf(out, "\n"); 3621da177e4SLinus Torvalds 3631da177e4SLinus Torvalds return out - buf; 3641da177e4SLinus Torvalds } 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds /** 3671da177e4SLinus Torvalds * pdcspath_layer_write - This function handles extended layer modifying. 3681da177e4SLinus Torvalds * @entry: An allocated and populated pdscpath_entry struct. 3691da177e4SLinus Torvalds * @buf: The input buffer to read from. 3701da177e4SLinus Torvalds * @count: The number of bytes to be read. 3711da177e4SLinus Torvalds * 3721da177e4SLinus Torvalds * We will call this function to change the current layer value. 3731da177e4SLinus Torvalds * Layers are to be given '.'-delimited, without brackets. 3741da177e4SLinus Torvalds * XXX beware we are far less checky WRT input data provided than for hwpath. 3751da177e4SLinus Torvalds * Potential harm can be done, since there's no way to check the validity of 3761da177e4SLinus Torvalds * the layer fields. 3771da177e4SLinus Torvalds */ 3781da177e4SLinus Torvalds static ssize_t 3791da177e4SLinus Torvalds pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count) 3801da177e4SLinus Torvalds { 3811da177e4SLinus Torvalds unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */ 3821da177e4SLinus Torvalds unsigned short i; 383c735483dSHelge Deller char in[64], *temp; 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds if (!entry || !buf || !count) 3861da177e4SLinus Torvalds return -EINVAL; 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds /* We'll use a local copy of buf */ 389c735483dSHelge Deller count = min_t(size_t, count, sizeof(in)-1); 390f2193bb2SXu Panda strscpy(in, buf, count + 1); 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvalds /* Let's clean up the target. 0 is a blank pattern */ 3931da177e4SLinus Torvalds memset(&layers, 0, sizeof(layers)); 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds /* First, pick the first layer */ 3961da177e4SLinus Torvalds if (unlikely(!isdigit(*in))) 3971da177e4SLinus Torvalds return -EINVAL; 3981da177e4SLinus Torvalds layers[0] = simple_strtoul(in, NULL, 10); 3991da177e4SLinus Torvalds DPRINTK("%s: layer[0]: %d\n", __func__, layers[0]); 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds temp = in; 4021da177e4SLinus Torvalds for (i=1; ((temp = strchr(temp, '.'))) && (likely(i<6)); i++) { 4031da177e4SLinus Torvalds if (unlikely(!isdigit(*(++temp)))) 4041da177e4SLinus Torvalds return -EINVAL; 4051da177e4SLinus Torvalds layers[i] = simple_strtoul(temp, NULL, 10); 4061da177e4SLinus Torvalds DPRINTK("%s: layer[%d]: %d\n", __func__, i, layers[i]); 4071da177e4SLinus Torvalds } 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds /* So far so good, let's get in deep */ 410c7428422SThibaut VARENE write_lock(&entry->rw_lock); 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds /* First, overwrite the current layers with the new ones, not touching 4131da177e4SLinus Torvalds the hardware path. */ 4141da177e4SLinus Torvalds memcpy(&entry->devpath.layers, &layers, sizeof(layers)); 4151da177e4SLinus Torvalds 4161da177e4SLinus Torvalds /* Now, dive in. Write back to the hardware */ 417c7428422SThibaut VARENE pdcspath_store(entry); 418c7428422SThibaut VARENE write_unlock(&entry->rw_lock); 4191da177e4SLinus Torvalds 420c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" layers to \"%s\"\n", 4211da177e4SLinus Torvalds entry->name, buf); 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvalds return count; 4241da177e4SLinus Torvalds } 4251da177e4SLinus Torvalds 4261da177e4SLinus Torvalds /** 4271da177e4SLinus Torvalds * pdcspath_attr_show - Generic read function call wrapper. 4281da177e4SLinus Torvalds * @kobj: The kobject to get info from. 4291da177e4SLinus Torvalds * @attr: The attribute looked upon. 4301da177e4SLinus Torvalds * @buf: The output buffer. 4311da177e4SLinus Torvalds */ 4321da177e4SLinus Torvalds static ssize_t 4331da177e4SLinus Torvalds pdcspath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) 4341da177e4SLinus Torvalds { 4351da177e4SLinus Torvalds struct pdcspath_entry *entry = to_pdcspath_entry(kobj); 4361da177e4SLinus Torvalds struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr); 4371da177e4SLinus Torvalds ssize_t ret = 0; 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds if (pdcs_attr->show) 4401da177e4SLinus Torvalds ret = pdcs_attr->show(entry, buf); 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds return ret; 4431da177e4SLinus Torvalds } 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds /** 4461da177e4SLinus Torvalds * pdcspath_attr_store - Generic write function call wrapper. 4471da177e4SLinus Torvalds * @kobj: The kobject to write info to. 4481da177e4SLinus Torvalds * @attr: The attribute to be modified. 4491da177e4SLinus Torvalds * @buf: The input buffer. 4501da177e4SLinus Torvalds * @count: The size of the buffer. 4511da177e4SLinus Torvalds */ 4521da177e4SLinus Torvalds static ssize_t 4531da177e4SLinus Torvalds pdcspath_attr_store(struct kobject *kobj, struct attribute *attr, 4541da177e4SLinus Torvalds const char *buf, size_t count) 4551da177e4SLinus Torvalds { 4561da177e4SLinus Torvalds struct pdcspath_entry *entry = to_pdcspath_entry(kobj); 4571da177e4SLinus Torvalds struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr); 4581da177e4SLinus Torvalds ssize_t ret = 0; 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds if (!capable(CAP_SYS_ADMIN)) 4611da177e4SLinus Torvalds return -EACCES; 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds if (pdcs_attr->store) 4641da177e4SLinus Torvalds ret = pdcs_attr->store(entry, buf, count); 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds return ret; 4671da177e4SLinus Torvalds } 4681da177e4SLinus Torvalds 46952cf25d0SEmese Revfy static const struct sysfs_ops pdcspath_attr_ops = { 4701da177e4SLinus Torvalds .show = pdcspath_attr_show, 4711da177e4SLinus Torvalds .store = pdcspath_attr_store, 4721da177e4SLinus Torvalds }; 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds /* These are the two attributes of any PDC path. */ 475c7428422SThibaut VARENE static PATHS_ATTR(hwpath, 0644, pdcspath_hwpath_read, pdcspath_hwpath_write); 476c7428422SThibaut VARENE static PATHS_ATTR(layer, 0644, pdcspath_layer_read, pdcspath_layer_write); 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds static struct attribute *paths_subsys_attrs[] = { 4791da177e4SLinus Torvalds &paths_attr_hwpath.attr, 4801da177e4SLinus Torvalds &paths_attr_layer.attr, 4811da177e4SLinus Torvalds NULL, 4821da177e4SLinus Torvalds }; 48375c09aadSGreg Kroah-Hartman ATTRIBUTE_GROUPS(paths_subsys); 4841da177e4SLinus Torvalds 4851da177e4SLinus Torvalds /* Specific kobject type for our PDC paths */ 486*75df38aaSHongbo Li static const struct kobj_type ktype_pdcspath = { 4871da177e4SLinus Torvalds .sysfs_ops = &pdcspath_attr_ops, 48875c09aadSGreg Kroah-Hartman .default_groups = paths_subsys_groups, 4891da177e4SLinus Torvalds }; 4901da177e4SLinus Torvalds 4911da177e4SLinus Torvalds /* We hard define the 4 types of path we expect to find */ 4921da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PPRI, primary); 4931da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PCON, console); 4941da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PALT, alternative); 4951da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PKBD, keyboard); 4961da177e4SLinus Torvalds 4971da177e4SLinus Torvalds /* An array containing all PDC paths we will deal with */ 4981da177e4SLinus Torvalds static struct pdcspath_entry *pdcspath_entries[] = { 4991da177e4SLinus Torvalds &pdcspath_entry_primary, 5001da177e4SLinus Torvalds &pdcspath_entry_alternative, 5011da177e4SLinus Torvalds &pdcspath_entry_console, 5021da177e4SLinus Torvalds &pdcspath_entry_keyboard, 5031da177e4SLinus Torvalds NULL, 5041da177e4SLinus Torvalds }; 5051da177e4SLinus Torvalds 506c7428422SThibaut VARENE 507c7428422SThibaut VARENE /* For more insight of what's going on here, refer to PDC Procedures doc, 508c7428422SThibaut VARENE * Section PDC_STABLE */ 509c7428422SThibaut VARENE 5101da177e4SLinus Torvalds /** 511c7428422SThibaut VARENE * pdcs_size_read - Stable Storage size output. 512f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 513f28a9877SHelge Deller * @attr: The kobject attributes. 5141da177e4SLinus Torvalds * @buf: The output buffer to write to. 5151da177e4SLinus Torvalds */ 5167f548217SGreg Kroah-Hartman static ssize_t pdcs_size_read(struct kobject *kobj, 5177f548217SGreg Kroah-Hartman struct kobj_attribute *attr, 5187f548217SGreg Kroah-Hartman char *buf) 5191da177e4SLinus Torvalds { 5201da177e4SLinus Torvalds char *out = buf; 5211da177e4SLinus Torvalds 5227f548217SGreg Kroah-Hartman if (!buf) 5231da177e4SLinus Torvalds return -EINVAL; 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds /* show the size of the stable storage */ 526c7428422SThibaut VARENE out += sprintf(out, "%ld\n", pdcs_size); 5271da177e4SLinus Torvalds 528c7428422SThibaut VARENE return out - buf; 529c7428422SThibaut VARENE } 5301da177e4SLinus Torvalds 531c7428422SThibaut VARENE /** 532c7428422SThibaut VARENE * pdcs_auto_read - Stable Storage autoboot/search flag output. 533f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 534f28a9877SHelge Deller * @attr: The kobject attributes. 535c7428422SThibaut VARENE * @buf: The output buffer to write to. 536c7428422SThibaut VARENE * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag 537c7428422SThibaut VARENE */ 5387f548217SGreg Kroah-Hartman static ssize_t pdcs_auto_read(struct kobject *kobj, 5397f548217SGreg Kroah-Hartman struct kobj_attribute *attr, 5407f548217SGreg Kroah-Hartman char *buf, int knob) 541c7428422SThibaut VARENE { 542c7428422SThibaut VARENE char *out = buf; 543c7428422SThibaut VARENE struct pdcspath_entry *pathentry; 544c7428422SThibaut VARENE 5457f548217SGreg Kroah-Hartman if (!buf) 546c7428422SThibaut VARENE return -EINVAL; 547c7428422SThibaut VARENE 548c7428422SThibaut VARENE /* Current flags are stored in primary boot path entry */ 549c7428422SThibaut VARENE pathentry = &pdcspath_entry_primary; 550c7428422SThibaut VARENE 551c7428422SThibaut VARENE read_lock(&pathentry->rw_lock); 55250f19697SHelge Deller out += sprintf(out, "%s\n", (pathentry->devpath.path.flags & knob) ? 553c7428422SThibaut VARENE "On" : "Off"); 554c7428422SThibaut VARENE read_unlock(&pathentry->rw_lock); 555c7428422SThibaut VARENE 556c7428422SThibaut VARENE return out - buf; 557c7428422SThibaut VARENE } 558c7428422SThibaut VARENE 559c7428422SThibaut VARENE /** 560c7428422SThibaut VARENE * pdcs_autoboot_read - Stable Storage autoboot flag output. 561f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 562f28a9877SHelge Deller * @attr: The kobject attributes. 563c7428422SThibaut VARENE * @buf: The output buffer to write to. 564c7428422SThibaut VARENE */ 5657f548217SGreg Kroah-Hartman static ssize_t pdcs_autoboot_read(struct kobject *kobj, 5667f548217SGreg Kroah-Hartman struct kobj_attribute *attr, char *buf) 567c7428422SThibaut VARENE { 5687f548217SGreg Kroah-Hartman return pdcs_auto_read(kobj, attr, buf, PF_AUTOBOOT); 569c7428422SThibaut VARENE } 570c7428422SThibaut VARENE 571c7428422SThibaut VARENE /** 572c7428422SThibaut VARENE * pdcs_autosearch_read - Stable Storage autoboot flag output. 573f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 574f28a9877SHelge Deller * @attr: The kobject attributes. 575c7428422SThibaut VARENE * @buf: The output buffer to write to. 576c7428422SThibaut VARENE */ 5777f548217SGreg Kroah-Hartman static ssize_t pdcs_autosearch_read(struct kobject *kobj, 5787f548217SGreg Kroah-Hartman struct kobj_attribute *attr, char *buf) 579c7428422SThibaut VARENE { 5807f548217SGreg Kroah-Hartman return pdcs_auto_read(kobj, attr, buf, PF_AUTOSEARCH); 581c7428422SThibaut VARENE } 582c7428422SThibaut VARENE 583c7428422SThibaut VARENE /** 584c7428422SThibaut VARENE * pdcs_timer_read - Stable Storage timer count output (in seconds). 585f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 586f28a9877SHelge Deller * @attr: The kobject attributes. 587c7428422SThibaut VARENE * @buf: The output buffer to write to. 588c7428422SThibaut VARENE * 589c7428422SThibaut VARENE * The value of the timer field correponds to a number of seconds in powers of 2. 590c7428422SThibaut VARENE */ 5917f548217SGreg Kroah-Hartman static ssize_t pdcs_timer_read(struct kobject *kobj, 5927f548217SGreg Kroah-Hartman struct kobj_attribute *attr, char *buf) 593c7428422SThibaut VARENE { 594c7428422SThibaut VARENE char *out = buf; 595c7428422SThibaut VARENE struct pdcspath_entry *pathentry; 596c7428422SThibaut VARENE 5977f548217SGreg Kroah-Hartman if (!buf) 598c7428422SThibaut VARENE return -EINVAL; 599c7428422SThibaut VARENE 600c7428422SThibaut VARENE /* Current flags are stored in primary boot path entry */ 601c7428422SThibaut VARENE pathentry = &pdcspath_entry_primary; 602c7428422SThibaut VARENE 603c7428422SThibaut VARENE /* print the timer value in seconds */ 604c7428422SThibaut VARENE read_lock(&pathentry->rw_lock); 60550f19697SHelge Deller out += sprintf(out, "%u\n", (pathentry->devpath.path.flags & PF_TIMER) ? 60650f19697SHelge Deller (1 << (pathentry->devpath.path.flags & PF_TIMER)) : 0); 607c7428422SThibaut VARENE read_unlock(&pathentry->rw_lock); 608c7428422SThibaut VARENE 609c7428422SThibaut VARENE return out - buf; 610c7428422SThibaut VARENE } 611c7428422SThibaut VARENE 612c7428422SThibaut VARENE /** 613c7428422SThibaut VARENE * pdcs_osid_read - Stable Storage OS ID register output. 614f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 615f28a9877SHelge Deller * @attr: The kobject attributes. 616c7428422SThibaut VARENE * @buf: The output buffer to write to. 617c7428422SThibaut VARENE */ 6187f548217SGreg Kroah-Hartman static ssize_t pdcs_osid_read(struct kobject *kobj, 6197f548217SGreg Kroah-Hartman struct kobj_attribute *attr, char *buf) 620c7428422SThibaut VARENE { 621c7428422SThibaut VARENE char *out = buf; 622c7428422SThibaut VARENE 6237f548217SGreg Kroah-Hartman if (!buf) 624c7428422SThibaut VARENE return -EINVAL; 6251da177e4SLinus Torvalds 62667a061a1SKyle McMartin out += sprintf(out, "%s dependent data (0x%.4x)\n", 62767a061a1SKyle McMartin os_id_to_string(pdcs_osid), pdcs_osid); 6283f9edb53SThibaut Varene 6293f9edb53SThibaut Varene return out - buf; 6303f9edb53SThibaut Varene } 6313f9edb53SThibaut Varene 6323f9edb53SThibaut Varene /** 6333f9edb53SThibaut Varene * pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output. 634f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 635f28a9877SHelge Deller * @attr: The kobject attributes. 6363f9edb53SThibaut Varene * @buf: The output buffer to write to. 6373f9edb53SThibaut Varene * 6383f9edb53SThibaut Varene * This can hold 16 bytes of OS-Dependent data. 6393f9edb53SThibaut Varene */ 6407f548217SGreg Kroah-Hartman static ssize_t pdcs_osdep1_read(struct kobject *kobj, 6417f548217SGreg Kroah-Hartman struct kobj_attribute *attr, char *buf) 6423f9edb53SThibaut Varene { 6433f9edb53SThibaut Varene char *out = buf; 6443f9edb53SThibaut Varene u32 result[4]; 6453f9edb53SThibaut Varene 6467f548217SGreg Kroah-Hartman if (!buf) 6473f9edb53SThibaut Varene return -EINVAL; 6483f9edb53SThibaut Varene 6493f9edb53SThibaut Varene if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK) 6503f9edb53SThibaut Varene return -EIO; 6513f9edb53SThibaut Varene 6523f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result[0]); 6533f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result[1]); 6543f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result[2]); 6553f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result[3]); 6563f9edb53SThibaut Varene 6573f9edb53SThibaut Varene return out - buf; 6583f9edb53SThibaut Varene } 6593f9edb53SThibaut Varene 6603f9edb53SThibaut Varene /** 6613f9edb53SThibaut Varene * pdcs_diagnostic_read - Stable Storage Diagnostic register output. 662f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 663f28a9877SHelge Deller * @attr: The kobject attributes. 6643f9edb53SThibaut Varene * @buf: The output buffer to write to. 6653f9edb53SThibaut Varene * 6663f9edb53SThibaut Varene * I have NFC how to interpret the content of that register ;-). 6673f9edb53SThibaut Varene */ 6687f548217SGreg Kroah-Hartman static ssize_t pdcs_diagnostic_read(struct kobject *kobj, 6697f548217SGreg Kroah-Hartman struct kobj_attribute *attr, char *buf) 6703f9edb53SThibaut Varene { 6713f9edb53SThibaut Varene char *out = buf; 6723f9edb53SThibaut Varene u32 result; 6733f9edb53SThibaut Varene 6747f548217SGreg Kroah-Hartman if (!buf) 6753f9edb53SThibaut Varene return -EINVAL; 6763f9edb53SThibaut Varene 6773f9edb53SThibaut Varene /* get diagnostic */ 6783f9edb53SThibaut Varene if (pdc_stable_read(PDCS_ADDR_DIAG, &result, sizeof(result)) != PDC_OK) 6793f9edb53SThibaut Varene return -EIO; 6803f9edb53SThibaut Varene 6813f9edb53SThibaut Varene out += sprintf(out, "0x%.4x\n", (result >> 16)); 682c7428422SThibaut VARENE 683c7428422SThibaut VARENE return out - buf; 684c7428422SThibaut VARENE } 685c7428422SThibaut VARENE 686c7428422SThibaut VARENE /** 687c7428422SThibaut VARENE * pdcs_fastsize_read - Stable Storage FastSize register output. 688f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 689f28a9877SHelge Deller * @attr: The kobject attributes. 690c7428422SThibaut VARENE * @buf: The output buffer to write to. 691c7428422SThibaut VARENE * 692c7428422SThibaut VARENE * This register holds the amount of system RAM to be tested during boot sequence. 693c7428422SThibaut VARENE */ 6947f548217SGreg Kroah-Hartman static ssize_t pdcs_fastsize_read(struct kobject *kobj, 6957f548217SGreg Kroah-Hartman struct kobj_attribute *attr, char *buf) 696c7428422SThibaut VARENE { 697c7428422SThibaut VARENE char *out = buf; 6983f9edb53SThibaut Varene u32 result; 699c7428422SThibaut VARENE 7007f548217SGreg Kroah-Hartman if (!buf) 701c7428422SThibaut VARENE return -EINVAL; 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds /* get fast-size */ 7041da177e4SLinus Torvalds if (pdc_stable_read(PDCS_ADDR_FSIZ, &result, sizeof(result)) != PDC_OK) 7051da177e4SLinus Torvalds return -EIO; 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds if ((result & 0x0F) < 0x0E) 708abff7543SRandolph Chung out += sprintf(out, "%d kB", (1<<(result & 0x0F))*256); 7091da177e4SLinus Torvalds else 7101da177e4SLinus Torvalds out += sprintf(out, "All"); 7111da177e4SLinus Torvalds out += sprintf(out, "\n"); 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds return out - buf; 7141da177e4SLinus Torvalds } 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds /** 7173f9edb53SThibaut Varene * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output. 718f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 719f28a9877SHelge Deller * @attr: The kobject attributes. 7203f9edb53SThibaut Varene * @buf: The output buffer to write to. 7213f9edb53SThibaut Varene * 7223f9edb53SThibaut Varene * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available. 7233f9edb53SThibaut Varene */ 7247f548217SGreg Kroah-Hartman static ssize_t pdcs_osdep2_read(struct kobject *kobj, 7257f548217SGreg Kroah-Hartman struct kobj_attribute *attr, char *buf) 7263f9edb53SThibaut Varene { 7273f9edb53SThibaut Varene char *out = buf; 7283f9edb53SThibaut Varene unsigned long size; 7293f9edb53SThibaut Varene unsigned short i; 7303f9edb53SThibaut Varene u32 result; 7313f9edb53SThibaut Varene 7323f9edb53SThibaut Varene if (unlikely(pdcs_size <= 224)) 7333f9edb53SThibaut Varene return -ENODATA; 7343f9edb53SThibaut Varene 7353f9edb53SThibaut Varene size = pdcs_size - 224; 7363f9edb53SThibaut Varene 7377f548217SGreg Kroah-Hartman if (!buf) 7383f9edb53SThibaut Varene return -EINVAL; 7393f9edb53SThibaut Varene 7403f9edb53SThibaut Varene for (i=0; i<size; i+=4) { 7413f9edb53SThibaut Varene if (unlikely(pdc_stable_read(PDCS_ADDR_OSD2 + i, &result, 7423f9edb53SThibaut Varene sizeof(result)) != PDC_OK)) 7433f9edb53SThibaut Varene return -EIO; 7443f9edb53SThibaut Varene out += sprintf(out, "0x%.8x\n", result); 7453f9edb53SThibaut Varene } 7463f9edb53SThibaut Varene 7473f9edb53SThibaut Varene return out - buf; 7483f9edb53SThibaut Varene } 7493f9edb53SThibaut Varene 7503f9edb53SThibaut Varene /** 751c7428422SThibaut VARENE * pdcs_auto_write - This function handles autoboot/search flag modifying. 752f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 753f28a9877SHelge Deller * @attr: The kobject attributes. 7541da177e4SLinus Torvalds * @buf: The input buffer to read from. 7551da177e4SLinus Torvalds * @count: The number of bytes to be read. 756c7428422SThibaut VARENE * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag 7571da177e4SLinus Torvalds * 758c7428422SThibaut VARENE * We will call this function to change the current autoboot flag. 7591da177e4SLinus Torvalds * We expect a precise syntax: 760c7428422SThibaut VARENE * \"n\" (n == 0 or 1) to toggle AutoBoot Off or On 7611da177e4SLinus Torvalds */ 7627f548217SGreg Kroah-Hartman static ssize_t pdcs_auto_write(struct kobject *kobj, 7637f548217SGreg Kroah-Hartman struct kobj_attribute *attr, const char *buf, 7647f548217SGreg Kroah-Hartman size_t count, int knob) 7651da177e4SLinus Torvalds { 7661da177e4SLinus Torvalds struct pdcspath_entry *pathentry; 7671da177e4SLinus Torvalds unsigned char flags; 76894c457deSRickard Strandqvist char in[8], *temp; 7691da177e4SLinus Torvalds char c; 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds if (!capable(CAP_SYS_ADMIN)) 7721da177e4SLinus Torvalds return -EACCES; 7731da177e4SLinus Torvalds 7747f548217SGreg Kroah-Hartman if (!buf || !count) 7751da177e4SLinus Torvalds return -EINVAL; 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvalds /* We'll use a local copy of buf */ 778c735483dSHelge Deller count = min_t(size_t, count, sizeof(in)-1); 779f2193bb2SXu Panda strscpy(in, buf, count + 1); 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds /* Current flags are stored in primary boot path entry */ 7821da177e4SLinus Torvalds pathentry = &pdcspath_entry_primary; 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds /* Be nice to the existing flag record */ 785c7428422SThibaut VARENE read_lock(&pathentry->rw_lock); 78650f19697SHelge Deller flags = pathentry->devpath.path.flags; 787c7428422SThibaut VARENE read_unlock(&pathentry->rw_lock); 7881da177e4SLinus Torvalds 7891da177e4SLinus Torvalds DPRINTK("%s: flags before: 0x%X\n", __func__, flags); 7901da177e4SLinus Torvalds 791e7d2860bSAndré Goddard Rosa temp = skip_spaces(in); 7921da177e4SLinus Torvalds 7931da177e4SLinus Torvalds c = *temp++ - '0'; 7941da177e4SLinus Torvalds if ((c != 0) && (c != 1)) 7951da177e4SLinus Torvalds goto parse_error; 7961da177e4SLinus Torvalds if (c == 0) 797c7428422SThibaut VARENE flags &= ~knob; 7981da177e4SLinus Torvalds else 799c7428422SThibaut VARENE flags |= knob; 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds DPRINTK("%s: flags after: 0x%X\n", __func__, flags); 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds /* So far so good, let's get in deep */ 804c7428422SThibaut VARENE write_lock(&pathentry->rw_lock); 8051da177e4SLinus Torvalds 8061da177e4SLinus Torvalds /* Change the path entry flags first */ 80750f19697SHelge Deller pathentry->devpath.path.flags = flags; 8081da177e4SLinus Torvalds 8091da177e4SLinus Torvalds /* Now, dive in. Write back to the hardware */ 810c7428422SThibaut VARENE pdcspath_store(pathentry); 811c7428422SThibaut VARENE write_unlock(&pathentry->rw_lock); 8121da177e4SLinus Torvalds 813c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" to \"%s\"\n", 814c7428422SThibaut VARENE (knob & PF_AUTOBOOT) ? "autoboot" : "autosearch", 815c7428422SThibaut VARENE (flags & knob) ? "On" : "Off"); 8161da177e4SLinus Torvalds 8171da177e4SLinus Torvalds return count; 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds parse_error: 820c7428422SThibaut VARENE printk(KERN_WARNING "%s: Parse error: expect \"n\" (n == 0 or 1)\n", __func__); 8211da177e4SLinus Torvalds return -EINVAL; 8221da177e4SLinus Torvalds } 8231da177e4SLinus Torvalds 824c7428422SThibaut VARENE /** 825c7428422SThibaut VARENE * pdcs_autoboot_write - This function handles autoboot flag modifying. 826f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 827f28a9877SHelge Deller * @attr: The kobject attributes. 828c7428422SThibaut VARENE * @buf: The input buffer to read from. 829c7428422SThibaut VARENE * @count: The number of bytes to be read. 830c7428422SThibaut VARENE * 831c7428422SThibaut VARENE * We will call this function to change the current boot flags. 832c7428422SThibaut VARENE * We expect a precise syntax: 833c7428422SThibaut VARENE * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On 834c7428422SThibaut VARENE */ 8357f548217SGreg Kroah-Hartman static ssize_t pdcs_autoboot_write(struct kobject *kobj, 8367f548217SGreg Kroah-Hartman struct kobj_attribute *attr, 8377f548217SGreg Kroah-Hartman const char *buf, size_t count) 838c7428422SThibaut VARENE { 839ff451d70SJoel Soete return pdcs_auto_write(kobj, attr, buf, count, PF_AUTOBOOT); 840c7428422SThibaut VARENE } 841c7428422SThibaut VARENE 842c7428422SThibaut VARENE /** 843c7428422SThibaut VARENE * pdcs_autosearch_write - This function handles autosearch flag modifying. 844f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 845f28a9877SHelge Deller * @attr: The kobject attributes. 846c7428422SThibaut VARENE * @buf: The input buffer to read from. 847c7428422SThibaut VARENE * @count: The number of bytes to be read. 848c7428422SThibaut VARENE * 849c7428422SThibaut VARENE * We will call this function to change the current boot flags. 850c7428422SThibaut VARENE * We expect a precise syntax: 851c7428422SThibaut VARENE * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On 852c7428422SThibaut VARENE */ 8537f548217SGreg Kroah-Hartman static ssize_t pdcs_autosearch_write(struct kobject *kobj, 8547f548217SGreg Kroah-Hartman struct kobj_attribute *attr, 8557f548217SGreg Kroah-Hartman const char *buf, size_t count) 856c7428422SThibaut VARENE { 857ff451d70SJoel Soete return pdcs_auto_write(kobj, attr, buf, count, PF_AUTOSEARCH); 858c7428422SThibaut VARENE } 859c7428422SThibaut VARENE 8603f9edb53SThibaut Varene /** 8613f9edb53SThibaut Varene * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input. 862f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 863f28a9877SHelge Deller * @attr: The kobject attributes. 8643f9edb53SThibaut Varene * @buf: The input buffer to read from. 8653f9edb53SThibaut Varene * @count: The number of bytes to be read. 8663f9edb53SThibaut Varene * 8673f9edb53SThibaut Varene * This can store 16 bytes of OS-Dependent data. We use a byte-by-byte 8683f9edb53SThibaut Varene * write approach. It's up to userspace to deal with it when constructing 8693f9edb53SThibaut Varene * its input buffer. 8703f9edb53SThibaut Varene */ 8717f548217SGreg Kroah-Hartman static ssize_t pdcs_osdep1_write(struct kobject *kobj, 8727f548217SGreg Kroah-Hartman struct kobj_attribute *attr, 8737f548217SGreg Kroah-Hartman const char *buf, size_t count) 8743f9edb53SThibaut Varene { 8753f9edb53SThibaut Varene u8 in[16]; 8763f9edb53SThibaut Varene 8773f9edb53SThibaut Varene if (!capable(CAP_SYS_ADMIN)) 8783f9edb53SThibaut Varene return -EACCES; 8793f9edb53SThibaut Varene 8807f548217SGreg Kroah-Hartman if (!buf || !count) 8813f9edb53SThibaut Varene return -EINVAL; 8823f9edb53SThibaut Varene 883ec1fdc24SKyle McMartin if (unlikely(pdcs_osid != OS_ID_LINUX)) 8843f9edb53SThibaut Varene return -EPERM; 8853f9edb53SThibaut Varene 8863f9edb53SThibaut Varene if (count > 16) 8873f9edb53SThibaut Varene return -EMSGSIZE; 8883f9edb53SThibaut Varene 8893f9edb53SThibaut Varene /* We'll use a local copy of buf */ 8903f9edb53SThibaut Varene memset(in, 0, 16); 8913f9edb53SThibaut Varene memcpy(in, buf, count); 8923f9edb53SThibaut Varene 8933f9edb53SThibaut Varene if (pdc_stable_write(PDCS_ADDR_OSD1, &in, sizeof(in)) != PDC_OK) 8943f9edb53SThibaut Varene return -EIO; 8953f9edb53SThibaut Varene 8963f9edb53SThibaut Varene return count; 8973f9edb53SThibaut Varene } 8983f9edb53SThibaut Varene 8993f9edb53SThibaut Varene /** 9003f9edb53SThibaut Varene * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input. 901f28a9877SHelge Deller * @kobj: The kobject used to share data with userspace. 902f28a9877SHelge Deller * @attr: The kobject attributes. 9033f9edb53SThibaut Varene * @buf: The input buffer to read from. 9043f9edb53SThibaut Varene * @count: The number of bytes to be read. 9053f9edb53SThibaut Varene * 9063f9edb53SThibaut Varene * This can store pdcs_size - 224 bytes of OS-Dependent data. We use a 9073f9edb53SThibaut Varene * byte-by-byte write approach. It's up to userspace to deal with it when 9083f9edb53SThibaut Varene * constructing its input buffer. 9093f9edb53SThibaut Varene */ 9107f548217SGreg Kroah-Hartman static ssize_t pdcs_osdep2_write(struct kobject *kobj, 9117f548217SGreg Kroah-Hartman struct kobj_attribute *attr, 9127f548217SGreg Kroah-Hartman const char *buf, size_t count) 9133f9edb53SThibaut Varene { 9143f9edb53SThibaut Varene unsigned long size; 9153f9edb53SThibaut Varene unsigned short i; 9163f9edb53SThibaut Varene u8 in[4]; 9173f9edb53SThibaut Varene 9183f9edb53SThibaut Varene if (!capable(CAP_SYS_ADMIN)) 9193f9edb53SThibaut Varene return -EACCES; 9203f9edb53SThibaut Varene 9217f548217SGreg Kroah-Hartman if (!buf || !count) 9223f9edb53SThibaut Varene return -EINVAL; 9233f9edb53SThibaut Varene 9243f9edb53SThibaut Varene if (unlikely(pdcs_size <= 224)) 9253f9edb53SThibaut Varene return -ENOSYS; 9263f9edb53SThibaut Varene 927ec1fdc24SKyle McMartin if (unlikely(pdcs_osid != OS_ID_LINUX)) 9283f9edb53SThibaut Varene return -EPERM; 9293f9edb53SThibaut Varene 9303f9edb53SThibaut Varene size = pdcs_size - 224; 9313f9edb53SThibaut Varene 9323f9edb53SThibaut Varene if (count > size) 9333f9edb53SThibaut Varene return -EMSGSIZE; 9343f9edb53SThibaut Varene 9353f9edb53SThibaut Varene /* We'll use a local copy of buf */ 9363f9edb53SThibaut Varene 9373f9edb53SThibaut Varene for (i=0; i<count; i+=4) { 9383f9edb53SThibaut Varene memset(in, 0, 4); 9393f9edb53SThibaut Varene memcpy(in, buf+i, (count-i < 4) ? count-i : 4); 9403f9edb53SThibaut Varene if (unlikely(pdc_stable_write(PDCS_ADDR_OSD2 + i, &in, 9413f9edb53SThibaut Varene sizeof(in)) != PDC_OK)) 9423f9edb53SThibaut Varene return -EIO; 9433f9edb53SThibaut Varene } 9443f9edb53SThibaut Varene 9453f9edb53SThibaut Varene return count; 9463f9edb53SThibaut Varene } 9473f9edb53SThibaut Varene 948c7428422SThibaut VARENE /* The remaining attributes. */ 949c7428422SThibaut VARENE static PDCS_ATTR(size, 0444, pdcs_size_read, NULL); 950c7428422SThibaut VARENE static PDCS_ATTR(autoboot, 0644, pdcs_autoboot_read, pdcs_autoboot_write); 951c7428422SThibaut VARENE static PDCS_ATTR(autosearch, 0644, pdcs_autosearch_read, pdcs_autosearch_write); 952c7428422SThibaut VARENE static PDCS_ATTR(timer, 0444, pdcs_timer_read, NULL); 9533f9edb53SThibaut Varene static PDCS_ATTR(osid, 0444, pdcs_osid_read, NULL); 9543f9edb53SThibaut Varene static PDCS_ATTR(osdep1, 0600, pdcs_osdep1_read, pdcs_osdep1_write); 9553f9edb53SThibaut Varene static PDCS_ATTR(diagnostic, 0400, pdcs_diagnostic_read, NULL); 956c7428422SThibaut VARENE static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL); 9573f9edb53SThibaut Varene static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write); 9581da177e4SLinus Torvalds 9597f548217SGreg Kroah-Hartman static struct attribute *pdcs_subsys_attrs[] = { 9607f548217SGreg Kroah-Hartman &pdcs_attr_size.attr, 9617f548217SGreg Kroah-Hartman &pdcs_attr_autoboot.attr, 9627f548217SGreg Kroah-Hartman &pdcs_attr_autosearch.attr, 9637f548217SGreg Kroah-Hartman &pdcs_attr_timer.attr, 9647f548217SGreg Kroah-Hartman &pdcs_attr_osid.attr, 9657f548217SGreg Kroah-Hartman &pdcs_attr_osdep1.attr, 9667f548217SGreg Kroah-Hartman &pdcs_attr_diagnostic.attr, 9677f548217SGreg Kroah-Hartman &pdcs_attr_fastsize.attr, 9687f548217SGreg Kroah-Hartman &pdcs_attr_osdep2.attr, 969c7428422SThibaut VARENE NULL, 9701da177e4SLinus Torvalds }; 9711da177e4SLinus Torvalds 972343fdfb7SArvind Yadav static const struct attribute_group pdcs_attr_group = { 9737f548217SGreg Kroah-Hartman .attrs = pdcs_subsys_attrs, 9747f548217SGreg Kroah-Hartman }; 9757f548217SGreg Kroah-Hartman 976c829a5b4SGreg Kroah-Hartman static struct kobject *stable_kobj; 9774443d07fSGreg Kroah-Hartman static struct kset *paths_kset; 9781da177e4SLinus Torvalds 9791da177e4SLinus Torvalds /** 9801da177e4SLinus Torvalds * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage. 9811da177e4SLinus Torvalds * 9821da177e4SLinus Torvalds * It creates kobjects corresponding to each path entry with nice sysfs 9831da177e4SLinus Torvalds * links to the real device. This is where the magic takes place: when 9841da177e4SLinus Torvalds * registering the subsystem attributes during module init, each kobject hereby 9851da177e4SLinus Torvalds * created will show in the sysfs tree as a folder containing files as defined 9861da177e4SLinus Torvalds * by path_subsys_attr[]. 9871da177e4SLinus Torvalds */ 9881da177e4SLinus Torvalds static inline int __init 9891da177e4SLinus Torvalds pdcs_register_pathentries(void) 9901da177e4SLinus Torvalds { 9911da177e4SLinus Torvalds unsigned short i; 9921da177e4SLinus Torvalds struct pdcspath_entry *entry; 9934b991da7SThibaut VARENE int err; 9941da177e4SLinus Torvalds 995c7428422SThibaut VARENE /* Initialize the entries rw_lock before anything else */ 996c7428422SThibaut VARENE for (i = 0; (entry = pdcspath_entries[i]); i++) 997c7428422SThibaut VARENE rwlock_init(&entry->rw_lock); 998c7428422SThibaut VARENE 9991da177e4SLinus Torvalds for (i = 0; (entry = pdcspath_entries[i]); i++) { 1000c7428422SThibaut VARENE write_lock(&entry->rw_lock); 1001c7428422SThibaut VARENE err = pdcspath_fetch(entry); 1002c7428422SThibaut VARENE write_unlock(&entry->rw_lock); 1003c7428422SThibaut VARENE 1004c7428422SThibaut VARENE if (err < 0) 10051da177e4SLinus Torvalds continue; 10061da177e4SLinus Torvalds 10074443d07fSGreg Kroah-Hartman entry->kobj.kset = paths_kset; 100873f368cfSGreg Kroah-Hartman err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL, 100973f368cfSGreg Kroah-Hartman "%s", entry->name); 1010d24846a4SMiaoqian Lin if (err) { 1011d24846a4SMiaoqian Lin kobject_put(&entry->kobj); 10124b991da7SThibaut VARENE return err; 1013d24846a4SMiaoqian Lin } 10144b991da7SThibaut VARENE 10154b991da7SThibaut VARENE /* kobject is now registered */ 1016c7428422SThibaut VARENE write_lock(&entry->rw_lock); 10174b991da7SThibaut VARENE entry->ready = 2; 101893964fd4SJames Bottomley write_unlock(&entry->rw_lock); 10191da177e4SLinus Torvalds 10201da177e4SLinus Torvalds /* Add a nice symlink to the real device */ 102126f03249SKyle McMartin if (entry->dev) { 102226f03249SKyle McMartin err = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); 102326f03249SKyle McMartin WARN_ON(err); 102426f03249SKyle McMartin } 1025c7428422SThibaut VARENE 102673f368cfSGreg Kroah-Hartman kobject_uevent(&entry->kobj, KOBJ_ADD); 10271da177e4SLinus Torvalds } 10281da177e4SLinus Torvalds 10291da177e4SLinus Torvalds return 0; 10301da177e4SLinus Torvalds } 10311da177e4SLinus Torvalds 10321da177e4SLinus Torvalds /** 10331da177e4SLinus Torvalds * pdcs_unregister_pathentries - Routine called when unregistering the module. 10341da177e4SLinus Torvalds */ 10354b991da7SThibaut VARENE static inline void 10361da177e4SLinus Torvalds pdcs_unregister_pathentries(void) 10371da177e4SLinus Torvalds { 10381da177e4SLinus Torvalds unsigned short i; 10391da177e4SLinus Torvalds struct pdcspath_entry *entry; 10401da177e4SLinus Torvalds 1041c7428422SThibaut VARENE for (i = 0; (entry = pdcspath_entries[i]); i++) { 1042c7428422SThibaut VARENE read_lock(&entry->rw_lock); 10434b991da7SThibaut VARENE if (entry->ready >= 2) 1044c10997f6SGreg Kroah-Hartman kobject_put(&entry->kobj); 1045c7428422SThibaut VARENE read_unlock(&entry->rw_lock); 1046c7428422SThibaut VARENE } 10471da177e4SLinus Torvalds } 10481da177e4SLinus Torvalds 10491da177e4SLinus Torvalds /* 1050c7428422SThibaut VARENE * For now we register the stable subsystem with the firmware subsystem 1051c7428422SThibaut VARENE * and the paths subsystem with the stable subsystem 10521da177e4SLinus Torvalds */ 10531da177e4SLinus Torvalds static int __init 10541da177e4SLinus Torvalds pdc_stable_init(void) 10551da177e4SLinus Torvalds { 1056f28a9877SHelge Deller int rc = 0, error; 10573f9edb53SThibaut Varene u32 result; 10581da177e4SLinus Torvalds 10591da177e4SLinus Torvalds /* find the size of the stable storage */ 10601da177e4SLinus Torvalds if (pdc_stable_get_size(&pdcs_size) != PDC_OK) 10611da177e4SLinus Torvalds return -ENODEV; 10621da177e4SLinus Torvalds 1063c7428422SThibaut VARENE /* make sure we have enough data */ 1064c7428422SThibaut VARENE if (pdcs_size < 96) 1065c7428422SThibaut VARENE return -ENODATA; 10661da177e4SLinus Torvalds 1067c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX " facility v%s\n", PDCS_VERSION); 1068c7428422SThibaut VARENE 10693f9edb53SThibaut Varene /* get OSID */ 10703f9edb53SThibaut Varene if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK) 10713f9edb53SThibaut Varene return -EIO; 10723f9edb53SThibaut Varene 10733f9edb53SThibaut Varene /* the actual result is 16 bits away */ 10743f9edb53SThibaut Varene pdcs_osid = (u16)(result >> 16); 10753f9edb53SThibaut Varene 1076c829a5b4SGreg Kroah-Hartman /* For now we'll register the directory at /sys/firmware/stable */ 1077c829a5b4SGreg Kroah-Hartman stable_kobj = kobject_create_and_add("stable", firmware_kobj); 1078c829a5b4SGreg Kroah-Hartman if (!stable_kobj) { 10794443d07fSGreg Kroah-Hartman rc = -ENOMEM; 10804b991da7SThibaut VARENE goto fail_firmreg; 10814443d07fSGreg Kroah-Hartman } 10821da177e4SLinus Torvalds 1083c7428422SThibaut VARENE /* Don't forget the root entries */ 1084ff451d70SJoel Soete error = sysfs_create_group(stable_kobj, &pdcs_attr_group); 1085f28a9877SHelge Deller if (error) { 1086f28a9877SHelge Deller rc = -ENOMEM; 1087f28a9877SHelge Deller goto fail_ksetreg; 1088f28a9877SHelge Deller } 10891da177e4SLinus Torvalds 10904443d07fSGreg Kroah-Hartman /* register the paths kset as a child of the stable kset */ 1091c829a5b4SGreg Kroah-Hartman paths_kset = kset_create_and_add("paths", NULL, stable_kobj); 10924443d07fSGreg Kroah-Hartman if (!paths_kset) { 10934443d07fSGreg Kroah-Hartman rc = -ENOMEM; 10944443d07fSGreg Kroah-Hartman goto fail_ksetreg; 10954443d07fSGreg Kroah-Hartman } 10961da177e4SLinus Torvalds 10974443d07fSGreg Kroah-Hartman /* now we create all "files" for the paths kset */ 10984b991da7SThibaut VARENE if ((rc = pdcs_register_pathentries())) 10994b991da7SThibaut VARENE goto fail_pdcsreg; 11001da177e4SLinus Torvalds 11014b991da7SThibaut VARENE return rc; 11024b991da7SThibaut VARENE 11034b991da7SThibaut VARENE fail_pdcsreg: 11044b991da7SThibaut VARENE pdcs_unregister_pathentries(); 11054443d07fSGreg Kroah-Hartman kset_unregister(paths_kset); 11064b991da7SThibaut VARENE 11074443d07fSGreg Kroah-Hartman fail_ksetreg: 1108c10997f6SGreg Kroah-Hartman kobject_put(stable_kobj); 11094b991da7SThibaut VARENE 11104b991da7SThibaut VARENE fail_firmreg: 1111c7428422SThibaut VARENE printk(KERN_INFO PDCS_PREFIX " bailing out\n"); 11124b991da7SThibaut VARENE return rc; 11131da177e4SLinus Torvalds } 11141da177e4SLinus Torvalds 11151da177e4SLinus Torvalds static void __exit 11161da177e4SLinus Torvalds pdc_stable_exit(void) 11171da177e4SLinus Torvalds { 11181da177e4SLinus Torvalds pdcs_unregister_pathentries(); 11194443d07fSGreg Kroah-Hartman kset_unregister(paths_kset); 1120c10997f6SGreg Kroah-Hartman kobject_put(stable_kobj); 11211da177e4SLinus Torvalds } 11221da177e4SLinus Torvalds 11231da177e4SLinus Torvalds 11241da177e4SLinus Torvalds module_init(pdc_stable_init); 11251da177e4SLinus Torvalds module_exit(pdc_stable_exit); 1126