All of lore.kernel.org
 help / color / mirror / Atom feed
* [v2] pair of device-tree helpers
@ 2022-06-18 20:14 Ben Dooks
  2022-06-18 20:14 ` [PATCH 1/4] device_tree: add qemu_fdt_setprop_reg64_map helper Ben Dooks
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Ben Dooks @ 2022-06-18 20:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: palmer, Alistair.Francis, bin.meng, qemu-riscv

I've been doing a bit of looking at riscv and dt creation, and                  
was thinking the following two helper functions would be useful                 
so implemented qemu_fdt_setprop_reg64_map() and qemu_fdt_setprop_strings()          
and then applied them to the hw/riscv/sifive_u.c machine.                       




^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/4] device_tree: add qemu_fdt_setprop_reg64_map helper
  2022-06-18 20:14 [v2] pair of device-tree helpers Ben Dooks
@ 2022-06-18 20:14 ` Ben Dooks
  2022-06-20  6:41   ` Alistair Francis
  2022-06-18 20:14 ` [PATCH 2/4] hw/riscv: use qemu_fdt_setprop_reg64_map() in sifive_u.c Ben Dooks
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 19+ messages in thread
From: Ben Dooks @ 2022-06-18 20:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: palmer, Alistair.Francis, bin.meng, qemu-riscv, Ben Dooks

Add a macro qemu_fdt_setprop_reg64_map() to set the given
node's reg property directly from the memory map entry
to avoid open coding of the following:

    qemu_fdt_setprop_cells(fdt, nodename, "reg",
        0x0, memmap[SIFIVE_U_DEV_OTP].base,
        0x0, memmap[SIFIVE_U_DEV_OTP].size);

Signed-off-by: Ben Dooks <qemu@ben.fluff.org>
--
v2:
- changed qemu_fdt_setprop_reg64 to qemu_fdt_setprop_reg64_map
---
 include/sysemu/device_tree.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
index ef060a9759..79ce009a22 100644
--- a/include/sysemu/device_tree.h
+++ b/include/sysemu/device_tree.h
@@ -135,6 +135,21 @@ int qemu_fdt_add_path(void *fdt, const char *path);
                          sizeof(qdt_tmp));                                    \
     } while (0)
 
