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.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
19 #include <asm/machdep.h>
21 static unsigned int nvram_size
;
23 static ssize_t
opal_nvram_size(void)
28 static ssize_t
opal_nvram_read(char *buf
, size_t count
, loff_t
*index
)
33 if (*index
>= nvram_size
)
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
)
45 static ssize_t
opal_nvram_write(char *buf
, size_t count
, loff_t
*index
)
50 if (*index
>= nvram_size
)
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
);
65 void __init
opal_nvram_init(void)
67 struct device_node
*np
;
70 np
= of_find_compatible_node(NULL
, NULL
, "ibm,opal-nvram");
74 nbytes_p
= of_get_property(np
, "#bytes", NULL
);
79 nvram_size
= *nbytes_p
;
81 printk(KERN_INFO
"OPAL nvram setup, %u bytes\n", nvram_size
);
84 ppc_md
.nvram_read
= opal_nvram_read
;
85 ppc_md
.nvram_write
= opal_nvram_write
;
86 ppc_md
.nvram_size
= opal_nvram_size
;