Skip to contentSkip to conversation

Machine config files

PATCH In review Paul Brook 13 participants 61 messages Jun 10, 2009 – Jul 7, 2009 Kbuild

lore
Share & tools
lore

Paul Brook

author
#0 lore raw

cover Machine config files

The following series implements machine config files, and adds converts some of the existing hardcoded machines.

The config files themselves are based on the ppc-linux Flattened Device Trees. In generaly I've tried to structure things so that the same config file can be used for both qemu and linux.

There are a still a few things missing, in particular PCI busses are untested, but both SSI and I2C work.

To handle options like -kernel I've added a "bootstrap" facility. This allows additional board initialization on top of normal hardware reset. In the future we may want some more common features (e.g. loading ROM images), but for now it just provides the functionality in the same way as the old board init routine.

Also available from git://repo.or.cz/qemu/pbrook.git devtree

---

Paul Brook (4):
Integrator machine config
Stellaris machine config
Add device tree machine
Include and build libfdt

 .gitignore                       |    1 
 Makefile                         |   39 +
 Makefile.hw                      |    2 
 Makefile.target                  |   19 -
 configure                        |   41 +
 hw/arm-cpu.c                     |   79 +++
 hw/arm_boot.c                    |   22 +
 hw/arm_timer.c                   |    2 
 hw/armv7m.c                      |   61 ++
 hw/boards.h                      |    9 
 hw/dt-machine.c                  |  582 +++++++++++++++++++++
 hw/gpio-buttons.c                |  124 ++++
 hw/i2c.c                         |    8 
 hw/integratorcp.c                |   97 ---
 hw/pci.c                         |    1 
 hw/petalogix_s3adsp1800_mmu.c    |   40 -
 hw/pl011.c                       |    2 
 hw/pl061.c                       |   25 +
 hw/ppc440_bamboo.c               |    2 
 hw/ppce500_mpc8544ds.c           |    4 
 hw/qdev.c                        |  225 ++++++++
 hw/qdev.h                        |   50 +-
 hw/ssi.c                         |    7 
 hw/stellaris.c                   |  272 ++--------
 hw/stellaris_enet.c              |    2 
 hw/stellaris_input.c             |   91 ---
 hw/syborg.c                      |  112 ----
 hw/sysbus.c                      |    5 
 hw/sysbus.h                      |   15 -
 libfdt/Makefile.libfdt           |   14 
 libfdt/TODO                      |    3 
 libfdt/fdt.c                     |  156 ++++++
 libfdt/fdt.h                     |   60 ++
 libfdt/fdt_ro.c                  |  583 +++++++++++++++++++++
 libfdt/fdt_rw.c                  |  471 +++++++++++++++++
 libfdt/fdt_strerror.c            |   96 +++
 libfdt/fdt_sw.c                  |  258 +++++++++
 libfdt/fdt_wip.c                 |  144 +++++
 libfdt/libfdt.h                  | 1070 ++++++++++++++++++++++++++++++++++++++
 libfdt/libfdt_env.h              |   21 +
 libfdt/libfdt_internal.h         |   89 +++
 libfdt/patch.libfdt              |   20 +
 pc-bios/boards/integrator-cp.dts |  110 ++++
 pc-bios/boards/lm3s6965evb.dts   |  212 ++++++++
 pc-bios/boards/lm3s811evb.dts    |  155 ++++++
 pc-bios/boards/syborg.dts        |  134 +++++
 rules.mak                        |    3 
 sysemu.h                         |    3 
 target-ppc/kvm_ppc.c             |    2 
 vl.c                             |   45 +-
 50 files changed, 4973 insertions(+), 615 deletions(-)
 create mode 100644 hw/arm-cpu.c
 create mode 100644 hw/dt-machine.c
 create mode 100644 hw/gpio-buttons.c
 delete mode 100644 hw/stellaris_input.c
 delete mode 100644 hw/syborg.c
 create mode 100644 libfdt/Makefile.libfdt
 create mode 100644 libfdt/TODO
 create mode 100644 libfdt/fdt.c
 create mode 100644 libfdt/fdt.h
 create mode 100644 libfdt/fdt_ro.c
 create mode 100644 libfdt/fdt_rw.c
 create mode 100644 libfdt/fdt_strerror.c
 create mode 100644 libfdt/fdt_sw.c
 create mode 100644 libfdt/fdt_wip.c
 create mode 100644 libfdt/libfdt.h
 create mode 100644 libfdt/libfdt_env.h
 create mode 100644 libfdt/libfdt_internal.h
 create mode 100644 libfdt/patch.libfdt
 create mode 100644 pc-bios/boards/integrator-cp.dts
 create mode 100644 pc-bios/boards/lm3s6965evb.dts
 create mode 100644 pc-bios/boards/lm3s811evb.dts
 create mode 100644 pc-bios/boards/syborg.dts
author
#1 lore raw

PATCH 1/4 Include and build libfdt

Inlcude libfdt in source tree, and build it if not already available.

---

 Makefile                      |   17 +
 Makefile.target               |   14 -
 configure                     |   24 -
 hw/petalogix_s3adsp1800_mmu.c |   40 --
 hw/ppc440_bamboo.c            |    2 
 hw/ppce500_mpc8544ds.c        |    4 
 libfdt/Makefile.libfdt        |   14 +
 libfdt/TODO                   |    3 
 libfdt/fdt.c                  |  156 ++++++
 libfdt/fdt.h                  |   60 ++
 libfdt/fdt_ro.c               |  583 ++++++++++++++++++++++
 libfdt/fdt_rw.c               |  471 ++++++++++++++++++
 libfdt/fdt_strerror.c         |   96 ++++
 libfdt/fdt_sw.c               |  258 ++++++++++
 libfdt/fdt_wip.c              |  144 ++++++
 libfdt/libfdt.h               | 1070 +++++++++++++++++++++++++++++++++++++++++
 libfdt/libfdt_env.h           |   21 +
 libfdt/libfdt_internal.h      |   89 +++
 libfdt/patch.libfdt           |   20 +
 target-ppc/kvm_ppc.c          |    2 
 20 files changed, 3028 insertions(+), 60 deletions(-)
 create mode 100644 libfdt/Makefile.libfdt
 create mode 100644 libfdt/TODO
 create mode 100644 libfdt/fdt.c
 create mode 100644 libfdt/fdt.h
 create mode 100644 libfdt/fdt_ro.c
 create mode 100644 libfdt/fdt_rw.c
 create mode 100644 libfdt/fdt_strerror.c
 create mode 100644 libfdt/fdt_sw.c
 create mode 100644 libfdt/fdt_wip.c
 create mode 100644 libfdt/libfdt.h
 create mode 100644 libfdt/libfdt_env.h
 create mode 100644 libfdt/libfdt_internal.h
 create mode 100644 libfdt/patch.libfdt
Makefile +15 -2
index 3177616..6fc234c 100644
@@ -57,12 +57,23 @@ SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS))
 subdir-%:
 	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" TARGET_DIR="$*/" all,)
 
-$(filter %-softmmu,$(SUBDIR_RULES)): libqemu_common.a
+$(filter %-softmmu,$(SUBDIR_RULES)): libqemu_common.a $(BUILD_LIBFDT)
 $(filter %-user,$(SUBDIR_RULES)): libqemu_user.a
 
 recurse-all: $(SUBDIR_RULES)
 
 #######################################################################
+# Build libfdt
+ifdef BUILD_LIBFDT
+include $(SRC_PATH)/libfdt/Makefile.libfdt
+FDT_OBJS=$(addprefix libfdt/,$(LIBFDT_OBJS))
+
+$(FDT_OBJS): CFLAGS+=-I$(SRC_PATH)/libfdt
+
+libfdt/libfdt.a: $(FDT_OBJS)
+endif
+
+#######################################################################
 # BLOCK_OBJS is code used by both qemu system emulation and qemu-img
 
 BLOCK_OBJS=cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
@@ -255,7 +266,9 @@ clean:
 # avoid old build problems by removing potentially incorrect old files
 	rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
 	rm -f *.o *.d *.a $(TOOLS) TAGS cscope.* *.pod *~ */*~
-	rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d
+	for d in slirp audio block libfdt; do \
+	  rm -f $$d/*.o $$d/*.d $$d/*.a ; \
+	done
 	rm -f qemu-img-cmds.h
 	$(MAKE) -C tests clean
 	for d in $(TARGET_DIRS) libhw32 libhw64; do \
Makefile.target +6 -8
index 27de4b9..4e302c0 100644
@@ -595,10 +595,6 @@ OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
 OBJS+= ppc440.o ppc440_bamboo.o
 # PowerPC E500 boards
 OBJS+= ppce500_pci.o ppce500_mpc8544ds.o
-ifdef FDT_LIBS
-OBJS+= device_tree.o
-LIBS+= $(FDT_LIBS)
-endif
 ifdef CONFIG_KVM
 OBJS+= kvm_ppc.o
 endif
@@ -624,10 +620,6 @@ OBJS+= xilinx_uartlite.o
 OBJS+= xilinx_ethlite.o
 
 OBJS+= pflash_cfi02.o
-ifdef FDT_LIBS
-OBJS+= device_tree.o
-LIBS+= $(FDT_LIBS)
-endif
 endif
 ifeq ($(TARGET_BASE_ARCH), cris)
 # Boards
@@ -695,6 +687,12 @@ endif
 ifdef CONFIG_SLIRP
 CPPFLAGS+=-I$(SRC_PATH)/slirp
 endif
+LIBS+=$(FDT_LIBS)
+OBJS+=device_tree.o
+ifdef BUILD_LIBFDT
+$(QEMU_PROG): $(FDT_LIBS)
+CPPFLAGS += -I$(SRC_PATH)/libfdt
+endif
 
 LIBS+=$(PTHREADLIBS)
 LIBS+=$(CLOCKLIBS)
configure +12 -12
index 89e7f53..59ba8ef 100755
@@ -194,7 +194,7 @@ kvm="yes"
 kerneldir=""
 aix="no"
 blobs="yes"
-fdt="yes"
+build_fdt="yes"
 sdl="yes"
 sdl_x11="no"
 xen="yes"
@@ -1218,15 +1218,13 @@ if $cc $ARCH_CFLAGS -o $TMPE $TMPC > /dev/null 2> /dev/null ; then
 fi
 
 ##########################################
-# fdt probe
-if test "$fdt" = "yes" ; then
-    fdt=no
-    cat > $TMPC << EOF
+# System libfdt probe
+build_fdt=yes
+cat > $TMPC << EOF
 int main(void) { return 0; }
 EOF
-  if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $TMPC -lfdt 2> /dev/null > /dev/null ; then
-    fdt=yes
-  fi
+if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $TMPC -lfdt 2> /dev/null > /dev/null ; then
+  build_fdt=no
 fi
 
 #
@@ -1380,7 +1378,7 @@ echo "AIO support       $aio"
 echo "IO thread         $io_thread"
 echo "Install blobs     $blobs"
 echo -e "KVM support       $kvm"
-echo "fdt support       $fdt"
+echo "Build libfdt      $build_fdt"
 echo "preadv support    $preadv"
 
 if test $sdl_too_old = "yes"; then
@@ -1712,8 +1710,10 @@ fi
 if test "$preadv" = "yes" ; then
   echo "#define HAVE_PREADV 1" >> $config_h
 fi
-if test "$fdt" = "yes" ; then
-  echo "#define HAVE_FDT 1" >> $config_h
+if test "$build_fdt" = "yes" ; then
+  echo "BUILD_LIBFDT=libfdt/libfdt.a" >> $config_mak
+  echo "FDT_LIBS=../libfdt/libfdt.a" >> $config_mak
+else
   echo "FDT_LIBS=-lfdt" >> $config_mak
 fi
 
@@ -2138,7 +2138,7 @@ done # for target in $targets
 
 # build tree in object directory if source path is different from current one
 if test "$source_path_used" = "yes" ; then
-    DIRS="tests tests/cris slirp audio block"
+    DIRS="tests tests/cris slirp audio block libfdt"
     FILES="Makefile tests/Makefile"
     FILES="$FILES tests/cris/Makefile tests/cris/.gdbinit"
     FILES="$FILES tests/test-mmap.c"
hw/petalogix_s3adsp1800_mmu.c +10 -30
index 9ccd12b..25076b7 100644
@@ -52,47 +52,27 @@ static int petalogix_load_device_tree(target_phys_addr_t addr,
                                       target_phys_addr_t initrd_size,
                                       const char *kernel_cmdline)
 {
-#ifdef HAVE_FDT
     void *fdt;
     int r;
-#endif
     char *path;
     int fdt_size;
 
-#ifdef HAVE_FDT
-    /* Try the local "mb.dtb" override.  */
-    fdt = load_device_tree("mb.dtb", &fdt_size);
+    path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
+    if (path) {
+        fdt = load_device_tree(path, &fdt_size);
+        qemu_free(path);
+    } else {
+        fdt = NULL;
+    }
     if (!fdt) {
-        path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
-        if (path) {
-            fdt = load_device_tree(path, &fdt_size);
-            qemu_free(path);
-        }
-        if (!fdt)
-            return 0;
+        return 0;
     }
 
     r = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline);
-    if (r < 0)
+    if (r < 0) {
         fprintf(stderr, "couldn't set /chosen/bootargs\n");
-    cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
-#else
-    /* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob
-       to the kernel.  */
-    fdt_size = load_image_targphys("mb.dtb", addr, 0x10000);
-    if (fdt_size < 0) {
-        path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
-        if (path) {
-            fdt_size = load_image_targphys(path, addr, 0x10000);
-	    qemu_free(path);
-        }
     }
-
-    if (kernel_cmdline) {
-        fprintf(stderr,
-                "Warning: missing libfdt, cannot pass cmdline to kernel!\n");
-    }
-#endif
+    cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
     return fdt_size;
 }
 