+/**
+ * qemu_fdt_setprop_reg64_map:
+ * @fdt: the device tree path
+ * @node_path: node to set property on
+ * @map: the map entry to set the reg from
+ *
+ * A helper tp set the 'reg' node on the specified node from the given map
+ * entry.
+ */
+#define qemu_fdt_setprop_reg64_map(fdt, path, map)              \
+    qemu_fdt_setprop_cells(fdt, path, "reg",                    \
+                           (map)->base >> 32, (map)->base,      \
+                           (map)->size >> 32, (map)->size)
+
+
 void qemu_fdt_dumpdtb(void *fdt, int size);
 
 /**
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 2/4] hw/riscv: use qemu_fdt_setprop_reg64_map() in sifive_u.c
  2022-06-18 20:14 [v2] pair of device-tree helpers Ben Dooks
  2022-06-18 20:14 ` [PATCH 1/4] device_tree: add qemu_fdt_setprop_reg64_map helper Ben Dooks
@ 2022-06-18 20:14 ` Ben Dooks
  2022-06-20  6:42   ` Alistair Francis
  2022-06-18 20:14 ` [PATCH 3/4] device_tree: add qemu_fdt_setprop_strings() helper Ben Dooks
  2022-06-18 20:14 ` [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c Ben Dooks
  3 siblings, 1 reply; 19+ messages in thread
From: Ben Dooks @ 2022-06-18 20:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: palmer, Alistair.Francis, bin.meng, qemu-riscv, Ben Dooks

Use the qemu_fdt_setprop_reg64_map() to replace the code
that sets the property manually.

Signed-off-by: Ben Dooks <qemu@ben.fluff.org>
--
v2:
- changed to qemu_fdt_setprop_reg64_map() from previous
---
 hw/riscv/sifive_u.c | 41 +++++++++++------------------------------
 1 file changed, 11 insertions(+), 30 deletions(-)

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index e4c814a3ea..89d7aa2a52 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -223,9 +223,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
     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_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_CLINT]);
     qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
         cells, ms->smp.cpus * sizeof(uint32_t) * 4);
     g_free(cells);
@@ -235,9 +233,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
         (long)memmap[SIFIVE_U_DEV_OTP].base);
     qemu_fdt_add_subnode(fdt, nodename);
     qemu_fdt_setprop_cell(fdt, nodename, "fuse-count", SIFIVE_U_OTP_REG_SIZE);
-    qemu_fdt_setprop_cells(fdt, nodename, "reg",
-        0x0, memmap[SIFIVE_U_DEV_OTP].base,
-        0x0, memmap[SIFIVE_U_DEV_OTP].size);
+    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_OTP]);
     qemu_fdt_setprop_string(fdt, nodename, "compatible",
         "sifive,fu540-c000-otp");
     g_free(nodename);
@@ -250,9 +246,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
     qemu_fdt_setprop_cell(fdt, nodename, "#clock-cells", 0x1);
     qemu_fdt_setprop_cells(fdt, nodename, "clocks",
         hfclk_phandle, rtcclk_phandle);
-    qemu_fdt_setprop_cells(fdt, nodename, "reg",
-        0x0, memmap[SIFIVE_U_DEV_PRCI].base,
-        0x0, memmap[SIFIVE_U_DEV_PRCI].size);
+    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_PRCI]);
     qemu_fdt_setprop_string(fdt, nodename, "compatible",
         "sifive,fu540-c000-prci");
     g_free(nodename);
@@ -284,9 +278,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
     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));
-    qemu_fdt_setprop_cells(fdt, nodename, "reg",
-        0x0, memmap[SIFIVE_U_DEV_PLIC].base,
-        0x0, memmap[SIFIVE_U_DEV_PLIC].size);
+    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_PLIC]);
     qemu_fdt_setprop_cell(fdt, nodename, "riscv,ndev", 0x35);
     qemu_fdt_setprop_cell(fdt, nodename, "phandle", plic_phandle);
     plic_phandle = qemu_fdt_get_phandle(fdt, nodename);
@@ -304,9 +296,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
     qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0);
     qemu_fdt_setprop_cell(fdt, nodename, "#gpio-cells", 2);
     qemu_fdt_setprop(fdt, nodename, "gpio-controller", NULL, 0);
-    qemu_fdt_setprop_cells(fdt, nodename, "reg",
-        0x0, memmap[SIFIVE_U_DEV_GPIO].base,
-        0x0, memmap[SIFIVE_U_DEV_GPIO].size);
+    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_GPIO]);
     qemu_fdt_setprop_cells(fdt, nodename, "interrupts", SIFIVE_U_GPIO_IRQ0,
         SIFIVE_U_GPIO_IRQ1, SIFIVE_U_GPIO_IRQ2, SIFIVE_U_GPIO_IRQ3,
         SIFIVE_U_GPIO_IRQ4, SIFIVE_U_GPIO_IRQ5, SIFIVE_U_GPIO_IRQ6,
@@ -342,9 +332,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
     nodename = g_strdup_printf("/soc/cache-controller@%lx",
         (long)memmap[SIFIVE_U_DEV_L2CC].base);
     qemu_fdt_add_subnode(fdt, nodename);
-    qemu_fdt_setprop_cells(fdt, nodename, "reg",
-        0x0, memmap[SIFIVE_U_DEV_L2CC].base,
-        0x0, memmap[SIFIVE_U_DEV_L2CC].size);
+    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_L2CC]);
     qemu_fdt_setprop_cells(fdt, nodename, "interrupts",
         SIFIVE_U_L2CC_IRQ0, SIFIVE_U_L2CC_IRQ1, SIFIVE_U_L2CC_IRQ2);
     qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
@@ -366,9 +354,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
         prci_phandle, PRCI_CLK_TLCLK);
     qemu_fdt_setprop_cell(fdt, nodename, "interrupts", SIFIVE_U_QSPI2_IRQ);
     qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
-    qemu_fdt_setprop_cells(fdt, nodename, "reg",
-        0x0, memmap[SIFIVE_U_DEV_QSPI2].base,
-        0x0, memmap[SIFIVE_U_DEV_QSPI2].size);
+    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_QSPI2]);
     qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,spi0");
     g_free(nodename);
 
@@ -391,9 +377,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
         prci_phandle, PRCI_CLK_TLCLK);
     qemu_fdt_setprop_cell(fdt, nodename, "interrupts", SIFIVE_U_QSPI0_IRQ);
     qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
-    qemu_fdt_setprop_cells(fdt, nodename, "reg",
-        0x0, memmap[SIFIVE_U_DEV_QSPI0].base,
-        0x0, memmap[SIFIVE_U_DEV_QSPI0].size);
+    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_QSPI0]);
     qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,spi0");
     g_free(nodename);
 
@@ -449,9 +433,8 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
         (long)memmap[SIFIVE_U_DEV_PWM0].base);
     qemu_fdt_add_subnode(fdt, nodename);
     qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,pwm0");
-    qemu_fdt_setprop_cells(fdt, nodename, "reg",
-        0x0, memmap[SIFIVE_U_DEV_PWM0].base,
-        0x0, memmap[SIFIVE_U_DEV_PWM0].size);
+qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_PWM0]);
+
     qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
     qemu_fdt_setprop_cells(fdt, nodename, "interrupts",
                            SIFIVE_U_PWM0_IRQ0, SIFIVE_U_PWM0_IRQ1,
@@ -496,9 +479,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
         (long)memmap[SIFIVE_U_DEV_UART0].base);
     qemu_fdt_add_subnode(fdt, nodename);
     qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,uart0");
-    qemu_fdt_setprop_cells(fdt, nodename, "reg",
-        0x0, memmap[SIFIVE_U_DEV_UART0].base,
-        0x0, memmap[SIFIVE_U_DEV_UART0].size);
+    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_UART0]);
     qemu_fdt_setprop_cells(fdt, nodename, "clocks",
         prci_phandle, PRCI_CLK_TLCLK);
     qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/4] device_tree: add qemu_fdt_setprop_strings() helper
  2022-06-18 20:14 [v2] pair of device-tree helpers Ben Dooks
  2022-06-18 20:14 ` [PATCH 1/4] device_tree: add qemu_fdt_setprop_reg64_map helper Ben Dooks
  2022-06-18 20:14 ` [PATCH 2/4] hw/riscv: use qemu_fdt_setprop_reg64_map() in sifive_u.c Ben Dooks
@ 2022-06-18 20:14 ` Ben Dooks
  2022-06-20  6:47   ` Alistair Francis
  2022-06-18 20:14 ` [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c Ben Dooks
  3 siblings, 1 reply; 19+ messages in thread
From: Ben Dooks @ 2022-06-18 20:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: palmer, Alistair.Francis, bin.meng, qemu-riscv, 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 <qemu@ben.fluff.org>
--
v2:
- fix node/path in comment
---
 include/sysemu/device_tree.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
index 79ce009a22..28b68bacaf 100644
--- a/include/sysemu/device_tree.h
+++ b/include/sysemu/device_tree.h
@@ -87,6 +87,21 @@ 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
+ */
+#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);
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
  2022-06-18 20:14 [v2] pair of device-tree helpers Ben Dooks
                   ` (2 preceding siblings ...)
  2022-06-18 20:14 ` [PATCH 3/4] device_tree: add qemu_fdt_setprop_strings() helper Ben Dooks
