diff options
| author | Andres Salomon <dilinger@queued.net> | 2010-10-10 23:42:33 -0400 |
|---|---|---|
| committer | Grant Likely <grant.likely@secretlab.ca> | 2010-10-10 23:53:30 -0400 |
| commit | 3cfc535c5df8122af1258ae05aaf2770c033425d (patch) | |
| tree | c5643066e544df08a852742060da2edfd2f6400d | |
| parent | 9bdf6bab4ecfb6a8ca50c0c46f2365ef6c3e35b7 (diff) | |
of/promtree: make drivers/of/pdt.c no longer sparc-only
Clean up pdt.c:
- make build dependent upon config OF_PROMTREE
- #ifdef out the sparc-specific stuff
- create pdt-specific header
Signed-off-by: Andres Salomon <dilinger@queued.net>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
| -rw-r--r-- | arch/sparc/Kconfig | 1 | ||||
| -rw-r--r-- | arch/sparc/include/asm/prom.h | 5 | ||||
| -rw-r--r-- | arch/sparc/kernel/prom.h | 6 | ||||
| -rw-r--r-- | arch/sparc/kernel/prom_common.c | 10 | ||||
| -rw-r--r-- | drivers/of/Kconfig | 5 | ||||
| -rw-r--r-- | drivers/of/Makefile | 1 | ||||
| -rw-r--r-- | drivers/of/pdt.c | 54 | ||||
| -rw-r--r-- | include/linux/of_pdt.h | 24 |
8 files changed, 81 insertions, 25 deletions
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index 491e9d6de191..a06c9598c2ed 100644 --- a/arch/sparc/Kconfig +++ b/arch/sparc/Kconfig | |||
| @@ -19,6 +19,7 @@ config SPARC | |||
| 19 | bool | 19 | bool |
| 20 | default y | 20 | default y |
| 21 | select OF | 21 | select OF |
| 22 | select OF_PROMTREE | ||
| 22 | select HAVE_IDE | 23 | select HAVE_IDE |
| 23 | select HAVE_OPROFILE | 24 | select HAVE_OPROFILE |
| 24 | select HAVE_ARCH_KGDB if !SMP || SPARC64 | 25 | select HAVE_ARCH_KGDB if !SMP || SPARC64 |
diff --git a/arch/sparc/include/asm/prom.h b/arch/sparc/include/asm/prom.h index 291f12575edd..56bbaadef646 100644 --- a/arch/sparc/include/asm/prom.h +++ b/arch/sparc/include/asm/prom.h | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | * 2 of the License, or (at your option) any later version. | 18 | * 2 of the License, or (at your option) any later version. |
| 19 | */ | 19 | */ |
| 20 | #include <linux/types.h> | 20 | #include <linux/types.h> |
| 21 | #include <linux/of_pdt.h> | ||
| 21 | #include <linux/proc_fs.h> | 22 | #include <linux/proc_fs.h> |
| 22 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
| 23 | #include <asm/atomic.h> | 24 | #include <asm/atomic.h> |
| @@ -67,8 +68,8 @@ extern struct device_node *of_console_device; | |||
| 67 | extern char *of_console_path; | 68 | extern char *of_console_path; |
| 68 | extern char *of_console_options; | 69 | extern char *of_console_options; |
| 69 | 70 | ||
| 70 | extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp); | 71 | extern void irq_trans_init(struct device_node *dp); |
| 71 | extern char *build_full_name(struct device_node *dp); | 72 | extern char *build_path_component(struct device_node *dp); |
| 72 | 73 | ||
| 73 | #endif /* __KERNEL__ */ | 74 | #endif /* __KERNEL__ */ |
| 74 | #endif /* _SPARC_PROM_H */ | 75 | #endif /* _SPARC_PROM_H */ |
diff --git a/arch/sparc/kernel/prom.h b/arch/sparc/kernel/prom.h index eeb04a782ec8..cf5fe1c0b024 100644 --- a/arch/sparc/kernel/prom.h +++ b/arch/sparc/kernel/prom.h | |||
| @@ -4,12 +4,6 @@ | |||
| 4 | #include <linux/spinlock.h> | 4 | #include <linux/spinlock.h> |
| 5 | #include <asm/prom.h> | 5 | #include <asm/prom.h> |
| 6 | 6 | ||
| 7 | extern void * prom_early_alloc(unsigned long size); | ||
| 8 | extern void irq_trans_init(struct device_node *dp); | ||
| 9 | |||
| 10 | extern unsigned int prom_unique_id; | ||
| 11 | |||
| 12 | extern char *build_path_component(struct device_node *dp); | ||
| 13 | extern void of_console_init(void); | 7 | extern void of_console_init(void); |
| 14 | 8 | ||
| 15 | extern unsigned int prom_early_allocated; | 9 | extern unsigned int prom_early_allocated; |
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c index 7b454f6413f7..fe84d56b7c5a 100644 --- a/arch/sparc/kernel/prom_common.c +++ b/arch/sparc/kernel/prom_common.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
| 21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
| 22 | #include <linux/of.h> | 22 | #include <linux/of.h> |
| 23 | #include <linux/of_pdt.h> | ||
| 23 | #include <asm/prom.h> | 24 | #include <asm/prom.h> |
| 24 | #include <asm/oplib.h> | 25 | #include <asm/oplib.h> |
| 25 | #include <asm/leon.h> | 26 | #include <asm/leon.h> |
| @@ -119,4 +120,11 @@ EXPORT_SYMBOL(of_find_in_proplist); | |||
| 119 | 120 | ||
| 120 | unsigned int prom_early_allocated __initdata; | 121 | unsigned int prom_early_allocated __initdata; |
| 121 | 122 | ||
| 122 | #include "../../../drivers/of/pdt.c" | 123 | void __init prom_build_devicetree(void) |
| 124 | { | ||
| 125 | of_pdt_build_devicetree(prom_root_node); | ||
| 126 | of_console_init(); | ||
| 127 | |||
| 128 | pr_info("PROM: Built device tree with %u bytes of memory.\n", | ||
| 129 | prom_early_allocated); | ||
| 130 | } | ||
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 6acbff389ab6..aa675ebd8eb3 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig | |||
| @@ -4,7 +4,7 @@ config DTC | |||
| 4 | config OF | 4 | config OF |
| 5 | bool | 5 | bool |
| 6 | 6 | ||
| 7 | menu "Flattened Device Tree and Open Firmware support" | 7 | menu "Device Tree and Open Firmware support" |
| 8 | depends on OF | 8 | depends on OF |
| 9 | 9 | ||
| 10 | config PROC_DEVICETREE | 10 | config PROC_DEVICETREE |
| @@ -19,6 +19,9 @@ config OF_FLATTREE | |||
| 19 | bool | 19 | bool |
| 20 | select DTC | 20 | select DTC |
| 21 | 21 | ||
| 22 | config OF_PROMTREE | ||
| 23 | bool | ||
| 24 | |||
| 22 | config OF_DYNAMIC | 25 | config OF_DYNAMIC |
| 23 | def_bool y | 26 | def_bool y |
| 24 | depends on PPC_OF | 27 | depends on PPC_OF |
diff --git a/drivers/of/Makefile b/drivers/of/Makefile index 0052c405463a..7888155bea08 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | obj-y = base.o | 1 | obj-y = base.o |
| 2 | obj-$(CONFIG_OF_FLATTREE) += fdt.o | 2 | obj-$(CONFIG_OF_FLATTREE) += fdt.o |
| 3 | obj-$(CONFIG_OF_PROMTREE) += pdt.o | ||
| 3 | obj-$(CONFIG_OF_ADDRESS) += address.o | 4 | obj-$(CONFIG_OF_ADDRESS) += address.o |
| 4 | obj-$(CONFIG_OF_IRQ) += irq.o | 5 | obj-$(CONFIG_OF_IRQ) += irq.o |
| 5 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o | 6 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o |
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c index c3c2d70b3f75..2fdb1b478d6f 100644 --- a/drivers/of/pdt.c +++ b/drivers/of/pdt.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* prom_common.c: OF device tree support common code. | 1 | /* pdt.c: OF PROM device tree support code. |
| 2 | * | 2 | * |
| 3 | * Paul Mackerras August 1996. | 3 | * Paul Mackerras August 1996. |
| 4 | * Copyright (C) 1996-2005 Paul Mackerras. | 4 | * Copyright (C) 1996-2005 Paul Mackerras. |
| @@ -7,6 +7,7 @@ | |||
| 7 | * {engebret|bergner}@us.ibm.com | 7 | * {engebret|bergner}@us.ibm.com |
| 8 | * | 8 | * |
| 9 | * Adapted for sparc by David S. Miller davem@davemloft.net | 9 | * Adapted for sparc by David S. Miller davem@davemloft.net |
| 10 | * Adapted for multiple architectures by Andres Salomon <dilinger@queued.net> | ||
| 10 | * | 11 | * |
| 11 | * This program is free software; you can redistribute it and/or | 12 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License | 13 | * modify it under the terms of the GNU General Public License |
| @@ -20,13 +21,36 @@ | |||
| 20 | #include <linux/mutex.h> | 21 | #include <linux/mutex.h> |
| 21 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
| 22 | #include <linux/of.h> | 23 | #include <linux/of.h> |
| 24 | #include <linux/of_pdt.h> | ||
| 23 | #include <asm/prom.h> | 25 | #include <asm/prom.h> |
| 24 | #include <asm/oplib.h> | 26 | #include <asm/oplib.h> |
| 25 | #include <asm/leon.h> | ||
| 26 | 27 | ||
| 27 | void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp); | 28 | void __initdata (*prom_build_more)(struct device_node *dp, |
| 29 | struct device_node ***nextp); | ||
| 28 | 30 | ||
| 29 | unsigned int prom_unique_id; | 31 | #if defined(CONFIG_SPARC) |
| 32 | unsigned int of_pdt_unique_id __initdata; | ||
| 33 | |||
| 34 | #define of_pdt_incr_unique_id(p) do { \ | ||
| 35 | (p)->unique_id = of_pdt_unique_id++; \ | ||
| 36 | } while (0) | ||
| 37 | |||
| 38 | static inline const char *of_pdt_node_name(struct device_node *dp) | ||
| 39 | { | ||
| 40 | return dp->path_component_name; | ||
| 41 | } | ||
| 42 | |||
| 43 | #else | ||
| 44 | |||
| 45 | static inline void of_pdt_incr_unique_id(void *p) { } | ||
| 46 | static inline void irq_trans_init(struct device_node *dp) { } | ||
| 47 | |||
| 48 | static inline const char *of_pdt_node_name(struct device_node *dp) | ||
| 49 | { | ||
| 50 | return dp->name; | ||
| 51 | } | ||
| 52 | |||
| 53 | #endif /* !CONFIG_SPARC */ | ||
| 30 | 54 | ||
| 31 | static struct property * __init build_one_prop(phandle node, char *prev, | 55 | static struct property * __init build_one_prop(phandle node, char *prev, |
| 32 | char *special_name, | 56 | char *special_name, |
| @@ -43,7 +67,7 @@ static struct property * __init build_one_prop(phandle node, char *prev, | |||
| 43 | tmp = NULL; | 67 | tmp = NULL; |
| 44 | } else { | 68 | } else { |
| 45 | p = prom_early_alloc(sizeof(struct property) + 32); | 69 | p = prom_early_alloc(sizeof(struct property) + 32); |
| 46 | p->unique_id = prom_unique_id++; | 70 | of_pdt_incr_unique_id(p); |
| 47 | } | 71 | } |
| 48 | 72 | ||
| 49 | p->name = (char *) (p + 1); | 73 | p->name = (char *) (p + 1); |
| @@ -124,7 +148,7 @@ static struct device_node * __init prom_create_node(phandle node, | |||
| 124 | return NULL; | 148 | return NULL; |
| 125 | 149 | ||
| 126 | dp = prom_early_alloc(sizeof(*dp)); | 150 | dp = prom_early_alloc(sizeof(*dp)); |
| 127 | dp->unique_id = prom_unique_id++; | 151 | of_pdt_incr_unique_id(dp); |
| 128 | dp->parent = parent; | 152 | dp->parent = parent; |
| 129 | 153 | ||
| 130 | kref_init(&dp->kref); | 154 | kref_init(&dp->kref); |
| @@ -140,13 +164,13 @@ static struct device_node * __init prom_create_node(phandle node, | |||
| 140 | return dp; | 164 | return dp; |
| 141 | } | 165 | } |
| 142 | 166 | ||
| 143 | char * __init build_full_name(struct device_node *dp) | 167 | static char * __init build_full_name(struct device_node *dp) |
| 144 | { | 168 | { |
| 145 | int len, ourlen, plen; | 169 | int len, ourlen, plen; |
| 146 | char *n; | 170 | char *n; |
| 147 | 171 | ||
| 148 | plen = strlen(dp->parent->full_name); | 172 | plen = strlen(dp->parent->full_name); |
| 149 | ourlen = strlen(dp->path_component_name); | 173 | ourlen = strlen(of_pdt_node_name(dp)); |
| 150 | len = ourlen + plen + 2; | 174 | len = ourlen + plen + 2; |
| 151 | 175 | ||
| 152 | n = prom_early_alloc(len); | 176 | n = prom_early_alloc(len); |
| @@ -155,7 +179,7 @@ char * __init build_full_name(struct device_node *dp) | |||
| 155 | strcpy(n + plen, "/"); | 179 | strcpy(n + plen, "/"); |
| 156 | plen++; | 180 | plen++; |
| 157 | } | 181 | } |
| 158 | strcpy(n + plen, dp->path_component_name); | 182 | strcpy(n + plen, of_pdt_node_name(dp)); |
| 159 | 183 | ||
| 160 | return n; | 184 | return n; |
| 161 | } | 185 | } |
| @@ -182,7 +206,9 @@ static struct device_node * __init prom_build_tree(struct device_node *parent, | |||
| 182 | *(*nextp) = dp; | 206 | *(*nextp) = dp; |
| 183 | *nextp = &dp->allnext; | 207 | *nextp = &dp->allnext; |
| 184 | 208 | ||
| 209 | #if defined(CONFIG_SPARC) | ||
| 185 | dp->path_component_name = build_path_component(dp); | 210 | dp->path_component_name = build_path_component(dp); |
| 211 | #endif | ||
| 186 | dp->full_name = build_full_name(dp); | 212 | dp->full_name = build_full_name(dp); |
| 187 | 213 | ||
| 188 | dp->child = prom_build_tree(dp, prom_getchild(node), nextp); | 214 | dp->child = prom_build_tree(dp, prom_getchild(node), nextp); |
| @@ -196,20 +222,18 @@ static struct device_node * __init prom_build_tree(struct device_node *parent, | |||
| 196 | return ret; | 222 | return ret; |
| 197 | } | 223 | } |
| 198 | 224 | ||
| 199 | void __init prom_build_devicetree(void) | 225 | void __init of_pdt_build_devicetree(phandle root_node) |
| 200 | { | 226 | { |
| 201 | struct device_node **nextp; | 227 | struct device_node **nextp; |
| 202 | 228 | ||
| 203 | allnodes = prom_create_node(prom_root_node, NULL); | 229 | allnodes = prom_create_node(root_node, NULL); |
| 230 | #if defined(CONFIG_SPARC) | ||
| 204 | allnodes->path_component_name = ""; | 231 | allnodes->path_component_name = ""; |
| 232 | #endif | ||
| 205 | allnodes->full_name = "/"; | 233 | allnodes->full_name = "/"; |
| 206 | 234 | ||
| 207 | nextp = &allnodes->allnext; | 235 | nextp = &allnodes->allnext; |
| 208 | allnodes->child = prom_build_tree(allnodes, | 236 | allnodes->child = prom_build_tree(allnodes, |
| 209 | prom_getchild(allnodes->phandle), | 237 | prom_getchild(allnodes->phandle), |
| 210 | &nextp); | 238 | &nextp); |
| 211 | of_console_init(); | ||
| 212 | |||
| 213 | printk("PROM: Built device tree with %u bytes of memory.\n", | ||
| 214 | prom_early_allocated); | ||
| 215 | } | 239 | } |
diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h new file mode 100644 index 000000000000..c0a8774e45d0 --- /dev/null +++ b/include/linux/of_pdt.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /* | ||
| 2 | * Definitions for building a device tree by calling into the | ||
| 3 | * Open Firmware PROM. | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010 Andres Salomon <dilinger@queued.net> | ||
| 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 | * as published by the Free Software Foundation; either version | ||
| 10 | * 2 of the License, or (at your option) any later version. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #ifndef _LINUX_OF_PDT_H | ||
| 14 | #define _LINUX_OF_PDT_H | ||
| 15 | |||
| 16 | extern void *prom_early_alloc(unsigned long size); | ||
| 17 | |||
| 18 | /* for building the device tree */ | ||
| 19 | extern void of_pdt_build_devicetree(phandle root_node); | ||
| 20 | |||
| 21 | extern void (*prom_build_more)(struct device_node *dp, | ||
| 22 | struct device_node ***nextp); | ||
| 23 | |||
| 24 | #endif /* _LINUX_OF_PDT_H */ | ||
