xref: /linux/drivers/parisc/pdc_stable.c (revision 93c3e913e104c9277e32a0d7e03f268d146c57ee)
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.
313f9edb53SThibaut Varene  *    One last word: there's one path we can always count on: the primary path.
323f9edb53SThibaut Varene  *    Anything above 224 bytes is used for 'osdep2' OS-dependent storage area.
333f9edb53SThibaut Varene  *
343f9edb53SThibaut Varene  *    The first OS-dependent area should always be available. Obviously, this is
353f9edb53SThibaut Varene  *    not true for the other one. Also bear in mind that reading/writing from/to
363f9edb53SThibaut Varene  *    osdep2 is much more expensive than from/to osdep1.
373f9edb53SThibaut Varene  *    NOTE: We do not handle the 2 bytes OS-dep area at 0x5D, nor the first
383f9edb53SThibaut Varene  *    2 bytes of storage available right after OSID. That's a total of 4 bytes
393f9edb53SThibaut 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 
743f9edb53SThibaut 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
793f9edb53SThibaut Varene #define PDCS_ADDR_OSD1	0x48
803f9edb53SThibaut 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
853f9edb53SThibaut 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 
953f9edb53SThibaut Varene /* holds OS ID. Initialized once and for all, hopefully to 0x0006 */
963f9edb53SThibaut Varene static u16 pdcs_osid __read_mostly;
973f9edb53SThibaut 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) \
1237f548217SGreg Kroah-Hartman struct kobj_attribute pdcs_attr_##_name = { \
1247b595756STejun Heo 	.attr = {.name = __stringify(_name), .mode = _mode}, \
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 = { \
1317b595756STejun Heo 	.attr = {.name = __stringify(_name), .mode = _mode}, \
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
14425985edcSLucas De Marchi  * you access the files provided by the facilities. 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 */
215*93c3e913SJulia Lawall 	if (pdc_stable_write(entry->addr, devpath, sizeof(*devpath)) != PDC_OK)
216*93c3e913SJulia Lawall 		WARN(1, KERN_ERR "%s: an error occurred 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__);
2191da177e4SLinus Torvalds 
2204b991da7SThibaut VARENE 	/* kobject is already registered */
2214b991da7SThibaut VARENE 	entry->ready = 2;
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds 	DPRINTK("%s: device: 0x%p\n", __func__, entry->dev);
2241da177e4SLinus Torvalds }
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds /**
2271da177e4SLinus Torvalds  * pdcspath_hwpath_read - This function handles hardware path pretty printing.
2281da177e4SLinus Torvalds  * @entry: An allocated and populated pdscpath_entry struct.
2291da177e4SLinus Torvalds  * @buf: The output buffer to write to.
2301da177e4SLinus Torvalds  *
2311da177e4SLinus Torvalds  * We will call this function to format the output of the hwpath attribute file.
2321da177e4SLinus Torvalds  */
2331da177e4SLinus Torvalds static ssize_t
2341da177e4SLinus Torvalds pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf)
2351da177e4SLinus Torvalds {
2361da177e4SLinus Torvalds 	char *out = buf;
2371da177e4SLinus Torvalds 	struct device_path *devpath;
238c7428422SThibaut VARENE 	short i;
2391da177e4SLinus Torvalds 
2401da177e4SLinus Torvalds 	if (!entry || !buf)
2411da177e4SLinus Torvalds 		return -EINVAL;
2421da177e4SLinus Torvalds 
243c7428422SThibaut VARENE 	read_lock(&entry->rw_lock);
2441da177e4SLinus Torvalds 	devpath = &entry->devpath;
245c7428422SThibaut VARENE 	i = entry->ready;
246c7428422SThibaut VARENE 	read_unlock(&entry->rw_lock);
2471da177e4SLinus Torvalds 
248c7428422SThibaut VARENE 	if (!i)	/* entry is not ready */
2491da177e4SLinus Torvalds 		return -ENODATA;
2501da177e4SLinus Torvalds 
2511da177e4SLinus Torvalds 	for (i = 0; i < 6; i++) {
2521da177e4SLinus Torvalds 		if (devpath->bc[i] >= 128)
2531da177e4SLinus Torvalds 			continue;
2541da177e4SLinus Torvalds 		out += sprintf(out, "%u/", (unsigned char)devpath->bc[i]);
2551da177e4SLinus Torvalds 	}
2561da177e4SLinus Torvalds 	out += sprintf(out, "%u\n", (unsigned char)devpath->mod);
2571da177e4SLinus Torvalds 
2581da177e4SLinus Torvalds 	return out - buf;
2591da177e4SLinus Torvalds }
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds /**
2621da177e4SLinus Torvalds  * pdcspath_hwpath_write - This function handles hardware path modifying.
2631da177e4SLinus Torvalds  * @entry: An allocated and populated pdscpath_entry struct.
2641da177e4SLinus Torvalds  * @buf: The input buffer to read from.
2651da177e4SLinus Torvalds  * @count: The number of bytes to be read.
2661da177e4SLinus Torvalds  *
2671da177e4SLinus Torvalds  * We will call this function to change the current hardware path.
2681da177e4SLinus Torvalds  * Hardware paths are to be given '/'-delimited, without brackets.
269c7428422SThibaut VARENE  * We make sure that the provided path actually maps to an existing
2701da177e4SLinus Torvalds  * device, BUT nothing would prevent some foolish user to set the path to some
2711da177e4SLinus Torvalds  * PCI bridge or even a CPU...
2721da177e4SLinus Torvalds  * A better work around would be to make sure we are at the end of a device tree
2731da177e4SLinus Torvalds  * for instance, but it would be IMHO beyond the simple scope of that driver.
2741da177e4SLinus Torvalds  * The aim is to provide a facility. Data correctness is left to userland.
2751da177e4SLinus Torvalds  */
2761da177e4SLinus Torvalds static ssize_t
2771da177e4SLinus Torvalds pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t count)
2781da177e4SLinus Torvalds {
2791da177e4SLinus Torvalds 	struct hardware_path hwpath;
2801da177e4SLinus Torvalds 	unsigned short i;
2811da177e4SLinus Torvalds 	char in[count+1], *temp;
2821da177e4SLinus Torvalds 	struct device *dev;
28326f03249SKyle McMartin 	int ret;
2841da177e4SLinus Torvalds 
2851da177e4SLinus Torvalds 	if (!entry || !buf || !count)
2861da177e4SLinus Torvalds 		return -EINVAL;
2871da177e4SLinus Torvalds 
2881da177e4SLinus Torvalds 	/* We'll use a local copy of buf */
2891da177e4SLinus Torvalds 	memset(in, 0, count+1);
2901da177e4SLinus Torvalds 	strncpy(in, buf, count);
2911da177e4SLinus Torvalds 
2921da177e4SLinus Torvalds 	/* Let's clean up the target. 0xff is a blank pattern */
2931da177e4SLinus Torvalds 	memset(&hwpath, 0xff, sizeof(hwpath));
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds 	/* First, pick the mod field (the last one of the input string) */
2961da177e4SLinus Torvalds 	if (!(temp = strrchr(in, '/')))
2971da177e4SLinus Torvalds 		return -EINVAL;
2981da177e4SLinus Torvalds 
2991da177e4SLinus Torvalds 	hwpath.mod = simple_strtoul(temp+1, NULL, 10);
3001da177e4SLinus Torvalds 	in[temp-in] = '\0';	/* truncate the remaining string. just precaution */
3011da177e4SLinus Torvalds 	DPRINTK("%s: mod: %d\n", __func__, hwpath.mod);
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds 	/* Then, loop for each delimiter, making sure we don't have too many.
3041da177e4SLinus Torvalds 	   we write the bc fields in a down-top way. No matter what, we stop
3051da177e4SLinus Torvalds 	   before writing the last field. If there are too many fields anyway,
3061da177e4SLinus Torvalds 	   then the user is a moron and it'll be caught up later when we'll
3071da177e4SLinus Torvalds 	   check the consistency of the given hwpath. */
3081da177e4SLinus Torvalds 	for (i=5; ((temp = strrchr(in, '/'))) && (temp-in > 0) && (likely(i)); i--) {
3091da177e4SLinus Torvalds 		hwpath.bc[i] = simple_strtoul(temp+1, NULL, 10);
3101da177e4SLinus Torvalds 		in[temp-in] = '\0';
3111da177e4SLinus Torvalds 		DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]);
3121da177e4SLinus Torvalds 	}
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds 	/* Store the final field */
3151da177e4SLinus Torvalds 	hwpath.bc[i] = simple_strtoul(in, NULL, 10);
3161da177e4SLinus Torvalds 	DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]);
3171da177e4SLinus Torvalds 
3181da177e4SLinus Torvalds 	/* Now we check that the user isn't trying to lure us */
3191da177e4SLinus Torvalds 	if (!(dev = hwpath_to_device((struct hardware_path *)&hwpath))) {
3201da177e4SLinus Torvalds 		printk(KERN_WARNING "%s: attempt to set invalid \"%s\" "
3211da177e4SLinus Torvalds 			"hardware path: %s\n", __func__, entry->name, buf);
3221da177e4SLinus Torvalds 		return -EINVAL;
3231da177e4SLinus Torvalds 	}
3241da177e4SLinus Torvalds 
3251da177e4SLinus Torvalds 	/* So far so good, let's get in deep */
326c7428422SThibaut VARENE 	write_lock(&entry->rw_lock);
3271da177e4SLinus Torvalds 	entry->ready = 0;
3281da177e4SLinus Torvalds 	entry->dev = dev;
3291da177e4SLinus Torvalds 
3301da177e4SLinus Torvalds 	/* Now, dive in. Write back to the hardware */
331c7428422SThibaut VARENE 	pdcspath_store(entry);
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds 	/* Update the symlink to the real device */
3341da177e4SLinus Torvalds 	sysfs_remove_link(&entry->kobj, "device");
33526f03249SKyle McMartin 	ret = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device");
33626f03249SKyle McMartin 	WARN_ON(ret);
33726f03249SKyle McMartin 
338c7428422SThibaut VARENE 	write_unlock(&entry->rw_lock);
3391da177e4SLinus Torvalds 
340c7428422SThibaut VARENE 	printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" path to \"%s\"\n",
3411da177e4SLinus Torvalds 		entry->name, buf);
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds 	return count;
3441da177e4SLinus Torvalds }
3451da177e4SLinus Torvalds 
3461da177e4SLinus Torvalds /**
3471da177e4SLinus Torvalds  * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing.
3481da177e4SLinus Torvalds  * @entry: An allocated and populated pdscpath_entry struct.
3491da177e4SLinus Torvalds  * @buf: The output buffer to write to.
3501da177e4SLinus Torvalds  *
3511da177e4SLinus Torvalds  * We will call this function to format the output of the layer attribute file.
3521da177e4SLinus Torvalds  */
3531da177e4SLinus Torvalds static ssize_t
3541da177e4SLinus Torvalds pdcspath_layer_read(struct pdcspath_entry *entry, char *buf)
3551da177e4SLinus Torvalds {
3561da177e4SLinus Torvalds 	char *out = buf;
3571da177e4SLinus Torvalds 	struct device_path *devpath;
358c7428422SThibaut VARENE 	short i;
3591da177e4SLinus Torvalds 
3601da177e4SLinus Torvalds 	if (!entry || !buf)
3611da177e4SLinus Torvalds 		return -EINVAL;
3621da177e4SLinus Torvalds 
363c7428422SThibaut VARENE 	read_lock(&entry->rw_lock);
3641da177e4SLinus Torvalds 	devpath = &entry->devpath;
365c7428422SThibaut VARENE 	i = entry->ready;
366c7428422SThibaut VARENE 	read_unlock(&entry->rw_lock);
3671da177e4SLinus Torvalds 
368c7428422SThibaut VARENE 	if (!i)	/* entry is not ready */
3691da177e4SLinus Torvalds 		return -ENODATA;
3701da177e4SLinus Torvalds 
371447c233dSRoel Kluin 	for (i = 0; i < 6 && devpath->layers[i]; i++)
3721da177e4SLinus Torvalds 		out += sprintf(out, "%u ", devpath->layers[i]);
3731da177e4SLinus Torvalds 
3741da177e4SLinus Torvalds 	out += sprintf(out, "\n");
3751da177e4SLinus Torvalds 
3761da177e4SLinus Torvalds 	return out - buf;
3771da177e4SLinus Torvalds }
3781da177e4SLinus Torvalds 
3791da177e4SLinus Torvalds /**
3801da177e4SLinus Torvalds  * pdcspath_layer_write - This function handles extended layer modifying.
3811da177e4SLinus Torvalds  * @entry: An allocated and populated pdscpath_entry struct.
3821da177e4SLinus Torvalds  * @buf: The input buffer to read from.
3831da177e4SLinus Torvalds  * @count: The number of bytes to be read.
3841da177e4SLinus Torvalds  *
3851da177e4SLinus Torvalds  * We will call this function to change the current layer value.
3861da177e4SLinus Torvalds  * Layers are to be given '.'-delimited, without brackets.
3871da177e4SLinus Torvalds  * XXX beware we are far less checky WRT input data provided than for hwpath.
3881da177e4SLinus Torvalds  * Potential harm can be done, since there's no way to check the validity of
3891da177e4SLinus Torvalds  * the layer fields.
3901da177e4SLinus Torvalds  */
3911da177e4SLinus Torvalds static ssize_t
3921da177e4SLinus Torvalds pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count)
3931da177e4SLinus Torvalds {
3941da177e4SLinus Torvalds 	unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */
3951da177e4SLinus Torvalds 	unsigned short i;
3961da177e4SLinus Torvalds 	char in[count+1], *temp;
3971da177e4SLinus Torvalds 
3981da177e4SLinus Torvalds 	if (!entry || !buf || !count)
3991da177e4SLinus Torvalds 		return -EINVAL;
4001da177e4SLinus Torvalds 
4011da177e4SLinus Torvalds 	/* We'll use a local copy of buf */
4021da177e4SLinus Torvalds 	memset(in, 0, count+1);
4031da177e4SLinus Torvalds 	strncpy(in, buf, count);
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds 	/* Let's clean up the target. 0 is a blank pattern */
4061da177e4SLinus Torvalds 	memset(&layers, 0, sizeof(layers));
4071da177e4SLinus Torvalds 
4081da177e4SLinus Torvalds 	/* First, pick the first layer */
4091da177e4SLinus Torvalds 	if (unlikely(!isdigit(*in)))
4101da177e4SLinus Torvalds 		return -EINVAL;
4111da177e4SLinus Torvalds 	layers[0] = simple_strtoul(in, NULL, 10);
4121da177e4SLinus Torvalds 	DPRINTK("%s: layer[0]: %d\n", __func__, layers[0]);
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds 	temp = in;
4151da177e4SLinus Torvalds 	for (i=1; ((temp = strchr(temp, '.'))) && (likely(i<6)); i++) {
4161da177e4SLinus Torvalds 		if (unlikely(!isdigit(*(++temp))))
4171da177e4SLinus Torvalds 			return -EINVAL;
4181da177e4SLinus Torvalds 		layers[i] = simple_strtoul(temp, NULL, 10);
4191da177e4SLinus Torvalds 		DPRINTK("%s: layer[%d]: %d\n", __func__, i, layers[i]);
4201da177e4SLinus Torvalds 	}
4211da177e4SLinus Torvalds 
4221da177e4SLinus Torvalds 	/* So far so good, let's get in deep */
423c7428422SThibaut VARENE 	write_lock(&entry->rw_lock);
4241da177e4SLinus Torvalds 
4251da177e4SLinus Torvalds 	/* First, overwrite the current layers with the new ones, not touching
4261da177e4SLinus Torvalds 	   the hardware path. */
4271da177e4SLinus Torvalds 	memcpy(&entry->devpath.layers, &layers, sizeof(layers));
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds 	/* Now, dive in. Write back to the hardware */
430c7428422SThibaut VARENE 	pdcspath_store(entry);
431c7428422SThibaut VARENE 	write_unlock(&entry->rw_lock);
4321da177e4SLinus Torvalds 
433c7428422SThibaut VARENE 	printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" layers to \"%s\"\n",
4341da177e4SLinus Torvalds 		entry->name, buf);
4351da177e4SLinus Torvalds 
4361da177e4SLinus Torvalds 	return count;
4371da177e4SLinus Torvalds }
4381da177e4SLinus Torvalds 
4391da177e4SLinus Torvalds /**
4401da177e4SLinus Torvalds  * pdcspath_attr_show - Generic read function call wrapper.
4411da177e4SLinus Torvalds  * @kobj: The kobject to get info from.
4421da177e4SLinus Torvalds  * @attr: The attribute looked upon.
4431da177e4SLinus Torvalds  * @buf: The output buffer.
4441da177e4SLinus Torvalds  */
4451da177e4SLinus Torvalds static ssize_t
4461da177e4SLinus Torvalds pdcspath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
4471da177e4SLinus Torvalds {
4481da177e4SLinus Torvalds 	struct pdcspath_entry *entry = to_pdcspath_entry(kobj);
4491da177e4SLinus Torvalds 	struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr);
4501da177e4SLinus Torvalds 	ssize_t ret = 0;
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds 	if (pdcs_attr->show)
4531da177e4SLinus Torvalds 		ret = pdcs_attr->show(entry, buf);
4541da177e4SLinus Torvalds 
4551da177e4SLinus Torvalds 	return ret;
4561da177e4SLinus Torvalds }
4571da177e4SLinus Torvalds 
4581da177e4SLinus Torvalds /**
4591da177e4SLinus Torvalds  * pdcspath_attr_store - Generic write function call wrapper.
4601da177e4SLinus Torvalds  * @kobj: The kobject to write info to.
4611da177e4SLinus Torvalds  * @attr: The attribute to be modified.
4621da177e4SLinus Torvalds  * @buf: The input buffer.
4631da177e4SLinus Torvalds  * @count: The size of the buffer.
4641da177e4SLinus Torvalds  */
4651da177e4SLinus Torvalds static ssize_t
4661da177e4SLinus Torvalds pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
4671da177e4SLinus Torvalds 			const char *buf, size_t count)
4681da177e4SLinus Torvalds {
4691da177e4SLinus Torvalds 	struct pdcspath_entry *entry = to_pdcspath_entry(kobj);
4701da177e4SLinus Torvalds 	struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr);
4711da177e4SLinus Torvalds 	ssize_t ret = 0;
4721da177e4SLinus Torvalds 
4731da177e4SLinus Torvalds 	if (!capable(CAP_SYS_ADMIN))
4741da177e4SLinus Torvalds 		return -EACCES;
4751da177e4SLinus Torvalds 
4761da177e4SLinus Torvalds 	if (pdcs_attr->store)
4771da177e4SLinus Torvalds 		ret = pdcs_attr->store(entry, buf, count);
4781da177e4SLinus Torvalds 
4791da177e4SLinus Torvalds 	return ret;
4801da177e4SLinus Torvalds }
4811da177e4SLinus Torvalds 
48252cf25d0SEmese Revfy static const struct sysfs_ops pdcspath_attr_ops = {
4831da177e4SLinus Torvalds 	.show = pdcspath_attr_show,
4841da177e4SLinus Torvalds 	.store = pdcspath_attr_store,
4851da177e4SLinus Torvalds };
4861da177e4SLinus Torvalds 
4871da177e4SLinus Torvalds /* These are the two attributes of any PDC path. */
488c7428422SThibaut VARENE static PATHS_ATTR(hwpath, 0644, pdcspath_hwpath_read, pdcspath_hwpath_write);
489c7428422SThibaut VARENE static PATHS_ATTR(layer, 0644, pdcspath_layer_read, pdcspath_layer_write);
4901da177e4SLinus Torvalds 
4911da177e4SLinus Torvalds static struct attribute *paths_subsys_attrs[] = {
4921da177e4SLinus Torvalds 	&paths_attr_hwpath.attr,
4931da177e4SLinus Torvalds 	&paths_attr_layer.attr,
4941da177e4SLinus Torvalds 	NULL,
4951da177e4SLinus Torvalds };
4961da177e4SLinus Torvalds 
4971da177e4SLinus Torvalds /* Specific kobject type for our PDC paths */
4981da177e4SLinus Torvalds static struct kobj_type ktype_pdcspath = {
4991da177e4SLinus Torvalds 	.sysfs_ops = &pdcspath_attr_ops,
5001da177e4SLinus Torvalds 	.default_attrs = paths_subsys_attrs,
5011da177e4SLinus Torvalds };
5021da177e4SLinus Torvalds 
5031da177e4SLinus Torvalds /* We hard define the 4 types of path we expect to find */
5041da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PPRI, primary);
5051da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PCON, console);
5061da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PALT, alternative);
5071da177e4SLinus Torvalds static PDCSPATH_ENTRY(PDCS_ADDR_PKBD, keyboard);
5081da177e4SLinus Torvalds 
5091da177e4SLinus Torvalds /* An array containing all PDC paths we will deal with */
5101da177e4SLinus Torvalds static struct pdcspath_entry *pdcspath_entries[] = {
5111da177e4SLinus Torvalds 	&pdcspath_entry_primary,
5121da177e4SLinus Torvalds 	&pdcspath_entry_alternative,
5131da177e4SLinus Torvalds 	&pdcspath_entry_console,
5141da177e4SLinus Torvalds 	&pdcspath_entry_keyboard,
5151da177e4SLinus Torvalds 	NULL,
5161da177e4SLinus Torvalds };
5171da177e4SLinus Torvalds 
518c7428422SThibaut VARENE 
519c7428422SThibaut VARENE /* For more insight of what's going on here, refer to PDC Procedures doc,
520c7428422SThibaut VARENE  * Section PDC_STABLE */
521c7428422SThibaut VARENE 
5221da177e4SLinus Torvalds /**
523c7428422SThibaut VARENE  * pdcs_size_read - Stable Storage size output.
5241da177e4SLinus Torvalds  * @buf: The output buffer to write to.
5251da177e4SLinus Torvalds  */
5267f548217SGreg Kroah-Hartman static ssize_t pdcs_size_read(struct kobject *kobj,
5277f548217SGreg Kroah-Hartman 			      struct kobj_attribute *attr,
5287f548217SGreg Kroah-Hartman 			      char *buf)
5291da177e4SLinus Torvalds {
5301da177e4SLinus Torvalds 	char *out = buf;
5311da177e4SLinus Torvalds 
5327f548217SGreg Kroah-Hartman 	if (!buf)
5331da177e4SLinus Torvalds 		return -EINVAL;
5341da177e4SLinus Torvalds 
5351da177e4SLinus Torvalds 	/* show the size of the stable storage */
536c7428422SThibaut VARENE 	out += sprintf(out, "%ld\n", pdcs_size);
5371da177e4SLinus Torvalds 
538c7428422SThibaut VARENE 	return out - buf;
539c7428422SThibaut VARENE }
5401da177e4SLinus Torvalds 
541c7428422SThibaut VARENE /**
542c7428422SThibaut VARENE  * pdcs_auto_read - Stable Storage autoboot/search flag output.
543c7428422SThibaut VARENE  * @buf: The output buffer to write to.
544c7428422SThibaut VARENE  * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
545c7428422SThibaut VARENE  */
5467f548217SGreg Kroah-Hartman static ssize_t pdcs_auto_read(struct kobject *kobj,
5477f548217SGreg Kroah-Hartman 			      struct kobj_attribute *attr,
5487f548217SGreg Kroah-Hartman 			      char *buf, int knob)
549c7428422SThibaut VARENE {
550c7428422SThibaut VARENE 	char *out = buf;
551c7428422SThibaut VARENE 	struct pdcspath_entry *pathentry;
552c7428422SThibaut VARENE 
5537f548217SGreg Kroah-Hartman 	if (!buf)
554c7428422SThibaut VARENE 		return -EINVAL;
555c7428422SThibaut VARENE 
556c7428422SThibaut VARENE 	/* Current flags are stored in primary boot path entry */
557c7428422SThibaut VARENE 	pathentry = &pdcspath_entry_primary;
558c7428422SThibaut VARENE 
559c7428422SThibaut VARENE 	read_lock(&pathentry->rw_lock);
560c7428422SThibaut VARENE 	out += sprintf(out, "%s\n", (pathentry->devpath.flags & knob) ?
561c7428422SThibaut VARENE 					"On" : "Off");
562c7428422SThibaut VARENE 	read_unlock(&pathentry->rw_lock);
563c7428422SThibaut VARENE 
564c7428422SThibaut VARENE 	return out - buf;
565c7428422SThibaut VARENE }
566c7428422SThibaut VARENE 
567c7428422SThibaut VARENE /**
568c7428422SThibaut VARENE  * pdcs_autoboot_read - Stable Storage autoboot flag output.
569c7428422SThibaut VARENE  * @buf: The output buffer to write to.
570c7428422SThibaut VARENE  */
5717f548217SGreg Kroah-Hartman static ssize_t pdcs_autoboot_read(struct kobject *kobj,
5727f548217SGreg Kroah-Hartman 				  struct kobj_attribute *attr, char *buf)
573c7428422SThibaut VARENE {
5747f548217SGreg Kroah-Hartman 	return pdcs_auto_read(kobj, attr, buf, PF_AUTOBOOT);
575c7428422SThibaut VARENE }
576c7428422SThibaut VARENE 
577c7428422SThibaut VARENE /**
578c7428422SThibaut VARENE  * pdcs_autosearch_read - Stable Storage autoboot flag output.
579c7428422SThibaut VARENE  * @buf: The output buffer to write to.
580c7428422SThibaut VARENE  */
5817f548217SGreg Kroah-Hartman static ssize_t pdcs_autosearch_read(struct kobject *kobj,
5827f548217SGreg Kroah-Hartman 				    struct kobj_attribute *attr, char *buf)
583c7428422SThibaut VARENE {
5847f548217SGreg Kroah-Hartman 	return pdcs_auto_read(kobj, attr, buf, PF_AUTOSEARCH);
585c7428422SThibaut VARENE }
586c7428422SThibaut VARENE 
587c7428422SThibaut VARENE /**
588c7428422SThibaut VARENE  * pdcs_timer_read - Stable Storage timer count output (in seconds).
589c7428422SThibaut VARENE  * @buf: The output buffer to write to.
590c7428422SThibaut VARENE  *
591c7428422SThibaut VARENE  * The value of the timer field correponds to a number of seconds in powers of 2.
592c7428422SThibaut VARENE  */
5937f548217SGreg Kroah-Hartman static ssize_t pdcs_timer_read(struct kobject *kobj,
5947f548217SGreg Kroah-Hartman 			       struct kobj_attribute *attr, char *buf)
595c7428422SThibaut VARENE {
596c7428422SThibaut VARENE 	char *out = buf;
597c7428422SThibaut VARENE 	struct pdcspath_entry *pathentry;
598c7428422SThibaut VARENE 
5997f548217SGreg Kroah-Hartman 	if (!buf)
600c7428422SThibaut VARENE 		return -EINVAL;
601c7428422SThibaut VARENE 
602c7428422SThibaut VARENE 	/* Current flags are stored in primary boot path entry */
603c7428422SThibaut VARENE 	pathentry = &pdcspath_entry_primary;
604c7428422SThibaut VARENE 
605c7428422SThibaut VARENE 	/* print the timer value in seconds */
606c7428422SThibaut VARENE 	read_lock(&pathentry->rw_lock);
607c7428422SThibaut VARENE 	out += sprintf(out, "%u\n", (pathentry->devpath.flags & PF_TIMER) ?
608c7428422SThibaut VARENE 				(1 << (pathentry->devpath.flags & PF_TIMER)) : 0);
609c7428422SThibaut VARENE 	read_unlock(&pathentry->rw_lock);
610c7428422SThibaut VARENE 
611c7428422SThibaut VARENE 	return out - buf;
612c7428422SThibaut VARENE }
613c7428422SThibaut VARENE 
614c7428422SThibaut VARENE /**
615c7428422SThibaut VARENE  * pdcs_osid_read - Stable Storage OS ID register output.
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.
6343f9edb53SThibaut Varene  * @buf: The output buffer to write to.
6353f9edb53SThibaut Varene  *
6363f9edb53SThibaut Varene  * This can hold 16 bytes of OS-Dependent data.
6373f9edb53SThibaut Varene  */
6387f548217SGreg Kroah-Hartman static ssize_t pdcs_osdep1_read(struct kobject *kobj,
6397f548217SGreg Kroah-Hartman 				struct kobj_attribute *attr, char *buf)
6403f9edb53SThibaut Varene {
6413f9edb53SThibaut Varene 	char *out = buf;
6423f9edb53SThibaut Varene 	u32 result[4];
6433f9edb53SThibaut Varene 
6447f548217SGreg Kroah-Hartman 	if (!buf)
6453f9edb53SThibaut Varene 		return -EINVAL;
6463f9edb53SThibaut Varene 
6473f9edb53SThibaut Varene 	if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK)
6483f9edb53SThibaut Varene 		return -EIO;
6493f9edb53SThibaut Varene 
6503f9edb53SThibaut Varene 	out += sprintf(out, "0x%.8x\n", result[0]);
6513f9edb53SThibaut Varene 	out += sprintf(out, "0x%.8x\n", result[1]);
6523f9edb53SThibaut Varene 	out += sprintf(out, "0x%.8x\n", result[2]);
6533f9edb53SThibaut Varene 	out += sprintf(out, "0x%.8x\n", result[3]);
6543f9edb53SThibaut Varene 
6553f9edb53SThibaut Varene 	return out - buf;
6563f9edb53SThibaut Varene }
6573f9edb53SThibaut Varene 
6583f9edb53SThibaut Varene /**
6593f9edb53SThibaut Varene  * pdcs_diagnostic_read - Stable Storage Diagnostic register output.
6603f9edb53SThibaut Varene  * @buf: The output buffer to write to.
6613f9edb53SThibaut Varene  *
6623f9edb53SThibaut Varene  * I have NFC how to interpret the content of that register ;-).
6633f9edb53SThibaut Varene  */
6647f548217SGreg Kroah-Hartman static ssize_t pdcs_diagnostic_read(struct kobject *kobj,
6657f548217SGreg Kroah-Hartman 				    struct kobj_attribute *attr, char *buf)
6663f9edb53SThibaut Varene {
6673f9edb53SThibaut Varene 	char *out = buf;
6683f9edb53SThibaut Varene 	u32 result;
6693f9edb53SThibaut Varene 
6707f548217SGreg Kroah-Hartman 	if (!buf)
6713f9edb53SThibaut Varene 		return -EINVAL;
6723f9edb53SThibaut Varene 
6733f9edb53SThibaut Varene 	/* get diagnostic */
6743f9edb53SThibaut Varene 	if (pdc_stable_read(PDCS_ADDR_DIAG, &result, sizeof(result)) != PDC_OK)
6753f9edb53SThibaut Varene 		return -EIO;
6763f9edb53SThibaut Varene 
6773f9edb53SThibaut Varene 	out += sprintf(out, "0x%.4x\n", (result >> 16));
678c7428422SThibaut VARENE 
679c7428422SThibaut VARENE 	return out - buf;
680c7428422SThibaut VARENE }
681c7428422SThibaut VARENE 
682c7428422SThibaut VARENE /**
683c7428422SThibaut VARENE  * pdcs_fastsize_read - Stable Storage FastSize register output.
684c7428422SThibaut VARENE  * @buf: The output buffer to write to.
685c7428422SThibaut VARENE  *
686c7428422SThibaut VARENE  * This register holds the amount of system RAM to be tested during boot sequence.
687c7428422SThibaut VARENE  */
6887f548217SGreg Kroah-Hartman static ssize_t pdcs_fastsize_read(struct kobject *kobj,
6897f548217SGreg Kroah-Hartman 				  struct kobj_attribute *attr, char *buf)
690c7428422SThibaut VARENE {
691c7428422SThibaut VARENE 	char *out = buf;
6923f9edb53SThibaut Varene 	u32 result;
693c7428422SThibaut VARENE 
6947f548217SGreg Kroah-Hartman 	if (!buf)
695c7428422SThibaut VARENE 		return -EINVAL;
6961da177e4SLinus Torvalds 
6971da177e4SLinus Torvalds 	/* get fast-size */
6981da177e4SLinus Torvalds 	if (pdc_stable_read(PDCS_ADDR_FSIZ, &result, sizeof(result)) != PDC_OK)
6991da177e4SLinus Torvalds 		return -EIO;
7001da177e4SLinus Torvalds 
7011da177e4SLinus Torvalds 	if ((result & 0x0F) < 0x0E)
702abff7543SRandolph Chung 		out += sprintf(out, "%d kB", (1<<(result & 0x0F))*256);
7031da177e4SLinus Torvalds 	else
7041da177e4SLinus Torvalds 		out += sprintf(out, "All");
7051da177e4SLinus Torvalds 	out += sprintf(out, "\n");
7061da177e4SLinus Torvalds 
7071da177e4SLinus Torvalds 	return out - buf;
7081da177e4SLinus Torvalds }
7091da177e4SLinus Torvalds 
7101da177e4SLinus Torvalds /**
7113f9edb53SThibaut Varene  * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output.
7123f9edb53SThibaut Varene  * @buf: The output buffer to write to.
7133f9edb53SThibaut Varene  *
7143f9edb53SThibaut Varene  * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available.
7153f9edb53SThibaut Varene  */
7167f548217SGreg Kroah-Hartman static ssize_t pdcs_osdep2_read(struct kobject *kobj,
7177f548217SGreg Kroah-Hartman 				struct kobj_attribute *attr, char *buf)
7183f9edb53SThibaut Varene {
7193f9edb53SThibaut Varene 	char *out = buf;
7203f9edb53SThibaut Varene 	unsigned long size;
7213f9edb53SThibaut Varene 	unsigned short i;
7223f9edb53SThibaut Varene 	u32 result;
7233f9edb53SThibaut Varene 
7243f9edb53SThibaut Varene 	if (unlikely(pdcs_size <= 224))
7253f9edb53SThibaut Varene 		return -ENODATA;
7263f9edb53SThibaut Varene 
7273f9edb53SThibaut Varene 	size = pdcs_size - 224;
7283f9edb53SThibaut Varene 
7297f548217SGreg Kroah-Hartman 	if (!buf)
7303f9edb53SThibaut Varene 		return -EINVAL;
7313f9edb53SThibaut Varene 
7323f9edb53SThibaut Varene 	for (i=0; i<size; i+=4) {
7333f9edb53SThibaut Varene 		if (unlikely(pdc_stable_read(PDCS_ADDR_OSD2 + i, &result,
7343f9edb53SThibaut Varene 					sizeof(result)) != PDC_OK))
7353f9edb53SThibaut Varene 			return -EIO;
7363f9edb53SThibaut Varene 		out += sprintf(out, "0x%.8x\n", result);
7373f9edb53SThibaut Varene 	}
7383f9edb53SThibaut Varene 
7393f9edb53SThibaut Varene 	return out - buf;
7403f9edb53SThibaut Varene }
7413f9edb53SThibaut Varene 
7423f9edb53SThibaut Varene /**
743c7428422SThibaut VARENE  * pdcs_auto_write - This function handles autoboot/search flag modifying.
7441da177e4SLinus Torvalds  * @buf: The input buffer to read from.
7451da177e4SLinus Torvalds  * @count: The number of bytes to be read.
746c7428422SThibaut VARENE  * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
7471da177e4SLinus Torvalds  *
748c7428422SThibaut VARENE  * We will call this function to change the current autoboot flag.
7491da177e4SLinus Torvalds  * We expect a precise syntax:
750c7428422SThibaut VARENE  *	\"n\" (n == 0 or 1) to toggle AutoBoot Off or On
7511da177e4SLinus Torvalds  */
7527f548217SGreg Kroah-Hartman static ssize_t pdcs_auto_write(struct kobject *kobj,
7537f548217SGreg Kroah-Hartman 			       struct kobj_attribute *attr, const char *buf,
7547f548217SGreg Kroah-Hartman 			       size_t count, int knob)
7551da177e4SLinus Torvalds {
7561da177e4SLinus Torvalds 	struct pdcspath_entry *pathentry;
7571da177e4SLinus Torvalds 	unsigned char flags;
7581da177e4SLinus Torvalds 	char in[count+1], *temp;
7591da177e4SLinus Torvalds 	char c;
7601da177e4SLinus Torvalds 
7611da177e4SLinus Torvalds 	if (!capable(CAP_SYS_ADMIN))
7621da177e4SLinus Torvalds 		return -EACCES;
7631da177e4SLinus Torvalds 
7647f548217SGreg Kroah-Hartman 	if (!buf || !count)
7651da177e4SLinus Torvalds 		return -EINVAL;
7661da177e4SLinus Torvalds 
7671da177e4SLinus Torvalds 	/* We'll use a local copy of buf */
7681da177e4SLinus Torvalds 	memset(in, 0, count+1);
7691da177e4SLinus Torvalds 	strncpy(in, buf, count);
7701da177e4SLinus Torvalds 
7711da177e4SLinus Torvalds 	/* Current flags are stored in primary boot path entry */
7721da177e4SLinus Torvalds 	pathentry = &pdcspath_entry_primary;
7731da177e4SLinus Torvalds 
7741da177e4SLinus Torvalds 	/* Be nice to the existing flag record */
775c7428422SThibaut VARENE 	read_lock(&pathentry->rw_lock);
7761da177e4SLinus Torvalds 	flags = pathentry->devpath.flags;
777c7428422SThibaut VARENE 	read_unlock(&pathentry->rw_lock);
7781da177e4SLinus Torvalds 
7791da177e4SLinus Torvalds 	DPRINTK("%s: flags before: 0x%X\n", __func__, flags);
7801da177e4SLinus Torvalds 
781e7d2860bSAndré Goddard Rosa 	temp = skip_spaces(in);
7821da177e4SLinus Torvalds 
7831da177e4SLinus Torvalds 	c = *temp++ - '0';
7841da177e4SLinus Torvalds 	if ((c != 0) && (c != 1))
7851da177e4SLinus Torvalds 		goto parse_error;
7861da177e4SLinus Torvalds 	if (c == 0)
787c7428422SThibaut VARENE 		flags &= ~knob;
7881da177e4SLinus Torvalds 	else
789c7428422SThibaut VARENE 		flags |= knob;
7901da177e4SLinus Torvalds 
7911da177e4SLinus Torvalds 	DPRINTK("%s: flags after: 0x%X\n", __func__, flags);
7921da177e4SLinus Torvalds 
7931da177e4SLinus Torvalds 	/* So far so good, let's get in deep */
794c7428422SThibaut VARENE 	write_lock(&pathentry->rw_lock);
7951da177e4SLinus Torvalds 
7961da177e4SLinus Torvalds 	/* Change the path entry flags first */
7971da177e4SLinus Torvalds 	pathentry->devpath.flags = flags;
7981da177e4SLinus Torvalds 
7991da177e4SLinus Torvalds 	/* Now, dive in. Write back to the hardware */
800c7428422SThibaut VARENE 	pdcspath_store(pathentry);
801c7428422SThibaut VARENE 	write_unlock(&pathentry->rw_lock);
8021da177e4SLinus Torvalds 
803c7428422SThibaut VARENE 	printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" to \"%s\"\n",
804c7428422SThibaut VARENE 		(knob & PF_AUTOBOOT) ? "autoboot" : "autosearch",
805c7428422SThibaut VARENE 		(flags & knob) ? "On" : "Off");
8061da177e4SLinus Torvalds 
8071da177e4SLinus Torvalds 	return count;
8081da177e4SLinus Torvalds 
8091da177e4SLinus Torvalds parse_error:
810c7428422SThibaut VARENE 	printk(KERN_WARNING "%s: Parse error: expect \"n\" (n == 0 or 1)\n", __func__);
8111da177e4SLinus Torvalds 	return -EINVAL;
8121da177e4SLinus Torvalds }
8131da177e4SLinus Torvalds 
814c7428422SThibaut VARENE /**
815c7428422SThibaut VARENE  * pdcs_autoboot_write - This function handles autoboot flag modifying.
816c7428422SThibaut VARENE  * @buf: The input buffer to read from.
817c7428422SThibaut VARENE  * @count: The number of bytes to be read.
818c7428422SThibaut VARENE  *
819c7428422SThibaut VARENE  * We will call this function to change the current boot flags.
820c7428422SThibaut VARENE  * We expect a precise syntax:
821c7428422SThibaut VARENE  *	\"n\" (n == 0 or 1) to toggle AutoSearch Off or On
822c7428422SThibaut VARENE  */
8237f548217SGreg Kroah-Hartman static ssize_t pdcs_autoboot_write(struct kobject *kobj,
8247f548217SGreg Kroah-Hartman 				   struct kobj_attribute *attr,
8257f548217SGreg Kroah-Hartman 				   const char *buf, size_t count)
826c7428422SThibaut VARENE {
827ff451d70SJoel Soete 	return pdcs_auto_write(kobj, attr, buf, count, PF_AUTOBOOT);
828c7428422SThibaut VARENE }
829c7428422SThibaut VARENE 
830c7428422SThibaut VARENE /**
831c7428422SThibaut VARENE  * pdcs_autosearch_write - This function handles autosearch flag modifying.
832c7428422SThibaut VARENE  * @buf: The input buffer to read from.
833c7428422SThibaut VARENE  * @count: The number of bytes to be read.
834c7428422SThibaut VARENE  *
835c7428422SThibaut VARENE  * We will call this function to change the current boot flags.
836c7428422SThibaut VARENE  * We expect a precise syntax:
837c7428422SThibaut VARENE  *	\"n\" (n == 0 or 1) to toggle AutoSearch Off or On
838c7428422SThibaut VARENE  */
8397f548217SGreg Kroah-Hartman static ssize_t pdcs_autosearch_write(struct kobject *kobj,
8407f548217SGreg Kroah-Hartman 				     struct kobj_attribute *attr,
8417f548217SGreg Kroah-Hartman 				     const char *buf, size_t count)
842c7428422SThibaut VARENE {
843ff451d70SJoel Soete 	return pdcs_auto_write(kobj, attr, buf, count, PF_AUTOSEARCH);
844c7428422SThibaut VARENE }
845c7428422SThibaut VARENE 
8463f9edb53SThibaut Varene /**
8473f9edb53SThibaut Varene  * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input.
8483f9edb53SThibaut Varene  * @buf: The input buffer to read from.
8493f9edb53SThibaut Varene  * @count: The number of bytes to be read.
8503f9edb53SThibaut Varene  *
8513f9edb53SThibaut Varene  * This can store 16 bytes of OS-Dependent data. We use a byte-by-byte
8523f9edb53SThibaut Varene  * write approach. It's up to userspace to deal with it when constructing
8533f9edb53SThibaut Varene  * its input buffer.
8543f9edb53SThibaut Varene  */
8557f548217SGreg Kroah-Hartman static ssize_t pdcs_osdep1_write(struct kobject *kobj,
8567f548217SGreg Kroah-Hartman 				 struct kobj_attribute *attr,
8577f548217SGreg Kroah-Hartman 				 const char *buf, size_t count)
8583f9edb53SThibaut Varene {
8593f9edb53SThibaut Varene 	u8 in[16];
8603f9edb53SThibaut Varene 
8613f9edb53SThibaut Varene 	if (!capable(CAP_SYS_ADMIN))
8623f9edb53SThibaut Varene 		return -EACCES;
8633f9edb53SThibaut Varene 
8647f548217SGreg Kroah-Hartman 	if (!buf || !count)
8653f9edb53SThibaut Varene 		return -EINVAL;
8663f9edb53SThibaut Varene 
867ec1fdc24SKyle McMartin 	if (unlikely(pdcs_osid != OS_ID_LINUX))
8683f9edb53SThibaut Varene 		return -EPERM;
8693f9edb53SThibaut Varene 
8703f9edb53SThibaut Varene 	if (count > 16)
8713f9edb53SThibaut Varene 		return -EMSGSIZE;
8723f9edb53SThibaut Varene 
8733f9edb53SThibaut Varene 	/* We'll use a local copy of buf */
8743f9edb53SThibaut Varene 	memset(in, 0, 16);
8753f9edb53SThibaut Varene 	memcpy(in, buf, count);
8763f9edb53SThibaut Varene 
8773f9edb53SThibaut Varene 	if (pdc_stable_write(PDCS_ADDR_OSD1, &in, sizeof(in)) != PDC_OK)
8783f9edb53SThibaut Varene 		return -EIO;
8793f9edb53SThibaut Varene 
8803f9edb53SThibaut Varene 	return count;
8813f9edb53SThibaut Varene }
8823f9edb53SThibaut Varene 
8833f9edb53SThibaut Varene /**
8843f9edb53SThibaut Varene  * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input.
8853f9edb53SThibaut Varene  * @buf: The input buffer to read from.
8863f9edb53SThibaut Varene  * @count: The number of bytes to be read.
8873f9edb53SThibaut Varene  *
8883f9edb53SThibaut Varene  * This can store pdcs_size - 224 bytes of OS-Dependent data. We use a
8893f9edb53SThibaut Varene  * byte-by-byte write approach. It's up to userspace to deal with it when
8903f9edb53SThibaut Varene  * constructing its input buffer.
8913f9edb53SThibaut Varene  */
8927f548217SGreg Kroah-Hartman static ssize_t pdcs_osdep2_write(struct kobject *kobj,
8937f548217SGreg Kroah-Hartman 				 struct kobj_attribute *attr,
8947f548217SGreg Kroah-Hartman 				 const char *buf, size_t count)
8953f9edb53SThibaut Varene {
8963f9edb53SThibaut Varene 	unsigned long size;
8973f9edb53SThibaut Varene 	unsigned short i;
8983f9edb53SThibaut Varene 	u8 in[4];
8993f9edb53SThibaut Varene 
9003f9edb53SThibaut Varene 	if (!capable(CAP_SYS_ADMIN))
9013f9edb53SThibaut Varene 		return -EACCES;
9023f9edb53SThibaut Varene 
9037f548217SGreg Kroah-Hartman 	if (!buf || !count)
9043f9edb53SThibaut Varene 		return -EINVAL;
9053f9edb53SThibaut Varene 
9063f9edb53SThibaut Varene 	if (unlikely(pdcs_size <= 224))
9073f9edb53SThibaut Varene 		return -ENOSYS;
9083f9edb53SThibaut Varene 
909ec1fdc24SKyle McMartin 	if (unlikely(pdcs_osid != OS_ID_LINUX))
9103f9edb53SThibaut Varene 		return -EPERM;
9113f9edb53SThibaut Varene 
9123f9edb53SThibaut Varene 	size = pdcs_size - 224;
9133f9edb53SThibaut Varene 
9143f9edb53SThibaut Varene 	if (count > size)
9153f9edb53SThibaut Varene 		return -EMSGSIZE;
9163f9edb53SThibaut Varene 
9173f9edb53SThibaut Varene 	/* We'll use a local copy of buf */
9183f9edb53SThibaut Varene 
9193f9edb53SThibaut Varene 	for (i=0; i<count; i+=4) {
9203f9edb53SThibaut Varene 		memset(in, 0, 4);
9213f9edb53SThibaut Varene 		memcpy(in, buf+i, (count-i < 4) ? count-i : 4);
9223f9edb53SThibaut Varene 		if (unlikely(pdc_stable_write(PDCS_ADDR_OSD2 + i, &in,
9233f9edb53SThibaut Varene 					sizeof(in)) != PDC_OK))
9243f9edb53SThibaut Varene 			return -EIO;
9253f9edb53SThibaut Varene 	}
9263f9edb53SThibaut Varene 
9273f9edb53SThibaut Varene 	return count;
9283f9edb53SThibaut Varene }
9293f9edb53SThibaut Varene 
930c7428422SThibaut VARENE /* The remaining attributes. */
931c7428422SThibaut VARENE static PDCS_ATTR(size, 0444, pdcs_size_read, NULL);
932c7428422SThibaut VARENE static PDCS_ATTR(autoboot, 0644, pdcs_autoboot_read, pdcs_autoboot_write);
933c7428422SThibaut VARENE static PDCS_ATTR(autosearch, 0644, pdcs_autosearch_read, pdcs_autosearch_write);
934c7428422SThibaut VARENE static PDCS_ATTR(timer, 0444, pdcs_timer_read, NULL);
9353f9edb53SThibaut Varene static PDCS_ATTR(osid, 0444, pdcs_osid_read, NULL);
9363f9edb53SThibaut Varene static PDCS_ATTR(osdep1, 0600, pdcs_osdep1_read, pdcs_osdep1_write);
9373f9edb53SThibaut Varene static PDCS_ATTR(diagnostic, 0400, pdcs_diagnostic_read, NULL);
938c7428422SThibaut VARENE static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL);
9393f9edb53SThibaut Varene static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write);
9401da177e4SLinus Torvalds 
9417f548217SGreg Kroah-Hartman static struct attribute *pdcs_subsys_attrs[] = {
9427f548217SGreg Kroah-Hartman 	&pdcs_attr_size.attr,
9437f548217SGreg Kroah-Hartman 	&pdcs_attr_autoboot.attr,
9447f548217SGreg Kroah-Hartman 	&pdcs_attr_autosearch.attr,
9457f548217SGreg Kroah-Hartman 	&pdcs_attr_timer.attr,
9467f548217SGreg Kroah-Hartman 	&pdcs_attr_osid.attr,
9477f548217SGreg Kroah-Hartman 	&pdcs_attr_osdep1.attr,
9487f548217SGreg Kroah-Hartman 	&pdcs_attr_diagnostic.attr,
9497f548217SGreg Kroah-Hartman 	&pdcs_attr_fastsize.attr,
9507f548217SGreg Kroah-Hartman 	&pdcs_attr_osdep2.attr,
951c7428422SThibaut VARENE 	NULL,
9521da177e4SLinus Torvalds };
9531da177e4SLinus Torvalds 
9547f548217SGreg Kroah-Hartman static struct attribute_group pdcs_attr_group = {
9557f548217SGreg Kroah-Hartman 	.attrs = pdcs_subsys_attrs,
9567f548217SGreg Kroah-Hartman };
9577f548217SGreg Kroah-Hartman 
958c829a5b4SGreg Kroah-Hartman static struct kobject *stable_kobj;
9594443d07fSGreg Kroah-Hartman static struct kset *paths_kset;
9601da177e4SLinus Torvalds 
9611da177e4SLinus Torvalds /**
9621da177e4SLinus Torvalds  * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
9631da177e4SLinus Torvalds  *
9641da177e4SLinus Torvalds  * It creates kobjects corresponding to each path entry with nice sysfs
9651da177e4SLinus Torvalds  * links to the real device. This is where the magic takes place: when
9661da177e4SLinus Torvalds  * registering the subsystem attributes during module init, each kobject hereby
9671da177e4SLinus Torvalds  * created will show in the sysfs tree as a folder containing files as defined
9681da177e4SLinus Torvalds  * by path_subsys_attr[].
9691da177e4SLinus Torvalds  */
9701da177e4SLinus Torvalds static inline int __init
9711da177e4SLinus Torvalds pdcs_register_pathentries(void)
9721da177e4SLinus Torvalds {
9731da177e4SLinus Torvalds 	unsigned short i;
9741da177e4SLinus Torvalds 	struct pdcspath_entry *entry;
9754b991da7SThibaut VARENE 	int err;
9761da177e4SLinus Torvalds 
977c7428422SThibaut VARENE 	/* Initialize the entries rw_lock before anything else */
978c7428422SThibaut VARENE 	for (i = 0; (entry = pdcspath_entries[i]); i++)
979c7428422SThibaut VARENE 		rwlock_init(&entry->rw_lock);
980c7428422SThibaut VARENE 
9811da177e4SLinus Torvalds 	for (i = 0; (entry = pdcspath_entries[i]); i++) {
982c7428422SThibaut VARENE 		write_lock(&entry->rw_lock);
983c7428422SThibaut VARENE 		err = pdcspath_fetch(entry);
984c7428422SThibaut VARENE 		write_unlock(&entry->rw_lock);
985c7428422SThibaut VARENE 
986c7428422SThibaut VARENE 		if (err < 0)
9871da177e4SLinus Torvalds 			continue;
9881da177e4SLinus Torvalds 
9894443d07fSGreg Kroah-Hartman 		entry->kobj.kset = paths_kset;
99073f368cfSGreg Kroah-Hartman 		err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL,
99173f368cfSGreg Kroah-Hartman 					   "%s", entry->name);
99273f368cfSGreg Kroah-Hartman 		if (err)
9934b991da7SThibaut VARENE 			return err;
9944b991da7SThibaut VARENE 
9954b991da7SThibaut VARENE 		/* kobject is now registered */
996c7428422SThibaut VARENE 		write_lock(&entry->rw_lock);
9974b991da7SThibaut VARENE 		entry->ready = 2;
9981da177e4SLinus Torvalds 
9991da177e4SLinus Torvalds 		/* Add a nice symlink to the real device */
100026f03249SKyle McMartin 		if (entry->dev) {
100126f03249SKyle McMartin 			err = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device");
100226f03249SKyle McMartin 			WARN_ON(err);
100326f03249SKyle McMartin 		}
1004c7428422SThibaut VARENE 
1005c7428422SThibaut VARENE 		write_unlock(&entry->rw_lock);
100673f368cfSGreg Kroah-Hartman 		kobject_uevent(&entry->kobj, KOBJ_ADD);
10071da177e4SLinus Torvalds 	}
10081da177e4SLinus Torvalds 
10091da177e4SLinus Torvalds 	return 0;
10101da177e4SLinus Torvalds }
10111da177e4SLinus Torvalds 
10121da177e4SLinus Torvalds /**
10131da177e4SLinus Torvalds  * pdcs_unregister_pathentries - Routine called when unregistering the module.
10141da177e4SLinus Torvalds  */
10154b991da7SThibaut VARENE static inline void
10161da177e4SLinus Torvalds pdcs_unregister_pathentries(void)
10171da177e4SLinus Torvalds {
10181da177e4SLinus Torvalds 	unsigned short i;
10191da177e4SLinus Torvalds 	struct pdcspath_entry *entry;
10201da177e4SLinus Torvalds 
1021c7428422SThibaut VARENE 	for (i = 0; (entry = pdcspath_entries[i]); i++) {
1022c7428422SThibaut VARENE 		read_lock(&entry->rw_lock);
10234b991da7SThibaut VARENE 		if (entry->ready >= 2)
1024c10997f6SGreg Kroah-Hartman 			kobject_put(&entry->kobj);
1025c7428422SThibaut VARENE 		read_unlock(&entry->rw_lock);
1026c7428422SThibaut VARENE 	}
10271da177e4SLinus Torvalds }
10281da177e4SLinus Torvalds 
10291da177e4SLinus Torvalds /*
1030c7428422SThibaut VARENE  * For now we register the stable subsystem with the firmware subsystem
1031c7428422SThibaut VARENE  * and the paths subsystem with the stable subsystem
10321da177e4SLinus Torvalds  */
10331da177e4SLinus Torvalds static int __init
10341da177e4SLinus Torvalds pdc_stable_init(void)
10351da177e4SLinus Torvalds {
10367f548217SGreg Kroah-Hartman 	int rc = 0, error = 0;
10373f9edb53SThibaut Varene 	u32 result;
10381da177e4SLinus Torvalds 
10391da177e4SLinus Torvalds 	/* find the size of the stable storage */
10401da177e4SLinus Torvalds 	if (pdc_stable_get_size(&pdcs_size) != PDC_OK)
10411da177e4SLinus Torvalds 		return -ENODEV;
10421da177e4SLinus Torvalds 
1043c7428422SThibaut VARENE 	/* make sure we have enough data */
1044c7428422SThibaut VARENE 	if (pdcs_size < 96)
1045c7428422SThibaut VARENE 		return -ENODATA;
10461da177e4SLinus Torvalds 
1047c7428422SThibaut VARENE 	printk(KERN_INFO PDCS_PREFIX " facility v%s\n", PDCS_VERSION);
1048c7428422SThibaut VARENE 
10493f9edb53SThibaut Varene 	/* get OSID */
10503f9edb53SThibaut Varene 	if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK)
10513f9edb53SThibaut Varene 		return -EIO;
10523f9edb53SThibaut Varene 
10533f9edb53SThibaut Varene 	/* the actual result is 16 bits away */
10543f9edb53SThibaut Varene 	pdcs_osid = (u16)(result >> 16);
10553f9edb53SThibaut Varene 
1056c829a5b4SGreg Kroah-Hartman 	/* For now we'll register the directory at /sys/firmware/stable */
1057c829a5b4SGreg Kroah-Hartman 	stable_kobj = kobject_create_and_add("stable", firmware_kobj);
1058c829a5b4SGreg Kroah-Hartman 	if (!stable_kobj) {
10594443d07fSGreg Kroah-Hartman 		rc = -ENOMEM;
10604b991da7SThibaut VARENE 		goto fail_firmreg;
10614443d07fSGreg Kroah-Hartman 	}
10621da177e4SLinus Torvalds 
1063c7428422SThibaut VARENE 	/* Don't forget the root entries */
1064ff451d70SJoel Soete 	error = sysfs_create_group(stable_kobj, &pdcs_attr_group);
10651da177e4SLinus Torvalds 
10664443d07fSGreg Kroah-Hartman 	/* register the paths kset as a child of the stable kset */
1067c829a5b4SGreg Kroah-Hartman 	paths_kset = kset_create_and_add("paths", NULL, stable_kobj);
10684443d07fSGreg Kroah-Hartman 	if (!paths_kset) {
10694443d07fSGreg Kroah-Hartman 		rc = -ENOMEM;
10704443d07fSGreg Kroah-Hartman 		goto fail_ksetreg;
10714443d07fSGreg Kroah-Hartman 	}
10721da177e4SLinus Torvalds 
10734443d07fSGreg Kroah-Hartman 	/* now we create all "files" for the paths kset */
10744b991da7SThibaut VARENE 	if ((rc = pdcs_register_pathentries()))
10754b991da7SThibaut VARENE 		goto fail_pdcsreg;
10761da177e4SLinus Torvalds 
10774b991da7SThibaut VARENE 	return rc;
10784b991da7SThibaut VARENE 
10794b991da7SThibaut VARENE fail_pdcsreg:
10804b991da7SThibaut VARENE 	pdcs_unregister_pathentries();
10814443d07fSGreg Kroah-Hartman 	kset_unregister(paths_kset);
10824b991da7SThibaut VARENE 
10834443d07fSGreg Kroah-Hartman fail_ksetreg:
1084c10997f6SGreg Kroah-Hartman 	kobject_put(stable_kobj);
10854b991da7SThibaut VARENE 
10864b991da7SThibaut VARENE fail_firmreg:
1087c7428422SThibaut VARENE 	printk(KERN_INFO PDCS_PREFIX " bailing out\n");
10884b991da7SThibaut VARENE 	return rc;
10891da177e4SLinus Torvalds }
10901da177e4SLinus Torvalds 
10911da177e4SLinus Torvalds static void __exit
10921da177e4SLinus Torvalds pdc_stable_exit(void)
10931da177e4SLinus Torvalds {
10941da177e4SLinus Torvalds 	pdcs_unregister_pathentries();
10954443d07fSGreg Kroah-Hartman 	kset_unregister(paths_kset);
1096c10997f6SGreg Kroah-Hartman 	kobject_put(stable_kobj);
10971da177e4SLinus Torvalds }
10981da177e4SLinus Torvalds 
10991da177e4SLinus Torvalds 
11001da177e4SLinus Torvalds module_init(pdc_stable_init);
11011da177e4SLinus Torvalds module_exit(pdc_stable_exit);
1102