add qemu_fdt_setprop_strings() and use it in most places
Subsystems (2)
Add a helper for qemu_fdt_setprop_strings() to take a set of strings to put into a device-tree, which removes several open-coded methods such as setting an char arr[] = {..} or setting char val[] = "str\0str2";
This is for hw/arm, hw/mips and hw/riscv as well as a couple of cores. It is not fully tested over all of those, I may not have caught all places this is to be replaced.
Changes:
v4:
- fix checkpatch issues
- remove error checking in hw/core/guest-loader.c
v3:
- fix return value for the call
- add better help text
v2:
- fix node/path in comment
PATCH v4 1/6 device_tree: add qemu_fdt_setprop_strings() helper
Add a helper to set a property from a set of strings to reduce the following code:
static const char * const clint_compat[2] = {
"sifive,clint0", "riscv,clint0"
};
qemu_fdt_setprop_string_array(fdt, nodename, "compatible",
(char **)&clint_compat, ARRAY_SIZE(clint_compat));---
v4:
- go back to the non-return call, no-one is using the result
v3;
- fix return value for the call
- add better help text
v2:
- fix node/path in comment
--- include/sysemu/device_tree.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
include/sysemu/device_tree.h +19 -0
@@ -87,6 +87,25 @@ int qemu_fdt_setprop_string(void *fdt, const char *node_path,int qemu_fdt_setprop_string_array (void *fdt,const char *node_path,const char *prop,char **array,int len); +/** +* qemu_fdt_setprop_strings: set a property from a set of strings +* +* @fdt: pointer to the dt blob +* @path: node name +* @prop: property array +* +* This is a helper for the qemu_fdt_setprop_string_array() function +* which takes a va-arg set of strings instead of having to setup a +* single use string array. +*/ +#define qemu_fdt_setprop_strings (fdt, path, prop, ...) \ + do { \ + static const char * const __strs[] = { __VA_ARGS__ }; \ + qemu_fdt_setprop_string_array(fdt, path, prop, \ + (char **)&__strs, ARRAY_SIZE(__strs)); \ + } while(0) + +int qemu_fdt_setprop_phandle (void *fdt,const char *node_path,const char *property,const char *target_node_path);
Signature · 1 line
2.35.1
Re: [PATCH v4 1/6] device_tree: add qemu_fdt_setprop_strings() helper
Quoted 35 lines · Ben Dooks
Add a helper to set a property from a set of strings to reduce the following code:
static const char * const clint_compat[2] = { "sifive,clint0", "riscv,clint0" }; qemu_fdt_setprop_string_array(fdt, nodename, "compatible", (char **)&clint_compat, ARRAY_SIZE(clint_compat));Signed-off-by Ben Dooks <[email protected]>---
v4:
- go back to the non-return call, no-one is using the result
v3;
- fix return value for the call
- add better help text
v2:
- fix node/path in comment--- include/sysemu/device_tree.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)include/sysemu/device_tree.h +4
-0@@ -87,6 +87,25 @@ int qemu_fdt_setprop_string(void *fdt, const char *node_path,int qemu_fdt_setprop_string_array (void *fdt,const char *node_path,const char *prop,char **array,int len); +/** +* qemu_fdt_setprop_strings: set a property from a set of strings +* +* @fdt: pointer to the dt blob
include/sysemu/device_tree.h int qemu_fdt_setprop_string(void *fdt, const char *node_path, · line 103
Quoted 10 lines
include/sysemu/device_tree.h +10
-0+* @path: node name +* @prop: property array +* +* This is a helper for the qemu_fdt_setprop_string_array() function +* which takes a va-arg set of strings instead of having to setup a +* single use string array. +*/ +#define qemu_fdt_setprop_strings (fdt, path, prop, ...) \ + do { \ + static const char * const __strs[] = { __VA_ARGS__ }; \
^^ We don't want that static there. That'll keep the storage for each invocation and require that __VA_ARGS__ are always constants only.
I'd drop the const's too since __strs is only used for a single call where it immediately gets the const's cast'ed away.
include/sysemu/device_tree.h int qemu_fdt_setprop_string(void *fdt, const char *node_path, · line 105
Quoted 2 lines
include/sysemu/device_tree.h +2
-0+qemu_fdt_setprop_string_array (fdt, path, prop, \ + (char **)&__strs,ARRAY_SIZE (__strs)); \
^^ And then this can just be __strs
Quoted 10 lines
include/sysemu/device_tree.h +3
-0+ }while (0 ) + + int qemu_fdt_setprop_phandle(void *fdt, const char *node_path, const char *property, const char *target_node_path);Signature · 1 line
2.35.1
Thanks,
drew
PATCH v4 2/6 hw/core: don't check return on qemu_fdt_setprop_string_array()
In reply to Ben DooksThe qemu_fdt_setprop_string_array() does not return error codes and will call exit() if any of the fdt calls fails (and should print an error with the node being altered). This is done to prepare for the change for qemu_fdt_setprop_strings() helper which does not return any error codes (hw/core/guest-loader.c is the only place where an return is checked).
--- hw/core/guest-loader.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
hw/core/guest-loader.c +7 -15
@@ -57,25 +57,17 @@ static void loader_insert_platform_data(GuestLoaderState *s, int size,if (s->kernel) {const char *compat[2 ] = {"multiboot,module" ,"multiboot,kernel" }; -if (qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)) <0 ) { -error_setg (errp,"couldn't set %s/compatible" , node); -return ; - } +qemu_fdt_setprop_string_array (fdt, node,"compatible" , + (char **) &compat, +ARRAY_SIZE (compat));if (s->args) { -if (qemu_fdt_setprop_string (fdt, node,"bootargs" , s->args) <0 ) { -error_setg (errp,"couldn't set %s/bootargs" , node); - } +qemu_fdt_setprop_string (fdt, node,"bootargs" , s->args); } }else if (s->initrd) {const char *compat[2 ] = {"multiboot,module" ,"multiboot,ramdisk" }; -if (qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)) <0 ) { -error_setg (errp,"couldn't set %s/compatible" , node); -return ; - } +qemu_fdt_setprop_string_array (fdt, node,"compatible" , + (char **) &compat, +ARRAY_SIZE (compat)); } }
Signature · 1 line
2.35.1
Re: [PATCH v4 2/6] hw/core: don't check return on qemu_fdt_setprop_string_array()
Quoted 53 lines · Ben Dooks
The
qemu_fdt_setprop_string_array()does not return error codes and will callexit()if any of the fdt calls fails (and should print an error with the node being altered). This is done to prepare for the change forqemu_fdt_setprop_strings()helper which does not return any error codes (hw/core/guest-loader.cis the only place where an return is checked).Signed-off-by Ben Dooks <[email protected]>--- hw/core/guest-loader.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)hw/core/guest-loader.c +7
-15@@ -57,25 +57,17 @@ static void loader_insert_platform_data(GuestLoaderState *s, int size,if (s->kernel) {const char *compat[2 ] = {"multiboot,module" ,"multiboot,kernel" }; -if (qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)) <0 ) { -error_setg (errp,"couldn't set %s/compatible" , node); -return ; - } +qemu_fdt_setprop_string_array (fdt, node,"compatible" , + (char **) &compat, +ARRAY_SIZE (compat));if (s->args) { -if (qemu_fdt_setprop_string (fdt, node,"bootargs" , s->args) <0 ) { -error_setg (errp,"couldn't set %s/bootargs" , node); - } +qemu_fdt_setprop_string (fdt, node,"bootargs" , s->args); } }else if (s->initrd) {const char *compat[2 ] = {"multiboot,module" ,"multiboot,ramdisk" }; -if (qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)) <0 ) { -error_setg (errp,"couldn't set %s/compatible" , node); -return ; - } +qemu_fdt_setprop_string_array (fdt, node,"compatible" , + (char **) &compat, +ARRAY_SIZE (compat)); } }Signature · 1 line
2.35.1
Re: [PATCH v4 2/6] hw/core: don't check return on qemu_fdt_setprop_string_array()
In reply to Ben DooksQuoted 9 lines · Ben Dooks
The
qemu_fdt_setprop_string_array()does not return error codes and will callexit()if any of the fdt calls fails (and should print an error with the node being altered). This is done to prepare for the change forqemu_fdt_setprop_strings()helper which does not return any error codes (hw/core/guest-loader.cis the only place where an return is checked).Signed-off-by Ben Dooks <[email protected]>
Alistair
Quoted 45 lines
--- hw/core/guest-loader.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)hw/core/guest-loader.c +7
-16@@ -57,25 +57,17 @@ static void loader_insert_platform_data(GuestLoaderState *s, int size,if (s->kernel) {const char *compat[2 ] = {"multiboot,module" ,"multiboot,kernel" }; -if (qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)) <0 ) { -error_setg (errp,"couldn't set %s/compatible" , node); -return ; - } +qemu_fdt_setprop_string_array (fdt, node,"compatible" , + (char **) &compat, +ARRAY_SIZE (compat));if (s->args) { -if (qemu_fdt_setprop_string (fdt, node,"bootargs" , s->args) <0 ) { -error_setg (errp,"couldn't set %s/bootargs" , node); - } +qemu_fdt_setprop_string (fdt, node,"bootargs" , s->args); } }else if (s->initrd) {const char *compat[2 ] = {"multiboot,module" ,"multiboot,ramdisk" }; -if (qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)) <0 ) { -error_setg (errp,"couldn't set %s/compatible" , node); -return ; - } +qemu_fdt_setprop_string_array (fdt, node,"compatible" , + (char **) &compat, +ARRAY_SIZE (compat)); } } --2.35.1
PATCH v4 3/6 hw/riscv: use qemu_fdt_setprop_strings() for string arrays
In reply to Ben DooksUse the qemu_fdt_setprop_strings() in sifve_u.c to simplify the code.
--- hw/riscv/sifive_u.c | 18 +++++------------- hw/riscv/spike.c | 7 ++----- hw/riscv/virt.c | 32 ++++++++------------------------ 3 files changed, 15 insertions(+), 42 deletions(-)
hw/riscv/sifive_u.c +5 -13
@@ -103,13 +103,6 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,char *nodename;uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle =1 ;uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle; -static const char *const ethclk_names[2 ] = {"pclk" ,"hclk" }; -static const char *const clint_compat[2 ] = { -"sifive,clint0" ,"riscv,clint0" - }; -static const char *const plic_compat[2 ] = { -"sifive,plic-1.0.0" ,"riscv,plic0" - };if (ms->dtb) { fdt = s->fdt =load_device_tree (ms->dtb, &s->fdt_size);
@@ -221,11 +214,11 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, nodename =g_strdup_printf ("/soc/clint@%lx" , (long )memmap[SIFIVE_U_DEV_CLINT ].base);qemu_fdt_add_subnode (fdt, nodename); -qemu_fdt_setprop_string_array (fdt, nodename,"compatible" , - (char **)&clint_compat,ARRAY_SIZE (clint_compat));qemu_fdt_setprop_cells (fdt, nodename,"reg" ,0x0 , memmap[SIFIVE_U_DEV_CLINT ].base,0x0 , memmap[SIFIVE_U_DEV_CLINT ].size); +qemu_fdt_setprop_strings (fdt, nodename,"compatible" , +"sifive,clint0" ,"riscv,clint0" );qemu_fdt_setprop (fdt, nodename,"interrupts-extended" , cells, ms->smp.cpus *sizeof (uint32_t ) *4 );g_free (cells);
@@ -279,8 +272,8 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, (long)memmap[SIFIVE_U_DEV_PLIC].base);qemu_fdt_add_subnode (fdt, nodename);qemu_fdt_setprop_cell (fdt, nodename,"#interrupt-cells" ,1 ); -qemu_fdt_setprop_string_array (fdt, nodename,"compatible" , - (char **)&plic_compat,ARRAY_SIZE (plic_compat)); +qemu_fdt_setprop_strings (fdt, nodename,"compatbile" , +"sifive,plic-1.0.0" ,"riscv,plic0" );qemu_fdt_setprop (fdt, nodename,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop (fdt, nodename,"interrupts-extended" , cells, (ms->smp.cpus *4 -2 ) *sizeof (uint32_t ));
@@ -426,8 +419,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,qemu_fdt_setprop_cell (fdt, nodename,"interrupts" ,SIFIVE_U_GEM_IRQ );qemu_fdt_setprop_cells (fdt, nodename,"clocks" , prci_phandle,PRCI_CLK_GEMGXLPLL , prci_phandle,PRCI_CLK_GEMGXLPLL ); -qemu_fdt_setprop_string_array (fdt, nodename,"clock-names" , - (char **)ðclk_names,ARRAY_SIZE (ethclk_names)); +qemu_fdt_setprop_strings (fdt, nodename,"clock-names" ,"pclk" ,"hclk" );qemu_fdt_setprop (fdt, nodename,"local-mac-address" , s->soc.gem.conf.macaddr.a,ETH_ALEN );qemu_fdt_setprop_cell (fdt, nodename,"#address-cells" ,1 );
hw/riscv/spike.c +2 -5
@@ -59,9 +59,6 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,uint32_t cpu_phandle, intc_phandle, phandle =1 ;char *name, *mem_name, *clint_name, *clust_name;char *core_name, *cpu_name, *intc_name; -static const char *const clint_compat[2 ] = { -"sifive,clint0" ,"riscv,clint0" - }; fdt = s->fdt =create_device_tree (&s->fdt_size);if (!fdt) {
@@ -159,8 +156,8 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, (memmap[SPIKE_CLINT ].size * socket); clint_name =g_strdup_printf ("/soc/clint@%lx" , clint_addr);qemu_fdt_add_subnode (fdt, clint_name); -qemu_fdt_setprop_string_array (fdt, clint_name,"compatible" , - (char **)&clint_compat,ARRAY_SIZE (clint_compat)); +qemu_fdt_setprop_strings (fdt, clint_name,"compatible" , +"sifive,clint0" ,"riscv,clint0" );qemu_fdt_setprop_cells (fdt, clint_name,"reg" ,0x0 , clint_addr,0x0 , memmap[SPIKE_CLINT ].size); qemu_fdt_setprop(fdt, clint_name, "interrupts-extended",
hw/riscv/virt.c +8 -24
@@ -261,11 +261,8 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, intc_phandles[cpu]);if (riscv_feature (&s->soc[socket].harts[cpu].env,RISCV_FEATURE_AIA )) { -static const char *const compat[2 ] = { -"riscv,cpu-intc-aia" ,"riscv,cpu-intc" - }; -qemu_fdt_setprop_string_array (mc->fdt, intc_name,"compatible" , - (char **)&compat,ARRAY_SIZE (compat)); +qemu_fdt_setprop_strings (mc->fdt, intc_name,"compatible" , +"riscv,cpu-intc-aia" ,"riscv,cpu-intc" ); }else {qemu_fdt_setprop_string (mc->fdt, intc_name,"compatible" ,"riscv,cpu-intc" );
@@ -310,9 +307,6 @@ static void create_fdt_socket_clint(RISCVVirtState *s,uint32_t *clint_cells;unsigned long clint_addr;MachineState *mc =MACHINE (s); -static const char *const clint_compat[2 ] = { -"sifive,clint0" ,"riscv,clint0" - }; clint_cells =g_new0 (uint32_t, s->soc[socket].num_harts *4 );
@@ -326,9 +320,8 @@ static void create_fdt_socket_clint(RISCVVirtState *s, clint_addr = memmap[VIRT_CLINT ].base + (memmap[VIRT_CLINT ].size * socket); clint_name =g_strdup_printf ("/soc/clint@%lx" , clint_addr);qemu_fdt_add_subnode (mc->fdt, clint_name); -qemu_fdt_setprop_string_array (mc->fdt, clint_name,"compatible" , - (char **)&clint_compat, -ARRAY_SIZE (clint_compat)); +qemu_fdt_setprop_strings (mc->fdt, clint_name,"compatible" , +"sifive,clint0" ,"riscv,clint0" );qemu_fdt_setprop_cells (mc->fdt, clint_name,"reg" ,0x0 , clint_addr,0x0 , memmap[VIRT_CLINT ].size); qemu_fdt_setprop(mc->fdt, clint_name, "interrupts-extended",
@@ -437,9 +430,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s,uint32_t *plic_cells;unsigned long plic_addr;MachineState *mc =MACHINE (s); -static const char *const plic_compat[2 ] = { -"sifive,plic-1.0.0" ,"riscv,plic0" - };if (kvm_enabled ()) { plic_cells =g_new0 (uint32_t, s->soc[socket].num_harts *2 );
@@ -465,9 +455,8 @@ static void create_fdt_socket_plic(RISCVVirtState *s,qemu_fdt_add_subnode (mc->fdt, plic_name);qemu_fdt_setprop_cell (mc->fdt, plic_name,"#interrupt-cells" ,FDT_PLIC_INT_CELLS ); -qemu_fdt_setprop_string_array (mc->fdt, plic_name,"compatible" , - (char **)&plic_compat, -ARRAY_SIZE (plic_compat)); +qemu_fdt_setprop_strings (mc->fdt, plic_name,"compatible" , +"sifive,plic-1.0.0" ,"riscv,plic0" );qemu_fdt_setprop (mc->fdt, plic_name,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop (mc->fdt, plic_name,"interrupts-extended" , plic_cells, s->soc[socket].num_harts *sizeof (uint32_t ) *4 );
@@ -881,13 +870,8 @@ static void create_fdt_reset(RISCVVirtState *s, const MemMapEntry *memmap, name =g_strdup_printf ("/soc/test@%lx" , (long )memmap[VIRT_TEST ].base);qemu_fdt_add_subnode (mc->fdt, name); - { -static const char *const compat[3 ] = { -"sifive,test1" ,"sifive,test0" ,"syscon" - }; -qemu_fdt_setprop_string_array (mc->fdt, name,"compatible" , - (char **)&compat,ARRAY_SIZE (compat)); - } +qemu_fdt_setprop_strings (mc->fdt, name,"compatible" , +"sifive,test1" ,"sifive,test0" ,"syscon" );qemu_fdt_setprop_cells (mc->fdt, name,"reg" ,0x0 , memmap[VIRT_TEST ].base,0x0 , memmap[VIRT_TEST ].size);qemu_fdt_setprop_cell (mc->fdt, name,"phandle" , test_phandle);
Signature · 1 line
2.35.1
Re: [PATCH v4 3/6] hw/riscv: use qemu_fdt_setprop_strings() for string arrays
Quoted 28 lines · Ben Dooks
Use the
qemu_fdt_setprop_strings()insifve_u.cto simplify the code.Signed-off-by Ben Dooks <[email protected]>--- hw/riscv/sifive_u.c | 18 +++++------------- hw/riscv/spike.c | 7 ++----- hw/riscv/virt.c | 32 ++++++++------------------------ 3 files changed, 15 insertions(+), 42 deletions(-)hw/riscv/sifive_u.c +0
-7@@ -103,13 +103,6 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,char *nodename;uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle =1 ;uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle; -static const char *const ethclk_names[2 ] = {"pclk" ,"hclk" }; -static const char *const clint_compat[2 ] = { -"sifive,clint0" ,"riscv,clint0" - }; -static const char *const plic_compat[2 ] = { -"sifive,plic-1.0.0" ,"riscv,plic0" - };if (ms->dtb) { fdt = s->fdt =load_device_tree (ms->dtb, &s->fdt_size);
hw/riscv/sifive_u.c static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, · line 221
Quoted 10 lines
hw/riscv/sifive_u.c +2
-2@@ -221,11 +214,11 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, nodename =g_strdup_printf ("/soc/clint@%lx" , (long )memmap[SIFIVE_U_DEV_CLINT ].base);qemu_fdt_add_subnode (fdt, nodename); -qemu_fdt_setprop_string_array (fdt, nodename,"compatible" , - (char **)&clint_compat,ARRAY_SIZE (clint_compat));qemu_fdt_setprop_cells (fdt, nodename,"reg" ,0x0 , memmap[SIFIVE_U_DEV_CLINT ].base,0x0 , memmap[SIFIVE_U_DEV_CLINT ].size); +qemu_fdt_setprop_strings (fdt, nodename,"compatible" , +"sifive,clint0" ,"riscv,clint0" );
Why move this down?
Quoted 131 lines
hw/riscv/sifive_u.c +3
-4qemu_fdt_setprop (fdt, nodename,"interrupts-extended" , cells, ms->smp.cpus *sizeof (uint32_t ) *4 );g_free (cells);@@ -279,8 +272,8 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, (long)memmap[SIFIVE_U_DEV_PLIC].base);qemu_fdt_add_subnode (fdt, nodename);qemu_fdt_setprop_cell (fdt, nodename,"#interrupt-cells" ,1 ); -qemu_fdt_setprop_string_array (fdt, nodename,"compatible" , - (char **)&plic_compat,ARRAY_SIZE (plic_compat)); +qemu_fdt_setprop_strings (fdt, nodename,"compatbile" , +"sifive,plic-1.0.0" ,"riscv,plic0" );qemu_fdt_setprop (fdt, nodename,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop (fdt, nodename,"interrupts-extended" , cells, (ms->smp.cpus *4 -2 ) *sizeof (uint32_t ));@@ -426,8 +419,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,qemu_fdt_setprop_cell (fdt, nodename,"interrupts" ,SIFIVE_U_GEM_IRQ );qemu_fdt_setprop_cells (fdt, nodename,"clocks" , prci_phandle,PRCI_CLK_GEMGXLPLL , prci_phandle,PRCI_CLK_GEMGXLPLL ); -qemu_fdt_setprop_string_array (fdt, nodename,"clock-names" , - (char **)ðclk_names,ARRAY_SIZE (ethclk_names)); +qemu_fdt_setprop_strings (fdt, nodename,"clock-names" ,"pclk" ,"hclk" );qemu_fdt_setprop (fdt, nodename,"local-mac-address" , s->soc.gem.conf.macaddr.a,ETH_ALEN );qemu_fdt_setprop_cell (fdt, nodename,"#address-cells" ,1 );hw/riscv/spike.c +2
-5@@ -59,9 +59,6 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,uint32_t cpu_phandle, intc_phandle, phandle =1 ;char *name, *mem_name, *clint_name, *clust_name;char *core_name, *cpu_name, *intc_name; -static const char *const clint_compat[2 ] = { -"sifive,clint0" ,"riscv,clint0" - }; fdt = s->fdt =create_device_tree (&s->fdt_size);if (!fdt) {@@ -159,8 +156,8 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, (memmap[SPIKE_CLINT ].size * socket); clint_name =g_strdup_printf ("/soc/clint@%lx" , clint_addr);qemu_fdt_add_subnode (fdt, clint_name); -qemu_fdt_setprop_string_array (fdt, clint_name,"compatible" , - (char **)&clint_compat,ARRAY_SIZE (clint_compat)); +qemu_fdt_setprop_strings (fdt, clint_name,"compatible" , +"sifive,clint0" ,"riscv,clint0" );qemu_fdt_setprop_cells (fdt, clint_name,"reg" ,0x0 , clint_addr,0x0 , memmap[SPIKE_CLINT ].size); qemu_fdt_setprop(fdt, clint_name, "interrupts-extended",hw/riscv/virt.c +8
-24@@ -261,11 +261,8 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, intc_phandles[cpu]);if (riscv_feature (&s->soc[socket].harts[cpu].env,RISCV_FEATURE_AIA )) { -static const char *const compat[2 ] = { -"riscv,cpu-intc-aia" ,"riscv,cpu-intc" - }; -qemu_fdt_setprop_string_array (mc->fdt, intc_name,"compatible" , - (char **)&compat,ARRAY_SIZE (compat)); +qemu_fdt_setprop_strings (mc->fdt, intc_name,"compatible" , +"riscv,cpu-intc-aia" ,"riscv,cpu-intc" ); }else {qemu_fdt_setprop_string (mc->fdt, intc_name,"compatible" ,"riscv,cpu-intc" );@@ -310,9 +307,6 @@ static void create_fdt_socket_clint(RISCVVirtState *s,uint32_t *clint_cells;unsigned long clint_addr;MachineState *mc =MACHINE (s); -static const char *const clint_compat[2 ] = { -"sifive,clint0" ,"riscv,clint0" - }; clint_cells =g_new0 (uint32_t, s->soc[socket].num_harts *4 );@@ -326,9 +320,8 @@ static void create_fdt_socket_clint(RISCVVirtState *s, clint_addr = memmap[VIRT_CLINT ].base + (memmap[VIRT_CLINT ].size * socket); clint_name =g_strdup_printf ("/soc/clint@%lx" , clint_addr);qemu_fdt_add_subnode (mc->fdt, clint_name); -qemu_fdt_setprop_string_array (mc->fdt, clint_name,"compatible" , - (char **)&clint_compat, -ARRAY_SIZE (clint_compat)); +qemu_fdt_setprop_strings (mc->fdt, clint_name,"compatible" , +"sifive,clint0" ,"riscv,clint0" );qemu_fdt_setprop_cells (mc->fdt, clint_name,"reg" ,0x0 , clint_addr,0x0 , memmap[VIRT_CLINT ].size); qemu_fdt_setprop(mc->fdt, clint_name, "interrupts-extended",@@ -437,9 +430,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s,uint32_t *plic_cells;unsigned long plic_addr;MachineState *mc =MACHINE (s); -static const char *const plic_compat[2 ] = { -"sifive,plic-1.0.0" ,"riscv,plic0" - };if (kvm_enabled ()) { plic_cells =g_new0 (uint32_t, s->soc[socket].num_harts *2 );@@ -465,9 +455,8 @@ static void create_fdt_socket_plic(RISCVVirtState *s,qemu_fdt_add_subnode (mc->fdt, plic_name);qemu_fdt_setprop_cell (mc->fdt, plic_name,"#interrupt-cells" ,FDT_PLIC_INT_CELLS ); -qemu_fdt_setprop_string_array (mc->fdt, plic_name,"compatible" , - (char **)&plic_compat, -ARRAY_SIZE (plic_compat)); +qemu_fdt_setprop_strings (mc->fdt, plic_name,"compatible" , +"sifive,plic-1.0.0" ,"riscv,plic0" );qemu_fdt_setprop (mc->fdt, plic_name,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop (mc->fdt, plic_name,"interrupts-extended" , plic_cells, s->soc[socket].num_harts *sizeof (uint32_t ) *4 );@@ -881,13 +870,8 @@ static void create_fdt_reset(RISCVVirtState *s, const MemMapEntry *memmap, name =g_strdup_printf ("/soc/test@%lx" , (long )memmap[VIRT_TEST ].base);qemu_fdt_add_subnode (mc->fdt, name); - { -static const char *const compat[3 ] = { -"sifive,test1" ,"sifive,test0" ,"syscon" - }; -qemu_fdt_setprop_string_array (mc->fdt, name,"compatible" , - (char **)&compat,ARRAY_SIZE (compat)); - } +qemu_fdt_setprop_strings (mc->fdt, name,"compatible" , +"sifive,test1" ,"sifive,test0" ,"syscon" );qemu_fdt_setprop_cells (mc->fdt, name,"reg" ,0x0 , memmap[VIRT_TEST ].base,0x0 , memmap[VIRT_TEST ].size);qemu_fdt_setprop_cell (mc->fdt, name,"phandle" , test_phandle);Signature · 1 line
2.35.1
Other than the unnecessary line move
Re: [PATCH v4 3/6] hw/riscv: use qemu_fdt_setprop_strings() for string arrays
In reply to Ben DooksQuoted 4 lines · Ben Dooks
Use the
qemu_fdt_setprop_strings()insifve_u.cto simplify the code.Signed-off-by Ben Dooks <[email protected]>
Alistair
Quoted 166 lines
--- hw/riscv/sifive_u.c | 18 +++++------------- hw/riscv/spike.c | 7 ++----- hw/riscv/virt.c | 32 ++++++++------------------------ 3 files changed, 15 insertions(+), 42 deletions(-)hw/riscv/sifive_u.c +5
-13@@ -103,13 +103,6 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,char *nodename;uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle =1 ;uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle; -static const char *const ethclk_names[2 ] = {"pclk" ,"hclk" }; -static const char *const clint_compat[2 ] = { -"sifive,clint0" ,"riscv,clint0" - }; -static const char *const plic_compat[2 ] = { -"sifive,plic-1.0.0" ,"riscv,plic0" - };if (ms->dtb) { fdt = s->fdt =load_device_tree (ms->dtb, &s->fdt_size);@@ -221,11 +214,11 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, nodename =g_strdup_printf ("/soc/clint@%lx" , (long )memmap[SIFIVE_U_DEV_CLINT ].base);qemu_fdt_add_subnode (fdt, nodename); -qemu_fdt_setprop_string_array (fdt, nodename,"compatible" , - (char **)&clint_compat,ARRAY_SIZE (clint_compat));qemu_fdt_setprop_cells (fdt, nodename,"reg" ,0x0 , memmap[SIFIVE_U_DEV_CLINT ].base,0x0 , memmap[SIFIVE_U_DEV_CLINT ].size); +qemu_fdt_setprop_strings (fdt, nodename,"compatible" , +"sifive,clint0" ,"riscv,clint0" );qemu_fdt_setprop (fdt, nodename,"interrupts-extended" , cells, ms->smp.cpus *sizeof (uint32_t ) *4 );g_free (cells);@@ -279,8 +272,8 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, (long)memmap[SIFIVE_U_DEV_PLIC].base);qemu_fdt_add_subnode (fdt, nodename);qemu_fdt_setprop_cell (fdt, nodename,"#interrupt-cells" ,1 ); -qemu_fdt_setprop_string_array (fdt, nodename,"compatible" , - (char **)&plic_compat,ARRAY_SIZE (plic_compat)); +qemu_fdt_setprop_strings (fdt, nodename,"compatbile" , +"sifive,plic-1.0.0" ,"riscv,plic0" );qemu_fdt_setprop (fdt, nodename,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop (fdt, nodename,"interrupts-extended" , cells, (ms->smp.cpus *4 -2 ) *sizeof (uint32_t ));@@ -426,8 +419,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,qemu_fdt_setprop_cell (fdt, nodename,"interrupts" ,SIFIVE_U_GEM_IRQ );qemu_fdt_setprop_cells (fdt, nodename,"clocks" , prci_phandle,PRCI_CLK_GEMGXLPLL , prci_phandle,PRCI_CLK_GEMGXLPLL ); -qemu_fdt_setprop_string_array (fdt, nodename,"clock-names" , - (char **)ðclk_names,ARRAY_SIZE (ethclk_names)); +qemu_fdt_setprop_strings (fdt, nodename,"clock-names" ,"pclk" ,"hclk" );qemu_fdt_setprop (fdt, nodename,"local-mac-address" , s->soc.gem.conf.macaddr.a,ETH_ALEN );qemu_fdt_setprop_cell (fdt, nodename,"#address-cells" ,1 );hw/riscv/spike.c +2
-5@@ -59,9 +59,6 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,uint32_t cpu_phandle, intc_phandle, phandle =1 ;char *name, *mem_name, *clint_name, *clust_name;char *core_name, *cpu_name, *intc_name; -static const char *const clint_compat[2 ] = { -"sifive,clint0" ,"riscv,clint0" - }; fdt = s->fdt =create_device_tree (&s->fdt_size);if (!fdt) {@@ -159,8 +156,8 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, (memmap[SPIKE_CLINT ].size * socket); clint_name =g_strdup_printf ("/soc/clint@%lx" , clint_addr);qemu_fdt_add_subnode (fdt, clint_name); -qemu_fdt_setprop_string_array (fdt, clint_name,"compatible" , - (char **)&clint_compat,ARRAY_SIZE (clint_compat)); +qemu_fdt_setprop_strings (fdt, clint_name,"compatible" , +"sifive,clint0" ,"riscv,clint0" );qemu_fdt_setprop_cells (fdt, clint_name,"reg" ,0x0 , clint_addr,0x0 , memmap[SPIKE_CLINT ].size); qemu_fdt_setprop(fdt, clint_name, "interrupts-extended",hw/riscv/virt.c +8
-25@@ -261,11 +261,8 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, intc_phandles[cpu]);if (riscv_feature (&s->soc[socket].harts[cpu].env,RISCV_FEATURE_AIA )) { -static const char *const compat[2 ] = { -"riscv,cpu-intc-aia" ,"riscv,cpu-intc" - }; -qemu_fdt_setprop_string_array (mc->fdt, intc_name,"compatible" , - (char **)&compat,ARRAY_SIZE (compat)); +qemu_fdt_setprop_strings (mc->fdt, intc_name,"compatible" , +"riscv,cpu-intc-aia" ,"riscv,cpu-intc" ); }else {qemu_fdt_setprop_string (mc->fdt, intc_name,"compatible" ,"riscv,cpu-intc" );@@ -310,9 +307,6 @@ static void create_fdt_socket_clint(RISCVVirtState *s,uint32_t *clint_cells;unsigned long clint_addr;MachineState *mc =MACHINE (s); -static const char *const clint_compat[2 ] = { -"sifive,clint0" ,"riscv,clint0" - }; clint_cells =g_new0 (uint32_t, s->soc[socket].num_harts *4 );@@ -326,9 +320,8 @@ static void create_fdt_socket_clint(RISCVVirtState *s, clint_addr = memmap[VIRT_CLINT ].base + (memmap[VIRT_CLINT ].size * socket); clint_name =g_strdup_printf ("/soc/clint@%lx" , clint_addr);qemu_fdt_add_subnode (mc->fdt, clint_name); -qemu_fdt_setprop_string_array (mc->fdt, clint_name,"compatible" , - (char **)&clint_compat, -ARRAY_SIZE (clint_compat)); +qemu_fdt_setprop_strings (mc->fdt, clint_name,"compatible" , +"sifive,clint0" ,"riscv,clint0" );qemu_fdt_setprop_cells (mc->fdt, clint_name,"reg" ,0x0 , clint_addr,0x0 , memmap[VIRT_CLINT ].size); qemu_fdt_setprop(mc->fdt, clint_name, "interrupts-extended",@@ -437,9 +430,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s,uint32_t *plic_cells;unsigned long plic_addr;MachineState *mc =MACHINE (s); -static const char *const plic_compat[2 ] = { -"sifive,plic-1.0.0" ,"riscv,plic0" - };if (kvm_enabled ()) { plic_cells =g_new0 (uint32_t, s->soc[socket].num_harts *2 );@@ -465,9 +455,8 @@ static void create_fdt_socket_plic(RISCVVirtState *s,qemu_fdt_add_subnode (mc->fdt, plic_name);qemu_fdt_setprop_cell (mc->fdt, plic_name,"#interrupt-cells" ,FDT_PLIC_INT_CELLS ); -qemu_fdt_setprop_string_array (mc->fdt, plic_name,"compatible" , - (char **)&plic_compat, -ARRAY_SIZE (plic_compat)); +qemu_fdt_setprop_strings (mc->fdt, plic_name,"compatible" , +"sifive,plic-1.0.0" ,"riscv,plic0" );qemu_fdt_setprop (mc->fdt, plic_name,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop (mc->fdt, plic_name,"interrupts-extended" , plic_cells, s->soc[socket].num_harts *sizeof (uint32_t ) *4 );@@ -881,13 +870,8 @@ static void create_fdt_reset(RISCVVirtState *s, const MemMapEntry *memmap, name =g_strdup_printf ("/soc/test@%lx" , (long )memmap[VIRT_TEST ].base);qemu_fdt_add_subnode (mc->fdt, name); - { -static const char *const compat[3 ] = { -"sifive,test1" ,"sifive,test0" ,"syscon" - }; -qemu_fdt_setprop_string_array (mc->fdt, name,"compatible" , - (char **)&compat,ARRAY_SIZE (compat)); - } +qemu_fdt_setprop_strings (mc->fdt, name,"compatible" , +"sifive,test1" ,"sifive,test0" ,"syscon" );qemu_fdt_setprop_cells (mc->fdt, name,"reg" ,0x0 , memmap[VIRT_TEST ].base,0x0 , memmap[VIRT_TEST ].size);qemu_fdt_setprop_cell (mc->fdt, name,"phandle" , test_phandle); --2.35.1
PATCH v4 4/6 hw/core: use qemu_fdt_setprop_strings()
In reply to Ben DooksChange to using the qemu_fdt_setprop_strings() helper in hw/core code.
--- hw/core/guest-loader.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
hw/core/guest-loader.c +5 -8
@@ -56,18 +56,15 @@ static void loader_insert_platform_data(GuestLoaderState *s, int size,qemu_fdt_setprop (fdt, node,"reg" , ®_attr,sizeof (reg_attr));if (s->kernel) { -const char *compat[2 ] = {"multiboot,module" ,"multiboot,kernel" }; -qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)); +qemu_fdt_setprop_strings (fdt, node,"compatible" , +"multiboot,module" ,"multiboot,kernel" ); +if (s->args) {qemu_fdt_setprop_string (fdt, node,"bootargs" , s->args); } }else if (s->initrd) { -const char *compat[2 ] = {"multiboot,module" ,"multiboot,ramdisk" }; -qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)); +qemu_fdt_setprop_strings (fdt, node,"compatible" , +"multiboot,module" ,"multiboot,ramdisk" ); } }
Signature · 1 line
2.35.1
Re: [PATCH v4 4/6] hw/core: use qemu_fdt_setprop_strings()
Quoted 40 lines · Ben Dooks
Change to using the
qemu_fdt_setprop_strings()helper in hw/core code.Signed-off-by Ben Dooks <[email protected]>--- hw/core/guest-loader.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)hw/core/guest-loader.c +5
-8@@ -56,18 +56,15 @@ static void loader_insert_platform_data(GuestLoaderState *s, int size,qemu_fdt_setprop (fdt, node,"reg" , ®_attr,sizeof (reg_attr));if (s->kernel) { -const char *compat[2 ] = {"multiboot,module" ,"multiboot,kernel" }; -qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)); +qemu_fdt_setprop_strings (fdt, node,"compatible" , +"multiboot,module" ,"multiboot,kernel" ); +if (s->args) {qemu_fdt_setprop_string (fdt, node,"bootargs" , s->args); } }else if (s->initrd) { -const char *compat[2 ] = {"multiboot,module" ,"multiboot,ramdisk" }; -qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)); +qemu_fdt_setprop_strings (fdt, node,"compatible" , +"multiboot,module" ,"multiboot,ramdisk" ); } }Signature · 1 line
2.35.1
Re: [PATCH v4 4/6] hw/core: use qemu_fdt_setprop_strings()
In reply to Ben DooksQuoted 5 lines · Ben Dooks
Change to using the
qemu_fdt_setprop_strings()helper in hw/core code.Signed-off-by Ben Dooks <[email protected]>
Alistair
Quoted 36 lines
--- hw/core/guest-loader.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)hw/core/guest-loader.c +5
-9@@ -56,18 +56,15 @@ static void loader_insert_platform_data(GuestLoaderState *s, int size,qemu_fdt_setprop (fdt, node,"reg" , ®_attr,sizeof (reg_attr));if (s->kernel) { -const char *compat[2 ] = {"multiboot,module" ,"multiboot,kernel" }; -qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)); +qemu_fdt_setprop_strings (fdt, node,"compatible" , +"multiboot,module" ,"multiboot,kernel" ); +if (s->args) {qemu_fdt_setprop_string (fdt, node,"bootargs" , s->args); } }else if (s->initrd) { -const char *compat[2 ] = {"multiboot,module" ,"multiboot,ramdisk" }; -qemu_fdt_setprop_string_array (fdt, node,"compatible" , - (char **) &compat, -ARRAY_SIZE (compat)); +qemu_fdt_setprop_strings (fdt, node,"compatible" , +"multiboot,module" ,"multiboot,ramdisk" ); } } --2.35.1
PATCH v4 5/6 hw/mips: use qemu_fdt_setprop_strings()
In reply to Ben DooksChange to using qemu_fdt_setprop_strings() helper in hw/mips.
--- hw/mips/boston.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
hw/mips/boston.c +2 -6
@@ -515,9 +515,6 @@ static const void *create_fdt(BostonState *s,MachineState *mc = s->mach;uint32_t platreg_ph, gic_ph, clk_ph;char *name, *gic_name, *platreg_name, *stdout_name; -static const char *const syscon_compat[2 ] = { -"img,boston-platform-regs" ,"syscon" - }; fdt =create_device_tree (dt_size);if (!fdt) {
@@ -608,9 +605,8 @@ static const void *create_fdt(BostonState *s, platreg_name =g_strdup_printf ("/soc/system-controller@%" HWADDR_PRIx, memmap[BOSTON_PLATREG ].base);qemu_fdt_add_subnode (fdt, platreg_name); -qemu_fdt_setprop_string_array (fdt, platreg_name,"compatible" , - (char **)&syscon_compat, -ARRAY_SIZE (syscon_compat)); +qemu_fdt_setprop_strings (fdt, platreg_name,"compatible" , +"img,boston-platform-regs" ,"syscon" );qemu_fdt_setprop_cells (fdt, platreg_name,"reg" , memmap[BOSTON_PLATREG ].base, memmap[BOSTON_PLATREG ].size);
Signature · 1 line
2.35.1
Re: [PATCH v4 5/6] hw/mips: use qemu_fdt_setprop_strings()
Quoted 38 lines · Ben Dooks
Change to using
qemu_fdt_setprop_strings()helper in hw/mips.Signed-off-by Ben Dooks <[email protected]>Reviewed-by Peter Maydell <[email protected]>--- hw/mips/boston.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)hw/mips/boston.c +2
-6@@ -515,9 +515,6 @@ static const void *create_fdt(BostonState *s,MachineState *mc = s->mach;uint32_t platreg_ph, gic_ph, clk_ph;char *name, *gic_name, *platreg_name, *stdout_name; -static const char *const syscon_compat[2 ] = { -"img,boston-platform-regs" ,"syscon" - }; fdt =create_device_tree (dt_size);if (!fdt) {@@ -608,9 +605,8 @@ static const void *create_fdt(BostonState *s, platreg_name =g_strdup_printf ("/soc/system-controller@%" HWADDR_PRIx, memmap[BOSTON_PLATREG ].base);qemu_fdt_add_subnode (fdt, platreg_name); -qemu_fdt_setprop_string_array (fdt, platreg_name,"compatible" , - (char **)&syscon_compat, -ARRAY_SIZE (syscon_compat)); +qemu_fdt_setprop_strings (fdt, platreg_name,"compatible" , +"img,boston-platform-regs" ,"syscon" );qemu_fdt_setprop_cells (fdt, platreg_name,"reg" , memmap[BOSTON_PLATREG ].base, memmap[BOSTON_PLATREG ].size);Signature · 1 line
2.35.1
Re: [PATCH v4 5/6] hw/mips: use qemu_fdt_setprop_strings()
In reply to Ben DooksQuoted 5 lines · Ben Dooks
Change to using
qemu_fdt_setprop_strings()helper in hw/mips.Signed-off-by Ben Dooks <[email protected]>Reviewed-by Peter Maydell <[email protected]>
Alistair
Quoted 34 lines
--- hw/mips/boston.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)hw/mips/boston.c +2
-7@@ -515,9 +515,6 @@ static const void *create_fdt(BostonState *s,MachineState *mc = s->mach;uint32_t platreg_ph, gic_ph, clk_ph;char *name, *gic_name, *platreg_name, *stdout_name; -static const char *const syscon_compat[2 ] = { -"img,boston-platform-regs" ,"syscon" - }; fdt =create_device_tree (dt_size);if (!fdt) {@@ -608,9 +605,8 @@ static const void *create_fdt(BostonState *s, platreg_name =g_strdup_printf ("/soc/system-controller@%" HWADDR_PRIx, memmap[BOSTON_PLATREG ].base);qemu_fdt_add_subnode (fdt, platreg_name); -qemu_fdt_setprop_string_array (fdt, platreg_name,"compatible" , - (char **)&syscon_compat, -ARRAY_SIZE (syscon_compat)); +qemu_fdt_setprop_strings (fdt, platreg_name,"compatible" , +"img,boston-platform-regs" ,"syscon" );qemu_fdt_setprop_cells (fdt, platreg_name,"reg" , memmap[BOSTON_PLATREG ].base, memmap[BOSTON_PLATREG ].size); --2.35.1
PATCH v4 6/6 hw/arm: change to use qemu_fdt_setprop_strings()
In reply to Ben DooksChange to using qemu_fdt_setprop_strings() instead of using \0 separated string arrays. Note, also there were a few places where qemu_fdt_setprop_string() can be used in the same areas.
---
v4:
- fixed checkpatch errors with string
- fixed patch subject
--- hw/arm/boot.c | 8 +++--- hw/arm/virt.c | 28 +++++++++------------ hw/arm/xlnx-versal-virt.c | 51 ++++++++++++++++----------------------- 3 files changed, 37 insertions(+), 50 deletions(-)
hw/arm/boot.c +4 -4
@@ -490,11 +490,11 @@ static void fdt_add_psci_node(void *fdt)qemu_fdt_add_subnode (fdt,"/psci" );if (armcpu->psci_version >=QEMU_PSCI_VERSION_0_2 ) {if (armcpu->psci_version <QEMU_PSCI_VERSION_1_0 ) { -const char comp[] ="arm,psci-0.2\0arm,psci" ; -qemu_fdt_setprop (fdt,"/psci" ,"compatible" , comp,sizeof (comp)); +qemu_fdt_setprop_strings (fdt,"/psci" ,"compatible" , +"arm,psci-0.2" ,"arm,psci" ); }else { -const char comp[] ="arm,psci-1.0\0arm,psci-0.2\0arm,psci" ; -qemu_fdt_setprop (fdt,"/psci" ,"compatible" , comp,sizeof (comp)); +qemu_fdt_setprop_strings (fdt,"/psci" ,"compatible" , +"arm,psci-1.0" ,"arm,psci-0.2" ,"arm,psci" ); } cpu_off_fn =QEMU_PSCI_0_2_FN_CPU_OFF ;
hw/arm/virt.c +12 -16
@@ -343,9 +343,8 @@ static void fdt_add_timer_nodes(const VirtMachineState *vms) armcpu =ARM_CPU (qemu_get_cpu (0 ));if (arm_feature (&armcpu->env,ARM_FEATURE_V8 )) { -const char compat[] ="arm,armv8-timer\0arm,armv7-timer" ; -qemu_fdt_setprop (ms->fdt,"/timer" ,"compatible" , - compat,sizeof (compat)); +qemu_fdt_setprop_strings (ms->fdt,"/timer" ,"compatible" , +"arm,armv8-timer" ,"arm,armv7-timer" ); }else {qemu_fdt_setprop_string (ms->fdt,"/timer" ,"compatible" ,"arm,armv7-timer" );
@@ -843,8 +842,6 @@ static void create_uart(const VirtMachineState *vms, int uart,hwaddr base = vms->memmap[uart].base;hwaddr size = vms->memmap[uart].size;int irq = vms->irqmap[uart]; -const char compat[] ="arm,pl011\0arm,primecell" ; -const char clocknames[] ="uartclk\0apb_pclk" ;DeviceState *dev =qdev_new (TYPE_PL011 );SysBusDevice *s =SYS_BUS_DEVICE (dev);MachineState *ms =MACHINE (vms);
@@ -858,8 +855,8 @@ static void create_uart(const VirtMachineState *vms, int uart, nodename =g_strdup_printf ("/pl011@%" PRIx64, base);qemu_fdt_add_subnode (ms->fdt, nodename);/* Note that we can't use setprop_string because of the embedded NUL */ -qemu_fdt_setprop (ms->fdt, nodename,"compatible" , - compat,sizeof (compat)); +qemu_fdt_setprop_strings (ms->fdt, nodename,"compatible" , +"arm,pl011" ,"arm,primecell" );qemu_fdt_setprop_sized_cells (ms->fdt, nodename,"reg" ,2 , base,2 , size); qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
@@ -867,8 +864,8 @@ static void create_uart(const VirtMachineState *vms, int uart, GIC_FDT_IRQ_FLAGS_LEVEL_HI);qemu_fdt_setprop_cells (ms->fdt, nodename,"clocks" , vms->clock_phandle, vms->clock_phandle); -qemu_fdt_setprop (ms->fdt, nodename,"clock-names" , - clocknames,sizeof (clocknames)); +qemu_fdt_setprop_strings (ms->fdt, nodename,"clock-names" , +"uartclk" ,"apb_pclk" );if (uart ==VIRT_UART ) {qemu_fdt_setprop_string (ms->fdt,"/chosen" ,"stdout-path" , nodename);
@@ -890,14 +887,14 @@ static void create_rtc(const VirtMachineState *vms)hwaddr base = vms->memmap[VIRT_RTC ].base;hwaddr size = vms->memmap[VIRT_RTC ].size;int irq = vms->irqmap[VIRT_RTC ]; -const char compat[] ="arm,pl031\0arm,primecell" ;MachineState *ms =MACHINE (vms);sysbus_create_simple ("pl031" , base,qdev_get_gpio_in (vms->gic, irq)); nodename =g_strdup_printf ("/pl031@%" PRIx64, base);qemu_fdt_add_subnode (ms->fdt, nodename); -qemu_fdt_setprop (ms->fdt, nodename,"compatible" , compat,sizeof (compat)); +qemu_fdt_setprop_strings (ms->fdt, nodename,"compatible" , +"arm,pl031" ,"arm,primecell" );qemu_fdt_setprop_sized_cells (ms->fdt, nodename,"reg" ,2 , base,2 , size); qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
@@ -983,7 +980,6 @@ static void create_gpio_devices(const VirtMachineState *vms, int gpio,hwaddr base = vms->memmap[gpio].base;hwaddr size = vms->memmap[gpio].size;int irq = vms->irqmap[gpio]; -const char compat[] ="arm,pl061\0arm,primecell" ;SysBusDevice *s;MachineState *ms =MACHINE (vms);
@@ -1001,7 +997,8 @@ static void create_gpio_devices(const VirtMachineState *vms, int gpio,qemu_fdt_add_subnode (ms->fdt, nodename);qemu_fdt_setprop_sized_cells (ms->fdt, nodename,"reg" ,2 , base,2 , size); -qemu_fdt_setprop (ms->fdt, nodename,"compatible" , compat,sizeof (compat)); +qemu_fdt_setprop_strings (ms->fdt, nodename,"compatible" , +"arm,pl061" ,"arm,primecell" );qemu_fdt_setprop_cell (ms->fdt, nodename,"#gpio-cells" ,2 );qemu_fdt_setprop (ms->fdt, nodename,"gpio-controller" ,NULL ,0 ); qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
@@ -1325,7 +1322,6 @@ static void create_smmu(const VirtMachineState *vms,int i;hwaddr base = vms->memmap[VIRT_SMMU ].base;hwaddr size = vms->memmap[VIRT_SMMU ].size; -const char irq_names[] ="eventq\0priq\0cmdq-sync\0gerror" ;DeviceState *dev;MachineState *ms =MACHINE (vms);
@@ -1355,8 +1351,8 @@ static void create_smmu(const VirtMachineState *vms,GIC_FDT_IRQ_TYPE_SPI , irq +2 ,GIC_FDT_IRQ_FLAGS_EDGE_LO_HI , GIC_FDT_IRQ_TYPE_SPI, irq + 3, GIC_FDT_IRQ_FLAGS_EDGE_LO_HI); -qemu_fdt_setprop (ms->fdt, node,"interrupt-names" , irq_names, -sizeof (irq_names)); +qemu_fdt_setprop_strings (ms->fdt, node,"interrupt-names" , +"eventq" ,"priq" ,"cmdq-sync" ,"gerror" );qemu_fdt_setprop_cell (ms->fdt, node,"clocks" , vms->clock_phandle);qemu_fdt_setprop_string (ms->fdt, node,"clock-names" ,"apb_pclk" );
hw/arm/xlnx-versal-virt.c +21 -30
147 lines not on this page · raw message
Signature · 1 line
2.35.1
Re: [PATCH v4 6/6] hw/arm: change to use qemu_fdt_setprop_strings()
Quoted 9 lines · Ben Dooks
Change to using
qemu_fdt_setprop_strings()instead of using \0 separated string arrays. Note, also there were a few places whereqemu_fdt_setprop_string()can be used in the same areas.Signed-off-by Ben Dooks <[email protected]>---
v4:
- fixed checkpatch errors with string
- fixed patch subject
Quoted 6 lines
--- hw/arm/boot.c | 8 +++--- hw/arm/virt.c | 28 +++++++++------------ hw/arm/xlnx-versal-virt.c | 51 ++++++++++++++++----------------------- 3 files changed, 37 insertions(+), 50 deletions(-)
Quoted 7 lines · Ben Dooks
Add a helper for
qemu_fdt_setprop_strings()to take a set of strings to put into a device-tree, which removes several open-coded methods such as setting an char arr[] = {..} or setting char val[] = "str\0str2";This is for hw/arm, hw/mips and hw/riscv as well as a couple of cores. It is not fully tested over all of those, I may not have caught all places this is to be replaced.
I've put a github repo up with this and possibly some other bits I am working on:
https://github.com/bendooks/qemu/tree/dev/fdt-string-array-v4
Quoted 13 lines
Changes:
v4:
- fix checkpatch issues
- remove error checking inhw/core/guest-loader.c
v3:
- fix return value for the call
- add better help text
v2:
- fix node/path in comment
Signature · 3 lines
Ben Dooks, [email protected], http://www.fluff.org/ben/ Large Hadron Colada: A large Pina Colada that makes the universe disappear.
Quoted 8 lines · Ben Dooks
Add a helper for
qemu_fdt_setprop_strings()to take a set of strings to put into a device-tree, which removes several open-coded methods such as setting an char arr[] = {..} or setting char val[] = "str\0str2";This is for hw/arm, hw/mips and hw/riscv as well as a couple of cores. It is not fully tested over all of those, I may not have caught all places this is to be replaced.
Hi; just as a minor process thing for next time you send a
patchset: the usual convention is that the 'cover letter' email has a subject starting with a tag like "[PATCH v4 0/6]". This makes it easier to pick the cover letter out when eyeballing a set of subject lines, and also helps some of the automated tooling (eg I think this is why https://patchew.org/QEMU/ didn't notice this series). Usually 'git format-patch --cover-letter' will get this right automatically for you.
thanks
-- PMM