@ 2022-06-18 20:14 ` Ben Dooks
  2022-06-20  6:47   ` Alistair Francis
  3 siblings, 1 reply; 19+ messages in thread
From: Ben Dooks @ 2022-06-18 20:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: palmer, Alistair.Francis, bin.meng, qemu-riscv, Ben Dooks

Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
the code.

Signed-off-by: Ben Dooks <qemu@ben.fluff.org>
---
 hw/riscv/sifive_u.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index 89d7aa2a52..16b18d90bd 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -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,8 +214,8 @@ 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_strings(fdt, nodename, "compatible",
+                             "sifive,clint0", "riscv,clint0");
     qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_CLINT]);
     qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
         cells, ms->smp.cpus * sizeof(uint32_t) * 4);
@@ -273,8 +266,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));
@@ -410,8 +403,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 **)&ethclk_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);
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/4] device_tree: add qemu_fdt_setprop_reg64_map helper
  2022-06-18 20:14 ` [PATCH 1/4] device_tree: add qemu_fdt_setprop_reg64_map helper Ben Dooks
@ 2022-06-20  6:41   ` Alistair Francis
  0 siblings, 0 replies; 19+ messages in thread
From: Alistair Francis @ 2022-06-20  6:41 UTC (permalink / raw)
  To: Ben Dooks
  Cc: qemu-devel@nongnu.org Developers, Palmer Dabbelt,
	Alistair Francis, Bin Meng, open list:RISC-V

