Hi,
I'm looking for input on the following patches; they're based upon the
OFW patch that's currently in the x86-tip tree[0], and they've only been
compile tested (on x86 and sparc64). This stuff takes the sparc
device tree creation code and makes it available for multiple
architectures, which OLPC then makes use of to build the tree.
There's still a bunch of little stuff that I need to fix (and of
course, I need to verify that it actually remains compatible w/ the
old promfs code that OLPC's been using[1]).
[0]
http://git.kernel.org/?p=linux/kernel/git/mingo/linux-2.6-x86.git;a=commit;h=fd699c76552bb
[1]
http://dev.laptop.org/git/olpc-2.6/commit/?id=0b9734dc5f0b3d24e8f3dfedaeacb61675c838ff
The arguments passed to OFW shouldn't be modified; update the 'args'
argument of olpc_ofw to reflect this. This saves us some later
casting away of consts.
Signed-off-by: Andres Salomon <[email protected]>
---
arch/x86/include/asm/olpc_ofw.h | 2 +-
arch/x86/kernel/olpc.c | 2 +-
arch/x86/kernel/olpc_ofw.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/olpc_ofw.h b/arch/x86/include/asm/olpc_ofw.h
index 3e63d85..08fde47 100644
--- a/arch/x86/include/asm/olpc_ofw.h
+++ b/arch/x86/include/asm/olpc_ofw.h
@@ -12,7 +12,7 @@
#define olpc_ofw(name, args, res) \
__olpc_ofw((name), ARRAY_SIZE(args), args, ARRAY_SIZE(res), res)
-extern int __olpc_ofw(const char *name, int nr_args, void **args, int nr_res,
+extern int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res,
void **res);
/* determine whether OFW is available and lives in the proper memory */
diff --git a/arch/x86/kernel/olpc.c b/arch/x86/kernel/olpc.c
index f5ff390..0e0cdde 100644
--- a/arch/x86/kernel/olpc.c
+++ b/arch/x86/kernel/olpc.c
@@ -188,7 +188,7 @@ static void __init platform_detect(void)
{
size_t propsize;
__be32 rev;
- void *args[] = { NULL, "board-revision-int", &rev, (void *)4 };
+ const void *args[] = { NULL, "board-revision-int", &rev, (void *)4 };
void *res[] = { &propsize };
if (olpc_ofw("getprop", args, res) || propsize != 4) {
diff --git a/arch/x86/kernel/olpc_ofw.c b/arch/x86/kernel/olpc_ofw.c
index deac703..3e13a4b 100644
--- a/arch/x86/kernel/olpc_ofw.c
+++ b/arch/x86/kernel/olpc_ofw.c
@@ -39,7 +39,7 @@ void __init setup_olpc_ofw_pgd(void)
/* implicit optimization barrier here due to uninline function return */
}
-int __olpc_ofw(const char *name, int nr_args, void **args, int nr_res,
+int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res,
void **res)
{
int ofw_args[MAXARGS + 3];
--
1.5.6.5
Stick code into drivers/of/pdt.c (Prom Device Tree) that other
architectures with OpenFirmware resident in memory can make use of.
Signed-off-by: Andres Salomon <[email protected]>
---
arch/sparc/Kconfig | 1 +
arch/sparc/include/asm/prom.h | 15 +++-
arch/sparc/kernel/prom.h | 14 ---
arch/sparc/kernel/prom_common.c | 173 +------------------------------
drivers/of/Kconfig | 4 +
drivers/of/Makefile | 1 +
drivers/of/pdt.c | 225 +++++++++++++++++++++++++++++++++++++++
include/linux/of_pdt.h | 37 +++++++
8 files changed, 282 insertions(+), 188 deletions(-)
create mode 100644 drivers/of/pdt.c
create mode 100644 include/linux/of_pdt.h
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 6f1470b..b4cb63b 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUS
config OF
def_bool y
+ select OF_PROMTREE
config ARCH_SUPPORTS_DEBUG_PAGEALLOC
def_bool y if SPARC64
diff --git a/arch/sparc/include/asm/prom.h b/arch/sparc/include/asm/prom.h
index f845828..0834c2a 100644
--- a/arch/sparc/include/asm/prom.h
+++ b/arch/sparc/include/asm/prom.h
@@ -18,6 +18,7 @@
* 2 of the License, or (at your option) any later version.
*/
#include <linux/types.h>
+#include <linux/of_pdt.h>
#include <linux/proc_fs.h>
#include <linux/mutex.h>
#include <asm/atomic.h>
@@ -65,8 +66,18 @@ extern struct device_node *of_console_device;
extern char *of_console_path;
extern char *of_console_options;
-extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
-extern char *build_full_name(struct device_node *dp);
+/* stuff used by of/pdt */
+extern void * prom_early_alloc(unsigned long size);
+extern void irq_trans_init(struct device_node *dp);
+extern char *build_path_component(struct device_node *dp);
+
+extern char *prom_firstprop(int node, char *buffer);
+extern char *prom_nextprop(int node, const char *oprop, char *buffer);
+extern int prom_getproplen(int node, const char *prop);
+extern int prom_getproperty(int node, const char *prop,
+ char *buffer, int bufsize);
+extern int prom_getchild(int node);
+extern int prom_getsibling(int node);
#endif /* __KERNEL__ */
#endif /* _SPARC_PROM_H */
diff --git a/arch/sparc/kernel/prom.h b/arch/sparc/kernel/prom.h
index a8591ef..cf5fe1c 100644
--- a/arch/sparc/kernel/prom.h
+++ b/arch/sparc/kernel/prom.h
@@ -4,20 +4,6 @@
#include <linux/spinlock.h>
#include <asm/prom.h>
-extern void * prom_early_alloc(unsigned long size);
-extern void irq_trans_init(struct device_node *dp);
-
-extern unsigned int prom_unique_id;
-
-static inline int is_root_node(const struct device_node *dp)
-{
- if (!dp)
- return 0;
-
- return (dp->parent == NULL);
-}
-
-extern char *build_path_component(struct device_node *dp);
extern void of_console_init(void);
extern unsigned int prom_early_allocated;
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
index 57ac9e2..fc990e1 100644
--- a/arch/sparc/kernel/prom_common.c
+++ b/arch/sparc/kernel/prom_common.c
@@ -20,14 +20,13 @@
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/of.h>
+#include <linux/of_pdt.h>
#include <asm/prom.h>
#include <asm/oplib.h>
#include <asm/leon.h>
#include "prom.h"
-void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
-
struct device_node *of_console_device;
EXPORT_SYMBOL(of_console_device);
@@ -119,176 +118,6 @@ int of_find_in_proplist(const char *list, const char *match, int len)
}
EXPORT_SYMBOL(of_find_in_proplist);
-unsigned int prom_unique_id;
-
-static struct property * __init build_one_prop(phandle node, char *prev,
- char *special_name,
- void *special_val,
- int special_len)
-{
- static struct property *tmp = NULL;
- struct property *p;
- const char *name;
-
- if (tmp) {
- p = tmp;
- memset(p, 0, sizeof(*p) + 32);
- tmp = NULL;
- } else {
- p = prom_early_alloc(sizeof(struct property) + 32);
- p->unique_id = prom_unique_id++;
- }
-
- p->name = (char *) (p + 1);
- if (special_name) {
- strcpy(p->name, special_name);
- p->length = special_len;
- p->value = prom_early_alloc(special_len);
- memcpy(p->value, special_val, special_len);
- } else {
- if (prev == NULL) {
- name = prom_firstprop(node, p->name);
- } else {
- name = prom_nextprop(node, prev, p->name);
- }
-
- if (!name || strlen(name) == 0) {
- tmp = p;
- return NULL;
- }
-#ifdef CONFIG_SPARC32
- strcpy(p->name, name);
-#endif
- p->length = prom_getproplen(node, p->name);
- if (p->length <= 0) {
- p->length = 0;
- } else {
- int len;
-
- p->value = prom_early_alloc(p->length + 1);
- len = prom_getproperty(node, p->name, p->value,
- p->length);
- if (len <= 0)
- p->length = 0;
- ((unsigned char *)p->value)[p->length] = '\0';
- }
- }
- return p;
-}
-
-static struct property * __init build_prop_list(phandle node)
-{
- struct property *head, *tail;
-
- head = tail = build_one_prop(node, NULL,
- ".node", &node, sizeof(node));
-
- tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
- tail = tail->next;
- while(tail) {
- tail->next = build_one_prop(node, tail->name,
- NULL, NULL, 0);
- tail = tail->next;
- }
-
- return head;
-}
-
-static char * __init get_one_property(phandle node, const char *name)
-{
- char *buf = "<NULL>";
- int len;
-
- len = prom_getproplen(node, name);
- if (len > 0) {
- buf = prom_early_alloc(len);
- len = prom_getproperty(node, name, buf, len);
- }
-
- return buf;
-}
-
-static struct device_node * __init prom_create_node(phandle node,
- struct device_node *parent)
-{
- struct device_node *dp;
-
- if (!node)
- return NULL;
-
- dp = prom_early_alloc(sizeof(*dp));
- dp->unique_id = prom_unique_id++;
- dp->parent = parent;
-
- kref_init(&dp->kref);
-
- dp->name = get_one_property(node, "name");
- dp->type = get_one_property(node, "device_type");
- dp->phandle = node;
-
- dp->properties = build_prop_list(node);
-
- irq_trans_init(dp);
-
- return dp;
-}
-
-char * __init build_full_name(struct device_node *dp)
-{
- int len, ourlen, plen;
- char *n;
-
- plen = strlen(dp->parent->full_name);
- ourlen = strlen(dp->path_component_name);
- len = ourlen + plen + 2;
-
- n = prom_early_alloc(len);
- strcpy(n, dp->parent->full_name);
- if (!is_root_node(dp->parent)) {
- strcpy(n + plen, "/");
- plen++;
- }
- strcpy(n + plen, dp->path_component_name);
-
- return n;
-}
-
-static struct device_node * __init prom_build_tree(struct device_node *parent,
- phandle node,
- struct device_node ***nextp)
-{
- struct device_node *ret = NULL, *prev_sibling = NULL;
- struct device_node *dp;
-
- while (1) {
- dp = prom_create_node(node, parent);
- if (!dp)
- break;
-
- if (prev_sibling)
- prev_sibling->sibling = dp;
-
- if (!ret)
- ret = dp;
- prev_sibling = dp;
-
- *(*nextp) = dp;
- *nextp = &dp->allnext;
-
- dp->path_component_name = build_path_component(dp);
- dp->full_name = build_full_name(dp);
-
- dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
-
- if (prom_build_more)
- prom_build_more(dp, nextp);
-
- node = prom_getsibling(node);
- }
-
- return ret;
-}
-
unsigned int prom_early_allocated __initdata;
void __init prom_build_devicetree(void)
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 7cecc8f..41921a8 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -2,6 +2,10 @@ config OF_FLATTREE
bool
depends on OF
+config OF_PROMTREE
+ bool
+ depends on OF
+
config OF_DYNAMIC
def_bool y
depends on OF && PPC_OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index f232cc9..54e8517 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,5 +1,6 @@
obj-y = base.o
obj-$(CONFIG_OF_FLATTREE) += fdt.o
+obj-$(CONFIG_OF_PROMTREE) += pdt.o
obj-$(CONFIG_OF_DEVICE) += device.o platform.o
obj-$(CONFIG_OF_GPIO) += gpio.o
obj-$(CONFIG_OF_I2C) += of_i2c.o
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
new file mode 100644
index 0000000..b24167f
--- /dev/null
+++ b/drivers/of/pdt.c
@@ -0,0 +1,225 @@
+/*
+ * Paul Mackerras August 1996.
+ * Copyright (C) 1996-2005 Paul Mackerras.
+ *
+ * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
+ * {engebret|bergner}@us.ibm.com
+ *
+ * Adapted for sparc by David S. Miller [email protected]
+ * Adapted for multiple architectures by Andres Salomon <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_pdt.h>
+#include <asm/prom.h>
+
+/* TODO: mark this stuff as __initdata */
+void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
+
+#if defined(CONFIG_SPARC)
+static unsigned int prom_unique_id;
+
+#define inc_unique_id(p) do { \
+ (p)->unique_id = prom_unique_id++; \
+} while (0)
+
+static inline const char *fetch_node_name(struct device_node *dp)
+{
+ return dp->path_component_name;
+}
+
+#else
+
+#define inc_unique_id(p) do { } while(0)
+
+static inline const char *fetch_node_name(struct device_node *dp)
+{
+ return dp->name;
+}
+
+static inline void irq_trans_init(struct device_node *dp)
+{
+ /* unused on non-SPARC architectures */
+}
+
+#endif /* !CONFIG_SPARC */
+
+static struct property * __init build_one_prop(phandle node, char *prev,
+ char *special_name,
+ void *special_val,
+ int special_len)
+{
+ static struct property *tmp = NULL;
+ struct property *p;
+ const char *name;
+
+ if (tmp) {
+ p = tmp;
+ memset(p, 0, sizeof(*p) + 32);
+ tmp = NULL;
+ } else {
+ p = prom_early_alloc(sizeof(struct property) + 32);
+ inc_unique_id(p);
+ }
+
+ p->name = (char *) (p + 1);
+ if (special_name) {
+ strcpy(p->name, special_name);
+ p->length = special_len;
+ p->value = prom_early_alloc(special_len);
+ memcpy(p->value, special_val, special_len);
+ } else {
+ if (prev == NULL) {
+ name = prom_firstprop(node, p->name);
+ } else {
+ name = prom_nextprop(node, prev, p->name);
+ }
+
+ if (!name || strlen(name) == 0) {
+ tmp = p;
+ return NULL;
+ }
+#ifdef CONFIG_SPARC32
+ strcpy(p->name, name);
+#endif
+ p->length = prom_getproplen(node, p->name);
+ if (p->length <= 0) {
+ p->length = 0;
+ } else {
+ int len;
+
+ p->value = prom_early_alloc(p->length + 1);
+ len = prom_getproperty(node, p->name, p->value,
+ p->length);
+ if (len <= 0)
+ p->length = 0;
+ ((unsigned char *)p->value)[p->length] = '\0';
+ }
+ }
+ return p;
+}
+
+static struct property * __init build_prop_list(phandle node)
+{
+ struct property *head, *tail;
+
+ head = tail = build_one_prop(node, NULL,
+ ".node", &node, sizeof(node));
+
+ tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
+ tail = tail->next;
+ while(tail) {
+ tail->next = build_one_prop(node, tail->name,
+ NULL, NULL, 0);
+ tail = tail->next;
+ }
+
+ return head;
+}
+
+static char * __init get_one_property(phandle node, const char *name)
+{
+ char *buf = "<NULL>";
+ int len;
+
+ len = prom_getproplen(node, name);
+ if (len > 0) {
+ buf = prom_early_alloc(len);
+ len = prom_getproperty(node, name, buf, len);
+ }
+
+ return buf;
+}
+
+struct device_node * __init prom_create_node(phandle node,
+ struct device_node *parent)
+{
+ struct device_node *dp;
+
+ if (!node)
+ return NULL;
+
+ dp = prom_early_alloc(sizeof(*dp));
+ inc_unique_id(dp);
+ dp->parent = parent;
+
+ kref_init(&dp->kref);
+
+ dp->name = get_one_property(node, "name");
+ dp->type = get_one_property(node, "device_type");
+ dp->phandle = node;
+
+ dp->properties = build_prop_list(node);
+
+ irq_trans_init(dp);
+
+ return dp;
+}
+
+static char * __init build_full_name(struct device_node *dp)
+{
+ int len, ourlen, plen;
+ char *n;
+
+ plen = strlen(dp->parent->full_name);
+ ourlen = strlen(fetch_node_name(dp));
+ len = ourlen + plen + 2;
+
+ n = prom_early_alloc(len);
+ strcpy(n, dp->parent->full_name);
+ if (!is_root_node(dp->parent)) {
+ strcpy(n + plen, "/");
+ plen++;
+ }
+ strcpy(n + plen, fetch_node_name(dp));
+
+ return n;
+}
+
+struct device_node * __init prom_build_tree(struct device_node *parent,
+ phandle node,
+ struct device_node ***nextp)
+{
+ struct device_node *ret = NULL, *prev_sibling = NULL;
+ struct device_node *dp;
+
+ while (1) {
+ dp = prom_create_node(node, parent);
+ if (!dp)
+ break;
+
+ if (prev_sibling)
+ prev_sibling->sibling = dp;
+
+ if (!ret)
+ ret = dp;
+ prev_sibling = dp;
+
+ *(*nextp) = dp;
+ *nextp = &dp->allnext;
+
+#if defined(CONFIG_SPARC)
+ dp->path_component_name = build_path_component(dp);
+#endif
+ dp->full_name = build_full_name(dp);
+
+ dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
+
+ if (prom_build_more)
+ prom_build_more(dp, nextp);
+
+ node = prom_getsibling(node);
+ }
+
+ return ret;
+}
diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
new file mode 100644
index 0000000..f62616e
--- /dev/null
+++ b/include/linux/of_pdt.h
@@ -0,0 +1,37 @@
+#include <linux/of.h> /* linux/of.h gets to determine #include ordering */
+/*
+ * Definitions for building a device tree by calling into the
+ * Open Firmware PROM.
+ *
+ * Copyright (C) 1996-2005 Paul Mackerras.
+ * Copyright (C) 2010 Andres Salomon <[email protected]>
+ *
+ * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
+ * Updates for SPARC by David S. Miller
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_OF_PDT_H
+#define _LINUX_OF_PDT_H
+
+extern struct device_node *prom_create_node(phandle node,
+ struct device_node *parent);
+extern struct device_node *prom_build_tree(struct device_node *parent,
+ phandle node,
+ struct device_node ***nextp);
+
+extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
+
+static inline int is_root_node(const struct device_node *dp)
+{
+ if (!dp)
+ return 0;
+
+ return (dp->parent == NULL);
+}
+
+#endif /* _LINUX_OF_PDT_H */
--
1.5.6.5
Microblaze and PPC both use PROC_DEVICETREE, and OLPC will as well.. put
the Kconfig option into fs/ rather than in arch/*/Kconfig.
Signed-off-by: Andres Salomon <[email protected]>
---
arch/microblaze/Kconfig | 8 --------
arch/powerpc/Kconfig | 8 --------
fs/proc/Kconfig | 8 ++++++++
3 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig
index 76818f9..b66c962 100644
--- a/arch/microblaze/Kconfig
+++ b/arch/microblaze/Kconfig
@@ -128,14 +128,6 @@ config OF
def_bool y
select OF_FLATTREE
-config PROC_DEVICETREE
- bool "Support for device tree in /proc"
- depends on PROC_FS
- help
- This option adds a device-tree directory under /proc which contains
- an image of the device tree that the kernel copies from Open
- Firmware or other boot firmware. If unsure, say Y here.
-
endmenu
menu "Advanced setup"
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 328774b..8a56e8b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -578,14 +578,6 @@ config SCHED_SMT
when dealing with POWER5 cpus at a cost of slightly increased
overhead in some places. If unsure say N here.
-config PROC_DEVICETREE
- bool "Support for device tree in /proc"
- depends on PROC_FS
- help
- This option adds a device-tree directory under /proc which contains
- an image of the device tree that the kernel copies from Open
- Firmware or other boot firmware. If unsure, say Y here.
-
config CMDLINE_BOOL
bool "Default bootloader kernel arguments"
diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
index 50f8f06..858a859 100644
--- a/fs/proc/Kconfig
+++ b/fs/proc/Kconfig
@@ -39,6 +39,14 @@ config PROC_VMCORE
help
Exports the dump image of crashed kernel in ELF format.
+config PROC_DEVICETREE
+ bool "Support for device tree in /proc"
+ depends on PROC_FS && (PPC || MICROBLAZE)
+ help
+ This option adds a device-tree directory under /proc which contains
+ an image of the device tree that the kernel copies from Open
+ Firmware or other boot firmware. If unsure, say Y here.
+
config PROC_SYSCTL
bool "Sysctl support (/proc/sys)" if EMBEDDED
depends on PROC_FS
--
1.5.6.5
Make use of PROC_DEVICETREE to export the tree, and sparc's PROMTREE code to
call into OLPC's Open Firmware to build the tree.
(Yes, I know this leaks memory by simply using kmalloc)
Signed-off-by: Andres Salomon <[email protected]>
---
arch/x86/Kconfig | 5 ++
arch/x86/include/asm/olpc_prom.h | 42 +++++++++++
arch/x86/include/asm/prom.h | 5 ++
arch/x86/kernel/Makefile | 1 +
arch/x86/kernel/olpc_ofw.c | 13 ++++
arch/x86/kernel/olpc_prom.c | 148 ++++++++++++++++++++++++++++++++++++++
fs/proc/Kconfig | 2 +-
7 files changed, 215 insertions(+), 1 deletions(-)
create mode 100644 arch/x86/include/asm/olpc_prom.h
create mode 100644 arch/x86/include/asm/prom.h
create mode 100644 arch/x86/kernel/olpc_prom.c
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 71c194d..7aea004 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWARE
that is used on the OLPC XO-1 Children's Machine.
If unsure, say N here.
+config OF
+ def_bool y
+ depends on OLPC_OPENFIRMWARE
+ select OF_PROMTREE
+
endif # X86_32
config K8_NB
diff --git a/arch/x86/include/asm/olpc_prom.h b/arch/x86/include/asm/olpc_prom.h
new file mode 100644
index 0000000..96cdcee
--- /dev/null
+++ b/arch/x86/include/asm/olpc_prom.h
@@ -0,0 +1,42 @@
+#include <linux/of.h> /* linux/of.h gets to determine #include ordering */
+/*
+ * Definitions for talking to the Open Firmware PROM on
+ * Power Macintosh computers.
+ *
+ * Copyright (C) 1996-2005 Paul Mackerras.
+ *
+ * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
+ * Updates for SPARC by David S. Miller
+ * Updates for x86/OLPC by Andres Salomon
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _X86_PROM_OLPC_H
+#define _X86_PROM_OLPC_H
+#ifdef __KERNEL__
+
+#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
+#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
+
+#define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l))
+#define of_prop_cmp(s1, s2) strcasecmp((s1), (s2))
+#define of_node_cmp(s1, s2) strcmp((s1), (s2))
+
+extern void prom_build_devicetree(void);
+
+extern void *prom_early_alloc(unsigned long size);
+
+extern char *prom_firstprop(phandle node, char *buf);
+extern char *prom_nextprop(phandle node, const char *prev, char *buf);
+extern int prom_getproplen(phandle node, const char *prop);
+extern int prom_getproperty(phandle node, const char *prop,
+ char *buffer, int bufsize);
+extern phandle prom_getchild(phandle node);
+extern phandle prom_getsibling(phandle node);
+
+#endif /* __KERNEL__ */
+#endif /* _X86_PROM_OLPC_H */
diff --git a/arch/x86/include/asm/prom.h b/arch/x86/include/asm/prom.h
new file mode 100644
index 0000000..7b561b2
--- /dev/null
+++ b/arch/x86/include/asm/prom.h
@@ -0,0 +1,5 @@
+#ifdef CONFIG_OLPC_OPENFIRMWARE
+# include <asm/olpc_prom.h>
+#else
+# error "No OFW prom defined for x86!"
+#endif
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 0925676..3d7e535 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -105,6 +105,7 @@ scx200-y += scx200_32.o
obj-$(CONFIG_OLPC) += olpc.o
obj-$(CONFIG_OLPC_OPENFIRMWARE) += olpc_ofw.o
+obj-$(CONFIG_PROC_DEVICETREE) += olpc_prom.o
obj-$(CONFIG_X86_MRST) += mrst.o
microcode-y := microcode_core.o
diff --git a/arch/x86/kernel/olpc_ofw.c b/arch/x86/kernel/olpc_ofw.c
index 3e13a4b..8838edb 100644
--- a/arch/x86/kernel/olpc_ofw.c
+++ b/arch/x86/kernel/olpc_ofw.c
@@ -6,6 +6,7 @@
#include <asm/io.h>
#include <asm/pgtable.h>
#include <asm/olpc_ofw.h>
+#include <asm/prom.h>
/* address of OFW callback interface; will be NULL if OFW isn't found */
static int (*olpc_ofw_cif)(int *);
@@ -103,3 +104,15 @@ void __init olpc_ofw_detect(void)
(unsigned long)olpc_ofw_cif, (-start) >> 20);
reserve_top_address(-start);
}
+
+#ifdef CONFIG_PROC_DEVICETREE
+static int __init olpc_ofw_build_devicetree(void)
+{
+ /* initialize the device-tree that proc uses */
+ if (olpc_ofw_cif)
+ prom_build_devicetree();
+
+ return 0;
+}
+arch_initcall(olpc_ofw_build_devicetree);
+#endif /* CONFIG_PROC_DEVICETREE */
diff --git a/arch/x86/kernel/olpc_prom.c b/arch/x86/kernel/olpc_prom.c
new file mode 100644
index 0000000..1128f3f
--- /dev/null
+++ b/arch/x86/kernel/olpc_prom.c
@@ -0,0 +1,148 @@
+/*
+ * olpc_prom.c: OLPC-specific OFW device tree support code.
+ *
+ * Paul Mackerras August 1996.
+ * Copyright (C) 1996-2005 Paul Mackerras.
+ *
+ * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
+ * {engebret|bergner}@us.ibm.com
+ *
+ * Adapted for sparc by David S. Miller [email protected]
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_pdt.h>
+#include <asm/olpc_ofw.h>
+#include <asm/prom.h>
+
+phandle prom_getsibling(phandle node)
+{
+ const void *args[] = { (void *)node };
+ void *res[] = { &node };
+
+ if (node == -1)
+ return -1;
+
+ if (olpc_ofw("peer", args, res) || node == -1)
+ return -1;
+
+ return node;
+}
+
+phandle prom_getchild(phandle node)
+{
+ const void *args[] = { (void *)node };
+ void *res[] = { &node };
+
+ if (node == -1)
+ return 0;
+
+ if (olpc_ofw("child", args, res) || node == -1) {
+ printk(KERN_ERR "PROM: %s: fetching child failed!\n", __func__);
+ return 0;
+ }
+
+ return node;
+}
+
+int prom_getproplen(phandle node, const char *prop)
+{
+ const void *args[] = { (void *)node, prop };
+ int len;
+ void *res[] = { &len };
+
+ if (node == -1)
+ return 0;
+
+ if (olpc_ofw("getproplen", args, res)) {
+ printk(KERN_ERR "PROM: %s: getproplen failed!\n", __func__);
+ return 0;
+ }
+
+ return len;
+}
+
+int prom_getproperty(phandle node, const char *prop, char *buf,
+ int bufsize)
+{
+ int plen;
+
+ plen = prom_getproplen(node, prop);
+ if (plen > bufsize || plen < 1)
+ return -1;
+ else {
+ const void *args[] = { (void *)node, prop, buf, (void *)plen };
+ void *res[] = { &plen };
+
+ if (olpc_ofw("getprop", args, res)) {
+ printk(KERN_ERR "PROM: %s: getprop failed!\n", __func__);
+ return -1;
+ }
+ //((unsigned char *)buf)[plen] = '\0';
+ }
+
+ return 0;
+}
+
+char *prom_firstprop(phandle node, char *buf)
+{
+ buf[0] = '\0';
+
+ if (node == -1)
+ return NULL;
+
+ return prom_nextprop(node, "", buf);
+}
+
+char *prom_nextprop(phandle node, const char *prev, char *buf)
+{
+ const void *args[] = { (void *)node, prev, buf };
+ int success;
+ void *res[] = { &success };
+
+ buf[0] = '\0';
+
+ if (node == -1)
+ return NULL;
+
+ if (olpc_ofw("nextprop", args, res) || success != 1) {
+ printk(KERN_ERR "PROM: %s: nextprop failed!\n", __func__);
+ return NULL;
+ }
+
+ return buf;
+}
+
+void * __init prom_early_alloc(unsigned long size)
+{
+ /* unlike SPARC, we don't bother keeping track of prom memory */
+ return kzalloc(size, GFP_KERNEL);
+}
+
+void __init prom_build_devicetree(void)
+{
+ struct device_node **nextp;
+ phandle root;
+
+ root = prom_getsibling(0);
+ if (root < 0) {
+ printk(KERN_ERR "PROM: unable to get root node from OFW!\n");
+ return;
+ }
+
+ allnodes = prom_create_node(root, NULL);
+ allnodes->full_name = "/";
+
+ nextp = &allnodes->allnext;
+ allnodes->child = prom_build_tree(allnodes,
+ prom_getchild(allnodes->phandle), &nextp);
+}
diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
index 858a859..86f67ce 100644
--- a/fs/proc/Kconfig
+++ b/fs/proc/Kconfig
@@ -41,7 +41,7 @@ config PROC_VMCORE
config PROC_DEVICETREE
bool "Support for device tree in /proc"
- depends on PROC_FS && (PPC || MICROBLAZE)
+ depends on PROC_FS && (PPC || MICROBLAZE || OLPC_OPENFIRMWARE)
help
This option adds a device-tree directory under /proc which contains
an image of the device tree that the kernel copies from Open
--
1.5.6.5
From: Andres Salomon <[email protected]>
Date: Mon, 28 Jun 2010 22:00:37 -0400
>
> Stick code into drivers/of/pdt.c (Prom Device Tree) that other
> architectures with OpenFirmware resident in memory can make use of.
>
> Signed-off-by: Andres Salomon <[email protected]>
Acked-by: David S. Miller <[email protected]>
Hi Andres,
On Mon, 28 Jun 2010 22:00:37 -0400 Andres Salomon <[email protected]> wrote:
>
> diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
> index 6f1470b..b4cb63b 100644
> --- a/arch/sparc/Kconfig
> +++ b/arch/sparc/Kconfig
> @@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUS
>
> config OF
> def_bool y
> + select OF_PROMTREE
Please put this select in CONFIG_SPARC instead as we want to move
CONFIG_OF to drivers/og/Kconfig
--
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/
On Mon, Jun 28, 2010 at 7:00 PM, Andres Salomon <[email protected]> wrote:
>
> Microblaze and PPC both use PROC_DEVICETREE, and OLPC will as well.. put
> the Kconfig option into fs/ rather than in arch/*/Kconfig.
>
> Signed-off-by: Andres Salomon <[email protected]>
> ---
> ?arch/microblaze/Kconfig | ? ?8 --------
> ?arch/powerpc/Kconfig ? ?| ? ?8 --------
> ?fs/proc/Kconfig ? ? ? ? | ? ?8 ++++++++
> ?3 files changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig
> index 76818f9..b66c962 100644
> --- a/arch/microblaze/Kconfig
> +++ b/arch/microblaze/Kconfig
> @@ -128,14 +128,6 @@ config OF
> ? ? ? ?def_bool y
> ? ? ? ?select OF_FLATTREE
>
> -config PROC_DEVICETREE
> - ? ? ? bool "Support for device tree in /proc"
> - ? ? ? depends on PROC_FS
> - ? ? ? help
> - ? ? ? ? This option adds a device-tree directory under /proc which contains
> - ? ? ? ? an image of the device tree that the kernel copies from Open
> - ? ? ? ? Firmware or other boot firmware. If unsure, say Y here.
> -
> ?endmenu
>
> ?menu "Advanced setup"
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 328774b..8a56e8b 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -578,14 +578,6 @@ config SCHED_SMT
> ? ? ? ? ?when dealing with POWER5 cpus at a cost of slightly increased
> ? ? ? ? ?overhead in some places. If unsure say N here.
>
> -config PROC_DEVICETREE
> - ? ? ? bool "Support for device tree in /proc"
> - ? ? ? depends on PROC_FS
> - ? ? ? help
> - ? ? ? ? This option adds a device-tree directory under /proc which contains
> - ? ? ? ? an image of the device tree that the kernel copies from Open
> - ? ? ? ? Firmware or other boot firmware. If unsure, say Y here.
> -
> ?config CMDLINE_BOOL
> ? ? ? ?bool "Default bootloader kernel arguments"
>
> diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
> index 50f8f06..858a859 100644
> --- a/fs/proc/Kconfig
> +++ b/fs/proc/Kconfig
> @@ -39,6 +39,14 @@ config PROC_VMCORE
> ? ? ? ? help
> ? ? ? ? Exports the dump image of crashed kernel in ELF format.
>
> +config PROC_DEVICETREE
> + ? ? ? bool "Support for device tree in /proc"
> + ? ? ? depends on PROC_FS && (PPC || MICROBLAZE)
> + ? ? ? help
> + ? ? ? ? This option adds a device-tree directory under /proc which contains
> + ? ? ? ? an image of the device tree that the kernel copies from Open
> + ? ? ? ? Firmware or other boot firmware. If unsure, say Y here.
> +
Looks good to me. However, I've changed the depends line to the following.
depends on PROC_FS && OF && !SPARC
Cheers,
g.
On Mon, Jun 28, 2010 at 7:00 PM, Andres Salomon <[email protected]> wrote:
>
> Stick code into drivers/of/pdt.c (Prom Device Tree) that other
> architectures with OpenFirmware resident in memory can make use of.
>
> Signed-off-by: Andres Salomon <[email protected]>
Hi Andres,
The patch itself looks fine, but there are currently two methods for
extracting the device tree from open firmware; one in arch/powerpc
using the flattened format, and one in arch/sparc. I don't want to
end up maintaining both methods in drivers/of, and there has also some
discussions on moving the powerpc version into common code. I've been
thinking about using the powerpc approach to support ARM platforms
using both the flat tree and real OFW.
Ben, what say you? Before I do anything I'd like to have your opinion.
Cheers,
g.
> ---
> ?arch/sparc/Kconfig ? ? ? ? ? ? ?| ? ?1 +
> ?arch/sparc/include/asm/prom.h ? | ? 15 +++-
> ?arch/sparc/kernel/prom.h ? ? ? ?| ? 14 ---
> ?arch/sparc/kernel/prom_common.c | ?173 +------------------------------
> ?drivers/of/Kconfig ? ? ? ? ? ? ?| ? ?4 +
> ?drivers/of/Makefile ? ? ? ? ? ? | ? ?1 +
> ?drivers/of/pdt.c ? ? ? ? ? ? ? ?| ?225 +++++++++++++++++++++++++++++++++++++++
> ?include/linux/of_pdt.h ? ? ? ? ?| ? 37 +++++++
> ?8 files changed, 282 insertions(+), 188 deletions(-)
> ?create mode 100644 drivers/of/pdt.c
> ?create mode 100644 include/linux/of_pdt.h
>
> diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
> index 6f1470b..b4cb63b 100644
> --- a/arch/sparc/Kconfig
> +++ b/arch/sparc/Kconfig
> @@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUS
>
> ?config OF
> ? ? ? ?def_bool y
> + ? ? ? select OF_PROMTREE
>
> ?config ARCH_SUPPORTS_DEBUG_PAGEALLOC
> ? ? ? ?def_bool y if SPARC64
> diff --git a/arch/sparc/include/asm/prom.h b/arch/sparc/include/asm/prom.h
> index f845828..0834c2a 100644
> --- a/arch/sparc/include/asm/prom.h
> +++ b/arch/sparc/include/asm/prom.h
> @@ -18,6 +18,7 @@
> ?* 2 of the License, or (at your option) any later version.
> ?*/
> ?#include <linux/types.h>
> +#include <linux/of_pdt.h>
> ?#include <linux/proc_fs.h>
> ?#include <linux/mutex.h>
> ?#include <asm/atomic.h>
> @@ -65,8 +66,18 @@ extern struct device_node *of_console_device;
> ?extern char *of_console_path;
> ?extern char *of_console_options;
>
> -extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
> -extern char *build_full_name(struct device_node *dp);
> +/* stuff used by of/pdt */
> +extern void * prom_early_alloc(unsigned long size);
> +extern void irq_trans_init(struct device_node *dp);
> +extern char *build_path_component(struct device_node *dp);
> +
> +extern char *prom_firstprop(int node, char *buffer);
> +extern char *prom_nextprop(int node, const char *oprop, char *buffer);
> +extern int prom_getproplen(int node, const char *prop);
> +extern int prom_getproperty(int node, const char *prop,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? char *buffer, int bufsize);
> +extern int prom_getchild(int node);
> +extern int prom_getsibling(int node);
>
> ?#endif /* __KERNEL__ */
> ?#endif /* _SPARC_PROM_H */
> diff --git a/arch/sparc/kernel/prom.h b/arch/sparc/kernel/prom.h
> index a8591ef..cf5fe1c 100644
> --- a/arch/sparc/kernel/prom.h
> +++ b/arch/sparc/kernel/prom.h
> @@ -4,20 +4,6 @@
> ?#include <linux/spinlock.h>
> ?#include <asm/prom.h>
>
> -extern void * prom_early_alloc(unsigned long size);
> -extern void irq_trans_init(struct device_node *dp);
> -
> -extern unsigned int prom_unique_id;
> -
> -static inline int is_root_node(const struct device_node *dp)
> -{
> - ? ? ? if (!dp)
> - ? ? ? ? ? ? ? return 0;
> -
> - ? ? ? return (dp->parent == NULL);
> -}
> -
> -extern char *build_path_component(struct device_node *dp);
> ?extern void of_console_init(void);
>
> ?extern unsigned int prom_early_allocated;
> diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
> index 57ac9e2..fc990e1 100644
> --- a/arch/sparc/kernel/prom_common.c
> +++ b/arch/sparc/kernel/prom_common.c
> @@ -20,14 +20,13 @@
> ?#include <linux/mutex.h>
> ?#include <linux/slab.h>
> ?#include <linux/of.h>
> +#include <linux/of_pdt.h>
> ?#include <asm/prom.h>
> ?#include <asm/oplib.h>
> ?#include <asm/leon.h>
>
> ?#include "prom.h"
>
> -void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
> -
> ?struct device_node *of_console_device;
> ?EXPORT_SYMBOL(of_console_device);
>
> @@ -119,176 +118,6 @@ int of_find_in_proplist(const char *list, const char *match, int len)
> ?}
> ?EXPORT_SYMBOL(of_find_in_proplist);
>
> -unsigned int prom_unique_id;
> -
> -static struct property * __init build_one_prop(phandle node, char *prev,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?char *special_name,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?void *special_val,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?int special_len)
> -{
> - ? ? ? static struct property *tmp = NULL;
> - ? ? ? struct property *p;
> - ? ? ? const char *name;
> -
> - ? ? ? if (tmp) {
> - ? ? ? ? ? ? ? p = tmp;
> - ? ? ? ? ? ? ? memset(p, 0, sizeof(*p) + 32);
> - ? ? ? ? ? ? ? tmp = NULL;
> - ? ? ? } else {
> - ? ? ? ? ? ? ? p = prom_early_alloc(sizeof(struct property) + 32);
> - ? ? ? ? ? ? ? p->unique_id = prom_unique_id++;
> - ? ? ? }
> -
> - ? ? ? p->name = (char *) (p + 1);
> - ? ? ? if (special_name) {
> - ? ? ? ? ? ? ? strcpy(p->name, special_name);
> - ? ? ? ? ? ? ? p->length = special_len;
> - ? ? ? ? ? ? ? p->value = prom_early_alloc(special_len);
> - ? ? ? ? ? ? ? memcpy(p->value, special_val, special_len);
> - ? ? ? } else {
> - ? ? ? ? ? ? ? if (prev == NULL) {
> - ? ? ? ? ? ? ? ? ? ? ? name = prom_firstprop(node, p->name);
> - ? ? ? ? ? ? ? } else {
> - ? ? ? ? ? ? ? ? ? ? ? name = prom_nextprop(node, prev, p->name);
> - ? ? ? ? ? ? ? }
> -
> - ? ? ? ? ? ? ? if (!name || strlen(name) == 0) {
> - ? ? ? ? ? ? ? ? ? ? ? tmp = p;
> - ? ? ? ? ? ? ? ? ? ? ? return NULL;
> - ? ? ? ? ? ? ? }
> -#ifdef CONFIG_SPARC32
> - ? ? ? ? ? ? ? strcpy(p->name, name);
> -#endif
> - ? ? ? ? ? ? ? p->length = prom_getproplen(node, p->name);
> - ? ? ? ? ? ? ? if (p->length <= 0) {
> - ? ? ? ? ? ? ? ? ? ? ? p->length = 0;
> - ? ? ? ? ? ? ? } else {
> - ? ? ? ? ? ? ? ? ? ? ? int len;
> -
> - ? ? ? ? ? ? ? ? ? ? ? p->value = prom_early_alloc(p->length + 1);
> - ? ? ? ? ? ? ? ? ? ? ? len = prom_getproperty(node, p->name, p->value,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?p->length);
> - ? ? ? ? ? ? ? ? ? ? ? if (len <= 0)
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? p->length = 0;
> - ? ? ? ? ? ? ? ? ? ? ? ((unsigned char *)p->value)[p->length] = '\0';
> - ? ? ? ? ? ? ? }
> - ? ? ? }
> - ? ? ? return p;
> -}
> -
> -static struct property * __init build_prop_list(phandle node)
> -{
> - ? ? ? struct property *head, *tail;
> -
> - ? ? ? head = tail = build_one_prop(node, NULL,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?".node", &node, sizeof(node));
> -
> - ? ? ? tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
> - ? ? ? tail = tail->next;
> - ? ? ? while(tail) {
> - ? ? ? ? ? ? ? tail->next = build_one_prop(node, tail->name,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL, NULL, 0);
> - ? ? ? ? ? ? ? tail = tail->next;
> - ? ? ? }
> -
> - ? ? ? return head;
> -}
> -
> -static char * __init get_one_property(phandle node, const char *name)
> -{
> - ? ? ? char *buf = "<NULL>";
> - ? ? ? int len;
> -
> - ? ? ? len = prom_getproplen(node, name);
> - ? ? ? if (len > 0) {
> - ? ? ? ? ? ? ? buf = prom_early_alloc(len);
> - ? ? ? ? ? ? ? len = prom_getproperty(node, name, buf, len);
> - ? ? ? }
> -
> - ? ? ? return buf;
> -}
> -
> -static struct device_node * __init prom_create_node(phandle node,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct device_node *parent)
> -{
> - ? ? ? struct device_node *dp;
> -
> - ? ? ? if (!node)
> - ? ? ? ? ? ? ? return NULL;
> -
> - ? ? ? dp = prom_early_alloc(sizeof(*dp));
> - ? ? ? dp->unique_id = prom_unique_id++;
> - ? ? ? dp->parent = parent;
> -
> - ? ? ? kref_init(&dp->kref);
> -
> - ? ? ? dp->name = get_one_property(node, "name");
> - ? ? ? dp->type = get_one_property(node, "device_type");
> - ? ? ? dp->phandle = node;
> -
> - ? ? ? dp->properties = build_prop_list(node);
> -
> - ? ? ? irq_trans_init(dp);
> -
> - ? ? ? return dp;
> -}
> -
> -char * __init build_full_name(struct device_node *dp)
> -{
> - ? ? ? int len, ourlen, plen;
> - ? ? ? char *n;
> -
> - ? ? ? plen = strlen(dp->parent->full_name);
> - ? ? ? ourlen = strlen(dp->path_component_name);
> - ? ? ? len = ourlen + plen + 2;
> -
> - ? ? ? n = prom_early_alloc(len);
> - ? ? ? strcpy(n, dp->parent->full_name);
> - ? ? ? if (!is_root_node(dp->parent)) {
> - ? ? ? ? ? ? ? strcpy(n + plen, "/");
> - ? ? ? ? ? ? ? plen++;
> - ? ? ? }
> - ? ? ? strcpy(n + plen, dp->path_component_name);
> -
> - ? ? ? return n;
> -}
> -
> -static struct device_node * __init prom_build_tree(struct device_node *parent,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?phandle node,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct device_node ***nextp)
> -{
> - ? ? ? struct device_node *ret = NULL, *prev_sibling = NULL;
> - ? ? ? struct device_node *dp;
> -
> - ? ? ? while (1) {
> - ? ? ? ? ? ? ? dp = prom_create_node(node, parent);
> - ? ? ? ? ? ? ? if (!dp)
> - ? ? ? ? ? ? ? ? ? ? ? break;
> -
> - ? ? ? ? ? ? ? if (prev_sibling)
> - ? ? ? ? ? ? ? ? ? ? ? prev_sibling->sibling = dp;
> -
> - ? ? ? ? ? ? ? if (!ret)
> - ? ? ? ? ? ? ? ? ? ? ? ret = dp;
> - ? ? ? ? ? ? ? prev_sibling = dp;
> -
> - ? ? ? ? ? ? ? *(*nextp) = dp;
> - ? ? ? ? ? ? ? *nextp = &dp->allnext;
> -
> - ? ? ? ? ? ? ? dp->path_component_name = build_path_component(dp);
> - ? ? ? ? ? ? ? dp->full_name = build_full_name(dp);
> -
> - ? ? ? ? ? ? ? dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
> -
> - ? ? ? ? ? ? ? if (prom_build_more)
> - ? ? ? ? ? ? ? ? ? ? ? prom_build_more(dp, nextp);
> -
> - ? ? ? ? ? ? ? node = prom_getsibling(node);
> - ? ? ? }
> -
> - ? ? ? return ret;
> -}
> -
> ?unsigned int prom_early_allocated __initdata;
>
> ?void __init prom_build_devicetree(void)
> diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
> index 7cecc8f..41921a8 100644
> --- a/drivers/of/Kconfig
> +++ b/drivers/of/Kconfig
> @@ -2,6 +2,10 @@ config OF_FLATTREE
> ? ? ? ?bool
> ? ? ? ?depends on OF
>
> +config OF_PROMTREE
> + ? ? ? bool
> + ? ? ? depends on OF
> +
> ?config OF_DYNAMIC
> ? ? ? ?def_bool y
> ? ? ? ?depends on OF && PPC_OF
> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> index f232cc9..54e8517 100644
> --- a/drivers/of/Makefile
> +++ b/drivers/of/Makefile
> @@ -1,5 +1,6 @@
> ?obj-y = base.o
> ?obj-$(CONFIG_OF_FLATTREE) += fdt.o
> +obj-$(CONFIG_OF_PROMTREE) += pdt.o
> ?obj-$(CONFIG_OF_DEVICE) += device.o platform.o
> ?obj-$(CONFIG_OF_GPIO) ? += gpio.o
> ?obj-$(CONFIG_OF_I2C) ? += of_i2c.o
> diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
> new file mode 100644
> index 0000000..b24167f
> --- /dev/null
> +++ b/drivers/of/pdt.c
> @@ -0,0 +1,225 @@
> +/*
> + * Paul Mackerras ? ? ?August 1996.
> + * Copyright (C) 1996-2005 Paul Mackerras.
> + *
> + * ?Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
> + * ? ?{engebret|bergner}@us.ibm.com
> + *
> + * ?Adapted for sparc by David S. Miller [email protected]
> + * ?Adapted for multiple architectures by Andres Salomon <[email protected]>
> + *
> + * ? ? ?This program is free software; you can redistribute it and/or
> + * ? ? ?modify it under the terms of the GNU General Public License
> + * ? ? ?as published by the Free Software Foundation; either version
> + * ? ? ?2 of the License, or (at your option) any later version.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/errno.h>
> +#include <linux/mutex.h>
> +#include <linux/slab.h>
> +#include <linux/of.h>
> +#include <linux/of_pdt.h>
> +#include <asm/prom.h>
> +
> +/* TODO: mark this stuff as __initdata */
> +void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
> +
> +#if defined(CONFIG_SPARC)
> +static unsigned int prom_unique_id;
> +
> +#define inc_unique_id(p) do { \
> + ? ? ? (p)->unique_id = prom_unique_id++; \
> +} while (0)
> +
> +static inline const char *fetch_node_name(struct device_node *dp)
> +{
> + ? ? ? return dp->path_component_name;
> +}
> +
> +#else
> +
> +#define inc_unique_id(p) ? ? ? do { } while(0)
> +
> +static inline const char *fetch_node_name(struct device_node *dp)
> +{
> + ? ? ? return dp->name;
> +}
> +
> +static inline void irq_trans_init(struct device_node *dp)
> +{
> + ? ? ? /* unused on non-SPARC architectures */
> +}
> +
> +#endif /* !CONFIG_SPARC */
> +
> +static struct property * __init build_one_prop(phandle node, char *prev,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?char *special_name,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?void *special_val,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?int special_len)
> +{
> + ? ? ? static struct property *tmp = NULL;
> + ? ? ? struct property *p;
> + ? ? ? const char *name;
> +
> + ? ? ? if (tmp) {
> + ? ? ? ? ? ? ? p = tmp;
> + ? ? ? ? ? ? ? memset(p, 0, sizeof(*p) + 32);
> + ? ? ? ? ? ? ? tmp = NULL;
> + ? ? ? } else {
> + ? ? ? ? ? ? ? p = prom_early_alloc(sizeof(struct property) + 32);
> + ? ? ? ? ? ? ? inc_unique_id(p);
> + ? ? ? }
> +
> + ? ? ? p->name = (char *) (p + 1);
> + ? ? ? if (special_name) {
> + ? ? ? ? ? ? ? strcpy(p->name, special_name);
> + ? ? ? ? ? ? ? p->length = special_len;
> + ? ? ? ? ? ? ? p->value = prom_early_alloc(special_len);
> + ? ? ? ? ? ? ? memcpy(p->value, special_val, special_len);
> + ? ? ? } else {
> + ? ? ? ? ? ? ? if (prev == NULL) {
> + ? ? ? ? ? ? ? ? ? ? ? name = prom_firstprop(node, p->name);
> + ? ? ? ? ? ? ? } else {
> + ? ? ? ? ? ? ? ? ? ? ? name = prom_nextprop(node, prev, p->name);
> + ? ? ? ? ? ? ? }
> +
> + ? ? ? ? ? ? ? if (!name || strlen(name) == 0) {
> + ? ? ? ? ? ? ? ? ? ? ? tmp = p;
> + ? ? ? ? ? ? ? ? ? ? ? return NULL;
> + ? ? ? ? ? ? ? }
> +#ifdef CONFIG_SPARC32
> + ? ? ? ? ? ? ? strcpy(p->name, name);
> +#endif
> + ? ? ? ? ? ? ? p->length = prom_getproplen(node, p->name);
> + ? ? ? ? ? ? ? if (p->length <= 0) {
> + ? ? ? ? ? ? ? ? ? ? ? p->length = 0;
> + ? ? ? ? ? ? ? } else {
> + ? ? ? ? ? ? ? ? ? ? ? int len;
> +
> + ? ? ? ? ? ? ? ? ? ? ? p->value = prom_early_alloc(p->length + 1);
> + ? ? ? ? ? ? ? ? ? ? ? len = prom_getproperty(node, p->name, p->value,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?p->length);
> + ? ? ? ? ? ? ? ? ? ? ? if (len <= 0)
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? p->length = 0;
> + ? ? ? ? ? ? ? ? ? ? ? ((unsigned char *)p->value)[p->length] = '\0';
> + ? ? ? ? ? ? ? }
> + ? ? ? }
> + ? ? ? return p;
> +}
> +
> +static struct property * __init build_prop_list(phandle node)
> +{
> + ? ? ? struct property *head, *tail;
> +
> + ? ? ? head = tail = build_one_prop(node, NULL,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?".node", &node, sizeof(node));
> +
> + ? ? ? tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
> + ? ? ? tail = tail->next;
> + ? ? ? while(tail) {
> + ? ? ? ? ? ? ? tail->next = build_one_prop(node, tail->name,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL, NULL, 0);
> + ? ? ? ? ? ? ? tail = tail->next;
> + ? ? ? }
> +
> + ? ? ? return head;
> +}
> +
> +static char * __init get_one_property(phandle node, const char *name)
> +{
> + ? ? ? char *buf = "<NULL>";
> + ? ? ? int len;
> +
> + ? ? ? len = prom_getproplen(node, name);
> + ? ? ? if (len > 0) {
> + ? ? ? ? ? ? ? buf = prom_early_alloc(len);
> + ? ? ? ? ? ? ? len = prom_getproperty(node, name, buf, len);
> + ? ? ? }
> +
> + ? ? ? return buf;
> +}
> +
> +struct device_node * __init prom_create_node(phandle node,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct device_node *parent)
> +{
> + ? ? ? struct device_node *dp;
> +
> + ? ? ? if (!node)
> + ? ? ? ? ? ? ? return NULL;
> +
> + ? ? ? dp = prom_early_alloc(sizeof(*dp));
> + ? ? ? inc_unique_id(dp);
> + ? ? ? dp->parent = parent;
> +
> + ? ? ? kref_init(&dp->kref);
> +
> + ? ? ? dp->name = get_one_property(node, "name");
> + ? ? ? dp->type = get_one_property(node, "device_type");
> + ? ? ? dp->phandle = node;
> +
> + ? ? ? dp->properties = build_prop_list(node);
> +
> + ? ? ? irq_trans_init(dp);
> +
> + ? ? ? return dp;
> +}
> +
> +static char * __init build_full_name(struct device_node *dp)
> +{
> + ? ? ? int len, ourlen, plen;
> + ? ? ? char *n;
> +
> + ? ? ? plen = strlen(dp->parent->full_name);
> + ? ? ? ourlen = strlen(fetch_node_name(dp));
> + ? ? ? len = ourlen + plen + 2;
> +
> + ? ? ? n = prom_early_alloc(len);
> + ? ? ? strcpy(n, dp->parent->full_name);
> + ? ? ? if (!is_root_node(dp->parent)) {
> + ? ? ? ? ? ? ? strcpy(n + plen, "/");
> + ? ? ? ? ? ? ? plen++;
> + ? ? ? }
> + ? ? ? strcpy(n + plen, fetch_node_name(dp));
> +
> + ? ? ? return n;
> +}
> +
> +struct device_node * __init prom_build_tree(struct device_node *parent,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? phandle node,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct device_node ***nextp)
> +{
> + ? ? ? struct device_node *ret = NULL, *prev_sibling = NULL;
> + ? ? ? struct device_node *dp;
> +
> + ? ? ? while (1) {
> + ? ? ? ? ? ? ? dp = prom_create_node(node, parent);
> + ? ? ? ? ? ? ? if (!dp)
> + ? ? ? ? ? ? ? ? ? ? ? break;
> +
> + ? ? ? ? ? ? ? if (prev_sibling)
> + ? ? ? ? ? ? ? ? ? ? ? prev_sibling->sibling = dp;
> +
> + ? ? ? ? ? ? ? if (!ret)
> + ? ? ? ? ? ? ? ? ? ? ? ret = dp;
> + ? ? ? ? ? ? ? prev_sibling = dp;
> +
> + ? ? ? ? ? ? ? *(*nextp) = dp;
> + ? ? ? ? ? ? ? *nextp = &dp->allnext;
> +
> +#if defined(CONFIG_SPARC)
> + ? ? ? ? ? ? ? dp->path_component_name = build_path_component(dp);
> +#endif
> + ? ? ? ? ? ? ? dp->full_name = build_full_name(dp);
> +
> + ? ? ? ? ? ? ? dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
> +
> + ? ? ? ? ? ? ? if (prom_build_more)
> + ? ? ? ? ? ? ? ? ? ? ? prom_build_more(dp, nextp);
> +
> + ? ? ? ? ? ? ? node = prom_getsibling(node);
> + ? ? ? }
> +
> + ? ? ? return ret;
> +}
> diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
> new file mode 100644
> index 0000000..f62616e
> --- /dev/null
> +++ b/include/linux/of_pdt.h
> @@ -0,0 +1,37 @@
> +#include <linux/of.h> ?/* linux/of.h gets to determine #include ordering */
> +/*
> + * Definitions for building a device tree by calling into the
> + * Open Firmware PROM.
> + *
> + * Copyright (C) 1996-2005 Paul Mackerras.
> + * Copyright (C) 2010 ?Andres Salomon <[email protected]>
> + *
> + * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
> + * Updates for SPARC by David S. Miller
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version
> + * 2 of the License, or (at your option) any later version.
> + */
> +
> +#ifndef _LINUX_OF_PDT_H
> +#define _LINUX_OF_PDT_H
> +
> +extern struct device_node *prom_create_node(phandle node,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct device_node *parent);
> +extern struct device_node *prom_build_tree(struct device_node *parent,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?phandle node,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct device_node ***nextp);
> +
> +extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
> +
> +static inline int is_root_node(const struct device_node *dp)
> +{
> + ? ? ? if (!dp)
> + ? ? ? ? ? ? ? return 0;
> +
> + ? ? ? return (dp->parent == NULL);
> +}
> +
> +#endif /* _LINUX_OF_PDT_H */
> --
> 1.5.6.5
>
>
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Hi Andres, comments below....
On Mon, Jun 28, 2010 at 7:00 PM, Andres Salomon <[email protected]> wrote:
>
> Make use of PROC_DEVICETREE to export the tree, and sparc's PROMTREE code to
> call into OLPC's Open Firmware to build the tree.
>
> (Yes, I know this leaks memory by simply using kmalloc)
>
> Signed-off-by: Andres Salomon <[email protected]>
> ---
> ?arch/x86/Kconfig ? ? ? ? ? ? ? ? | ? ?5 ++
> ?arch/x86/include/asm/olpc_prom.h | ? 42 +++++++++++
> ?arch/x86/include/asm/prom.h ? ? ?| ? ?5 ++
> ?arch/x86/kernel/Makefile ? ? ? ? | ? ?1 +
> ?arch/x86/kernel/olpc_ofw.c ? ? ? | ? 13 ++++
> ?arch/x86/kernel/olpc_prom.c ? ? ?| ?148 ++++++++++++++++++++++++++++++++++++++
> ?fs/proc/Kconfig ? ? ? ? ? ? ? ? ?| ? ?2 +-
> ?7 files changed, 215 insertions(+), 1 deletions(-)
> ?create mode 100644 arch/x86/include/asm/olpc_prom.h
> ?create mode 100644 arch/x86/include/asm/prom.h
> ?create mode 100644 arch/x86/kernel/olpc_prom.c
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 71c194d..7aea004 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWARE
> ? ? ? ? ?that is used on the OLPC XO-1 Children's Machine.
> ? ? ? ? ?If unsure, say N here.
>
> +config OF
> + ? ? ? def_bool y
> + ? ? ? depends on OLPC_OPENFIRMWARE
> + ? ? ? select OF_PROMTREE
> +
This hunk will need to be respun on top of Stephen's CONFIG_OF change.
It's currently in my test-devicetree branch on
git://git.secretlab.ca/git/linux-2.6
> ?endif # X86_32
>
> ?config K8_NB
> diff --git a/arch/x86/include/asm/olpc_prom.h b/arch/x86/include/asm/olpc_prom.h
> new file mode 100644
> index 0000000..96cdcee
> --- /dev/null
> +++ b/arch/x86/include/asm/olpc_prom.h
> @@ -0,0 +1,42 @@
> +#include <linux/of.h> ?/* linux/of.h gets to determine #include ordering */
> +/*
> + * Definitions for talking to the Open Firmware PROM on
> + * Power Macintosh computers.
> + *
> + * Copyright (C) 1996-2005 Paul Mackerras.
> + *
> + * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
> + * Updates for SPARC by David S. Miller
> + * Updates for x86/OLPC by Andres Salomon
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version
> + * 2 of the License, or (at your option) any later version.
> + */
> +
> +#ifndef _X86_PROM_OLPC_H
> +#define _X86_PROM_OLPC_H
> +#ifdef __KERNEL__
> +
> +#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
> +#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
Do you really need to override these from the default?
> +#define of_compat_cmp(s1, s2, l) ? ? ? strncmp((s1), (s2), (l))
> +#define of_prop_cmp(s1, s2) ? ? ? ? ? ?strcasecmp((s1), (s2))
> +#define of_node_cmp(s1, s2) ? ? ? ? ? ?strcmp((s1), (s2))
Ditto here?
> +extern void prom_build_devicetree(void);
> +
> +extern void *prom_early_alloc(unsigned long size);
> +
> +extern char *prom_firstprop(phandle node, char *buf);
> +extern char *prom_nextprop(phandle node, const char *prev, char *buf);
> +extern int prom_getproplen(phandle node, const char *prop);
> +extern int prom_getproperty(phandle node, const char *prop,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ?char *buffer, int bufsize);
> +extern phandle prom_getchild(phandle node);
> +extern phandle prom_getsibling(phandle node);
> +
> +#endif /* __KERNEL__ */
> +#endif /* _X86_PROM_OLPC_H */
> diff --git a/arch/x86/include/asm/prom.h b/arch/x86/include/asm/prom.h
> new file mode 100644
> index 0000000..7b561b2
> --- /dev/null
> +++ b/arch/x86/include/asm/prom.h
> @@ -0,0 +1,5 @@
> +#ifdef CONFIG_OLPC_OPENFIRMWARE
> +# include <asm/olpc_prom.h>
> +#else
> +# error "No OFW prom defined for x86!"
> +#endif
Personally, I wouldn't bother with the header file redirection.
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index 0925676..3d7e535 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -105,6 +105,7 @@ scx200-y ? ? ? ? ? ? ? ? ? ?+= scx200_32.o
>
> ?obj-$(CONFIG_OLPC) ? ? ? ? ? ? += olpc.o
> ?obj-$(CONFIG_OLPC_OPENFIRMWARE) ? ? ? ?+= olpc_ofw.o
> +obj-$(CONFIG_PROC_DEVICETREE) ?+= olpc_prom.o
> ?obj-$(CONFIG_X86_MRST) ? ? ? ? += mrst.o
>
> ?microcode-y ? ? ? ? ? ? ? ? ? ? ? ? ? ?:= microcode_core.o
> diff --git a/arch/x86/kernel/olpc_ofw.c b/arch/x86/kernel/olpc_ofw.c
> index 3e13a4b..8838edb 100644
> --- a/arch/x86/kernel/olpc_ofw.c
> +++ b/arch/x86/kernel/olpc_ofw.c
> @@ -6,6 +6,7 @@
> ?#include <asm/io.h>
> ?#include <asm/pgtable.h>
> ?#include <asm/olpc_ofw.h>
> +#include <asm/prom.h>
>
> ?/* address of OFW callback interface; will be NULL if OFW isn't found */
> ?static int (*olpc_ofw_cif)(int *);
> @@ -103,3 +104,15 @@ void __init olpc_ofw_detect(void)
> ? ? ? ? ? ? ? ? ? ? ? ?(unsigned long)olpc_ofw_cif, (-start) >> 20);
> ? ? ? ?reserve_top_address(-start);
> ?}
> +
> +#ifdef CONFIG_PROC_DEVICETREE
> +static int __init olpc_ofw_build_devicetree(void)
> +{
> + ? ? ? /* initialize the device-tree that proc uses */
> + ? ? ? if (olpc_ofw_cif)
> + ? ? ? ? ? ? ? prom_build_devicetree();
> +
> + ? ? ? return 0;
> +}
> +arch_initcall(olpc_ofw_build_devicetree);
> +#endif /* CONFIG_PROC_DEVICETREE */
> diff --git a/arch/x86/kernel/olpc_prom.c b/arch/x86/kernel/olpc_prom.c
> new file mode 100644
> index 0000000..1128f3f
> --- /dev/null
> +++ b/arch/x86/kernel/olpc_prom.c
> @@ -0,0 +1,148 @@
> +/*
> + * olpc_prom.c: OLPC-specific OFW device tree support code.
> + *
> + * Paul Mackerras ? ? ?August 1996.
> + * Copyright (C) 1996-2005 Paul Mackerras.
> + *
> + * ?Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
> + * ? ?{engebret|bergner}@us.ibm.com
> + *
> + * ?Adapted for sparc by David S. Miller [email protected]
> + *
> + * ? ? ?This program is free software; you can redistribute it and/or
> + * ? ? ?modify it under the terms of the GNU General Public License
> + * ? ? ?as published by the Free Software Foundation; either version
> + * ? ? ?2 of the License, or (at your option) any later version.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/errno.h>
> +#include <linux/slab.h>
> +#include <linux/of.h>
> +#include <linux/of_pdt.h>
> +#include <asm/olpc_ofw.h>
> +#include <asm/prom.h>
> +
> +phandle prom_getsibling(phandle node)
> +{
> + ? ? ? const void *args[] = { (void *)node };
> + ? ? ? void *res[] = { &node };
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return -1;
> +
> + ? ? ? if (olpc_ofw("peer", args, res) || node == -1)
> + ? ? ? ? ? ? ? return -1;
> +
> + ? ? ? return node;
> +}
> +
> +phandle prom_getchild(phandle node)
> +{
> + ? ? ? const void *args[] = { (void *)node };
> + ? ? ? void *res[] = { &node };
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return 0;
> +
> + ? ? ? if (olpc_ofw("child", args, res) || node == -1) {
> + ? ? ? ? ? ? ? printk(KERN_ERR "PROM: %s: fetching child failed!\n", __func__);
> + ? ? ? ? ? ? ? return 0;
> + ? ? ? }
> +
> + ? ? ? return node;
> +}
> +
> +int prom_getproplen(phandle node, const char *prop)
> +{
> + ? ? ? const void *args[] = { (void *)node, prop };
> + ? ? ? int len;
> + ? ? ? void *res[] = { &len };
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return 0;
> +
> + ? ? ? if (olpc_ofw("getproplen", args, res)) {
> + ? ? ? ? ? ? ? printk(KERN_ERR "PROM: %s: getproplen failed!\n", __func__);
> + ? ? ? ? ? ? ? return 0;
> + ? ? ? }
> +
> + ? ? ? return len;
> +}
> +
> +int prom_getproperty(phandle node, const char *prop, char *buf,
> + ? ? ? ? ? ? ? int bufsize)
> +{
> + ? ? ? int plen;
> +
> + ? ? ? plen = prom_getproplen(node, prop);
> + ? ? ? if (plen > bufsize || plen < 1)
> + ? ? ? ? ? ? ? return -1;
> + ? ? ? else {
> + ? ? ? ? ? ? ? const void *args[] = { (void *)node, prop, buf, (void *)plen };
> + ? ? ? ? ? ? ? void *res[] = { &plen };
> +
> + ? ? ? ? ? ? ? if (olpc_ofw("getprop", args, res)) {
> + ? ? ? ? ? ? ? ? ? ? ? printk(KERN_ERR "PROM: %s: getprop failed!\n", __func__);
> + ? ? ? ? ? ? ? ? ? ? ? return -1;
> + ? ? ? ? ? ? ? }
> + ? ? ? ? ? ? ? //((unsigned char *)buf)[plen] = '\0';
> + ? ? ? }
> +
> + ? ? ? return 0;
> +}
> +
> +char *prom_firstprop(phandle node, char *buf)
> +{
> + ? ? ? buf[0] = '\0';
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return NULL;
> +
> + ? ? ? return prom_nextprop(node, "", buf);
> +}
> +
> +char *prom_nextprop(phandle node, const char *prev, char *buf)
> +{
> + ? ? ? const void *args[] = { (void *)node, prev, buf };
> + ? ? ? int success;
> + ? ? ? void *res[] = { &success };
> +
> + ? ? ? buf[0] = '\0';
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return NULL;
> +
> + ? ? ? if (olpc_ofw("nextprop", args, res) || success != 1) {
> + ? ? ? ? ? ? ? printk(KERN_ERR "PROM: %s: nextprop failed!\n", __func__);
> + ? ? ? ? ? ? ? return NULL;
> + ? ? ? }
> +
> + ? ? ? return buf;
> +}
> +
> +void * __init prom_early_alloc(unsigned long size)
> +{
> + ? ? ? /* unlike SPARC, we don't bother keeping track of prom memory */
> + ? ? ? return kzalloc(size, GFP_KERNEL);
> +}
> +
> +void __init prom_build_devicetree(void)
> +{
> + ? ? ? struct device_node **nextp;
> + ? ? ? phandle root;
> +
> + ? ? ? root = prom_getsibling(0);
> + ? ? ? if (root < 0) {
> + ? ? ? ? ? ? ? printk(KERN_ERR "PROM: unable to get root node from OFW!\n");
> + ? ? ? ? ? ? ? return;
> + ? ? ? }
> +
> + ? ? ? allnodes = prom_create_node(root, NULL);
> + ? ? ? allnodes->full_name = "/";
> +
> + ? ? ? nextp = &allnodes->allnext;
> + ? ? ? allnodes->child = prom_build_tree(allnodes,
> + ? ? ? ? ? ? ? ? ? ? ? prom_getchild(allnodes->phandle), &nextp);
> +}
> diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
> index 858a859..86f67ce 100644
> --- a/fs/proc/Kconfig
> +++ b/fs/proc/Kconfig
> @@ -41,7 +41,7 @@ config PROC_VMCORE
>
> ?config PROC_DEVICETREE
> ? ? ? ?bool "Support for device tree in /proc"
> - ? ? ? depends on PROC_FS && (PPC || MICROBLAZE)
> + ? ? ? depends on PROC_FS && (PPC || MICROBLAZE || OLPC_OPENFIRMWARE)
This change should no longer be necessary with the way I've modified patch 3/4.
Cheers,
g.
Hi Andres,
On Tue, 29 Jun 2010 01:12:36 -0700 Grant Likely <[email protected]> wrote:
>
> > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> > index 71c194d..7aea004 100644
> > --- a/arch/x86/Kconfig
> > +++ b/arch/x86/Kconfig
> > @@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWARE
> > Â Â Â Â Â that is used on the OLPC XO-1 Children's Machine.
> > Â Â Â Â Â If unsure, say N here.
> >
> > +config OF
> > + Â Â Â def_bool y
> > + Â Â Â depends on OLPC_OPENFIRMWARE
> > + Â Â Â select OF_PROMTREE
> > +
>
> This hunk will need to be respun on top of Stephen's CONFIG_OF change.
> It's currently in my test-devicetree branch on
> git://git.secretlab.ca/git/linux-2.6
Yeah, just make config OLPC_OPENFIRMWARE select OF and OF_PROMTREE and just use
config OF
bool
for now. This will work even without my changes. We will remove those
latter two lines later.
--
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/
On Tue, 29 Jun 2010 01:12:36 -0700
Grant Likely <[email protected]> wrote:
> Hi Andres, comments below....
Thanks!
>
> On Mon, Jun 28, 2010 at 7:00 PM, Andres Salomon <[email protected]>
> wrote:
> >
> > Make use of PROC_DEVICETREE to export the tree, and sparc's
> > PROMTREE code to call into OLPC's Open Firmware to build the tree.
> >
> > (Yes, I know this leaks memory by simply using kmalloc)
> >
> > Signed-off-by: Andres Salomon <[email protected]>
> > ---
> >  arch/x86/Kconfig         |   5 ++
> > Â arch/x86/include/asm/olpc_prom.h | Â 42 +++++++++++
> >  arch/x86/include/asm/prom.h    |   5 ++
> >  arch/x86/kernel/Makefile     |   1 +
> >  arch/x86/kernel/olpc_ofw.c    |  13 ++++
> >  arch/x86/kernel/olpc_prom.c    |  148
> > ++++++++++++++++++++++++++++++++++++++ fs/proc/Kconfig
> > Â Â Â | Â Â 2 +- 7 files changed, 215 insertions(+), 1 deletions(-)
> > Â create mode 100644 arch/x86/include/asm/olpc_prom.h
> > Â create mode 100644 arch/x86/include/asm/prom.h
> > Â create mode 100644 arch/x86/kernel/olpc_prom.c
> >
> > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> > index 71c194d..7aea004 100644
> > --- a/arch/x86/Kconfig
> > +++ b/arch/x86/Kconfig
> > @@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWARE
> > Â Â Â Â Â that is used on the OLPC XO-1 Children's Machine.
> > Â Â Â Â Â If unsure, say N here.
> >
> > +config OF
> > + Â Â Â def_bool y
> > + Â Â Â depends on OLPC_OPENFIRMWARE
> > + Â Â Â select OF_PROMTREE
> > +
>
> This hunk will need to be respun on top of Stephen's CONFIG_OF change.
> It's currently in my test-devicetree branch on
> git://git.secretlab.ca/git/linux-2.6
Yep, I've changed it locally.
>
> > Â endif # X86_32
> >
> > Â config K8_NB
> > diff --git a/arch/x86/include/asm/olpc_prom.h
> > b/arch/x86/include/asm/olpc_prom.h new file mode 100644
> > index 0000000..96cdcee
> > --- /dev/null
> > +++ b/arch/x86/include/asm/olpc_prom.h
> > @@ -0,0 +1,42 @@
> > +#include <linux/of.h> Â /* linux/of.h gets to determine #include
> > ordering */ +/*
> > + * Definitions for talking to the Open Firmware PROM on
> > + * Power Macintosh computers.
> > + *
> > + * Copyright (C) 1996-2005 Paul Mackerras.
> > + *
> > + * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM
> > Corp.
> > + * Updates for SPARC by David S. Miller
> > + * Updates for x86/OLPC by Andres Salomon
> > + *
> > + * This program is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License
> > + * as published by the Free Software Foundation; either version
> > + * 2 of the License, or (at your option) any later version.
> > + */
> > +
> > +#ifndef _X86_PROM_OLPC_H
> > +#define _X86_PROM_OLPC_H
> > +#ifdef __KERNEL__
> > +
> > +#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
> > +#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
>
> Do you really need to override these from the default?
>
> > +#define of_compat_cmp(s1, s2, l) Â Â Â strncmp((s1), (s2), (l))
> > +#define of_prop_cmp(s1, s2) Â Â Â Â Â Â strcasecmp((s1), (s2))
> > +#define of_node_cmp(s1, s2) Â Â Â Â Â Â strcmp((s1), (s2))
>
> Ditto here?
They're based upon what the old promfs patch used. I need to test and
verify that strings are being mangled in the same way before I start
making changes here.
>
> > +extern void prom_build_devicetree(void);
> > +
> > +extern void *prom_early_alloc(unsigned long size);
> > +
> > +extern char *prom_firstprop(phandle node, char *buf);
> > +extern char *prom_nextprop(phandle node, const char *prev, char
> > *buf); +extern int prom_getproplen(phandle node, const char *prop);
> > +extern int prom_getproperty(phandle node, const char *prop,
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â char *buffer, int bufsize);
> > +extern phandle prom_getchild(phandle node);
> > +extern phandle prom_getsibling(phandle node);
> > +
> > +#endif /* __KERNEL__ */
> > +#endif /* _X86_PROM_OLPC_H */
> > diff --git a/arch/x86/include/asm/prom.h
> > b/arch/x86/include/asm/prom.h new file mode 100644
> > index 0000000..7b561b2
> > --- /dev/null
> > +++ b/arch/x86/include/asm/prom.h
> > @@ -0,0 +1,5 @@
> > +#ifdef CONFIG_OLPC_OPENFIRMWARE
> > +# include <asm/olpc_prom.h>
> > +#else
> > +# error "No OFW prom defined for x86!"
> > +#endif
>
> Personally, I wouldn't bother with the header file redirection.
The reason for the header file redirection is because this is
OLPC-only; the x86 folks don't want me claiming this to be the One
True x86 OFW.
On Tue, 29 Jun 2010 00:50:08 -0700
Grant Likely <[email protected]> wrote:
> On Mon, Jun 28, 2010 at 7:00 PM, Andres Salomon <[email protected]> wrote:
> >
> > Stick code into drivers/of/pdt.c (Prom Device Tree) that other
> > architectures with OpenFirmware resident in memory can make use of.
> >
> > Signed-off-by: Andres Salomon <[email protected]>
>
> Hi Andres,
>
> The patch itself looks fine, but there are currently two methods for
> extracting the device tree from open firmware; one in arch/powerpc
> using the flattened format, and one in arch/sparc. I don't want to
> end up maintaining both methods in drivers/of, and there has also some
> discussions on moving the powerpc version into common code. I've been
> thinking about using the powerpc approach to support ARM platforms
> using both the flat tree and real OFW.
>
> Ben, what say you? Before I do anything I'd like to have your opinion.
>
So you're saying that you want ARM (and sparc, and OLPC) to generate a
flat tree by calling into OFW? Sparc and OLPC have very similar
mechanisms for getting device tree info from OFW, so it makes sense to
share code between them.
On Tue, Jun 29, 2010 at 9:03 AM, Andres Salomon <[email protected]> wrote:
> On Tue, 29 Jun 2010 00:50:08 -0700
> Grant Likely <[email protected]> wrote:
>
>> On Mon, Jun 28, 2010 at 7:00 PM, Andres Salomon <[email protected]> wrote:
>> >
>> > Stick code into drivers/of/pdt.c (Prom Device Tree) that other
>> > architectures with OpenFirmware resident in memory can make use of.
>> >
>> > Signed-off-by: Andres Salomon <[email protected]>
>>
>> Hi Andres,
>>
>> The patch itself looks fine, but there are currently two methods for
>> extracting the device tree from open firmware; one in arch/powerpc
>> using the flattened format, and one in arch/sparc. ?I don't want to
>> end up maintaining both methods in drivers/of, and there has also some
>> discussions on moving the powerpc version into common code. ?I've been
>> thinking about using the powerpc approach to support ARM platforms
>> using both the flat tree and real OFW.
>>
>> Ben, what say you? ?Before I do anything I'd like to have your opinion.
>>
>
> So you're saying that you want ARM (and sparc, and OLPC) to generate a
> flat tree by calling into OFW?
ARM: yes, it will use the same mechanism as powerpc and microblaze.
Direct usage of the flat representation will be more common that
machines with real OFW. I'm following the powerpc lead here because
the powerpc approach already supports both the flat tree and OFW in
the same kernel.
Sparc: I don't have a strong opinion. Sparc and PowerPC have a lot of
shared code, but they've diverged quite a bit. I have no intention to
force a model changes onto sparc. For a lot of the merge work that
I'm doing I'm leaving the sparc code as-is in the arch/sparc tree with
the assumption that support for new architectures will use the common
code in drivers/of.
There of course is a gap when it comes to talking to OFW in that both
the current powerpc and sparc variants still remain in arch code.
x86: I've also just received patches that make use of the flattened
representation on x86 for FPGA add in boards. It is conceivable that
a single kernel will want support for both OFW and FDT. Since PowerPC
already supports this use case, my preference is for the powerpc
implementation of OFW.
I'm squeamish about having both the powerpc and sparc methods in
common drivers/of code, but I'm not saying no. I want to hear from
Ben and David who are more familiar with the history before I make a
decision. I do know that Ben has been talking about generalizing the
powerpc version of the code, and I definitely don't want two methods
for extracting the OFW device tree in drivers/of.
> Sparc and OLPC have very similar
> mechanisms for getting device tree info from OFW, so it makes sense to
> share code between them.
Other than the flattened tree step; is the powerpc method dissimilar
from the Sparc and OLPC method for talking to OFW? (This is not a
rhetorical question, I'm want to know if I'm missing some details).
The main difference I know about is that OFW can still kept alive at
runtime for sparc, which powerpc does not do. However, keeping OFW
callable is a separate issue from how to extract the device tree.
g.
On Tue, 29 Jun 2010 15:42:54 -0600
Grant Likely <[email protected]> wrote:
> On Tue, Jun 29, 2010 at 9:03 AM, Andres Salomon <[email protected]>
> wrote:
[...]
>
> > Sparc and OLPC have very similar
> > mechanisms for getting device tree info from OFW, so it makes sense
> > to share code between them.
>
> Other than the flattened tree step; is the powerpc method dissimilar
> from the Sparc and OLPC method for talking to OFW? (This is not a
> rhetorical question, I'm want to know if I'm missing some details).
> The main difference I know about is that OFW can still kept alive at
> runtime for sparc, which powerpc does not do. However, keeping OFW
> callable is a separate issue from how to extract the device tree.
>
After having a look at powerpc's flatten_device_tree, I don't see any
obvious reason why OLPC couldn't use this (though it still strikes me
as weird to go from prom->fdt->dt when the option of prom->dt is
available and less complex). Do you already have the patches that put
this into drivers/of/?
On Tue, Jun 29, 2010 at 8:23 AM, Andres Salomon <[email protected]> wrote:
> On Tue, 29 Jun 2010 01:12:36 -0700
> Grant Likely <[email protected]> wrote:
>
>> Hi Andres, comments below....
>
> Thanks!
>
>
>>
>> On Mon, Jun 28, 2010 at 7:00 PM, Andres Salomon <[email protected]>
>> wrote:
>> >
>> > Make use of PROC_DEVICETREE to export the tree, and sparc's
>> > PROMTREE code to call into OLPC's Open Firmware to build the tree.
>> >
>> > (Yes, I know this leaks memory by simply using kmalloc)
>> >
>> > Signed-off-by: Andres Salomon <[email protected]>
>> > ---
>> > ?arch/x86/Kconfig ? ? ? ? ? ? ? ? | ? ?5 ++
>> > ?arch/x86/include/asm/olpc_prom.h | ? 42 +++++++++++
>> > ?arch/x86/include/asm/prom.h ? ? ?| ? ?5 ++
>> > ?arch/x86/kernel/Makefile ? ? ? ? | ? ?1 +
>> > ?arch/x86/kernel/olpc_ofw.c ? ? ? | ? 13 ++++
>> > ?arch/x86/kernel/olpc_prom.c ? ? ?| ?148
>> > ++++++++++++++++++++++++++++++++++++++ fs/proc/Kconfig
>> > ? ? ?| ? ?2 +- 7 files changed, 215 insertions(+), 1 deletions(-)
>> > ?create mode 100644 arch/x86/include/asm/olpc_prom.h
>> > ?create mode 100644 arch/x86/include/asm/prom.h
>> > ?create mode 100644 arch/x86/kernel/olpc_prom.c
>> >
>> > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> > index 71c194d..7aea004 100644
>> > --- a/arch/x86/Kconfig
>> > +++ b/arch/x86/Kconfig
>> > @@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWARE
>> > ? ? ? ? ?that is used on the OLPC XO-1 Children's Machine.
>> > ? ? ? ? ?If unsure, say N here.
>> >
>> > +config OF
>> > + ? ? ? def_bool y
>> > + ? ? ? depends on OLPC_OPENFIRMWARE
>> > + ? ? ? select OF_PROMTREE
>> > +
>>
>> This hunk will need to be respun on top of Stephen's CONFIG_OF change.
>> ?It's currently in my test-devicetree branch on
>> git://git.secretlab.ca/git/linux-2.6
>
> Yep, I've changed it locally.
>
>>
>> > ?endif # X86_32
>> >
>> > ?config K8_NB
>> > diff --git a/arch/x86/include/asm/olpc_prom.h
>> > b/arch/x86/include/asm/olpc_prom.h new file mode 100644
>> > index 0000000..96cdcee
>> > --- /dev/null
>> > +++ b/arch/x86/include/asm/olpc_prom.h
>> > @@ -0,0 +1,42 @@
>> > +#include <linux/of.h> ?/* linux/of.h gets to determine #include
>> > ordering */ +/*
>> > + * Definitions for talking to the Open Firmware PROM on
>> > + * Power Macintosh computers.
>> > + *
>> > + * Copyright (C) 1996-2005 Paul Mackerras.
>> > + *
>> > + * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM
>> > Corp.
>> > + * Updates for SPARC by David S. Miller
>> > + * Updates for x86/OLPC by Andres Salomon
>> > + *
>> > + * This program is free software; you can redistribute it and/or
>> > + * modify it under the terms of the GNU General Public License
>> > + * as published by the Free Software Foundation; either version
>> > + * 2 of the License, or (at your option) any later version.
>> > + */
>> > +
>> > +#ifndef _X86_PROM_OLPC_H
>> > +#define _X86_PROM_OLPC_H
>> > +#ifdef __KERNEL__
>> > +
>> > +#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
>> > +#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
>>
>> Do you really need to override these from the default?
>>
>> > +#define of_compat_cmp(s1, s2, l) ? ? ? strncmp((s1), (s2), (l))
>> > +#define of_prop_cmp(s1, s2) ? ? ? ? ? ?strcasecmp((s1), (s2))
>> > +#define of_node_cmp(s1, s2) ? ? ? ? ? ?strcmp((s1), (s2))
>>
>> Ditto here?
>
> They're based upon what the old promfs patch used. ?I need to test and
> verify that strings are being mangled in the same way before I start
> making changes here.
The defaults should do the right thing. I would be very surprised if
stfncmp() was what you wanted to use because truncates compatible
values on compare. I believe Sparc has historical reasons for using
it, but new platforms shouldn't need it.
On that point, I think I'm going to change the default override to
specifically test for CONFIG_SPARC instead of doing the weird
defined(OF_ROOT_NODE_ADDR_CELLS_DEFAULT)/defined(of_compat_cmp) I
currently have it doing. That would probably make this separate
header completely unnecessary (see below).
>> > +extern void prom_build_devicetree(void);
>> > +
>> > +extern void *prom_early_alloc(unsigned long size);
>> > +
>> > +extern char *prom_firstprop(phandle node, char *buf);
>> > +extern char *prom_nextprop(phandle node, const char *prev, char
>> > *buf); +extern int prom_getproplen(phandle node, const char *prop);
>> > +extern int prom_getproperty(phandle node, const char *prop,
>> > + ? ? ? ? ? ? ? ? ? ? ? ? ? ?char *buffer, int bufsize);
>> > +extern phandle prom_getchild(phandle node);
>> > +extern phandle prom_getsibling(phandle node);
>> > +
>> > +#endif /* __KERNEL__ */
>> > +#endif /* _X86_PROM_OLPC_H */
>> > diff --git a/arch/x86/include/asm/prom.h
>> > b/arch/x86/include/asm/prom.h new file mode 100644
>> > index 0000000..7b561b2
>> > --- /dev/null
>> > +++ b/arch/x86/include/asm/prom.h
>> > @@ -0,0 +1,5 @@
>> > +#ifdef CONFIG_OLPC_OPENFIRMWARE
>> > +# include <asm/olpc_prom.h>
>> > +#else
>> > +# error "No OFW prom defined for x86!"
>> > +#endif
>>
>> Personally, I wouldn't bother with the header file redirection.
>
> The reason for the header file redirection is because this is
> OLPC-only; the x86 folks don't want me claiming this to be the One
> True x86 OFW.
However, the #ifdef/#elseif/#else/#endif approach also makes the
assumption that only one kind of OFW will be supported by any given
kernel. Or for that matter, both OFW and the flattened tree also
become mutually exclusive due to the default behaviour override.
Besides, aren't the function declarations just the interface defined
by the prom extraction code? Is there any need to #ifdef that API? I
would think those function prototypes should be defined by the header
for the prom extraction code.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
On Wed, 30 Jun 2010 15:13:26 -0600
Grant Likely <[email protected]> wrote:
> On Tue, Jun 29, 2010 at 8:23 AM, Andres Salomon <[email protected]>
> wrote:
> > On Tue, 29 Jun 2010 01:12:36 -0700
> > Grant Likely <[email protected]> wrote:
[...]
> >> > +extern void prom_build_devicetree(void);
> >> > +
> >> > +extern void *prom_early_alloc(unsigned long size);
> >> > +
> >> > +extern char *prom_firstprop(phandle node, char *buf);
> >> > +extern char *prom_nextprop(phandle node, const char *prev, char
> >> > *buf); +extern int prom_getproplen(phandle node, const char
> >> > *prop); +extern int prom_getproperty(phandle node, const char
> >> > *prop,
> >> > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â char *buffer, int bufsize);
> >> > +extern phandle prom_getchild(phandle node);
> >> > +extern phandle prom_getsibling(phandle node);
> >> > +
> >> > +#endif /* __KERNEL__ */
> >> > +#endif /* _X86_PROM_OLPC_H */
> >> > diff --git a/arch/x86/include/asm/prom.h
> >> > b/arch/x86/include/asm/prom.h new file mode 100644
> >> > index 0000000..7b561b2
> >> > --- /dev/null
> >> > +++ b/arch/x86/include/asm/prom.h
> >> > @@ -0,0 +1,5 @@
> >> > +#ifdef CONFIG_OLPC_OPENFIRMWARE
> >> > +# include <asm/olpc_prom.h>
> >> > +#else
> >> > +# error "No OFW prom defined for x86!"
> >> > +#endif
> >>
> >> Personally, I wouldn't bother with the header file redirection.
> >
> > The reason for the header file redirection is because this is
> > OLPC-only; the x86 folks don't want me claiming this to be the One
> > True x86 OFW.
>
> However, the #ifdef/#elseif/#else/#endif approach also makes the
> assumption that only one kind of OFW will be supported by any given
> kernel. Or for that matter, both OFW and the flattened tree also
> become mutually exclusive due to the default behaviour override.
>
> Besides, aren't the function declarations just the interface defined
> by the prom extraction code? Is there any need to #ifdef that API? I
> would think those function prototypes should be defined by the header
> for the prom extraction code.
Mm, both are good points; I suppose for now it doesn't hurt to lose the
#ifdefs, and deal w/ additional x86 proms support if it comes up.
On Tue, Jun 29, 2010 at 5:36 PM, Andres Salomon <[email protected]> wrote:
> On Tue, 29 Jun 2010 15:42:54 -0600
> Grant Likely <[email protected]> wrote:
>
>> On Tue, Jun 29, 2010 at 9:03 AM, Andres Salomon <[email protected]>
>> wrote:
> [...]
>>
>> > ?Sparc and OLPC have very similar
>> > mechanisms for getting device tree info from OFW, so it makes sense
>> > to share code between them.
>>
>> Other than the flattened tree step; is the powerpc method dissimilar
>> from the Sparc and OLPC method for talking to OFW? ?(This is not a
>> rhetorical question, I'm want to know if I'm missing some details).
>> The main difference I know about is that OFW can still kept alive at
>> runtime for sparc, which powerpc does not do. ?However, keeping OFW
>> callable is a separate issue from how to extract the device tree.
>>
>
> After having a look at powerpc's flatten_device_tree, I don't see any
> obvious reason why OLPC couldn't use this
Okay.
>(though it still strikes me
> as weird to go from prom->fdt->dt when the option of prom->dt is
> available and less complex).
Which is why I didn't simply NACK it out of hand. It is a valid point.
I'd probably be happier if both fdt and pdt used a shared set of
utility functions for allocating and tying together the device_node
data structures. Then at least there would be only one instance of
code to deal with the fiddly data structure interconnections.
The nice thing about the powerpc version is that the tree can be
extracted really early in the boot process, before any of the core
kernel infrastructure or memory management is initialized.
> Do you already have the patches that put
> this into drivers/of/?
No.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
On Wed, 30 Jun 2010 15:52:51 -0600
Grant Likely <[email protected]> wrote:
> On Tue, Jun 29, 2010 at 5:36 PM, Andres Salomon <[email protected]>
> wrote:
> > On Tue, 29 Jun 2010 15:42:54 -0600
> > Grant Likely <[email protected]> wrote:
> >
> >> On Tue, Jun 29, 2010 at 9:03 AM, Andres Salomon
> >> <[email protected]> wrote:
> > [...]
> >>
> >> > ?Sparc and OLPC have very similar
> >> > mechanisms for getting device tree info from OFW, so it makes
> >> > sense to share code between them.
> >>
> >> Other than the flattened tree step; is the powerpc method
> >> dissimilar from the Sparc and OLPC method for talking to OFW?
> >> ?(This is not a rhetorical question, I'm want to know if I'm
> >> missing some details). The main difference I know about is that
> >> OFW can still kept alive at runtime for sparc, which powerpc does
> >> not do. ?However, keeping OFW callable is a separate issue from
> >> how to extract the device tree.
> >>
> >
> > After having a look at powerpc's flatten_device_tree, I don't see
> > any obvious reason why OLPC couldn't use this
>
> Okay.
>
> >(though it still strikes me
> > as weird to go from prom->fdt->dt when the option of prom->dt is
> > available and less complex).
>
> Which is why I didn't simply NACK it out of hand. It is a valid
> point.
>
> I'd probably be happier if both fdt and pdt used a shared set of
> utility functions for allocating and tying together the device_node
> data structures. Then at least there would be only one instance of
> code to deal with the fiddly data structure interconnections.
The problem with unifying it is that both methods have different
assumptions; the fdt determines the size of the unflattened dt in
advance, and allocates a contiguous block of memory up front (the
memory block being smaller than the pdt memory usage because various
strings are already present in the fdt, so the unflattened tree simply
points at those strings). The pdt, otoh, allocates more memory as the
tree is discovered (by calling into the prom).
Possible options include:
- For the pdt, calling into the prom twice for each property/node,
getting the size of everything during the first tree traversal,
allocating memory, and then creating the tree during the second
traversal. This is slow and I don't see much point to it.
- For the pdt, calling into the prom once for each property/node to
create a fdt, and then unflattening it. This is better than the
previous option, but I don't think the prom->fdt code will be very
nice.
- Changing the fdt code to allocate memory more dynamically; rather
than a first run through the fdt to determine the unflattened tree
size, simply allocate memory chunks as we run through the tree.
Memory might still be backed the same way (calling
early_init_dt_alloc_memory_arch to grab a chunk of memory, and then
allocating chunks of it via unflatten_dt_alloc), but the difference
would be that it wouldn't necessarily be contiguous, and in how it's
done. For example, early_init_dt_alloc_memory_arch might be called
initially to allocate a 16k chunk, and once unflatten_dt_alloc runs
out of memory in that chunk, another 16k chunk might be allocated.
This would also translate to sparc's prom_early_alloc being used to
allocate the chunk, and then node/property structs being
allocated from those chunks. (The 16k choice
is completely arbitrary; people more familiar w/ the early memory
setup of ppc/sparc might have a better suggestion)
That last option is what I think makes the most sense; however, are
there technical reasons (other than how unflatten_device_tree is
written) that the unflattened dt must be in a contiguous memory
region? The chunk allocation code would be backed by things like
__alloc_bootmem and lmb_alloc, and the dt_alloc code would be new code
that simply tracks the amount remaining in a list of chunks, and
allocates a new chunk if necessary.
>
> The nice thing about the powerpc version is that the tree can be
> extracted really early in the boot process, before any of the core
> kernel infrastructure or memory management is initialized.
>
From: Andres Salomon <[email protected]>
Date: Wed, 7 Jul 2010 04:07:34 +0000
> - For the pdt, calling into the prom once for each property/node to
> create a fdt, and then unflattening it. This is better than the
> previous option, but I don't think the prom->fdt code will be very
> nice.
I'll need this on sparc64 at some point to support kexec() anyways.
So at least for sparc you can assume that a something-->fdt translator
is going to exist at some point in the future regardless of what
happens here.
On Mon, 05 Jul 2010 19:22:21 -0700 (PDT)
David Miller <[email protected]> wrote:
> From: Andres Salomon <[email protected]>
> Date: Wed, 7 Jul 2010 04:07:34 +0000
>
> > - For the pdt, calling into the prom once for each property/node to
> > create a fdt, and then unflattening it. This is better than the
> > previous option, but I don't think the prom->fdt code will be
> > very nice.
>
> I'll need this on sparc64 at some point to support kexec() anyways.
>
> So at least for sparc you can assume that a something-->fdt translator
> is going to exist at some point in the future regardless of what
> happens here.
>
Sounds like we have a winner. I'll concentrate on that, thanks for
the heads up.
On Mon, Jul 5, 2010 at 8:22 PM, David Miller <[email protected]> wrote:
> From: Andres Salomon <[email protected]>
> Date: Wed, 7 Jul 2010 04:07:34 +0000
>
>> ?- For the pdt, calling into the prom once for each property/node to
>> ? ?create a fdt, and then unflattening it. ?This is better than the
>> ? ?previous option, but I don't think the prom->fdt code will be very
>> ? ?nice.
>
> I'll need this on sparc64 at some point to support kexec() anyways.
>
> So at least for sparc you can assume that a something-->fdt translator
> is going to exist at some point in the future regardless of what
> happens here.
Hi David,
I'm curious... what are your plans here? Will you be keeping OF alive
between kexec()? Will the new kernel get the entire device tree from
fdt, or will it still be talking to OF? How will the fdt fragments as
Andres described above fit into sparc kexec (as opposed to generating
one big tree as in his first option)?
Cheers,
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
From: Grant Likely <[email protected]>
Date: Tue, 6 Jul 2010 01:00:06 -0600
> I'm curious... what are your plans here? Will you be keeping OF alive
> between kexec()? Will the new kernel get the entire device tree from
> fdt, or will it still be talking to OF? How will the fdt fragments as
> Andres described above fit into sparc kexec (as opposed to generating
> one big tree as in his first option)?
On certain sparc64 systems, I have to stop making PROM calls early
in the boot right after I fetch the device tree into the kernel.
So yes for a kexec() I'll have to pass an fdt or similar to the
child kernel.
It could be a big linear fdt buffer, or fragments, it really doesn't
matter all that much actually.
On Tue, Jul 6, 2010 at 1:16 AM, David Miller <[email protected]> wrote:
> From: Grant Likely <[email protected]>
> Date: Tue, 6 Jul 2010 01:00:06 -0600
>
>> I'm curious... what are your plans here? ?Will you be keeping OF alive
>> between kexec()? ?Will the new kernel get the entire device tree from
>> fdt, or will it still be talking to OF? ?How will the fdt fragments as
>> Andres described above fit into sparc kexec (as opposed to generating
>> one big tree as in his first option)?
>
> On certain sparc64 systems, I have to stop making PROM calls early
> in the boot right after I fetch the device tree into the kernel.
>
> So yes for a kexec() I'll have to pass an fdt or similar to the
> child kernel.
>
> It could be a big linear fdt buffer, or fragments, it really doesn't
> matter all that much actually.
Okay. There is already support for getting the tree out of the kernel
and into fdt form via procfs. Userspace can also modify it before
sending it back to kexec(). This will be easy no matter which
approach Andres uses.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
On Tue, Jul 6, 2010 at 10:07 PM, Andres Salomon <[email protected]> wrote:
> On Wed, 30 Jun 2010 15:52:51 -0600
> Grant Likely <[email protected]> wrote:
> ?- For the pdt, calling into the prom twice for each property/node,
> ? getting the size of everything during the first tree traversal,
> ? allocating memory, and then creating the tree during the second
> ? traversal. This is slow and I don't see much point to it.
>
> ?- For the pdt, calling into the prom once for each property/node to
> ? create a fdt, and then unflattening it. ?This is better than the
> ? previous option, but I don't think the prom->fdt code will be very
> ? nice.
No, don't do this. It will be ugly.
> ?- Changing the fdt code to allocate memory more dynamically; rather
> ? than a first run through the fdt to determine the unflattened tree
> ? size, simply allocate memory chunks as we run through the tree.
> ? Memory might still be backed the same way (calling
> ? early_init_dt_alloc_memory_arch to grab a chunk of memory, and then
> ? allocating chunks of it via unflatten_dt_alloc), but the difference
> ? would be that it wouldn't necessarily be contiguous, and in how it's
> ? done. ?For example, early_init_dt_alloc_memory_arch might be called
> ? initially to allocate a 16k chunk, and once unflatten_dt_alloc runs
> ? out of memory in that chunk, another 16k chunk might be allocated.
> ? This would also translate to sparc's prom_early_alloc being used to
> ? allocate the chunk, and then node/property structs being
> ? allocated from those chunks. ?(The 16k choice
> ? is completely arbitrary; people more familiar w/ the early memory
> ? setup of ppc/sparc might have a better suggestion)
I'm fine with option 3, but it is more complicated and the code for
option 1 already exists. In fact, option 1 is almost of a
pre-requisite for doing option 3. It makes sense to get the
double-pass method factored out of powerpc and working before
attempting the performance enhancement of option 3.
Note however, the fdt data format parser expects a single contiguous
region. You'll want to copy it into a single region before parsing
it.
That Being Said....
I just finished talking with Ben about the parser code. There is no
immediate imperative to generalizing the powerpc OF->fdt->unflatten
code (unless David decides it makes sense for sparc too), and the
possibility of an ARM machine using it is theoretical enough that I'm
just not going to waste cycles thinking about it. If the situation
changes in a couple of year or two, then it can be refactored.
That clears the way for your original pdt patch. It will need to be
respun for Stephen's CONFIG_OF changes, and I have some other
comments, but I'll reply to the patches directly for those.
Cheers,
g.
On Mon, Jun 28, 2010 at 8:00 PM, Andres Salomon <[email protected]> wrote:
>
> Stick code into drivers/of/pdt.c (Prom Device Tree) that other
> architectures with OpenFirmware resident in memory can make use of.
>
> Signed-off-by: Andres Salomon <[email protected]>
Some more comments below...
BTW, for the changes, you might what to split this patch into two
pieces. One to verbatim copy the code from prom_common.c, and a
second to adapt it for non-sparc. That will make the changes obvious
to future readers. It will also make review easier.
> ---
> ?arch/sparc/Kconfig ? ? ? ? ? ? ?| ? ?1 +
> ?arch/sparc/include/asm/prom.h ? | ? 15 +++-
> ?arch/sparc/kernel/prom.h ? ? ? ?| ? 14 ---
> ?arch/sparc/kernel/prom_common.c | ?173 +------------------------------
> ?drivers/of/Kconfig ? ? ? ? ? ? ?| ? ?4 +
> ?drivers/of/Makefile ? ? ? ? ? ? | ? ?1 +
> ?drivers/of/pdt.c ? ? ? ? ? ? ? ?| ?225 +++++++++++++++++++++++++++++++++++++++
> ?include/linux/of_pdt.h ? ? ? ? ?| ? 37 +++++++
> ?8 files changed, 282 insertions(+), 188 deletions(-)
> ?create mode 100644 drivers/of/pdt.c
> ?create mode 100644 include/linux/of_pdt.h
>
> diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
> index 6f1470b..b4cb63b 100644
> --- a/arch/sparc/Kconfig
> +++ b/arch/sparc/Kconfig
> @@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUS
>
> ?config OF
> ? ? ? ?def_bool y
> + ? ? ? select OF_PROMTREE
>
> ?config ARCH_SUPPORTS_DEBUG_PAGEALLOC
> ? ? ? ?def_bool y if SPARC64
> diff --git a/arch/sparc/include/asm/prom.h b/arch/sparc/include/asm/prom.h
> index f845828..0834c2a 100644
> --- a/arch/sparc/include/asm/prom.h
> +++ b/arch/sparc/include/asm/prom.h
> @@ -18,6 +18,7 @@
> ?* 2 of the License, or (at your option) any later version.
> ?*/
> ?#include <linux/types.h>
> +#include <linux/of_pdt.h>
> ?#include <linux/proc_fs.h>
> ?#include <linux/mutex.h>
> ?#include <asm/atomic.h>
> @@ -65,8 +66,18 @@ extern struct device_node *of_console_device;
> ?extern char *of_console_path;
> ?extern char *of_console_options;
>
> -extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
> -extern char *build_full_name(struct device_node *dp);
> +/* stuff used by of/pdt */
> +extern void * prom_early_alloc(unsigned long size);
> +extern void irq_trans_init(struct device_node *dp);
> +extern char *build_path_component(struct device_node *dp);
> +
> +extern char *prom_firstprop(int node, char *buffer);
> +extern char *prom_nextprop(int node, const char *oprop, char *buffer);
> +extern int prom_getproplen(int node, const char *prop);
> +extern int prom_getproperty(int node, const char *prop,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? char *buffer, int bufsize);
> +extern int prom_getchild(int node);
> +extern int prom_getsibling(int node);
These become the API required by of/pdt. They should be defined in a
arch-independent header file. Something like include/linux/of_pdt.h
Right now only OLPC will be using this, so static function definitions
are just fine. However, if there is ever more than one method for
talking to OFW, then these hooks will need to be converted into an ops
structure so the right one can be passed in at runtime.
> diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
> new file mode 100644
> index 0000000..b24167f
> --- /dev/null
> +++ b/drivers/of/pdt.c
> @@ -0,0 +1,225 @@
> +/*
> + * Paul Mackerras ? ? ?August 1996.
> + * Copyright (C) 1996-2005 Paul Mackerras.
> + *
> + * ?Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
> + * ? ?{engebret|bergner}@us.ibm.com
> + *
> + * ?Adapted for sparc by David S. Miller [email protected]
> + * ?Adapted for multiple architectures by Andres Salomon <[email protected]>
> + *
> + * ? ? ?This program is free software; you can redistribute it and/or
> + * ? ? ?modify it under the terms of the GNU General Public License
> + * ? ? ?as published by the Free Software Foundation; either version
> + * ? ? ?2 of the License, or (at your option) any later version.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/errno.h>
> +#include <linux/mutex.h>
> +#include <linux/slab.h>
> +#include <linux/of.h>
> +#include <linux/of_pdt.h>
> +#include <asm/prom.h>
> +
> +/* TODO: mark this stuff as __initdata */
> +void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
So do it. :-)
> +
> +#if defined(CONFIG_SPARC)
> +static unsigned int prom_unique_id;
> +
> +#define inc_unique_id(p) do { \
> + ? ? ? (p)->unique_id = prom_unique_id++; \
> +} while (0)
> +
> +static inline const char *fetch_node_name(struct device_node *dp)
> +{
> + ? ? ? return dp->path_component_name;
> +}
> +
> +#else
> +
> +#define inc_unique_id(p) ? ? ? do { } while(0)
Use an empty static inline instead.
> +
> +static inline const char *fetch_node_name(struct device_node *dp)
> +{
> + ? ? ? return dp->name;
> +}
> +
> +static inline void irq_trans_init(struct device_node *dp)
> +{
> + ? ? ? /* unused on non-SPARC architectures */
> +}
> +
> +#endif /* !CONFIG_SPARC */
> +
> +static struct property * __init build_one_prop(phandle node, char *prev,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?char *special_name,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?void *special_val,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?int special_len)
I'd like to see all the static symbols in this file prefixed with
something unique to avoid collisions with the global namespace.
of_pdt_* would be good. I'm doing this with the other files in
drivers/of whenever I can too.
> +{
> + ? ? ? static struct property *tmp = NULL;
> + ? ? ? struct property *p;
> + ? ? ? const char *name;
> +
> + ? ? ? if (tmp) {
> + ? ? ? ? ? ? ? p = tmp;
> + ? ? ? ? ? ? ? memset(p, 0, sizeof(*p) + 32);
> + ? ? ? ? ? ? ? tmp = NULL;
> + ? ? ? } else {
> + ? ? ? ? ? ? ? p = prom_early_alloc(sizeof(struct property) + 32);
> + ? ? ? ? ? ? ? inc_unique_id(p);
> + ? ? ? }
> +
> + ? ? ? p->name = (char *) (p + 1);
> + ? ? ? if (special_name) {
> + ? ? ? ? ? ? ? strcpy(p->name, special_name);
> + ? ? ? ? ? ? ? p->length = special_len;
> + ? ? ? ? ? ? ? p->value = prom_early_alloc(special_len);
> + ? ? ? ? ? ? ? memcpy(p->value, special_val, special_len);
> + ? ? ? } else {
> + ? ? ? ? ? ? ? if (prev == NULL) {
> + ? ? ? ? ? ? ? ? ? ? ? name = prom_firstprop(node, p->name);
> + ? ? ? ? ? ? ? } else {
> + ? ? ? ? ? ? ? ? ? ? ? name = prom_nextprop(node, prev, p->name);
> + ? ? ? ? ? ? ? }
> +
> + ? ? ? ? ? ? ? if (!name || strlen(name) == 0) {
> + ? ? ? ? ? ? ? ? ? ? ? tmp = p;
> + ? ? ? ? ? ? ? ? ? ? ? return NULL;
> + ? ? ? ? ? ? ? }
> +#ifdef CONFIG_SPARC32
> + ? ? ? ? ? ? ? strcpy(p->name, name);
> +#endif
> + ? ? ? ? ? ? ? p->length = prom_getproplen(node, p->name);
> + ? ? ? ? ? ? ? if (p->length <= 0) {
> + ? ? ? ? ? ? ? ? ? ? ? p->length = 0;
> + ? ? ? ? ? ? ? } else {
> + ? ? ? ? ? ? ? ? ? ? ? int len;
> +
> + ? ? ? ? ? ? ? ? ? ? ? p->value = prom_early_alloc(p->length + 1);
> + ? ? ? ? ? ? ? ? ? ? ? len = prom_getproperty(node, p->name, p->value,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?p->length);
> + ? ? ? ? ? ? ? ? ? ? ? if (len <= 0)
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? p->length = 0;
> + ? ? ? ? ? ? ? ? ? ? ? ((unsigned char *)p->value)[p->length] = '\0';
> + ? ? ? ? ? ? ? }
> + ? ? ? }
> + ? ? ? return p;
> +}
> +
> +static struct property * __init build_prop_list(phandle node)
> +{
> + ? ? ? struct property *head, *tail;
> +
> + ? ? ? head = tail = build_one_prop(node, NULL,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?".node", &node, sizeof(node));
> +
> + ? ? ? tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
> + ? ? ? tail = tail->next;
> + ? ? ? while(tail) {
> + ? ? ? ? ? ? ? tail->next = build_one_prop(node, tail->name,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL, NULL, 0);
> + ? ? ? ? ? ? ? tail = tail->next;
> + ? ? ? }
> +
> + ? ? ? return head;
> +}
> +
> +static char * __init get_one_property(phandle node, const char *name)
> +{
> + ? ? ? char *buf = "<NULL>";
> + ? ? ? int len;
> +
> + ? ? ? len = prom_getproplen(node, name);
> + ? ? ? if (len > 0) {
> + ? ? ? ? ? ? ? buf = prom_early_alloc(len);
> + ? ? ? ? ? ? ? len = prom_getproperty(node, name, buf, len);
> + ? ? ? }
> +
> + ? ? ? return buf;
> +}
> +
> +struct device_node * __init prom_create_node(phandle node,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct device_node *parent)
> +{
> + ? ? ? struct device_node *dp;
> +
> + ? ? ? if (!node)
> + ? ? ? ? ? ? ? return NULL;
> +
> + ? ? ? dp = prom_early_alloc(sizeof(*dp));
> + ? ? ? inc_unique_id(dp);
> + ? ? ? dp->parent = parent;
> +
> + ? ? ? kref_init(&dp->kref);
> +
> + ? ? ? dp->name = get_one_property(node, "name");
> + ? ? ? dp->type = get_one_property(node, "device_type");
> + ? ? ? dp->phandle = node;
> +
> + ? ? ? dp->properties = build_prop_list(node);
> +
> + ? ? ? irq_trans_init(dp);
> +
> + ? ? ? return dp;
> +}
> +
> +static char * __init build_full_name(struct device_node *dp)
> +{
> + ? ? ? int len, ourlen, plen;
> + ? ? ? char *n;
> +
> + ? ? ? plen = strlen(dp->parent->full_name);
> + ? ? ? ourlen = strlen(fetch_node_name(dp));
> + ? ? ? len = ourlen + plen + 2;
> +
> + ? ? ? n = prom_early_alloc(len);
> + ? ? ? strcpy(n, dp->parent->full_name);
> + ? ? ? if (!is_root_node(dp->parent)) {
> + ? ? ? ? ? ? ? strcpy(n + plen, "/");
> + ? ? ? ? ? ? ? plen++;
> + ? ? ? }
> + ? ? ? strcpy(n + plen, fetch_node_name(dp));
> +
> + ? ? ? return n;
> +}
> +
> +struct device_node * __init prom_build_tree(struct device_node *parent,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? phandle node,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct device_node ***nextp)
> +{
> + ? ? ? struct device_node *ret = NULL, *prev_sibling = NULL;
> + ? ? ? struct device_node *dp;
> +
> + ? ? ? while (1) {
> + ? ? ? ? ? ? ? dp = prom_create_node(node, parent);
> + ? ? ? ? ? ? ? if (!dp)
> + ? ? ? ? ? ? ? ? ? ? ? break;
> +
> + ? ? ? ? ? ? ? if (prev_sibling)
> + ? ? ? ? ? ? ? ? ? ? ? prev_sibling->sibling = dp;
> +
> + ? ? ? ? ? ? ? if (!ret)
> + ? ? ? ? ? ? ? ? ? ? ? ret = dp;
> + ? ? ? ? ? ? ? prev_sibling = dp;
> +
> + ? ? ? ? ? ? ? *(*nextp) = dp;
> + ? ? ? ? ? ? ? *nextp = &dp->allnext;
> +
> +#if defined(CONFIG_SPARC)
> + ? ? ? ? ? ? ? dp->path_component_name = build_path_component(dp);
> +#endif
> + ? ? ? ? ? ? ? dp->full_name = build_full_name(dp);
> +
> + ? ? ? ? ? ? ? dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
> +
> + ? ? ? ? ? ? ? if (prom_build_more)
> + ? ? ? ? ? ? ? ? ? ? ? prom_build_more(dp, nextp);
> +
> + ? ? ? ? ? ? ? node = prom_getsibling(node);
> + ? ? ? }
> +
> + ? ? ? return ret;
> +}
prom_build_devicetree() should also be factored out.
> diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
> new file mode 100644
> index 0000000..f62616e
> --- /dev/null
> +++ b/include/linux/of_pdt.h
> @@ -0,0 +1,37 @@
> +#include <linux/of.h> ?/* linux/of.h gets to determine #include ordering */
Do you really need this #include in this way? Can it be moved inside
the #ifndef OF_PDT block below?
> +/*
> + * Definitions for building a device tree by calling into the
> + * Open Firmware PROM.
> + *
> + * Copyright (C) 1996-2005 Paul Mackerras.
> + * Copyright (C) 2010 ?Andres Salomon <[email protected]>
> + *
> + * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
> + * Updates for SPARC by David S. Miller
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version
> + * 2 of the License, or (at your option) any later version.
> + */
> +
> +#ifndef _LINUX_OF_PDT_H
> +#define _LINUX_OF_PDT_H
> +
> +extern struct device_node *prom_create_node(phandle node,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct device_node *parent);
> +extern struct device_node *prom_build_tree(struct device_node *parent,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?phandle node,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct device_node ***nextp);
> +
> +extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
> +
> +static inline int is_root_node(const struct device_node *dp)
> +{
> + ? ? ? if (!dp)
> + ? ? ? ? ? ? ? return 0;
> +
> + ? ? ? return (dp->parent == NULL);
> +}
This doesn't look like a pdt specific function, it could go in
include/linux/of.h.
Another general comment, I'm still not thrilled with this code having
its own independent method for building the tree, but I doubt the
existing add/remove nodes and properties code is usable early enough
to be suitable for sparc. How early do you extract the device tree on
OLPC? How are you going to use the data?
Anyway, enough comments for tonight. I'll may have more on then next
round. Time to go to bed.
g.
> Sounds like we have a winner. I'll concentrate on that, thanks for
> the heads up.
Note that the conversion from OF -> fdt that powerpc does is a bit
"special". The code isn't quite a "wrapper" but almost. It shared pretty
much no symbols or variables with the rest of the kernel.
There are various reasons for that. It has to run -very- early, in fact,
before we do anything else at boot time, since we run off OF existing
environment (stack etc...) at at whatever address the kernel is loaded,
ie. before we relocate it down to 0.
To deal with that, we use compile/linker tricks to generate
pseudo-relocatable code (with limitations) and funny macros when
accessing global symbols.
In addition, we have various workarounds for powerpc specific
implementation issues (OF bugs, but also instanciating the IOMMU tables
on Power4, starting secondary CPUs and parking them in a wait loop,
etc...).
Thus I'm not sure there's that much benefit in trying to make that code
common with other archs, and possibly a lot of pain involved.
Cheers,
Ben.
On Tue, 6 Jul 2010 03:21:21 -0600
Grant Likely <[email protected]> wrote:
> On Mon, Jun 28, 2010 at 8:00 PM, Andres Salomon <[email protected]>
> wrote:
> >
> > Stick code into drivers/of/pdt.c (Prom Device Tree) that other
> > architectures with OpenFirmware resident in memory can make use of.
> >
> > Signed-off-by: Andres Salomon <[email protected]>
>
> Some more comments below...
>
Thanks for the review!
> > ?arch/sparc/Kconfig ? ? ? ? ? ? ?| ? ?1 +
> > ?arch/sparc/include/asm/prom.h ? | ? 15 +++-
> > ?arch/sparc/kernel/prom.h ? ? ? ?| ? 14 ---
> > ?arch/sparc/kernel/prom_common.c | ?173
> > +------------------------------ drivers/of/Kconfig ? ? ? ? ? ? ?|
> > ?4 + drivers/of/Makefile ? ? ? ? ? ? | ? ?1 +
> > ?drivers/of/pdt.c ? ? ? ? ? ? ? ?| ?225
> > +++++++++++++++++++++++++++++++++++++++ include/linux/of_pdt.h
> > ? ? ?| ? 37 +++++++ 8 files changed, 282 insertions(+), 188
> > deletions(-) create mode 100644 drivers/of/pdt.c
> > ?create mode 100644 include/linux/of_pdt.h
> >
> > diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
> > index 6f1470b..b4cb63b 100644
> > --- a/arch/sparc/Kconfig
> > +++ b/arch/sparc/Kconfig
> > @@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUS
> >
> > ?config OF
> > ? ? ? ?def_bool y
> > + ? ? ? select OF_PROMTREE
> >
> > ?config ARCH_SUPPORTS_DEBUG_PAGEALLOC
> > ? ? ? ?def_bool y if SPARC64
> > diff --git a/arch/sparc/include/asm/prom.h
> > b/arch/sparc/include/asm/prom.h index f845828..0834c2a 100644
> > --- a/arch/sparc/include/asm/prom.h
> > +++ b/arch/sparc/include/asm/prom.h
> > @@ -18,6 +18,7 @@
> > ?* 2 of the License, or (at your option) any later version.
> > ?*/
> > ?#include <linux/types.h>
> > +#include <linux/of_pdt.h>
> > ?#include <linux/proc_fs.h>
> > ?#include <linux/mutex.h>
> > ?#include <asm/atomic.h>
> > @@ -65,8 +66,18 @@ extern struct device_node *of_console_device;
> > ?extern char *of_console_path;
> > ?extern char *of_console_options;
> >
> > -extern void (*prom_build_more)(struct device_node *dp, struct
> > device_node ***nextp); -extern char *build_full_name(struct
> > device_node *dp); +/* stuff used by of/pdt */
> > +extern void * prom_early_alloc(unsigned long size);
> > +extern void irq_trans_init(struct device_node *dp);
> > +extern char *build_path_component(struct device_node *dp);
> > +
> > +extern char *prom_firstprop(int node, char *buffer);
> > +extern char *prom_nextprop(int node, const char *oprop, char
> > *buffer); +extern int prom_getproplen(int node, const char *prop);
> > +extern int prom_getproperty(int node, const char *prop,
> > + ? ? ? ? ? ? ? ? ? ? ? ? ? char *buffer, int bufsize);
> > +extern int prom_getchild(int node);
> > +extern int prom_getsibling(int node);
>
> These become the API required by of/pdt. They should be defined in a
> arch-independent header file. Something like include/linux/of_pdt.h
>
> Right now only OLPC will be using this, so static function definitions
> are just fine. However, if there is ever more than one method for
> talking to OFW, then these hooks will need to be converted into an ops
> structure so the right one can be passed in at runtime.
>
Note that sparc and OLPC actually use slightly different function
signatures; OLPC uses phandles for nodes, while sparc uses ints. Not a
huge difference, but enough that I didn't want to mess w/ a generic
version of it early in the process. I agree that op structs would be
nicer, and will probably move towards that.
[...]
> > diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
> > new file mode 100644
> > index 0000000..f62616e
> > --- /dev/null
> > +++ b/include/linux/of_pdt.h
> > @@ -0,0 +1,37 @@
> > +#include <linux/of.h> ?/* linux/of.h gets to determine #include
> > ordering */
>
> Do you really need this #include in this way? Can it be moved inside
> the #ifndef OF_PDT block below?
>
Not sure, will try out different variants and see what breaks.
[...]
> Another general comment, I'm still not thrilled with this code having
> its own independent method for building the tree, but I doubt the
> existing add/remove nodes and properties code is usable early enough
> to be suitable for sparc. How early do you extract the device tree on
> OLPC? How are you going to use the data?
Not that early; very early code fetches information necessary to call
into the PROM, and ensures that the kernel doesn't clobber OFW's
memory. After that, we can build the dt at any point during init.
The data is to be exported via proc for userspace to use in
determining hardware (and firmware) info.
On Tue, Jul 6, 2010 at 3:54 PM, Andres Salomon <[email protected]> wrote:
> On Tue, 6 Jul 2010 03:21:21 -0600
> Grant Likely <[email protected]> wrote:
>
>> On Mon, Jun 28, 2010 at 8:00 PM, Andres Salomon <[email protected]>
>> wrote:
>> >
>> > Stick code into drivers/of/pdt.c (Prom Device Tree) that other
>> > architectures with OpenFirmware resident in memory can make use of.
>> >
>> > Signed-off-by: Andres Salomon <[email protected]>
>>
>> Some more comments below...
>>
>
> Thanks for the review!
>
>
>
>> > ?arch/sparc/Kconfig ? ? ? ? ? ? ?| ? ?1 +
>> > ?arch/sparc/include/asm/prom.h ? | ? 15 +++-
>> > ?arch/sparc/kernel/prom.h ? ? ? ?| ? 14 ---
>> > ?arch/sparc/kernel/prom_common.c | ?173
>> > +------------------------------ drivers/of/Kconfig ? ? ? ? ? ? ?|
>> > ?4 + drivers/of/Makefile ? ? ? ? ? ? | ? ?1 +
>> > ?drivers/of/pdt.c ? ? ? ? ? ? ? ?| ?225
>> > +++++++++++++++++++++++++++++++++++++++ include/linux/of_pdt.h
>> > ? ? ?| ? 37 +++++++ 8 files changed, 282 insertions(+), 188
>> > deletions(-) create mode 100644 drivers/of/pdt.c
>> > ?create mode 100644 include/linux/of_pdt.h
>> >
>> > diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
>> > index 6f1470b..b4cb63b 100644
>> > --- a/arch/sparc/Kconfig
>> > +++ b/arch/sparc/Kconfig
>> > @@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUS
>> >
>> > ?config OF
>> > ? ? ? ?def_bool y
>> > + ? ? ? select OF_PROMTREE
>> >
>> > ?config ARCH_SUPPORTS_DEBUG_PAGEALLOC
>> > ? ? ? ?def_bool y if SPARC64
>> > diff --git a/arch/sparc/include/asm/prom.h
>> > b/arch/sparc/include/asm/prom.h index f845828..0834c2a 100644
>> > --- a/arch/sparc/include/asm/prom.h
>> > +++ b/arch/sparc/include/asm/prom.h
>> > @@ -18,6 +18,7 @@
>> > ?* 2 of the License, or (at your option) any later version.
>> > ?*/
>> > ?#include <linux/types.h>
>> > +#include <linux/of_pdt.h>
>> > ?#include <linux/proc_fs.h>
>> > ?#include <linux/mutex.h>
>> > ?#include <asm/atomic.h>
>> > @@ -65,8 +66,18 @@ extern struct device_node *of_console_device;
>> > ?extern char *of_console_path;
>> > ?extern char *of_console_options;
>> >
>> > -extern void (*prom_build_more)(struct device_node *dp, struct
>> > device_node ***nextp); -extern char *build_full_name(struct
>> > device_node *dp); +/* stuff used by of/pdt */
>> > +extern void * prom_early_alloc(unsigned long size);
>> > +extern void irq_trans_init(struct device_node *dp);
>> > +extern char *build_path_component(struct device_node *dp);
>> > +
>> > +extern char *prom_firstprop(int node, char *buffer);
>> > +extern char *prom_nextprop(int node, const char *oprop, char
>> > *buffer); +extern int prom_getproplen(int node, const char *prop);
>> > +extern int prom_getproperty(int node, const char *prop,
>> > + ? ? ? ? ? ? ? ? ? ? ? ? ? char *buffer, int bufsize);
>> > +extern int prom_getchild(int node);
>> > +extern int prom_getsibling(int node);
>>
>> These become the API required by of/pdt. ?They should be defined in a
>> arch-independent header file. ?Something like include/linux/of_pdt.h
>>
>> Right now only OLPC will be using this, so static function definitions
>> are just fine. ?However, if there is ever more than one method for
>> talking to OFW, then these hooks will need to be converted into an ops
>> structure so the right one can be passed in at runtime.
>>
>
> Note that sparc and OLPC actually use slightly different function
> signatures; OLPC uses phandles for nodes, while sparc uses ints. ?Not a
> huge difference, but enough that I didn't want to mess w/ a generic
> version of it early in the process.
phandle is simply defined as a u32. It probably wouldn't be difficult
to change the sparc code to use phandle; redefining the type for sparc
if need be.
> ?I agree that op structs would be
> nicer, and will probably move towards that.
>
> [...]
>
>> > diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
>> > new file mode 100644
>> > index 0000000..f62616e
>> > --- /dev/null
>> > +++ b/include/linux/of_pdt.h
>> > @@ -0,0 +1,37 @@
>> > +#include <linux/of.h> ?/* linux/of.h gets to determine #include
>> > ordering */
>>
>> Do you really need this #include in this way? ?Can it be moved inside
>> the #ifndef OF_PDT block below?
>>
>
> Not sure, will try out different variants and see what breaks.
>
> [...]
>
>> Another general comment, I'm still not thrilled with this code having
>> its own independent method for building the tree, but I doubt the
>> existing add/remove nodes and properties code is usable early enough
>> to be suitable for sparc. ?How early do you extract the device tree on
>> OLPC? ?How are you going to use the data?
>
> Not that early; very early code fetches information necessary to call
> into the PROM, and ensures that the kernel doesn't clobber OFW's
> memory. ? After that, we can build the dt at any point during init.
> The data is to be exported via proc for userspace to use in
> determining hardware (and firmware) info.
Okay, so it is only the userspace interface that you're interested in,
correct? You have no needs/plans (as of yet) to register devices out
of the device tree?
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
On Tue, 6 Jul 2010 16:06:54 -0600
Grant Likely <[email protected]> wrote:
[...]
> Okay, so it is only the userspace interface that you're interested in,
> correct? You have no needs/plans (as of yet) to register devices out
> of the device tree?
>
Correct.
Commit-ID: 54e5bc020ce1c959eaa7be18cedb734b6b13745e
Gitweb: http://git.kernel.org/tip/54e5bc020ce1c959eaa7be18cedb734b6b13745e
Author: Andres Salomon <[email protected]>
AuthorDate: Mon, 28 Jun 2010 22:00:29 -0400
Committer: H. Peter Anvin <[email protected]>
CommitDate: Fri, 30 Jul 2010 18:02:21 -0700
x86, olpc: Constify an olpc_ofw() arg
The arguments passed to OFW shouldn't be modified; update the 'args'
argument of olpc_ofw to reflect this. This saves us some later
casting away of consts.
Signed-off-by: Andres Salomon <[email protected]>
LKML-Reference: <20100628220029.1555ac24@debian>
Signed-off-by: H. Peter Anvin <[email protected]>
---
arch/x86/include/asm/olpc_ofw.h | 2 +-
arch/x86/kernel/olpc.c | 2 +-
arch/x86/kernel/olpc_ofw.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/olpc_ofw.h b/arch/x86/include/asm/olpc_ofw.h
index 3e63d85..08fde47 100644
--- a/arch/x86/include/asm/olpc_ofw.h
+++ b/arch/x86/include/asm/olpc_ofw.h
@@ -12,7 +12,7 @@
#define olpc_ofw(name, args, res) \
__olpc_ofw((name), ARRAY_SIZE(args), args, ARRAY_SIZE(res), res)
-extern int __olpc_ofw(const char *name, int nr_args, void **args, int nr_res,
+extern int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res,
void **res);
/* determine whether OFW is available and lives in the proper memory */
diff --git a/arch/x86/kernel/olpc.c b/arch/x86/kernel/olpc.c
index f5ff3903..0e0cdde 100644
--- a/arch/x86/kernel/olpc.c
+++ b/arch/x86/kernel/olpc.c
@@ -188,7 +188,7 @@ static void __init platform_detect(void)
{
size_t propsize;
__be32 rev;
- void *args[] = { NULL, "board-revision-int", &rev, (void *)4 };
+ const void *args[] = { NULL, "board-revision-int", &rev, (void *)4 };
void *res[] = { &propsize };
if (olpc_ofw("getprop", args, res) || propsize != 4) {
diff --git a/arch/x86/kernel/olpc_ofw.c b/arch/x86/kernel/olpc_ofw.c
index f5d499f..3218aa7 100644
--- a/arch/x86/kernel/olpc_ofw.c
+++ b/arch/x86/kernel/olpc_ofw.c
@@ -40,7 +40,7 @@ void __init setup_olpc_ofw_pgd(void)
early_iounmap(base, sizeof(olpc_ofw_pgd) * PTRS_PER_PGD);
}
-int __olpc_ofw(const char *name, int nr_args, void **args, int nr_res,
+int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res,
void **res)
{
int ofw_args[MAXARGS + 3];
These patches modify drivers/of, sparc, and x86 accordingly to add
OLPC device-tree support. Updates have been made based upon Grant and
Davem's comments. They've been compile-tested on sparc64 and x86, and
runtime tested on OLPC machines.
Dave's 25edd6946 commit caused some conflicts w/ patch #2;
hopefully I mangled it properly.
We need phandle for some exported sparc headers; of.h isn't an
exported header, and it would be silly to export it when all we
really need is one or two types from it. So, move the phandle/ihandle
definitions into types.h.
Signed-off-by: Andres Salomon <[email protected]>
---
include/linux/of.h | 3 ---
include/linux/types.h | 4 ++++
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/linux/of.h b/include/linux/of.h
index cad7cf0..db184dc 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -25,9 +25,6 @@
#ifdef CONFIG_OF
-typedef u32 phandle;
-typedef u32 ihandle;
-
struct property {
char *name;
int length;
diff --git a/include/linux/types.h b/include/linux/types.h
index 01a082f..26526ea 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -219,6 +219,10 @@ struct ustat {
char f_fpack[6];
};
+/* Basic openboot/openfirmware types */
+typedef u32 phandle;
+typedef u32 ihandle;
+
#endif /* __KERNEL__ */
#endif /* __ASSEMBLY__ */
#endif /* _LINUX_TYPES_H */
--
1.5.6.5
Rather than passing around ints everywhere, use the
phandle type where appropriate for the various functions
that talk to the PROM.
Note: this has only been compile-tested for 64bit sparc.
Signed-off-by: Andres Salomon <[email protected]>
---
arch/sparc/include/asm/floppy_32.h | 3 +-
arch/sparc/include/asm/openprom.h | 15 +++++----
arch/sparc/include/asm/oplib_32.h | 44 +++++++++++++-------------
arch/sparc/include/asm/oplib_64.h | 39 +++++++++++-----------
arch/sparc/kernel/auxio_32.c | 4 +-
arch/sparc/kernel/btext.c | 4 +-
arch/sparc/kernel/devices.c | 23 +++++++------
arch/sparc/kernel/pcic.c | 4 +-
arch/sparc/kernel/setup_64.c | 2 +-
arch/sparc/kernel/starfire.c | 2 +-
arch/sparc/kernel/tadpole.c | 2 +-
arch/sparc/mm/init_64.c | 2 +-
arch/sparc/mm/srmmu.c | 8 +++--
arch/sparc/mm/sun4c.c | 2 +-
arch/sparc/prom/init_32.c | 2 +-
arch/sparc/prom/init_64.c | 4 +-
arch/sparc/prom/memory.c | 3 +-
arch/sparc/prom/misc_64.c | 6 ++-
arch/sparc/prom/ranges.c | 6 ++--
arch/sparc/prom/tree_32.c | 58 +++++++++++++++++----------------
arch/sparc/prom/tree_64.c | 62 ++++++++++++++++++------------------
drivers/sbus/char/jsflash.c | 2 +-
drivers/video/aty/atyfb_base.c | 3 +-
23 files changed, 156 insertions(+), 144 deletions(-)
diff --git a/arch/sparc/include/asm/floppy_32.h b/arch/sparc/include/asm/floppy_32.h
index c792830..86666f7 100644
--- a/arch/sparc/include/asm/floppy_32.h
+++ b/arch/sparc/include/asm/floppy_32.h
@@ -304,7 +304,8 @@ static struct linux_prom_registers fd_regs[2];
static int sun_floppy_init(void)
{
char state[128];
- int tnode, fd_node, num_regs;
+ phandle tnode, fd_node;
+ int num_regs;
struct resource r;
use_virtual_dma = 1;
diff --git a/arch/sparc/include/asm/openprom.h b/arch/sparc/include/asm/openprom.h
index 963e1a4..667b226 100644
--- a/arch/sparc/include/asm/openprom.h
+++ b/arch/sparc/include/asm/openprom.h
@@ -6,6 +6,7 @@
*
* Copyright (C) 1995,1996 David S. Miller ([email protected])
*/
+#include <linux/types.h>
/* Empirical constants... */
#define LINUX_OPPROM_MAGIC 0x10010407
@@ -26,7 +27,7 @@ struct linux_dev_v0_funcs {
/* V2 and later prom device operations. */
struct linux_dev_v2_funcs {
- int (*v2_inst2pkg)(int d); /* Convert ihandle to phandle */
+ phandle (*v2_inst2pkg)(int d); /* Convert ihandle to phandle */
char * (*v2_dumb_mem_alloc)(char *va, unsigned sz);
void (*v2_dumb_mem_free)(char *va, unsigned sz);
@@ -168,12 +169,12 @@ struct linux_romvec {
/* Routines for traversing the prom device tree. */
struct linux_nodeops {
- int (*no_nextnode)(int node);
- int (*no_child)(int node);
- int (*no_proplen)(int node, const char *name);
- int (*no_getprop)(int node, const char *name, char *val);
- int (*no_setprop)(int node, const char *name, char *val, int len);
- char * (*no_nextprop)(int node, char *name);
+ phandle (*no_nextnode)(phandle node);
+ phandle (*no_child)(phandle node);
+ int (*no_proplen)(phandle node, const char *name);
+ int (*no_getprop)(phandle node, const char *name, char *val);
+ int (*no_setprop)(phandle node, const char *name, char *val, int len);
+ char * (*no_nextprop)(phandle node, char *name);
};
/* More fun PROM structures for device probing. */
diff --git a/arch/sparc/include/asm/oplib_32.h b/arch/sparc/include/asm/oplib_32.h
index 33e31ce..51296a6 100644
--- a/arch/sparc/include/asm/oplib_32.h
+++ b/arch/sparc/include/asm/oplib_32.h
@@ -30,7 +30,7 @@ extern unsigned int prom_rev, prom_prev;
/* Root node of the prom device tree, this stays constant after
* initialization is complete.
*/
-extern int prom_root_node;
+extern phandle prom_root_node;
/* Pointer to prom structure containing the device tree traversal
* and usage utility functions. Only prom-lib should use these,
@@ -178,68 +178,68 @@ extern void prom_putsegment(int context, unsigned long virt_addr,
/* PROM device tree traversal functions... */
/* Get the child node of the given node, or zero if no child exists. */
-extern int prom_getchild(int parent_node);
+extern phandle prom_getchild(phandle parent_node);
/* Get the next sibling node of the given node, or zero if no further
* siblings exist.
*/
-extern int prom_getsibling(int node);
+extern phandle prom_getsibling(phandle node);
/* Get the length, at the passed node, of the given property type.
* Returns -1 on error (ie. no such property at this node).
*/
-extern int prom_getproplen(int thisnode, const char *property);
+extern int prom_getproplen(phandle thisnode, const char *property);
/* Fetch the requested property using the given buffer. Returns
* the number of bytes the prom put into your buffer or -1 on error.
*/
-extern int __must_check prom_getproperty(int thisnode, const char *property,
+extern int __must_check prom_getproperty(phandle thisnode, const char *property,
char *prop_buffer, int propbuf_size);
/* Acquire an integer property. */
-extern int prom_getint(int node, char *property);
+extern int prom_getint(phandle node, char *property);
/* Acquire an integer property, with a default value. */
-extern int prom_getintdefault(int node, char *property, int defval);
+extern int prom_getintdefault(phandle node, char *property, int defval);
/* Acquire a boolean property, 0=FALSE 1=TRUE. */
-extern int prom_getbool(int node, char *prop);
+extern int prom_getbool(phandle node, char *prop);
/* Acquire a string property, null string on error. */
-extern void prom_getstring(int node, char *prop, char *buf, int bufsize);
+extern void prom_getstring(phandle node, char *prop, char *buf, int bufsize);
/* Does the passed node have the given "name"? YES=1 NO=0 */
-extern int prom_nodematch(int thisnode, char *name);
+extern int prom_nodematch(phandle thisnode, char *name);
/* Search all siblings starting at the passed node for "name" matching
* the given string. Returns the node on success, zero on failure.
*/
-extern int prom_searchsiblings(int node_start, char *name);
+extern phandle prom_searchsiblings(phandle node_start, char *name);
/* Return the first property type, as a string, for the given node.
* Returns a null string on error.
*/
-extern char *prom_firstprop(int node, char *buffer);
+extern char *prom_firstprop(phandle node, char *buffer);
/* Returns the next property after the passed property for the given
* node. Returns null string on failure.
*/
-extern char *prom_nextprop(int node, char *prev_property, char *buffer);
+extern char *prom_nextprop(phandle node, char *prev_property, char *buffer);
/* Returns phandle of the path specified */
-extern int prom_finddevice(char *name);
+extern phandle prom_finddevice(char *name);
/* Returns 1 if the specified node has given property. */
-extern int prom_node_has_property(int node, char *property);
+extern int prom_node_has_property(phandle node, char *property);
/* Set the indicated property at the given node with the passed value.
* Returns the number of bytes of your value that the prom took.
*/
-extern int prom_setprop(int node, const char *prop_name, char *prop_value,
+extern int prom_setprop(phandle node, const char *prop_name, char *prop_value,
int value_size);
-extern int prom_pathtoinode(char *path);
-extern int prom_inst2pkg(int);
+extern phandle prom_pathtoinode(char *path);
+extern phandle prom_inst2pkg(int);
/* Dorking with Bus ranges... */
@@ -247,13 +247,13 @@ extern int prom_inst2pkg(int);
extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
/* Apply ranges of any prom node (and optionally parent node as well) to registers. */
-extern void prom_apply_generic_ranges(int node, int parent,
+extern void prom_apply_generic_ranges(phandle node, phandle parent,
struct linux_prom_registers *sbusregs, int nregs);
/* CPU probing helpers. */
-int cpu_find_by_instance(int instance, int *prom_node, int *mid);
-int cpu_find_by_mid(int mid, int *prom_node);
-int cpu_get_hwmid(int prom_node);
+int cpu_find_by_instance(int instance, phandle *prom_node, int *mid);
+int cpu_find_by_mid(int mid, phandle *prom_node);
+int cpu_get_hwmid(phandle prom_node);
extern spinlock_t prom_lock;
diff --git a/arch/sparc/include/asm/oplib_64.h b/arch/sparc/include/asm/oplib_64.h
index 3e0b2d6..c9cc078 100644
--- a/arch/sparc/include/asm/oplib_64.h
+++ b/arch/sparc/include/asm/oplib_64.h
@@ -16,7 +16,7 @@ extern char prom_version[];
/* Root node of the prom device tree, this stays constant after
* initialization is complete.
*/
-extern int prom_root_node;
+extern phandle prom_root_node;
/* PROM stdin and stdout */
extern int prom_stdin, prom_stdout;
@@ -24,7 +24,7 @@ extern int prom_stdin, prom_stdout;
/* /chosen node of the prom device tree, this stays constant after
* initialization is complete.
*/
-extern int prom_chosen_node;
+extern phandle prom_chosen_node;
/* Helper values and strings in arch/sparc64/kernel/head.S */
extern const char prom_peer_name[];
@@ -218,68 +218,69 @@ extern void prom_unmap(unsigned long size, unsigned long vaddr);
/* PROM device tree traversal functions... */
/* Get the child node of the given node, or zero if no child exists. */
-extern int prom_getchild(int parent_node);
+extern phandle prom_getchild(phandle parent_node);
/* Get the next sibling node of the given node, or zero if no further
* siblings exist.
*/
-extern int prom_getsibling(int node);
+extern phandle prom_getsibling(phandle node);
/* Get the length, at the passed node, of the given property type.
* Returns -1 on error (ie. no such property at this node).
*/
-extern int prom_getproplen(int thisnode, const char *property);
+extern int prom_getproplen(phandle thisnode, const char *property);
/* Fetch the requested property using the given buffer. Returns
* the number of bytes the prom put into your buffer or -1 on error.
*/
-extern int prom_getproperty(int thisnode, const char *property,
+extern int prom_getproperty(phandle thisnode, const char *property,
char *prop_buffer, int propbuf_size);
/* Acquire an integer property. */
-extern int prom_getint(int node, const char *property);
+extern int prom_getint(phandle node, const char *property);
/* Acquire an integer property, with a default value. */
-extern int prom_getintdefault(int node, const char *property, int defval);
+extern int prom_getintdefault(phandle node, const char *property, int defval);
/* Acquire a boolean property, 0=FALSE 1=TRUE. */
-extern int prom_getbool(int node, const char *prop);
+extern int prom_getbool(phandle node, const char *prop);
/* Acquire a string property, null string on error. */
-extern void prom_getstring(int node, const char *prop, char *buf, int bufsize);
+extern void prom_getstring(phandle node, const char *prop, char *buf,
+ int bufsize);
/* Does the passed node have the given "name"? YES=1 NO=0 */
-extern int prom_nodematch(int thisnode, const char *name);
+extern int prom_nodematch(phandle thisnode, const char *name);
/* Search all siblings starting at the passed node for "name" matching
* the given string. Returns the node on success, zero on failure.
*/
-extern int prom_searchsiblings(int node_start, const char *name);
+extern phandle prom_searchsiblings(phandle node_start, const char *name);
/* Return the first property type, as a string, for the given node.
* Returns a null string on error. Buffer should be at least 32B long.
*/
-extern char *prom_firstprop(int node, char *buffer);
+extern char *prom_firstprop(phandle node, char *buffer);
/* Returns the next property after the passed property for the given
* node. Returns null string on failure. Buffer should be at least 32B long.
*/
-extern char *prom_nextprop(int node, const char *prev_property, char *buffer);
+extern char *prom_nextprop(phandle node, const char *prev_property, char *buf);
/* Returns 1 if the specified node has given property. */
-extern int prom_node_has_property(int node, const char *property);
+extern int prom_node_has_property(phandle node, const char *property);
/* Returns phandle of the path specified */
-extern int prom_finddevice(const char *name);
+extern phandle prom_finddevice(const char *name);
/* Set the indicated property at the given node with the passed value.
* Returns the number of bytes of your value that the prom took.
*/
-extern int prom_setprop(int node, const char *prop_name, char *prop_value,
+extern int prom_setprop(phandle node, const char *prop_name, char *prop_value,
int value_size);
-extern int prom_pathtoinode(const char *path);
-extern int prom_inst2pkg(int);
+extern phandle prom_pathtoinode(const char *path);
+extern phandle prom_inst2pkg(int);
extern int prom_service_exists(const char *service_name);
extern void prom_sun4v_guest_soft_state(void);
diff --git a/arch/sparc/kernel/auxio_32.c b/arch/sparc/kernel/auxio_32.c
index ee8d214..35f4883 100644
--- a/arch/sparc/kernel/auxio_32.c
+++ b/arch/sparc/kernel/auxio_32.c
@@ -23,7 +23,7 @@ static DEFINE_SPINLOCK(auxio_lock);
void __init auxio_probe(void)
{
- int node, auxio_nd;
+ phandle node, auxio_nd;
struct linux_prom_registers auxregs[1];
struct resource r;
@@ -113,7 +113,7 @@ volatile unsigned char * auxio_power_register = NULL;
void __init auxio_power_probe(void)
{
struct linux_prom_registers regs;
- int node;
+ phandle node;
struct resource r;
/* Attempt to find the sun4m power control node. */
diff --git a/arch/sparc/kernel/btext.c b/arch/sparc/kernel/btext.c
index 8cc2d56..89aa4eb 100644
--- a/arch/sparc/kernel/btext.c
+++ b/arch/sparc/kernel/btext.c
@@ -40,7 +40,7 @@ static unsigned char *dispDeviceBase __force_data;
static unsigned char vga_font[cmapsz];
-static int __init btext_initialize(unsigned int node)
+static int __init btext_initialize(phandle node)
{
unsigned int width, height, depth, pitch;
unsigned long address = 0;
@@ -309,7 +309,7 @@ static struct console btext_console = {
int __init btext_find_display(void)
{
- unsigned int node;
+ phandle node;
char type[32];
int ret;
diff --git a/arch/sparc/kernel/devices.c b/arch/sparc/kernel/devices.c
index 62dc7a0..d2eddd6 100644
--- a/arch/sparc/kernel/devices.c
+++ b/arch/sparc/kernel/devices.c
@@ -31,9 +31,9 @@ static char *cpu_mid_prop(void)
return "mid";
}
-static int check_cpu_node(int nd, int *cur_inst,
- int (*compare)(int, int, void *), void *compare_arg,
- int *prom_node, int *mid)
+static int check_cpu_node(phandle nd, int *cur_inst,
+ int (*compare)(phandle, int, void *), void *compare_arg,
+ phandle *prom_node, int *mid)
{
if (!compare(nd, *cur_inst, compare_arg)) {
if (prom_node)
@@ -51,8 +51,8 @@ static int check_cpu_node(int nd, int *cur_inst,
return -ENODEV;
}
-static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
- int *prom_node, int *mid)
+static int __cpu_find_by(int (*compare)(phandle, int, void *),
+ void *compare_arg, phandle *prom_node, int *mid)
{
struct device_node *dp;
int cur_inst;
@@ -71,7 +71,7 @@ static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
return -ENODEV;
}
-static int cpu_instance_compare(int nd, int instance, void *_arg)
+static int cpu_instance_compare(phandle nd, int instance, void *_arg)
{
int desired_instance = (int) _arg;
@@ -80,13 +80,13 @@ static int cpu_instance_compare(int nd, int instance, void *_arg)
return -ENODEV;
}
-int cpu_find_by_instance(int instance, int *prom_node, int *mid)
+int cpu_find_by_instance(int instance, phandle *prom_node, int *mid)
{
return __cpu_find_by(cpu_instance_compare, (void *)instance,
prom_node, mid);
}
-static int cpu_mid_compare(int nd, int instance, void *_arg)
+static int cpu_mid_compare(phandle nd, int instance, void *_arg)
{
int desired_mid = (int) _arg;
int this_mid;
@@ -98,7 +98,7 @@ static int cpu_mid_compare(int nd, int instance, void *_arg)
return -ENODEV;
}
-int cpu_find_by_mid(int mid, int *prom_node)
+int cpu_find_by_mid(int mid, phandle *prom_node)
{
return __cpu_find_by(cpu_mid_compare, (void *)mid,
prom_node, NULL);
@@ -108,7 +108,7 @@ int cpu_find_by_mid(int mid, int *prom_node)
* address (0-3). This gives us the true hardware mid, which might have
* some other bits set. On 4d hardware and software mids are the same.
*/
-int cpu_get_hwmid(int prom_node)
+int cpu_get_hwmid(phandle prom_node)
{
return prom_getintdefault(prom_node, cpu_mid_prop(), -ENODEV);
}
@@ -119,7 +119,8 @@ void __init device_scan(void)
#ifndef CONFIG_SMP
{
- int err, cpu_node;
+ phandle cpu_node;
+ int err;
err = cpu_find_by_instance(0, &cpu_node, NULL);
if (err) {
/* Probably a sun4e, Sun is trying to trick us ;-) */
diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c
index d36a8d3..aeaa09a 100644
--- a/arch/sparc/kernel/pcic.c
+++ b/arch/sparc/kernel/pcic.c
@@ -284,7 +284,7 @@ int __init pcic_probe(void)
struct linux_prom_registers regs[PROMREG_MAX];
struct linux_pbm_info* pbm;
char namebuf[64];
- int node;
+ phandle node;
int err;
if (pcic0_up) {
@@ -440,7 +440,7 @@ static int __devinit pdev_to_pnode(struct linux_pbm_info *pbm,
{
struct linux_prom_pci_registers regs[PROMREG_MAX];
int err;
- int node = prom_getchild(pbm->prom_node);
+ phandle node = prom_getchild(pbm->prom_node);
while(node) {
err = prom_getproperty(node, "reg",
diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
index 5f72de6..29bafe0 100644
--- a/arch/sparc/kernel/setup_64.c
+++ b/arch/sparc/kernel/setup_64.c
@@ -315,7 +315,7 @@ void __init setup_arch(char **cmdline_p)
#ifdef CONFIG_IP_PNP
if (!ic_set_manually) {
- int chosen = prom_finddevice ("/chosen");
+ phandle chosen = prom_finddevice("/chosen");
u32 cl, sv, gw;
cl = prom_getintdefault (chosen, "client-ip", 0);
diff --git a/arch/sparc/kernel/starfire.c b/arch/sparc/kernel/starfire.c
index 060d0f3..a4446c0 100644
--- a/arch/sparc/kernel/starfire.c
+++ b/arch/sparc/kernel/starfire.c
@@ -23,7 +23,7 @@ int this_is_starfire = 0;
void check_if_starfire(void)
{
- int ssnode = prom_finddevice("/ssp-serial");
+ phandle ssnode = prom_finddevice("/ssp-serial");
if (ssnode != 0 && ssnode != -1)
this_is_starfire = 1;
}
diff --git a/arch/sparc/kernel/tadpole.c b/arch/sparc/kernel/tadpole.c
index f476a5f..9aba8bd 100644
--- a/arch/sparc/kernel/tadpole.c
+++ b/arch/sparc/kernel/tadpole.c
@@ -100,7 +100,7 @@ static void swift_clockstop(void)
void __init clock_stop_probe(void)
{
- unsigned int node, clk_nd;
+ phandle node, clk_nd;
char name[20];
prom_getstring(prom_root_node, "name", name, sizeof(name));
diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
index f043451..9b020d6 100644
--- a/arch/sparc/mm/init_64.c
+++ b/arch/sparc/mm/init_64.c
@@ -88,7 +88,7 @@ static void __init read_obp_memory(const char *property,
struct linux_prom64_registers *regs,
int *num_ents)
{
- int node = prom_finddevice("/memory");
+ phandle node = prom_finddevice("/memory");
int prop_size = prom_getproplen(node, property);
int ents, ret, i;
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index b0b43aa..92319aa 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -1262,7 +1262,8 @@ extern unsigned long bootmem_init(unsigned long *pages_avail);
void __init srmmu_paging_init(void)
{
- int i, cpunode;
+ int i;
+ phandle cpunode;
char node_str[128];
pgd_t *pgd;
pmd_t *pmd;
@@ -1398,7 +1399,8 @@ static void __init srmmu_is_bad(void)
static void __init init_vac_layout(void)
{
- int nd, cache_lines;
+ phandle nd;
+ int cache_lines;
char node_str[128];
#ifdef CONFIG_SMP
int cpu = 0;
@@ -2082,7 +2084,7 @@ static void __init get_srmmu_type(void)
/* Next check for Fujitsu Swift. */
if(psr_typ == 0 && psr_vers == 4) {
- int cpunode;
+ phandle cpunode;
char node_str[128];
/* Look if it is not a TurboSparc emulating Swift... */
diff --git a/arch/sparc/mm/sun4c.c b/arch/sparc/mm/sun4c.c
index 4289f90..ddd0d86 100644
--- a/arch/sparc/mm/sun4c.c
+++ b/arch/sparc/mm/sun4c.c
@@ -420,7 +420,7 @@ volatile unsigned long __iomem *sun4c_memerr_reg = NULL;
void __init sun4c_probe_memerr_reg(void)
{
- int node;
+ phandle node;
struct linux_prom_registers regs[1];
node = prom_getchild(prom_root_node);
diff --git a/arch/sparc/prom/init_32.c b/arch/sparc/prom/init_32.c
index ccb36c7..d342dba 100644
--- a/arch/sparc/prom/init_32.c
+++ b/arch/sparc/prom/init_32.c
@@ -20,7 +20,7 @@ enum prom_major_version prom_vers;
unsigned int prom_rev, prom_prev;
/* The root node of the prom device tree. */
-int prom_root_node;
+phandle prom_root_node;
EXPORT_SYMBOL(prom_root_node);
/* Pointer to the device tree operations structure. */
diff --git a/arch/sparc/prom/init_64.c b/arch/sparc/prom/init_64.c
index 7b00f89..3ff911e 100644
--- a/arch/sparc/prom/init_64.c
+++ b/arch/sparc/prom/init_64.c
@@ -19,7 +19,7 @@ char prom_version[80];
/* The root node of the prom device tree. */
int prom_stdin, prom_stdout;
-int prom_chosen_node;
+phandle prom_chosen_node;
/* You must call prom_init() before you attempt to use any of the
* routines in the prom library. It returns 0 on success, 1 on
@@ -30,7 +30,7 @@ extern void prom_cif_init(void *, void *);
void __init prom_init(void *cif_handler, void *cif_stack)
{
- int node;
+ phandle node;
prom_cif_init(cif_handler, cif_stack);
diff --git a/arch/sparc/prom/memory.c b/arch/sparc/prom/memory.c
index fac7899..3f263a6 100644
--- a/arch/sparc/prom/memory.c
+++ b/arch/sparc/prom/memory.c
@@ -31,7 +31,8 @@ static int __init prom_meminit_v0(void)
static int __init prom_meminit_v2(void)
{
struct linux_prom_registers reg[64];
- int node, size, num_ents, i;
+ phandle node;
+ int size, num_ents, i;
node = prom_searchsiblings(prom_getchild(prom_root_node), "memory");
size = prom_getproperty(node, "available", (char *) reg, sizeof(reg));
diff --git a/arch/sparc/prom/misc_64.c b/arch/sparc/prom/misc_64.c
index 6cb1581..d24bc44 100644
--- a/arch/sparc/prom/misc_64.c
+++ b/arch/sparc/prom/misc_64.c
@@ -183,7 +183,8 @@ unsigned char prom_get_idprom(char *idbuf, int num_bytes)
int prom_get_mmu_ihandle(void)
{
- int node, ret;
+ phandle node;
+ int ret;
if (prom_mmu_ihandle_cache != 0)
return prom_mmu_ihandle_cache;
@@ -201,7 +202,8 @@ int prom_get_mmu_ihandle(void)
static int prom_get_memory_ihandle(void)
{
static int memory_ihandle_cache;
- int node, ret;
+ phandle node;
+ int ret;
if (memory_ihandle_cache != 0)
return memory_ihandle_cache;
diff --git a/arch/sparc/prom/ranges.c b/arch/sparc/prom/ranges.c
index aeff43e..541fc82 100644
--- a/arch/sparc/prom/ranges.c
+++ b/arch/sparc/prom/ranges.c
@@ -68,7 +68,7 @@ EXPORT_SYMBOL(prom_apply_obio_ranges);
void __init prom_ranges_init(void)
{
- int node, obio_node;
+ phandle node, obio_node;
int success;
num_obio_ranges = 0;
@@ -89,8 +89,8 @@ void __init prom_ranges_init(void)
prom_printf("PROMLIB: obio_ranges %d\n", num_obio_ranges);
}
-void
-prom_apply_generic_ranges (int node, int parent, struct linux_prom_registers *regs, int nregs)
+void prom_apply_generic_ranges(phandle node, phandle parent,
+ struct linux_prom_registers *regs, int nregs)
{
int success;
int num_ranges;
diff --git a/arch/sparc/prom/tree_32.c b/arch/sparc/prom/tree_32.c
index b21592f..63e08e1 100644
--- a/arch/sparc/prom/tree_32.c
+++ b/arch/sparc/prom/tree_32.c
@@ -20,10 +20,10 @@ extern void restore_current(void);
static char promlib_buf[128];
/* Internal version of prom_getchild that does not alter return values. */
-int __prom_getchild(int node)
+phandle __prom_getchild(phandle node)
{
unsigned long flags;
- int cnode;
+ phandle cnode;
spin_lock_irqsave(&prom_lock, flags);
cnode = prom_nodeops->no_child(node);
@@ -36,9 +36,9 @@ int __prom_getchild(int node)
/* Return the child of node 'node' or zero if no this node has no
* direct descendent.
*/
-int prom_getchild(int node)
+phandle prom_getchild(phandle node)
{
- int cnode;
+ phandle cnode;
if (node == -1)
return 0;
@@ -52,10 +52,10 @@ int prom_getchild(int node)
EXPORT_SYMBOL(prom_getchild);
/* Internal version of prom_getsibling that does not alter return values. */
-int __prom_getsibling(int node)
+phandle __prom_getsibling(phandle node)
{
unsigned long flags;
- int cnode;
+ phandle cnode;
spin_lock_irqsave(&prom_lock, flags);
cnode = prom_nodeops->no_nextnode(node);
@@ -68,9 +68,9 @@ int __prom_getsibling(int node)
/* Return the next sibling of node 'node' or zero if no more siblings
* at this level of depth in the tree.
*/
-int prom_getsibling(int node)
+phandle prom_getsibling(phandle node)
{
- int sibnode;
+ phandle sibnode;
if (node == -1)
return 0;
@@ -86,7 +86,7 @@ EXPORT_SYMBOL(prom_getsibling);
/* Return the length in bytes of property 'prop' at node 'node'.
* Return -1 on error.
*/
-int prom_getproplen(int node, const char *prop)
+int prom_getproplen(phandle node, const char *prop)
{
int ret;
unsigned long flags;
@@ -106,7 +106,7 @@ EXPORT_SYMBOL(prom_getproplen);
* 'buffer' which has a size of 'bufsize'. If the acquisition
* was successful the length will be returned, else -1 is returned.
*/
-int prom_getproperty(int node, const char *prop, char *buffer, int bufsize)
+int prom_getproperty(phandle node, const char *prop, char *buffer, int bufsize)
{
int plen, ret;
unsigned long flags;
@@ -126,7 +126,7 @@ EXPORT_SYMBOL(prom_getproperty);
/* Acquire an integer property and return its value. Returns -1
* on failure.
*/
-int prom_getint(int node, char *prop)
+int prom_getint(phandle node, char *prop)
{
static int intprop;
@@ -140,7 +140,7 @@ EXPORT_SYMBOL(prom_getint);
/* Acquire an integer property, upon error return the passed default
* integer.
*/
-int prom_getintdefault(int node, char *property, int deflt)
+int prom_getintdefault(phandle node, char *property, int deflt)
{
int retval;
@@ -152,7 +152,7 @@ int prom_getintdefault(int node, char *property, int deflt)
EXPORT_SYMBOL(prom_getintdefault);
/* Acquire a boolean property, 1=TRUE 0=FALSE. */
-int prom_getbool(int node, char *prop)
+int prom_getbool(phandle node, char *prop)
{
int retval;
@@ -166,7 +166,7 @@ EXPORT_SYMBOL(prom_getbool);
* string on error. The char pointer is the user supplied string
* buffer.
*/
-void prom_getstring(int node, char *prop, char *user_buf, int ubuf_size)
+void prom_getstring(phandle node, char *prop, char *user_buf, int ubuf_size)
{
int len;
@@ -180,7 +180,7 @@ EXPORT_SYMBOL(prom_getstring);
/* Does the device at node 'node' have name 'name'?
* YES = 1 NO = 0
*/
-int prom_nodematch(int node, char *name)
+int prom_nodematch(phandle node, char *name)
{
int error;
@@ -194,10 +194,11 @@ int prom_nodematch(int node, char *name)
/* Search siblings at 'node_start' for a node with name
* 'nodename'. Return node if successful, zero if not.
*/
-int prom_searchsiblings(int node_start, char *nodename)
+phandle prom_searchsiblings(phandle node_start, char *nodename)
{
- int thisnode, error;
+ phandle thisnode;
+ int error;
for(thisnode = node_start; thisnode;
thisnode=prom_getsibling(thisnode)) {
@@ -213,7 +214,7 @@ int prom_searchsiblings(int node_start, char *nodename)
EXPORT_SYMBOL(prom_searchsiblings);
/* Interal version of nextprop that does not alter return values. */
-char * __prom_nextprop(int node, char * oprop)
+char *__prom_nextprop(phandle node, char * oprop)
{
unsigned long flags;
char *prop;
@@ -228,7 +229,7 @@ char * __prom_nextprop(int node, char * oprop)
/* Return the first property name for node 'node'. */
/* buffer is unused argument, but as v9 uses it, we need to have the same interface */
-char * prom_firstprop(int node, char *bufer)
+char *prom_firstprop(phandle node, char *bufer)
{
if (node == 0 || node == -1)
return "";
@@ -241,7 +242,7 @@ EXPORT_SYMBOL(prom_firstprop);
* at node 'node' . Returns empty string if no more
* property types for this node.
*/
-char * prom_nextprop(int node, char *oprop, char *buffer)
+char *prom_nextprop(phandle node, char *oprop, char *buffer)
{
if (node == 0 || node == -1)
return "";
@@ -250,11 +251,11 @@ char * prom_nextprop(int node, char *oprop, char *buffer)
}
EXPORT_SYMBOL(prom_nextprop);
-int prom_finddevice(char *name)
+phandle prom_finddevice(char *name)
{
char nbuf[128];
char *s = name, *d;
- int node = prom_root_node, node2;
+ phandle node = prom_root_node, node2;
unsigned int which_io, phys_addr;
struct linux_prom_registers reg[PROMREG_MAX];
@@ -298,7 +299,7 @@ int prom_finddevice(char *name)
}
EXPORT_SYMBOL(prom_finddevice);
-int prom_node_has_property(int node, char *prop)
+int prom_node_has_property(phandle node, char *prop)
{
char *current_property = "";
@@ -314,7 +315,7 @@ EXPORT_SYMBOL(prom_node_has_property);
/* Set property 'pname' at node 'node' to value 'value' which has a length
* of 'size' bytes. Return the number of bytes the prom accepted.
*/
-int prom_setprop(int node, const char *pname, char *value, int size)
+int prom_setprop(phandle node, const char *pname, char *value, int size)
{
unsigned long flags;
int ret;
@@ -329,9 +330,9 @@ int prom_setprop(int node, const char *pname, char *value, int size)
}
EXPORT_SYMBOL(prom_setprop);
-int prom_inst2pkg(int inst)
+phandle prom_inst2pkg(int inst)
{
- int node;
+ phandle node;
unsigned long flags;
spin_lock_irqsave(&prom_lock, flags);
@@ -345,9 +346,10 @@ int prom_inst2pkg(int inst)
/* Return 'node' assigned to a particular prom 'path'
* FIXME: Should work for v0 as well
*/
-int prom_pathtoinode(char *path)
+phandle prom_pathtoinode(char *path)
{
- int node, inst;
+ phandle node;
+ int inst;
inst = prom_devopen (path);
if (inst == -1) return 0;
diff --git a/arch/sparc/prom/tree_64.c b/arch/sparc/prom/tree_64.c
index 9d3f913..691be68 100644
--- a/arch/sparc/prom/tree_64.c
+++ b/arch/sparc/prom/tree_64.c
@@ -16,7 +16,7 @@
#include <asm/oplib.h>
#include <asm/ldc.h>
-static int prom_node_to_node(const char *type, int node)
+static phandle prom_node_to_node(const char *type, phandle node)
{
unsigned long args[5];
@@ -28,20 +28,20 @@ static int prom_node_to_node(const char *type, int node)
p1275_cmd_direct(args);
- return (int) args[4];
+ return (phandle) args[4];
}
/* Return the child of node 'node' or zero if no this node has no
* direct descendent.
*/
-inline int __prom_getchild(int node)
+inline phandle __prom_getchild(phandle node)
{
return prom_node_to_node("child", node);
}
-inline int prom_getchild(int node)
+inline phandle prom_getchild(phandle node)
{
- int cnode;
+ phandle cnode;
if (node == -1)
return 0;
@@ -52,9 +52,9 @@ inline int prom_getchild(int node)
}
EXPORT_SYMBOL(prom_getchild);
-inline int prom_getparent(int node)
+inline phandle prom_getparent(phandle node)
{
- int cnode;
+ phandle cnode;
if (node == -1)
return 0;
@@ -67,14 +67,14 @@ inline int prom_getparent(int node)
/* Return the next sibling of node 'node' or zero if no more siblings
* at this level of depth in the tree.
*/
-inline int __prom_getsibling(int node)
+inline phandle __prom_getsibling(phandle node)
{
return prom_node_to_node(prom_peer_name, node);
}
-inline int prom_getsibling(int node)
+inline phandle prom_getsibling(phandle node)
{
- int sibnode;
+ phandle sibnode;
if (node == -1)
return 0;
@@ -89,7 +89,7 @@ EXPORT_SYMBOL(prom_getsibling);
/* Return the length in bytes of property 'prop' at node 'node'.
* Return -1 on error.
*/
-inline int prom_getproplen(int node, const char *prop)
+inline int prom_getproplen(phandle node, const char *prop)
{
unsigned long args[6];
@@ -113,7 +113,7 @@ EXPORT_SYMBOL(prom_getproplen);
* 'buffer' which has a size of 'bufsize'. If the acquisition
* was successful the length will be returned, else -1 is returned.
*/
-inline int prom_getproperty(int node, const char *prop,
+inline int prom_getproperty(phandle node, const char *prop,
char *buffer, int bufsize)
{
unsigned long args[8];
@@ -141,7 +141,7 @@ EXPORT_SYMBOL(prom_getproperty);
/* Acquire an integer property and return its value. Returns -1
* on failure.
*/
-inline int prom_getint(int node, const char *prop)
+inline int prom_getint(phandle node, const char *prop)
{
int intprop;
@@ -156,7 +156,7 @@ EXPORT_SYMBOL(prom_getint);
* integer.
*/
-int prom_getintdefault(int node, const char *property, int deflt)
+int prom_getintdefault(phandle node, const char *property, int deflt)
{
int retval;
@@ -169,7 +169,7 @@ int prom_getintdefault(int node, const char *property, int deflt)
EXPORT_SYMBOL(prom_getintdefault);
/* Acquire a boolean property, 1=TRUE 0=FALSE. */
-int prom_getbool(int node, const char *prop)
+int prom_getbool(phandle node, const char *prop)
{
int retval;
@@ -184,7 +184,8 @@ EXPORT_SYMBOL(prom_getbool);
* string on error. The char pointer is the user supplied string
* buffer.
*/
-void prom_getstring(int node, const char *prop, char *user_buf, int ubuf_size)
+void prom_getstring(phandle node, const char *prop, char *user_buf,
+ int ubuf_size)
{
int len;
@@ -198,7 +199,7 @@ EXPORT_SYMBOL(prom_getstring);
/* Does the device at node 'node' have name 'name'?
* YES = 1 NO = 0
*/
-int prom_nodematch(int node, const char *name)
+int prom_nodematch(phandle node, const char *name)
{
char namebuf[128];
prom_getproperty(node, "name", namebuf, sizeof(namebuf));
@@ -210,10 +211,10 @@ int prom_nodematch(int node, const char *name)
/* Search siblings at 'node_start' for a node with name
* 'nodename'. Return node if successful, zero if not.
*/
-int prom_searchsiblings(int node_start, const char *nodename)
+phandle prom_searchsiblings(phandle node_start, const char *nodename)
{
-
- int thisnode, error;
+ phandle thisnode;
+ int error;
char promlib_buf[128];
for(thisnode = node_start; thisnode;
@@ -234,7 +235,7 @@ static const char *prom_nextprop_name = "nextprop";
/* Return the first property type for node 'node'.
* buffer should be at least 32B in length
*/
-inline char *prom_firstprop(int node, char *buffer)
+inline char *prom_firstprop(phandle node, char *buffer)
{
unsigned long args[7];
@@ -260,7 +261,7 @@ EXPORT_SYMBOL(prom_firstprop);
* at node 'node' . Returns NULL string if no more
* property types for this node.
*/
-inline char *prom_nextprop(int node, const char *oprop, char *buffer)
+inline char *prom_nextprop(phandle node, const char *oprop, char *buffer)
{
unsigned long args[7];
char buf[32];
@@ -288,8 +289,7 @@ inline char *prom_nextprop(int node, const char *oprop, char *buffer)
}
EXPORT_SYMBOL(prom_nextprop);
-int
-prom_finddevice(const char *name)
+phandle prom_finddevice(const char *name)
{
unsigned long args[5];
@@ -307,7 +307,7 @@ prom_finddevice(const char *name)
}
EXPORT_SYMBOL(prom_finddevice);
-int prom_node_has_property(int node, const char *prop)
+int prom_node_has_property(phandle node, const char *prop)
{
char buf [32];
@@ -325,7 +325,7 @@ EXPORT_SYMBOL(prom_node_has_property);
* of 'size' bytes. Return the number of bytes the prom accepted.
*/
int
-prom_setprop(int node, const char *pname, char *value, int size)
+prom_setprop(phandle node, const char *pname, char *value, int size)
{
unsigned long args[8];
@@ -355,10 +355,10 @@ prom_setprop(int node, const char *pname, char *value, int size)
}
EXPORT_SYMBOL(prom_setprop);
-inline int prom_inst2pkg(int inst)
+inline phandle prom_inst2pkg(int inst)
{
unsigned long args[5];
- int node;
+ phandle node;
args[0] = (unsigned long) "instance-to-package";
args[1] = 1;
@@ -377,10 +377,10 @@ inline int prom_inst2pkg(int inst)
/* Return 'node' assigned to a particular prom 'path'
* FIXME: Should work for v0 as well
*/
-int
-prom_pathtoinode(const char *path)
+phandle prom_pathtoinode(const char *path)
{
- int node, inst;
+ phandle node;
+ int inst;
inst = prom_devopen (path);
if (inst == 0)
diff --git a/drivers/sbus/char/jsflash.c b/drivers/sbus/char/jsflash.c
index 4942050..5139371 100644
--- a/drivers/sbus/char/jsflash.c
+++ b/drivers/sbus/char/jsflash.c
@@ -459,7 +459,7 @@ static int jsflash_init(void)
{
int rc;
struct jsflash *jsf;
- int node;
+ phandle node;
char banner[128];
struct linux_prom_registers reg0;
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index f8d69ad..5bf9123 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -2970,7 +2970,8 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
struct atyfb_par *par = info->par;
struct device_node *dp;
char prop[128];
- int node, len, i, j, ret;
+ phandle node;
+ int len, i, j, ret;
u32 mem, chip_id;
/*
--
1.5.6.5
Transitioning into making this useful for architectures other than sparc.
This is a verbatim copy of all functions/variables that've been moved.
Signed-off-by: Andres Salomon <[email protected]>
---
arch/sparc/kernel/prom_common.c | 190 +----------------------------------
drivers/of/pdt.c | 215 +++++++++++++++++++++++++++++++++++++++
2 files changed, 216 insertions(+), 189 deletions(-)
create mode 100644 drivers/of/pdt.c
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
index 1f830da..7b454f6 100644
--- a/arch/sparc/kernel/prom_common.c
+++ b/arch/sparc/kernel/prom_common.c
@@ -26,8 +26,6 @@
#include "prom.h"
-void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
-
struct device_node *of_console_device;
EXPORT_SYMBOL(of_console_device);
@@ -119,192 +117,6 @@ int of_find_in_proplist(const char *list, const char *match, int len)
}
EXPORT_SYMBOL(of_find_in_proplist);
-unsigned int prom_unique_id;
-
-static struct property * __init build_one_prop(phandle node, char *prev,
- char *special_name,
- void *special_val,
- int special_len)
-{
- static struct property *tmp = NULL;
- struct property *p;
- const char *name;
-
- if (tmp) {
- p = tmp;
- memset(p, 0, sizeof(*p) + 32);
- tmp = NULL;
- } else {
- p = prom_early_alloc(sizeof(struct property) + 32);
- p->unique_id = prom_unique_id++;
- }
-
- p->name = (char *) (p + 1);
- if (special_name) {
- strcpy(p->name, special_name);
- p->length = special_len;
- p->value = prom_early_alloc(special_len);
- memcpy(p->value, special_val, special_len);
- } else {
- if (prev == NULL) {
- name = prom_firstprop(node, p->name);
- } else {
- name = prom_nextprop(node, prev, p->name);
- }
-
- if (!name || strlen(name) == 0) {
- tmp = p;
- return NULL;
- }
-#ifdef CONFIG_SPARC32
- strcpy(p->name, name);
-#endif
- p->length = prom_getproplen(node, p->name);
- if (p->length <= 0) {
- p->length = 0;
- } else {
- int len;
-
- p->value = prom_early_alloc(p->length + 1);
- len = prom_getproperty(node, p->name, p->value,
- p->length);
- if (len <= 0)
- p->length = 0;
- ((unsigned char *)p->value)[p->length] = '\0';
- }
- }
- return p;
-}
-
-static struct property * __init build_prop_list(phandle node)
-{
- struct property *head, *tail;
-
- head = tail = build_one_prop(node, NULL,
- ".node", &node, sizeof(node));
-
- tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
- tail = tail->next;
- while(tail) {
- tail->next = build_one_prop(node, tail->name,
- NULL, NULL, 0);
- tail = tail->next;
- }
-
- return head;
-}
-
-static char * __init get_one_property(phandle node, const char *name)
-{
- char *buf = "<NULL>";
- int len;
-
- len = prom_getproplen(node, name);
- if (len > 0) {
- buf = prom_early_alloc(len);
- len = prom_getproperty(node, name, buf, len);
- }
-
- return buf;
-}
-
-static struct device_node * __init prom_create_node(phandle node,
- struct device_node *parent)
-{
- struct device_node *dp;
-
- if (!node)
- return NULL;
-
- dp = prom_early_alloc(sizeof(*dp));
- dp->unique_id = prom_unique_id++;
- dp->parent = parent;
-
- kref_init(&dp->kref);
-
- dp->name = get_one_property(node, "name");
- dp->type = get_one_property(node, "device_type");
- dp->phandle = node;
-
- dp->properties = build_prop_list(node);
-
- irq_trans_init(dp);
-
- return dp;
-}
-
-char * __init build_full_name(struct device_node *dp)
-{
- int len, ourlen, plen;
- char *n;
-
- plen = strlen(dp->parent->full_name);
- ourlen = strlen(dp->path_component_name);
- len = ourlen + plen + 2;
-
- n = prom_early_alloc(len);
- strcpy(n, dp->parent->full_name);
- if (!of_node_is_root(dp->parent)) {
- strcpy(n + plen, "/");
- plen++;
- }
- strcpy(n + plen, dp->path_component_name);
-
- return n;
-}
-
-static struct device_node * __init prom_build_tree(struct device_node *parent,
- phandle node,
- struct device_node ***nextp)
-{
- struct device_node *ret = NULL, *prev_sibling = NULL;
- struct device_node *dp;
-
- while (1) {
- dp = prom_create_node(node, parent);
- if (!dp)
- break;
-
- if (prev_sibling)
- prev_sibling->sibling = dp;
-
- if (!ret)
- ret = dp;
- prev_sibling = dp;
-
- *(*nextp) = dp;
- *nextp = &dp->allnext;
-
- dp->path_component_name = build_path_component(dp);
- dp->full_name = build_full_name(dp);
-
- dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
-
- if (prom_build_more)
- prom_build_more(dp, nextp);
-
- node = prom_getsibling(node);
- }
-
- return ret;
-}
-
unsigned int prom_early_allocated __initdata;
-void __init prom_build_devicetree(void)
-{
- struct device_node **nextp;
-
- allnodes = prom_create_node(prom_root_node, NULL);
- allnodes->path_component_name = "";
- allnodes->full_name = "/";
-
- nextp = &allnodes->allnext;
- allnodes->child = prom_build_tree(allnodes,
- prom_getchild(allnodes->phandle),
- &nextp);
- of_console_init();
-
- printk("PROM: Built device tree with %u bytes of memory.\n",
- prom_early_allocated);
-}
+#include "../../../drivers/of/pdt.c"
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
new file mode 100644
index 0000000..c3c2d70
--- /dev/null
+++ b/drivers/of/pdt.c
@@ -0,0 +1,215 @@
+/* prom_common.c: OF device tree support common code.
+ *
+ * Paul Mackerras August 1996.
+ * Copyright (C) 1996-2005 Paul Mackerras.
+ *
+ * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
+ * {engebret|bergner}@us.ibm.com
+ *
+ * Adapted for sparc by David S. Miller [email protected]
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <asm/prom.h>
+#include <asm/oplib.h>
+#include <asm/leon.h>
+
+void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
+
+unsigned int prom_unique_id;
+
+static struct property * __init build_one_prop(phandle node, char *prev,
+ char *special_name,
+ void *special_val,
+ int special_len)
+{
+ static struct property *tmp = NULL;
+ struct property *p;
+ const char *name;
+
+ if (tmp) {
+ p = tmp;
+ memset(p, 0, sizeof(*p) + 32);
+ tmp = NULL;
+ } else {
+ p = prom_early_alloc(sizeof(struct property) + 32);
+ p->unique_id = prom_unique_id++;
+ }
+
+ p->name = (char *) (p + 1);
+ if (special_name) {
+ strcpy(p->name, special_name);
+ p->length = special_len;
+ p->value = prom_early_alloc(special_len);
+ memcpy(p->value, special_val, special_len);
+ } else {
+ if (prev == NULL) {
+ name = prom_firstprop(node, p->name);
+ } else {
+ name = prom_nextprop(node, prev, p->name);
+ }
+
+ if (!name || strlen(name) == 0) {
+ tmp = p;
+ return NULL;
+ }
+#ifdef CONFIG_SPARC32
+ strcpy(p->name, name);
+#endif
+ p->length = prom_getproplen(node, p->name);
+ if (p->length <= 0) {
+ p->length = 0;
+ } else {
+ int len;
+
+ p->value = prom_early_alloc(p->length + 1);
+ len = prom_getproperty(node, p->name, p->value,
+ p->length);
+ if (len <= 0)
+ p->length = 0;
+ ((unsigned char *)p->value)[p->length] = '\0';
+ }
+ }
+ return p;
+}
+
+static struct property * __init build_prop_list(phandle node)
+{
+ struct property *head, *tail;
+
+ head = tail = build_one_prop(node, NULL,
+ ".node", &node, sizeof(node));
+
+ tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
+ tail = tail->next;
+ while(tail) {
+ tail->next = build_one_prop(node, tail->name,
+ NULL, NULL, 0);
+ tail = tail->next;
+ }
+
+ return head;
+}
+
+static char * __init get_one_property(phandle node, const char *name)
+{
+ char *buf = "<NULL>";
+ int len;
+
+ len = prom_getproplen(node, name);
+ if (len > 0) {
+ buf = prom_early_alloc(len);
+ len = prom_getproperty(node, name, buf, len);
+ }
+
+ return buf;
+}
+
+static struct device_node * __init prom_create_node(phandle node,
+ struct device_node *parent)
+{
+ struct device_node *dp;
+
+ if (!node)
+ return NULL;
+
+ dp = prom_early_alloc(sizeof(*dp));
+ dp->unique_id = prom_unique_id++;
+ dp->parent = parent;
+
+ kref_init(&dp->kref);
+
+ dp->name = get_one_property(node, "name");
+ dp->type = get_one_property(node, "device_type");
+ dp->phandle = node;
+
+ dp->properties = build_prop_list(node);
+
+ irq_trans_init(dp);
+
+ return dp;
+}
+
+char * __init build_full_name(struct device_node *dp)
+{
+ int len, ourlen, plen;
+ char *n;
+
+ plen = strlen(dp->parent->full_name);
+ ourlen = strlen(dp->path_component_name);
+ len = ourlen + plen + 2;
+
+ n = prom_early_alloc(len);
+ strcpy(n, dp->parent->full_name);
+ if (!of_node_is_root(dp->parent)) {
+ strcpy(n + plen, "/");
+ plen++;
+ }
+ strcpy(n + plen, dp->path_component_name);
+
+ return n;
+}
+
+static struct device_node * __init prom_build_tree(struct device_node *parent,
+ phandle node,
+ struct device_node ***nextp)
+{
+ struct device_node *ret = NULL, *prev_sibling = NULL;
+ struct device_node *dp;
+
+ while (1) {
+ dp = prom_create_node(node, parent);
+ if (!dp)
+ break;
+
+ if (prev_sibling)
+ prev_sibling->sibling = dp;
+
+ if (!ret)
+ ret = dp;
+ prev_sibling = dp;
+
+ *(*nextp) = dp;
+ *nextp = &dp->allnext;
+
+ dp->path_component_name = build_path_component(dp);
+ dp->full_name = build_full_name(dp);
+
+ dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
+
+ if (prom_build_more)
+ prom_build_more(dp, nextp);
+
+ node = prom_getsibling(node);
+ }
+
+ return ret;
+}
+
+void __init prom_build_devicetree(void)
+{
+ struct device_node **nextp;
+
+ allnodes = prom_create_node(prom_root_node, NULL);
+ allnodes->path_component_name = "";
+ allnodes->full_name = "/";
+
+ nextp = &allnodes->allnext;
+ allnodes->child = prom_build_tree(allnodes,
+ prom_getchild(allnodes->phandle),
+ &nextp);
+ of_console_init();
+
+ printk("PROM: Built device tree with %u bytes of memory.\n",
+ prom_early_allocated);
+}
--
1.5.6.5
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 <[email protected]>
---
arch/sparc/Kconfig | 1 +
arch/sparc/include/asm/prom.h | 5 ++-
arch/sparc/kernel/prom.h | 6 ----
arch/sparc/kernel/prom_common.c | 10 ++++++-
drivers/of/Kconfig | 5 +++-
drivers/of/Makefile | 1 +
drivers/of/pdt.c | 55 +++++++++++++++++++++++++++-----------
include/linux/of_pdt.h | 24 +++++++++++++++++
8 files changed, 81 insertions(+), 26 deletions(-)
create mode 100644 include/linux/of_pdt.h
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 491e9d6..a06c959 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -19,6 +19,7 @@ config SPARC
bool
default y
select OF
+ select OF_PROMTREE
select HAVE_IDE
select HAVE_OPROFILE
select HAVE_ARCH_KGDB if !SMP || SPARC64
diff --git a/arch/sparc/include/asm/prom.h b/arch/sparc/include/asm/prom.h
index 291f125..56bbaad 100644
--- a/arch/sparc/include/asm/prom.h
+++ b/arch/sparc/include/asm/prom.h
@@ -18,6 +18,7 @@
* 2 of the License, or (at your option) any later version.
*/
#include <linux/types.h>
+#include <linux/of_pdt.h>
#include <linux/proc_fs.h>
#include <linux/mutex.h>
#include <asm/atomic.h>
@@ -67,8 +68,8 @@ extern struct device_node *of_console_device;
extern char *of_console_path;
extern char *of_console_options;
-extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
-extern char *build_full_name(struct device_node *dp);
+extern void irq_trans_init(struct device_node *dp);
+extern char *build_path_component(struct device_node *dp);
#endif /* __KERNEL__ */
#endif /* _SPARC_PROM_H */
diff --git a/arch/sparc/kernel/prom.h b/arch/sparc/kernel/prom.h
index eeb04a7..cf5fe1c 100644
--- a/arch/sparc/kernel/prom.h
+++ b/arch/sparc/kernel/prom.h
@@ -4,12 +4,6 @@
#include <linux/spinlock.h>
#include <asm/prom.h>
-extern void * prom_early_alloc(unsigned long size);
-extern void irq_trans_init(struct device_node *dp);
-
-extern unsigned int prom_unique_id;
-
-extern char *build_path_component(struct device_node *dp);
extern void of_console_init(void);
extern unsigned int prom_early_allocated;
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
index 7b454f6..fe84d56 100644
--- a/arch/sparc/kernel/prom_common.c
+++ b/arch/sparc/kernel/prom_common.c
@@ -20,6 +20,7 @@
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/of.h>
+#include <linux/of_pdt.h>
#include <asm/prom.h>
#include <asm/oplib.h>
#include <asm/leon.h>
@@ -119,4 +120,11 @@ EXPORT_SYMBOL(of_find_in_proplist);
unsigned int prom_early_allocated __initdata;
-#include "../../../drivers/of/pdt.c"
+void __init prom_build_devicetree(void)
+{
+ of_pdt_build_devicetree(prom_root_node);
+ of_console_init();
+
+ pr_info("PROM: Built device tree with %u bytes of memory.\n",
+ prom_early_allocated);
+}
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 6acbff3..aa675eb 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -4,7 +4,7 @@ config DTC
config OF
bool
-menu "Flattened Device Tree and Open Firmware support"
+menu "Device Tree and Open Firmware support"
depends on OF
config PROC_DEVICETREE
@@ -19,6 +19,9 @@ config OF_FLATTREE
bool
select DTC
+config OF_PROMTREE
+ bool
+
config OF_DYNAMIC
def_bool y
depends on PPC_OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 0052c40..7888155 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,5 +1,6 @@
obj-y = base.o
obj-$(CONFIG_OF_FLATTREE) += fdt.o
+obj-$(CONFIG_OF_PROMTREE) += pdt.o
obj-$(CONFIG_OF_ADDRESS) += address.o
obj-$(CONFIG_OF_IRQ) += irq.o
obj-$(CONFIG_OF_DEVICE) += device.o platform.o
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index c3c2d70..f0872b6 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -1,4 +1,4 @@
-/* prom_common.c: OF device tree support common code.
+/* pdt.c: OF PROM device tree support code.
*
* Paul Mackerras August 1996.
* Copyright (C) 1996-2005 Paul Mackerras.
@@ -7,6 +7,7 @@
* {engebret|bergner}@us.ibm.com
*
* Adapted for sparc by David S. Miller [email protected]
+ * Adapted for multiple architectures by Andres Salomon <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,13 +21,35 @@
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/of.h>
+#include <linux/of_pdt.h>
#include <asm/prom.h>
-#include <asm/oplib.h>
-#include <asm/leon.h>
-void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
+void __initdata (*prom_build_more)(struct device_node *dp,
+ struct device_node ***nextp);
-unsigned int prom_unique_id;
+#if defined(CONFIG_SPARC)
+unsigned int of_pdt_unique_id __initdata;
+
+#define of_pdt_incr_unique_id(p) do { \
+ (p)->unique_id = of_pdt_unique_id++; \
+} while (0)
+
+static inline const char *of_pdt_node_name(struct device_node *dp)
+{
+ return dp->path_component_name;
+}
+
+#else
+
+static inline void of_pdt_incr_unique_id(void *p) { }
+static inline void irq_trans_init(struct device_node *dp) { }
+
+static inline const char *of_pdt_node_name(struct device_node *dp)
+{
+ return dp->name;
+}
+
+#endif /* !CONFIG_SPARC */
static struct property * __init build_one_prop(phandle node, char *prev,
char *special_name,
@@ -43,7 +66,7 @@ static struct property * __init build_one_prop(phandle node, char *prev,
tmp = NULL;
} else {
p = prom_early_alloc(sizeof(struct property) + 32);
- p->unique_id = prom_unique_id++;
+ of_pdt_incr_unique_id(p);
}
p->name = (char *) (p + 1);
@@ -124,7 +147,7 @@ static struct device_node * __init prom_create_node(phandle node,
return NULL;
dp = prom_early_alloc(sizeof(*dp));
- dp->unique_id = prom_unique_id++;
+ of_pdt_incr_unique_id(dp);
dp->parent = parent;
kref_init(&dp->kref);
@@ -140,13 +163,13 @@ static struct device_node * __init prom_create_node(phandle node,
return dp;
}
-char * __init build_full_name(struct device_node *dp)
+static char * __init build_full_name(struct device_node *dp)
{
int len, ourlen, plen;
char *n;
plen = strlen(dp->parent->full_name);
- ourlen = strlen(dp->path_component_name);
+ ourlen = strlen(of_pdt_node_name(dp));
len = ourlen + plen + 2;
n = prom_early_alloc(len);
@@ -155,7 +178,7 @@ char * __init build_full_name(struct device_node *dp)
strcpy(n + plen, "/");
plen++;
}
- strcpy(n + plen, dp->path_component_name);
+ strcpy(n + plen, of_pdt_node_name(dp));
return n;
}
@@ -182,7 +205,9 @@ static struct device_node * __init prom_build_tree(struct device_node *parent,
*(*nextp) = dp;
*nextp = &dp->allnext;
+#if defined(CONFIG_SPARC)
dp->path_component_name = build_path_component(dp);
+#endif
dp->full_name = build_full_name(dp);
dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
@@ -196,20 +221,18 @@ static struct device_node * __init prom_build_tree(struct device_node *parent,
return ret;
}
-void __init prom_build_devicetree(void)
+void __init of_pdt_build_devicetree(phandle root_node)
{
struct device_node **nextp;
- allnodes = prom_create_node(prom_root_node, NULL);
+ allnodes = prom_create_node(root_node, NULL);
+#if defined(CONFIG_SPARC)
allnodes->path_component_name = "";
+#endif
allnodes->full_name = "/";
nextp = &allnodes->allnext;
allnodes->child = prom_build_tree(allnodes,
prom_getchild(allnodes->phandle),
&nextp);
- of_console_init();
-
- printk("PROM: Built device tree with %u bytes of memory.\n",
- prom_early_allocated);
}
diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
new file mode 100644
index 0000000..c0a8774
--- /dev/null
+++ b/include/linux/of_pdt.h
@@ -0,0 +1,24 @@
+/*
+ * Definitions for building a device tree by calling into the
+ * Open Firmware PROM.
+ *
+ * Copyright (C) 2010 Andres Salomon <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_OF_PDT_H
+#define _LINUX_OF_PDT_H
+
+extern void *prom_early_alloc(unsigned long size);
+
+/* for building the device tree */
+extern void of_pdt_build_devicetree(phandle root_node);
+
+extern void (*prom_build_more)(struct device_node *dp,
+ struct device_node ***nextp);
+
+#endif /* _LINUX_OF_PDT_H */
--
1.5.6.5
Rather than assuming an architecture defines prom_getchild and friends,
define an ops struct with hooks for the various prom functions that
pdt.c needs. This ops struct is filled in by the
arch-(and sometimes firmware-)specific code, and passed to
of_pdt_build_devicetree.
Update sparc code to define the ops struct as well.
Signed-off-by: Andres Salomon <[email protected]>
---
arch/sparc/kernel/prom_common.c | 37 ++++++++++++++++++++++++++++++++++++-
drivers/of/pdt.c | 39 ++++++++++++++++++---------------------
include/linux/of_pdt.h | 20 +++++++++++++++++++-
3 files changed, 73 insertions(+), 23 deletions(-)
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
index fe84d56..0972b39 100644
--- a/arch/sparc/kernel/prom_common.c
+++ b/arch/sparc/kernel/prom_common.c
@@ -118,11 +118,46 @@ int of_find_in_proplist(const char *list, const char *match, int len)
}
EXPORT_SYMBOL(of_find_in_proplist);
+/*
+ * SPARC32 and SPARC64's prom_nextprop() do things differently
+ * here, despite sharing the same interface. SPARC32 doesn't fill in 'buf',
+ * returning NULL on an error. SPARC64 fills in 'buf', but sets it to an
+ * empty string upon error.
+ */
+static int __init handle_nextprop_quirks(char *buf, const char *name)
+{
+ if (!name || strlen(name) == 0)
+ return -1;
+
+#ifdef CONFIG_SPARC32
+ strcpy(buf, name);
+#endif
+ return 0;
+}
+
+static int __init prom_common_nextprop(phandle node, const char *prev,
+ char *buf)
+{
+ const char *name;
+
+ buf[0] = '\0';
+ name = prom_nextprop(node, prev, buf);
+ return handle_nextprop_quirks(buf, name);
+}
+
unsigned int prom_early_allocated __initdata;
+static struct of_pdt_ops prom_sparc_ops __initdata = {
+ .nextprop = prom_common_nextprop,
+ .getproplen = prom_getproplen,
+ .getproperty = prom_getproperty,
+ .getchild = prom_getchild,
+ .getsibling = prom_getsibling,
+};
+
void __init prom_build_devicetree(void)
{
- of_pdt_build_devicetree(prom_root_node);
+ of_pdt_build_devicetree(prom_root_node, &prom_sparc_ops);
of_console_init();
pr_info("PROM: Built device tree with %u bytes of memory.\n",
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index f0872b6..fd02fc1 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -24,6 +24,8 @@
#include <linux/of_pdt.h>
#include <asm/prom.h>
+static struct of_pdt_ops *of_pdt_prom_ops __initdata;
+
void __initdata (*prom_build_more)(struct device_node *dp,
struct device_node ***nextp);
@@ -58,7 +60,7 @@ static struct property * __init build_one_prop(phandle node, char *prev,
{
static struct property *tmp = NULL;
struct property *p;
- const char *name;
+ int err;
if (tmp) {
p = tmp;
@@ -76,28 +78,20 @@ static struct property * __init build_one_prop(phandle node, char *prev,
p->value = prom_early_alloc(special_len);
memcpy(p->value, special_val, special_len);
} else {
- if (prev == NULL) {
- name = prom_firstprop(node, p->name);
- } else {
- name = prom_nextprop(node, prev, p->name);
- }
-
- if (!name || strlen(name) == 0) {
+ err = of_pdt_prom_ops->nextprop(node, prev, p->name);
+ if (err) {
tmp = p;
return NULL;
}
-#ifdef CONFIG_SPARC32
- strcpy(p->name, name);
-#endif
- p->length = prom_getproplen(node, p->name);
+ p->length = of_pdt_prom_ops->getproplen(node, p->name);
if (p->length <= 0) {
p->length = 0;
} else {
int len;
p->value = prom_early_alloc(p->length + 1);
- len = prom_getproperty(node, p->name, p->value,
- p->length);
+ len = of_pdt_prom_ops->getproperty(node, p->name,
+ p->value, p->length);
if (len <= 0)
p->length = 0;
((unsigned char *)p->value)[p->length] = '\0';
@@ -129,10 +123,10 @@ static char * __init get_one_property(phandle node, const char *name)
char *buf = "<NULL>";
int len;
- len = prom_getproplen(node, name);
+ len = of_pdt_prom_ops->getproplen(node, name);
if (len > 0) {
buf = prom_early_alloc(len);
- len = prom_getproperty(node, name, buf, len);
+ len = of_pdt_prom_ops->getproperty(node, name, buf, len);
}
return buf;
@@ -210,21 +204,25 @@ static struct device_node * __init prom_build_tree(struct device_node *parent,
#endif
dp->full_name = build_full_name(dp);
- dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
+ dp->child = prom_build_tree(dp,
+ of_pdt_prom_ops->getchild(node), nextp);
if (prom_build_more)
prom_build_more(dp, nextp);
- node = prom_getsibling(node);
+ node = of_pdt_prom_ops->getsibling(node);
}
return ret;
}
-void __init of_pdt_build_devicetree(phandle root_node)
+void __init of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops)
{
struct device_node **nextp;
+ BUG_ON(!ops);
+ of_pdt_prom_ops = ops;
+
allnodes = prom_create_node(root_node, NULL);
#if defined(CONFIG_SPARC)
allnodes->path_component_name = "";
@@ -233,6 +231,5 @@ void __init of_pdt_build_devicetree(phandle root_node)
nextp = &allnodes->allnext;
allnodes->child = prom_build_tree(allnodes,
- prom_getchild(allnodes->phandle),
- &nextp);
+ of_pdt_prom_ops->getchild(allnodes->phandle), &nextp);
}
diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
index c0a8774..7acabff 100644
--- a/include/linux/of_pdt.h
+++ b/include/linux/of_pdt.h
@@ -13,10 +13,28 @@
#ifndef _LINUX_OF_PDT_H
#define _LINUX_OF_PDT_H
+/* overridable operations for calling into the PROM */
+struct of_pdt_ops {
+ /*
+ * buf should be 32 bytes; return 0 on success.
+ * If prev is NULL, the first property will be returned.
+ */
+ int (*nextprop)(phandle node, const char *prev, char *buf);
+
+ /* for both functions, return proplen on success; -1 on error */
+ int (*getproplen)(phandle node, const char *prop);
+ int (*getproperty)(phandle node, const char *prop, char *buf,
+ int bufsize);
+
+ /* phandles are 0 if no child or sibling exists */
+ phandle (*getchild)(phandle parent);
+ phandle (*getsibling)(phandle node);
+};
+
extern void *prom_early_alloc(unsigned long size);
/* for building the device tree */
-extern void of_pdt_build_devicetree(phandle root_node);
+extern void of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops);
extern void (*prom_build_more)(struct device_node *dp,
struct device_node ***nextp);
--
1.5.6.5
For symbols still lacking namespace qualifiers, add an of_pdt_ prefix.
Signed-off-by: Andres Salomon <[email protected]>
---
arch/sparc/kernel/leon_kernel.c | 2 +-
drivers/of/pdt.c | 40 +++++++++++++++++++-------------------
include/linux/of_pdt.h | 2 +-
3 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
index 6a7b4db..2d51527 100644
--- a/arch/sparc/kernel/leon_kernel.c
+++ b/arch/sparc/kernel/leon_kernel.c
@@ -282,5 +282,5 @@ void __init leon_init_IRQ(void)
void __init leon_init(void)
{
- prom_build_more = &leon_node_init;
+ of_pdt_build_more = &leon_node_init;
}
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index fd02fc1..31a4fb8 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -26,7 +26,7 @@
static struct of_pdt_ops *of_pdt_prom_ops __initdata;
-void __initdata (*prom_build_more)(struct device_node *dp,
+void __initdata (*of_pdt_build_more)(struct device_node *dp,
struct device_node ***nextp);
#if defined(CONFIG_SPARC)
@@ -53,7 +53,7 @@ static inline const char *of_pdt_node_name(struct device_node *dp)
#endif /* !CONFIG_SPARC */
-static struct property * __init build_one_prop(phandle node, char *prev,
+static struct property * __init of_pdt_build_one_prop(phandle node, char *prev,
char *special_name,
void *special_val,
int special_len)
@@ -100,17 +100,17 @@ static struct property * __init build_one_prop(phandle node, char *prev,
return p;
}
-static struct property * __init build_prop_list(phandle node)
+static struct property * __init of_pdt_build_prop_list(phandle node)
{
struct property *head, *tail;
- head = tail = build_one_prop(node, NULL,
+ head = tail = of_pdt_build_one_prop(node, NULL,
".node", &node, sizeof(node));
- tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
+ tail->next = of_pdt_build_one_prop(node, NULL, NULL, NULL, 0);
tail = tail->next;
while(tail) {
- tail->next = build_one_prop(node, tail->name,
+ tail->next = of_pdt_build_one_prop(node, tail->name,
NULL, NULL, 0);
tail = tail->next;
}
@@ -118,7 +118,7 @@ static struct property * __init build_prop_list(phandle node)
return head;
}
-static char * __init get_one_property(phandle node, const char *name)
+static char * __init of_pdt_get_one_property(phandle node, const char *name)
{
char *buf = "<NULL>";
int len;
@@ -132,7 +132,7 @@ static char * __init get_one_property(phandle node, const char *name)
return buf;
}
-static struct device_node * __init prom_create_node(phandle node,
+static struct device_node * __init of_pdt_create_node(phandle node,
struct device_node *parent)
{
struct device_node *dp;
@@ -146,18 +146,18 @@ static struct device_node * __init prom_create_node(phandle node,
kref_init(&dp->kref);
- dp->name = get_one_property(node, "name");
- dp->type = get_one_property(node, "device_type");
+ dp->name = of_pdt_get_one_property(node, "name");
+ dp->type = of_pdt_get_one_property(node, "device_type");
dp->phandle = node;
- dp->properties = build_prop_list(node);
+ dp->properties = of_pdt_build_prop_list(node);
irq_trans_init(dp);
return dp;
}
-static char * __init build_full_name(struct device_node *dp)
+static char * __init of_pdt_build_full_name(struct device_node *dp)
{
int len, ourlen, plen;
char *n;
@@ -177,7 +177,7 @@ static char * __init build_full_name(struct device_node *dp)
return n;
}
-static struct device_node * __init prom_build_tree(struct device_node *parent,
+static struct device_node * __init of_pdt_build_tree(struct device_node *parent,
phandle node,
struct device_node ***nextp)
{
@@ -185,7 +185,7 @@ static struct device_node * __init prom_build_tree(struct device_node *parent,
struct device_node *dp;
while (1) {
- dp = prom_create_node(node, parent);
+ dp = of_pdt_create_node(node, parent);
if (!dp)
break;
@@ -202,13 +202,13 @@ static struct device_node * __init prom_build_tree(struct device_node *parent,
#if defined(CONFIG_SPARC)
dp->path_component_name = build_path_component(dp);
#endif
- dp->full_name = build_full_name(dp);
+ dp->full_name = of_pdt_build_full_name(dp);
- dp->child = prom_build_tree(dp,
+ dp->child = of_pdt_build_tree(dp,
of_pdt_prom_ops->getchild(node), nextp);
- if (prom_build_more)
- prom_build_more(dp, nextp);
+ if (of_pdt_build_more)
+ of_pdt_build_more(dp, nextp);
node = of_pdt_prom_ops->getsibling(node);
}
@@ -223,13 +223,13 @@ void __init of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops)
BUG_ON(!ops);
of_pdt_prom_ops = ops;
- allnodes = prom_create_node(root_node, NULL);
+ allnodes = of_pdt_create_node(root_node, NULL);
#if defined(CONFIG_SPARC)
allnodes->path_component_name = "";
#endif
allnodes->full_name = "/";
nextp = &allnodes->allnext;
- allnodes->child = prom_build_tree(allnodes,
+ allnodes->child = of_pdt_build_tree(allnodes,
of_pdt_prom_ops->getchild(allnodes->phandle), &nextp);
}
diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
index 7acabff..a057417 100644
--- a/include/linux/of_pdt.h
+++ b/include/linux/of_pdt.h
@@ -36,7 +36,7 @@ extern void *prom_early_alloc(unsigned long size);
/* for building the device tree */
extern void of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops);
-extern void (*prom_build_more)(struct device_node *dp,
+extern void (*of_pdt_build_more)(struct device_node *dp,
struct device_node ***nextp);
#endif /* _LINUX_OF_PDT_H */
--
1.5.6.5
package-to-path is a PROM function which tells us the real (full) name of the
node. This provides a hook for that in the prom ops struct, and makes use
of it in the pdt code when attempting to determine a node's name. If the
hook is available, try using it (falling back to looking at the "name"
property if it fails).
Signed-off-by: Andres Salomon <[email protected]>
---
drivers/of/pdt.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
include/linux/of_pdt.h | 3 +++
2 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index 31a4fb8..28295d0 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -132,6 +132,47 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
return buf;
}
+static char * __init of_pdt_try_pkg2path(phandle node)
+{
+ char *res, *buf = NULL;
+ int len;
+
+ if (!of_pdt_prom_ops->pkg2path)
+ return NULL;
+
+ if (of_pdt_prom_ops->pkg2path(node, buf, 0, &len))
+ return NULL;
+ buf = prom_early_alloc(len + 1);
+ if (of_pdt_prom_ops->pkg2path(node, buf, len, &len)) {
+ pr_err("%s: package-to-path failed\n", __func__);
+ return NULL;
+ }
+
+ res = strrchr(buf, '/');
+ if (!res) {
+ pr_err("%s: couldn't find / in %s\n", __func__, buf);
+ return NULL;
+ }
+ return res+1;
+}
+
+/*
+ * When fetching the node's name, first try using package-to-path; if
+ * that fails (either because the arch hasn't supplied a PROM callback,
+ * or some other random failure), fall back to just looking at the node's
+ * 'name' property.
+ */
+static char * __init of_pdt_build_name(phandle node)
+{
+ char *buf;
+
+ buf = of_pdt_try_pkg2path(node);
+ if (!buf)
+ buf = of_pdt_get_one_property(node, "name");
+
+ return buf;
+}
+
static struct device_node * __init of_pdt_create_node(phandle node,
struct device_node *parent)
{
@@ -146,7 +187,7 @@ static struct device_node * __init of_pdt_create_node(phandle node,
kref_init(&dp->kref);
- dp->name = of_pdt_get_one_property(node, "name");
+ dp->name = of_pdt_build_name(node);
dp->type = of_pdt_get_one_property(node, "device_type");
dp->phandle = node;
diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
index a057417..9945e58 100644
--- a/include/linux/of_pdt.h
+++ b/include/linux/of_pdt.h
@@ -29,6 +29,9 @@ struct of_pdt_ops {
/* phandles are 0 if no child or sibling exists */
phandle (*getchild)(phandle parent);
phandle (*getsibling)(phandle node);
+
+ /* return 0 on success; fill in 'len' with number of bytes in path */
+ int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
};
extern void *prom_early_alloc(unsigned long size);
--
1.5.6.5
This functionality overlaps with patches previously submitted
by Stephen Neuendorffer. I don't care whose eventually get applied,
so long as drivers/of/* becomes buildable on x86.
Signed-off-by: Andres Salomon <[email protected]>
---
arch/x86/include/asm/irq.h | 5 +++++
arch/x86/kernel/irq.c | 8 ++++++++
include/linux/of_irq.h | 1 +
3 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h
index 5458380..0a656b9 100644
--- a/arch/x86/include/asm/irq.h
+++ b/arch/x86/include/asm/irq.h
@@ -10,6 +10,11 @@
#include <asm/apicdef.h>
#include <asm/irq_vectors.h>
+#define NO_IRQ 0
+
+/* Even though we don't support this, supply it to appease OF */
+static inline void irq_dispose_mapping(unsigned int virq) { }
+
static inline int irq_canonicalize(int irq)
{
return ((irq == 2) ? 9 : irq);
diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
index 91fd0c7..d53f639 100644
--- a/arch/x86/kernel/irq.c
+++ b/arch/x86/kernel/irq.c
@@ -7,6 +7,7 @@
#include <linux/seq_file.h>
#include <linux/smp.h>
#include <linux/ftrace.h>
+#include <linux/of.h>
#include <asm/apic.h>
#include <asm/io_apic.h>
@@ -275,6 +276,13 @@ void smp_x86_platform_ipi(struct pt_regs *regs)
EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);
+unsigned int irq_create_of_mapping(struct device_node *controller,
+ const u32 *intspec, unsigned int intsize)
+{
+ return intspec[0] + 1;
+}
+EXPORT_SYMBOL_GPL(irq_create_of_mapping);
+
#ifdef CONFIG_HOTPLUG_CPU
/* A cpu has been removed from cpu_online_mask. Reset irq affinities. */
void fixup_irqs(void)
diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
index 5929781..05ad27b 100644
--- a/include/linux/of_irq.h
+++ b/include/linux/of_irq.h
@@ -5,6 +5,7 @@
struct of_irq;
#include <linux/types.h>
#include <linux/errno.h>
+#include <linux/irq.h>
#include <linux/ioport.h>
#include <linux/of.h>
--
1.5.6.5
Make use of PROC_DEVICETREE to export the tree, and sparc's PROMTREE code to
call into OLPC's Open Firmware to build the tree.
This also adds an init hook to proc_device_tree_init so that we can ensure
the device tree has been built prior to the proc_root_init stuff attempting
to populate /proc/device-tree.
Signed-off-by: Andres Salomon <[email protected]>
---
arch/x86/Kconfig | 2 +
arch/x86/include/asm/olpc_ofw.h | 4 +
arch/x86/include/asm/prom.h | 1 +
arch/x86/kernel/Makefile | 1 +
arch/x86/kernel/olpc_ofw.c | 8 ++
arch/x86/kernel/olpc_prom.c | 152 +++++++++++++++++++++++++++++++++++++++
drivers/of/pdt.c | 2 +
fs/proc/proc_devtree.c | 4 +
include/linux/of_pdt.h | 1 +
9 files changed, 175 insertions(+), 0 deletions(-)
create mode 100644 arch/x86/include/asm/prom.h
create mode 100644 arch/x86/kernel/olpc_prom.c
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index cea0cd9..7d4ef72 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2069,6 +2069,8 @@ config OLPC_OPENFIRMWARE
bool "Support for OLPC's Open Firmware"
depends on !X86_64 && !X86_PAE
default y if OLPC
+ select OF
+ select OF_PROMTREE
help
This option adds support for the implementation of Open Firmware
that is used on the OLPC XO-1 Children's Machine.
diff --git a/arch/x86/include/asm/olpc_ofw.h b/arch/x86/include/asm/olpc_ofw.h
index 08fde47..13075df 100644
--- a/arch/x86/include/asm/olpc_ofw.h
+++ b/arch/x86/include/asm/olpc_ofw.h
@@ -28,4 +28,8 @@ static inline void setup_olpc_ofw_pgd(void) { }
#endif /* !CONFIG_OLPC_OPENFIRMWARE */
+#ifdef CONFIG_PROC_DEVICETREE
+extern void olpc_prom_build_devicetree(void);
+#endif /* CONFIG_PROC_DEVICETREE */
+
#endif /* _ASM_X86_OLPC_OFW_H */
diff --git a/arch/x86/include/asm/prom.h b/arch/x86/include/asm/prom.h
new file mode 100644
index 0000000..b4ec95f
--- /dev/null
+++ b/arch/x86/include/asm/prom.h
@@ -0,0 +1 @@
+/* dummy prom.h; here to make linux/of.h's #includes happy */
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 0925676..3d7e535 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -105,6 +105,7 @@ scx200-y += scx200_32.o
obj-$(CONFIG_OLPC) += olpc.o
obj-$(CONFIG_OLPC_OPENFIRMWARE) += olpc_ofw.o
+obj-$(CONFIG_PROC_DEVICETREE) += olpc_prom.o
obj-$(CONFIG_X86_MRST) += mrst.o
microcode-y := microcode_core.o
diff --git a/arch/x86/kernel/olpc_ofw.c b/arch/x86/kernel/olpc_ofw.c
index 3218aa7..6c4d243 100644
--- a/arch/x86/kernel/olpc_ofw.c
+++ b/arch/x86/kernel/olpc_ofw.c
@@ -1,5 +1,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_pdt.h>
#include <linux/init.h>
#include <asm/page.h>
#include <asm/setup.h>
@@ -38,6 +40,12 @@ void __init setup_olpc_ofw_pgd(void)
/* implicit optimization barrier here due to uninline function return */
early_iounmap(base, sizeof(olpc_ofw_pgd) * PTRS_PER_PGD);
+
+#ifdef CONFIG_PROC_DEVICETREE
+ /* OFW set up succesfully; use it for the device tree */
+ of_pdt_init_devicetree = olpc_prom_build_devicetree;
+#endif
+
}
int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res,
diff --git a/arch/x86/kernel/olpc_prom.c b/arch/x86/kernel/olpc_prom.c
new file mode 100644
index 0000000..fb04d8a
--- /dev/null
+++ b/arch/x86/kernel/olpc_prom.c
@@ -0,0 +1,152 @@
+/*
+ * olpc_prom.c: OLPC-specific OFW device tree support code.
+ *
+ * Paul Mackerras August 1996.
+ * Copyright (C) 1996-2005 Paul Mackerras.
+ *
+ * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
+ * {engebret|bergner}@us.ibm.com
+ *
+ * Adapted for sparc by David S. Miller [email protected]
+ * Adapted for x86/OLPC by Andres Salomon <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_pdt.h>
+#include <asm/olpc_ofw.h>
+
+static phandle __init olpc_prom_getsibling(phandle node)
+{
+ const void *args[] = { (void *)node };
+ void *res[] = { &node };
+
+ if (node == -1)
+ return 0;
+
+ if (olpc_ofw("peer", args, res) || node == -1)
+ return 0;
+
+ return node;
+}
+
+static phandle __init olpc_prom_getchild(phandle node)
+{
+ const void *args[] = { (void *)node };
+ void *res[] = { &node };
+
+ if (node == -1)
+ return 0;
+
+ if (olpc_ofw("child", args, res) || node == -1) {
+ pr_err("PROM: %s: fetching child failed!\n", __func__);
+ return 0;
+ }
+
+ return node;
+}
+
+static int __init olpc_prom_getproplen(phandle node, const char *prop)
+{
+ const void *args[] = { (void *)node, prop };
+ int len;
+ void *res[] = { &len };
+
+ if (node == -1)
+ return -1;
+
+ if (olpc_ofw("getproplen", args, res)) {
+ pr_err("PROM: %s: getproplen failed!\n", __func__);
+ return -1;
+ }
+
+ return len;
+}
+
+static int __init olpc_prom_getproperty(phandle node, const char *prop,
+ char *buf, int bufsize)
+{
+ int plen;
+
+ plen = olpc_prom_getproplen(node, prop);
+ if (plen > bufsize || plen < 1)
+ return -1;
+ else {
+ const void *args[] = { (void *)node, prop, buf, (void *)plen };
+ void *res[] = { &plen };
+
+ if (olpc_ofw("getprop", args, res)) {
+ pr_err("PROM: %s: getprop failed!\n", __func__);
+ return -1;
+ }
+ }
+
+ return plen;
+}
+
+static int __init olpc_prom_nextprop(phandle node, const char *prev, char *buf)
+{
+ const void *args[] = { (void *)node, prev, buf };
+ int success;
+ void *res[] = { &success };
+
+ buf[0] = '\0';
+
+ if (node == -1)
+ return -1;
+
+ if (olpc_ofw("nextprop", args, res) || success != 1)
+ return -1;
+
+ return 0;
+}
+
+static int __init olpc_prom_pkg2path(phandle node, char *buf,
+ const int buflen, int *len)
+{
+ const void *args[] = { (void *)node, buf, (void *)buflen };
+ void *res[] = { len };
+
+ if (node == -1)
+ return -1;
+
+ if (olpc_ofw("package-to-path", args, res) || *len < 1)
+ return -1;
+
+ return 0;
+}
+
+void * __init prom_early_alloc(unsigned long size)
+{
+ /* this is called late enough that we can alloc normally */
+ return kzalloc(size, GFP_KERNEL);
+}
+
+static struct of_pdt_ops prom_olpc_ops __initdata = {
+ .nextprop = olpc_prom_nextprop,
+ .getproplen = olpc_prom_getproplen,
+ .getproperty = olpc_prom_getproperty,
+ .getchild = olpc_prom_getchild,
+ .getsibling = olpc_prom_getsibling,
+ .pkg2path = olpc_prom_pkg2path,
+};
+
+void __init olpc_prom_build_devicetree(void)
+{
+ phandle root;
+
+ root = olpc_prom_getsibling(0);
+ if (root < 0) {
+ pr_err("PROM: unable to get root node from OFW!\n");
+ return;
+ }
+ of_pdt_build_devicetree(root, &prom_olpc_ops);
+}
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index 28295d0..07e3daa 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -29,6 +29,8 @@ static struct of_pdt_ops *of_pdt_prom_ops __initdata;
void __initdata (*of_pdt_build_more)(struct device_node *dp,
struct device_node ***nextp);
+void __initdata (*of_pdt_init_devicetree)(void);
+
#if defined(CONFIG_SPARC)
unsigned int of_pdt_unique_id __initdata;
diff --git a/fs/proc/proc_devtree.c b/fs/proc/proc_devtree.c
index d9396a4..9779039 100644
--- a/fs/proc/proc_devtree.c
+++ b/fs/proc/proc_devtree.c
@@ -11,6 +11,7 @@
#include <linux/stat.h>
#include <linux/string.h>
#include <linux/of.h>
+#include <linux/of_pdt.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <asm/prom.h>
@@ -228,6 +229,9 @@ void __init proc_device_tree_init(void)
{
struct device_node *root;
+ if (of_pdt_init_devicetree)
+ of_pdt_init_devicetree();
+
proc_device_tree = proc_mkdir("device-tree", NULL);
if (proc_device_tree == NULL)
return;
diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
index 9945e58..b4bd0ee 100644
--- a/include/linux/of_pdt.h
+++ b/include/linux/of_pdt.h
@@ -38,6 +38,7 @@ extern void *prom_early_alloc(unsigned long size);
/* for building the device tree */
extern void of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops);
+extern void (*of_pdt_init_devicetree)(void);
extern void (*of_pdt_build_more)(struct device_node *dp,
struct device_node ***nextp);
--
1.5.6.5
On Sun, Aug 29, 2010 at 11:53:52PM -0400, Andres Salomon wrote:
>
> We need phandle for some exported sparc headers; of.h isn't an
> exported header, and it would be silly to export it when all we
> really need is one or two types from it. So, move the phandle/ihandle
> definitions into types.h.
>
> diff --git a/include/linux/types.h b/include/linux/types.h
> index 01a082f..26526ea 100644
> --- a/include/linux/types.h
> +++ b/include/linux/types.h
> @@ -219,6 +219,10 @@ struct ustat {
> char f_fpack[6];
> };
>
> +/* Basic openboot/openfirmware types */
> +typedef u32 phandle;
> +typedef u32 ihandle;
> +
> #endif /* __KERNEL__ */
The above is inside #ifdef __KERNEL__ / #endif
so it is not exported as we drop code protected
by __KERNEL__ when we prepare for export.
Id addition "phandle" and "ihandle" needs to have
two underscores apended as we cannot just add the above
to the userspace namespace and expect it to be OK.
We do this for many other typers already, see __u32 for example.
Sam
> -----Original Message-----
> From: Andres Salomon [mailto:[email protected]]
> Sent: Sunday, August 29, 2010 9:06 PM
> To: [email protected]
> Cc: [email protected]; [email protected]; [email protected];
[email protected]; [email protected];
> [email protected]; Mitch Bradley; [email protected];
[email protected]; [email protected];
> [email protected]; Stephen Neuendorffer
> Subject: [PATCH 8/9] x86: of: irq additions to make drivers/of/* build
on x86
>
>
> This functionality overlaps with patches previously submitted
> by Stephen Neuendorffer. I don't care whose eventually get applied,
> so long as drivers/of/* becomes buildable on x86.
>
> Signed-off-by: Andres Salomon <[email protected]>
Agreed..
Signed-off-by: Stephen Neuendorffer <[email protected]>
> ---
> arch/x86/include/asm/irq.h | 5 +++++
> arch/x86/kernel/irq.c | 8 ++++++++
> include/linux/of_irq.h | 1 +
> 3 files changed, 14 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h
> index 5458380..0a656b9 100644
> --- a/arch/x86/include/asm/irq.h
> +++ b/arch/x86/include/asm/irq.h
> @@ -10,6 +10,11 @@
> #include <asm/apicdef.h>
> #include <asm/irq_vectors.h>
>
> +#define NO_IRQ 0
> +
> +/* Even though we don't support this, supply it to appease OF */
> +static inline void irq_dispose_mapping(unsigned int virq) { }
> +
> static inline int irq_canonicalize(int irq)
> {
> return ((irq == 2) ? 9 : irq);
> diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
> index 91fd0c7..d53f639 100644
> --- a/arch/x86/kernel/irq.c
> +++ b/arch/x86/kernel/irq.c
> @@ -7,6 +7,7 @@
> #include <linux/seq_file.h>
> #include <linux/smp.h>
> #include <linux/ftrace.h>
> +#include <linux/of.h>
>
> #include <asm/apic.h>
> #include <asm/io_apic.h>
> @@ -275,6 +276,13 @@ void smp_x86_platform_ipi(struct pt_regs *regs)
>
> EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);
>
> +unsigned int irq_create_of_mapping(struct device_node *controller,
> + const u32 *intspec, unsigned int intsize)
> +{
> + return intspec[0] + 1;
> +}
> +EXPORT_SYMBOL_GPL(irq_create_of_mapping);
> +
> #ifdef CONFIG_HOTPLUG_CPU
> /* A cpu has been removed from cpu_online_mask. Reset irq
affinities. */
> void fixup_irqs(void)
> diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
> index 5929781..05ad27b 100644
> --- a/include/linux/of_irq.h
> +++ b/include/linux/of_irq.h
> @@ -5,6 +5,7 @@
> struct of_irq;
> #include <linux/types.h>
> #include <linux/errno.h>
> +#include <linux/irq.h>
> #include <linux/ioport.h>
> #include <linux/of.h>
>
> --
> 1.5.6.5
>
This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.
On Mon, Aug 30, 2010 at 9:58 AM, Stephen Neuendorffer
<[email protected]> wrote:
>
>
>> -----Original Message-----
>> From: Andres Salomon [mailto:[email protected]]
>> Sent: Sunday, August 29, 2010 9:06 PM
>> To: [email protected]
>> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
>> [email protected]; Mitch Bradley; [email protected];
> [email protected]; [email protected];
>> [email protected]; Stephen Neuendorffer
>> Subject: [PATCH 8/9] x86: of: irq additions to make drivers/of/* build
> on x86
>>
>>
>> This functionality overlaps with patches previously submitted
>> by Stephen Neuendorffer. ?I don't care whose eventually get applied,
>> so long as drivers/of/* becomes buildable on x86.
>>
>> Signed-off-by: Andres Salomon <[email protected]>
>
> Agreed..
> Signed-off-by: Stephen Neuendorffer <[email protected]>
Okay, I've thought about this problem some more, and I think I've
decided how I want it solved. Nack on this particular patch because
it adds NO_IRQ to arch/x86/kernel/irq.c (it has been nacked before).
Instead, I'd like the of irq code to be reworked a bit to make this
nicer and isolate the NO_IRQ definition only to the OF irq .c file
(when the arch doesn't explicitly define it).
Right now, there are two files in drivers/of referencing NO_IRQ;
drivers/of/platform.c and drivers/of/irq.c. platform.c only
references in the context of figuring out how many irqs there are and
populating a resource table. I'd like to remove that code from
platform.c and add a pair of helper functions to irq.c. Then the top
of irq.c could conditionally #define NO_IRQ 0 and thereby prevent the
definition leaking out to the rest of the kernel.
Eventually I'll get around to doing this myself, but it would be
helpful to me if either you or Stephen could craft and test a patch.
Perhaps something like:
int of_irq_count(device_node *np)
{
/* Count and return the number of IRQs. */
}
int of_irq_to_resource_table(device_node *np, struct resource *res, int max)
{
for (i = 0; i < max; i++; res++)
if (of_irq_to_resource(np, i, res) == NO_IRQ)
break;
return i;
}
>> ---
>> @@ -275,6 +276,13 @@ void smp_x86_platform_ipi(struct pt_regs *regs)
>>
>> ?EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);
>>
>> +unsigned int irq_create_of_mapping(struct device_node *controller,
>> + ? ? ? ? ? ? const u32 *intspec, unsigned int intsize)
>> +{
>> + ? ? return intspec[0] + 1;
>> +}
>> +EXPORT_SYMBOL_GPL(irq_create_of_mapping);
>> +
This simplistic implementation is of course non-ideal, but it works as
a stop-gap measure until I've got the irq infrastructure more mature.
g.
On Sun, Aug 29, 2010 at 9:51 PM, Andres Salomon <[email protected]> wrote:
> These patches modify drivers/of, sparc, and x86 accordingly to add
> OLPC device-tree support. ?Updates have been made based upon Grant and
> Davem's comments. ?They've been compile-tested on sparc64 and x86, and
> runtime tested on OLPC machines.
>
> Dave's 25edd6946 commit caused some conflicts w/ patch #2;
> hopefully I mangled it properly.
I've only looked through this code lightly, but it seems fairly sane,
other than issues already raised. Since this has more impact on sparc
than anything, I'll need to have David's feedback before doing
anything with it.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
On Sun, Aug 29, 2010 at 10:07 PM, Andres Salomon <[email protected]> wrote:
>
> Make use of PROC_DEVICETREE to export the tree, and sparc's PROMTREE code to
> call into OLPC's Open Firmware to build the tree.
>
> This also adds an init hook to proc_device_tree_init so that we can ensure
> the device tree has been built prior to the proc_root_init stuff attempting
> to populate /proc/device-tree.
I'm not clear as to why this is needed. I would expect OLPC platform
setup code would take care of extracting the device tree well before
the kernel gets to setting up the representation in /proc/device-tree.
g.
>
> Signed-off-by: Andres Salomon <[email protected]>
> ---
> ?arch/x86/Kconfig ? ? ? ? ? ? ? ?| ? ?2 +
> ?arch/x86/include/asm/olpc_ofw.h | ? ?4 +
> ?arch/x86/include/asm/prom.h ? ? | ? ?1 +
> ?arch/x86/kernel/Makefile ? ? ? ?| ? ?1 +
> ?arch/x86/kernel/olpc_ofw.c ? ? ?| ? ?8 ++
> ?arch/x86/kernel/olpc_prom.c ? ? | ?152 +++++++++++++++++++++++++++++++++++++++
> ?drivers/of/pdt.c ? ? ? ? ? ? ? ?| ? ?2 +
> ?fs/proc/proc_devtree.c ? ? ? ? ?| ? ?4 +
> ?include/linux/of_pdt.h ? ? ? ? ?| ? ?1 +
> ?9 files changed, 175 insertions(+), 0 deletions(-)
> ?create mode 100644 arch/x86/include/asm/prom.h
> ?create mode 100644 arch/x86/kernel/olpc_prom.c
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index cea0cd9..7d4ef72 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -2069,6 +2069,8 @@ config OLPC_OPENFIRMWARE
> ? ? ? ?bool "Support for OLPC's Open Firmware"
> ? ? ? ?depends on !X86_64 && !X86_PAE
> ? ? ? ?default y if OLPC
> + ? ? ? select OF
> + ? ? ? select OF_PROMTREE
> ? ? ? ?help
> ? ? ? ? ?This option adds support for the implementation of Open Firmware
> ? ? ? ? ?that is used on the OLPC XO-1 Children's Machine.
> diff --git a/arch/x86/include/asm/olpc_ofw.h b/arch/x86/include/asm/olpc_ofw.h
> index 08fde47..13075df 100644
> --- a/arch/x86/include/asm/olpc_ofw.h
> +++ b/arch/x86/include/asm/olpc_ofw.h
> @@ -28,4 +28,8 @@ static inline void setup_olpc_ofw_pgd(void) { }
>
> ?#endif /* !CONFIG_OLPC_OPENFIRMWARE */
>
> +#ifdef CONFIG_PROC_DEVICETREE
> +extern void olpc_prom_build_devicetree(void);
> +#endif /* CONFIG_PROC_DEVICETREE */
> +
> ?#endif /* _ASM_X86_OLPC_OFW_H */
> diff --git a/arch/x86/include/asm/prom.h b/arch/x86/include/asm/prom.h
> new file mode 100644
> index 0000000..b4ec95f
> --- /dev/null
> +++ b/arch/x86/include/asm/prom.h
> @@ -0,0 +1 @@
> +/* dummy prom.h; here to make linux/of.h's #includes happy */
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index 0925676..3d7e535 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -105,6 +105,7 @@ scx200-y ? ? ? ? ? ? ? ? ? ?+= scx200_32.o
>
> ?obj-$(CONFIG_OLPC) ? ? ? ? ? ? += olpc.o
> ?obj-$(CONFIG_OLPC_OPENFIRMWARE) ? ? ? ?+= olpc_ofw.o
> +obj-$(CONFIG_PROC_DEVICETREE) ?+= olpc_prom.o
> ?obj-$(CONFIG_X86_MRST) ? ? ? ? += mrst.o
>
> ?microcode-y ? ? ? ? ? ? ? ? ? ? ? ? ? ?:= microcode_core.o
> diff --git a/arch/x86/kernel/olpc_ofw.c b/arch/x86/kernel/olpc_ofw.c
> index 3218aa7..6c4d243 100644
> --- a/arch/x86/kernel/olpc_ofw.c
> +++ b/arch/x86/kernel/olpc_ofw.c
> @@ -1,5 +1,7 @@
> ?#include <linux/kernel.h>
> ?#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_pdt.h>
> ?#include <linux/init.h>
> ?#include <asm/page.h>
> ?#include <asm/setup.h>
> @@ -38,6 +40,12 @@ void __init setup_olpc_ofw_pgd(void)
> ? ? ? ?/* implicit optimization barrier here due to uninline function return */
>
> ? ? ? ?early_iounmap(base, sizeof(olpc_ofw_pgd) * PTRS_PER_PGD);
> +
> +#ifdef CONFIG_PROC_DEVICETREE
> + ? ? ? /* OFW set up succesfully; use it for the device tree */
> + ? ? ? of_pdt_init_devicetree = olpc_prom_build_devicetree;
> +#endif
> +
> ?}
>
> ?int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res,
> diff --git a/arch/x86/kernel/olpc_prom.c b/arch/x86/kernel/olpc_prom.c
> new file mode 100644
> index 0000000..fb04d8a
> --- /dev/null
> +++ b/arch/x86/kernel/olpc_prom.c
> @@ -0,0 +1,152 @@
> +/*
> + * olpc_prom.c: OLPC-specific OFW device tree support code.
> + *
> + * Paul Mackerras ? ? ?August 1996.
> + * Copyright (C) 1996-2005 Paul Mackerras.
> + *
> + * ?Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
> + * ? ?{engebret|bergner}@us.ibm.com
> + *
> + * ?Adapted for sparc by David S. Miller [email protected]
> + * ?Adapted for x86/OLPC by Andres Salomon <[email protected]>
> + *
> + * ? ? ?This program is free software; you can redistribute it and/or
> + * ? ? ?modify it under the terms of the GNU General Public License
> + * ? ? ?as published by the Free Software Foundation; either version
> + * ? ? ?2 of the License, or (at your option) any later version.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/errno.h>
> +#include <linux/slab.h>
> +#include <linux/of.h>
> +#include <linux/of_pdt.h>
> +#include <asm/olpc_ofw.h>
> +
> +static phandle __init olpc_prom_getsibling(phandle node)
> +{
> + ? ? ? const void *args[] = { (void *)node };
> + ? ? ? void *res[] = { &node };
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return 0;
> +
> + ? ? ? if (olpc_ofw("peer", args, res) || node == -1)
> + ? ? ? ? ? ? ? return 0;
> +
> + ? ? ? return node;
> +}
> +
> +static phandle __init olpc_prom_getchild(phandle node)
> +{
> + ? ? ? const void *args[] = { (void *)node };
> + ? ? ? void *res[] = { &node };
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return 0;
> +
> + ? ? ? if (olpc_ofw("child", args, res) || node == -1) {
> + ? ? ? ? ? ? ? pr_err("PROM: %s: fetching child failed!\n", __func__);
> + ? ? ? ? ? ? ? return 0;
> + ? ? ? }
> +
> + ? ? ? return node;
> +}
> +
> +static int __init olpc_prom_getproplen(phandle node, const char *prop)
> +{
> + ? ? ? const void *args[] = { (void *)node, prop };
> + ? ? ? int len;
> + ? ? ? void *res[] = { &len };
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return -1;
> +
> + ? ? ? if (olpc_ofw("getproplen", args, res)) {
> + ? ? ? ? ? ? ? pr_err("PROM: %s: getproplen failed!\n", __func__);
> + ? ? ? ? ? ? ? return -1;
> + ? ? ? }
> +
> + ? ? ? return len;
> +}
> +
> +static int __init olpc_prom_getproperty(phandle node, const char *prop,
> + ? ? ? ? ? ? ? char *buf, int bufsize)
> +{
> + ? ? ? int plen;
> +
> + ? ? ? plen = olpc_prom_getproplen(node, prop);
> + ? ? ? if (plen > bufsize || plen < 1)
> + ? ? ? ? ? ? ? return -1;
> + ? ? ? else {
> + ? ? ? ? ? ? ? const void *args[] = { (void *)node, prop, buf, (void *)plen };
> + ? ? ? ? ? ? ? void *res[] = { &plen };
> +
> + ? ? ? ? ? ? ? if (olpc_ofw("getprop", args, res)) {
> + ? ? ? ? ? ? ? ? ? ? ? pr_err("PROM: %s: getprop failed!\n", __func__);
> + ? ? ? ? ? ? ? ? ? ? ? return -1;
> + ? ? ? ? ? ? ? }
> + ? ? ? }
> +
> + ? ? ? return plen;
> +}
> +
> +static int __init olpc_prom_nextprop(phandle node, const char *prev, char *buf)
> +{
> + ? ? ? const void *args[] = { (void *)node, prev, buf };
> + ? ? ? int success;
> + ? ? ? void *res[] = { &success };
> +
> + ? ? ? buf[0] = '\0';
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return -1;
> +
> + ? ? ? if (olpc_ofw("nextprop", args, res) || success != 1)
> + ? ? ? ? ? ? ? return -1;
> +
> + ? ? ? return 0;
> +}
> +
> +static int __init olpc_prom_pkg2path(phandle node, char *buf,
> + ? ? ? ? ? ? ? const int buflen, int *len)
> +{
> + ? ? ? const void *args[] = { (void *)node, buf, (void *)buflen };
> + ? ? ? void *res[] = { len };
> +
> + ? ? ? if (node == -1)
> + ? ? ? ? ? ? ? return -1;
> +
> + ? ? ? if (olpc_ofw("package-to-path", args, res) || *len < 1)
> + ? ? ? ? ? ? ? return -1;
> +
> + ? ? ? return 0;
> +}
> +
> +void * __init prom_early_alloc(unsigned long size)
> +{
> + ? ? ? /* this is called late enough that we can alloc normally */
> + ? ? ? return kzalloc(size, GFP_KERNEL);
> +}
> +
> +static struct of_pdt_ops prom_olpc_ops __initdata = {
> + ? ? ? .nextprop = olpc_prom_nextprop,
> + ? ? ? .getproplen = olpc_prom_getproplen,
> + ? ? ? .getproperty = olpc_prom_getproperty,
> + ? ? ? .getchild = olpc_prom_getchild,
> + ? ? ? .getsibling = olpc_prom_getsibling,
> + ? ? ? .pkg2path = olpc_prom_pkg2path,
> +};
> +
> +void __init olpc_prom_build_devicetree(void)
> +{
> + ? ? ? phandle root;
> +
> + ? ? ? root = olpc_prom_getsibling(0);
> + ? ? ? if (root < 0) {
> + ? ? ? ? ? ? ? pr_err("PROM: unable to get root node from OFW!\n");
> + ? ? ? ? ? ? ? return;
> + ? ? ? }
> + ? ? ? of_pdt_build_devicetree(root, &prom_olpc_ops);
> +}
> diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
> index 28295d0..07e3daa 100644
> --- a/drivers/of/pdt.c
> +++ b/drivers/of/pdt.c
> @@ -29,6 +29,8 @@ static struct of_pdt_ops *of_pdt_prom_ops __initdata;
> ?void __initdata (*of_pdt_build_more)(struct device_node *dp,
> ? ? ? ? ? ? ? ?struct device_node ***nextp);
>
> +void __initdata (*of_pdt_init_devicetree)(void);
> +
> ?#if defined(CONFIG_SPARC)
> ?unsigned int of_pdt_unique_id __initdata;
>
> diff --git a/fs/proc/proc_devtree.c b/fs/proc/proc_devtree.c
> index d9396a4..9779039 100644
> --- a/fs/proc/proc_devtree.c
> +++ b/fs/proc/proc_devtree.c
> @@ -11,6 +11,7 @@
> ?#include <linux/stat.h>
> ?#include <linux/string.h>
> ?#include <linux/of.h>
> +#include <linux/of_pdt.h>
> ?#include <linux/module.h>
> ?#include <linux/slab.h>
> ?#include <asm/prom.h>
> @@ -228,6 +229,9 @@ void __init proc_device_tree_init(void)
> ?{
> ? ? ? ?struct device_node *root;
>
> + ? ? ? if (of_pdt_init_devicetree)
> + ? ? ? ? ? ? ? of_pdt_init_devicetree();
> +
> ? ? ? ?proc_device_tree = proc_mkdir("device-tree", NULL);
> ? ? ? ?if (proc_device_tree == NULL)
> ? ? ? ? ? ? ? ?return;
> diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
> index 9945e58..b4bd0ee 100644
> --- a/include/linux/of_pdt.h
> +++ b/include/linux/of_pdt.h
> @@ -38,6 +38,7 @@ extern void *prom_early_alloc(unsigned long size);
>
> ?/* for building the device tree */
> ?extern void of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops);
> +extern void (*of_pdt_init_devicetree)(void);
>
> ?extern void (*of_pdt_build_more)(struct device_node *dp,
> ? ? ? ? ? ? ? ?struct device_node ***nextp);
> --
> 1.5.6.5
>
>
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
On Mon, 30 Aug 2010 12:14:57 -0600
Grant Likely <[email protected]> wrote:
> On Sun, Aug 29, 2010 at 10:07 PM, Andres Salomon
> <[email protected]> wrote:
> >
> > Make use of PROC_DEVICETREE to export the tree, and sparc's
> > PROMTREE code to call into OLPC's Open Firmware to build the tree.
> >
> > This also adds an init hook to proc_device_tree_init so that we can
> > ensure the device tree has been built prior to the proc_root_init
> > stuff attempting to populate /proc/device-tree.
>
> I'm not clear as to why this is needed. I would expect OLPC platform
> setup code would take care of extracting the device tree well before
> the kernel gets to setting up the representation in /proc/device-tree.
>
> g.
>
For simplicity; the OLPC platform setup code runs very early during
boot. I preferred to keep that as minimal as possible, and defer
device tree allocation until the x86 mm code has finished initializing
(this skipping all the fun bootmem/etc work that'll be happening for
x86 soon).
Of course, once it's done initializing, one can either hardcode an
olpc_init_devtree call at the end of x86's setup_arch, or we can add a
generic hook for late devtree initialization right before proc
populates /proc/device-tree. I chose the latter, but it could easily
be changed to the former if folks feel strongly about it.
I would've normally just used an initcall for it, but the proc_devtree
code runs prior to any of the initcall hooks.
On Mon, Aug 30, 2010 at 12:49 PM, Andres Salomon <[email protected]> wrote:
> On Mon, 30 Aug 2010 12:14:57 -0600
> Grant Likely <[email protected]> wrote:
>
>> On Sun, Aug 29, 2010 at 10:07 PM, Andres Salomon
>> <[email protected]> wrote:
>> >
>> > Make use of PROC_DEVICETREE to export the tree, and sparc's
>> > PROMTREE code to call into OLPC's Open Firmware to build the tree.
>> >
>> > This also adds an init hook to proc_device_tree_init so that we can
>> > ensure the device tree has been built prior to the proc_root_init
>> > stuff attempting to populate /proc/device-tree.
>>
>> I'm not clear as to why this is needed. ?I would expect OLPC platform
>> setup code would take care of extracting the device tree well before
>> the kernel gets to setting up the representation in /proc/device-tree.
>>
>> g.
>>
>
> For simplicity; the OLPC platform setup code runs very early during
> boot. ?I preferred to keep that as minimal as possible, and defer
> device tree allocation until the x86 mm code has finished initializing
> (this skipping all the fun bootmem/etc work that'll be happening for
> x86 soon).
>
> Of course, once it's done initializing, one can either hardcode an
> olpc_init_devtree call at the end of x86's setup_arch, or we can add a
> generic hook for late devtree initialization right before proc
> populates /proc/device-tree. ?I chose the latter, but it could easily
> be changed to the former if folks feel strongly about it.
>
> I would've normally just used an initcall for it, but the proc_devtree
> code runs prior to any of the initcall hooks.
Hmmm. I wonder if proc_devtree initialization could be deferred to an
initcall. That would make the problem go away.
g.