1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/slab.h>
3 #include <linux/proc_fs.h>
13 static ssize_t atags_read(struct file *file, char __user *buf,
14 size_t count, loff_t *ppos)
16 struct buffer *b = PDE_DATA(file_inode(file));
17 return simple_read_from_buffer(buf, count, ppos, b->data, b->size);
20 static const struct proc_ops atags_proc_ops = {
21 .proc_read = atags_read,
22 .proc_lseek = default_llseek,
25 #define BOOT_PARAMS_SIZE 1536
26 static char __initdata atags_copy[BOOT_PARAMS_SIZE];
28 void __init save_atags(const struct tag *tags)
30 memcpy(atags_copy, tags, sizeof(atags_copy));
33 static int __init init_atags_procfs(void)
36 * This cannot go into save_atags() because kmalloc and proc don't work
37 * yet when it is called.
39 struct proc_dir_entry *tags_entry;
40 struct tag *tag = (struct tag *)atags_copy;
44 if (tag->hdr.tag != ATAG_CORE) {
45 pr_info("No ATAGs?\n");
49 for (; tag->hdr.size; tag = tag_next(tag))
52 /* include the terminating ATAG_NONE */
53 size = (char *)tag - atags_copy + sizeof(struct tag_header);
55 WARN_ON(tag->hdr.tag != ATAG_NONE);
57 b = kmalloc(sizeof(*b) + size, GFP_KERNEL);
62 memcpy(b->data, atags_copy, size);
64 tags_entry = proc_create_data("atags", 0400, NULL, &atags_proc_ops, b);
72 pr_err("Exporting ATAGs: not enough memory\n");
76 arch_initcall(init_atags_procfs);