Basic ARM devicetree support
Subsystems (5)
v3 cover Basic ARM devicetree support
Third posting. v3 reverts the v2 changes to the handling of the dtb during early init. The real problem turned out to be using the wrong function for allocating early memory. Switching to alloc_bootmem() fixed the corruption issue. Memory reservation was never the issue.
v3 also simplifies the handling of reserved memory sections and adds parsing of the dtb reserved map.
I'm not asking for these patches to be merged into mainline yet, but I'm fairly confident that they should be pretty close to their final form.
Not included in this series is Russell's patch to remove early vetting of the machine type number and Rob's patch to map the region if atags or the dtb are not within the first 1MB. However, I am carrying those patches in my devicetree/arm and devicetree/test branches.
Please test.
...
This patch series allows CONFIG_OF to be enabled on ARM and allows the kernel to accept a dtb pointer from boot firmware instead of atags. If a dtb is passed, then the kernel will use the root 'compatible' property to find a matching machine_desc, and it will use it to obtain the memory layout, initrd location and kernel parameters string.
Only limited device tree support is enabled here. It does not perform any kind of device registration from device tree data. That support will be enabled in a later patch set. Rather, this series is a stable base that other engineers can use to start working on device tree support for their platforms.
Tested on Versatile (qemu) and nVidia Tegra Harmony. Kernel compiles and boots with CONFIG_OF both on and off, both with and without passing a device tree blob.
This series is reflected in the following branch (stable; will not be rebased):
git://git.secretlab.ca/git/linux-2.6 devicetree/arm
The 'clean' patches (rebased) can be found here:
git://git.secretlab.ca/git/linux-2.6 devicetree/test
---
Grant Likely (5):
arm/dt: Make __vet_atags also accept a dtb image arm/dt: consolidate atags setup into setup_machine_atags arm/dt: probe for platforms via the device tree arm/dt: Basic versatile devicetree support arm/dt: Basic tegra devicetree support
Jeremy Kerr (1):
arm/dt: Allow CONFIG_OF on ARM
arch/arm/Kconfig | 7 ++ arch/arm/include/asm/mach/arch.h | 2 arch/arm/include/asm/prom.h | 37 +++++++++ arch/arm/include/asm/setup.h | 3 + arch/arm/kernel/Makefile | 1 arch/arm/kernel/devtree.c | 136 ++++++++++++++++++++++++++++++++ arch/arm/kernel/head-common.S | 24 ++++-- arch/arm/kernel/head.S | 8 +- arch/arm/kernel/setup.c | 78 ++++++++++-------- arch/arm/mach-tegra/board-harmony.c | 6 + arch/arm/mach-versatile/versatile_ab.c | 6 + arch/arm/mach-versatile/versatile_pb.c | 6 + arch/arm/mm/init.c | 11 +++ 13 files changed, 280 insertions(+), 45 deletions(-) create mode 100644 arch/arm/include/asm/prom.h create mode 100644 arch/arm/kernel/devtree.c
Signature · 1 line
Signature
PATCH v3 1/6 arm/dt: Make __vet_atags also accept a dtb image
The dtb is passed to the kernel via register r2, which is the same method that is used to pass an atags pointer. This patch modifies __vet_atags to not clear r2 when it encounters a dtb image.
v2: fixed bugs pointed out by Nicolas Pitre
--- arch/arm/kernel/head-common.S | 24 ++++++++++++++++++------ arch/arm/kernel/head.S | 8 ++++---- 2 files changed, 22 insertions(+), 10 deletions(-)
arch/arm/kernel/head-common.S +18 -6
@@ -15,6 +15,12 @@ #define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2) #define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2) +#ifdef CONFIG_CPU_BIG_ENDIAN +#define OF_DT_MAGIC 0xd00dfeed +#else +#define OF_DT_MAGIC 0xedfe0dd0 /* 0xd00dfeed in big-endian */ +#endif + /* * Exception handling. Something went wrong and we can't proceed. We * ought to tell the user, but since we don't have any guarantee that
@@ -28,20 +34,26 @@ /* Determine validity of the r2 atags pointer. The heuristic requires * that the pointer be aligned, in the first 16k of physical RAM and - * that the ATAG_CORE marker is first and present. Future revisions + * that the ATAG_CORE marker is first and present. If CONFIG_OF_FLATTREE + * is selected, then it will also accept a dtb pointer. Future revisions * of this function may be more lenient with the physical address and * may also be able to move the ATAGS block if necessary. * * Returns: - * r2 either valid atags pointer, or zero + * r2 either valid atags pointer, valid dtb pointer, or zero * r5, r6 corrupted */ __vet_atags: tst r2, #0x3 @ aligned? bne 1f - ldr r5, [r2, #0] @ is first tag ATAG_CORE? - cmp r5, #ATAG_CORE_SIZE + ldr r5, [r2, #0] +#ifdef CONFIG_OF_FLATTREE + ldr r6, =OF_DT_MAGIC @ is it a DTB? + cmp r5, r6 + beq 2f +#endif + cmp r5, #ATAG_CORE_SIZE @ is first tag ATAG_CORE? cmpne r5, #ATAG_CORE_SIZE_EMPTY bne 1f ldr r5, [r2, #4]
@@ -49,7 +61,7 @@ __vet_atags: cmp r5, r6 bne 1f - mov pc, lr @ atag pointer is ok +2: mov pc, lr @ atag/dtb pointer is ok 1: mov r2, #0 mov pc, lr
@@ -61,7 +73,7 @@ ENDPROC(__vet_atags) * * r0 = cp#15 control register * r1 = machine ID - * r2 = atags pointer + * r2 = atags/dtb pointer * r9 = processor ID */ __INIT
arch/arm/kernel/head.S +4 -4
@@ -66,7 +66,7 @@ * * This is normally called from the decompressor code. The requirements * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0, - * r1 = machine nr, r2 = atags pointer. + * r1 = machine nr, r2 = atags or dtb pointer. * * This code is mostly position independent, so if you link the kernel at * 0xc0008000, you call this at __pa(0xc0008000).
@@ -89,7 +89,7 @@ ENTRY(stext) beq __error_p @ yes, error 'p' /* - * r1 = machine no, r2 = atags, + * r1 = machine no, r2 = atags or dtb, * r9 = cpuid, r10 = procinfo */ bl __vet_atags
@@ -347,7 +347,7 @@ __secondary_data: * * r0 = cp#15 control register * r1 = machine ID - * r2 = atags pointer + * r2 = atags or dtb pointer * r4 = page table pointer * r9 = processor ID * r13 = *virtual* address to jump to upon completion
@@ -384,7 +384,7 @@ ENDPROC(__enable_mmu) * * r0 = cp#15 control register * r1 = machine ID - * r2 = atags pointer + * r2 = atags or dtb pointer * r9 = processor ID * r13 = *virtual* address to jump to upon completion *
PATCH v3 2/6 arm/dt: Allow CONFIG_OF on ARM
In reply to Grant LikelyFrom: Jeremy Kerr <[email protected]>
Add some basic empty infrastructure for DT support on ARM.
v3: - moved cmd_line export and initrd setup to this patch to make the
series bisectable.
- switched to alloc_bootmem_align() for allocation when unflattening the device tree. memblock_alloc() was not the right interface.
--- arch/arm/Kconfig | 7 ++++++ arch/arm/include/asm/prom.h | 25 ++++++++++++++++++++++ arch/arm/include/asm/setup.h | 3 +++ arch/arm/kernel/Makefile | 1 + arch/arm/kernel/devtree.c | 47 ++++++++++++++++++++++++++++++++++++++++++ arch/arm/kernel/setup.c | 4 ++-- arch/arm/mm/init.c | 9 ++++++++ 7 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 arch/arm/include/asm/prom.h create mode 100644 arch/arm/kernel/devtree.c
arch/arm/Kconfig +7 -0
@@ -1586,6 +1586,13 @@ endmenu menu "Boot options" +config USE_OF + bool "Flattened Device Tree support" + select OF + select OF_EARLY_FLATTREE + help + Include support for flattened device tree machine descriptions. + # Compressed boot loader in ROM. Yes, we really want to ask about # TEXT and BSS so we preserve their values in the config files. config ZBOOT_ROM_TEXT
arch/arm/include/asm/prom.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* arch/arm/include/asm/prom.h +* +* Copyright (C) 2009 Canonical Ltd. <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ +#ifndef __ASMARM_PROM_H +#define __ASMARM_PROM_H + +#ifdef CONFIG_OF + +#include <asm/setup.h> +#include <asm/irq.h> + +static inline void irq_dispose_mapping (unsigned int virq) +{ +return ; +} + +#endif /* CONFIG_OF */ +#endif /* ASMARM_PROM_H */
arch/arm/include/asm/setup.h +3 -0
@@ -221,6 +221,9 @@ extern struct meminfo meminfo;#define bank_phys_end (bank) ((bank)->start + (bank)->size)#define bank_phys_size (bank) (bank)->size +extern int arm_add_memory (unsigned long start,unsigned long size); +extern char cmd_line[COMMAND_LINE_SIZE ]; +#endif /* __KERNEL__ */ #endif
arch/arm/kernel/Makefile +1 -0
@@ -43,6 +43,7 @@ obj-$(CONFIG_ARM_THUMBEE) += thumbee.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_ARM_UNWIND) += unwind.o obj-$(CONFIG_HAVE_TCM) += tcm.o +obj-$(CONFIG_OF) += devtree.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o obj-$(CONFIG_SWP_EMULATE) += swp_emulate.o CFLAGS_swp_emulate.o := -Wa,-march=armv7-a
arch/arm/kernel/devtree.c new file +47 -0
47 lines not on this page · raw message
arch/arm/kernel/setup.c +2 -2
@@ -125,7 +125,7 @@ EXPORT_SYMBOL(elf_platform);static const char *cpu_name;static const char *machine_name; -static char __initdata cmd_line[COMMAND_LINE_SIZE ]; +char cmd_line[COMMAND_LINE_SIZE ];struct machine_desc *machine_desc__initdata ;static char default_command_line[COMMAND_LINE_SIZE ]__initdata =CONFIG_CMDLINE ;
@@ -480,7 +480,7 @@ static struct machine_desc * __init setup_machine(unsigned int nr)return list; } -static int __init arm_add_memory (unsigned long start,unsigned long size) +int __init arm_add_memory (unsigned long start,unsigned long size) {struct membank *bank = &meminfo.bank[meminfo.nr_banks];
arch/arm/mm/init.c +9 -0
@@ -15,6 +15,7 @@#include <linux/mman.h> #include <linux/nodemask.h> #include <linux/initrd.h> +#include <linux/of_fdt.h> #include <linux/highmem.h> #include <linux/gfp.h> #include <linux/memblock.h>
@@ -71,6 +72,14 @@ static int __init parse_tag_initrd2(const struct tag *tag)__tagtable (ATAG_INITRD2 , parse_tag_initrd2); +#ifdef CONFIG_OF_FLATTREE +void __init early_init_dt_setup_initrd_arch (unsigned long start,unsigned long end) +{ + phys_initrd_start = start; + phys_initrd_size = end - start +1 ; +} +#endif /* CONFIG_OF_FLATTREE */ +/* * This keeps memory configuration data used by a couple memory * initialization functions, as well as show_mem() for the skipping
PATCH v3 3/6 arm/dt: consolidate atags setup into setup_machine_atags
In reply to Grant LikelyIn preparation for adding device tree support, this patch consolidates all of the atag-specific setup into a single function.
--- arch/arm/kernel/setup.c | 68 ++++++++++++++++++++++++----------------------- 1 files changed, 35 insertions(+), 33 deletions(-)
arch/arm/kernel/setup.c +35 -33
@@ -461,25 +461,6 @@ void cpu_init(void) : "r14"); } -static struct machine_desc *__init setup_machine (unsigned int nr) -{ -struct machine_desc *list; - -/* -* locate machine in the list of supported machines. -*/ - list =lookup_machine_type (nr); -if (!list) { -printk ("Machine configuration botched (nr %d), unable " -"to continue.\n" , nr); -while (1 ); - } - -printk ("Machine: %s\n" , list->name); - -return list; -} -int __init arm_add_memory (unsigned long start,unsigned long size) {struct membank *bank = &meminfo.bank[meminfo.nr_banks];
@@ -833,21 +814,23 @@ static void __init squash_mem_tags(struct tag *tag) tag->hdr.tag =ATAG_NONE ; } -void __init setup_arch (char **cmdline_p) +static struct machine_desc *__init setup_machine_tags (unsigned int nr) {struct tag *tags = (struct tag *)&init_tags;struct machine_desc *mdesc;char *from = default_command_line; -unwind_init (); - -setup_processor (); - mdesc =setup_machine (machine_arch_type); - machine_desc = mdesc; - machine_name = mdesc->name; +/* +* locate machine in the list of supported machines. +*/ + mdesc =lookup_machine_type (nr); +if (!mdesc) { +printk ("Machine configuration botched (nr %d), unable " +"to continue.\n" , nr); +while (1 ); + } -if (mdesc->soft_reboot) -reboot_setup ("s" ); +printk ("Machine: %s\n" , mdesc->name);if (__atags_pointer) tags =phys_to_virt (__atags_pointer);
@@ -875,16 +858,35 @@ void __init setup_arch(char **cmdline_p)parse_tags (tags); } - init_mm.start_code = (unsigned long ) _text; - init_mm.end_code = (unsigned long ) _etext; - init_mm.end_data = (unsigned long ) _edata; - init_mm.brk = (unsigned long ) _end; -/* parse_early_param needs a boot_command_line */ strlcpy (boot_command_line, from,COMMAND_LINE_SIZE );/* populate cmd_line too for later use, preserving boot_command_line */ strlcpy (cmd_line, boot_command_line,COMMAND_LINE_SIZE ); + +return mdesc; +} + + +void __init setup_arch (char **cmdline_p) +{ +struct machine_desc *mdesc; + +unwind_init (); + +setup_processor (); + mdesc =setup_machine_tags (machine_arch_type); + machine_desc = mdesc; + machine_name = mdesc->name; + +if (mdesc->soft_reboot) +reboot_setup ("s" ); + + init_mm.start_code = (unsigned long ) _text; + init_mm.end_code = (unsigned long ) _etext; + init_mm.end_data = (unsigned long ) _edata; + init_mm.brk = (unsigned long ) _end; + *cmdline_p = cmd_line;parse_early_param ();
PATCH v3 4/6 arm/dt: probe for platforms via the device tree
In reply to Grant LikelyIf a dtb is passed to the kernel then the kernel needs to iterate through compiled-in mdescs looking for one that matches and move the dtb data to a safe location before it gets accidentally overwritten by the kernel.
This patch creates a new function, setup_machine_fdt() which is analogous to the setup_machine_atags() created in the previous patch. It does all the early setup needed to use a device tree machine description.
v3: - Added processing of reserved list.
- Backed out the v2 change that copied instead of reserved the dtb. dtb is reserved again and the real problem was fixed by using alloc_bootmem_align() for early allocation of RAM for unflattening the tree.
- Moved cmd_line and initrd changes to earlier patch to make series bisectable.
v2: Changed to save the dtb by copying into an allocated buffer.
- Since the dtb will very likely be passed in the first 16k of ram where the interrupt vectors live, memblock_reserve() is insufficient to protect the dtb data.
--- arch/arm/include/asm/mach/arch.h | 2 + arch/arm/include/asm/prom.h | 12 +++++ arch/arm/kernel/devtree.c | 89 ++++++++++++++++++++++++++++++++++++++ arch/arm/kernel/setup.c | 8 +++ arch/arm/mm/init.c | 2 + 5 files changed, 112 insertions(+), 1 deletions(-)
arch/arm/include/asm/mach/arch.h +2 -0
@@ -22,6 +22,8 @@ struct machine_desc {unsigned int nr;/* architecture number */ const char *name;/* architecture name */ unsigned long boot_params;/* tagged list */ +const char **dt_compat;/* array of device tree +* 'compatible' strings */ unsigned int nr_irqs;/* number of IRQs */
arch/arm/include/asm/prom.h +12 -0
@@ -21,5 +21,17 @@ static inline void irq_dispose_mapping(unsigned int virq)return ; } +extern struct machine_desc *setup_machine_fdt (unsigned int dt_phys); +extern void arm_dt_memblock_reserve (void ); + +#else /* CONFIG_OF */ + +static inline struct machine_desc *setup_machine_fdt (unsigned int dt_phys) +{ +return NULL ; +} + +static inline void arm_dt_memblock_reserve (void ) { } +#endif /* CONFIG_OF */ #endif /* ASMARM_PROM_H */
arch/arm/kernel/devtree.c +89 -0
104 lines not on this page · raw message
arch/arm/kernel/setup.c +7 -1
@@ -20,6 +20,7 @@#include <linux/screen_info.h> #include <linux/init.h> #include <linux/kexec.h> +#include <linux/of_fdt.h> #include <linux/crash_dump.h> #include <linux/root_dev.h> #include <linux/cpu.h>
@@ -42,6 +43,7 @@#include <asm/cachetype.h> #include <asm/tlbflush.h> +#include <asm/prom.h> #include <asm/mach/arch.h> #include <asm/mach/irq.h> #include <asm/mach/time.h>
@@ -875,7 +877,9 @@ void __init setup_arch(char **cmdline_p)unwind_init ();setup_processor (); - mdesc =setup_machine_tags (machine_arch_type); + mdesc =setup_machine_fdt (__atags_pointer); +if (!mdesc) + mdesc =setup_machine_tags (machine_arch_type); machine_desc = mdesc; machine_name = mdesc->name;
@@ -896,6 +900,8 @@ void __init setup_arch(char **cmdline_p)paging_init (mdesc);request_standard_resources (mdesc); +unflatten_device_tree (); +#ifdef CONFIG_SMP if (is_smp ())smp_init_cpus ();
arch/arm/mm/init.c +2 -0
@@ -22,6 +22,7 @@#include <linux/sort.h> #include <asm/mach-types.h> +#include <asm/prom.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h>
@@ -322,6 +323,7 @@ void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)#endif arm_mm_memblock_reserve (); +arm_dt_memblock_reserve ();/* reserve any platform specific memblock areas */ if (mdesc->reserve)
PATCH v3 5/6 arm/dt: Basic versatile devicetree support
In reply to Grant LikelyThis patch adds adds very basic support for booting versatile with a device tree. It simply allows the existing machine_descs to match against the versatile ab & pb compatible values so that the kernel can boot. Kernel parameters and the initrd pointer is read out of the tree instead of atags.
This is not complete device tree support. This change will be reverted when a new machine_desc is added that can populate the versatile device registrations directly from data in the tree instead of using hard coded data. That change will be made in a future patch.
--- arch/arm/mach-versatile/versatile_ab.c | 6 ++++++ arch/arm/mach-versatile/versatile_pb.c | 6 ++++++ 2 files changed, 12 insertions(+), 0 deletions(-)
arch/arm/mach-versatile/versatile_ab.c +6 -0
@@ -33,6 +33,11 @@#include "core.h" +static const char *versatile_ab_match[]__initdata = { +"arm,versatile-ab" , +NULL , +}; +MACHINE_START (VERSATILE_AB ,"ARM-Versatile AB" )/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */ .boot_params = 0x00000100,
@@ -40,4 +45,5 @@ MACHINE_START(VERSATILE_AB, "ARM-Versatile AB") .init_irq = versatile_init_irq, .timer = &versatile_timer, .init_machine = versatile_init, + .dt_compat = versatile_ab_match,MACHINE_END
arch/arm/mach-versatile/versatile_pb.c +6 -0
@@ -106,6 +106,11 @@ static void __init versatile_pb_init(void) } } +static const char *versatile_pb_match[]__initdata = { +"arm,versatile-pb" , +NULL , +}; +MACHINE_START (VERSATILE_PB ,"ARM-Versatile PB" )/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */ .boot_params = 0x00000100,
@@ -113,4 +118,5 @@ MACHINE_START(VERSATILE_PB, "ARM-Versatile PB") .init_irq = versatile_init_irq, .timer = &versatile_timer, .init_machine = versatile_pb_init, + .dt_compat = versatile_pb_match,MACHINE_END
PATCH v3 6/6 arm/dt: Basic tegra devicetree support
In reply to Grant LikelyThis patch adds adds very basic support for booting tegra with a device tree. It simply allows the existing machine_descs to match against the tegra compatible values so that the kernel can boot. Kernel parameters and the initrd pointer is read out of the tree instead of atags.
This is not complete device tree support. This change will be reverted when a new machine_desc is added that can populate the device registrations directly from data in the tree instead of using hard coded data. That change will be made in a future patch.
v2: Fixed cut-and-paste error in commit text
--- arch/arm/mach-tegra/board-harmony.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
arch/arm/mach-tegra/board-harmony.c +6 -0
@@ -113,6 +113,11 @@ static void __init tegra_harmony_init(void)platform_add_devices (harmony_devices,ARRAY_SIZE (harmony_devices)); } +static const char * tegra_harmony_board_compat[] = { +"nvidia,harmony" , +NULL +}; +MACHINE_START (HARMONY ,"harmony" ) .boot_params = 0x00000100, .fixup = tegra_harmony_fixup,
@@ -120,4 +125,5 @@ MACHINE_START(HARMONY, "harmony") .init_machine = tegra_harmony_init, .map_io = tegra_map_common_io, .timer = &tegra_timer, + .dt_compat = tegra_harmony_board_compat,MACHINE_END