Skip to contentSkip to conversation

arm: initial device tree support (#3)

PATCH In review David Vrabel 3 participants 20 messages Feb 13, 2012 – Mar 14, 2012

lore
Share & tools
lore
#0 lore raw

cover arm: initial device tree support (#3)

This series adds preliminary device tree support to Xen for ARM.

libfdt for parsing a device tree in flattened device tree (fdt) format and added and used to find the location and size of RAM. This info is then used when relocating Xen and setting up the mm and heaps.

Since we don't have a bootloader when using the model the device tree blob (DTB) is linked into .dtb section of the Xen image. The CONFIG_DTB_FILE make variable (set in .config or on the make command line) gives the name of the DTB file to use. See the wiki[1] for a device tree for the model.

This series is also available in the device-tree-v3 branch of
git://xenbits.xen.org/people/dvrabel/xen-unstable.git

Changes since v2:

- use the CONFIG_DTB_FILE variable instead of a hardcoded path for the DTB file.

Changes since v1:

- map DTB in head.S using the L2 slot after the fixmap.
- new patch 8 for setting up mm/heaps.

David

[1] http://wiki.xen.org/wiki/Xen_ARMv7_with_Virtualization_Extensions

#1 lore raw

PATCH 1/8 libfdt: add version 1.3.0

From: David Vrabel <[email protected]>

Add libfdt 1.3.0 from http://git.jdl.com/gitweb/?p=dtc.git

This will be used by Xen to parse the DTBs provided by bootloaders on ARM platforms.

---
 xen/common/libfdt/Makefile.libfdt   |   10 +
 xen/common/libfdt/TODO              |    3 +
 xen/common/libfdt/fdt.c             |  222 +++++++
 xen/common/libfdt/fdt.h             |   60 ++
 xen/common/libfdt/fdt_ro.c          |  574 ++++++++++++++++
 xen/common/libfdt/fdt_rw.c          |  465 +++++++++++++
 xen/common/libfdt/fdt_strerror.c    |   96 +++
 xen/common/libfdt/fdt_sw.c          |  256 ++++++++
 xen/common/libfdt/fdt_wip.c         |  118 ++++
 xen/common/libfdt/libfdt.h          | 1235 +++++++++++++++++++++++++++++++++++
 xen/common/libfdt/libfdt_env.h      |   23 +
 xen/common/libfdt/libfdt_internal.h |   95 +++
 xen/common/libfdt/version.lds       |   54 ++
 13 files changed, 3211 insertions(+), 0 deletions(-)
 create mode 100644 xen/common/libfdt/Makefile.libfdt
 create mode 100644 xen/common/libfdt/TODO
 create mode 100644 xen/common/libfdt/fdt.c
 create mode 100644 xen/common/libfdt/fdt.h
 create mode 100644 xen/common/libfdt/fdt_ro.c
 create mode 100644 xen/common/libfdt/fdt_rw.c
 create mode 100644 xen/common/libfdt/fdt_strerror.c
 create mode 100644 xen/common/libfdt/fdt_sw.c
 create mode 100644 xen/common/libfdt/fdt_wip.c
 create mode 100644 xen/common/libfdt/libfdt.h
 create mode 100644 xen/common/libfdt/libfdt_env.h
 create mode 100644 xen/common/libfdt/libfdt_internal.h
 create mode 100644 xen/common/libfdt/version.lds
xen/common/libfdt/Makefile.libfdt new file +10 -0
new file mode 100644
index 0000000..d55a6f8
@@ -0,0 +1,10 @@
+# Makefile.libfdt
+#
+# This is not a complete Makefile of itself.  Instead, it is designed to
+# be easily embeddable into other systems of Makefiles.
+#
+LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
+LIBFDT_INCLUDES = fdt.h libfdt.h
+LIBFDT_VERSION = version.lds
+LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c
+LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
xen/common/libfdt/TODO new file +3 -0
new file mode 100644
index 0000000..288437e
@@ -0,0 +1,3 @@
+- Tree traversal functions
+- Graft function
+- Complete libfdt.h documenting comments
xen/common/libfdt/fdt.c new file +222 -0

222 lines not on this page · raw message

xen/common/libfdt/fdt.h new file +60 -0

60 lines not on this page · raw message

xen/common/libfdt/fdt_ro.c new file +574 -0

574 lines not on this page · raw message

xen/common/libfdt/fdt_rw.c new file +465 -0

465 lines not on this page · raw message

xen/common/libfdt/fdt_strerror.c new file +96 -0

96 lines not on this page · raw message

xen/common/libfdt/fdt_sw.c new file +256 -0

256 lines not on this page · raw message

xen/common/libfdt/fdt_wip.c new file +118 -0

118 lines not on this page · raw message

xen/common/libfdt/libfdt.h new file +1235 -0

1,196 lines not on this page · raw message

xen/common/libfdt/libfdt_env.h new file +23 -0
new file mode 100644
index 0000000..449bf60

Lines of this file are not shown. View the raw message.

xen/common/libfdt/libfdt_internal.h new file +95 -0

95 lines not on this page · raw message

xen/common/libfdt/version.lds new file +54 -0

54 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.2.5

Part of the diff is not shown here. View the raw message.

#2 lore raw

PATCH 2/8 libfdt: fixup libfdt_env.h for xen

In reply to David Vrabel

From: David Vrabel <[email protected]>

---
 xen/common/libfdt/libfdt_env.h |   27 ++++++++++-----------------
 xen/include/xen/types.h        |    2 ++
 2 files changed, 12 insertions(+), 17 deletions(-)
xen/common/libfdt/libfdt_env.h +10 -17
index 449bf60..8c0c030 100644
@@ -1,23 +1,16 @@
 #ifndef _LIBFDT_ENV_H
 #define _LIBFDT_ENV_H
 
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h>
+#include <xen/config.h>
+#include <xen/types.h>
+#include <xen/string.h>
+#include <asm/byteorder.h>
 
-#define _B(n)	((unsigned long long)((uint8_t *)&x)[n])
-static inline uint32_t fdt32_to_cpu(uint32_t x)
-{
-	return (_B(0) << 24) | (_B(1) << 16) | (_B(2) << 8) | _B(3);
-}
-#define cpu_to_fdt32(x) fdt32_to_cpu(x)
-
-static inline uint64_t fdt64_to_cpu(uint64_t x)
-{
-	return (_B(0) << 56) | (_B(1) << 48) | (_B(2) << 40) | (_B(3) << 32)
-		| (_B(4) << 24) | (_B(5) << 16) | (_B(6) << 8) | _B(7);
-}
-#define cpu_to_fdt64(x) fdt64_to_cpu(x)
-#undef _B
+#define fdt16_to_cpu(x) be16_to_cpu(x)
+#define cpu_to_fdt16(x) cpu_to_be16(x)
+#define fdt32_to_cpu(x) be32_to_cpu(x)
+#define cpu_to_fdt32(x) cpu_to_be32(x)
+#define fdt64_to_cpu(x) be64_to_cpu(x)
+#define cpu_to_fdt64(x) cpu_to_be64(x)
 
 #endif /* _LIBFDT_ENV_H */
xen/include/xen/types.h +2 -0
index ac96647..8596ded 100644
@@ -57,4 +57,6 @@ typedef __u32 __be32;
 typedef __u64 __le64;
 typedef __u64 __be64;
 
+typedef unsigned long uintptr_t;
+
 #endif /* __TYPES_H__ */
Signature · 1 line
1.7.2.5
#3 lore raw

PATCH 3/8 libfdt: add to build

In reply to David Vrabel

From: David Vrabel <[email protected]>

---
 xen/arch/arm/Rules.mk      |    2 ++
 xen/common/Makefile        |    1 +
 xen/common/libfdt/Makefile |    5 +++++
 3 files changed, 8 insertions(+), 0 deletions(-)
 create mode 100644 xen/common/libfdt/Makefile
xen/arch/arm/Rules.mk +2 -0
index 336e209..14082dd 100644
@@ -6,6 +6,8 @@
 # 'make clean' before rebuilding.
 #
 
+HAS_DEVICE_TREE := y
+
 CFLAGS += -fno-builtin -fno-common -Wredundant-decls
 CFLAGS += -iwithprefix include -Werror -Wno-pointer-arith -pipe
 CFLAGS += -I$(BASEDIR)/include
xen/common/Makefile +1 -0
index 9249845..4b1e6f2 100644
@@ -59,3 +59,4 @@ subdir-$(x86_64) += hvm
 subdir-$(ia64) += hvm
 
 subdir-y += libelf
+subdir-$(HAS_DEVICE_TREE) += libfdt
xen/common/libfdt/Makefile new file +5 -0
new file mode 100644
index 0000000..0e65bc0
@@ -0,0 +1,5 @@
+include Makefile.libfdt
+
+obj-y += $(LIBFDT_OBJS)
+
+CFLAGS += -I.
Signature · 1 line
1.7.2.5
#4 lore raw

PATCH 4/8 arm: link a device tree blob into the xen image

In reply to David Vrabel

From: David Vrabel <[email protected]>

Link a device tree blob (DTB) into the xen image. This is loaded immediately after Xen and xen_start() is called with the correct address in atag_paddr.

The DTB file must be supplied by setting the CONFIG_DTB_FILE variable in .config or on the make command line.

---
 config/arm.mk          |    6 ++++++
 xen/arch/arm/Makefile  |    9 ++++++++-
 xen/arch/arm/dtb.S     |    2 ++
 xen/arch/arm/head.S    |    6 ++++++
 xen/arch/arm/xen.lds.S |    4 ++++
 5 files changed, 26 insertions(+), 1 deletions(-)
 create mode 100644 xen/arch/arm/dtb.S
config/arm.mk +6 -0
index f64f0c1..f20fd2d 100644
@@ -16,3 +16,9 @@ LDFLAGS_DIRECT_Linux = _linux
 LDFLAGS_DIRECT += -marmelf$(LDFLAGS_DIRECT_$(XEN_OS))_eabi
 
 CONFIG_LOAD_ADDRESS ?= 0x80000000
+
+# XXX: When running on the model there is no bootloader to provide a
+# device tree.  It must be linked into Xen.
+ifndef CONFIG_DTB_FILE
+$(error CONFIG_DTB_FILE must be set to the absolute filename of a DTB)
+endif
xen/arch/arm/Makefile +8 -1
index 9bc2fc8..b4dd3b1 100644
@@ -22,12 +22,17 @@ obj-y += vtimer.o
 
 #obj-bin-y += ....o
 
+ifdef CONFIG_DTB_FILE
+obj-y += dtb.o
+AFLAGS += -DCONFIG_DTB_FILE=\"$(CONFIG_DTB_FILE)\"
+endif
+
 ALL_OBJS := head.o $(ALL_OBJS)
 
 $(TARGET): $(TARGET)-syms
 	# XXX: VE model loads by VMA so instead of
 	# making a proper ELF we link with LMA == VMA and adjust crudely
-	$(OBJCOPY) --change-addresses +0x7fe00000 $< $@
+	$(OBJCOPY) --change-addresses +0x80000000 $< $@
 	# XXX strip it
 
 #$(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
@@ -71,6 +76,8 @@ xen.lds: xen.lds.S
 	sed -e 's/xen\.lds\.o:/xen\.lds:/g' <.xen.lds.d >.xen.lds.d.new
 	mv -f .xen.lds.d.new .xen.lds.d
 
+dtb.o: $(CONFIG_DTB_FILE)
+
 .PHONY: clean
 clean::
 	rm -f asm-offsets.s xen.lds
xen/arch/arm/dtb.S new file +2 -0
new file mode 100644
index 0000000..c703aef
@@ -0,0 +1,2 @@
+        .section .dtb,#alloc
+        .incbin CONFIG_DTB_FILE
xen/arch/arm/head.S +6 -0
index 57b990d..ea557c2 100644
@@ -55,6 +55,12 @@ start:
        adr   r9, start              /* r9  := paddr (start) */
        sub   r10, r9, r0            /* r10 := phys-offset */
 
+        /* Using the DTB in the .dtb section? */
+#ifdef CONFIG_DTB_FILE
+        ldr   r8, =_sdtb
+        add   r8, r10                /* r8 := paddr(DTB) */
+#endif
+
 #ifdef EARLY_UART_ADDRESS
        /* Say hello */
        ldr   r11, =EARLY_UART_ADDRESS  /* r11 := UART base address */
xen/arch/arm/xen.lds.S +4 -0
index 5a62e2c..6fb7662 100644
@@ -122,6 +122,10 @@ SECTIONS
   } :text
   _end = . ;
 
+  /* Section for the device tree blob (if any). */
+  _sdtb = .;
+  .dtb : { *(.dtb) } :text
+
   /* Sections to be discarded */
   /DISCARD/ : {
        *(.exit.text)
Signature · 1 line
1.7.2.5
#5 lore raw

Re: [PATCH 4/8] arm: link a device tree blob into the xen image

Quoted 13 lines · David Vrabel
config/arm.mk +5 -0
index f64f0c1..f20fd2d 100644
@@ -16,3 +16,9 @@ LDFLAGS_DIRECT_Linux = _linux
 LDFLAGS_DIRECT += -marmelf$(LDFLAGS_DIRECT_$(XEN_OS))_eabi
 
 CONFIG_LOAD_ADDRESS ?= 0x80000000
+
+# XXX: When running on the model there is no bootloader to provide a
+# device tree.  It must be linked into Xen.
+ifndef CONFIG_DTB_FILE
+$(error CONFIG_DTB_FILE must be set to the absolute filename of a
Quoted 2 lines

DTB)
+endif

This turns out to be a little aggressive -- it also triggers when you are building the tools. Not a big deal, but a bit annoying, is there some way we can avoid this? Put it in xen/arch/arm/Foo perhaps?

Ian.

#6 lore raw

Re: [PATCH 4/8] arm: link a device tree blob into the xen image

Quoted 8 lines · Ian Campbell
Quoted 7 lines · David Vrabel
config/arm.mk +0 -0
index f64f0c1..f20fd2d 100644
@@ -16,3 +16,9 @@ LDFLAGS_DIRECT_Linux = _linux
 LDFLAGS_DIRECT += -marmelf$(LDFLAGS_DIRECT_$(XEN_OS))_eabi
 
Quoted 12 lines
Quoted 8 lines
config/arm.mk +5 -0
 CONFIG_LOAD_ADDRESS ?= 0x80000000
+
+# XXX: When running on the model there is no bootloader to provide a
+# device tree.  It must be linked into Xen.
+ifndef CONFIG_DTB_FILE
+$(error CONFIG_DTB_FILE must be set to the absolute filename of a

DTB)
+endif

This turns out to be a little aggressive -- it also triggers when you are building the tools. Not a big deal, but a bit annoying, is there some way we can avoid this? Put it in xen/arch/arm/Foo perhaps?

Does this do the right thing?

8<---------
arm: move check for CONFIG_DTB_FILE to xen/arch/arm/Makefile

CONFIG_DTB_FILE only needs to be set when building Xen itself.

---
 config/arm.mk         |    6 ------
 xen/arch/arm/Makefile |    4 ++++
 2 files changed, 4 insertions(+), 6 deletions(-)
config/arm.mk +0 -6
index f20fd2d..f64f0c1 100644
@@ -16,9 +16,3 @@ LDFLAGS_DIRECT_Linux = _linux
 LDFLAGS_DIRECT += -marmelf$(LDFLAGS_DIRECT_$(XEN_OS))_eabi
 
 CONFIG_LOAD_ADDRESS ?= 0x80000000
-
-# XXX: When running on the model there is no bootloader to provide a
-# device tree.  It must be linked into Xen.
-ifndef CONFIG_DTB_FILE
-$(error CONFIG_DTB_FILE must be set to the absolute filename of a DTB)
-endif
xen/arch/arm/Makefile +4 -0
index 168716e..da9134b 100644
@@ -26,6 +26,10 @@ obj-y += vtimer.o
 ifdef CONFIG_DTB_FILE
 obj-y += dtb.o
 AFLAGS += -DCONFIG_DTB_FILE=\"$(CONFIG_DTB_FILE)\"
+else
+# XXX: When running on the model there is no bootloader to provide a
+# device tree.  It must be linked into Xen.
+$(error CONFIG_DTB_FILE must be set to the absolute filename of a DTB)
 endif
 
 ALL_OBJS := head.o $(ALL_OBJS)
Signature · 1 line
1.7.2.5
Acked-by
#7 lore raw

Re: [PATCH 4/8] arm: link a device tree blob into the xen image

Quoted 22 lines · David Vrabel
Quoted 8 lines · Ian Campbell
Quoted 7 lines · David Vrabel
config/arm.mk +0 -0
index f64f0c1..f20fd2d 100644
@@ -16,3 +16,9 @@ LDFLAGS_DIRECT_Linux = _linux
 LDFLAGS_DIRECT += -marmelf$(LDFLAGS_DIRECT_$(XEN_OS))_eabi
 
Quoted 12 lines
Quoted 8 lines
config/arm.mk +5 -0
 CONFIG_LOAD_ADDRESS ?= 0x80000000
+
+# XXX: When running on the model there is no bootloader to provide a
+# device tree.  It must be linked into Xen.
+ifndef CONFIG_DTB_FILE
+$(error CONFIG_DTB_FILE must be set to the absolute filename of a

DTB)
+endif

This turns out to be a little aggressive -- it also triggers when you are building the tools. Not a big deal, but a bit annoying, is there some way we can avoid this? Put it in xen/arch/arm/Foo perhaps?

Quoted 1 line

Does this do the right thing?

It seems to, thanks.

It still fails the Xen case reasonably early which was the only problem I could foresee.

Quoted 7 lines

8<---------
arm: move check for CONFIG_DTB_FILE to xen/arch/arm/Makefile

CONFIG_DTB_FILE only needs to be set when building Xen itself.

and queued for commit.

Quoted 34 lines
---
 config/arm.mk         |    6 ------
 xen/arch/arm/Makefile |    4 ++++
 2 files changed, 4 insertions(+), 6 deletions(-)
config/arm.mk +0 -6
index f20fd2d..f64f0c1 100644
@@ -16,9 +16,3 @@ LDFLAGS_DIRECT_Linux = _linux
 LDFLAGS_DIRECT += -marmelf$(LDFLAGS_DIRECT_$(XEN_OS))_eabi
 
 CONFIG_LOAD_ADDRESS ?= 0x80000000
-
-# XXX: When running on the model there is no bootloader to provide a
-# device tree.  It must be linked into Xen.
-ifndef CONFIG_DTB_FILE
-$(error CONFIG_DTB_FILE must be set to the absolute filename of a DTB)
-endif
xen/arch/arm/Makefile +4 -0
index 168716e..da9134b 100644
@@ -26,6 +26,10 @@ obj-y += vtimer.o
 ifdef CONFIG_DTB_FILE
 obj-y += dtb.o
 AFLAGS += -DCONFIG_DTB_FILE=\"$(CONFIG_DTB_FILE)\"
+else
+# XXX: When running on the model there is no bootloader to provide a
+# device tree.  It must be linked into Xen.
+$(error CONFIG_DTB_FILE must be set to the absolute filename of a DTB)
 endif
 
 ALL_OBJS := head.o $(ALL_OBJS)
#9 lore raw

PATCH 5/8 arm: map device tree blob in initial page tables

In reply to David Vrabel

From: David Vrabel <[email protected]>

Add a mapping for the device tree blob in the initial page tables. This will allow the DTB to be parsed for memory information prior to setting up the real page tables.

It is mapped into the first L2 slot after the fixmap. When this slot is reused in setup_pagetables(), flush the TLB.

---
 xen/arch/arm/head.S          |    9 +++++++++
 xen/arch/arm/mm.c            |    5 +++--
 xen/include/asm-arm/config.h |    6 ++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
xen/arch/arm/head.S +9 -0
index ea557c2..8b23424 100644
@@ -202,7 +202,16 @@ hyp:
        orr   r2, r2, #0x071         /* r2:r3 := 2MB dev map including UART */
        add   r4, r4, #8
        strd  r2, r3, [r1, r4]       /* Map it in the fixmap's slot */
+#else
+       add   r4, r4, #8             /* Skip over unused fixmap slot */
 #endif
+       mov   r3, #0x0
+       lsr   r2, r8, #21
+       lsl   r2, r2, #21            /* 2MB-aligned paddr of DTB */
+       orr   r2, r2, #0xf00
+       orr   r2, r2, #0x07d         /* r2:r3 := 2MB RAM incl. DTB */
+       add   r4, r4, #8
+       strd  r2, r3, [r1, r4]       /* Map it in the early boot slot */
 
        PRINT("- Turning on paging -\r\n")
 
xen/arch/arm/mm.c +3 -2
index c863507..f1fe4ba 100644
@@ -161,10 +161,11 @@ void __init setup_pagetables(unsigned long boot_phys_offset)
 
     xen_paddr = XEN_PADDR;
 
-    /* Map the destination in the empty L2 above the fixmap */
-    dest_va = FIXMAP_ADDR(0) + (1u << SECOND_SHIFT);
+    /* Map the destination in the boot misc area. */
+    dest_va = BOOT_MISC_VIRT_START;
     pte = mfn_to_xen_entry(xen_paddr >> PAGE_SHIFT);
     write_pte(xen_second + second_table_offset(dest_va), pte);
+    flush_xen_data_tlb_va(dest_va);
 
     /* Calculate virt-to-phys offset for the new location */
     phys_offset = xen_paddr - (unsigned long) _start;
xen/include/asm-arm/config.h +6 -0
index 9294f8f..c2ab0a2 100644
@@ -55,15 +55,21 @@
  *  0  -   2M   Unmapped
  *  2M -   4M   Xen text, data, bss
  *  4M -   6M   Fixmap: special-purpose 4K mapping slots
+ *  6M  -  8M   Early boot misc (see below)
  *
  * 32M - 128M   Frametable: 24 bytes per page for 16GB of RAM
  *
  *  1G -   2G   Xenheap: always-mapped memory
  *  2G -   4G   Domheap: on-demand-mapped
+ *
+ * The early boot misc area is used:
+ *   - in head.S for the DTB for device_tree_early_init().
+ *   - in setup_pagetables() when relocating Xen.
  */
 
 #define XEN_VIRT_START         0x00200000
 #define FIXMAP_ADDR(n)        (0x00400000 + (n) * PAGE_SIZE)
+#define BOOT_MISC_VIRT_START   0x00600000
 #define FRAMETABLE_VIRT_START  0x02000000
 #define XENHEAP_VIRT_START     0x40000000
 #define DOMHEAP_VIRT_START     0x80000000
Signature · 1 line
1.7.2.5
#10 lore raw

PATCH 6/8 arm: add early_printk()

In reply to David Vrabel

From: David Vrabel <[email protected]>

Add early_printk() which can be used before setup_pagetables(). This will be used when doing the early parsing of the DTB.

---
 xen/arch/arm/Makefile              |    1 +
 xen/arch/arm/early_printk.c        |   72 ++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/early_printk.h |   27 +++++++++++++
 3 files changed, 100 insertions(+), 0 deletions(-)
 create mode 100644 xen/arch/arm/early_printk.c
 create mode 100644 xen/include/asm-arm/early_printk.h
xen/arch/arm/Makefile +1 -0
index b4dd3b1..168716e 100644
@@ -1,6 +1,7 @@
 subdir-y += lib
 
 obj-y += dummy.o
+obj-y += early_printk.o
 obj-y += entry.o
 obj-y += domain.o
 obj-y += domain_build.o
xen/arch/arm/early_printk.c new file +72 -0

72 lines not on this page · raw message

xen/include/asm-arm/early_printk.h new file +27 -0
new file mode 100644
index 0000000..f45f21e
@@ -0,0 +1,27 @@
+/*
+ * printk() for use before the final page tables are setup.
+ *
+ * Copyright (C) 2012 Citrix Systems, Inc.
+ *
+ * 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 __ARM_EARLY_PRINTK_H__
+#define __ARM_EARLY_PRINTK_H__
+
+#include <xen/config.h>
+
+#ifdef EARLY_UART_ADDRESS
+
+void early_printk(const char *fmt, ...);
+void early_panic(const char *fmt, ...);
+
+#else
+
+static inline void early_printk(const char *fmt, ...) {}
+static inline void early_panic(const char *fmt, ...) {}
+
+#endif
+
+#endif
Signature · 1 line
1.7.2.5
#11 lore raw

PATCH 7/8 arm, device tree: parse the DTB for RAM location and size

In reply to David Vrabel

From: David Vrabel <[email protected]>

Prior to setting up the page tables, parse the DTB for the location and size of RAM.

Use this information to get the physical address to relocate Xen to in setup_pagetables().

---
 xen/arch/arm/mm.c             |    3 +-
 xen/arch/arm/setup.c          |    6 ++
 xen/common/Makefile           |    3 +
 xen/common/device_tree.c      |  179 +++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/mm.h      |    5 +-
 xen/include/xen/device_tree.h |   36 ++++++++
 6 files changed, 228 insertions(+), 4 deletions(-)
 create mode 100644 xen/common/device_tree.c
 create mode 100644 xen/include/xen/device_tree.h
xen/arch/arm/mm.c +2 -1
index f1fe4ba..24f977c 100644
@@ -20,6 +20,7 @@
 #include <xen/config.h>
 #include <xen/compile.h>
 #include <xen/types.h>
+#include <xen/device_tree.h>
 #include <xen/init.h>
 #include <xen/mm.h>
 #include <xen/preempt.h>
@@ -159,7 +160,7 @@ void __init setup_pagetables(unsigned long boot_phys_offset)
         write_pte(xen_second + second_linear_offset(dest_va), pte);
     }
 
-    xen_paddr = XEN_PADDR;
+    xen_paddr = device_tree_get_xen_paddr();
 
     /* Map the destination in the boot misc area. */
     dest_va = BOOT_MISC_VIRT_START;
xen/arch/arm/setup.c +6 -0
index 51afb31..01d2668 100644
@@ -19,6 +19,7 @@
 
 #include <xen/config.h>
 #include <xen/compile.h>
+#include <xen/device_tree.h>
 #include <xen/domain_page.h>
 #include <xen/types.h>
 #include <xen/string.h>
@@ -68,8 +69,13 @@ void __init start_xen(unsigned long boot_phys_offset,
                       unsigned long atag_paddr)
 
 {
+    void *fdt;
     int i;
 
+    fdt = (void *)BOOT_MISC_VIRT_START
+        + (atag_paddr & ((1 << SECOND_SHIFT) - 1));
+    device_tree_early_init(fdt);
+
     setup_pagetables(boot_phys_offset);
 
 #ifdef EARLY_UART_ADDRESS
xen/common/Makefile +3 -0
index 4b1e6f2..372b259 100644
@@ -1,6 +1,7 @@
 obj-y += bitmap.o
 obj-y += cpu.o
 obj-y += cpupool.o
+obj-$(HAS_DEVICE_TREE) += device_tree.o
 obj-y += domctl.o
 obj-y += domain.o
 obj-y += event_channel.o
@@ -60,3 +61,5 @@ subdir-$(ia64) += hvm
 
 subdir-y += libelf
 subdir-$(HAS_DEVICE_TREE) += libfdt
+
+CFLAGS += -Ilibfdt
xen/common/device_tree.c new file +179 -0

179 lines not on this page · raw message

xen/include/asm-arm/mm.h +2 -3
index f721c54..8efa63b 100644
@@ -6,9 +6,8 @@
 #include <asm/page.h>
 #include <public/xen.h>
 
-/* Find a suitable place at the top of memory for Xen to live */
-/* XXX For now, use the top of the VE's 4GB RAM, at a 40-bit alias */
-#define XEN_PADDR 0x80ffe00000ull
+/* Align Xen to a 2 MiB boundary. */
+#define XEN_PADDR_ALIGN (1 << 21)
 
 /*
  * Per-page-frame information.
xen/include/xen/device_tree.h new file +36 -0
new file mode 100644
index 0000000..ae3e344
@@ -0,0 +1,36 @@
+/*
+ * Device Tree
+ *
+ * Copyright (C) 2012 Citrix Systems, Inc.
+ *
+ * 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 __XEN_DEVICE_TREE_H__
+#define __XEN_DEVICE_TREE_H__
+
+#include <xen/types.h>
+
+#define NR_MEM_BANKS 8
+
+struct membank {
+    paddr_t start;
+    paddr_t size;
+};
+
+struct dt_mem_info {
+    int nr_banks;
+    struct membank bank[NR_MEM_BANKS];
+};
+
+struct dt_early_info {
+    struct dt_mem_info mem;
+};
+
+extern struct dt_early_info early_info;
+
+void device_tree_early_init(const void *fdt);
+paddr_t device_tree_get_xen_paddr(void);
+
+#endif
Signature · 1 line
1.7.2.5
#12 lore raw

Re: [PATCH 7/8] arm, device tree: parse the DTB for RAM location and size

Quoted 11 lines · David Vrabel

From: David Vrabel <[email protected]>

Prior to setting up the page tables, parse the DTB for the location and size of RAM.

Use this information to get the physical address to relocate Xen to in setup_pagetables().

---

[...]

Quoted 2 lines
 xen/common/Makefile           |    3 +
 xen/common/device_tree.c      |  179 +++++++++++++++++++++++++++++++++++++++++

[...]

Quoted 1 line
 xen/include/xen/device_tree.h |   36 ++++++++

I'd have preferred these non-ARM bits in a separate patch if possible. I'm going to commit them anyway though on the basis that they are in reality ARM specific unless Keir (or someone else) objects quite soon.

Ian.

#13 lore raw

Re: [PATCH 7/8] arm, device tree: parse the DTB for RAM location and size

Quoted 13 lines · Ian Campbell
Quoted 11 lines · David Vrabel

From: David Vrabel <[email protected]>

Prior to setting up the page tables, parse the DTB for the location and size of RAM.

Use this information to get the physical address to relocate Xen to in setup_pagetables().

---

[...]

Quoted 8 lines
Quoted 2 lines
 xen/common/Makefile           |    3 +
 xen/common/device_tree.c      |  179 +++++++++++++++++++++++++++++++++++++++++

[...]

Quoted 1 line
 xen/include/xen/device_tree.h |   36 ++++++++

I'd have preferred these non-ARM bits in a separate patch if possible. I'm going to commit them anyway though on the basis that they are in reality ARM specific unless Keir (or someone else) objects quite soon.

Dividing maintainer-ship by directory seems a little coarse grained. It may be more practical for you (Ian) to be the maintainer/committer for the device tree related stuff even though they live under xen/common/.

Or, if you prefer, I can make sure to split the patches in common and arch bits.

David

#14 lore raw

Re: [PATCH 7/8] arm, device tree: parse the DTB for RAM location and size

Quoted 19 lines · David Vrabel
Quoted 18 lines · Ian Campbell
Quoted 11 lines · David Vrabel

From: David Vrabel <[email protected]>

Prior to setting up the page tables, parse the DTB for the location and size of RAM.

Use this information to get the physical address to relocate Xen to in setup_pagetables().

---

[...]

Quoted 2 lines
 xen/common/Makefile           |    3 +
 xen/common/device_tree.c      |  179 +++++++++++++++++++++++++++++++++++++++++

[...]

Quoted 1 line
 xen/include/xen/device_tree.h |   36 ++++++++
Quoted 7 lines
Quoted 3 lines

I'd have preferred these non-ARM bits in a separate patch if possible. I'm going to commit them anyway though on the basis that they are in reality ARM specific unless Keir (or someone else) objects quite soon.

Dividing maintainer-ship by directory seems a little coarse grained. It may be more practical for you (Ian) to be the maintainer/committer for the device tree related stuff even though they live under xen/common/.

I'd be happy to do that if there is agreement among the other maintainers.

Of course as soon as some joker ports x86 to use DT we are back where we started ;-)

Quoted 4 lines

Or, if you prefer, I can make sure to split the patches in common and arch bits.

David

#15 lore raw

Re: [PATCH 7/8] arm, device tree: parse the DTB for RAM location and size

Ian Campbell writes ("Re: [Xen-devel] [PATCH 7/8] arm, device tree: parse the DTB for RAM location and size"):

Quoted 7 lines · David Vrabel
Quoted 3 lines

Dividing maintainer-ship by directory seems a little coarse grained. It may be more practical for you (Ian) to be the maintainer/committer for the device tree related stuff even though they live under xen/common/.

I'd be happy to do that if there is agreement among the other maintainers.

That would seem sensible to me. For now at least.

Ian.

#16 lore raw

Re: [PATCH 7/8] arm, device tree: parse the DTB for RAM location and size

Quoted 10 lines · Ian Jackson

Ian Campbell writes ("Re: [Xen-devel] [PATCH 7/8] arm, device tree: parse the DTB for RAM location and size"):

Quoted 7 lines · David Vrabel
Quoted 3 lines

Dividing maintainer-ship by directory seems a little coarse grained. It may be more practical for you (Ian) to be the maintainer/committer for the device tree related stuff even though they live under xen/common/.

I'd be happy to do that if there is agreement among the other maintainers.

That would seem sensible to me. For now at least.

Keir, are you happy for me to commit changes to
xen/common/libfdt/*
xen/common/device_tree.c
xen/include/xen/device_tree.h
as I see fit for the time being?

I've also suggested that David sends a patch to add himself to MAINTAINERS for those as well.

Ian.

#17 lore raw

PATCH 8/8 arm: setup MM using information from the device tree

In reply to David Vrabel

From: David Vrabel <[email protected]>

Setup memory management, heaps etc. using the location and size of the first memory bank given in the device tree.

The DTB is also copied so it can be used afterwards.

---
 xen/arch/arm/kernel.c         |   22 +++++----
 xen/arch/arm/mm.c             |    3 +
 xen/arch/arm/setup.c          |   98 +++++++++++++++++++++++++++++++----------
 xen/common/device_tree.c      |    7 +++-
 xen/include/asm-arm/mm.h      |   11 +++--
 xen/include/asm-arm/setup.h   |    2 +
 xen/include/xen/device_tree.h |    3 +-
 7 files changed, 107 insertions(+), 39 deletions(-)
xen/arch/arm/kernel.c +13 -9
index d4ffa4f..f2339fa 100644
@@ -11,6 +11,7 @@
 #include <xen/domain_page.h>
 #include <xen/sched.h>
 #include <asm/byteorder.h>
+#include <asm/setup.h>
 
 #include "kernel.h"
 
@@ -32,25 +33,28 @@ struct minimal_dtb_header {
 
 #define DTB_MAGIC 0xd00dfeed
 
-static void copy_from_flash(void *dst, paddr_t flash, unsigned long len)
+/**
+ * copy_from_paddr - copy data from a physical address
+ * @dst: destination virtual address
+ * @paddr: source physical address
+ * @len: length to copy
+ */
+void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len)
 {
     void *src = (void *)FIXMAP_ADDR(FIXMAP_MISC);
 
-    printk("Copying %#lx bytes from flash %"PRIpaddr" to %p",
-           len, flash, dst);
-
     while (len) {
         paddr_t p;
         unsigned long l, s;
 
-        p = flash >> PAGE_SHIFT;
-        s = flash & (PAGE_SIZE-1);
+        p = paddr >> PAGE_SHIFT;
+        s = paddr & (PAGE_SIZE-1);
         l = min(PAGE_SIZE - s, len);
 
         set_fixmap(FIXMAP_MISC, p, DEV_SHARED);
         memcpy(dst, src + s, l);
 
-        flash += l;
+        paddr += l;
         dst += l;
         len -= l;
     }
@@ -108,7 +112,7 @@ static int kernel_try_zimage_prepare(struct kernel_info *info)
     /*
      * Check for an appended DTB.
      */
-    copy_from_flash(&dtb_hdr, KERNEL_FLASH_ADDRESS + end - start, sizeof(dtb_hdr));
+    copy_from_paddr(&dtb_hdr, KERNEL_FLASH_ADDRESS + end - start, sizeof(dtb_hdr));
     if (be32_to_cpu(dtb_hdr.magic) == DTB_MAGIC) {
         end += be32_to_cpu(dtb_hdr.total_size);
     }
@@ -150,7 +154,7 @@ static int kernel_try_elf_prepare(struct kernel_info *info)
     if ( info->kernel_img == NULL )
         panic("Cannot allocate temporary buffer for kernel.\n");
 
-    copy_from_flash(info->kernel_img, KERNEL_FLASH_ADDRESS, KERNEL_FLASH_SIZE);
+    copy_from_paddr(info->kernel_img, KERNEL_FLASH_ADDRESS, KERNEL_FLASH_SIZE);
 
     if ( (rc = elf_init(&info->elf.elf, info->kernel_img, KERNEL_FLASH_SIZE )) != 0 )
         return rc;
xen/arch/arm/mm.c +3 -0
index 24f977c..0d6c0ca 100644
@@ -39,6 +39,7 @@ static lpae_t xen_xenmap[LPAE_ENTRIES] __attribute__((__aligned__(4096)));
 unsigned long xenheap_mfn_start, xenheap_mfn_end;
 unsigned long xenheap_virt_end;
 
+unsigned long frametable_base_mfn;
 unsigned long frametable_virt_end;
 
 /* Map a 4k page in a fixmap entry */
@@ -301,6 +302,8 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe)
     unsigned long frametable_size = nr_pages * sizeof(struct page_info);
     unsigned long base_mfn;
 
+    frametable_base_mfn = ps >> PAGE_SHIFT;
+
     /* Round up to 32M boundary */
     frametable_size = (frametable_size + 0x1ffffff) & ~0x1ffffff;
     base_mfn = alloc_boot_pages(frametable_size >> PAGE_SHIFT, 5);
xen/arch/arm/setup.c +75 -23

120 lines not on this page · raw message

xen/common/device_tree.c +6 -1
index 7d7514d..d50cb9c 100644
@@ -22,6 +22,7 @@
 #include <libfdt.h>
 
 struct dt_early_info __initdata early_info;
+void *device_tree_flattened;
 
 static void __init get_val(const u32 **cell, u32 cells, u64 *val)
 {
@@ -126,8 +127,10 @@ static void __init early_print_info(void)
 /**
  * device_tree_early_init - initialize early info from a DTB
  * @fdt: flattened device tree binary
+ *
+ * Returns the size of the DTB.
  */
-void __init device_tree_early_init(const void *fdt)
+size_t __init device_tree_early_init(const void *fdt)
 {
     int ret;
 
@@ -137,6 +140,8 @@ void __init device_tree_early_init(const void *fdt)
 
     early_scan(fdt);
     early_print_info();
+
+    return fdt_totalsize(fdt);
 }
 
 /**
xen/include/asm-arm/mm.h +6 -5
index 8efa63b..bfc0f76 100644
@@ -128,6 +128,8 @@ extern void share_xen_page_with_privileged_guests(
     struct page_info *page, int readonly);
 
 #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
+/* MFN of the first page in the frame table. */
+extern unsigned long frametable_base_mfn;
 
 extern unsigned long max_page;
 extern unsigned long total_pages;
@@ -151,15 +153,14 @@ extern void clear_fixmap(unsigned map);
 })
 
 #define max_pdx                 max_page
-/* XXX Assume everything in the 40-bit physical alias 0x8000000000 for now */
-#define pfn_to_pdx(pfn)         ((pfn) - 0x8000000UL)
-#define pdx_to_pfn(pdx)         ((pdx) + 0x8000000UL)
+#define pfn_to_pdx(pfn)         (pfn)
+#define pdx_to_pfn(pdx)         (pdx)
 #define virt_to_pdx(va)         virt_to_mfn(va)
 #define pdx_to_virt(pdx)        mfn_to_virt(pdx)
 
 /* Convert between machine frame numbers and page-info structures. */
-#define mfn_to_page(mfn)  (frame_table + pfn_to_pdx(mfn))
-#define page_to_mfn(pg)   pdx_to_pfn((unsigned long)((pg) - frame_table))
+#define mfn_to_page(mfn)  (frame_table + (pfn_to_pdx(mfn) - frametable_base_mfn))
+#define page_to_mfn(pg)   pdx_to_pfn((unsigned long)((pg) - frame_table) + frametable_base_mfn)
 #define __page_to_mfn(pg)  page_to_mfn(pg)
 #define __mfn_to_page(mfn) mfn_to_page(mfn)
 
xen/include/asm-arm/setup.h +2 -0
index 2041f06..05ff89e 100644
@@ -3,6 +3,8 @@
 
 #include <public/version.h>
 
+void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);
+
 void arch_get_xen_caps(xen_capabilities_info_t *info);
 
 int construct_dom0(struct domain *d);
xen/include/xen/device_tree.h +2 -1
index ae3e344..28a3dee 100644
@@ -29,8 +29,9 @@ struct dt_early_info {
 };
 
 extern struct dt_early_info early_info;
+extern void *device_tree_flattened;
 
-void device_tree_early_init(const void *fdt);
+size_t device_tree_early_init(const void *fdt);
 paddr_t device_tree_get_xen_paddr(void);
 
 #endif
Signature · 1 line
1.7.2.5
#18 lore raw
In reply to David Vrabel
Quoted 1 line · David Vrabel

This series adds preliminary device tree support to Xen for ARM.

Keir applied #1-3 so I have gone ahead and applied #4-8, including the xen/common/$devicetree bits as I mentioned.

Thanks David.

Does the wiki page need updating now?

Ian.

#19 lore raw
Quoted 9 lines · Ian Campbell
Quoted 1 line · David Vrabel

This series adds preliminary device tree support to Xen for ARM.

Keir applied #1-3 so I have gone ahead and applied #4-8, including the xen/common/$devicetree bits as I mentioned.

Thanks David.

Does the wiki page need updating now?

I've updated it somewhat. That page doesn't really know who its audience is so it more a collection of notes rather than something with more structure/flow.

David