]>
Commit | Line | Data |
---|---|---|
4cd9d6f7 | 1 | #include <linux/slab.h> |
4cd9d6f7 RP |
2 | #include <linux/proc_fs.h> |
3 | #include <asm/setup.h> | |
4 | #include <asm/types.h> | |
5 | #include <asm/page.h> | |
6 | ||
7 | struct buffer { | |
8 | size_t size; | |
f7b0b939 | 9 | char data[]; |
4cd9d6f7 | 10 | }; |
4cd9d6f7 | 11 | |
03b642a7 AV |
12 | static ssize_t atags_read(struct file *file, char __user *buf, |
13 | size_t count, loff_t *ppos) | |
4cd9d6f7 | 14 | { |
03b642a7 AV |
15 | struct buffer *b = PDE(file_inode(file))->data; |
16 | return simple_read_from_buffer(buf, count, ppos, b->data, b->size); | |
4cd9d6f7 RP |
17 | } |
18 | ||
03b642a7 AV |
19 | static const struct file_operations atags_fops = { |
20 | .read = atags_read, | |
21 | .llseek = default_llseek, | |
22 | }; | |
23 | ||
8ff7f2a4 | 24 | #define BOOT_PARAMS_SIZE 1536 |
f7b0b939 | 25 | static char __initdata atags_copy[BOOT_PARAMS_SIZE]; |
4cd9d6f7 RP |
26 | |
27 | void __init save_atags(const struct tag *tags) | |
28 | { | |
f7b0b939 | 29 | memcpy(atags_copy, tags, sizeof(atags_copy)); |
4cd9d6f7 RP |
30 | } |
31 | ||
4cd9d6f7 RP |
32 | static int __init init_atags_procfs(void) |
33 | { | |
f7b0b939 UKK |
34 | /* |
35 | * This cannot go into save_atags() because kmalloc and proc don't work | |
36 | * yet when it is called. | |
37 | */ | |
38 | struct proc_dir_entry *tags_entry; | |
39 | struct tag *tag = (struct tag *)atags_copy; | |
40 | struct buffer *b; | |
41 | size_t size; | |
4cd9d6f7 | 42 | |
f7b0b939 UKK |
43 | if (tag->hdr.tag != ATAG_CORE) { |
44 | printk(KERN_INFO "No ATAGs?"); | |
45 | return -EINVAL; | |
4cd9d6f7 RP |
46 | } |
47 | ||
f7b0b939 | 48 | for (; tag->hdr.size; tag = tag_next(tag)) |
4cd9d6f7 RP |
49 | ; |
50 | ||
f7b0b939 UKK |
51 | /* include the terminating ATAG_NONE */ |
52 | size = (char *)tag - atags_copy + sizeof(struct tag_header); | |
4cd9d6f7 | 53 | |
f7b0b939 UKK |
54 | WARN_ON(tag->hdr.tag != ATAG_NONE); |
55 | ||
56 | b = kmalloc(sizeof(*b) + size, GFP_KERNEL); | |
57 | if (!b) | |
58 | goto nomem; | |
4cd9d6f7 | 59 | |
f7b0b939 UKK |
60 | b->size = size; |
61 | memcpy(b->data, atags_copy, size); | |
62 | ||
03b642a7 | 63 | tags_entry = proc_create_data("atags", 0400, NULL, &atags_fops, b); |
f7b0b939 UKK |
64 | if (!tags_entry) |
65 | goto nomem; | |
66 | ||
67 | return 0; | |
68 | ||
69 | nomem: | |
70 | kfree(b); | |
71 | printk(KERN_ERR "Exporting ATAGs: not enough memory\n"); | |
72 | ||
73 | return -ENOMEM; | |
74 | } | |
4cd9d6f7 | 75 | arch_initcall(init_atags_procfs); |