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=fd699c765... [1] http://dev.laptop.org/git/olpc-2.6/commit/?id=0b9734dc5f0b3d24e8f3dfedaeacb61675c838ff --
The arguments passed to OFW shouldn't be modified; update the 'args'
argument of olpc_ofw to reflect this. This saves us some later
casting away of consts.
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
arch/x86/include/asm/olpc_ofw.h | 2 +-
arch/x86/kernel/olpc.c | 2 +-
arch/x86/kernel/olpc_ofw.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/olpc_ofw.h b/arch/x86/include/asm/olpc_ofw.h
index 3e63d85..08fde47 100644
--- a/arch/x86/include/asm/olpc_ofw.h
+++ b/arch/x86/include/asm/olpc_ofw.h
@@ -12,7 +12,7 @@
#define olpc_ofw(name, args, res) \
__olpc_ofw((name), ARRAY_SIZE(args), args, ARRAY_SIZE(res), res)
-extern int __olpc_ofw(const char *name, int nr_args, void **args, int nr_res,
+extern int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res,
void **res);
/* determine whether OFW is available and lives in the proper memory */
diff --git a/arch/x86/kernel/olpc.c b/arch/x86/kernel/olpc.c
index f5ff390..0e0cdde 100644
--- a/arch/x86/kernel/olpc.c
+++ b/arch/x86/kernel/olpc.c
@@ -188,7 +188,7 @@ static void __init platform_detect(void)
{
size_t propsize;
__be32 rev;
- void *args[] = { NULL, "board-revision-int", &rev, (void *)4 };
+ const void *args[] = { NULL, "board-revision-int", &rev, (void *)4 };
void *res[] = { &propsize };
if (olpc_ofw("getprop", args, res) || propsize != 4) {
diff --git a/arch/x86/kernel/olpc_ofw.c b/arch/x86/kernel/olpc_ofw.c
index deac703..3e13a4b 100644
--- a/arch/x86/kernel/olpc_ofw.c
+++ b/arch/x86/kernel/olpc_ofw.c
@@ -39,7 +39,7 @@ void __init setup_olpc_ofw_pgd(void)
/* implicit optimization barrier here due to uninline function return */
}
-int __olpc_ofw(const char *name, int nr_args, void **args, int nr_res,
+int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res,
void **res)
{
int ofw_args[MAXARGS + 3];
--
1.5.6.5
--
Commit-ID: 54e5bc020ce1c959eaa7be18cedb734b6b13745e Gitweb: http://git.kernel.org/tip/54e5bc020ce1c959eaa7be18cedb734b6b13745e Author: Andres Salomon <dilinger@queued.net> AuthorDate: Mon, 28 Jun 2010 22:00:29 -0400 Committer: H. Peter Anvin <hpa@linux.intel.com> CommitDate: Fri, 30 Jul 2010 18:02:21 -0700 x86, olpc: Constify an olpc_ofw() arg The arguments passed to OFW shouldn't be modified; update the 'args' argument of olpc_ofw to reflect this. This saves us some later casting away of consts. Signed-off-by: Andres Salomon <dilinger@queued.net> LKML-Reference: <20100628220029.1555ac24@debian> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> --- arch/x86/include/asm/olpc_ofw.h | 2 +- arch/x86/kernel/olpc.c | 2 +- arch/x86/kernel/olpc_ofw.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/olpc_ofw.h b/arch/x86/include/asm/olpc_ofw.h index 3e63d85..08fde47 100644 --- a/arch/x86/include/asm/olpc_ofw.h +++ b/arch/x86/include/asm/olpc_ofw.h @@ -12,7 +12,7 @@ #define olpc_ofw(name, args, res) \ __olpc_ofw((name), ARRAY_SIZE(args), args, ARRAY_SIZE(res), res) -extern int __olpc_ofw(const char *name, int nr_args, void **args, int nr_res, +extern int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res, void **res); /* determine whether OFW is available and lives in the proper memory */ diff --git a/arch/x86/kernel/olpc.c b/arch/x86/kernel/olpc.c index f5ff3903..0e0cdde 100644 --- a/arch/x86/kernel/olpc.c +++ b/arch/x86/kernel/olpc.c @@ -188,7 +188,7 @@ static void __init platform_detect(void) { size_t propsize; __be32 rev; - void *args[] = { NULL, "board-revision-int", &rev, (void *)4 }; + const void *args[] = { NULL, "board-revision-int", &rev, (void *)4 }; void *res[] = { &propsize }; if (olpc_ofw("getprop", args, res) || propsize != 4) { diff --git a/arch/x86/kernel/olpc_ofw.c b/arch/x86/kernel/olpc_ofw.c index f5d499f..3218aa7 100644 --- ...
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 <dilinger@queued.net> --- arch/sparc/Kconfig | 1 + arch/sparc/include/asm/prom.h | 15 +++- arch/sparc/kernel/prom.h | 14 --- arch/sparc/kernel/prom_common.c | 173 +------------------------------ drivers/of/Kconfig | 4 + drivers/of/Makefile | 1 + drivers/of/pdt.c | 225 +++++++++++++++++++++++++++++++++++++++ include/linux/of_pdt.h | 37 +++++++ 8 files changed, 282 insertions(+), 188 deletions(-) create mode 100644 drivers/of/pdt.c create mode 100644 include/linux/of_pdt.h diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index 6f1470b..b4cb63b 100644 --- a/arch/sparc/Kconfig +++ b/arch/sparc/Kconfig @@ -150,6 +150,7 @@ config ARCH_NO_VIRT_TO_BUS config OF def_bool y + select OF_PROMTREE config ARCH_SUPPORTS_DEBUG_PAGEALLOC def_bool y if SPARC64 diff --git a/arch/sparc/include/asm/prom.h b/arch/sparc/include/asm/prom.h index f845828..0834c2a 100644 --- a/arch/sparc/include/asm/prom.h +++ b/arch/sparc/include/asm/prom.h @@ -18,6 +18,7 @@ * 2 of the License, or (at your option) any later version. */ #include <linux/types.h> +#include <linux/of_pdt.h> #include <linux/proc_fs.h> #include <linux/mutex.h> #include <asm/atomic.h> @@ -65,8 +66,18 @@ extern struct device_node *of_console_device; extern char *of_console_path; extern char *of_console_options; -extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp); -extern char *build_full_name(struct device_node *dp); +/* stuff used by of/pdt */ +extern void * prom_early_alloc(unsigned long size); +extern void irq_trans_init(struct device_node *dp); +extern char *build_path_component(struct device_node *dp); + +extern char *prom_firstprop(int node, char *buffer); +extern char *prom_nextprop(int node, const ...
From: Andres Salomon <dilinger@queued.net> Acked-by: David S. Miller <davem@davemloft.net> --
Hi Andres, Please put this select in CONFIG_SPARC instead as we want to move CONFIG_OF to drivers/og/Kconfig -- Cheers, Stephen Rothwell sfr@canb.auug.org.au http://www.canb.auug.org.au/~sfr/
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, -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. --
On Tue, 29 Jun 2010 00:50:08 -0700 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. --
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 Other than the flattened tree step; is the powerpc method dissimilar from the Sparc and OLPC method for talking to OFW? (This is not a rhetorical question, I'm want to know if I'm missing some details). The main difference I know about is that OFW can still kept alive at runtime for sparc, which powerpc does not do. However, keeping OFW callable is a separate issue from how to extract the device tree. g. --
On Tue, 29 Jun 2010 15:42:54 -0600 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/? --
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 No. g. -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. --
On Wed, 30 Jun 2010 15:52:51 -0600 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 ...
From: Andres Salomon <dilinger@queued.net> I'll need this on sparc64 at some point to support kexec() anyways. So at least for sparc you can assume that a something-->fdt translator is going to exist at some point in the future regardless of what happens here. --
On Mon, 05 Jul 2010 19:22:21 -0700 (PDT) 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. --
Hi David, I'm curious... what are your plans here? Will you be keeping OF alive between kexec()? Will the new kernel get the entire device tree from fdt, or will it still be talking to OF? How will the fdt fragments as Andres described above fit into sparc kexec (as opposed to generating one big tree as in his first option)? Cheers, g. -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. --
From: Grant Likely <grant.likely@secretlab.ca> On certain sparc64 systems, I have to stop making PROM calls early in the boot right after I fetch the device tree into the kernel. So yes for a kexec() I'll have to pass an fdt or similar to the child kernel. It could be a big linear fdt buffer, or fragments, it really doesn't matter all that much actually. --
Okay. There is already support for getting the tree out of the kernel and into fdt form via procfs. Userspace can also modify it before sending it back to kexec(). This will be easy no matter which approach Andres uses. g. -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. --
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. --
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 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 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 Do you really need this #include in this way? Can it be moved inside 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. --
On Tue, 6 Jul 2010 03:21:21 -0600 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. Not sure, will try out different variants and see what breaks. 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. --
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 Okay, so it is only the userspace interface that you're interested in, correct? You have no needs/plans (as of yet) to register devices out of the device tree? g. -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. --
On Tue, 6 Jul 2010 16:06:54 -0600 Grant Likely <grant.likely@secretlab.ca> wrote: Correct. --
Microblaze and PPC both use PROC_DEVICETREE, and OLPC will as well.. put
the Kconfig option into fs/ rather than in arch/*/Kconfig.
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
arch/microblaze/Kconfig | 8 --------
arch/powerpc/Kconfig | 8 --------
fs/proc/Kconfig | 8 ++++++++
3 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig
index 76818f9..b66c962 100644
--- a/arch/microblaze/Kconfig
+++ b/arch/microblaze/Kconfig
@@ -128,14 +128,6 @@ config OF
def_bool y
select OF_FLATTREE
-config PROC_DEVICETREE
- bool "Support for device tree in /proc"
- depends on PROC_FS
- help
- This option adds a device-tree directory under /proc which contains
- an image of the device tree that the kernel copies from Open
- Firmware or other boot firmware. If unsure, say Y here.
-
endmenu
menu "Advanced setup"
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 328774b..8a56e8b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -578,14 +578,6 @@ config SCHED_SMT
when dealing with POWER5 cpus at a cost of slightly increased
overhead in some places. If unsure say N here.
-config PROC_DEVICETREE
- bool "Support for device tree in /proc"
- depends on PROC_FS
- help
- This option adds a device-tree directory under /proc which contains
- an image of the device tree that the kernel copies from Open
- Firmware or other boot firmware. If unsure, say Y here.
-
config CMDLINE_BOOL
bool "Default bootloader kernel arguments"
diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
index 50f8f06..858a859 100644
--- a/fs/proc/Kconfig
+++ b/fs/proc/Kconfig
@@ -39,6 +39,14 @@ config PROC_VMCORE
help
Exports the dump image of crashed kernel in ELF format.
+config PROC_DEVICETREE
+ bool "Support for device tree in /proc"
+ depends on PROC_FS && (PPC || MICROBLAZE)
+ help
+ This option adds a device-tree directory under ...Looks good to me. However, I've changed the depends line to the following. depends on PROC_FS && OF && !SPARC Cheers, g. --
Make use of PROC_DEVICETREE to export the tree, and sparc's PROMTREE code to call into OLPC's Open Firmware to build the tree. (Yes, I know this leaks memory by simply using kmalloc) Signed-off-by: Andres Salomon <dilinger@queued.net> --- arch/x86/Kconfig | 5 ++ arch/x86/include/asm/olpc_prom.h | 42 +++++++++++ arch/x86/include/asm/prom.h | 5 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/olpc_ofw.c | 13 ++++ arch/x86/kernel/olpc_prom.c | 148 ++++++++++++++++++++++++++++++++++++++ fs/proc/Kconfig | 2 +- 7 files changed, 215 insertions(+), 1 deletions(-) create mode 100644 arch/x86/include/asm/olpc_prom.h create mode 100644 arch/x86/include/asm/prom.h create mode 100644 arch/x86/kernel/olpc_prom.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 71c194d..7aea004 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2071,6 +2071,11 @@ config OLPC_OPENFIRMWARE that is used on the OLPC XO-1 Children's Machine. If unsure, say N here. +config OF + def_bool y + depends on OLPC_OPENFIRMWARE + select OF_PROMTREE + endif # X86_32 config K8_NB diff --git a/arch/x86/include/asm/olpc_prom.h b/arch/x86/include/asm/olpc_prom.h new file mode 100644 index 0000000..96cdcee --- /dev/null +++ b/arch/x86/include/asm/olpc_prom.h @@ -0,0 +1,42 @@ +#include <linux/of.h> /* linux/of.h gets to determine #include ordering */ +/* + * Definitions for talking to the Open Firmware PROM on + * Power Macintosh computers. + * + * Copyright (C) 1996-2005 Paul Mackerras. + * + * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp. + * Updates for SPARC by David S. Miller + * Updates for x86/OLPC by Andres Salomon + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later ...
Hi Andres, comments below.... This hunk will need to be respun on top of Stephen's CONFIG_OF change. It's currently in my test-devicetree branch on This change should no longer be necessary with the way I've modified patch 3/4. Cheers, g. --
Hi Andres, Yeah, just make config OLPC_OPENFIRMWARE select OF and OF_PROMTREE and just use config OF bool for now. This will work even without my changes. We will remove those latter two lines later. -- Cheers, Stephen Rothwell sfr@canb.auug.org.au http://www.canb.auug.org.au/~sfr/
On Tue, 29 Jun 2010 01:12:36 -0700 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 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. --
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 However, the #ifdef/#elseif/#else/#endif approach also makes the assumption that only one kind of OFW will be supported by any given kernel. Or for that matter, both OFW and the flattened tree also become mutually exclusive due to the default behaviour override. Besides, aren't the function declarations just the interface defined by the prom extraction code? Is there any need to #ifdef that API? I would think those function prototypes should be defined by the header for the prom extraction code. g. -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. --
On Wed, 30 Jun 2010 15:13:26 -0600 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. --
These patches modify drivers/of, sparc, and x86 accordingly to add OLPC device-tree support. Updates have been made based upon Grant and Davem's comments. They've been compile-tested on sparc64 and x86, and runtime tested on OLPC machines. Dave's 25edd6946 commit caused some conflicts w/ patch #2; hopefully I mangled it properly. --
We need phandle for some exported sparc headers; of.h isn't an
exported header, and it would be silly to export it when all we
really need is one or two types from it. So, move the phandle/ihandle
definitions into types.h.
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
include/linux/of.h | 3 ---
include/linux/types.h | 4 ++++
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/linux/of.h b/include/linux/of.h
index cad7cf0..db184dc 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -25,9 +25,6 @@
#ifdef CONFIG_OF
-typedef u32 phandle;
-typedef u32 ihandle;
-
struct property {
char *name;
int length;
diff --git a/include/linux/types.h b/include/linux/types.h
index 01a082f..26526ea 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -219,6 +219,10 @@ struct ustat {
char f_fpack[6];
};
+/* Basic openboot/openfirmware types */
+typedef u32 phandle;
+typedef u32 ihandle;
+
#endif /* __KERNEL__ */
#endif /* __ASSEMBLY__ */
#endif /* _LINUX_TYPES_H */
--
1.5.6.5
--
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 --
On Mon, 30 Aug 2010 07:06:27 +0200 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 --
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 --
Rather than passing around ints everywhere, use the
phandle type where appropriate for the various functions
that talk to the PROM.
Note: this has only been compile-tested for 64bit sparc.
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
arch/sparc/include/asm/floppy_32.h | 3 +-
arch/sparc/include/asm/openprom.h | 15 +++++----
arch/sparc/include/asm/oplib_32.h | 44 +++++++++++++-------------
arch/sparc/include/asm/oplib_64.h | 39 +++++++++++-----------
arch/sparc/kernel/auxio_32.c | 4 +-
arch/sparc/kernel/btext.c | 4 +-
arch/sparc/kernel/devices.c | 23 +++++++------
arch/sparc/kernel/pcic.c | 4 +-
arch/sparc/kernel/setup_64.c | 2 +-
arch/sparc/kernel/starfire.c | 2 +-
arch/sparc/kernel/tadpole.c | 2 +-
arch/sparc/mm/init_64.c | 2 +-
arch/sparc/mm/srmmu.c | 8 +++--
arch/sparc/mm/sun4c.c | 2 +-
arch/sparc/prom/init_32.c | 2 +-
arch/sparc/prom/init_64.c | 4 +-
arch/sparc/prom/memory.c | 3 +-
arch/sparc/prom/misc_64.c | 6 ++-
arch/sparc/prom/ranges.c | 6 ++--
arch/sparc/prom/tree_32.c | 58 +++++++++++++++++----------------
arch/sparc/prom/tree_64.c | 62 ++++++++++++++++++------------------
drivers/sbus/char/jsflash.c | 2 +-
drivers/video/aty/atyfb_base.c | 3 +-
23 files changed, 156 insertions(+), 144 deletions(-)
diff --git a/arch/sparc/include/asm/floppy_32.h b/arch/sparc/include/asm/floppy_32.h
index c792830..86666f7 100644
--- a/arch/sparc/include/asm/floppy_32.h
+++ b/arch/sparc/include/asm/floppy_32.h
@@ -304,7 +304,8 @@ static struct linux_prom_registers fd_regs[2];
static int sun_floppy_init(void)
{
char state[128];
- int tnode, fd_node, num_regs;
+ phandle tnode, fd_node;
+ int num_regs;
struct resource r;
use_virtual_dma = 1;
diff --git a/arch/sparc/include/asm/openprom.h ...Transitioning into making this useful for architectures other than sparc.
This is a verbatim copy of all functions/variables that've been moved.
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
arch/sparc/kernel/prom_common.c | 190 +----------------------------------
drivers/of/pdt.c | 215 +++++++++++++++++++++++++++++++++++++++
2 files changed, 216 insertions(+), 189 deletions(-)
create mode 100644 drivers/of/pdt.c
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
index 1f830da..7b454f6 100644
--- a/arch/sparc/kernel/prom_common.c
+++ b/arch/sparc/kernel/prom_common.c
@@ -26,8 +26,6 @@
#include "prom.h"
-void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
-
struct device_node *of_console_device;
EXPORT_SYMBOL(of_console_device);
@@ -119,192 +117,6 @@ int of_find_in_proplist(const char *list, const char *match, int len)
}
EXPORT_SYMBOL(of_find_in_proplist);
-unsigned int prom_unique_id;
-
-static struct property * __init build_one_prop(phandle node, char *prev,
- char *special_name,
- void *special_val,
- int special_len)
-{
- static struct property *tmp = NULL;
- struct property *p;
- const char *name;
-
- if (tmp) {
- p = tmp;
- memset(p, 0, sizeof(*p) + 32);
- tmp = NULL;
- } else {
- p = prom_early_alloc(sizeof(struct property) + 32);
- p->unique_id = prom_unique_id++;
- }
-
- p->name = (char *) (p + 1);
- if (special_name) {
- strcpy(p->name, special_name);
- p->length = special_len;
- p->value = prom_early_alloc(special_len);
- memcpy(p->value, special_val, special_len);
- } else {
- if (prev == NULL) {
- name = prom_firstprop(node, p->name);
- } else {
- name = prom_nextprop(node, prev, p->name);
- }
-
- if (!name || strlen(name) == 0) {
- tmp = p;
- return NULL;
- }
-#ifdef CONFIG_SPARC32
- strcpy(p->name, name);
-#endif
- p->length = prom_getproplen(node, p->name);
- if ...Clean up pdt.c: - make build dependent upon config OF_PROMTREE - #ifdef out the sparc-specific stuff - create pdt-specific header Signed-off-by: Andres Salomon <dilinger@queued.net> --- arch/sparc/Kconfig | 1 + arch/sparc/include/asm/prom.h | 5 ++- arch/sparc/kernel/prom.h | 6 ---- arch/sparc/kernel/prom_common.c | 10 ++++++- drivers/of/Kconfig | 5 +++- drivers/of/Makefile | 1 + drivers/of/pdt.c | 55 +++++++++++++++++++++++++++----------- include/linux/of_pdt.h | 24 +++++++++++++++++ 8 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 include/linux/of_pdt.h diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index 491e9d6..a06c959 100644 --- a/arch/sparc/Kconfig +++ b/arch/sparc/Kconfig @@ -19,6 +19,7 @@ config SPARC bool default y select OF + select OF_PROMTREE select HAVE_IDE select HAVE_OPROFILE select HAVE_ARCH_KGDB if !SMP || SPARC64 diff --git a/arch/sparc/include/asm/prom.h b/arch/sparc/include/asm/prom.h index 291f125..56bbaad 100644 --- a/arch/sparc/include/asm/prom.h +++ b/arch/sparc/include/asm/prom.h @@ -18,6 +18,7 @@ * 2 of the License, or (at your option) any later version. */ #include <linux/types.h> +#include <linux/of_pdt.h> #include <linux/proc_fs.h> #include <linux/mutex.h> #include <asm/atomic.h> @@ -67,8 +68,8 @@ extern struct device_node *of_console_device; extern char *of_console_path; extern char *of_console_options; -extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp); -extern char *build_full_name(struct device_node *dp); +extern void irq_trans_init(struct device_node *dp); +extern char *build_path_component(struct device_node *dp); #endif /* __KERNEL__ */ #endif /* _SPARC_PROM_H */ diff --git a/arch/sparc/kernel/prom.h b/arch/sparc/kernel/prom.h index eeb04a7..cf5fe1c 100644 --- a/arch/sparc/kernel/prom.h +++ b/arch/sparc/kernel/prom.h @@ ...
Rather than assuming an architecture defines prom_getchild and friends,
define an ops struct with hooks for the various prom functions that
pdt.c needs. This ops struct is filled in by the
arch-(and sometimes firmware-)specific code, and passed to
of_pdt_build_devicetree.
Update sparc code to define the ops struct as well.
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
arch/sparc/kernel/prom_common.c | 37 ++++++++++++++++++++++++++++++++++++-
drivers/of/pdt.c | 39 ++++++++++++++++++---------------------
include/linux/of_pdt.h | 20 +++++++++++++++++++-
3 files changed, 73 insertions(+), 23 deletions(-)
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
index fe84d56..0972b39 100644
--- a/arch/sparc/kernel/prom_common.c
+++ b/arch/sparc/kernel/prom_common.c
@@ -118,11 +118,46 @@ int of_find_in_proplist(const char *list, const char *match, int len)
}
EXPORT_SYMBOL(of_find_in_proplist);
+/*
+ * SPARC32 and SPARC64's prom_nextprop() do things differently
+ * here, despite sharing the same interface. SPARC32 doesn't fill in 'buf',
+ * returning NULL on an error. SPARC64 fills in 'buf', but sets it to an
+ * empty string upon error.
+ */
+static int __init handle_nextprop_quirks(char *buf, const char *name)
+{
+ if (!name || strlen(name) == 0)
+ return -1;
+
+#ifdef CONFIG_SPARC32
+ strcpy(buf, name);
+#endif
+ return 0;
+}
+
+static int __init prom_common_nextprop(phandle node, const char *prev,
+ char *buf)
+{
+ const char *name;
+
+ buf[0] = '\0';
+ name = prom_nextprop(node, prev, buf);
+ return handle_nextprop_quirks(buf, name);
+}
+
unsigned int prom_early_allocated __initdata;
+static struct of_pdt_ops prom_sparc_ops __initdata = {
+ .nextprop = prom_common_nextprop,
+ .getproplen = prom_getproplen,
+ .getproperty = prom_getproperty,
+ .getchild = prom_getchild,
+ .getsibling = prom_getsibling,
+};
+
void __init prom_build_devicetree(void)
...For symbols still lacking namespace qualifiers, add an of_pdt_ prefix.
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
arch/sparc/kernel/leon_kernel.c | 2 +-
drivers/of/pdt.c | 40 +++++++++++++++++++-------------------
include/linux/of_pdt.h | 2 +-
3 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
index 6a7b4db..2d51527 100644
--- a/arch/sparc/kernel/leon_kernel.c
+++ b/arch/sparc/kernel/leon_kernel.c
@@ -282,5 +282,5 @@ void __init leon_init_IRQ(void)
void __init leon_init(void)
{
- prom_build_more = &leon_node_init;
+ of_pdt_build_more = &leon_node_init;
}
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index fd02fc1..31a4fb8 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -26,7 +26,7 @@
static struct of_pdt_ops *of_pdt_prom_ops __initdata;
-void __initdata (*prom_build_more)(struct device_node *dp,
+void __initdata (*of_pdt_build_more)(struct device_node *dp,
struct device_node ***nextp);
#if defined(CONFIG_SPARC)
@@ -53,7 +53,7 @@ static inline const char *of_pdt_node_name(struct device_node *dp)
#endif /* !CONFIG_SPARC */
-static struct property * __init build_one_prop(phandle node, char *prev,
+static struct property * __init of_pdt_build_one_prop(phandle node, char *prev,
char *special_name,
void *special_val,
int special_len)
@@ -100,17 +100,17 @@ static struct property * __init build_one_prop(phandle node, char *prev,
return p;
}
-static struct property * __init build_prop_list(phandle node)
+static struct property * __init of_pdt_build_prop_list(phandle node)
{
struct property *head, *tail;
- head = tail = build_one_prop(node, NULL,
+ head = tail = of_pdt_build_one_prop(node, NULL,
".node", &node, sizeof(node));
- tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
+ tail->next = of_pdt_build_one_prop(node, NULL, NULL, NULL, ...package-to-path is a PROM function which tells us the real (full) name of the
node. This provides a hook for that in the prom ops struct, and makes use
of it in the pdt code when attempting to determine a node's name. If the
hook is available, try using it (falling back to looking at the "name"
property if it fails).
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
drivers/of/pdt.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
include/linux/of_pdt.h | 3 +++
2 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index 31a4fb8..28295d0 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -132,6 +132,47 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
return buf;
}
+static char * __init of_pdt_try_pkg2path(phandle node)
+{
+ char *res, *buf = NULL;
+ int len;
+
+ if (!of_pdt_prom_ops->pkg2path)
+ return NULL;
+
+ if (of_pdt_prom_ops->pkg2path(node, buf, 0, &len))
+ return NULL;
+ buf = prom_early_alloc(len + 1);
+ if (of_pdt_prom_ops->pkg2path(node, buf, len, &len)) {
+ pr_err("%s: package-to-path failed\n", __func__);
+ return NULL;
+ }
+
+ res = strrchr(buf, '/');
+ if (!res) {
+ pr_err("%s: couldn't find / in %s\n", __func__, buf);
+ return NULL;
+ }
+ return res+1;
+}
+
+/*
+ * When fetching the node's name, first try using package-to-path; if
+ * that fails (either because the arch hasn't supplied a PROM callback,
+ * or some other random failure), fall back to just looking at the node's
+ * 'name' property.
+ */
+static char * __init of_pdt_build_name(phandle node)
+{
+ char *buf;
+
+ buf = of_pdt_try_pkg2path(node);
+ if (!buf)
+ buf = of_pdt_get_one_property(node, "name");
+
+ return buf;
+}
+
static struct device_node * __init of_pdt_create_node(phandle node,
struct device_node *parent)
{
@@ -146,7 +187,7 @@ static struct device_node * __init of_pdt_create_node(phandle node,
kref_init(&dp->kref);
...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 <dilinger@queued.net>
---
arch/x86/include/asm/irq.h | 5 +++++
arch/x86/kernel/irq.c | 8 ++++++++
include/linux/of_irq.h | 1 +
3 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h
index 5458380..0a656b9 100644
--- a/arch/x86/include/asm/irq.h
+++ b/arch/x86/include/asm/irq.h
@@ -10,6 +10,11 @@
#include <asm/apicdef.h>
#include <asm/irq_vectors.h>
+#define NO_IRQ 0
+
+/* Even though we don't support this, supply it to appease OF */
+static inline void irq_dispose_mapping(unsigned int virq) { }
+
static inline int irq_canonicalize(int irq)
{
return ((irq == 2) ? 9 : irq);
diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
index 91fd0c7..d53f639 100644
--- a/arch/x86/kernel/irq.c
+++ b/arch/x86/kernel/irq.c
@@ -7,6 +7,7 @@
#include <linux/seq_file.h>
#include <linux/smp.h>
#include <linux/ftrace.h>
+#include <linux/of.h>
#include <asm/apic.h>
#include <asm/io_apic.h>
@@ -275,6 +276,13 @@ void smp_x86_platform_ipi(struct pt_regs *regs)
EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);
+unsigned int irq_create_of_mapping(struct device_node *controller,
+ const u32 *intspec, unsigned int intsize)
+{
+ return intspec[0] + 1;
+}
+EXPORT_SYMBOL_GPL(irq_create_of_mapping);
+
#ifdef CONFIG_HOTPLUG_CPU
/* A cpu has been removed from cpu_online_mask. Reset irq affinities. */
void fixup_irqs(void)
diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
index 5929781..05ad27b 100644
--- a/include/linux/of_irq.h
+++ b/include/linux/of_irq.h
@@ -5,6 +5,7 @@
struct of_irq;
#include <linux/types.h>
#include <linux/errno.h>
+#include <linux/irq.h>
#include <linux/ioport.h>
#include <linux/of.h>
--
1.5.6.5
--
Agreed.. This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately. --
On Mon, Aug 30, 2010 at 9:58 AM, Stephen Neuendorffer
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;
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.
--
Make use of PROC_DEVICETREE to export the tree, and sparc's PROMTREE code to
call into OLPC's Open Firmware to build the tree.
This also adds an init hook to proc_device_tree_init so that we can ensure
the device tree has been built prior to the proc_root_init stuff attempting
to populate /proc/device-tree.
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
arch/x86/Kconfig | 2 +
arch/x86/include/asm/olpc_ofw.h | 4 +
arch/x86/include/asm/prom.h | 1 +
arch/x86/kernel/Makefile | 1 +
arch/x86/kernel/olpc_ofw.c | 8 ++
arch/x86/kernel/olpc_prom.c | 152 +++++++++++++++++++++++++++++++++++++++
drivers/of/pdt.c | 2 +
fs/proc/proc_devtree.c | 4 +
include/linux/of_pdt.h | 1 +
9 files changed, 175 insertions(+), 0 deletions(-)
create mode 100644 arch/x86/include/asm/prom.h
create mode 100644 arch/x86/kernel/olpc_prom.c
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index cea0cd9..7d4ef72 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2069,6 +2069,8 @@ config OLPC_OPENFIRMWARE
bool "Support for OLPC's Open Firmware"
depends on !X86_64 && !X86_PAE
default y if OLPC
+ select OF
+ select OF_PROMTREE
help
This option adds support for the implementation of Open Firmware
that is used on the OLPC XO-1 Children's Machine.
diff --git a/arch/x86/include/asm/olpc_ofw.h b/arch/x86/include/asm/olpc_ofw.h
index 08fde47..13075df 100644
--- a/arch/x86/include/asm/olpc_ofw.h
+++ b/arch/x86/include/asm/olpc_ofw.h
@@ -28,4 +28,8 @@ static inline void setup_olpc_ofw_pgd(void) { }
#endif /* !CONFIG_OLPC_OPENFIRMWARE */
+#ifdef CONFIG_PROC_DEVICETREE
+extern void olpc_prom_build_devicetree(void);
+#endif /* CONFIG_PROC_DEVICETREE */
+
#endif /* _ASM_X86_OLPC_OFW_H */
diff --git a/arch/x86/include/asm/prom.h b/arch/x86/include/asm/prom.h
new file mode 100644
index 0000000..b4ec95f
--- /dev/null
+++ b/arch/x86/include/asm/prom.h
@@ -0,0 +1 ...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. -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. --
On Mon, 30 Aug 2010 12:14:57 -0600 For simplicity; the OLPC platform setup code runs very early during boot. I preferred to keep that as minimal as possible, and defer device tree allocation until the x86 mm code has finished initializing (this skipping all the fun bootmem/etc work that'll be happening for x86 soon). Of course, once it's done initializing, one can either hardcode an olpc_init_devtree call at the end of x86's setup_arch, or we can add a generic hook for late devtree initialization right before proc populates /proc/device-tree. I chose the latter, but it could easily be changed to the former if folks feel strongly about it. I would've normally just used an initcall for it, but the proc_devtree code runs prior to any of the initcall hooks. --
Hmmm. I wonder if proc_devtree initialization could be deferred to an initcall. That would make the problem go away. g. --
I've only looked through this code lightly, but it seems fairly sane, other than issues already raised. Since this has more impact on sparc than anything, I'll need to have David's feedback before doing anything with it. g. -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. --
