nvram_64.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * c 2001 PPC 64 Team, IBM Corp
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * /dev/nvram driver for PPC64
  10. *
  11. * This perhaps should live in drivers/char
  12. *
  13. * TODO: Split the /dev/nvram part (that one can use
  14. * drivers/char/generic_nvram.c) from the arch & partition
  15. * parsing code.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/types.h>
  19. #include <linux/errno.h>
  20. #include <linux/fs.h>
  21. #include <linux/miscdevice.h>
  22. #include <linux/fcntl.h>
  23. #include <linux/nvram.h>
  24. #include <linux/init.h>
  25. #include <linux/slab.h>
  26. #include <linux/spinlock.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/nvram.h>
  29. #include <asm/rtas.h>
  30. #include <asm/prom.h>
  31. #include <asm/machdep.h>
  32. #undef DEBUG_NVRAM
  33. static int nvram_scan_partitions(void);
  34. static int nvram_setup_partition(void);
  35. static int nvram_create_os_partition(void);
  36. static int nvram_remove_os_partition(void);
  37. static struct nvram_partition * nvram_part;
  38. static long nvram_error_log_index = -1;
  39. static long nvram_error_log_size = 0;
  40. int no_logging = 1; /* Until we initialize everything,
  41. * make sure we don't try logging
  42. * anything */
  43. extern volatile int error_log_cnt;
  44. struct err_log_info {
  45. int error_type;
  46. unsigned int seq_num;
  47. };
  48. static loff_t dev_nvram_llseek(struct file *file, loff_t offset, int origin)
  49. {
  50. int size;
  51. if (ppc_md.nvram_size == NULL)
  52. return -ENODEV;
  53. size = ppc_md.nvram_size();
  54. switch (origin) {
  55. case 1:
  56. offset += file->f_pos;
  57. break;
  58. case 2:
  59. offset += size;
  60. break;
  61. }
  62. if (offset < 0)
  63. return -EINVAL;
  64. file->f_pos = offset;
  65. return file->f_pos;
  66. }
  67. static ssize_t dev_nvram_read(struct file *file, char __user *buf,
  68. size_t count, loff_t *ppos)
  69. {
  70. ssize_t ret;
  71. char *tmp = NULL;
  72. ssize_t size;
  73. ret = -ENODEV;
  74. if (!ppc_md.nvram_size)
  75. goto out;
  76. ret = 0;
  77. size = ppc_md.nvram_size();
  78. if (*ppos >= size || size < 0)
  79. goto out;
  80. count = min_t(size_t, count, size - *ppos);
  81. count = min(count, PAGE_SIZE);
  82. ret = -ENOMEM;
  83. tmp = kmalloc(count, GFP_KERNEL);
  84. if (!tmp)
  85. goto out;
  86. ret = ppc_md.nvram_read(tmp, count, ppos);
  87. if (ret <= 0)
  88. goto out;
  89. if (copy_to_user(buf, tmp, ret))
  90. ret = -EFAULT;
  91. out:
  92. kfree(tmp);
  93. return ret;
  94. }
  95. static ssize_t dev_nvram_write(struct file *file, const char __user *buf,
  96. size_t count, loff_t *ppos)
  97. {
  98. ssize_t ret;
  99. char *tmp = NULL;
  100. ssize_t size;
  101. ret = -ENODEV;
  102. if (!ppc_md.nvram_size)
  103. goto out;
  104. ret = 0;
  105. size = ppc_md.nvram_size();
  106. if (*ppos >= size || size < 0)
  107. goto out;
  108. count = min_t(size_t, count, size - *ppos);
  109. count = min(count, PAGE_SIZE);
  110. ret = -ENOMEM;
  111. tmp = kmalloc(count, GFP_KERNEL);
  112. if (!tmp)
  113. goto out;
  114. ret = -EFAULT;
  115. if (copy_from_user(tmp, buf, count))
  116. goto out;
  117. ret = ppc_md.nvram_write(tmp, count, ppos);
  118. out:
  119. kfree(tmp);
  120. return ret;
  121. }
  122. static int dev_nvram_ioctl(struct inode *inode, struct file *file,
  123. unsigned int cmd, unsigned long arg)
  124. {
  125. switch(cmd) {
  126. #ifdef CONFIG_PPC_PMAC
  127. case OBSOLETE_PMAC_NVRAM_GET_OFFSET:
  128. printk(KERN_WARNING "nvram: Using obsolete PMAC_NVRAM_GET_OFFSET ioctl\n");
  129. case IOC_NVRAM_GET_OFFSET: {
  130. int part, offset;
  131. if (!machine_is(powermac))
  132. return -EINVAL;
  133. if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
  134. return -EFAULT;
  135. if (part < pmac_nvram_OF || part > pmac_nvram_NR)
  136. return -EINVAL;
  137. offset = pmac_get_partition(part);
  138. if (offset < 0)
  139. return offset;
  140. if (copy_to_user((void __user*)arg, &offset, sizeof(offset)) != 0)
  141. return -EFAULT;
  142. return 0;
  143. }
  144. #endif /* CONFIG_PPC_PMAC */
  145. default:
  146. return -EINVAL;
  147. }
  148. }
  149. struct file_operations nvram_fops = {
  150. .owner = THIS_MODULE,
  151. .llseek = dev_nvram_llseek,
  152. .read = dev_nvram_read,
  153. .write = dev_nvram_write,
  154. .ioctl = dev_nvram_ioctl,
  155. };
  156. static struct miscdevice nvram_dev = {
  157. NVRAM_MINOR,
  158. "nvram",
  159. &nvram_fops
  160. };
  161. #ifdef DEBUG_NVRAM
  162. static void nvram_print_partitions(char * label)
  163. {
  164. struct list_head * p;
  165. struct nvram_partition * tmp_part;
  166. printk(KERN_WARNING "--------%s---------\n", label);
  167. printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
  168. list_for_each(p, &nvram_part->partition) {
  169. tmp_part = list_entry(p, struct nvram_partition, partition);
  170. printk(KERN_WARNING "%4d \t%02x\t%02x\t%d\t%s\n",
  171. tmp_part->index, tmp_part->header.signature,
  172. tmp_part->header.checksum, tmp_part->header.length,
  173. tmp_part->header.name);
  174. }
  175. }
  176. #endif
  177. static int nvram_write_header(struct nvram_partition * part)
  178. {
  179. loff_t tmp_index;
  180. int rc;
  181. tmp_index = part->index;
  182. rc = ppc_md.nvram_write((char *)&part->header, NVRAM_HEADER_LEN, &tmp_index);
  183. return rc;
  184. }
  185. static unsigned char nvram_checksum(struct nvram_header *p)
  186. {
  187. unsigned int c_sum, c_sum2;
  188. unsigned short *sp = (unsigned short *)p->name; /* assume 6 shorts */
  189. c_sum = p->signature + p->length + sp[0] + sp[1] + sp[2] + sp[3] + sp[4] + sp[5];
  190. /* The sum may have spilled into the 3rd byte. Fold it back. */
  191. c_sum = ((c_sum & 0xffff) + (c_sum >> 16)) & 0xffff;
  192. /* The sum cannot exceed 2 bytes. Fold it into a checksum */
  193. c_sum2 = (c_sum >> 8) + (c_sum << 8);
  194. c_sum = ((c_sum + c_sum2) >> 8) & 0xff;
  195. return c_sum;
  196. }
  197. /*
  198. * Find an nvram partition, sig can be 0 for any
  199. * partition or name can be NULL for any name, else
  200. * tries to match both
  201. */
  202. struct nvram_partition *nvram_find_partition(int sig, const char *name)
  203. {
  204. struct nvram_partition * part;
  205. struct list_head * p;
  206. list_for_each(p, &nvram_part->partition) {
  207. part = list_entry(p, struct nvram_partition, partition);
  208. if (sig && part->header.signature != sig)
  209. continue;
  210. if (name && 0 != strncmp(name, part->header.name, 12))
  211. continue;
  212. return part;
  213. }
  214. return NULL;
  215. }
  216. EXPORT_SYMBOL(nvram_find_partition);
  217. static int nvram_remove_os_partition(void)
  218. {
  219. struct list_head *i;
  220. struct list_head *j;
  221. struct nvram_partition * part;
  222. struct nvram_partition * cur_part;
  223. int rc;
  224. list_for_each(i, &nvram_part->partition) {
  225. part = list_entry(i, struct nvram_partition, partition);
  226. if (part->header.signature != NVRAM_SIG_OS)
  227. continue;
  228. /* Make os partition a free partition */
  229. part->header.signature = NVRAM_SIG_FREE;
  230. sprintf(part->header.name, "wwwwwwwwwwww");
  231. part->header.checksum = nvram_checksum(&part->header);
  232. /* Merge contiguous free partitions backwards */
  233. list_for_each_prev(j, &part->partition) {
  234. cur_part = list_entry(j, struct nvram_partition, partition);
  235. if (cur_part == nvram_part || cur_part->header.signature != NVRAM_SIG_FREE) {
  236. break;
  237. }
  238. part->header.length += cur_part->header.length;
  239. part->header.checksum = nvram_checksum(&part->header);
  240. part->index = cur_part->index;
  241. list_del(&cur_part->partition);
  242. kfree(cur_part);
  243. j = &part->partition; /* fixup our loop */
  244. }
  245. /* Merge contiguous free partitions forwards */
  246. list_for_each(j, &part->partition) {
  247. cur_part = list_entry(j, struct nvram_partition, partition);
  248. if (cur_part == nvram_part || cur_part->header.signature != NVRAM_SIG_FREE) {
  249. break;
  250. }
  251. part->header.length += cur_part->header.length;
  252. part->header.checksum = nvram_checksum(&part->header);
  253. list_del(&cur_part->partition);
  254. kfree(cur_part);
  255. j = &part->partition; /* fixup our loop */
  256. }
  257. rc = nvram_write_header(part);
  258. if (rc <= 0) {
  259. printk(KERN_ERR "nvram_remove_os_partition: nvram_write failed (%d)\n", rc);
  260. return rc;
  261. }
  262. }
  263. return 0;
  264. }
  265. /* nvram_create_os_partition
  266. *
  267. * Create a OS linux partition to buffer error logs.
  268. * Will create a partition starting at the first free
  269. * space found if space has enough room.
  270. */
  271. static int nvram_create_os_partition(void)
  272. {
  273. struct nvram_partition *part;
  274. struct nvram_partition *new_part;
  275. struct nvram_partition *free_part = NULL;
  276. int seq_init[2] = { 0, 0 };
  277. loff_t tmp_index;
  278. long size = 0;
  279. int rc;
  280. /* Find a free partition that will give us the maximum needed size
  281. If can't find one that will give us the minimum size needed */
  282. list_for_each_entry(part, &nvram_part->partition, partition) {
  283. if (part->header.signature != NVRAM_SIG_FREE)
  284. continue;
  285. if (part->header.length >= NVRAM_MAX_REQ) {
  286. size = NVRAM_MAX_REQ;
  287. free_part = part;
  288. break;
  289. }
  290. if (!size && part->header.length >= NVRAM_MIN_REQ) {
  291. size = NVRAM_MIN_REQ;
  292. free_part = part;
  293. }
  294. }
  295. if (!size)
  296. return -ENOSPC;
  297. /* Create our OS partition */
  298. new_part = kmalloc(sizeof(*new_part), GFP_KERNEL);
  299. if (!new_part) {
  300. printk(KERN_ERR "nvram_create_os_partition: kmalloc failed\n");
  301. return -ENOMEM;
  302. }
  303. new_part->index = free_part->index;
  304. new_part->header.signature = NVRAM_SIG_OS;
  305. new_part->header.length = size;
  306. strcpy(new_part->header.name, "ppc64,linux");
  307. new_part->header.checksum = nvram_checksum(&new_part->header);
  308. rc = nvram_write_header(new_part);
  309. if (rc <= 0) {
  310. printk(KERN_ERR "nvram_create_os_partition: nvram_write_header \
  311. failed (%d)\n", rc);
  312. return rc;
  313. }
  314. /* make sure and initialize to zero the sequence number and the error
  315. type logged */
  316. tmp_index = new_part->index + NVRAM_HEADER_LEN;
  317. rc = ppc_md.nvram_write((char *)&seq_init, sizeof(seq_init), &tmp_index);
  318. if (rc <= 0) {
  319. printk(KERN_ERR "nvram_create_os_partition: nvram_write "
  320. "failed (%d)\n", rc);
  321. return rc;
  322. }
  323. nvram_error_log_index = new_part->index + NVRAM_HEADER_LEN;
  324. nvram_error_log_size = ((part->header.length - 1) *
  325. NVRAM_BLOCK_LEN) - sizeof(struct err_log_info);
  326. list_add_tail(&new_part->partition, &free_part->partition);
  327. if (free_part->header.length <= size) {
  328. list_del(&free_part->partition);
  329. kfree(free_part);
  330. return 0;
  331. }
  332. /* Adjust the partition we stole the space from */
  333. free_part->index += size * NVRAM_BLOCK_LEN;
  334. free_part->header.length -= size;
  335. free_part->header.checksum = nvram_checksum(&free_part->header);
  336. rc = nvram_write_header(free_part);
  337. if (rc <= 0) {
  338. printk(KERN_ERR "nvram_create_os_partition: nvram_write_header "
  339. "failed (%d)\n", rc);
  340. return rc;
  341. }
  342. return 0;
  343. }
  344. /* nvram_setup_partition
  345. *
  346. * This will setup the partition we need for buffering the
  347. * error logs and cleanup partitions if needed.
  348. *
  349. * The general strategy is the following:
  350. * 1.) If there is ppc64,linux partition large enough then use it.
  351. * 2.) If there is not a ppc64,linux partition large enough, search
  352. * for a free partition that is large enough.
  353. * 3.) If there is not a free partition large enough remove
  354. * _all_ OS partitions and consolidate the space.
  355. * 4.) Will first try getting a chunk that will satisfy the maximum
  356. * error log size (NVRAM_MAX_REQ).
  357. * 5.) If the max chunk cannot be allocated then try finding a chunk
  358. * that will satisfy the minum needed (NVRAM_MIN_REQ).
  359. */
  360. static int nvram_setup_partition(void)
  361. {
  362. struct list_head * p;
  363. struct nvram_partition * part;
  364. int rc;
  365. /* For now, we don't do any of this on pmac, until I
  366. * have figured out if it's worth killing some unused stuffs
  367. * in our nvram, as Apple defined partitions use pretty much
  368. * all of the space
  369. */
  370. if (machine_is(powermac))
  371. return -ENOSPC;
  372. /* see if we have an OS partition that meets our needs.
  373. will try getting the max we need. If not we'll delete
  374. partitions and try again. */
  375. list_for_each(p, &nvram_part->partition) {
  376. part = list_entry(p, struct nvram_partition, partition);
  377. if (part->header.signature != NVRAM_SIG_OS)
  378. continue;
  379. if (strcmp(part->header.name, "ppc64,linux"))
  380. continue;
  381. if (part->header.length >= NVRAM_MIN_REQ) {
  382. /* found our partition */
  383. nvram_error_log_index = part->index + NVRAM_HEADER_LEN;
  384. nvram_error_log_size = ((part->header.length - 1) *
  385. NVRAM_BLOCK_LEN) - sizeof(struct err_log_info);
  386. return 0;
  387. }
  388. }
  389. /* try creating a partition with the free space we have */
  390. rc = nvram_create_os_partition();
  391. if (!rc) {
  392. return 0;
  393. }
  394. /* need to free up some space */
  395. rc = nvram_remove_os_partition();
  396. if (rc) {
  397. return rc;
  398. }
  399. /* create a partition in this new space */
  400. rc = nvram_create_os_partition();
  401. if (rc) {
  402. printk(KERN_ERR "nvram_create_os_partition: Could not find a "
  403. "NVRAM partition large enough\n");
  404. return rc;
  405. }
  406. return 0;
  407. }
  408. static int nvram_scan_partitions(void)
  409. {
  410. loff_t cur_index = 0;
  411. struct nvram_header phead;
  412. struct nvram_partition * tmp_part;
  413. unsigned char c_sum;
  414. char * header;
  415. int total_size;
  416. int err;
  417. if (ppc_md.nvram_size == NULL)
  418. return -ENODEV;
  419. total_size = ppc_md.nvram_size();
  420. header = kmalloc(NVRAM_HEADER_LEN, GFP_KERNEL);
  421. if (!header) {
  422. printk(KERN_ERR "nvram_scan_partitions: Failed kmalloc\n");
  423. return -ENOMEM;
  424. }
  425. while (cur_index < total_size) {
  426. err = ppc_md.nvram_read(header, NVRAM_HEADER_LEN, &cur_index);
  427. if (err != NVRAM_HEADER_LEN) {
  428. printk(KERN_ERR "nvram_scan_partitions: Error parsing "
  429. "nvram partitions\n");
  430. goto out;
  431. }
  432. cur_index -= NVRAM_HEADER_LEN; /* nvram_read will advance us */
  433. memcpy(&phead, header, NVRAM_HEADER_LEN);
  434. err = 0;
  435. c_sum = nvram_checksum(&phead);
  436. if (c_sum != phead.checksum) {
  437. printk(KERN_WARNING "WARNING: nvram partition checksum"
  438. " was %02x, should be %02x!\n",
  439. phead.checksum, c_sum);
  440. printk(KERN_WARNING "Terminating nvram partition scan\n");
  441. goto out;
  442. }
  443. if (!phead.length) {
  444. printk(KERN_WARNING "WARNING: nvram corruption "
  445. "detected: 0-length partition\n");
  446. goto out;
  447. }
  448. tmp_part = (struct nvram_partition *)
  449. kmalloc(sizeof(struct nvram_partition), GFP_KERNEL);
  450. err = -ENOMEM;
  451. if (!tmp_part) {
  452. printk(KERN_ERR "nvram_scan_partitions: kmalloc failed\n");
  453. goto out;
  454. }
  455. memcpy(&tmp_part->header, &phead, NVRAM_HEADER_LEN);
  456. tmp_part->index = cur_index;
  457. list_add_tail(&tmp_part->partition, &nvram_part->partition);
  458. cur_index += phead.length * NVRAM_BLOCK_LEN;
  459. }
  460. err = 0;
  461. out:
  462. kfree(header);
  463. return err;
  464. }
  465. static int __init nvram_init(void)
  466. {
  467. int error;
  468. int rc;
  469. if (ppc_md.nvram_size == NULL || ppc_md.nvram_size() <= 0)
  470. return -ENODEV;
  471. rc = misc_register(&nvram_dev);
  472. if (rc != 0) {
  473. printk(KERN_ERR "nvram_init: failed to register device\n");
  474. return rc;
  475. }
  476. /* initialize our anchor for the nvram partition list */
  477. nvram_part = kmalloc(sizeof(struct nvram_partition), GFP_KERNEL);
  478. if (!nvram_part) {
  479. printk(KERN_ERR "nvram_init: Failed kmalloc\n");
  480. return -ENOMEM;
  481. }
  482. INIT_LIST_HEAD(&nvram_part->partition);
  483. /* Get all the NVRAM partitions */
  484. error = nvram_scan_partitions();
  485. if (error) {
  486. printk(KERN_ERR "nvram_init: Failed nvram_scan_partitions\n");
  487. return error;
  488. }
  489. if(nvram_setup_partition())
  490. printk(KERN_WARNING "nvram_init: Could not find nvram partition"
  491. " for nvram buffered error logging.\n");
  492. #ifdef DEBUG_NVRAM
  493. nvram_print_partitions("NVRAM Partitions");
  494. #endif
  495. return rc;
  496. }
  497. void __exit nvram_cleanup(void)
  498. {
  499. misc_deregister( &nvram_dev );
  500. }
  501. #ifdef CONFIG_PPC_PSERIES
  502. /* nvram_write_error_log
  503. *
  504. * We need to buffer the error logs into nvram to ensure that we have
  505. * the failure information to decode. If we have a severe error there
  506. * is no way to guarantee that the OS or the machine is in a state to
  507. * get back to user land and write the error to disk. For example if
  508. * the SCSI device driver causes a Machine Check by writing to a bad
  509. * IO address, there is no way of guaranteeing that the device driver
  510. * is in any state that is would also be able to write the error data
  511. * captured to disk, thus we buffer it in NVRAM for analysis on the
  512. * next boot.
  513. *
  514. * In NVRAM the partition containing the error log buffer will looks like:
  515. * Header (in bytes):
  516. * +-----------+----------+--------+------------+------------------+
  517. * | signature | checksum | length | name | data |
  518. * |0 |1 |2 3|4 15|16 length-1|
  519. * +-----------+----------+--------+------------+------------------+
  520. *
  521. * The 'data' section would look like (in bytes):
  522. * +--------------+------------+-----------------------------------+
  523. * | event_logged | sequence # | error log |
  524. * |0 3|4 7|8 nvram_error_log_size-1|
  525. * +--------------+------------+-----------------------------------+
  526. *
  527. * event_logged: 0 if event has not been logged to syslog, 1 if it has
  528. * sequence #: The unique sequence # for each event. (until it wraps)
  529. * error log: The error log from event_scan
  530. */
  531. int nvram_write_error_log(char * buff, int length, unsigned int err_type)
  532. {
  533. int rc;
  534. loff_t tmp_index;
  535. struct err_log_info info;
  536. if (no_logging) {
  537. return -EPERM;
  538. }
  539. if (nvram_error_log_index == -1) {
  540. return -ESPIPE;
  541. }
  542. if (length > nvram_error_log_size) {
  543. length = nvram_error_log_size;
  544. }
  545. info.error_type = err_type;
  546. info.seq_num = error_log_cnt;
  547. tmp_index = nvram_error_log_index;
  548. rc = ppc_md.nvram_write((char *)&info, sizeof(struct err_log_info), &tmp_index);
  549. if (rc <= 0) {
  550. printk(KERN_ERR "nvram_write_error_log: Failed nvram_write (%d)\n", rc);
  551. return rc;
  552. }
  553. rc = ppc_md.nvram_write(buff, length, &tmp_index);
  554. if (rc <= 0) {
  555. printk(KERN_ERR "nvram_write_error_log: Failed nvram_write (%d)\n", rc);
  556. return rc;
  557. }
  558. return 0;
  559. }
  560. /* nvram_read_error_log
  561. *
  562. * Reads nvram for error log for at most 'length'
  563. */
  564. int nvram_read_error_log(char * buff, int length, unsigned int * err_type)
  565. {
  566. int rc;
  567. loff_t tmp_index;
  568. struct err_log_info info;
  569. if (nvram_error_log_index == -1)
  570. return -1;
  571. if (length > nvram_error_log_size)
  572. length = nvram_error_log_size;
  573. tmp_index = nvram_error_log_index;
  574. rc = ppc_md.nvram_read((char *)&info, sizeof(struct err_log_info), &tmp_index);
  575. if (rc <= 0) {
  576. printk(KERN_ERR "nvram_read_error_log: Failed nvram_read (%d)\n", rc);
  577. return rc;
  578. }
  579. rc = ppc_md.nvram_read(buff, length, &tmp_index);
  580. if (rc <= 0) {
  581. printk(KERN_ERR "nvram_read_error_log: Failed nvram_read (%d)\n", rc);
  582. return rc;
  583. }
  584. error_log_cnt = info.seq_num;
  585. *err_type = info.error_type;
  586. return 0;
  587. }
  588. /* This doesn't actually zero anything, but it sets the event_logged
  589. * word to tell that this event is safely in syslog.
  590. */
  591. int nvram_clear_error_log(void)
  592. {
  593. loff_t tmp_index;
  594. int clear_word = ERR_FLAG_ALREADY_LOGGED;
  595. int rc;
  596. tmp_index = nvram_error_log_index;
  597. rc = ppc_md.nvram_write((char *)&clear_word, sizeof(int), &tmp_index);
  598. if (rc <= 0) {
  599. printk(KERN_ERR "nvram_clear_error_log: Failed nvram_write (%d)\n", rc);
  600. return rc;
  601. }
  602. return 0;
  603. }
  604. #endif /* CONFIG_PPC_PSERIES */
  605. module_init(nvram_init);
  606. module_exit(nvram_cleanup);
  607. MODULE_LICENSE("GPL");