RFC: OLPC/x86 device tree code
Subsystems (7)
cover RFC: OLPC/x86 device tree code
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
PATCH 1/4 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.
--- 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(-)
arch/x86/include/asm/olpc_ofw.h +1 -1
@@ -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 */
arch/x86/kernel/olpc.c +1 -1
@@ -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 ) {
arch/x86/kernel/olpc_ofw.c +1 -1
@@ -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 ];
Signature · 1 line
1.5.6.5
[tip:x86/olpc] x86, olpc: Constify an olpc_ofw() arg
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.
LKML-Reference: <20100628220029.1555ac24@debian>
--- 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(-)
arch/x86/include/asm/olpc_ofw.h +1 -1
@@ -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 */
arch/x86/kernel/olpc.c +1 -1
@@ -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 ) {
arch/x86/kernel/olpc_ofw.c +1 -1
@@ -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 ];
PATCH 2/4 sparc: break out some prom device-tree building code out into drivers/of
In reply to Andres SalomonStick code into drivers/of/pdt.c (Prom Device Tree) that other architectures with OpenFirmware resident in memory can make use of.
--- 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
arch/sparc/Kconfig +1 -0
@@ -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
arch/sparc/include/asm/prom.h +13 -2
@@ -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 */
arch/sparc/kernel/prom.h +0 -14
@@ -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;
arch/sparc/kernel/prom_common.c +1 -172
191 lines not on this page · raw message
drivers/of/Kconfig +4 -0
@@ -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
drivers/of/Makefile +1 -0
@@ -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
drivers/of/pdt.c new file +225 -0
225 lines not on this page · raw message
include/linux/of_pdt.h new file +37 -0
@@ -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 */
Signature · 1 line
1.5.6.5
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
From: Andres Salomon <[email protected]>
Date: Mon, 28 Jun 2010 22:00:37 -0400
Quoted 5 lines
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]>
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
In reply to Andres SalomonHi Andres,
arch/sparc/Kconfig config ARCH_NO_VIRT_TO_BUS · line 153
Quoted 10 lines · On Mon, 28 Jun 2010 22:00:37 -0400 Andres Salomon <[email protected]> wrote:
arch/sparc/Kconfig +1
-0@@ -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
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
In reply to Andres SalomonQuoted 5 lines · Andres Salomon
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.
Quoted 584 lines
---
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 100644include/linux/of_pdt.harch/sparc/Kconfig +0
-0@@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUSconfig OF
def_bool y
+ selectOF_PROMTREEconfig
ARCH_SUPPORTS_DEBUG_PAGEALLOC
def_bool y if SPARC64arch/sparc/include/asm/prom.h +13
-2@@ -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 */arch/sparc/kernel/prom.h +0
-14@@ -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;arch/sparc/kernel/prom_common.c +1
-172@@ -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)drivers/of/Kconfig +0
-0@@ -2,6 +2,10 @@ config OF_FLATTREEbool
depends on OFdrivers/of/Kconfig +4
-0+config OF_PROMTREE + bool + depends on OF +config
OF_DYNAMIC
def_bool y
depends on OF &&PPC_OFdrivers/of/Makefile +0
-0@@ -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.odrivers/of/pdt.c new file +225
-0@@ -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; +}include/linux/of_pdt.h new file +37
-1@@ -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
Signature · 6 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 17 lines · On Tue, 29 Jun 2010 00:50:08 -0700 Grant Likely <[email protected]>…
Quoted 5 lines · Andres Salomon
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/powerpcusing the flattened format, and one inarch/sparc. I don't want to end up maintaining both methods indrivers/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.
Quoted 2 lines
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.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 20 lines · Andres Salomon
Quoted 17 lines · On Tue, 29 Jun 2010 00:50:08 -0700 Grant Likely <[email protected]>…
Quoted 5 lines · Andres Salomon
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/powerpcusing the flattened format, and one inarch/sparc. I don't want to end up maintaining both methods indrivers/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.
Quoted 5 lines
Quoted 2 lines
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.
Quoted 3 lines
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.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 2 lines · On Tue, 29 Jun 2010 15:42:54 -0600 Grant Likely <[email protected]>…
On Tue, Jun 29, 2010 at 9:03 AM, Andres Salomon <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Sparc and OLPC have very similar
mechanisms for getting device tree info from OFW, so it makes sense to share code between them.
Quoted 7 lines
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/?
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 19 lines · Andres Salomon
Quoted 2 lines · On Tue, 29 Jun 2010 15:42:54 -0600 Grant Likely <[email protected]>…
On Tue, Jun 29, 2010 at 9:03 AM, Andres Salomon <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Sparc and OLPC have very similar
mechanisms for getting device tree info from OFW, so it makes sense to share code between them.Quoted 7 lines
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.
Quoted 2 lines
After having a look at powerpc's
flatten_device_tree, I don't see any obvious reason why OLPC couldn't use this
Okay.
Quoted 3 lines
(though it still strikes me
as weird to go fromprom->fdt->dtwhen the option ofprom->dtis 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.
Quoted 2 lines
Do you already have the patches that put
this intodrivers/of/?
No.
g.
Signature · 6 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 31 lines · On Wed, 30 Jun 2010 15:52:51 -0600 Grant Likely <[email protected]>…
Quoted 20 lines · Andres Salomon
Quoted 2 lines · On Tue, 29 Jun 2010 15:42:54 -0600 Grant Likely <[email protected]>…
On Tue, Jun 29, 2010 at 9:03 AM, Andres Salomon
<[email protected]> wrote:[...]
Quoted 5 lines
Quoted 4 lines
Sparc and OLPC have very similar
mechanisms for getting device tree info from OFW, so it makes sense to share code between them.Quoted 8 lines
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.
Quoted 2 lines
After having a look at powerpc's
flatten_device_tree, I don't see any obvious reason why OLPC couldn't use thisOkay.
Quoted 3 lines
(though it still strikes me
as weird to go fromprom->fdt->dtwhen the option ofprom->dtis available and less complex).
Quoted 7 lines
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_nodedata 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.
Quoted 5 lines
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.
David Miller
maintainerRe: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
From: Andres Salomon <[email protected]>
Date: Wed, 7 Jul 2010 04:07:34 +0000
Quoted 4 lines
- 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->fdtcode 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.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 8 lines · On Mon, 05 Jul 2010 19:22:21 -0700 (PDT) David Miller <[email protected]>…
From: Andres Salomon <[email protected]>
Date: Wed, 7 Jul 2010 04:07:34 +0000Quoted 4 lines
- 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->fdtcode will be
very nice.
Quoted 6 lines
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.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 3 lines
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.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
In reply to David MillerQuoted 8 lines · On Mon, 05 Jul 2010 19:22:21 -0700 (PDT) David Miller <[email protected]>…
From: Andres Salomon <[email protected]>
Date: Wed, 7 Jul 2010 04:07:34 +0000Quoted 4 lines
- 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->fdtcode will be
very nice.
Quoted 6 lines
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.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
In reply to David MillerQuoted 8 lines · On Mon, 05 Jul 2010 19:22:21 -0700 (PDT) David Miller <[email protected]>…
From: Andres Salomon <[email protected]>
Date: Wed, 7 Jul 2010 04:07:34 +0000Quoted 4 lines
- 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->fdtcode will be
very nice.
Quoted 6 lines
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.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
In reply to David MillerQuoted 8 lines · David Miller
From: Andres Salomon <[email protected]>
Date: Wed, 7 Jul 2010 04:07:34 +0000Quoted 4 lines
- 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->fdtcode will be very nice.
Quoted 5 lines
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.
Signature · 6 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
David Miller
maintainerRe: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
From: Grant Likely <[email protected]>
Date: Tue, 6 Jul 2010 01:00:06 -0600
Quoted 5 lines
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.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 9 lines · David Miller
From: Grant Likely <[email protected]>
Date: Tue, 6 Jul 2010 01:00:06 -0600Quoted 5 lines
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)?
Quoted 8 lines
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.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
In reply to Andres SalomonQuoted 11 lines · Andres Salomon
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->fdtcode will be very nice.
No, don't do this. It will be ugly.
Quoted 7 lines
- 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_archto grab a chunk of memory, and then allocating chunks of it viaunflatten_dt_alloc), but the difference would be that it wouldn't necessarily be contiguous, and in how it's
Quoted 8 lines
done. For example,
early_init_dt_alloc_memory_archmight be called initially to allocate a 16k chunk, and onceunflatten_dt_allocruns out of memory in that chunk, another 16k chunk might be allocated. This would also translate to sparc'sprom_early_allocbeing 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.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
In reply to Grant LikelyQuoted 31 lines · On Wed, 30 Jun 2010 15:52:51 -0600 Grant Likely <[email protected]>…
Quoted 20 lines · Andres Salomon
Quoted 2 lines · On Tue, 29 Jun 2010 15:42:54 -0600 Grant Likely <[email protected]>…
On Tue, Jun 29, 2010 at 9:03 AM, Andres Salomon
<[email protected]> wrote:[...]
Quoted 5 lines
Quoted 4 lines
Sparc and OLPC have very similar
mechanisms for getting device tree info from OFW, so it makes sense to share code between them.Quoted 8 lines
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.
Quoted 2 lines
After having a look at powerpc's
flatten_device_tree, I don't see any obvious reason why OLPC couldn't use thisOkay.
Quoted 3 lines
(though it still strikes me
as weird to go fromprom->fdt->dtwhen the option ofprom->dtis available and less complex).
Quoted 7 lines
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_nodedata 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.
Quoted 5 lines
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.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
In reply to Grant LikelyQuoted 31 lines · On Wed, 30 Jun 2010 15:52:51 -0600 Grant Likely <[email protected]>…
Quoted 20 lines · Andres Salomon
Quoted 2 lines · On Tue, 29 Jun 2010 15:42:54 -0600 Grant Likely <[email protected]>…
On Tue, Jun 29, 2010 at 9:03 AM, Andres Salomon
<[email protected]> wrote:[...]
Quoted 5 lines
Quoted 4 lines
Sparc and OLPC have very similar
mechanisms for getting device tree info from OFW, so it makes sense to share code between them.Quoted 8 lines
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.
Quoted 2 lines
After having a look at powerpc's
flatten_device_tree, I don't see any obvious reason why OLPC couldn't use thisOkay.
Quoted 3 lines
(though it still strikes me
as weird to go fromprom->fdt->dtwhen the option ofprom->dtis available and less complex).
Quoted 7 lines
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_nodedata 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.
Quoted 5 lines
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.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
In reply to Andres SalomonQuoted 5 lines · Andres Salomon
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.
Quoted 45 lines
---
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 100644include/linux/of_pdt.harch/sparc/Kconfig +0
-0@@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUSconfig OF
def_bool y
+ selectOF_PROMTREEconfig
ARCH_SUPPORTS_DEBUG_PAGEALLOC
def_bool y if SPARC64arch/sparc/include/asm/prom.h +3
-2@@ -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);
arch/sparc/include/asm/prom.h extern struct device_node *of_console_device; · line 80
Quoted 10 lines
arch/sparc/include/asm/prom.h +10
-0+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.
Quoted 23 lines
drivers/of/pdt.c new file +17
-0@@ -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>
drivers/of/pdt.c line 27
Quoted 10 lines
drivers/of/pdt.c new file +10
-0+#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. :-)
Quoted 6 lines
drivers/of/pdt.c new file +6
-0+ +#if defined(CONFIG_SPARC ) +static unsigned int prom_unique_id; + +#define inc_unique_id (p) do { \ + (p)->unique_id = prom_unique_id++; \
drivers/of/pdt.c line 43
Quoted 10 lines
drivers/of/pdt.c new file +10
-0+} 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.
Quoted 7 lines
drivers/of/pdt.c new file +7
-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)
drivers/of/pdt.c line 60
Quoted 10 lines
drivers/of/pdt.c new file +10
-0+{ + /* 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.
Quoted 155 lines
drivers/of/pdt.c new file +155
-0+{ + 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); +
drivers/of/pdt.c line 225
Quoted 10 lines
drivers/of/pdt.c new file +10
-0+ 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.
include/linux/of_pdt.h line 1
Quoted 7 lines
include/linux/of_pdt.h new file +1
-0@@ -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?
Quoted 24 lines
include/linux/of_pdt.h new file +24
-0+/* +* 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);
include/linux/of_pdt.h line 35
Quoted 10 lines
include/linux/of_pdt.h new file +10
-0+ +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.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 10 lines · On Tue, 6 Jul 2010 03:21:21 -0600 Grant Likely <[email protected]>…
Quoted 5 lines · Andres Salomon
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!
Quoted 58 lines
Quoted 50 lines
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 100644drivers/of/pdt.ccreate mode 100644include/linux/of_pdt.harch/sparc/Kconfig +0
-0@@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUSconfig OF
def_bool y
+ selectOF_PROMTREEconfig
ARCH_SUPPORTS_DEBUG_PAGEALLOC
def_bool y if SPARC64(quoted diff) +0
-0
b/arch/sparc/include/asm/prom.hindex f845828..0834c2a 100644arch/sparc/include/asm/prom.h +1
-1@@ -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(structdevice_node*dp); +/* stuff used by of/pdt */arch/sparc/include/asm/prom.h +6
-0+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);arch/sparc/include/asm/prom.h extern struct device_node *of_console_device; · line 80
Quoted 4 lines
arch/sparc/include/asm/prom.h +4
-0+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
Quoted 5 lines
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.
[...]
Quoted 12 lines
Quoted 8 lines
include/linux/of_pdt.h new file +1
-0@@ -0,0 +1,37 @@ +#include <linux/of.h> /* linux/of.h gets to determine #includeordering */
Do you really need this #include in this way? Can it be moved inside the #ifndef
OF_PDTblock below?
Not sure, will try out different variants and see what breaks.
[...]
Quoted 5 lines
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.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
Quoted 82 lines · Andres Salomon
Quoted 10 lines · On Tue, 6 Jul 2010 03:21:21 -0600 Grant Likely…
Quoted 5 lines · Andres Salomon
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!
Quoted 58 lines
Quoted 50 lines
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 100644drivers/of/pdt.ccreate mode 100644include/linux/of_pdt.harch/sparc/Kconfig +0
-0@@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUSconfig OF
def_bool y
+ selectOF_PROMTREEconfig
ARCH_SUPPORTS_DEBUG_PAGEALLOC
def_bool y if SPARC64(quoted diff) +0
-0
b/arch/sparc/include/asm/prom.hindex f845828..0834c2a 100644arch/sparc/include/asm/prom.h +1
-1@@ -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(structdevice_node*dp); +/* stuff used by of/pdt */arch/sparc/include/asm/prom.h +6
-0+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);arch/sparc/include/asm/prom.h extern struct device_node *of_console_device; · line 80
Quoted 4 lines
arch/sparc/include/asm/prom.h +4
-0+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.hQuoted 5 lines
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.
Quoted 4 lines
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.
Quoted 28 lines
I agree that op structs would be
nicer, and will probably move towards that.[...]
Quoted 12 lines
Quoted 8 lines
include/linux/of_pdt.h new file +1
-0@@ -0,0 +1,37 @@ +#include <linux/of.h> /* linux/of.h gets to determine #includeordering */
Do you really need this #include in this way? Can it be moved inside the #ifndef
OF_PDTblock below?Not sure, will try out different variants and see what breaks.
[...]
Quoted 5 lines
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?
Quoted 5 lines
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.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Re: [PATCH 2/4] sparc: break out some prom device-tree building code out into drivers/of
On Tue, 6 Jul 2010 16:06:54 -0600
Grant Likely <[email protected]> wrote:
[...]
Quoted 4 lines
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.
PATCH 3/4 proc: unify PROC_DEVICETREE config
In reply to Andres SalomonMicroblaze and PPC both use PROC_DEVICETREE, and OLPC will as well.. put the Kconfig option into fs/ rather than in arch/*/Kconfig.
--- arch/microblaze/Kconfig | 8 -------- arch/powerpc/Kconfig | 8 -------- fs/proc/Kconfig | 8 ++++++++ 3 files changed, 8 insertions(+), 16 deletions(-)
arch/microblaze/Kconfig +0 -8
@@ -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"
arch/powerpc/Kconfig +0 -8
@@ -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"
fs/proc/Kconfig +8 -0
@@ -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
Signature · 1 line
1.5.6.5
Re: [PATCH 3/4] proc: unify PROC_DEVICETREE config
Quoted 57 lines · Andres Salomon
Microblaze and PPC both use
PROC_DEVICETREE, and OLPC will as well.. put theKconfigoption intofs/rather than inarch/*/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(-)arch/microblaze/Kconfig +0
-0@@ -128,14 +128,6 @@ config OFdef_bool y
selectOF_FLATTREEarch/microblaze/Kconfig +0
-8-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"
arch/powerpc/Kconfig +0
-0@@ -578,14 +578,6 @@ config SCHED_SMTwhen dealing with POWER5 cpus at a cost of slightly increased overhead in some places. If unsure say N here.
arch/powerpc/Kconfig +0
-8-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"fs/proc/Kconfig +0
-0@@ -39,6 +39,14 @@ config PROC_VMCOREhelp
Exports the dump image of crashed kernel in ELF format.
fs/proc/Kconfig config PROC_VMCORE · line 49
Quoted 8 lines
fs/proc/Kconfig +8
-0+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.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/4 x86: OLPC: add OLPC device-tree support
In reply to Andres SalomonMake 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)
--- 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
arch/x86/Kconfig +5 -0
@@ -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
arch/x86/include/asm/olpc_prom.h new file +42 -0
42 lines not on this page · raw message
arch/x86/include/asm/prom.h new file +5 -0
@@ -0,0 +1,5 @@ +#ifdef CONFIG_OLPC_OPENFIRMWARE +# include <asm/olpc_prom.h> +#else +# error "No OFW prom defined for x86!" +#endif
arch/x86/kernel/Makefile +1 -0
@@ -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
arch/x86/kernel/olpc_ofw.c +13 -0
@@ -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 */
arch/x86/kernel/olpc_prom.c new file +148 -0
148 lines not on this page · raw message
fs/proc/Kconfig +1 -1
@@ -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
Signature · 1 line
1.5.6.5
Re: [PATCH 4/4] x86: OLPC: add OLPC device-tree support
Hi Andres, comments below....
Quoted 28 lines · Andres Salomon
Make use of
PROC_DEVICETREEto 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.hcreate mode 100644arch/x86/include/asm/prom.hcreate mode 100644arch/x86/kernel/olpc_prom.carch/x86/Kconfig +0
-0@@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWAREthat is used on the OLPC XO-1 Children's Machine. If unsure, say N here.
arch/x86/Kconfig config OLPC_OPENFIRMWARE · line 2078
Quoted 5 lines
arch/x86/Kconfig +5
-0+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 ongit://git.secretlab.ca/git/linux-2.6
Quoted 22 lines
endif #
X86_32config
K8_NBarch/x86/include/asm/olpc_prom.h new file +13
-0@@ -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
arch/x86/include/asm/olpc_prom.h line 23
Quoted 10 lines
arch/x86/include/asm/olpc_prom.h new file +10
-0+* 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?
arch/x86/include/asm/olpc_prom.h line 27
Quoted 3 lines
arch/x86/include/asm/olpc_prom.h new file +3
-0+#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?
Quoted 20 lines
arch/x86/include/asm/olpc_prom.h new file +14
-0+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 */ arch/x86/include/asm/prom.h new file +0
-0
arch/x86/include/asm/prom.h line 5
Quoted 5 lines
arch/x86/include/asm/prom.h new file +5
-0@@ -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.
Quoted 202 lines
arch/x86/kernel/Makefile +0
-0@@ -105,6 +105,7 @@ scx200-y += scx200_32.oobj-$(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
arch/x86/kernel/olpc_ofw.c +13
-0@@ -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 */ arch/x86/kernel/olpc_prom.c new file +148
-0@@ -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); +}fs/proc/Kconfig +0
-0@@ -41,7 +41,7 @@ config PROC_VMCOREconfig
PROC_DEVICETREE
bool "Support for device tree in /proc"
Quoted 2 lines
- 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.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/4] x86: OLPC: add OLPC device-tree support
Hi Andres,
Quoted 9 lines · On Tue, 29 Jun 2010 01:12:36 -0700 Grant Likely…
Quoted 9 lines
arch/x86/Kconfig +0
-0@@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWAREthat is used on the OLPC XO-1 Children's Machine. If unsure, say N here.
Quoted 9 lines
arch/x86/Kconfig config OLPC_OPENFIRMWARE · line 2078
Quoted 5 lines
arch/x86/Kconfig +5
-0+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_OFchange.
It's currently in my test-devicetree branch ongit://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.
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Re: [PATCH 4/4] x86: OLPC: add OLPC device-tree support
In reply to Grant LikelyQuoted 1 line · On Tue, 29 Jun 2010 01:12:36 -0700 Grant Likely <[email protected]>…
Hi Andres, comments below....
Thanks!
Quoted 31 lines
Quoted 28 lines · Andres Salomon
Make use of
PROC_DEVICETREEto 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 100644arch/x86/include/asm/olpc_prom.hcreate mode 100644arch/x86/include/asm/prom.h
create mode 100644arch/x86/kernel/olpc_prom.carch/x86/Kconfig +0
-0@@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWAREthat is used on the OLPC XO-1 Children's Machine. If unsure, say N here.
Quoted 9 lines
arch/x86/Kconfig config OLPC_OPENFIRMWARE · line 2078
Quoted 5 lines
arch/x86/Kconfig +5
-0+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_OFchange.
It's currently in my test-devicetree branch ongit://git.secretlab.ca/git/linux-2.6
Yep, I've changed it locally.
Quoted 37 lines
Quoted 27 lines
endif #
X86_32config
K8_NB(quoted diff) +0
-0
b/arch/x86/include/asm/olpc_prom.hnew file mode 100644 index 0000000..96cdceearch/x86/include/asm/olpc_prom.h new file +1
-0@@ -0,0 +1,42 @@ +#include <linux/of.h> /* linux/of.h gets to determine #includeordering */ +/*
+ * 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.
+ */arch/x86/include/asm/olpc_prom.h line 23
Quoted 7 lines
arch/x86/include/asm/olpc_prom.h new file +7
-0+ +#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 1Do you really need to override these from the default?
Quoted 5 lines
arch/x86/include/asm/olpc_prom.h line 27
Quoted 3 lines
arch/x86/include/asm/olpc_prom.h new file +3
-0+#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.
Quoted 20 lines
Quoted 20 lines
arch/x86/include/asm/olpc_prom.h new file +6
-0+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);arch/x86/include/asm/olpc_prom.h new file +7
-0+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 */ (quoted diff) +0
-0
b/arch/x86/include/asm/prom.hnew file mode 100644 index 0000000..7b561b2arch/x86/include/asm/prom.h new file +0
-0
Quoted 8 lines
arch/x86/include/asm/prom.h line 5
Quoted 6 lines
arch/x86/include/asm/prom.h new file +5
-0@@ -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.
_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Re: [PATCH 4/4] x86: OLPC: add OLPC device-tree support
Quoted 94 lines · Andres Salomon
Quoted 1 line · On Tue, 29 Jun 2010 01:12:36 -0700 Grant Likely…
Hi Andres, comments below....
Thanks!
Quoted 31 lines
Quoted 28 lines · Andres Salomon
Make use of
PROC_DEVICETREEto 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 100644arch/x86/include/asm/olpc_prom.hcreate mode 100644arch/x86/include/asm/prom.h
create mode 100644arch/x86/kernel/olpc_prom.carch/x86/Kconfig +0
-0@@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWAREthat is used on the OLPC XO-1 Children's Machine. If unsure, say N here.
Quoted 9 lines
arch/x86/Kconfig config OLPC_OPENFIRMWARE · line 2078
Quoted 5 lines
arch/x86/Kconfig +5
-0+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_OFchange. It's currently in my test-devicetree branch ongit://git.secretlab.ca/git/linux-2.6Yep, I've changed it locally.
Quoted 37 lines
Quoted 27 lines
endif #
X86_32config
K8_NB(quoted diff) +0
-0
b/arch/x86/include/asm/olpc_prom.hnew file mode 100644 index 0000000..96cdceearch/x86/include/asm/olpc_prom.h new file +1
-0@@ -0,0 +1,42 @@ +#include <linux/of.h> /* linux/of.h gets to determine #includeordering */ +/*
+ * 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.
+ */arch/x86/include/asm/olpc_prom.h line 23
Quoted 7 lines
arch/x86/include/asm/olpc_prom.h new file +7
-0+ +#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 1Do you really need to override these from the default?
Quoted 5 lines
arch/x86/include/asm/olpc_prom.h line 27
Quoted 3 lines
arch/x86/include/asm/olpc_prom.h new file +3
-0+#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?
Quoted 3 lines
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).
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
arch/x86/include/asm/olpc_prom.h new file +6
-0+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);arch/x86/include/asm/olpc_prom.h new file +7
-0+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 */ (quoted diff) +0
-0
b/arch/x86/include/asm/prom.hnew file mode 100644 index 0000000..7b561b2arch/x86/include/asm/prom.h new file +0
-0Quoted 8 lines
arch/x86/include/asm/prom.h line 5
Quoted 6 lines
arch/x86/include/asm/prom.h new file +5
-0@@ -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.
Quoted 3 lines
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.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Re: [PATCH 4/4] x86: OLPC: add OLPC device-tree support
Quoted 4 lines · On Wed, 30 Jun 2010 15:13:26 -0600 Grant Likely <[email protected]>…
Quoted 2 lines · Andres Salomon
On Tue, 29 Jun 2010 01:12:36 -0700
Grant Likely <[email protected]> wrote:
[...]
Quoted 38 lines
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
arch/x86/include/asm/olpc_prom.h new file +6
-0+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);arch/x86/include/asm/olpc_prom.h new file +5
-0+extern phandle prom_getchild (phandle node); +extern phandle prom_getsibling (phandle node); + +#endif /* __KERNEL__ */ +#endif /* _X86_PROM_OLPC_H */ (quoted diff) +0
-0
b/arch/x86/include/asm/prom.hnew file mode 100644 index 0000000..7b561b2arch/x86/include/asm/prom.h new file +0
-0Quoted 8 lines
arch/x86/include/asm/prom.h line 5
Quoted 6 lines
arch/x86/include/asm/prom.h new file +5
-0@@ -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.
Quoted 3 lines
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.
Quoted 4 lines
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.
_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
cover add OLPC device-tree support
In reply to Andres SalomonThese 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.
PATCH 1/9 of: move phandle/ihandle into types.h
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.
--- include/linux/of.h | 3 --- include/linux/types.h | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-)
include/linux/of.h +0 -3
@@ -25,9 +25,6 @@ #ifdef CONFIG_OF -typedef u32 phandle; -typedef u32 ihandle; - struct property { char *name; int length;
include/linux/types.h +4 -0
@@ -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 */
Signature · 1 line
1.5.6.5
Re: [PATCH 1/9] of: move phandle/ihandle into types.h
Quoted 11 lines · Andres Salomon
We need phandle for some exported sparc headers;
of.hisn'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 intotypes.h.include/linux/types.h +0
-0
include/linux/types.h struct ustat { · line 226
Quoted 8 lines
include/linux/types.h +4
-0@@ -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
Re: [PATCH 1/9] of: move phandle/ihandle into types.h
Quoted 15 lines · On Mon, 30 Aug 2010 07:06:27 +0200 Sam Ravnborg <[email protected]> wrote:
Quoted 14 lines · Andres Salomon
We need phandle for some exported sparc headers;
of.hisn'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 intotypes.h.include/linux/types.h +0
-0@@ -219,6 +219,10 @@ struct ustat {char f_fpack[6 ]; };
Quoted 9 lines
include/linux/types.h struct ustat { · line 226
Quoted 5 lines
include/linux/types.h +4
-0+/* 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.
At least for me, that's fine; I don't need phandle/ihandle to be available to userspace. The folks who work on the userspace fdt code may feel differently, however.
(I'm not sure if you're suggesting it be outside the __KERNEL__ ifdef or not..)
Quoted 8 lines
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
__u32for example.Sam
Re: [PATCH 1/9] of: move phandle/ihandle into types.h
Quoted 30 lines · Andres Salomon
Quoted 15 lines · On Mon, 30 Aug 2010 07:06:27 +0200 Sam Ravnborg <[email protected]> wrote:
Quoted 14 lines · Andres Salomon
We need phandle for some exported sparc headers;
of.hisn'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 intotypes.h.include/linux/types.h +0
-0@@ -219,6 +219,10 @@ struct ustat {char f_fpack[6 ]; };Quoted 9 lines
include/linux/types.h struct ustat { · line 226
Quoted 5 lines
include/linux/types.h +4
-0+/* 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.
Quoted 6 lines
At least for me, that's fine; I don't need phandle/ihandle to be available to userspace. The folks who work on the userspace fdt code may feel differently, however.
(I'm not sure if you're suggesting it be outside the
__KERNEL__ifdef or not..)
If the goal is to get ihandle/phandle exported to userspace then they have to be moved outside __KERNEL__.
I just tried to export sparc64 headers,
and here I found references to ihandle/phandle in a comment only sparc does not need these types today.
The relevant function took and returns an int btw.
So the above looks good considerign that userspace so far does not require ihanlde/phandle.
Sam
PATCH 2/9 sparc: convert various prom_* functions to use phandle
In reply to Andres SalomonRather 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.
--- 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(-)
arch/sparc/include/asm/floppy_32.h +2 -1
@@ -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 ;
arch/sparc/include/asm/openprom.h +8 -7
@@ -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. */
arch/sparc/include/asm/oplib_32.h +22 -22
110 lines not on this page · raw message
arch/sparc/include/asm/oplib_64.h +20 -19
@@ -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 );
arch/sparc/kernel/auxio_32.c +2 -2
@@ -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. */
arch/sparc/kernel/btext.c +2 -2
@@ -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;
arch/sparc/kernel/devices.c +12 -11
@@ -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 ;-) */
arch/sparc/kernel/pcic.c +2 -2
@@ -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",
arch/sparc/kernel/setup_64.c +1 -1
@@ -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 );
arch/sparc/kernel/starfire.c +1 -1
@@ -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 ; }
arch/sparc/kernel/tadpole.c +1 -1
@@ -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));
arch/sparc/mm/init_64.c +1 -1
@@ -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;
arch/sparc/mm/srmmu.c +5 -3
@@ -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... */
arch/sparc/mm/sun4c.c +1 -1
@@ -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);
arch/sparc/prom/init_32.c +1 -1
@@ -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. */
arch/sparc/prom/init_64.c +2 -2
@@ -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);
arch/sparc/prom/memory.c +2 -1
@@ -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));
arch/sparc/prom/misc_64.c +4 -2
@@ -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;
arch/sparc/prom/ranges.c +3 -3
@@ -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;
arch/sparc/prom/tree_32.c +30 -28
191 lines not on this page · raw message
arch/sparc/prom/tree_64.c +31 -31
196 lines not on this page · raw message
drivers/sbus/char/jsflash.c +1 -1
@@ -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;
drivers/video/aty/atyfb_base.c +2 -1
@@ -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;/*
Signature · 1 line
1.5.6.5
PATCH 3/9 sparc: break out some PROM device-tree building code out into drivers/of
In reply to Andres SalomonTransitioning into making this useful for architectures other than sparc. This is a verbatim copy of all functions/variables that've been moved.
--- 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
arch/sparc/kernel/prom_common.c +1 -189
@@ -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"
drivers/of/pdt.c new file +215 -0
215 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 4/9 sparc: make drivers/of/pdt.c no longer sparc-only
In reply to Andres SalomonClean up pdt.c:
- make build dependent upon config OF_PROMTREE
- #ifdef out the sparc-specific stuff
- create pdt-specific header
--- 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
arch/sparc/Kconfig +1 -0
@@ -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
arch/sparc/include/asm/prom.h +3 -2
@@ -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 */
arch/sparc/kernel/prom.h +0 -6
@@ -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;
arch/sparc/kernel/prom_common.c +9 -1
@@ -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); +}
drivers/of/Kconfig +4 -1
@@ -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
drivers/of/Makefile +1 -0
@@ -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
drivers/of/pdt.c +39 -16
123 lines not on this page · raw message
include/linux/of_pdt.h new file +24 -0
@@ -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 */
Signature · 1 line
1.5.6.5
PATCH 5/9 of: no longer call prom_ functions directly; use an ops structure
In reply to Andres SalomonRather 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.
--- 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(-)
arch/sparc/kernel/prom_common.c +36 -1
@@ -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",
drivers/of/pdt.c +18 -21
@@ -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); }
include/linux/of_pdt.h +19 -1
@@ -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);
Signature · 1 line
1.5.6.5
PATCH 6/9 of: add of_pdt namespace to pdt code
In reply to Andres SalomonFor symbols still lacking namespace qualifiers, add an of_pdt_ prefix.
--- 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(-)
arch/sparc/kernel/leon_kernel.c +1 -1
@@ -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; }
drivers/of/pdt.c +20 -20
@@ -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); }
include/linux/of_pdt.h +1 -1
@@ -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 */
Signature · 1 line
1.5.6.5
PATCH 7/9 of: add package-to-path support to pdt
In reply to Andres Salomonpackage-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).
--- drivers/of/pdt.c | 43 ++++++++++++++++++++++++++++++++++++++++++- include/linux/of_pdt.h | 3 +++ 2 files changed, 45 insertions(+), 1 deletions(-)
drivers/of/pdt.c +42 -1
@@ -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;
include/linux/of_pdt.h +3 -0
@@ -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);
Signature · 1 line
1.5.6.5
PATCH 8/9 x86: of: irq additions to make drivers/of/* build on x86
In reply to Andres SalomonThis 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.
--- 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(-)
arch/x86/include/asm/irq.h +5 -0
@@ -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);
arch/x86/kernel/irq.c +8 -0
@@ -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 )
include/linux/of_irq.h +1 -0
@@ -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>
Signature · 1 line
1.5.6.5
RE: [PATCH 8/9] x86: of: irq additions to make drivers/of/* build on x86
Quoted 7 lines
-----Original Message-----
From: Andres Salomon [mailto:[email protected]]
Sent: Sunday, August 29, 2010 9:06 PM
To: devicetree-discuss-uLR06cmDAlY/[email protected]
Cc: [email protected]; [email protected]; [email protected];
[email protected]; [email protected];
Quoted 1 line
[email protected]; Mitch Bradley; [email protected];
[email protected]; davem-fT/PcQaiUtIeIZ0/[email protected];
Quoted 2 lines
grant.likely-s3s/[email protected]; Stephen Neuendorffer
Subject: [PATCH 8/9] x86: of: irq additions to makedrivers/of/*build
on x86
Quoted 7 lines
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..
Quoted 37 lines
--- 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(-)arch/x86/include/asm/irq.h +5
-0@@ -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);arch/x86/kernel/irq.c +1
-0@@ -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);
arch/x86/kernel/irq.c void smp_x86_platform_ipi(struct pt_regs *regs) · line 287
Quoted 10 lines
arch/x86/kernel/irq.c +7
-0+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. */
Quoted 14 lines
arch/x86/kernel/irq.c +0
-0void fixup_irqs (void )include/linux/of_irq.h +1
-1@@ -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> --
Quoted 2 lines
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.
Re: [PATCH 8/9] x86: of: irq additions to make drivers/of/* build on x86
Quoted 15 lines · Stephen Neuendorffer
Quoted 7 lines
-----Original Message-----
From: Andres Salomon [mailto:[email protected]]
Sent: Sunday, August 29, 2010 9:06 PM
To: devicetree-discuss-uLR06cmDAlY/[email protected]
Cc: [email protected]; [email protected]; [email protected];[email protected]; [email protected];
Quoted 1 line
[email protected]; Mitch Bradley; [email protected];
[email protected]; davem-fT/PcQaiUtIeIZ0/[email protected];
Quoted 2 lines
grant.likely-s3s/[email protected]; Stephen Neuendorffer
Subject: [PATCH 8/9] x86: of: irq additions to makedrivers/of/*buildon x86
Quoted 2 lines
Quoted 8 lines
Quoted 5 lines
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;
}Quoted 5 lines
Quoted 5 lines
---
arch/x86/kernel/irq.c +0
-0@@ -275,6 +276,13 @@ void smp_x86_platform_ipi(struct pt_regs *regs) EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);
Quoted 7 lines
arch/x86/kernel/irq.c void smp_x86_platform_ipi(struct pt_regs *regs) · line 285
Quoted 7 lines
arch/x86/kernel/irq.c +7
-0+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.
PATCH 9/9 x86: OLPC: add OLPC device-tree support
In reply to Andres SalomonMake 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.
--- 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
arch/x86/Kconfig +2 -0
@@ -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.
arch/x86/include/asm/olpc_ofw.h +4 -0
@@ -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 */
arch/x86/include/asm/prom.h new file +1 -0
@@ -0,0 +1 @@ +/* dummy prom.h; here to make linux/of.h's #includes happy */
arch/x86/kernel/Makefile +1 -0
@@ -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
arch/x86/kernel/olpc_ofw.c +8 -0
@@ -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,
arch/x86/kernel/olpc_prom.c new file +152 -0
152 lines not on this page · raw message
drivers/of/pdt.c +2 -0
@@ -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 ;
fs/proc/proc_devtree.c +4 -0
@@ -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 ;
include/linux/of_pdt.h +1 -0
@@ -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);
Signature · 1 line
1.5.6.5
Re: [PATCH 9/9] x86: OLPC: add OLPC device-tree support
Quoted 7 lines · Andres Salomon
Make use of
PROC_DEVICETREEto 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_initso that we can ensure the device tree has been built prior to theproc_root_initstuff 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.
Quoted 295 lines
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 100644arch/x86/kernel/olpc_prom.carch/x86/Kconfig +0
-0@@ -2069,6 +2069,8 @@ config OLPC_OPENFIRMWAREbool "Support for OLPC's Open Firmware"
depends on !X86_64 && !X86_PAE
default y if OLPC
+ select OF
+ selectOF_PROMTREE
help
This option adds support for the implementation of Open Firmware that is used on the OLPC XO-1 Children's Machine.arch/x86/include/asm/olpc_ofw.h +4
-0@@ -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 */arch/x86/include/asm/prom.h new file +1
-0@@ -0,0 +1 @@ +/* dummy prom.h; here to make linux/of.h's #includes happy */ arch/x86/kernel/Makefile +0
-0@@ -105,6 +105,7 @@ scx200-y += scx200_32.oobj-$(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
arch/x86/kernel/olpc_ofw.c +8
-0@@ -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,arch/x86/kernel/olpc_prom.c new file +152
-0@@ -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); +}drivers/of/pdt.c +2
-0@@ -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;fs/proc/proc_devtree.c +4
-0@@ -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;include/linux/of_pdt.h +1
-1@@ -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
Signature · 6 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 9/9] x86: OLPC: add OLPC device-tree support
Quoted 10 lines · On Mon, 30 Aug 2010 12:14:57 -0600 Grant Likely <[email protected]>…
Quoted 7 lines · Andres Salomon
Make use of
PROC_DEVICETREEto 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_initso that we can ensure the device tree has been built prior to theproc_root_initstuff attempting to populate/proc/device-tree.
Quoted 6 lines
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.
Re: [PATCH 9/9] x86: OLPC: add OLPC device-tree support
Quoted 26 lines · Andres Salomon
Quoted 10 lines · On Mon, 30 Aug 2010 12:14:57 -0600 Grant Likely <[email protected]>…
Quoted 7 lines · Andres Salomon
Make use of
PROC_DEVICETREEto 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_initso that we can ensure the device tree has been built prior to theproc_root_initstuff attempting to populate/proc/device-tree.Quoted 6 lines
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).
Quoted 8 lines
Of course, once it's done initializing, one can either hardcode an
olpc_init_devtreecall at the end of x86'ssetup_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_devtreecode 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.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/9] add OLPC device-tree support
In reply to Andres SalomonQuoted 7 lines · Andres Salomon
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
25edd6946commit 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.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.