hw/ppc440_bamboo.c +0 -2
index 00aa2c7..5796570 100644
@@ -32,7 +32,6 @@ static void *bamboo_load_device_tree(target_phys_addr_t addr,
                                      const char *kernel_cmdline)
 {
     void *fdt = NULL;
-#ifdef HAVE_FDT
     uint32_t mem_reg_property[] = { 0, 0, ramsize };
     char *filename;
     int fdt_size;
@@ -76,7 +75,6 @@ static void *bamboo_load_device_tree(target_phys_addr_t addr,
     cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
 
 out:
-#endif
 
     return fdt;
 }
hw/ppce500_mpc8544ds.c +0 -4
index d9ed36c..b1f1458 100644
@@ -46,7 +46,6 @@
 #define MPC8544_PCI_IO             0xE1000000
 #define MPC8544_PCI_IOLEN          0x10000
 
-#ifdef HAVE_FDT
 static int mpc8544_copy_soc_cell(void *fdt, const char *node, const char *prop)
 {
     uint32_t cell;
@@ -68,7 +67,6 @@ static int mpc8544_copy_soc_cell(void *fdt, const char *node, const char *prop)
 out:
     return ret;
 }
-#endif
 
 static void *mpc8544_load_device_tree(target_phys_addr_t addr,
                                      uint32_t ramsize,
@@ -77,7 +75,6 @@ static void *mpc8544_load_device_tree(target_phys_addr_t addr,
                                      const char *kernel_cmdline)
 {
     void *fdt = NULL;
-#ifdef HAVE_FDT
     uint32_t mem_reg_property[] = {0, ramsize};
     char *filename;
     int fdt_size;
@@ -144,7 +141,6 @@ static void *mpc8544_load_device_tree(target_phys_addr_t addr,
     cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
 
 out:
-#endif
 
     return fdt;
 }
libfdt/Makefile.libfdt new file +14 -0
new file mode 100644
index 0000000..82f9c6a
@@ -0,0 +1,14 @@
+# Makefile.libfdt
+#
+# This is not a complete Makefile of itself.  Instead, it is designed to
+# be easily embeddable into other systems of Makefiles.
+#
+LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c
+LIBFDT_INCLUDES = fdt.h libfdt.h
+LIBFDT_EXTRA = libfdt_internal.h
+LIBFDT_LIB = libfdt/libfdt.a
+
+LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
+
+$(LIBFDT_objdir)/$(LIBFDT_LIB): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
+
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
libfdt/fdt.c new file +156 -0

156 lines not on this page · raw message

libfdt/fdt.h new file +60 -0

60 lines not on this page · raw message

libfdt/fdt_ro.c new file +583 -0

583 lines not on this page · raw message

libfdt/fdt_rw.c new file +471 -0

471 lines not on this page · raw message

libfdt/fdt_strerror.c new file +96 -0

96 lines not on this page · raw message

libfdt/fdt_sw.c new file +258 -0

258 lines not on this page · raw message

libfdt/fdt_wip.c new file +144 -0

144 lines not on this page · raw message

libfdt/libfdt.h new file +1070 -0

994 lines not on this page · raw message

libfdt/libfdt_env.h new file +21 -0
new file mode 100644
index 0000000..81bcd7a

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

libfdt/libfdt_internal.h new file +89 -0

89 lines not on this page · raw message

libfdt/patch.libfdt new file +20 -0
new file mode 100644
index 0000000..c911d10

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

target-ppc/kvm_ppc.c +0 -2
index 10cfdb3..cc639c6 100644

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

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

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

#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] Include and build libfdt

Quoted 1 line · Paul Brook

Inlcude libfdt in source tree, and build it if not already available.

what makes libfdt different than everything else that we link with? Why do we have to have a in-tree copy of that?

#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] Include and build libfdt

Quoted 7 lines · Glauber Costa
Quoted 2 lines · Paul Brook

Inlcude libfdt in source tree, and build it if not already available.

what makes libfdt different than everything else that we link with? Why do we have to have a in-tree copy of that?

Yeah, I had the same comment and withheld it while I considered it.

libfdt isn't widely available as a distro package. Historically, it's been part of dtc and not available for independent download/installation.

It's a tough call.

Regards,

Anthony Liguori

Quoted 4 lines
author
#4 lore raw

Re: [Qemu-devel] [PATCH 1/4] Include and build libfdt

In reply to Glauber Costa
Quoted 5 lines · Glauber Costa
Quoted 1 line · Paul Brook

Inlcude libfdt in source tree, and build it if not already available.

what makes libfdt different than everything else that we link with? Why do we have to have a in-tree copy of that?

AFAIK libfdt is still absent from current releases of common mainstream distros[1], and qemu is going to become increasingly useless without it.

c.f. dtc where we use the system version.

Paul

[1] We can argue about what constitutes sufficiently wide acceptance, but IMHO Fedora, Ubuntu and Debian Sid would be a fairly good start.

#5 lore raw

Re: [Qemu-devel] [PATCH 1/4] Include and build libfdt

Quoted 9 lines · Paul Brook
Quoted 5 lines · Glauber Costa
Quoted 1 line · Paul Brook

Inlcude libfdt in source tree, and build it if not already available.

what makes libfdt different than everything else that we link with? Why do we have to have a in-tree copy of that?

AFAIK libfdt is still absent from current releases of common mainstream distros[1], and qemu is going to become increasingly useless without it.

This is an argument for both including it in our source release, and pushing it to get shipped as a stand alone package. I believe the later is a much more sane approach long term

Quoted 7 lines

c.f. dtc where we use the system version.

Paul

[1] We can argue about what constitutes sufficiently wide acceptance, but IMHO Fedora, Ubuntu and Debian Sid would be a fairly good start.

author
#6 lore raw

Re: [Qemu-devel] [PATCH 1/4] Include and build libfdt

Quoted 8 lines · Glauber Costa
Quoted 7 lines · Paul Brook
Quoted 5 lines · Glauber Costa
Quoted 1 line · Paul Brook

Inlcude libfdt in source tree, and build it if not already available.

what makes libfdt different than everything else that we link with? Why do we have to have a in-tree copy of that?

Quoted 6 lines
Quoted 2 lines

AFAIK libfdt is still absent from current releases of common mainstream distros, and qemu is going to become increasingly useless without it.

This is an argument for both including it in our source release, and pushing it to get shipped as a stand alone package. I believe the later is a much more sane approach long term

Agreed. The configure check will prefer an installed libfdt, so hopefully the in-tree copy will go away over timer.

Paul

#7 lore raw

Re: [Qemu-devel] [PATCH 1/4] Include and build libfdt

In reply to Paul Brook
Quoted 10 lines · Paul Brook
Quoted 5 lines · Glauber Costa
Quoted 1 line · Paul Brook

Inlcude libfdt in source tree, and build it if not already available.

what makes libfdt different than everything else that we link with? Why do we have to have a in-tree copy of that?

AFAIK libfdt is still absent from current releases of common mainstream distros[1], and qemu is going to become increasingly useless without it.

Quoted 6 lines

c.f. dtc where we use the system version.

Paul

[1] We can argue about what constitutes sufficiently wide acceptance, but IMHO Fedora, Ubuntu and Debian Sid would be a fairly good start.

With the microblaze port, one of the main issues I get complaints about is missing libfdt. We have a dynamic fdt driven board off-tree and a static board in mainline but both really depend on libfdt to be useful.

Pretty much everybody has to download dtc and install the libs from there.

It could be that we have looked for the wrong distro packages but if not, it's missing on the above mentioned distros + gentoo.

FWIW though, I'd like to see libfdt in qemu as a temporary thing until libfdt is more widespread.

Cheers

#8 lore raw

Re: [Qemu-devel] [PATCH 1/4] Include and build libfdt

In reply to Glauber Costa
Quoted 5 lines · Glauber Costa
Quoted 1 line · Paul Brook

Inlcude libfdt in source tree, and build it if not already available.

what makes libfdt different than everything else that we link with?
Why do we have to have a in-tree copy of that?

Maybe libfdt is already shipping by your distro, but is it available on Windows, OSX, *Solaris, *BSD, Haiku etc.?

author
#9 lore raw

PATCH 2/4 Add device tree machine

In reply to Paul Brook

FDT based machine creation.
When -M foo is specified look for and use foo.fdb. Build and ship board configs.

---

 .gitignore                |    1 
 Makefile                  |   20 +-
 Makefile.target           |    5 
 configure                 |   17 +
 hw/arm-cpu.c              |   78 ++++++
 hw/arm_boot.c             |   22 ++
 hw/boards.h               |    9 +
 hw/dt-machine.c           |  582 +++++++++++++++++++++++++++++++++++++++++++++
 hw/i2c.c                  |    8 +
 hw/pci.c                  |    1 
 hw/qdev.c                 |  225 +++++++++++++++++
 hw/qdev.h                 |   50 +++-
 hw/ssi.c                  |    7 -
 hw/syborg.c               |  112 ---------
 hw/sysbus.c               |    5 
 hw/sysbus.h               |   15 +
 pc-bios/boards/syborg.dts |  134 ++++++++++
 rules.mak                 |    3 
 sysemu.h                  |    3 
 vl.c                      |   45 +++
 20 files changed, 1179 insertions(+), 163 deletions(-)
 create mode 100644 hw/arm-cpu.c
 create mode 100644 hw/dt-machine.c
 delete mode 100644 hw/syborg.c
 create mode 100644 pc-bios/boards/syborg.dts
.gitignore +1 -0
index a8da10e..225f705 100644
@@ -37,6 +37,7 @@ qemu-io
 *.vr
 *.d
 *.o
+pc-bios/boards/*.dtb
 .pc
 patches
 pc-bios/bios-pq/status
Makefile +18 -2
index 6fc234c..6d15c44 100644
@@ -14,7 +14,7 @@ endif
 .PHONY: all clean cscope distclean dvi html info install install-doc \
 	recurse-all speed tar tarbin test
 
-VPATH=$(SRC_PATH):$(SRC_PATH)/hw
+VPATH=$(SRC_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/pc-bios/boards
 
 
 CFLAGS += $(OS_CFLAGS) $(ARCH_CFLAGS)
@@ -43,7 +43,16 @@ ifdef CONFIG_WIN32
 LIBS+=-lwinmm -lws2_32 -liphlpapi
 endif
 
-build-all: $(TOOLS) $(DOCS) recurse-all
+#######################################################################
+# Board descriptions
+
+BOARDS = syborg
+
+ifdef DTC
+BOARDS_BIN = $(BOARDS:%=pc-bios/boards/%.dtb)
+endif
+
+build-all: $(TOOLS) $(DOCS) recurse-all $(BOARDS_BIN)
 
 config-host.mak: configure
 ifneq ($(wildcard config-host.mak),)
@@ -266,6 +275,7 @@ clean:
 # avoid old build problems by removing potentially incorrect old files
 	rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
 	rm -f *.o *.d *.a $(TOOLS) TAGS cscope.* *.pod *~ */*~
+	rm -f $(BOARDS_BIN)
 	for d in slirp audio block libfdt; do \
 	  rm -f $$d/*.o $$d/*.d $$d/*.a ; \
 	done
@@ -316,6 +326,12 @@ ifneq ($(BLOBS),)
 		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
 	done
 endif
+ifneq ($(BOARDS_BIN),)
+	$(INSTALL_DIR) "$(DESTDIR)$(datadir)/boards"
+	set -e; for x in $(BOARDS_BIN); do \
+		$(INSTALL_DATA) $(SRC_PATH)/$$x "$(DESTDIR)$(datadir)/boards"; \
+	done
+endif
 ifndef CONFIG_WIN32
 	$(INSTALL_DIR) "$(DESTDIR)$(datadir)/keymaps"
 	set -e; for x in $(KEYMAPS); do \
Makefile.target +3 -2
index 4e302c0..4bc4c76 100644
@@ -494,7 +494,7 @@ endif #CONFIG_BSD_USER
 ifndef CONFIG_USER_ONLY
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \
-     gdbstub.o gdbstub-xml.o
+     gdbstub.o gdbstub-xml.o dt-machine.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 OBJS+=virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o
@@ -664,9 +664,10 @@ OBJS+= nseries.o blizzard.o onenand.o vga.o cbus.o tusb6010.o usb-musb.o
 OBJS+= mst_fpga.o mainstone.o
 OBJS+= musicpal.o pflash_cfi02.o
 OBJS+= framebuffer.o
-OBJS+= syborg.o syborg_fb.o syborg_interrupt.o syborg_keyboard.o
+OBJS+= syborg_fb.o syborg_interrupt.o syborg_keyboard.o
 OBJS+= syborg_serial.o syborg_timer.o syborg_pointer.o syborg_rtc.o
 OBJS+= syborg_virtio.o
+OBJS+= arm-cpu.o
 CPPFLAGS += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), sh4)
configure +16 -1
index 59ba8ef..f20da35 100755
@@ -199,6 +199,7 @@ sdl="yes"
 sdl_x11="no"
 xen="yes"
 pkgversion=""
+dtc=""
 
 # OS specific
 if check_define __linux__ ; then
@@ -503,6 +504,8 @@ for opt do
   ;;
   --with-pkgversion=*) pkgversion=" ($optarg)"
   ;;
+  --with-dtc=*) dtc="$optarg"
+  ;;
   --disable-docs) build_docs="no"
   ;;
   *) echo "ERROR: unknown option $opt"; show_help="yes"
@@ -1227,6 +1230,13 @@ if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $TMPC -lfdt 2> /dev/null > /dev/null ;
   build_fdt=no
 fi
 
+# Check for device tree compiler
+if test -z "$dtc" ; then
+  dtc="`which dtc 2>/dev/null`"
+  if test ! -x "$dtc" ; then
+    dtc=""
+  fi
+fi
 #
 # Check for xxxat() functions when we are building linux-user
 # emulator.  This is done because older glibc versions don't
@@ -1380,6 +1390,7 @@ echo "Install blobs     $blobs"
 echo -e "KVM support       $kvm"
 echo "Build libfdt      $build_fdt"
 echo "preadv support    $preadv"
+echo "dtc               ${dtc:-(Not Found)}"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -1708,7 +1719,7 @@ if test "$iovec" = "yes" ; then
   echo "#define HAVE_IOVEC 1" >> $config_h
 fi
 if test "$preadv" = "yes" ; then
-  echo "#define HAVE_PREADV 1" >> $config_h
+  echo "#defne HAVE_PREADV 1" >> $config_h
 fi
 if test "$build_fdt" = "yes" ; then
   echo "BUILD_LIBFDT=libfdt/libfdt.a" >> $config_mak
@@ -1717,6 +1728,10 @@ else
   echo "FDT_LIBS=-lfdt" >> $config_mak
 fi
 
+if [ -n "$dtc" ] ; then
+  echo "DTC=$dtc" >> $config_mak
+fi
+
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then
   echo "#define O_LARGEFILE 0" >> $config_h
hw/arm-cpu.c new file +78 -0

78 lines not on this page · raw message

hw/arm_boot.c +22 -0
index acfa67e..95dd532 100644
@@ -10,6 +10,7 @@
 #include "hw.h"
 #include "arm-misc.h"
 #include "sysemu.h"
+#include "boards.h"
 
 #define KERNEL_ARGS_ADDR 0x100
 #define KERNEL_LOAD_ADDR 0x00010000
@@ -260,3 +261,24 @@ void arm_load_kernel(CPUState *env, struct arm_boot_info *info)
             set_kernel_args(info, initrd_size, info->loader_start);
     }
 }
+
+static struct arm_boot_info arm_linux_binfo;
+static void arm_linux_bootstrap(ram_addr_t ram_size, const char *boot_device,
+    const char *kernel_filename, const char *kernel_cmdline,
+    const char *initrd_filename)
+{
+    arm_linux_binfo.ram_size = ram_size;
+    arm_linux_binfo.kernel_filename = kernel_filename;
+    arm_linux_binfo.kernel_cmdline = kernel_cmdline;
+    arm_linux_binfo.initrd_filename = initrd_filename;
+    arm_linux_binfo.board_id = get_bootstrap_arg_int("board-id", 0);
+    arm_linux_binfo.loader_start = get_bootstrap_arg_int("loader-start", 0);
+    arm_load_kernel(first_cpu, &arm_linux_binfo);
+}
+
+static void arm_boot_register(void)
+{
+    register_machine_bootstrap("arm-linux", arm_linux_bootstrap);
+}
+
+machine_init(arm_boot_register);
hw/boards.h +9 -0
index f6733b7..1733e8b 100644
@@ -23,5 +23,14 @@ typedef struct QEMUMachine {
 int qemu_register_machine(QEMUMachine *m);
 
 extern QEMUMachine *current_machine;
+extern QEMUMachine dt_machine;
+
+typedef void (*machine_bootstrapfn)(ram_addr_t ram_size,
+    const char *boot_device,
+    const char *kernel_filename, const char *kernel_cmdline,
+    const char *initrd_filename);
+
+void register_machine_bootstrap(const char *name, machine_bootstrapfn fn);
+uint64_t get_bootstrap_arg_int(const char *name, uint64_t def);
 
 #endif
hw/dt-machine.c new file +582 -0

582 lines not on this page · raw message

hw/i2c.c +7 -1
index 8a0c4d7..4e53c09 100644
@@ -68,7 +68,7 @@ int i2c_start_transfer(i2c_bus *bus, int address, int recv)
     DeviceState *qdev;
     i2c_slave *slave = NULL;
 
-    LIST_FOREACH(qdev, &bus->qbus.children, sibling) {
+    TAILQ_FOREACH(qdev, &bus->qbus.children, sibling) {
         slave = I2C_SLAVE_FROM_QDEV(qdev);
         if (slave->address == address)
             break;
@@ -152,9 +152,15 @@ static void i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base)
     info->init(s);
 }
 
+static const DevicePropList i2c_bus_props[] = {
+      {.name = "address", .type = PROP_TYPE_INT},
+      {.name = NULL}
+};
 void i2c_register_slave(const char *name, int size, I2CSlaveInfo *info)
 {
+    assert(!info->qdev.init);
     assert(size >= sizeof(i2c_slave));
+    info->qdev.props = qdev_merge_props(info->qdev.props, i2c_bus_props);
     info->qdev.init = i2c_slave_qdev_init;
     info->qdev.bus_type = BUS_TYPE_I2C;
     qdev_register(name, size, &info->qdev);
hw/pci.c +1 -0
index 8c904ba..487017d 100644
@@ -924,6 +924,7 @@ void pci_qdev_register(const char *name, int size, pci_qdev_initfn init)
     PCIDeviceInfo *info;
 
     info = qemu_mallocz(sizeof(*info));
+    assert(!info->qdev.init);
     info->init = init;
     info->qdev.init = pci_qdev_init;
     info->qdev.bus_type = BUS_TYPE_PCI;
hw/qdev.c +215 -10

307 lines not on this page · raw message

hw/qdev.h +38 -12

101 lines not on this page · raw message

hw/ssi.c +4 -3
index 52b7b7c..c086f02 100644
@@ -20,8 +20,8 @@ static void ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
     SSIBus *bus;
 
     bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
-    if (LIST_FIRST(&bus->qbus.children) != dev
-        || LIST_NEXT(dev, sibling) != NULL) {
+    if (TAILQ_FIRST(&bus->qbus.children) != dev
+        || TAILQ_NEXT(dev, sibling) != NULL) {
         hw_error("Too many devices on SSI bus");
     }
 
@@ -32,6 +32,7 @@ static void ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
 void ssi_register_slave(const char *name, int size, SSISlaveInfo *info)
 {
     assert(size >= sizeof(SSISlave));
+    assert(!info->qdev.init);
     info->qdev.init = ssi_slave_init;
     info->qdev.bus_type = BUS_TYPE_SSI;
     qdev_register(name, size, &info->qdev);
@@ -56,7 +57,7 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
 {
     DeviceState *dev;
     SSISlave *slave;
-    dev = LIST_FIRST(&bus->qbus.children);
+    dev = TAILQ_FIRST(&bus->qbus.children);
     if (!dev) {
         return 0;
     }
hw/syborg.c deleted +0 -112

112 lines not on this page · raw message

hw/sysbus.c +4 -1
index fbd2ddf..4903747 100644
@@ -101,13 +101,16 @@ void sysbus_init_mmio_cb(SysBusDevice *dev, target_phys_addr_t size,
 static void sysbus_device_init(DeviceState *dev, DeviceInfo *base)
 {
     SysBusDeviceInfo *info = container_of(base, SysBusDeviceInfo, qdev);
+    SysBusDevice *s = sysbus_from_qdev(dev);
 
-    info->init(sysbus_from_qdev(dev));
+    s->info = info;
+    info->init(s);
 }
 
 void sysbus_register_withprop(const char *name, size_t size,
                               SysBusDeviceInfo *info)
 {
+    assert(!info->qdev.init);
     info->qdev.init = sysbus_device_init;
     info->qdev.bus_type = BUS_TYPE_SYSTEM;
 
hw/sysbus.h +8 -7
index 2973661..11fa8ad 100644
@@ -11,8 +11,16 @@
 typedef struct SysBusDevice SysBusDevice;
 typedef void (*mmio_mapfunc)(SysBusDevice *dev, target_phys_addr_t addr);
 
+typedef void (*sysbus_initfn)(SysBusDevice *dev);
+
+typedef struct {
+    DeviceInfo qdev;
+    sysbus_initfn init;
+} SysBusDeviceInfo;
+
 struct SysBusDevice {
     DeviceState qdev;
+    SysBusDeviceInfo *info;
     int num_irq;
     qemu_irq irqs[QDEV_MAX_IRQ];
     qemu_irq *irqp[QDEV_MAX_IRQ];
@@ -25,17 +33,10 @@ struct SysBusDevice {
     } mmio[QDEV_MAX_MMIO];
 };
 
-typedef void (*sysbus_initfn)(SysBusDevice *dev);
-
 /* Macros to compensate for lack of type inheritance in C.  */
 #define sysbus_from_qdev(dev) ((SysBusDevice *)(dev))
 #define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)
 
-typedef struct {
-    DeviceInfo qdev;
-    sysbus_initfn init;
-} SysBusDeviceInfo;
-
 void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init);
 void sysbus_register_withprop(const char *name, size_t size,
                               SysBusDeviceInfo *info);
pc-bios/boards/syborg.dts new file +134 -0

134 lines not on this page · raw message

rules.mak +3 -0
index 8d6d96e..d332209 100644
@@ -16,4 +16,7 @@ LINK = $(call quiet-command,$(CC) $(LDFLAGS) -o $@ $(1) $(ARLIBS_BEGIN) $(ARLIBS
 %.a:
 	$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"  AR    $(TARGET_DIR)$@")
 
+%.dtb: %.dts
+	$(call quiet-command,$(DTC) -O dtb -o $@ $<, "  DTC   $(TARGET_DIR)$@")
+
 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
sysemu.h +3 -0
index 658aeec..ec2961c 100644
@@ -13,6 +13,7 @@ extern const char *bios_name;
 
 #define QEMU_FILE_TYPE_BIOS   0
 #define QEMU_FILE_TYPE_KEYMAP 1
+#define QEMU_FILE_TYPE_BOARD  2
 char *qemu_find_file(int type, const char *name);
 
 extern int vm_running;
@@ -274,4 +275,6 @@ int check_params(const char * const *params, const char *str);
 
 void register_devices(void);
 
+void qdev_do_late_init(void);
+
 #endif
vl.c +33 -12

92 lines not on this page · raw message

#10 lore raw

Re: [Qemu-devel] [PATCH 2/4] Add device tree machine

Quoted 3 lines · Paul Brook

FDT based machine creation.
When -M foo is specified look for and use foo.fdb. Build and ship board configs.

Cool.

Quoted 3 lines

if test "$preadv" = "yes" ; then
- echo "#define HAVE_PREADV 1" >> $config_h
+ echo "#defne HAVE_PREADV 1" >> $config_h

#defne?

Quoted 2 lines

+ buf = qemu_mallocz(strlen(name) + 5);
+ sprintf(buf, "%s.dtb", name);

snprintf?

author
#11 lore raw

Re: [Qemu-devel] [PATCH 2/4] Add device tree machine

Quoted 5 lines
Quoted 3 lines

if test "$preadv" = "yes" ; then
- echo "#define HAVE_PREADV 1" >> $config_h
+ echo "#defne HAVE_PREADV 1" >> $config_h

#defne?

Oops. I've sure I've already fixed that at least twice...

Quoted 4 lines
Quoted 2 lines

+ buf = qemu_mallocz(strlen(name) + 5);
+ sprintf(buf, "%s.dtb", name);

snprintf?

Bah. Stoopid paranoid OpenBSD. :-)

Paul

#12 lore raw

Re: [Qemu-devel] [PATCH 2/4] Add device tree machine

In reply to Paul Brook
Quoted 15 lines

+++ b/hw/arm-cpu.c

hw/arm-cpu.c new file +12 -0
+/* FIXME: Remove this and make the CPU emulation use the right names.  */
+static const struct {
+    const char *devname;
+    const char *cpuname;
+} cpu_device_name_map[] = {
+    {"ARM,ARM926EJ-S", "arm926"},
+    {"ARM,Cortex-A8", "cortex-a8"}
+};
 
+static void arm_cpu_register_devices(void)
+{
+    int i;
+    CPUInfo *info;

hw/arm-cpu.c line 75

Quoted 10 lines
hw/arm-cpu.c new file +10 -0
+
+    for (i = 0; i<  ARRAY_SIZE(cpu_device_name_map); i++) {
+        info = qemu_mallocz(sizeof(*info));
+        info->sysbus.qdev.props = cpu_qdev_props;
+        info->sysbus.init = arm_cpu_dev_init;
+        info->cpuname = cpu_device_name_map[i].cpuname;
+        sysbus_register_withprop(cpu_device_name_map[i].devname,
+                                 sizeof(CPUDevice),
+&info->sysbus);
+    }

I would drop cpu_device_name_map[] and have static CPUInfo structs instead.

hw/dt-machine.c line 410

Quoted 4 lines

+++ b/hw/dt-machine.c

hw/dt-machine.c new file +2 -0
+void dt_fixup_sysbus_device(DeviceState *dev)
+{

That doesn't belong here, it should go to sysbus.c.

With the businfo patch (http://git.et.redhat.com/?p=qemu-kraxel.git;a=commitdiff;h=c02134e1d986892df7e8cc1cd27cf340fcafec63) posted yesterday it is easy, just add a fixup_device() callback to the BusInfo struct. I'd name it configure() instead of fixup() though.

Quoted 1 line

+ qdev_fixup_devices();

qdev_configure_devices() ?

hw/qdev.c BusState *qbus_create(BusType type, size_t size, · line 465

Quoted 7 lines
hw/qdev.c +7 -0
+DeviceState *qdev_from_phandle(uint32_t phandle)
+{
+    if (!main_system_bus) {
+        return NULL;
+    }
+    return qdev_from_phandle1(main_system_bus, phandle);
+}

What this is good for? Seems to be unused in the existing board descriptions ...

cheers,
Gerd

#13 lore raw

Re: [Qemu-devel] [PATCH 2/4] Add device tree machine

In reply to Paul Brook

A few more comments ...

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void dt_add_props(DeviceState *dev, void *dt, int offset)
+{

Where do device properties come from? Only the fdt tree? If so, do we need the property lists in the first place? We could get them directly from the fdt tree instead.

hw/i2c.c static void i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base) · line 158

Quoted 4 lines
hw/i2c.c +4 -0
+static const DevicePropList i2c_bus_props[] = {
+      {.name = "address", .type = PROP_TYPE_INT},
+      {.name = NULL}
+};

That could go into BusInfo as well.

cheers,
Gerd

author
#14 lore raw

Re: [Qemu-devel] [PATCH 2/4] Add device tree machine

Quoted 8 lines · Gerd Hoffmann

A few more comments ...

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void dt_add_props(DeviceState *dev, void *dt, int offset)
+{

Where do device properties come from? Only the fdt tree? If so, do we need the property lists in the first place? We could get them directly from the fdt tree instead.

The FDT doesn't contain any type information. My initial implementation omitted DevicePropertyList altogether. That ended up fairly messy. Also, when we're using the same tree for both qemu and linux the tree probably has additional properties we don't care about.

Paul

#15 lore raw

Re: [Qemu-devel] [PATCH 2/4] Add device tree machine

Quoted 6 lines · Paul Brook
Quoted 3 lines · Gerd Hoffmann

Where do device properties come from? Only the fdt tree? If so, do we need the property lists in the first place? We could get them directly from the fdt tree instead.

The FDT doesn't contain any type information.

Which isn't a issue IMHO. The driver which needs the value knows the type to expect, doesn't it?

To outline in more detail what I mean:

Now we have (picking an example with int type):
dt_add_props(), calling

    fdt_getprop() + fdt32_to_cpu() + qdev_set_prop_int().
And
  i2c_slave_qdev_init(), calling
    qdev_get_prop_int().

I think instead we can do:
Have a helper named --say -- qdev_get_fdt_int(), calling
fdt_getprop() + fdt32_to_cpu(), returning an int.
Then have
i2c_slave_qdev_init() calling

    qdev_get_fdt_int().

i.e. don't extract and save the properties at all, instead have helper functions to get them directly from the fdt tree.

cheers,
Gerd

#16 lore raw

Re: [Qemu-devel] [PATCH 2/4] Add device tree machine

In reply to Paul Brook
Quoted 33 lines · Paul Brook

FDT based machine creation.
When -M foo is specified look for and use foo.fdb. Build and ship board configs.

---

 .gitignore                |    1 
 Makefile                  |   20 +-
 Makefile.target           |    5 
 configure                 |   17 +
 hw/arm-cpu.c              |   78 ++++++
 hw/arm_boot.c             |   22 ++
 hw/boards.h               |    9 +
 hw/dt-machine.c           |  582 +++++++++++++++++++++++++++++++++++++++++++++
 hw/i2c.c                  |    8 +
 hw/pci.c                  |    1 
 hw/qdev.c                 |  225 +++++++++++++++++
 hw/qdev.h                 |   50 +++-
 hw/ssi.c                  |    7 -
 hw/syborg.c               |  112 ---------
 hw/sysbus.c               |    5 
 hw/sysbus.h               |   15 +
 pc-bios/boards/syborg.dts |  134 ++++++++++
 rules.mak                 |    3 
 sysemu.h                  |    3 
 vl.c                      |   45 +++
 20 files changed, 1179 insertions(+), 163 deletions(-)
 create mode 100644 hw/arm-cpu.c
 create mode 100644 hw/dt-machine.c
 delete mode 100644 hw/syborg.c
 create mode 100644 pc-bios/boards/syborg.dts

[...]

Quoted 22 lines
configure +3 -0
index 59ba8ef..f20da35 100755
@@ -199,6 +199,7 @@ sdl="yes"
 sdl_x11="no"
 xen="yes"
 pkgversion=""
+dtc=""
 
 # OS specific
 if check_define __linux__ ; then
@@ -503,6 +504,8 @@ for opt do
   ;;
   --with-pkgversion=*) pkgversion=" ($optarg)"
   ;;
+  --with-dtc=*) dtc="$optarg"
+  ;;
   --disable-docs) build_docs="no"
   ;;
   *) echo "ERROR: unknown option $opt"; show_help="yes"

configure if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $TMPC -lfdt 2> /dev/null > /dev/null ; · line 1239

Quoted 10 lines
configure +7 -0
@@ -1227,6 +1230,13 @@ if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $TMPC -lfdt 2> /dev/null > /dev/null ;
   build_fdt=no
 fi
 
+# Check for device tree compiler
+if test -z "$dtc" ; then
+  dtc="`which dtc 2>/dev/null`"
+  if test ! -x "$dtc" ; then
+    dtc=""
+  fi
+fi

New build dependency. Fine with me.

Quoted 31 lines
configure +6 -1
 #
 # Check for xxxat() functions when we are building linux-user
 # emulator.  This is done because older glibc versions don't
@@ -1380,6 +1390,7 @@ echo "Install blobs     $blobs"
 echo -e "KVM support       $kvm"
 echo "Build libfdt      $build_fdt"
 echo "preadv support    $preadv"
+echo "dtc               ${dtc:-(Not Found)}"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -1708,7 +1719,7 @@ if test "$iovec" = "yes" ; then
   echo "#define HAVE_IOVEC 1" >> $config_h
 fi
 if test "$preadv" = "yes" ; then
-  echo "#define HAVE_PREADV 1" >> $config_h
+  echo "#defne HAVE_PREADV 1" >> $config_h
 fi
 if test "$build_fdt" = "yes" ; then
   echo "BUILD_LIBFDT=libfdt/libfdt.a" >> $config_mak
@@ -1717,6 +1728,10 @@ else
   echo "FDT_LIBS=-lfdt" >> $config_mak
 fi
 
+if [ -n "$dtc" ] ; then
+  echo "DTC=$dtc" >> $config_mak
+fi
+
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then
   echo "#define O_LARGEFILE 0" >> $config_h

[...]

Quoted 141 lines
hw/dt-machine.c new file +135 -0
new file mode 100644
index 0000000..b960a6c
@@ -0,0 +1,582 @@
+#include "sysbus.h"
+#include "device_tree.h"
+#include "boards.h"
+
+#include <libfdt.h>
+
+/* FIXME: Remove this.  */
+static void *the_dt;
+static int bootstrap_offset;
+
+static void dt_walk_bus(DeviceState *parent, void *dt, int offset, int folded);
+
+static int fdt_next_node(const void *fdt, int offset)
+{
+    int level = 1;
+    uint32_t tag;
+    int nextoffset;
+
+    tag = fdt_next_tag(fdt, offset, &nextoffset);
+    if (tag != FDT_BEGIN_NODE)
+        return -FDT_ERR_BADOFFSET;
+
+    while (level >= 0) {
+        offset = nextoffset;
+        tag = fdt_next_tag(fdt, offset, &nextoffset);
+
+        switch (tag) {
+        case FDT_END:
+            return -FDT_ERR_TRUNCATED;
+        case FDT_BEGIN_NODE:
+            level++;
+            if (level == 1)
+                return offset;
+            break;
+        case FDT_END_NODE:
+            level--;
+            break;
+        case FDT_PROP:
+        case FDT_NOP:
+            break;
+        default:
+            return -FDT_ERR_BADSTRUCTURE;
+        }
+    }
+
+    return -FDT_ERR_NOTFOUND;
+}
+
+static int fdt_first_subnode(const void *fdt, int offset)
+{
+    uint32_t tag;
+    int nextoffset;
+
+    tag = fdt_next_tag(fdt, offset, &nextoffset);
+    if (tag != FDT_BEGIN_NODE)
+        return -FDT_ERR_BADOFFSET;
+
+    while (tag != FDT_END_NODE) {
+        offset = nextoffset;
+        tag = fdt_next_tag(fdt, offset, &nextoffset);
+
+        switch (tag) {
+        case FDT_END:
+            return -FDT_ERR_TRUNCATED;
+        case FDT_BEGIN_NODE:
+            return offset;
+        case FDT_END_NODE:
+        case FDT_PROP:
+        case FDT_NOP:
+            break;
+        default:
+            return -FDT_ERR_BADSTRUCTURE;
+        }
+    }
+
+    return -FDT_ERR_NOTFOUND;
+}
+
+static void dt_add_props(DeviceState *dev, void *dt, int offset)
+{
+    DevicePropList *prop;
+    const void *p;
+    int prop_len;
+    uint64_t i;
+    const uint32_t *ip;
+
+    prop = qdev_get_proplist(dev);
+    if (!prop) {
+        return;
+    }
+    for (; prop->name; prop++) {
+        p = fdt_getprop(dt, offset, prop->name, &prop_len);
+        if (!p) {
+            continue;
+        }
+        ip = p;
+        switch (prop->type) {
+        case PROP_TYPE_INT:
+            if (prop_len != 4 && prop_len != 8) {
+                hw_error("%s: Bad length for property '%s'\n",
+                         fdt_get_name(dt, offset, NULL), prop->name);
+            }
+            i = fdt32_to_cpu(ip[0]);
+            if (prop_len == 8) {
+                i = (i << 32) | fdt32_to_cpu(ip[1]);
+            }
+            qdev_set_prop_int(dev, prop->name, i);
+            break;
+        case PROP_TYPE_DEV:
+            {
+                uint32_t phandle;
+                DeviceState *other_dev;
+                if (prop_len != 4) {
+                    hw_error("%s: Bad length for property '%s'\n",
+                             fdt_get_name(dt, offset, NULL), prop->name);
+                }
+                phandle = fdt32_to_cpu(ip[0]);
+                other_dev = qdev_from_phandle(phandle);
+                if (!other_dev) {
+                    hw_error("%s: Device (%d) not found\n",
+                             fdt_get_name(dt, offset, NULL), phandle);
+                }
+                qdev_set_prop_dev(dev, prop->name, other_dev);
+            }
+            break;
+        case PROP_TYPE_ARRAY:
+            {
+                uint32_t *data;
+                if (prop_len & 3) {
+                    hw_error("%s: Bad length for property '%s'\n",
+                             fdt_get_name(dt, offset, NULL), prop->name);
+                }
+                data = qemu_malloc(prop_len);
+                for (i = 0; i < prop_len >> 2; i++) {
+                    data[i] = fdt32_to_cpu(ip[i]);

hw/dt-machine.c line 145

Quoted 10 lines
hw/dt-machine.c new file +10 -0
+                }
+                qdev_set_prop_array(dev, prop->name, data, prop_len >> 2);
+                qemu_free(data);
+            }
+            break;
+        default:
+            abort();
+        }
+    }
+}

Here you copy the device's known properties from FDT to the qdev->props.

Why have a dynamically typed property list in qdev? Why not make the properties ordinary members of the device struct, and have the property descriptor DevicePropList specify where they are (offset from qdev)? Moves some type checking to compile-time.

Alternatively, why not get the properties straight from FDT, as Gerd suggested?

Quoted 60 lines
hw/dt-machine.c new file +60 -0
+
+static void dt_create_device(BusState *bus, void *dt, int offset)
+{
+    char namebuf[128];
+    const char *type;
+    const uint32_t *prop;
+    char *p;
+    DeviceState *dev;
+
+    /* First try the "model" property.  */
+    type = fdt_getprop(dt, offset, "model", NULL);
+    if (type && !qdev_device_exists(type)) {
+        type = NULL;
+    }
+    /* If that does not work then try "compatible".  */
+    if (!type) {
+        type = fdt_getprop(dt, offset, "compatible", NULL);
+        if (type && !qdev_device_exists(type)) {
+            type = NULL;
+        }
+    }
+    /* If all else fails then resort to the device name.  */
+    if (!type) {
+        type = fdt_get_name(dt, offset, NULL);
+        p = namebuf;
+        while (*type && *type != '@') {
+            *(p++) = *(type++);
+        }
+        *p = 0;
+        if (!qdev_device_exists(namebuf)) {
+            hw_error("Unrecognised device '%s'\n",
+                     fdt_get_name(dt, offset, NULL));
+        }
+        type = namebuf;
+    }
+
+    dev = qdev_create(bus, type);
+    dev->fdt_offset = offset;
+    prop = fdt_getprop(dt, offset, "linux,phandle", NULL);
+    if (prop) {
+        dev->phandle = fdt32_to_cpu(*prop);
+    } else {
+        dev->phandle = -1;
+    }
+}
+
+static void dt_init_device(DeviceState *dev, void *opaque)
+{
+    void *dt = opaque;
+    int offset;
+
+    offset = dev->fdt_offset;
+    dt_add_props(dev, dt, offset);
+    qdev_init(dev);
+
+    dt_walk_bus(dev, dt, offset, 0);
+}
+
+static int dt_fold_bus(void *dt, int offset)
+{

hw/dt-machine.c line 215

Quoted 10 lines
hw/dt-machine.c new file +10 -0
+    const char *name = fdt_get_name(dt, offset, NULL);
+
+    if (strcmp(name, "cpus") == 0) {
+        return 1;
+    }
+    if (fdt_getprop(dt, offset, "qemu,fold-bus", NULL)) {
+        return 1;
+    }
+    return 0;
+}

Please document all qemu,FOO properties.

Quoted 93 lines
hw/dt-machine.c new file +93 -0
+
+static int dt_ignore_node(void *dt, int offset)
+{
+    const char *name = fdt_get_name(dt, offset, NULL);
+
+    if (strcmp(name, "chosen") == 0) {
+        return 1;
+    }
+    if (strcmp(name, "aliases") == 0) {
+        return 1;
+    }
+    if (fdt_getprop(dt, offset, "qemu,ignore", NULL)) {
+        return 1;
+    }
+    return 0;
+}
+
+static void dt_get_sizes(void *dt, int offset,
+                         int *addr_cells, int *size_cells)
+{
+    const uint32_t *prop;
+    int parent;
+
+    parent = fdt_parent_offset(dt, offset);
+    assert(parent >= 0);
+
+    if (addr_cells) {
+        prop = fdt_getprop(dt, parent, "#address-cells", NULL);
+        if (!prop) {
+            hw_error("%s: Missing #address-cells",
+                     fdt_get_name(dt, offset, NULL));
+        }
+        *addr_cells = fdt32_to_cpu(*prop);
+    }
+
+    if (size_cells) {
+        prop = fdt_getprop(dt, parent, "#size-cells", NULL);
+        if (!prop) {
+            hw_error("%s: Missing #size-cells",
+                     fdt_get_name(dt, offset, NULL));
+        }
+        *size_cells = fdt32_to_cpu(*prop);
+    }
+}
+
+static void dt_create_memory(void *dt, int offset, int flags)
+{
+    const uint32_t *regs;
+    int regs_len;
+    const uint32_t *alias;
+    int alias_len;
+    int addr_cells;
+    int size_cells;
+    uint64_t addr;
+    uint64_t size;
+    ram_addr_t ram_offset;
+
+    dt_get_sizes(dt, offset, &addr_cells, &size_cells);
+    regs = fdt_getprop(dt, offset, "reg", &regs_len);
+    if (!regs || regs_len == 0) {
+        return;
+    }
+    if ((regs_len % ((addr_cells + size_cells) * 4)) != 0) {
+        hw_error("%s: Bad reg size\n", fdt_get_name(dt, offset, NULL));
+    }
+    alias = fdt_getprop(dt, offset, "qemu,alias", &alias_len);
+    while (regs_len > 0) {
+        addr = fdt32_to_cpu(*(regs++));
+        if (addr_cells == 2) {
+            addr = (addr << 32) | fdt32_to_cpu(*(regs++));
+        }
+        size = fdt32_to_cpu(*(regs++));
+        if (size_cells == 2) {
+            size = (size << 32) | fdt32_to_cpu(*(regs++));
+        }
+        regs_len -= (addr_cells + size_cells) * 4;
+        if (size != (ram_addr_t)size) {
+            hw_error("Ram too big\n");
+        }
+        ram_offset = qemu_ram_alloc(size);
+        cpu_register_physical_memory(addr, size, ram_offset | flags);
+        if (alias) {
+            if (regs_len > 0) {
+                hw_error("%s: Aliased memory may only have a single region",
+                         fdt_get_name(dt, offset, NULL));
+            }
+            if ((alias_len % addr_cells) != 0) {
+                hw_error("%s: Bad qemu,alias size\n",
+                         fdt_get_name(dt, offset, NULL));
+            }
+            while (alias_len) {
+                addr = fdt32_to_cpu(*(alias++));
+                if (addr_cells== 2) {

hw/dt-machine.c line 318

Quoted 10 lines
hw/dt-machine.c new file +10 -0
+                    addr = (addr << 32) | fdt32_to_cpu(*(alias++));
+                }
+                cpu_register_physical_memory(addr, size, ram_offset | flags);
+                alias_len -= addr_cells * 4;
+            }
+        }
+    }
+}
+
+static void dt_walk_bus(DeviceState *parent, void *dt, int offset, int folded)

This seems to create the device tree for an FDT. Not obvious from the name.

Quoted 264 lines
hw/dt-machine.c new file +264 -0
+{
+    int next_offset;
+    const char *type;
+    const char *bus_name;
+    BusState *parent_bus;
+
+    if (parent) {
+        parent_bus = LIST_FIRST(&parent->child_bus);
+    } else {
+        parent_bus = NULL;
+    }
+    next_offset = fdt_first_subnode(dt, offset);
+    while (next_offset > 0) {
+        offset = next_offset;
+        next_offset = fdt_next_node(dt, offset);
+        if (dt_ignore_node(dt, offset)) {
+            continue;
+        }
+        if (dt_fold_bus(dt, offset)) {
+            dt_walk_bus(parent, dt, offset, 1);
+            continue;
+        }
+        bus_name = fdt_getprop(dt, offset, "qemu,parent-bus", NULL);
+        if (bus_name) {
+            if (parent) {
+                parent_bus = qdev_get_child_bus(parent, bus_name);
+            }
+            if (!parent_bus) {
+                hw_error("%s: Unable to find parent bus\n",
+                         fdt_get_name(dt, offset, NULL));
+            }
+        }
+        type = fdt_getprop(dt, offset, "device_type", NULL);
+        /* Special case for memory.  */
+        if (type && strcmp(type, "memory") == 0) {
+            dt_create_memory(dt, offset, IO_MEM_RAM);
+            continue;
+        }
+        if (type && strcmp(type, "rom") == 0) {
+            dt_create_memory(dt, offset, IO_MEM_ROM);
+            continue;
+        }
+        dt_create_device(parent_bus, dt, offset);
+    }
+    if (!folded) {
+        qdev_enumerate_child_devices(parent, dt_init_device, dt);
+    }
+}
+
+void dt_fixup_qdev(DeviceState *dev)
+{
+    void *dt = the_dt;
+    int offset = dev->fdt_offset;
+    int n;
+    int prop_size;
+    const uint32_t *prop;
+
+    if (dev->num_gpio_out) {
+        int parent;
+        int irqn;
+        qemu_irq pin;
+        DeviceState *parent_dev;
+
+        prop = fdt_getprop(dt, offset, "qemu,gpio", &prop_size);
+        if (prop_size != 8 * dev->num_gpio_out) {
+            hw_error("%s: Bad GPIO size\n", fdt_get_name(dt, offset, NULL));
+        }
+        for (n = 0; n < dev->num_gpio_out; n++) {
+            parent = fdt32_to_cpu(*(prop++));
+            if (parent == 0) {
+                /* Assume zero phandle means disconnected.  */
+                prop++;
+                continue;
+            }
+            parent_dev = qdev_from_phandle(parent);
+            if (!parent_dev) {
+                hw_error("%s: GPIO device (%d) not found\n",
+                         fdt_get_name(dt, offset, NULL), parent);
+            }
+            irqn = fdt32_to_cpu(*(prop++));
+            if (irqn >= parent_dev->num_gpio_in) {
+                hw_error("%s: Invalid GPIO %d (%d)\n",
+                         fdt_get_name(dt, offset, NULL), n, irqn);
+            }
+            pin = qdev_get_gpio_in(parent_dev, irqn);
+            qdev_connect_gpio_out(dev, n, pin);
+        }
+    }
+}
+
+void dt_fixup_sysbus_device(DeviceState *dev)
+{
+    SysBusDevice *s = sysbus_from_qdev(dev);
+    void *dt = the_dt;
+    int offset = dev->fdt_offset;
+    const uint32_t *prop;
+    int prop_size;
+    int n;
+
+    if (s->num_mmio) {
+        int addr_cells;
+        int size_cells;
+        uint64_t addr;
+        dt_get_sizes(dt, offset, &addr_cells, &size_cells);
+        if (addr_cells < 1 || addr_cells > 2) {
+            hw_error("%s: unsupported #address-cells (%d)\n",
+                     fdt_get_name(dt, offset, NULL), addr_cells);
+        }
+        prop = fdt_getprop(dt, offset, "reg", &prop_size);
+        if (prop_size != (addr_cells + size_cells) * 4 * s->num_mmio) {
+            hw_error("%s: Bad reg size\n", fdt_get_name(dt, offset, NULL));
+        }
+        for (n = 0; n < s->num_mmio; n++) {
+            addr = fdt32_to_cpu(*(prop++));
+            if (addr_cells == 2) {
+                addr = (addr << 32) | fdt32_to_cpu(*(prop++));
+            }
+            /* The device already told up how big the region is, so ignore
+               what the device tree says.  */
+            prop += size_cells;
+            sysbus_mmio_map(s, n, addr);
+        }
+    }
+
+    if (s->num_irq) {
+        int parent;
+        int irqn;
+        DeviceState *parent_dev;
+
+        prop = fdt_getprop(dt, offset, "interrupt-parent", &prop_size);
+        if (!prop || prop_size != 4) {
+            hw_error("%s: Missing/bad interrupt-parent\n",
+                     fdt_get_name(dt, offset, NULL));
+        }
+        parent = fdt32_to_cpu(*prop);
+        parent_dev = qdev_from_phandle(parent);
+        if (!parent_dev) {
+            hw_error("%s: interrupt-parent device (%d) not found\n",
+                     fdt_get_name(dt, offset, NULL), parent);
+        }
+        prop = fdt_getprop(dt, parent_dev->fdt_offset, "#interrupt-cells",
+                           &prop_size);
+        if (!prop || prop_size != 4) {
+            hw_error("%s: Missing #interrupt-cells\n",
+                     fdt_get_name(dt, parent_dev->fdt_offset, NULL));
+        }
+        if (fdt32_to_cpu(*prop) != 1) {
+            hw_error("%s: unsupported #interrupt-cells\n",
+                     fdt_get_name(dt, parent_dev->fdt_offset, NULL));
+        }
+        prop = fdt_getprop(dt, offset, "interrupts", &prop_size);
+        if (prop_size != 4 * s->num_irq) {
+            hw_error("%s: Bad interrupts size\n",
+                     fdt_get_name(dt, offset, NULL));
+        }
+        for (n = 0; n < s->num_irq; n++) {
+            irqn = fdt32_to_cpu(*(prop++));
+            if (irqn == -1) {
+                continue;
+            }
+            if (irqn >= parent_dev->num_gpio_in) {
+                hw_error("%s: Invalid interrupt %d (%d)\n",
+                         fdt_get_name(dt, offset, NULL), n, irqn);
+            }
+            sysbus_connect_irq(s, n, qdev_get_gpio_in(parent_dev, irqn));
+        }
+    }
+}
+
+typedef struct MachineBootstrap {
+    const char *name;
+    machine_bootstrapfn fn;
+    LIST_ENTRY(MachineBootstrap) next;
+} MachineBootstrap;
+
+LIST_HEAD(, MachineBootstrap) machine_bootstrap_list =
+    LIST_HEAD_INITIALIZER(machine_bootstrap_list);
+
+void register_machine_bootstrap(const char *name, machine_bootstrapfn fn)
+{
+    MachineBootstrap *bootstrap;
+
+    bootstrap = qemu_mallocz(sizeof(*bootstrap));
+    bootstrap->name = qemu_strdup(name);
+    bootstrap->fn = fn;
+    LIST_INSERT_HEAD(&machine_bootstrap_list, bootstrap, next);
+}
+
+uint64_t get_bootstrap_arg_int(const char *name, uint64_t def)
+{
+    void *dt = the_dt;
+    const uint32_t *p;
+    int prop_len;
+    uint64_t val;
+
+    p = fdt_getprop(dt, bootstrap_offset, name, &prop_len);
+    if (!p) {
+        return def;
+    }
+    if (prop_len != 4 && prop_len != 8) {
+        hw_error("Bad length for property '%s'\n", name);
+    }
+    val = fdt32_to_cpu(p[0]);
+    if (prop_len == 8) {
+        val = (val << 32) | fdt32_to_cpu(p[1]);
+    }
+    return val;
+}
+
+static void dt_init(ram_addr_t ram_size,
+                     const char *boot_device,
+                     const char *kernel_filename, const char *kernel_cmdline,
+                     const char *initrd_filename, const char *cpu_model)
+{
+    void *dt;
+    int dt_size;
+    const char *filename;
+
+    filename = dt_machine.name;
+    /* FIXME: Allow user to specify filename.  */
+    dt = load_device_tree(filename, &dt_size);
+    if (!dt) {
+        hw_error("Failed to load device tree\n");
+    }
+
+    the_dt = dt;
+
+    dt_walk_bus(NULL, dt, 0, 0);
+
+    qdev_fixup_devices();
+
+    {
+    const char *p;
+    MachineBootstrap *bootstrap;
+
+    bootstrap_offset = fdt_path_offset(dt, "/chosen/qemu");
+    if (bootstrap_offset < 0) {
+        return;
+    }
+    p = fdt_getprop(dt, bootstrap_offset, "bootstrap", NULL);
+    if (!p) {
+        return;
+    }
+
+    LIST_FOREACH(bootstrap, &machine_bootstrap_list, next) {
+        if (strcmp(bootstrap->name, p) == 0) {
+            break;
+        }
+    }
+    if (!bootstrap) {
+        hw_error("Unrecognised machine bootstrap '%s'\n", p);
+    }
+    bootstrap->fn(ram_size, boot_device, kernel_filename, kernel_cmdline,
+                  initrd_filename);
+
+    }
+}
+
+/* This is used directly by vl.c, and not registered by normal means.  */
+QEMUMachine dt_machine = {
+    .name = "devtree",
+    .desc = "Device Tree",
+    .init = dt_init,
+};

[...]

Quoted 5 lines
hw/qdev.c +0 -0
index 636dc78..39e8ce8 100644

hw/qdev.c line 35

Quoted 10 lines
hw/qdev.c +7 -0
@@ -26,6 +26,25 @@
    inherit from a particular bus (e.g. PCI or I2C) rather than
    this API directly.  */
 
+/* Device instantiation occurs in several stages.
+
+   1) Device objects are created (qdev_create).
+   2) Device properties are set.
+   3) Device init routines are run.
+   4) GPIO and IRQ lines are connected and MMIO regions are mapped.
+   5) Device late init routines are run.

I see you discovered the need for a second initialization callback. Good.

Quoted 300 lines
hw/qdev.c +207 -9
+
+   It can be assumed that all siblings on a bus have been created before
+   any are initialized.  Child devices are created after the parent
+   device is initialized.  Thus PROP_TYPE_DEV may only refer to siblings or
+   siblings of direct ancestors.  No dependency tracking is performed, so
+   a device may be initialized before the devices it references.
+
+   Other than Within each stage, devices are processed in arbitrary order.
+
+   Steps 3, 4 and 5 only occur after preceeding steps have been completed
+   for all devices. */
+
 #include "net.h"
 #include "qdev.h"
 #include "sysemu.h"
@@ -37,6 +56,10 @@ struct DeviceProperty {
     union {
         uint64_t i;
         void *ptr;
+        struct {
+            uint32_t *data;
+            int len;
+        } array;
     } value;
     DeviceProperty *next;
 };
@@ -68,6 +91,23 @@ void qdev_register(const char *name, int size, DeviceInfo *info)
     t->info = info;
 }
 
+static DeviceType *qdev_find_devtype(const char *name)
+{
+    DeviceType *t;
+
+    for (t = device_type_list; t; t = t->next) {
+        if (strcmp(t->name, name) == 0) {
+            return t;;
+        }
+    }
+    return NULL;
+}
+
+int qdev_device_exists(const char *name)
+{
+    return qdev_find_devtype(name) != NULL;
+}
+
 /* Create a new device.  This only initializes the device state structure
    and allows properties to be set.  qdev_init should be called to
    initialize the actual device emulation.  */
@@ -76,11 +116,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
     DeviceType *t;
     DeviceState *dev;
 
-    for (t = device_type_list; t; t = t->next) {
-        if (strcmp(t->name, name) == 0) {
-            break;
-        }
-    }
+    t = qdev_find_devtype(name);
     if (!t) {
         hw_error("Unknown device '%s'\n", name);
     }
@@ -89,8 +125,8 @@ DeviceState *qdev_create(BusState *bus, const char *name)
     dev->type = t;
 
     if (!bus) {
-        /* ???: This assumes system busses have no additional state.  */
         if (!main_system_bus) {
+            /* ???: This assumes system busses have no additional state.  */
             main_system_bus = qbus_create(BUS_TYPE_SYSTEM, sizeof(BusState),
                                           NULL, "main-system-bus");
         }
@@ -102,7 +138,9 @@ DeviceState *qdev_create(BusState *bus, const char *name)
                  t->info->bus_type, bus->type);
     }
     dev->parent_bus = bus;
-    LIST_INSERT_HEAD(&bus->children, dev, sibling);
+    /* Keep devices in creation order for consistency between creation
+       and initialization passes.  */
+    TAILQ_INSERT_TAIL(&bus->children, dev, sibling);
     return dev;
 }
 