On Sun, Jun 19, 2022 at 6:15 AM Ben Dooks <qemu@ben.fluff.org> wrote:
>
> Add a macro qemu_fdt_setprop_reg64_map() to set the given
> node's reg property directly from the memory map entry
> to avoid open coding of the following:
>
>     qemu_fdt_setprop_cells(fdt, nodename, "reg",
>         0x0, memmap[SIFIVE_U_DEV_OTP].base,
>         0x0, memmap[SIFIVE_U_DEV_OTP].size);
>
> Signed-off-by: Ben Dooks <qemu@ben.fluff.org>
> --
> v2:
> - changed qemu_fdt_setprop_reg64 to qemu_fdt_setprop_reg64_map
> ---
>  include/sysemu/device_tree.h | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
> index ef060a9759..79ce009a22 100644
> --- a/include/sysemu/device_tree.h
> +++ b/include/sysemu/device_tree.h
> @@ -135,6 +135,21 @@ int qemu_fdt_add_path(void *fdt, const char *path);
>                           sizeof(qdt_tmp));                                    \
>      } while (0)
>
> +/**
> + * qemu_fdt_setprop_reg64_map:
> + * @fdt: the device tree path
> + * @node_path: node to set property on
> + * @map: the map entry to set the reg from
> + *
> + * A helper tp set the 'reg' node on the specified node from the given map

A helper to

Otherwise:

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> + * entry.
> + */
> +#define qemu_fdt_setprop_reg64_map(fdt, path, map)              \
> +    qemu_fdt_setprop_cells(fdt, path, "reg",                    \
> +                           (map)->base >> 32, (map)->base,      \
> +                           (map)->size >> 32, (map)->size)
> +
> +
>  void qemu_fdt_dumpdtb(void *fdt, int size);
>
>  /**
> --
> 2.35.1
>
>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/4] hw/riscv: use qemu_fdt_setprop_reg64_map() in sifive_u.c
  2022-06-18 20:14 ` [PATCH 2/4] hw/riscv: use qemu_fdt_setprop_reg64_map() in sifive_u.c Ben Dooks
@ 2022-06-20  6:42   ` Alistair Francis
  2022-06-20  6:44     ` Alistair Francis
  0 siblings, 1 reply; 19+ messages in thread
From: Alistair Francis @ 2022-06-20  6:42 UTC (permalink / raw)
  To: Ben Dooks
  Cc: qemu-devel@nongnu.org Developers, Palmer Dabbelt,
	Alistair Francis, Bin Meng, open list:RISC-V

On Sun, Jun 19, 2022 at 6:14 AM Ben Dooks <qemu@ben.fluff.org> wrote:
>
> Use the qemu_fdt_setprop_reg64_map() to replace the code
> that sets the property manually.
>
> Signed-off-by: Ben Dooks <qemu@ben.fluff.org>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> --
> v2:
> - changed to qemu_fdt_setprop_reg64_map() from previous
> ---
>  hw/riscv/sifive_u.c | 41 +++++++++++------------------------------
>  1 file changed, 11 insertions(+), 30 deletions(-)
>
> diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
> index e4c814a3ea..89d7aa2a52 100644
> --- a/hw/riscv/sifive_u.c
> +++ b/hw/riscv/sifive_u.c
> @@ -223,9 +223,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>      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_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_CLINT]);
>      qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
>          cells, ms->smp.cpus * sizeof(uint32_t) * 4);
>      g_free(cells);
> @@ -235,9 +233,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>          (long)memmap[SIFIVE_U_DEV_OTP].base);
>      qemu_fdt_add_subnode(fdt, nodename);
>      qemu_fdt_setprop_cell(fdt, nodename, "fuse-count", SIFIVE_U_OTP_REG_SIZE);
> -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> -        0x0, memmap[SIFIVE_U_DEV_OTP].base,
> -        0x0, memmap[SIFIVE_U_DEV_OTP].size);
> +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_OTP]);
>      qemu_fdt_setprop_string(fdt, nodename, "compatible",
>          "sifive,fu540-c000-otp");
>      g_free(nodename);
> @@ -250,9 +246,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>      qemu_fdt_setprop_cell(fdt, nodename, "#clock-cells", 0x1);
>      qemu_fdt_setprop_cells(fdt, nodename, "clocks",
>          hfclk_phandle, rtcclk_phandle);
> -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> -        0x0, memmap[SIFIVE_U_DEV_PRCI].base,
> -        0x0, memmap[SIFIVE_U_DEV_PRCI].size);
> +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_PRCI]);
>      qemu_fdt_setprop_string(fdt, nodename, "compatible",
>          "sifive,fu540-c000-prci");
>      g_free(nodename);
> @@ -284,9 +278,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>      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));
> -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> -        0x0, memmap[SIFIVE_U_DEV_PLIC].base,
> -        0x0, memmap[SIFIVE_U_DEV_PLIC].size);
> +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_PLIC]);
>      qemu_fdt_setprop_cell(fdt, nodename, "riscv,ndev", 0x35);
>      qemu_fdt_setprop_cell(fdt, nodename, "phandle", plic_phandle);
>      plic_phandle = qemu_fdt_get_phandle(fdt, nodename);
> @@ -304,9 +296,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>      qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0);
>      qemu_fdt_setprop_cell(fdt, nodename, "#gpio-cells", 2);
>      qemu_fdt_setprop(fdt, nodename, "gpio-controller", NULL, 0);
> -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> -        0x0, memmap[SIFIVE_U_DEV_GPIO].base,
> -        0x0, memmap[SIFIVE_U_DEV_GPIO].size);
> +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_GPIO]);
>      qemu_fdt_setprop_cells(fdt, nodename, "interrupts", SIFIVE_U_GPIO_IRQ0,
>          SIFIVE_U_GPIO_IRQ1, SIFIVE_U_GPIO_IRQ2, SIFIVE_U_GPIO_IRQ3,
>          SIFIVE_U_GPIO_IRQ4, SIFIVE_U_GPIO_IRQ5, SIFIVE_U_GPIO_IRQ6,
> @@ -342,9 +332,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>      nodename = g_strdup_printf("/soc/cache-controller@%lx",
>          (long)memmap[SIFIVE_U_DEV_L2CC].base);
>      qemu_fdt_add_subnode(fdt, nodename);
> -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> -        0x0, memmap[SIFIVE_U_DEV_L2CC].base,
> -        0x0, memmap[SIFIVE_U_DEV_L2CC].size);
> +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_L2CC]);
>      qemu_fdt_setprop_cells(fdt, nodename, "interrupts",
>          SIFIVE_U_L2CC_IRQ0, SIFIVE_U_L2CC_IRQ1, SIFIVE_U_L2CC_IRQ2);
>      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
> @@ -366,9 +354,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>          prci_phandle, PRCI_CLK_TLCLK);
>      qemu_fdt_setprop_cell(fdt, nodename, "interrupts", SIFIVE_U_QSPI2_IRQ);
>      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
> -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> -        0x0, memmap[SIFIVE_U_DEV_QSPI2].base,
> -        0x0, memmap[SIFIVE_U_DEV_QSPI2].size);
> +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_QSPI2]);
>      qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,spi0");
>      g_free(nodename);
>
> @@ -391,9 +377,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>          prci_phandle, PRCI_CLK_TLCLK);
>      qemu_fdt_setprop_cell(fdt, nodename, "interrupts", SIFIVE_U_QSPI0_IRQ);
>      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
> -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> -        0x0, memmap[SIFIVE_U_DEV_QSPI0].base,
> -        0x0, memmap[SIFIVE_U_DEV_QSPI0].size);
> +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_QSPI0]);
>      qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,spi0");
>      g_free(nodename);
>
> @@ -449,9 +433,8 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>          (long)memmap[SIFIVE_U_DEV_PWM0].base);
>      qemu_fdt_add_subnode(fdt, nodename);
>      qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,pwm0");
> -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> -        0x0, memmap[SIFIVE_U_DEV_PWM0].base,
> -        0x0, memmap[SIFIVE_U_DEV_PWM0].size);
> +qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_PWM0]);
> +
>      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
>      qemu_fdt_setprop_cells(fdt, nodename, "interrupts",
>                             SIFIVE_U_PWM0_IRQ0, SIFIVE_U_PWM0_IRQ1,
> @@ -496,9 +479,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
>          (long)memmap[SIFIVE_U_DEV_UART0].base);
>      qemu_fdt_add_subnode(fdt, nodename);
>      qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,uart0");
> -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> -        0x0, memmap[SIFIVE_U_DEV_UART0].base,
> -        0x0, memmap[SIFIVE_U_DEV_UART0].size);
> +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_UART0]);
>      qemu_fdt_setprop_cells(fdt, nodename, "clocks",
>          prci_phandle, PRCI_CLK_TLCLK);
>      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
> --
> 2.35.1
>
>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/4] hw/riscv: use qemu_fdt_setprop_reg64_map() in sifive_u.c
  2022-06-20  6:42   ` Alistair Francis
@ 2022-06-20  6:44     ` Alistair Francis
  0 siblings, 0 replies; 19+ messages in thread
From: Alistair Francis @ 2022-06-20  6:44 UTC (permalink / raw)
  To: Ben Dooks
  Cc: qemu-devel@nongnu.org Developers, Palmer Dabbelt,
	Alistair Francis, Bin Meng, open list:RISC-V

On Mon, Jun 20, 2022 at 4:42 PM Alistair Francis <alistair23@gmail.com> wrote:
>
> On Sun, Jun 19, 2022 at 6:14 AM Ben Dooks <qemu@ben.fluff.org> wrote:
> >
> > Use the qemu_fdt_setprop_reg64_map() to replace the code
> > that sets the property manually.
> >
> > Signed-off-by: Ben Dooks <qemu@ben.fluff.org>
>
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>
> Alistair
>
> > --
> > v2:
> > - changed to qemu_fdt_setprop_reg64_map() from previous
> > ---
> >  hw/riscv/sifive_u.c | 41 +++++++++++------------------------------
> >  1 file changed, 11 insertions(+), 30 deletions(-)
> >
> > diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
> > index e4c814a3ea..89d7aa2a52 100644
> > --- a/hw/riscv/sifive_u.c
> > +++ b/hw/riscv/sifive_u.c
> > @@ -223,9 +223,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >      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_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_CLINT]);

Do you mind doing this for the other RISC-V machines as well?
Hopefully making this whole FDT process a bit easier to read


Alistair

> >      qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
> >          cells, ms->smp.cpus * sizeof(uint32_t) * 4);
> >      g_free(cells);
> > @@ -235,9 +233,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >          (long)memmap[SIFIVE_U_DEV_OTP].base);
> >      qemu_fdt_add_subnode(fdt, nodename);
> >      qemu_fdt_setprop_cell(fdt, nodename, "fuse-count", SIFIVE_U_OTP_REG_SIZE);
> > -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> > -        0x0, memmap[SIFIVE_U_DEV_OTP].base,
> > -        0x0, memmap[SIFIVE_U_DEV_OTP].size);
> > +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_OTP]);
> >      qemu_fdt_setprop_string(fdt, nodename, "compatible",
> >          "sifive,fu540-c000-otp");
> >      g_free(nodename);
> > @@ -250,9 +246,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >      qemu_fdt_setprop_cell(fdt, nodename, "#clock-cells", 0x1);
> >      qemu_fdt_setprop_cells(fdt, nodename, "clocks",
> >          hfclk_phandle, rtcclk_phandle);
> > -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> > -        0x0, memmap[SIFIVE_U_DEV_PRCI].base,
> > -        0x0, memmap[SIFIVE_U_DEV_PRCI].size);
> > +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_PRCI]);
> >      qemu_fdt_setprop_string(fdt, nodename, "compatible",
> >          "sifive,fu540-c000-prci");
> >      g_free(nodename);
> > @@ -284,9 +278,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >      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));
> > -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> > -        0x0, memmap[SIFIVE_U_DEV_PLIC].base,
> > -        0x0, memmap[SIFIVE_U_DEV_PLIC].size);
> > +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_PLIC]);
> >      qemu_fdt_setprop_cell(fdt, nodename, "riscv,ndev", 0x35);
> >      qemu_fdt_setprop_cell(fdt, nodename, "phandle", plic_phandle);
> >      plic_phandle = qemu_fdt_get_phandle(fdt, nodename);
> > @@ -304,9 +296,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >      qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0);
> >      qemu_fdt_setprop_cell(fdt, nodename, "#gpio-cells", 2);
> >      qemu_fdt_setprop(fdt, nodename, "gpio-controller", NULL, 0);
> > -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> > -        0x0, memmap[SIFIVE_U_DEV_GPIO].base,
> > -        0x0, memmap[SIFIVE_U_DEV_GPIO].size);
> > +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_GPIO]);
> >      qemu_fdt_setprop_cells(fdt, nodename, "interrupts", SIFIVE_U_GPIO_IRQ0,
> >          SIFIVE_U_GPIO_IRQ1, SIFIVE_U_GPIO_IRQ2, SIFIVE_U_GPIO_IRQ3,
> >          SIFIVE_U_GPIO_IRQ4, SIFIVE_U_GPIO_IRQ5, SIFIVE_U_GPIO_IRQ6,
> > @@ -342,9 +332,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >      nodename = g_strdup_printf("/soc/cache-controller@%lx",
> >          (long)memmap[SIFIVE_U_DEV_L2CC].base);
> >      qemu_fdt_add_subnode(fdt, nodename);
> > -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> > -        0x0, memmap[SIFIVE_U_DEV_L2CC].base,
> > -        0x0, memmap[SIFIVE_U_DEV_L2CC].size);
> > +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_L2CC]);
> >      qemu_fdt_setprop_cells(fdt, nodename, "interrupts",
> >          SIFIVE_U_L2CC_IRQ0, SIFIVE_U_L2CC_IRQ1, SIFIVE_U_L2CC_IRQ2);
> >      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
> > @@ -366,9 +354,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >          prci_phandle, PRCI_CLK_TLCLK);
> >      qemu_fdt_setprop_cell(fdt, nodename, "interrupts", SIFIVE_U_QSPI2_IRQ);
> >      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
> > -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> > -        0x0, memmap[SIFIVE_U_DEV_QSPI2].base,
> > -        0x0, memmap[SIFIVE_U_DEV_QSPI2].size);
> > +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_QSPI2]);
> >      qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,spi0");
> >      g_free(nodename);
> >
> > @@ -391,9 +377,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >          prci_phandle, PRCI_CLK_TLCLK);
> >      qemu_fdt_setprop_cell(fdt, nodename, "interrupts", SIFIVE_U_QSPI0_IRQ);
> >      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
> > -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> > -        0x0, memmap[SIFIVE_U_DEV_QSPI0].base,
> > -        0x0, memmap[SIFIVE_U_DEV_QSPI0].size);
> > +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_QSPI0]);
> >      qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,spi0");
> >      g_free(nodename);
> >
> > @@ -449,9 +433,8 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >          (long)memmap[SIFIVE_U_DEV_PWM0].base);
> >      qemu_fdt_add_subnode(fdt, nodename);
> >      qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,pwm0");
> > -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> > -        0x0, memmap[SIFIVE_U_DEV_PWM0].base,
> > -        0x0, memmap[SIFIVE_U_DEV_PWM0].size);
> > +qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_PWM0]);
> > +
> >      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
> >      qemu_fdt_setprop_cells(fdt, nodename, "interrupts",
> >                             SIFIVE_U_PWM0_IRQ0, SIFIVE_U_PWM0_IRQ1,
> > @@ -496,9 +479,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> >          (long)memmap[SIFIVE_U_DEV_UART0].base);
> >      qemu_fdt_add_subnode(fdt, nodename);
> >      qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,uart0");
> > -    qemu_fdt_setprop_cells(fdt, nodename, "reg",
> > -        0x0, memmap[SIFIVE_U_DEV_UART0].base,
> > -        0x0, memmap[SIFIVE_U_DEV_UART0].size);
> > +    qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_UART0]);
> >      qemu_fdt_setprop_cells(fdt, nodename, "clocks",
> >          prci_phandle, PRCI_CLK_TLCLK);
> >      qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
> > --
> > 2.35.1
> >
> >


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/4] device_tree: add qemu_fdt_setprop_strings() helper
  2022-06-18 20:14 ` [PATCH 3/4] device_tree: add qemu_fdt_setprop_strings() helper Ben Dooks
@ 2022-06-20  6:47   ` Alistair Francis
  0 siblings, 0 replies; 19+ messages in thread
From: Alistair Francis @ 2022-06-20  6:47 UTC (permalink / raw)
  To: Ben Dooks
  Cc: qemu-devel@nongnu.org Developers, Palmer Dabbelt,
	Alistair Francis, Bin Meng, open list:RISC-V

On Sun, Jun 19, 2022 at 6:20 AM Ben Dooks <qemu@ben.fluff.org> wrote:
>
> 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 <qemu@ben.fluff.org>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> --
> v2:
> - fix node/path in comment
> ---
>  include/sysemu/device_tree.h | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
> index 79ce009a22..28b68bacaf 100644
> --- a/include/sysemu/device_tree.h
> +++ b/include/sysemu/device_tree.h
> @@ -87,6 +87,21 @@ 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
> + */
> +#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);
> --
> 2.35.1
>
>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
  2022-06-18 20:14 ` [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c Ben Dooks
@ 2022-06-20  6:47   ` Alistair Francis
  2022-06-21 10:54     ` Ben Dooks
  0 siblings, 1 reply; 19+ messages in thread
From: Alistair Francis @ 2022-06-20  6:47 UTC (permalink / raw)
  To: Ben Dooks
  Cc: qemu-devel@nongnu.org Developers, Palmer Dabbelt,
	Alistair Francis, Bin Meng, open list:RISC-V

On Sun, Jun 19, 2022 at 6:14 AM Ben Dooks <qemu@ben.fluff.org> wrote:
>
> Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
> the code.
>
> Signed-off-by: Ben Dooks <qemu@ben.fluff.org>

Do you mind updating the other machines as well?

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/riscv/sifive_u.c | 18 +++++-------------
>  1 file changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
> index 89d7aa2a52..16b18d90bd 100644
> --- a/hw/riscv/sifive_u.c
> +++ b/hw/riscv/sifive_u.c
> @@ -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,8 +214,8 @@ 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_strings(fdt, nodename, "compatible",
> +                             "sifive,clint0", "riscv,clint0");
>      qemu_fdt_setprop_reg64_map(fdt, nodename, &memmap[SIFIVE_U_DEV_CLINT]);
>      qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
>          cells, ms->smp.cpus * sizeof(uint32_t) * 4);
> @@ -273,8 +266,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));
> @@ -410,8 +403,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 **)&ethclk_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);
> --
> 2.35.1
>
>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
  2022-06-20  6:47   ` Alistair Francis
