diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-08 10:46:56 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-08 10:46:56 -0500 |
commit | 3ad1f3b35e8309ec93454dbf89beaafcdb5312da (patch) | |
tree | d26e60c334b70adc310b807a33d3491dc205d52d | |
parent | 1557d33007f63dd96e5d15f33af389378e5f2e54 (diff) | |
parent | e91edcf5a2940bb7f1f316c871dfe9e2aaf9d6d9 (diff) |
Merge branch 'next-devicetree' of git://git.secretlab.ca/git/linux-2.6
* 'next-devicetree' of git://git.secretlab.ca/git/linux-2.6:
of: merge of_find_all_nodes() implementations
of: merge other miscellaneous prototypes
of: merge of_*_flat_dt*() functions
of: merge of_node_get(), of_node_put() and of_find_all_nodes()
of: merge of_read_number() an of_read_ulong()
of: merge of_node_*_flag() and set_node_proc_entry()
of: merge struct boot_param_header from Microblaze and PowerPC
of: add common header for flattened device tree representation
of: Move OF_IS_DYNAMIC and OF_MARK_DYNAMIC macros to of.h
of: merge struct device_node
of: merge phandle, ihandle and struct property
of: Rework linux/of.h and asm/prom.h include ordering
-rw-r--r-- | arch/microblaze/include/asm/prom.h | 135 | ||||
-rw-r--r-- | arch/microblaze/kernel/head.S | 2 | ||||
-rw-r--r-- | arch/microblaze/kernel/prom.c | 23 | ||||
-rw-r--r-- | arch/powerpc/include/asm/prom.h | 147 | ||||
-rw-r--r-- | arch/powerpc/kernel/prom.c | 23 | ||||
-rw-r--r-- | arch/sparc/include/asm/prom.h | 55 | ||||
-rw-r--r-- | drivers/of/base.c | 26 | ||||
-rw-r--r-- | include/linux/of.h | 103 | ||||
-rw-r--r-- | include/linux/of_fdt.h | 86 |
9 files changed, 221 insertions, 379 deletions
diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h index 37e6f305a68e..ef3ec1d6ceb3 100644 --- a/arch/microblaze/include/asm/prom.h +++ b/arch/microblaze/include/asm/prom.h | |||
@@ -12,23 +12,15 @@ | |||
12 | * 2 of the License, or (at your option) any later version. | 12 | * 2 of the License, or (at your option) any later version. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/of.h> /* linux/of.h gets to determine #include ordering */ | ||
16 | |||
15 | #ifndef _ASM_MICROBLAZE_PROM_H | 17 | #ifndef _ASM_MICROBLAZE_PROM_H |
16 | #define _ASM_MICROBLAZE_PROM_H | 18 | #define _ASM_MICROBLAZE_PROM_H |
17 | #ifdef __KERNEL__ | 19 | #ifdef __KERNEL__ |
18 | |||
19 | /* Definitions used by the flattened device tree */ | ||
20 | #define OF_DT_HEADER 0xd00dfeed /* marker */ | ||
21 | #define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */ | ||
22 | #define OF_DT_END_NODE 0x2 /* End node */ | ||
23 | #define OF_DT_PROP 0x3 /* Property: name off, size, content */ | ||
24 | #define OF_DT_NOP 0x4 /* nop */ | ||
25 | #define OF_DT_END 0x9 | ||
26 | |||
27 | #define OF_DT_VERSION 0x10 | ||
28 | |||
29 | #ifndef __ASSEMBLY__ | 20 | #ifndef __ASSEMBLY__ |
30 | 21 | ||
31 | #include <linux/types.h> | 22 | #include <linux/types.h> |
23 | #include <linux/of_fdt.h> | ||
32 | #include <linux/proc_fs.h> | 24 | #include <linux/proc_fs.h> |
33 | #include <linux/platform_device.h> | 25 | #include <linux/platform_device.h> |
34 | #include <asm/irq.h> | 26 | #include <asm/irq.h> |
@@ -41,122 +33,19 @@ | |||
41 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) | 33 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) |
42 | #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) | 34 | #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) |
43 | 35 | ||
44 | /* | ||
45 | * This is what gets passed to the kernel by prom_init or kexec | ||
46 | * | ||
47 | * The dt struct contains the device tree structure, full pathes and | ||
48 | * property contents. The dt strings contain a separate block with just | ||
49 | * the strings for the property names, and is fully page aligned and | ||
50 | * self contained in a page, so that it can be kept around by the kernel, | ||
51 | * each property name appears only once in this page (cheap compression) | ||
52 | * | ||
53 | * the mem_rsvmap contains a map of reserved ranges of physical memory, | ||
54 | * passing it here instead of in the device-tree itself greatly simplifies | ||
55 | * the job of everybody. It's just a list of u64 pairs (base/size) that | ||
56 | * ends when size is 0 | ||
57 | */ | ||
58 | struct boot_param_header { | ||
59 | u32 magic; /* magic word OF_DT_HEADER */ | ||
60 | u32 totalsize; /* total size of DT block */ | ||
61 | u32 off_dt_struct; /* offset to structure */ | ||
62 | u32 off_dt_strings; /* offset to strings */ | ||
63 | u32 off_mem_rsvmap; /* offset to memory reserve map */ | ||
64 | u32 version; /* format version */ | ||
65 | u32 last_comp_version; /* last compatible version */ | ||
66 | /* version 2 fields below */ | ||
67 | u32 boot_cpuid_phys; /* Physical CPU id we're booting on */ | ||
68 | /* version 3 fields below */ | ||
69 | u32 dt_strings_size; /* size of the DT strings block */ | ||
70 | /* version 17 fields below */ | ||
71 | u32 dt_struct_size; /* size of the DT structure block */ | ||
72 | }; | ||
73 | |||
74 | typedef u32 phandle; | ||
75 | typedef u32 ihandle; | ||
76 | |||
77 | struct property { | ||
78 | char *name; | ||
79 | int length; | ||
80 | void *value; | ||
81 | struct property *next; | ||
82 | }; | ||
83 | |||
84 | struct device_node { | ||
85 | const char *name; | ||
86 | const char *type; | ||
87 | phandle node; | ||
88 | phandle linux_phandle; | ||
89 | char *full_name; | ||
90 | |||
91 | struct property *properties; | ||
92 | struct property *deadprops; /* removed properties */ | ||
93 | struct device_node *parent; | ||
94 | struct device_node *child; | ||
95 | struct device_node *sibling; | ||
96 | struct device_node *next; /* next device of same type */ | ||
97 | struct device_node *allnext; /* next in list of all nodes */ | ||
98 | struct proc_dir_entry *pde; /* this node's proc directory */ | ||
99 | struct kref kref; | ||
100 | unsigned long _flags; | ||
101 | void *data; | ||
102 | }; | ||
103 | |||
104 | extern struct device_node *of_chosen; | 36 | extern struct device_node *of_chosen; |
105 | 37 | ||
106 | static inline int of_node_check_flag(struct device_node *n, unsigned long flag) | ||
107 | { | ||
108 | return test_bit(flag, &n->_flags); | ||
109 | } | ||
110 | |||
111 | static inline void of_node_set_flag(struct device_node *n, unsigned long flag) | ||
112 | { | ||
113 | set_bit(flag, &n->_flags); | ||
114 | } | ||
115 | |||
116 | #define HAVE_ARCH_DEVTREE_FIXUPS | 38 | #define HAVE_ARCH_DEVTREE_FIXUPS |
117 | 39 | ||
118 | static inline void set_node_proc_entry(struct device_node *dn, | ||
119 | struct proc_dir_entry *de) | ||
120 | { | ||
121 | dn->pde = de; | ||
122 | } | ||
123 | |||
124 | extern struct device_node *allnodes; /* temporary while merging */ | 40 | extern struct device_node *allnodes; /* temporary while merging */ |
125 | extern rwlock_t devtree_lock; /* temporary while merging */ | 41 | extern rwlock_t devtree_lock; /* temporary while merging */ |
126 | 42 | ||
127 | extern struct device_node *of_find_all_nodes(struct device_node *prev); | ||
128 | extern struct device_node *of_node_get(struct device_node *node); | ||
129 | extern void of_node_put(struct device_node *node); | ||
130 | |||
131 | /* For scanning the flat device-tree at boot time */ | ||
132 | extern int __init of_scan_flat_dt(int (*it)(unsigned long node, | ||
133 | const char *uname, int depth, | ||
134 | void *data), | ||
135 | void *data); | ||
136 | extern void *__init of_get_flat_dt_prop(unsigned long node, const char *name, | ||
137 | unsigned long *size); | ||
138 | extern int __init | ||
139 | of_flat_dt_is_compatible(unsigned long node, const char *name); | ||
140 | extern unsigned long __init of_get_flat_dt_root(void); | ||
141 | |||
142 | /* For updating the device tree at runtime */ | 43 | /* For updating the device tree at runtime */ |
143 | extern void of_attach_node(struct device_node *); | 44 | extern void of_attach_node(struct device_node *); |
144 | extern void of_detach_node(struct device_node *); | 45 | extern void of_detach_node(struct device_node *); |
145 | 46 | ||
146 | /* Other Prototypes */ | 47 | /* Other Prototypes */ |
147 | extern void finish_device_tree(void); | ||
148 | extern void unflatten_device_tree(void); | ||
149 | extern int early_uartlite_console(void); | 48 | extern int early_uartlite_console(void); |
150 | extern void early_init_devtree(void *); | ||
151 | extern int machine_is_compatible(const char *compat); | ||
152 | extern void print_properties(struct device_node *node); | ||
153 | extern int prom_n_intr_cells(struct device_node *np); | ||
154 | extern void prom_get_irq_senses(unsigned char *senses, int off, int max); | ||
155 | extern int prom_add_property(struct device_node *np, struct property *prop); | ||
156 | extern int prom_remove_property(struct device_node *np, struct property *prop); | ||
157 | extern int prom_update_property(struct device_node *np, | ||
158 | struct property *newprop, | ||
159 | struct property *oldprop); | ||
160 | 49 | ||
161 | extern struct resource *request_OF_resource(struct device_node *node, | 50 | extern struct resource *request_OF_resource(struct device_node *node, |
162 | int index, const char *name_postfix); | 51 | int index, const char *name_postfix); |
@@ -166,18 +55,6 @@ extern int release_OF_resource(struct device_node *node, int index); | |||
166 | * OF address retreival & translation | 55 | * OF address retreival & translation |
167 | */ | 56 | */ |
168 | 57 | ||
169 | /* Helper to read a big number; size is in cells (not bytes) */ | ||
170 | static inline u64 of_read_number(const u32 *cell, int size) | ||
171 | { | ||
172 | u64 r = 0; | ||
173 | while (size--) | ||
174 | r = (r << 32) | *(cell++); | ||
175 | return r; | ||
176 | } | ||
177 | |||
178 | /* Like of_read_number, but we want an unsigned long result */ | ||
179 | #define of_read_ulong(cell, size) of_read_number(cell, size) | ||
180 | |||
181 | /* Translate an OF address block into a CPU physical address | 58 | /* Translate an OF address block into a CPU physical address |
182 | */ | 59 | */ |
183 | extern u64 of_translate_address(struct device_node *np, const u32 *addr); | 60 | extern u64 of_translate_address(struct device_node *np, const u32 *addr); |
@@ -305,12 +182,6 @@ extern int of_irq_to_resource(struct device_node *dev, int index, | |||
305 | */ | 182 | */ |
306 | extern void __iomem *of_iomap(struct device_node *device, int index); | 183 | extern void __iomem *of_iomap(struct device_node *device, int index); |
307 | 184 | ||
308 | /* | ||
309 | * NB: This is here while we transition from using asm/prom.h | ||
310 | * to linux/of.h | ||
311 | */ | ||
312 | #include <linux/of.h> | ||
313 | |||
314 | #endif /* __ASSEMBLY__ */ | 185 | #endif /* __ASSEMBLY__ */ |
315 | #endif /* __KERNEL__ */ | 186 | #endif /* __KERNEL__ */ |
316 | #endif /* _ASM_MICROBLAZE_PROM_H */ | 187 | #endif /* _ASM_MICROBLAZE_PROM_H */ |
diff --git a/arch/microblaze/kernel/head.S b/arch/microblaze/kernel/head.S index 697ce3007f30..30916193fcc7 100644 --- a/arch/microblaze/kernel/head.S +++ b/arch/microblaze/kernel/head.S | |||
@@ -31,7 +31,7 @@ | |||
31 | #include <linux/linkage.h> | 31 | #include <linux/linkage.h> |
32 | #include <asm/thread_info.h> | 32 | #include <asm/thread_info.h> |
33 | #include <asm/page.h> | 33 | #include <asm/page.h> |
34 | #include <asm/prom.h> /* for OF_DT_HEADER */ | 34 | #include <linux/of_fdt.h> /* for OF_DT_HEADER */ |
35 | 35 | ||
36 | #ifdef CONFIG_MMU | 36 | #ifdef CONFIG_MMU |
37 | #include <asm/setup.h> /* COMMAND_LINE_SIZE */ | 37 | #include <asm/setup.h> /* COMMAND_LINE_SIZE */ |
diff --git a/arch/microblaze/kernel/prom.c b/arch/microblaze/kernel/prom.c index c005cc6f1aaf..b817df172aa9 100644 --- a/arch/microblaze/kernel/prom.c +++ b/arch/microblaze/kernel/prom.c | |||
@@ -860,29 +860,6 @@ struct device_node *of_find_node_by_phandle(phandle handle) | |||
860 | EXPORT_SYMBOL(of_find_node_by_phandle); | 860 | EXPORT_SYMBOL(of_find_node_by_phandle); |
861 | 861 | ||
862 | /** | 862 | /** |
863 | * of_find_all_nodes - Get next node in global list | ||
864 | * @prev: Previous node or NULL to start iteration | ||
865 | * of_node_put() will be called on it | ||
866 | * | ||
867 | * Returns a node pointer with refcount incremented, use | ||
868 | * of_node_put() on it when done. | ||
869 | */ | ||
870 | struct device_node *of_find_all_nodes(struct device_node *prev) | ||
871 | { | ||
872 | struct device_node *np; | ||
873 | |||
874 | read_lock(&devtree_lock); | ||
875 | np = prev ? prev->allnext : allnodes; | ||
876 | for (; np != NULL; np = np->allnext) | ||
877 | if (of_node_get(np)) | ||
878 | break; | ||
879 | of_node_put(prev); | ||
880 | read_unlock(&devtree_lock); | ||
881 | return np; | ||
882 | } | ||
883 | EXPORT_SYMBOL(of_find_all_nodes); | ||
884 | |||
885 | /** | ||
886 | * of_node_get - Increment refcount of a node | 863 | * of_node_get - Increment refcount of a node |
887 | * @node: Node to inc refcount, NULL is supported to | 864 | * @node: Node to inc refcount, NULL is supported to |
888 | * simplify writing of callers | 865 | * simplify writing of callers |
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h index 6ff04185d2aa..2ab9cbd98826 100644 --- a/arch/powerpc/include/asm/prom.h +++ b/arch/powerpc/include/asm/prom.h | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <linux/of.h> /* linux/of.h gets to determine #include ordering */ | ||
1 | #ifndef _POWERPC_PROM_H | 2 | #ifndef _POWERPC_PROM_H |
2 | #define _POWERPC_PROM_H | 3 | #define _POWERPC_PROM_H |
3 | #ifdef __KERNEL__ | 4 | #ifdef __KERNEL__ |
@@ -16,6 +17,7 @@ | |||
16 | * 2 of the License, or (at your option) any later version. | 17 | * 2 of the License, or (at your option) any later version. |
17 | */ | 18 | */ |
18 | #include <linux/types.h> | 19 | #include <linux/types.h> |
20 | #include <linux/of_fdt.h> | ||
19 | #include <linux/proc_fs.h> | 21 | #include <linux/proc_fs.h> |
20 | #include <linux/platform_device.h> | 22 | #include <linux/platform_device.h> |
21 | #include <asm/irq.h> | 23 | #include <asm/irq.h> |
@@ -28,133 +30,14 @@ | |||
28 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) | 30 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) |
29 | #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) | 31 | #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) |
30 | 32 | ||
31 | /* Definitions used by the flattened device tree */ | ||
32 | #define OF_DT_HEADER 0xd00dfeed /* marker */ | ||
33 | #define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */ | ||
34 | #define OF_DT_END_NODE 0x2 /* End node */ | ||
35 | #define OF_DT_PROP 0x3 /* Property: name off, size, | ||
36 | * content */ | ||
37 | #define OF_DT_NOP 0x4 /* nop */ | ||
38 | #define OF_DT_END 0x9 | ||
39 | |||
40 | #define OF_DT_VERSION 0x10 | ||
41 | |||
42 | /* | ||
43 | * This is what gets passed to the kernel by prom_init or kexec | ||
44 | * | ||
45 | * The dt struct contains the device tree structure, full pathes and | ||
46 | * property contents. The dt strings contain a separate block with just | ||
47 | * the strings for the property names, and is fully page aligned and | ||
48 | * self contained in a page, so that it can be kept around by the kernel, | ||
49 | * each property name appears only once in this page (cheap compression) | ||
50 | * | ||
51 | * the mem_rsvmap contains a map of reserved ranges of physical memory, | ||
52 | * passing it here instead of in the device-tree itself greatly simplifies | ||
53 | * the job of everybody. It's just a list of u64 pairs (base/size) that | ||
54 | * ends when size is 0 | ||
55 | */ | ||
56 | struct boot_param_header | ||
57 | { | ||
58 | u32 magic; /* magic word OF_DT_HEADER */ | ||
59 | u32 totalsize; /* total size of DT block */ | ||
60 | u32 off_dt_struct; /* offset to structure */ | ||
61 | u32 off_dt_strings; /* offset to strings */ | ||
62 | u32 off_mem_rsvmap; /* offset to memory reserve map */ | ||
63 | u32 version; /* format version */ | ||
64 | u32 last_comp_version; /* last compatible version */ | ||
65 | /* version 2 fields below */ | ||
66 | u32 boot_cpuid_phys; /* Physical CPU id we're booting on */ | ||
67 | /* version 3 fields below */ | ||
68 | u32 dt_strings_size; /* size of the DT strings block */ | ||
69 | /* version 17 fields below */ | ||
70 | u32 dt_struct_size; /* size of the DT structure block */ | ||
71 | }; | ||
72 | |||
73 | |||
74 | |||
75 | typedef u32 phandle; | ||
76 | typedef u32 ihandle; | ||
77 | |||
78 | struct property { | ||
79 | char *name; | ||
80 | int length; | ||
81 | void *value; | ||
82 | struct property *next; | ||
83 | }; | ||
84 | |||
85 | struct device_node { | ||
86 | const char *name; | ||
87 | const char *type; | ||
88 | phandle node; | ||
89 | phandle linux_phandle; | ||
90 | char *full_name; | ||
91 | |||
92 | struct property *properties; | ||
93 | struct property *deadprops; /* removed properties */ | ||
94 | struct device_node *parent; | ||
95 | struct device_node *child; | ||
96 | struct device_node *sibling; | ||
97 | struct device_node *next; /* next device of same type */ | ||
98 | struct device_node *allnext; /* next in list of all nodes */ | ||
99 | struct proc_dir_entry *pde; /* this node's proc directory */ | ||
100 | struct kref kref; | ||
101 | unsigned long _flags; | ||
102 | void *data; | ||
103 | }; | ||
104 | |||
105 | extern struct device_node *of_chosen; | 33 | extern struct device_node *of_chosen; |
106 | 34 | ||
107 | static inline int of_node_check_flag(struct device_node *n, unsigned long flag) | ||
108 | { | ||
109 | return test_bit(flag, &n->_flags); | ||
110 | } | ||
111 | |||
112 | static inline void of_node_set_flag(struct device_node *n, unsigned long flag) | ||
113 | { | ||
114 | set_bit(flag, &n->_flags); | ||
115 | } | ||
116 | |||
117 | |||
118 | #define HAVE_ARCH_DEVTREE_FIXUPS | 35 | #define HAVE_ARCH_DEVTREE_FIXUPS |
119 | 36 | ||
120 | static inline void set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de) | ||
121 | { | ||
122 | dn->pde = de; | ||
123 | } | ||
124 | |||
125 | |||
126 | extern struct device_node *of_find_all_nodes(struct device_node *prev); | ||
127 | extern struct device_node *of_node_get(struct device_node *node); | ||
128 | extern void of_node_put(struct device_node *node); | ||
129 | |||
130 | /* For scanning the flat device-tree at boot time */ | ||
131 | extern int __init of_scan_flat_dt(int (*it)(unsigned long node, | ||
132 | const char *uname, int depth, | ||
133 | void *data), | ||
134 | void *data); | ||
135 | extern void* __init of_get_flat_dt_prop(unsigned long node, const char *name, | ||
136 | unsigned long *size); | ||
137 | extern int __init of_flat_dt_is_compatible(unsigned long node, const char *name); | ||
138 | extern unsigned long __init of_get_flat_dt_root(void); | ||
139 | |||
140 | /* For updating the device tree at runtime */ | 37 | /* For updating the device tree at runtime */ |
141 | extern void of_attach_node(struct device_node *); | 38 | extern void of_attach_node(struct device_node *); |
142 | extern void of_detach_node(struct device_node *); | 39 | extern void of_detach_node(struct device_node *); |
143 | 40 | ||
144 | /* Other Prototypes */ | ||
145 | extern void finish_device_tree(void); | ||
146 | extern void unflatten_device_tree(void); | ||
147 | extern void early_init_devtree(void *); | ||
148 | extern int machine_is_compatible(const char *compat); | ||
149 | extern void print_properties(struct device_node *node); | ||
150 | extern int prom_n_intr_cells(struct device_node* np); | ||
151 | extern void prom_get_irq_senses(unsigned char *senses, int off, int max); | ||
152 | extern int prom_add_property(struct device_node* np, struct property* prop); | ||
153 | extern int prom_remove_property(struct device_node *np, struct property *prop); | ||
154 | extern int prom_update_property(struct device_node *np, | ||
155 | struct property *newprop, | ||
156 | struct property *oldprop); | ||
157 | |||
158 | #ifdef CONFIG_PPC32 | 41 | #ifdef CONFIG_PPC32 |
159 | /* | 42 | /* |
160 | * PCI <-> OF matching functions | 43 | * PCI <-> OF matching functions |
@@ -178,26 +61,6 @@ extern int release_OF_resource(struct device_node* node, int index); | |||
178 | * OF address retreival & translation | 61 | * OF address retreival & translation |
179 | */ | 62 | */ |
180 | 63 | ||
181 | |||
182 | /* Helper to read a big number; size is in cells (not bytes) */ | ||
183 | static inline u64 of_read_number(const u32 *cell, int size) | ||
184 | { | ||
185 | u64 r = 0; | ||
186 | while (size--) | ||
187 | r = (r << 32) | *(cell++); | ||
188 | return r; | ||
189 | } | ||
190 | |||
191 | /* Like of_read_number, but we want an unsigned long result */ | ||
192 | #ifdef CONFIG_PPC32 | ||
193 | static inline unsigned long of_read_ulong(const u32 *cell, int size) | ||
194 | { | ||
195 | return cell[size-1]; | ||
196 | } | ||
197 | #else | ||
198 | #define of_read_ulong(cell, size) of_read_number(cell, size) | ||
199 | #endif | ||
200 | |||
201 | /* Translate an OF address block into a CPU physical address | 64 | /* Translate an OF address block into a CPU physical address |
202 | */ | 65 | */ |
203 | extern u64 of_translate_address(struct device_node *np, const u32 *addr); | 66 | extern u64 of_translate_address(struct device_node *np, const u32 *addr); |
@@ -349,11 +212,5 @@ extern int of_irq_to_resource(struct device_node *dev, int index, | |||
349 | */ | 212 | */ |
350 | extern void __iomem *of_iomap(struct device_node *device, int index); | 213 | extern void __iomem *of_iomap(struct device_node *device, int index); |
351 | 214 | ||
352 | /* | ||
353 | * NB: This is here while we transition from using asm/prom.h | ||
354 | * to linux/of.h | ||
355 | */ | ||
356 | #include <linux/of.h> | ||
357 | |||
358 | #endif /* __KERNEL__ */ | 215 | #endif /* __KERNEL__ */ |
359 | #endif /* _POWERPC_PROM_H */ | 216 | #endif /* _POWERPC_PROM_H */ |
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index d4405b95bfaa..4ec300862466 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c | |||
@@ -1317,29 +1317,6 @@ struct device_node *of_find_next_cache_node(struct device_node *np) | |||
1317 | } | 1317 | } |
1318 | 1318 | ||
1319 | /** | 1319 | /** |
1320 | * of_find_all_nodes - Get next node in global list | ||
1321 | * @prev: Previous node or NULL to start iteration | ||
1322 | * of_node_put() will be called on it | ||
1323 | * | ||
1324 | * Returns a node pointer with refcount incremented, use | ||
1325 | * of_node_put() on it when done. | ||
1326 | */ | ||
1327 | struct device_node *of_find_all_nodes(struct device_node *prev) | ||
1328 | { | ||
1329 | struct device_node *np; | ||
1330 | |||
1331 | read_lock(&devtree_lock); | ||
1332 | np = prev ? prev->allnext : allnodes; | ||
1333 | for (; np != 0; np = np->allnext) | ||
1334 | if (of_node_get(np)) | ||
1335 | break; | ||
1336 | of_node_put(prev); | ||
1337 | read_unlock(&devtree_lock); | ||
1338 | return np; | ||
1339 | } | ||
1340 | EXPORT_SYMBOL(of_find_all_nodes); | ||
1341 | |||
1342 | /** | ||
1343 | * of_node_get - Increment refcount of a node | 1320 | * of_node_get - Increment refcount of a node |
1344 | * @node: Node to inc refcount, NULL is supported to | 1321 | * @node: Node to inc refcount, NULL is supported to |
1345 | * simplify writing of callers | 1322 | * simplify writing of callers |
diff --git a/arch/sparc/include/asm/prom.h b/arch/sparc/include/asm/prom.h index 82a190d7efc1..f845828ca4c6 100644 --- a/arch/sparc/include/asm/prom.h +++ b/arch/sparc/include/asm/prom.h | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <linux/of.h> /* linux/of.h gets to determine #include ordering */ | ||
1 | #ifndef _SPARC_PROM_H | 2 | #ifndef _SPARC_PROM_H |
2 | #define _SPARC_PROM_H | 3 | #define _SPARC_PROM_H |
3 | #ifdef __KERNEL__ | 4 | #ifdef __KERNEL__ |
@@ -28,50 +29,11 @@ | |||
28 | #define of_prop_cmp(s1, s2) strcasecmp((s1), (s2)) | 29 | #define of_prop_cmp(s1, s2) strcasecmp((s1), (s2)) |
29 | #define of_node_cmp(s1, s2) strcmp((s1), (s2)) | 30 | #define of_node_cmp(s1, s2) strcmp((s1), (s2)) |
30 | 31 | ||
31 | typedef u32 phandle; | ||
32 | typedef u32 ihandle; | ||
33 | |||
34 | struct property { | ||
35 | char *name; | ||
36 | int length; | ||
37 | void *value; | ||
38 | struct property *next; | ||
39 | unsigned long _flags; | ||
40 | unsigned int unique_id; | ||
41 | }; | ||
42 | |||
43 | struct of_irq_controller; | ||
44 | struct device_node { | ||
45 | const char *name; | ||
46 | const char *type; | ||
47 | phandle node; | ||
48 | char *path_component_name; | ||
49 | char *full_name; | ||
50 | |||
51 | struct property *properties; | ||
52 | struct property *deadprops; /* removed properties */ | ||
53 | struct device_node *parent; | ||
54 | struct device_node *child; | ||
55 | struct device_node *sibling; | ||
56 | struct device_node *next; /* next device of same type */ | ||
57 | struct device_node *allnext; /* next in list of all nodes */ | ||
58 | struct proc_dir_entry *pde; /* this node's proc directory */ | ||
59 | struct kref kref; | ||
60 | unsigned long _flags; | ||
61 | void *data; | ||
62 | unsigned int unique_id; | ||
63 | |||
64 | struct of_irq_controller *irq_trans; | ||
65 | }; | ||
66 | |||
67 | struct of_irq_controller { | 32 | struct of_irq_controller { |
68 | unsigned int (*irq_build)(struct device_node *, unsigned int, void *); | 33 | unsigned int (*irq_build)(struct device_node *, unsigned int, void *); |
69 | void *data; | 34 | void *data; |
70 | }; | 35 | }; |
71 | 36 | ||
72 | #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) | ||
73 | #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) | ||
74 | |||
75 | extern struct device_node *of_find_node_by_cpuid(int cpuid); | 37 | extern struct device_node *of_find_node_by_cpuid(int cpuid); |
76 | extern int of_set_property(struct device_node *node, const char *name, void *val, int len); | 38 | extern int of_set_property(struct device_node *node, const char *name, void *val, int len); |
77 | extern struct mutex of_set_property_mutex; | 39 | extern struct mutex of_set_property_mutex; |
@@ -89,15 +51,6 @@ extern void prom_build_devicetree(void); | |||
89 | extern void of_populate_present_mask(void); | 51 | extern void of_populate_present_mask(void); |
90 | extern void of_fill_in_cpu_data(void); | 52 | extern void of_fill_in_cpu_data(void); |
91 | 53 | ||
92 | /* Dummy ref counting routines - to be implemented later */ | ||
93 | static inline struct device_node *of_node_get(struct device_node *node) | ||
94 | { | ||
95 | return node; | ||
96 | } | ||
97 | static inline void of_node_put(struct device_node *node) | ||
98 | { | ||
99 | } | ||
100 | |||
101 | /* These routines are here to provide compatibility with how powerpc | 54 | /* These routines are here to provide compatibility with how powerpc |
102 | * handles IRQ mapping for OF device nodes. We precompute and permanently | 55 | * handles IRQ mapping for OF device nodes. We precompute and permanently |
103 | * register them in the of_device objects, whereas powerpc computes them | 56 | * register them in the of_device objects, whereas powerpc computes them |
@@ -108,12 +61,6 @@ static inline void irq_dispose_mapping(unsigned int virq) | |||
108 | { | 61 | { |
109 | } | 62 | } |
110 | 63 | ||
111 | /* | ||
112 | * NB: This is here while we transition from using asm/prom.h | ||
113 | * to linux/of.h | ||
114 | */ | ||
115 | #include <linux/of.h> | ||
116 | |||
117 | extern struct device_node *of_console_device; | 64 | extern struct device_node *of_console_device; |
118 | extern char *of_console_path; | 65 | extern char *of_console_path; |
119 | extern char *of_console_options; | 66 | extern char *of_console_options; |
diff --git a/drivers/of/base.c b/drivers/of/base.c index ddf224d456b2..e6627b2320f1 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -9,7 +9,8 @@ | |||
9 | * | 9 | * |
10 | * Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net | 10 | * Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net |
11 | * | 11 | * |
12 | * Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell. | 12 | * Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell and |
13 | * Grant Likely. | ||
13 | * | 14 | * |
14 | * This program is free software; you can redistribute it and/or | 15 | * This program is free software; you can redistribute it and/or |
15 | * modify it under the terms of the GNU General Public License | 16 | * modify it under the terms of the GNU General Public License |
@@ -82,6 +83,29 @@ struct property *of_find_property(const struct device_node *np, | |||
82 | } | 83 | } |
83 | EXPORT_SYMBOL(of_find_property); | 84 | EXPORT_SYMBOL(of_find_property); |
84 | 85 | ||
86 | /** | ||
87 | * of_find_all_nodes - Get next node in global list | ||
88 | * @prev: Previous node or NULL to start iteration | ||
89 | * of_node_put() will be called on it | ||
90 | * | ||
91 | * Returns a node pointer with refcount incremented, use | ||
92 | * of_node_put() on it when done. | ||
93 | */ | ||
94 | struct device_node *of_find_all_nodes(struct device_node *prev) | ||
95 | { | ||
96 | struct device_node *np; | ||
97 | |||
98 | read_lock(&devtree_lock); | ||
99 | np = prev ? prev->allnext : allnodes; | ||
100 | for (; np != NULL; np = np->allnext) | ||
101 | if (of_node_get(np)) | ||
102 | break; | ||
103 | of_node_put(prev); | ||
104 | read_unlock(&devtree_lock); | ||
105 | return np; | ||
106 | } | ||
107 | EXPORT_SYMBOL(of_find_all_nodes); | ||
108 | |||
85 | /* | 109 | /* |
86 | * Find a property with a given name for a given node | 110 | * Find a property with a given name for a given node |
87 | * and return the value. | 111 | * and return the value. |
diff --git a/include/linux/of.h b/include/linux/of.h index 7be2d1043c16..e7facd8fbce8 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
@@ -17,14 +17,117 @@ | |||
17 | */ | 17 | */ |
18 | #include <linux/types.h> | 18 | #include <linux/types.h> |
19 | #include <linux/bitops.h> | 19 | #include <linux/bitops.h> |
20 | #include <linux/kref.h> | ||
20 | #include <linux/mod_devicetable.h> | 21 | #include <linux/mod_devicetable.h> |
21 | 22 | ||
23 | typedef u32 phandle; | ||
24 | typedef u32 ihandle; | ||
25 | |||
26 | struct property { | ||
27 | char *name; | ||
28 | int length; | ||
29 | void *value; | ||
30 | struct property *next; | ||
31 | unsigned long _flags; | ||
32 | unsigned int unique_id; | ||
33 | }; | ||
34 | |||
35 | #if defined(CONFIG_SPARC) | ||
36 | struct of_irq_controller; | ||
37 | #endif | ||
38 | |||
39 | struct device_node { | ||
40 | const char *name; | ||
41 | const char *type; | ||
42 | phandle node; | ||
43 | #if !defined(CONFIG_SPARC) | ||
44 | phandle linux_phandle; | ||
45 | #endif | ||
46 | char *full_name; | ||
47 | |||
48 | struct property *properties; | ||
49 | struct property *deadprops; /* removed properties */ | ||
50 | struct device_node *parent; | ||
51 | struct device_node *child; | ||
52 | struct device_node *sibling; | ||
53 | struct device_node *next; /* next device of same type */ | ||
54 | struct device_node *allnext; /* next in list of all nodes */ | ||
55 | struct proc_dir_entry *pde; /* this node's proc directory */ | ||
56 | struct kref kref; | ||
57 | unsigned long _flags; | ||
58 | void *data; | ||
59 | #if defined(CONFIG_SPARC) | ||
60 | char *path_component_name; | ||
61 | unsigned int unique_id; | ||
62 | struct of_irq_controller *irq_trans; | ||
63 | #endif | ||
64 | }; | ||
65 | |||
66 | static inline int of_node_check_flag(struct device_node *n, unsigned long flag) | ||
67 | { | ||
68 | return test_bit(flag, &n->_flags); | ||
69 | } | ||
70 | |||
71 | static inline void of_node_set_flag(struct device_node *n, unsigned long flag) | ||
72 | { | ||
73 | set_bit(flag, &n->_flags); | ||
74 | } | ||
75 | |||
76 | static inline void | ||
77 | set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de) | ||
78 | { | ||
79 | dn->pde = de; | ||
80 | } | ||
81 | |||
82 | extern struct device_node *of_find_all_nodes(struct device_node *prev); | ||
83 | |||
84 | #if defined(CONFIG_SPARC) | ||
85 | /* Dummy ref counting routines - to be implemented later */ | ||
86 | static inline struct device_node *of_node_get(struct device_node *node) | ||
87 | { | ||
88 | return node; | ||
89 | } | ||
90 | static inline void of_node_put(struct device_node *node) | ||
91 | { | ||
92 | } | ||
93 | |||
94 | #else | ||
95 | extern struct device_node *of_node_get(struct device_node *node); | ||
96 | extern void of_node_put(struct device_node *node); | ||
97 | #endif | ||
98 | |||
99 | /* | ||
100 | * OF address retreival & translation | ||
101 | */ | ||
102 | |||
103 | /* Helper to read a big number; size is in cells (not bytes) */ | ||
104 | static inline u64 of_read_number(const u32 *cell, int size) | ||
105 | { | ||
106 | u64 r = 0; | ||
107 | while (size--) | ||
108 | r = (r << 32) | *(cell++); | ||
109 | return r; | ||
110 | } | ||
111 | |||
112 | /* Like of_read_number, but we want an unsigned long result */ | ||
113 | #ifdef CONFIG_PPC32 | ||
114 | static inline unsigned long of_read_ulong(const u32 *cell, int size) | ||
115 | { | ||
116 | return cell[size-1]; | ||
117 | } | ||
118 | #else | ||
119 | #define of_read_ulong(cell, size) of_read_number(cell, size) | ||
120 | #endif | ||
121 | |||
22 | #include <asm/prom.h> | 122 | #include <asm/prom.h> |
23 | 123 | ||
24 | /* flag descriptions */ | 124 | /* flag descriptions */ |
25 | #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ | 125 | #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ |
26 | #define OF_DETACHED 2 /* node has been detached from the device tree */ | 126 | #define OF_DETACHED 2 /* node has been detached from the device tree */ |
27 | 127 | ||
128 | #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) | ||
129 | #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) | ||
130 | |||
28 | #define OF_BAD_ADDR ((u64)-1) | 131 | #define OF_BAD_ADDR ((u64)-1) |
29 | 132 | ||
30 | extern struct device_node *of_find_node_by_name(struct device_node *from, | 133 | extern struct device_node *of_find_node_by_name(struct device_node *from, |
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h new file mode 100644 index 000000000000..41d432b13553 --- /dev/null +++ b/include/linux/of_fdt.h | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * Definitions for working with the Flattened Device Tree data format | ||
3 | * | ||
4 | * Copyright 2009 Benjamin Herrenschmidt, IBM Corp | ||
5 | * benh@kernel.crashing.org | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #ifndef _LINUX_OF_FDT_H | ||
13 | #define _LINUX_OF_FDT_H | ||
14 | |||
15 | #include <linux/types.h> | ||
16 | #include <linux/init.h> | ||
17 | |||
18 | /* Definitions used by the flattened device tree */ | ||
19 | #define OF_DT_HEADER 0xd00dfeed /* marker */ | ||
20 | #define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */ | ||
21 | #define OF_DT_END_NODE 0x2 /* End node */ | ||
22 | #define OF_DT_PROP 0x3 /* Property: name off, size, | ||
23 | * content */ | ||
24 | #define OF_DT_NOP 0x4 /* nop */ | ||
25 | #define OF_DT_END 0x9 | ||
26 | |||
27 | #define OF_DT_VERSION 0x10 | ||
28 | |||
29 | #ifndef __ASSEMBLY__ | ||
30 | /* | ||
31 | * This is what gets passed to the kernel by prom_init or kexec | ||
32 | * | ||
33 | * The dt struct contains the device tree structure, full pathes and | ||
34 | * property contents. The dt strings contain a separate block with just | ||
35 | * the strings for the property names, and is fully page aligned and | ||
36 | * self contained in a page, so that it can be kept around by the kernel, | ||
37 | * each property name appears only once in this page (cheap compression) | ||
38 | * | ||
39 | * the mem_rsvmap contains a map of reserved ranges of physical memory, | ||
40 | * passing it here instead of in the device-tree itself greatly simplifies | ||
41 | * the job of everybody. It's just a list of u64 pairs (base/size) that | ||
42 | * ends when size is 0 | ||
43 | */ | ||
44 | struct boot_param_header { | ||
45 | u32 magic; /* magic word OF_DT_HEADER */ | ||
46 | u32 totalsize; /* total size of DT block */ | ||
47 | u32 off_dt_struct; /* offset to structure */ | ||
48 | u32 off_dt_strings; /* offset to strings */ | ||
49 | u32 off_mem_rsvmap; /* offset to memory reserve map */ | ||
50 | u32 version; /* format version */ | ||
51 | u32 last_comp_version; /* last compatible version */ | ||
52 | /* version 2 fields below */ | ||
53 | u32 boot_cpuid_phys; /* Physical CPU id we're booting on */ | ||
54 | /* version 3 fields below */ | ||
55 | u32 dt_strings_size; /* size of the DT strings block */ | ||
56 | /* version 17 fields below */ | ||
57 | u32 dt_struct_size; /* size of the DT structure block */ | ||
58 | }; | ||
59 | |||
60 | /* For scanning the flat device-tree at boot time */ | ||
61 | extern int __init of_scan_flat_dt(int (*it)(unsigned long node, | ||
62 | const char *uname, int depth, | ||
63 | void *data), | ||
64 | void *data); | ||
65 | extern void __init *of_get_flat_dt_prop(unsigned long node, const char *name, | ||
66 | unsigned long *size); | ||
67 | extern int __init of_flat_dt_is_compatible(unsigned long node, | ||
68 | const char *name); | ||
69 | extern unsigned long __init of_get_flat_dt_root(void); | ||
70 | |||
71 | /* Other Prototypes */ | ||
72 | extern void finish_device_tree(void); | ||
73 | extern void unflatten_device_tree(void); | ||
74 | extern void early_init_devtree(void *); | ||
75 | extern int machine_is_compatible(const char *compat); | ||
76 | extern void print_properties(struct device_node *node); | ||
77 | extern int prom_n_intr_cells(struct device_node* np); | ||
78 | extern void prom_get_irq_senses(unsigned char *senses, int off, int max); | ||
79 | extern int prom_add_property(struct device_node* np, struct property* prop); | ||
80 | extern int prom_remove_property(struct device_node *np, struct property *prop); | ||
81 | extern int prom_update_property(struct device_node *np, | ||
82 | struct property *newprop, | ||
83 | struct property *oldprop); | ||
84 | |||
85 | #endif /* __ASSEMBLY__ */ | ||
86 | #endif /* _LINUX_OF_FDT_H */ | ||