Skip to contentSkip to conversation

riscv/virt: Add syscon reboot and poweroff DT nodes

PATCH Superseded Anup Patel 3 participants 5 messages Nov 11, 2019 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 riscv/virt: Add syscon reboot and poweroff DT nodes

The SiFive test device found on virt machine can be used by generic syscon reboot and poweroff drivers available in Linux kernel.

This patch updates FDT generation in virt machine so that Linux kernel can probe and use generic syscon drivers.

---
 hw/riscv/virt.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
hw/riscv/virt.c +24 -4
index cc8f311e6b..fdfa359713 100644
@@ -182,11 +182,11 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
     uint64_t mem_size, const char *cmdline)
 {
     void *fdt;
-    int cpu;
+    int cpu, i;
     uint32_t *cells;
     char *nodename;
-    uint32_t plic_phandle, phandle = 1;
-    int i;
+    const char test_compat[] = "sifive,test0\0syscon";
+    uint32_t plic_phandle, test_phandle, phandle = 1;
     hwaddr flashsize = virt_memmap[VIRT_FLASH].size / 2;
     hwaddr flashbase = virt_memmap[VIRT_FLASH].base;
 
@@ -356,13 +356,33 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
     create_pcie_irq_map(fdt, nodename, plic_phandle);
     g_free(nodename);
 
+    test_phandle = phandle++;
     nodename = g_strdup_printf("/test@%lx",
         (long)memmap[VIRT_TEST].base);
     qemu_fdt_add_subnode(fdt, nodename);
-    qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,test0");
+    qemu_fdt_setprop(fdt, nodename, "compatible",
+                     test_compat, sizeof(test_compat));
     qemu_fdt_setprop_cells(fdt, nodename, "reg",
         0x0, memmap[VIRT_TEST].base,
         0x0, memmap[VIRT_TEST].size);
+    qemu_fdt_setprop_cell(fdt, nodename, "phandle", test_phandle);
+    test_phandle = qemu_fdt_get_phandle(fdt, nodename);
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/reboot");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-reboot");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_RESET);
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/poweroff");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-poweroff");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_PASS);
     g_free(nodename);
 
     nodename = g_strdup_printf("/uart@%lx",
Signature · 1 line
2.17.1
author
#1 lore raw

Correct Palmer's email address.

Quoted 81 lines

-----Original Message-----
From: Anup Patel
Sent: Monday, November 11, 2019 7:08 PM
To: Peter Maydell <[email protected]>; Palmer Dabbelt <[email protected]>; Alistair Francis <[email protected]>; Sagar Karandikar <[email protected]>
Cc: Atish Patra <[email protected]>; Christoph Hellwig <[email protected]>; Anup Patel <[email protected]>; [email protected]; qemu- [email protected]; Anup Patel <[email protected]>
Subject: [PATCH] riscv/virt: Add syscon reboot and poweroff DT nodes

The SiFive test device found on virt machine can be used by generic syscon reboot and poweroff drivers available in Linux kernel.

This patch updates FDT generation in virt machine so that Linux kernel can probe and use generic syscon drivers.

---
 hw/riscv/virt.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
hw/riscv/virt.c index cc8f311e6b..fdfa359713 renamed from hw/riscv/virt.c +0 -0

100644

hw/riscv/virt.c +24 -4
@@ -182,11 +182,11 @@ static void create_fdt(RISCVVirtState *s, const
 struct MemmapEntry *memmap,
     uint64_t mem_size, const char *cmdline)  {
     void *fdt;
-    int cpu;
+    int cpu, i;
     uint32_t *cells;
     char *nodename;
-    uint32_t plic_phandle, phandle = 1;
-    int i;
+    const char test_compat[] = "sifive,test0\0syscon";
+    uint32_t plic_phandle, test_phandle, phandle = 1;
     hwaddr flashsize = virt_memmap[VIRT_FLASH].size / 2;
     hwaddr flashbase = virt_memmap[VIRT_FLASH].base;
 
@@ -356,13 +356,33 @@ static void create_fdt(RISCVVirtState *s, const
 struct MemmapEntry *memmap,
     create_pcie_irq_map(fdt, nodename, plic_phandle);
     g_free(nodename);
 
+    test_phandle = phandle++;
     nodename = g_strdup_printf("/test@%lx",
         (long)memmap[VIRT_TEST].base);
     qemu_fdt_add_subnode(fdt, nodename);
-    qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,test0");
+    qemu_fdt_setprop(fdt, nodename, "compatible",
+                     test_compat, sizeof(test_compat));
     qemu_fdt_setprop_cells(fdt, nodename, "reg",
         0x0, memmap[VIRT_TEST].base,
         0x0, memmap[VIRT_TEST].size);
+    qemu_fdt_setprop_cell(fdt, nodename, "phandle", test_phandle);
+    test_phandle = qemu_fdt_get_phandle(fdt, nodename);
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/reboot");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-
 reboot");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_RESET);
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/poweroff");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-
 poweroff");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_PASS);
     g_free(nodename);

     nodename = g_strdup_printf("/uart@%lx",

--
2.17.1

#2 lore raw
Quoted 49 lines · Anup Patel

Correct Palmer's email address.

Quoted 46 lines

-----Original Message-----
From: Anup Patel
Sent: Monday, November 11, 2019 7:08 PM
To: Peter Maydell <[email protected]>; Palmer Dabbelt <[email protected]>; Alistair Francis <[email protected]>; Sagar Karandikar <[email protected]>
Cc: Atish Patra <[email protected]>; Christoph Hellwig <[email protected]>; Anup Patel <[email protected]>; [email protected]; qemu- [email protected]; Anup Patel <[email protected]>
Subject: [PATCH] riscv/virt: Add syscon reboot and poweroff DT nodes

The SiFive test device found on virt machine can be used by generic syscon reboot and poweroff drivers available in Linux kernel.

This patch updates FDT generation in virt machine so that Linux kernel can probe and use generic syscon drivers.

---
 hw/riscv/virt.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
hw/riscv/virt.c index cc8f311e6b..fdfa359713 renamed from hw/riscv/virt.c +0 -0

100644

hw/riscv/virt.c +3 -3
@@ -182,11 +182,11 @@ static void create_fdt(RISCVVirtState *s, const
 struct MemmapEntry *memmap,
     uint64_t mem_size, const char *cmdline)  {
     void *fdt;
-    int cpu;
+    int cpu, i;
     uint32_t *cells;
     char *nodename;
-    uint32_t plic_phandle, phandle = 1;
-    int i;
+    const char test_compat[] = "sifive,test0\0syscon";
+    uint32_t plic_phandle, test_phandle, phandle = 1;
     hwaddr flashsize = virt_memmap[VIRT_FLASH].size / 2;
     hwaddr flashbase = virt_memmap[VIRT_FLASH].base;
 
@@ -356,13 +356,33 @@ static void create_fdt(RISCVVirtState *s, const
 struct MemmapEntry *memmap,
     create_pcie_irq_map(fdt, nodename, plic_phandle);
     g_free(nodename);
 
Quoted 12 lines

hw/riscv/virt.c static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap, · line 369

Quoted 12 lines
hw/riscv/virt.c +5 -1
+    test_phandle = phandle++;
     nodename = g_strdup_printf("/test@%lx",
         (long)memmap[VIRT_TEST].base);
     qemu_fdt_add_subnode(fdt, nodename);
-    qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,test0");
+    qemu_fdt_setprop(fdt, nodename, "compatible",
+                     test_compat, sizeof(test_compat));
     qemu_fdt_setprop_cells(fdt, nodename, "reg",
         0x0, memmap[VIRT_TEST].base,
         0x0, memmap[VIRT_TEST].size);
+    qemu_fdt_setprop_cell(fdt, nodename, "phandle", test_phandle);
+    test_phandle = qemu_fdt_get_phandle(fdt, nodename);

Is this necessary?

Quoted 20 lines
Quoted 20 lines
hw/riscv/virt.c +16 -0
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/reboot");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-
 reboot");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_RESET);
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/poweroff");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-
 poweroff");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_PASS);
     g_free(nodename);
Quoted 2 lines
Quoted 2 lines
     nodename = g_strdup_printf("/uart@%lx",

--

Regards,
Bin

author
#3 lore raw
Quoted 79 lines

-----Original Message-----
From: Bin Meng <[email protected]>
Sent: Monday, November 11, 2019 8:58 PM
To: Anup Patel <[email protected]>
Cc: Peter Maydell <[email protected]>; Alistair Francis <[email protected]>; Sagar Karandikar <[email protected]>; Palmer Dabbelt <[email protected]>; [email protected]; Atish Patra <[email protected]>; [email protected]; Christoph Hellwig <[email protected]>; Anup Patel <[email protected]>
Subject: Re: [PATCH] riscv/virt: Add syscon reboot and poweroff DT nodes

Quoted 51 lines · Anup Patel

Correct Palmer's email address.

Quoted 48 lines

-----Original Message-----
From: Anup Patel
Sent: Monday, November 11, 2019 7:08 PM
To: Peter Maydell <[email protected]>; Palmer Dabbelt <[email protected]>; Alistair Francis <[email protected]>; Sagar Karandikar <[email protected]>
Cc: Atish Patra <[email protected]>; Christoph Hellwig <[email protected]>; Anup Patel <[email protected]>; [email protected]; qemu- [email protected]; Anup Patel <[email protected]>
Subject: [PATCH] riscv/virt: Add syscon reboot and poweroff DT nodes

The SiFive test device found on virt machine can be used by generic syscon reboot and poweroff drivers available in Linux kernel.

This patch updates FDT generation in virt machine so that Linux kernel can probe and use generic syscon drivers.

---
 hw/riscv/virt.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
hw/riscv/virt.c index renamed from hw/riscv/virt.c +0 -0

cc8f311e6b..fdfa359713
100644

hw/riscv/virt.c +3 -3
@@ -182,11 +182,11 @@ static void create_fdt(RISCVVirtState *s,
 const struct MemmapEntry *memmap,
     uint64_t mem_size, const char *cmdline)  {
     void *fdt;
-    int cpu;
+    int cpu, i;
     uint32_t *cells;
     char *nodename;
-    uint32_t plic_phandle, phandle = 1;
-    int i;
+    const char test_compat[] = "sifive,test0\0syscon";
+    uint32_t plic_phandle, test_phandle, phandle = 1;
     hwaddr flashsize = virt_memmap[VIRT_FLASH].size / 2;
     hwaddr flashbase = virt_memmap[VIRT_FLASH].base;
 
@@ -356,13 +356,33 @@ static void create_fdt(RISCVVirtState *s,
 const struct MemmapEntry *memmap,
     create_pcie_irq_map(fdt, nodename, plic_phandle);
     g_free(nodename);
 
Quoted 5 lines

hw/riscv/virt.c static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,

Quoted 5 lines
hw/riscv/virt.c +1 -1
+    test_phandle = phandle++;
     nodename = g_strdup_printf("/test@%lx",
         (long)memmap[VIRT_TEST].base);
     qemu_fdt_add_subnode(fdt, nodename);
-    qemu_fdt_setprop_string(fdt, nodename, "compatible",

"sifive,test0");

Quoted 7 lines

hw/riscv/virt.c static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap, · line 369

Quoted 7 lines
hw/riscv/virt.c +4 -0
+    qemu_fdt_setprop(fdt, nodename, "compatible",
+                     test_compat, sizeof(test_compat));
     qemu_fdt_setprop_cells(fdt, nodename, "reg",
         0x0, memmap[VIRT_TEST].base,
         0x0, memmap[VIRT_TEST].size);
+    qemu_fdt_setprop_cell(fdt, nodename, "phandle", test_phandle);
+    test_phandle = qemu_fdt_get_phandle(fdt, nodename);
Quoted 1 line

Is this necessary?

I was doubtful about this line myself but I tried to keep code consistent with other DT nodes (such as PLIC).

Regards,
Anup

Quoted 26 lines
Quoted 21 lines
Quoted 21 lines
hw/riscv/virt.c +16 -0
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/reboot");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-
 reboot");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_RESET);
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/poweroff");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-
 poweroff");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_PASS);
     g_free(nodename);
Quoted 2 lines
Quoted 2 lines
     nodename = g_strdup_printf("/uart@%lx",

--

Regards,
Bin

#4 lore raw
In reply to Anup Patel
Quoted 9 lines · Anup Patel

The SiFive test device found on virt machine can be used by generic syscon reboot and poweroff drivers available in Linux kernel.

This patch updates FDT generation in virt machine so that Linux kernel can probe and use generic syscon drivers.

Overall this looks fine. Palmer currently has a patch on list changing the sifive test string as well. It's probably best to rebase this on that patch.

We probably also need to make sure this is accepted in the RISC-V kernel tree first.

Alistair

Quoted 62 lines
---
 hw/riscv/virt.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
hw/riscv/virt.c +24 -5
index cc8f311e6b..fdfa359713 100644
@@ -182,11 +182,11 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
     uint64_t mem_size, const char *cmdline)
 {
     void *fdt;
-    int cpu;
+    int cpu, i;
     uint32_t *cells;
     char *nodename;
-    uint32_t plic_phandle, phandle = 1;
-    int i;
+    const char test_compat[] = "sifive,test0\0syscon";
+    uint32_t plic_phandle, test_phandle, phandle = 1;
     hwaddr flashsize = virt_memmap[VIRT_FLASH].size / 2;
     hwaddr flashbase = virt_memmap[VIRT_FLASH].base;
 
@@ -356,13 +356,33 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
     create_pcie_irq_map(fdt, nodename, plic_phandle);
     g_free(nodename);
 
+    test_phandle = phandle++;
     nodename = g_strdup_printf("/test@%lx",
         (long)memmap[VIRT_TEST].base);
     qemu_fdt_add_subnode(fdt, nodename);
-    qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,test0");
+    qemu_fdt_setprop(fdt, nodename, "compatible",
+                     test_compat, sizeof(test_compat));
     qemu_fdt_setprop_cells(fdt, nodename, "reg",
         0x0, memmap[VIRT_TEST].base,
         0x0, memmap[VIRT_TEST].size);
+    qemu_fdt_setprop_cell(fdt, nodename, "phandle", test_phandle);
+    test_phandle = qemu_fdt_get_phandle(fdt, nodename);
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/reboot");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-reboot");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_RESET);
+    g_free(nodename);
+
+    nodename = g_strdup_printf("/poweroff");
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-poweroff");
+    qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0);
+    qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_PASS);
     g_free(nodename);
 
     nodename = g_strdup_printf("/uart@%lx",
--

2.17.1