18 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/errno.h>
24 #include <linux/fcntl.h>
25 #include <linux/nvram.h>
27 #include <linux/slab.h>
29 #include <asm/uaccess.h>
30 #include <asm/nvram.h>
33 #include <asm/machdep.h>
37 #define NVRAM_HEADER_LEN sizeof(struct nvram_header)
38 #define NVRAM_BLOCK_LEN NVRAM_HEADER_LEN
63 size =
ppc_md.nvram_size();
67 offset += file->
f_pos;
80 static ssize_t dev_nvram_read(
struct file *file,
char __user *
buf,
81 size_t count, loff_t *ppos)
92 size =
ppc_md.nvram_size();
93 if (*ppos >= size || size < 0)
96 count =
min_t(
size_t, count, size - *ppos);
104 ret =
ppc_md.nvram_read(tmp, count, ppos);
117 static ssize_t dev_nvram_write(
struct file *file,
const char __user *buf,
118 size_t count, loff_t *ppos)
129 size =
ppc_md.nvram_size();
130 if (*ppos >= size || size < 0)
133 count =
min_t(
size_t, count, size - *ppos);
145 ret =
ppc_md.nvram_write(tmp, count, ppos);
153 static long dev_nvram_ioctl(
struct file *file,
unsigned int cmd,
157 #ifdef CONFIG_PPC_PMAC
163 if (!machine_is(powermac))
172 if (
copy_to_user((
void __user*)arg, &offset,
sizeof(offset)) != 0)
184 .llseek = dev_nvram_llseek,
185 .read = dev_nvram_read,
186 .write = dev_nvram_write,
187 .unlocked_ioctl = dev_nvram_ioctl,
198 static void __init nvram_print_partitions(
char *
label)
219 tmp_index = part->
index;
228 unsigned int c_sum, c_sum2;
229 unsigned short *
sp = (
unsigned short *)p->
name;
230 c_sum = p->
signature + p->
length + sp[0] + sp[1] + sp[2] + sp[3] + sp[4] + sp[5];
233 c_sum = ((c_sum & 0xffff) + (c_sum >> 16)) & 0xffff;
235 c_sum2 = (c_sum >> 8) + (c_sum << 8);
236 c_sum = ((c_sum + c_sum2) >> 8) & 0xff;
245 const char *
name,
int sig,
const char *exceptions[])
247 if (part->
header.signature != sig)
252 }
else if (exceptions) {
254 for (except = exceptions; *except; except++) {
272 const char *exceptions[])
278 if (!nvram_can_remove_partition(part, name, sig, exceptions))
285 rc = nvram_write_header(part);
287 printk(
KERN_ERR "nvram_remove_partition: nvram_write failed (%d)\n", rc);
302 rc = nvram_write_header(part);
304 printk(
KERN_ERR "nvram_remove_partition: nvram_write failed (%d)\n", rc);
330 int req_size,
int min_size)
335 static char nv_init_vals[16];
349 if (min_size > req_size)
362 if (part->
header.length >= req_size) {
367 if (part->
header.length > size &&
368 part->
header.length >= min_size) {
369 size = part->
header.length;
379 pr_err(
"nvram_create_os_partition: kmalloc failed\n");
387 new_part->
header.checksum = nvram_checksum(&new_part->
header);
389 rc = nvram_write_header(new_part);
391 pr_err(
"nvram_create_os_partition: nvram_write_header "
392 "failed (%d)\n", rc);
398 if (free_part->
header.length > size) {
401 free_part->
header.checksum = nvram_checksum(&free_part->
header);
402 rc = nvram_write_header(free_part);
404 pr_err(
"nvram_create_os_partition: nvram_write_header "
405 "failed (%d)\n", rc);
419 pr_err(
"nvram_create_partition: nvram_write failed (%d)\n", rc);
456 if (p->
header.signature == sig &&
459 *out_size = (p->
header.length - 1) *
469 loff_t cur_index = 0;
479 total_size =
ppc_md.nvram_size();
487 while (cur_index < total_size) {
492 "nvram partitions\n");
501 c_sum = nvram_checksum(&phead);
504 " was %02x, should be %02x!\n",
511 "detected: 0-length partition\n");
523 tmp_part->
index = cur_index;
531 nvram_print_partitions(
"NVRAM Partitions");
539 static int __init nvram_init(
void)