@@ -114,10 +152,32 @@ void qdev_init(DeviceState *dev)
     dev->type->info->init(dev, dev->type->info);
 }
 
+static void qdev_late_init_bus(BusState *bus)
+{
+    DeviceState *dev;
+    BusState *child_bus;
+
+    TAILQ_FOREACH(dev, &bus->children, sibling) {
+        if (dev->type->info->late_init) {
+            dev->type->info->late_init(dev);
+        }
+        LIST_FOREACH(child_bus, &dev->child_bus, sibling) {
+            qdev_late_init_bus(child_bus);
+        }
+    }
+}
+
+void qdev_do_late_init(void)
+{
+    if (main_system_bus) {
+        qdev_late_init_bus(main_system_bus);
+    }
+}
+
 /* Unlink device from bus and free the structure.  */
 void qdev_free(DeviceState *dev)
 {
-    LIST_REMOVE(dev, sibling);
+    TAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
     free(dev);
 }
 
@@ -152,6 +212,17 @@ void qdev_set_prop_dev(DeviceState *dev, const char *name, DeviceState *value)
     prop->value.ptr = value;
 }
 
+void qdev_set_prop_array(DeviceState *dev, const char *name, uint32_t *data,
+                         int len)
+{
+    DeviceProperty *prop;
+
+    prop = create_prop(dev, name, PROP_TYPE_ARRAY);
+    prop->value.array.data = qemu_malloc(len * 4);
+    prop->value.array.len = len;
+    memcpy(prop->value.array.data, data, len * 4);
+}
+
 void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value)
 {
     DeviceProperty *prop;
@@ -231,6 +302,21 @@ DeviceState *qdev_get_prop_dev(DeviceState *dev, const char *name)
     return prop->value.ptr;
 }
 
