x86, efi: Set runtime_version to the EFI spec revision
[linux/fpc-iii.git] / arch / powerpc / platforms / powernv / opal-nvram.c
blob3f83e1ae26acb591fbf3614bd9afbb6ae4ffa3d3
1 /*
2 * PowerNV nvram code.
4 * Copyright 2011 IBM Corp.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #define DEBUG
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/of.h>
18 #include <asm/opal.h>
19 #include <asm/machdep.h>
21 static unsigned int nvram_size;
23 static ssize_t opal_nvram_size(void)
25 return nvram_size;
28 static ssize_t opal_nvram_read(char *buf, size_t count, loff_t *index)
30 s64 rc;
31 int off;
33 if (*index >= nvram_size)
34 return 0;
35 off = *index;
36 if ((off + count) > nvram_size)
37 count = nvram_size - off;
38 rc = opal_read_nvram(__pa(buf), count, off);
39 if (rc != OPAL_SUCCESS)
40 return -EIO;
41 *index += count;
42 return count;
45 static ssize_t opal_nvram_write(char *buf, size_t count, loff_t *index)
47 s64 rc = OPAL_BUSY;
48 int off;
50 if (*index >= nvram_size)
51 return 0;
52 off = *index;
53 if ((off + count) > nvram_size)
54 count = nvram_size - off;
56 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
57 rc = opal_write_nvram(__pa(buf), count, off);
58 if (rc == OPAL_BUSY_EVENT)
59 opal_poll_events(NULL);
61 *index += count;
62 return count;
65 void __init opal_nvram_init(void)
67 struct device_node *np;
68 const u32 *nbytes_p;
70 np = of_find_compatible_node(NULL, NULL, "ibm,opal-nvram");
71 if (np == NULL)
72 return;
74 nbytes_p = of_get_property(np, "#bytes", NULL);
75 if (!nbytes_p) {
76 of_node_put(np);
77 return;
79 nvram_size = *nbytes_p;
81 printk(KERN_INFO "OPAL nvram setup, %u bytes\n", nvram_size);
82 of_node_put(np);
84 ppc_md.nvram_read = opal_nvram_read;
85 ppc_md.nvram_write = opal_nvram_write;
86 ppc_md.nvram_size = opal_nvram_size;