Skip to contentSkip to conversation

RFC: arm: (really) minimal device tree support

PATCH In review David Vrabel 2 participants 12 messages Feb 3, 2012 – Feb 7, 2012

lore
Share & tools
lore
#0 lore raw

cover RFC: arm: (really) minimal device tree support

This set of patches adds libfdt and some minimal infrastructure for parsing a DTB. The DTB is linked into the Xen image since there isn't a bootloader when running on the model. Information on available RAM is obtained and used to get the address to relocate Xen to (the MM is still initialized with hard-coded values, I'll be fixing this next).

I also added an early_printk() function since its needed when doing the early scan of the DTB. It's not very platform-independant but it should do for now.

So, not really a lot here but I think it would be useful to get the basic infrastructure reviewed a bit before making more use of it.

David

#1 lore raw

PATCH 1/7 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/7 libfdt: add to build

In reply to David Vrabel

From: David Vrabel <[email protected]>

---
 xen/common/Makefile        |    1 +
 xen/common/libfdt/Makefile |    5 +++++
 2 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100644 xen/common/libfdt/Makefile
xen/common/Makefile +1 -0
index 9249845..7a3cd38 100644
@@ -59,3 +59,4 @@ subdir-$(x86_64) += hvm
 subdir-$(ia64) += hvm
 
 subdir-y += libelf
+subdir-y += 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
#3 lore raw

PATCH 3/7 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 to start of RAM + 0x100 and xen_start() is called with the correct address in atag_paddr.

---
 xen/arch/arm/Makefile  |    7 +++++--
 xen/arch/arm/dtb.S     |    2 ++
 xen/arch/arm/head.S    |    5 +++++
 xen/arch/arm/xen.lds.S |    6 ++++++
 4 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/dtb.S
xen/arch/arm/Makefile +5 -2
index 9bc2fc8..ac346a5 100644
@@ -1,5 +1,6 @@
 subdir-y += lib
 
+obj-y += dtb.o
 obj-y += dummy.o
 obj-y += entry.o
 obj-y += domain.o
@@ -27,7 +28,7 @@ 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
@@ -50,7 +51,7 @@ endif
 $(BASEDIR)/common/symbols-dummy.o:
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C $(BASEDIR)/common symbols-dummy.o
 
