2 * proc_devtree.c - handles /proc/device-tree
4 * Copyright 1997 Paul Mackerras
6 #include <linux/errno.h>
7 #include <linux/sched.h>
8 #include <linux/proc_fs.h>
9 #include <linux/stat.h>
10 #include <linux/string.h>
12 #include <asm/uaccess.h>
14 static struct proc_dir_entry *proc_device_tree;
17 * Supply data on a read from /proc/device-tree/node/property.
19 static int property_read_proc(char *page, char **start, off_t off,
20 int count, int *eof, void *data)
22 struct property *pp = data;
25 if (off >= pp->length) {
34 memcpy(page, pp->value + off, n);
40 * For a node with a name like "gc@10", we make symlinks called "gc"
45 * Process a node, adding entries for its children and its properties.
47 static void add_node(struct device_node *np, struct proc_dir_entry *de)
50 struct proc_dir_entry *ent;
51 struct device_node *child, *sib;
54 struct proc_dir_entry *list, **lastp, *al;
57 for (pp = np->properties; pp != 0; pp = pp->next) {
59 * Unfortunately proc_register puts each new entry
60 * at the beginning of the list. So we rearrange them.
62 ent = create_proc_read_entry(pp->name, S_IRUGO, de,
63 property_read_proc, pp);
66 ent->size = pp->length;
70 for (child = np->child; child != 0; child = child->sibling) {
71 p = strrchr(child->full_name, '/');
76 /* chop off '@0' if the name ends with that */
78 if (l > 2 && p[l-2] == '@' && p[l-1] == '0')
80 ent = proc_mkdir(p, de);
88 * If we left the address part on the name, consider
89 * adding symlinks from the name and address parts.
91 if (p[l] != 0 || (at = strchr(p, '@')) == 0)
95 * If this is the first node with a given name property,
96 * add a symlink with the name property as its name.
98 for (sib = np->child; sib != child; sib = sib->sibling)
99 if (sib->name && strcmp(sib->name, child->name) == 0)
101 if (sib == child && strncmp(p, child->name, l) != 0) {
102 al = proc_symlink(child->name, de, ent->name);
110 * Add another directory with the @address part as its name.
112 al = proc_symlink(at, de, ent->name);
123 * Called on initialization to set up the /proc/device-tree subtree
125 void proc_device_tree_init(void)
127 struct device_node *root;
130 proc_device_tree = proc_mkdir("device-tree", 0);
131 if (proc_device_tree == 0)
133 root = find_path_device("/");
135 printk(KERN_ERR "/proc/device-tree: can't find root\n");
138 add_node(root, proc_device_tree);