+int qdev_get_prop_array(DeviceState *dev, const char *name,
+                        const uint32_t **p)
+{
+    DeviceProperty *prop;
+
+    prop = find_prop(dev, name, PROP_TYPE_ARRAY);
+    if (!prop) {
+        return -1;
+    }
+    if (p) {
+        *p = prop->value.array.data;
+    }
+    return prop->value.array.len;
+}
+
 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
 {
     assert(dev->num_gpio_in == 0);
@@ -272,6 +358,17 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev,
 
 void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr)
 {
+    static int next_netdev;
+    if (!dev->nd) {
+        /* FIXME: This is just plain broken.  */
+        if (next_netdev >= nb_nics) {
+            abort();
+        }
+        dev->nd = &nd_table[next_netdev];
+        next_netdev++;
+
+        qemu_check_nic_model(dev->nd, dev->type->name);
+    }
     memcpy(macaddr, dev->nd->macaddr, 6);
 }
 
@@ -332,13 +429,121 @@ BusState *qbus_create(BusType type, size_t size,
     bus->type = type;
     bus->parent = parent;
     bus->name = qemu_strdup(name);
-    LIST_INIT(&bus->children);
+    TAILQ_INIT(&bus->children);
     if (parent) {
         LIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
     }
     return bus;
 }
 
