nvram_64.c 18 KB

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