hw/ppc: Implement -dtb support for PowerNV
PATCH v2 1/1 hw/ppc: Implement -dtb support for PowerNV
Currently any device tree passed with -dtb option in QEMU, was ignored by the PowerNV code.
Read and pass the passed -dtb to the kernel, thus enabling easier debugging with custom DTBs.
The existing behaviour when -dtb is 'not' passed, is preserved as-is.
But when a '-dtb' is passed, it completely overrides any dtb nodes or changes QEMU might have done, such as '-append' arguments to the kernel (which are mentioned in /chosen/bootargs in the dtb), hence add warning when -dtb is being used
---
Changelog
===========
v2:
+ move reading dtb and warning to pnv_init
v1:
+ use 'g_file_get_contents' and add check for -append & -dtb as suggested by Daniel
---
--- hw/ppc/pnv.c | 29 ++++++++++++++++++++++++++--- include/hw/ppc/pnv.h | 2 ++ 2 files changed, 28 insertions(+), 3 deletions(-)
hw/ppc/pnv.c +26 -3
@@ -736,11 +736,14 @@ static void pnv_reset(MachineState *machine, ShutdownCause reason) } } - fdt =pnv_dt_create (machine); +if (!pnv->fdt) { + pnv->fdt =pnv_dt_create (machine); -/* Pack resulting tree */ -_FDT ((fdt_pack (fdt))); +/* Pack resulting tree */ +_FDT ((fdt_pack (pnv->fdt))); + } + fdt = pnv->fdt;qemu_fdt_dumpdtb (fdt,fdt_totalsize (fdt));cpu_physical_memory_write (PNV_FDT_ADDR , fdt,fdt_totalsize (fdt));
@@ -952,6 +955,14 @@ static void pnv_init(MachineState *machine)g_free (sz);exit (EXIT_FAILURE ); } + +/* checks for invalid option combinations */ +if (machine->dtb && (strlen (machine->kernel_cmdline) !=0 )) { +error_report ("-append and -dtb cannot be used together, as passed" +" command line is ignored in case of custom dtb" ); +exit (EXIT_FAILURE ); + } +memory_region_add_subregion (get_system_memory (),0 , machine->ram);/*
@@ -1003,6 +1014,18 @@ static void pnv_init(MachineState *machine) } } +/* load dtb if passed */ +if (machine->dtb) { +warn_report ("with manually passed dtb, some options like '-append'" +" will get ignored and the dtb passed will be used as-is" ); + +/* read the file 'machine->dtb', and load it into 'fdt' buffer */ +if (!g_file_get_contents (machine->dtb, (gchar **)&pnv->fdt,NULL ,NULL )) { +error_report ("Could not load dtb '%s'" , machine->dtb); +exit (1 ); + } + } +/* MSIs are supported on this platform */ msi_nonbroken = true;
include/hw/ppc/pnv.h +2 -0
@@ -91,6 +91,8 @@ struct PnvMachineState {uint32_t initrd_base;long initrd_size; +void *fdt; +uint32_t num_chips;PnvChip **chips;
Signature · 1 line
2.45.2
Quoted 34 lines · Aditya Gupta
Currently any device tree passed with -dtb option in QEMU, was ignored by the PowerNV code.
Read and pass the passed -dtb to the kernel, thus enabling easier debugging with custom DTBs.
The existing behaviour when -dtb is 'not' passed, is preserved as-is.
But when a '-dtb' is passed, it completely overrides any dtb nodes or changes QEMU might have done, such as '-append' arguments to the kernel (which are mentioned in /chosen/bootargs in the dtb), hence add warning when -dtb is being used
Signed-off-by Aditya Gupta <[email protected]>---
Changelog
===========
v2:
+ move reading dtb and warning topnv_initv1:
+ use 'g_file_get_contents' and add check for -append & -dtb as suggested by Daniel
------ hw/ppc/pnv.c | 29 ++++++++++++++++++++++++++--- include/hw/ppc/pnv.h | 2 ++ 2 files changed, 28 insertions(+), 3 deletions(-)hw/ppc/pnv.c +0
-0
hw/ppc/pnv.c static void pnv_reset(MachineState *machine, ShutdownCause reason) · line 740
Quoted 6 lines
hw/ppc/pnv.c +2
-1@@ -736,11 +736,14 @@ static void pnv_reset(MachineState *machine, ShutdownCause reason) } } - fdt =pnv_dt_create (machine); +if (!pnv->fdt) { + pnv->fdt =pnv_dt_create (machine);
At next reset, the dtb specified on the command line will be ignored. Please reverse the logic :
if (pnv->fdt) {
fdt = pnv->fdt;
} else {
fdt = pnv_dt_create(machine);
/* Pack resulting tree */
_FDT((fdt_pack(fdt)));
}but, at the end of pnv_reset(), beware of :
g_free(machine->fdt);
machine->fdt = fdt;Quoted 11 lines
hw/ppc/pnv.c +4
-2-/* Pack resulting tree */ -_FDT ((fdt_pack (fdt))); +/* Pack resulting tree */ +_FDT ((fdt_pack (pnv->fdt))); + } + fdt = pnv->fdt;qemu_fdt_dumpdtb (fdt,fdt_totalsize (fdt));cpu_physical_memory_write (PNV_FDT_ADDR , fdt,fdt_totalsize (fdt));
hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 963
Quoted 9 lines
hw/ppc/pnv.c +6
-0@@ -952,6 +955,14 @@ static void pnv_init(MachineState *machine)g_free (sz);exit (EXIT_FAILURE ); } + +/* checks for invalid option combinations */ +if (machine->dtb && (strlen (machine->kernel_cmdline) !=0 )) { +error_report ("-append and -dtb cannot be used together, as passed" +" command line is ignored in case of custom dtb" ); +exit (EXIT_FAILURE );
I think this is redundant with the warn report below.
Quoted 9 lines
hw/ppc/pnv.c +2
-0+ } +memory_region_add_subregion (get_system_memory (),0 , machine->ram);/* @@ -1003,6 +1014,18 @@ static void pnv_init(MachineState *machine) } }
hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 1026
Quoted 10 lines
hw/ppc/pnv.c +10
-0+/* load dtb if passed */ +if (machine->dtb) { +warn_report ("with manually passed dtb, some options like '-append'" +" will get ignored and the dtb passed will be used as-is" ); + +/* read the file 'machine->dtb', and load it into 'fdt' buffer */ +if (!g_file_get_contents (machine->dtb, (gchar **)&pnv->fdt,NULL ,NULL )) { +error_report ("Could not load dtb '%s'" , machine->dtb); +exit (1 ); + }
There is a load_device_tree() routine you could use. Please check how other machines handle -dtb for examples.
Thanks,
C.
Quoted 18 lines
hw/ppc/pnv.c +2
-0+ } +/* MSIs are supported on this platform */ msi_nonbroken = true;include/hw/ppc/pnv.h +2
-0@@ -91,6 +91,8 @@ struct PnvMachineState {uint32_t initrd_base;long initrd_size; +void *fdt; +uint32_t num_chips;PnvChip **chips;
Hi Cedric,
Sorry for the late reply.
Quoted 45 lines · Cédric Le Goater
Quoted 34 lines · Aditya Gupta
Currently any device tree passed with -dtb option in QEMU, was ignored by the PowerNV code.
Read and pass the passed -dtb to the kernel, thus enabling easier debugging with custom DTBs.
The existing behaviour when -dtb is 'not' passed, is preserved as-is.
But when a '-dtb' is passed, it completely overrides any dtb nodes or changes QEMU might have done, such as '-append' arguments to the kernel (which are mentioned in /chosen/bootargs in the dtb), hence add warning when -dtb is being used
Signed-off-by Aditya Gupta <[email protected]>---
Changelog
===========
v2:
+ move reading dtb and warning topnv_initv1:
+ use 'g_file_get_contents' and add check for -append & -dtb as suggested by Daniel
---
---
hw/ppc/pnv.c | 29 ++++++++++++++++++++++++++---include/hw/ppc/pnv.h| 2 ++2 files changed, 28 insertions(+), 3 deletions(-)hw/ppc/pnv.c +0
-0hw/ppc/pnv.c static void pnv_reset(MachineState *machine, · line 741
Quoted 6 lines
hw/ppc/pnv.c +2
-0@@ -736,11 +736,14 @@ static void pnv_reset(MachineState *machine, ShutdownCause reason) } } - fdt = pnv_dt_create(machine); + if (!pnv->fdt) { + pnv->fdt = pnv_dt_create(machine);At next reset, the dtb specified on the command line will be ignored. Please reverse the logic :
Quoted 7 lines
if (
pnv->fdt) {
fdt =pnv->fdt;
} else {
fdt =pnv_dt_create(machine);
/* Pack resulting tree */
_FDT((fdt_pack(fdt)));
}
Understood, thanks for pointing it out.
Quoted 6 lines
but, at the end of
pnv_reset(), beware of :
g_free(machine->fdt);
machine->fdt= fdt;
That should be okay right ? Even if machine->fdt is NULL, that's okay, and we assign the latest fdt to machine->fdt
Quoted 21 lines
Quoted 12 lines
hw/ppc/pnv.c +3
-2- /* Pack resulting tree */ - _FDT((fdt_pack(fdt))); + /* Pack resulting tree */ + _FDT((fdt_pack(pnv->fdt))); + } + fdt = pnv->fdt; qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt)); cpu_physical_memory_write(PNV_FDT_ADDR, fdt, fdt_totalsize(fdt)); @@ -952,6 +955,14 @@ static void pnv_init(MachineState *machine) g_free(sz);
exit(EXIT_FAILURE);Quoted 8 lines
}
+
+ /* checks for invalid option combinations */
+ if (machine->dtb&& (strlen(machine->kernel_cmdline)!= 0)) { + error_report("-append and -dtb cannot be used together, as passed"
+ " command line is ignored in case of custom dtb"); +exit(EXIT_FAILURE);
Quoted 1 line
I think this is redundant with the warn report below.
Can we keep it ?
The warning is meant to be generic, as other options, maybe even -smp might get ignored. There might be lot of such combinations.
While, the error above just covers one of the combinations, give an error if -append & -dtb are used together.
The error and warning seem repetitive, maybe I will add some more flags to the warning ?
Thanks,
Aditya Gupta
Quoted 49 lines
Quoted 14 lines
+ }
+
memory_region_add_subregion(get_system_memory(), 0, machine->ram); /*hw/ppc/pnv.c +0
-0@@ -1003,6 +1014,18 @@ static void pnv_init(MachineState *machine) } }+ /* load dtb if passed */
+ if (machine->dtb) {
+ warn_report("with manually passed dtb, some options like '-append'"
+ " will get ignored and the dtb passed will be used as-is");Quoted 8 lines
+
+ /* read the file 'machine->dtb', and load it into 'fdt' buffer */
+ if (!g_file_get_contents(machine->dtb, (gchar **)&pnv->fdt, NULL, NULL)) {
+error_report("Could not load dtb '%s'", machine->dtb); + exit(1);
+ }There is a
load_device_tree()routine you could use. Please check how other machines handle -dtb for examples.Thanks,
C.
Quoted 15 lines
+ }
+
/* MSIs are supported on this platform */msi_nonbroken= true;
diff --gita/include/hw/ppc/pnv.hb/include/hw/ppc/pnv.hindexfcb6699150c8..20b68fd9264e100644include/hw/ppc/pnv.h +1
-0@@ -91,6 +91,8 @@ struct PnvMachineState { uint32_t initrd_base; long initrd_size; + void *fdt; + uint32_t num_chips; PnvChip **chips;