@ 2022-06-21 10:54     ` Ben Dooks
  2022-06-22  5:13       ` Alistair Francis
  0 siblings, 1 reply; 19+ messages in thread
From: Ben Dooks @ 2022-06-21 10:54 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Ben Dooks, qemu-devel@nongnu.org Developers, Palmer Dabbelt,
	Alistair Francis, Bin Meng, open list:RISC-V

On Mon, Jun 20, 2022 at 04:47:44PM +1000, Alistair Francis wrote:
> On Sun, Jun 19, 2022 at 6:14 AM Ben Dooks <qemu@ben.fluff.org> wrote:
> >
> > Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
> > the code.
> >
> > Signed-off-by: Ben Dooks <qemu@ben.fluff.org>
> 
> Do you mind updating the other machines as well?

I can do, I was wondering if anyone had a good guide how to use cocci
to do it automatiically as I have been finding it really difficult to
work out how to automate API changes.

-- 
Ben Dooks, ben@fluff.org, http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
  2022-06-21 10:54     ` Ben Dooks
@ 2022-06-22  5:13       ` Alistair Francis
  0 siblings, 0 replies; 19+ messages in thread
From: Alistair Francis @ 2022-06-22  5:13 UTC (permalink / raw)
  To: Ben Dooks
  Cc: qemu-devel@nongnu.org Developers, Palmer Dabbelt,
	Alistair Francis, Bin Meng, open list:RISC-V