-$(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
+$(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o dtb.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
 	$(NM) -n $(@D)/.$(@F).0 | $(BASEDIR)/tools/symbols >$(@D)/.$(@F).0.S
@@ -71,6 +72,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: platform.dtb
+
 .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..0728c04
@@ -0,0 +1,2 @@
+        .section .dtb,#alloc
+        .incbin "platform.dtb"
xen/arch/arm/head.S +5 -0
index b98c921..9951f37 100644
@@ -55,6 +55,11 @@ start:
 	adr   r9, start              /* r9  := paddr (start) */
 	sub   r10, r9, r0            /* r10 := phys-offset */
 
+        /* FIXME: using the DTB in the .dtb section. */
+        mov   r7, #0
+        ldr   r8, =_sdtb
+        add   r8, r10
+
 #ifdef EARLY_UART_ADDRESS
 	/* Say hello */
 	ldr   r11, =EARLY_UART_ADDRESS  /* r11 := UART base address */
xen/arch/arm/xen.lds.S +6 -0
index 5a62e2c..4bcca57 100644
@@ -122,6 +122,12 @@ SECTIONS
   } :text
   _end = . ;
 
+  /* FIXME: don't yet have a bootloader to provide the DTB, link it
+     into Xen in its own section. */
+  . = 0x100;
+  _sdtb = .;
+  .dtb : { dtb.o(.dtb) }
+
   /* Sections to be discarded */
   /DISCARD/ : {
        *(.exit.text)
Signature · 1 line
1.7.2.5
#4 lore raw

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

xen/arch/arm/head.S start: · line 58

Quoted 9 lines · David Vrabel
xen/arch/arm/head.S +1 -0
index b98c921..9951f37 100644
@@ -55,6 +55,11 @@ start:
 	adr   r9, start              /* r9  := paddr (start) */
 	sub   r10, r9, r0            /* r10 := phys-offset */
 
+        /* FIXME: using the DTB in the .dtb section. */

The rest of this file uses leading tabs for indentation (not for any particular reason except emascs did it by default). I'd be happy with a patch to change to spaces throughout but I'd rather not mix.

xen/arch/arm/head.S start: · line 59

Quoted 1 line
xen/arch/arm/head.S +1 -0
+        mov   r7, #0

Why?

xen/arch/arm/head.S start: · line 61

Quoted 2 lines
xen/arch/arm/head.S +2 -0
+        ldr   r8, =_sdtb
+        add   r8, r10

This should have a comment like 'r8 := paddr (DTB)', to make it clear what you're overriding the previous r8 value with. (Yes, I'm being picky but I really believe you can't over-comment asm, specially wierd start of day stuff.)

Cheers,

Tim.

#5 lore raw

PATCH 4/7 arm: map device tree blob in initial page tables

In reply to David Vrabel

From: David Vrabel <[email protected]>

Add a 1:1 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.

---
 xen/arch/arm/head.S |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
xen/arch/arm/head.S +5 -0
index 9951f37..8385481 100644
@@ -202,6 +202,11 @@ hyp:
 	add   r4, r4, #8
 	strd  r2, r3, [r1, r4]       /* Map it in the fixmap's slot */
 #endif
+	mov   r3, #0x0
+	orr   r2, r8, #0xe00
+	orr   r2, r2, #0x07d
+	mov   r4, r8, lsr #18        /* Slot for (r8 == atag_paddr) */
+	strd  r2, r3, [r1, r4]       /* Map DTB there */
 
 	PRINT("- Turning on paging -\r\n")
 
Signature · 1 line
1.7.2.5
#6 lore raw

Re: [PATCH 4/7] arm: map device tree blob in initial page tables

Quoted 16 lines · David Vrabel

From: David Vrabel <[email protected]>

Add a 1:1 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.

---
 xen/arch/arm/head.S |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
xen/arch/arm/head.S +0 -0
index 9951f37..8385481 100644

xen/arch/arm/head.S hyp: · line 209

Quoted 8 lines
xen/arch/arm/head.S +5 -0
@@ -202,6 +202,11 @@ hyp:
 	add   r4, r4, #8
 	strd  r2, r3, [r1, r4]       /* Map it in the fixmap's slot */
 #endif
+	mov   r3, #0x0
+	orr   r2, r8, #0xe00
+	orr   r2, r2, #0x07d
+	mov   r4, r8, lsr #18        /* Slot for (r8 == atag_paddr) */
+	strd  r2, r3, [r1, r4]       /* Map DTB there */

It might be better to map the DTB at a fixed VA (say, the next second-level slot up from the fixmap one) so we don't have to worry about the DTB's PA clashing with Xen's VAs.

Tim.

#7 lore raw

Re: [PATCH 4/7] arm: map device tree blob in initial page tables

Quoted 21 lines · Tim Deegan
Quoted 20 lines · David Vrabel

From: David Vrabel <[email protected]>

Add a 1:1 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.

---
 xen/arch/arm/head.S |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
xen/arch/arm/head.S +1 -0
index 9951f37..8385481 100644
@@ -202,6 +202,11 @@ hyp:
 	add   r4, r4, #8
 	strd  r2, r3, [r1, r4]       /* Map it in the fixmap's slot */
 #endif
+	mov   r3, #0x0
Quoted 8 lines

xen/arch/arm/head.S hyp: · line 209

Quoted 4 lines
xen/arch/arm/head.S +4 -0
+	orr   r2, r8, #0xe00
+	orr   r2, r2, #0x07d
+	mov   r4, r8, lsr #18        /* Slot for (r8 == atag_paddr) */
+	strd  r2, r3, [r1, r4]       /* Map DTB there */

It might be better to map the DTB at a fixed VA (say, the next second-level slot up from the fixmap one) so we don't have to worry about the DTB's PA clashing with Xen's VAs.

That was already used in setup_pagetables() to relocate Xen but since the two uses don't overlap they can share the same slot. Not 100% sure on the TLB flush after updating the L2 PTE -- it makes it work but is it sufficient/optimal?

8<-------
arm: map device tree blob in initial page tables

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          |    7 +++++++
 xen/arch/arm/mm.c            |    5 +++--
 xen/include/asm-arm/config.h |    6 ++++++
 3 files changed, 16 insertions(+), 2 deletions(-)
xen/arch/arm/head.S +7 -0
index 3c1f624..f1a81b3 100644
@@ -201,6 +201,13 @@ hyp:
         add   r4, r4, #8
         strd  r2, r3, [r1, r4]       /* Map it in the fixmap's 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 +0 -0
index 613d084..0599102 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();

     /* 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 12285dd..8546a50 100644
@@ -52,15 +52,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

David

#8 lore raw

Re: [PATCH 4/7] arm: map device tree blob in initial page tables

Quoted 4 lines · David Vrabel

That was already used in setup_pagetables() to relocate Xen but since the two uses don't overlap they can share the same slot. Not 100% sure on the TLB flush after updating the L2 PTE -- it makes it work but is it sufficient/optimal?

Hrmn. Yes, I think that's sufficient. You should be able to use flush_xen_data_tlb_va() to just flush that one entry, AFAICS.

xen/arch/arm/head.S hyp: · line 210

Quoted 13 lines
xen/arch/arm/head.S +7 -0
@@ -201,6 +201,13 @@ hyp:
         add   r4, r4, #8
         strd  r2, r3, [r1, r4]       /* Map it in the fixmap's 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 */

That's good, but you should move the previous "add r4, r4, #8" out of the #ifdef. :)

Tim.

#9 lore raw

PATCH 5/7 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 fd89c98..727d5a5 100644
@@ -58,4 +58,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
#10 lore raw

PATCH 6/7 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 ac346a5..4794cfc 100644
@@ -2,6 +2,7 @@ subdir-y += lib
 
 obj-y += dtb.o
 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/7 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          |    3 +
 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, 225 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 613d084..20968e0 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 empty L2 above the fixmap */
     dest_va = FIXMAP_ADDR(0) + (1u << SECOND_SHIFT);
xen/arch/arm/setup.c +3 -0
index 33c880e..ef50ccc 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>
@@ -70,6 +71,8 @@ void __init start_xen(unsigned long boot_phys_offset,
 {
     int i;
 
+    device_tree_early_init((void *)atag_paddr);
+
     setup_pagetables(boot_phys_offset);
 
 #ifdef EARLY_UART_ADDRESS
xen/common/Makefile +3 -0
index 7a3cd38..2f9b674 100644
@@ -1,6 +1,7 @@
 obj-y += bitmap.o
 obj-y += cpu.o
 obj-y += cpupool.o
+obj-y += 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-y += 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..eb7f219
@@ -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