2 * proc_devtree.c - handles /proc/device-tree
4 * Copyright 1997 Paul Mackerras
6 #include <linux/errno.h>
7 #include <linux/time.h>
8 #include <linux/proc_fs.h>
9 #include <linux/stat.h>
10 #include <linux/string.h>
12 #include <asm/uaccess.h>
14 #ifndef HAVE_ARCH_DEVTREE_FIXUPS
15 static inline void set_node_proc_entry(struct device_node
*np
, struct proc_dir_entry
*de
)
19 static void inline set_node_name_link(struct device_node
*np
, struct proc_dir_entry
*de
)
23 static void inline set_node_addr_link(struct device_node
*np
, struct proc_dir_entry
*de
)
28 static struct proc_dir_entry
*proc_device_tree
;
31 * Supply data on a read from /proc/device-tree/node/property.
33 static int property_read_proc(char *page
, char **start
, off_t off
,
34 int count
, int *eof
, void *data
)
36 struct property
*pp
= data
;
39 if (off
>= pp
->length
) {
48 memcpy(page
, pp
->value
+ off
, n
);
54 * For a node with a name like "gc@10", we make symlinks called "gc"
59 * Process a node, adding entries for its children and its properties.
61 void proc_device_tree_add_node(struct device_node
*np
, struct proc_dir_entry
*de
)
64 struct proc_dir_entry
*ent
;
65 struct device_node
*child
, *sib
;
68 struct proc_dir_entry
*list
, **lastp
, *al
;
70 set_node_proc_entry(np
, de
);
72 for (pp
= np
->properties
; pp
!= 0; pp
= pp
->next
) {
74 * Unfortunately proc_register puts each new entry
75 * at the beginning of the list. So we rearrange them.
77 ent
= create_proc_read_entry(pp
->name
, strncmp(pp
->name
, "security-", 9) ?
78 S_IRUGO
: S_IRUSR
, de
, property_read_proc
, pp
);
81 if (!strncmp(pp
->name
, "security-", 9))
82 ent
->size
= 0; /* don't leak number of password chars */
84 ent
->size
= pp
->length
;
89 while ((child
= of_get_next_child(np
, child
))) {
90 p
= strrchr(child
->full_name
, '/');
95 /* chop off '@0' if the name ends with that */
97 if (l
> 2 && p
[l
-2] == '@' && p
[l
-1] == '0')
99 ent
= proc_mkdir(p
, de
);
104 proc_device_tree_add_node(child
, ent
);
107 * If we left the address part on the name, consider
108 * adding symlinks from the name and address parts.
110 if (p
[l
] != 0 || (at
= strchr(p
, '@')) == 0)
114 * If this is the first node with a given name property,
115 * add a symlink with the name property as its name.
118 while ((sib
= of_get_next_child(np
, sib
)) && sib
!= child
)
119 if (sib
->name
&& strcmp(sib
->name
, child
->name
) == 0)
121 if (sib
== child
&& strncmp(p
, child
->name
, l
) != 0) {
122 al
= proc_symlink(child
->name
, de
, ent
->name
);
127 set_node_name_link(child
, al
);
133 * Add another directory with the @address part as its name.
135 al
= proc_symlink(at
, de
, ent
->name
);
138 set_node_addr_link(child
, al
);
148 * Called on initialization to set up the /proc/device-tree subtree
150 void proc_device_tree_init(void)
152 struct device_node
*root
;
155 proc_device_tree
= proc_mkdir("device-tree", NULL
);
156 if (proc_device_tree
== 0)
158 root
= of_find_node_by_path("/");
160 printk(KERN_ERR
"/proc/device-tree: can't find root\n");
163 proc_device_tree_add_node(root
, proc_device_tree
);