nvram_64.c 18 KB

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