Skip to contentSkip to conversation

riscv: Generate devicetree only after machine initialization is complete

PATCH Applied Guenter Roeck 3 participants 4 messages Jul 6, 2023 – Jul 10, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 riscv: Generate devicetree only after machine initialization is complete

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. Load/create devicetree in virt_machine_done() to solve the problem.

Cc Daniel Henrique Barboza <[email protected]>
Cc Alistair Francis <[email protected]>
Cc Daniel Henrique Barboza <[email protected]>
Fixes 325b7c4e75 hw/riscv: Enable TPM backends

---
v2: Handle devicetree (load & create) entirely in machine_done function.

 hw/riscv/virt.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
hw/riscv/virt.c +11 -11
index ed4c27487e..1c4bd823df 100644
@@ -1248,6 +1248,17 @@ static void virt_machine_done(Notifier *notifier, void *data)
     uint64_t kernel_entry = 0;
     BlockBackend *pflash_blk0;
 
+    /* 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);
+    }
+
     /*
      * Only direct boot kernel is currently supported for KVM VM,
      * so the "-bios" parameter is not supported when KVM is enabled.
@@ -1508,17 +1519,6 @@ static void virt_machine_init(MachineState *machine)
     }
     virt_flash_map(s, system_memory);
 
-    /* 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);
-    }
-
     s->machine_done.notify = virt_machine_done;
     qemu_add_machine_init_done_notifier(&s->machine_done);
 }
Signature · 1 line
2.39.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Guenter Roeck

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. Load/create devicetree in virt_machine_done() to solve the problem.

Cc Daniel Henrique Barboza <[email protected]>
Cc Alistair Francis <[email protected]>
Cc Daniel Henrique Barboza <[email protected]>
Fixes 325b7c4e75 hw/riscv: Enable TPM backends
Quoted 5 lines

---
v2: Handle devicetree (load & create) entirely in machine_done function.

  hw/riscv/virt.c | 22 +++++++++++-----------
  1 file changed, 11 insertions(+), 11 deletions(-)
Reviewed-by on v2 1/1
#2 lore raw
In reply to Guenter Roeck
Quoted 11 lines · Guenter Roeck

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. Load/create devicetree in virt_machine_done() to solve the problem.

Cc Daniel Henrique Barboza <[email protected]>
Cc Alistair Francis <[email protected]>
Cc Daniel Henrique Barboza <[email protected]>
Fixes 325b7c4e75 hw/riscv: Enable TPM backends

Alistair

Quoted 49 lines

---
v2: Handle devicetree (load & create) entirely in machine_done function.

 hw/riscv/virt.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
hw/riscv/virt.c +11 -12
index ed4c27487e..1c4bd823df 100644
@@ -1248,6 +1248,17 @@ static void virt_machine_done(Notifier *notifier, void *data)
     uint64_t kernel_entry = 0;
     BlockBackend *pflash_blk0;
 
+    /* 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);
+    }
+
     /*
      * Only direct boot kernel is currently supported for KVM VM,
      * so the "-bios" parameter is not supported when KVM is enabled.
@@ -1508,17 +1519,6 @@ static void virt_machine_init(MachineState *machine)
     }
     virt_flash_map(s, system_memory);
 
-    /* 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);
-    }
-
     s->machine_done.notify = virt_machine_done;
     qemu_add_machine_init_done_notifier(&s->machine_done);
 }
--

2.39.2

#3 lore raw
In reply to Guenter Roeck
Quoted 11 lines · Guenter Roeck

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. Load/create devicetree in virt_machine_done() to solve the problem.

Cc Daniel Henrique Barboza <[email protected]>
Cc Alistair Francis <[email protected]>
Cc Daniel Henrique Barboza <[email protected]>
Fixes 325b7c4e75 hw/riscv: Enable TPM backends

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 49 lines

---
v2: Handle devicetree (load & create) entirely in machine_done function.

 hw/riscv/virt.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
hw/riscv/virt.c +11 -12
index ed4c27487e..1c4bd823df 100644
@@ -1248,6 +1248,17 @@ static void virt_machine_done(Notifier *notifier, void *data)
     uint64_t kernel_entry = 0;
     BlockBackend *pflash_blk0;
 
+    /* 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);
+    }
+
     /*
      * Only direct boot kernel is currently supported for KVM VM,
      * so the "-bios" parameter is not supported when KVM is enabled.
@@ -1508,17 +1519,6 @@ static void virt_machine_init(MachineState *machine)
     }
     virt_flash_map(s, system_memory);
 
-    /* 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);
-    }
-
     s->machine_done.notify = virt_machine_done;
     qemu_add_machine_init_done_notifier(&s->machine_done);
 }
--

2.39.2