There is no need to have BOOT_PARAMS_SIZE known outside of atags.c
[linux-2.6-block.git] / arch / arm / kernel / atags.c
1 #include <linux/slab.h>
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;
9         char *data;
10 };
11 static struct buffer tags_buffer;
12
13 static int
14 read_buffer(char* page, char** start, off_t off, int count,
15         int* eof, void* data)
16 {
17         struct buffer *buffer = (struct buffer *)data;
18
19         if (off >= buffer->size) {
20                 *eof = 1;
21                 return 0;
22         }
23
24         count = min((int) (buffer->size - off), count);
25
26         memcpy(page, &buffer->data[off], count);
27
28         return count;
29 }
30
31
32 static int
33 create_proc_entries(void)
34 {
35         struct proc_dir_entry* tags_entry;
36
37         tags_entry = create_proc_read_entry("atags", 0400, NULL, read_buffer, &tags_buffer);
38         if (!tags_entry)
39                 return -ENOMEM;
40
41         return 0;
42 }
43
44 #define BOOT_PARAMS_SIZE 1536
45 static char __initdata atags_copy_buf[BOOT_PARAMS_SIZE];
46 static char __initdata *atags_copy;
47
48 void __init save_atags(const struct tag *tags)
49 {
50         atags_copy = atags_copy_buf;
51         memcpy(atags_copy, tags, sizeof(atags_copy_buf));
52 }
53
54
55 static int __init init_atags_procfs(void)
56 {
57         struct tag *tag;
58         int error;
59
60         if (!atags_copy) {
61                 printk(KERN_WARNING "Exporting ATAGs: No saved tags found\n");
62                 return -EIO;
63         }
64
65         for (tag = (struct tag *) atags_copy; tag->hdr.size; tag = tag_next(tag))
66                 ;
67
68         tags_buffer.size = ((char *) tag - atags_copy) + sizeof(tag->hdr);
69         tags_buffer.data = kmalloc(tags_buffer.size, GFP_KERNEL);
70         if (tags_buffer.data == NULL)
71                 return -ENOMEM;
72         memcpy(tags_buffer.data, atags_copy, tags_buffer.size);
73
74         error = create_proc_entries();
75         if (error) {
76                 printk(KERN_ERR "Exporting ATAGs: not enough memory\n");
77                 kfree(tags_buffer.data);
78                 tags_buffer.size = 0;
79                 tags_buffer.data = NULL;
80         }
81
82         return error;
83 }
84
85 arch_initcall(init_atags_procfs);