ppc: QOM'ify 405 board
v3 cover ppc: QOM'ify 405 board
Hello,
Here is large series QOM'ifying the PPC405 board. It introduces a new generic machine and SoC models, converts the current device models to QOM and populates the SoC. The process is quite mechanical without too much issues to handle. The noisy part is the initial patch introducing the SoC realize routine.
What's left ?
* the SDRAM mappings are very baroque and certainly could be simplified. I think we should QOMify the ppc440 machines before addressing this part.
Thanks,
C.
Changes in v3 :
- New device model Ppc4xxDcrDeviceState
- Removal of ppc4xx_mal_init(), ppc4xx_plb_init() and ppc405_ebc_init()
- Fixes for some reset issues
- Kept 2 RAM banks at the Soc level but only one is initialized.
- Moved SRAM under the machine. It's not part of the SoC according to the 405 specs
Changes in v2 :
- docs/about/removed-features.rst update
- Fix compile breakage (uic)
- Fix CPU reset, which breaking u-boot boot
- Changed prefix of memory regions to "ppc405"
- Reduced the number of RAM banks to 1. Second was a dummy one to please ppc405ep_init()
Cédric Le Goater (22):
ppc/ppc405: Remove taihu machine ppc/ppc405: Introduce a PPC405 generic machine ppc/ppc405: Move devices under the ref405ep machine ppc/ppc405: Move SRAM under the ref405ep machine ppc/ppc405: Introduce a PPC405 SoC ppc/ppc405: Start QOMification of the SoC ppc/ppc405: QOM'ify CPU
ppc/ppc4xx: Introduce a DCR device model ppc/ppc405: QOM'ify CPC
ppc/ppc405: QOM'ify GPT
ppc/ppc405: QOM'ify OCM
ppc/ppc405: QOM'ify GPIO
ppc/ppc405: QOM'ify DMA
ppc/ppc405: QOM'ify EBC
ppc/ppc405: QOM'ify OPBA
ppc/ppc405: QOM'ify POB
ppc/ppc405: QOM'ify PLB
ppc/ppc405: QOM'ify MAL
ppc/ppc405: QOM'ify FPGA
ppc/ppc405: Use an explicit PPCUIC object ppc/ppc405: Use an explicit I2C object ppc/ppc4xx: Fix sdram trace events
docs/about/deprecated.rst | 9 - docs/about/removed-features.rst | 6 + docs/system/ppc/embedded.rst | 1 - hw/ppc/ppc405.h | 198 +++++++- include/hw/ppc/ppc4xx.h | 48 +- hw/ppc/ppc405_boards.c | 375 ++++----------- hw/ppc/ppc405_uc.c | 828 +++++++++++++++++--------------- hw/ppc/ppc4xx_devs.c | 184 ++++--- hw/ppc/sam460ex.c | 24 +- MAINTAINERS | 2 +- 10 files changed, 903 insertions(+), 772 deletions(-)
Signature · 1 line
2.37.1
PATCH v3 1/22 ppc/ppc405: Remove taihu machine
It has been deprecated since 7.0.
--- docs/about/deprecated.rst | 9 -- docs/about/removed-features.rst | 6 + docs/system/ppc/embedded.rst | 1 - hw/ppc/ppc405_boards.c | 232 -------------------------------- MAINTAINERS | 2 +- 5 files changed, 7 insertions(+), 243 deletions(-)
docs/about/deprecated.rst +0 -9
@@ -233,15 +233,6 @@ deprecated; use the new name ``dtb-randomness`` instead. The new name better reflects the way this property affects all random data within the device tree blob, not just the ``kaslr-seed`` node. -PPC 405 ``taihu`` machine (since 7.0) -''''''''''''''''''''''''''''''''''''' - -The PPC 405 CPU is a system-on-a-chip, so all 405 machines are very similar, -except for some external periphery. However, the periphery of the ``taihu`` -machine is hardly emulated at all (e.g. neither the LCD nor the USB part had -been implemented), so there is not much value added by this board. Use the -``ref405ep`` machine instead. - ``pc-i440fx-1.4`` up to ``pc-i440fx-1.7`` (since 7.0) '''''''''''''''''''''''''''''''''''''''''''''''''''''
docs/about/removed-features.rst +6 -0
@@ -668,6 +668,12 @@ Aspeed ``swift-bmc`` machine (removed in 7.0) This machine was removed because it was unused. Alternative AST2500 based OpenPOWER machines are ``witherspoon-bmc`` and ``romulus-bmc``. +ppc ``taihu`` machine (removed in 7.2) +''''''''''''''''''''''''''''''''''''''''''''' + +This machine was removed because it was partially emulated and 405 +machines are very similar. Use the ``ref405ep`` machine instead. + linux-user mode CPUs --------------------
docs/system/ppc/embedded.rst +0 -1
@@ -6,5 +6,4 @@ Embedded family boards - ``ppce500`` generic paravirt e500 platform - ``ref405ep`` ref405ep - ``sam460ex`` aCube Sam460ex -- ``taihu`` taihu - ``virtex-ml507`` Xilinx Virtex ML507 reference design
hw/ppc/ppc405_boards.c +0 -232
241 lines not on this page · raw message
MAINTAINERS +1 -1
@@ -1282,7 +1282,7 @@ F: hw/openrisc/openrisc_sim.c PowerPC Machines ---------------- -405 (ref405ep and taihu) +405 (ref405ep) L: [email protected] S: Orphan F: hw/ppc/ppc405_boards.c
Signature · 1 line
2.37.1
PATCH v3 2/22 ppc/ppc405: Introduce a PPC405 generic machine
In reply to Cédric Le GoaterWe will use this machine as a base to define the ref405ep and possibly the PPC405 hotfoot board as found in the Linux kernel.
--- hw/ppc/ppc405_boards.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
hw/ppc/ppc405_boards.c +28 -3
@@ -50,6 +50,15 @@#define USE_FLASH_BIOS +#define TYPE_PPC405_MACHINE MACHINE_TYPE_NAME("ppc405") +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405MachineState,PPC405_MACHINE ); + +struct Ppc405MachineState { +/* Private */ +MachineState parent_obj; +/* Public */ +}; +/*****************************************************************************/ /* PPC405EP reference board (IBM) */ /* Standalone board with:
@@ -332,18 +341,34 @@ static void ref405ep_class_init(ObjectClass *oc, void *data) mc->desc ="ref405ep" ; mc->init = ref405ep_init; - mc->default_ram_size =0x08000000 ; - mc->default_ram_id ="ef405ep.ram" ; }static const TypeInfo ref405ep_type = { .name =MACHINE_TYPE_NAME ("ref405ep" ), - .parent =TYPE_MACHINE , + .parent =TYPE_PPC405_MACHINE , .class_init = ref405ep_class_init, }; +static void ppc405_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->desc ="PPC405 generic machine" ; + mc->default_ram_size =128 * MiB; + mc->default_ram_id ="ppc405.ram" ; +} + +static const TypeInfo ppc405_machine_type = { + .name =TYPE_PPC405_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (Ppc405MachineState), + .class_init = ppc405_machine_class_init, + .abstract = true, +}; +static void ppc405_machine_init (void ) { +type_register_static (&ppc405_machine_type);type_register_static (&ref405ep_type); }
Signature · 1 line
2.37.1
Re: [PATCH v3 02/22] ppc/ppc405: Introduce a PPC405 generic machine
Quoted 4 lines · Cédric Le Goater
We will use this machine as a base to define the ref405ep and possibly the PPC405 hotfoot board as found in the Linux kernel.
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 63 lines
---
hw/ppc/ppc405_boards.c| 31 ++++++++++++++++++++++++++++---1 file changed, 28 insertions(+), 3 deletions(-)hw/ppc/ppc405_boards.c +28
-3@@ -50,6 +50,15 @@#define USE_FLASH_BIOS +#define TYPE_PPC405_MACHINE MACHINE_TYPE_NAME("ppc405") +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405MachineState,PPC405_MACHINE ); + +struct Ppc405MachineState { +/* Private */ +MachineState parent_obj; +/* Public */ +}; +/*****************************************************************************/ /* PPC405EP reference board (IBM) */ /* Standalone board with: @@ -332,18 +341,34 @@ static void ref405ep_class_init(ObjectClass *oc, void *data) mc->desc ="ref405ep" ; mc->init = ref405ep_init; - mc->default_ram_size =0x08000000 ; - mc->default_ram_id ="ef405ep.ram" ; }static const TypeInfo ref405ep_type = { .name =MACHINE_TYPE_NAME ("ref405ep" ), - .parent =TYPE_MACHINE , + .parent =TYPE_PPC405_MACHINE , .class_init = ref405ep_class_init, }; +static void ppc405_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->desc ="PPC405 generic machine" ; + mc->default_ram_size =128 * MiB; + mc->default_ram_id ="ppc405.ram" ; +} + +static const TypeInfo ppc405_machine_type = { + .name =TYPE_PPC405_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (Ppc405MachineState), + .class_init = ppc405_machine_class_init, + .abstract = true, +}; +static void ppc405_machine_init (void ) { +type_register_static (&ppc405_machine_type);type_register_static (&ref405ep_type); }
PATCH v3 3/22 ppc/ppc405: Move devices under the ref405ep machine
In reply to Cédric Le Goater--- hw/ppc/ppc405_boards.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
hw/ppc/ppc405_boards.c +19 -12
@@ -230,13 +230,11 @@ static void boot_from_kernel(MachineState *machine, PowerPCCPU *cpu) env->load_info = &boot_info; } -static void ref405ep_init (MachineState *machine) +static void ppc405_init (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;PowerPCCPU *cpu; -DeviceState *dev; -SysBusDevice *s;MemoryRegion *sram =g_new (MemoryRegion,1 );MemoryRegion *ram_memories =g_new (MemoryRegion,2 );hwaddr ram_bases[2 ], ram_sizes[2 ];
@@ -294,15 +292,6 @@ static void ref405ep_init(MachineState *machine)memory_region_add_subregion (sysmem, (uint32_t )(-bios_size), bios); } -/* Register FPGA */ -ref405ep_fpga_init (sysmem,PPC405EP_FPGA_BASE ); -/* Register NVRAM */ - dev =qdev_new ("sysbus-m48t08" ); -qdev_prop_set_int32 (dev,"base-year" ,1968 ); - s =SYS_BUS_DEVICE (dev); -sysbus_realize_and_unref (s, &error_fatal); -sysbus_mmio_map (s,0 ,PPC405EP_NVRAM_BASE ); -/* Load kernel and initrd using U-Boot images */ if (kernel_filename && machine->firmware) {target_ulong kernel_base, initrd_base;
@@ -335,6 +324,23 @@ static void ref405ep_init(MachineState *machine) } } +static void ref405ep_init (MachineState *machine) +{ +DeviceState *dev; +SysBusDevice *s; + +ppc405_init (machine); + +/* Register FPGA */ +ref405ep_fpga_init (get_system_memory (),PPC405EP_FPGA_BASE ); +/* Register NVRAM */ + dev =qdev_new ("sysbus-m48t08" ); +qdev_prop_set_int32 (dev,"base-year" ,1968 ); + s =SYS_BUS_DEVICE (dev); +sysbus_realize_and_unref (s, &error_fatal); +sysbus_mmio_map (s,0 ,PPC405EP_NVRAM_BASE ); +} +static void ref405ep_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -354,6 +360,7 @@ static void ppc405_machine_class_init(ObjectClass *oc, void *data)MachineClass *mc =MACHINE_CLASS (oc); mc->desc ="PPC405 generic machine" ; + mc->init = ppc405_init; mc->default_ram_size =128 * MiB; mc->default_ram_id ="ppc405.ram" ; }
Signature · 1 line
2.37.1
Re: [PATCH v3 03/22] ppc/ppc405: Move devices under the ref405ep machine
Quoted 2 lines · Cédric Le Goater
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Quoted 72 lines
---
hw/ppc/ppc405_boards.c| 31 +++++++++++++++++++------------1 file changed, 19 insertions(+), 12 deletions(-)hw/ppc/ppc405_boards.c +19
-12@@ -230,13 +230,11 @@ static void boot_from_kernel(MachineState *machine, PowerPCCPU *cpu) env->load_info = &boot_info; } -static void ref405ep_init (MachineState *machine) +static void ppc405_init (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;PowerPCCPU *cpu; -DeviceState *dev; -SysBusDevice *s;MemoryRegion *sram =g_new (MemoryRegion,1 );MemoryRegion *ram_memories =g_new (MemoryRegion,2 );hwaddr ram_bases[2 ], ram_sizes[2 ];@@ -294,15 +292,6 @@ static void ref405ep_init(MachineState *machine)memory_region_add_subregion (sysmem, (uint32_t )(-bios_size), bios); } -/* Register FPGA */ -ref405ep_fpga_init (sysmem,PPC405EP_FPGA_BASE ); -/* Register NVRAM */ - dev =qdev_new ("sysbus-m48t08" ); -qdev_prop_set_int32 (dev,"base-year" ,1968 ); - s =SYS_BUS_DEVICE (dev); -sysbus_realize_and_unref (s, &error_fatal); -sysbus_mmio_map (s,0 ,PPC405EP_NVRAM_BASE ); -/* Load kernel and initrd using U-Boot images */ if (kernel_filename && machine->firmware) {target_ulong kernel_base, initrd_base;@@ -335,6 +324,23 @@ static void ref405ep_init(MachineState *machine) } } +static void ref405ep_init (MachineState *machine) +{ +DeviceState *dev; +SysBusDevice *s; + +ppc405_init (machine); + +/* Register FPGA */ +ref405ep_fpga_init (get_system_memory (),PPC405EP_FPGA_BASE ); +/* Register NVRAM */ + dev =qdev_new ("sysbus-m48t08" ); +qdev_prop_set_int32 (dev,"base-year" ,1968 ); + s =SYS_BUS_DEVICE (dev); +sysbus_realize_and_unref (s, &error_fatal); +sysbus_mmio_map (s,0 ,PPC405EP_NVRAM_BASE ); +} +static void ref405ep_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -354,6 +360,7 @@ static void ppc405_machine_class_init(ObjectClass *oc, void *data)MachineClass *mc =MACHINE_CLASS (oc); mc->desc ="PPC405 generic machine" ; + mc->init = ppc405_init; mc->default_ram_size =128 * MiB; mc->default_ram_id ="ppc405.ram" ; }
PATCH v3 4/22 ppc/ppc405: Move SRAM under the ref405ep machine
In reply to Cédric Le GoaterIt doesn't belong to the generic machine nor the SoC.
--- hw/ppc/ppc405_boards.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
hw/ppc/ppc405_boards.c +7 -6
@@ -235,7 +235,6 @@ static void ppc405_init(MachineState *machine)MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;PowerPCCPU *cpu; -MemoryRegion *sram =g_new (MemoryRegion,1 );MemoryRegion *ram_memories =g_new (MemoryRegion,2 );hwaddr ram_bases[2 ], ram_sizes[2 ];MemoryRegion *sysmem =get_system_memory ();
@@ -260,11 +259,6 @@ static void ppc405_init(MachineState *machine) cpu =ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes,33333333 , &uicdev, kernel_filename ==NULL ?0 :1 ); -/* allocate SRAM */ -memory_region_init_ram (sram,NULL ,"ef405ep.sram" ,PPC405EP_SRAM_SIZE , - &error_fatal); -memory_region_add_subregion (sysmem,PPC405EP_SRAM_BASE , sram); -/* allocate and load BIOS */ if (machine->firmware) {MemoryRegion *bios =g_new (MemoryRegion,1 );
@@ -328,9 +322,16 @@ static void ref405ep_init(MachineState *machine) {DeviceState *dev;SysBusDevice *s; +MemoryRegion *sram =g_new (MemoryRegion,1 ); +MemoryRegion *sysmem =get_system_memory ();ppc405_init (machine); +/* allocate SRAM */ +memory_region_init_ram (sram,NULL ,"ef405ep.sram" ,PPC405EP_SRAM_SIZE , + &error_fatal); +memory_region_add_subregion (sysmem,PPC405EP_SRAM_BASE , sram); +/* Register FPGA */ ref405ep_fpga_init (get_system_memory (),PPC405EP_FPGA_BASE );/* Register NVRAM */
Signature · 1 line
2.37.1
Re: [PATCH v3 04/22] ppc/ppc405: Move SRAM under the ref405ep machine
Quoted 32 lines · Cédric Le Goater
It doesn't belong to the generic machine nor the SoC.
Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405_boards.c| 13 +++++++------1 file changed, 7 insertions(+), 6 deletions(-)hw/ppc/ppc405_boards.c +0
-6@@ -235,7 +235,6 @@ static void ppc405_init(MachineState *machine)MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;PowerPCCPU *cpu; -MemoryRegion *sram =g_new (MemoryRegion,1 );MemoryRegion *ram_memories =g_new (MemoryRegion,2 );hwaddr ram_bases[2 ], ram_sizes[2 ];MemoryRegion *sysmem =get_system_memory ();@@ -260,11 +259,6 @@ static void ppc405_init(MachineState *machine) cpu =ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes,33333333 , &uicdev, kernel_filename ==NULL ?0 :1 ); -/* allocate SRAM */ -memory_region_init_ram (sram,NULL ,"ef405ep.sram" ,PPC405EP_SRAM_SIZE , - &error_fatal); -memory_region_add_subregion (sysmem,PPC405EP_SRAM_BASE , sram); -/* allocate and load BIOS */ if (machine->firmware) {MemoryRegion *bios =g_new (MemoryRegion,1 );
hw/ppc/ppc405_boards.c static void ref405ep_init(MachineState *machine) · line 326
Quoted 5 lines
hw/ppc/ppc405_boards.c +2
-0@@ -328,9 +322,16 @@ static void ref405ep_init(MachineState *machine) {DeviceState *dev;SysBusDevice *s; +MemoryRegion *sram =g_new (MemoryRegion,1 ); +MemoryRegion *sysmem =get_system_memory ();
You could drop thi "system" local and just use get_system_memory() in add_subregion
hw/ppc/ppc405_boards.c static void ref405ep_init(MachineState *machine) · line 336
Quoted 9 lines
hw/ppc/ppc405_boards.c +5
-0ppc405_init (machine); +/* allocate SRAM */ +memory_region_init_ram (sram,NULL ,"ef405ep.sram" ,PPC405EP_SRAM_SIZE , + &error_fatal); +memory_region_add_subregion (sysmem,PPC405EP_SRAM_BASE , sram); +/* Register FPGA */ ref405ep_fpga_init (get_system_memory (),PPC405EP_FPGA_BASE );
or use it everywhere consistently.
Regards,
BALATON Zoltan
Quoted 2 lines
hw/ppc/ppc405_boards.c +0
-0/* Register NVRAM */
Re: [PATCH v3 04/22] ppc/ppc405: Move SRAM under the ref405ep machine
Quoted 24 lines · BALATON Zoltan
Quoted 23 lines · Cédric Le Goater
It doesn't belong to the generic machine nor the SoC.
Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405_boards.c| 13 +++++++------1 file changed, 7 insertions(+), 6 deletions(-)hw/ppc/ppc405_boards.c +0
-1@@ -235,7 +235,6 @@ static void ppc405_init(MachineState *machine) MachineClass *mc = MACHINE_GET_CLASS(machine); const char *kernel_filename = machine->kernel_filename; PowerPCCPU *cpu; - MemoryRegion *sram = g_new(MemoryRegion, 1); MemoryRegion *ram_memories = g_new(MemoryRegion, 2); hwaddr ram_bases[2], ram_sizes[2]; MemoryRegion *sysmem = get_system_memory();@@ -260,11 +259,6 @@ static void ppc405_init(MachineState *machine) cpu = ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes, 33333333, &uicdev, kernel_filename == NULL ? 0 : 1);
Quoted 16 lines
Quoted 9 lines
hw/ppc/ppc405_boards.c +0
-5- /* allocate SRAM */ - memory_region_init_ram(sram, NULL, "ef405ep.sram", PPC405EP_SRAM_SIZE, - &error_fatal); - memory_region_add_subregion(sysmem, PPC405EP_SRAM_BASE, sram); - /* allocate and load BIOS */ if (machine->firmware) { MemoryRegion *bios = g_new(MemoryRegion, 1);hw/ppc/ppc405_boards.c static void ref405ep_init(MachineState *machine) · line 326
Quoted 5 lines
hw/ppc/ppc405_boards.c +2
-0@@ -328,9 +322,16 @@ static void ref405ep_init(MachineState *machine) { DeviceState *dev; SysBusDevice *s; + MemoryRegion *sram = g_new(MemoryRegion, 1); + MemoryRegion *sysmem = get_system_memory();You could drop thi "system" local and just use
get_system_memory()inadd_subregion
Yes. Let's drop it.
Thanks,
C.
Quoted 18 lines
hw/ppc/ppc405_boards.c static void ref405ep_init(MachineState *machine) · line 336
Quoted 10 lines
hw/ppc/ppc405_boards.c +5
-0ppc405_init(machine); + /* allocate SRAM */ + memory_region_init_ram(sram, NULL, "ef405ep.sram", PPC405EP_SRAM_SIZE, + &error_fatal); + memory_region_add_subregion(sysmem, PPC405EP_SRAM_BASE, sram); + /* Register FPGA */ ref405ep_fpga_init(get_system_memory(), PPC405EP_FPGA_BASE);or use it everywhere consistently.
Regards,
BALATON ZoltanQuoted 2 lines
hw/ppc/ppc405_boards.c +0
-0/* Register NVRAM */
PATCH v3 5/22 ppc/ppc405: Introduce a PPC405 SoC
In reply to Cédric Le GoaterIt is an initial model to start QOMification of the PPC405 board. QOM'ified devices will be reintroduced one by one. Start with the memory regions, which name prefix is changed to "ppc405".
Also, initialize only one RAM bank. The second bank is a dummy one (zero size) which is here to match the hard coded number of banks in ppc405ep_init().
--- hw/ppc/ppc405.h | 16 ++++++++++++++++ hw/ppc/ppc405_boards.c | 23 ++++++++++++----------- hw/ppc/ppc405_uc.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 11 deletions(-)
hw/ppc/ppc405.h +16 -0
@@ -25,6 +25,7 @@#ifndef PPC405_H #define PPC405_H +#include "qom/object.h" #include "hw/ppc/ppc4xx.h" #define PPC405EP_SDRAM_BASE 0x00000000
@@ -62,6 +63,21 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +#define TYPE_PPC405_SOC "ppc405-soc" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405SoCState,PPC405_SOC ); + +struct Ppc405SoCState { +/* Private */ +DeviceState parent_obj; + +/* Public */ +MemoryRegion ram_banks[2 ]; +hwaddr ram_bases[2 ], ram_sizes[2 ]; + +MemoryRegion *dram_mr; +hwaddr ram_size; +}; +/* PowerPC 405 core */ ram_addr_t ppc405_set_bootinfo (CPUPPCState *env,ram_addr_t ram_size);
hw/ppc/ppc405_boards.c +12 -11
@@ -57,6 +57,8 @@ struct Ppc405MachineState {/* Private */ MachineState parent_obj;/* Public */ + +Ppc405SoCState soc; };/*****************************************************************************/
@@ -232,11 +234,10 @@ static void boot_from_kernel(MachineState *machine, PowerPCCPU *cpu)static void ppc405_init (MachineState *machine) { +Ppc405MachineState *ppc405 =PPC405_MACHINE (machine);MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;PowerPCCPU *cpu; -MemoryRegion *ram_memories =g_new (MemoryRegion,2 ); -hwaddr ram_bases[2 ], ram_sizes[2 ];MemoryRegion *sysmem =get_system_memory ();DeviceState *uicdev;
@@ -247,16 +248,16 @@ static void ppc405_init(MachineState *machine)exit (EXIT_FAILURE ); } -/* XXX: fix this */ -memory_region_init_alias (&ram_memories[0 ],NULL ,"ef405ep.ram.alias" , - machine->ram,0 , machine->ram_size); - ram_bases[0 ] =0 ; - ram_sizes[0 ] = machine->ram_size; -memory_region_init (&ram_memories[1 ],NULL ,"ef405ep.ram1" ,0 ); - ram_bases[1 ] =0x00000000 ; - ram_sizes[1 ] =0x00000000 ; +object_initialize_child (OBJECT (machine),"soc" , &ppc405->soc, +TYPE_PPC405_SOC ); +object_property_set_uint (OBJECT (&ppc405->soc),"ram-size" , + machine->ram_size, &error_fatal); +object_property_set_link (OBJECT (&ppc405->soc),"dram" , +OBJECT (machine->ram), &error_abort); +qdev_realize (DEVICE (&ppc405->soc),NULL , &error_abort); - cpu =ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes, + cpu =ppc405ep_init (sysmem, ppc405->soc.ram_banks, ppc405->soc.ram_bases, + ppc405->soc.ram_sizes,33333333 , &uicdev, kernel_filename ==NULL ?0 :1 );/* allocate and load BIOS */
hw/ppc/ppc405_uc.c +40 -0
@@ -30,6 +30,7 @@#include "hw/ppc/ppc.h" #include "hw/i2c/ppc4xx_i2c.h" #include "hw/irq.h" +#include "hw/qdev-properties.h" #include "ppc405.h" #include "hw/char/serial.h" #include "qemu/timer.h"
@@ -1530,3 +1531,42 @@ PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem,return cpu; } + +static void ppc405_soc_realize (DeviceState *dev,Error **errp) +{ +Ppc405SoCState *s =PPC405_SOC (dev); + +/* Initialize only one bank */ + s->ram_bases[0 ] =0 ; + s->ram_sizes[0 ] = s->ram_size; +memory_region_init_alias (&s->ram_banks[0 ],OBJECT (s), +"ppc405.sdram0" , s->dram_mr, + s->ram_bases[0 ], s->ram_sizes[0 ]); +} + +static Property ppc405_soc_properties[] = { +DEFINE_PROP_LINK ("dram" , Ppc405SoCState, dram_mr,TYPE_MEMORY_REGION , + MemoryRegion *), +DEFINE_PROP_UINT64 ("ram-size" , Ppc405SoCState, ram_size,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void ppc405_soc_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = ppc405_soc_realize; + dc->user_creatable = false; +device_class_set_props (dc, ppc405_soc_properties); +} + +static const TypeInfo ppc405_types[] = { + { + .name =TYPE_PPC405_SOC , + .parent =TYPE_DEVICE , + .instance_size =sizeof (Ppc405SoCState), + .class_init = ppc405_soc_class_init, + } +}; + +DEFINE_TYPES (ppc405_types)
Signature · 1 line
2.37.1
Re: [PATCH v3 05/22] ppc/ppc405: Introduce a PPC405 SoC
Quoted 127 lines · Cédric Le Goater
It is an initial model to start QOMification of the PPC405 board. QOM'ified devices will be reintroduced one by one. Start with the memory regions, which name prefix is changed to "ppc405".
Also, initialize only one RAM bank. The second bank is a dummy one (zero size) which is here to match the hard coded number of banks in
ppc405ep_init().Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h | 16 ++++++++++++++++ hw/ppc/ppc405_boards.c | 23 ++++++++++++----------- hw/ppc/ppc405_uc.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 11 deletions(-)hw/ppc/ppc405.h +16
-0@@ -25,6 +25,7 @@#ifndef PPC405_H #define PPC405_H +#include "qom/object.h" #include "hw/ppc/ppc4xx.h" #define PPC405EP_SDRAM_BASE 0x00000000@@ -62,6 +63,21 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +#define TYPE_PPC405_SOC "ppc405-soc" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405SoCState,PPC405_SOC ); + +struct Ppc405SoCState { +/* Private */ +DeviceState parent_obj; + +/* Public */ +MemoryRegion ram_banks[2 ]; +hwaddr ram_bases[2 ], ram_sizes[2 ]; + +MemoryRegion *dram_mr; +hwaddr ram_size; +}; +/* PowerPC 405 core */ ram_addr_t ppc405_set_bootinfo (CPUPPCState *env,ram_addr_t ram_size);hw/ppc/ppc405_boards.c +12
-11@@ -57,6 +57,8 @@ struct Ppc405MachineState {/* Private */ MachineState parent_obj;/* Public */ + +Ppc405SoCState soc; };/*****************************************************************************/ @@ -232,11 +234,10 @@ static void boot_from_kernel(MachineState *machine, PowerPCCPU *cpu)static void ppc405_init (MachineState *machine) { +Ppc405MachineState *ppc405 =PPC405_MACHINE (machine);MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;PowerPCCPU *cpu; -MemoryRegion *ram_memories =g_new (MemoryRegion,2 ); -hwaddr ram_bases[2 ], ram_sizes[2 ];MemoryRegion *sysmem =get_system_memory ();DeviceState *uicdev;@@ -247,16 +248,16 @@ static void ppc405_init(MachineState *machine)exit (EXIT_FAILURE ); } -/* XXX: fix this */ -memory_region_init_alias (&ram_memories[0 ],NULL ,"ef405ep.ram.alias" , - machine->ram,0 , machine->ram_size); - ram_bases[0 ] =0 ; - ram_sizes[0 ] = machine->ram_size; -memory_region_init (&ram_memories[1 ],NULL ,"ef405ep.ram1" ,0 ); - ram_bases[1 ] =0x00000000 ; - ram_sizes[1 ] =0x00000000 ; +object_initialize_child (OBJECT (machine),"soc" , &ppc405->soc, +TYPE_PPC405_SOC ); +object_property_set_uint (OBJECT (&ppc405->soc),"ram-size" , + machine->ram_size, &error_fatal); +object_property_set_link (OBJECT (&ppc405->soc),"dram" , +OBJECT (machine->ram), &error_abort); +qdev_realize (DEVICE (&ppc405->soc),NULL , &error_abort); - cpu =ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes, + cpu =ppc405ep_init (sysmem, ppc405->soc.ram_banks, ppc405->soc.ram_bases, + ppc405->soc.ram_sizes,33333333 , &uicdev, kernel_filename ==NULL ?0 :1 );/* allocate and load BIOS */ hw/ppc/ppc405_uc.c +10
-0@@ -30,6 +30,7 @@#include "hw/ppc/ppc.h" #include "hw/i2c/ppc4xx_i2c.h" #include "hw/irq.h" +#include "hw/qdev-properties.h" #include "ppc405.h" #include "hw/char/serial.h" #include "qemu/timer.h" @@ -1530,3 +1531,42 @@ PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem,return cpu; } + +static void ppc405_soc_realize (DeviceState *dev,Error **errp) +{ +Ppc405SoCState *s =PPC405_SOC (dev); + +/* Initialize only one bank */ + s->ram_bases[0 ] =0 ; + s->ram_sizes[0 ] = s->ram_size; + memory_region_init_alias(&s->ram_banks[0], OBJECT(s),
hw/ppc/ppc405_uc.c PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem, · line 1552
Quoted 10 lines
hw/ppc/ppc405_uc.c +10
-0+"ppc405.sdram0" , s->dram_mr, + s->ram_bases[0], s->ram_sizes[0]); +} + +static Property ppc405_soc_properties[] = { +DEFINE_PROP_LINK ("dram" , Ppc405SoCState, dram_mr,TYPE_MEMORY_REGION , + MemoryRegion *), +DEFINE_PROP_UINT64 ("ram-size" , Ppc405SoCState, ram_size,0 ), +DEFINE_PROP_END_OF_LIST (), +};
I'm not sure why we need to duplicate these in the soc if they are always the same as machine->ram and machine->ram_size. Is it theoretically possible to have a soc where it uses ram that's not the whole ram? If not then you could just uose machine which is accessible either as current_machine or qdev_get_machine() (also the parent of out soc but we don't know how to get that). If setting ram this way is still desired do we separately need to set its size or we could use memory_region_size() instead?
hw/ppc/ppc405_uc.c PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem, · line 1559
Quoted 7 lines
hw/ppc/ppc405_uc.c +7
-0+ +static void ppc405_soc_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = ppc405_soc_realize; + dc->user_creatable = false;
May need a comment explaining why user_creatable = false. (Also for all other similar lines in other patches, I won't repeat this there.)
Regards,
BALATON Zoltan
Quoted 14 lines
hw/ppc/ppc405_uc.c +13
-0+device_class_set_props (dc, ppc405_soc_properties); +} + +static const TypeInfo ppc405_types[] = { + { + .name =TYPE_PPC405_SOC , + .parent =TYPE_DEVICE , + .instance_size =sizeof (Ppc405SoCState), + .class_init = ppc405_soc_class_init, + } +}; + +DEFINE_TYPES (ppc405_types)
Re: [PATCH v3 05/22] ppc/ppc405: Introduce a PPC405 SoC
Quoted 132 lines · BALATON Zoltan
Quoted 131 lines · Cédric Le Goater
It is an initial model to start QOMification of the PPC405 board. QOM'ified devices will be reintroduced one by one. Start with the memory regions, which name prefix is changed to "ppc405".
Also, initialize only one RAM bank. The second bank is a dummy one (zero size) which is here to match the hard coded number of banks in
ppc405ep_init().Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h | 16 ++++++++++++++++hw/ppc/ppc405_boards.c| 23 ++++++++++++----------- hw/ppc/ppc405_uc.c | 40 ++++++++++++++++++++++++++++++++++++++++3 files changed, 68 insertions(+), 11 deletions(-)hw/ppc/ppc405.h +16
-0@@ -25,6 +25,7 @@#ifndef PPC405_H #define PPC405_H +#include "qom/object.h" #include "hw/ppc/ppc4xx.h" #define PPC405EP_SDRAM_BASE 0x00000000@@ -62,6 +63,21 @@ struct ppc4xx_bd_info_t { uint32_t bi_iic_fast[2]; }; +#define TYPE_PPC405_SOC "ppc405-soc" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405SoCState,PPC405_SOC ); + +struct Ppc405SoCState { + /* Private */ + DeviceState parent_obj; + + /* Public */ + MemoryRegion ram_banks[2]; + hwaddr ram_bases[2], ram_sizes[2]; + + MemoryRegion *dram_mr; + hwaddr ram_size; +}; +/* PowerPC 405 core */ ram_addr_t ppc405_set_bootinfo (CPUPPCState *env,ram_addr_t ram_size);hw/ppc/ppc405_boards.c +12
-11@@ -57,6 +57,8 @@ struct Ppc405MachineState { /* Private */ MachineState parent_obj; /* Public */ + + Ppc405SoCState soc; };/*****************************************************************************/ @@ -232,11 +234,10 @@ static void boot_from_kernel(MachineState *machine, PowerPCCPU *cpu)static void ppc405_init (MachineState *machine) { + Ppc405MachineState *ppc405 = PPC405_MACHINE(machine); MachineClass *mc = MACHINE_GET_CLASS(machine); const char *kernel_filename = machine->kernel_filename; PowerPCCPU *cpu; - MemoryRegion *ram_memories = g_new(MemoryRegion, 2); - hwaddr ram_bases[2], ram_sizes[2]; MemoryRegion *sysmem = get_system_memory(); DeviceState *uicdev;@@ -247,16 +248,16 @@ static void ppc405_init(MachineState *machine) exit(EXIT_FAILURE); } - /* XXX: fix this */ - memory_region_init_alias(&ram_memories[0], NULL, "ef405ep.ram.alias", - machine->ram, 0, machine->ram_size); - ram_bases[0] = 0; - ram_sizes[0] = machine->ram_size; - memory_region_init(&ram_memories[1], NULL, "ef405ep.ram1", 0); - ram_bases[1] = 0x00000000; - ram_sizes[1] = 0x00000000; + object_initialize_child(OBJECT(machine), "soc", &ppc405->soc, + TYPE_PPC405_SOC); + object_property_set_uint(OBJECT(&ppc405->soc), "ram-size", + machine->ram_size, &error_fatal); + object_property_set_link(OBJECT(&ppc405->soc), "dram", + OBJECT(machine->ram), &error_abort); + qdev_realize(DEVICE(&ppc405->soc), NULL, &error_abort); - cpu = ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes, + cpu = ppc405ep_init(sysmem, ppc405->soc.ram_banks, ppc405->soc.ram_bases, + ppc405->soc.ram_sizes, 33333333, &uicdev, kernel_filename == NULL ? 0 : 1); /* allocate and load BIOS */hw/ppc/ppc405_uc.c +14
-0@@ -30,6 +30,7 @@#include "hw/ppc/ppc.h" #include "hw/i2c/ppc4xx_i2c.h" #include "hw/irq.h" +#include "hw/qdev-properties.h" #include "ppc405.h" #include "hw/char/serial.h" #include "qemu/timer.h" @@ -1530,3 +1531,42 @@ PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem, return cpu; } + +static void ppc405_soc_realize (DeviceState *dev,Error **errp) +{ + Ppc405SoCState *s = PPC405_SOC(dev); + + /* Initialize only one bank */ + s->ram_bases[0] = 0; + s->ram_sizes[0] = s->ram_size; + memory_region_init_alias(&s->ram_banks[0], OBJECT(s), + "ppc405.sdram0", s->dram_mr, + s->ram_bases[0], s->ram_sizes[0]); +} +
Quoted 8 lines
hw/ppc/ppc405_uc.c PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem, · line 1552
Quoted 6 lines
hw/ppc/ppc405_uc.c +6
-0+static Property ppc405_soc_properties[] = { + DEFINE_PROP_LINK("dram", Ppc405SoCState, dram_mr, TYPE_MEMORY_REGION, + MemoryRegion *), + DEFINE_PROP_UINT64("ram-size", Ppc405SoCState, ram_size, 0), + DEFINE_PROP_END_OF_LIST(), +};I'm not sure why we need to duplicate these in the soc if they are always the same as
machine->ramandmachine->ram_size.
There are machines with multi SoCs. PowerNV can have 16.
But that's not the reason here, we pass the dram memory region to the SoC for controllers that might need it for memory transactions, typically DMAs. In this case, it's the SDRAM controller which creates slices of RAM for each available RAM bank.
Quoted 1 line
Is it theoretically possible to have a soc where it uses ram that's not the whole ram?
Yes.
Quoted 1 line
If not then you could just uose machine which is accessible either as
current_machineorqdev_get_machine()
These are QEMU globals. We should avoid using them in device models.
Quoted 2 lines
(also the parent of out soc but we don't know how to get that). If setting ram this way is still desired do we separately need to set its size or we could use
memory_region_size()instead?
Let's keep SDRAM modeling for the next patchset.
Quoted 9 lines
hw/ppc/ppc405_uc.c PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem, · line 1559
Quoted 7 lines
hw/ppc/ppc405_uc.c +7
-0+ +static void ppc405_soc_class_init (ObjectClass *oc,void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->realize = ppc405_soc_realize; + dc->user_creatable = false;May need a comment explaining why
user_creatable= false. (Also for all other similar lines in other patches, I won't repeat this there.)
TYPE_PPC405_SOC devices can not be created from the QEMU command line. it doesn't make sense. That's what 'dc->user_creatable = false' means.
Thanks,
C.
Quoted 18 lines
Regards,
BALATON ZoltanQuoted 14 lines
hw/ppc/ppc405_uc.c +13
-0+ device_class_set_props(dc, ppc405_soc_properties); +} + +static const TypeInfo ppc405_types[] = { + { + .name = TYPE_PPC405_SOC, + .parent = TYPE_DEVICE, + .instance_size = sizeof(Ppc405SoCState), + .class_init = ppc405_soc_class_init, + } +}; + +DEFINE_TYPES (ppc405_types)
Re: [PATCH v3 05/22] ppc/ppc405: Introduce a PPC405 SoC
Quoted 156 lines · Cédric Le Goater
Quoted 135 lines · BALATON Zoltan
Quoted 134 lines · Cédric Le Goater
It is an initial model to start QOMification of the PPC405 board. QOM'ified devices will be reintroduced one by one. Start with the memory regions, which name prefix is changed to "ppc405".
Also, initialize only one RAM bank. The second bank is a dummy one (zero size) which is here to match the hard coded number of banks in
ppc405ep_init().Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h | 16 ++++++++++++++++hw/ppc/ppc405_boards.c| 23 ++++++++++++----------- hw/ppc/ppc405_uc.c | 40 ++++++++++++++++++++++++++++++++++++++++3 files changed, 68 insertions(+), 11 deletions(-)hw/ppc/ppc405.h +16
-0@@ -25,6 +25,7 @@#ifndef PPC405_H #define PPC405_H +#include "qom/object.h" #include "hw/ppc/ppc4xx.h" #define PPC405EP_SDRAM_BASE 0x00000000@@ -62,6 +63,21 @@ struct ppc4xx_bd_info_t { uint32_t bi_iic_fast[2]; }; +#define TYPE_PPC405_SOC "ppc405-soc" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405SoCState,PPC405_SOC ); + +struct Ppc405SoCState { + /* Private */ + DeviceState parent_obj; + + /* Public */ + MemoryRegion ram_banks[2]; + hwaddr ram_bases[2], ram_sizes[2]; + + MemoryRegion *dram_mr; + hwaddr ram_size; +}; +/* PowerPC 405 core */ ram_addr_t ppc405_set_bootinfo (CPUPPCState *env,ram_addr_t ram_size);hw/ppc/ppc405_boards.c +12
-11@@ -57,6 +57,8 @@ struct Ppc405MachineState { /* Private */ MachineState parent_obj; /* Public */ + + Ppc405SoCState soc; };/*****************************************************************************/ @@ -232,11 +234,10 @@ static void boot_from_kernel(MachineState *machine, PowerPCCPU *cpu)static void ppc405_init (MachineState *machine) { + Ppc405MachineState *ppc405 = PPC405_MACHINE(machine); MachineClass *mc = MACHINE_GET_CLASS(machine); const char *kernel_filename = machine->kernel_filename; PowerPCCPU *cpu; - MemoryRegion *ram_memories = g_new(MemoryRegion, 2); - hwaddr ram_bases[2], ram_sizes[2]; MemoryRegion *sysmem = get_system_memory(); DeviceState *uicdev;@@ -247,16 +248,16 @@ static void ppc405_init(MachineState *machine) exit(EXIT_FAILURE); } - /* XXX: fix this */ - memory_region_init_alias(&ram_memories[0], NULL, "ef405ep.ram.alias", - machine->ram, 0, machine->ram_size); - ram_bases[0] = 0; - ram_sizes[0] = machine->ram_size; - memory_region_init(&ram_memories[1], NULL, "ef405ep.ram1", 0); - ram_bases[1] = 0x00000000; - ram_sizes[1] = 0x00000000; + object_initialize_child(OBJECT(machine), "soc", &ppc405->soc, + TYPE_PPC405_SOC); + object_property_set_uint(OBJECT(&ppc405->soc), "ram-size", + machine->ram_size, &error_fatal); + object_property_set_link(OBJECT(&ppc405->soc), "dram", + OBJECT(machine->ram), &error_abort); + qdev_realize(DEVICE(&ppc405->soc), NULL, &error_abort); - cpu = ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes, + cpu = ppc405ep_init(sysmem, ppc405->soc.ram_banks, ppc405->soc.ram_bases, + ppc405->soc.ram_sizes, 33333333, &uicdev, kernel_filename == NULL ? 0 : 1);/* allocate and load BIOS */
hw/ppc/ppc405_uc.c +1
-0@@ -30,6 +30,7 @@#include "hw/ppc/ppc.h" #include "hw/i2c/ppc4xx_i2c.h" #include "hw/irq.h" +#include "hw/qdev-properties.h" #include "ppc405.h" #include "hw/char/serial.h" #include "qemu/timer.h" @@ -1530,3 +1531,42 @@ PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem, return cpu;}
hw/ppc/ppc405_uc.c +13
-0+ +static void ppc405_soc_realize (DeviceState *dev,Error **errp) +{ + Ppc405SoCState *s = PPC405_SOC(dev); + + /* Initialize only one bank */ + s->ram_bases[0] = 0; + s->ram_sizes[0] = s->ram_size; + memory_region_init_alias(&s->ram_banks[0], OBJECT(s), + "ppc405.sdram0", s->dram_mr, + s->ram_bases[0], s->ram_sizes[0]); +} +Quoted 8 lines
hw/ppc/ppc405_uc.c PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem, · line 1552
Quoted 6 lines
hw/ppc/ppc405_uc.c +6
-0+static Property ppc405_soc_properties[] = { + DEFINE_PROP_LINK("dram", Ppc405SoCState, dram_mr, TYPE_MEMORY_REGION, + MemoryRegion *), + DEFINE_PROP_UINT64("ram-size", Ppc405SoCState, ram_size, 0), + DEFINE_PROP_END_OF_LIST(), +};I'm not sure why we need to duplicate these in the soc if they are always the same as
machine->ramandmachine->ram_size.There are machines with multi SoCs. PowerNV can have 16.
But that's not the reason here, we pass the dram memory region to the SoC for controllers that might need it for memory transactions, typically DMAs. In this case, it's the SDRAM controller which creates slices of RAM for each available RAM bank.
Quoted 1 line
Is it theoretically possible to have a soc where it uses ram that's not the whole ram?
Yes.
Quoted 8 lines
Quoted 1 line
If not then you could just uose machine which is accessible either as
current_machineorqdev_get_machine()These are QEMU globals. We should avoid using them in device models.
Quoted 2 lines
(also the parent of out soc but we don't know how to get that). If setting ram this way is still desired do we separately need to set its size or we could use
memory_region_size()instead?Let's keep SDRAM modeling for the next patchset.
OK.
Quoted 11 lines
Quoted 10 lines
hw/ppc/ppc405_uc.c PowerPCCPU *ppc405ep_init(MemoryRegion *address_space_mem, · line 1559
Quoted 8 lines
hw/ppc/ppc405_uc.c +7
-0+ +static void ppc405_soc_class_init (ObjectClass *oc,void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->realize = ppc405_soc_realize; + dc->user_creatable = false;May need a comment explaining why
user_creatable= false. (Also for all other similar lines in other patches, I won't repeat this there.)
Quoted 2 lines
TYPE_PPC405_SOCdevices can not be created from the QEMU command line. it doesn't make sense. That's what 'dc->user_creatable= false' means.
I know but near the definition of user_creatable there's a comment demanding that each occurance has to have a comment explaining why.
Regards,
BALATON Zoltan
Quoted 24 lines
Thanks,
C.
Quoted 18 lines
Regards,
BALATON ZoltanQuoted 14 lines
+
device_class_set_props(dc, ppc405_soc_properties);hw/ppc/ppc405_uc.c +12
-0+} + +static const TypeInfo ppc405_types[] = { + { + .name = TYPE_PPC405_SOC, + .parent = TYPE_DEVICE, + .instance_size = sizeof(Ppc405SoCState), + .class_init = ppc405_soc_class_init, + } +}; + +DEFINE_TYPES (ppc405_types)
PATCH v3 6/22 ppc/ppc405: Start QOMification of the SoC
In reply to Cédric Le GoaterThis moves all the code previously done in the ppc405ep_init() routine under ppc405_soc_realize(). We can also adjust the number of banks now that we have control on ppc4xx_sdram_init().
--- hw/ppc/ppc405.h | 12 ++-- hw/ppc/ppc405_boards.c | 12 ++-- hw/ppc/ppc405_uc.c | 123 ++++++++++++++++++++--------------------- 3 files changed, 70 insertions(+), 77 deletions(-)
hw/ppc/ppc405.h +5 -7
@@ -73,9 +73,14 @@ struct Ppc405SoCState {/* Public */ MemoryRegion ram_banks[2 ];hwaddr ram_bases[2 ], ram_sizes[2 ]; +bool do_dram_init;MemoryRegion *dram_mr;hwaddr ram_size; + +uint32_t sysclk; +PowerPCCPU *cpu; +DeviceState *uic; };/* PowerPC 405 core */
@@ -84,11 +89,4 @@ ram_addr_t ppc405_set_bootinfo(CPUPPCState *env, ram_addr_t ram_size);void ppc4xx_plb_init (CPUPPCState *env);void ppc405_ebc_init (CPUPPCState *env); -PowerPCCPU *ppc405ep_init (MemoryRegion *address_space_mem, -MemoryRegion ram_memories[2 ], -hwaddr ram_bases[2 ], -hwaddr ram_sizes[2 ], -uint32_t sysclk,DeviceState **uicdev, -int do_init); -#endif /* PPC405_H */
hw/ppc/ppc405_boards.c +5 -7
@@ -237,9 +237,7 @@ static void ppc405_init(MachineState *machine)Ppc405MachineState *ppc405 =PPC405_MACHINE (machine);MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename; -PowerPCCPU *cpu;MemoryRegion *sysmem =get_system_memory (); -DeviceState *uicdev;if (machine->ram_size != mc->default_ram_size) {char *sz =size_to_str (mc->default_ram_size);
@@ -254,12 +252,12 @@ static void ppc405_init(MachineState *machine) machine->ram_size, &error_fatal);object_property_set_link (OBJECT (&ppc405->soc),"dram" ,OBJECT (machine->ram), &error_abort); +object_property_set_bool (OBJECT (&ppc405->soc),"dram-init" , + !(kernel_filename ==NULL ), &error_abort); +object_property_set_uint (OBJECT (&ppc405->soc),"sys-clk" ,33333333 , + &error_abort);qdev_realize (DEVICE (&ppc405->soc),NULL , &error_abort); - cpu =ppc405ep_init (sysmem, ppc405->soc.ram_banks, ppc405->soc.ram_bases, - ppc405->soc.ram_sizes, -33333333 , &uicdev, kernel_filename ==NULL ?0 :1 ); -/* allocate and load BIOS */ if (machine->firmware) {MemoryRegion *bios =g_new (MemoryRegion,1 );
@@ -315,7 +313,7 @@ static void ppc405_init(MachineState *machine)/* Load ELF kernel and rootfs.cpio */ }else if (kernel_filename && !machine->firmware) { -boot_from_kernel (machine, cpu); +boot_from_kernel (machine, ppc405->soc.cpu); } }
hw/ppc/ppc405_uc.c +60 -63
181 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH v3 06/22] ppc/ppc405: Start QOMification of the SoC
Quoted 16 lines · Cédric Le Goater
This moves all the code previously done in the
ppc405ep_init()routine underppc405_soc_realize(). We can also adjust the number of banks now that we have control onppc4xx_sdram_init().Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h | 12 ++-- hw/ppc/ppc405_boards.c | 12 ++-- hw/ppc/ppc405_uc.c | 123 ++++++++++++++++++++--------------------- 3 files changed, 70 insertions(+), 77 deletions(-)hw/ppc/ppc405.h +0
-0
hw/ppc/ppc405.h struct Ppc405SoCState { · line 81
Quoted 9 lines
hw/ppc/ppc405.h +3
-0@@ -73,9 +73,14 @@ struct Ppc405SoCState {/* Public */ MemoryRegion ram_banks[2 ];hwaddr ram_bases[2 ], ram_sizes[2 ]; +bool do_dram_init;MemoryRegion *dram_mr;hwaddr ram_size; + +uint32_t sysclk;
Putting this together with dram_init would keep properties set from outside together which is clearer than here with others set by to object itself but this is just a small thing, not really important.
Quoted 32 lines
hw/ppc/ppc405.h +2
-7+PowerPCCPU *cpu; +DeviceState *uic; };/* PowerPC 405 core */ @@ -84,11 +89,4 @@ ram_addr_t ppc405_set_bootinfo(CPUPPCState *env, ram_addr_t ram_size);void ppc4xx_plb_init (CPUPPCState *env);void ppc405_ebc_init (CPUPPCState *env); -PowerPCCPU *ppc405ep_init (MemoryRegion *address_space_mem, -MemoryRegion ram_memories[2 ], -hwaddr ram_bases[2 ], -hwaddr ram_sizes[2 ], -uint32_t sysclk,DeviceState **uicdev, -int do_init); -#endif /* PPC405_H */ hw/ppc/ppc405_boards.c +0
-2@@ -237,9 +237,7 @@ static void ppc405_init(MachineState *machine)Ppc405MachineState *ppc405 =PPC405_MACHINE (machine);MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename; -PowerPCCPU *cpu;MemoryRegion *sysmem =get_system_memory (); -DeviceState *uicdev;if (machine->ram_size != mc->default_ram_size) {char *sz =size_to_str (mc->default_ram_size);
hw/ppc/ppc405_boards.c static void ppc405_init(MachineState *machine) · line 256
Quoted 5 lines
hw/ppc/ppc405_boards.c +2
-0@@ -254,12 +252,12 @@ static void ppc405_init(MachineState *machine) machine->ram_size, &error_fatal);object_property_set_link (OBJECT (&ppc405->soc),"dram" ,OBJECT (machine->ram), &error_abort); +object_property_set_bool (OBJECT (&ppc405->soc),"dram-init" , + !(kernel_filename ==NULL ), &error_abort);
Maybe clearer as kernel_filename != NULL
Is there a problem with indentation in this patch? Does it pass checkpatch.pl?
Regards,
BALATON Zoltan
Quoted 207 lines
hw/ppc/ppc405_boards.c +3
-5+object_property_set_uint (OBJECT (&ppc405->soc),"sys-clk" ,33333333 , + &error_abort);qdev_realize (DEVICE (&ppc405->soc),NULL , &error_abort); - cpu =ppc405ep_init (sysmem, ppc405->soc.ram_banks, ppc405->soc.ram_bases, - ppc405->soc.ram_sizes, -33333333 , &uicdev, kernel_filename ==NULL ?0 :1 ); -/* allocate and load BIOS */ if (machine->firmware) {MemoryRegion *bios =g_new (MemoryRegion,1 );@@ -315,7 +313,7 @@ static void ppc405_init(MachineState *machine)/* Load ELF kernel and rootfs.cpio */ }else if (kernel_filename && !machine->firmware) { -boot_from_kernel (machine, cpu); +boot_from_kernel (machine, ppc405->soc.cpu); } }hw/ppc/ppc405_uc.c +60
-63@@ -1432,121 +1432,118 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],#endif } -PowerPCCPU *ppc405ep_init (MemoryRegion *address_space_mem, -MemoryRegion ram_memories[2 ], -hwaddr ram_bases[2 ], -hwaddr ram_sizes[2 ], -uint32_t sysclk,DeviceState **uicdevp, -int do_init) +static void ppc405_soc_realize (DeviceState *dev,Error **errp) { +Ppc405SoCState *s =PPC405_SOC (dev);clk_setup_t clk_setup[PPC405EP_CLK_NB ], tlb_clk_setup;qemu_irq dma_irqs[4 ], gpt_irqs[5 ], mal_irqs[4 ]; -PowerPCCPU *cpu;CPUPPCState *env; -DeviceState *uicdev; -SysBusDevice *uicsbd;memset (clk_setup,0 ,sizeof (clk_setup)); +/* init CPUs */ - cpu =ppc4xx_init (POWERPC_CPU_TYPE_NAME ("405ep" ), + s->cpu =ppc4xx_init (POWERPC_CPU_TYPE_NAME ("405ep" ), &clk_setup[PPC405EP_CPU_CLK ], - &tlb_clk_setup, sysclk); - env = &cpu->env; + &tlb_clk_setup, s->sysclk); + env = &s->cpu->env; clk_setup[PPC405EP_CPU_CLK ].cb = tlb_clk_setup.cb; clk_setup[PPC405EP_CPU_CLK ].opaque = tlb_clk_setup.opaque; -/* Internal devices init */ -/* Memory mapped devices registers */ + +/* CPU control */ +ppc405ep_cpc_init (env, clk_setup, s->sysclk); +/* PLB arbitrer */ ppc4xx_plb_init (env); +/* PLB to OPB bridge */ ppc4xx_pob_init (env); +/* OBP arbitrer */ ppc4xx_opba_init (0xef600600 ); +/* Universal interrupt controller */ - uicdev =qdev_new (TYPE_PPC_UIC ); - uicsbd =SYS_BUS_DEVICE (uicdev); + s->uic =qdev_new (TYPE_PPC_UIC ); -object_property_set_link (OBJECT (uicdev),"cpu" ,OBJECT (cpu), +object_property_set_link (OBJECT (s->uic),"cpu" ,OBJECT (s->cpu), &error_fatal); -sysbus_realize_and_unref (uicsbd, &error_fatal); - -sysbus_connect_irq (uicsbd,PPCUIC_OUTPUT_INT , -qdev_get_gpio_in (DEVICE (cpu), PPC40x_INPUT_INT)); -sysbus_connect_irq (uicsbd,PPCUIC_OUTPUT_CINT , -qdev_get_gpio_in (DEVICE (cpu), PPC40x_INPUT_CINT)); +if (!sysbus_realize (SYS_BUS_DEVICE (s->uic), errp)) { +return ; + } - *uicdevp = uicdev; +sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_INT , +qdev_get_gpio_in (DEVICE (s->cpu), PPC40x_INPUT_INT)); +sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_CINT , +qdev_get_gpio_in (DEVICE (s->cpu), PPC40x_INPUT_CINT));/* SDRAM controller */ /* XXX 405EP has no ECC interrupt */ -ppc4xx_sdram_init (env,qdev_get_gpio_in (uicdev,17 ),2 , ram_memories, - ram_bases, ram_sizes, do_init); + s->ram_bases[0 ] =0 ; + s->ram_sizes[0 ] = s->ram_size; +memory_region_init_alias (&s->ram_banks[0 ],OBJECT (s), +"ppc405.sdram0" , s->dram_mr, + s->ram_bases[0 ], s->ram_sizes[0 ]); + +ppc4xx_sdram_init (env,qdev_get_gpio_in (s->uic,17 ),1 , + s->ram_banks, s->ram_bases, s->ram_sizes, + s->do_dram_init); +/* External bus controller */ ppc405_ebc_init (env); +/* DMA controller */ - dma_irqs[0 ] =qdev_get_gpio_in (uicdev,5 ); - dma_irqs[1 ] =qdev_get_gpio_in (uicdev,6 ); - dma_irqs[2 ] =qdev_get_gpio_in (uicdev,7 ); - dma_irqs[3 ] =qdev_get_gpio_in (uicdev,8 ); + dma_irqs[0 ] =qdev_get_gpio_in (s->uic,5 ); + dma_irqs[1 ] =qdev_get_gpio_in (s->uic,6 ); + dma_irqs[2 ] =qdev_get_gpio_in (s->uic,7 ); + dma_irqs[3 ] =qdev_get_gpio_in (s->uic,8 );ppc405_dma_init (env, dma_irqs); -/* IIC controller */ + +/* I2C controller */ sysbus_create_simple (TYPE_PPC4xx_I2C,0xef600500 , -qdev_get_gpio_in (uicdev,2 )); +qdev_get_gpio_in (s->uic,2 ));/* GPIO */ ppc405_gpio_init (0xef600700 ); +/* Serial ports */ if (serial_hd (0 ) !=NULL ) { -serial_mm_init (address_space_mem,0xef600300 ,0 , -qdev_get_gpio_in (uicdev,0 ), +serial_mm_init (get_system_memory (),0xef600300 ,0 , +qdev_get_gpio_in (s->uic,0 ),PPC_SERIAL_MM_BAUDBASE ,serial_hd (0 ),DEVICE_BIG_ENDIAN ); }if (serial_hd (1 ) !=NULL ) { -serial_mm_init (address_space_mem,0xef600400 ,0 , -qdev_get_gpio_in (uicdev,1 ), +serial_mm_init (get_system_memory (),0xef600400 ,0 , +qdev_get_gpio_in (s->uic,1 ),PPC_SERIAL_MM_BAUDBASE ,serial_hd (1 ),DEVICE_BIG_ENDIAN ); } +/* OCM */ ppc405_ocm_init (env); +/* GPT */ - gpt_irqs[0 ] =qdev_get_gpio_in (uicdev,19 ); - gpt_irqs[1 ] =qdev_get_gpio_in (uicdev,20 ); - gpt_irqs[2 ] =qdev_get_gpio_in (uicdev,21 ); - gpt_irqs[3 ] =qdev_get_gpio_in (uicdev,22 ); - gpt_irqs[4 ] =qdev_get_gpio_in (uicdev,23 ); + gpt_irqs[0 ] =qdev_get_gpio_in (s->uic,19 ); + gpt_irqs[1 ] =qdev_get_gpio_in (s->uic,20 ); + gpt_irqs[2 ] =qdev_get_gpio_in (s->uic,21 ); + gpt_irqs[3 ] =qdev_get_gpio_in (s->uic,22 ); + gpt_irqs[4 ] =qdev_get_gpio_in (s->uic,23 );ppc4xx_gpt_init (0xef600000 , gpt_irqs); -/* PCI */ -/* Uses UIC IRQs 3, 16, 18 */ +/* MAL */ - mal_irqs[0 ] =qdev_get_gpio_in (uicdev,11 ); - mal_irqs[1 ] =qdev_get_gpio_in (uicdev,12 ); - mal_irqs[2 ] =qdev_get_gpio_in (uicdev,13 ); - mal_irqs[3 ] =qdev_get_gpio_in (uicdev,14 ); + mal_irqs[0 ] =qdev_get_gpio_in (s->uic,11 ); + mal_irqs[1 ] =qdev_get_gpio_in (s->uic,12 ); + mal_irqs[2 ] =qdev_get_gpio_in (s->uic,13 ); + mal_irqs[3 ] =qdev_get_gpio_in (s->uic,14 );ppc4xx_mal_init (env,4 ,2 , mal_irqs); +/* Ethernet */ /* Uses UIC IRQs 9, 15, 17 */ -/* CPU control */ -ppc405ep_cpc_init (env, clk_setup, sysclk); - -return cpu; -} - -static void ppc405_soc_realize (DeviceState *dev,Error **errp) -{ -Ppc405SoCState *s =PPC405_SOC (dev); - -/* Initialize only one bank */ - s->ram_bases[0 ] =0 ; - s->ram_sizes[0 ] = s->ram_size; -memory_region_init_alias (&s->ram_banks[0 ],OBJECT (s), -"ppc405.sdram0" , s->dram_mr, - s->ram_bases[0 ], s->ram_sizes[0 ]); }static Property ppc405_soc_properties[] = {DEFINE_PROP_LINK ("dram" , Ppc405SoCState, dram_mr,TYPE_MEMORY_REGION , MemoryRegion *), +DEFINE_PROP_UINT32 ("sys-clk" , Ppc405SoCState, sysclk,0 ), +DEFINE_PROP_BOOL ("dram-init" , Ppc405SoCState, do_dram_init,0 ),DEFINE_PROP_UINT64 ("ram-size" , Ppc405SoCState, ram_size,0 ),DEFINE_PROP_END_OF_LIST (), };
Re: [PATCH v3 06/22] ppc/ppc405: Start QOMification of the SoC
Quoted 22 lines · BALATON Zoltan
Quoted 21 lines · Cédric Le Goater
This moves all the code previously done in the
ppc405ep_init()routine underppc405_soc_realize(). We can also adjust the number of banks now that we have control onppc4xx_sdram_init().Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h | 12 ++--hw/ppc/ppc405_boards.c| 12 ++--
hw/ppc/ppc405_uc.c | 123 ++++++++++++++++++++---------------------3 files changed, 70 insertions(+), 77 deletions(-)hw/ppc/ppc405.h +1
-0@@ -73,9 +73,14 @@ struct Ppc405SoCState { /* Public */ MemoryRegion ram_banks[2]; hwaddr ram_bases[2], ram_sizes[2]; + bool do_dram_init;
Quoted 6 lines
hw/ppc/ppc405.h struct Ppc405SoCState { · line 81
Quoted 4 lines
hw/ppc/ppc405.h +2
-0MemoryRegion *dram_mr; hwaddr ram_size; + + uint32_t sysclk;Putting this together with
dram_initwould keep properties set from outside together which is clearer than here with others set by to object itself but this is just a small thing, not really important.
Makes sense but I am removing SoC::sysclk in the following patches.
Quoted 30 lines
Quoted 30 lines
hw/ppc/ppc405.h +2
-7+ PowerPCCPU *cpu; + DeviceState *uic; };/* PowerPC 405 core */ @@ -84,11 +89,4 @@ ram_addr_t ppc405_set_bootinfo(CPUPPCState *env, ram_addr_t ram_size);void ppc4xx_plb_init (CPUPPCState *env);void ppc405_ebc_init (CPUPPCState *env); -PowerPCCPU *ppc405ep_init (MemoryRegion *address_space_mem, - MemoryRegion ram_memories[2], - hwaddr ram_bases[2], - hwaddr ram_sizes[2], - uint32_t sysclk, DeviceState **uicdev, - int do_init); -#endif /* PPC405_H */ hw/ppc/ppc405_boards.c +0
-2@@ -237,9 +237,7 @@ static void ppc405_init(MachineState *machine) Ppc405MachineState *ppc405 = PPC405_MACHINE(machine); MachineClass *mc = MACHINE_GET_CLASS(machine); const char *kernel_filename = machine->kernel_filename; - PowerPCCPU *cpu; MemoryRegion *sysmem = get_system_memory(); - DeviceState *uicdev;
Quoted 10 lines
hw/ppc/ppc405_boards.c static void ppc405_init(MachineState *machine) · line 256
Quoted 8 lines
hw/ppc/ppc405_boards.c +2
-0if (machine->ram_size != mc->default_ram_size) { char *sz = size_to_str(mc->default_ram_size);@@ -254,12 +252,12 @@ static void ppc405_init(MachineState *machine) machine->ram_size, &error_fatal); object_property_set_link(OBJECT(&ppc405->soc), "dram", OBJECT(machine->ram), &error_abort); + object_property_set_bool(OBJECT(&ppc405->soc), "dram-init", + !(kernel_filename == NULL), &error_abort);Maybe clearer as
kernel_filename!= NULL
ok.
Quoted 1 line
Is there a problem with indentation in this patch? Does it pass checkpatch.pl?
No. All is fine.
Thanks,
C.
Quoted 211 lines
Regards,
BALATON ZoltanQuoted 207 lines
hw/ppc/ppc405_boards.c +3
-5+ object_property_set_uint(OBJECT(&ppc405->soc), "sys-clk", 33333333, + &error_abort); qdev_realize(DEVICE(&ppc405->soc), NULL, &error_abort); - cpu = ppc405ep_init(sysmem, ppc405->soc.ram_banks, ppc405->soc.ram_bases, - ppc405->soc.ram_sizes, - 33333333, &uicdev, kernel_filename == NULL ? 0 : 1); - /* allocate and load BIOS */ if (machine->firmware) { MemoryRegion *bios = g_new(MemoryRegion, 1);@@ -315,7 +313,7 @@ static void ppc405_init(MachineState *machine) /* Load ELF kernel and rootfs.cpio */ } else if (kernel_filename && !machine->firmware) { - boot_from_kernel(machine, cpu); + boot_from_kernel(machine, ppc405->soc.cpu); } }hw/ppc/ppc405_uc.c +60
-63@@ -1432,121 +1432,118 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],#endif } -PowerPCCPU *ppc405ep_init (MemoryRegion *address_space_mem, - MemoryRegion ram_memories[2], - hwaddr ram_bases[2], - hwaddr ram_sizes[2], - uint32_t sysclk, DeviceState **uicdevp, - int do_init) +static void ppc405_soc_realize (DeviceState *dev,Error **errp) { + Ppc405SoCState *s = PPC405_SOC(dev); clk_setup_t clk_setup[PPC405EP_CLK_NB], tlb_clk_setup; qemu_irq dma_irqs[4], gpt_irqs[5], mal_irqs[4]; - PowerPCCPU *cpu; CPUPPCState *env; - DeviceState *uicdev; - SysBusDevice *uicsbd; memset(clk_setup, 0, sizeof(clk_setup)); + /* init CPUs */ - cpu = ppc4xx_init(POWERPC_CPU_TYPE_NAME("405ep"), + s->cpu = ppc4xx_init(POWERPC_CPU_TYPE_NAME("405ep"), &clk_setup[PPC405EP_CPU_CLK], - &tlb_clk_setup, sysclk); - env = &cpu->env; + &tlb_clk_setup, s->sysclk); + env = &s->cpu->env; clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb; clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque; - /* Internal devices init */ - /* Memory mapped devices registers */ + + /* CPU control */ + ppc405ep_cpc_init(env, clk_setup, s->sysclk); + /* PLB arbitrer */ ppc4xx_plb_init(env); + /* PLB to OPB bridge */ ppc4xx_pob_init(env); + /* OBP arbitrer */ ppc4xx_opba_init(0xef600600); + /* Universal interrupt controller */ - uicdev = qdev_new(TYPE_PPC_UIC); - uicsbd = SYS_BUS_DEVICE(uicdev); + s->uic = qdev_new(TYPE_PPC_UIC); - object_property_set_link(OBJECT(uicdev), "cpu", OBJECT(cpu), + object_property_set_link(OBJECT(s->uic), "cpu", OBJECT(s->cpu), &error_fatal); - sysbus_realize_and_unref(uicsbd, &error_fatal); - - sysbus_connect_irq(uicsbd, PPCUIC_OUTPUT_INT, - qdev_get_gpio_in(DEVICE(cpu), PPC40x_INPUT_INT)); - sysbus_connect_irq(uicsbd, PPCUIC_OUTPUT_CINT, - qdev_get_gpio_in(DEVICE(cpu), PPC40x_INPUT_CINT)); + if (!sysbus_realize(SYS_BUS_DEVICE(s->uic), errp)) { + return; + } - *uicdevp = uicdev; + sysbus_connect_irq(SYS_BUS_DEVICE(s->uic), PPCUIC_OUTPUT_INT, + qdev_get_gpio_in(DEVICE(s->cpu), PPC40x_INPUT_INT)); + sysbus_connect_irq(SYS_BUS_DEVICE(s->uic), PPCUIC_OUTPUT_CINT, + qdev_get_gpio_in(DEVICE(s->cpu), PPC40x_INPUT_CINT)); /* SDRAM controller */ /* XXX 405EP has no ECC interrupt */ - ppc4xx_sdram_init(env, qdev_get_gpio_in(uicdev, 17), 2, ram_memories, - ram_bases, ram_sizes, do_init); + s->ram_bases[0] = 0; + s->ram_sizes[0] = s->ram_size; + memory_region_init_alias(&s->ram_banks[0], OBJECT(s), + "ppc405.sdram0", s->dram_mr, + s->ram_bases[0], s->ram_sizes[0]); + + ppc4xx_sdram_init(env, qdev_get_gpio_in(s->uic, 17), 1, + s->ram_banks, s->ram_bases, s->ram_sizes, + s->do_dram_init); + /* External bus controller */ ppc405_ebc_init(env); + /* DMA controller */ - dma_irqs[0] = qdev_get_gpio_in(uicdev, 5); - dma_irqs[1] = qdev_get_gpio_in(uicdev, 6); - dma_irqs[2] = qdev_get_gpio_in(uicdev, 7); - dma_irqs[3] = qdev_get_gpio_in(uicdev, 8); + dma_irqs[0] = qdev_get_gpio_in(s->uic, 5); + dma_irqs[1] = qdev_get_gpio_in(s->uic, 6); + dma_irqs[2] = qdev_get_gpio_in(s->uic, 7); + dma_irqs[3] = qdev_get_gpio_in(s->uic, 8); ppc405_dma_init(env, dma_irqs); - /* IIC controller */ + + /* I2C controller */ sysbus_create_simple(TYPE_PPC4xx_I2C, 0xef600500, - qdev_get_gpio_in(uicdev, 2)); + qdev_get_gpio_in(s->uic, 2)); /* GPIO */ ppc405_gpio_init(0xef600700); + /* Serial ports */ if (serial_hd(0) != NULL) { - serial_mm_init(address_space_mem, 0xef600300, 0, - qdev_get_gpio_in(uicdev, 0), + serial_mm_init(get_system_memory(), 0xef600300, 0, + qdev_get_gpio_in(s->uic, 0), PPC_SERIAL_MM_BAUDBASE, serial_hd(0), DEVICE_BIG_ENDIAN); } if (serial_hd(1) != NULL) { - serial_mm_init(address_space_mem, 0xef600400, 0, - qdev_get_gpio_in(uicdev, 1), + serial_mm_init(get_system_memory(), 0xef600400, 0, + qdev_get_gpio_in(s->uic, 1), PPC_SERIAL_MM_BAUDBASE, serial_hd(1), DEVICE_BIG_ENDIAN); } + /* OCM */ ppc405_ocm_init(env); + /* GPT */ - gpt_irqs[0] = qdev_get_gpio_in(uicdev, 19); - gpt_irqs[1] = qdev_get_gpio_in(uicdev, 20); - gpt_irqs[2] = qdev_get_gpio_in(uicdev, 21); - gpt_irqs[3] = qdev_get_gpio_in(uicdev, 22); - gpt_irqs[4] = qdev_get_gpio_in(uicdev, 23); + gpt_irqs[0] = qdev_get_gpio_in(s->uic, 19); + gpt_irqs[1] = qdev_get_gpio_in(s->uic, 20); + gpt_irqs[2] = qdev_get_gpio_in(s->uic, 21); + gpt_irqs[3] = qdev_get_gpio_in(s->uic, 22); + gpt_irqs[4] = qdev_get_gpio_in(s->uic, 23); ppc4xx_gpt_init(0xef600000, gpt_irqs); - /* PCI */ - /* Uses UIC IRQs 3, 16, 18 */ + /* MAL */ - mal_irqs[0] = qdev_get_gpio_in(uicdev, 11); - mal_irqs[1] = qdev_get_gpio_in(uicdev, 12); - mal_irqs[2] = qdev_get_gpio_in(uicdev, 13); - mal_irqs[3] = qdev_get_gpio_in(uicdev, 14); + mal_irqs[0] = qdev_get_gpio_in(s->uic, 11); + mal_irqs[1] = qdev_get_gpio_in(s->uic, 12); + mal_irqs[2] = qdev_get_gpio_in(s->uic, 13); + mal_irqs[3] = qdev_get_gpio_in(s->uic, 14); ppc4xx_mal_init(env, 4, 2, mal_irqs); + /* Ethernet */ /* Uses UIC IRQs 9, 15, 17 */ - /* CPU control */ - ppc405ep_cpc_init(env, clk_setup, sysclk); - - return cpu; -} - -static void ppc405_soc_realize (DeviceState *dev,Error **errp) -{ - Ppc405SoCState *s = PPC405_SOC(dev); - - /* Initialize only one bank */ - s->ram_bases[0] = 0; - s->ram_sizes[0] = s->ram_size; - memory_region_init_alias(&s->ram_banks[0], OBJECT(s), - "ppc405.sdram0", s->dram_mr, - s->ram_bases[0], s->ram_sizes[0]); }static Property ppc405_soc_properties[] = { DEFINE_PROP_LINK("dram", Ppc405SoCState, dram_mr, TYPE_MEMORY_REGION, MemoryRegion *), + DEFINE_PROP_UINT32("sys-clk", Ppc405SoCState, sysclk, 0), + DEFINE_PROP_BOOL("dram-init", Ppc405SoCState, do_dram_init, 0), DEFINE_PROP_UINT64("ram-size", Ppc405SoCState, ram_size, 0), DEFINE_PROP_END_OF_LIST(), };
PATCH v3 7/22 ppc/ppc405: QOM'ify CPU
In reply to Cédric Le GoaterDrop the use of ppc4xx_init() and duplicate a bit of code related to clocks in the SoC realize routine. We will clean that up in the following patches.
ppc_dcr_init() simply allocates default DCR handlers for the CPU. Maybe this could be done in model initializer of the CPU families needing it.
--- hw/ppc/ppc405.h | 2 +- include/hw/ppc/ppc4xx.h | 1 + hw/ppc/ppc405_boards.c | 2 +- hw/ppc/ppc405_uc.c | 35 +++++++++++++++++++++++++---------- hw/ppc/ppc4xx_devs.c | 2 +- 5 files changed, 29 insertions(+), 13 deletions(-)
hw/ppc/ppc405.h +1 -1
@@ -79,7 +79,7 @@ struct Ppc405SoCState {hwaddr ram_size;uint32_t sysclk; -PowerPCCPU *cpu; +PowerPCCPU cpu;DeviceState *uic; };
include/hw/ppc/ppc4xx.h +1 -0
@@ -29,6 +29,7 @@#include "exec/memory.h" /* PowerPC 4xx core initialization */ +void ppc4xx_reset (void *opaque);PowerPCCPU *ppc4xx_init (const char *cpu_model,clk_setup_t *cpu_clk,clk_setup_t *tb_clk,uint32_t sysclk);
hw/ppc/ppc405_boards.c +1 -1
@@ -313,7 +313,7 @@ static void ppc405_init(MachineState *machine)/* Load ELF kernel and rootfs.cpio */ }else if (kernel_filename && !machine->firmware) { -boot_from_kernel (machine, ppc405->soc.cpu); +boot_from_kernel (machine, &ppc405->soc.cpu); } }
hw/ppc/ppc405_uc.c +25 -10
@@ -1432,22 +1432,36 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],#endif } +static void ppc405_soc_instance_init (Object *obj) +{ +Ppc405SoCState *s =PPC405_SOC (obj); + +object_initialize_child (obj,"cpu" , &s->cpu, +POWERPC_CPU_TYPE_NAME ("405ep" )); +} +static void ppc405_soc_realize (DeviceState *dev,Error **errp) {Ppc405SoCState *s =PPC405_SOC (dev); -clk_setup_t clk_setup[PPC405EP_CLK_NB ], tlb_clk_setup; +clk_setup_t clk_setup[PPC405EP_CLK_NB ];qemu_irq dma_irqs[4 ], gpt_irqs[5 ], mal_irqs[4 ];CPUPPCState *env;memset (clk_setup,0 ,sizeof (clk_setup));/* init CPUs */ - s->cpu =ppc4xx_init (POWERPC_CPU_TYPE_NAME ("405ep" ), - &clk_setup[PPC405EP_CPU_CLK ], - &tlb_clk_setup, s->sysclk); - env = &s->cpu->env; - clk_setup[PPC405EP_CPU_CLK ].cb = tlb_clk_setup.cb; - clk_setup[PPC405EP_CPU_CLK ].opaque = tlb_clk_setup.opaque; +if (!qdev_realize (DEVICE (&s->cpu),NULL , errp)) { +return ; + } +qemu_register_reset (ppc4xx_reset, &s->cpu); + + env = &s->cpu.env; + + clk_setup[PPC405EP_CPU_CLK ].cb = +ppc_40x_timers_init (env, s->sysclk,PPC_INTERRUPT_PIT ); + clk_setup[PPC405EP_CPU_CLK ].opaque = env; + +ppc_dcr_init (env,NULL ,NULL );/* CPU control */ ppc405ep_cpc_init (env, clk_setup, s->sysclk);
@@ -1464,16 +1478,16 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)/* Universal interrupt controller */ s->uic =qdev_new (TYPE_PPC_UIC ); -object_property_set_link (OBJECT (s->uic),"cpu" ,OBJECT (s->cpu), +object_property_set_link (OBJECT (s->uic),"cpu" ,OBJECT (&s->cpu), &error_fatal);if (!sysbus_realize (SYS_BUS_DEVICE (s->uic), errp)) {return ; }sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_INT , -qdev_get_gpio_in (DEVICE (s->cpu), PPC40x_INPUT_INT)); +qdev_get_gpio_in (DEVICE (&s->cpu), PPC40x_INPUT_INT));sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_CINT , -qdev_get_gpio_in (DEVICE (s->cpu), PPC40x_INPUT_CINT)); +qdev_get_gpio_in (DEVICE (&s->cpu), PPC40x_INPUT_CINT));/* SDRAM controller */ /* XXX 405EP has no ECC interrupt */
@@ -1562,6 +1576,7 @@ static const TypeInfo ppc405_types[] = { .name = TYPE_PPC405_SOC, .parent = TYPE_DEVICE, .instance_size = sizeof(Ppc405SoCState), + .instance_init = ppc405_soc_instance_init, .class_init = ppc405_soc_class_init, } };
hw/ppc/ppc4xx_devs.c +1 -1
@@ -37,7 +37,7 @@#include "qapi/error.h" #include "trace.h" -static void ppc4xx_reset (void *opaque) +void ppc4xx_reset (void *opaque) {PowerPCCPU *cpu = opaque;
Signature · 1 line
2.37.1
Re: [PATCH v3 07/22] ppc/ppc405: QOM'ify CPU
Patch title is wrong. It should be Embed CPU object in SoC as it's not QOMifies the CPU just moves it from dinamically allocated to embedded.
Quoted 3 lines · Cédric Le Goater
Drop the use of
ppc4xx_init()and duplicate a bit of code related to clocks in the SoC realize routine. We will clean that up in the following patches.
Could this be split off into a separate patch? Maybe it would be clearer that way what's related to stop using ppc4xx_init() (which is needed because it dinamically allocates CPU) and what's the embedding it in the soc object.
Quoted 132 lines
ppc_dcr_init()simply allocates default DCR handlers for the CPU. Maybe this could be done in model initializer of the CPU families needing it.Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h | 2 +- include/hw/ppc/ppc4xx.h | 1 + hw/ppc/ppc405_boards.c | 2 +- hw/ppc/ppc405_uc.c | 35 +++++++++++++++++++++++++---------- hw/ppc/ppc4xx_devs.c | 2 +- 5 files changed, 29 insertions(+), 13 deletions(-)hw/ppc/ppc405.h +1
-1@@ -79,7 +79,7 @@ struct Ppc405SoCState {hwaddr ram_size;uint32_t sysclk; -PowerPCCPU *cpu; +PowerPCCPU cpu;DeviceState *uic; };include/hw/ppc/ppc4xx.h +1
-0@@ -29,6 +29,7 @@#include "exec/memory.h" /* PowerPC 4xx core initialization */ +void ppc4xx_reset (void *opaque);PowerPCCPU *ppc4xx_init (const char *cpu_model,clk_setup_t *cpu_clk,clk_setup_t *tb_clk,uint32_t sysclk);hw/ppc/ppc405_boards.c +1
-1@@ -313,7 +313,7 @@ static void ppc405_init(MachineState *machine)/* Load ELF kernel and rootfs.cpio */ }else if (kernel_filename && !machine->firmware) { -boot_from_kernel (machine, ppc405->soc.cpu); +boot_from_kernel (machine, &ppc405->soc.cpu); } }hw/ppc/ppc405_uc.c +25
-10@@ -1432,22 +1432,36 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],#endif } +static void ppc405_soc_instance_init (Object *obj) +{ +Ppc405SoCState *s =PPC405_SOC (obj); + +object_initialize_child (obj,"cpu" , &s->cpu, +POWERPC_CPU_TYPE_NAME ("405ep" )); +} +static void ppc405_soc_realize (DeviceState *dev,Error **errp) {Ppc405SoCState *s =PPC405_SOC (dev); -clk_setup_t clk_setup[PPC405EP_CLK_NB ], tlb_clk_setup; +clk_setup_t clk_setup[PPC405EP_CLK_NB ];qemu_irq dma_irqs[4 ], gpt_irqs[5 ], mal_irqs[4 ];CPUPPCState *env;memset (clk_setup,0 ,sizeof (clk_setup));/* init CPUs */ - s->cpu =ppc4xx_init (POWERPC_CPU_TYPE_NAME ("405ep" ), - &clk_setup[PPC405EP_CPU_CLK ], - &tlb_clk_setup, s->sysclk); - env = &s->cpu->env; - clk_setup[PPC405EP_CPU_CLK ].cb = tlb_clk_setup.cb; - clk_setup[PPC405EP_CPU_CLK ].opaque = tlb_clk_setup.opaque; +if (!qdev_realize (DEVICE (&s->cpu),NULL , errp)) { +return ; + } +qemu_register_reset (ppc4xx_reset, &s->cpu); + + env = &s->cpu.env; + + clk_setup[PPC405EP_CPU_CLK ].cb = +ppc_40x_timers_init (env, s->sysclk,PPC_INTERRUPT_PIT ); + clk_setup[PPC405EP_CPU_CLK ].opaque = env; + +ppc_dcr_init (env,NULL ,NULL );/* CPU control */ ppc405ep_cpc_init (env, clk_setup, s->sysclk);@@ -1464,16 +1478,16 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)/* Universal interrupt controller */ s->uic =qdev_new (TYPE_PPC_UIC ); -object_property_set_link (OBJECT (s->uic),"cpu" ,OBJECT (s->cpu), +object_property_set_link (OBJECT (s->uic),"cpu" ,OBJECT (&s->cpu), &error_fatal);if (!sysbus_realize (SYS_BUS_DEVICE (s->uic), errp)) {return ; }sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_INT , -qdev_get_gpio_in (DEVICE (s->cpu), PPC40x_INPUT_INT)); +qdev_get_gpio_in (DEVICE (&s->cpu), PPC40x_INPUT_INT));sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_CINT , -qdev_get_gpio_in (DEVICE (s->cpu), PPC40x_INPUT_CINT)); +qdev_get_gpio_in (DEVICE (&s->cpu), PPC40x_INPUT_CINT));/* SDRAM controller */ /* XXX 405EP has no ECC interrupt */ @@ -1562,6 +1576,7 @@ static const TypeInfo ppc405_types[] = { .name = TYPE_PPC405_SOC, .parent = TYPE_DEVICE, .instance_size = sizeof(Ppc405SoCState), + .instance_init = ppc405_soc_instance_init, .class_init = ppc405_soc_class_init, } };hw/ppc/ppc4xx_devs.c +0
-0
hw/ppc/ppc4xx_devs.c line 42
Quoted 7 lines
hw/ppc/ppc4xx_devs.c +1
-1@@ -37,7 +37,7 @@#include "qapi/error.h" #include "trace.h" -static void ppc4xx_reset (void *opaque) +void ppc4xx_reset (void *opaque) {PowerPCCPU *cpu = opaque;
This just calls cpu_reset() and does nothing else. Can't that be registered directly so this could be kept static to this file? Why do we need this at all? Isn't the cpu object reset automatically? Why do we need to register it separately?
Regards,
BALATON Zoltan
Re: [PATCH v3 07/22] ppc/ppc405: QOM'ify CPU
Quoted 9 lines · BALATON Zoltan
Patch title is wrong. It should be Embed CPU object in SoC as it's not QOMifies the CPU just moves it from dinamically allocated to embedded.
Quoted 3 lines · Cédric Le Goater
Drop the use of
ppc4xx_init()and duplicate a bit of code related to clocks in the SoC realize routine. We will clean that up in the following patches.Could this be split off into a separate patch? Maybe it would be clearer that way what's related to stop using
ppc4xx_init()(which is needed because it dinamically allocates CPU) and what's the embedding it in the soc object.
I'd rather not. It has been painful enough to untangle. Let's keep it that way. And, this part is further changed in the CPC patch.
Quoted 135 lines
Quoted 135 lines
ppc_dcr_init()simply allocates default DCR handlers for the CPU. Maybe this could be done in model initializer of the CPU families needing it.Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h | 2 +-include/hw/ppc/ppc4xx.h| 1 +
hw/ppc/ppc405_boards.c | 2 +-
hw/ppc/ppc405_uc.c | 35 +++++++++++++++++++++++++---------- hw/ppc/ppc4xx_devs.c | 2 +-5 files changed, 29 insertions(+), 13 deletions(-)hw/ppc/ppc405.h +1
-1@@ -79,7 +79,7 @@ struct Ppc405SoCState { hwaddr ram_size; uint32_t sysclk; - PowerPCCPU *cpu; + PowerPCCPU cpu; DeviceState *uic; };include/hw/ppc/ppc4xx.h +1
-0@@ -29,6 +29,7 @@#include "exec/memory.h" /* PowerPC 4xx core initialization */ +void ppc4xx_reset (void *opaque);PowerPCCPU *ppc4xx_init (const char *cpu_model, clk_setup_t *cpu_clk, clk_setup_t *tb_clk, uint32_t sysclk);hw/ppc/ppc405_boards.c +1
-1@@ -313,7 +313,7 @@ static void ppc405_init(MachineState *machine) /* Load ELF kernel and rootfs.cpio */ } else if (kernel_filename && !machine->firmware) { - boot_from_kernel(machine, ppc405->soc.cpu); + boot_from_kernel(machine, &ppc405->soc.cpu); } }hw/ppc/ppc405_uc.c +25
-10@@ -1432,22 +1432,36 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],#endif } +static void ppc405_soc_instance_init (Object *obj) +{ + Ppc405SoCState *s = PPC405_SOC(obj); + + object_initialize_child(obj, "cpu", &s->cpu, + POWERPC_CPU_TYPE_NAME("405ep")); +} +static void ppc405_soc_realize (DeviceState *dev,Error **errp) { Ppc405SoCState *s = PPC405_SOC(dev); - clk_setup_t clk_setup[PPC405EP_CLK_NB], tlb_clk_setup; + clk_setup_t clk_setup[PPC405EP_CLK_NB]; qemu_irq dma_irqs[4], gpt_irqs[5], mal_irqs[4]; CPUPPCState *env; memset(clk_setup, 0, sizeof(clk_setup)); /* init CPUs */ - s->cpu = ppc4xx_init(POWERPC_CPU_TYPE_NAME("405ep"), - &clk_setup[PPC405EP_CPU_CLK], - &tlb_clk_setup, s->sysclk); - env = &s->cpu->env; - clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb; - clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque; + if (!qdev_realize(DEVICE(&s->cpu), NULL, errp)) { + return; + } + qemu_register_reset(ppc4xx_reset, &s->cpu); + + env = &s->cpu.env; + + clk_setup[PPC405EP_CPU_CLK].cb = + ppc_40x_timers_init(env, s->sysclk, PPC_INTERRUPT_PIT); + clk_setup[PPC405EP_CPU_CLK].opaque = env; + + ppc_dcr_init(env, NULL, NULL); /* CPU control */ ppc405ep_cpc_init(env, clk_setup, s->sysclk);@@ -1464,16 +1478,16 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp) /* Universal interrupt controller */ s->uic = qdev_new(TYPE_PPC_UIC); - object_property_set_link(OBJECT(s->uic), "cpu", OBJECT(s->cpu), + object_property_set_link(OBJECT(s->uic), "cpu", OBJECT(&s->cpu), &error_fatal); if (!sysbus_realize(SYS_BUS_DEVICE(s->uic), errp)) { return; } sysbus_connect_irq(SYS_BUS_DEVICE(s->uic), PPCUIC_OUTPUT_INT, - qdev_get_gpio_in(DEVICE(s->cpu), PPC40x_INPUT_INT)); + qdev_get_gpio_in(DEVICE(&s->cpu), PPC40x_INPUT_INT)); sysbus_connect_irq(SYS_BUS_DEVICE(s->uic), PPCUIC_OUTPUT_CINT, - qdev_get_gpio_in(DEVICE(s->cpu), PPC40x_INPUT_CINT)); + qdev_get_gpio_in(DEVICE(&s->cpu), PPC40x_INPUT_CINT)); /* SDRAM controller */ /* XXX 405EP has no ECC interrupt */@@ -1562,6 +1576,7 @@ static const TypeInfo ppc405_types[] = { .name = TYPE_PPC405_SOC, .parent = TYPE_DEVICE, .instance_size = sizeof(Ppc405SoCState), + .instance_init = ppc405_soc_instance_init, .class_init = ppc405_soc_class_init, } };hw/ppc/ppc4xx_devs.c +0
-0@@ -37,7 +37,7 @@#include "qapi/error.h" #include "trace.h"
Quoted 6 lines
hw/ppc/ppc4xx_devs.c line 42
Quoted 4 lines
hw/ppc/ppc4xx_devs.c +1
-1-static void ppc4xx_reset (void *opaque) +void ppc4xx_reset (void *opaque) { PowerPCCPU *cpu = opaque;This just calls
cpu_reset()and does nothing else. Can't that be registered directly so this could be kept static to this file?
what do you mean ?
Quoted 1 line
Why do we need this at all?
Oh yes. We need the CPU to start in a reset state, for U-boot at least.
Quoted 1 line
Isn't the cpu object reset automatically? Why do we need to register it separately?
All devices need a reset handler. The handler of the PPC405 CPU is registered in ppc405_soc_realize() :
qemu_register_reset(ppc4xx_reset, &s->cpu);
If we had a more complex model, like pseries or PowerNV, we would install the reset handler in the realize routine of the CPU model. But we don't.
Thanks,
C.
Quoted 3 lines
Regards,
BALATON Zoltan
Re: [PATCH v3 07/22] ppc/ppc405: QOM'ify CPU
Quoted 5 lines · Cédric Le Goater
Quoted 4 lines · BALATON Zoltan
Patch title is wrong. It should be Embed CPU object in SoC as it's not QOMifies the CPU just moves it from dinamically allocated to embedded.
On Mon, 8 Aug 2022, Cédric Le Goater wrote:
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Drop the use of
ppc4xx_init()and duplicate a bit of code related to clocks in the SoC realize routine. We will clean that up in the following patches.Could this be split off into a separate patch? Maybe it would be clearer that way what's related to stop using
ppc4xx_init()(which is needed because it dinamically allocates CPU) and what's the embedding it in the soc object.I'd rather not. It has been painful enough to untangle. Let's keep it that way. And, this part is further changed in the CPC patch.
OK, if nobody else thinks this should be split I'm OK with it.
Quoted 141 lines
Quoted 141 lines
Quoted 141 lines
ppc_dcr_init()simply allocates default DCR handlers for the CPU. Maybe this could be done in model initializer of the CPU families needing it.Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h | 2 +-include/hw/ppc/ppc4xx.h| 1 +
hw/ppc/ppc405_boards.c | 2 +-
hw/ppc/ppc405_uc.c | 35 +++++++++++++++++++++++++---------- hw/ppc/ppc4xx_devs.c | 2 +-5 files changed, 29 insertions(+), 13 deletions(-)hw/ppc/ppc405.h +1
-1@@ -79,7 +79,7 @@ struct Ppc405SoCState { hwaddr ram_size; uint32_t sysclk; - PowerPCCPU *cpu; + PowerPCCPU cpu; DeviceState *uic; };include/hw/ppc/ppc4xx.h +1
-0@@ -29,6 +29,7 @@#include "exec/memory.h" /* PowerPC 4xx core initialization */ +void ppc4xx_reset (void *opaque);PowerPCCPU *ppc4xx_init (const char *cpu_model, clk_setup_t *cpu_clk, clk_setup_t *tb_clk, uint32_t sysclk);hw/ppc/ppc405_boards.c +1
-1@@ -313,7 +313,7 @@ static void ppc405_init(MachineState *machine) /* Load ELF kernel and rootfs.cpio */ } else if (kernel_filename && !machine->firmware) { - boot_from_kernel(machine, ppc405->soc.cpu); + boot_from_kernel(machine, &ppc405->soc.cpu); } }hw/ppc/ppc405_uc.c +21
-7@@ -1432,22 +1432,36 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],#endif } +static void ppc405_soc_instance_init (Object *obj) +{ + Ppc405SoCState *s = PPC405_SOC(obj); + + object_initialize_child(obj, "cpu", &s->cpu, + POWERPC_CPU_TYPE_NAME("405ep")); +} +static void ppc405_soc_realize (DeviceState *dev,Error **errp) { Ppc405SoCState *s = PPC405_SOC(dev); - clk_setup_t clk_setup[PPC405EP_CLK_NB], tlb_clk_setup; + clk_setup_t clk_setup[PPC405EP_CLK_NB]; qemu_irq dma_irqs[4], gpt_irqs[5], mal_irqs[4]; CPUPPCState *env; memset(clk_setup, 0, sizeof(clk_setup)); /* init CPUs */ - s->cpu = ppc4xx_init(POWERPC_CPU_TYPE_NAME("405ep"), - &clk_setup[PPC405EP_CPU_CLK], - &tlb_clk_setup, s->sysclk); - env = &s->cpu->env; - clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb; - clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque; + if (!qdev_realize(DEVICE(&s->cpu), NULL, errp)) { + return; + } + qemu_register_reset(ppc4xx_reset, &s->cpu); + + env = &s->cpu.env; + + clk_setup[PPC405EP_CPU_CLK].cb = + ppc_40x_timers_init(env, s->sysclk, PPC_INTERRUPT_PIT); + clk_setup[PPC405EP_CPU_CLK].opaque = env; + + ppc_dcr_init(env, NULL, NULL); /* CPU control */
ppc405ep_cpc_init(env, clk_setup, s->sysclk);hw/ppc/ppc405_uc.c +2
-3@@ -1464,16 +1478,16 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp) /* Universal interrupt controller */ s->uic = qdev_new(TYPE_PPC_UIC); - object_property_set_link(OBJECT(s->uic), "cpu", OBJECT(s->cpu), + object_property_set_link(OBJECT(s->uic), "cpu", OBJECT(&s->cpu), &error_fatal); if (!sysbus_realize(SYS_BUS_DEVICE(s->uic), errp)) { return; } sysbus_connect_irq(SYS_BUS_DEVICE(s->uic), PPCUIC_OUTPUT_INT, - qdev_get_gpio_in(DEVICE(s->cpu), PPC40x_INPUT_INT)); + qdev_get_gpio_in(DEVICE(&s->cpu), PPC40x_INPUT_INT)); sysbus_connect_irq(SYS_BUS_DEVICE(s->uic), PPCUIC_OUTPUT_CINT, - qdev_get_gpio_in(DEVICE(s->cpu),
PPC40x_INPUT_CINT));
+qdev_get_gpio_in(DEVICE(&s->cpu), PPC40x_INPUT_CINT));/* SDRAM controller */
/* XXX 405EP has no ECC interrupt */hw/ppc/ppc405_uc.c +1
-0@@ -1562,6 +1576,7 @@ static const TypeInfo ppc405_types[] = { .name = TYPE_PPC405_SOC, .parent = TYPE_DEVICE, .instance_size = sizeof(Ppc405SoCState), + .instance_init = ppc405_soc_instance_init, .class_init = ppc405_soc_class_init, } };hw/ppc/ppc4xx_devs.c +0
-0@@ -37,7 +37,7 @@#include "qapi/error.h" #include "trace.h"
Quoted 8 lines
Quoted 6 lines
hw/ppc/ppc4xx_devs.c line 42
Quoted 4 lines
hw/ppc/ppc4xx_devs.c +1
-1-static void ppc4xx_reset (void *opaque) +void ppc4xx_reset (void *opaque) { PowerPCCPU *cpu = opaque;This just calls
cpu_reset()and does nothing else. Can't that be registered directly so this could be kept static to this file?what do you mean ?
Something like qemu_register_reset(cpu_reset, &s->cpu); but I'm not sure this is even needed.
Quoted 10 lines
Quoted 1 line
Why do we need this at all?
Oh yes. We need the CPU to start in a reset state, for U-boot at least.
Quoted 1 line
Isn't the cpu object reset automatically? Why do we need to register it separately?
All devices need a reset handler. The handler of the PPC405 CPU is registered in
ppc405_soc_realize():
qemu_register_reset(ppc4xx_reset, &s->cpu);
But the handler we register here just calls cpu_reset which seems to just call the reset method of the CPU object. If we have nothing else to do here do we need to explicitly call cpi_reset like this? Wouldn't the CPU object be reset by qdev when resetting the machine or the soc its in? If we have our own reset method we may call cpu_reset from there to make sure the CPU is in a known state but is this needed when we don't want to do anything else? I don't know how reset handling works but some machines seems to do this and others don't.
Quoted 2 lines
If we had a more complex model, like pseries or PowerNV, we would install the reset handler in the realize routine of the CPU model. But we don't.
If this is needed maybe you should add a soc_reset method and call cpu_reset() from there and get rid of ppc4xx_reset or move it to ppc405_uc.c if it's not used anywhere else, so it can be kept static and does not need to be added to ppc4xx.h.
Regards,
BALATON Zoltan
Re: [PATCH v3 07/22] ppc/ppc405: QOM'ify CPU
Quoted 8 lines · BALATON Zoltan
But the handler we register here just calls
cpu_resetwhich seems to just call the reset method of the CPU object. If we have nothing else to do here do we need to explicitly callcpi_resetlike this? Wouldn't the CPU object be reset by qdev when resetting the machine or the soc its in? If we have our own reset method we may callcpu_resetfrom there to make sure the CPU is in a known state but is this needed when we don't want to do anything else? I don't know how reset handling works but some machines seems to do this and others don't.
You do unfortunately need to manually reset the CPU object. This is because the 'automatic' qdev reset only works for devices that hang off a bus (including sysbus devices). This is because it works by having qdev_machine_creation_done() register a reset function which does "reset the sysbus". Resetting a bus resets every device on it. Resetting a device resets every bus it owns. (This means that for instance PCI devices get reset because the PCI controller is on the sysbus, so it gets reset, and it owns the PCI bus, so the PCI bus resets when the controller is reset, and when the PCI bus resets then all the devices on it are reset.) So reset propagates down the bus tree, but it won't reach devices which aren't on that bus tree at all. The most common case of "device which isn't on a bus" is the CPU objects.
This is, clearly, a complete mess. I would strongly like to sort it out, but to do that we need (a) a plan for what reset handling ought to look like and (b) a transition plan for getting from here to there without breaking everything in the process. I haven't had the time to focus on that, though it's been nominally on my todo list for years.
In the meantime, it's the responsibility of something in architecture specific code to arrange for the CPU objects to be reset -- whether that's done directly by the board, or hidden in some other layer of code, depends on the target arch. For instance for arm it's hidden inside arm_load_kernel() and board models must therefore call that function even if they have no intention of supporting loading Linux kernels. For sparc it's done directly in the board code.
thanks
-- PMM
Re: [PATCH v3 07/22] ppc/ppc405: QOM'ify CPU
Quoted 30 lines · Peter Maydell
Quoted 8 lines · BALATON Zoltan
But the handler we register here just calls
cpu_resetwhich seems to just call the reset method of the CPU object. If we have nothing else to do here do we need to explicitly callcpi_resetlike this? Wouldn't the CPU object be reset by qdev when resetting the machine or the soc its in? If we have our own reset method we may callcpu_resetfrom there to make sure the CPU is in a known state but is this needed when we don't want to do anything else? I don't know how reset handling works but some machines seems to do this and others don't.You do unfortunately need to manually reset the CPU object. This is because the 'automatic' qdev reset only works for devices that hang off a bus (including sysbus devices). This is because it works by having
qdev_machine_creation_done()register a reset function which does "reset the sysbus". Resetting a bus resets every device on it. Resetting a device resets every bus it owns. (This means that for instance PCI devices get reset because the PCI controller is on the sysbus, so it gets reset, and it owns the PCI bus, so the PCI bus resets when the controller is reset, and when the PCI bus resets then all the devices on it are reset.) So reset propagates down the bus tree, but it won't reach devices which aren't on that bus tree at all. The most common case of "device which isn't on a bus" is the CPU objects.This is, clearly, a complete mess. I would strongly like to sort it out, but to do that we need (a) a plan for what reset handling ought to look like and (b) a transition plan for getting from here to there without breaking everything in the process. I haven't had the time to focus on that, though it's been nominally on my todo list for years.
Quoted 7 lines
In the meantime, it's the responsibility of something in architecture specific code to arrange for the CPU objects to be reset -- whether that's done directly by the board, or hidden in some other layer of code, depends on the target arch. For instance for arm it's hidden inside
arm_load_kernel()and board models must therefore call that function even if they have no intention of supporting loading Linux kernels. For sparc it's done directly in the board code.
OK thanks for the clarification. Both bamboo and sam460ex has a main_cpu_reset function that is registered from the machine init func which calls cpu_reset. Maybe 405 boards could do the same for consistency? It could also be added to the soc object's reset method as that owns the cpu so maybe it may make more sense that way. This is probably also OK as 440 machines don't have soc object yet so it wouldn't cause any problems.
I think the ppc4xx_reset func was kept around because ppc4xx_init was also kept but nothing else seems to use it so maybe these should become the soc object's realize and reset methods and drop the current ppc4xx_init and reset funcs?
Regards,
BALATON Zoltan
Re: [PATCH v3 07/22] ppc/ppc405: QOM'ify CPU
Quoted 39 lines · BALATON Zoltan
Quoted 30 lines · Peter Maydell
Quoted 8 lines · BALATON Zoltan
But the handler we register here just calls
cpu_resetwhich seems to just call the reset method of the CPU object. If we have nothing else to do here do we need to explicitly callcpi_resetlike this? Wouldn't the CPU object be reset by qdev when resetting the machine or the soc its in? If we have our own reset method we may callcpu_resetfrom there to make sure the CPU is in a known state but is this needed when we don't want to do anything else? I don't know how reset handling works but some machines seems to do this and others don't.You do unfortunately need to manually reset the CPU object. This is because the 'automatic' qdev reset only works for devices that hang off a bus (including sysbus devices). This is because it works by having
qdev_machine_creation_done()register a reset function which does "reset the sysbus". Resetting a bus resets every device on it. Resetting a device resets every bus it owns. (This means that for instance PCI devices get reset because the PCI controller is on the sysbus, so it gets reset, and it owns the PCI bus, so the PCI bus resets when the controller is reset, and when the PCI bus resets then all the devices on it are reset.) So reset propagates down the bus tree, but it won't reach devices which aren't on that bus tree at all. The most common case of "device which isn't on a bus" is the CPU objects.This is, clearly, a complete mess. I would strongly like to sort it out, but to do that we need (a) a plan for what reset handling ought to look like and (b) a transition plan for getting from here to there without breaking everything in the process. I haven't had the time to focus on that, though it's been nominally on my todo list for years.
Quoted 7 lines
In the meantime, it's the responsibility of something in architecture specific code to arrange for the CPU objects to be reset -- whether that's done directly by the board, or hidden in some other layer of code, depends on the target arch. For instance for arm it's hidden inside
arm_load_kernel()and board models must therefore call that function even if they have no intention of supporting loading Linux kernels. For sparc it's done directly in the board code.
Quoted 3 lines
OK thanks for the clarification. Both bamboo and sam460ex has a
main_cpu_resetfunction that is registered from the machine init func which callscpu_reset. Maybe 405 boards could do the same for consistency? It could also be added to the soc object's reset method as that owns the cpu so maybe it may make more sense that way. This is probably also OK as 440 machines don't have soc object yet so it wouldn't cause any problems.I think the
ppc4xx_resetfunc was kept around becauseppc4xx_initwas also kept but nothing else seems to use it so maybe these should become the soc object's realize and reset methods and drop the currentppc4xx_initand reset funcs?
Yes. I have moved the CPU reset routine under ppc405_uc.c and removed ppc4xx_init() which is now unused.
Thanks,
C.
PATCH v3 8/22 ppc/ppc4xx: Introduce a DCR device model
In reply to Cédric Le GoaterThe Device Control Registers (DCR) of on-SoC devices are accessed by software through the use of the mtdcr and mfdcr instructions. These are converted in transactions on a side band bus, the DCR bus, which connects the on-SoC devices to the CPU.
Ideally, we should model these accesses with a DCR namespace and DCR memory regions but today the DCR handlers are installed in a DCR table under the CPU. Instead introduce a little device model wrapper to hold a CPU link and handle registration of DCR handlers.
The DCR device inherits from SysBus because most of these devices also have a MMIO regions and/or IRQs. Being a SysBusDevice makes things easier to install the device model in the overall SoC.
The "cpu" link should be considered as modeling the piece of HW logic connecting the device to the DCR bus.
--- include/hw/ppc/ppc4xx.h | 17 +++++++++++++++ hw/ppc/ppc4xx_devs.c | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+)
include/hw/ppc/ppc4xx.h +17 -0
@@ -27,6 +27,7 @@#include "hw/ppc/ppc.h" #include "exec/memory.h" +#include "hw/sysbus.h" /* PowerPC 4xx core initialization */ void ppc4xx_reset (void *opaque);
@@ -50,4 +51,20 @@ void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum,#define TYPE_PPC4xx_PCI_HOST_BRIDGE "ppc4xx-pcihost" +/* +* Generic DCR device +*/ +#define TYPE_PPC4xx_DCR_DEVICE "ppc4xx-dcr" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc4xxDcrDeviceState, PPC4xx_DCR_DEVICE); +struct Ppc4xxDcrDeviceState { +SysBusDevice parent_obj; + +PowerPCCPU *cpu; +}; + +void ppc4xx_dcr_register (Ppc4xxDcrDeviceState *dev,int dcrn, +dcr_read_cb dcr_read,dcr_write_cb dcr_write); +bool ppc4xx_dcr_realize (Ppc4xxDcrDeviceState *dev,PowerPCCPU *cpu, +Error **errp); +#endif /* PPC4XX_H */
hw/ppc/ppc4xx_devs.c +46 -0
49 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH v3 08/22] ppc/ppc4xx: Introduce a DCR device model
Quoted 5 lines · Cédric Le Goater
The Device Control Registers (DCR) of on-SoC devices are accessed by software through the use of the mtdcr and mfdcr instructions. These are converted in transactions on a side band bus, the DCR bus, which connects the on-SoC devices to the CPU.
Quoted 7 lines
Ideally, we should model these accesses with a DCR namespace and DCR memory regions but today the DCR handlers are installed in a DCR table under the CPU. Instead introduce a little device model wrapper to hold a CPU link and handle registration of DCR handlers.
The DCR device inherits from SysBus because most of these devices also have a MMIO regions and/or IRQs. Being a SysBusDevice makes things
Drop "a", just "MMIO regions" due to plural. Also "makes it easier to install" or "makes things easier".
Quoted 24 lines
easier to install the device model in the overall SoC.
The "cpu" link should be considered as modeling the piece of HW logic connecting the device to the DCR bus.
Signed-off-by Cédric Le Goater <[email protected]>---
include/hw/ppc/ppc4xx.h| 17 +++++++++++++++hw/ppc/ppc4xx_devs.c| 46 +++++++++++++++++++++++++++++++++++++++++2 files changed, 63 insertions(+)include/hw/ppc/ppc4xx.h +1
-0@@ -27,6 +27,7 @@#include "hw/ppc/ppc.h" #include "exec/memory.h" +#include "hw/sysbus.h" /* PowerPC 4xx core initialization */ void ppc4xx_reset (void *opaque);
include/hw/ppc/ppc4xx.h void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum, · line 57
Quoted 7 lines
include/hw/ppc/ppc4xx.h +4
-0@@ -50,4 +51,20 @@ void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum,#define TYPE_PPC4xx_PCI_HOST_BRIDGE "ppc4xx-pcihost" +/* +* Generic DCR device +*/ +#define TYPE_PPC4xx_DCR_DEVICE "ppc4xx-dcr"
Should it be named ppc4xx-dcr-device for clarity? This probably won't appear anywhere where users have to type it.
Quoted 43 lines
include/hw/ppc/ppc4xx.h +12
-0+OBJECT_DECLARE_SIMPLE_TYPE (Ppc4xxDcrDeviceState, PPC4xx_DCR_DEVICE); +struct Ppc4xxDcrDeviceState { +SysBusDevice parent_obj; + +PowerPCCPU *cpu; +}; + +void ppc4xx_dcr_register (Ppc4xxDcrDeviceState *dev,int dcrn, +dcr_read_cb dcr_read,dcr_write_cb dcr_write); +bool ppc4xx_dcr_realize (Ppc4xxDcrDeviceState *dev,PowerPCCPU *cpu, +Error **errp); +#endif /* PPC4XX_H */ hw/ppc/ppc4xx_devs.c +22
-0@@ -696,3 +696,49 @@ void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum, mal, &dcr_read_mal, &dcr_write_mal); } } + +void ppc4xx_dcr_register (Ppc4xxDcrDeviceState *dev,int dcrn, +dcr_read_cb dcr_read,dcr_write_cb dcr_write) +{ +CPUPPCState *env; + +assert (dev->cpu); + + env = &dev->cpu->env; + +ppc_dcr_register (env, dcrn, dev, dcr_read, dcr_write); +} + +bool ppc4xx_dcr_realize (Ppc4xxDcrDeviceState *dev,PowerPCCPU *cpu, +Error **errp) +{ +object_property_set_link (OBJECT (dev),"cpu" ,OBJECT (cpu), &error_abort); +return sysbus_realize (SYS_BUS_DEVICE (dev), errp); +} + + +static Property ppc4xx_dcr_properties[] = {
hw/ppc/ppc4xx_devs.c void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum, · line 730
Quoted 10 lines
hw/ppc/ppc4xx_devs.c +10
-0+DEFINE_PROP_LINK ("cpu" , Ppc4xxDcrDeviceState, cpu,TYPE_POWERPC_CPU , + PowerPCCPU *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void ppc4xx_dcr_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->user_creatable = false;
Should this be .abstract instead? We expect this to not be used directly but only via SoC devices which is what abstract is for AFAIK.
hw/ppc/ppc4xx_devs.c void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum, · line 740
Quoted 10 lines
hw/ppc/ppc4xx_devs.c +10
-0+device_class_set_props (dc, ppc4xx_dcr_properties); +} + +static const TypeInfo ppc4xx_types[] = { + { + .name = TYPE_PPC4xx_DCR_DEVICE, + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ppc4xxDcrDeviceState), + .class_init = ppc4xx_dcr_class_init, + .abstract = true,
Oh, it's abstract already. So does it also need user_creatable for an abstract class then? Maybe you can drop the user_creatable.
Regards,
BALATON Zoltan
Quoted 5 lines
hw/ppc/ppc4xx_devs.c +4
-0+ } +}; + +DEFINE_TYPES (ppc4xx_types)
Re: [PATCH v3 08/22] ppc/ppc4xx: Introduce a DCR device model
Quoted 41 lines · BALATON Zoltan
Quoted 5 lines · Cédric Le Goater
The Device Control Registers (DCR) of on-SoC devices are accessed by software through the use of the mtdcr and mfdcr instructions. These are converted in transactions on a side band bus, the DCR bus, which connects the on-SoC devices to the CPU.
Quoted 7 lines
Ideally, we should model these accesses with a DCR namespace and DCR memory regions but today the DCR handlers are installed in a DCR table under the CPU. Instead introduce a little device model wrapper to hold a CPU link and handle registration of DCR handlers.
The DCR device inherits from SysBus because most of these devices also have a MMIO regions and/or IRQs. Being a SysBusDevice makes things
Drop "a", just "MMIO regions" due to plural. Also "makes it easier to install" or "makes things easier".
Quoted 25 lines
easier to install the device model in the overall SoC.
The "cpu" link should be considered as modeling the piece of HW logic connecting the device to the DCR bus.
Signed-off-by Cédric Le Goater <[email protected]>---
include/hw/ppc/ppc4xx.h| 17 +++++++++++++++ hw/ppc/ppc4xx_devs.c | 46 +++++++++++++++++++++++++++++++++++++++++2 files changed, 63 insertions(+)include/hw/ppc/ppc4xx.h +1
-0@@ -27,6 +27,7 @@#include "hw/ppc/ppc.h" #include "exec/memory.h" +#include "hw/sysbus.h" /* PowerPC 4xx core initialization */ void ppc4xx_reset (void *opaque);@@ -50,4 +51,20 @@ void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum,
Quoted 8 lines
include/hw/ppc/ppc4xx.h void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum, · line 57
Quoted 6 lines
include/hw/ppc/ppc4xx.h +4
-0#define TYPE_PPC4xx_PCI_HOST_BRIDGE "ppc4xx-pcihost" +/* +* Generic DCR device +*/ +#define TYPE_PPC4xx_DCR_DEVICE "ppc4xx-dcr"Should it be named ppc4xx-dcr-device for clarity? This probably won't appear anywhere where users have to type it.
ok.
Quoted 58 lines
Quoted 44 lines
include/hw/ppc/ppc4xx.h +12
-0+OBJECT_DECLARE_SIMPLE_TYPE (Ppc4xxDcrDeviceState, PPC4xx_DCR_DEVICE); +struct Ppc4xxDcrDeviceState { + SysBusDevice parent_obj; + + PowerPCCPU *cpu; +}; + +void ppc4xx_dcr_register (Ppc4xxDcrDeviceState *dev,int dcrn, + dcr_read_cb dcr_read, dcr_write_cb dcr_write); +bool ppc4xx_dcr_realize (Ppc4xxDcrDeviceState *dev,PowerPCCPU *cpu, + Error **errp); +#endif /* PPC4XX_H */ hw/ppc/ppc4xx_devs.c +22
-0@@ -696,3 +696,49 @@ void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum, mal, &dcr_read_mal, &dcr_write_mal); } } + +void ppc4xx_dcr_register (Ppc4xxDcrDeviceState *dev,int dcrn, + dcr_read_cb dcr_read, dcr_write_cb dcr_write) +{ + CPUPPCState *env; + + assert(dev->cpu); + + env = &dev->cpu->env; + + ppc_dcr_register(env, dcrn, dev, dcr_read, dcr_write); +} + +bool ppc4xx_dcr_realize (Ppc4xxDcrDeviceState *dev,PowerPCCPU *cpu, + Error **errp) +{ + object_property_set_link(OBJECT(dev), "cpu", OBJECT(cpu), &error_abort); + return sysbus_realize(SYS_BUS_DEVICE(dev), errp); +} + + +static Property ppc4xx_dcr_properties[] = {hw/ppc/ppc4xx_devs.c void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum, · line 730
Quoted 10 lines
hw/ppc/ppc4xx_devs.c +10
-0+ DEFINE_PROP_LINK("cpu", Ppc4xxDcrDeviceState, cpu, TYPE_POWERPC_CPU, + PowerPCCPU *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void ppc4xx_dcr_class_init (ObjectClass *oc,void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->user_creatable = false;Should this be .abstract instead? We expect this to not be used directly but only via SoC devices which is what abstract is for AFAIK.
Quoted 12 lines
hw/ppc/ppc4xx_devs.c void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum, · line 740
Quoted 10 lines
hw/ppc/ppc4xx_devs.c +10
-0+ device_class_set_props(dc, ppc4xx_dcr_properties); +} + +static const TypeInfo ppc4xx_types[] = { + { + .name = TYPE_PPC4xx_DCR_DEVICE, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(Ppc4xxDcrDeviceState), + .class_init = ppc4xx_dcr_class_init, + .abstract = true,Oh, it's abstract already. So does it also need
user_creatablefor an abstract class then? Maybe you can drop theuser_creatable.
Indeed.
Thanks,
C.
Quoted 8 lines
Regards,
BALATON ZoltanQuoted 5 lines
hw/ppc/ppc4xx_devs.c +4
-0+ } +}; + +DEFINE_TYPES (ppc4xx_types)
PATCH v3 9/22 ppc/ppc405: QOM'ify CPC
In reply to Cédric Le GoaterThe OCM controller is currently modeled as a DCR device.
Now that all clock settings are handled at the CPC level, change the SoC "sys-clk" property to be an alias on the same property in the CPC model.
--- hw/ppc/ppc405.h | 35 ++++++++++++- hw/ppc/ppc405_uc.c | 122 +++++++++++++++++++-------------------------- 2 files changed, 86 insertions(+), 71 deletions(-)
hw/ppc/ppc405.h +34 -1
@@ -63,6 +63,39 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +#define TYPE_PPC405_CPC "ppc405-cpc" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405CpcState,PPC405_CPC ); + +enum { +PPC405EP_CPU_CLK =0 , +PPC405EP_PLB_CLK =1 , +PPC405EP_OPB_CLK =2 , +PPC405EP_EBC_CLK =3 , +PPC405EP_MAL_CLK =4 , +PPC405EP_PCI_CLK =5 , +PPC405EP_UART0_CLK =6 , +PPC405EP_UART1_CLK =7 , +PPC405EP_CLK_NB =8 , +}; + +struct Ppc405CpcState { +Ppc4xxDcrDeviceState parent_obj; + +uint32_t sysclk; +clk_setup_t clk_setup[PPC405EP_CLK_NB ]; +uint32_t boot; +uint32_t epctl; +uint32_t pllmr[2 ]; +uint32_t ucr; +uint32_t srr; +uint32_t jtagid; +uint32_t pci; +/* Clock and power management */ +uint32_t er; +uint32_t fr; +uint32_t sr; +}; +#define TYPE_PPC405_SOC "ppc405-soc"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405SoCState,PPC405_SOC );
@@ -78,9 +111,9 @@ struct Ppc405SoCState {MemoryRegion *dram_mr;hwaddr ram_size; -uint32_t sysclk;PowerPCCPU cpu;DeviceState *uic; +Ppc405CpcState cpc; };/* PowerPC 405 core */
hw/ppc/ppc405_uc.c +52 -70
205 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH v3 09/22] ppc/ppc405: QOM'ify CPC
Quoted 1 line · Cédric Le Goater
The OCM controller is currently modeled as a DCR device.
What's OCM? Did you mean CPC?
Quoted 109 lines
Now that all clock settings are handled at the CPC level, change the SoC "sys-clk" property to be an alias on the same property in the CPC model.
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h| 35 ++++++++++++-hw/ppc/ppc405_uc.c| 122 +++++++++++++++++++--------------------------2 files changed, 86 insertions(+), 71 deletions(-)hw/ppc/ppc405.h +34
-1@@ -63,6 +63,39 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +#define TYPE_PPC405_CPC "ppc405-cpc" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405CpcState,PPC405_CPC ); + +enum { +PPC405EP_CPU_CLK =0 , +PPC405EP_PLB_CLK =1 , +PPC405EP_OPB_CLK =2 , +PPC405EP_EBC_CLK =3 , +PPC405EP_MAL_CLK =4 , +PPC405EP_PCI_CLK =5 , +PPC405EP_UART0_CLK =6 , +PPC405EP_UART1_CLK =7 , +PPC405EP_CLK_NB =8 , +}; + +struct Ppc405CpcState { +Ppc4xxDcrDeviceState parent_obj; + +uint32_t sysclk; +clk_setup_t clk_setup[PPC405EP_CLK_NB ]; +uint32_t boot; +uint32_t epctl; +uint32_t pllmr[2 ]; +uint32_t ucr; +uint32_t srr; +uint32_t jtagid; +uint32_t pci; +/* Clock and power management */ +uint32_t er; +uint32_t fr; +uint32_t sr; +}; +#define TYPE_PPC405_SOC "ppc405-soc"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405SoCState,PPC405_SOC );@@ -78,9 +111,9 @@ struct Ppc405SoCState {MemoryRegion *dram_mr;hwaddr ram_size; -uint32_t sysclk;PowerPCCPU cpu;DeviceState *uic; +Ppc405CpcState cpc; };/* PowerPC 405 core */ hw/ppc/ppc405_uc.c +1
-30@@ -1178,36 +1178,7 @@ enum {#endif }; -enum { -PPC405EP_CPU_CLK =0 , -PPC405EP_PLB_CLK =1 , -PPC405EP_OPB_CLK =2 , -PPC405EP_EBC_CLK =3 , -PPC405EP_MAL_CLK =4 , -PPC405EP_PCI_CLK =5 , -PPC405EP_UART0_CLK =6 , -PPC405EP_UART1_CLK =7 , -PPC405EP_CLK_NB =8 , -}; - -typedef struct ppc405ep_cpc_t ppc405ep_cpc_t ; -struct ppc405ep_cpc_t { -uint32_t sysclk; -clk_setup_t clk_setup[PPC405EP_CLK_NB ]; -uint32_t boot; -uint32_t epctl; -uint32_t pllmr[2 ]; -uint32_t ucr; -uint32_t srr; -uint32_t jtagid; -uint32_t pci; -/* Clock and power management */ -uint32_t er; -uint32_t fr; -uint32_t sr; -}; - -static void ppc405ep_compute_clocks (ppc405ep_cpc_t *cpc) +static void ppc405ep_compute_clocks (Ppc405CpcState *cpc) {uint32_t CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk;uint32_t UART0_clk, UART1_clk;
hw/ppc/ppc405_uc.c static void ppc405ep_compute_clocks (ppc405ep_cpc_t *cpc) · line 1276
Quoted 5 lines
hw/ppc/ppc405_uc.c +1
-1@@ -1302,10 +1273,9 @@ static void ppc405ep_compute_clocks (ppc405ep_cpc_t *cpc)static uint32_t dcr_read_epcpc (void *opaque,int dcrn) { -ppc405ep_cpc_t *cpc; +Ppc405CpcState *cpc =PPC405_CPC (opaque);
I still think that these callbacks that are registered by the realize method with an already checked opaque pointer don't need to check it again here so I'd drop the QOM casts from all these callbacks and assign opaque directly. Only cast where needed (you're passed a DeviceState, wtc.). But now that you've introduced ppc4xx_dcr_register it is passed a DcrDevice as it registers the callbacks with itself. That's wrong, the scr callbacks could have any opaque data so ppc4xx_dcr_register() should have an opaque argument (where you pass cpc uin this patch) then drop these casts. Same for all later patches.
Quoted 35 lines
hw/ppc/ppc405_uc.c +4
-5uint32_t ret; - cpc = opaque;switch (dcrn) {case PPC405EP_CPC0_BOOT : ret = cpc->boot;@@ -1342,9 +1312,8 @@ static uint32_t dcr_read_epcpc (void *opaque, int dcrn)static void dcr_write_epcpc (void *opaque,int dcrn,uint32_t val) { -ppc405ep_cpc_t *cpc; +Ppc405CpcState *cpc =PPC405_CPC (opaque); - cpc = opaque;switch (dcrn) {case PPC405EP_CPC0_BOOT :/* Read-only register */ @@ -1377,9 +1346,9 @@ static void dcr_write_epcpc (void *opaque, int dcrn, uint32_t val) } } -static void ppc405ep_cpc_reset (void *opaque) +static void ppc405_cpc_reset (DeviceState *opaque) { -ppc405ep_cpc_t *cpc = opaque; +Ppc405CpcState *cpc =PPC405_CPC (opaque); cpc->boot =0x00000010 ;/* Boot from PCI - IIC EEPROM disabled */ cpc->epctl =0x00000000 ;@@ -1391,45 +1360,56 @@ static void ppc405ep_cpc_reset (void *opaque) cpc->er =0x00000000 ; cpc->fr =0x00000000 ; cpc->sr =0x00000000 ; + cpc->jtagid =0x20267049 ;ppc405ep_compute_clocks (cpc);
hw/ppc/ppc405_uc.c static void ppc405ep_cpc_reset (void *opaque) · line 1371
Quoted 10 lines
hw/ppc/ppc405_uc.c +3
-3}/* XXX: sysclk should be between 25 and 100 MHz */ -static void ppc405ep_cpc_init (CPUPPCState *env,clk_setup_t clk_setup[8 ], -uint32_t sysclk) +static void ppc405_cpc_realize (DeviceState *dev,Error **errp) { -ppc405ep_cpc_t *cpc; +Ppc405CpcState *cpc =PPC405_CPC (dev); +Ppc4xxDcrDeviceState *dcr =PPC4xx_DCR_DEVICE (dev);
Only these casts are enough to check the object as it's only passed on from this point.
Quoted 6 lines
hw/ppc/ppc405_uc.c +1
-4+CPUPPCState *env; - cpc =g_new0 (ppc405ep_cpc_t,1 ); -memcpy (cpc->clk_setup, clk_setup, -PPC405EP_CLK_NB *sizeof (clk_setup_t)); - cpc->jtagid =0x20267049 ;
hw/ppc/ppc405_uc.c static void ppc405ep_cpc_reset (void *opaque) · line 1374
Quoted 10 lines
hw/ppc/ppc405_uc.c +1
-9- cpc->sysclk = sysclk; -qemu_register_reset (&ppc405ep_cpc_reset, cpc); -ppc_dcr_register (env,PPC405EP_CPC0_BOOT , cpc, - &dcr_read_epcpc, &dcr_write_epcpc); -ppc_dcr_register (env,PPC405EP_CPC0_EPCTL , cpc, - &dcr_read_epcpc, &dcr_write_epcpc); -ppc_dcr_register (env,PPC405EP_CPC0_PLLMR0 , cpc, - &dcr_read_epcpc, &dcr_write_epcpc); - ppc_dcr_register(env, PPC405EP_CPC0_PLLMR1, cpc, +assert (dcr->cpu);
So if you move this to the end you can drop this assert. Also env may not be needed any more now that it only apears twice.
Regards,
BALATON Zoltan
Quoted 110 lines
hw/ppc/ppc405_uc.c +41
-18+ + env = &dcr->cpu->env; + + cpc->clk_setup[PPC405EP_CPU_CLK ].cb = +ppc_40x_timers_init (env, cpc->sysclk,PPC_INTERRUPT_PIT ); + cpc->clk_setup[PPC405EP_CPU_CLK ].opaque = env; + +ppc4xx_dcr_register (dcr,PPC405EP_CPC0_BOOT , &dcr_read_epcpc, &dcr_write_epcpc); -ppc_dcr_register (env,PPC405EP_CPC0_UCR , cpc, +ppc4xx_dcr_register (dcr,PPC405EP_CPC0_EPCTL , &dcr_read_epcpc, &dcr_write_epcpc); -ppc_dcr_register (env,PPC405EP_CPC0_SRR , cpc, +ppc4xx_dcr_register (dcr,PPC405EP_CPC0_PLLMR0 , &dcr_read_epcpc, &dcr_write_epcpc); -ppc_dcr_register (env,PPC405EP_CPC0_JTAGID , cpc, +ppc4xx_dcr_register (dcr,PPC405EP_CPC0_PLLMR1 , &dcr_read_epcpc, &dcr_write_epcpc); -ppc_dcr_register (env,PPC405EP_CPC0_PCI , cpc, +ppc4xx_dcr_register (dcr,PPC405EP_CPC0_UCR , &dcr_read_epcpc, &dcr_write_epcpc); -#if 0 -ppc_dcr_register (env,PPC405EP_CPC0_ER , cpc, +ppc4xx_dcr_register (dcr,PPC405EP_CPC0_SRR , &dcr_read_epcpc, &dcr_write_epcpc); -ppc_dcr_register (env,PPC405EP_CPC0_FR , cpc, +ppc4xx_dcr_register (dcr,PPC405EP_CPC0_JTAGID , &dcr_read_epcpc, &dcr_write_epcpc); -ppc_dcr_register (env,PPC405EP_CPC0_SR , cpc, +ppc4xx_dcr_register (dcr,PPC405EP_CPC0_PCI , &dcr_read_epcpc, &dcr_write_epcpc); -#endif +} + +static Property ppc405_cpc_properties[] = { +DEFINE_PROP_UINT32 ("sys-clk" , Ppc405CpcState, sysclk,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void ppc405_cpc_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = ppc405_cpc_realize; + dc->user_creatable = false; +device_class_set_props (dc, ppc405_cpc_properties); + dc->reset = ppc405_cpc_reset; }static void ppc405_soc_instance_init (Object *obj)@@ -1438,17 +1418,17 @@ static void ppc405_soc_instance_init(Object *obj)object_initialize_child (obj,"cpu" , &s->cpu,POWERPC_CPU_TYPE_NAME ("405ep" )); + +object_initialize_child (obj,"cpc" , &s->cpc,TYPE_PPC405_CPC ); +object_property_add_alias (obj,"sys-clk" ,OBJECT (&s->cpc),"sys-clk" ); }static void ppc405_soc_realize (DeviceState *dev,Error **errp) {Ppc405SoCState *s =PPC405_SOC (dev); -clk_setup_t clk_setup[PPC405EP_CLK_NB ];qemu_irq dma_irqs[4 ], gpt_irqs[5 ], mal_irqs[4 ];CPUPPCState *env; -memset (clk_setup,0 ,sizeof (clk_setup)); -/* init CPUs */ if (!qdev_realize (DEVICE (&s->cpu),NULL , errp)) {return ;@@ -1457,14 +1437,12 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp) env = &s->cpu.env; - clk_setup[PPC405EP_CPU_CLK ].cb = -ppc_40x_timers_init (env, s->sysclk,PPC_INTERRUPT_PIT ); - clk_setup[PPC405EP_CPU_CLK ].opaque = env; -ppc_dcr_init (env,NULL ,NULL );/* CPU control */ -ppc405ep_cpc_init (env, clk_setup, s->sysclk); +if (!ppc4xx_dcr_realize (PPC4xx_DCR_DEVICE (&s->cpc), &s->cpu, errp)) { +return ; + }/* PLB arbitrer */ ppc4xx_plb_init (env);@@ -1556,7 +1534,6 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)static Property ppc405_soc_properties[] = {DEFINE_PROP_LINK ("dram" , Ppc405SoCState, dram_mr,TYPE_MEMORY_REGION , MemoryRegion *), -DEFINE_PROP_UINT32 ("sys-clk" , Ppc405SoCState, sysclk,0 ),DEFINE_PROP_BOOL ("dram-init" , Ppc405SoCState, do_dram_init,0 ),DEFINE_PROP_UINT64 ("ram-size" , Ppc405SoCState, ram_size,0 ),DEFINE_PROP_END_OF_LIST (),@@ -1573,6 +1550,11 @@ static void ppc405_soc_class_init(ObjectClass *oc, void *data)static const TypeInfo ppc405_types[] = { { + .name =TYPE_PPC405_CPC , + .parent = TYPE_PPC4xx_DCR_DEVICE, + .instance_size =sizeof (Ppc405CpcState), + .class_init = ppc405_cpc_class_init, + }, { .name =TYPE_PPC405_SOC , .parent =TYPE_DEVICE , .instance_size =sizeof (Ppc405SoCState),
PATCH v3 10/22 ppc/ppc405: QOM'ify GPT
In reply to Cédric Le GoaterThe GPT controller is currently modeled as a SysBus device with a unique memory region, a couple of IRQs and a timer.
--- hw/ppc/ppc405.h | 22 ++++++++++++ hw/ppc/ppc405_uc.c | 90 +++++++++++++++++++++++----------------------- 2 files changed, 67 insertions(+), 45 deletions(-)
hw/ppc/ppc405.h +22 -0
@@ -63,6 +63,27 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* General purpose timers */ +#define TYPE_PPC405_GPT "ppc405-gpt" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405GptState,PPC405_GPT ); +struct Ppc405GptState { +SysBusDevice parent_obj; + +MemoryRegion iomem; + +int64_t tb_offset; +uint32_t tb_freq; +QEMUTimer *timer; +qemu_irq irqs[5 ]; +uint32_t oe; +uint32_t ol; +uint32_t im; +uint32_t is; +uint32_t ie; +uint32_t comp[5 ]; +uint32_t mask[5 ]; +}; +#define TYPE_PPC405_CPC "ppc405-cpc"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405CpcState,PPC405_CPC );
@@ -114,6 +135,7 @@ struct Ppc405SoCState {PowerPCCPU cpu;DeviceState *uic;Ppc405CpcState cpc; +Ppc405GptState gpt; };/* PowerPC 405 core */
hw/ppc/ppc405_uc.c +45 -45
179 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH v3 10/22] ppc/ppc405: QOM'ify GPT
Quoted 154 lines · Cédric Le Goater
The GPT controller is currently modeled as a SysBus device with a unique memory region, a couple of IRQs and a timer.
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h| 22 ++++++++++++hw/ppc/ppc405_uc.c| 90 +++++++++++++++++++++++-----------------------2 files changed, 67 insertions(+), 45 deletions(-)hw/ppc/ppc405.h +22
-0@@ -63,6 +63,27 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* General purpose timers */ +#define TYPE_PPC405_GPT "ppc405-gpt" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405GptState,PPC405_GPT ); +struct Ppc405GptState { +SysBusDevice parent_obj; + +MemoryRegion iomem; + +int64_t tb_offset; +uint32_t tb_freq; +QEMUTimer *timer; +qemu_irq irqs[5 ]; +uint32_t oe; +uint32_t ol; +uint32_t im; +uint32_t is; +uint32_t ie; +uint32_t comp[5 ]; +uint32_t mask[5 ]; +}; +#define TYPE_PPC405_CPC "ppc405-cpc"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405CpcState,PPC405_CPC );@@ -114,6 +135,7 @@ struct Ppc405SoCState {PowerPCCPU cpu;DeviceState *uic;Ppc405CpcState cpc; +Ppc405GptState gpt; };/* PowerPC 405 core */ hw/ppc/ppc405_uc.c +10
-28@@ -926,34 +926,18 @@ static void ppc405_ocm_init(CPUPPCState *env)/*****************************************************************************/ /* General purpose timers */ -typedef struct ppc4xx_gpt_t ppc4xx_gpt_t ; -struct ppc4xx_gpt_t { -MemoryRegion iomem; -int64_t tb_offset; -uint32_t tb_freq; -QEMUTimer *timer; -qemu_irq irqs[5 ]; -uint32_t oe; -uint32_t ol; -uint32_t im; -uint32_t is; -uint32_t ie; -uint32_t comp[5 ]; -uint32_t mask[5 ]; -}; - -static int ppc4xx_gpt_compare (ppc4xx_gpt_t *gpt,int n) +static int ppc4xx_gpt_compare (Ppc405GptState *gpt,int n) {/* XXX: TODO */ return 0 ; } -static void ppc4xx_gpt_set_output (ppc4xx_gpt_t *gpt,int n,int level) +static void ppc4xx_gpt_set_output (Ppc405GptState *gpt,int n,int level) {/* XXX: TODO */ } -static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t *gpt) +static void ppc4xx_gpt_set_outputs (Ppc405GptState *gpt) {uint32_t mask;int i;@@ -974,7 +958,7 @@ static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t *gpt) } } -static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t *gpt) +static void ppc4xx_gpt_set_irqs (Ppc405GptState *gpt) {uint32_t mask;int i;@@ -989,14 +973,14 @@ static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t *gpt) } } -static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t *gpt) +static void ppc4xx_gpt_compute_timer (Ppc405GptState *gpt) {/* XXX: TODO */ }static uint64_t ppc4xx_gpt_read (void *opaque,hwaddr addr,unsigned size) { -ppc4xx_gpt_t *gpt = opaque; +Ppc405GptState *gpt =PPC405_GPT (opaque);uint32_t ret;int idx;@@ -1050,7 +1034,7 @@ static uint64_t ppc4xx_gpt_read(void *opaque, hwaddr addr, unsigned size)static void ppc4xx_gpt_write (void *opaque,hwaddr addr,uint64_t value,unsigned size) { -ppc4xx_gpt_t *gpt = opaque; +Ppc405GptState *gpt =PPC405_GPT (opaque);int idx;trace_ppc4xx_gpt_write (addr, size, value);@@ -1116,20 +1100,18 @@ static const MemoryRegionOps gpt_ops = {static void ppc4xx_gpt_cb (void *opaque) { -ppc4xx_gpt_t *gpt; +Ppc405GptState *gpt =PPC405_GPT (opaque); - gpt = opaque;ppc4xx_gpt_set_irqs (gpt);ppc4xx_gpt_set_outputs (gpt);ppc4xx_gpt_compute_timer (gpt); } -static void ppc4xx_gpt_reset (void *opaque) +static void ppc405_gpt_reset (DeviceState *dev) { -ppc4xx_gpt_t *gpt; +Ppc405GptState *gpt =PPC405_GPT (dev);int i; - gpt = opaque;timer_del (gpt->timer); gpt->oe =0x00000000 ; gpt->ol =0x00000000 ;@@ -1142,21 +1124,28 @@ static void ppc4xx_gpt_reset (void *opaque) } }
hw/ppc/ppc405_uc.c static void ppc4xx_gpt_reset (void *opaque) · line 1150
Quoted 10 lines
hw/ppc/ppc405_uc.c +3
-3-static void ppc4xx_gpt_init (hwaddr base,qemu_irq irqs[5 ]) +static void ppc405_gpt_realize (DeviceState *dev,Error **errp) { -ppc4xx_gpt_t *gpt; +Ppc405GptState *s =PPC405_GPT (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev);int i; -trace_ppc4xx_gpt_init (base);
Where has this trace gone? If you've dropped it then you should also drop it from trace-events.
Quoted 52 lines
hw/ppc/ppc405_uc.c +18
-12+ s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , &ppc4xx_gpt_cb, s); +memory_region_init_io (&s->iomem,OBJECT (s), &gpt_ops, s,"gpt" ,0x0d4 ); +sysbus_init_mmio (sbd, &s->iomem); - gpt =g_new0 (ppc4xx_gpt_t,1 ); -for (i =0 ; i <5 ; i++) { - gpt->irqs[i] = irqs[i]; +for (i =0 ; i <ARRAY_SIZE (s->irqs); i++) { +sysbus_init_irq (sbd, &s->irqs[i]); } - gpt->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , &ppc4xx_gpt_cb, gpt); -memory_region_init_io (&gpt->iomem,NULL , &gpt_ops, gpt,"gpt" ,0x0d4 ); -memory_region_add_subregion (get_system_memory (), base, &gpt->iomem); -qemu_register_reset (ppc4xx_gpt_reset, gpt); +} + +static void ppc405_gpt_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = ppc405_gpt_realize; + dc->user_creatable = false; + dc->reset = ppc405_gpt_reset; }/*****************************************************************************/ @@ -1421,13 +1410,16 @@ static void ppc405_soc_instance_init(Object *obj)object_initialize_child (obj,"cpc" , &s->cpc,TYPE_PPC405_CPC );object_property_add_alias (obj,"sys-clk" ,OBJECT (&s->cpc),"sys-clk" ); + +object_initialize_child (obj,"gpt" , &s->gpt,TYPE_PPC405_GPT ); }static void ppc405_soc_realize (DeviceState *dev,Error **errp) {Ppc405SoCState *s =PPC405_SOC (dev); -qemu_irq dma_irqs[4 ], gpt_irqs[5 ], mal_irqs[4 ]; +qemu_irq dma_irqs[4 ], mal_irqs[4 ];CPUPPCState *env; +int i;/* init CPUs */ if (!qdev_realize (DEVICE (&s->cpu),NULL , errp)) {@@ -1513,12 +1505,15 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)ppc405_ocm_init (env);/* GPT */ - gpt_irqs[0 ] =qdev_get_gpio_in (s->uic,19 ); - gpt_irqs[1 ] =qdev_get_gpio_in (s->uic,20 ); - gpt_irqs[2 ] =qdev_get_gpio_in (s->uic,21 ); - gpt_irqs[3 ] =qdev_get_gpio_in (s->uic,22 );
hw/ppc/ppc405_uc.c static void ppc405_soc_realize(DeviceState *dev, Error **errp) · line 1515
Quoted 10 lines
hw/ppc/ppc405_uc.c +8
-2- gpt_irqs[4 ] =qdev_get_gpio_in (s->uic,23 ); -ppc4xx_gpt_init (0xef600000 , gpt_irqs); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->gpt), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gpt),0 ,0xef600000 ); + +for (i =0 ; i <ARRAY_SIZE (s->gpt.irqs); i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gpt), i, +qdev_get_gpio_in (s->uic,19 + i));
Maybe you should have a SysBusDevice *sbd local here and cast only once if you need it several times. It's also more readable that way.
Regards,
BALATON Zoltan
Quoted 17 lines
hw/ppc/ppc405_uc.c +6
-0+ }/* MAL */ mal_irqs[0 ] =qdev_get_gpio_in (s->uic,11 );@@ -1550,6 +1545,11 @@ static void ppc405_soc_class_init(ObjectClass *oc, void *data)static const TypeInfo ppc405_types[] = { { + .name =TYPE_PPC405_GPT , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ppc405GptState), + .class_init = ppc405_gpt_class_init, + }, { .name =TYPE_PPC405_CPC , .parent = TYPE_PPC4xx_DCR_DEVICE, .instance_size =sizeof (Ppc405CpcState),
PATCH v3 11/22 ppc/ppc405: QOM'ify OCM
In reply to Cédric Le GoaterThe OCM controller is currently modeled as a simple DCR device with a couple of memory regions.
--- hw/ppc/ppc405.h | 16 +++++++++++ hw/ppc/ppc405_uc.c | 72 +++++++++++++++++++++++----------------------- 2 files changed, 52 insertions(+), 36 deletions(-)
hw/ppc/ppc405.h +16 -0
@@ -63,6 +63,21 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* On Chip Memory */ +#define TYPE_PPC405_OCM "ppc405-ocm" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405OcmState,PPC405_OCM ); +struct Ppc405OcmState { +Ppc4xxDcrDeviceState parent_obj; + +MemoryRegion ram; +MemoryRegion isarc_ram; +MemoryRegion dsarc_ram; +uint32_t isarc; +uint32_t isacntl; +uint32_t dsarc; +uint32_t dsacntl; +}; +/* General purpose timers */ #define TYPE_PPC405_GPT "ppc405-gpt"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405GptState,PPC405_GPT );
@@ -136,6 +151,7 @@ struct Ppc405SoCState {DeviceState *uic;Ppc405CpcState cpc;Ppc405GptState gpt; +Ppc405OcmState ocm; };/* PowerPC 405 core */
hw/ppc/ppc405_uc.c +36 -36
132 lines not on this page · raw message
Signature · 1 line
2.37.1
PATCH v3 12/22 ppc/ppc405: QOM'ify GPIO
In reply to Cédric Le GoaterThe GPIO controller is currently modeled as a simple SysBus device with a unique memory region.
--- hw/ppc/ppc405.h | 21 +++++++++++++++++++ hw/ppc/ppc405_uc.c | 50 +++++++++++++++++++++------------------------- 2 files changed, 44 insertions(+), 27 deletions(-)
hw/ppc/ppc405.h +21 -0
@@ -63,6 +63,26 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* GPIO */ +#define TYPE_PPC405_GPIO "ppc405-gpio" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405GpioState,PPC405_GPIO ); +struct Ppc405GpioState { +SysBusDevice parent_obj; + +MemoryRegion io; +uint32_t or; +uint32_t tcr; +uint32_t osrh; +uint32_t osrl; +uint32_t tsrh; +uint32_t tsrl; +uint32_t odr; +uint32_t ir; +uint32_t rr1; +uint32_t isr1h; +uint32_t isr1l; +}; +/* On Chip Memory */ #define TYPE_PPC405_OCM "ppc405-ocm"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405OcmState,PPC405_OCM );
@@ -152,6 +172,7 @@ struct Ppc405SoCState {Ppc405CpcState cpc;Ppc405GptState gpt;Ppc405OcmState ocm; +Ppc405GpioState gpio; };/* PowerPC 405 core */
hw/ppc/ppc405_uc.c +23 -27
86 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH v3 12/22] ppc/ppc405: QOM'ify GPIO
Quoted 88 lines · Cédric Le Goater
The GPIO controller is currently modeled as a simple SysBus device with a unique memory region.
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h| 21 +++++++++++++++++++hw/ppc/ppc405_uc.c| 50 +++++++++++++++++++++-------------------------2 files changed, 44 insertions(+), 27 deletions(-)hw/ppc/ppc405.h +21
-0@@ -63,6 +63,26 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* GPIO */ +#define TYPE_PPC405_GPIO "ppc405-gpio" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405GpioState,PPC405_GPIO ); +struct Ppc405GpioState { +SysBusDevice parent_obj; + +MemoryRegion io; +uint32_t or; +uint32_t tcr; +uint32_t osrh; +uint32_t osrl; +uint32_t tsrh; +uint32_t tsrl; +uint32_t odr; +uint32_t ir; +uint32_t rr1; +uint32_t isr1h; +uint32_t isr1l; +}; +/* On Chip Memory */ #define TYPE_PPC405_OCM "ppc405-ocm"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405OcmState,PPC405_OCM );@@ -152,6 +172,7 @@ struct Ppc405SoCState {Ppc405CpcState cpc;Ppc405GptState gpt;Ppc405OcmState ocm; +Ppc405GpioState gpio; };/* PowerPC 405 core */ hw/ppc/ppc405_uc.c +5
-18@@ -713,23 +713,6 @@ static void ppc405_dma_init(CPUPPCState *env, qemu_irq irqs[4]) }/*****************************************************************************/ -/* GPIO */ -typedef struct ppc405_gpio_t ppc405_gpio_t ; -struct ppc405_gpio_t { -MemoryRegion io; -uint32_t or; -uint32_t tcr; -uint32_t osrh; -uint32_t osrl; -uint32_t tsrh; -uint32_t tsrl; -uint32_t odr; -uint32_t ir; -uint32_t rr1; -uint32_t isr1h; -uint32_t isr1l; -}; -static uint64_t ppc405_gpio_read (void *opaque,hwaddr addr,unsigned size) {trace_ppc405_gpio_read (addr, size);@@ -748,20 +731,22 @@ static const MemoryRegionOps ppc405_gpio_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void ppc405_gpio_reset (void *opaque) +static void ppc405_gpio_realize (DeviceState *dev,Error **errp) { +Ppc405GpioState *s =PPC405_GPIO (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); + + memory_region_init_io(&s->io, OBJECT(s), &ppc405_gpio_ops, s, "gpio",
hw/ppc/ppc405_uc.c static const MemoryRegionOps ppc405_gpio_ops = { · line 759
Quoted 10 lines
hw/ppc/ppc405_uc.c +3
-4+ 0x038); +sysbus_init_mmio (sbd, &s->io); } -static void ppc405_gpio_init (hwaddr base) +static void ppc405_gpio_class_init (ObjectClass *oc,void *data) { -ppc405_gpio_t *gpio; - -trace_ppc405_gpio_init (base);
Trace gone, update trace-events too.
Quoted 47 lines
hw/ppc/ppc405_uc.c +15
-5+DeviceClass *dc =DEVICE_CLASS (oc); - gpio =g_new0 (ppc405_gpio_t,1 ); -memory_region_init_io (&gpio->io,NULL , &ppc405_gpio_ops, gpio,"pgio" ,0x038 ); -memory_region_add_subregion (get_system_memory (), base, &gpio->io); -qemu_register_reset (&ppc405_gpio_reset, gpio); + dc->realize = ppc405_gpio_realize; + dc->user_creatable = false; }/*****************************************************************************/ @@ -1405,6 +1390,8 @@ static void ppc405_soc_instance_init(Object *obj)object_initialize_child (obj,"gpt" , &s->gpt,TYPE_PPC405_GPT );object_initialize_child (obj,"ocm" , &s->ocm,TYPE_PPC405_OCM ); + +object_initialize_child (obj,"gpio" , &s->gpio,TYPE_PPC405_GPIO ); }static void ppc405_soc_realize (DeviceState *dev,Error **errp)@@ -1477,8 +1464,12 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)/* I2C controller */ sysbus_create_simple (TYPE_PPC4xx_I2C,0xef600500 ,qdev_get_gpio_in (s->uic,2 )); +/* GPIO */ -ppc405_gpio_init (0xef600700 ); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->gpio), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gpio),0 ,0xef600700 );/* Serial ports */ if (serial_hd (0 ) !=NULL ) {@@ -1540,6 +1531,11 @@ static void ppc405_soc_class_init(ObjectClass *oc, void *data)static const TypeInfo ppc405_types[] = { { + .name =TYPE_PPC405_GPIO , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ppc405GpioState), + .class_init = ppc405_gpio_class_init, + }, { .name =TYPE_PPC405_OCM , .parent = TYPE_PPC4xx_DCR_DEVICE, .instance_size =sizeof (Ppc405OcmState),
Re: [PATCH v3 12/22] ppc/ppc405: QOM'ify GPIO
Quoted 93 lines · BALATON Zoltan
Quoted 92 lines · Cédric Le Goater
The GPIO controller is currently modeled as a simple SysBus device with a unique memory region.
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h | 21 +++++++++++++++++++hw/ppc/ppc405_uc.c| 50 +++++++++++++++++++++-------------------------2 files changed, 44 insertions(+), 27 deletions(-)hw/ppc/ppc405.h +21
-0@@ -63,6 +63,26 @@ struct ppc4xx_bd_info_t { uint32_t bi_iic_fast[2]; }; +/* GPIO */ +#define TYPE_PPC405_GPIO "ppc405-gpio" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405GpioState,PPC405_GPIO ); +struct Ppc405GpioState { + SysBusDevice parent_obj; + + MemoryRegion io; + uint32_t or; + uint32_t tcr; + uint32_t osrh; + uint32_t osrl; + uint32_t tsrh; + uint32_t tsrl; + uint32_t odr; + uint32_t ir; + uint32_t rr1; + uint32_t isr1h; + uint32_t isr1l; +}; +/* On Chip Memory */ #define TYPE_PPC405_OCM "ppc405-ocm"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405OcmState,PPC405_OCM );@@ -152,6 +172,7 @@ struct Ppc405SoCState { Ppc405CpcState cpc; Ppc405GptState gpt; Ppc405OcmState ocm; + Ppc405GpioState gpio; };/* PowerPC 405 core */ hw/ppc/ppc405_uc.c +7
-18@@ -713,23 +713,6 @@ static void ppc405_dma_init(CPUPPCState *env, qemu_irq irqs[4]) }/*****************************************************************************/ -/* GPIO */ -typedef struct ppc405_gpio_t ppc405_gpio_t ; -struct ppc405_gpio_t { - MemoryRegion io; - uint32_t or; - uint32_t tcr; - uint32_t osrh; - uint32_t osrl; - uint32_t tsrh; - uint32_t tsrl; - uint32_t odr; - uint32_t ir; - uint32_t rr1; - uint32_t isr1h; - uint32_t isr1l; -}; -static uint64_t ppc405_gpio_read (void *opaque,hwaddr addr,unsigned size) { trace_ppc405_gpio_read(addr, size);@@ -748,20 +731,22 @@ static const MemoryRegionOps ppc405_gpio_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void ppc405_gpio_reset (void *opaque) +static void ppc405_gpio_realize (DeviceState *dev,Error **errp) { + Ppc405GpioState *s = PPC405_GPIO(dev); + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); + + memory_region_init_io(&s->io, OBJECT(s), &ppc405_gpio_ops, s, "gpio", + 0x038); + sysbus_init_mmio(sbd, &s->io); }
Quoted 8 lines
hw/ppc/ppc405_uc.c static const MemoryRegionOps ppc405_gpio_ops = { · line 759
Quoted 6 lines
hw/ppc/ppc405_uc.c +1
-4-static void ppc405_gpio_init (hwaddr base) +static void ppc405_gpio_class_init (ObjectClass *oc,void *data) { - ppc405_gpio_t *gpio; - - trace_ppc405_gpio_init(base);Trace gone, update trace-events too.
Yes. I have checked the others.
Thanks,
C.
Quoted 48 lines
Quoted 48 lines
hw/ppc/ppc405_uc.c +15
-5+ DeviceClass *dc = DEVICE_CLASS(oc); - gpio = g_new0(ppc405_gpio_t, 1); - memory_region_init_io(&gpio->io, NULL, &ppc405_gpio_ops, gpio, "pgio", 0x038); - memory_region_add_subregion(get_system_memory(), base, &gpio->io); - qemu_register_reset(&ppc405_gpio_reset, gpio); + dc->realize = ppc405_gpio_realize; + dc->user_creatable = false; }/*****************************************************************************/ @@ -1405,6 +1390,8 @@ static void ppc405_soc_instance_init(Object *obj) object_initialize_child(obj, "gpt", &s->gpt, TYPE_PPC405_GPT); object_initialize_child(obj, "ocm", &s->ocm, TYPE_PPC405_OCM); + + object_initialize_child(obj, "gpio", &s->gpio, TYPE_PPC405_GPIO); }static void ppc405_soc_realize (DeviceState *dev,Error **errp)@@ -1477,8 +1464,12 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp) /* I2C controller */ sysbus_create_simple(TYPE_PPC4xx_I2C, 0xef600500, qdev_get_gpio_in(s->uic, 2)); + /* GPIO */ - ppc405_gpio_init(0xef600700); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, 0xef600700); /* Serial ports */ if (serial_hd(0) != NULL) {@@ -1540,6 +1531,11 @@ static void ppc405_soc_class_init(ObjectClass *oc, void *data)static const TypeInfo ppc405_types[] = { { + .name = TYPE_PPC405_GPIO, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(Ppc405GpioState), + .class_init = ppc405_gpio_class_init, + }, { .name = TYPE_PPC405_OCM, .parent = TYPE_PPC4xx_DCR_DEVICE, .instance_size = sizeof(Ppc405OcmState),
PATCH v3 13/22 ppc/ppc405: QOM'ify DMA
In reply to Cédric Le GoaterThe GPIO controller is currently modeled as a DCR device with a couple of IRQs.
--- hw/ppc/ppc405.h | 19 ++++++ hw/ppc/ppc405_uc.c | 141 ++++++++++++++++++++------------------------- 2 files changed, 81 insertions(+), 79 deletions(-)
hw/ppc/ppc405.h +19 -0
@@ -63,6 +63,24 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* DMA controller */ +#define TYPE_PPC405_DMA "ppc405-dma" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405DmaState,PPC405_DMA ); +struct Ppc405DmaState { +Ppc4xxDcrDeviceState parent_obj; + +qemu_irq irqs[4 ]; +uint32_t cr[4 ]; +uint32_t ct[4 ]; +uint32_t da[4 ]; +uint32_t sa[4 ]; +uint32_t sg[4 ]; +uint32_t sr; +uint32_t sgc; +uint32_t slp; +uint32_t pol; +}; +/* GPIO */ #define TYPE_PPC405_GPIO "ppc405-gpio"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405GpioState,PPC405_GPIO );
@@ -173,6 +191,7 @@ struct Ppc405SoCState {Ppc405GptState gpt;Ppc405OcmState ocm;Ppc405GpioState gpio; +Ppc405DmaState dma; };/* PowerPC 405 core */
hw/ppc/ppc405_uc.c +62 -79
187 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH v3 13/22] ppc/ppc405: QOM'ify DMA
Quoted 1 line · Cédric Le Goater
The GPIO controller is currently modeled as a DCR device with a couple
It's the DMA already not the GPIU.
Regards,
BALATON Zoltan
Quoted 243 lines
of IRQs.
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h| 19 ++++++hw/ppc/ppc405_uc.c| 141 ++++++++++++++++++++-------------------------2 files changed, 81 insertions(+), 79 deletions(-)hw/ppc/ppc405.h +19
-0@@ -63,6 +63,24 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* DMA controller */ +#define TYPE_PPC405_DMA "ppc405-dma" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405DmaState,PPC405_DMA ); +struct Ppc405DmaState { +Ppc4xxDcrDeviceState parent_obj; + +qemu_irq irqs[4 ]; +uint32_t cr[4 ]; +uint32_t ct[4 ]; +uint32_t da[4 ]; +uint32_t sa[4 ]; +uint32_t sg[4 ]; +uint32_t sr; +uint32_t sgc; +uint32_t slp; +uint32_t pol; +}; +/* GPIO */ #define TYPE_PPC405_GPIO "ppc405-gpio"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405GpioState,PPC405_GPIO );@@ -173,6 +191,7 @@ struct Ppc405SoCState {Ppc405GptState gpt;Ppc405OcmState ocm;Ppc405GpioState gpio; +Ppc405DmaState dma; };/* PowerPC 405 core */ hw/ppc/ppc405_uc.c +62
-79@@ -613,35 +613,20 @@ enum { DMA0_POL = 0x126, }; -typedef struct ppc405_dma_t ppc405_dma_t ; -struct ppc405_dma_t { -qemu_irq irqs[4 ]; -uint32_t cr[4 ]; -uint32_t ct[4 ]; -uint32_t da[4 ]; -uint32_t sa[4 ]; -uint32_t sg[4 ]; -uint32_t sr; -uint32_t sgc; -uint32_t slp; -uint32_t pol; -}; - -static uint32_t dcr_read_dma (void *opaque,int dcrn) +static uint32_t dcr_read_dma (void *opaque,int dcrn) {return 0 ; } -static void dcr_write_dma (void *opaque,int dcrn,uint32_t val) +static void dcr_write_dma (void *opaque,int dcrn,uint32_t val) { } -static void ppc405_dma_reset (void *opaque) +static void ppc405_dma_reset (DeviceState *dev) { -ppc405_dma_t *dma; +Ppc405DmaState *dma =PPC405_DMA (dev);int i; - dma = opaque;for (i =0 ; i <4 ; i++) { dma->cr[i] =0x00000000 ; dma->ct[i] =0x00000000 ;@@ -655,61 +640,49 @@ static void ppc405_dma_reset (void *opaque) dma->pol =0x00000000 ; } -static void ppc405_dma_init (CPUPPCState *env,qemu_irq irqs[4 ]) +static void ppc405_dma_realize (DeviceState *dev,Error **errp) +{ +Ppc405DmaState *dma =PPC405_DMA (dev); +Ppc4xxDcrDeviceState *dcr =PPC4xx_DCR_DEVICE (dev); +int i; + +for (i =0 ; i <ARRAY_SIZE (dma->irqs); i++) { +sysbus_init_irq (SYS_BUS_DEVICE (dma), &dma->irqs[i]); + } + +ppc4xx_dcr_register (dcr,DMA0_CR0 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_CT0 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_DA0 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SA0 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SG0 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_CR1 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_CT1 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_DA1 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SA1 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SG1 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_CR2 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_CT2 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_DA2 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SA2 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SG2 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_CR3 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_CT3 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_DA3 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SA3 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SG3 , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SR , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SGC , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_SLP , &dcr_read_dma, &dcr_write_dma); +ppc4xx_dcr_register (dcr,DMA0_POL , &dcr_read_dma, &dcr_write_dma); +} + +static void ppc405_dma_class_init (ObjectClass *oc,void *data) { -ppc405_dma_t *dma; - - dma =g_new0 (ppc405_dma_t,1 ); -memcpy (dma->irqs, irqs,4 *sizeof (qemu_irq)); -qemu_register_reset (&ppc405_dma_reset, dma); -ppc_dcr_register (env,DMA0_CR0 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_CT0 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_DA0 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SA0 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SG0 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_CR1 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_CT1 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_DA1 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SA1 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SG1 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_CR2 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_CT2 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_DA2 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SA2 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SG2 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_CR3 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_CT3 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_DA3 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SA3 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SG3 , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SR , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SGC , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_SLP , - dma, &dcr_read_dma, &dcr_write_dma); -ppc_dcr_register (env,DMA0_POL , - dma, &dcr_read_dma, &dcr_write_dma); +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = ppc405_dma_realize; + dc->user_creatable = false; + dc->reset = ppc405_dma_reset; }/*****************************************************************************/ @@ -1392,12 +1365,14 @@ static void ppc405_soc_instance_init(Object *obj)object_initialize_child (obj,"ocm" , &s->ocm,TYPE_PPC405_OCM );object_initialize_child (obj,"gpio" , &s->gpio,TYPE_PPC405_GPIO ); + +object_initialize_child (obj,"dma" , &s->dma,TYPE_PPC405_DMA ); }static void ppc405_soc_realize (DeviceState *dev,Error **errp) {Ppc405SoCState *s =PPC405_SOC (dev); -qemu_irq dma_irqs[4 ], mal_irqs[4 ]; +qemu_irq mal_irqs[4 ];CPUPPCState *env;int i;@@ -1455,11 +1430,14 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)ppc405_ebc_init (env);/* DMA controller */ - dma_irqs[0 ] =qdev_get_gpio_in (s->uic,5 ); - dma_irqs[1 ] =qdev_get_gpio_in (s->uic,6 ); - dma_irqs[2 ] =qdev_get_gpio_in (s->uic,7 ); - dma_irqs[3 ] =qdev_get_gpio_in (s->uic,8 ); -ppc405_dma_init (env, dma_irqs); +if (!ppc4xx_dcr_realize (PPC4xx_DCR_DEVICE (&s->dma), &s->cpu, errp)) { +return ; + } + +for (i =0 ; i <ARRAY_SIZE (s->dma.irqs); i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (&s->dma), i, +qdev_get_gpio_in (s->uic,5 + i)); + }/* I2C controller */ sysbus_create_simple(TYPE_PPC4xx_I2C, 0xef600500,@@ -1531,6 +1509,11 @@ static void ppc405_soc_class_init(ObjectClass *oc, void *data)static const TypeInfo ppc405_types[] = { { + .name =TYPE_PPC405_DMA , + .parent = TYPE_PPC4xx_DCR_DEVICE, + .instance_size =sizeof (Ppc405DmaState), + .class_init = ppc405_dma_class_init, + }, { .name =TYPE_PPC405_GPIO , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (Ppc405GpioState),
PATCH v3 14/22 ppc/ppc405: QOM'ify EBC
In reply to Cédric Le GoaterEBC is currently modeled as a DCR device. Also drop the ppc405_ebc_init() helper and adapt the sam460ex machine.
--- hw/ppc/ppc405.h | 17 +++++++++++++- hw/ppc/ppc405_uc.c | 56 +++++++++++++++++++++++----------------------- hw/ppc/sam460ex.c | 4 +++- 3 files changed, 47 insertions(+), 30 deletions(-)
hw/ppc/ppc405.h +16 -1
@@ -63,6 +63,21 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* Peripheral controller */ +#define TYPE_PPC405_EBC "ppc405-ebc" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405EbcState,PPC405_EBC ); +struct Ppc405EbcState { +Ppc4xxDcrDeviceState parent_obj; + +uint32_t addr; +uint32_t bcr[8 ]; +uint32_t bap[8 ]; +uint32_t bear; +uint32_t besr0; +uint32_t besr1; +uint32_t cfg; +}; +/* DMA controller */ #define TYPE_PPC405_DMA "ppc405-dma"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405DmaState,PPC405_DMA );
@@ -192,12 +207,12 @@ struct Ppc405SoCState {Ppc405OcmState ocm;Ppc405GpioState gpio;Ppc405DmaState dma; + Ppc405EbcState ebc; };/* PowerPC 405 core */ ram_addr_t ppc405_set_bootinfo (CPUPPCState *env,ram_addr_t ram_size);void ppc4xx_plb_init (CPUPPCState *env); -void ppc405_ebc_init (CPUPPCState *env);#endif /* PPC405_H */
hw/ppc/ppc405_uc.c +28 -28
111 lines not on this page · raw message
hw/ppc/sam460ex.c +3 -1
@@ -371,7 +371,9 @@ static void sam460ex_init(MachineState *machine) qdev_get_gpio_in(uic[0], 3));/* External bus controller */ -ppc405_ebc_init (env); + dev =qdev_new (TYPE_PPC405_EBC ); +ppc4xx_dcr_realize (PPC4xx_DCR_DEVICE (dev), cpu, &error_fatal); +object_unref (OBJECT (dev));/* CPR */ ppc4xx_cpr_init (env);
Signature · 1 line
2.37.1
PATCH v3 15/22 ppc/ppc405: QOM'ify OPBA
In reply to Cédric Le GoaterThe OPB arbitrer is currently modeled as a simple SysBus device with a unique memory region.
--- hw/ppc/ppc405.h | 12 ++++++++++++ hw/ppc/ppc405_uc.c | 47 +++++++++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 19 deletions(-)
hw/ppc/ppc405.h +12 -0
@@ -63,6 +63,17 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* OPB arbitrer */ +#define TYPE_PPC405_OPBA "ppc405-opba" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405OpbaState,PPC405_OPBA ); +struct Ppc405OpbaState { +SysBusDevice parent_obj; + +MemoryRegion io; +uint8_t cr; +uint8_t pr; +}; +/* Peripheral controller */ #define TYPE_PPC405_EBC "ppc405-ebc"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405EbcState,PPC405_EBC );
@@ -208,6 +219,7 @@ struct Ppc405SoCState {Ppc405GpioState gpio;Ppc405DmaState dma;Ppc405EbcState ebc; +Ppc405OpbaState opba; };/* PowerPC 405 core */
hw/ppc/ppc405_uc.c +28 -19
95 lines not on this page · raw message
Signature · 1 line
2.37.1
PATCH v3 16/22 ppc/ppc405: QOM'ify POB
In reply to Cédric Le GoaterPOB is currently modeled as a simple DCR device.
--- hw/ppc/ppc405.h | 12 +++++++++++ hw/ppc/ppc405_uc.c | 50 ++++++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 22 deletions(-)
hw/ppc/ppc405.h +12 -0
@@ -63,6 +63,17 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* PLB to OPB bridge */ +#define TYPE_PPC405_POB "ppc405-pob" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405PobState,PPC405_POB ); +struct Ppc405PobState { +Ppc4xxDcrDeviceState parent_obj; + +uint32_t bear; +uint32_t besr0; +uint32_t besr1; +}; +/* OPB arbitrer */ #define TYPE_PPC405_OPBA "ppc405-opba"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405OpbaState,PPC405_OPBA );
@@ -220,6 +231,7 @@ struct Ppc405SoCState {Ppc405DmaState dma;Ppc405EbcState ebc;Ppc405OpbaState opba; +Ppc405PobState pob; };/* PowerPC 405 core */
hw/ppc/ppc405_uc.c +28 -22
101 lines not on this page · raw message
Signature · 1 line
2.37.1
PATCH v3 17/22 ppc/ppc405: QOM'ify PLB
In reply to Cédric Le GoaterPLB is currently modeled as a simple DCR device. Also drop the ppc4xx_plb_init() helper and adapt the sam460ex machine.
--- hw/ppc/ppc405.h | 14 +++++++++-- hw/ppc/ppc405_uc.c | 58 +++++++++++++++++++++++++--------------------- hw/ppc/sam460ex.c | 4 +++- 3 files changed, 47 insertions(+), 29 deletions(-)
hw/ppc/ppc405.h +12 -2
@@ -63,6 +63,17 @@ struct ppc4xx_bd_info_t {uint32_t bi_iic_fast[2 ]; }; +/* Peripheral local bus arbitrer */ +#define TYPE_PPC405_PLB "ppc405-plb" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405PlbState,PPC405_PLB ); +struct Ppc405PlbState { +Ppc4xxDcrDeviceState parent_obj; + +uint32_t acr; +uint32_t bear; +uint32_t besr; +}; +/* PLB to OPB bridge */ #define TYPE_PPC405_POB "ppc405-pob"OBJECT_DECLARE_SIMPLE_TYPE (Ppc405PobState,PPC405_POB );
@@ -232,11 +243,10 @@ struct Ppc405SoCState {Ppc405EbcState ebc;Ppc405OpbaState opba;Ppc405PobState pob; + Ppc405PlbState plb; };/* PowerPC 405 core */ ram_addr_t ppc405_set_bootinfo (CPUPPCState *env,ram_addr_t ram_size); -void ppc4xx_plb_init (CPUPPCState *env); -#endif /* PPC405_H */
hw/ppc/ppc405_uc.c +32 -26
107 lines not on this page · raw message
hw/ppc/sam460ex.c +3 -1
@@ -309,7 +309,9 @@ static void sam460ex_init(MachineState *machine)ppc_dcr_init (env,NULL ,NULL );/* PLB arbitrer */ -ppc4xx_plb_init (env); + dev =qdev_new (TYPE_PPC405_PLB ); +ppc4xx_dcr_realize (PPC4xx_DCR_DEVICE (dev), cpu, &error_fatal); +object_unref (OBJECT (dev));/* interrupt controllers */ for (i =0 ; i <ARRAY_SIZE (uic); i++) {
Signature · 1 line
2.37.1
PATCH v3 18/22 ppc/ppc405: QOM'ify MAL
In reply to Cédric Le GoaterThe Memory Access Layer (MAL) controller is currently modeled as a DCR device with 4 IRQs. Also drop the ppc4xx_mal_init() helper and adapt the sam460ex machine.
--- hw/ppc/ppc405.h | 1 + include/hw/ppc/ppc4xx.h | 32 +++++++++- hw/ppc/ppc405_uc.c | 18 ++++-- hw/ppc/ppc4xx_devs.c | 134 ++++++++++++++++++---------------------- hw/ppc/sam460ex.c | 16 +++-- 5 files changed, 115 insertions(+), 86 deletions(-)
hw/ppc/ppc405.h +1 -0
@@ -244,6 +244,7 @@ struct Ppc405SoCState {Ppc405OpbaState opba;Ppc405PobState pob;Ppc405PlbState plb; +Ppc4xxMalState mal; };/* PowerPC 405 core */
include/hw/ppc/ppc4xx.h +29 -3
@@ -26,6 +26,7 @@#define PPC4XX_H #include "hw/ppc/ppc.h" +#include "hw/sysbus.h" #include "exec/memory.h" #include "hw/sysbus.h"
@@ -46,9 +47,6 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,hwaddr *ram_sizes, int do_init); -void ppc4xx_mal_init (CPUPPCState *env,uint8_t txcnum,uint8_t rxcnum, -qemu_irq irqs[4 ]); -#define TYPE_PPC4xx_PCI_HOST_BRIDGE "ppc4xx-pcihost"/*
@@ -67,4 +65,32 @@ void ppc4xx_dcr_register(Ppc4xxDcrDeviceState *dev, int dcrn,bool ppc4xx_dcr_realize (Ppc4xxDcrDeviceState *dev,PowerPCCPU *cpu,Error **errp); +/* Memory Access Layer (MAL) */ +#define TYPE_PPC4xx_MAL "ppc4xx-mal" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc4xxMalState, PPC4xx_MAL); +struct Ppc4xxMalState { +Ppc4xxDcrDeviceState parent_obj; + +qemu_irq irqs[4 ]; +uint32_t cfg; +uint32_t esr; +uint32_t ier; +uint32_t txcasr; +uint32_t txcarr; +uint32_t txeobisr; +uint32_t txdeir; +uint32_t rxcasr; +uint32_t rxcarr; +uint32_t rxeobisr; +uint32_t rxdeir; +uint32_t *txctpr; +uint32_t *rxctpr; +uint32_t *rcbs; +uint8_t txcnum; +uint8_t rxcnum; +}; + +void ppc4xx_mal_init (CPUPPCState *env,uint8_t txcnum,uint8_t rxcnum, +qemu_irq irqs[4 ]); +#endif /* PPC4XX_H */
hw/ppc/ppc405_uc.c +12 -6
@@ -1359,12 +1359,13 @@ static void ppc405_soc_instance_init(Object *obj)object_initialize_child (obj,"pob" , &s->pob,TYPE_PPC405_POB );object_initialize_child (obj,"plb" , &s->plb,TYPE_PPC405_PLB ); + +object_initialize_child (obj,"mal" , &s->mal, TYPE_PPC4xx_MAL); }static void ppc405_soc_realize (DeviceState *dev,Error **errp) {Ppc405SoCState *s =PPC405_SOC (dev); -qemu_irq mal_irqs[4 ];CPUPPCState *env;int i;
@@ -1481,11 +1482,16 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp) }/* MAL */ - mal_irqs[0 ] =qdev_get_gpio_in (s->uic,11 ); - mal_irqs[1 ] =qdev_get_gpio_in (s->uic,12 ); - mal_irqs[2 ] =qdev_get_gpio_in (s->uic,13 ); - mal_irqs[3 ] =qdev_get_gpio_in (s->uic,14 ); -ppc4xx_mal_init (env,4 ,2 , mal_irqs); +object_property_set_int (OBJECT (&s->mal),"txc-num" ,4 , &error_abort); +object_property_set_int (OBJECT (&s->mal),"rxc-num" ,2 , &error_abort); +if (!ppc4xx_dcr_realize (PPC4xx_DCR_DEVICE (&s->mal), &s->cpu, errp)) { +return ; + } + +for (i =0 ; i <ARRAY_SIZE (s->mal.irqs); i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (&s->mal), i, +qdev_get_gpio_in (s->uic,11 + i)); + }/* Ethernet */ /* Uses UIC IRQs 9, 15, 17 */
hw/ppc/ppc4xx_devs.c +61 -73
181 lines not on this page · raw message
hw/ppc/sam460ex.c +12 -4
@@ -280,7 +280,7 @@ static void sam460ex_init(MachineState *machine)hwaddr ram_sizes[SDRAM_NR_BANKS ] = {0 };MemoryRegion *l2cache_ram =g_new (MemoryRegion,1 );DeviceState *uic[4 ]; -qemu_irq mal_irqs[4 ]; +Ppc4xxMalState *mal;int i;PCIBus *pci_bus;PowerPCCPU *cpu;
@@ -387,10 +387,18 @@ static void sam460ex_init(MachineState *machine)ppc4xx_sdr_init (env);/* MAL */ -for (i =0 ; i <ARRAY_SIZE (mal_irqs); i++) { - mal_irqs[i] =qdev_get_gpio_in (uic[2 ],3 + i); + dev =qdev_new (TYPE_PPC4xx_MAL); + mal =PPC4xx_MAL (dev); + +qdev_prop_set_uint32 (dev,"txc-num" ,4 ); +qdev_prop_set_uint32 (dev,"rxc-num" ,16 ); +ppc4xx_dcr_realize (PPC4xx_DCR_DEVICE (mal), cpu, &error_fatal); +object_unref (OBJECT (mal)); + +for (i =0 ; i <ARRAY_SIZE (mal->irqs); i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (dev), i, +qdev_get_gpio_in (uic[2 ],3 + i)); } -ppc4xx_mal_init (env,4 ,16 , mal_irqs);/* DMA */ ppc4xx_dma_init (env,0x200 );
Signature · 1 line
2.37.1
PATCH v3 19/22 ppc/ppc405: QOM'ify FPGA
In reply to Cédric Le Goater--- hw/ppc/ppc405_boards.c | 55 +++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 17 deletions(-)
hw/ppc/ppc405_boards.c +38 -17
@@ -71,18 +71,23 @@ struct Ppc405MachineState {* - NVRAM (0xF0000000) * - FPGA (0xF0300000) */ -typedef struct ref405ep_fpga_t ref405ep_fpga_t ; -struct ref405ep_fpga_t { + +#define TYPE_PPC405_FPGA "ppc405-fpga" +OBJECT_DECLARE_SIMPLE_TYPE (Ppc405FpgaState,PPC405_FPGA ); +struct Ppc405FpgaState { +SysBusDevice parent_obj; + +MemoryRegion iomem; +uint8_t reg0;uint8_t reg1; };static uint64_t ref405ep_fpga_readb (void *opaque,hwaddr addr,unsigned size) { -ref405ep_fpga_t *fpga; +Ppc405FpgaState *fpga =PPC405_FPGA (opaque);uint32_t ret; - fpga = opaque;switch (addr) {case 0x0 : ret = fpga->reg0;
@@ -101,9 +106,8 @@ static uint64_t ref405ep_fpga_readb(void *opaque, hwaddr addr, unsigned size)static void ref405ep_fpga_writeb (void *opaque,hwaddr addr,uint64_t value,unsigned size) { -ref405ep_fpga_t *fpga; +Ppc405FpgaState *fpga =PPC405_FPGA (opaque); - fpga = opaque;switch (addr) {case 0x0 :/* Read only */
@@ -126,27 +130,39 @@ static const MemoryRegionOps ref405ep_fpga_ops = { .endianness = DEVICE_BIG_ENDIAN, }; -static void ref405ep_fpga_reset (void *opaque) +static void ref405ep_fpga_reset (DeviceState *dev) { -ref405ep_fpga_t *fpga; +Ppc405FpgaState *fpga =PPC405_FPGA (dev); - fpga = opaque; fpga->reg0 =0x00 ; fpga->reg1 =0x0F ; } -static void ref405ep_fpga_init (MemoryRegion *sysmem,uint32_t base) +static void ref405ep_fpga_realize (DeviceState *dev,Error **errp) { -ref405ep_fpga_t *fpga; -MemoryRegion *fpga_memory =g_new (MemoryRegion,1 ); +Ppc405FpgaState *s =PPC405_FPGA (dev); - fpga =g_new0 (ref405ep_fpga_t,1 ); -memory_region_init_io (fpga_memory,NULL , &ref405ep_fpga_ops, fpga, +memory_region_init_io (&s->iomem,OBJECT (s), &ref405ep_fpga_ops, s,"fpga" ,0x00000100 ); -memory_region_add_subregion (sysmem, base, fpga_memory); -qemu_register_reset (&ref405ep_fpga_reset, fpga); +sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->iomem); +} + +static void ref405ep_fpga_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = ref405ep_fpga_realize; + dc->user_creatable = false; + dc->reset = ref405ep_fpga_reset; } +static const TypeInfo ref405ep_fpga_type = { + .name =TYPE_PPC405_FPGA , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ppc405FpgaState), + .class_init = ref405ep_fpga_class_init, +}; +/* * CPU reset handler when booting directly from a loaded kernel */
@@ -332,7 +348,11 @@ static void ref405ep_init(MachineState *machine)memory_region_add_subregion (sysmem,PPC405EP_SRAM_BASE , sram);/* Register FPGA */ -ref405ep_fpga_init (get_system_memory (),PPC405EP_FPGA_BASE ); + dev =qdev_new (TYPE_PPC405_FPGA ); +object_property_add_child (OBJECT (machine),"fpga" ,OBJECT (dev)); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,PPC405EP_FPGA_BASE ); +/* Register NVRAM */ dev =qdev_new ("sysbus-m48t08" );qdev_prop_set_int32 (dev,"base-year" ,1968 );
@@ -377,6 +397,7 @@ static void ppc405_machine_init(void) {type_register_static (&ppc405_machine_type);type_register_static (&ref405ep_type); +type_register_static (&ref405ep_fpga_type); }type_init (ppc405_machine_init)
Signature · 1 line
2.37.1
Re: [PATCH v3 19/22] ppc/ppc405: QOM'ify FPGA
Quoted 11 lines · Cédric Le Goater
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405_boards.c| 55 +++++++++++++++++++++++++++++-------------1 file changed, 38 insertions(+), 17 deletions(-)hw/ppc/ppc405_boards.c +0
-0
hw/ppc/ppc405_boards.c struct Ppc405MachineState { · line 75
Quoted 7 lines
hw/ppc/ppc405_boards.c +2
-2@@ -71,18 +71,23 @@ struct Ppc405MachineState {* - NVRAM (0xF0000000) * - FPGA (0xF0300000) */ -typedef struct ref405ep_fpga_t ref405ep_fpga_t ; -struct ref405ep_fpga_t { + +#define TYPE_PPC405_FPGA "ppc405-fpga"
If this is specific to ref405ep maybe it should be named accordingly.
Regards,
BALATON Zoltan
Quoted 103 lines
hw/ppc/ppc405_boards.c +36
-15+OBJECT_DECLARE_SIMPLE_TYPE (Ppc405FpgaState,PPC405_FPGA ); +struct Ppc405FpgaState { +SysBusDevice parent_obj; + +MemoryRegion iomem; +uint8_t reg0;uint8_t reg1; };static uint64_t ref405ep_fpga_readb (void *opaque,hwaddr addr,unsigned size) { -ref405ep_fpga_t *fpga; +Ppc405FpgaState *fpga =PPC405_FPGA (opaque);uint32_t ret; - fpga = opaque;switch (addr) {case 0x0 : ret = fpga->reg0;@@ -101,9 +106,8 @@ static uint64_t ref405ep_fpga_readb(void *opaque, hwaddr addr, unsigned size)static void ref405ep_fpga_writeb (void *opaque,hwaddr addr,uint64_t value,unsigned size) { -ref405ep_fpga_t *fpga; +Ppc405FpgaState *fpga =PPC405_FPGA (opaque); - fpga = opaque;switch (addr) {case 0x0 :/* Read only */ @@ -126,27 +130,39 @@ static const MemoryRegionOps ref405ep_fpga_ops = { .endianness = DEVICE_BIG_ENDIAN, }; -static void ref405ep_fpga_reset (void *opaque) +static void ref405ep_fpga_reset (DeviceState *dev) { -ref405ep_fpga_t *fpga; +Ppc405FpgaState *fpga =PPC405_FPGA (dev); - fpga = opaque; fpga->reg0 =0x00 ; fpga->reg1 =0x0F ; } -static void ref405ep_fpga_init (MemoryRegion *sysmem,uint32_t base) +static void ref405ep_fpga_realize (DeviceState *dev,Error **errp) { -ref405ep_fpga_t *fpga; -MemoryRegion *fpga_memory =g_new (MemoryRegion,1 ); +Ppc405FpgaState *s =PPC405_FPGA (dev); - fpga =g_new0 (ref405ep_fpga_t,1 ); -memory_region_init_io (fpga_memory,NULL , &ref405ep_fpga_ops, fpga, +memory_region_init_io (&s->iomem,OBJECT (s), &ref405ep_fpga_ops, s,"fpga" ,0x00000100 ); -memory_region_add_subregion (sysmem, base, fpga_memory); -qemu_register_reset (&ref405ep_fpga_reset, fpga); +sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->iomem); +} + +static void ref405ep_fpga_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = ref405ep_fpga_realize; + dc->user_creatable = false; + dc->reset = ref405ep_fpga_reset; } +static const TypeInfo ref405ep_fpga_type = { + .name =TYPE_PPC405_FPGA , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ppc405FpgaState), + .class_init = ref405ep_fpga_class_init, +}; +/* * CPU reset handler when booting directly from a loaded kernel */ @@ -332,7 +348,11 @@ static void ref405ep_init(MachineState *machine)memory_region_add_subregion (sysmem,PPC405EP_SRAM_BASE , sram);/* Register FPGA */ -ref405ep_fpga_init (get_system_memory (),PPC405EP_FPGA_BASE ); + dev =qdev_new (TYPE_PPC405_FPGA ); +object_property_add_child (OBJECT (machine),"fpga" ,OBJECT (dev)); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,PPC405EP_FPGA_BASE ); +/* Register NVRAM */ dev =qdev_new ("sysbus-m48t08" );qdev_prop_set_int32 (dev,"base-year" ,1968 );@@ -377,6 +397,7 @@ static void ppc405_machine_init(void) {type_register_static (&ppc405_machine_type);type_register_static (&ref405ep_type); +type_register_static (&ref405ep_fpga_type); }type_init (ppc405_machine_init)
Re: [PATCH v3 19/22] ppc/ppc405: QOM'ify FPGA
Quoted 7 lines · BALATON Zoltan
Quoted 6 lines · Cédric Le Goater
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405_boards.c| 55 +++++++++++++++++++++++++++++-------------1 file changed, 38 insertions(+), 17 deletions(-)
Quoted 14 lines
hw/ppc/ppc405_boards.c struct Ppc405MachineState { · line 75
Quoted 12 lines
hw/ppc/ppc405_boards.c +2
-2@@ -71,18 +71,23 @@ struct Ppc405MachineState {* - NVRAM (0xF0000000) * - FPGA (0xF0300000) */ -typedef struct ref405ep_fpga_t ref405ep_fpga_t ; -struct ref405ep_fpga_t { + +#define TYPE_PPC405_FPGA "ppc405-fpga"If this is specific to ref405ep maybe it should be named accordingly.
done.
Thanks,
C.
Quoted 107 lines
Regards,
BALATON ZoltanQuoted 103 lines
hw/ppc/ppc405_boards.c +7
-2+OBJECT_DECLARE_SIMPLE_TYPE (Ppc405FpgaState,PPC405_FPGA ); +struct Ppc405FpgaState { + SysBusDevice parent_obj; + + MemoryRegion iomem; + uint8_t reg0; uint8_t reg1; };static uint64_t ref405ep_fpga_readb (void *opaque,hwaddr addr,unsigned size) { - ref405ep_fpga_t *fpga; + Ppc405FpgaState *fpga = PPC405_FPGA(opaque); uint32_t ret; - fpga = opaque; switch (addr) {case
0x0:
ret =fpga->reg0;hw/ppc/ppc405_boards.c +1
-2@@ -101,9 +106,8 @@ static uint64_t ref405ep_fpga_readb(void *opaque, hwaddr addr, unsigned size)static void ref405ep_fpga_writeb (void *opaque,hwaddr addr,uint64_t value, unsigned size) { - ref405ep_fpga_t *fpga; + Ppc405FpgaState *fpga = PPC405_FPGA(opaque); - fpga = opaque; switch (addr) {case
0x0:
/* Read only */hw/ppc/ppc405_boards.c +28
-11@@ -126,27 +130,39 @@ static const MemoryRegionOps ref405ep_fpga_ops = { .endianness = DEVICE_BIG_ENDIAN, }; -static void ref405ep_fpga_reset (void *opaque) +static void ref405ep_fpga_reset (DeviceState *dev) { - ref405ep_fpga_t *fpga; + Ppc405FpgaState *fpga = PPC405_FPGA(dev); - fpga = opaque; fpga->reg0 = 0x00; fpga->reg1 = 0x0F; } -static void ref405ep_fpga_init (MemoryRegion *sysmem,uint32_t base) +static void ref405ep_fpga_realize (DeviceState *dev,Error **errp) { - ref405ep_fpga_t *fpga; - MemoryRegion *fpga_memory = g_new(MemoryRegion, 1); + Ppc405FpgaState *s = PPC405_FPGA(dev); - fpga = g_new0(ref405ep_fpga_t, 1); - memory_region_init_io(fpga_memory, NULL, &ref405ep_fpga_ops, fpga, + memory_region_init_io(&s->iomem, OBJECT(s), &ref405ep_fpga_ops, s, "fpga", 0x00000100); - memory_region_add_subregion(sysmem, base, fpga_memory); - qemu_register_reset(&ref405ep_fpga_reset, fpga); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); +} + +static void ref405ep_fpga_class_init (ObjectClass *oc,void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->realize = ref405ep_fpga_realize; + dc->user_creatable = false; + dc->reset = ref405ep_fpga_reset; } +static const TypeInfo ref405ep_fpga_type = { + .name = TYPE_PPC405_FPGA, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(Ppc405FpgaState), + .class_init = ref405ep_fpga_class_init, +}; +/* * CPU reset handler when booting directly from a loaded kernel */ @@ -332,7 +348,11 @@ static void ref405ep_init(MachineState *machine) memory_region_add_subregion(sysmem, PPC405EP_SRAM_BASE, sram); /* Register FPGA */ - ref405ep_fpga_init(get_system_memory(), PPC405EP_FPGA_BASE); + dev = qdev_new(TYPE_PPC405_FPGA); + object_property_add_child(OBJECT(machine), "fpga", OBJECT(dev)); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, PPC405EP_FPGA_BASE); + /* Register NVRAM */ dev = qdev_new("sysbus-m48t08"); qdev_prop_set_int32(dev, "base-year", 1968);@@ -377,6 +397,7 @@ static void ppc405_machine_init(void) { type_register_static(&ppc405_machine_type); type_register_static(&ref405ep_type); + type_register_static(&ref405ep_fpga_type); }type_init (ppc405_machine_init)
PATCH v3 20/22 ppc/ppc405: Use an explicit PPCUIC object
In reply to Cédric Le Goater--- hw/ppc/ppc405.h | 3 ++- hw/ppc/ppc405_uc.c | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-)
hw/ppc/ppc405.h +2 -1
@@ -27,6 +27,7 @@#include "qom/object.h" #include "hw/ppc/ppc4xx.h" +#include "hw/intc/ppc-uic.h" #define PPC405EP_SDRAM_BASE 0x00000000#define PPC405EP_NVRAM_BASE 0xF0000000
@@ -234,7 +235,7 @@ struct Ppc405SoCState {hwaddr ram_size;PowerPCCPU cpu; -DeviceState *uic; +PPCUIC uic;Ppc405CpcState cpc;Ppc405GptState gpt;Ppc405OcmState ocm;
hw/ppc/ppc405_uc.c +13 -13
@@ -1341,6 +1341,8 @@ static void ppc405_soc_instance_init(Object *obj)object_initialize_child (obj,"cpu" , &s->cpu,POWERPC_CPU_TYPE_NAME ("405ep" )); +object_initialize_child (obj,"uic" , &s->uic,TYPE_PPC_UIC ); +object_initialize_child (obj,"cpc" , &s->cpc,TYPE_PPC405_CPC );object_property_add_alias (obj,"sys-clk" ,OBJECT (&s->cpc),"sys-clk" );
@@ -1401,17 +1403,15 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->opba),0 ,0xef600600 );/* Universal interrupt controller */ - s->uic =qdev_new (TYPE_PPC_UIC ); - -object_property_set_link (OBJECT (s->uic),"cpu" ,OBJECT (&s->cpu), +object_property_set_link (OBJECT (&s->uic),"cpu" ,OBJECT (&s->cpu), &error_fatal); -if (!sysbus_realize (SYS_BUS_DEVICE (s->uic), errp)) { +if (!sysbus_realize (SYS_BUS_DEVICE (&s->uic), errp)) {return ; } -sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_INT , +sysbus_connect_irq (SYS_BUS_DEVICE (&s->uic),PPCUIC_OUTPUT_INT ,qdev_get_gpio_in (DEVICE (&s->cpu), PPC40x_INPUT_INT)); -sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_CINT , +sysbus_connect_irq (SYS_BUS_DEVICE (&s->uic),PPCUIC_OUTPUT_CINT ,qdev_get_gpio_in (DEVICE (&s->cpu), PPC40x_INPUT_CINT));/* SDRAM controller */
@@ -1422,7 +1422,7 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)"ppc405.sdram0" , s->dram_mr, s->ram_bases[0], s->ram_sizes[0]); -ppc4xx_sdram_init (env,qdev_get_gpio_in (s->uic,17 ),1 , +ppc4xx_sdram_init (env,qdev_get_gpio_in (DEVICE (&s->uic),17 ),1 , s->ram_banks, s->ram_bases, s->ram_sizes, s->do_dram_init);
@@ -1438,12 +1438,12 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)for (i =0 ; i <ARRAY_SIZE (s->dma.irqs); i++) {sysbus_connect_irq (SYS_BUS_DEVICE (&s->dma), i, -qdev_get_gpio_in (s->uic,5 + i)); +qdev_get_gpio_in (DEVICE (&s->uic),5 + i)); }/* I2C controller */ sysbus_create_simple (TYPE_PPC4xx_I2C,0xef600500 , -qdev_get_gpio_in (s->uic,2 )); +qdev_get_gpio_in (DEVICE (&s->uic),2 ));/* GPIO */ if (!sysbus_realize (SYS_BUS_DEVICE (&s->gpio), errp)) {
@@ -1454,13 +1454,13 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)/* Serial ports */ if (serial_hd (0 ) !=NULL ) {serial_mm_init (get_system_memory (),0xef600300 ,0 , -qdev_get_gpio_in (s->uic,0 ), +qdev_get_gpio_in (DEVICE (&s->uic),0 ),PPC_SERIAL_MM_BAUDBASE ,serial_hd (0 ),DEVICE_BIG_ENDIAN ); }if (serial_hd (1 ) !=NULL ) {serial_mm_init (get_system_memory (),0xef600400 ,0 , -qdev_get_gpio_in (s->uic,1 ), +qdev_get_gpio_in (DEVICE (&s->uic),1 ),PPC_SERIAL_MM_BAUDBASE ,serial_hd (1 ),DEVICE_BIG_ENDIAN ); }
@@ -1478,7 +1478,7 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)for (i =0 ; i <ARRAY_SIZE (s->gpt.irqs); i++) {sysbus_connect_irq (SYS_BUS_DEVICE (&s->gpt), i, -qdev_get_gpio_in (s->uic,19 + i)); +qdev_get_gpio_in (DEVICE (&s->uic),19 + i)); }/* MAL */
@@ -1490,7 +1490,7 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)for (i =0 ; i <ARRAY_SIZE (s->mal.irqs); i++) {sysbus_connect_irq (SYS_BUS_DEVICE (&s->mal), i, -qdev_get_gpio_in (s->uic,11 + i)); +qdev_get_gpio_in (DEVICE (&s->uic),11 + i)); }/* Ethernet */
Signature · 1 line
2.37.1
Re: [PATCH v3 20/22] ppc/ppc405: Use an explicit PPCUIC object
It's not that it's now explicitly typed as PPCUIC but more that it's now embedded in soc state instead of dynamically allocated. So Embed UIC in soc state may be a better patch title.
Regards,
BALATON Zoltan
Quoted 122 lines · Cédric Le Goater
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ppc/ppc405.h| 3 ++-hw/ppc/ppc405_uc.c| 26 +++++++++++++-------------2 files changed, 15 insertions(+), 14 deletions(-)hw/ppc/ppc405.h +2
-1@@ -27,6 +27,7 @@#include "qom/object.h" #include "hw/ppc/ppc4xx.h" +#include "hw/intc/ppc-uic.h" #define PPC405EP_SDRAM_BASE 0x00000000#define PPC405EP_NVRAM_BASE 0xF0000000@@ -234,7 +235,7 @@ struct Ppc405SoCState {hwaddr ram_size;PowerPCCPU cpu; -DeviceState *uic; +PPCUIC uic;Ppc405CpcState cpc;Ppc405GptState gpt;Ppc405OcmState ocm;hw/ppc/ppc405_uc.c +13
-13@@ -1341,6 +1341,8 @@ static void ppc405_soc_instance_init(Object *obj)object_initialize_child (obj,"cpu" , &s->cpu,POWERPC_CPU_TYPE_NAME ("405ep" )); +object_initialize_child (obj,"uic" , &s->uic,TYPE_PPC_UIC ); +object_initialize_child (obj,"cpc" , &s->cpc,TYPE_PPC405_CPC );object_property_add_alias (obj,"sys-clk" ,OBJECT (&s->cpc),"sys-clk" );@@ -1401,17 +1403,15 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->opba),0 ,0xef600600 );/* Universal interrupt controller */ - s->uic =qdev_new (TYPE_PPC_UIC ); - -object_property_set_link (OBJECT (s->uic),"cpu" ,OBJECT (&s->cpu), +object_property_set_link (OBJECT (&s->uic),"cpu" ,OBJECT (&s->cpu), &error_fatal); -if (!sysbus_realize (SYS_BUS_DEVICE (s->uic), errp)) { +if (!sysbus_realize (SYS_BUS_DEVICE (&s->uic), errp)) {return ; } -sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_INT , +sysbus_connect_irq (SYS_BUS_DEVICE (&s->uic),PPCUIC_OUTPUT_INT ,qdev_get_gpio_in (DEVICE (&s->cpu), PPC40x_INPUT_INT)); -sysbus_connect_irq (SYS_BUS_DEVICE (s->uic),PPCUIC_OUTPUT_CINT , +sysbus_connect_irq (SYS_BUS_DEVICE (&s->uic),PPCUIC_OUTPUT_CINT ,qdev_get_gpio_in (DEVICE (&s->cpu), PPC40x_INPUT_CINT));/* SDRAM controller */ @@ -1422,7 +1422,7 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)"ppc405.sdram0" , s->dram_mr, s->ram_bases[0], s->ram_sizes[0]); -ppc4xx_sdram_init (env,qdev_get_gpio_in (s->uic,17 ),1 , +ppc4xx_sdram_init (env,qdev_get_gpio_in (DEVICE (&s->uic),17 ),1 , s->ram_banks, s->ram_bases, s->ram_sizes, s->do_dram_init);@@ -1438,12 +1438,12 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)for (i =0 ; i <ARRAY_SIZE (s->dma.irqs); i++) {sysbus_connect_irq (SYS_BUS_DEVICE (&s->dma), i, -qdev_get_gpio_in (s->uic,5 + i)); +qdev_get_gpio_in (DEVICE (&s->uic),5 + i)); }/* I2C controller */ sysbus_create_simple (TYPE_PPC4xx_I2C,0xef600500 , -qdev_get_gpio_in (s->uic,2 )); +qdev_get_gpio_in (DEVICE (&s->uic),2 ));/* GPIO */ if (!sysbus_realize (SYS_BUS_DEVICE (&s->gpio), errp)) {@@ -1454,13 +1454,13 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)/* Serial ports */ if (serial_hd (0 ) !=NULL ) {serial_mm_init (get_system_memory (),0xef600300 ,0 , -qdev_get_gpio_in (s->uic,0 ), +qdev_get_gpio_in (DEVICE (&s->uic),0 ),PPC_SERIAL_MM_BAUDBASE ,serial_hd (0 ),DEVICE_BIG_ENDIAN ); }if (serial_hd (1 ) !=NULL ) {serial_mm_init (get_system_memory (),0xef600400 ,0 , -qdev_get_gpio_in (s->uic,1 ), +qdev_get_gpio_in (DEVICE (&s->uic),1 ),PPC_SERIAL_MM_BAUDBASE ,serial_hd (1 ),DEVICE_BIG_ENDIAN ); }@@ -1478,7 +1478,7 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)for (i =0 ; i <ARRAY_SIZE (s->gpt.irqs); i++) {sysbus_connect_irq (SYS_BUS_DEVICE (&s->gpt), i, -qdev_get_gpio_in (s->uic,19 + i)); +qdev_get_gpio_in (DEVICE (&s->uic),19 + i)); }/* MAL */ @@ -1490,7 +1490,7 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)for (i =0 ; i <ARRAY_SIZE (s->mal.irqs); i++) {sysbus_connect_irq (SYS_BUS_DEVICE (&s->mal), i, -qdev_get_gpio_in (s->uic,11 + i)); +qdev_get_gpio_in (DEVICE (&s->uic),11 + i)); }/* Ethernet */
PATCH v3 21/22 ppc/ppc405: Use an explicit I2C object
In reply to Cédric Le GoaterHaving an explicit I2C model object will help if one day we want to add I2C devices on the bus from the machine init routine.
--- hw/ppc/ppc405.h | 2 ++ hw/ppc/ppc405_uc.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-)
hw/ppc/ppc405.h +2 -0
@@ -28,6 +28,7 @@#include "qom/object.h" #include "hw/ppc/ppc4xx.h" #include "hw/intc/ppc-uic.h" +#include "hw/i2c/ppc4xx_i2c.h" #define PPC405EP_SDRAM_BASE 0x00000000#define PPC405EP_NVRAM_BASE 0xF0000000
@@ -241,6 +242,7 @@ struct Ppc405SoCState {Ppc405OcmState ocm;Ppc405GpioState gpio;Ppc405DmaState dma; +PPC4xxI2CState i2c;Ppc405EbcState ebc;Ppc405OpbaState opba;Ppc405PobState pob;
hw/ppc/ppc405_uc.c +8 -2
@@ -1354,6 +1354,8 @@ static void ppc405_soc_instance_init(Object *obj)object_initialize_child (obj,"dma" , &s->dma,TYPE_PPC405_DMA ); +object_initialize_child (obj,"i2c" , &s->i2c, TYPE_PPC4xx_I2C); +object_initialize_child (obj,"ebc" , &s->ebc,TYPE_PPC405_EBC );object_initialize_child (obj,"opba" , &s->opba,TYPE_PPC405_OPBA );
@@ -1442,8 +1444,12 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp) }/* I2C controller */ -sysbus_create_simple (TYPE_PPC4xx_I2C,0xef600500 , -qdev_get_gpio_in (DEVICE (&s->uic),2 )); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->i2c), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->i2c),0 ,0xef600500 ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->i2c),0 , +qdev_get_gpio_in (DEVICE (&s->uic),2 ));/* GPIO */ if (!sysbus_realize (SYS_BUS_DEVICE (&s->gpio), errp)) {
Signature · 1 line
2.37.1
PATCH v3 22/22 ppc/ppc4xx: Fix sdram trace events
In reply to Cédric Le Goater--- hw/ppc/ppc4xx_devs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/ppc4xx_devs.c +1 -1
@@ -175,7 +175,7 @@ static void sdram_set_bcr(ppc4xx_sdram_t *sdram, int i, } sdram->bcr[i] = bcr &0xFFDEE001 ;if (enabled && (bcr &0x00000001 )) { -trace_ppc4xx_sdram_unmap (sdram_base (bcr),sdram_size (bcr)); +trace_ppc4xx_sdram_map (sdram_base (bcr),sdram_size (bcr));memory_region_init (&sdram->containers[i],NULL ,"sdram-containers" ,sdram_size (bcr)); memory_region_add_subregion(&sdram->containers[i], 0,
Signature · 1 line
2.37.1
Quoted 8 lines · Cédric Le Goater
Hello,
Here is large series QOM'ifying the PPC405 board. It introduces a new generic machine and SoC models, converts the current device models to QOM and populates the SoC. The process is quite mechanical without too much issues to handle. The noisy part is the initial patch introducing the SoC realize routine.
Quoted 5 lines
What's left ?
* the SDRAM mappings are very baroque and certainly could be simplified. I think we should QOMify the ppc440 machines before addressing this part.
The issue with SDRAM controller and the likely reason why its model looks so complex is that it can't handle any RAM size because of how the bank sizes are encoded in the registers so it only really supports real RAM modules which are predefined sizes. Also the firmware discovers RAM by looking at SPD data and may only check the slots that the real hardware has which may not be the first one. Previously I had code to round down the memory size specified on the command line to an acceptable size and issue a warning to let the user know but this was dropped because of some changes in code elsewhere which now allocates memory before the machine could check and ajust it so we can only adjust it by wasting some. Take this into account and check the ppc4xx_sdram_banks() function and 440 machines before changing this.
Regards,
BALATON Zoltan
Quoted 59 lines
Thanks,
C.
Changes in v3 :
- New device model Ppc4xxDcrDeviceState
- Removal ofppc4xx_mal_init(),ppc4xx_plb_init()andppc405_ebc_init()
- Fixes for some reset issues
- Kept 2 RAM banks at the Soc level but only one is initialized.
- Moved SRAM under the machine. It's not part of the SoC according to the 405 specsChanges in v2 :
-
docs/about/removed-features.rstupdate
- Fix compile breakage (uic)
- Fix CPU reset, which breaking u-boot boot
- Changed prefix of memory regions to "ppc405"
- Reduced the number of RAM banks to 1. Second was a dummy one to pleaseppc405ep_init()Cédric Le Goater (22):
ppc/ppc405: Remove taihu machine ppc/ppc405: Introduce a PPC405 generic machine ppc/ppc405: Move devices under the ref405ep machine ppc/ppc405: Move SRAM under the ref405ep machine ppc/ppc405: Introduce a PPC405 SoC ppc/ppc405: Start QOMification of the SoC ppc/ppc405: QOM'ify CPU
ppc/ppc4xx: Introduce a DCR device model ppc/ppc405: QOM'ify CPC
ppc/ppc405: QOM'ify GPT
ppc/ppc405: QOM'ify OCM
ppc/ppc405: QOM'ify GPIO
ppc/ppc405: QOM'ify DMA
ppc/ppc405: QOM'ify EBC
ppc/ppc405: QOM'ify OPBA
ppc/ppc405: QOM'ify POB
ppc/ppc405: QOM'ify PLB
ppc/ppc405: QOM'ify MAL
ppc/ppc405: QOM'ify FPGA
ppc/ppc405: Use an explicit PPCUIC object ppc/ppc405: Use an explicit I2C object ppc/ppc4xx: Fix sdram trace eventsdocs/about/deprecated.rst | 9 - docs/about/removed-features.rst | 6 + docs/system/ppc/embedded.rst | 1 - hw/ppc/ppc405.h | 198 +++++++- include/hw/ppc/ppc4xx.h | 48 +- hw/ppc/ppc405_boards.c | 375 ++++----------- hw/ppc/ppc405_uc.c | 828 +++++++++++++++++--------------- hw/ppc/ppc4xx_devs.c | 184 ++++--- hw/ppc/sam460ex.c | 24 +- MAINTAINERS | 2 +- 10 files changed, 903 insertions(+), 772 deletions(-)
Quoted 11 lines · BALATON Zoltan
Quoted 10 lines · Cédric Le Goater
Hello,
Here is large series QOM'ifying the PPC405 board. It introduces a new generic machine and SoC models, converts the current device models to QOM and populates the SoC. The process is quite mechanical without too much issues to handle. The noisy part is the initial patch introducing the SoC realize routine.
What's left ?
Quoted 7 lines
Quoted 3 lines
* the SDRAM mappings are very baroque and certainly could be simplified. I think we should QOMify the ppc440 machines before addressing this part.
The issue with SDRAM controller and the likely reason why its model looks so complex is that it can't handle any RAM size because of how the bank sizes are encoded in the registers so it only really supports real RAM modules which are predefined sizes. Also the firmware discovers RAM by looking at SPD data and may only check the slots that the real hardware has which may not be the first one.
Previously I had code to round down the memory size specified on the command line to an acceptable size and issue a warning to let the user know but this was dropped because of some changes in code elsewhere which now allocates memory before the machine could check and ajust it so we can only adjust it by wasting some.
I don't think we should care adjusting the values. the machine init routine should check that the RAM size is valid or fail. The machine should also have a sane RAM size value by default.
See how the aspeed machine deals with similar constraints of its SDRAM controller in aspeed_machine_init(). If the sdram controller does not validate the RAM size, aspeed_sdmc_set_ram_size() fails with an error.
C.
Quoted 65 lines
Take this into account and check the
ppc4xx_sdram_banks()function and 440 machines before changing this.Regards,
BALATON ZoltanQuoted 59 lines
Thanks,
C.
Changes in v3 :
- New device model Ppc4xxDcrDeviceState
- Removal ofppc4xx_mal_init(),ppc4xx_plb_init()andppc405_ebc_init()
- Fixes for some reset issues
- Kept 2 RAM banks at the Soc level but only one is initialized.
- Moved SRAM under the machine. It's not part of the SoC according to the 405 specsChanges in v2 :
-
docs/about/removed-features.rstupdate
- Fix compile breakage (uic)
- Fix CPU reset, which breaking u-boot boot
- Changed prefix of memory regions to "ppc405"
- Reduced the number of RAM banks to 1. Second was a dummy one to pleaseppc405ep_init()Cédric Le Goater (22):
ppc/ppc405: Remove taihu machine ppc/ppc405: Introduce a PPC405 generic machine ppc/ppc405: Move devices under the ref405ep machine ppc/ppc405: Move SRAM under the ref405ep machine ppc/ppc405: Introduce a PPC405 SoC ppc/ppc405: Start QOMification of the SoC ppc/ppc405: QOM'ify CPU
ppc/ppc4xx: Introduce a DCR device model ppc/ppc405: QOM'ify CPC
ppc/ppc405: QOM'ify GPT
ppc/ppc405: QOM'ify OCM
ppc/ppc405: QOM'ify GPIO
ppc/ppc405: QOM'ify DMA
ppc/ppc405: QOM'ify EBC
ppc/ppc405: QOM'ify OPBA
ppc/ppc405: QOM'ify POB
ppc/ppc405: QOM'ify PLB
ppc/ppc405: QOM'ify MAL
ppc/ppc405: QOM'ify FPGA
ppc/ppc405: Use an explicit PPCUIC object ppc/ppc405: Use an explicit I2C object ppc/ppc4xx: Fix sdram trace eventsdocs/about/deprecated.rst | 9 -
docs/about/removed-features.rst| 6 + docs/system/ppc/embedded.rst | 1 -
hw/ppc/ppc405.h | 198 +++++++- include/hw/ppc/ppc4xx.h | 48 +- hw/ppc/ppc405_boards.c | 375 ++++----------- hw/ppc/ppc405_uc.c | 828 +++++++++++++++++--------------- hw/ppc/ppc4xx_devs.c | 184 ++++--- hw/ppc/sam460ex.c | 24 +-
MAINTAINERS | 2 +-10 files changed, 903 insertions(+), 772 deletions(-)
Quoted 18 lines · Cédric Le Goater
Quoted 9 lines · BALATON Zoltan
Quoted 8 lines · Cédric Le Goater
Hello,
Here is large series QOM'ifying the PPC405 board. It introduces a new generic machine and SoC models, converts the current device models to QOM and populates the SoC. The process is quite mechanical without too much issues to handle. The noisy part is the initial patch introducing the SoC realize routine.
Quoted 7 lines
Quoted 5 lines
What's left ?
* the SDRAM mappings are very baroque and certainly could be simplified. I think we should QOMify the ppc440 machines before addressing this part.
The issue with SDRAM controller and the likely reason why its model looks so complex is that it can't handle any RAM size because of how the bank sizes are encoded in the registers so it only really supports real RAM modules which are predefined sizes. Also the firmware discovers RAM by looking at SPD data and may only check the slots that the real hardware has which may not be the first one. Previously I had code to round down the memory size specified on the command line to an acceptable size and issue a warning to let the user know but this was dropped because of some changes in code elsewhere which now allocates memory before the machine could check and ajust it so we can only adjust it by wasting some.
Quoted 7 lines
I don't think we should care adjusting the values. the machine init routine should check that the RAM size is valid or fail. The machine should also have a sane RAM size value by default.
See how the aspeed machine deals with similar constraints of its SDRAM controller in
aspeed_machine_init(). If the sdram controller does not validate the RAM size,aspeed_sdmc_set_ram_size()fails with an error.
Even then we need to check if the specified memory matches one of the allowed sized and distribute it to the allowed banks by the soc. This code is more complex than the 405ep has currently and should not be reprated in each board. That's why we have the ppc4xx_memory_banks and sdram_init functions so while it may be possible to simmplify it a bit maybe not much. I've spent quite some time with it so if you change it check that at least sam360ex -m 2G still works.
Regards,
BALATON Zoltan