PPC: mpc8544ds: Create device tree dynamically
cover PPC: mpc8544ds: Create device tree dynamically
Today we have two separate places where we keep information which device is where:
- hw/ppce500_mpc8544ds.c to instantiate all devices
- pc-bios/mpc8544ds.dtb as device tree to tell the guest about devices
Every time we split crucial information, things can go terribly wrong. If you update one file, but not the other, you can screw things up without realizing it quickly.
The redundancy is also unnecessary, because QEMU already knows all the information at which addresses its devices live. So we can generate the device tree from the same variables - and even have the device tree adjust if something changes in there.
The one functionality we lose with this approach is the ability to manually patch the device tree to contain additional devices. To still be able to do so easily, we introduce a new option -machine dumpdtb=<file> that creates a dtb output file which can be used with -machine dtb=<file> later. In between these 2 executions of QEMU, the dtb can be modified however much you like.
A lot of bits in this patch set are still hardcoded. We also don't accomodate for dynamic creation of device tree nodes when -device is used. This requires a bit more QOM'ification for us to be able to loop through all devices, so we can dynamically create the device tree nodes for them. The basic concept should still hold as is though.
Alex
v1 -> v2:
- rename cell64 -> u64
- don't treat memory as single u64
- remove commit id from patch description
- NEW: PPC: e500: Use new MPIC dt format
PPC: e500: Use new SOC dt format
PPC: e500: Define addresses as always 64bit
PPC: e500: Extend address/size of / to 64bit
dt: Add global option to set phandle start offset
PPC: e500: Refactor serial dt generation
v2 -> v3:
- [phandle helper] rename "string" to target_node_path
- [phandle helper] add correct header includes
- use snprintf
- create and use new multi-cell setting api
Alexander Graf (31):
dt: allow add_subnode to create root subnodes
dt: add helpers for multi-cell adds
dt: add helper for phandle references
dt: temporarily disable subtree creation failure check
dt: add helper for phandle enumeration
dt: add helper for empty dt creation
dt: add helper for phandle allocation
dt: add helper for 64bit cell adds
PPC: e500: require libfdt
PPC: e500: dt: create memory node dynamically
PPC: e500: dt: create /cpus node dynamically
PPC: e500: dt: create /hypervisor node dynamically
PPC: e500: dt: create / node dynamically
PPC: e500: dt: create /chosen node dynamically
PPC: e500: dt: create /soc8544 node dynamically
PPC: e500: dt: create serial nodes dynamically
PPC: e500: dt: create mpic node dynamically
PPC: e500: dt: create global-utils node dynamically
PPC: e500: dt: create pci node dynamically
PPC: e500: dt: start with empty device tree
dt: Add -machine dumpdtb option to dump the current dtb
PPC: e500: dt: use 64bit cell helper
PPC: e500: dt: use target_phys_addr_t for ramsize
PPC: e500: enable manual loading of dtb blob
Revert "dt: temporarily disable subtree creation failure check"
PPC: e500: Use new MPIC dt format
PPC: e500: Use new SOC dt format
PPC: e500: Define addresses as always 64bit
PPC: e500: Extend address/size of / to 64bit
dt: Add global option to set phandle start offset
PPC: e500: Refactor serial dt generation
Makefile | 1 - device_tree.c | 106 +++++++++++++++++++++- device_tree.h | 20 ++++ hw/ppc/Makefile.objs | 2 +- hw/ppce500_mpc8544ds.c | 237 +++++++++++++++++++++++++++++++++++++++++------ pc-bios/mpc8544ds.dtb | Bin 2028 -> 0 bytes pc-bios/mpc8544ds.dts | 119 ------------------------ qemu-config.c | 8 ++ 8 files changed, 340 insertions(+), 153 deletions(-) delete mode 100644 pc-bios/mpc8544ds.dtb delete mode 100644 pc-bios/mpc8544ds.dts
PATCH 1/31 dt: allow add_subnode to create root subnodes
Our subnode creation helper can't handle creation of root subnodes, like "/memory". Fix this by allowing the parent node to be an empty string, indicating the root node.
--- device_tree.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
device_tree.c +6 -1
@@ -151,6 +151,7 @@ int qemu_devtree_add_subnode(void *fdt, const char *name)char *dupname =g_strdup (name);char *basename =strrchr (dupname,'/' );int retval; +int parent =0 ;if (!basename) {g_free (dupname);
@@ -160,7 +161,11 @@ int qemu_devtree_add_subnode(void *fdt, const char *name) basename[0 ] ='\0' ; basename++; - retval =fdt_add_subnode (fdt,findnode_nofail (fdt, dupname), basename); +if (dupname[0 ]) { + parent =findnode_nofail (fdt, dupname); + } + + retval =fdt_add_subnode (fdt, parent, basename);if (retval <0 ) {fprintf (stderr,"FDT: Failed to create subnode %s: %s\n" , name,fdt_strerror (retval));
Signature · 1 line
1.6.0.2
PATCH 2/31 dt: add helpers for multi-cell adds
In reply to Alexander GrafWe have device tree helpers that allow us to create single cell (u32) wide properties. However, when creating properties that contain an array of cells, we need to jump through hoops, manually passing in an array with converted endianness.
To ease the pain of this, create a generic macro helper that allows us to pass the cells as arguments.
--- device_tree.h | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
device_tree.h +12 -0
@@ -25,4 +25,16 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,int qemu_devtree_nop_node (void *fdt,const char *node_path);int qemu_devtree_add_subnode (void *fdt,const char *name); +#define qemu_devtree_setprop_cells (fdt, node_path, property, ...) \ + do { \ + uint32_t qdt_tmp[] = { __VA_ARGS__ }; \ + int i; \ + \ + for (i = 0; i < ARRAY_SIZE(qdt_tmp); i++) { \ + qdt_tmp[i] = cpu_to_be32(qdt_tmp[i]); \ + } \ + qemu_devtree_setprop(fdt, node_path, property, qdt_tmp, \ + sizeof(qdt_tmp)); \ + } while (0) +#endif /* __DEVICE_TREE_H__ */
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 02/31] dt: add helpers for multi-cell adds
Quoted 9 lines · Alexander Graf
We have device tree helpers that allow us to create single cell (u32) wide properties. However, when creating properties that contain an array of cells, we need to jump through hoops, manually passing in an array with converted endianness.
To ease the pain of this, create a generic macro helper that allows us to pass the cells as arguments.
Signed-off-by Alexander Graf <[email protected]>
Quoted 25 lines
--- device_tree.h | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)device_tree.h +12
-0@@ -25,4 +25,16 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,int qemu_devtree_nop_node (void *fdt,const char *node_path);int qemu_devtree_add_subnode (void *fdt,const char *name); +#define qemu_devtree_setprop_cells (fdt, node_path, property, ...) \ + do { \ + uint32_t qdt_tmp[] = { __VA_ARGS__ }; \ + int i; \ + \ + for (i = 0; i < ARRAY_SIZE(qdt_tmp); i++) { \ + qdt_tmp[i] = cpu_to_be32(qdt_tmp[i]); \ + } \ + qemu_devtree_setprop(fdt, node_path, property, qdt_tmp, \ + sizeof(qdt_tmp)); \ + } while (0) +#endif /* __DEVICE_TREE_H__ */
PATCH 3/31 dt: add helper for phandle references
In reply to Alexander GrafPhandles are the fancy device tree name for "pointer to another node". To create a phandle property, we most likely want to reference to the node we're pointing to by its path. So create a helper that allows us to do so.
---
v2 -> v3:
- rename "string" to target_node_path
--- device_tree.c | 8 ++++++++ device_tree.h | 3 +++ 2 files changed, 11 insertions(+), 0 deletions(-)
device_tree.c +8 -0
@@ -132,6 +132,14 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,return r; } +int qemu_devtree_setprop_phandle (void *fdt,const char *node_path, +const char *property, +const char *target_node_path) +{ +uint32_t phandle =fdt_get_phandle (fdt,findnode_nofail (fdt, target_node_path)); +return qemu_devtree_setprop_cell (fdt, node_path, property, phandle); +} +int qemu_devtree_nop_node (void *fdt,const char *node_path) {int r;
device_tree.h +3 -0
@@ -22,6 +22,9 @@ int qemu_devtree_setprop_cell(void *fdt, const char *node_path, const char *property, uint32_t val);int qemu_devtree_setprop_string (void *fdt,const char *node_path,const char *property,const char *string); +int qemu_devtree_setprop_phandle (void *fdt,const char *node_path, +const char *property, +const char *target_node_path);int qemu_devtree_nop_node (void *fdt,const char *node_path);int qemu_devtree_add_subnode (void *fdt,const char *name);
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 03/31] dt: add helper for phandle references
Quoted 7 lines · Alexander Graf
Phandles are the fancy device tree name for "pointer to another node". To create a phandle property, we most likely want to reference to the node we're pointing to by its path. So create a helper that allows us to do so.
Signed-off-by Alexander Graf <[email protected]>
There are consistency issues with the whole nofail/fail discussion but as Alex pointed out, thats a battle for another day.
Quoted 43 lines
---
v2 -> v3:
- rename "string" to
target_node_path--- device_tree.c | 8 ++++++++ device_tree.h | 3 +++ 2 files changed, 11 insertions(+), 0 deletions(-)device_tree.c +8
-0@@ -132,6 +132,14 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,return r; } +int qemu_devtree_setprop_phandle (void *fdt,const char *node_path, +const char *property, +const char *target_node_path) +{ +uint32_t phandle =fdt_get_phandle (fdt,findnode_nofail (fdt, target_node_path)); +return qemu_devtree_setprop_cell (fdt, node_path, property, phandle); +} +int qemu_devtree_nop_node (void *fdt,const char *node_path) {int r;device_tree.h +3
-0@@ -22,6 +22,9 @@ int qemu_devtree_setprop_cell(void *fdt, const char *node_path, const char *property, uint32_t val);int qemu_devtree_setprop_string (void *fdt,const char *node_path,const char *property,const char *string); +int qemu_devtree_setprop_phandle (void *fdt,const char *node_path, +const char *property, +const char *target_node_path);int qemu_devtree_nop_node (void *fdt,const char *node_path);int qemu_devtree_add_subnode (void *fdt,const char *name);
PATCH 4/31 dt: temporarily disable subtree creation failure check
In reply to Alexander GrafUsually we want to know when creating a subtree fails. However, while introducing this patch set we have to modify the device tree and some times have the code to create a subtree in both the binary tree and the dynamically created tree.
So ignore failures about this for now and enable them once we got rid of the binary device tree.
--- device_tree.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
device_tree.c +2 -0
@@ -174,11 +174,13 @@ int qemu_devtree_add_subnode(void *fdt, const char *name) } retval =fdt_add_subnode (fdt, parent, basename); +#if 0 if (retval <0 ) {fprintf (stderr,"FDT: Failed to create subnode %s: %s\n" , name,fdt_strerror (retval));exit (1 ); } +#endif g_free (dupname);return retval;
Signature · 1 line
1.6.0.2
PATCH 5/31 dt: add helper for phandle enumeration
In reply to Alexander GrafThis patch adds a helper to search for a node's phandle by its path. This is especially useful when the phandle is part of an array, not just a single cell in which case qemu_devtree_setprop_phandle would be the easy choice.
--- device_tree.c | 16 +++++++++++++++- device_tree.h | 1 + 2 files changed, 16 insertions(+), 1 deletions(-)
device_tree.c +15 -1
@@ -132,11 +132,25 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,return r; } +uint32_t qemu_devtree_get_phandle (void *fdt,const char *path) +{ +uint32_t r; + + r =fdt_get_phandle (fdt,findnode_nofail (fdt, path)); +if (r <=0 ) { +fprintf (stderr,"%s: Couldn't get phandle for %s: %s\n" , __func__, + path,fdt_strerror (r)); +exit (1 ); + } + +return r; +} +int qemu_devtree_setprop_phandle (void *fdt,const char *node_path,const char *property,const char *target_node_path) { -uint32_t phandle =fdt_get_phandle (fdt,findnode_nofail (fdt, target_node_path)); +uint32_t phandle =qemu_devtree_get_phandle (fdt, target_node_path);return qemu_devtree_setprop_cell (fdt, node_path, property, phandle); }
device_tree.h +1 -0
@@ -25,6 +25,7 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,int qemu_devtree_setprop_phandle (void *fdt,const char *node_path,const char *property,const char *target_node_path); +uint32_t qemu_devtree_get_phandle (void *fdt,const char *path);int qemu_devtree_nop_node (void *fdt,const char *node_path);int qemu_devtree_add_subnode (void *fdt,const char *name);
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 05/31] dt: add helper for phandle enumeration
Quoted 5 lines · Alexander Graf
This patch adds a helper to search for a node's phandle by its path. This is especially useful when the phandle is part of an array, not just a single cell in which case
qemu_devtree_setprop_phandlewould be the easy choice.Signed-off-by Alexander Graf <[email protected]>
Quoted 48 lines
--- device_tree.c | 16 +++++++++++++++- device_tree.h | 1 + 2 files changed, 16 insertions(+), 1 deletions(-)device_tree.c +15
-1@@ -132,11 +132,25 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,return r; } +uint32_t qemu_devtree_get_phandle (void *fdt,const char *path) +{ +uint32_t r; + + r =fdt_get_phandle (fdt,findnode_nofail (fdt, path)); +if (r <=0 ) { +fprintf (stderr,"%s: Couldn't get phandle for %s: %s\n" , __func__, + path,fdt_strerror (r)); +exit (1 ); + } + +return r; +} +int qemu_devtree_setprop_phandle (void *fdt,const char *node_path,const char *property,const char *target_node_path) { -uint32_t phandle =fdt_get_phandle (fdt,findnode_nofail (fdt, target_node_path)); +uint32_t phandle =qemu_devtree_get_phandle (fdt, target_node_path);return qemu_devtree_setprop_cell (fdt, node_path, property, phandle); }device_tree.h +1
-0@@ -25,6 +25,7 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,int qemu_devtree_setprop_phandle (void *fdt,const char *node_path,const char *property,const char *target_node_path); +uint32_t qemu_devtree_get_phandle (void *fdt,const char *path);int qemu_devtree_nop_node (void *fdt,const char *node_path);int qemu_devtree_add_subnode (void *fdt,const char *name);
PATCH 6/31 dt: add helper for empty dt creation
In reply to Alexander GrafWe want to get rid of the concept of loading an external device tree and instead generate our own. However, to do this we need to also create a device tree template programatically.
This patch adds a helper to create an empty device tree in memory.
--- device_tree.c | 37 +++++++++++++++++++++++++++++++++++++ device_tree.h | 1 + 2 files changed, 38 insertions(+), 0 deletions(-)
device_tree.c +37 -0
@@ -25,6 +25,43 @@#include <libfdt.h> +#define FDT_MAX_SIZE 0x10000 + +void *create_device_tree (int *sizep) +{ +void *fdt; +int ret; + + *sizep =FDT_MAX_SIZE ; + fdt =g_malloc0 (FDT_MAX_SIZE ); + ret =fdt_create (fdt,FDT_MAX_SIZE ); +if (ret <0 ) { + goto fail; + } + ret =fdt_begin_node (fdt,"" ); +if (ret <0 ) { + goto fail; + } + ret =fdt_end_node (fdt); +if (ret <0 ) { + goto fail; + } + ret =fdt_finish (fdt); +if (ret <0 ) { + goto fail; + } + ret =fdt_open_into (fdt, fdt, *sizep); +if (ret) { +fprintf (stderr,"Unable to copy device tree in memory\n" ); +exit (1 ); + } + +return fdt; +fail: +fprintf (stderr,"%s Couldn't create dt: %s\n" , __func__,fdt_strerror (ret)); +exit (1 ); +} +void *load_device_tree (const char *filename_path,int *sizep) {int dt_size;
device_tree.h +1 -0
@@ -14,6 +14,7 @@#ifndef __DEVICE_TREE_H__#define __DEVICE_TREE_H__ +void *create_device_tree (int *sizep);void *load_device_tree (const char *filename_path,int *sizep); int qemu_devtree_setprop(void *fdt, const char *node_path,
Signature · 1 line
1.6.0.2
PATCH 7/31 dt: add helper for phandle allocation
In reply to Alexander GrafPhandle references work by having 2 pieces:
- a "phandle" 1-cell property in the device tree node
- a reference to the same value in a property we want to point to the other node
To generate the 1-cell property, we need an allocation mechanism that gives us a unique number space. This patch adds an allocator for these properties.
--- device_tree.c | 7 +++++++ device_tree.h | 1 + 2 files changed, 8 insertions(+), 0 deletions(-)
device_tree.c +7 -0
@@ -191,6 +191,13 @@ int qemu_devtree_setprop_phandle(void *fdt, const char *node_path,return qemu_devtree_setprop_cell (fdt, node_path, property, phandle); } +uint32_t qemu_devtree_alloc_phandle (void *fdt) +{ +static int phandle =0x8000 ; + +return phandle++; +} +int qemu_devtree_nop_node (void *fdt,const char *node_path) {int r;
device_tree.h +1 -0
@@ -27,6 +27,7 @@ int qemu_devtree_setprop_phandle(void *fdt, const char *node_path,const char *property, const char *target_node_path);uint32_t qemu_devtree_get_phandle (void *fdt,const char *path); +uint32_t qemu_devtree_alloc_phandle (void *fdt);int qemu_devtree_nop_node (void *fdt,const char *node_path);int qemu_devtree_add_subnode (void *fdt,const char *name);
Signature · 1 line
1.6.0.2
PATCH 8/31 dt: add helper for 64bit cell adds
In reply to Alexander GrafSome times in the device tree, we find an array of 2 u32 cells that really are a single u64 value. This patch adds a helper to make the creation of these easy.
---
v1 -> v2:
- rename cell64 -> u64
--- device_tree.c | 7 +++++++ device_tree.h | 2 ++ 2 files changed, 9 insertions(+), 0 deletions(-)
device_tree.c +7 -0
@@ -154,6 +154,13 @@ int qemu_devtree_setprop_cell(void *fdt, const char *node_path,return r; } +int qemu_devtree_setprop_u64 (void *fdt,const char *node_path, +const char *property,uint64_t val) +{ + val =cpu_to_be64 (val); +return qemu_devtree_setprop (fdt, node_path, property, &val,sizeof (val)); +} +int qemu_devtree_setprop_string (void *fdt,const char *node_path,const char *property,const char *string) {
device_tree.h +2 -0
@@ -21,6 +21,8 @@ int qemu_devtree_setprop(void *fdt, const char *node_path, const char *property, void *val_array, int size);int qemu_devtree_setprop_cell (void *fdt,const char *node_path,const char *property,uint32_t val); +int qemu_devtree_setprop_u64 (void *fdt,const char *node_path, +const char *property,uint64_t val);int qemu_devtree_setprop_string (void *fdt,const char *node_path,const char *property,const char *string); int qemu_devtree_setprop_phandle(void *fdt, const char *node_path,
Signature · 1 line
1.6.0.2
PATCH 9/31 PPC: e500: require libfdt
In reply to Alexander GrafNow that we're moving all of the device tree generation from an external pre-execution generated blob to runtime generation using libfdt, we absolutely must have libfdt around.
This requirement was there before already, as the only way to not require libfdt with e500 was to not use -kernel, which was the only way to boot the mpc8544ds machine. This patch only manifests said requirement in the build system.
--- hw/ppc/Makefile.objs | 2 +- hw/ppce500_mpc8544ds.c | 5 ----- 2 files changed, 1 insertions(+), 6 deletions(-)
hw/ppc/Makefile.objs +1 -1
@@ -15,7 +15,7 @@ obj-$(CONFIG_PSERIES) += spapr_pci.o pci-hotplug.o obj-y += ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o obj-y += ppc440_bamboo.o # PowerPC E500 boards -obj-y += ppce500_mpc8544ds.o mpc8544_guts.o ppce500_spin.o +obj-$(CONFIG_FDT) += ppce500_mpc8544ds.o mpc8544_guts.o ppce500_spin.o # PowerPC 440 Xilinx ML507 reference board. obj-y += virtex_ml507.o # PowerPC OpenPIC
hw/ppce500_mpc8544ds.c +0 -5
@@ -68,7 +68,6 @@ static int mpc8544_load_device_tree(CPUPPCState *env, const char *kernel_cmdline) {int ret =-1 ; -#ifdef CONFIG_FDT uint32_t mem_reg_property[] = {0 ,cpu_to_be32 (ramsize)};char *filename;int fdt_size;
@@ -173,7 +172,6 @@ static int mpc8544_load_device_tree(CPUPPCState *env, ret = fdt_size; out: -#endif return ret; }
@@ -391,9 +389,6 @@ static void mpc8544ds_init(ram_addr_t ram_size,struct boot_info *boot_info;int dt_size; -#ifndef CONFIG_FDT -cpu_abort (env,"Compiled without FDT support - can't load kernel\n" ); -#endif dt_base = (loadaddr + kernel_size +DTC_LOAD_PAD ) & ~DTC_PAD_MASK ; dt_size =mpc8544_load_device_tree (env, dt_base, ram_size, initrd_base, initrd_size, kernel_cmdline);
Signature · 1 line
1.6.0.2
PATCH 10/31 PPC: e500: dt: create memory node dynamically
In reply to Alexander Graf--- hw/ppce500_mpc8544ds.c | 8 ++++---- pc-bios/mpc8544ds.dtb | Bin 2028 -> 1972 bytes pc-bios/mpc8544ds.dts | 5 ----- 3 files changed, 4 insertions(+), 9 deletions(-)
hw/ppce500_mpc8544ds.c +4 -4
@@ -88,10 +88,10 @@ static int mpc8544_load_device_tree(CPUPPCState *env, }/* Manipulate device tree in memory. */ - ret =qemu_devtree_setprop (fdt,"/memory" ,"reg" , mem_reg_property, -sizeof (mem_reg_property)); -if (ret <0 ) -fprintf (stderr,"couldn't set /memory/reg\n" ); +qemu_devtree_add_subnode (fdt,"/memory" ); +qemu_devtree_setprop_string (fdt,"/memory" ,"device_type" ,"memory" ); +qemu_devtree_setprop (fdt,"/memory" ,"reg" , mem_reg_property, +sizeof (mem_reg_property));if (initrd_size) { ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
pc-bios/mpc8544ds.dtb binary +0 -0
pc-bios/mpc8544ds.dts +0 -5
@@ -27,11 +27,6 @@ #size-cells = <0>; }; - memory { - device_type = "memory"; - reg = <0x0 0x0>; // Filled by U-Boot - }; - soc8544@e0000000 { #address-cells = <1>; #size-cells = <1>;
Signature · 1 line
1.6.0.2
PATCH 11/31 PPC: e500: dt: create /cpus node dynamically
In reply to Alexander Graf--- hw/ppce500_mpc8544ds.c | 5 +++++ pc-bios/mpc8544ds.dtb | Bin 1972 -> 1924 bytes pc-bios/mpc8544ds.dts | 5 ----- 3 files changed, 5 insertions(+), 5 deletions(-)
hw/ppce500_mpc8544ds.c +5 -0
@@ -125,6 +125,11 @@ static int mpc8544_load_device_tree(CPUPPCState *env, hypercall, sizeof(hypercall)); } +/* Create CPU nodes */ +qemu_devtree_add_subnode (fdt,"/cpus" ); +qemu_devtree_setprop_cell (fdt,"/cpus" ,"#address-cells" ,1 ); +qemu_devtree_setprop_cell (fdt,"/cpus" ,"#size-cells" ,0 ); +/* We need to generate the cpu nodes in reverse order, so Linux can pick the first node as boot node and be happy */ for (i = smp_cpus -1 ; i >=0 ; i--) {
pc-bios/mpc8544ds.dtb binary +0 -0
pc-bios/mpc8544ds.dts +0 -5
@@ -22,11 +22,6 @@ pci0 = &pci0; }; - cpus { - #address-cells = <1>; - #size-cells = <0>; - }; - soc8544@e0000000 { #address-cells = <1>; #size-cells = <1>;
Signature · 1 line
1.6.0.2
PATCH 12/31 PPC: e500: dt: create /hypervisor node dynamically
In reply to Alexander Graf--- hw/ppce500_mpc8544ds.c | 1 + pc-bios/mpc8544ds.dtb | Bin 1924 -> 1904 bytes pc-bios/mpc8544ds.dts | 3 --- 3 files changed, 1 insertions(+), 3 deletions(-)
hw/ppce500_mpc8544ds.c +1 -0
@@ -118,6 +118,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env, tb_freq =kvmppc_get_tbfreq ();/* indicate KVM hypercall interface */ +qemu_devtree_add_subnode (fdt,"/hypervisor" );qemu_devtree_setprop_string (fdt,"/hypervisor" ,"compatible" ,"linux,kvm" );kvmppc_get_hypercall (env, hypercall,sizeof (hypercall));
pc-bios/mpc8544ds.dtb binary +0 -0
pc-bios/mpc8544ds.dts +0 -3
@@ -103,7 +103,4 @@ chosen { linux,stdout-path = "/soc8544@e0000000/serial@4500"; }; - - hypervisor { - }; };
Signature · 1 line
1.6.0.2
PATCH 13/31 PPC: e500: dt: create / node dynamically
In reply to Alexander Graf--- hw/ppce500_mpc8544ds.c | 8 ++++++++ pc-bios/mpc8544ds.dtb | Bin 1904 -> 1810 bytes pc-bios/mpc8544ds.dts | 5 ----- 3 files changed, 8 insertions(+), 5 deletions(-)
hw/ppce500_mpc8544ds.c +8 -0
@@ -76,6 +76,8 @@ static int mpc8544_load_device_tree(CPUPPCState *env,uint32_t clock_freq =400000000 ;uint32_t tb_freq =400000000 ;int i; +char compatible[] ="MPC8544DS\0MPC85xxDS" ; +char model[] ="MPC8544DS" ; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE );if (!filename) {
@@ -88,6 +90,12 @@ static int mpc8544_load_device_tree(CPUPPCState *env, }/* Manipulate device tree in memory. */ +qemu_devtree_setprop_string (fdt,"/" ,"model" , model); +qemu_devtree_setprop (fdt,"/" ,"compatible" , compatible, +sizeof (compatible)); +qemu_devtree_setprop_cell (fdt,"/" ,"#address-cells" ,1 ); +qemu_devtree_setprop_cell (fdt,"/" ,"#size-cells" ,1 ); +qemu_devtree_add_subnode (fdt,"/memory" );qemu_devtree_setprop_string (fdt,"/memory" ,"device_type" ,"memory" ); qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
pc-bios/mpc8544ds.dtb binary +0 -0
pc-bios/mpc8544ds.dts +0 -5
@@ -11,11 +11,6 @@ /dts-v1/; / { - model = "MPC8544DS"; - compatible = "MPC8544DS", "MPC85xxDS"; - #address-cells = <1>; - #size-cells = <1>; - aliases { serial0 = &serial0; serial1 = &serial1;
Signature · 1 line
1.6.0.2
PATCH 14/31 PPC: e500: dt: create /chosen node dynamically
In reply to Alexander Graf--- hw/ppce500_mpc8544ds.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/ppce500_mpc8544ds.c +1 -0
@@ -101,6 +101,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_setprop (fdt,"/memory" ,"reg" , mem_reg_property,sizeof (mem_reg_property)); +qemu_devtree_add_subnode (fdt,"/chosen" );if (initrd_size) { ret =qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , initrd_base);
Signature · 1 line
1.6.0.2
PATCH 15/31 PPC: e500: dt: create /soc8544 node dynamically
In reply to Alexander Graf---
v2 -> v3:
- use snprintf
- use new multi-cell setting api
--- hw/ppce500_mpc8544ds.c | 17 +++++++++++++++++ pc-bios/mpc8544ds.dts | 9 --------- 2 files changed, 17 insertions(+), 9 deletions(-)
hw/ppce500_mpc8544ds.c +17 -0
@@ -43,6 +43,8 @@#define RAM_SIZES_ALIGN (64UL << 20)#define MPC8544_CCSRBAR_BASE 0xE0000000 +#define MPC8544_CCSRBAR_REGSIZE 0x00001000 +#define MPC8544_CCSRBAR_SIZE 0x00100000#define MPC8544_MPIC_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x40000)#define MPC8544_SERIAL0_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x4500)#define MPC8544_SERIAL1_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x4600)
@@ -78,6 +80,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,int i;char compatible[] ="MPC8544DS\0MPC85xxDS" ;char model[] ="MPC8544DS" ; +char soc[128 ]; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE );if (!filename) {
@@ -179,6 +182,20 @@ static int mpc8544_load_device_tree(CPUPPCState *env, } } +/* XXX These should go into their respective devices' code */ +snprintf (soc,sizeof (soc),"/soc8544@%x" ,MPC8544_CCSRBAR_BASE ); +qemu_devtree_add_subnode (fdt, soc); +qemu_devtree_setprop_string (fdt, soc,"device_type" ,"soc" ); +qemu_devtree_setprop_string (fdt, soc,"compatible" ,"simple-bus" ); +qemu_devtree_setprop_cell (fdt, soc,"#address-cells" ,1 ); +qemu_devtree_setprop_cell (fdt, soc,"#size-cells" ,1 ); +qemu_devtree_setprop_cells (fdt, soc,"ranges" ,0x0 ,MPC8544_CCSRBAR_BASE , +MPC8544_CCSRBAR_SIZE ); +qemu_devtree_setprop_cells (fdt, soc,"reg" ,MPC8544_CCSRBAR_BASE , +MPC8544_CCSRBAR_REGSIZE ); +/* XXX should contain a reasonable value */ +qemu_devtree_setprop_cell (fdt, soc,"bus-frequency" ,0 ); + ret =rom_add_blob_fixed (BINARY_DEVICE_TREE_FILE , fdt, fdt_size, addr);if (ret <0 ) { goto out;
pc-bios/mpc8544ds.dts +0 -9
@@ -18,15 +18,6 @@ }; soc8544@e0000000 { - #address-cells = <1>; - #size-cells = <1>; - device_type = "soc"; - compatible = "simple-bus"; - - ranges = <0x0 0xe0000000 0x100000>; - reg = <0xe0000000 0x1000>; // CCSRBAR 1M - bus-frequency = <0>; // Filled out by uboot. - serial0: serial@4500 { cell-index = <0>; device_type = "serial";
Signature · 1 line
1.6.0.2
PATCH 16/31 PPC: e500: dt: create serial nodes dynamically
In reply to Alexander Graf---
v2 -> v3:
- use snprintf
- use new multi-cell setting api
--- hw/ppce500_mpc8544ds.c | 35 +++++++++++++++++++++++++++++++++++ pc-bios/mpc8544ds.dts | 26 -------------------------- 2 files changed, 35 insertions(+), 26 deletions(-)
hw/ppce500_mpc8544ds.c +35 -0
@@ -81,6 +81,8 @@ static int mpc8544_load_device_tree(CPUPPCState *env,char compatible[] ="MPC8544DS\0MPC85xxDS" ;char model[] ="MPC8544DS" ;char soc[128 ]; +char ser0[128 ]; +char ser1[128 ]; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE );if (!filename) {
@@ -182,6 +184,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env, } } +qemu_devtree_add_subnode (fdt,"/aliases" );/* XXX These should go into their respective devices' code */ snprintf (soc,sizeof (soc),"/soc8544@%x" ,MPC8544_CCSRBAR_BASE );qemu_devtree_add_subnode (fdt, soc);
@@ -196,6 +199,38 @@ static int mpc8544_load_device_tree(CPUPPCState *env,/* XXX should contain a reasonable value */ qemu_devtree_setprop_cell (fdt, soc,"bus-frequency" ,0 ); +/* +* We have to generate ser1 first, because Linux takes the first +* device it finds in the dt as serial output device. And we generate +* devices in reverse order to the dt. +*/ +snprintf (ser1,sizeof (ser1),"%s/serial@%x" , soc, +MPC8544_SERIAL1_REGS_BASE -MPC8544_CCSRBAR_BASE ); +qemu_devtree_add_subnode (fdt, ser1); +qemu_devtree_setprop_string (fdt, ser1,"device_type" ,"serial" ); +qemu_devtree_setprop_string (fdt, ser1,"compatible" ,"ns16550" ); +qemu_devtree_setprop_cells (fdt, ser1,"reg" ,MPC8544_SERIAL1_REGS_BASE - +MPC8544_CCSRBAR_BASE ,0x100 ); +qemu_devtree_setprop_cell (fdt, ser1,"cell-index" ,1 ); +qemu_devtree_setprop_cell (fdt, ser1,"clock-frequency" ,0 ); +qemu_devtree_setprop_cells (fdt, ser1,"interrupts" ,42 ,2 ); +qemu_devtree_setprop_phandle (fdt, ser1,"interrupt-parent" , mpic); +qemu_devtree_setprop_string (fdt,"/aliases" ,"serial1" , ser1); + +snprintf (ser0,sizeof (ser0),"%s/serial@%x" , soc, +MPC8544_SERIAL0_REGS_BASE -MPC8544_CCSRBAR_BASE ); +qemu_devtree_add_subnode (fdt, ser0); +qemu_devtree_setprop_string (fdt, ser0,"device_type" ,"serial" ); +qemu_devtree_setprop_string (fdt, ser0,"compatible" ,"ns16550" ); +qemu_devtree_setprop_cells (fdt, ser0,"reg" ,MPC8544_SERIAL0_REGS_BASE - +MPC8544_CCSRBAR_BASE ,0x100 ); +qemu_devtree_setprop_cell (fdt, ser0,"cell-index" ,0 ); +qemu_devtree_setprop_cell (fdt, ser0,"clock-frequency" ,0 ); +qemu_devtree_setprop_cells (fdt, ser0,"interrupts" ,42 ,2 ); +qemu_devtree_setprop_phandle (fdt, ser0,"interrupt-parent" , mpic); +qemu_devtree_setprop_string (fdt,"/aliases" ,"serial0" , ser0); +qemu_devtree_setprop_string (fdt,"/chosen" ,"linux,stdout-path" , ser0); + ret =rom_add_blob_fixed (BINARY_DEVICE_TREE_FILE , fdt, fdt_size, addr);if (ret <0 ) { goto out;
pc-bios/mpc8544ds.dts +0 -26
@@ -12,32 +12,10 @@ /dts-v1/; / { aliases { - serial0 = &serial0; - serial1 = &serial1; pci0 = &pci0; }; soc8544@e0000000 { - serial0: serial@4500 { - cell-index = <0>; - device_type = "serial"; - compatible = "ns16550"; - reg = <0x4500 0x100>; - clock-frequency = <0>; - interrupts = <42 2>; - interrupt-parent = <&mpic>; - }; - - serial1: serial@4600 { - cell-index = <1>; - device_type = "serial"; - compatible = "ns16550"; - reg = <0x4600 0x100>; - clock-frequency = <0>; - interrupts = <42 2>; - interrupt-parent = <&mpic>; - }; - mpic: pic@40000 { interrupt-controller; #address-cells = <0>;
@@ -85,8 +63,4 @@ #address-cells = <3>; reg = <0xe0008000 0x1000>; }; - - chosen { - linux,stdout-path = "/soc8544@e0000000/serial@4500"; - }; };
Signature · 1 line
1.6.0.2
PATCH 17/31 PPC: e500: dt: create mpic node dynamically
In reply to Alexander Graf---
v2 -> v3:
- use snprintf
- use new multi-cell setting api
--- hw/ppce500_mpc8544ds.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
hw/ppce500_mpc8544ds.c +16 -0
@@ -83,6 +83,8 @@ static int mpc8544_load_device_tree(CPUPPCState *env,char soc[128 ];char ser0[128 ];char ser1[128 ]; +char mpic[128 ]; +uint32_t mpic_ph; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE );if (!filename) {
@@ -199,6 +201,20 @@ static int mpc8544_load_device_tree(CPUPPCState *env,/* XXX should contain a reasonable value */ qemu_devtree_setprop_cell (fdt, soc,"bus-frequency" ,0 ); +snprintf (mpic,sizeof (mpic),"%s/pic@%x" , soc, +MPC8544_MPIC_REGS_BASE -MPC8544_CCSRBAR_BASE ); +qemu_devtree_add_subnode (fdt, mpic); +qemu_devtree_setprop_string (fdt, mpic,"device_type" ,"open-pic" ); +qemu_devtree_setprop_string (fdt, mpic,"compatible" ,"chrp,open-pic" ); +qemu_devtree_setprop_cells (fdt, mpic,"reg" ,MPC8544_MPIC_REGS_BASE - +MPC8544_CCSRBAR_BASE ,0x40000 ); +qemu_devtree_setprop_cell (fdt, mpic,"#address-cells" ,0 ); +qemu_devtree_setprop_cell (fdt, mpic,"#interrupt-cells" ,2 ); + mpic_ph =qemu_devtree_alloc_phandle (fdt); +qemu_devtree_setprop_cell (fdt, mpic,"phandle" , mpic_ph); +qemu_devtree_setprop_cell (fdt, mpic,"linux,phandle" , mpic_ph); +qemu_devtree_setprop (fdt, mpic,"interrupt-controller" ,NULL ,0 ); +/* * We have to generate ser1 first, because Linux takes the first * device it finds in the dt as serial output device. And we generate
Signature · 1 line
1.6.0.2
PATCH 18/31 PPC: e500: dt: create global-utils node dynamically
In reply to Alexander Graf---
v2 -> v3:
- use snprintf
- use new multi-cell setting api
--- hw/ppce500_mpc8544ds.c | 9 +++++++++ pc-bios/mpc8544ds.dts | 6 ------ 2 files changed, 9 insertions(+), 6 deletions(-)
hw/ppce500_mpc8544ds.c +9 -0
@@ -85,6 +85,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,char ser1[128 ];char mpic[128 ];uint32_t mpic_ph; +char gutil[128 ]; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE );if (!filename) {
@@ -247,6 +248,14 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_setprop_string (fdt,"/aliases" ,"serial0" , ser0);qemu_devtree_setprop_string (fdt,"/chosen" ,"linux,stdout-path" , ser0); +snprintf (gutil,sizeof (gutil),"%s/global-utilities@%x" , soc, +MPC8544_UTIL_BASE -MPC8544_CCSRBAR_BASE ); +qemu_devtree_add_subnode (fdt, gutil); +qemu_devtree_setprop_string (fdt, gutil,"compatible" ,"fsl,mpc8544-guts" ); +qemu_devtree_setprop_cells (fdt, gutil,"reg" ,MPC8544_UTIL_BASE - +MPC8544_CCSRBAR_BASE ,0x1000 ); +qemu_devtree_setprop (fdt, gutil,"fsl,has-rstcr" ,NULL ,0 ); + ret =rom_add_blob_fixed (BINARY_DEVICE_TREE_FILE , fdt, fdt_size, addr);if (ret <0 ) { goto out;
pc-bios/mpc8544ds.dts +0 -6
@@ -24,12 +24,6 @@ compatible = "chrp,open-pic"; device_type = "open-pic"; }; - - global-utilities@e0000 { //global utilities block - compatible = "fsl,mpc8544-guts"; - reg = <0xe0000 0x1000>; - fsl,has-rstcr; - }; }; pci0: pci@e0008000 {
Signature · 1 line
1.6.0.2
PATCH 19/31 PPC: e500: dt: create pci node dynamically
In reply to Alexander Graf---
v2 -> v3:
- use snprintf
- use new multi-cell setting api
--- hw/ppce500_mpc8544ds.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ pc-bios/mpc8544ds.dtb | Bin 1810 -> 72 bytes pc-bios/mpc8544ds.dts | 46 -------------------------------------------- 3 files changed, 50 insertions(+), 46 deletions(-)
hw/ppce500_mpc8544ds.c +50 -0
@@ -62,6 +62,27 @@ struct boot_infouint32_t entry; }; +static void pci_map_create (void *fdt,uint32_t *pci_map,uint32_t mpic) +{ +int i; +const uint32_t tmp[] = { +/* IDSEL 0x11 J17 Slot 1 */ +0x8800 ,0x0 ,0x0 ,0x1 , mpic,0x2 ,0x1 , +0x8800 ,0x0 ,0x0 ,0x2 , mpic,0x3 ,0x1 , +0x8800 ,0x0 ,0x0 ,0x3 , mpic,0x4 ,0x1 , +0x8800 ,0x0 ,0x0 ,0x4 , mpic,0x1 ,0x1 , + +/* IDSEL 0x12 J16 Slot 2 */ +0x9000 ,0x0 ,0x0 ,0x1 , mpic,0x3 ,0x1 , +0x9000 ,0x0 ,0x0 ,0x2 , mpic,0x4 ,0x1 , +0x9000 ,0x0 ,0x0 ,0x3 , mpic,0x2 ,0x1 , +0x9000 ,0x0 ,0x0 ,0x4 , mpic,0x1 ,0x1 , + }; +for (i =0 ; i < (7 *8 ); i++) { + pci_map[i] =cpu_to_be32 (tmp[i]); + } +} + static int mpc8544_load_device_tree(CPUPPCState *env, target_phys_addr_t addr, uint32_t ramsize,
@@ -86,6 +107,11 @@ static int mpc8544_load_device_tree(CPUPPCState *env,char mpic[128 ];uint32_t mpic_ph;char gutil[128 ]; +char pci[128 ]; +uint32_t pci_map[7 *8 ]; +uint32_t pci_ranges[12 ] = {0x2000000 ,0x0 ,0xc0000000 ,0xc0000000 ,0x0 , +0x20000000 ,0x1000000 ,0x0 ,0x0 ,0xe1000000 , +0x0 ,0x10000 }; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE );if (!filename) {
@@ -256,6 +282,30 @@ static int mpc8544_load_device_tree(CPUPPCState *env, MPC8544_CCSRBAR_BASE, 0x1000);qemu_devtree_setprop (fdt, gutil,"fsl,has-rstcr" ,NULL ,0 ); +snprintf (pci,sizeof (pci),"/pci@%x" ,MPC8544_PCI_REGS_BASE ); +qemu_devtree_add_subnode (fdt, pci); +qemu_devtree_setprop_cell (fdt, pci,"cell-index" ,0 ); +qemu_devtree_setprop_string (fdt, pci,"compatible" ,"fsl,mpc8540-pci" ); +qemu_devtree_setprop_string (fdt, pci,"device_type" ,"pci" ); +qemu_devtree_setprop_cells (fdt, pci,"interrupt-map-mask" ,0xf800 ,0x0 , +0x0 ,0x7 ); +pci_map_create (fdt, pci_map,qemu_devtree_get_phandle (fdt, mpic)); +qemu_devtree_setprop (fdt, pci,"interrupt-map" , pci_map,sizeof (pci_map)); +qemu_devtree_setprop_phandle (fdt, pci,"interrupt-parent" , mpic); +qemu_devtree_setprop_cells (fdt, pci,"interrupts" ,24 ,2 ); +qemu_devtree_setprop_cells (fdt, pci,"bus-range" ,0 ,255 ); +for (i =0 ; i <12 ; i++) { + pci_ranges[i] =cpu_to_be32 (pci_ranges[i]); + } +qemu_devtree_setprop (fdt, pci,"ranges" , pci_ranges,sizeof (pci_ranges)); +qemu_devtree_setprop_cells (fdt, pci,"reg" ,MPC8544_PCI_REGS_BASE , +0x1000 ); +qemu_devtree_setprop_cell (fdt, pci,"clock-frequency" ,66666666 ); +qemu_devtree_setprop_cell (fdt, pci,"#interrupt-cells" ,1 ); +qemu_devtree_setprop_cell (fdt, pci,"#size-cells" ,2 ); +qemu_devtree_setprop_cell (fdt, pci,"#address-cells" ,3 ); +qemu_devtree_setprop_string (fdt,"/aliases" ,"pci0" , pci); + ret =rom_add_blob_fixed (BINARY_DEVICE_TREE_FILE , fdt, fdt_size, addr);if (ret <0 ) { goto out;
pc-bios/mpc8544ds.dtb binary +0 -0
pc-bios/mpc8544ds.dts +0 -46
50 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 20/31 PPC: e500: dt: start with empty device tree
In reply to Alexander GrafNow that all of the device tree bits are generated during runtime, we can get rid of the device tree blob and instead start from scratch with an empty device tree.
--- Makefile | 1 - hw/ppce500_mpc8544ds.c | 8 +------- pc-bios/mpc8544ds.dtb | Bin 72 -> 0 bytes pc-bios/mpc8544ds.dts | 14 -------------- 4 files changed, 1 insertions(+), 22 deletions(-) delete mode 100644 pc-bios/mpc8544ds.dtb delete mode 100644 pc-bios/mpc8544ds.dts
Makefile +0 -1
@@ -260,7 +260,6 @@ pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \ pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \ qemu-icon.bmp \ bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \ -mpc8544ds.dtb \ multiboot.bin linuxboot.bin kvmvapic.bin \ s390-zipl.rom \ spapr-rtas.bin slof.bin \
hw/ppce500_mpc8544ds.c +1 -7
@@ -92,7 +92,6 @@ static int mpc8544_load_device_tree(CPUPPCState *env, {int ret =-1 ;uint32_t mem_reg_property[] = {0 ,cpu_to_be32 (ramsize)}; -char *filename;int fdt_size;void *fdt;uint8_t hypercall[16 ];
@@ -113,12 +112,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,0x20000000 ,0x1000000 ,0x0 ,0x0 ,0xe1000000 , 0x0, 0x10000 }; - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE ); -if (!filename) { - goto out; - } - fdt =load_device_tree (filename, &fdt_size); -g_free (filename); + fdt =create_device_tree (&fdt_size);if (fdt ==NULL ) { goto out; }
pc-bios/mpc8544ds.dtb deleted binary +0 -0
pc-bios/mpc8544ds.dts deleted +0 -14
@@ -1,14 +0,0 @@ -/* - * MPC8544 DS Device Tree Source - * - * Copyright 2007, 2008 Freescale Semiconductor Inc. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - */ - -/dts-v1/; -/ { -};
Signature · 1 line
1.6.0.2
PATCH 21/31 dt: Add -machine dumpdtb option to dump the current dtb
In reply to Alexander GrafNow that we are dynamically creating the dtb, it's really useful to be able to dump the created blob for debugging.
This patch implements a -machine dumpdtb=<file> option for e500 that dumps the dtb exactly in the form the guest would get it to disk. It can then be analyzed by dtc to get information about the guest configuration.
--- hw/ppce500_mpc8544ds.c | 18 ++++++++++++++++++ qemu-config.c | 4 ++++ 2 files changed, 22 insertions(+), 0 deletions(-)
hw/ppce500_mpc8544ds.c +18 -0
@@ -111,6 +111,8 @@ static int mpc8544_load_device_tree(CPUPPCState *env,uint32_t pci_ranges[12 ] = {0x2000000 ,0x0 ,0xc0000000 ,0xc0000000 ,0x0 ,0x20000000 ,0x1000000 ,0x0 ,0x0 ,0xe1000000 ,0x0 ,0x10000 }; +QemuOpts *machine_opts; +const char *dumpdtb =NULL ; fdt =create_device_tree (&fdt_size);if (fdt ==NULL ) {
@@ -300,6 +302,22 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_setprop_cell (fdt, pci,"#address-cells" ,3 );qemu_devtree_setprop_string (fdt,"/aliases" ,"pci0" , pci); + machine_opts =qemu_opts_find (qemu_find_opts ("machine" ),0 ); +if (machine_opts) { + dumpdtb =qemu_opt_get (machine_opts,"dumpdtb" ); + } +if (dumpdtb) { +/* Dump the dtb to a file and quit */ +FILE *f =fopen (dumpdtb,"wb" ); +size_t len; + len =fwrite (fdt, fdt_size,1 , f); +fclose (f); +if (len != fdt_size) { +exit (1 ); + } +exit (0 ); + } + ret =rom_add_blob_fixed (BINARY_DEVICE_TREE_FILE , fdt, fdt_size, addr);if (ret <0 ) { goto out;
qemu-config.c +4 -0
@@ -583,6 +583,10 @@ static QemuOptsList qemu_machine_opts = { .name = "dtb", .type = QEMU_OPT_STRING, .help = "Linux kernel device tree file", + }, { + .name = "dumpdtb", + .type = QEMU_OPT_STRING, + .help = "Dump current dtb to a file and quit", }, {/* End of list */ } },
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 21/31] dt: Add -machine dumpdtb option to dump the current dtb
Quoted 13 lines · Alexander Graf
Now that we are dynamically creating the dtb, it's really useful to be able to dump the created blob for debugging.
hw/ppce500_mpc8544ds.c +6
-0@@ -300,6 +302,22 @@ static int mpc8544_load_device_tree(CPUPPCState *env, qemu_devtree_setprop_cell(fdt, pci, "#address-cells", 3); qemu_devtree_setprop_string(fdt, "/aliases", "pci0", pci); + machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0); + if (machine_opts) { + dumpdtb = qemu_opt_get(machine_opts, "dumpdtb"); + } + if (dumpdtb) { + /* Dump the dtb to a file and quit */
hw/ppce500_mpc8544ds.c static int mpc8544_load_device_tree(CPUPPCState *env, · line 320
Quoted 10 lines
hw/ppce500_mpc8544ds.c +10
-0+ FILE *f = fopen(dumpdtb, "wb"); + size_t len; + len = fwrite(fdt, fdt_size, 1, f); + fclose(f); + if (len != fdt_size) { + exit(1); + } + exit(0); + } +
Maybe this should be abstracted out into a subfunction somewhere? I'm guessing there might be more than one machine in the future that wants a dumpable device tree.
-- PMM
Re: [Qemu-devel] [PATCH 21/31] dt: Add -machine dumpdtb option to dump the current dtb
Quoted 20 lines · Peter Maydell
Quoted 19 lines · Alexander Graf
Now that we are dynamically creating the dtb, it's really useful to be able to dump the created blob for debugging.
hw/ppce500_mpc8544ds.c +12
-0@@ -300,6 +302,22 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_setprop_cell (fdt, pci,"#address-cells" ,3 );qemu_devtree_setprop_string (fdt,"/aliases" ,"pci0" , pci); + machine_opts =qemu_opts_find (qemu_find_opts ("machine" ),0 ); +if (machine_opts) { + dumpdtb =qemu_opt_get (machine_opts,"dumpdtb" ); + } +if (dumpdtb) { +/* Dump the dtb to a file and quit */ +FILE *f =fopen (dumpdtb,"wb" ); +size_t len; + len =fwrite (fdt, fdt_size,1 , f); +fclose (f); +if (len != fdt_size) { +exit (1 );
Quoted 8 lines
hw/ppce500_mpc8544ds.c static int mpc8544_load_device_tree(CPUPPCState *env, · line 320
Quoted 4 lines
hw/ppce500_mpc8544ds.c +4
-0+ } +exit (0 ); + } +Maybe this should be abstracted out into a subfunction somewhere? I'm guessing there might be more than one machine in the future that wants a dumpable device tree.
Yup, that should be done with the second machine that allows this option. Basically the second one that implements dynamic device tree generation. If you beat me to it, that'd mean you generalize it. Otherwise I'd do it on bamboo :).
Alex
PATCH 22/31 PPC: e500: dt: use 64bit cell helper
In reply to Alexander GrafWe have a nice 64bit helper to ease the device tree generation and make the code more readable when creating 64bit 2-cell parameters. Use it when generating the device tree.
---
v1 -> v2:
- rename cell64 -> u64
- don't treat memory as single u64
--- hw/ppce500_mpc8544ds.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
hw/ppce500_mpc8544ds.c +3 -3
@@ -174,7 +174,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,the first node as boot node and be happy */ for (i = smp_cpus -1 ; i >=0 ; i--) {char cpu_name[128 ]; -uint64_t cpu_release_addr =cpu_to_be64 (MPC8544_SPIN_BASE + (i *0x20 )); +uint64_t cpu_release_addr =MPC8544_SPIN_BASE + (i *0x20 );for (env = first_cpu; env !=NULL ; env = env->next_cpu) {if (env->cpu_index == i) {
@@ -202,8 +202,8 @@ static int mpc8544_load_device_tree(CPUPPCState *env,if (env->cpu_index) {qemu_devtree_setprop_string (fdt, cpu_name,"status" ,"disabled" );qemu_devtree_setprop_string (fdt, cpu_name,"enable-method" ,"spin-table" ); -qemu_devtree_setprop (fdt, cpu_name,"cpu-release-addr" , - &cpu_release_addr,sizeof (cpu_release_addr)); +qemu_devtree_setprop_u64 (fdt, cpu_name,"cpu-release-addr" , + cpu_release_addr); }else {qemu_devtree_setprop_string (fdt, cpu_name,"status" ,"okay" ); }
Signature · 1 line
1.6.0.2
PATCH 23/31 PPC: e500: dt: use target_phys_addr_t for ramsize
In reply to Alexander GrafWe're passing the ram size as uint32_t, capping it to 32 bits atm. Change to target_phys_addr_t (uint64_t) to make sure we have all the bits.
--- hw/ppce500_mpc8544ds.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/ppce500_mpc8544ds.c +1 -1
@@ -85,7 +85,7 @@ static void pci_map_create(void *fdt, uint32_t *pci_map, uint32_t mpic)static int mpc8544_load_device_tree (CPUPPCState *env,target_phys_addr_t addr, -uint32_t ramsize, +target_phys_addr_t ramsize,target_phys_addr_t initrd_base,target_phys_addr_t initrd_size,const char *kernel_cmdline)
Signature · 1 line
1.6.0.2
PATCH 24/31 PPC: e500: enable manual loading of dtb blob
In reply to Alexander GrafWe want to be able to override the automatically created device tree by using the -dtb option. Implement this for the mpc8544ds machine.
--- hw/ppce500_mpc8544ds.c | 26 ++++++++++++++++++++++---- 1 files changed, 22 insertions(+), 4 deletions(-)
hw/ppce500_mpc8544ds.c +22 -4
@@ -113,6 +113,27 @@ static int mpc8544_load_device_tree(CPUPPCState *env, 0x0, 0x10000 };QemuOpts *machine_opts;const char *dumpdtb =NULL ; +const char *dtb_file =NULL ; + + machine_opts =qemu_opts_find (qemu_find_opts ("machine" ),0 ); +if (machine_opts) { + dumpdtb =qemu_opt_get (machine_opts,"dumpdtb" ); + dtb_file =qemu_opt_get (machine_opts,"dtb" ); + } + +if (dtb_file) { +char *filename; + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , dtb_file); +if (!filename) { + goto out; + } + + fdt =load_device_tree (filename, &fdt_size); +if (!fdt) { + goto out; + } + goto done; + } fdt =create_device_tree (&fdt_size);if (fdt ==NULL ) {
@@ -302,10 +323,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_setprop_cell (fdt, pci,"#address-cells" ,3 );qemu_devtree_setprop_string (fdt,"/aliases" ,"pci0" , pci); - machine_opts =qemu_opts_find (qemu_find_opts ("machine" ),0 ); -if (machine_opts) { - dumpdtb =qemu_opt_get (machine_opts,"dumpdtb" ); - } +done:if (dumpdtb) {/* Dump the dtb to a file and quit */ FILE *f =fopen (dumpdtb,"wb" );
Signature · 1 line
1.6.0.2
PATCH 25/31 Revert "dt: temporarily disable subtree creation failure check"
In reply to Alexander GrafThis reverts commit "dt: temporarily disable subtree creation failure check" which was meant as a temporary solution to keep external and dynamic device tree construction intact.
Now that we switched to fully dynamic dt construction, it's no longer necessary.
---
v1 -> v2:
- remove commit id from patch description
--- device_tree.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
device_tree.c +0 -2
@@ -239,13 +239,11 @@ int qemu_devtree_add_subnode(void *fdt, const char *name) } retval =fdt_add_subnode (fdt, parent, basename); -#if 0 if (retval <0 ) {fprintf (stderr,"FDT: Failed to create subnode %s: %s\n" , name,fdt_strerror (retval));exit (1 ); } -#endif g_free (dupname);return retval;
Signature · 1 line
1.6.0.2
PATCH 26/31 PPC: e500: Use new MPIC dt format
In reply to Alexander GrafDue to popular demand, we're updating the way we generate the MPIC node and interrupt lines based on what the current state of art is.
--- hw/ppce500_mpc8544ds.c | 33 ++++++++++++++++++--------------- 1 files changed, 18 insertions(+), 15 deletions(-)
hw/ppce500_mpc8544ds.c +18 -15
@@ -67,18 +67,18 @@ static void pci_map_create(void *fdt, uint32_t *pci_map, uint32_t mpic)int i;const uint32_t tmp[] = {/* IDSEL 0x11 J17 Slot 1 */ -0x8800 ,0x0 ,0x0 ,0x1 , mpic,0x2 ,0x1 , -0x8800 ,0x0 ,0x0 ,0x2 , mpic,0x3 ,0x1 , -0x8800 ,0x0 ,0x0 ,0x3 , mpic,0x4 ,0x1 , -0x8800 ,0x0 ,0x0 ,0x4 , mpic,0x1 ,0x1 , +0x8800 ,0x0 ,0x0 ,0x1 , mpic,0x2 ,0x1 ,0x0 ,0x0 , +0x8800 ,0x0 ,0x0 ,0x2 , mpic,0x3 ,0x1 ,0x0 ,0x0 , +0x8800 ,0x0 ,0x0 ,0x3 , mpic,0x4 ,0x1 ,0x0 ,0x0 , +0x8800 ,0x0 ,0x0 ,0x4 , mpic,0x1 ,0x1 ,0x0 ,0x0 ,/* IDSEL 0x12 J16 Slot 2 */ -0x9000 ,0x0 ,0x0 ,0x1 , mpic,0x3 ,0x1 , -0x9000 ,0x0 ,0x0 ,0x2 , mpic,0x4 ,0x1 , -0x9000 ,0x0 ,0x0 ,0x3 , mpic,0x2 ,0x1 , -0x9000 ,0x0 ,0x0 ,0x4 , mpic,0x1 ,0x1 , +0x9000 ,0x0 ,0x0 ,0x1 , mpic,0x3 ,0x1 ,0x0 ,0x0 , +0x9000 ,0x0 ,0x0 ,0x2 , mpic,0x4 ,0x1 ,0x0 ,0x0 , +0x9000 ,0x0 ,0x0 ,0x3 , mpic,0x2 ,0x1 ,0x0 ,0x0 , +0x9000 ,0x0 ,0x0 ,0x4 , mpic,0x1 ,0x1 ,0x0 ,0x0 , }; -for (i =0 ; i < (7 *8 ); i++) { +for (i =0 ; i <ARRAY_SIZE (tmp); i++) { pci_map[i] =cpu_to_be32 (tmp[i]); } }
@@ -107,7 +107,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,uint32_t mpic_ph;char gutil[128 ];char pci[128 ]; -uint32_t pci_map[7 *8 ]; +uint32_t pci_map[9 *8 ];uint32_t pci_ranges[12 ] = {0x2000000 ,0x0 ,0xc0000000 ,0xc0000000 ,0x0 ,0x20000000 ,0x1000000 ,0x0 ,0x0 ,0xe1000000 ,0x0 ,0x10000 };
@@ -249,15 +249,18 @@ static int mpc8544_load_device_tree(CPUPPCState *env, MPC8544_MPIC_REGS_BASE - MPC8544_CCSRBAR_BASE);qemu_devtree_add_subnode (fdt, mpic);qemu_devtree_setprop_string (fdt, mpic,"device_type" ,"open-pic" ); -qemu_devtree_setprop_string (fdt, mpic,"compatible" ,"chrp,open-pic" ); +qemu_devtree_setprop_string (fdt, mpic,"compatible" ,"fsl,mpic" );qemu_devtree_setprop_cells (fdt, mpic,"reg" ,MPC8544_MPIC_REGS_BASE -MPC8544_CCSRBAR_BASE ,0x40000 );qemu_devtree_setprop_cell (fdt, mpic,"#address-cells" ,0 ); -qemu_devtree_setprop_cell (fdt, mpic,"#interrupt-cells" ,2 ); +qemu_devtree_setprop_cell (fdt, mpic,"#interrupt-cells" ,4 ); mpic_ph =qemu_devtree_alloc_phandle (fdt);qemu_devtree_setprop_cell (fdt, mpic,"phandle" , mpic_ph);qemu_devtree_setprop_cell (fdt, mpic,"linux,phandle" , mpic_ph);qemu_devtree_setprop (fdt, mpic,"interrupt-controller" ,NULL ,0 ); +qemu_devtree_setprop (fdt, mpic,"big-endian" ,NULL ,0 ); +qemu_devtree_setprop (fdt, mpic,"single-cpu-affinity" ,NULL ,0 ); +qemu_devtree_setprop_cell (fdt, mpic,"last-interrupt-source" ,255 );/* * We have to generate ser1 first, because Linux takes the first
@@ -273,7 +276,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env, MPC8544_CCSRBAR_BASE, 0x100);qemu_devtree_setprop_cell (fdt, ser1,"cell-index" ,1 );qemu_devtree_setprop_cell (fdt, ser1,"clock-frequency" ,0 ); -qemu_devtree_setprop_cells (fdt, ser1,"interrupts" ,42 ,2 ); +qemu_devtree_setprop_cells (fdt, ser1,"interrupts" ,42 ,2 ,0 ,0 );qemu_devtree_setprop_phandle (fdt, ser1,"interrupt-parent" , mpic);qemu_devtree_setprop_string (fdt,"/aliases" ,"serial1" , ser1);
@@ -286,7 +289,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env, MPC8544_CCSRBAR_BASE, 0x100);qemu_devtree_setprop_cell (fdt, ser0,"cell-index" ,0 );qemu_devtree_setprop_cell (fdt, ser0,"clock-frequency" ,0 ); -qemu_devtree_setprop_cells (fdt, ser0,"interrupts" ,42 ,2 ); +qemu_devtree_setprop_cells (fdt, ser0,"interrupts" ,42 ,2 ,0 ,0 );qemu_devtree_setprop_phandle (fdt, ser0,"interrupt-parent" , mpic);qemu_devtree_setprop_string (fdt,"/aliases" ,"serial0" , ser0);qemu_devtree_setprop_string (fdt,"/chosen" ,"linux,stdout-path" , ser0);
@@ -309,7 +312,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,pci_map_create (fdt, pci_map,qemu_devtree_get_phandle (fdt, mpic));qemu_devtree_setprop (fdt, pci,"interrupt-map" , pci_map,sizeof (pci_map));qemu_devtree_setprop_phandle (fdt, pci,"interrupt-parent" , mpic); -qemu_devtree_setprop_cells (fdt, pci,"interrupts" ,24 ,2 ); +qemu_devtree_setprop_cells (fdt, pci,"interrupts" ,24 ,2 ,0 ,0 );qemu_devtree_setprop_cells (fdt, pci,"bus-range" ,0 ,255 );for (i =0 ; i <12 ; i++) { pci_ranges[i] =cpu_to_be32 (pci_ranges[i]);
Signature · 1 line
1.6.0.2
PATCH 27/31 PPC: e500: Use new SOC dt format
In reply to Alexander GrafDue to popular demand, let's clean up the soc node a bit and use more recent dt notions.
--- hw/ppce500_mpc8544ds.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
hw/ppce500_mpc8544ds.c +4 -5
@@ -43,7 +43,6 @@#define RAM_SIZES_ALIGN (64UL << 20)#define MPC8544_CCSRBAR_BASE 0xE0000000 -#define MPC8544_CCSRBAR_REGSIZE 0x00001000#define MPC8544_CCSRBAR_SIZE 0x00100000#define MPC8544_MPIC_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x40000)#define MPC8544_SERIAL0_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x4500)
@@ -99,6 +98,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,uint32_t tb_freq =400000000 ;int i;char compatible[] ="MPC8544DS\0MPC85xxDS" ; +char compatible_sb[] ="fsl,mpc8544-immr\0simple-bus" ;char model[] ="MPC8544DS" ;char soc[128 ];char ser0[128 ];
@@ -232,16 +232,15 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_add_subnode (fdt,"/aliases" );/* XXX These should go into their respective devices' code */ -snprintf (soc,sizeof (soc),"/soc8544@%x" ,MPC8544_CCSRBAR_BASE ); +snprintf (soc,sizeof (soc),"/soc@%x" ,MPC8544_CCSRBAR_BASE );qemu_devtree_add_subnode (fdt, soc);qemu_devtree_setprop_string (fdt, soc,"device_type" ,"soc" ); -qemu_devtree_setprop_string (fdt, soc,"compatible" ,"simple-bus" ); +qemu_devtree_setprop (fdt, soc,"compatible" , compatible_sb, +sizeof (compatible_sb));qemu_devtree_setprop_cell (fdt, soc,"#address-cells" ,1 );qemu_devtree_setprop_cell (fdt, soc,"#size-cells" ,1 );qemu_devtree_setprop_cells (fdt, soc,"ranges" ,0x0 ,MPC8544_CCSRBAR_BASE ,MPC8544_CCSRBAR_SIZE ); -qemu_devtree_setprop_cells (fdt, soc,"reg" ,MPC8544_CCSRBAR_BASE , -MPC8544_CCSRBAR_REGSIZE );/* XXX should contain a reasonable value */ qemu_devtree_setprop_cell (fdt, soc,"bus-frequency" ,0 );
Signature · 1 line
1.6.0.2
PATCH 28/31 PPC: e500: Define addresses as always 64bit
In reply to Alexander GrafEvery time we use an address constant, it needs to potentially fit into a 64bit physical address space. So let's define things accordingly.
--- hw/ppce500_mpc8544ds.c | 34 +++++++++++++++++----------------- 1 files changed, 17 insertions(+), 17 deletions(-)
hw/ppce500_mpc8544ds.c +17 -17
@@ -42,17 +42,17 @@#define RAM_SIZES_ALIGN (64UL << 20) -#define MPC8544_CCSRBAR_BASE 0xE0000000 -#define MPC8544_CCSRBAR_SIZE 0x00100000 -#define MPC8544_MPIC_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x40000) -#define MPC8544_SERIAL0_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x4500) -#define MPC8544_SERIAL1_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x4600) -#define MPC8544_PCI_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x8000) -#define MPC8544_PCI_REGS_SIZE 0x1000 -#define MPC8544_PCI_IO 0xE1000000 -#define MPC8544_PCI_IOLEN 0x10000 -#define MPC8544_UTIL_BASE (MPC8544_CCSRBAR_BASE + 0xe0000) -#define MPC8544_SPIN_BASE 0xEF000000 +#define MPC8544_CCSRBAR_BASE 0xE0000000ULL +#define MPC8544_CCSRBAR_SIZE 0x00100000ULL +#define MPC8544_MPIC_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x40000ULL) +#define MPC8544_SERIAL0_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x4500ULL) +#define MPC8544_SERIAL1_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x4600ULL) +#define MPC8544_PCI_REGS_BASE (MPC8544_CCSRBAR_BASE + 0x8000ULL) +#define MPC8544_PCI_REGS_SIZE 0x1000ULL +#define MPC8544_PCI_IO 0xE1000000ULL +#define MPC8544_PCI_IOLEN 0x10000ULL +#define MPC8544_UTIL_BASE (MPC8544_CCSRBAR_BASE + 0xe0000ULL) +#define MPC8544_SPIN_BASE 0xEF000000ULLstruct boot_info {
@@ -232,7 +232,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_add_subnode (fdt,"/aliases" );/* XXX These should go into their respective devices' code */ -snprintf (soc,sizeof (soc),"/soc@%x" ,MPC8544_CCSRBAR_BASE ); +snprintf (soc,sizeof (soc),"/soc@%llx" ,MPC8544_CCSRBAR_BASE );qemu_devtree_add_subnode (fdt, soc);qemu_devtree_setprop_string (fdt, soc,"device_type" ,"soc" ); qemu_devtree_setprop(fdt, soc, "compatible", compatible_sb,
@@ -244,7 +244,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,/* XXX should contain a reasonable value */ qemu_devtree_setprop_cell (fdt, soc,"bus-frequency" ,0 ); -snprintf (mpic,sizeof (mpic),"%s/pic@%x" , soc, +snprintf (mpic,sizeof (mpic),"%s/pic@%llx" , soc,MPC8544_MPIC_REGS_BASE -MPC8544_CCSRBAR_BASE );qemu_devtree_add_subnode (fdt, mpic);qemu_devtree_setprop_string (fdt, mpic,"device_type" ,"open-pic" );
@@ -266,7 +266,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,* device it finds in the dt as serial output device. And we generate * devices in reverse order to the dt. */ -snprintf (ser1,sizeof (ser1),"%s/serial@%x" , soc, +snprintf (ser1,sizeof (ser1),"%s/serial@%llx" , soc,MPC8544_SERIAL1_REGS_BASE -MPC8544_CCSRBAR_BASE );qemu_devtree_add_subnode (fdt, ser1);qemu_devtree_setprop_string (fdt, ser1,"device_type" ,"serial" );
@@ -279,7 +279,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_setprop_phandle (fdt, ser1,"interrupt-parent" , mpic);qemu_devtree_setprop_string (fdt,"/aliases" ,"serial1" , ser1); -snprintf (ser0,sizeof (ser0),"%s/serial@%x" , soc, +snprintf (ser0,sizeof (ser0),"%s/serial@%llx" , soc,MPC8544_SERIAL0_REGS_BASE -MPC8544_CCSRBAR_BASE );qemu_devtree_add_subnode (fdt, ser0);qemu_devtree_setprop_string (fdt, ser0,"device_type" ,"serial" );
@@ -293,7 +293,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_setprop_string (fdt,"/aliases" ,"serial0" , ser0);qemu_devtree_setprop_string (fdt,"/chosen" ,"linux,stdout-path" , ser0); -snprintf (gutil,sizeof (gutil),"%s/global-utilities@%x" , soc, +snprintf (gutil,sizeof (gutil),"%s/global-utilities@%llx" , soc,MPC8544_UTIL_BASE -MPC8544_CCSRBAR_BASE );qemu_devtree_add_subnode (fdt, gutil);qemu_devtree_setprop_string (fdt, gutil,"compatible" ,"fsl,mpc8544-guts" );
@@ -301,7 +301,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env, MPC8544_CCSRBAR_BASE, 0x1000);qemu_devtree_setprop (fdt, gutil,"fsl,has-rstcr" ,NULL ,0 ); -snprintf (pci,sizeof (pci),"/pci@%x" ,MPC8544_PCI_REGS_BASE ); +snprintf (pci,sizeof (pci),"/pci@%llx" ,MPC8544_PCI_REGS_BASE );qemu_devtree_add_subnode (fdt, pci);qemu_devtree_setprop_cell (fdt, pci,"cell-index" ,0 );qemu_devtree_setprop_string (fdt, pci,"compatible" ,"fsl,mpc8540-pci" );
Signature · 1 line
1.6.0.2
PATCH 29/31 PPC: e500: Extend address/size of / to 64bit
In reply to Alexander GrafWe want to be able to support >= 4GB of RAM. To do so, we need to be able to tell the guest OS how much RAM it has.
However, that information today is capped to 32bit. So let's extend the offset and size fields to 64bit, so we can fit in big addresses and even one day - if we wish to do so - map devices above 32bit.
--- hw/ppce500_mpc8544ds.c | 28 ++++++++++++++++++---------- 1 files changed, 18 insertions(+), 10 deletions(-)
hw/ppce500_mpc8544ds.c +18 -10
@@ -90,7 +90,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env, const char *kernel_cmdline) {int ret =-1 ; -uint32_t mem_reg_property[] = {0 ,cpu_to_be32 (ramsize)}; +uint64_t mem_reg_property[] = {0 ,cpu_to_be64 (ramsize) };int fdt_size;void *fdt;uint8_t hypercall[16 ];
@@ -108,9 +108,16 @@ static int mpc8544_load_device_tree(CPUPPCState *env,char gutil[128 ];char pci[128 ];uint32_t pci_map[9 *8 ]; -uint32_t pci_ranges[12 ] = {0x2000000 ,0x0 ,0xc0000000 ,0xc0000000 ,0x0 , -0x20000000 ,0x1000000 ,0x0 ,0x0 ,0xe1000000 , -0x0 ,0x10000 }; +uint32_t pci_ranges[14 ] = + { +0x2000000 ,0x0 ,0xc0000000 , +0x0 ,0xc0000000 , +0x0 ,0x20000000 , + +0x1000000 ,0x0 ,0x0 , +0x0 ,0xe1000000 , +0x0 ,0x10000 , + };QemuOpts *machine_opts;const char *dumpdtb =NULL ;const char *dtb_file =NULL ;
@@ -144,8 +151,8 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_setprop_string (fdt,"/" ,"model" , model);qemu_devtree_setprop (fdt,"/" ,"compatible" , compatible,sizeof (compatible)); -qemu_devtree_setprop_cell (fdt,"/" ,"#address-cells" ,1 ); -qemu_devtree_setprop_cell (fdt,"/" ,"#size-cells" ,1 ); +qemu_devtree_setprop_cell (fdt,"/" ,"#address-cells" ,2 ); +qemu_devtree_setprop_cell (fdt,"/" ,"#size-cells" ,2 );qemu_devtree_add_subnode (fdt,"/memory" );qemu_devtree_setprop_string (fdt,"/memory" ,"device_type" ,"memory" );
@@ -239,7 +246,8 @@ static int mpc8544_load_device_tree(CPUPPCState *env, sizeof(compatible_sb));qemu_devtree_setprop_cell (fdt, soc,"#address-cells" ,1 );qemu_devtree_setprop_cell (fdt, soc,"#size-cells" ,1 ); -qemu_devtree_setprop_cells (fdt, soc,"ranges" ,0x0 ,MPC8544_CCSRBAR_BASE , +qemu_devtree_setprop_cells (fdt, soc,"ranges" ,0x0 , +MPC8544_CCSRBAR_BASE >>32 ,MPC8544_CCSRBAR_BASE ,MPC8544_CCSRBAR_SIZE );/* XXX should contain a reasonable value */ qemu_devtree_setprop_cell (fdt, soc,"bus-frequency" ,0 );
@@ -313,12 +321,12 @@ static int mpc8544_load_device_tree(CPUPPCState *env,qemu_devtree_setprop_phandle (fdt, pci,"interrupt-parent" , mpic);qemu_devtree_setprop_cells (fdt, pci,"interrupts" ,24 ,2 ,0 ,0 );qemu_devtree_setprop_cells (fdt, pci,"bus-range" ,0 ,255 ); -for (i =0 ; i <12 ; i++) { +for (i =0 ; i <14 ; i++) { pci_ranges[i] =cpu_to_be32 (pci_ranges[i]); }qemu_devtree_setprop (fdt, pci,"ranges" , pci_ranges,sizeof (pci_ranges)); -qemu_devtree_setprop_cells (fdt, pci,"reg" ,MPC8544_PCI_REGS_BASE , -0x1000 ); +qemu_devtree_setprop_cells (fdt, pci,"reg" ,MPC8544_PCI_REGS_BASE >>32 , +MPC8544_PCI_REGS_BASE ,0 ,0x1000 );qemu_devtree_setprop_cell (fdt, pci,"clock-frequency" ,66666666 );qemu_devtree_setprop_cell (fdt, pci,"#interrupt-cells" ,1 );qemu_devtree_setprop_cell (fdt, pci,"#size-cells" ,2 );
Signature · 1 line
1.6.0.2
PATCH 30/31 dt: Add global option to set phandle start offset
In reply to Alexander GrafIf anyone outside of QEMU wants to mess with a QEMU generated device tree, he needs to know which range phandles are valid in. So let's expose a machine option that an external program can use to set the start allocate id for phandles in QEMU.
---
v2 -> v3:
- add correct header includes
--- device_tree.c | 28 +++++++++++++++++++++++++++- qemu-config.c | 4 ++++ 2 files changed, 31 insertions(+), 1 deletions(-)
device_tree.c +27 -1
@@ -22,6 +22,8 @@#include "qemu-common.h" #include "device_tree.h" #include "hw/loader.h" +#include "qemu-option.h" +#include "qemu-config.h" #include <libfdt.h>
@@ -200,7 +202,31 @@ int qemu_devtree_setprop_phandle(void *fdt, const char *node_path,uint32_t qemu_devtree_alloc_phandle (void *fdt) { -static int phandle =0x8000 ; +static int phandle =0x0 ; + +/* +* We need to find out if the user gave us special instruction at +* which phandle id to start allocting phandles. +*/ +if (!phandle) { +QemuOpts *machine_opts; + machine_opts =qemu_opts_find (qemu_find_opts ("machine" ),0 ); +if (machine_opts) { +const char *phandle_start; + phandle_start =qemu_opt_get (machine_opts,"phandle_start" ); +if (phandle_start) { + phandle =strtoul (phandle_start,NULL ,0 ); + } + } + } + +if (!phandle) { +/* +* None or invalid phandle given on the command line, so fall back to +* default starting point. +*/ + phandle =0x8000 ; + }return phandle++; }
qemu-config.c +4 -0
@@ -587,6 +587,10 @@ static QemuOptsList qemu_machine_opts = { .name = "dumpdtb", .type = QEMU_OPT_STRING, .help = "Dump current dtb to a file and quit", + }, { + .name = "phandle_start", + .type = QEMU_OPT_STRING, + .help = "The first phandle ID we may generate dynamically", }, {/* End of list */ } },
Signature · 1 line
1.6.0.2
PATCH 31/31 PPC: e500: Refactor serial dt generation
In reply to Alexander GrafWhen generating serial port device tree nodes, we duplicate quite a bit of code, because there are 2 of them in the mpc8544ds board we emulate.
Shove the generating code into a function, so we duplicate less code.
---
v2 -> v3:
- use snprintf
--- hw/ppce500_mpc8544ds.c | 54 +++++++++++++++++++++++------------------------ 1 files changed, 26 insertions(+), 28 deletions(-)
hw/ppce500_mpc8544ds.c +26 -28
@@ -82,6 +82,28 @@ static void pci_map_create(void *fdt, uint32_t *pci_map, uint32_t mpic) } } +static void dt_serial_create (void *fdt,unsigned long long offset, +const char *soc,const char *mpic, +const char *alias,int idx,bool defcon) +{ +char ser[128 ]; + +snprintf (ser,sizeof (ser),"%s/serial@%llx" , soc, offset); +qemu_devtree_add_subnode (fdt, ser); +qemu_devtree_setprop_string (fdt, ser,"device_type" ,"serial" ); +qemu_devtree_setprop_string (fdt, ser,"compatible" ,"ns16550" ); +qemu_devtree_setprop_cells (fdt, ser,"reg" , offset,0x100 ); +qemu_devtree_setprop_cell (fdt, ser,"cell-index" , idx); +qemu_devtree_setprop_cell (fdt, ser,"clock-frequency" ,0 ); +qemu_devtree_setprop_cells (fdt, ser,"interrupts" ,42 ,2 ,0 ,0 ); +qemu_devtree_setprop_phandle (fdt, ser,"interrupt-parent" , mpic); +qemu_devtree_setprop_string (fdt,"/aliases" , alias, ser); + +if (defcon) { +qemu_devtree_setprop_string (fdt,"/chosen" ,"linux,stdout-path" , ser); + } +} + static int mpc8544_load_device_tree(CPUPPCState *env, target_phys_addr_t addr, target_phys_addr_t ramsize,
@@ -101,8 +123,6 @@ static int mpc8544_load_device_tree(CPUPPCState *env,char compatible_sb[] ="fsl,mpc8544-immr\0simple-bus" ;char model[] ="MPC8544DS" ;char soc[128 ]; -char ser0[128 ]; -char ser1[128 ];char mpic[128 ];uint32_t mpic_ph;char gutil[128 ];
@@ -274,32 +294,10 @@ static int mpc8544_load_device_tree(CPUPPCState *env,* device it finds in the dt as serial output device. And we generate * devices in reverse order to the dt. */ -snprintf (ser1,sizeof (ser1),"%s/serial@%llx" , soc, -MPC8544_SERIAL1_REGS_BASE -MPC8544_CCSRBAR_BASE ); -qemu_devtree_add_subnode (fdt, ser1); -qemu_devtree_setprop_string (fdt, ser1,"device_type" ,"serial" ); -qemu_devtree_setprop_string (fdt, ser1,"compatible" ,"ns16550" ); -qemu_devtree_setprop_cells (fdt, ser1,"reg" ,MPC8544_SERIAL1_REGS_BASE - -MPC8544_CCSRBAR_BASE ,0x100 ); -qemu_devtree_setprop_cell (fdt, ser1,"cell-index" ,1 ); -qemu_devtree_setprop_cell (fdt, ser1,"clock-frequency" ,0 ); -qemu_devtree_setprop_cells (fdt, ser1,"interrupts" ,42 ,2 ,0 ,0 ); -qemu_devtree_setprop_phandle (fdt, ser1,"interrupt-parent" , mpic); -qemu_devtree_setprop_string (fdt,"/aliases" ,"serial1" , ser1); - -snprintf (ser0,sizeof (ser0),"%s/serial@%llx" , soc, -MPC8544_SERIAL0_REGS_BASE -MPC8544_CCSRBAR_BASE ); -qemu_devtree_add_subnode (fdt, ser0); -qemu_devtree_setprop_string (fdt, ser0,"device_type" ,"serial" ); -qemu_devtree_setprop_string (fdt, ser0,"compatible" ,"ns16550" ); -qemu_devtree_setprop_cells (fdt, ser0,"reg" ,MPC8544_SERIAL0_REGS_BASE - -MPC8544_CCSRBAR_BASE ,0x100 ); -qemu_devtree_setprop_cell (fdt, ser0,"cell-index" ,0 ); -qemu_devtree_setprop_cell (fdt, ser0,"clock-frequency" ,0 ); -qemu_devtree_setprop_cells (fdt, ser0,"interrupts" ,42 ,2 ,0 ,0 ); -qemu_devtree_setprop_phandle (fdt, ser0,"interrupt-parent" , mpic); -qemu_devtree_setprop_string (fdt,"/aliases" ,"serial0" , ser0); -qemu_devtree_setprop_string (fdt,"/chosen" ,"linux,stdout-path" , ser0); +dt_serial_create (fdt,MPC8544_SERIAL1_REGS_BASE -MPC8544_CCSRBAR_BASE , + soc, mpic,"serial1" ,1 , false); +dt_serial_create (fdt,MPC8544_SERIAL0_REGS_BASE -MPC8544_CCSRBAR_BASE , + soc, mpic,"serial0" ,0 , true);snprintf (gutil,sizeof (gutil),"%s/global-utilities@%llx" , soc,MPC8544_UTIL_BASE -MPC8544_CCSRBAR_BASE );
Signature · 1 line
1.6.0.2
Am 19.06.2012 21:14, schrieb Alexander Graf:
Quoted 12 lines
v1 -> v2:
- rename cell64 -> u64
- don't treat memory as single u64
- remove commit id from patch description
- NEW: PPC: e500: Use new MPIC dt format
PPC: e500: Use new SOC dt format
PPC: e500: Define addresses as always 64bit
PPC: e500: Extend address/size of / to 64bit
dt: Add global option to set phandle start offset
PPC: e500: Refactor serial dt generation
Quoted 6 lines
v2 -> v3:
- [phandle helper] rename "string" to
target_node_path
- [phandle helper] add correct header includes
- use snprintf
- create and use new multi-cell setting api
Gentle reminder: --subject-prefix="PATCH v3"
Otherwise they're indistinguishable in Patchwork and in search results within our inboxes.
/-F
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg