pdc_stable.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. /*
  2. * Interfaces to retrieve and set PDC Stable options (firmware)
  3. *
  4. * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. *
  21. * DEV NOTE: the PDC Procedures reference states that:
  22. * "A minimum of 96 bytes of Stable Storage is required. Providing more than
  23. * 96 bytes of Stable Storage is optional [...]. Failure to provide the
  24. * optional locations from 96 to 192 results in the loss of certain
  25. * functionality during boot."
  26. *
  27. * Since locations between 96 and 192 are the various paths, most (if not
  28. * all) PA-RISC machines should have them. Anyway, for safety reasons, the
  29. * following code can deal with only 96 bytes of Stable Storage, and all
  30. * sizes between 96 and 192 bytes (provided they are multiple of struct
  31. * device_path size, eg: 128, 160 and 192) to provide full information.
  32. * The code makes no use of data above 192 bytes. One last word: there's one
  33. * path we can always count on: the primary path.
  34. */
  35. #undef PDCS_DEBUG
  36. #ifdef PDCS_DEBUG
  37. #define DPRINTK(fmt, args...) printk(KERN_DEBUG fmt, ## args)
  38. #else
  39. #define DPRINTK(fmt, args...)
  40. #endif
  41. #include <linux/module.h>
  42. #include <linux/init.h>
  43. #include <linux/sched.h> /* for capable() */
  44. #include <linux/kernel.h>
  45. #include <linux/string.h>
  46. #include <linux/ctype.h>
  47. #include <linux/sysfs.h>
  48. #include <linux/kobject.h>
  49. #include <linux/device.h>
  50. #include <linux/errno.h>
  51. #include <asm/pdc.h>
  52. #include <asm/page.h>
  53. #include <asm/uaccess.h>
  54. #include <asm/hardware.h>
  55. #define PDCS_VERSION "0.09"
  56. #define PDCS_ADDR_PPRI 0x00
  57. #define PDCS_ADDR_OSID 0x40
  58. #define PDCS_ADDR_FSIZ 0x5C
  59. #define PDCS_ADDR_PCON 0x60
  60. #define PDCS_ADDR_PALT 0x80
  61. #define PDCS_ADDR_PKBD 0xA0
  62. MODULE_AUTHOR("Thibaut VARENE <varenet@parisc-linux.org>");
  63. MODULE_DESCRIPTION("sysfs interface to HP PDC Stable Storage data");
  64. MODULE_LICENSE("GPL");
  65. MODULE_VERSION(PDCS_VERSION);
  66. static unsigned long pdcs_size = 0;
  67. /* This struct defines what we need to deal with a parisc pdc path entry */
  68. struct pdcspath_entry {
  69. short ready; /* entry record is valid if != 0 */
  70. unsigned long addr; /* entry address in stable storage */
  71. char *name; /* entry name */
  72. struct device_path devpath; /* device path in parisc representation */
  73. struct device *dev; /* corresponding device */
  74. struct kobject kobj;
  75. };
  76. struct pdcspath_attribute {
  77. struct attribute attr;
  78. ssize_t (*show)(struct pdcspath_entry *entry, char *buf);
  79. ssize_t (*store)(struct pdcspath_entry *entry, const char *buf, size_t count);
  80. };
  81. #define PDCSPATH_ENTRY(_addr, _name) \
  82. struct pdcspath_entry pdcspath_entry_##_name = { \
  83. .ready = 0, \
  84. .addr = _addr, \
  85. .name = __stringify(_name), \
  86. };
  87. #define PDCS_ATTR(_name, _mode, _show, _store) \
  88. struct subsys_attribute pdcs_attr_##_name = { \
  89. .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \
  90. .show = _show, \
  91. .store = _store, \
  92. };
  93. #define PATHS_ATTR(_name, _mode, _show, _store) \
  94. struct pdcspath_attribute paths_attr_##_name = { \
  95. .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \
  96. .show = _show, \
  97. .store = _store, \
  98. };
  99. #define to_pdcspath_attribute(_attr) container_of(_attr, struct pdcspath_attribute, attr)
  100. #define to_pdcspath_entry(obj) container_of(obj, struct pdcspath_entry, kobj)
  101. /**
  102. * pdcspath_fetch - This function populates the path entry structs.
  103. * @entry: A pointer to an allocated pdcspath_entry.
  104. *
  105. * The general idea is that you don't read from the Stable Storage every time
  106. * you access the files provided by the facilites. We store a copy of the
  107. * content of the stable storage WRT various paths in these structs. We read
  108. * these structs when reading the files, and we will write to these structs when
  109. * writing to the files, and only then write them back to the Stable Storage.
  110. */
  111. static int
  112. pdcspath_fetch(struct pdcspath_entry *entry)
  113. {
  114. struct device_path *devpath;
  115. if (!entry)
  116. return -EINVAL;
  117. devpath = &entry->devpath;
  118. DPRINTK("%s: fetch: 0x%p, 0x%p, addr: 0x%lx\n", __func__,
  119. entry, devpath, entry->addr);
  120. /* addr, devpath and count must be word aligned */
  121. if (pdc_stable_read(entry->addr, devpath, sizeof(*devpath)) != PDC_OK)
  122. return -EIO;
  123. /* Find the matching device.
  124. NOTE: hardware_path overlays with device_path, so the nice cast can
  125. be used */
  126. entry->dev = hwpath_to_device((struct hardware_path *)devpath);
  127. entry->ready = 1;
  128. DPRINTK("%s: device: 0x%p\n", __func__, entry->dev);
  129. return 0;
  130. }
  131. /**
  132. * pdcspath_store - This function writes a path to stable storage.
  133. * @entry: A pointer to an allocated pdcspath_entry.
  134. *
  135. * It can be used in two ways: either by passing it a preset devpath struct
  136. * containing an already computed hardware path, or by passing it a device
  137. * pointer, from which it'll find out the corresponding hardware path.
  138. * For now we do not handle the case where there's an error in writing to the
  139. * Stable Storage area, so you'd better not mess up the data :P
  140. */
  141. static int
  142. pdcspath_store(struct pdcspath_entry *entry)
  143. {
  144. struct device_path *devpath;
  145. if (!entry)
  146. return -EINVAL;
  147. devpath = &entry->devpath;
  148. /* We expect the caller to set the ready flag to 0 if the hardware
  149. path struct provided is invalid, so that we know we have to fill it.
  150. First case, we don't have a preset hwpath... */
  151. if (!entry->ready) {
  152. /* ...but we have a device, map it */
  153. if (entry->dev)
  154. device_to_hwpath(entry->dev, (struct hardware_path *)devpath);
  155. else
  156. return -EINVAL;
  157. }
  158. /* else, we expect the provided hwpath to be valid. */
  159. DPRINTK("%s: store: 0x%p, 0x%p, addr: 0x%lx\n", __func__,
  160. entry, devpath, entry->addr);
  161. /* addr, devpath and count must be word aligned */
  162. if (pdc_stable_write(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) {
  163. printk(KERN_ERR "%s: an error occured when writing to PDC.\n"
  164. "It is likely that the Stable Storage data has been corrupted.\n"
  165. "Please check it carefully upon next reboot.\n", __func__);
  166. return -EIO;
  167. }
  168. entry->ready = 1;
  169. DPRINTK("%s: device: 0x%p\n", __func__, entry->dev);
  170. return 0;
  171. }
  172. /**
  173. * pdcspath_hwpath_read - This function handles hardware path pretty printing.
  174. * @entry: An allocated and populated pdscpath_entry struct.
  175. * @buf: The output buffer to write to.
  176. *
  177. * We will call this function to format the output of the hwpath attribute file.
  178. */
  179. static ssize_t
  180. pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf)
  181. {
  182. char *out = buf;
  183. struct device_path *devpath;
  184. unsigned short i;
  185. if (!entry || !buf)
  186. return -EINVAL;
  187. devpath = &entry->devpath;
  188. if (!entry->ready)
  189. return -ENODATA;
  190. for (i = 0; i < 6; i++) {
  191. if (devpath->bc[i] >= 128)
  192. continue;
  193. out += sprintf(out, "%u/", (unsigned char)devpath->bc[i]);
  194. }
  195. out += sprintf(out, "%u\n", (unsigned char)devpath->mod);
  196. return out - buf;
  197. }
  198. /**
  199. * pdcspath_hwpath_write - This function handles hardware path modifying.
  200. * @entry: An allocated and populated pdscpath_entry struct.
  201. * @buf: The input buffer to read from.
  202. * @count: The number of bytes to be read.
  203. *
  204. * We will call this function to change the current hardware path.
  205. * Hardware paths are to be given '/'-delimited, without brackets.
  206. * We take care to make sure that the provided path actually maps to an existing
  207. * device, BUT nothing would prevent some foolish user to set the path to some
  208. * PCI bridge or even a CPU...
  209. * A better work around would be to make sure we are at the end of a device tree
  210. * for instance, but it would be IMHO beyond the simple scope of that driver.
  211. * The aim is to provide a facility. Data correctness is left to userland.
  212. */
  213. static ssize_t
  214. pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t count)
  215. {
  216. struct hardware_path hwpath;
  217. unsigned short i;
  218. char in[count+1], *temp;
  219. struct device *dev;
  220. if (!entry || !buf || !count)
  221. return -EINVAL;
  222. /* We'll use a local copy of buf */
  223. memset(in, 0, count+1);
  224. strncpy(in, buf, count);
  225. /* Let's clean up the target. 0xff is a blank pattern */
  226. memset(&hwpath, 0xff, sizeof(hwpath));
  227. /* First, pick the mod field (the last one of the input string) */
  228. if (!(temp = strrchr(in, '/')))
  229. return -EINVAL;
  230. hwpath.mod = simple_strtoul(temp+1, NULL, 10);
  231. in[temp-in] = '\0'; /* truncate the remaining string. just precaution */
  232. DPRINTK("%s: mod: %d\n", __func__, hwpath.mod);
  233. /* Then, loop for each delimiter, making sure we don't have too many.
  234. we write the bc fields in a down-top way. No matter what, we stop
  235. before writing the last field. If there are too many fields anyway,
  236. then the user is a moron and it'll be caught up later when we'll
  237. check the consistency of the given hwpath. */
  238. for (i=5; ((temp = strrchr(in, '/'))) && (temp-in > 0) && (likely(i)); i--) {
  239. hwpath.bc[i] = simple_strtoul(temp+1, NULL, 10);
  240. in[temp-in] = '\0';
  241. DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]);
  242. }
  243. /* Store the final field */
  244. hwpath.bc[i] = simple_strtoul(in, NULL, 10);
  245. DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]);
  246. /* Now we check that the user isn't trying to lure us */
  247. if (!(dev = hwpath_to_device((struct hardware_path *)&hwpath))) {
  248. printk(KERN_WARNING "%s: attempt to set invalid \"%s\" "
  249. "hardware path: %s\n", __func__, entry->name, buf);
  250. return -EINVAL;
  251. }
  252. /* So far so good, let's get in deep */
  253. entry->ready = 0;
  254. entry->dev = dev;
  255. /* Now, dive in. Write back to the hardware */
  256. WARN_ON(pdcspath_store(entry)); /* this warn should *NEVER* happen */
  257. /* Update the symlink to the real device */
  258. sysfs_remove_link(&entry->kobj, "device");
  259. sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device");
  260. printk(KERN_INFO "PDC Stable Storage: changed \"%s\" path to \"%s\"\n",
  261. entry->name, buf);
  262. return count;
  263. }
  264. /**
  265. * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing.
  266. * @entry: An allocated and populated pdscpath_entry struct.
  267. * @buf: The output buffer to write to.
  268. *
  269. * We will call this function to format the output of the layer attribute file.
  270. */
  271. static ssize_t
  272. pdcspath_layer_read(struct pdcspath_entry *entry, char *buf)
  273. {
  274. char *out = buf;
  275. struct device_path *devpath;
  276. unsigned short i;
  277. if (!entry || !buf)
  278. return -EINVAL;
  279. devpath = &entry->devpath;
  280. if (!entry->ready)
  281. return -ENODATA;
  282. for (i = 0; devpath->layers[i] && (likely(i < 6)); i++)
  283. out += sprintf(out, "%u ", devpath->layers[i]);
  284. out += sprintf(out, "\n");
  285. return out - buf;
  286. }
  287. /**
  288. * pdcspath_layer_write - This function handles extended layer modifying.
  289. * @entry: An allocated and populated pdscpath_entry struct.
  290. * @buf: The input buffer to read from.
  291. * @count: The number of bytes to be read.
  292. *
  293. * We will call this function to change the current layer value.
  294. * Layers are to be given '.'-delimited, without brackets.
  295. * XXX beware we are far less checky WRT input data provided than for hwpath.
  296. * Potential harm can be done, since there's no way to check the validity of
  297. * the layer fields.
  298. */
  299. static ssize_t
  300. pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count)
  301. {
  302. unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */
  303. unsigned short i;
  304. char in[count+1], *temp;
  305. if (!entry || !buf || !count)
  306. return -EINVAL;
  307. /* We'll use a local copy of buf */
  308. memset(in, 0, count+1);
  309. strncpy(in, buf, count);
  310. /* Let's clean up the target. 0 is a blank pattern */
  311. memset(&layers, 0, sizeof(layers));
  312. /* First, pick the first layer */
  313. if (unlikely(!isdigit(*in)))
  314. return -EINVAL;
  315. layers[0] = simple_strtoul(in, NULL, 10);
  316. DPRINTK("%s: layer[0]: %d\n", __func__, layers[0]);
  317. temp = in;
  318. for (i=1; ((temp = strchr(temp, '.'))) && (likely(i<6)); i++) {
  319. if (unlikely(!isdigit(*(++temp))))
  320. return -EINVAL;
  321. layers[i] = simple_strtoul(temp, NULL, 10);
  322. DPRINTK("%s: layer[%d]: %d\n", __func__, i, layers[i]);
  323. }
  324. /* So far so good, let's get in deep */
  325. /* First, overwrite the current layers with the new ones, not touching
  326. the hardware path. */
  327. memcpy(&entry->devpath.layers, &layers, sizeof(layers));
  328. /* Now, dive in. Write back to the hardware */
  329. WARN_ON(pdcspath_store(entry)); /* this warn should *NEVER* happen */
  330. printk(KERN_INFO "PDC Stable Storage: changed \"%s\" layers to \"%s\"\n",
  331. entry->name, buf);
  332. return count;
  333. }
  334. /**
  335. * pdcspath_attr_show - Generic read function call wrapper.
  336. * @kobj: The kobject to get info from.
  337. * @attr: The attribute looked upon.
  338. * @buf: The output buffer.
  339. */
  340. static ssize_t
  341. pdcspath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
  342. {
  343. struct pdcspath_entry *entry = to_pdcspath_entry(kobj);
  344. struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr);
  345. ssize_t ret = 0;
  346. if (!capable(CAP_SYS_ADMIN))
  347. return -EACCES;
  348. if (pdcs_attr->show)
  349. ret = pdcs_attr->show(entry, buf);
  350. return ret;
  351. }
  352. /**
  353. * pdcspath_attr_store - Generic write function call wrapper.
  354. * @kobj: The kobject to write info to.
  355. * @attr: The attribute to be modified.
  356. * @buf: The input buffer.
  357. * @count: The size of the buffer.
  358. */
  359. static ssize_t
  360. pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
  361. const char *buf, size_t count)
  362. {
  363. struct pdcspath_entry *entry = to_pdcspath_entry(kobj);
  364. struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr);
  365. ssize_t ret = 0;
  366. if (!capable(CAP_SYS_ADMIN))
  367. return -EACCES;
  368. if (pdcs_attr->store)
  369. ret = pdcs_attr->store(entry, buf, count);
  370. return ret;
  371. }
  372. static struct sysfs_ops pdcspath_attr_ops = {
  373. .show = pdcspath_attr_show,
  374. .store = pdcspath_attr_store,
  375. };
  376. /* These are the two attributes of any PDC path. */
  377. static PATHS_ATTR(hwpath, 0600, pdcspath_hwpath_read, pdcspath_hwpath_write);
  378. static PATHS_ATTR(layer, 0600, pdcspath_layer_read, pdcspath_layer_write);
  379. static struct attribute *paths_subsys_attrs[] = {
  380. &paths_attr_hwpath.attr,
  381. &paths_attr_layer.attr,
  382. NULL,
  383. };
  384. /* Specific kobject type for our PDC paths */
  385. static struct kobj_type ktype_pdcspath = {
  386. .sysfs_ops = &pdcspath_attr_ops,
  387. .default_attrs = paths_subsys_attrs,
  388. };
  389. /* We hard define the 4 types of path we expect to find */
  390. static PDCSPATH_ENTRY(PDCS_ADDR_PPRI, primary);
  391. static PDCSPATH_ENTRY(PDCS_ADDR_PCON, console);
  392. static PDCSPATH_ENTRY(PDCS_ADDR_PALT, alternative);
  393. static PDCSPATH_ENTRY(PDCS_ADDR_PKBD, keyboard);
  394. /* An array containing all PDC paths we will deal with */
  395. static struct pdcspath_entry *pdcspath_entries[] = {
  396. &pdcspath_entry_primary,
  397. &pdcspath_entry_alternative,
  398. &pdcspath_entry_console,
  399. &pdcspath_entry_keyboard,
  400. NULL,
  401. };
  402. /**
  403. * pdcs_info_read - Pretty printing of the remaining useful data.
  404. * @entry: An allocated and populated subsytem struct. We don't use it tho.
  405. * @buf: The output buffer to write to.
  406. *
  407. * We will call this function to format the output of the 'info' attribute file.
  408. * Please refer to PDC Procedures documentation, section PDC_STABLE to get a
  409. * better insight of what we're doing here.
  410. */
  411. static ssize_t
  412. pdcs_info_read(struct subsystem *entry, char *buf)
  413. {
  414. char *out = buf;
  415. __u32 result;
  416. struct device_path devpath;
  417. char *tmpstr = NULL;
  418. if (!entry || !buf)
  419. return -EINVAL;
  420. /* show the size of the stable storage */
  421. out += sprintf(out, "Stable Storage size: %ld bytes\n", pdcs_size);
  422. /* deal with flags */
  423. if (pdc_stable_read(PDCS_ADDR_PPRI, &devpath, sizeof(devpath)) != PDC_OK)
  424. return -EIO;
  425. out += sprintf(out, "Autoboot: %s\n", (devpath.flags & PF_AUTOBOOT) ? "On" : "Off");
  426. out += sprintf(out, "Autosearch: %s\n", (devpath.flags & PF_AUTOSEARCH) ? "On" : "Off");
  427. out += sprintf(out, "Timer: %u s\n", (devpath.flags & PF_TIMER) ? (1 << (devpath.flags & PF_TIMER)) : 0);
  428. /* get OSID */
  429. if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK)
  430. return -EIO;
  431. /* the actual result is 16 bits away */
  432. switch (result >> 16) {
  433. case 0x0000: tmpstr = "No OS-dependent data"; break;
  434. case 0x0001: tmpstr = "HP-UX dependent data"; break;
  435. case 0x0002: tmpstr = "MPE-iX dependent data"; break;
  436. case 0x0003: tmpstr = "OSF dependent data"; break;
  437. case 0x0004: tmpstr = "HP-RT dependent data"; break;
  438. case 0x0005: tmpstr = "Novell Netware dependent data"; break;
  439. default: tmpstr = "Unknown"; break;
  440. }
  441. out += sprintf(out, "OS ID: %s (0x%.4x)\n", tmpstr, (result >> 16));
  442. /* get fast-size */
  443. if (pdc_stable_read(PDCS_ADDR_FSIZ, &result, sizeof(result)) != PDC_OK)
  444. return -EIO;
  445. out += sprintf(out, "Memory tested: ");
  446. if ((result & 0x0F) < 0x0E)
  447. out += sprintf(out, "%.3f MB", 0.256*(1<<(result & 0x0F)));
  448. else
  449. out += sprintf(out, "All");
  450. out += sprintf(out, "\n");
  451. return out - buf;
  452. }
  453. /**
  454. * pdcs_info_write - This function handles boot flag modifying.
  455. * @entry: An allocated and populated subsytem struct. We don't use it tho.
  456. * @buf: The input buffer to read from.
  457. * @count: The number of bytes to be read.
  458. *
  459. * We will call this function to change the current boot flags.
  460. * We expect a precise syntax:
  461. * \"n n\" (n == 0 or 1) to toggle respectively AutoBoot and AutoSearch
  462. *
  463. * As of now there is no incentive on my side to provide more "knobs" to that
  464. * interface, since modifying the rest of the data is pretty meaningless when
  465. * the machine is running and for the expected use of that facility, such as
  466. * PALO setting up the boot disk when installing a Linux distribution...
  467. */
  468. static ssize_t
  469. pdcs_info_write(struct subsystem *entry, const char *buf, size_t count)
  470. {
  471. struct pdcspath_entry *pathentry;
  472. unsigned char flags;
  473. char in[count+1], *temp;
  474. char c;
  475. if (!capable(CAP_SYS_ADMIN))
  476. return -EACCES;
  477. if (!entry || !buf || !count)
  478. return -EINVAL;
  479. /* We'll use a local copy of buf */
  480. memset(in, 0, count+1);
  481. strncpy(in, buf, count);
  482. /* Current flags are stored in primary boot path entry */
  483. pathentry = &pdcspath_entry_primary;
  484. /* Be nice to the existing flag record */
  485. flags = pathentry->devpath.flags;
  486. DPRINTK("%s: flags before: 0x%X\n", __func__, flags);
  487. temp = in;
  488. while (*temp && isspace(*temp))
  489. temp++;
  490. c = *temp++ - '0';
  491. if ((c != 0) && (c != 1))
  492. goto parse_error;
  493. if (c == 0)
  494. flags &= ~PF_AUTOBOOT;
  495. else
  496. flags |= PF_AUTOBOOT;
  497. if (*temp++ != ' ')
  498. goto parse_error;
  499. c = *temp++ - '0';
  500. if ((c != 0) && (c != 1))
  501. goto parse_error;
  502. if (c == 0)
  503. flags &= ~PF_AUTOSEARCH;
  504. else
  505. flags |= PF_AUTOSEARCH;
  506. DPRINTK("%s: flags after: 0x%X\n", __func__, flags);
  507. /* So far so good, let's get in deep */
  508. /* Change the path entry flags first */
  509. pathentry->devpath.flags = flags;
  510. /* Now, dive in. Write back to the hardware */
  511. WARN_ON(pdcspath_store(pathentry)); /* this warn should *NEVER* happen */
  512. printk(KERN_INFO "PDC Stable Storage: changed flags to \"%s\"\n", buf);
  513. return count;
  514. parse_error:
  515. printk(KERN_WARNING "%s: Parse error: expect \"n n\" (n == 0 or 1) for AB and AS\n", __func__);
  516. return -EINVAL;
  517. }
  518. /* The last attribute (the 'root' one actually) with all remaining data. */
  519. static PDCS_ATTR(info, 0600, pdcs_info_read, pdcs_info_write);
  520. static struct subsys_attribute *pdcs_subsys_attrs[] = {
  521. &pdcs_attr_info,
  522. NULL, /* maybe more in the future? */
  523. };
  524. static decl_subsys(paths, &ktype_pdcspath, NULL);
  525. static decl_subsys(pdc, NULL, NULL);
  526. /**
  527. * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
  528. *
  529. * It creates kobjects corresponding to each path entry with nice sysfs
  530. * links to the real device. This is where the magic takes place: when
  531. * registering the subsystem attributes during module init, each kobject hereby
  532. * created will show in the sysfs tree as a folder containing files as defined
  533. * by path_subsys_attr[].
  534. */
  535. static inline int __init
  536. pdcs_register_pathentries(void)
  537. {
  538. unsigned short i;
  539. struct pdcspath_entry *entry;
  540. for (i = 0; (entry = pdcspath_entries[i]); i++) {
  541. if (pdcspath_fetch(entry) < 0)
  542. continue;
  543. kobject_set_name(&entry->kobj, "%s", entry->name);
  544. kobj_set_kset_s(entry, paths_subsys);
  545. kobject_register(&entry->kobj);
  546. if (!entry->dev)
  547. continue;
  548. /* Add a nice symlink to the real device */
  549. sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device");
  550. }
  551. return 0;
  552. }
  553. /**
  554. * pdcs_unregister_pathentries - Routine called when unregistering the module.
  555. */
  556. static inline void __exit
  557. pdcs_unregister_pathentries(void)
  558. {
  559. unsigned short i;
  560. struct pdcspath_entry *entry;
  561. for (i = 0; (entry = pdcspath_entries[i]); i++)
  562. if (entry->ready)
  563. kobject_unregister(&entry->kobj);
  564. }
  565. /*
  566. * For now we register the pdc subsystem with the firmware subsystem
  567. * and the paths subsystem with the pdc subsystem
  568. */
  569. static int __init
  570. pdc_stable_init(void)
  571. {
  572. struct subsys_attribute *attr;
  573. int i, rc = 0, error = 0;
  574. /* find the size of the stable storage */
  575. if (pdc_stable_get_size(&pdcs_size) != PDC_OK)
  576. return -ENODEV;
  577. printk(KERN_INFO "PDC Stable Storage facility v%s\n", PDCS_VERSION);
  578. /* For now we'll register the pdc subsys within this driver */
  579. if ((rc = firmware_register(&pdc_subsys)))
  580. return rc;
  581. /* Don't forget the info entry */
  582. for (i = 0; (attr = pdcs_subsys_attrs[i]) && !error; i++)
  583. if (attr->show)
  584. error = subsys_create_file(&pdc_subsys, attr);
  585. /* register the paths subsys as a subsystem of pdc subsys */
  586. kset_set_kset_s(&paths_subsys, pdc_subsys);
  587. subsystem_register(&paths_subsys);
  588. /* now we create all "files" for the paths subsys */
  589. pdcs_register_pathentries();
  590. return 0;
  591. }
  592. static void __exit
  593. pdc_stable_exit(void)
  594. {
  595. pdcs_unregister_pathentries();
  596. subsystem_unregister(&paths_subsys);
  597. firmware_unregister(&pdc_subsys);
  598. }
  599. module_init(pdc_stable_init);
  600. module_exit(pdc_stable_exit);