On Tue, Jun 21, 2022 at 8:54 PM Ben Dooks <qemu@ben.fluff.org> wrote:
>
> On Mon, Jun 20, 2022 at 04:47:44PM +1000, Alistair Francis wrote:
> > On Sun, Jun 19, 2022 at 6:14 AM Ben Dooks <qemu@ben.fluff.org> wrote:
> > >
> > > Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
> > > the code.
> > >
> > > Signed-off-by: Ben Dooks <qemu@ben.fluff.org>
> >
> > Do you mind updating the other machines as well?
>
> I can do, I was wondering if anyone had a good guide how to use cocci
> to do it automatiically as I have been finding it really difficult to
> work out how to automate API changes.

I don't have any tips unfortunately

Alistair

>
> --
> Ben Dooks, ben@fluff.org, http://www.fluff.org/ben/
>
> Large Hadron Colada: A large Pina Colada that makes the universe disappear.
>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
  2022-04-22  2:19     ` Bin Meng
  (?)
@ 2022-06-18 19:40     ` Ben Dooks
  -1 siblings, 0 replies; 19+ messages in thread
From: Ben Dooks @ 2022-06-18 19:40 UTC (permalink / raw)
  To: Bin Meng
  Cc: Ben Dooks, Alistair Francis, Bin Meng, Palmer Dabbelt,
	qemu-devel@nongnu.org Developers, open list:RISC-V

