pdc_stable.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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/kernel.h>
  44. #include <linux/string.h>
  45. #include <linux/capability.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.10"
  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 __read_mostly;
  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. /* kobject is already registered */
  169. entry->ready = 2;
  170. DPRINTK("%s: device: 0x%p\n", __func__, entry->dev);
  171. return 0;
  172. }
  173. /**
  174. * pdcspath_hwpath_read - This function handles hardware path pretty printing.
  175. * @entry: An allocated and populated pdscpath_entry struct.
  176. * @buf: The output buffer to write to.
  177. *
  178. * We will call this function to format the output of the hwpath attribute file.
  179. */
  180. static ssize_t
  181. pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf)
  182. {
  183. char *out = buf;
  184. struct device_path *devpath;
  185. unsigned short i;
  186. if (!entry || !buf)
  187. return -EINVAL;
  188. devpath = &entry->devpath;
  189. if (!entry->ready)
  190. return -ENODATA;
  191. for (i = 0; i < 6; i++) {
  192. if (devpath->bc[i] >= 128)
  193. continue;
  194. out += sprintf(out, "%u/", (unsigned char)devpath->bc[i]);
  195. }
  196. out += sprintf(out, "%u\n", (unsigned char)devpath->mod);
  197. return out - buf;
  198. }
  199. /**
  200. * pdcspath_hwpath_write - This function handles hardware path modifying.
  201. * @entry: An allocated and populated pdscpath_entry struct.
  202. * @buf: The input buffer to read from.
  203. * @count: The number of bytes to be read.
  204. *
  205. * We will call this function to change the current hardware path.
  206. * Hardware paths are to be given '/'-delimited, without brackets.
  207. * We take care to make sure that the provided path actually maps to an existing
  208. * device, BUT nothing would prevent some foolish user to set the path to some
  209. * PCI bridge or even a CPU...
  210. * A better work around would be to make sure we are at the end of a device tree
  211. * for instance, but it would be IMHO beyond the simple scope of that driver.
  212. * The aim is to provide a facility. Data correctness is left to userland.
  213. */
  214. static ssize_t
  215. pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t count)
  216. {
  217. struct hardware_path hwpath;
  218. unsigned short i;
  219. char in[count+1], *temp;
  220. struct device *dev;
  221. if (!entry || !buf || !count)
  222. return -EINVAL;
  223. /* We'll use a local copy of buf */
  224. memset(in, 0, count+1);
  225. strncpy(in, buf, count);
  226. /* Let's clean up the target. 0xff is a blank pattern */
  227. memset(&hwpath, 0xff, sizeof(hwpath));
  228. /* First, pick the mod field (the last one of the input string) */
  229. if (!(temp = strrchr(in, '/')))
  230. return -EINVAL;
  231. hwpath.mod = simple_strtoul(temp+1, NULL, 10);
  232. in[temp-in] = '\0'; /* truncate the remaining string. just precaution */
  233. DPRINTK("%s: mod: %d\n", __func__, hwpath.mod);
  234. /* Then, loop for each delimiter, making sure we don't have too many.
  235. we write the bc fields in a down-top way. No matter what, we stop
  236. before writing the last field. If there are too many fields anyway,
  237. then the user is a moron and it'll be caught up later when we'll
  238. check the consistency of the given hwpath. */
  239. for (i=5; ((temp = strrchr(in, '/'))) && (temp-in > 0) && (likely(i)); i--) {
  240. hwpath.bc[i] = simple_strtoul(temp+1, NULL, 10);
  241. in[temp-in] = '\0';
  242. DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]);
  243. }
  244. /* Store the final field */
  245. hwpath.bc[i] = simple_strtoul(in, NULL, 10);
  246. DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]);
  247. /* Now we check that the user isn't trying to lure us */
  248. if (!(dev = hwpath_to_device((struct hardware_path *)&hwpath))) {
  249. printk(KERN_WARNING "%s: attempt to set invalid \"%s\" "
  250. "hardware path: %s\n", __func__, entry->name, buf);
  251. return -EINVAL;
  252. }
  253. /* So far so good, let's get in deep */
  254. entry->ready = 0;
  255. entry->dev = dev;
  256. /* Now, dive in. Write back to the hardware */
  257. WARN_ON(pdcspath_store(entry)); /* this warn should *NEVER* happen */
  258. /* Update the symlink to the real device */
  259. sysfs_remove_link(&entry->kobj, "device");
  260. sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device");
  261. printk(KERN_INFO "PDC Stable Storage: changed \"%s\" path to \"%s\"\n",
  262. entry->name, buf);
  263. return count;
  264. }
  265. /**
  266. * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing.
  267. * @entry: An allocated and populated pdscpath_entry struct.
  268. * @buf: The output buffer to write to.
  269. *
  270. * We will call this function to format the output of the layer attribute file.
  271. */
  272. static ssize_t
  273. pdcspath_layer_read(struct pdcspath_entry *entry, char *buf)
  274. {
  275. char *out = buf;
  276. struct device_path *devpath;
  277. unsigned short i;
  278. if (!entry || !buf)
  279. return -EINVAL;
  280. devpath = &entry->devpath;
  281. if (!entry->ready)
  282. return -ENODATA;
  283. for (i = 0; devpath->layers[i] && (likely(i < 6)); i++)
  284. out += sprintf(out, "%u ", devpath->layers[i]);
  285. out += sprintf(out, "\n");
  286. return out - buf;
  287. }
  288. /**
  289. * pdcspath_layer_write - This function handles extended layer modifying.
  290. * @entry: An allocated and populated pdscpath_entry struct.
  291. * @buf: The input buffer to read from.
  292. * @count: The number of bytes to be read.
  293. *
  294. * We will call this function to change the current layer value.
  295. * Layers are to be given '.'-delimited, without brackets.
  296. * XXX beware we are far less checky WRT input data provided than for hwpath.
  297. * Potential harm can be done, since there's no way to check the validity of
  298. * the layer fields.
  299. */
  300. static ssize_t
  301. pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count)
  302. {
  303. unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */
  304. unsigned short i;
  305. char in[count+1], *temp;
  306. if (!entry || !buf || !count)
  307. return -EINVAL;
  308. /* We'll use a local copy of buf */
  309. memset(in, 0, count+1);
  310. strncpy(in, buf, count);
  311. /* Let's clean up the target. 0 is a blank pattern */
  312. memset(&layers, 0, sizeof(layers));
  313. /* First, pick the first layer */
  314. if (unlikely(!isdigit(*in)))
  315. return -EINVAL;
  316. layers[0] = simple_strtoul(in, NULL, 10);
  317. DPRINTK("%s: layer[0]: %d\n", __func__, layers[0]);
  318. temp = in;
  319. for (i=1; ((temp = strchr(temp, '.'))) && (likely(i<6)); i++) {
  320. if (unlikely(!isdigit(*(++temp))))
  321. return -EINVAL;
  322. layers[i] = simple_strtoul(temp, NULL, 10);
  323. DPRINTK("%s: layer[%d]: %d\n", __func__, i, layers[i]);
  324. }
  325. /* So far so good, let's get in deep */
  326. /* First, overwrite the current layers with the new ones, not touching
  327. the hardware path. */
  328. memcpy(&entry->devpath.layers, &layers, sizeof(layers));
  329. /* Now, dive in. Write back to the hardware */
  330. WARN_ON(pdcspath_store(entry)); /* this warn should *NEVER* happen */
  331. printk(KERN_INFO "PDC Stable Storage: changed \"%s\" layers to \"%s\"\n",
  332. entry->name, buf);
  333. return count;
  334. }
  335. /**
  336. * pdcspath_attr_show - Generic read function call wrapper.
  337. * @kobj: The kobject to get info from.
  338. * @attr: The attribute looked upon.
  339. * @buf: The output buffer.
  340. */
  341. static ssize_t
  342. pdcspath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
  343. {
  344. struct pdcspath_entry *entry = to_pdcspath_entry(kobj);
  345. struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr);
  346. ssize_t ret = 0;
  347. if (!capable(CAP_SYS_ADMIN))
  348. return -EACCES;
  349. if (pdcs_attr->show)
  350. ret = pdcs_attr->show(entry, buf);
  351. return ret;
  352. }
  353. /**
  354. * pdcspath_attr_store - Generic write function call wrapper.
  355. * @kobj: The kobject to write info to.
  356. * @attr: The attribute to be modified.
  357. * @buf: The input buffer.
  358. * @count: The size of the buffer.
  359. */
  360. static ssize_t
  361. pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
  362. const char *buf, size_t count)
  363. {
  364. struct pdcspath_entry *entry = to_pdcspath_entry(kobj);
  365. struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr);
  366. ssize_t ret = 0;
  367. if (!capable(CAP_SYS_ADMIN))
  368. return -EACCES;
  369. if (pdcs_attr->store)
  370. ret = pdcs_attr->store(entry, buf, count);
  371. return ret;
  372. }
  373. static struct sysfs_ops pdcspath_attr_ops = {
  374. .show = pdcspath_attr_show,
  375. .store = pdcspath_attr_store,
  376. };
  377. /* These are the two attributes of any PDC path. */
  378. static PATHS_ATTR(hwpath, 0600, pdcspath_hwpath_read, pdcspath_hwpath_write);
  379. static PATHS_ATTR(layer, 0600, pdcspath_layer_read, pdcspath_layer_write);
  380. static struct attribute *paths_subsys_attrs[] = {
  381. &paths_attr_hwpath.attr,
  382. &paths_attr_layer.attr,
  383. NULL,
  384. };
  385. /* Specific kobject type for our PDC paths */
  386. static struct kobj_type ktype_pdcspath = {
  387. .sysfs_ops = &pdcspath_attr_ops,
  388. .default_attrs = paths_subsys_attrs,
  389. };
  390. /* We hard define the 4 types of path we expect to find */
  391. static PDCSPATH_ENTRY(PDCS_ADDR_PPRI, primary);
  392. static PDCSPATH_ENTRY(PDCS_ADDR_PCON, console);
  393. static PDCSPATH_ENTRY(PDCS_ADDR_PALT, alternative);
  394. static PDCSPATH_ENTRY(PDCS_ADDR_PKBD, keyboard);
  395. /* An array containing all PDC paths we will deal with */
  396. static struct pdcspath_entry *pdcspath_entries[] = {
  397. &pdcspath_entry_primary,
  398. &pdcspath_entry_alternative,
  399. &pdcspath_entry_console,
  400. &pdcspath_entry_keyboard,
  401. NULL,
  402. };
  403. /**
  404. * pdcs_info_read - Pretty printing of the remaining useful data.
  405. * @entry: An allocated and populated subsytem struct. We don't use it tho.
  406. * @buf: The output buffer to write to.
  407. *
  408. * We will call this function to format the output of the 'info' attribute file.
  409. * Please refer to PDC Procedures documentation, section PDC_STABLE to get a
  410. * better insight of what we're doing here.
  411. */
  412. static ssize_t
  413. pdcs_info_read(struct subsystem *entry, char *buf)
  414. {
  415. char *out = buf;
  416. __u32 result;
  417. struct device_path devpath;
  418. char *tmpstr = NULL;
  419. if (!entry || !buf)
  420. return -EINVAL;
  421. /* show the size of the stable storage */
  422. out += sprintf(out, "Stable Storage size: %ld bytes\n", pdcs_size);
  423. /* deal with flags */
  424. if (pdc_stable_read(PDCS_ADDR_PPRI, &devpath, sizeof(devpath)) != PDC_OK)
  425. return -EIO;
  426. out += sprintf(out, "Autoboot: %s\n", (devpath.flags & PF_AUTOBOOT) ? "On" : "Off");
  427. out += sprintf(out, "Autosearch: %s\n", (devpath.flags & PF_AUTOSEARCH) ? "On" : "Off");
  428. out += sprintf(out, "Timer: %u s\n", (devpath.flags & PF_TIMER) ? (1 << (devpath.flags & PF_TIMER)) : 0);
  429. /* get OSID */
  430. if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK)
  431. return -EIO;
  432. /* the actual result is 16 bits away */
  433. switch (result >> 16) {
  434. case 0x0000: tmpstr = "No OS-dependent data"; break;
  435. case 0x0001: tmpstr = "HP-UX dependent data"; break;
  436. case 0x0002: tmpstr = "MPE-iX dependent data"; break;
  437. case 0x0003: tmpstr = "OSF dependent data"; break;
  438. case 0x0004: tmpstr = "HP-RT dependent data"; break;
  439. case 0x0005: tmpstr = "Novell Netware dependent data"; break;
  440. default: tmpstr = "Unknown"; break;
  441. }
  442. out += sprintf(out, "OS ID: %s (0x%.4x)\n", tmpstr, (result >> 16));
  443. /* get fast-size */
  444. if (pdc_stable_read(PDCS_ADDR_FSIZ, &result, sizeof(result)) != PDC_OK)
  445. return -EIO;
  446. out += sprintf(out, "Memory tested: ");
  447. if ((result & 0x0F) < 0x0E)
  448. out += sprintf(out, "%d kB", (1<<(result & 0x0F))*256);
  449. else
  450. out += sprintf(out, "All");
  451. out += sprintf(out, "\n");
  452. return out - buf;
  453. }
  454. /**
  455. * pdcs_info_write - This function handles boot flag modifying.
  456. * @entry: An allocated and populated subsytem struct. We don't use it tho.
  457. * @buf: The input buffer to read from.
  458. * @count: The number of bytes to be read.
  459. *
  460. * We will call this function to change the current boot flags.
  461. * We expect a precise syntax:
  462. * \"n n\" (n == 0 or 1) to toggle respectively AutoBoot and AutoSearch
  463. *
  464. * As of now there is no incentive on my side to provide more "knobs" to that
  465. * interface, since modifying the rest of the data is pretty meaningless when
  466. * the machine is running and for the expected use of that facility, such as
  467. * PALO setting up the boot disk when installing a Linux distribution...
  468. */
  469. static ssize_t
  470. pdcs_info_write(struct subsystem *entry, const char *buf, size_t count)
  471. {
  472. struct pdcspath_entry *pathentry;
  473. unsigned char flags;
  474. char in[count+1], *temp;
  475. char c;
  476. if (!capable(CAP_SYS_ADMIN))
  477. return -EACCES;
  478. if (!entry || !buf || !count)
  479. return -EINVAL;
  480. /* We'll use a local copy of buf */
  481. memset(in, 0, count+1);
  482. strncpy(in, buf, count);
  483. /* Current flags are stored in primary boot path entry */
  484. pathentry = &pdcspath_entry_primary;
  485. /* Be nice to the existing flag record */
  486. flags = pathentry->devpath.flags;
  487. DPRINTK("%s: flags before: 0x%X\n", __func__, flags);
  488. temp = in;
  489. while (*temp && isspace(*temp))
  490. temp++;
  491. c = *temp++ - '0';
  492. if ((c != 0) && (c != 1))
  493. goto parse_error;
  494. if (c == 0)
  495. flags &= ~PF_AUTOBOOT;
  496. else
  497. flags |= PF_AUTOBOOT;
  498. if (*temp++ != ' ')
  499. goto parse_error;
  500. c = *temp++ - '0';
  501. if ((c != 0) && (c != 1))
  502. goto parse_error;
  503. if (c == 0)
  504. flags &= ~PF_AUTOSEARCH;
  505. else
  506. flags |= PF_AUTOSEARCH;
  507. DPRINTK("%s: flags after: 0x%X\n", __func__, flags);
  508. /* So far so good, let's get in deep */
  509. /* Change the path entry flags first */
  510. pathentry->devpath.flags = flags;
  511. /* Now, dive in. Write back to the hardware */
  512. WARN_ON(pdcspath_store(pathentry)); /* this warn should *NEVER* happen */
  513. printk(KERN_INFO "PDC Stable Storage: changed flags to \"%s\"\n", buf);
  514. return count;
  515. parse_error:
  516. printk(KERN_WARNING "%s: Parse error: expect \"n n\" (n == 0 or 1) for AB and AS\n", __func__);
  517. return -EINVAL;
  518. }
  519. /* The last attribute (the 'root' one actually) with all remaining data. */
  520. static PDCS_ATTR(info, 0600, pdcs_info_read, pdcs_info_write);
  521. static struct subsys_attribute *pdcs_subsys_attrs[] = {
  522. &pdcs_attr_info,
  523. NULL, /* maybe more in the future? */
  524. };
  525. static decl_subsys(paths, &ktype_pdcspath, NULL);
  526. static decl_subsys(pdc, NULL, NULL);
  527. /**
  528. * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
  529. *
  530. * It creates kobjects corresponding to each path entry with nice sysfs
  531. * links to the real device. This is where the magic takes place: when
  532. * registering the subsystem attributes during module init, each kobject hereby
  533. * created will show in the sysfs tree as a folder containing files as defined
  534. * by path_subsys_attr[].
  535. */
  536. static inline int __init
  537. pdcs_register_pathentries(void)
  538. {
  539. unsigned short i;
  540. struct pdcspath_entry *entry;
  541. int err;
  542. for (i = 0; (entry = pdcspath_entries[i]); i++) {
  543. if (pdcspath_fetch(entry) < 0)
  544. continue;
  545. if ((err = kobject_set_name(&entry->kobj, "%s", entry->name)))
  546. return err;
  547. kobj_set_kset_s(entry, paths_subsys);
  548. if ((err = kobject_register(&entry->kobj)))
  549. return err;
  550. /* kobject is now registered */
  551. entry->ready = 2;
  552. if (!entry->dev)
  553. continue;
  554. /* Add a nice symlink to the real device */
  555. sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device");
  556. }
  557. return 0;
  558. }
  559. /**
  560. * pdcs_unregister_pathentries - Routine called when unregistering the module.
  561. */
  562. static inline void
  563. pdcs_unregister_pathentries(void)
  564. {
  565. unsigned short i;
  566. struct pdcspath_entry *entry;
  567. for (i = 0; (entry = pdcspath_entries[i]); i++)
  568. if (entry->ready >= 2)
  569. kobject_unregister(&entry->kobj);
  570. }
  571. /*
  572. * For now we register the pdc subsystem with the firmware subsystem
  573. * and the paths subsystem with the pdc subsystem
  574. */
  575. static int __init
  576. pdc_stable_init(void)
  577. {
  578. struct subsys_attribute *attr;
  579. int i, rc = 0, error = 0;
  580. /* find the size of the stable storage */
  581. if (pdc_stable_get_size(&pdcs_size) != PDC_OK)
  582. return -ENODEV;
  583. printk(KERN_INFO "PDC Stable Storage facility v%s\n", PDCS_VERSION);
  584. /* For now we'll register the pdc subsys within this driver */
  585. if ((rc = firmware_register(&pdc_subsys)))
  586. goto fail_firmreg;
  587. /* Don't forget the info entry */
  588. for (i = 0; (attr = pdcs_subsys_attrs[i]) && !error; i++)
  589. if (attr->show)
  590. error = subsys_create_file(&pdc_subsys, attr);
  591. /* register the paths subsys as a subsystem of pdc subsys */
  592. kset_set_kset_s(&paths_subsys, pdc_subsys);
  593. if ((rc= subsystem_register(&paths_subsys)))
  594. goto fail_subsysreg;
  595. /* now we create all "files" for the paths subsys */
  596. if ((rc = pdcs_register_pathentries()))
  597. goto fail_pdcsreg;
  598. return rc;
  599. fail_pdcsreg:
  600. pdcs_unregister_pathentries();
  601. subsystem_unregister(&paths_subsys);
  602. fail_subsysreg:
  603. firmware_unregister(&pdc_subsys);
  604. fail_firmreg:
  605. printk(KERN_INFO "PDC Stable Storage bailing out\n");
  606. return rc;
  607. }
  608. static void __exit
  609. pdc_stable_exit(void)
  610. {
  611. pdcs_unregister_pathentries();
  612. subsystem_unregister(&paths_subsys);
  613. firmware_unregister(&pdc_subsys);
  614. }
  615. module_init(pdc_stable_init);
  616. module_exit(pdc_stable_exit);