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
,
16 struct proc_dir_entry
*de
)
21 static struct proc_dir_entry
*proc_device_tree
;
24 * Supply data on a read from /proc/device-tree/node/property.
26 static int property_read_proc(char *page
, char **start
, off_t off
,
27 int count
, int *eof
, void *data
)
29 struct property
*pp
= data
;
32 if (off
>= pp
->length
) {
41 memcpy(page
, pp
->value
+ off
, n
);
47 * For a node with a name like "gc@10", we make symlinks called "gc"
52 * Add a property to a node
54 static struct proc_dir_entry
*
55 __proc_device_tree_add_prop(struct proc_dir_entry
*de
, struct property
*pp
)
57 struct proc_dir_entry
*ent
;
60 * Unfortunately proc_register puts each new entry
61 * at the beginning of the list. So we rearrange them.
63 ent
= create_proc_read_entry(pp
->name
,
64 strncmp(pp
->name
, "security-", 9)
65 ? S_IRUGO
: S_IRUSR
, de
,
66 property_read_proc
, pp
);
70 if (!strncmp(pp
->name
, "security-", 9))
71 ent
->size
= 0; /* don't leak number of password chars */
73 ent
->size
= pp
->length
;
79 void proc_device_tree_add_prop(struct proc_dir_entry
*pde
, struct property
*prop
)
81 __proc_device_tree_add_prop(pde
, prop
);
84 void proc_device_tree_remove_prop(struct proc_dir_entry
*pde
,
85 struct property
*prop
)
87 remove_proc_entry(prop
->name
, pde
);
90 void proc_device_tree_update_prop(struct proc_dir_entry
*pde
,
91 struct property
*newprop
,
92 struct property
*oldprop
)
94 struct proc_dir_entry
*ent
;
96 for (ent
= pde
->subdir
; ent
!= NULL
; ent
= ent
->next
)
97 if (ent
->data
== oldprop
)
100 printk(KERN_WARNING
"device-tree: property \"%s\" "
101 " does not exist\n", oldprop
->name
);
104 ent
->size
= newprop
->length
;
109 * Process a node, adding entries for its children and its properties.
111 void proc_device_tree_add_node(struct device_node
*np
,
112 struct proc_dir_entry
*de
)
115 struct proc_dir_entry
*ent
;
116 struct device_node
*child
;
119 set_node_proc_entry(np
, de
);
120 for (child
= NULL
; (child
= of_get_next_child(np
, child
));) {
121 p
= strrchr(child
->full_name
, '/');
123 p
= child
->full_name
;
126 ent
= proc_mkdir(p
, de
);
129 proc_device_tree_add_node(child
, ent
);
132 for (pp
= np
->properties
; pp
!= 0; pp
= pp
->next
) {
134 * Yet another Apple device-tree bogosity: on some machines,
135 * they have properties & nodes with the same name. Those
136 * properties are quite unimportant for us though, thus we
137 * simply "skip" them here, but we do have to check.
139 for (ent
= de
->subdir
; ent
!= NULL
; ent
= ent
->next
)
140 if (!strcmp(ent
->name
, pp
->name
))
143 printk(KERN_WARNING
"device-tree: property \"%s\" name"
144 " conflicts with node in %s\n", pp
->name
,
149 ent
= __proc_device_tree_add_prop(de
, pp
);
156 * Called on initialization to set up the /proc/device-tree subtree
158 void proc_device_tree_init(void)
160 struct device_node
*root
;
163 proc_device_tree
= proc_mkdir("device-tree", NULL
);
164 if (proc_device_tree
== 0)
166 root
= of_find_node_by_path("/");
168 printk(KERN_ERR
"/proc/device-tree: can't find root\n");
171 proc_device_tree_add_node(root
, proc_device_tree
);