On Fri, Apr 22, 2022 at 10:19:34AM +0800, Bin Meng wrote:
> On Mon, Apr 18, 2022 at 5:13 AM Ben Dooks <qemu@ben.fluff.org> wrote:
> >
> > Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
> > the code.
> >
> > Signed-off-by; Ben Dooks <qemu@ben.fluff.org>
> 
> ; should be replaced to :
> 
> Not sure how you did that, but you can do with "git commit -s" and git
> will take care of the SoB tag.

I'm used to adding them manually to git commit messages.

-- 
Ben Dooks, ben@fluff.org, http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
  2022-04-16 19:30   ` Ben Dooks
@ 2022-04-22  2:19     ` Bin Meng
  -1 siblings, 0 replies; 19+ messages in thread
From: Bin Meng @ 2022-04-22  2:19 UTC (permalink / raw)
  To: Ben Dooks
  Cc: Alistair Francis, Bin Meng, Palmer Dabbelt,
	qemu-devel@nongnu.org Developers, open list:RISC-V

On Mon, Apr 18, 2022 at 5:13 AM Ben Dooks <qemu@ben.fluff.org> wrote:
>
> Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
> the code.
>
> Signed-off-by; Ben Dooks <qemu@ben.fluff.org>

; should be replaced to :

Not sure how you did that, but you can do with "git commit -s" and git
will take care of the SoB tag.

> ---
>  hw/riscv/sifive_u.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
>

Regards,
Bin


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
@ 2022-04-22  2:19     ` Bin Meng
  0 siblings, 0 replies; 19+ messages in thread
From: Bin Meng @ 2022-04-22  2:19 UTC (permalink / raw)
  To: Ben Dooks
  Cc: qemu-devel@nongnu.org Developers, Palmer Dabbelt,
	Alistair Francis, Bin Meng, open list:RISC-V

On Mon, Apr 18, 2022 at 5:13 AM Ben Dooks <qemu@ben.fluff.org> wrote:
>
> Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
> the code.
>
> Signed-off-by; Ben Dooks <qemu@ben.fluff.org>

; should be replaced to :

Not sure how you did that, but you can do with "git commit -s" and git
will take care of the SoB tag.

> ---
>  hw/riscv/sifive_u.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
>

Regards,
Bin


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
  2022-04-16 19:30   ` Ben Dooks
@ 2022-04-17 21:38     ` Ben Dooks
  -1 siblings, 0 replies; 19+ messages in thread
From: Ben Dooks @ 2022-04-17 21:38 UTC (permalink / raw)
  To: Ben Dooks; +Cc: Alistair.Francis, bin.meng, palmer, qemu-devel, qemu-riscv

On Sat, Apr 16, 2022 at 08:30:34PM +0100, Ben Dooks wrote:
> Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
> the code.
> 
> Signed-off-by; Ben Dooks <qemu@ben.fluff.org>
> ---
>  hw/riscv/sifive_u.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
> index 1fe364cbb0..b00086d86e 100644
> --- a/hw/riscv/sifive_u.c
> +++ b/hw/riscv/sifive_u.c
> @@ -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,8 +214,8 @@ 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_strings(fdt, nodename, "compatible",
> +                             "sifive,clint0", "riscv,clint0");
>      qemu_fdt_setprop_reg64(fdt, nodename, &memmap[SIFIVE_U_DEV_CLINT]);
>      qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
>          cells, ms->smp.cpus * sizeof(uint32_t) * 4);
> @@ -273,8 +266,10 @@ 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_string_array(fdt, nodename, "compatible",
> +    //    (char **)&plic_compat, ARRAY_SIZE(plic_compat));

Whoops, will fix this conversion, should have removed the original
instead of commenting it out.

-- 
Ben Dooks, ben@fluff.org, http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
@ 2022-04-17 21:38     ` Ben Dooks
  0 siblings, 0 replies; 19+ messages in thread