+static DeviceState *qdev_from_phandle1(BusState *bus, uint32_t phandle)
+{
+    DeviceState *dev;
+    BusState *child_bus;
+    DeviceState *child_dev;
+
+    TAILQ_FOREACH(dev, &bus->children, sibling) {
+        if (dev->phandle == phandle) {
+            return dev;
+        }
+        LIST_FOREACH(child_bus, &dev->child_bus, sibling) {
+            child_dev = qdev_from_phandle1(child_bus, phandle);
+            if (child_dev) {
+                return child_dev;
+            }
+        }
+    }
+    return NULL;
+}
+
+DeviceState *qdev_from_phandle(uint32_t phandle)
+{
+    if (!main_system_bus) {
+        return NULL;
+    }
+    return qdev_from_phandle1(main_system_bus, phandle);  
+}
+
+static void qdev_fixup_bus(BusState *bus)
+{
+    DeviceState *dev;
+
+    TAILQ_FOREACH(dev, &bus->children, sibling) {
+        if (!dev->fdt_offset) {
+            continue;
+        }
+        dt_fixup_qdev(dev);
+        switch (bus->type) {
+        case BUS_TYPE_SYSTEM:
+            dt_fixup_sysbus_device(dev);
+            break;
+        default:
+            break;
+        }
+    }
+}
+
+void qdev_fixup_devices(void)
+{
+    assert(main_system_bus);
+    qdev_fixup_bus(main_system_bus);
+}
+
+static void enumerate_bus_devices(BusState *bus, enumdevfn cb, void *opaque)
+{
+    DeviceState *dev;
+
+    TAILQ_FOREACH(dev, &bus->children, sibling) {
+        cb(dev, opaque);
+    }
+}
+
+void qdev_enumerate_child_devices(DeviceState *dev, enumdevfn cb, void *opaque)
+{
+    BusState *bus;
+
+    if (!dev) {
+        enumerate_bus_devices(main_system_bus, cb, opaque);
+        return;
+    }
+    LIST_FOREACH(bus, &dev->child_bus, sibling) {
+        enumerate_bus_devices(bus, cb, opaque);
+    }
+}
+
+DevicePropList *qdev_get_proplist(DeviceState *dev)
+{
+    return dev->type->info->props;
+}
+
+DevicePropList *qdev_merge_props(const DevicePropList *a,
+                                 const DevicePropList *b)
+{
+    int n;
+    const DevicePropList *p;
+    DevicePropList *q;
+    DevicePropList *ret;
+
+    n = 0;
+    for (p = a; p && p->name; p++) {
+        n++;
+    }
+    for (p = b; p && p->name; p++) {
+        n++;
+    }
+    n++;
+    ret = qemu_malloc(sizeof(DevicePropList) * n);
+    q = ret;
+    for (p = a; p && p->name; p++) {
+        *(q++) = *p;
+    }
+    for (p = b; p && p->name; p++) {
+        *(q++) = *p;
+    }
+    q->name = NULL;
+    return ret;
+}
+
 static const char *bus_type_names[] = {
     [ BUS_TYPE_SYSTEM ] = "System",
     [ BUS_TYPE_PCI ]    = "PCI",

hw/qdev.c static void qbus_print(Monitor *mon, BusState *bus, int indent) · line 610

Quoted 8 lines
hw/qdev.c +1 -1
@@ -399,7 +604,7 @@ static void qbus_print(Monitor *mon, BusState *bus, int indent)
     qdev_printf("bus: %s\n", bus->name);
     indent += 2;
     qdev_printf("type %s\n", bus_type_names[bus->type]);
-    LIST_FOREACH(dev, &bus->children, sibling) {
+    TAILQ_FOREACH(dev, &bus->children, sibling) {
         qdev_print(mon, dev, indent);
     }
 }

[...]

There's a fair amount of IEEE-1275 gunk in here, which I believe QEMU could well do without. Being able to pass the config straight on to the PowerPC kernel is nice, but I'm not at all sure that can justify the gunk.

author
#17 lore raw

PATCH 3/4 Stellaris machine config

In reply to Paul Brook

Replace hardcoded stellaris boards with machine configs

---

 Makefile                       |    4 -
 Makefile.hw                    |    2 
 hw/arm-cpu.c                   |    3 
 hw/armv7m.c                    |   61 +++++++++
 hw/gpio-buttons.c              |  124 ++++++++++++++++++
 hw/pl011.c                     |    2 
 hw/pl061.c                     |   25 +++-
 hw/stellaris.c                 |  272 +++++++++-------------------------------
 hw/stellaris_enet.c            |    2 
 hw/stellaris_input.c           |   91 -------------
 pc-bios/boards/lm3s6965evb.dts |  212 +++++++++++++++++++++++++++++++
 pc-bios/boards/lm3s811evb.dts  |  155 +++++++++++++++++++++++
 12 files changed, 645 insertions(+), 308 deletions(-)
 create mode 100644 hw/gpio-buttons.c
 delete mode 100644 hw/stellaris_input.c
 create mode 100644 pc-bios/boards/lm3s6965evb.dts
 create mode 100644 pc-bios/boards/lm3s811evb.dts
Makefile +2 -2
index 6d15c44..48a3ec3 100644
@@ -46,7 +46,7 @@ endif
 #######################################################################
 # Board descriptions
 
-BOARDS = syborg
+BOARDS = syborg lm3s811evb lm3s6965evb
 
 ifdef DTC
 BOARDS_BIN = $(BOARDS:%=pc-bios/boards/%.dtb)
@@ -115,7 +115,7 @@ OBJS+=readline.o console.o
 
 OBJS+=irq.o ptimer.o
 OBJS+=i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o
-OBJS+=ssd0303.o ssd0323.o ads7846.o stellaris_input.o twl92230.o
+OBJS+=ssd0303.o ssd0323.o ads7846.o twl92230.o
 OBJS+=tmp105.o lm832x.o eeprom93xx.o tsc2005.o
 OBJS+=scsi-disk.o cdrom.o
 OBJS+=scsi-generic.o
Makefile.hw +2 -0
index 6accb3b..1953b85 100644
@@ -28,6 +28,8 @@ OBJS+= lsi53c895a.o esp.o
 
 OBJS+= dma-helpers.o sysbus.o
 
+OBJS+= gpio-buttons.o
+
 all: $(HWLIB)
 # Dummy command so that make thinks it has done something
 	@true
hw/arm-cpu.c +2 -1
index c15eb12..4c128d1 100644
@@ -17,7 +17,8 @@ static const struct {
     const char *cpuname;
 } cpu_device_name_map[] = {
     {"ARM,ARM926EJ-S", "arm926"},
-    {"ARM,Cortex-A8", "cortex-a8"}
+    {"ARM,Cortex-A8", "cortex-a8"},
+    {"ARM,Cortex-M3", "cortex-m3"}
 };
 
 typedef struct {
hw/armv7m.c +59 -2

81 lines not on this page · raw message

hw/gpio-buttons.c new file +124 -0

124 lines not on this page · raw message

hw/pl011.c +1 -1
index 3a1a4cb..f167bec 100644
@@ -323,7 +323,7 @@ static void pl011_register_devices(void)
 {
     sysbus_register_dev("pl011", sizeof(pl011_state),
                         pl011_init_arm);
-    sysbus_register_dev("pl011_luminary", sizeof(pl011_state),
+    sysbus_register_dev("luminary,pl011", sizeof(pl011_state),
                         pl011_init_luminary);
 }
 
hw/pl061.c +23 -2
index aa0a322..8e38bd6 100644
@@ -291,6 +291,18 @@ static int pl061_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
+static void pl061_late_init(DeviceState *dev)
+{
+    pl061_state *s = FROM_SYSBUS(pl061_state, sysbus_from_qdev(dev));
+    int i;
+
+    for (i = 0; i < 8; i++) {
+        if (s->float_high & (1 << i)) {
+            qemu_irq_raise(s->out[i]);
+        }
+    }
+}
+
 static void pl061_init(SysBusDevice *dev)
 {
     int iomemtype;
@@ -302,14 +314,23 @@ static void pl061_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
     qdev_init_gpio_in(&dev->qdev, pl061_set_irq, 8);
     qdev_init_gpio_out(&dev->qdev, s->out, 8);
+    s->float_high = qdev_get_prop_int(&dev->qdev, "float-high", 0);
     pl061_reset(s);
     register_savevm("pl061_gpio", -1, 1, pl061_save, pl061_load, s);
 }
 
+static SysBusDeviceInfo pl061_info = {
+    .init = pl061_init,
+    .qdev.late_init = pl061_late_init,
+    .qdev.props = (DevicePropList[]) {
+        {.name = "float-high", .type = PROP_TYPE_INT},
+        {.name = NULL}
+    }
+};
 static void pl061_register_devices(void)
 {
-    sysbus_register_dev("pl061", sizeof(pl061_state),
-                        pl061_init);
+    sysbus_register_withprop("pl061", sizeof(pl061_state),
+                             &pl061_info);
 }
 
 device_init(pl061_register_devices)
hw/stellaris.c +64 -208

341 lines not on this page · raw message

hw/stellaris_enet.c +1 -1
index 36fabd3..86df231 100644
@@ -417,7 +417,7 @@ static void stellaris_enet_init(SysBusDevice *dev)
 
 static void stellaris_enet_register_devices(void)
 {
-    sysbus_register_dev("stellaris_enet", sizeof(stellaris_enet_state),
+    sysbus_register_dev("stellaris-enet", sizeof(stellaris_enet_state),
                         stellaris_enet_init);
 }
 
hw/stellaris_input.c deleted +0 -91

91 lines not on this page · raw message

pc-bios/boards/lm3s6965evb.dts new file +212 -0

212 lines not on this page · raw message

pc-bios/boards/lm3s811evb.dts new file +155 -0

155 lines not on this page · raw message

#18 lore raw

Re: [Qemu-devel] [PATCH 3/4] Stellaris machine config

I've been following the tree, and the qdev bits in general since I have my own stack of patches against a few things.

I'm sure it's been discussed to death already, but I just recently joined so sorry to add another layer on top.

I don't understand how replacing things with a non-source code file helps anything in this case. The original stellaris code was rather bad already compared to some other CPUs/SoC:
+ Not a single #define constant, all encoded in good old HEX.
+ No constants for /anything/ in fact, down to the number of GPIO ports hard coded to 7 in many places.
+ No way to create a derivative board with /just/ the SoC, and add custom IOs.

So now, with qdev, it's all official, /every value, constant, and bitfield/ is hard coded, in hex, into a different non-code file, with no way of derivating or overloading from.

I've seen (well I even done a few) projects that tought that using a super-duper 'meta file' (xml etc) was a fantastic idea, it turns out it's never really a fantastic idea, and you spend your time looking at code that is busy recovering properties from deep down an abstract (and unreadable) runtime tree to do /anything/.

If you look at your diff here and count lines, it's exactly whats happening, You replaced about 2 page-worth of straightforward readable code with countless new pages of entirely unrelated non-code. In fact, the stellaris share /a lot/ between themselves, and there is not a single shared line between your two stellaris boards definition file.

When I started hacking at qemu to add my own board supports some month ago, I tought it was the neatest, meanest, "no frill" approach that made it so cool. You could actualy /follow code thru!/ -- how refreshing! Now there are a bunch of arcane and ugly /macros/ to convert blindly struct into others, with no type checking, no overloading, no methods. It's like even-worse-c++.

Sorry for the rant, I'll go back to idling.

Michel

Quoted 1,197 lines · Paul Brook

Replace hardcoded stellaris boards with machine configs

---

 Makefile                       |    4 -
 Makefile.hw                    |    2
 hw/arm-cpu.c                   |    3
 hw/armv7m.c                    |   61 +++++++++
 hw/gpio-buttons.c              |  124 ++++++++++++++++++ hw/pl011.c                     |    2
 hw/pl061.c                     |   25 +++-
 hw/stellaris.c                 |  272 +++++++++------------------------------- hw/stellaris_enet.c            |    2
 hw/stellaris_input.c           |   91 ------------- pc-bios/boards/lm3s6965evb.dts |  212 +++++++++++++++++++++++++++++++ pc-bios/boards/lm3s811evb.dts  |  155 +++++++++++++++++++++++

 12 files changed, 645 insertions(+), 308 deletions(-)

 create mode 100644 hw/gpio-buttons.c delete mode 100644 hw/stellaris_input.c create mode 100644 pc-bios/boards/lm3s6965evb.dts create mode 100644 pc-bios/boards/lm3s811evb.dts

Makefile +1 -1
index 6d15c44..48a3ec3 100644
@@ -46,7 +46,7 @@ endif
  #######################################################################
  # Board descriptions
 
-BOARDS = syborg
+BOARDS = syborg lm3s811evb lm3s6965evb
 

 ifdef DTC
 BOARDS_BIN = $(BOARDS:%=pc-bios/boards/%.dtb)

Makefile +0 -0
@@ -115,7 +115,7 @@ OBJS+=readline.o console.o
 

 OBJS+=irq.o ptimer.o
 OBJS+=i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o

Makefile +1 -1
-OBJS+=ssd0303.o ssd0323.o ads7846.o stellaris_input.o twl92230.o
+OBJS+=ssd0303.o ssd0323.o ads7846.o twl92230.o

 OBJS+=tmp105.o lm832x.o eeprom93xx.o tsc2005.o
 OBJS+=scsi-disk.o cdrom.o
 OBJS+=scsi-generic.o

Makefile.hw +0 -0
index 6accb3b..1953b85 100644
@@ -28,6 +28,8 @@ OBJS+= lsi53c895a.o esp.o
 

 OBJS+= dma-helpers.o sysbus.o

Makefile.hw +2 -0
+OBJS+= gpio-buttons.o
+

 all: $(HWLIB)
 # Dummy command so that make thinks it has done something @true

hw/arm-cpu.c +2 -1
index c15eb12..4c128d1 100644
@@ -17,7 +17,8 @@ static const struct {
     const char *cpuname;
  } cpu_device_name_map[] = {
     {"ARM,ARM926EJ-S", "arm926"},
-    {"ARM,Cortex-A8", "cortex-a8"}
+    {"ARM,Cortex-A8", "cortex-a8"},
+    {"ARM,Cortex-M3", "cortex-m3"}
  };
 
  typedef struct {
hw/armv7m.c +42 -0
index c3c5b9e..d74a2fb 100644
@@ -10,6 +10,7 @@
  #include "sysbus.h"
  #include "arm-misc.h"
  #include "sysemu.h"
+#include "boards.h"
 
  /* Bitbanded IO.  Each word corresponds to a single bit.  */
 
@@ -149,6 +150,47 @@ static void armv7m_bitband_init(void)
  }
 
  /* Board init.  */
+/* Reset initialization and iage loading for ARMv7-M cores.  */
+static void armv7m_bootstrap(ram_addr_t ram_size, const char *boot_device,
+    const char *kernel_filename, const char *kernel_cmdline,
+    const char *initrd_filename)
+{
+    CPUState *env = first_cpu;
+    uint32_t pc;
+    int image_size;
+    uint64_t entry;
+    uint64_t lowaddr;
+
+    image_size = load_elf(kernel_filename, 0, &entry, &lowaddr, NULL);
+    if (image_size < 0) {
+        image_size = load_image_targphys(kernel_filename, 0, ram_size);
+       lowaddr = 0;
+    }
+    if (image_size < 0) {
+        fprintf(stderr, "qemu: could not load kernel '%s'\n",
+                kernel_filename);
+        exit(1);
+    }
+
+    /* If the image was loaded at address zero then assume it is a
+       regular ROM image and perform the normal CPU reset sequence.
+       Otherwise jump directly to the entry point.  */
+    if (lowaddr == 0) {
+       env->regs[13] = ldl_phys(0);
+       pc = ldl_phys(4);
+    } else {
+       pc = entry;
+    }
+    env->thumb = pc & 1;
+    env->regs[15] = pc & ~1;
+
+    /* Hack to map an additional page of ram at the top of the address
+       space.  This stops qemu complaining about executing code outside RAM
+       when returning from an exception.  */
+    cpu_register_physical_memory(0xfffff000, 0x1000,
+                                 qemu_ram_alloc(0x1000) | IO_MEM_RAM);
+}
+
  /* Init CPU and memory for a v7-M based board.

   flash_size and sram_size are in kb.
   Returns the NVIC array.  */

hw/armv7m.c +17 -2
@@ -238,10 +280,25 @@ qemu_irq *armv7m_init(int flash_size, int sram_size,
     return pic;
  }
 
+static SysBusDeviceInfo bitband_info = {
+    .init = bitband_init,
+    .qdev.props = (DevicePropList[]) {
+        {.name = "base", .type = PROP_TYPE_INT},
+        {.name = NULL}
+    }
+};
+
  static void armv7m_register_devices(void)
  {
-    sysbus_register_dev("ARM,bitband-memory", sizeof(BitBandState),
-                        bitband_init);
+    sysbus_register_withprop("ARM,bitband-memory", sizeof(BitBandState),
+                             &bitband_info);
  }
 
  device_init(armv7m_register_devices)
+
+static void armv7m_boot_register(void)
+{
+    register_machine_bootstrap("ARMv7-M", armv7m_bootstrap);
+}
+
+machine_init(armv7m_boot_register);
hw/gpio-buttons.c new file +124 -0
new file mode 100644
index 0000000..0627818
@@ -0,0 +1,124 @@
+/*
+ * Buttons connected directly to GPIO pins.
+ *
+ * Copyright (c) 2009 CodeSourcery.
+ * Written by Paul Brook
+ *
+ * This code is licenced under the GNU GPL v2.
+ */
+#include "sysbus.h"
+#include "console.h"
+
+#define KEY_INVERT      0x80000000u
+#define KEY_CODE_MASK   0x0000ffffu
+
+typedef struct {
+    SysBusDevice busdev;
+    qemu_irq *irq;
+    const uint32_t *keys;
+    int *pressed;
+    int num_buttons;
+    int extension;
+} GPIOButtonsState;
+
+static void gpio_buttons_put_key(void *opaque, int keycode)
+{
+    GPIOButtonsState *s = (GPIOButtonsState *)opaque;
+    int i;
+    int down;
+
+    if (keycode == 0xe0 && !s->extension) {
+        s->extension = 0x80;
+        return;
+    }
+
+    down = (keycode & 0x80) == 0;
+    keycode = (keycode & 0x7f) | s->extension;
+
+    for (i = 0; i < s->num_buttons; i++) {
+        if ((s->keys[i] & KEY_CODE_MASK) == keycode
+                && s->pressed[i] != down) {
+            s->pressed[i] = down;
+            if (s->keys[i] & KEY_INVERT) {
+                qemu_set_irq(s->irq[i], !down);
+            } else {
+                qemu_set_irq(s->irq[i], down);
+            }
+        }
+    }
+
+    s->extension = 0;
+}
+
+static void gpio_buttons_save(QEMUFile *f, void *opaque)
+{
+    GPIOButtonsState *s = (GPIOButtonsState *)opaque;
+    int i;
+
+    qemu_put_be32(f, s->extension);
+    for (i = 0; i < s->num_buttons; i++)
+        qemu_put_byte(f, s->pressed[i]);
+}
+
+static int gpio_buttons_load(QEMUFile *f, void *opaque, int version_id)
+{
+    GPIOButtonsState *s = (GPIOButtonsState *)opaque;
+    int i;
+
+    if (version_id != 1)
+        return -EINVAL;
+
+    s->extension = qemu_get_be32(f);
+    for (i = 0; i < s->num_buttons; i++)
+        s->pressed[i] = qemu_get_byte(f);
+
+    return 0;
+}
+
+static void gpio_buttons_late_init(DeviceState *dev)
+{
+    GPIOButtonsState *s = FROM_SYSBUS(GPIOButtonsState, sysbus_from_qdev(dev));
+    int i;
+
+    for (i = 0; i < s->num_buttons; i++) {
+        if (s->keys[i] & KEY_INVERT) {
+            qemu_irq_raise(s->irq[i]);
+        }
+    }
+}
+
+static void gpio_buttons_init(SysBusDevice *dev)
+{
+    GPIOButtonsState *s = FROM_SYSBUS(GPIOButtonsState, dev);
+
+    s->num_buttons = qdev_get_prop_array(&dev->qdev, "keys", &s->keys);
+    if (s->num_buttons <= 0) {
+        hw_error("gpio-buttons: Missing keys property");
+    }
+
+    s->irq = qemu_mallocz(sizeof(qemu_irq) * s->num_buttons);
+    qdev_init_gpio_out(&dev->qdev, s->irq, s->num_buttons);
+    s->pressed = qemu_mallocz(sizeof(int) * s->num_buttons);
+    qemu_add_kbd_event_handler(gpio_buttons_put_key, s);
+    register_savevm("gpio-buttons", -1, 1,
+                    gpio_buttons_save, gpio_buttons_load, s);
+}
+
+static SysBusDeviceInfo gpio_buttons_info = {
+    .init = gpio_buttons_init,
+    .qdev.late_init = gpio_buttons_late_init,
+    .qdev.props = (DevicePropList[]) {
+        {.name = "keys", .type = PROP_TYPE_ARRAY},
+        {.name = NULL}
+    }
+};
+
+static void gpio_buttons_register_devices(void)
+{
+    /* ??? This isn't really attached to the system bus, but it's as good
+       a place as any to put it.  */
+    sysbus_register_withprop("qemu,gpio-buttons", sizeof(GPIOButtonsState),
+                             &gpio_buttons_info);
+}
+
+device_init(gpio_buttons_register_devices)
hw/pl011.c +1 -1
index 3a1a4cb..f167bec 100644
@@ -323,7 +323,7 @@ static void pl011_register_devices(void)
  {
     sysbus_register_dev("pl011", sizeof(pl011_state),
                         pl011_init_arm);
-    sysbus_register_dev("pl011_luminary", sizeof(pl011_state),
+    sysbus_register_dev("luminary,pl011", sizeof(pl011_state),
                         pl011_init_luminary);
  }
 
hw/pl061.c +23 -2
index aa0a322..8e38bd6 100644
@@ -291,6 +291,18 @@ static int pl061_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
  }
 
+static void pl061_late_init(DeviceState *dev)
+{
+    pl061_state *s = FROM_SYSBUS(pl061_state, sysbus_from_qdev(dev));
+    int i;
+
+    for (i = 0; i < 8; i++) {
+        if (s->float_high & (1 << i)) {
+            qemu_irq_raise(s->out[i]);
+        }
+    }
+}
+
  static void pl061_init(SysBusDevice *dev)
  {
     int iomemtype;
@@ -302,14 +314,23 @@ static void pl061_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
     qdev_init_gpio_in(&dev->qdev, pl061_set_irq, 8);
     qdev_init_gpio_out(&dev->qdev, s->out, 8);
+    s->float_high = qdev_get_prop_int(&dev->qdev, "float-high", 0);
     pl061_reset(s);
     register_savevm("pl061_gpio", -1, 1, pl061_save, pl061_load, s);
  }
 
+static SysBusDeviceInfo pl061_info = {
+    .init = pl061_init,
+    .qdev.late_init = pl061_late_init,
+    .qdev.props = (DevicePropList[]) {
+        {.name = "float-high", .type = PROP_TYPE_INT},
+        {.name = NULL}
+    }
+};
  static void pl061_register_devices(void)
  {
-    sysbus_register_dev("pl061", sizeof(pl061_state),
-                        pl061_init);
+    sysbus_register_withprop("pl061", sizeof(pl061_state),
+                             &pl061_info);
  }
 
  device_init(pl061_register_devices)
hw/stellaris.c +6 -1
index 38b9830..ba5b11f 100644
@@ -361,6 +361,7 @@ static void stellaris_gptm_init(SysBusDevice *dev)
  /* System controller.  */
 
  typedef struct {
+    SysBusDevice busdev;
     uint32_t pborctl;
     uint32_t ldopctl;
     uint32_t int_status;
@@ -374,8 +375,12 @@ typedef struct {
     uint32_t ldoarst;
     uint32_t user0;
     uint32_t user1;
+    uint32_t did0;
+    uint32_t did1;
+    uint32_t dc[4];
     qemu_irq irq;
-    stellaris_board_info *board;
+    int got_mac;
+    DeviceState *netdev;
  } ssys_state;
 
  static void ssys_update(ssys_state *s)
@@ -421,25 +426,38 @@ static uint32_t pllcfg_fury[16] = {

    0xb11c /* 8.192 Mhz */
 };

hw/stellaris.c +13 -0
+static void ssys_get_mac(ssys_state *s)
+{
+    uint8_t macaddr[6];
+
+    s->got_mac = 1;
+    if (!s->netdev) {
+        return;
+    }
+    qdev_get_macaddr(s->netdev, macaddr);
+    s->user0 = macaddr[0] | (macaddr[1] << 8) | (macaddr[2] << 16);
+    s->user1 = macaddr[3] | (macaddr[4] << 8) | (macaddr[5] << 16);
+}
+

 static uint32_t ssys_read(void *opaque, target_phys_addr_t offset) {
    ssys_state *s = (ssys_state *)opaque;

    switch (offset) {
    case 0x000: /* DID0 */
-        return s->board->did0;
+        return s->did0;
    case 0x004: /* DID1 */
-        return s->board->did1;
+        return s->did1;
    case 0x008: /* DC0 */
-        return s->board->dc0;
+        return s->dc[0];
    case 0x010: /* DC1 */
-        return s->board->dc1;
+        return s->dc[1];
    case 0x014: /* DC2 */
-        return s->board->dc2;
+        return s->dc[2];
    case 0x018: /* DC3 */
-        return s->board->dc3;
+        return s->dc[3];
    case 0x01c: /* DC4 */
-        return s->board->dc4;
+        return s->dc[4];
    case 0x030: /* PBORCTL */
        return s->pborctl;
    case 0x034: /* LDOPCTL */

hw/stellaris.c +1 -1
@@ -464,7 +482,7 @@ static uint32_t ssys_read(void *opaque, target_phys_addr_t offset)
         {
             int xtal;
             xtal = (s->rcc >> 6) & 0xf;
-            if (s->board->did0 & (1 << 16)) {
+            if (s->did0 & (1 << 16)) {
                 return pllcfg_fury[xtal];
             } else {
                 return pllcfg_sandstorm[xtal];
@@ -493,8 +511,14 @@ static uint32_t ssys_read(void *opaque, target_phys_addr_t offset)

    case 0x160: /* LDOARST */
        return s->ldoarst;
    case 0x1e0: /* USER0 */
+        if (!s->got_mac) {
+            ssys_get_mac(s);
+        }
        return s->user0;
    case 0x1e4: /* USER1 */
+        if (!s->got_mac) {
+            ssys_get_mac(s);
+        }
        return s->user1;
    default:
        hw_error("ssys_read: Bad offset 0x%x\n", (int)offset);

hw/stellaris.c +14 -199
@@ -654,23 +678,25 @@ static int ssys_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
  }
 
-static void stellaris_sys_init(uint32_t base, qemu_irq irq,
-                               stellaris_board_info * board,
-                               uint8_t *macaddr)
+static void stellaris_sysctl_init(SysBusDevice *dev)
  {
     int iomemtype;
-    ssys_state *s;
-
-    s = (ssys_state *)qemu_mallocz(sizeof(ssys_state));
-    s->irq = irq;
-    s->board = board;
-    /* Most devices come preprogrammed with a MAC address in the user data. */
-    s->user0 = macaddr[0] | (macaddr[1] << 8) | (macaddr[2] << 16);
-    s->user1 = macaddr[3] | (macaddr[4] << 8) | (macaddr[5] << 16);
+    ssys_state *s = FROM_SYSBUS(ssys_state, dev);
 
     iomemtype = cpu_register_io_memory(0, ssys_readfn,
                                        ssys_writefn, s);
-    cpu_register_physical_memory(base, 0x00001000, iomemtype);
+    sysbus_init_mmio(dev, 0x1000, iomemtype);
+    sysbus_init_irq(dev, &s->irq);
+    s->netdev = qdev_get_prop_dev(&dev->qdev, "enet");
+    s->got_mac = 0;
+    s->did0 = qdev_get_prop_int(&dev->qdev, "did0", 0);
+    s->did1 = qdev_get_prop_int(&dev->qdev, "did1", 0);
+    s->dc[0] = qdev_get_prop_int(&dev->qdev, "dc0", 0);
+    s->dc[1] = qdev_get_prop_int(&dev->qdev, "dc1", 0);
+    s->dc[2] = qdev_get_prop_int(&dev->qdev, "dc2", 0);
+    s->dc[3] = qdev_get_prop_int(&dev->qdev, "dc3", 0);
+    s->dc[4] = qdev_get_prop_int(&dev->qdev, "dc4", 0);
+
     ssys_reset(s);
     register_savevm("stellaris_sys", -1, 1, ssys_save, ssys_load, s);
  }
@@ -1256,200 +1282,30 @@ static void stellaris_ssi_bus_init(SSISlave *dev)
                     stellaris_ssi_bus_save, stellaris_ssi_bus_load, s);
  }
 
-/* Board init.  */
-static stellaris_board_info stellaris_boards[] = {
-  { "LM3S811EVB",
-    0,
-    0x0032000e,
-    0x001f001f, /* dc0 */
-    0x001132bf,
-    0x01071013,
-    0x3f0f01ff,
-    0x0000001f,
-    BP_OLED_I2C
-  },
-  { "LM3S6965EVB",
-    0x10010002,
-    0x1073402e,
-    0x00ff007f, /* dc0 */
-    0x001133ff,
-    0x030f5317,
-    0x0f0f87ff,
-    0x5000007f,
-    BP_OLED_SSI | BP_GAMEPAD
-  }
-};
-
-static void stellaris_init(const char *kernel_filename, const char *cpu_model,
-                           stellaris_board_info *board)
-{
-    static const int uart_irq[] = {5, 6, 33, 34};
-    static const int timer_irq[] = {19, 21, 23, 35};
-    static const uint32_t gpio_addr[7] =
-      { 0x40004000, 0x40005000, 0x40006000, 0x40007000,
-        0x40024000, 0x40025000, 0x40026000};
-    static const int gpio_irq[7] = {0, 1, 2, 3, 4, 30, 31};
-
-    qemu_irq *pic;
-    DeviceState *gpio_dev[7];
-    qemu_irq gpio_in[7][8];
-    qemu_irq gpio_out[7][8];
-    qemu_irq adc;
-    int sram_size;
-    int flash_size;
-    i2c_bus *i2c;
-    DeviceState *dev;
-    int i;
-    int j;
-
-    flash_size = ((board->dc0 & 0xffff) + 1) << 1;
-    sram_size = (board->dc0 >> 18) + 1;
-    pic = armv7m_init(flash_size, sram_size, kernel_filename, cpu_model);
-
-    if (board->dc1 & (1 << 16)) {
-        dev = sysbus_create_varargs("stellaris-adc", 0x40038000,
-                                    pic[14], pic[15], pic[16], pic[17], NULL);
-        adc = qdev_get_gpio_in(dev, 0);
-    } else {
-        adc = NULL;
-    }
-    for (i = 0; i < 4; i++) {
-        if (board->dc2 & (0x10000 << i)) {
-            dev = sysbus_create_simple("stellaris-gptm",
-                                       0x40030000 + i * 0x1000,
-                                       pic[timer_irq[i]]);
-            /* TODO: This is incorrect, but we get away with it because
-               the ADC output is only ever pulsed.  */
-            qdev_connect_gpio_out(dev, 0, adc);
-        }
-    }
-
-    stellaris_sys_init(0x400fe000, pic[28], board, nd_table[0].macaddr);
-
-    for (i = 0; i < 7; i++) {
-        if (board->dc4 & (1 << i)) {
-            gpio_dev[i] = sysbus_create_simple("pl061", gpio_addr[i],
-                                               pic[gpio_irq[i]]);
-            for (j = 0; j < 8; j++) {
-                gpio_in[i][j] = qdev_get_gpio_in(gpio_dev[i], j);
-                gpio_out[i][j] = NULL;
-            }
-        }
-    }
-
-    if (board->dc2 & (1 << 12)) {
-        dev = sysbus_create_simple("stellaris-i2c", 0x40020000, pic[8]);
-        i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c");
-        if (board->peripherals & BP_OLED_I2C) {
-            i2c_create_slave(i2c, "ssd0303", 0x3d);
-        }
-    }
-
-    for (i = 0; i < 4; i++) {
-        if (board->dc2 & (1 << i)) {
-            sysbus_create_simple("pl011_luminary", 0x4000c000 + i * 0x1000,
-                                 pic[uart_irq[i]]);
-        }
-    }
-    if (board->dc2 & (1 << 4)) {
-        dev = sysbus_create_simple("pl022", 0x40008000, pic[7]);
-        if (board->peripherals & BP_OLED_SSI) {
-            DeviceState *mux;
-            void *bus;
-
-            bus = qdev_get_child_bus(dev, "ssi");
-            mux = ssi_create_slave(bus, "evb6965-ssi");
-            gpio_out[GPIO_D][0] = qdev_get_gpio_in(mux, 0);
-
-            bus = qdev_get_child_bus(mux, "ssi0");
-            dev = ssi_create_slave(bus, "ssi-sd");
-
-            bus = qdev_get_child_bus(mux, "ssi1");
-            dev = ssi_create_slave(bus, "ssd0323");
-            gpio_out[GPIO_C][7] = qdev_get_gpio_in(dev, 0);
-
-            /* Make sure the select pin is high.  */
-            qemu_irq_raise(gpio_out[GPIO_D][0]);
-        }
-    }
-    if (board->dc4 & (1 << 28)) {
-        DeviceState *enet;
-
-        qemu_check_nic_model(&nd_table[0], "stellaris");
-
-        enet = qdev_create(NULL, "stellaris_enet");
-        qdev_set_netdev(enet, &nd_table[0]);
-        qdev_init(enet);
-        sysbus_mmio_map(sysbus_from_qdev(enet), 0, 0x40048000);
-        sysbus_connect_irq(sysbus_from_qdev(enet), 0, pic[42]);
-    }
-    if (board->peripherals & BP_GAMEPAD) {
-        qemu_irq gpad_irq[5];
-        static const int gpad_keycode[5] = { 0xc8, 0xd0, 0xcb, 0xcd, 0x1d };
-
-        gpad_irq[0] = qemu_irq_invert(gpio_in[GPIO_E][0]); /* up */
-        gpad_irq[1] = qemu_irq_invert(gpio_in[GPIO_E][1]); /* down */
-        gpad_irq[2] = qemu_irq_invert(gpio_in[GPIO_E][2]); /* left */
-        gpad_irq[3] = qemu_irq_invert(gpio_in[GPIO_E][3]); /* right */
-        gpad_irq[4] = qemu_irq_invert(gpio_in[GPIO_F][1]); /* select */
-
-        stellaris_gamepad_init(5, gpad_irq, gpad_keycode);
-    }
-    for (i = 0; i < 7; i++) {
-        if (board->dc4 & (1 << i)) {
-            for (j = 0; j < 8; j++) {
-                if (gpio_out[i][j]) {
-                    qdev_connect_gpio_out(gpio_dev[i], j, gpio_out[i][j]);
-                }
-            }
-        }
-    }
-}
-
-/* FIXME: Figure out how to generate these from stellaris_boards.  */
-static void lm3s811evb_init(ram_addr_t ram_size,
-                     const char *boot_device,
-                     const char *kernel_filename, const char *kernel_cmdline,
-                     const char *initrd_filename, const char *cpu_model)
-{
-    stellaris_init(kernel_filename, cpu_model, &stellaris_boards[0]);
-}
-
-static void lm3s6965evb_init(ram_addr_t ram_size,
-                     const char *boot_device,
-                     const char *kernel_filename, const char *kernel_cmdline,
-                     const char *initrd_filename, const char *cpu_model)
-{
-    stellaris_init(kernel_filename, cpu_model, &stellaris_boards[1]);
-}
-
-static QEMUMachine lm3s811evb_machine = {
-    .name = "lm3s811evb",
-    .desc = "Stellaris LM3S811EVB",
-    .init = lm3s811evb_init,
-};
-
-static QEMUMachine lm3s6965evb_machine = {
-    .name = "lm3s6965evb",
-    .desc = "Stellaris LM3S6965EVB",
-    .init = lm3s6965evb_init,
-};
-
-static void stellaris_machine_init(void)
-{
-    qemu_register_machine(&lm3s811evb_machine);
-    qemu_register_machine(&lm3s6965evb_machine);
-}
-
-machine_init(stellaris_machine_init);
-
  static SSISlaveInfo stellaris_ssi_bus_info = {
     .init = stellaris_ssi_bus_init,

    .transfer = stellaris_ssi_bus_transfer
 };

hw/stellaris.c +15 -0
+static SysBusDeviceInfo ssys_info = {
+    .init = stellaris_sysctl_init,
+    .qdev.props = (DevicePropList[]) {
+        {.name = "enet", .type = PROP_TYPE_DEV},
+        {.name = "did0", .type = PROP_TYPE_INT},
+        {.name = "did1", .type = PROP_TYPE_INT},
+        {.name = "dc0", .type = PROP_TYPE_INT},
+        {.name = "dc1", .type = PROP_TYPE_INT},
+        {.name = "dc2", .type = PROP_TYPE_INT},
+        {.name = "dc3", .type = PROP_TYPE_INT},
+        {.name = "dc4", .type = PROP_TYPE_INT},
+        {.name = NULL}
+    }
+};
+

 static void stellaris_register_devices(void)
 {
+    sysbus_register_withprop("stellaris-sysctl", sizeof(ssys_state),
+                             &ssys_info); sysbus_register_dev("stellaris-i2c", sizeof(stellaris_i2c_state), stellaris_i2c_init); sysbus_register_dev("stellaris-gptm", sizeof(gptm_state),

hw/stellaris_enet.c +1 -1
index 36fabd3..86df231 100644
@@ -417,7 +417,7 @@ static void stellaris_enet_init(SysBusDevice *dev)
 
  static void stellaris_enet_register_devices(void)
  {
-    sysbus_register_dev("stellaris_enet", sizeof(stellaris_enet_state),
+    sysbus_register_dev("stellaris-enet", sizeof(stellaris_enet_state),
                         stellaris_enet_init);
  }
 
hw/stellaris_input.c deleted +0 -91
deleted file mode 100644
index 33395a4..0000000
@@ -1,91 +0,0 @@
-/*
- * Gamepad style buttons connected to IRQ/GPIO lines
- *
- * Copyright (c) 2007 CodeSourcery.
- * Written by Paul Brook
- *
- * This code is licenced under the GPL.
- */
-#include "hw.h"
-#include "devices.h"
-#include "console.h"
-
-typedef struct {
-    qemu_irq irq;
-    int keycode;
-    int pressed;
-} gamepad_button;
-
-typedef struct {
-    gamepad_button *buttons;
-    int num_buttons;
-    int extension;
-} gamepad_state;
-
-static void stellaris_gamepad_put_key(void * opaque, int keycode)
-{
-    gamepad_state *s = (gamepad_state *)opaque;
-    int i;
-    int down;
-
-    if (keycode == 0xe0 && !s->extension) {
-        s->extension = 0x80;
-        return;
-    }
-
-    down = (keycode & 0x80) == 0;
-    keycode = (keycode & 0x7f) | s->extension;
-
-    for (i = 0; i < s->num_buttons; i++) {
-        if (s->buttons[i].keycode == keycode
-                && s->buttons[i].pressed != down) {
-            s->buttons[i].pressed = down;
-            qemu_set_irq(s->buttons[i].irq, down);
-        }
-    }
-
-    s->extension = 0;
-}
-
-static void stellaris_gamepad_save(QEMUFile *f, void *opaque)
-{
-    gamepad_state *s = (gamepad_state *)opaque;
-    int i;
-
-    qemu_put_be32(f, s->extension);
-    for (i = 0; i < s->num_buttons; i++)
-        qemu_put_byte(f, s->buttons[i].pressed);
-}
-
-static int stellaris_gamepad_load(QEMUFile *f, void *opaque, int version_id)
-{
-    gamepad_state *s = (gamepad_state *)opaque;
-    int i;
-
-    if (version_id != 1)
-        return -EINVAL;
-
-    s->extension = qemu_get_be32(f);
-    for (i = 0; i < s->num_buttons; i++)
-        s->buttons[i].pressed = qemu_get_byte(f);
-
-    return 0;
-}
-
-/* Returns an array 5 ouput slots.  */
-void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode)
-{
-    gamepad_state *s;
-    int i;
-
-    s = (gamepad_state *)qemu_mallocz(sizeof (gamepad_state));
-    s->buttons = (gamepad_button *)qemu_mallocz(n * sizeof (gamepad_button));
-    for (i = 0; i < n; i++) {
-        s->buttons[i].irq = irq[i];
-        s->buttons[i].keycode = keycode[i];
-    }
-    s->num_buttons = n;
-    qemu_add_kbd_event_handler(stellaris_gamepad_put_key, s);
-    register_savevm("stellaris_gamepad", -1, 1,
-                    stellaris_gamepad_save, stellaris_gamepad_load, s);
-}
pc-bios/boards/lm3s6965evb.dts new file +212 -0
new file mode 100644
index 0000000..9bc0128
@@ -0,0 +1,212 @@
+/ {
+    #address-cells = <1>;
+    #size-cells  = <1>;
+
+    cpus {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        cpu0: ARM,Cortex-M3@0 {
+            device_type = "cpu";
+            reg = <0>;
+            #interrupt-cells = <1>;
+            nvic = <&nvic>;
+        };
+    };
+    flash@0 {
+        device_type = "rom";
+        reg = <00000000 00040000>;
+    };
+    memory@0 {
+        device_type = "memory";
+        reg = <20000000 00010000>;
+    };
+    bitband@0 {
+        model = "ARM,bitband-memory";
+        reg = <22000000 02000000>;
+        base = <20000000>;
+    };
+    bitband@1 {
+        model = "ARM,bitband-memory";
+        reg = <42000000 02000000>;
+        base = <40000000>;
+    };
+    nvic: nvic@0 {
+        model = "armv7m_nvic";
+        interrupt-parent = <&cpu0>;
+        interrupts = <0>;
+        interrupt-controller;
+        #interrupt-cells = <1>;
+    };
+    lm3s6965@0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        qemu,fold-bus;
+        // TODO Watchdog at 0x40000000
+        gpioA: gpio@0 {
+            model = "pl061";
+            reg = <40004000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <0>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        gpioB: gpio@1 {
+            model = "pl061";
+            reg = <40005000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <1>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        gpioC: gpio@2 {
+            model = "pl061";
+            reg = <40006000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <2>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 &oled 0>;
+        };
+        gpioD: gpio@3 {
+            model = "pl061";
+            reg = <40007000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <3>;
+            qemu,gpio = <&ssimux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+            float-high = <01>;
+        };
+        ssi@0 {
+            model = "pl022";
+            reg = <40008000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <7>;
+            ssimux: mux@0 {
+                model = "evb6965-ssi";
+                sd@0 {
+                    model = "ssi-sd";
+                    qemu,parent-bus = "ssi0";
+                };
+                oled: oled@1 {
+                    model = "ssd0323";
+                    qemu,parent-bus = "ssi1";
+                };
+            };
+        };
+        uart@0 {
+            model = "luminary,pl011";
+            reg = <4000c000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <5>;
+        };
+        uart@1 {
+            model = "luminary,pl011";
+            reg = <4000d000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <6>;
+        };
+        uart@2 {
+            model = "luminary,pl011";
+            reg = <4000e000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#33>;
+        };
+        i2c@0 {
+            model = "stellaris-i2c";
+            reg = <40020000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <8>;
+        };
+        i2c@1 {
+            model = "stellaris-i2c";
+            reg = <40021000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#37>;
+        };
+        gpioE: gpio@4 {
+            model = "pl061";
+            reg = <40024000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <4>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        gpioF: gpio@5 {
+            model = "pl061";
+            reg = <40025000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#30>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        gpioG: gpio@6 {
+            model = "pl061";
+            reg = <40026000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#31>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        // TODO PWM at 0x40028000
+        // TODO QEI0 at 0x4002c000
+        // TODO QEI1 at 0x4002d000
+        gptm@0 {
+            model = "stellaris-gptm";
+            reg = <40030000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#19>;
+            qemu,gpio = <&adc0 0>;
+        };
+        gptm@1 {
+            model = "stellaris-gptm";
+            reg = <40031000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#21>;
+            qemu,gpio = <&adc0 0>;
+        };
+        gptm@2 {
+            model = "stellaris-gptm";
+            reg = <40032000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#23>;
+            qemu,gpio = <&adc0 0>;
+        };
+        gptm@3 {
+            model = "stellaris-gptm";
+            reg = <40033000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#35>;
+            qemu,gpio = <&adc0 0>;
+        };
+        adc0: adc@0 {
+            model = "stellaris-adc";
+            reg = <40038000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#14 d#15 d#16 d#17>;
+        };
+        // TODO Comparator at 0x4003c000
+        enet: enet@0 {
+            model = "stellaris-enet";
+            reg = <40048000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#42>;
+        };
+        // TODO Hybernation module at 0x400fc000
+        sysctl@0 {
+            model = "stellaris-sysctl";
+            reg = <400fe000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#28>;
+            did0 = <10010002>;
+            did1 = <1073402e>;
+            dc0 = <00ff007f>;
+            dc1 = <001133ff>;
+            dc2 = <030f5317>;
+            dc3 = <0f0f87ff>;
+            dc4 = <5000007f>;
+            enet = <&enet>;
+        };
+        buttons@0 {
+            model = "qemu,gpio-buttons";
+            keys = <800000c8 800000d0 800000cb 800000cd 8000001d>;
+            qemu,gpio = <&gpioE 0 &gpioE 1 &gpioE 2 &gpioE 3 &gpioF 1>;
+        };
+    };
+    chosen {
+        qemu {
+            bootstrap = "ARMv7-M";
+        };
+    };
+};
pc-bios/boards/lm3s811evb.dts new file +155 -0
new file mode 100644
index 0000000..977d080
@@ -0,0 +1,155 @@
+/ {
+    #address-cells = <1>;
+    #size-cells  = <1>;
+
+    cpus {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        cpu0: ARM,Cortex-M3@0 {
+            device_type = "cpu";
+            reg = <0>;
+            #interrupt-cells = <1>;
+            nvic = <&nvic>;
+        };
+    };
+    flash@0 {
+        device_type = "rom";
+        reg = <00000000 00010000>;
+    };
+    memory@0 {
+        device_type = "memory";
+        reg = <20000000 00002000>;
+    };
+    bitband@0 {
+        model = "ARM,bitband-memory";
+        reg = <22000000 02000000>;
+        base = <20000000>;
+    };
+    bitband@1 {
+        model = "ARM,bitband-memory";
+        reg = <42000000 02000000>;
+        base = <40000000>;
+    };
+    nvic: nvic@0 {
+        model = "armv7m_nvic";
+        interrupt-parent = <&cpu0>;
+        interrupts = <0>;
+        interrupt-controller;
+        #interrupt-cells = <1>;
+    };
+    lm3s811@0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        qemu,fold-bus;
+        // TODO Watchdog at 0x40000000
+        gpioA: gpio@0 {
+            model = "pl061";
+            reg = <40004000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <0>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        gpioB: gpio@1 {
+            model = "pl061";
+            reg = <40005000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <1>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        gpioC: gpio@2 {
+            model = "pl061";
+            reg = <40006000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <2>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        gpioD: gpio@3 {
+            model = "pl061";
+            reg = <40007000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <3>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        ssi@0 {
+            model = "pl022";
+            reg = <40008000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <7>;
+        };
+        uart@0 {
+            model = "luminary,pl011";
+            reg = <4000c000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <5>;
+        };
+        uart@1 {
+            model = "luminary,pl011";
+            reg = <4000d000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <6>;
+        };
+        i2c@0 {
+            model = "stellaris-i2c";
+            reg = <40020000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <8>;
+            oled@0 {
+                model = "ssd0303";
+                address = <3d>;
+            };
+        };
+        gpioE: gpio@4 {
+            model = "pl061";
+            reg = <40024000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <4>;
+            qemu,gpio = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
+        };
+        // TODO PWM at 0x40028000
+        gptm@0 {
+            model = "stellaris-gptm";
+            reg = <40030000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#19>;
+            qemu,gpio = <&adc0 0>;
+        };
+        gptm@1 {
+            model = "stellaris-gptm";
+            reg = <40031000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#21>;
+            qemu,gpio = <&adc0 0>;
+        };
+        gptm@2 {
+            model = "stellaris-gptm";
+            reg = <40032000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#23>;
+            qemu,gpio = <&adc0 0>;
+        };
+        adc0: adc@0 {
+            model = "stellaris-adc";
+            reg = <40038000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#14 d#15 d#16 d#17>;
+        };
+        sysctl@0 {
+            model = "stellaris-sysctl";
+            reg = <400fe000>;
+            interrupt-parent = <&nvic>;
+            interrupts = <d#28>;
+            did0 = <00000000>;
+            did1 = <0032000e>;
+            dc0 = <001f001f>;
+            dc1 = <001132bf>;
+            dc2 = <01071013>;
+            dc3 = <3f0f01ff>;
+            dc4 = <0000001f>;
+        };
+    };
+    chosen {
+        qemu {
+            bootstrap = "ARMv7-M";
+        };
+    };
+};
#19 lore raw

Re: [Qemu-devel] [PATCH 3/4] Stellaris machine config

Quoted 3 lines · M P

So now, with qdev, it's all official, /every value, constant, and bitfield/ is hard coded, in hex, into a different non-code file, with no way of derivating or overloading from.

[...]

Quoted 3 lines

In fact,
the stellaris share /a lot/ between themselves, and there is not a single shared line between your two stellaris boards definition file.

This is a good point.

I guess FDT is missing a "#include" equivalent, and possibly name constants.

That isn't surprising given FDT's original use, to pass an entire machine description to a running kernel.

But for QEMU, some way to give names to, say, a standard SoC or a basic board, or a PC without peripherals, and then refer to them in another FDT tree, would be useful.

Whether it's done in QEMU itself or by preprocessing doesn't matter. Preprocessing would have the advantage that it would output FDTs that could, maybe, be passed to the guest kernel and just work. Or maybe QEMU can have a tree preprocessor built in.

-- Jamie

#20 lore raw

Re: [Qemu-devel] [PATCH 3/4] Stellaris machine config

Quoted 2 lines

I guess FDT is missing a "#include" equivalent, and possibly name constants.

See: http://git.jdl.com/gitweb/?p=dtc.git;a=blob;f=Documentation/manual.txt;h=f8a8a7b482e3a2a1501614c94fa0ea87aeb3a9e7;hb=HEAD

There is:

/include/ "filename"

Quoted 3 lines

But for QEMU, some way to give names to, say, a standard SoC or a basic board, or a PC without peripherals, and then refer to them in another FDT tree, would be useful.

Yes, that must be solved somehow. Just punting the issue to the vm management software isn't acceptable IMHO.

I'm not sure includes will solve that issue. What we need is more a tree merge, i.e. you could have basic config files for a few pc variants without devices (i.e. isapc, pc) and config files snippets for devices (ide interface foo, sound card bar, ...). Then you need some way to merge the latter into the former.

Even that solves only a part of the problem. For some options you effectively have to edit the device tree:

-m <mem>
You have edit memory@0 node. You even might have to add a node depending on the amount of memory (i.e. one for the memory below 4G one for the memory above ...).

-cpu <cpu>
You have to edit the cpu node.

-smp <n>
You have to insert cpu nodes.

cheers,
Gerd

#21 lore raw

Re: [Qemu-devel] [PATCH 3/4] Stellaris machine config

Quoted 37 lines · Gerd Hoffmann
Quoted 2 lines

I guess FDT is missing a "#include" equivalent, and possibly name constants.

See:
http://git.jdl.com/gitweb/?p=dtc.git;a=blob;f=Documentation/manual.txt;h=f8a8a7b482e3a2a1501614c94fa0ea87aeb3a9e7;hb=HEAD

There is:

/include/ "filename"

Quoted 3 lines

But for QEMU, some way to give names to, say, a standard SoC or a basic board, or a PC without peripherals, and then refer to them in another FDT tree, would be useful.

Yes, that must be solved somehow. Just punting the issue to the vm management software isn't acceptable IMHO.

I'm not sure includes will solve that issue. What we need is more a tree merge, i.e. you could have basic config files for a few pc variants without devices (i.e. isapc, pc) and config files snippets for devices (ide interface foo, sound card bar, ...). Then you need some way to merge the latter into the former.

Even that solves only a part of the problem. For some options you effectively have to edit the device tree:

(quoted diff) +0 -3
-m <mem>
  You have edit memory@0 node.  You even might have to add a node
  depending on the amount of memory (i.e. one for the memory below
  4G one for the memory above ...).
 
-cpu <cpu>
  You have to edit the cpu node.
 
-smp <n>
  You have to insert cpu nodes.
Quoted 2 lines

cheers,
Gerd

For what it's worth, that's how my prototype worked. Start with a minimal, fixed tree for the machine type, then edit it according to options.

#22 lore raw

Re: [Qemu-devel] [PATCH 3/4] Stellaris machine config

In reply to Jamie Lokier
Quoted 21 lines · Jamie Lokier
Quoted 3 lines · M P

So now, with qdev, it's all official, /every value, constant, and bitfield/ is hard coded, in hex, into a different non-code file, with no way of derivating or overloading from.

[...]

Quoted 3 lines

In fact,
the stellaris share /a lot/ between themselves, and there is not a single shared line between your two stellaris boards definition file.

This is a good point.

I guess FDT is missing a "#include" equivalent, and possibly name constants.

That isn't surprising given FDT's original use, to pass an entire machine description to a running kernel.

But for QEMU, some way to give names to, say, a standard SoC or a basic board, or a PC without peripherals, and then refer to them in another FDT tree, would be useful.

Quoted 6 lines

Whether it's done in QEMU itself or by preprocessing doesn't matter. Preprocessing would have the advantage that it would output FDTs that could, maybe, be passed to the guest kernel and just work. Or maybe QEMU can have a tree preprocessor built in.

-- Jamie

The need for an FDT to pass to the kernel doesn't dictate that we must use it as configuration file. FDT could be generated from the internal machine description.

#23 lore raw

Re: [Qemu-devel] [PATCH 3/4] Stellaris machine config

Quoted 3 lines · Markus Armbruster

The need for an FDT to pass to the kernel doesn't dictate that we must use it as configuration file. FDT could be generated from the internal machine description.

I agree and that might be nicer in the end, if FDTs turn out to be an inconvenient representation of QEMU devices.

I would not be surprised if we start with FDTs, and then gradually modify the FDT code to get "QEMU FDTs", and eventually evolve to something everyone likes :-)

-- Jamie

author
#24 lore raw

PATCH 4/4 Integrator machine config

In reply to Paul Brook

Replace integrator board with machine config

---

 Makefile                         |    2 -
 hw/arm_timer.c                   |    2 -
 hw/integratorcp.c                |   97 ++++------------------------------
 pc-bios/boards/integrator-cp.dts |  110 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 124 insertions(+), 87 deletions(-)
 create mode 100644 pc-bios/boards/integrator-cp.dts
Makefile +1 -1
index 48a3ec3..5cc346e 100644
@@ -46,7 +46,7 @@ endif
 #######################################################################
 # Board descriptions
 
-BOARDS = syborg lm3s811evb lm3s6965evb
+BOARDS = syborg lm3s811evb lm3s6965evb integrator-cp
 
 ifdef DTC
 BOARDS_BIN = $(BOARDS:%=pc-bios/boards/%.dtb)
hw/arm_timer.c +1 -1
index 226ecc4..6570929 100644
@@ -347,7 +347,7 @@ static void icp_pit_init(SysBusDevice *dev)
 
 static void arm_timer_register_devices(void)
 {
-    sysbus_register_dev("integrator_pit", sizeof(icp_pit_state), icp_pit_init);
+    sysbus_register_dev("integrator-pit", sizeof(icp_pit_state), icp_pit_init);
     sysbus_register_dev("sp804", sizeof(sp804_state), sp804_init);
 }
 
hw/integratorcp.c +12 -85

116 lines not on this page · raw message

pc-bios/boards/integrator-cp.dts new file +110 -0

110 lines not on this page · raw message

#25 lore raw
In reply to Paul Brook
Quoted 1 line

Also available from git://repo.or.cz/qemu/pbrook.git devtree

Doesn't build:

In file included from /home/kraxel/projects/qemu/osdep.c:40,
from /home/kraxel/projects/qemu/tool-osdep.c:3:
./config-host.h:25:2: error: invalid preprocessing directive #defne

zweiblum kraxel ~/projects/qemu (devtree)# grep "#defne" configure
echo "#defne HAVE_PREADV 1" >> $config_h

Huh? Doesn't look intentional ...

cheers,
Gerd

#26 lore raw
In reply to Paul Brook
Quoted 2 lines · Paul Brook

The following series implements machine config files, and adds converts some of the existing hardcoded machines.

Hmm. The converted machine types have a pretty static configuration, i.e. where you don't need to specify more that just "-M type" on the command line.

What is the plan for machines which can be configured in alot of different ways such as a typical PC? Where you can configure lots of details such as cpu, memory, nic, disk drives, ... using command line options?

What is the plan for linking host and guest devices (i.e. hook up nics to vlans, connect disks to blkdrvstates, ...)? Right now qdev_get_macaddr() does it in a hackish way with a bold FIXME ...

Quoted 3 lines

The config files themselves are based on the ppc-linux Flattened Device Trees. In generaly I've tried to structure things so that the same config file can be used for both qemu and linux.

Is there Documentation (other than source code) for libftd? Do you have a pointer for me?

Guess I have to dive into the libftd to get a more clear picture how all this is supposed to work together ...

cheers,
Gerd

author
#27 lore raw
Quoted 4 lines · Gerd Hoffmann
Quoted 2 lines · Paul Brook

The following series implements machine config files, and adds converts some of the existing hardcoded machines.

Quoted 8 lines

Hmm. The converted machine types have a pretty static configuration, i.e. where you don't need to specify more that just "-M type" on the command line.

What is the plan for machines which can be configured in alot of different ways such as a typical PC? Where you can configure lots of details such as cpu, memory, nic, disk drives, ... using command line options?

I don't believe most of these things should be configured by commandline options. It's only done that way because we don't have any alternative (i.e. a machine config file). If you really want full control, I expect your VM manager will generate the machine config for you.

Quoted 3 lines

What is the plan for linking host and guest devices (i.e. hook up nics to vlans, connect disks to blkdrvstates, ...)? Right now qdev_get_macaddr() does it in a hackish way with a bold FIXME ...

Probably identifying things by name.

As I've said before, I think it's good to isolate machine configuration (what hardware to emulate) and host configuration (image location, vlans, etc). The details are going to depend how we end up doing the host configuration bits.

Quoted 6 lines
Quoted 3 lines

The config files themselves are based on the ppc-linux Flattened Device Trees. In generaly I've tried to structure things so that the same config file can be used for both qemu and linux.

Is there Documentation (other than source code) for libftd? Do you have a pointer for me?

git://www.jdl.com/software/dtc.git

Paul

#28 lore raw
Quoted 10 lines · Paul Brook
Quoted 4 lines · Gerd Hoffmann

What is the plan for machines which can be configured in alot of different ways such as a typical PC? Where you can configure lots of details such as cpu, memory, nic, disk drives, ... using command line options?

I don't believe most of these things should be configured by commandline options. It's only done that way because we don't have any alternative (i.e. a machine config file). If you really want full control, I expect your VM manager will generate the machine config for you.

Not supporting command line options isn't going to fly. While VM managers probably can and will generate config files, not everybody uses management software. And having to hack the dts and run it through the dtc doesn't look like a reasonable solution for users to me.

Also currently qemu lacks an option to specify such dt directly.

Quoted 8 lines
Quoted 3 lines

What is the plan for linking host and guest devices (i.e. hook up nics to vlans, connect disks to blkdrvstates, ...)? Right now qdev_get_macaddr() does it in a hackish way with a bold FIXME ...

Probably identifying things by name.

As I've said before, I think it's good to isolate machine configuration (what hardware to emulate) and host configuration (image location, vlans, etc).

Sure. You still have to link them.

Quoted 2 lines

The
details are going to depend how we end up doing the host configuration bits.

Ok, sounds like there isn't (yet) a plan.

Quoted 1 line

git://www.jdl.com/software/dtc.git

Thanks.

cheers,
Gerd

#29 lore raw
In reply to Paul Brook
Quoted 13 lines · Paul Brook
Quoted 11 lines · Gerd Hoffmann
Quoted 2 lines · Paul Brook

The following series implements machine config files, and adds converts some of the existing hardcoded machines.

Hmm. The converted machine types have a pretty static configuration, i.e. where you don't need to specify more that just "-M type" on the command line.

What is the plan for machines which can be configured in alot of different ways such as a typical PC? Where you can configure lots of details such as cpu, memory, nic, disk drives, ... using command line options?

Quoted 6 lines

I don't believe most of these things should be configured by commandline options. It's only done that way because we don't have any alternative (i.e. a machine config file). If you really want full control, I expect your VM manager will generate the machine config for you.

From my perspective as a qemu user, I definitely don't want to miss the

command line options. Not having to create configuration files is exactly what gave me the "just works" feeling when I started using qemu. And I really don't plan to use management tools in future.

Kevin

#30 lore raw
Quoted 19 lines · Kevin Wolf
Quoted 17 lines · Paul Brook
Quoted 11 lines · Gerd Hoffmann
Quoted 2 lines · Paul Brook

The following series implements machine config files, and adds converts some of the existing hardcoded machines.

Hmm. The converted machine types have a pretty static configuration, i.e. where you don't need to specify more that just "-M type" on the command line.

What is the plan for machines which can be configured in alot of different ways such as a typical PC? Where you can configure lots of details such as cpu, memory, nic, disk drives, ... using command line options?

I don't believe most of these things should be configured by commandline options. It's only done that way because we don't have any alternative (i.e. a machine config file). If you really want full control, I expect your VM manager will generate the machine config for you.

Quoted 6 lines
Quoted 1 line

From my perspective as a qemu user, I definitely don't want to miss the

command line options. Not having to create configuration files is exactly what gave me the "just works" feeling when I started using qemu. And I really don't plan to use management tools in future.

Kevin

I understand where you come from. For me, configuration files are fine. What I don't want is having to copy a lengthy configuration file just to add a device. Because that leads to zillions of copies with little differences here and there, and much diffing and merging on upgrade.

#31 lore raw
Quoted 20 lines · Markus Armbruster
Quoted 18 lines · Kevin Wolf
Quoted 17 lines · Paul Brook
Quoted 11 lines · Gerd Hoffmann
Quoted 2 lines · Paul Brook

The following series implements machine config files, and adds converts some of the existing hardcoded machines.

Hmm. The converted machine types have a pretty static configuration, i.e. where you don't need to specify more that just "-M type" on the command line.

What is the plan for machines which can be configured in alot of different ways such as a typical PC? Where you can configure lots of details such as cpu, memory, nic, disk drives, ... using command line options?

I don't believe most of these things should be configured by commandline options. It's only done that way because we don't have any alternative (i.e. a machine config file). If you really want full control, I expect your VM manager will generate the machine config for you.
From my perspective as a qemu user, I definitely don't want to miss the

Quoted 5 lines
Quoted 3 lines

command line options. Not having to create configuration files is exactly what gave me the "just works" feeling when I started using qemu. And I really don't plan to use management tools in future.

I understand where you come from. For me, configuration files are fine.

Don't get me wrong, I'm not against configuration files. Having them is great and probably I'd even find some uses for them occasionally. I just don't want to be _forced_ to use them which I fear is what Paul is talking about.

Quoted 3 lines

What I don't want is having to copy a lengthy configuration file just to add a device. Because that leads to zillions of copies with little differences here and there, and much diffing and merging on upgrade.

Sure, couldn't agree more, but this is a different story. The solution for my problem is to retain command line options, the solution for your problem is some mechanism to have a config that adds devices to an existing base config (or changes options, removes devices, whatever).

Probably my command line switches would use the same mechanism internally, but I don't really care. I'm just a random qemu user in this discussion. ;-)

Kevin

#32 lore raw
Quoted 32 lines · Kevin Wolf
Quoted 20 lines · Markus Armbruster
Quoted 18 lines · Kevin Wolf
Quoted 17 lines · Paul Brook
Quoted 11 lines · Gerd Hoffmann
Quoted 2 lines · Paul Brook

The following series implements machine config files, and adds converts some of the existing hardcoded machines.

Hmm. The converted machine types have a pretty static configuration, i.e. where you don't need to specify more that just "-M type" on the command line.

What is the plan for machines which can be configured in alot of different ways such as a typical PC? Where you can configure lots of details such as cpu, memory, nic, disk drives, ... using command line options?

I don't believe most of these things should be configured by commandline options. It's only done that way because we don't have any alternative (i.e. a machine config file). If you really want full control, I expect your VM manager will generate the machine config for you.
From my perspective as a qemu user, I definitely don't want to miss the

Quoted 5 lines
Quoted 3 lines

command line options. Not having to create configuration files is exactly what gave me the "just works" feeling when I started using qemu. And I really don't plan to use management tools in future.

I understand where you come from. For me, configuration files are fine.

Don't get me wrong, I'm not against configuration files. Having them is great and probably I'd even find some uses for them occasionally. I just don't want to be _forced_ to use them which I fear is what Paul is talking about.

Quoted 5 lines
Quoted 3 lines

What I don't want is having to copy a lengthy configuration file just to add a device. Because that leads to zillions of copies with little differences here and there, and much diffing and merging on upgrade.

Sure, couldn't agree more, but this is a different story. The solution

It is a different story, and I consider both stories valid.

Quoted 7 lines

for my problem is to retain command line options, the solution for your problem is some mechanism to have a config that adds devices to an existing base config (or changes options, removes devices, whatever).

Probably my command line switches would use the same mechanism internally, but I don't really care. I'm just a random qemu user in this discussion. ;-)

Yes, it would be nice if monitor commands, command line options and configuration file directives to add devices were all frontends to the same code.

#33 lore raw
In reply to Kevin Wolf
Quoted 7 lines · Kevin Wolf

Markus Armbruster schrieb:

Don't get me wrong, I'm not against configuration files. Having them is great and probably I'd even find some uses for them occasionally. I just don't want to be _forced_ to use them which I fear is what Paul is talking about.

What we need is a command line option that can be used to manipulate a device tree. All of the existing options could then be implemented in terms of the former option.

There will probably be a lot of things in the future that you can only do via device tree manipulation. I don't see any reason why not to add convenient syntax though for the most common things.

Regards,

Anthony Liguori

#34 lore raw
Quoted 9 lines · Anthony Liguori
Quoted 7 lines · Kevin Wolf

Markus Armbruster schrieb:

Don't get me wrong, I'm not against configuration files. Having them is great and probably I'd even find some uses for them occasionally. I just don't want to be _forced_ to use them which I fear is what Paul is talking about.

Quoted 3 lines

What we need is a command line option that can be used to manipulate a device tree. All of the existing options could then be implemented in terms of the former option.

I like this idea of a generic device tree manipulation option. Could come in handy for small ad-hoc modifications to the default config.

Quoted 3 lines

There will probably be a lot of things in the future that you can only do via device tree manipulation. I don't see any reason why not to add convenient syntax though for the most common things.

Having to use the generic option or a config file for the more obscure things is absolutely fine with me as long as I can still change the memory size, network cards and so on using the existing (more or less obvious) options.

Kevin

#35 lore raw
In reply to Anthony Liguori
Quoted 10 lines · Anthony Liguori
Quoted 7 lines · Kevin Wolf

Markus Armbruster schrieb:
Don't get me wrong, I'm not against configuration files. Having them is
great and probably I'd even find some uses for them occasionally. I just don't want to be _forced_ to use them which I fear is what Paul is talking about.

Quoted 7 lines

What we need is a command line option that can be used to manipulate a
device tree. All of the existing options could then be implemented in terms of the former option.

There will probably be a lot of things in the future that you can only do
via device tree manipulation. I don't see any reason why not to add convenient syntax though for the most common things.

-fdt_change /cpus/cpu@0/clock-frequency 0x20000000 -fdt_delete /plb/obp/serial@ef600400
-fdt_add /plb/obp/serial@ef600500 serial (this is complicated)

But I fear we would be replicating basic awk functionality.

An external tool for manipulating the tree may still be useful.

#36 lore raw
In reply to Paul Brook
Quoted 6 lines · Paul Brook

The following series implements machine config files, and adds converts some of the existing hardcoded machines.

The config files themselves are based on the ppc-linux Flattened Device Trees. In generaly I've tried to structure things so that the same config file can be used for both qemu and linux.

This means the configuration file is binary.

It can be compiled from source with dtc, which doesn't seem to be included in the patch series. The language accepted by dtc is pretty
low-level: it talks NUL-terminates strings, byte strings and arrays of "cells" (32 bit integers).

This leaves compiling from configuration concepts like "physical address range", "interrupt" and so forth to FDT concepts like "array of cell" to the user.

For instance, to specify an physical address range of 0x7f00000 bytes starting at 0x100000, you say

    #address-cells = <1>;
    #size-cells  = <1>;
    reg = <0x100000 0x7f00000>

except when you're dealing with 64 bit physical address space, where it becomes

    #address-cells = <2>;
    #size-cells  = <2>;
    reg = <0 0x100000 0 0x7f00000>

Not sure I got the endianess right.

To specify 8 bytes of ISA I/O space starting at 0x3f8, you say

    #address-cells = <2>;
    #size-cells = <1>;
    reg = <1 0x000002f8 0x00000008>;

The "1" in there means I/O space. It's defined in the IEEE 1275 binding document for ISA.

To specify ISA interrupt 4, you do:

    #interrupt-cells = <2>;
    interrupts = <4 3>;

The "3" encodes the interrupt type (level vs. edge; can't be bothered to look up the number right now).

The various PCI addresses are "fun", too, and covered by their own binding document.

Is that really what we want for a configuration file?

[...]

#37 lore raw
Quoted 4 lines · Markus Armbruster

It can be compiled from source with dtc, which doesn't seem to be included in the patch series. The language accepted by dtc is pretty
low-level: it talks NUL-terminates strings, byte strings and arrays of "cells" (32 bit integers).

[ a bunch of examples snipped ]

Quoted 1 line

Is that really what we want for a configuration file?

I do see a point in using fdt as qemu-internal representation. ppc needs it anyway. It is also a nice way to store the guest configuration for save/load and migration, you can just send the blob over the wire. And we can hide the details such as cells behind some nifty helper functions.

Qemu users should not be required to be fdt experts though. We need another, more user-friendly interface to configure virtual machines.

libfdt has functions to modify the device tree. I think we will need them to keep the fdt in sync with the machine configuration when hot-plugging in and out devices (otherwise the fdt is useless for migration). So when we have code to handle the fdt updates triggered by the "drive_add ..." monitor command anyway, also handling the -drive command line switch (or the same input from a more userfriendly machine config file) should be easy.

cheers,
Gerd

#38 lore raw
Quoted 11 lines · Gerd Hoffmann
Quoted 4 lines · Markus Armbruster

It can be compiled from source with dtc, which doesn't seem to be included in the patch series. The language accepted by dtc is pretty
low-level: it talks NUL-terminates strings, byte strings and arrays of "cells" (32 bit integers).

[ a bunch of examples snipped ]

Quoted 1 line

Is that really what we want for a configuration file?

I do see a point in using fdt as qemu-internal representation.

I was talking about configuration file usability. Internal representation is a different matter.

Quoted 2 lines

ppc
needs it anyway.

Could be generated from whatever internal representation we use.

Quoted 4 lines

It is also a nice way to store the guest
configuration for save/load and migration, you can just send the blob over the wire. And we can hide the details such as cells behind some nifty helper functions.

I agree we need the tree flattened to send it to disk or over the wire. Keeping it flattened all the time could make certain tree editing jobs more cumbersome. We'll see.

Quoted 2 lines

Qemu users should not be required to be fdt experts though. We need another, more user-friendly interface to configure virtual machines.

Yup.

[...]

#39 lore raw
In reply to Gerd Hoffmann
Quoted 19 lines · Gerd Hoffmann
Quoted 4 lines · Markus Armbruster

It can be compiled from source with dtc, which doesn't seem to be included in the patch series. The language accepted by dtc is pretty
low-level: it talks NUL-terminates strings, byte strings and arrays of "cells" (32 bit integers).

[ a bunch of examples snipped ]

Quoted 1 line

Is that really what we want for a configuration file?

I do see a point in using fdt as qemu-internal representation. ppc needs it anyway. It is also a nice way to store the guest configuration for save/load and migration, you can just send the blob over the wire. And we can hide the details such as cells behind some nifty helper functions.

Qemu users should not be required to be fdt experts though. We need another, more user-friendly interface to configure virtual machines.

Quoted 7 lines

libfdt has functions to modify the device tree. I think we will need them to keep the fdt in sync with the machine configuration when hot-plugging in and out devices (otherwise the fdt is useless for migration). So when we have code to handle the fdt updates triggered by the "drive_add ..." monitor command anyway, also handling the -drive command line switch (or the same input from a more userfriendly machine config file) should be easy.

And if you factor out that code so that a stand-alone tool, say 'qemu-config' could use it too, you would have a way to generate such
files: Simply pass the well-known command line switches to that tool and let it generate the corresponding config file for you. That file could then be stuffed into qemu on startup again, maybe temporarily customized by additional command line switches. Of course, the qemu-config tool could also read existing configs and modify them according to the specified wishes.

Not having thought too much about this whole topic, such a path sounds quite handy for me, specifically as I do not use fancy front-ends for daily work either.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#40 lore raw
Quoted 37 lines · Jan Kiszka
Quoted 19 lines · Gerd Hoffmann
Quoted 4 lines · Markus Armbruster

It can be compiled from source with dtc, which doesn't seem to be included in the patch series. The language accepted by dtc is pretty
low-level: it talks NUL-terminates strings, byte strings and arrays of "cells" (32 bit integers).

[ a bunch of examples snipped ]

Quoted 1 line

Is that really what we want for a configuration file?

I do see a point in using fdt as qemu-internal representation. ppc needs it anyway. It is also a nice way to store the guest configuration for save/load and migration, you can just send the blob over the wire. And we can hide the details such as cells behind some nifty helper functions.

Qemu users should not be required to be fdt experts though. We need another, more user-friendly interface to configure virtual machines.

Quoted 7 lines

libfdt has functions to modify the device tree. I think we will need them to keep the fdt in sync with the machine configuration when hot-plugging in and out devices (otherwise the fdt is useless for migration). So when we have code to handle the fdt updates triggered by the "drive_add ..." monitor command anyway, also handling the -drive command line switch (or the same input from a more userfriendly machine config file) should be easy.

And if you factor out that code so that a stand-alone tool, say 'qemu-config' could use it too, you would have a way to generate such
files: Simply pass the well-known command line switches to that tool and let it generate the corresponding config file for you. That file could then be stuffed into qemu on startup again, maybe temporarily customized by additional command line switches. Of course, the qemu-config tool could also read existing configs and modify them according to the specified wishes.

Quoted 5 lines

Not having thought too much about this whole topic, such a path sounds quite handy for me, specifically as I do not use fancy front-ends for daily work either.

Jan

Can't we extend loadvm/savevm format to support machine config? It is already supported by all devices, it seems that we just need to add some detail such as pci addresses, and qemu flags to save/load this config. No?

Signature · 1 line
MST
#41 lore raw
Quoted 5 lines · Michael S. Tsirkin

On Fri, Jun 12, 2009 at 06:11:24PM +0200, Jan Kiszka wrote:
Can't we extend loadvm/savevm format to support machine config? It is already supported by all devices, it seems that we just need to add some detail such as pci addresses, and qemu flags to save/load this config. No?

No. Adding some info to the devices doesn't cut it as you also need to know which devices are present in the first place. Current savevm doesn't do that, thats why you have to start the virtual machine with the complete set of command line arguments even when resuming / migrating. Once we have a working device tree implementation we can fix that too though. Rough plan is:

(1) convert drivers to qdev.
(2) create qdev device tree from config file (probably fdt).

With this in place it is just a little step to also carry this in the savevm format: We just need a to do a qdev->fdt conversion, then we can send the device tree as one savevm section and rebuild the vm from that.

cheers,
Gerd

#42 lore raw
Quoted 9 lines · Gerd Hoffmann
Quoted 5 lines · Michael S. Tsirkin

On Fri, Jun 12, 2009 at 06:11:24PM +0200, Jan Kiszka wrote:
Can't we extend loadvm/savevm format to support machine config? It is already supported by all devices, it seems that we just need to add some detail such as pci addresses, and qemu flags to save/load this config. No?

No. Adding some info to the devices doesn't cut it as you also need to know which devices are present in the first place.

Actually at least for pci devices you have the devid/vendor id register - from this you can know which devices are present.

Quoted 15 lines

Current savevm
doesn't do that, thats why you have to start the virtual machine with the complete set of command line arguments even when resuming / migrating. Once we have a working device tree implementation we can fix that too though. Rough plan is:

(1) convert drivers to qdev.
(2) create qdev device tree from config file (probably fdt).

With this in place it is just a little step to also carry this in the savevm format: We just need a to do a qdev->fdt conversion, then we can send the device tree as one savevm section and rebuild the vm from that.

cheers,
Gerd

#43 lore raw
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Gerd Hoffmann
Quoted 5 lines · Michael S. Tsirkin

On Fri, Jun 12, 2009 at 06:11:24PM +0200, Jan Kiszka wrote:
Can't we extend loadvm/savevm format to support machine config? It is already supported by all devices, it seems that we just need to add some detail such as pci addresses, and qemu flags to save/load this config. No?

Quoted 10 lines
Quoted 2 lines

No. Adding some info to the devices doesn't cut it as you also need to know which devices are present in the first place.

Actually at least for pci devices you have the devid/vendor id register - from this you can know which devices are present.

Quoted 4 lines

Current savevm
doesn't do that, thats why you have to start the virtual machine with the complete set of command line arguments even when resuming / migrating.

It seems that it'd be trivial to solve this just by adding a fixed size header telling you which load function to call. No?

Quoted 12 lines
Quoted 12 lines

Once we have a working device tree implementation we can fix
that too though. Rough plan is:

(1) convert drivers to qdev.
(2) create qdev device tree from config file (probably fdt).

With this in place it is just a little step to also carry this in the savevm format: We just need a to do a qdev->fdt conversion, then we can send the device tree as one savevm section and rebuild the vm from that.

cheers,
Gerd

#44 lore raw
Quoted 7 lines · Michael S. Tsirkin
Quoted 4 lines
Quoted 4 lines

Current savevm
doesn't do that, thats why you have to start the virtual machine with the complete set of command line arguments even when resuming / migrating.

It seems that it'd be trivial to solve this just by adding a fixed size header telling you which load function to call. No?

No. Go read the code.

User adds -somedev params,more=options to the command line. Qemu asks the corresponding driver to creates a device instance. Every device instance registers loadvm/savevm callbacks to load/save state (tagged with name + instance id).

When loading vm state qemu will see name + instance id. There is no way to figure the actual driver from that.

Additionall issue: There is no standardized way to create a device instance. This one will be fixed by qdev though.

It might make sense to integrate savevm callbacks into qdev, then you'd have actually a chance to figure which driver belongs to your piece of savevm state. I suspect it isn't enougth to make it work though, you still need to know the position of the device in the device tree. To answer questions like "is your pci device behind a bridge and if so which one?".

cheers,
Gerd

#45 lore raw
Quoted 1 line · Gerd Hoffmann

It might make sense to integrate savevm callbacks into qdev, then you'd have actually a chance to figure which driver belongs to your piece of savevm state.

That's my preference. The very first pass iterates the device tree and serializes it.

Quoted 1 line

I suspect it isn't enougth to make it work though, you still need to know the position of the device in the device tree. To answer questions like "is your pci device behind a bridge and if so which one?".

Isn't that info provided by qdev? qdev will walk the pci bus, note there's a bridge, walk the bridged pci bus, note there's a usb controller, walk the usb bus, note there's a usb-scsi controller, walk the scsi bus, ... (ran out of steam).

Signature · 1 line
error compiling committee.c: too many arguments to function
#46 lore raw
Quoted 7 lines · Avi Kivity
Quoted 3 lines · Gerd Hoffmann

It might make sense to integrate savevm callbacks into qdev, then you'd have actually a chance to figure which driver belongs to your piece of savevm state.

That's my preference. The very first pass iterates the device tree and serializes it.

Sure, needs to happen.

I meant something else though: Instead of having the drivers call register_savevm() in there init functions add section name and savevm/loadvm function pointers to qdevs DeviceInfo. That will add the missing link section name -> driver. That alone will *not* provide the position in the device tree though. And I suspect making the transition without breaking backward compatibility could be quite tricky too. So I'm not sure how useful that actually is, although it surely would be much cleaner from a design point of view.

Quoted 5 lines
Quoted 3 lines

I suspect it isn't enougth to make it work though, you still need to know the position of the device in the device tree. To answer questions like "is your pci device behind a bridge and if so which one?".

Isn't that info provided by qdev?

Yep, it is.

Serialize qdev tree (into fdt or whatever else), send it over wire first, recreate qdev tree on the other side (including save/load callback registration), then parse everything else. That is how I wanna have it work some day ...

cheers,
Gerd

#47 lore raw
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Gerd Hoffmann

It might make sense to integrate savevm callbacks into qdev, then you'd have actually a chance to figure which driver belongs to your piece of savevm state.

Quoted 6 lines
Quoted 2 lines

That's my preference. The very first pass iterates the device tree and serializes it.

Sure, needs to happen.

I meant something else though: Instead of having the drivers call register_savevm() in there init functions add section name and savevm/loadvm function pointers to qdevs DeviceInfo.

Yes, that's how I see it too. It's just another device method.

Quoted 1 line

That will add the missing link section name -> driver.

There's no reason to have a section name.

Quoted 1 line

That alone will *not* provide the position in the device tree though. And I suspect making the transition without breaking backward compatibility could be quite tricky too. So I'm not sure how useful that actually is, although it surely would be much cleaner from a design point of view.

I think we need to break the format. It's semi-broken anyway wrt hotplug and the use of ram addresses. It may be possible to add transition code but I don't think it's worth it.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

I suspect it isn't enougth to make it work though, you still need to know the position of the device in the device tree. To answer questions like "is your pci device behind a bridge and if so which one?".

Isn't that info provided by qdev?

Yep, it is.

Serialize qdev tree (into fdt or whatever else), send it over wire first, recreate qdev tree on the other side (including save/load callback registration), then parse everything else. That is how I wanna have it work some day ...

Slight change: instead of serializing into a tree, have a qdev callback which generates an add event that can be sent over the wire. While migrating, additional hotplug simply call the same callback and the hotplug is migrated in real time.

Signature · 1 line
error compiling committee.c: too many arguments to function
#48 lore raw
Quoted 46 lines · Avi Kivity
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Gerd Hoffmann

It might make sense to integrate savevm callbacks into qdev, then you'd have actually a chance to figure which driver belongs to your piece of savevm state.

Quoted 8 lines
Quoted 2 lines

That's my preference. The very first pass iterates the device tree and serializes it.

Sure, needs to happen.

I meant something else though: Instead of having the drivers call register_savevm() in there init functions add section name and savevm/loadvm function pointers to qdevs DeviceInfo.

Yes, that's how I see it too. It's just another device method.

Quoted 1 line

That will add the missing link section name -> driver.

There's no reason to have a section name.

Quoted 5 lines

That alone will *not* provide the position in the device tree though. And I suspect making the transition without breaking backward compatibility could be quite tricky too. So I'm not sure how useful that actually is, although it surely would be much cleaner from a design point of view.

I think we need to break the format. It's semi-broken anyway wrt hotplug and the use of ram addresses. It may be possible to add transition code but I don't think it's worth it.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

I suspect it isn't enougth to make it work though, you still need to know the position of the device in the device tree. To answer questions like "is your pci device behind a bridge and if so which one?".

Quoted 8 lines
Quoted 1 line

Isn't that info provided by qdev?

Yep, it is.

Serialize qdev tree (into fdt or whatever else), send it over wire first, recreate qdev tree on the other side (including save/load callback registration), then parse everything else. That is how I wanna have it work some day ...

Quoted 4 lines

Slight change: instead of serializing into a tree, have a qdev callback which generates an add event that can be sent over the wire. While migrating, additional hotplug simply call the same callback and the hotplug is migrated in real time.

IOW, each device just needs to record where it is in the tree. The tree can be then reconstructed by each driver finding the parent bus and attaching the device to it.

Signature · 1 line
MST
#49 lore raw
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines

Slight change: instead of serializing into a tree, have a qdev callback which generates an add event that can be sent over the wire. While migrating, additional hotplug simply call the same callback and the hotplug is migrated in real time.

IOW, each device just needs to record where it is in the tree.

There is no easy way to do that. Instead, each bus records its component devices.

Quoted 3 lines

The tree can be then reconstructed by each driver finding the parent bus and attaching the device to it.

With a hierarhical save this is much more natural.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
author
#50 lore raw
In reply to Avi Kivity
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

I suspect it isn't enougth to make it work though, you still need to know the position of the device in the device tree. To answer questions like "is your pci device behind a bridge and if so which one?".

Quoted 8 lines
Quoted 1 line

Isn't that info provided by qdev?

Yep, it is.

Serialize qdev tree (into fdt or whatever else), send it over wire first, recreate qdev tree on the other side (including save/load callback registration), then parse everything else. That is how I wanna have it work some day ...

Quoted 4 lines

Slight change: instead of serializing into a tree, have a qdev callback which generates an add event that can be sent over the wire. While migrating, additional hotplug simply call the same callback and the hotplug is migrated in real time.

I think this is just going to cause you problems. Way simpler to just disable changing the machine configuration while migration is in progress.

Paul

#51 lore raw
Quoted 9 lines · Paul Brook
Quoted 5 lines

Slight change: instead of serializing into a tree, have a qdev callback which generates an add event that can be sent over the wire. While migrating, additional hotplug simply call the same callback and the hotplug is migrated in real time.

I think this is just going to cause you problems. Way simpler to just disable changing the machine configuration while migration is in progress.

These features are logically orthogonal and initiated by different users, so it will be seen as if hotplug randomly has high latency.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#52 lore raw
In reply to Avi Kivity
Quoted 4 lines · Avi Kivity
Quoted 2 lines

That alone will *not* provide the position in the device tree though. And I suspect making the transition without breaking backward compatibility could be quite tricky too. So I'm not sure how useful that actually is, although it surely would be much cleaner from a design point of view.

I think we need to break the format. It's semi-broken anyway wrt hotplug and the use of ram addresses. It may be possible to add transition code but I don't think it's worth it.

The format is fine. ram v3 uses ram_addr_t because it's was the only sane thing to do at the time. v4 could easily use target_phys_t.

Most importantly, machine config should not be sent until non-live migration kicks in. At this point, the device tree is stable because the guest isn't running. The device tree should be the first section saved for non-live migration.

This means you need to avoid initializing the device model until after you get to the second step in migration. You really just need to register any live migration handlers outside of the device model creation which pretty much already happens today.

Regards,

Anthony Liguori

author
#53 lore raw
Quoted 4 lines

Most importantly, machine config should not be sent until non-live migration kicks in. At this point, the device tree is stable because the guest isn't running. The device tree should be the first section saved for non-live migration.

RAM is part of the machine config, and can be hotplugged[1], so you need at least that before you start transferring anything.

Paul

[1] We don't currently have user accessible knobs for this, but all the code is there.

#54 lore raw
Quoted 8 lines · Paul Brook
Quoted 5 lines

Most importantly, machine config should not be sent until non-live migration kicks in. At this point, the device tree is stable because the guest isn't running. The device tree should be the first section saved for non-live migration.

RAM is part of the machine config, and can be hotplugged[1], so you need at least that before you start transferring anything.

You really don't. The ram_load_live handler should receive RAM as it comes in and maintain a growable buffer for all the independently transferred regions. A nice property of live migration is that you'll get the whole region at once so something simple based on realloc() will work well.

When it comes time to create the virtual machine, you have memory buffers ready to be used as the guest's memory. If it's not sized appropriately, you throw an error and migration aborts.

Regards,

Anthony Liguori

#55 lore raw
Quoted 10 lines · Anthony Liguori
Quoted 6 lines · Paul Brook
Quoted 4 lines

Most importantly, machine config should not be sent until non-live migration kicks in. At this point, the device tree is stable because the guest isn't running. The device tree should be the first section saved for non-live migration.

RAM is part of the machine config, and can be hotplugged[1], so you need at least that before you start transferring anything.

You really don't. The ram_load_live handler should receive RAM as it comes in and maintain a growable buffer for all the independently transferred regions. A nice property of live migration is that you'll get the whole region at once so something simple based on realloc() will work well.

It's doable but it looks like we're implementing things twice. If we have memory/vga hotplug, then we already support all of this at the hotplug level. All we need to do is send the hotplug command over.

It occured to me that except for RAM we can migrate using the monitor protocol. Start by serializing the qdev tree into an object and create the target machine from that. Additional hotplug commands during the migration are simply forwarded to the other side.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#56 lore raw
In reply to Anthony Liguori
Quoted 6 lines · Anthony Liguori
Quoted 2 lines

RAM is part of the machine config, and can be hotplugged[1], so you need at least that before you start transferring anything.

You really don't. The ram_load_live handler should receive RAM as it comes in and maintain a growable buffer for all the independently transferred regions. A nice property of live migration is that you'll get the whole region at once so something simple based on realloc() will work well.

One nasty bit here is large page support. We need to know memory layout in advance so we can migrate to appropriately allocated and aligned sections.

realloc()s could work, but they'd be slow (seconds) on large guests, and you're not guaranteed to have enough memory.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#57 lore raw
In reply to Anthony Liguori
Quoted 7 lines · Anthony Liguori
Quoted 4 lines · Avi Kivity
Quoted 2 lines

That alone will *not* provide the position in the device tree though. And I suspect making the transition without breaking backward compatibility could be quite tricky too. So I'm not sure how useful that actually is, although it surely would be much cleaner from a design point of view.

I think we need to break the format. It's semi-broken anyway wrt hotplug and the use of ram addresses. It may be possible to add transition code but I don't think it's worth it.

The format is fine. ram v3 uses ram_addr_t because it's was the only sane thing to do at the time. v4 could easily use target_phys_t.

IMO the flat format currently used is fragile wrt. hotplug, as is the requirement to start qemu with exactly the same parameters. If we serialize the state from the current qdev configuration we don't depend on any implementation ordering.

Quoted 1 line

Most importantly, machine config should not be sent until non-live migration kicks in. At this point, the device tree is stable because the guest isn't running. The device tree should be the first section saved for non-live migration.

Memory layout depends on the machine configuration. RAM, hotplug RAM, and framebuffers. It would get worse if more components migrate live (disks?).

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#58 lore raw
In reply to Anthony Liguori
Quoted 4 lines · Anthony Liguori

Most importantly, machine config should not be sent until non-live migration kicks in. At this point, the device tree is stable because the guest isn't running. The device tree should be the first section saved for non-live migration.

Why is that? guest by definition can't change the machine config.

Signature · 1 line
MST
#59 lore raw
In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines · Michael S. Tsirkin

On Fri, Jun 12, 2009 at 06:11:24PM +0200, Jan Kiszka wrote:
Can't we extend loadvm/savevm format to support machine config? It is already supported by all devices, it seems that we just need to add some detail such as pci addresses, and qemu flags to save/load this config. No?

Quoted 5 lines
Quoted 2 lines

No. Adding some info to the devices doesn't cut it as you also need to know which devices are present in the first place.

Actually at least for pci devices you have the devid/vendor id register - from this you can know which devices are present.

Doesn't help you. You can't easily pull out that information from the savevm file. And even it you could you still don't know which backend actually drives that piece of hardware.

cheers,
Gerd

#60 lore raw
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Gerd Hoffmann
Quoted 5 lines · Michael S. Tsirkin

On Fri, Jun 12, 2009 at 06:11:24PM +0200, Jan Kiszka wrote:
Can't we extend loadvm/savevm format to support machine config? It is already supported by all devices, it seems that we just need to add some detail such as pci addresses, and qemu flags to save/load this config. No?

No. Adding some info to the devices doesn't cut it as you also need to know which devices are present in the first place.

Quoted 6 lines
Quoted 2 lines

Actually at least for pci devices you have the devid/vendor id register - from this you can know which devices are present.

Doesn't help you. You can't easily pull out that information from the savevm file. And even it you could you still don't know which backend actually drives that piece of hardware.

How hard is it to add a fixed size backend id before each device?

Signature · 1 line
MST