diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-05-01 02:26:07 -0400 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-07-19 23:28:41 -0400 |
commit | 97e873e5c8ad8711ce4cca080cff4eb5d21b3aeb (patch) | |
tree | 7736415a2086522a083392f9ead34dac76c9560c | |
parent | 76c1ce7870fd9b05431da1bbd47fdafcc029a25b (diff) |
Start split out of common open firmware code
This creates drivers/of/base.c (depending on CONFIG_OF) and puts
the first trivially common bits from the prom.c files into it.
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Paul Mackerras <paulus@samba.org>
Acked-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | arch/powerpc/Kconfig | 3 | ||||
-rw-r--r-- | arch/powerpc/kernel/prom.c | 41 | ||||
-rw-r--r-- | arch/sparc/Kconfig | 3 | ||||
-rw-r--r-- | arch/sparc/kernel/prom.c | 42 | ||||
-rw-r--r-- | arch/sparc64/Kconfig | 3 | ||||
-rw-r--r-- | arch/sparc64/kernel/prom.c | 42 | ||||
-rw-r--r-- | drivers/Makefile | 1 | ||||
-rw-r--r-- | drivers/of/Makefile | 1 | ||||
-rw-r--r-- | drivers/of/base.c | 65 | ||||
-rw-r--r-- | include/asm-powerpc/prom.h | 3 | ||||
-rw-r--r-- | include/asm-sparc/prom.h | 3 | ||||
-rw-r--r-- | include/asm-sparc64/prom.h | 3 |
12 files changed, 85 insertions, 125 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index d860b640a140..853c282da22e 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig | |||
@@ -92,6 +92,9 @@ config ARCH_MAY_HAVE_PC_FDC | |||
92 | config PPC_OF | 92 | config PPC_OF |
93 | def_bool y | 93 | def_bool y |
94 | 94 | ||
95 | config OF | ||
96 | def_bool y | ||
97 | |||
95 | config PPC_UDBG_16550 | 98 | config PPC_UDBG_16550 |
96 | bool | 99 | bool |
97 | default n | 100 | default n |
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 37ff99bd98b4..6c9419a4d70a 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c | |||
@@ -1056,35 +1056,6 @@ void __init early_init_devtree(void *params) | |||
1056 | DBG(" <- early_init_devtree()\n"); | 1056 | DBG(" <- early_init_devtree()\n"); |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | int of_n_addr_cells(struct device_node* np) | ||
1060 | { | ||
1061 | const int *ip; | ||
1062 | do { | ||
1063 | if (np->parent) | ||
1064 | np = np->parent; | ||
1065 | ip = of_get_property(np, "#address-cells", NULL); | ||
1066 | if (ip != NULL) | ||
1067 | return *ip; | ||
1068 | } while (np->parent); | ||
1069 | /* No #address-cells property for the root node, default to 1 */ | ||
1070 | return 1; | ||
1071 | } | ||
1072 | EXPORT_SYMBOL(of_n_addr_cells); | ||
1073 | |||
1074 | int of_n_size_cells(struct device_node* np) | ||
1075 | { | ||
1076 | const int* ip; | ||
1077 | do { | ||
1078 | if (np->parent) | ||
1079 | np = np->parent; | ||
1080 | ip = of_get_property(np, "#size-cells", NULL); | ||
1081 | if (ip != NULL) | ||
1082 | return *ip; | ||
1083 | } while (np->parent); | ||
1084 | /* No #size-cells property for the root node, default to 1 */ | ||
1085 | return 1; | ||
1086 | } | ||
1087 | EXPORT_SYMBOL(of_n_size_cells); | ||
1088 | 1059 | ||
1089 | /** Checks if the given "compat" string matches one of the strings in | 1060 | /** Checks if the given "compat" string matches one of the strings in |
1090 | * the device's "compatible" property | 1061 | * the device's "compatible" property |
@@ -1563,18 +1534,6 @@ struct property *of_find_property(const struct device_node *np, | |||
1563 | EXPORT_SYMBOL(of_find_property); | 1534 | EXPORT_SYMBOL(of_find_property); |
1564 | 1535 | ||
1565 | /* | 1536 | /* |
1566 | * Find a property with a given name for a given node | ||
1567 | * and return the value. | ||
1568 | */ | ||
1569 | const void *of_get_property(const struct device_node *np, const char *name, | ||
1570 | int *lenp) | ||
1571 | { | ||
1572 | struct property *pp = of_find_property(np,name,lenp); | ||
1573 | return pp ? pp->value : NULL; | ||
1574 | } | ||
1575 | EXPORT_SYMBOL(of_get_property); | ||
1576 | |||
1577 | /* | ||
1578 | * Add a property to a node | 1537 | * Add a property to a node |
1579 | */ | 1538 | */ |
1580 | int prom_add_property(struct device_node* np, struct property* prop) | 1539 | int prom_add_property(struct device_node* np, struct property* prop) |
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index 603d83ad65c8..9d327ec59759 100644 --- a/arch/sparc/Kconfig +++ b/arch/sparc/Kconfig | |||
@@ -24,6 +24,9 @@ config GENERIC_ISA_DMA | |||
24 | config ARCH_NO_VIRT_TO_BUS | 24 | config ARCH_NO_VIRT_TO_BUS |
25 | def_bool y | 25 | def_bool y |
26 | 26 | ||
27 | config OF | ||
28 | def_bool y | ||
29 | |||
27 | source "init/Kconfig" | 30 | source "init/Kconfig" |
28 | 31 | ||
29 | menu "General machine setup" | 32 | menu "General machine setup" |
diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c index eed140b3c739..ac3f3c29b174 100644 --- a/arch/sparc/kernel/prom.c +++ b/arch/sparc/kernel/prom.c | |||
@@ -168,18 +168,6 @@ struct property *of_find_property(const struct device_node *np, | |||
168 | } | 168 | } |
169 | EXPORT_SYMBOL(of_find_property); | 169 | EXPORT_SYMBOL(of_find_property); |
170 | 170 | ||
171 | /* | ||
172 | * Find a property with a given name for a given node | ||
173 | * and return the value. | ||
174 | */ | ||
175 | const void *of_get_property(const struct device_node *np, const char *name, | ||
176 | int *lenp) | ||
177 | { | ||
178 | struct property *pp = of_find_property(np,name,lenp); | ||
179 | return pp ? pp->value : NULL; | ||
180 | } | ||
181 | EXPORT_SYMBOL(of_get_property); | ||
182 | |||
183 | int of_getintprop_default(struct device_node *np, const char *name, int def) | 171 | int of_getintprop_default(struct device_node *np, const char *name, int def) |
184 | { | 172 | { |
185 | struct property *prop; | 173 | struct property *prop; |
@@ -193,36 +181,6 @@ int of_getintprop_default(struct device_node *np, const char *name, int def) | |||
193 | } | 181 | } |
194 | EXPORT_SYMBOL(of_getintprop_default); | 182 | EXPORT_SYMBOL(of_getintprop_default); |
195 | 183 | ||
196 | int of_n_addr_cells(struct device_node *np) | ||
197 | { | ||
198 | const int* ip; | ||
199 | do { | ||
200 | if (np->parent) | ||
201 | np = np->parent; | ||
202 | ip = of_get_property(np, "#address-cells", NULL); | ||
203 | if (ip != NULL) | ||
204 | return *ip; | ||
205 | } while (np->parent); | ||
206 | /* No #address-cells property for the root node, default to 2 */ | ||
207 | return 2; | ||
208 | } | ||
209 | EXPORT_SYMBOL(of_n_addr_cells); | ||
210 | |||
211 | int of_n_size_cells(struct device_node *np) | ||
212 | { | ||
213 | const int* ip; | ||
214 | do { | ||
215 | if (np->parent) | ||
216 | np = np->parent; | ||
217 | ip = of_get_property(np, "#size-cells", NULL); | ||
218 | if (ip != NULL) | ||
219 | return *ip; | ||
220 | } while (np->parent); | ||
221 | /* No #size-cells property for the root node, default to 1 */ | ||
222 | return 1; | ||
223 | } | ||
224 | EXPORT_SYMBOL(of_n_size_cells); | ||
225 | |||
226 | int of_set_property(struct device_node *dp, const char *name, void *val, int len) | 184 | int of_set_property(struct device_node *dp, const char *name, void *val, int len) |
227 | { | 185 | { |
228 | struct property **prevp; | 186 | struct property **prevp; |
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig index df6ee71894d1..f1cc55677ff2 100644 --- a/arch/sparc64/Kconfig +++ b/arch/sparc64/Kconfig | |||
@@ -65,6 +65,9 @@ config AUDIT_ARCH | |||
65 | config ARCH_NO_VIRT_TO_BUS | 65 | config ARCH_NO_VIRT_TO_BUS |
66 | def_bool y | 66 | def_bool y |
67 | 67 | ||
68 | config OF | ||
69 | def_bool y | ||
70 | |||
68 | choice | 71 | choice |
69 | prompt "Kernel page size" | 72 | prompt "Kernel page size" |
70 | default SPARC64_PAGE_SIZE_8KB | 73 | default SPARC64_PAGE_SIZE_8KB |
diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c index 5d220302cd50..8f926d439c0f 100644 --- a/arch/sparc64/kernel/prom.c +++ b/arch/sparc64/kernel/prom.c | |||
@@ -173,18 +173,6 @@ struct property *of_find_property(const struct device_node *np, | |||
173 | } | 173 | } |
174 | EXPORT_SYMBOL(of_find_property); | 174 | EXPORT_SYMBOL(of_find_property); |
175 | 175 | ||
176 | /* | ||
177 | * Find a property with a given name for a given node | ||
178 | * and return the value. | ||
179 | */ | ||
180 | const void *of_get_property(const struct device_node *np, const char *name, | ||
181 | int *lenp) | ||
182 | { | ||
183 | struct property *pp = of_find_property(np,name,lenp); | ||
184 | return pp ? pp->value : NULL; | ||
185 | } | ||
186 | EXPORT_SYMBOL(of_get_property); | ||
187 | |||
188 | int of_getintprop_default(struct device_node *np, const char *name, int def) | 176 | int of_getintprop_default(struct device_node *np, const char *name, int def) |
189 | { | 177 | { |
190 | struct property *prop; | 178 | struct property *prop; |
@@ -198,36 +186,6 @@ int of_getintprop_default(struct device_node *np, const char *name, int def) | |||
198 | } | 186 | } |
199 | EXPORT_SYMBOL(of_getintprop_default); | 187 | EXPORT_SYMBOL(of_getintprop_default); |
200 | 188 | ||
201 | int of_n_addr_cells(struct device_node *np) | ||
202 | { | ||
203 | const int* ip; | ||
204 | do { | ||
205 | if (np->parent) | ||
206 | np = np->parent; | ||
207 | ip = of_get_property(np, "#address-cells", NULL); | ||
208 | if (ip != NULL) | ||
209 | return *ip; | ||
210 | } while (np->parent); | ||
211 | /* No #address-cells property for the root node, default to 2 */ | ||
212 | return 2; | ||
213 | } | ||
214 | EXPORT_SYMBOL(of_n_addr_cells); | ||
215 | |||
216 | int of_n_size_cells(struct device_node *np) | ||
217 | { | ||
218 | const int* ip; | ||
219 | do { | ||
220 | if (np->parent) | ||
221 | np = np->parent; | ||
222 | ip = of_get_property(np, "#size-cells", NULL); | ||
223 | if (ip != NULL) | ||
224 | return *ip; | ||
225 | } while (np->parent); | ||
226 | /* No #size-cells property for the root node, default to 1 */ | ||
227 | return 1; | ||
228 | } | ||
229 | EXPORT_SYMBOL(of_n_size_cells); | ||
230 | |||
231 | int of_set_property(struct device_node *dp, const char *name, void *val, int len) | 189 | int of_set_property(struct device_node *dp, const char *name, void *val, int len) |
232 | { | 190 | { |
233 | struct property **prevp; | 191 | struct property **prevp; |
diff --git a/drivers/Makefile b/drivers/Makefile index 0ea8e3237c0d..a9e4c5f922a0 100644 --- a/drivers/Makefile +++ b/drivers/Makefile | |||
@@ -86,3 +86,4 @@ obj-$(CONFIG_GENERIC_TIME) += clocksource/ | |||
86 | obj-$(CONFIG_DMA_ENGINE) += dma/ | 86 | obj-$(CONFIG_DMA_ENGINE) += dma/ |
87 | obj-$(CONFIG_HID) += hid/ | 87 | obj-$(CONFIG_HID) += hid/ |
88 | obj-$(CONFIG_PPC_PS3) += ps3/ | 88 | obj-$(CONFIG_PPC_PS3) += ps3/ |
89 | obj-$(CONFIG_OF) += of/ | ||
diff --git a/drivers/of/Makefile b/drivers/of/Makefile new file mode 100644 index 000000000000..cddbe840e30a --- /dev/null +++ b/drivers/of/Makefile | |||
@@ -0,0 +1 @@ | |||
obj-y = base.o | |||
diff --git a/drivers/of/base.c b/drivers/of/base.c new file mode 100644 index 000000000000..723d80d704e0 --- /dev/null +++ b/drivers/of/base.c | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * Procedures for creating, accessing and interpreting the device tree. | ||
3 | * | ||
4 | * Paul Mackerras August 1996. | ||
5 | * Copyright (C) 1996-2005 Paul Mackerras. | ||
6 | * | ||
7 | * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. | ||
8 | * {engebret|bergner}@us.ibm.com | ||
9 | * | ||
10 | * Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net | ||
11 | * | ||
12 | * Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell. | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version | ||
17 | * 2 of the License, or (at your option) any later version. | ||
18 | */ | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/of.h> | ||
21 | |||
22 | int of_n_addr_cells(struct device_node *np) | ||
23 | { | ||
24 | const int *ip; | ||
25 | |||
26 | do { | ||
27 | if (np->parent) | ||
28 | np = np->parent; | ||
29 | ip = of_get_property(np, "#address-cells", NULL); | ||
30 | if (ip) | ||
31 | return *ip; | ||
32 | } while (np->parent); | ||
33 | /* No #address-cells property for the root node */ | ||
34 | return OF_ROOT_NODE_ADDR_CELLS_DEFAULT; | ||
35 | } | ||
36 | EXPORT_SYMBOL(of_n_addr_cells); | ||
37 | |||
38 | int of_n_size_cells(struct device_node *np) | ||
39 | { | ||
40 | const int *ip; | ||
41 | |||
42 | do { | ||
43 | if (np->parent) | ||
44 | np = np->parent; | ||
45 | ip = of_get_property(np, "#size-cells", NULL); | ||
46 | if (ip) | ||
47 | return *ip; | ||
48 | } while (np->parent); | ||
49 | /* No #size-cells property for the root node */ | ||
50 | return OF_ROOT_NODE_SIZE_CELLS_DEFAULT; | ||
51 | } | ||
52 | EXPORT_SYMBOL(of_n_size_cells); | ||
53 | |||
54 | /* | ||
55 | * Find a property with a given name for a given node | ||
56 | * and return the value. | ||
57 | */ | ||
58 | const void *of_get_property(const struct device_node *np, const char *name, | ||
59 | int *lenp) | ||
60 | { | ||
61 | struct property *pp = of_find_property(np, name, lenp); | ||
62 | |||
63 | return pp ? pp->value : NULL; | ||
64 | } | ||
65 | EXPORT_SYMBOL(of_get_property); | ||
diff --git a/include/asm-powerpc/prom.h b/include/asm-powerpc/prom.h index 1134aeab2327..9fe0152ae245 100644 --- a/include/asm-powerpc/prom.h +++ b/include/asm-powerpc/prom.h | |||
@@ -21,6 +21,9 @@ | |||
21 | #include <asm/irq.h> | 21 | #include <asm/irq.h> |
22 | #include <asm/atomic.h> | 22 | #include <asm/atomic.h> |
23 | 23 | ||
24 | #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1 | ||
25 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 | ||
26 | |||
24 | /* Definitions used by the flattened device tree */ | 27 | /* Definitions used by the flattened device tree */ |
25 | #define OF_DT_HEADER 0xd00dfeed /* marker */ | 28 | #define OF_DT_HEADER 0xd00dfeed /* marker */ |
26 | #define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */ | 29 | #define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */ |
diff --git a/include/asm-sparc/prom.h b/include/asm-sparc/prom.h index d67af08abb43..a8a121f6332b 100644 --- a/include/asm-sparc/prom.h +++ b/include/asm-sparc/prom.h | |||
@@ -20,6 +20,9 @@ | |||
20 | #include <linux/proc_fs.h> | 20 | #include <linux/proc_fs.h> |
21 | #include <asm/atomic.h> | 21 | #include <asm/atomic.h> |
22 | 22 | ||
23 | #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2 | ||
24 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 | ||
25 | |||
23 | typedef u32 phandle; | 26 | typedef u32 phandle; |
24 | typedef u32 ihandle; | 27 | typedef u32 ihandle; |
25 | 28 | ||
diff --git a/include/asm-sparc64/prom.h b/include/asm-sparc64/prom.h index 9905ed057d93..c98d1545ee8d 100644 --- a/include/asm-sparc64/prom.h +++ b/include/asm-sparc64/prom.h | |||
@@ -20,6 +20,9 @@ | |||
20 | #include <linux/proc_fs.h> | 20 | #include <linux/proc_fs.h> |
21 | #include <asm/atomic.h> | 21 | #include <asm/atomic.h> |
22 | 22 | ||
23 | #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2 | ||
24 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 | ||
25 | |||
23 | typedef u32 phandle; | 26 | typedef u32 phandle; |
24 | typedef u32 ihandle; | 27 | typedef u32 ihandle; |
25 | 28 | ||