qemu-riscv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] riscv: Generate devicetree only after machine initialization


From: Daniel Henrique Barboza
Subject: Re: [PATCH] riscv: Generate devicetree only after machine initialization is complete
Date: Mon, 3 Jul 2023 16:25:14 -0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0

On 7/3/23 00:46, Guenter Roeck wrote:
If the devicetree is created before machine initialization is complete,
it misses dynamic devices. Specifically, the tpm device is not added
to the devicetree file and is therefore not instantiated in Linux.
Create devicetree in virt_machine_done() to solve the problem.

Cc: Alistair Francis <alistair23@gmail.com>
Fixes: 325b7c4e75 hw/riscv: Enable TPM backends
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
  hw/riscv/virt.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index ed4c27487e..08876284f5 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -1248,6 +1248,11 @@ static void virt_machine_done(Notifier *notifier, void 
*data)
      uint64_t kernel_entry = 0;
      BlockBackend *pflash_blk0;
+ /* create devicetree if not provided */
+    if (!machine->dtb) {
+        create_fdt(s, memmap);
+    }
+

I suggest moving the entire load/create DT code from virt_machine_init() to
the start of virt_machine_done():

    /* load/create device tree */
    if (machine->dtb) {
        machine->fdt = load_device_tree(machine->dtb, &s->fdt_size);
        if (!machine->fdt) {
            error_report("load_device_tree() failed");
            exit(1);
        }
    } else {
        create_fdt(s, memmap);
    }

This way we don't have to look in to 2 different functions to wonder what 
happens
in case machine->dtb is NULL.


Thanks,


Daniel


      /*
       * Only direct boot kernel is currently supported for KVM VM,
       * so the "-bios" parameter is not supported when KVM is enabled.
@@ -1508,15 +1513,13 @@ static void virt_machine_init(MachineState *machine)
      }
      virt_flash_map(s, system_memory);
- /* load/create device tree */
+    /* load device tree */
      if (machine->dtb) {
          machine->fdt = load_device_tree(machine->dtb, &s->fdt_size);
          if (!machine->fdt) {
              error_report("load_device_tree() failed");
              exit(1);
          }
-    } else {
-        create_fdt(s, memmap);
      }
s->machine_done.notify = virt_machine_done;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]