From: Ben Dooks @ 2022-04-17 21:38 UTC (permalink / raw)
  To: Ben Dooks; +Cc: qemu-devel, palmer, Alistair.Francis, bin.meng, qemu-riscv

On Sat, Apr 16, 2022 at 08:30:34PM +0100, Ben Dooks wrote:
> Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
> the code.
> 
> Signed-off-by; Ben Dooks <qemu@ben.fluff.org>
> ---
>  hw/riscv/sifive_u.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
> index 1fe364cbb0..b00086d86e 100644
> --- a/hw/riscv/sifive_u.c
> +++ b/hw/riscv/sifive_u.c
> @@ -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,8 +214,8 @@ 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_strings(fdt, nodename, "compatible",
> +                             "sifive,clint0", "riscv,clint0");
>      qemu_fdt_setprop_reg64(fdt, nodename, &memmap[SIFIVE_U_DEV_CLINT]);
>      qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
>          cells, ms->smp.cpus * sizeof(uint32_t) * 4);
> @@ -273,8 +266,10 @@ 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_string_array(fdt, nodename, "compatible",
> +    //    (char **)&plic_compat, ARRAY_SIZE(plic_compat));

Whoops, will fix this conversion, should have removed the original
instead of commenting it out.

-- 
Ben Dooks, ben@fluff.org, http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
  2022-04-16 19:30 A couple of new device-tree helpers Ben Dooks
@ 2022-04-16 19:30   ` Ben Dooks
  0 siblings, 0 replies; 19+ messages in thread
From: Ben Dooks @ 2022-04-16 19:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ben Dooks, palmer, Alistair.Francis, bin.meng, qemu-riscv

Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
the code.

Signed-off-by; Ben Dooks <qemu@ben.fluff.org>
---
 hw/riscv/sifive_u.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index 1fe364cbb0..b00086d86e 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -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,8 +214,8 @@ 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_strings(fdt, nodename, "compatible",
+                             "sifive,clint0", "riscv,clint0");
     qemu_fdt_setprop_reg64(fdt, nodename, &memmap[SIFIVE_U_DEV_CLINT]);
     qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
         cells, ms->smp.cpus * sizeof(uint32_t) * 4);
@@ -273,8 +266,10 @@ 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_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));
@@ -410,8 +405,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 **)&ethclk_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);
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c
@ 2022-04-16 19:30   ` Ben Dooks
  0 siblings, 0 replies; 19+ messages in thread
From: Ben Dooks @ 2022-04-16 19:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-riscv, palmer, bin.meng, Alistair.Francis, Ben Dooks

Use the qemu_fdt_setprop_strings() in sifve_u.c to simplify
the code.

Signed-off-by; Ben Dooks <qemu@ben.fluff.org>
---
 hw/riscv/sifive_u.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index 1fe364cbb0..b00086d86e 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -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,8 +214,8 @@ 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_strings(fdt, nodename, "compatible",
+                             "sifive,clint0", "riscv,clint0");
     qemu_fdt_setprop_reg64(fdt, nodename, &memmap[SIFIVE_U_DEV_CLINT]);
     qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
         cells, ms->smp.cpus * sizeof(uint32_t) * 4);
@@ -273,8 +266,10 @@ 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_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));
@@ -410,8 +405,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 **)&ethclk_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);
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-06-22  5:16 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-18 20:14 [v2] pair of device-tree helpers Ben Dooks
2022-06-18 20:14 ` [PATCH 1/4] device_tree: add qemu_fdt_setprop_reg64_map helper Ben Dooks
2022-06-20  6:41   ` Alistair Francis
2022-06-18 20:14 ` [PATCH 2/4] hw/riscv: use qemu_fdt_setprop_reg64_map() in sifive_u.c Ben Dooks
2022-06-20  6:42   ` Alistair Francis
2022-06-20  6:44     ` Alistair Francis
2022-06-18 20:14 ` [PATCH 3/4] device_tree: add qemu_fdt_setprop_strings() helper Ben Dooks
2022-06-20  6:47   ` Alistair Francis
2022-06-18 20:14 ` [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c Ben Dooks
2022-06-20  6:47   ` Alistair Francis
2022-06-21 10:54     ` Ben Dooks
2022-06-22  5:13       ` Alistair Francis
  -- strict thread matches above, loose matches on Subject: below --
2022-04-16 19:30 A couple of new device-tree helpers Ben Dooks
2022-04-16 19:30 ` [PATCH 4/4] hw/riscv: use qemu_fdt_setprop_strings() in sifive_u.c Ben Dooks
2022-04-16 19:30   ` Ben Dooks
2022-04-17 21:38   ` Ben Dooks
2022-04-17 21:38     ` Ben Dooks
2022-04-22  2:19   ` Bin Meng
2022-04-22  2:19     ` Bin Meng
2022-06-18 19:40     ` Ben Dooks

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.