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