hw/riscv: Socify Atlantis
Subsystems (2)
v2 cover hw/riscv: Socify Atlantis
v1: https://lore.kernel.org/qemu-riscv/[email protected]/
Changes in v2:
- Reword patch 14 "hart private memory" commit message to clarify hart vs hart array
- Fix indentation in patch 4 (riscv_aplic MemoryRegion)
Thanks to Daniel and Philippe for the reviews.
Original commit message:
This addresses the review given by Cedric on v1 of the Atlantis patches, where he suggested making the machine a SoC. This is the pattern followed by the Aspeed ARM machines, where the SoC represents the modelled hardware, attaching its devices to a memory container, with the SoC instantiated by a QEMU machine that provides the memory container and the machine's RAM.
Aside from the clean abstraction that this encourages, this pattern will be useful in adding other SoCs to the Atlantis machine, such as the RCPU (boot microcontroller) and CPL (Cluster Power Logic microcontroller).
The series converts the RISC-V interrupt controllers to take a MemoryRegion for mapping themselves, with no change in behaviour for existing machines, and then cleans up the CPS device to place its devices in the memory container provided.
The next few patches clean up the Atlantis machine to make extracting the SoC device and mapping it in a container relatively straightforward.
Joel Stanley (15):
hw/riscv/aia: Take a MemoryRegion for the created devices hw/intc/riscv_aclint: Take a MemoryRegion for the created devices hw/intc/riscv_imsic: Take a MemoryRegion for the created device hw/intc/riscv_aplic: Take a MemoryRegion for the created device hw/intc/sifive_plic: Take a MemoryRegion for the created device hw/riscv/cps: Map interrupt controllers in SoC container hw/riscv/atlantis: Make UART unimp region a SoC device hw/riscv/atlantis: Remove unused fdt_size hw/riscv/atlantis: Rename hart array 'soc' to 'cpus' hw/riscv/atlantis: Rework device tree creation hw/riscv/atlantis: Use local reference for system memory hw/riscv/atlantis: Decouple RAM size from MachineState hw/riscv/atlantis: Make TTAtlantisState own memory containers hw/riscv/atlantis: Extract an Atlantis SoC device hw/riscv/atlantis: Map the SoC through a memory container
Portia Stephens (1):
hw/riscv: Add property to hart to allow private memory
hw/riscv/aia.h | 2 +- include/hw/intc/riscv_aclint.h | 7 +- include/hw/intc/riscv_aplic.h | 2 +- include/hw/intc/riscv_imsic.h | 3 +- include/hw/intc/sifive_plic.h | 3 +- include/hw/riscv/riscv_hart.h | 2 + include/hw/riscv/tt_atlantis.h | 32 +++- hw/intc/riscv_aclint.c | 12 +- hw/intc/riscv_aplic.c | 5 +- hw/intc/riscv_imsic.c | 6 +- hw/intc/sifive_plic.c | 6 +- hw/riscv/aia.c | 14 +- hw/riscv/cps.c | 12 +- hw/riscv/k230.c | 9 +- hw/riscv/microchip_pfsoc.c | 8 +- hw/riscv/riscv_hart.c | 8 + hw/riscv/shakti_c.c | 10 +- hw/riscv/sifive_e.c | 6 +- hw/riscv/sifive_u.c | 10 +- hw/riscv/spike.c | 4 +- hw/riscv/tt_atlantis.c | 277 +++++++++++++++++++++------------ hw/riscv/virt.c | 21 ++- hw/riscv/xiangshan_kmh.c | 17 +- 23 files changed, 317 insertions(+), 159 deletions(-)
Signature · 1 line
2.47.3
PATCH v2 1/16 hw/riscv/aia: Take a MemoryRegion for the created devices
Add a MemoryRegion parameter to riscv_create_aia(), to be passed on to the IMSIC and APLIC helpers so a SoC can have the controllers mapped into its own memory container. Both callers pass system_memory, so there is no change in behaviour.
As the controllers don't yet take a MemoryRegion the parameter is not yet passed on. Changing riscv_create_aia first avoids churn in the intermediate commits.
--- hw/riscv/aia.h | 2 +- hw/riscv/aia.c | 2 +- hw/riscv/tt_atlantis.c | 3 ++- hw/riscv/virt.c | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-)
hw/riscv/aia.h +1 -1
@@ -13,7 +13,7 @@uint32_t imsic_num_bits (uint32_t count); -DeviceState *riscv_create_aia(bool msimode, int aia_guests, +DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests, uint32_t m_imsic_stride, uint32_t s_imsic_stride, uint16_t num_sources,
hw/riscv/aia.c +1 -1
@@ -24,7 +24,7 @@ uint32_t imsic_num_bits(uint32_t count)return ret; } -DeviceState *riscv_create_aia(bool msimode, int aia_guests, +DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests, uint32_t m_imsic_stride, uint32_t s_imsic_stride, uint16_t num_sources,
hw/riscv/tt_atlantis.c +2 -1
@@ -496,7 +496,8 @@ static void tt_atlantis_machine_init(MachineState *machine) &error_abort);sysbus_realize (SYS_BUS_DEVICE (&s->soc), &error_fatal); - s->irqchip = riscv_create_aia(true, TT_IMSIC_GUESTS, + s->irqchip = riscv_create_aia(system_memory, + true, TT_IMSIC_GUESTS, TT_IMSIC_STRIDE, TT_IMSIC_STRIDE, TT_IRQCHIP_NUM_SOURCES,
hw/riscv/virt.c +2 -1
@@ -1411,8 +1411,9 @@ static void virt_machine_init(MachineState *machine) s->irqchip[i] =virt_create_plic (s->memmap, i, base_hartid, hart_count); }else { +bool msimode = s->aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ;int imsic_bits =imsic_num_bits (s->aia_guests +1 ); - s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC, + s->irqchip[i] = riscv_create_aia(system_memory, msimode, s->aia_guests, IMSIC_HART_SIZE(0), IMSIC_HART_SIZE(imsic_bits),
Signature · 1 line
2.47.3
Re: [PATCH v2 01/16] hw/riscv/aia: Take a MemoryRegion for the created devices
Quoted 9 lines · Joel Stanley
Add a MemoryRegion parameter to
riscv_create_aia(), to be passed on to the IMSIC and APLIC helpers so a SoC can have the controllers mapped into its own memory container. Both callers passsystem_memory, so there is no change in behaviour.As the controllers don't yet take a MemoryRegion the parameter is not yet passed on. Changing
riscv_create_aiafirst avoids churn in the intermediate commits.
Quoted 7 lines
Signed-off-by Joel Stanley <[email protected]>--- hw/riscv/aia.h | 2 +- hw/riscv/aia.c | 2 +- hw/riscv/tt_atlantis.c | 3 ++- hw/riscv/virt.c | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-)
Re: [PATCH v2 01/16] hw/riscv/aia: Take a MemoryRegion for the created devices
In reply to Joel StanleyQuoted 7 lines · Joel Stanley
Add a MemoryRegion parameter to
riscv_create_aia(), to be passed on to
the IMSIC and APLIC helpers so a SoC can have the controllers mapped into its own memory container. Both callers passsystem_memory, so there
is no change in behaviour.
Quoted 5 lines
As the controllers don't yet take a MemoryRegion the parameter is not yet passed on. Changing
riscv_create_aiafirst avoids churn in the intermediate commits.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 69 lines
---
hw/riscv/aia.h | 2 +-
hw/riscv/aia.c | 2 +-
hw/riscv/tt_atlantis.c | 3 ++-
hw/riscv/virt.c | 3 ++-4 files changed, 6 insertions(+), 4 deletions(-)hw/riscv/aia.h +0
-0@@ -13,7 +13,7 @@
uint32_timsic_num_bits(uint32_t count);hw/riscv/aia.h +1
-1-DeviceState *riscv_create_aia(bool msimode, int aia_guests, +DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int
aia_guests,
uint32_tm_imsic_stride,uint32_ts_imsic_stride,uint16_tnum_sources,hw/riscv/aia.c +0
-0@@ -24,7 +24,7 @@ uint32_t imsic_num_bits(uint32_t count) return ret; }hw/riscv/aia.c +1
-1-DeviceState *riscv_create_aia(bool msimode, int aia_guests, +DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int
aia_guests,
uint32_tm_imsic_stride,uint32_ts_imsic_stride,uint16_tnum_sources,hw/riscv/tt_atlantis.c +0
-0@@ -496,7 +496,8 @@ static void tt_atlantis_machine_init(MachineState *machine) &error_abort); sysbus_realize(SYS_BUS_DEVICE(&s->soc), &error_fatal);
-s->irqchip= riscv_create_aia(true,TT_IMSIC_GUESTS, +s->irqchip= riscv_create_aia(system_memory, + true,TT_IMSIC_GUESTS,TT_IMSIC_STRIDE,TT_IMSIC_STRIDE,TT_IRQCHIP_NUM_SOURCES,hw/riscv/virt.c +2
-1@@ -1411,8 +1411,9 @@ static void virt_machine_init(MachineState *machine) s->irqchip[i] = virt_create_plic(s->memmap, i, base_hartid, hart_count); } else { + bool msimode = s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; int imsic_bits = imsic_num_bits(s->aia_guests + 1); - s->irqchip[i] = riscv_create_aia(s->aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC , + s->irqchip[i] = riscv_create_aia(system_memory, msimode,
s->aia_guests,IMSIC_HART_SIZE(0),IMSIC_HART_SIZE(imsic_bits),
PATCH v2 2/16 hw/intc/riscv_aclint: Take a MemoryRegion for the created devices
In reply to Joel StanleyThe riscv_aclint_mtimer_create() and riscv_aclint_swi_create() helpers map the device they create into system_memory, which prevents their use by SoCs that map devices into a memory container of their own.
Add a MemoryRegion parameter and map the device into it instead of calling sysbus_mmio_map(). All callers pass system_memory, so there is no change in behaviour.
--- include/hw/intc/riscv_aclint.h | 7 ++++--- hw/intc/riscv_aclint.c | 12 ++++++++---- hw/riscv/cps.c | 6 ++++-- hw/riscv/k230.c | 6 ++++-- hw/riscv/microchip_pfsoc.c | 5 +++-- hw/riscv/shakti_c.c | 7 ++++--- hw/riscv/sifive_e.c | 4 ++-- hw/riscv/sifive_u.c | 7 ++++--- hw/riscv/spike.c | 4 ++-- hw/riscv/tt_atlantis.c | 3 ++- hw/riscv/virt.c | 17 +++++++++++------ hw/riscv/xiangshan_kmh.c | 6 ++++-- 12 files changed, 52 insertions(+), 32 deletions(-)
include/hw/intc/riscv_aclint.h +4 -3
@@ -46,7 +46,8 @@ typedef struct RISCVAclintMTimerState {qemu_irq *timer_irqs; } RISCVAclintMTimerState; -DeviceState *riscv_aclint_mtimer_create (hwaddr addr,hwaddr size, +DeviceState *riscv_aclint_mtimer_create (MemoryRegion *mr, +hwaddr addr,hwaddr size,uint32_t hartid_base,uint32_t num_harts,uint32_t timecmp_base,uint32_t time_base,uint32_t timebase_freq,bool provide_rdtime);
@@ -68,8 +69,8 @@ typedef struct RISCVAclintSwiState {qemu_irq *soft_irqs; } RISCVAclintSwiState; -DeviceState *riscv_aclint_swi_create (hwaddr addr,uint32_t hartid_base, -uint32_t num_harts,bool sswi); +DeviceState *riscv_aclint_swi_create (MemoryRegion *mr, +hwaddr addr,uint32_t hartid_base,uint32_t num_harts,bool sswi);enum {RISCV_ACLINT_DEFAULT_MTIMECMP =0x0 ,
hw/intc/riscv_aclint.c +8 -4
@@ -371,7 +371,8 @@ static const TypeInfo riscv_aclint_mtimer_info = {/* * Create ACLINT MTIMER device. */ -DeviceState *riscv_aclint_mtimer_create (hwaddr addr,hwaddr size, +DeviceState *riscv_aclint_mtimer_create (MemoryRegion *mr, +hwaddr addr,hwaddr size,uint32_t hartid_base,uint32_t num_harts,uint32_t timecmp_base,uint32_t time_base,uint32_t timebase_freq,bool provide_rdtime)
@@ -392,7 +393,8 @@ DeviceState *riscv_aclint_mtimer_create(hwaddr addr, hwaddr size,qdev_prop_set_uint32 (dev,"aperture-size" , size);qdev_prop_set_uint32 (dev,"timebase-freq" , timebase_freq);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); +memory_region_add_subregion (mr, addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ));for (i =0 ; i < num_harts; i++) {CPUState *cpu =cpu_by_arch_id (hartid_base + i);
@@ -556,7 +558,8 @@ static const TypeInfo riscv_aclint_swi_info = {/* * Create ACLINT [M|S]SWI device. */ -DeviceState *riscv_aclint_swi_create (hwaddr addr,uint32_t hartid_base, +DeviceState *riscv_aclint_swi_create (MemoryRegion *mr, +hwaddr addr,uint32_t hartid_base,uint32_t num_harts,bool sswi) {int i;
@@ -569,7 +572,8 @@ DeviceState *riscv_aclint_swi_create(hwaddr addr, uint32_t hartid_base,qdev_prop_set_uint32 (dev,"num-harts" , num_harts);qdev_prop_set_uint32 (dev,"sswi" , sswi ? true : false);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); +memory_region_add_subregion (mr, addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ));for (i =0 ; i < num_harts; i++) {CPUState *cpu =cpu_by_arch_id (hartid_base + i);
hw/riscv/cps.c +4 -2
@@ -151,9 +151,11 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp) false, false, s->aplic);/* PLIC changes msi_nonbroken to ture. We revert the change. */ msi_nonbroken = false; -riscv_aclint_swi_create (cm_base +AIA_CLINT_OFFSET , +riscv_aclint_swi_create (get_system_memory (), + cm_base +AIA_CLINT_OFFSET , hartid_base,MAX_HARTS , false); - riscv_aclint_mtimer_create(cm_base + AIA_CLINT_OFFSET + + riscv_aclint_mtimer_create(get_system_memory(), + cm_base + AIA_CLINT_OFFSET + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, hartid_base,
hw/riscv/k230.c +4 -2
@@ -196,9 +196,11 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) s->c908_plic =k230_create_plic (C908_CPU_HARTID , c908_cpus);/* CLINT */ -riscv_aclint_swi_create (memmap[K230_DEV_CLINT ].base, +riscv_aclint_swi_create (sys_mem, + memmap[K230_DEV_CLINT ].base,C908_CPU_HARTID , c908_cpus, false); - riscv_aclint_mtimer_create(memmap[K230_DEV_CLINT].base + 0x4000, + riscv_aclint_mtimer_create(sys_mem, + memmap[K230_DEV_CLINT].base + 0x4000, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, C908_CPU_HARTID, c908_cpus, RISCV_ACLINT_DEFAULT_MTIMECMP,
hw/riscv/microchip_pfsoc.c +3 -2
@@ -250,9 +250,10 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) memmap[MICROCHIP_PFSOC_BUSERR_UNIT4].size);/* CLINT */ -riscv_aclint_swi_create (memmap[MICROCHIP_PFSOC_CLINT ].base, +riscv_aclint_swi_create (system_memory, + memmap[MICROCHIP_PFSOC_CLINT ].base,0 , ms->smp.cpus, false); - riscv_aclint_mtimer_create( + riscv_aclint_mtimer_create(system_memory, memmap[MICROCHIP_PFSOC_CLINT].base + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, ms->smp.cpus, RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,
hw/riscv/shakti_c.c +4 -3
@@ -127,10 +127,11 @@ static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp)SHAKTI_C_PLIC_CONTEXT_STRIDE , shakti_c_memmap[SHAKTI_C_PLIC].size); -riscv_aclint_swi_create (shakti_c_memmap[SHAKTI_C_CLINT ].base, +riscv_aclint_swi_create (system_memory, + shakti_c_memmap[SHAKTI_C_CLINT ].base,0 ,1 , false); -riscv_aclint_mtimer_create (shakti_c_memmap[SHAKTI_C_CLINT ].base + -RISCV_ACLINT_SWI_SIZE , +riscv_aclint_mtimer_create (system_memory, + shakti_c_memmap[SHAKTI_C_CLINT ].base +RISCV_ACLINT_SWI_SIZE ,RISCV_ACLINT_DEFAULT_MTIMER_SIZE ,0 ,1 ,RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME ,RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ , false);
hw/riscv/sifive_e.c +2 -2
@@ -225,9 +225,9 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)SIFIVE_E_PLIC_CONTEXT_BASE ,SIFIVE_E_PLIC_CONTEXT_STRIDE , memmap[SIFIVE_E_DEV_PLIC].size); -riscv_aclint_swi_create (memmap[SIFIVE_E_DEV_CLINT ].base, +riscv_aclint_swi_create (sys_mem, memmap[SIFIVE_E_DEV_CLINT ].base,0 , ms->smp.cpus, false); - riscv_aclint_mtimer_create(memmap[SIFIVE_E_DEV_CLINT].base + + riscv_aclint_mtimer_create(sys_mem, memmap[SIFIVE_E_DEV_CLINT].base + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, ms->smp.cpus, RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,
hw/riscv/sifive_u.c +4 -3
@@ -788,10 +788,11 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART0_IRQ));sifive_uart_create (system_memory, memmap[SIFIVE_U_DEV_UART1 ].base,serial_hd (1 ),qdev_get_gpio_in (DEVICE (s->plic),SIFIVE_U_UART1_IRQ )); -riscv_aclint_swi_create (memmap[SIFIVE_U_DEV_CLINT ].base,0 , +riscv_aclint_swi_create (system_memory, + memmap[SIFIVE_U_DEV_CLINT ].base,0 , ms->smp.cpus, false); -riscv_aclint_mtimer_create (memmap[SIFIVE_U_DEV_CLINT ].base + -RISCV_ACLINT_SWI_SIZE , +riscv_aclint_mtimer_create (system_memory, + memmap[SIFIVE_U_DEV_CLINT ].base +RISCV_ACLINT_SWI_SIZE ,RISCV_ACLINT_DEFAULT_MTIMER_SIZE ,0 , ms->smp.cpus,RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME ,CLINT_TIMEBASE_FREQ , false);
hw/riscv/spike.c +2 -2
@@ -163,10 +163,10 @@ static void spike_board_init(MachineState *machine)sysbus_realize (SYS_BUS_DEVICE (&s->soc[i]), &error_fatal);/* Core Local Interruptor (timer and IPI) for each socket */ -riscv_aclint_swi_create ( +riscv_aclint_swi_create (system_memory, memmap[SPIKE_CLINT ].base + i * memmap[SPIKE_CLINT ].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create( + riscv_aclint_mtimer_create(system_memory, memmap[SPIKE_CLINT].base + i * memmap[SPIKE_CLINT].size + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count,
hw/riscv/tt_atlantis.c +2 -1
@@ -509,7 +509,8 @@ static void tt_atlantis_machine_init(MachineState *machine)TT_IRQCHIP_NUM_MSIS , TT_IRQCHIP_NUM_PRIO_BITS); - riscv_aclint_mtimer_create(s->memmap[TT_ATL_ACLINT].base, + riscv_aclint_mtimer_create(system_memory, + s->memmap[TT_ATL_ACLINT].base, TT_ACLINT_MTIME_SIZE, 0, hart_count, TT_ACLINT_MTIMECMP,
hw/riscv/virt.c +11 -6
@@ -1370,7 +1370,8 @@ static void virt_machine_init(MachineState *machine)if (virt_aclint_allowed () && s->have_aclint) {if (s->aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ) {/* Per-socket ACLINT MTIMER */ - riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * RISCV_ACLINT_DEFAULT_MTIMER_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count,
@@ -1379,10 +1380,12 @@ static void virt_machine_init(MachineState *machine) RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); }else {/* Per-socket ACLINT MSWI, MTIMER, and SSWI */ -riscv_aclint_swi_create (s->memmap[VIRT_CLINT ].base + +riscv_aclint_swi_create (system_memory, + s->memmap[VIRT_CLINT ].base + i * s->memmap[VIRT_CLINT ].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * s->memmap[VIRT_CLINT].size + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE,
@@ -1390,16 +1393,18 @@ static void virt_machine_init(MachineState *machine)RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME , RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); -riscv_aclint_swi_create (s->memmap[VIRT_ACLINT_SSWI ].base + +riscv_aclint_swi_create (system_memory, + s->memmap[VIRT_ACLINT_SSWI ].base + i * s->memmap[VIRT_ACLINT_SSWI ].size, base_hartid, hart_count, true); } }else if (tcg_enabled ()) {/* Per-socket SiFive CLINT */ -riscv_aclint_swi_create ( +riscv_aclint_swi_create (system_memory, s->memmap[VIRT_CLINT ].base + i * s->memmap[VIRT_CLINT ].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * s->memmap[VIRT_CLINT].size + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,
hw/riscv/xiangshan_kmh.c +4 -2
@@ -116,9 +116,11 @@ static void xiangshan_kmh_soc_realize(DeviceState *dev, Error **errp) 115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);/* CLINT */ -riscv_aclint_swi_create (memmap[XIANGSHAN_KMH_CLINT ].base, +riscv_aclint_swi_create (system_memory, + memmap[XIANGSHAN_KMH_CLINT ].base,0 , num_harts, false); - riscv_aclint_mtimer_create(memmap[XIANGSHAN_KMH_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + memmap[XIANGSHAN_KMH_CLINT].base + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, num_harts, RISCV_ACLINT_DEFAULT_MTIMECMP,
Signature · 1 line
2.47.3
Re: [PATCH v2 02/16] hw/intc/riscv_aclint: Take a MemoryRegion for the created devices
Quoted 9 lines · Joel Stanley
The
riscv_aclint_mtimer_create()andriscv_aclint_swi_create()helpers map the device they create intosystem_memory, which prevents their use by SoCs that map devices into a memory container of their own.Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). All callers passsystem_memory, so there is no change in behaviour.Signed-off-by Joel Stanley <[email protected]>
Quoted 14 lines
--- include/hw/intc/riscv_aclint.h | 7 ++++--- hw/intc/riscv_aclint.c | 12 ++++++++---- hw/riscv/cps.c | 6 ++++-- hw/riscv/k230.c | 6 ++++-- hw/riscv/microchip_pfsoc.c | 5 +++-- hw/riscv/shakti_c.c | 7 ++++--- hw/riscv/sifive_e.c | 4 ++-- hw/riscv/sifive_u.c | 7 ++++--- hw/riscv/spike.c | 4 ++-- hw/riscv/tt_atlantis.c | 3 ++- hw/riscv/virt.c | 17 +++++++++++------ hw/riscv/xiangshan_kmh.c | 6 ++++-- 12 files changed, 52 insertions(+), 32 deletions(-)
Re: [PATCH v2 02/16] hw/intc/riscv_aclint: Take a MemoryRegion for the created devices
In reply to Joel StanleyQuoted 84 lines · Joel Stanley
The
riscv_aclint_mtimer_create()andriscv_aclint_swi_create()helpers map the device they create intosystem_memory, which prevents their use by SoCs that map devices into a memory container of their own.Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). All callers passsystem_memory, so there is no change in behaviour.Signed-off-by Joel Stanley <[email protected]>--- include/hw/intc/riscv_aclint.h | 7 ++++--- hw/intc/riscv_aclint.c | 12 ++++++++---- hw/riscv/cps.c | 6 ++++-- hw/riscv/k230.c | 6 ++++-- hw/riscv/microchip_pfsoc.c | 5 +++-- hw/riscv/shakti_c.c | 7 ++++--- hw/riscv/sifive_e.c | 4 ++-- hw/riscv/sifive_u.c | 7 ++++--- hw/riscv/spike.c | 4 ++-- hw/riscv/tt_atlantis.c | 3 ++- hw/riscv/virt.c | 17 +++++++++++------ hw/riscv/xiangshan_kmh.c | 6 ++++-- 12 files changed, 52 insertions(+), 32 deletions(-)include/hw/intc/riscv_aclint.h +4
-3@@ -46,7 +46,8 @@ typedef struct RISCVAclintMTimerState {qemu_irq *timer_irqs; } RISCVAclintMTimerState; -DeviceState *riscv_aclint_mtimer_create (hwaddr addr,hwaddr size, +DeviceState *riscv_aclint_mtimer_create (MemoryRegion *mr, +hwaddr addr,hwaddr size,uint32_t hartid_base,uint32_t num_harts,uint32_t timecmp_base,uint32_t time_base,uint32_t timebase_freq,bool provide_rdtime);@@ -68,8 +69,8 @@ typedef struct RISCVAclintSwiState {qemu_irq *soft_irqs; } RISCVAclintSwiState; -DeviceState *riscv_aclint_swi_create (hwaddr addr,uint32_t hartid_base, -uint32_t num_harts,bool sswi); +DeviceState *riscv_aclint_swi_create (MemoryRegion *mr, +hwaddr addr,uint32_t hartid_base,uint32_t num_harts,bool sswi);enum {RISCV_ACLINT_DEFAULT_MTIMECMP =0x0 ,hw/intc/riscv_aclint.c +6
-3@@ -371,7 +371,8 @@ static const TypeInfo riscv_aclint_mtimer_info = {/* * Create ACLINT MTIMER device. */ -DeviceState *riscv_aclint_mtimer_create (hwaddr addr,hwaddr size, +DeviceState *riscv_aclint_mtimer_create (MemoryRegion *mr, +hwaddr addr,hwaddr size,uint32_t hartid_base,uint32_t num_harts,uint32_t timecmp_base,uint32_t time_base,uint32_t timebase_freq,bool provide_rdtime)@@ -392,7 +393,8 @@ DeviceState *riscv_aclint_mtimer_create(hwaddr addr, hwaddr size,qdev_prop_set_uint32 (dev,"aperture-size" , size);qdev_prop_set_uint32 (dev,"timebase-freq" , timebase_freq);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); +memory_region_add_subregion (mr, addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ));for (i =0 ; i < num_harts; i++) {CPUState *cpu =cpu_by_arch_id (hartid_base + i);@@ -556,7 +558,8 @@ static const TypeInfo riscv_aclint_swi_info = {/* * Create ACLINT [M|S]SWI device. */ -DeviceState *riscv_aclint_swi_create (hwaddr addr,uint32_t hartid_base, +DeviceState *riscv_aclint_swi_create (MemoryRegion *mr, +hwaddr addr,uint32_t hartid_base,uint32_t num_harts,bool sswi) {int i;
hw/intc/riscv_aclint.c DeviceState *riscv_aclint_swi_create(hwaddr addr, uint32_t hartid_base, · line 573
Quoted 2 lines
hw/intc/riscv_aclint.c +0
-0@@ -569,7 +572,8 @@ DeviceState *riscv_aclint_swi_create(hwaddr addr, uint32_t hartid_base,qdev_prop_set_uint32 (dev,"num-harts" , num_harts);qdev_prop_set_uint32 (dev,"sswi" , sswi ? true : false);
let 'true' be 'true' !
Cheers,
C.
Quoted 214 lines
hw/intc/riscv_aclint.c +2
-1sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); +memory_region_add_subregion (mr, addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ));for (i =0 ; i < num_harts; i++) {CPUState *cpu =cpu_by_arch_id (hartid_base + i);hw/riscv/cps.c +4
-2@@ -151,9 +151,11 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp) false, false, s->aplic);/* PLIC changes msi_nonbroken to ture. We revert the change. */ msi_nonbroken = false; -riscv_aclint_swi_create (cm_base +AIA_CLINT_OFFSET , +riscv_aclint_swi_create (get_system_memory (), + cm_base +AIA_CLINT_OFFSET , hartid_base,MAX_HARTS , false); - riscv_aclint_mtimer_create(cm_base + AIA_CLINT_OFFSET + + riscv_aclint_mtimer_create(get_system_memory(), + cm_base + AIA_CLINT_OFFSET + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, hartid_base,hw/riscv/k230.c +4
-2@@ -196,9 +196,11 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) s->c908_plic =k230_create_plic (C908_CPU_HARTID , c908_cpus);/* CLINT */ -riscv_aclint_swi_create (memmap[K230_DEV_CLINT ].base, +riscv_aclint_swi_create (sys_mem, + memmap[K230_DEV_CLINT ].base,C908_CPU_HARTID , c908_cpus, false); - riscv_aclint_mtimer_create(memmap[K230_DEV_CLINT].base + 0x4000, + riscv_aclint_mtimer_create(sys_mem, + memmap[K230_DEV_CLINT].base + 0x4000, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, C908_CPU_HARTID, c908_cpus, RISCV_ACLINT_DEFAULT_MTIMECMP,hw/riscv/microchip_pfsoc.c +3
-2@@ -250,9 +250,10 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) memmap[MICROCHIP_PFSOC_BUSERR_UNIT4].size);/* CLINT */ -riscv_aclint_swi_create (memmap[MICROCHIP_PFSOC_CLINT ].base, +riscv_aclint_swi_create (system_memory, + memmap[MICROCHIP_PFSOC_CLINT ].base,0 , ms->smp.cpus, false); - riscv_aclint_mtimer_create( + riscv_aclint_mtimer_create(system_memory, memmap[MICROCHIP_PFSOC_CLINT].base + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, ms->smp.cpus, RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,hw/riscv/shakti_c.c +4
-3@@ -127,10 +127,11 @@ static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp)SHAKTI_C_PLIC_CONTEXT_STRIDE , shakti_c_memmap[SHAKTI_C_PLIC].size); -riscv_aclint_swi_create (shakti_c_memmap[SHAKTI_C_CLINT ].base, +riscv_aclint_swi_create (system_memory, + shakti_c_memmap[SHAKTI_C_CLINT ].base,0 ,1 , false); -riscv_aclint_mtimer_create (shakti_c_memmap[SHAKTI_C_CLINT ].base + -RISCV_ACLINT_SWI_SIZE , +riscv_aclint_mtimer_create (system_memory, + shakti_c_memmap[SHAKTI_C_CLINT ].base +RISCV_ACLINT_SWI_SIZE ,RISCV_ACLINT_DEFAULT_MTIMER_SIZE ,0 ,1 ,RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME ,RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ , false);hw/riscv/sifive_e.c +2
-2@@ -225,9 +225,9 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)SIFIVE_E_PLIC_CONTEXT_BASE ,SIFIVE_E_PLIC_CONTEXT_STRIDE , memmap[SIFIVE_E_DEV_PLIC].size); -riscv_aclint_swi_create (memmap[SIFIVE_E_DEV_CLINT ].base, +riscv_aclint_swi_create (sys_mem, memmap[SIFIVE_E_DEV_CLINT ].base,0 , ms->smp.cpus, false); - riscv_aclint_mtimer_create(memmap[SIFIVE_E_DEV_CLINT].base + + riscv_aclint_mtimer_create(sys_mem, memmap[SIFIVE_E_DEV_CLINT].base + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, ms->smp.cpus, RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,hw/riscv/sifive_u.c +4
-3@@ -788,10 +788,11 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART0_IRQ));sifive_uart_create (system_memory, memmap[SIFIVE_U_DEV_UART1 ].base,serial_hd (1 ),qdev_get_gpio_in (DEVICE (s->plic),SIFIVE_U_UART1_IRQ )); -riscv_aclint_swi_create (memmap[SIFIVE_U_DEV_CLINT ].base,0 , +riscv_aclint_swi_create (system_memory, + memmap[SIFIVE_U_DEV_CLINT ].base,0 , ms->smp.cpus, false); -riscv_aclint_mtimer_create (memmap[SIFIVE_U_DEV_CLINT ].base + -RISCV_ACLINT_SWI_SIZE , +riscv_aclint_mtimer_create (system_memory, + memmap[SIFIVE_U_DEV_CLINT ].base +RISCV_ACLINT_SWI_SIZE ,RISCV_ACLINT_DEFAULT_MTIMER_SIZE ,0 , ms->smp.cpus,RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME ,CLINT_TIMEBASE_FREQ , false);hw/riscv/spike.c +2
-2@@ -163,10 +163,10 @@ static void spike_board_init(MachineState *machine)sysbus_realize (SYS_BUS_DEVICE (&s->soc[i]), &error_fatal);/* Core Local Interruptor (timer and IPI) for each socket */ -riscv_aclint_swi_create ( +riscv_aclint_swi_create (system_memory, memmap[SPIKE_CLINT ].base + i * memmap[SPIKE_CLINT ].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create( + riscv_aclint_mtimer_create(system_memory, memmap[SPIKE_CLINT].base + i * memmap[SPIKE_CLINT].size + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count,hw/riscv/tt_atlantis.c +2
-1@@ -509,7 +509,8 @@ static void tt_atlantis_machine_init(MachineState *machine)TT_IRQCHIP_NUM_MSIS , TT_IRQCHIP_NUM_PRIO_BITS); - riscv_aclint_mtimer_create(s->memmap[TT_ATL_ACLINT].base, + riscv_aclint_mtimer_create(system_memory, + s->memmap[TT_ATL_ACLINT].base, TT_ACLINT_MTIME_SIZE, 0, hart_count, TT_ACLINT_MTIMECMP,hw/riscv/virt.c +11
-6@@ -1370,7 +1370,8 @@ static void virt_machine_init(MachineState *machine)if (virt_aclint_allowed () && s->have_aclint) {if (s->aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ) {/* Per-socket ACLINT MTIMER */ - riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * RISCV_ACLINT_DEFAULT_MTIMER_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count,@@ -1379,10 +1380,12 @@ static void virt_machine_init(MachineState *machine) RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); }else {/* Per-socket ACLINT MSWI, MTIMER, and SSWI */ -riscv_aclint_swi_create (s->memmap[VIRT_CLINT ].base + +riscv_aclint_swi_create (system_memory, + s->memmap[VIRT_CLINT ].base + i * s->memmap[VIRT_CLINT ].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * s->memmap[VIRT_CLINT].size + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE,@@ -1390,16 +1393,18 @@ static void virt_machine_init(MachineState *machine)RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME , RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); -riscv_aclint_swi_create (s->memmap[VIRT_ACLINT_SSWI ].base + +riscv_aclint_swi_create (system_memory, + s->memmap[VIRT_ACLINT_SSWI ].base + i * s->memmap[VIRT_ACLINT_SSWI ].size, base_hartid, hart_count, true); } }else if (tcg_enabled ()) {/* Per-socket SiFive CLINT */ -riscv_aclint_swi_create ( +riscv_aclint_swi_create (system_memory, s->memmap[VIRT_CLINT ].base + i * s->memmap[VIRT_CLINT ].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * s->memmap[VIRT_CLINT].size + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,hw/riscv/xiangshan_kmh.c +4
-2@@ -116,9 +116,11 @@ static void xiangshan_kmh_soc_realize(DeviceState *dev, Error **errp) 115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);/* CLINT */ -riscv_aclint_swi_create (memmap[XIANGSHAN_KMH_CLINT ].base, +riscv_aclint_swi_create (system_memory, + memmap[XIANGSHAN_KMH_CLINT ].base,0 , num_harts, false); - riscv_aclint_mtimer_create(memmap[XIANGSHAN_KMH_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + memmap[XIANGSHAN_KMH_CLINT].base + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, num_harts, RISCV_ACLINT_DEFAULT_MTIMECMP,
Re: [PATCH v2 02/16] hw/intc/riscv_aclint: Take a MemoryRegion for the created devices
In reply to Joel StanleyQuoted 3 lines · Joel Stanley
The
riscv_aclint_mtimer_create()andriscv_aclint_swi_create()helpers map the device they create intosystem_memory, which prevents their use by SoCs that map devices into a memory container of their own.
Since these routines are going to be used later on in a realize() handler, I would add a 'Error **errp' parameter.
Cheers,
C.
Quoted 297 lines
Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). All callers passsystem_memory, so there is no change in behaviour.Signed-off-by Joel Stanley <[email protected]>--- include/hw/intc/riscv_aclint.h | 7 ++++--- hw/intc/riscv_aclint.c | 12 ++++++++---- hw/riscv/cps.c | 6 ++++-- hw/riscv/k230.c | 6 ++++-- hw/riscv/microchip_pfsoc.c | 5 +++-- hw/riscv/shakti_c.c | 7 ++++--- hw/riscv/sifive_e.c | 4 ++-- hw/riscv/sifive_u.c | 7 ++++--- hw/riscv/spike.c | 4 ++-- hw/riscv/tt_atlantis.c | 3 ++- hw/riscv/virt.c | 17 +++++++++++------ hw/riscv/xiangshan_kmh.c | 6 ++++-- 12 files changed, 52 insertions(+), 32 deletions(-)include/hw/intc/riscv_aclint.h +4
-3@@ -46,7 +46,8 @@ typedef struct RISCVAclintMTimerState {qemu_irq *timer_irqs; } RISCVAclintMTimerState; -DeviceState *riscv_aclint_mtimer_create (hwaddr addr,hwaddr size, +DeviceState *riscv_aclint_mtimer_create (MemoryRegion *mr, +hwaddr addr,hwaddr size,uint32_t hartid_base,uint32_t num_harts,uint32_t timecmp_base,uint32_t time_base,uint32_t timebase_freq,bool provide_rdtime);@@ -68,8 +69,8 @@ typedef struct RISCVAclintSwiState {qemu_irq *soft_irqs; } RISCVAclintSwiState; -DeviceState *riscv_aclint_swi_create (hwaddr addr,uint32_t hartid_base, -uint32_t num_harts,bool sswi); +DeviceState *riscv_aclint_swi_create (MemoryRegion *mr, +hwaddr addr,uint32_t hartid_base,uint32_t num_harts,bool sswi);enum {RISCV_ACLINT_DEFAULT_MTIMECMP =0x0 ,hw/intc/riscv_aclint.c +8
-4@@ -371,7 +371,8 @@ static const TypeInfo riscv_aclint_mtimer_info = {/* * Create ACLINT MTIMER device. */ -DeviceState *riscv_aclint_mtimer_create (hwaddr addr,hwaddr size, +DeviceState *riscv_aclint_mtimer_create (MemoryRegion *mr, +hwaddr addr,hwaddr size,uint32_t hartid_base,uint32_t num_harts,uint32_t timecmp_base,uint32_t time_base,uint32_t timebase_freq,bool provide_rdtime)@@ -392,7 +393,8 @@ DeviceState *riscv_aclint_mtimer_create(hwaddr addr, hwaddr size,qdev_prop_set_uint32 (dev,"aperture-size" , size);qdev_prop_set_uint32 (dev,"timebase-freq" , timebase_freq);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); +memory_region_add_subregion (mr, addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ));for (i =0 ; i < num_harts; i++) {CPUState *cpu =cpu_by_arch_id (hartid_base + i);@@ -556,7 +558,8 @@ static const TypeInfo riscv_aclint_swi_info = {/* * Create ACLINT [M|S]SWI device. */ -DeviceState *riscv_aclint_swi_create (hwaddr addr,uint32_t hartid_base, +DeviceState *riscv_aclint_swi_create (MemoryRegion *mr, +hwaddr addr,uint32_t hartid_base,uint32_t num_harts,bool sswi) {int i;@@ -569,7 +572,8 @@ DeviceState *riscv_aclint_swi_create(hwaddr addr, uint32_t hartid_base,qdev_prop_set_uint32 (dev,"num-harts" , num_harts);qdev_prop_set_uint32 (dev,"sswi" , sswi ? true : false);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); +memory_region_add_subregion (mr, addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ));for (i =0 ; i < num_harts; i++) {CPUState *cpu =cpu_by_arch_id (hartid_base + i);hw/riscv/cps.c +4
-2@@ -151,9 +151,11 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp) false, false, s->aplic);/* PLIC changes msi_nonbroken to ture. We revert the change. */ msi_nonbroken = false; -riscv_aclint_swi_create (cm_base +AIA_CLINT_OFFSET , +riscv_aclint_swi_create (get_system_memory (), + cm_base +AIA_CLINT_OFFSET , hartid_base,MAX_HARTS , false); - riscv_aclint_mtimer_create(cm_base + AIA_CLINT_OFFSET + + riscv_aclint_mtimer_create(get_system_memory(), + cm_base + AIA_CLINT_OFFSET + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, hartid_base,hw/riscv/k230.c +4
-2@@ -196,9 +196,11 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) s->c908_plic =k230_create_plic (C908_CPU_HARTID , c908_cpus);/* CLINT */ -riscv_aclint_swi_create (memmap[K230_DEV_CLINT ].base, +riscv_aclint_swi_create (sys_mem, + memmap[K230_DEV_CLINT ].base,C908_CPU_HARTID , c908_cpus, false); - riscv_aclint_mtimer_create(memmap[K230_DEV_CLINT].base + 0x4000, + riscv_aclint_mtimer_create(sys_mem, + memmap[K230_DEV_CLINT].base + 0x4000, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, C908_CPU_HARTID, c908_cpus, RISCV_ACLINT_DEFAULT_MTIMECMP,hw/riscv/microchip_pfsoc.c +3
-2@@ -250,9 +250,10 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) memmap[MICROCHIP_PFSOC_BUSERR_UNIT4].size);/* CLINT */ -riscv_aclint_swi_create (memmap[MICROCHIP_PFSOC_CLINT ].base, +riscv_aclint_swi_create (system_memory, + memmap[MICROCHIP_PFSOC_CLINT ].base,0 , ms->smp.cpus, false); - riscv_aclint_mtimer_create( + riscv_aclint_mtimer_create(system_memory, memmap[MICROCHIP_PFSOC_CLINT].base + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, ms->smp.cpus, RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,hw/riscv/shakti_c.c +4
-3@@ -127,10 +127,11 @@ static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp)SHAKTI_C_PLIC_CONTEXT_STRIDE , shakti_c_memmap[SHAKTI_C_PLIC].size); -riscv_aclint_swi_create (shakti_c_memmap[SHAKTI_C_CLINT ].base, +riscv_aclint_swi_create (system_memory, + shakti_c_memmap[SHAKTI_C_CLINT ].base,0 ,1 , false); -riscv_aclint_mtimer_create (shakti_c_memmap[SHAKTI_C_CLINT ].base + -RISCV_ACLINT_SWI_SIZE , +riscv_aclint_mtimer_create (system_memory, + shakti_c_memmap[SHAKTI_C_CLINT ].base +RISCV_ACLINT_SWI_SIZE ,RISCV_ACLINT_DEFAULT_MTIMER_SIZE ,0 ,1 ,RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME ,RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ , false);hw/riscv/sifive_e.c +2
-2@@ -225,9 +225,9 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)SIFIVE_E_PLIC_CONTEXT_BASE ,SIFIVE_E_PLIC_CONTEXT_STRIDE , memmap[SIFIVE_E_DEV_PLIC].size); -riscv_aclint_swi_create (memmap[SIFIVE_E_DEV_CLINT ].base, +riscv_aclint_swi_create (sys_mem, memmap[SIFIVE_E_DEV_CLINT ].base,0 , ms->smp.cpus, false); - riscv_aclint_mtimer_create(memmap[SIFIVE_E_DEV_CLINT].base + + riscv_aclint_mtimer_create(sys_mem, memmap[SIFIVE_E_DEV_CLINT].base + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, ms->smp.cpus, RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,hw/riscv/sifive_u.c +4
-3@@ -788,10 +788,11 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART0_IRQ));sifive_uart_create (system_memory, memmap[SIFIVE_U_DEV_UART1 ].base,serial_hd (1 ),qdev_get_gpio_in (DEVICE (s->plic),SIFIVE_U_UART1_IRQ )); -riscv_aclint_swi_create (memmap[SIFIVE_U_DEV_CLINT ].base,0 , +riscv_aclint_swi_create (system_memory, + memmap[SIFIVE_U_DEV_CLINT ].base,0 , ms->smp.cpus, false); -riscv_aclint_mtimer_create (memmap[SIFIVE_U_DEV_CLINT ].base + -RISCV_ACLINT_SWI_SIZE , +riscv_aclint_mtimer_create (system_memory, + memmap[SIFIVE_U_DEV_CLINT ].base +RISCV_ACLINT_SWI_SIZE ,RISCV_ACLINT_DEFAULT_MTIMER_SIZE ,0 , ms->smp.cpus,RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME ,CLINT_TIMEBASE_FREQ , false);hw/riscv/spike.c +2
-2@@ -163,10 +163,10 @@ static void spike_board_init(MachineState *machine)sysbus_realize (SYS_BUS_DEVICE (&s->soc[i]), &error_fatal);/* Core Local Interruptor (timer and IPI) for each socket */ -riscv_aclint_swi_create ( +riscv_aclint_swi_create (system_memory, memmap[SPIKE_CLINT ].base + i * memmap[SPIKE_CLINT ].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create( + riscv_aclint_mtimer_create(system_memory, memmap[SPIKE_CLINT].base + i * memmap[SPIKE_CLINT].size + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count,hw/riscv/tt_atlantis.c +2
-1@@ -509,7 +509,8 @@ static void tt_atlantis_machine_init(MachineState *machine)TT_IRQCHIP_NUM_MSIS , TT_IRQCHIP_NUM_PRIO_BITS); - riscv_aclint_mtimer_create(s->memmap[TT_ATL_ACLINT].base, + riscv_aclint_mtimer_create(system_memory, + s->memmap[TT_ATL_ACLINT].base, TT_ACLINT_MTIME_SIZE, 0, hart_count, TT_ACLINT_MTIMECMP,hw/riscv/virt.c +11
-6@@ -1370,7 +1370,8 @@ static void virt_machine_init(MachineState *machine)if (virt_aclint_allowed () && s->have_aclint) {if (s->aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ) {/* Per-socket ACLINT MTIMER */ - riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * RISCV_ACLINT_DEFAULT_MTIMER_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count,@@ -1379,10 +1380,12 @@ static void virt_machine_init(MachineState *machine) RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); }else {/* Per-socket ACLINT MSWI, MTIMER, and SSWI */ -riscv_aclint_swi_create (s->memmap[VIRT_CLINT ].base + +riscv_aclint_swi_create (system_memory, + s->memmap[VIRT_CLINT ].base + i * s->memmap[VIRT_CLINT ].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * s->memmap[VIRT_CLINT].size + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE,@@ -1390,16 +1393,18 @@ static void virt_machine_init(MachineState *machine)RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME , RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); -riscv_aclint_swi_create (s->memmap[VIRT_ACLINT_SSWI ].base + +riscv_aclint_swi_create (system_memory, + s->memmap[VIRT_ACLINT_SSWI ].base + i * s->memmap[VIRT_ACLINT_SSWI ].size, base_hartid, hart_count, true); } }else if (tcg_enabled ()) {/* Per-socket SiFive CLINT */ -riscv_aclint_swi_create ( +riscv_aclint_swi_create (system_memory, s->memmap[VIRT_CLINT ].base + i * s->memmap[VIRT_CLINT ].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * s->memmap[VIRT_CLINT].size + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,hw/riscv/xiangshan_kmh.c +4
-2@@ -116,9 +116,11 @@ static void xiangshan_kmh_soc_realize(DeviceState *dev, Error **errp) 115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);/* CLINT */ -riscv_aclint_swi_create (memmap[XIANGSHAN_KMH_CLINT ].base, +riscv_aclint_swi_create (system_memory, + memmap[XIANGSHAN_KMH_CLINT ].base,0 , num_harts, false); - riscv_aclint_mtimer_create(memmap[XIANGSHAN_KMH_CLINT].base + + riscv_aclint_mtimer_create(system_memory, + memmap[XIANGSHAN_KMH_CLINT].base + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, num_harts, RISCV_ACLINT_DEFAULT_MTIMECMP,
Re: [PATCH v2 02/16] hw/intc/riscv_aclint: Take a MemoryRegion for the created devices
Quoted 8 lines · Cédric Le Goater
Quoted 3 lines · Joel Stanley
The
riscv_aclint_mtimer_create()andriscv_aclint_swi_create()helpers map the device they create intosystem_memory, which prevents their use by SoCs that map devices into a memory container of their own.Since these routines are going to be used later on in a
realize()handler, I would add a 'Error **errp' parameter.
Seems like a reasonable thing to do.
I started having a look at this and plumbing through errp is a bit more involved. I think I'll do that as it's own series as a follow up to this one.
Cheers,
Joel
Re: [PATCH v2 02/16] hw/intc/riscv_aclint: Take a MemoryRegion for the created devices
In reply to Joel StanleyQuoted 6 lines · Joel Stanley
The
riscv_aclint_mtimer_create()andriscv_aclint_swi_create()helpers
map the device they create intosystem_memory, which prevents their use
by SoCs that map devices into a memory container of their own.
Quoted 6 lines
Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). All callers passsystem_memory, so there is
no change in behaviour.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 330 lines
---
include/hw/intc/riscv_aclint.h | 7 ++++---
hw/intc/riscv_aclint.c | 12 ++++++++----
hw/riscv/cps.c | 6 ++++--
hw/riscv/k230.c | 6 ++++--
hw/riscv/microchip_pfsoc.c | 5 +++--hw/riscv/shakti_c.c | 7 ++++--- hw/riscv/sifive_e.c | 4 ++-- hw/riscv/sifive_u.c | 7 ++++---hw/riscv/spike.c | 4 ++-- hw/riscv/tt_atlantis.c | 3 ++- hw/riscv/virt.c | 17 +++++++++++------ hw/riscv/xiangshan_kmh.c | 6 ++++--
12 files changed, 52 insertions(+), 32 deletions(-)include/hw/intc/riscv_aclint.h +0
-0@@ -46,7 +46,8 @@ typedef struct RISCVAclintMTimerState { qemu_irq *timer_irqs; } RISCVAclintMTimerState;include/hw/intc/riscv_aclint.h +2
-1-DeviceState *riscv_aclint_mtimer_create(hwaddr addr, hwaddr size, +DeviceState *riscv_aclint_mtimer_create(MemoryRegion *mr, + hwaddr addr, hwaddr size,
uint32_thartid_base,uint32_tnum_harts,uint32_ttimecmp_base,uint32_ttime_base,uint32_ttimebase_freq,
boolprovide_rdtime);include/hw/intc/riscv_aclint.h +0
-0@@ -68,8 +69,8 @@ typedef struct RISCVAclintSwiState { qemu_irq *soft_irqs; } RISCVAclintSwiState;
-DeviceState *riscv_aclint_swi_create(hwaddr addr,uint32_thartid_base,
-uint32_tnum_harts, bool sswi);
+DeviceState *riscv_aclint_swi_create(MemoryRegion *mr, + hwaddr addr,uint32_thartid_base,uint32_tnum_harts, bool sswi);
enum {
RISCV_ACLINT_DEFAULT_MTIMECMP =0x0,hw/intc/riscv_aclint.c +2
-1@@ -371,7 +371,8 @@ static const TypeInfo riscv_aclint_mtimer_info = { /** Create ACLINT MTIMER device. */ -DeviceState *riscv_aclint_mtimer_create(hwaddr addr, hwaddr size, +DeviceState *riscv_aclint_mtimer_create(MemoryRegion *mr, + hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts,
uint32_ttimecmp_base,uint32_ttime_base,uint32_ttimebase_freq,
boolprovide_rdtime)hw/intc/riscv_aclint.c +2
-1@@ -392,7 +393,8 @@ DeviceState *riscv_aclint_mtimer_create(hwaddr addr, hwaddr size, qdev_prop_set_uint32(dev, "aperture-size", size); qdev_prop_set_uint32(dev, "timebase-freq", timebase_freq); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + memory_region_add_subregion(mr, addr, + sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
for (i = 0; i <num_harts; i++) {
CPUState *cpu =cpu_by_arch_id(hartid_base + i);hw/intc/riscv_aclint.c +2
-1@@ -556,7 +558,8 @@ static const TypeInfo riscv_aclint_swi_info = { /** Create ACLINT [M|S]SWI device. */ -DeviceState *riscv_aclint_swi_create (hwaddr addr,uint32_t hartid_base, +DeviceState *riscv_aclint_swi_create (MemoryRegion *mr, + hwaddr addr, uint32_t hartid_base, uint32_t num_harts, bool sswi) {int i;
hw/intc/riscv_aclint.c +2
-1@@ -569,7 +572,8 @@ DeviceState *riscv_aclint_swi_create(hwaddr addr,uint32_t hartid_base, qdev_prop_set_uint32(dev, "num-harts", num_harts); qdev_prop_set_uint32(dev, "sswi", sswi ? true : false); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + memory_region_add_subregion(mr, addr, + sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
for (i = 0; i <num_harts; i++) {
CPUState *cpu =cpu_by_arch_id(hartid_base + i);hw/riscv/cps.c +4
-2@@ -151,9 +151,11 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp) false, false, s->aplic); /* PLIC changes msi_nonbroken to ture. We revert the change. */ msi_nonbroken = false; - riscv_aclint_swi_create(cm_base + AIA_CLINT_OFFSET, + riscv_aclint_swi_create(get_system_memory(), + cm_base + AIA_CLINT_OFFSET, hartid_base, MAX_HARTS, false); - riscv_aclint_mtimer_create(cm_base + AIA_CLINT_OFFSET + + riscv_aclint_mtimer_create(get_system_memory(), + cm_base + AIA_CLINT_OFFSET + RISCV_ACLINT_SWI_SIZE,
RISCV_ACLINT_DEFAULT_MTIMER_SIZE,hartid_base,hw/riscv/k230.c +0
-0@@ -196,9 +196,11 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) s->c908_plic = k230_create_plic(C908_CPU_HARTID, c908_cpus);
/* CLINT */
- riscv_aclint_swi_create(memmap[K230_DEV_CLINT].base, + riscv_aclint_swi_create(sys_mem,
+ memmap[K230_DEV_CLINT].base,C908_CPU_HARTID,c908_cpus, false); - riscv_aclint_mtimer_create(memmap[K230_DEV_CLINT].base +0x4000, + riscv_aclint_mtimer_create(sys_mem,
+ memmap[K230_DEV_CLINT].base +0x4000,RISCV_ACLINT_DEFAULT_MTIMER_SIZE,C908_CPU_HARTID,c908_cpus,RISCV_ACLINT_DEFAULT_MTIMECMP,hw/riscv/microchip_pfsoc.c +0
-0@@ -250,9 +250,10 @@ static voidmicrochip_pfsoc_soc_realize (DeviceState *dev, Error **errp) memmap[MICROCHIP_PFSOC_BUSERR_UNIT4].size);
/* CLINT */
- riscv_aclint_swi_create(memmap[MICROCHIP_PFSOC_CLINT].base, + riscv_aclint_swi_create(system_memory,
+ memmap[MICROCHIP_PFSOC_CLINT].base,
0,ms->smp.cpus, false);
- riscv_aclint_mtimer_create(
+ riscv_aclint_mtimer_create(system_memory, memmap[MICROCHIP_PFSOC_CLINT].base +RISCV_ACLINT_SWI_SIZE,RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0,ms->smp.cpus,RISCV_ACLINT_DEFAULT_MTIMECMP,RISCV_ACLINT_DEFAULT_MTIME,hw/riscv/shakti_c.c +0
-0@@ -127,10 +127,11 @@ static voidshakti_c_soc_state_realize (DeviceState *dev, Error **errp) SHAKTI_C_PLIC_CONTEXT_STRIDE, shakti_c_memmap[SHAKTI_C_PLIC].size);
- riscv_aclint_swi_create(shakti_c_memmap[SHAKTI_C_CLINT].base, + riscv_aclint_swi_create(system_memory,
+ shakti_c_memmap[SHAKTI_C_CLINT].base,
0, 1, false);
- riscv_aclint_mtimer_create(shakti_c_memmap[SHAKTI_C_CLINT].base +
-RISCV_ACLINT_SWI_SIZE,
+ riscv_aclint_mtimer_create(system_memory,
+ shakti_c_memmap[SHAKTI_C_CLINT].base +RISCV_ACLINT_SWI_SIZE,
RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, 1,RISCV_ACLINT_DEFAULT_MTIMECMP,RISCV_ACLINT_DEFAULT_MTIME,RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, false);hw/riscv/sifive_e.c +2
-2@@ -225,9 +225,9 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp) SIFIVE_E_PLIC_CONTEXT_BASE, SIFIVE_E_PLIC_CONTEXT_STRIDE, memmap[SIFIVE_E_DEV_PLIC].size); - riscv_aclint_swi_create(memmap[SIFIVE_E_DEV_CLINT].base, + riscv_aclint_swi_create(sys_mem, memmap[SIFIVE_E_DEV_CLINT ].base, 0, ms->smp.cpus, false); - riscv_aclint_mtimer_create(memmap[SIFIVE_E_DEV_CLINT].base + + riscv_aclint_mtimer_create(sys_mem,memmap[SIFIVE_E_DEV_CLINT].base +
RISCV_ACLINT_SWI_SIZE,RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0,ms->smp.cpus,RISCV_ACLINT_DEFAULT_MTIMECMP,RISCV_ACLINT_DEFAULT_MTIME,hw/riscv/sifive_u.c +4
-3@@ -788,10 +788,11 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART0_IRQ)); sifive_uart_create(system_memory, memmap[SIFIVE_U_DEV_UART1 ].base, serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic),SIFIVE_U_UART1_IRQ )); - riscv_aclint_swi_create(memmap[SIFIVE_U_DEV_CLINT].base, 0, + riscv_aclint_swi_create(system_memory, + memmap[SIFIVE_U_DEV_CLINT].base, 0, ms->smp.cpus, false); - riscv_aclint_mtimer_create(memmap[SIFIVE_U_DEV_CLINT].base + - RISCV_ACLINT_SWI_SIZE, + riscv_aclint_mtimer_create(system_memory, + memmap[SIFIVE_U_DEV_CLINT].base + RISCV_ACLINT_SWI_SIZE,
RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0,ms->smp.cpus,RISCV_ACLINT_DEFAULT_MTIMECMP,RISCV_ACLINT_DEFAULT_MTIME,CLINT_TIMEBASE_FREQ, false);hw/riscv/spike.c +0
-0@@ -163,10 +163,10 @@ static void spike_board_init(MachineState *machine) sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal);
/* Core Local Interruptor (timer and IPI) for each socket */ - riscv_aclint_swi_create(
+ riscv_aclint_swi_create(system_memory, memmap[SPIKE_CLINT].base + i * memmap[SPIKE_CLINT].size,base_hartid,hart_count, false);
- riscv_aclint_mtimer_create(
+ riscv_aclint_mtimer_create(system_memory, memmap[SPIKE_CLINT].base + i * memmap[SPIKE_CLINT].size +
RISCV_ACLINT_SWI_SIZE,RISCV_ACLINT_DEFAULT_MTIMER_SIZE,base_hartid,hart_count,hw/riscv/tt_atlantis.c +0
-0@@ -509,7 +509,8 @@ static void tt_atlantis_machine_init(MachineState *machine) TT_IRQCHIP_NUM_MSIS, TT_IRQCHIP_NUM_PRIO_BITS);
- riscv_aclint_mtimer_create(s->memmap[TT_ATL_ACLINT].base, + riscv_aclint_mtimer_create(system_memory,
+ s->memmap[TT_ATL_ACLINT].base,TT_ACLINT_MTIME_SIZE,
0,hart_count,
TT_ACLINT_MTIMECMP,hw/riscv/virt.c +0
-1@@ -1370,7 +1370,8 @@ static void virt_machine_init(MachineState *machine) if (virt_aclint_allowed() && s->have_aclint) { if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) { /* Per-socket ACLINT MTIMER */ - riscv_aclint_mtimer_create(s-Quoted 1 line
memmap[VIRT_CLINT].base +
+ riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base +
i *RISCV_ACLINT_DEFAULT_MTIMER_SIZE,RISCV_ACLINT_DEFAULT_MTIMER_SIZE,base_hartid,hart_count,hw/riscv/virt.c +2
-2@@ -1379,10 +1380,12 @@ static void virt_machine_init(MachineState *machine) RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); } else { /* Per-socket ACLINT MSWI, MTIMER, and SSWI */ - riscv_aclint_swi_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_swi_create(system_memory, + s->memmap[VIRT_CLINT].base + i * s->memmap[VIRT_CLINT].size, base_hartid, hart_count, false); - riscv_aclint_mtimer_create(s-Quoted 1 line
memmap[VIRT_CLINT].base +
+ riscv_aclint_mtimer_create(system_memory, + s->memmap[VIRT_CLINT].base + i * s->memmap[VIRT_CLINT].size +
RISCV_ACLINT_SWI_SIZE,RISCV_ACLINT_DEFAULT_MTIMER_SIZE,hw/riscv/virt.c +0
-1@@ -1390,16 +1393,18 @@ static void virt_machine_init(MachineState *machine) RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME, RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); - riscv_aclint_swi_create(s-Quoted 1 line
memmap[VIRT_ACLINT_SSWI].base +
+ riscv_aclint_swi_create(system_memory, + s->memmap[VIRT_ACLINT_SSWI].base + i * s->memmap[VIRT_ACLINT_SSWI].size,
base_hartid,hart_count, true); }
} else if (tcg_enabled()) {
/* Per-socket SiFive CLINT */
- riscv_aclint_swi_create(
+ riscv_aclint_swi_create(system_memory, s->memmap[VIRT_CLINT].base + i * s-Quoted 1 line
memmap[VIRT_CLINT].size,
base_hartid,hart_count, false);
- riscv_aclint_mtimer_create(s->memmap[VIRT_CLINT].base + + riscv_aclint_mtimer_create(system_memory,
+ s->memmap[VIRT_CLINT].base +
i * s->memmap[VIRT_CLINT].size +RISCV_ACLINT_SWI_SIZE,
RISCV_ACLINT_DEFAULT_MTIMER_SIZE,base_hartid,hart_count,
RISCV_ACLINT_DEFAULT_MTIMECMP,RISCV_ACLINT_DEFAULT_MTIME,hw/riscv/xiangshan_kmh.c +0
-0@@ -116,9 +116,11 @@ static voidxiangshan_kmh_soc_realize (DeviceState *dev, Error **errp) 115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);
/* CLINT */
- riscv_aclint_swi_create(memmap[XIANGSHAN_KMH_CLINT].base, + riscv_aclint_swi_create(system_memory,
+ memmap[XIANGSHAN_KMH_CLINT].base, 0,num_harts, false);
- riscv_aclint_mtimer_create(memmap[XIANGSHAN_KMH_CLINT].base + + riscv_aclint_mtimer_create(system_memory,
+ memmap[XIANGSHAN_KMH_CLINT].base +RISCV_ACLINT_SWI_SIZE,RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0,num_harts,RISCV_ACLINT_DEFAULT_MTIMECMP,
PATCH v2 3/16 hw/intc/riscv_imsic: Take a MemoryRegion for the created device
In reply to Joel Stanleyriscv_imsic_create() maps the device it creates into system_memory, which prevents its use by SoCs that map devices into their own memory container.
Add a MemoryRegion parameter and map the device into it instead of calling sysbus_mmio_map(). All callers pass system_memory, so there is no change in behaviour.
--- include/hw/intc/riscv_imsic.h | 3 ++- hw/intc/riscv_imsic.c | 6 ++++-- hw/riscv/aia.c | 6 ++++-- hw/riscv/xiangshan_kmh.c | 5 +++-- 4 files changed, 13 insertions(+), 7 deletions(-)
include/hw/intc/riscv_imsic.h +2 -1
@@ -62,7 +62,8 @@ struct RISCVIMSICState { uint32_t num_irqs; }; -DeviceState *riscv_imsic_create (hwaddr addr,uint32_t hartid,bool mmode, +DeviceState *riscv_imsic_create (MemoryRegion *mr,hwaddr addr, +uint32_t hartid,bool mmode,uint32_t num_pages,uint32_t num_ids);#endif
hw/intc/riscv_imsic.c +4 -2
@@ -495,7 +495,8 @@ type_init(riscv_imsic_register_types)/* * Create IMSIC device. */ -DeviceState *riscv_imsic_create (hwaddr addr,uint32_t hartid,bool mmode, +DeviceState *riscv_imsic_create (MemoryRegion *mr,hwaddr addr, +uint32_t hartid,bool mmode,uint32_t num_pages,uint32_t num_ids) {DeviceState *dev =qdev_new (TYPE_RISCV_IMSIC );
@@ -518,7 +519,8 @@ DeviceState *riscv_imsic_create(hwaddr addr, uint32_t hartid, bool mmode,qdev_prop_set_uint32 (dev,"num-irqs" , num_ids +1 );sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); +memory_region_add_subregion (mr, addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ));if (!kvm_irqchip_in_kernel ()) {for (i =0 ; i < num_pages; i++) {
hw/riscv/aia.c +4 -2
@@ -52,7 +52,8 @@ DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests,/* Per-socket M-level IMSICs */ addr = imsic_m->base + socket * (1U <<IMSIC_MMIO_GROUP_MIN_SHIFT );for (i =0 ; i < hart_count; i++) { -riscv_imsic_create (addr + i * m_imsic_stride, +riscv_imsic_create (mr, + addr + i * m_imsic_stride, base_hartid + i, true,1 , num_msis); }
@@ -61,7 +62,8 @@ DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests,/* Per-socket S-level IMSICs */ addr = imsic_s->base + socket * (1U <<IMSIC_MMIO_GROUP_MIN_SHIFT );for (i =0 ; i < hart_count; i++) { -riscv_imsic_create (addr + i * s_imsic_stride, +riscv_imsic_create (mr, + addr + i * s_imsic_stride, base_hartid + i, false,1 + aia_guests, num_msis); }
hw/riscv/xiangshan_kmh.c +3 -2
@@ -65,14 +65,15 @@ static DeviceState *xiangshan_kmh_create_aia(uint32_t num_harts)/* M-level IMSICs */ addr = memmap[XIANGSHAN_KMH_IMSIC_M ].base;for (i =0 ; i < num_harts; i++) { -riscv_imsic_create (addr + i *IMSIC_HART_SIZE (0 ), i, true, +riscv_imsic_create (get_system_memory (), + addr + i *IMSIC_HART_SIZE (0 ), i, true,1 ,XIANGSHAN_KMH_IMSIC_NUM_IDS ); }/* S-level IMSICs */ addr = memmap[XIANGSHAN_KMH_IMSIC_S ].base;for (i =0 ; i < num_harts; i++) { -riscv_imsic_create (addr + +riscv_imsic_create (get_system_memory (), addr + i *IMSIC_HART_SIZE (XIANGSHAN_KMH_IMSIC_GUEST_BITS ), i, false,1 +XIANGSHAN_KMH_IMSIC_GUEST_BITS ,XIANGSHAN_KMH_IMSIC_NUM_IDS );
Signature · 1 line
2.47.3
Re: [PATCH v2 03/16] hw/intc/riscv_imsic: Take a MemoryRegion for the created device
Quoted 3 lines · Joel Stanley
riscv_imsic_create()maps the device it creates intosystem_memory, which prevents its use by SoCs that map devices into their own memory container.
Reviewing previous patches I was thinking maybe @mr argument would be better named as @container. This description confirms that. Not a request to change, but still mentioning in case you think it fits well if a v3 is required.
Quoted 11 lines
Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). All callers passsystem_memory, so there is no change in behaviour.Signed-off-by Joel Stanley <[email protected]>--- include/hw/intc/riscv_imsic.h | 3 ++- hw/intc/riscv_imsic.c | 6 ++++-- hw/riscv/aia.c | 6 ++++-- hw/riscv/xiangshan_kmh.c | 5 +++-- 4 files changed, 13 insertions(+), 7 deletions(-)
Re: [PATCH v2 03/16] hw/intc/riscv_imsic: Take a MemoryRegion for the created device
In reply to Joel StanleyQuoted 10 lines · Joel Stanley
riscv_imsic_create()maps the device it creates intosystem_memory, which prevents its use by SoCs that map devices into their own memory container.Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). All callers passsystem_memory, so there is
no change in behaviour.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 105 lines
---
include/hw/intc/riscv_imsic.h | 3 ++-
hw/intc/riscv_imsic.c | 6 ++++--
hw/riscv/aia.c | 6 ++++--
hw/riscv/xiangshan_kmh.c | 5 +++--4 files changed, 13 insertions(+), 7 deletions(-)include/hw/intc/riscv_imsic.h +0
-0@@ -62,7 +62,8 @@ struct RISCVIMSICState { uint32_t num_irqs; };
-DeviceState *riscv_imsic_create(hwaddr addr,uint32_thartid, bool mmode,
+DeviceState *riscv_imsic_create(MemoryRegion *mr, hwaddr addr, +uint32_thartid, bool mmode,uint32_tnum_pages,uint32_tnum_ids);
#endifhw/intc/riscv_imsic.c +2
-1@@ -495,7 +495,8 @@ type_init(riscv_imsic_register_types) /** Create IMSIC device. */ -DeviceState *riscv_imsic_create(hwaddr addr, uint32_t hartid, bool mmode, +DeviceState *riscv_imsic_create(MemoryRegion *mr, hwaddr addr, + uint32_t hartid, bool mmode,
uint32_tnum_pages,uint32_tnum_ids)
{
DeviceState *dev =qdev_new(TYPE_RISCV_IMSIC);hw/intc/riscv_imsic.c +0
-0@@ -518,7 +519,8 @@ DeviceState *riscv_imsic_create(hwaddr addr, uint32_t hartid, bool mmode, qdev_prop_set_uint32(dev, "num-irqs", num_ids + 1);
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); -sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
+ memory_region_add_subregion(mr, addr,
+sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
if (!kvm_irqchip_in_kernel()) {
for (i = 0; i <num_pages; i++) {hw/riscv/aia.c +0
-0@@ -52,7 +52,8 @@ DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests, /* Per-socket M-level IMSICs */addr =
imsic_m->base+ socket * (1U <<IMSIC_MMIO_GROUP_MIN_SHIFT);
for (i = 0; i <hart_count; i++) {
- riscv_imsic_create(addr + i *m_imsic_stride, + riscv_imsic_create(mr,
+ addr + i *m_imsic_stride,base_hartid+ i, true, 1,num_msis);
}hw/riscv/aia.c +0
-0@@ -61,7 +62,8 @@ DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests, /* Per-socket S-level IMSICs */addr =
imsic_s->base+ socket * (1U <<IMSIC_MMIO_GROUP_MIN_SHIFT);
for (i = 0; i <hart_count; i++) {
- riscv_imsic_create(addr + i *s_imsic_stride, + riscv_imsic_create(mr,
+ addr + i *s_imsic_stride,base_hartid+ i, false, 1 +aia_guests,
num_msis);
}hw/riscv/xiangshan_kmh.c +2
-1@@ -65,14 +65,15 @@ static DeviceState *xiangshan_kmh_create_aia(uint32_t num_harts) /* M-level IMSICs */ addr = memmap[XIANGSHAN_KMH_IMSIC_M].base; for (i = 0; i < num_harts; i++) { - riscv_imsic_create(addr + i * IMSIC_HART_SIZE(0), i, true, + riscv_imsic_create(get_system_memory(), + addr + i * IMSIC_HART_SIZE(0), i, true, 1, XIANGSHAN_KMH_IMSIC_NUM_IDS); }
/* S-level IMSICs */
addr = memmap[XIANGSHAN_KMH_IMSIC_S].base; for (i = 0; i <num_harts; i++) {
- riscv_imsic_create(addr +
+ riscv_imsic_create(get_system_memory(), addr + i *IMSIC_HART_SIZE(XIANGSHAN_KMH_IMSIC_GUEST_BITS), i, false, 1 +XIANGSHAN_KMH_IMSIC_GUEST_BITS,XIANGSHAN_KMH_IMSIC_NUM_IDS);
PATCH v2 4/16 hw/intc/riscv_aplic: Take a MemoryRegion for the created device
In reply to Joel Stanleyriscv_aplic_create() maps the device it creates into system_memory, which prevents its use by SoCs that map devices into their own memory container.
Add a MemoryRegion parameter and map the device into it instead of calling sysbus_mmio_map(). The mapping still only happens when the APLIC is emulated. All callers pass system_memory, so there is no change in behaviour.
--- include/hw/intc/riscv_aplic.h | 2 +- hw/intc/riscv_aplic.c | 5 +++-- hw/riscv/aia.c | 6 ++++-- hw/riscv/cps.c | 6 ++++-- hw/riscv/xiangshan_kmh.c | 6 ++++-- 5 files changed, 16 insertions(+), 9 deletions(-)
include/hw/intc/riscv_aplic.h +1 -1
@@ -80,7 +80,7 @@ bool riscv_is_kvm_aia_aplic_imsic(bool msimode);bool riscv_use_emulated_aplic (bool msimode);void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr); -DeviceState *riscv_aplic_create (hwaddr addr,hwaddr size, +DeviceState *riscv_aplic_create (MemoryRegion *mr,hwaddr addr,hwaddr size,uint32_t hartid_base,uint32_t num_harts,uint32_t num_sources,uint32_t iprio_bits,bool msimode,bool mmode,DeviceState *parent);
hw/intc/riscv_aplic.c +3 -2
@@ -1109,7 +1109,7 @@ void riscv_aplic_add_child(DeviceState *parent, DeviceState *child)/* * Create APLIC device. */ -DeviceState *riscv_aplic_create (hwaddr addr,hwaddr size, +DeviceState *riscv_aplic_create (MemoryRegion *mr,hwaddr addr,hwaddr size,uint32_t hartid_base,uint32_t num_harts,uint32_t num_sources,uint32_t iprio_bits,bool msimode,bool mmode,DeviceState *parent) {
@@ -1137,7 +1137,8 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);if (riscv_use_emulated_aplic (msimode)) { -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); +memory_region_add_subregion (mr, addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ));if (!msimode) {for (i =0 ; i < num_harts; i++) {
hw/riscv/aia.c +4 -2
@@ -71,7 +71,8 @@ DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests,if (!kvm_enabled ()) {/* Per-socket M-level APLIC */ - aplic_m_dev = riscv_aplic_create(aplic_m->base + + aplic_m_dev = riscv_aplic_create(mr, + aplic_m->base + socket * aplic_m->size, aplic_m->size, (msimode) ? 0 : base_hartid,
@@ -82,7 +83,8 @@ DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests, }/* Per-socket S-level APLIC */ - aplic_s_dev = riscv_aplic_create(aplic_s->base + + aplic_s_dev = riscv_aplic_create(mr, + aplic_s->base + socket * aplic_s->size, aplic_s->size, (msimode) ? 0 : base_hartid,
hw/riscv/cps.c +4 -2
@@ -135,14 +135,16 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp)for (i =0 ; i < num_of_clusters; i++) {uint64_t cm_base =GLOBAL_CM_BASE + (CM_SIZE * i);uint32_t hartid_base = i <<MHARTID_CLUSTER_SHIFT ; - s->aplic =riscv_aplic_create (cm_base +AIA_PLIC_M_OFFSET , + s->aplic =riscv_aplic_create (get_system_memory (), + cm_base +AIA_PLIC_M_OFFSET ,AIA_PLIC_M_SIZE , hartid_base,/* hartid_base */ MAX_HARTS ,/* num_harts */ APLIC_NUM_SOURCES ,APLIC_NUM_PRIO_BITS , false, true,NULL ); - riscv_aplic_create(cm_base + AIA_PLIC_S_OFFSET, + riscv_aplic_create(get_system_memory(), + cm_base + AIA_PLIC_S_OFFSET, AIA_PLIC_S_SIZE, hartid_base, /* hartid_base */ MAX_HARTS, /* num_harts */
hw/riscv/xiangshan_kmh.c +4 -2
@@ -80,13 +80,15 @@ static DeviceState *xiangshan_kmh_create_aia(uint32_t num_harts) }/* M-level APLIC */ - aplic_m =riscv_aplic_create (memmap[XIANGSHAN_KMH_APLIC_M ].base, + aplic_m =riscv_aplic_create (get_system_memory (), + memmap[XIANGSHAN_KMH_APLIC_M ].base, memmap[XIANGSHAN_KMH_APLIC_M ].size,0 ,0 ,XIANGSHAN_KMH_APLIC_NUM_SOURCES ,1 , true, true,NULL );/* S-level APLIC */ -riscv_aplic_create (memmap[XIANGSHAN_KMH_APLIC_S ].base, +riscv_aplic_create (get_system_memory (), + memmap[XIANGSHAN_KMH_APLIC_S ].base, memmap[XIANGSHAN_KMH_APLIC_S ].size,0 ,0 ,XIANGSHAN_KMH_APLIC_NUM_SOURCES ,1 , true, false, aplic_m);
Signature · 1 line
2.47.3
Re: [PATCH v2 04/16] hw/intc/riscv_aplic: Take a MemoryRegion for the created device
Quoted 9 lines · Joel Stanley
riscv_aplic_create()maps the device it creates intosystem_memory, which prevents its use by SoCs that map devices into their own memory container.Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). The mapping still only happens when the APLIC is emulated. All callers passsystem_memory, so there is no change in behaviour.
Quoted 8 lines
Signed-off-by Joel Stanley <[email protected]>--- include/hw/intc/riscv_aplic.h | 2 +- hw/intc/riscv_aplic.c | 5 +++-- hw/riscv/aia.c | 6 ++++-- hw/riscv/cps.c | 6 ++++-- hw/riscv/xiangshan_kmh.c | 6 ++++-- 5 files changed, 16 insertions(+), 9 deletions(-)
Re: [PATCH v2 04/16] hw/intc/riscv_aplic: Take a MemoryRegion for the created device
In reply to Joel StanleyQuoted 10 lines · Joel Stanley
riscv_aplic_create()maps the device it creates intosystem_memory, which prevents its use by SoCs that map devices into their own memory container.Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). The mapping still only happens when the APLIC is emulated. All callers passsystem_memory, so there is no change in behaviour.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 126 lines
---
include/hw/intc/riscv_aplic.h | 2 +-
hw/intc/riscv_aplic.c | 5 +++--
hw/riscv/aia.c | 6 ++++--
hw/riscv/cps.c | 6 ++++--
hw/riscv/xiangshan_kmh.c | 6 ++++--5 files changed, 16 insertions(+), 9 deletions(-)include/hw/intc/riscv_aplic.h +0
-0@@ -80,7 +80,7 @@ bool riscv_is_kvm_aia_aplic_imsic(bool msimode); bool riscv_use_emulated_aplic(bool msimode);void
riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr);include/hw/intc/riscv_aplic.h +1
-1-DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, +DeviceState *riscv_aplic_create(MemoryRegion *mr, hwaddr addr,hwaddr size,
uint32_thartid_base,uint32_tnum_harts,uint32_tnum_sources,uint32_tiprio_bits, bool msimode, bool mmode, DeviceState *parent);hw/intc/riscv_aplic.c +1
-1@@ -1109,7 +1109,7 @@ void riscv_aplic_add_child(DeviceState *parent, DeviceState *child) /** Create APLIC device. */ -DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, +DeviceState *riscv_aplic_create(MemoryRegion *mr, hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources,
uint32_tiprio_bits, bool msimode, bool mmode, DeviceState *parent)
{hw/intc/riscv_aplic.c +0
-0@@ -1137,7 +1137,8 @@ DeviceState *riscv_aplic_create(hwaddr addr,hwaddr size, sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
if (riscv_use_emulated_aplic(msimode)) {
-sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + memory_region_add_subregion(mr, addr,
+sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
if (!msimode) {
for (i = 0; i <num_harts; i++) {hw/riscv/aia.c +0
-0@@ -71,7 +71,8 @@ DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests,
if (!kvm_enabled()) {
/* Per-socket M-level APLIC */
-aplic_m_dev= riscv_aplic_create(aplic_m->base + +aplic_m_dev= riscv_aplic_create(mr,
+aplic_m->base+ socket *aplic_m->size,aplic_m->size, (msimode) ? 0 :base_hartid,hw/riscv/aia.c +0
-0@@ -82,7 +83,8 @@ DeviceState *riscv_create_aia(MemoryRegion *mr, bool msimode, int aia_guests, }
/* Per-socket S-level APLIC */
-aplic_s_dev= riscv_aplic_create(aplic_s->base + +aplic_s_dev= riscv_aplic_create(mr,
+aplic_s->base+ socket *aplic_s->size,aplic_s->size, (msimode) ? 0 :base_hartid,hw/riscv/cps.c +2
-1@@ -135,14 +135,16 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp) for (i = 0; i < num_of_clusters; i++) { uint64_t cm_base = GLOBAL_CM_BASE + (CM_SIZE * i); uint32_t hartid_base = i << MHARTID_CLUSTER_SHIFT; - s->aplic = riscv_aplic_create(cm_base + AIA_PLIC_M_OFFSET, + s->aplic = riscv_aplic_create(get_system_memory(), + cm_base + AIA_PLIC_M_OFFSET, AIA_PLIC_M_SIZE,
hartid_base, /*hartid_base*/MAX_HARTS, /*num_harts*/APLIC_NUM_SOURCES,APLIC_NUM_PRIO_BITS, false, true, NULL); - riscv_aplic_create(cm_base +AIA_PLIC_S_OFFSET,
+ riscv_aplic_create(get_system_memory(),
+cm_base+AIA_PLIC_S_OFFSET,AIA_PLIC_S_SIZE,
hartid_base, /*hartid_base*/MAX_HARTS, /*num_harts*/hw/riscv/xiangshan_kmh.c +0
-0@@ -80,13 +80,15 @@ static DeviceState *xiangshan_kmh_create_aia(uint32_t num_harts) }
/* M-level APLIC */
-aplic_m= riscv_aplic_create(memmap[XIANGSHAN_KMH_APLIC_M].base, +aplic_m= riscv_aplic_create(get_system_memory(),
+ memmap[XIANGSHAN_KMH_APLIC_M].base, memmap[XIANGSHAN_KMH_APLIC_M].size, 0, 0,XIANGSHAN_KMH_APLIC_NUM_SOURCES,
1, true, true, NULL);
/* S-level APLIC */
- riscv_aplic_create(memmap[XIANGSHAN_KMH_APLIC_S].base, + riscv_aplic_create(get_system_memory(),
+ memmap[XIANGSHAN_KMH_APLIC_S].base, memmap[XIANGSHAN_KMH_APLIC_S].size, 0, 0,XIANGSHAN_KMH_APLIC_NUM_SOURCES, 1, true, false,aplic_m);
PATCH v2 5/16 hw/intc/sifive_plic: Take a MemoryRegion for the created device
In reply to Joel Stanleysifive_plic_create() maps the device it creates into system_memory, which prevents its use by SoCs that map devices into their own memory container.
Add a MemoryRegion parameter and map the device into it instead of calling sysbus_mmio_map(). All callers pass system_memory, so there is no change in behaviour.
--- include/hw/intc/sifive_plic.h | 3 ++- hw/intc/sifive_plic.c | 6 ++++-- hw/riscv/k230.c | 3 ++- hw/riscv/microchip_pfsoc.c | 3 ++- hw/riscv/shakti_c.c | 3 ++- hw/riscv/sifive_e.c | 2 +- hw/riscv/sifive_u.c | 3 ++- hw/riscv/virt.c | 1 + 8 files changed, 16 insertions(+), 8 deletions(-)
include/hw/intc/sifive_plic.h +2 -1
@@ -76,7 +76,8 @@ struct SiFivePLICState {qemu_irq *s_external_irqs; }; -DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, +DeviceState *sifive_plic_create(MemoryRegion *mr, hwaddr addr, + char *hart_config, uint32_t num_harts, uint32_t hartid_base, uint32_t num_sources, uint32_t num_priorities, uint32_t priority_base,
hw/intc/sifive_plic.c +4 -2
@@ -473,7 +473,8 @@ type_init(sifive_plic_register_types)/* * Create PLIC device. */ -DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, +DeviceState *sifive_plic_create(MemoryRegion *mr, hwaddr addr, + char *hart_config, uint32_t num_harts, uint32_t hartid_base, uint32_t num_sources, uint32_t num_priorities, uint32_t priority_base,
@@ -499,7 +500,8 @@ DeviceState *sifive_plic_create(hwaddr addr, char *hart_config,qdev_prop_set_uint32 (dev,"context-stride" , context_stride);qdev_prop_set_uint32 (dev,"aperture-size" , aperture_size);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); +memory_region_add_subregion (mr, addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 )); plic =SIFIVE_PLIC (dev);
hw/riscv/k230.c +2 -1
@@ -134,7 +134,8 @@ static DeviceState *k230_create_plic(int base_hartid, int hartid_count) plic_hart_config =riscv_plic_hart_config_string (hartid_count);/* Per-socket PLIC */ - return sifive_plic_create(memmap[K230_DEV_PLIC].base, + return sifive_plic_create(get_system_memory(), + memmap[K230_DEV_PLIC].base, plic_hart_config, hartid_count, base_hartid, K230_PLIC_NUM_SOURCES, K230_PLIC_NUM_PRIORITIES,
hw/riscv/microchip_pfsoc.c +2 -1
@@ -282,7 +282,8 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) plic_hart_config =riscv_plic_hart_config_string (ms->smp.cpus);/* PLIC */ - s->plic = sifive_plic_create(memmap[MICROCHIP_PFSOC_PLIC].base, + s->plic = sifive_plic_create(system_memory, + memmap[MICROCHIP_PFSOC_PLIC].base, plic_hart_config, ms->smp.cpus, 0, MICROCHIP_PFSOC_PLIC_NUM_SOURCES, MICROCHIP_PFSOC_PLIC_NUM_PRIORITIES,
hw/riscv/shakti_c.c +2 -1
@@ -115,7 +115,8 @@ static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp)sysbus_realize (SYS_BUS_DEVICE (&sss->cpus), &error_abort); - sss->plic = sifive_plic_create(shakti_c_memmap[SHAKTI_C_PLIC].base, + sss->plic = sifive_plic_create(system_memory, + shakti_c_memmap[SHAKTI_C_PLIC].base, (char *)SHAKTI_C_PLIC_HART_CONFIG, ms->smp.cpus, 0, SHAKTI_C_PLIC_NUM_SOURCES, SHAKTI_C_PLIC_NUM_PRIORITIES,
hw/riscv/sifive_e.c +1 -1
@@ -214,7 +214,7 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp) memmap[SIFIVE_E_DEV_MROM].base, &s->mask_rom);/* MMIO */ - s->plic = sifive_plic_create(memmap[SIFIVE_E_DEV_PLIC].base, + s->plic = sifive_plic_create(sys_mem, memmap[SIFIVE_E_DEV_PLIC].base, (char *)SIFIVE_E_PLIC_HART_CONFIG, ms->smp.cpus, 0, SIFIVE_E_PLIC_NUM_SOURCES, SIFIVE_E_PLIC_NUM_PRIORITIES,
hw/riscv/sifive_u.c +2 -1
@@ -772,7 +772,8 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) plic_hart_config =riscv_plic_hart_config_string (ms->smp.cpus);/* MMIO */ - s->plic = sifive_plic_create(memmap[SIFIVE_U_DEV_PLIC].base, + s->plic = sifive_plic_create(system_memory, + memmap[SIFIVE_U_DEV_PLIC].base, plic_hart_config, ms->smp.cpus, 0, SIFIVE_U_PLIC_NUM_SOURCES, SIFIVE_U_PLIC_NUM_PRIORITIES,
hw/riscv/virt.c +1 -0
@@ -1138,6 +1138,7 @@ static DeviceState *virt_create_plic(const MemMapEntry *memmap, int socket,/* Per-socket PLIC */ return sifive_plic_create( + get_system_memory(), memmap[VIRT_PLIC].base + socket * memmap[VIRT_PLIC].size, plic_hart_config, hart_count, base_hartid, VIRT_IRQCHIP_NUM_SOURCES,
Signature · 1 line
2.47.3
Re: [PATCH v2 05/16] hw/intc/sifive_plic: Take a MemoryRegion for the created device
Quoted 9 lines · Joel Stanley
sifive_plic_create()maps the device it creates intosystem_memory, which prevents its use by SoCs that map devices into their own memory container.Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). All callers passsystem_memory, so there is no change in behaviour.Signed-off-by Joel Stanley <[email protected]>
Quoted 10 lines
--- include/hw/intc/sifive_plic.h | 3 ++- hw/intc/sifive_plic.c | 6 ++++-- hw/riscv/k230.c | 3 ++- hw/riscv/microchip_pfsoc.c | 3 ++- hw/riscv/shakti_c.c | 3 ++- hw/riscv/sifive_e.c | 2 +- hw/riscv/sifive_u.c | 3 ++- hw/riscv/virt.c | 1 + 8 files changed, 16 insertions(+), 8 deletions(-)
Re: [PATCH v2 05/16] hw/intc/sifive_plic: Take a MemoryRegion for the created device
In reply to Joel StanleyQuoted 10 lines · Joel Stanley
sifive_plic_create()maps the device it creates intosystem_memory, which prevents its use by SoCs that map devices into their own memory container.Add a MemoryRegion parameter and map the device into it instead of calling
sysbus_mmio_map(). All callers passsystem_memory, so there is
no change in behaviour.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 142 lines
---
include/hw/intc/sifive_plic.h | 3 ++-
hw/intc/sifive_plic.c | 6 ++++--
hw/riscv/k230.c | 3 ++-
hw/riscv/microchip_pfsoc.c | 3 ++-hw/riscv/shakti_c.c | 3 ++- hw/riscv/sifive_e.c | 2 +- hw/riscv/sifive_u.c | 3 ++- hw/riscv/virt.c | 1 + 8 files changed, 16 insertions(+), 8 deletions(-)include/hw/intc/sifive_plic.h +0
-0@@ -76,7 +76,8 @@ struct SiFivePLICState { qemu_irq *s_external_irqs; };include/hw/intc/sifive_plic.h +2
-1-DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, +DeviceState *sifive_plic_create(MemoryRegion *mr, hwaddr addr, + char *hart_config,
uint32_tnum_harts,
uint32_thartid_base,uint32_tnum_sources,uint32_tnum_priorities,uint32_tpriority_base,hw/intc/sifive_plic.c +4
-2@@ -473,7 +473,8 @@ type_init(sifive_plic_register_types) /** Create PLIC device. */ -DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, +DeviceState *sifive_plic_create(MemoryRegion *mr, hwaddr addr, + char *hart_config, uint32_t num_harts, uint32_t hartid_base, uint32_t num_sources, uint32_t num_priorities, uint32_t priority_base,@@ -499,7 +500,8 @@ DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, qdev_prop_set_uint32(dev, "context-stride", context_stride); qdev_prop_set_uint32(dev, "aperture-size", aperture_size); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + memory_region_add_subregion(mr, addr, + sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
plic =SIFIVE_PLIC(dev);hw/riscv/k230.c +0
-0@@ -134,7 +134,8 @@ static DeviceState *k230_create_plic(int base_hartid, int hartid_count) plic_hart_config = riscv_plic_hart_config_string(hartid_count);
/* Per-socket PLIC */
- return sifive_plic_create(memmap[K230_DEV_PLIC].base, + return sifive_plic_create(get_system_memory(), + memmap[K230_DEV_PLIC].base,plic_hart_config,hartid_count,base_hartid,
K230_PLIC_NUM_SOURCES,K230_PLIC_NUM_PRIORITIES,hw/riscv/microchip_pfsoc.c +0
-0@@ -282,7 +282,8 @@ static voidmicrochip_pfsoc_soc_realize (DeviceState *dev, Error **errp) plic_hart_config = riscv_plic_hart_config_string(ms->smp.cpus);
/* PLIC */
-s->plic= sifive_plic_create(memmap[MICROCHIP_PFSOC_PLIC].base, +s->plic= sifive_plic_create(system_memory,
+ memmap[MICROCHIP_PFSOC_PLIC].base,plic_hart_config,ms->smp.cpus, 0,MICROCHIP_PFSOC_PLIC_NUM_SOURCES,MICROCHIP_PFSOC_PLIC_NUM_PRIORITIES,hw/riscv/shakti_c.c +0
-0@@ -115,7 +115,8 @@ static voidshakti_c_soc_state_realize (DeviceState *dev, Error **errp)
sysbus_realize(SYS_BUS_DEVICE(&sss->cpus), &error_abort);
-sss->plic= sifive_plic_create(shakti_c_memmap[SHAKTI_C_PLIC].base, +sss->plic= sifive_plic_create(system_memory,
+ shakti_c_memmap[SHAKTI_C_PLIC].base,
(char *)SHAKTI_C_PLIC_HART_CONFIG,ms->smp.cpus, 0,SHAKTI_C_PLIC_NUM_SOURCES,SHAKTI_C_PLIC_NUM_PRIORITIES,hw/riscv/sifive_e.c +0
-0@@ -214,7 +214,7 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp) memmap[SIFIVE_E_DEV_MROM].base, &s->mask_rom);
/* MMIO */
-s->plic= sifive_plic_create(memmap[SIFIVE_E_DEV_PLIC].base, +s->plic= sifive_plic_create(sys_mem, memmap[SIFIVE_E_DEV_PLIC].base,
(char *)SIFIVE_E_PLIC_HART_CONFIG,ms->smp.cpus, 0,SIFIVE_E_PLIC_NUM_SOURCES,SIFIVE_E_PLIC_NUM_PRIORITIES,hw/riscv/sifive_u.c +0
-0@@ -772,7 +772,8 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) plic_hart_config = riscv_plic_hart_config_string(ms->smp.cpus);
/* MMIO */
-s->plic= sifive_plic_create(memmap[SIFIVE_U_DEV_PLIC].base, +s->plic= sifive_plic_create(system_memory,
+ memmap[SIFIVE_U_DEV_PLIC].base,plic_hart_config,ms->smp.cpus, 0,SIFIVE_U_PLIC_NUM_SOURCES,SIFIVE_U_PLIC_NUM_PRIORITIES,hw/riscv/virt.c +0
-0@@ -1138,6 +1138,7 @@ static DeviceState *virt_create_plic(const MemMapEntry *memmap, int socket,
/* Per-socket PLIC */
return sifive_plic_create(
+get_system_memory(), memmap[VIRT_PLIC].base + socket * memmap[VIRT_PLIC].size,
plic_hart_config,hart_count,base_hartid,VIRT_IRQCHIP_NUM_SOURCES,
PATCH v2 6/16 hw/riscv/cps: Map interrupt controllers in SoC container
In reply to Joel StanleyThe CPS device maps some devices into a container region, but the ACLINT and APLIC were mapped directly to system_memory.
Pass the container memory region to the interrupt controller helpers so all CPS devices live in the container. The location of devices in memory for the boston-aia machine is unchanged.
--- hw/riscv/cps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/riscv/cps.c +4 -4
@@ -135,7 +135,7 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp)for (i =0 ; i < num_of_clusters; i++) {uint64_t cm_base =GLOBAL_CM_BASE + (CM_SIZE * i);uint32_t hartid_base = i <<MHARTID_CLUSTER_SHIFT ; - s->aplic = riscv_aplic_create(get_system_memory(), + s->aplic = riscv_aplic_create(&s->container, cm_base + AIA_PLIC_M_OFFSET, AIA_PLIC_M_SIZE, hartid_base, /* hartid_base */
@@ -143,7 +143,7 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp)APLIC_NUM_SOURCES ,APLIC_NUM_PRIO_BITS , false, true, NULL); - riscv_aplic_create(get_system_memory(), + riscv_aplic_create(&s->container, cm_base + AIA_PLIC_S_OFFSET, AIA_PLIC_S_SIZE, hartid_base, /* hartid_base */
@@ -153,10 +153,10 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp) false, false, s->aplic);/* PLIC changes msi_nonbroken to ture. We revert the change. */ msi_nonbroken = false; -riscv_aclint_swi_create (get_system_memory (), +riscv_aclint_swi_create (&s->container, cm_base +AIA_CLINT_OFFSET , hartid_base,MAX_HARTS , false); - riscv_aclint_mtimer_create(get_system_memory(), + riscv_aclint_mtimer_create(&s->container, cm_base + AIA_CLINT_OFFSET + RISCV_ACLINT_SWI_SIZE, RISCV_ACLINT_DEFAULT_MTIMER_SIZE,
Signature · 1 line
2.47.3
Re: [PATCH v2 06/16] hw/riscv/cps: Map interrupt controllers in SoC container
Quoted 11 lines · Joel Stanley
The CPS device maps some devices into a container region, but the ACLINT and APLIC were mapped directly to
system_memory.Pass the container memory region to the interrupt controller helpers so all CPS devices live in the container. The location of devices in memory for the boston-aia machine is unchanged.
Signed-off-by Joel Stanley <[email protected]>--- hw/riscv/cps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
(I'd have expected this as 1st patch in this series)
Re: [PATCH v2 06/16] hw/riscv/cps: Map interrupt controllers in SoC container
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Joel Stanley
The CPS device maps some devices into a container region, but the ACLINT and APLIC were mapped directly to
system_memory.Pass the container memory region to the interrupt controller helpers so all CPS devices live in the container. The location of devices in memory for the boston-aia machine is unchanged.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Joel Stanley <[email protected]>--- hw/riscv/cps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)(I'd have expected this as 1st patch in this series)
This is a fix that is enabled by the first four patches; only possible now that we can pass a MemoryRegion.
So the first few patches modify the cps machine to pass system_memory() to preserve behaviour. Then this patch switches them over to use the container.
Usually a no-no, modifying a line that was modified in an earlier patch. I could fold this change into the first few patches, but then the change in behaviour wouldn't have been as clear to reviewers.
Cheers,
Joel
Re: [PATCH v2 06/16] hw/riscv/cps: Map interrupt controllers in SoC container
Quoted 16 lines · Joel Stanley
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Joel Stanley
The CPS device maps some devices into a container region, but the ACLINT and APLIC were mapped directly to
system_memory.Pass the container memory region to the interrupt controller helpers so all CPS devices live in the container. The location of devices in memory for the boston-aia machine is unchanged.
Signed-off-by Joel Stanley <[email protected]>--- hw/riscv/cps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 4 lines
Quoted 1 line
(I'd have expected this as 1st patch in this series)
This is a fix that is enabled by the first four patches; only possible now that we can pass a MemoryRegion.
Oh right, good then!
Quoted 13 lines
So the first few patches modify the cps machine to pass
system_memory()to preserve behaviour. Then this patch switches them over to use the container.Usually a no-no, modifying a line that was modified in an earlier patch. I could fold this change into the first few patches, but then the change in behaviour wouldn't have been as clear to reviewers.
Cheers,
Joel
Re: [PATCH v2 06/16] hw/riscv/cps: Map interrupt controllers in SoC container
In reply to Joel StanleyQuoted 10 lines · Joel Stanley
The CPS device maps some devices into a container region, but the ACLINT and APLIC were mapped directly to
system_memory.Pass the container memory region to the interrupt controller helpers so
all CPS devices live in the container. The location of devices in memory
for the boston-aia machine is unchanged.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 43 lines
---
hw/riscv/cps.c | 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)hw/riscv/cps.c +1
-1@@ -135,7 +135,7 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp) for (i = 0; i < num_of_clusters; i++) { uint64_t cm_base = GLOBAL_CM_BASE + (CM_SIZE * i); uint32_t hartid_base = i << MHARTID_CLUSTER_SHIFT; - s->aplic = riscv_aplic_create(get_system_memory(), + s->aplic = riscv_aplic_create(&s->container, cm_base + AIA_PLIC_M_OFFSET, AIA_PLIC_M_SIZE,
hartid_base, /*hartid_base*/hw/riscv/cps.c +1
-1@@ -143,7 +143,7 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp) APLIC_NUM_SOURCES, APLIC_NUM_PRIO_BITS, false, true, NULL); - riscv_aplic_create(get_system_memory(), + riscv_aplic_create(&s->container, cm_base + AIA_PLIC_S_OFFSET, AIA_PLIC_S_SIZE,
hartid_base, /*hartid_base*/hw/riscv/cps.c +2
-2@@ -153,10 +153,10 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp) false, false, s->aplic); /* PLIC changes msi_nonbroken to ture. We revert the change. */ msi_nonbroken = false; - riscv_aclint_swi_create(get_system_memory(), + riscv_aclint_swi_create(&s->container, cm_base + AIA_CLINT_OFFSET, hartid_base, MAX_HARTS, false); - riscv_aclint_mtimer_create(get_system_memory(), + riscv_aclint_mtimer_create(&s->container,
cm_base+AIA_CLINT_OFFSET+RISCV_ACLINT_SWI_SIZE,RISCV_ACLINT_DEFAULT_MTIMER_SIZE,
PATCH v2 7/16 hw/riscv/atlantis: Make UART unimp region a SoC device
In reply to Joel StanleyMake the unimplemented region covering the remainder of the console UART's register space a SoC child device, mapped using a helper. This makes it easier to map it into the SoC's memory container along with the other devices in the future.
While here, rename the region from uart0 to uart1. The uart0 name was a leftover from an earlier revision that used a different device for the console.
--- include/hw/riscv/tt_atlantis.h | 2 ++ hw/riscv/tt_atlantis.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-)
include/hw/riscv/tt_atlantis.h +2 -0
@@ -13,6 +13,7 @@#include "hw/core/sysbus.h" #include "hw/i2c/designware_i2c.h" #include "hw/intc/riscv_imsic.h" +#include "hw/misc/unimp.h" #include "hw/riscv/riscv_hart.h" #define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis")
@@ -31,6 +32,7 @@ struct TTAtlantisState {RISCVHartArrayState soc;DeviceState *irqchip;DesignWareI2CState i2c[TT_ATL_NUM_I2C ]; +UnimplementedDeviceState uart1;int fdt_size; };
hw/riscv/tt_atlantis.c +16 -3
@@ -409,6 +409,17 @@ static void load_fdt(TTAtlantisState *s)create_fdt_memory (s); } +static void mmio_map_unimplemented (MemoryRegion *memory,SysBusDevice *dev, +const char *name,hwaddr addr,uint64_t size) +{ +qdev_prop_set_string (DEVICE (dev),"name" , name); +qdev_prop_set_uint64 (DEVICE (dev),"size" , size); +sysbus_realize (dev, &error_abort); + +memory_region_add_subregion_overlap (memory, addr, +sysbus_mmio_get_region (dev,0 ),-1000 ); +} +static void tt_atlantis_machine_done (Notifier *notifier,void *data) {TTAtlantisState *s =container_of (notifier, TTAtlantisState, machine_done);
@@ -560,9 +571,11 @@ static void tt_atlantis_machine_init(MachineState *machine)* Create an unimplemented device region so writes don't fault * and reads return zero, which keeps Linux happy. */ -create_unimplemented_device ("tt-atlantis.uart0" , - s->memmap[TT_ATL_UART1 ].base, - s->memmap[TT_ATL_UART1 ].size); +object_initialize_child (OBJECT (s),"uart1" , &s->uart1, +TYPE_UNIMPLEMENTED_DEVICE ); +mmio_map_unimplemented (system_memory,SYS_BUS_DEVICE (&s->uart1), +"tt-atlantis.uart1" , s->memmap[TT_ATL_UART1 ].base, + s->memmap[TT_ATL_UART1 ].size);/* I2C */ for (int i =0 ; i <TT_ATL_NUM_I2C ; i++) {
Signature · 1 line
2.47.3
Re: [PATCH v2 07/16] hw/riscv/atlantis: Make UART unimp region a SoC device
Quoted 43 lines · Joel Stanley
Make the unimplemented region covering the remainder of the console UART's register space a SoC child device, mapped using a helper. This makes it easier to map it into the SoC's memory container along with the other devices in the future.
While here, rename the region from uart0 to uart1. The uart0 name was a leftover from an earlier revision that used a different device for the console.
Signed-off-by Joel Stanley <[email protected]>--- include/hw/riscv/tt_atlantis.h | 2 ++ hw/riscv/tt_atlantis.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-)include/hw/riscv/tt_atlantis.h +2
-0@@ -13,6 +13,7 @@#include "hw/core/sysbus.h" #include "hw/i2c/designware_i2c.h" #include "hw/intc/riscv_imsic.h" +#include "hw/misc/unimp.h" #include "hw/riscv/riscv_hart.h" #define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis")@@ -31,6 +32,7 @@ struct TTAtlantisState {RISCVHartArrayState soc;DeviceState *irqchip;DesignWareI2CState i2c[TT_ATL_NUM_I2C ]; +UnimplementedDeviceState uart1;int fdt_size; };hw/riscv/tt_atlantis.c +0
-0@@ -409,6 +409,17 @@ static void load_fdt(TTAtlantisState *s)create_fdt_memory (s); }
hw/riscv/tt_atlantis.c static void load_fdt(TTAtlantisState *s) · line 421
Quoted 10 lines
hw/riscv/tt_atlantis.c +10
-0+static void mmio_map_unimplemented (MemoryRegion *memory,SysBusDevice *dev, +const char *name,hwaddr addr,uint64_t size) +{ +qdev_prop_set_string (DEVICE (dev),"name" , name); +qdev_prop_set_uint64 (DEVICE (dev),"size" , size); +sysbus_realize (dev, &error_abort); + +memory_region_add_subregion_overlap (memory, addr, +sysbus_mmio_get_region (dev,0 ),-1000 ); +}
Peter, maybe it is time to allow this boiler plate as a generic helper?
Re: [PATCH v2 07/16] hw/riscv/atlantis: Make UART unimp region a SoC device
In reply to Joel StanleyQuoted 10 lines · Joel Stanley
Make the unimplemented region covering the remainder of the console UART's register space a SoC child device, mapped using a helper. This makes it easier to map it into the SoC's memory container along with the other devices in the future.
While here, rename the region from uart0 to uart1. The uart0 name was a leftover from an earlier revision that used a different device for the console.
Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 69 lines
---
include/hw/riscv/tt_atlantis.h | 2 ++ hw/riscv/tt_atlantis.c | 19 ++++++++++++++++---2 files changed, 18 insertions(+), 3 deletions(-)include/hw/riscv/tt_atlantis.h +1
-0@@ -13,6 +13,7 @@ #include "hw/core/sysbus.h" #include "hw/i2c/designware_i2c.h" #include "hw/intc/riscv_imsic.h" +#include "hw/misc/unimp.h" #include "hw/riscv/riscv_hart.h"
#defineTYPE_TT_ATLANTIS_MACHINEMACHINE_TYPE_NAME("tt-atlantis")include/hw/riscv/tt_atlantis.h +1
-0@@ -31,6 +32,7 @@ struct TTAtlantisState { RISCVHartArrayState soc; DeviceState *irqchip; DesignWareI2CState i2c[TT_ATL_NUM_I2C]; + UnimplementedDeviceState uart1;
intfdt_size;
};hw/riscv/tt_atlantis.c +0
-0@@ -409,6 +409,17 @@ static void load_fdt(TTAtlantisState *s) create_fdt_memory(s); }
+static void mmio_map_unimplemented(MemoryRegion *memory, SysBusDevice *dev,
+ const char *name, hwaddr addr,uint64_tsize)hw/riscv/tt_atlantis.c +7
-0+{ + qdev_prop_set_string(DEVICE(dev), "name", name); + qdev_prop_set_uint64(DEVICE(dev), "size", size); + sysbus_realize(dev, &error_abort); + + memory_region_add_subregion_overlap(memory, addr, + sysbus_mmio_get_region(dev,0), -1000);
hw/riscv/tt_atlantis.c +2
-0+} +static void
tt_atlantis_machine_done(Notifier *notifier, void *data){
TTAtlantisState *s =container_of(notifier, TTAtlantisState, machine_done);hw/riscv/tt_atlantis.c +5
-3@@ -560,9 +571,11 @@ static voidtt_atlantis_machine_init(MachineState *machine) * Create an unimplemented device region so writes don't fault * and reads return zero, which keeps Linux happy. */ - create_unimplemented_device("tt-atlantis.uart0", - s->memmap[TT_ATL_UART1].base, - s->memmap[TT_ATL_UART1].size); + object_initialize_child(OBJECT(s), "uart1", &s->uart1, + TYPE_UNIMPLEMENTED_DEVICE); + mmio_map_unimplemented(system_memory, SYS_BUS_DEVICE(&s->uart1), + "tt-atlantis.uart1", s- >memmap[TT_ATL_UART1].base, + s->memmap[TT_ATL_UART1].size);
/* I2C */
for (int i = 0; i <TT_ATL_NUM_I2C; i++) {
PATCH v2 8/16 hw/riscv/atlantis: Remove unused fdt_size
In reply to Joel StanleyThe machine state carries around the FDT size which isn't used by anything.
--- include/hw/riscv/tt_atlantis.h | 2 -- hw/riscv/tt_atlantis.c | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-)
include/hw/riscv/tt_atlantis.h +0 -2
@@ -33,8 +33,6 @@ struct TTAtlantisState {DeviceState *irqchip;DesignWareI2CState i2c[TT_ATL_NUM_I2C ];UnimplementedDeviceState uart1; - -int fdt_size; };enum {
hw/riscv/tt_atlantis.c +4 -2
@@ -366,9 +366,10 @@ static void finalize_fdt(TTAtlantisState *s)static void create_fdt (TTAtlantisState *s) {MachineState *ms =MACHINE (s); +int fdt_size =0 ; ms->fdt =create_board_device_tree ("Tenstorrent Atlantis RISC-V Machine" , -"tenstorrent,atlantis" , &s->fdt_size); +"tenstorrent,atlantis" , &fdt_size);qemu_fdt_add_subnode (ms->fdt,"/chosen" );
@@ -384,8 +385,9 @@ static void load_fdt(TTAtlantisState *s)MachineState *ms =MACHINE (s);char **node_path;Error *err =NULL ; +int fdt_size =0 ; - ms->fdt =load_device_tree (ms->dtb, &s->fdt_size); + ms->fdt =load_device_tree (ms->dtb, &fdt_size);if (!ms->fdt) {error_report ("load_device_tree() failed" );exit (1 );
Signature · 1 line
2.47.3
Re: [PATCH v2 08/16] hw/riscv/atlantis: Remove unused fdt_size
Quoted 4 lines · Joel Stanley
The machine state carries around the FDT size which isn't used by anything.
Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 49 lines
---
include/hw/riscv/tt_atlantis.h | 2 --
hw/riscv/tt_atlantis.c | 6 ++++--2 files changed, 4 insertions(+), 4 deletions(-)include/hw/riscv/tt_atlantis.h +0
-2@@ -33,8 +33,6 @@ struct TTAtlantisState { DeviceState *irqchip; DesignWareI2CState i2c[TT_ATL_NUM_I2C]; UnimplementedDeviceState uart1; - - int fdt_size; };
enum {hw/riscv/tt_atlantis.c +1
-0@@ -366,9 +366,10 @@ static void finalize_fdt(TTAtlantisState *s) static void create_fdt(TTAtlantisState *s) { MachineState *ms = MACHINE(s); + int fdt_size = 0;
ms->fdt= create_board_device_tree("Tenstorrent Atlantis RISC-V Machine",
- "tenstorrent,atlantis", &s-Quoted 1 line
fdt_size);+ "tenstorrent,atlantis",
&fdt_size);
qemu_fdt_add_subnode(ms->fdt, "/chosen");hw/riscv/tt_atlantis.c +1
-0@@ -384,8 +385,9 @@ static void load_fdt(TTAtlantisState *s) MachineState *ms = MACHINE(s); char **node_path; Error *err = NULL; + int fdt_size = 0;
-ms->fdt=load_device_tree(ms->dtb, &s->fdt_size); +ms->fdt=load_device_tree(ms->dtb, &fdt_size); if (!ms->fdt) {error_report("load_device_tree() failed"); exit(1);
PATCH v2 9/16 hw/riscv/atlantis: Rename hart array 'soc' to 'cpus'
In reply to Joel StanleyThe RISCVHartArrayState member is named soc, but it's an array of cpus, not the entire SoC. Use cpus instead as an accurate description of the hart array.
--- include/hw/riscv/tt_atlantis.h | 2 +- hw/riscv/tt_atlantis.c | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-)
include/hw/riscv/tt_atlantis.h +1 -1
@@ -29,7 +29,7 @@ struct TTAtlantisState {Notifier machine_done;const MemMapEntry *memmap; -RISCVHartArrayState soc; +RISCVHartArrayState cpus;DeviceState *irqchip;DesignWareI2CState i2c[TT_ATL_NUM_I2C ];UnimplementedDeviceState uart1;
hw/riscv/tt_atlantis.c +17 -17
@@ -112,13 +112,13 @@ static void create_fdt_aclint(TTAtlantisState *s, uint32_t *intc_phandles)uint32_t aclint_cells_size;hwaddr addr; - aclint_mtimer_cells =g_new0 (uint32_t, s->soc.num_harts *2 ); + aclint_mtimer_cells =g_new0 (uint32_t, s->cpus.num_harts *2 ); -for (int cpu =0 ; cpu < s->soc.num_harts; cpu++) { +for (int cpu =0 ; cpu < s->cpus.num_harts; cpu++) { aclint_mtimer_cells[cpu *2 +0 ] =cpu_to_be32 (intc_phandles[cpu]); aclint_mtimer_cells[cpu *2 +1 ] =cpu_to_be32 (IRQ_M_TIMER ); } - aclint_cells_size = s->soc.num_harts *sizeof (uint32_t ) *2 ; + aclint_cells_size = s->cpus.num_harts *sizeof (uint32_t ) *2 ; addr = s->memmap[TT_ATL_ACLINT ].base;
@@ -210,7 +210,7 @@ static void create_fdt_pmu(TTAtlantisState *s) {char pmu_name[] ="/pmu" ;void *fdt =MACHINE (s)->fdt; -RISCVCPU *hart = &s->soc.harts[0 ]; +RISCVCPU *hart = &s->cpus.harts[0 ];qemu_fdt_add_subnode (fdt, pmu_name);qemu_fdt_setprop_string (fdt, pmu_name,"compatible" ,"riscv,pmu" );
@@ -227,8 +227,8 @@ static void create_fdt_cpu(TTAtlantisState *s, const MemMapEntry *memmap,fdt_create_cpu_socket_subnode (fdt,TT_ACLINT_TIMEBASE_FREQ ); -create_fdt_socket_cpus (fdt, s->soc.harts,0 , s->soc.num_harts, - s->soc.hartid_base, &fdt_phandle, intc_phandles, +create_fdt_socket_cpus (fdt, s->cpus.harts,0 , s->cpus.num_harts, + s->cpus.hartid_base, &fdt_phandle, intc_phandles, false, false);create_fdt_memory (s);
@@ -252,13 +252,13 @@ static void create_fdt_cpu(TTAtlantisState *s, const MemMapEntry *memmap,create_fdt_one_aplic (fdt, &s->memmap[TT_ATL_MAPLIC ], msi_m_phandle, intc_phandles, aplic_m_phandle, aplic_s_phandle, -IRQ_M_EXT , s->soc.num_harts); +IRQ_M_EXT , s->cpus.num_harts);/* S-level APLIC node */ create_fdt_one_aplic (fdt, &s->memmap[TT_ATL_SAPLIC ], imsic_s_phandle, intc_phandles, aplic_s_phandle,0 , -IRQ_S_EXT , s->soc.num_harts); +IRQ_S_EXT , s->cpus.num_harts); } static void create_fdt_uart(void *fdt, const MemMapEntry *mem, int irq,
@@ -429,7 +429,7 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data)hwaddr start_addr = s->memmap[TT_ATL_DDR_LO ].base;hwaddr mem_size;target_ulong firmware_end_addr, kernel_start_addr; -const char *firmware_name =riscv_default_firmware_name (&s->soc); +const char *firmware_name =riscv_default_firmware_name (&s->cpus);uint64_t fdt_load_addr;uint64_t kernel_entry;RISCVBootInfo boot_info;
@@ -446,7 +446,7 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data)if (mem_size > s->memmap[TT_ATL_DDR_LO ].size) { mem_size = s->memmap[TT_ATL_DDR_LO ].size; } -riscv_boot_info_init_discontig_mem (&boot_info, &s->soc, +riscv_boot_info_init_discontig_mem (&boot_info, &s->cpus, s->memmap[TT_ATL_DDR_LO ].base, mem_size);
@@ -476,7 +476,7 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data)riscv_load_fdt (fdt_load_addr, machine->fdt);/* load the reset vector */ - riscv_setup_rom_reset_vec(machine, &s->soc, start_addr, + riscv_setup_rom_reset_vec(machine, &s->cpus, start_addr, s->memmap[TT_ATL_BOOTROM].base, s->memmap[TT_ATL_BOOTROM].size, kernel_entry,
@@ -496,18 +496,18 @@ static void tt_atlantis_machine_init(MachineState *machine) s->memmap = tt_atlantis_memmap; -object_initialize_child (OBJECT (machine),"soc" , &s->soc, +object_initialize_child (OBJECT (machine),"soc" , &s->cpus,TYPE_RISCV_HART_ARRAY ); -object_property_set_str (OBJECT (&s->soc),"cpu-type" , machine->cpu_type, +object_property_set_str (OBJECT (&s->cpus),"cpu-type" , machine->cpu_type, &error_abort); -object_property_set_int (OBJECT (&s->soc),"hartid-base" ,0 , +object_property_set_int (OBJECT (&s->cpus),"hartid-base" ,0 , &error_abort); -object_property_set_int (OBJECT (&s->soc),"num-harts" , hart_count, +object_property_set_int (OBJECT (&s->cpus),"num-harts" , hart_count, &error_abort); -object_property_set_int (OBJECT (&s->soc),"resetvec" , +object_property_set_int (OBJECT (&s->cpus),"resetvec" , s->memmap[TT_ATL_BOOTROM ].base, &error_abort); -sysbus_realize (SYS_BUS_DEVICE (&s->soc), &error_fatal); +sysbus_realize (SYS_BUS_DEVICE (&s->cpus), &error_fatal); s->irqchip = riscv_create_aia(system_memory, true, TT_IMSIC_GUESTS,
Signature · 1 line
2.47.3
Re: [PATCH v2 09/16] hw/riscv/atlantis: Rename hart array 'soc' to 'cpus'
Quoted 15 lines · Joel Stanley
The RISCVHartArrayState member is named soc, but it's an array of cpus, not the entire SoC. Use cpus instead as an accurate description of the hart array.
Signed-off-by Joel Stanley <[email protected]>--- include/hw/riscv/tt_atlantis.h | 2 +- hw/riscv/tt_atlantis.c | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-)include/hw/riscv/tt_atlantis.h +0
-0
include/hw/riscv/tt_atlantis.h struct TTAtlantisState { · line 32
Quoted 5 lines
include/hw/riscv/tt_atlantis.h +1
-1@@ -29,7 +29,7 @@ struct TTAtlantisState {Notifier machine_done;const MemMapEntry *memmap; -RISCVHartArrayState soc; +RISCVHartArrayState cpus;
@hart_cluster could be more pedantically correct.
Re: [PATCH v2 09/16] hw/riscv/atlantis: Rename hart array 'soc' to 'cpus'
In reply to Joel StanleyQuoted 7 lines · Joel Stanley
The RISCVHartArrayState member is named soc, but it's an array of cpus,
not the entire SoC. Use cpus instead as an accurate description of the
hart array.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 148 lines
---
include/hw/riscv/tt_atlantis.h | 2 +- hw/riscv/tt_atlantis.c | 34 +++++++++++++++++--------------- --2 files changed, 18 insertions(+), 18 deletions(-)include/hw/riscv/tt_atlantis.h +0
-0@@ -29,7 +29,7 @@ struct TTAtlantisState { Notifier machine_done; const MemMapEntry *memmap;
- RISCVHartArrayState soc;
+ RISCVHartArrayState cpus;
DeviceState *irqchip;
DesignWareI2CState i2c[TT_ATL_NUM_I2C];
UnimplementedDeviceState uart1;hw/riscv/tt_atlantis.c +0
-0@@ -112,13 +112,13 @@ static void create_fdt_aclint(TTAtlantisState *s, uint32_t *intc_phandles) uint32_t aclint_cells_size; hwaddr addr;
-aclint_mtimer_cells=g_new0(uint32_t, s->soc.num_harts * 2); +aclint_mtimer_cells=g_new0(uint32_t, s->cpus.num_harts * 2);
- for (int cpu = 0; cpu <s->soc.num_harts; cpu++) {
+ for (int cpu = 0; cpu <s->cpus.num_harts; cpu++) { aclint_mtimer_cells[cpu * 2 + 0] =cpu_to_be32(intc_phandles[cpu]);
aclint_mtimer_cells[cpu * 2 + 1] =cpu_to_be32(IRQ_M_TIMER); }
-aclint_cells_size=s->soc.num_harts*sizeof(uint32_t)* 2; +aclint_cells_size=s->cpus.num_harts*sizeof(uint32_t)* 2;
addr = s->memmap[TT_ATL_ACLINT].base;hw/riscv/tt_atlantis.c +1
-1@@ -210,7 +210,7 @@ static void create_fdt_pmu(TTAtlantisState *s) { char pmu_name[] = "/pmu"; void *fdt = MACHINE(s)->fdt; - RISCVCPU *hart = &s->soc.harts[0]; + RISCVCPU *hart = &s->cpus.harts[0];
qemu_fdt_add_subnode(fdt, pmu_name);qemu_fdt_setprop_string(fdt, pmu_name, "compatible", "riscv,pmu");hw/riscv/tt_atlantis.c +0
-0@@ -227,8 +227,8 @@ static void create_fdt_cpu(TTAtlantisState *s, const MemMapEntry *memmap,
fdt_create_cpu_socket_subnode(fdt, TT_ACLINT_TIMEBASE_FREQ);
- create_fdt_socket_cpus(fdt,s->soc.harts, 0,s->soc.num_harts, -s->soc.hartid_base,&fdt_phandle,intc_phandles,
+ create_fdt_socket_cpus(fdt,s->cpus.harts, 0,s->cpus.num_harts, +s->cpus.hartid_base,&fdt_phandle,intc_phandles,
false, false);
create_fdt_memory(s);hw/riscv/tt_atlantis.c +1
-1@@ -252,13 +252,13 @@ static void create_fdt_cpu(TTAtlantisState *s,const MemMapEntry *memmap, create_fdt_one_aplic(fdt, &s->memmap[TT_ATL_MAPLIC], msi_m_phandle, intc_phandles, aplic_m_phandle, aplic_s_phandle, - IRQ_M_EXT, s->soc.num_harts); + IRQ_M_EXT, s->cpus.num_harts);
/* S-level APLIC node */
create_fdt_one_aplic(fdt, &s->memmap[TT_ATL_SAPLIC],imsic_s_phandle,intc_phandles,aplic_s_phandle, 0,
-IRQ_S_EXT,s->soc.num_harts); +IRQ_S_EXT,s->cpus.num_harts); }
static void create_fdt_uart(void *fdt, const MemMapEntry *mem, int irq,hw/riscv/tt_atlantis.c +1
-1@@ -429,7 +429,7 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data) hwaddr start_addr = s->memmap[TT_ATL_DDR_LO].base; hwaddr mem_size; target_ulong firmware_end_addr, kernel_start_addr; - const char *firmware_name = riscv_default_firmware_name(&s- >soc); + const char *firmware_name = riscv_default_firmware_name(&s- >cpus);
uint64_tfdt_load_addr;
uint64_tkernel_entry;
RISCVBootInfoboot_info;hw/riscv/tt_atlantis.c +1
-1@@ -446,7 +446,7 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data) if (mem_size > s->memmap[TT_ATL_DDR_LO].size) { mem_size = s->memmap[TT_ATL_DDR_LO].size; } - riscv_boot_info_init_discontig_mem(&boot_info, &s->soc, + riscv_boot_info_init_discontig_mem(&boot_info, &s->cpus,s-
Quoted 1 line
memmap[TT_ATL_DDR_LO].base,
mem_size);hw/riscv/tt_atlantis.c +0
-0@@ -476,7 +476,7 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data) riscv_load_fdt(fdt_load_addr, machine->fdt);
/* load the reset vector */
- riscv_setup_rom_reset_vec(machine,&s->soc,start_addr, + riscv_setup_rom_reset_vec(machine,&s->cpus,start_addr, s->memmap[TT_ATL_BOOTROM].base, s->memmap[TT_ATL_BOOTROM].size,kernel_entry,hw/riscv/tt_atlantis.c +0
-0@@ -496,18 +496,18 @@ static voidtt_atlantis_machine_init (MachineState *machine)
s->memmap=tt_atlantis_memmap;
- object_initialize_child(OBJECT(machine), "soc",&s->soc, +object_initialize_child(OBJECT(machine), "soc", &s->cpus, TYPE_RISCV_HART_ARRAY);
- object_property_set_str(OBJECT(&s->soc), "cpu-type", machine-Quoted 1 line
cpu_type,+ object_property_set_str(OBJECT(&s->cpus), "cpu-type", machine-
Quoted 1 line
cpu_type,
&error_abort);
- object_property_set_int(OBJECT(&s->soc), "hartid-base", 0, +object_property_set_int(OBJECT(&s->cpus), "hartid-base", 0, &error_abort);
- object_property_set_int(OBJECT(&s->soc), "num-harts",hart_count,
+ object_property_set_int(OBJECT(&s->cpus), "num-harts",hart_count,
&error_abort);
- object_property_set_int(OBJECT(&s->soc), "resetvec", +object_property_set_int(OBJECT(&s->cpus), "resetvec", s->memmap[TT_ATL_BOOTROM].base, &error_abort);
-sysbus_realize(SYS_BUS_DEVICE(&s->soc), &error_fatal); +sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal);
s->irqchip= riscv_create_aia(system_memory, true,TT_IMSIC_GUESTS,
PATCH v2 10/16 hw/riscv/atlantis: Rework device tree creation
In reply to Joel StanleyRemove the direct use of MachineState from the device tree creation to allow separation between the SoC (TTAtlantisState) and the QEMU MachineState.
Fix this for the device tree pointer by passing it directly to the functions that use it, instead of casting the TTAtlantisState to a MachineState.
MachineState::smp.cpus is replaced with TTAtlantisState::cpus.num_harts, as these are equivalent after tt_atlantis_machine_init.
--- hw/riscv/tt_atlantis.c | 51 +++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 28 deletions(-)
hw/riscv/tt_atlantis.c +23 -28
@@ -80,9 +80,8 @@ static uint32_t next_phandle(void)return fdt_phandle++; } -static void create_fdt_memory (TTAtlantisState *s) +static void create_fdt_memory (void *fdt,TTAtlantisState *s) { -void *fdt =MACHINE (s)->fdt;hwaddr size_lo =MACHINE (s)->ram_size;hwaddr size_hi =0 ;
@@ -104,9 +103,9 @@ static void create_fdt_memory(TTAtlantisState *s) } } -static void create_fdt_aclint (TTAtlantisState *s,uint32_t *intc_phandles) +static void create_fdt_aclint (void *fdt,TTAtlantisState *s, +uint32_t *intc_phandles) { -void *fdt =MACHINE (s)->fdt; g_autofree char *name = NULL; g_autofree uint32_t *aclint_mtimer_cells = NULL;uint32_t aclint_cells_size;
@@ -206,10 +205,9 @@ static void create_fdt_one_aplic(void *fdt,qemu_fdt_setprop_cell (fdt, name,"phandle" , aplic_phandle); } -static void create_fdt_pmu (TTAtlantisState *s) +static void create_fdt_pmu (void *fdt,TTAtlantisState *s) {char pmu_name[] ="/pmu" ; -void *fdt =MACHINE (s)->fdt;RISCVCPU *hart = &s->cpus.harts[0 ];qemu_fdt_add_subnode (fdt, pmu_name);
@@ -217,32 +215,29 @@ static void create_fdt_pmu(TTAtlantisState *s)riscv_pmu_generate_fdt_node (fdt, hart->pmu_avail_ctrs, pmu_name); } -static void create_fdt_cpu (TTAtlantisState *s,const MemMapEntry *memmap, +static void create_fdt_cpu (void *fdt,TTAtlantisState *s,uint32_t aplic_s_phandle,uint32_t imsic_s_phandle) { -MachineState *ms =MACHINE (s); -void *fdt =MACHINE (s)->fdt; - g_autofree uint32_t *intc_phandles = g_new0(uint32_t, ms->smp.cpus); + g_autofree uint32_t *intc_phandles = g_new0(uint32_t, s->cpus.num_harts); +int num_harts = s->cpus.num_harts;fdt_create_cpu_socket_subnode (fdt,TT_ACLINT_TIMEBASE_FREQ ); -create_fdt_socket_cpus (fdt, s->cpus.harts,0 , s->cpus.num_harts, +create_fdt_socket_cpus (fdt, s->cpus.harts,0 , num_harts, s->cpus.hartid_base, &fdt_phandle, intc_phandles, false, false); -create_fdt_memory (s); - -create_fdt_aclint (s, intc_phandles); +create_fdt_aclint (fdt, s, intc_phandles);/* M-level IMSIC node */ uint32_t msi_m_phandle =next_phandle (); -create_fdt_one_imsic (fdt, &s->memmap[TT_ATL_MIMSIC ], ms->smp.cpus, +create_fdt_one_imsic (fdt, &s->memmap[TT_ATL_MIMSIC ], num_harts, intc_phandles, msi_m_phandle,IRQ_M_EXT ,TT_IMSIC_GUEST_BITS );/* S-level IMSIC node */ -create_fdt_one_imsic (fdt, &s->memmap[TT_ATL_SIMSIC ], ms->smp.cpus, +create_fdt_one_imsic (fdt, &s->memmap[TT_ATL_SIMSIC ], num_harts, intc_phandles, imsic_s_phandle,IRQ_S_EXT ,TT_IMSIC_GUEST_BITS );
@@ -252,13 +247,13 @@ static void create_fdt_cpu(TTAtlantisState *s, const MemMapEntry *memmap,create_fdt_one_aplic (fdt, &s->memmap[TT_ATL_MAPLIC ], msi_m_phandle, intc_phandles, aplic_m_phandle, aplic_s_phandle, -IRQ_M_EXT , s->cpus.num_harts); +IRQ_M_EXT , num_harts);/* S-level APLIC node */ create_fdt_one_aplic (fdt, &s->memmap[TT_ATL_SAPLIC ], imsic_s_phandle, intc_phandles, aplic_s_phandle,0 , -IRQ_S_EXT , s->cpus.num_harts); +IRQ_S_EXT , num_harts); } static void create_fdt_uart(void *fdt, const MemMapEntry *mem, int irq,
@@ -317,10 +312,9 @@ static void create_fdt_i2c(void *fdt, const MemMapEntry *mem, uint32_t irq,qemu_fdt_setprop_cell (fdt, name,"#size-cells" ,0 ); } -static void create_fdt_i2c_device (TTAtlantisState *s,int bus, +static void create_fdt_i2c_device (void *fdt,TTAtlantisState *s,int bus,const char *compat,int addr) { -void *fdt =MACHINE (s)->fdt;hwaddr base = s->memmap[TT_ATL_I2C0 + bus].base; g_autofree char *name = g_strdup_printf("/soc/i2c@%"HWADDR_PRIX"/sensor@%x", base, addr);
@@ -330,14 +324,15 @@ static void create_fdt_i2c_device(TTAtlantisState *s, int bus,qemu_fdt_setprop_cell (fdt, name,"reg" , addr); } -static void finalize_fdt (TTAtlantisState *s) +static void finalize_fdt (void *fdt,TTAtlantisState *s) {uint32_t aplic_s_phandle =next_phandle ();uint32_t imsic_s_phandle =next_phandle ();uint32_t periph_clk_phandle =next_phandle (); -void *fdt =MACHINE (s)->fdt; -create_fdt_cpu (s, s->memmap, aplic_s_phandle, imsic_s_phandle); +create_fdt_cpu (fdt, s, aplic_s_phandle, imsic_s_phandle); + +create_fdt_memory (fdt, s);/* * We want to do this, but the Linux aplic driver was broken before v6.16
@@ -359,8 +354,8 @@ static void finalize_fdt(TTAtlantisState *s) }/* I2C peripherals: qemu specific */ -create_fdt_i2c_device (s,0 ,"dallas,ds1338" ,0x6f ); -create_fdt_i2c_device (s,4 ,"ti,tmp105" ,0x48 ); +create_fdt_i2c_device (fdt, s,0 ,"dallas,ds1338" ,0x6f ); +create_fdt_i2c_device (fdt, s,4 ,"ti,tmp105" ,0x48 ); }static void create_fdt (TTAtlantisState *s)
@@ -377,7 +372,7 @@ static void create_fdt(TTAtlantisState *s)qemu_fdt_add_subnode (ms->fdt,"/aliases" ); -create_fdt_pmu (s); +create_fdt_pmu (ms->fdt, s); }static void load_fdt (TTAtlantisState *s)
@@ -408,7 +403,7 @@ static void load_fdt(TTAtlantisState *s)g_strfreev (node_path); } -create_fdt_memory (s); +create_fdt_memory (ms->fdt, s); } static void mmio_map_unimplemented(MemoryRegion *memory, SysBusDevice *dev,
@@ -439,7 +434,7 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data)* dynamic sysbus devices. Our FDT needs to be finalized. */ if (machine->dtb ==NULL ) { -finalize_fdt (s); +finalize_fdt (machine->fdt, s); } mem_size = machine->ram_size;
Signature · 1 line
2.47.3
Re: [PATCH v2 10/16] hw/riscv/atlantis: Rework device tree creation
Quoted 8 lines · Joel Stanley
Remove the direct use of MachineState from the device tree creation to allow separation between the SoC (TTAtlantisState) and the QEMU MachineState.
Fix this for the device tree pointer by passing it directly to the functions that use it, instead of casting the TTAtlantisState to a MachineState.
Quoted 7 lines
MachineState::smp.cpusis replaced withTTAtlantisState::cpus.num_harts, as these are equivalent aftertt_atlantis_machine_init.Signed-off-by Joel Stanley <[email protected]>--- hw/riscv/tt_atlantis.c | 51 +++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 28 deletions(-)
Re: [PATCH v2 10/16] hw/riscv/atlantis: Rework device tree creation
In reply to Joel StanleyQuoted 9 lines · Joel Stanley
Remove the direct use of MachineState from the device tree creation to
allow separation between the SoC (TTAtlantisState) and the QEMU MachineState.Fix this for the device tree pointer by passing it directly to the functions that use it, instead of casting the TTAtlantisState to a MachineState.
Quoted 5 lines
MachineState::smp.cpusis replaced withTTAtlantisState::cpus.num_harts,
as these are equivalent aftertt_atlantis_machine_init.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 186 lines
---
hw/riscv/tt_atlantis.c | 51 +++++++++++++++++++--------------------- --1 file changed, 23 insertions(+), 28 deletions(-)hw/riscv/tt_atlantis.c +0
-0@@ -80,9 +80,8 @@ static uint32_t next_phandle(void) return fdt_phandle++; }hw/riscv/tt_atlantis.c +1
-1-static void create_fdt_memory (TTAtlantisState *s) +static void create_fdt_memory (void *fdt,TTAtlantisState *s){
- void *fdt = MACHINE(s)->fdt;
hwaddrsize_lo= MACHINE(s)->ram_size;
hwaddrsize_hi= 0;hw/riscv/tt_atlantis.c +0
-0@@ -104,9 +103,9 @@ static void create_fdt_memory(TTAtlantisState *s) } }
-static voidcreate_fdt_aclint(TTAtlantisState *s, uint32_t *intc_phandles)
+static void create_fdt_aclint(void *fdt, TTAtlantisState *s, +uint32_t*intc_phandles) {
- void *fdt = MACHINE(s)->fdt;
g_autofreechar *name = NULL;
g_autofreeuint32_t*aclint_mtimer_cells= NULL;uint32_taclint_cells_size;hw/riscv/tt_atlantis.c +0
-0@@ -206,10 +205,9 @@ static void create_fdt_one_aplic(void *fdt, qemu_fdt_setprop_cell(fdt, name, "phandle", aplic_phandle); }hw/riscv/tt_atlantis.c +1
-1-static void create_fdt_pmu (TTAtlantisState *s) +static void create_fdt_pmu (void *fdt,TTAtlantisState *s){
char pmu_name[] = "/pmu";
- void *fdt = MACHINE(s)->fdt;
RISCVCPU *hart = &s->cpus.harts[0];
qemu_fdt_add_subnode(fdt, pmu_name);hw/riscv/tt_atlantis.c +0
-0@@ -217,32 +215,29 @@ static void create_fdt_pmu(TTAtlantisState *s) riscv_pmu_generate_fdt_node(fdt, hart->pmu_avail_ctrs, pmu_name); }
-static void create_fdt_cpu(TTAtlantisState *s, const MemMapEntry *memmap,
+static voidcreate_fdt_cpu(void *fdt, TTAtlantisState *s, uint32_t aplic_s_phandle, uint32_t imsic_s_phandle)
{
- MachineState *ms = MACHINE(s);
- void *fdt = MACHINE(s)->fdt;
-g_autofreeuint32_t*intc_phandles= g_new0(uint32_t, ms-Quoted 1 line
smp.cpus);
+
g_autofreeuint32_t*intc_phandles= g_new0(uint32_t, s-Quoted 1 line
cpus.num_harts);
+ int
num_harts=s->cpus.num_harts;
fdt_create_cpu_socket_subnode(fdt, TT_ACLINT_TIMEBASE_FREQ);
- create_fdt_socket_cpus(fdt,s->cpus.harts, 0,s->cpus.num_harts, + create_fdt_socket_cpus(fdt,s->cpus.harts, 0,num_harts,s->cpus.hartid_base,&fdt_phandle,intc_phandles,
false, false);
-create_fdt_memory(s);
-
-create_fdt_aclint(s, intc_phandles);
+create_fdt_aclint(fdt, s, intc_phandles);
/* M-level IMSIC node */
uint32_tmsi_m_phandle=next_phandle();
- create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_MIMSIC], ms-Quoted 1 line
smp.cpus,
+ create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_MIMSIC],
num_harts,intc_phandles,msi_m_phandle,IRQ_M_EXT,TT_IMSIC_GUEST_BITS);
/* S-level IMSIC node */
- create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_SIMSIC], ms-Quoted 1 line
smp.cpus,
+ create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_SIMSIC],
num_harts,intc_phandles,imsic_s_phandle,IRQ_S_EXT,TT_IMSIC_GUEST_BITS);hw/riscv/tt_atlantis.c +1
-1@@ -252,13 +247,13 @@ static void create_fdt_cpu(TTAtlantisState *s,const MemMapEntry *memmap, create_fdt_one_aplic(fdt, &s->memmap[TT_ATL_MAPLIC], msi_m_phandle, intc_phandles, aplic_m_phandle, aplic_s_phandle, - IRQ_M_EXT, s->cpus.num_harts); + IRQ_M_EXT, num_harts);
/* S-level APLIC node */
create_fdt_one_aplic(fdt, &s->memmap[TT_ATL_SAPLIC],imsic_s_phandle,intc_phandles,aplic_s_phandle, 0,
-IRQ_S_EXT,s->cpus.num_harts); +IRQ_S_EXT,num_harts);
}
static void create_fdt_uart(void *fdt, const MemMapEntry *mem, int irq,hw/riscv/tt_atlantis.c +0
-0@@ -317,10 +312,9 @@ static void create_fdt_i2c(void *fdt, const MemMapEntry *mem, uint32_t irq, qemu_fdt_setprop_cell(fdt, name, "#size-cells", 0); }hw/riscv/tt_atlantis.c +1
-1-static void create_fdt_i2c_device(TTAtlantisState *s, int bus, +static void create_fdt_i2c_device(void *fdt, TTAtlantisState *s, intbus,
const char *compat, int addr) {
- void *fdt = MACHINE(s)->fdt;
hwaddr base = s->memmap[TT_ATL_I2C0 + bus].base;g_autofreechar *name =g_strdup_printf("/soc/i2c@%"HWADDR_PRIX"/sensor@%x", base, addr);hw/riscv/tt_atlantis.c +0
-0@@ -330,14 +324,15 @@ static void create_fdt_i2c_device(TTAtlantisState *s, int bus, qemu_fdt_setprop_cell(fdt, name, "reg", addr); }hw/riscv/tt_atlantis.c +1
-1-static void finalize_fdt (TTAtlantisState *s) +static void finalize_fdt (void *fdt,TTAtlantisState *s){
uint32_taplic_s_phandle=next_phandle();
uint32_timsic_s_phandle=next_phandle();
uint32_tperiph_clk_phandle=next_phandle();
- void *fdt = MACHINE(s)->fdt;
-create_fdt_cpu(s, s->memmap, aplic_s_phandle, imsic_s_phandle); +create_fdt_cpu(fdt, s, aplic_s_phandle, imsic_s_phandle); +
+create_fdt_memory(fdt, s);
/*
* We want to do this, but the Linux aplic driver was broken before v6.16hw/riscv/tt_atlantis.c +0
-0@@ -359,8 +354,8 @@ static void finalize_fdt(TTAtlantisState *s) }
/* I2C peripherals: qemu specific */
-create_fdt_i2c_device(s, 0, "dallas,ds1338", 0x6f); -create_fdt_i2c_device(s, 4, "ti,tmp105", 0x48); +create_fdt_i2c_device(fdt, s, 0, "dallas,ds1338", 0x6f); +create_fdt_i2c_device(fdt, s, 4, "ti,tmp105", 0x48); }
static voidcreate_fdt(TTAtlantisState *s)hw/riscv/tt_atlantis.c +0
-0@@ -377,7 +372,7 @@ static void create_fdt(TTAtlantisState *s)
qemu_fdt_add_subnode(ms->fdt, "/aliases");
-create_fdt_pmu(s);
+create_fdt_pmu(ms->fdt, s);
}
static voidload_fdt(TTAtlantisState *s)hw/riscv/tt_atlantis.c +0
-0@@ -408,7 +403,7 @@ static void load_fdt(TTAtlantisState *s) g_strfreev(node_path); }
-create_fdt_memory(s);
+create_fdt_memory(ms->fdt, s);
}
static void mmio_map_unimplemented(MemoryRegion *memory, SysBusDevice *dev,hw/riscv/tt_atlantis.c +1
-1@@ -439,7 +434,7 @@ static void tt_atlantis_machine_done(Notifier*notifier, void *data) * dynamic sysbus devices. Our FDT needs to be finalized. */ if (machine->dtb == NULL) { - finalize_fdt(s); + finalize_fdt(machine->fdt, s); }
mem_size=machine->ram_size;
PATCH v2 11/16 hw/riscv/atlantis: Use local reference for system memory
In reply to Joel StanleyInstead of system_memory, attach devices to TTAtlantisState::memory in preparation for the ->memory becoming a container.
--- include/hw/riscv/tt_atlantis.h | 1 + hw/riscv/tt_atlantis.c | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-)
include/hw/riscv/tt_atlantis.h +1 -0
@@ -29,6 +29,7 @@ struct TTAtlantisState {Notifier machine_done;const MemMapEntry *memmap; +MemoryRegion *memory;RISCVHartArrayState cpus;DeviceState *irqchip;DesignWareI2CState i2c[TT_ATL_NUM_I2C ];
hw/riscv/tt_atlantis.c +10 -9
@@ -482,13 +482,14 @@ static void tt_atlantis_machine_init(MachineState *machine) {TTAtlantisState *s =TT_ATLANTIS_MACHINE (machine); -MemoryRegion *system_memory =get_system_memory ();MemoryRegion *ram_hi =g_new (MemoryRegion,1 );MemoryRegion *ram_lo =g_new (MemoryRegion,1 );MemoryRegion *bootrom =g_new (MemoryRegion,1 );ram_addr_t lo_ram_size;int hart_count = machine->smp.cpus; + s->memory =get_system_memory (); + s->memmap = tt_atlantis_memmap; object_initialize_child(OBJECT(machine), "soc", &s->cpus,
@@ -504,7 +505,7 @@ static void tt_atlantis_machine_init(MachineState *machine) &error_abort);sysbus_realize (SYS_BUS_DEVICE (&s->cpus), &error_fatal); - s->irqchip = riscv_create_aia(system_memory, + s->irqchip = riscv_create_aia(s->memory, true, TT_IMSIC_GUESTS, TT_IMSIC_STRIDE, TT_IMSIC_STRIDE,
@@ -517,7 +518,7 @@ static void tt_atlantis_machine_init(MachineState *machine)TT_IRQCHIP_NUM_MSIS , TT_IRQCHIP_NUM_PRIO_BITS); - riscv_aclint_mtimer_create(system_memory, + riscv_aclint_mtimer_create(s->memory, s->memmap[TT_ATL_ACLINT].base, TT_ACLINT_MTIME_SIZE, 0, hart_count,
@@ -540,23 +541,23 @@ static void tt_atlantis_machine_init(MachineState *machine)memory_region_init_alias (ram_hi,OBJECT (machine),"ram.high" , machine->ram,0 , machine->ram_size); -memory_region_add_subregion (system_memory, +memory_region_add_subregion (s->memory, s->memmap[TT_ATL_DDR_HI ].base, ram_hi); lo_ram_size =MIN (machine->ram_size, s->memmap[TT_ATL_DDR_LO ].size);memory_region_init_alias (ram_lo,OBJECT (machine),"ram.low" , machine->ram,0 , lo_ram_size); -memory_region_add_subregion (system_memory, +memory_region_add_subregion (s->memory, s->memmap[TT_ATL_DDR_LO ].base, ram_lo);/* Boot ROM */ memory_region_init_rom (bootrom,NULL ,"tt-atlantis.bootrom" , s->memmap[TT_ATL_BOOTROM ].size, &error_fatal); -memory_region_add_subregion (system_memory, s->memmap[TT_ATL_BOOTROM ].base, +memory_region_add_subregion (s->memory, s->memmap[TT_ATL_BOOTROM ].base, bootrom);/* UART1, the soc console (UART0 is for the boot microcontroller) */ -serial_mm_init (system_memory, s->memmap[TT_ATL_UART1 ].base,2 , +serial_mm_init (s->memory, s->memmap[TT_ATL_UART1 ].base,2 ,qdev_get_gpio_in (s->irqchip,TT_ATL_UART1_IRQ ),115200 ,serial_hd (0 ),DEVICE_LITTLE_ENDIAN );/*
@@ -570,7 +571,7 @@ static void tt_atlantis_machine_init(MachineState *machine)*/ object_initialize_child (OBJECT (s),"uart1" , &s->uart1,TYPE_UNIMPLEMENTED_DEVICE ); -mmio_map_unimplemented (system_memory,SYS_BUS_DEVICE (&s->uart1), +mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->uart1),"tt-atlantis.uart1" , s->memmap[TT_ATL_UART1 ].base, s->memmap[TT_ATL_UART1 ].size);
@@ -582,7 +583,7 @@ static void tt_atlantis_machine_init(MachineState *machine) TYPE_DESIGNWARE_I2C); sbd =SYS_BUS_DEVICE (&s->i2c[i]);sysbus_realize (sbd, &error_fatal); -memory_region_add_subregion (system_memory, +memory_region_add_subregion (s->memory, s->memmap[TT_ATL_I2C0 + i].base,sysbus_mmio_get_region (sbd,0 )); sysbus_connect_irq(sbd, 0,
Signature · 1 line
2.47.3
Re: [PATCH v2 11/16] hw/riscv/atlantis: Use local reference for system memory
Quoted 5 lines · Joel Stanley
Instead of
system_memory, attach devices toTTAtlantisState::memoryin
preparation for the ->memory becoming a container.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 118 lines
---
include/hw/riscv/tt_atlantis.h | 1 + hw/riscv/tt_atlantis.c | 19 ++++++++++---------2 files changed, 11 insertions(+), 9 deletions(-)include/hw/riscv/tt_atlantis.h +0
-0@@ -29,6 +29,7 @@ struct TTAtlantisState { Notifier machine_done; const MemMapEntry *memmap;
+ MemoryRegion *memory;
RISCVHartArrayState cpus;
DeviceState *irqchip;
DesignWareI2CState i2c[TT_ATL_NUM_I2C];hw/riscv/tt_atlantis.c +0
-0@@ -482,13 +482,14 @@ static voidtt_atlantis_machine_init (MachineState *machine) { TTAtlantisState *s = TT_ATLANTIS_MACHINE(machine);
- MemoryRegion*system_memory=get_system_memory(); MemoryRegion*ram_hi=g_new(MemoryRegion, 1); MemoryRegion*ram_lo=g_new(MemoryRegion, 1); MemoryRegion *bootrom =g_new(MemoryRegion, 1);ram_addr_tlo_ram_size;
inthart_count=machine->smp.cpus;
+s->memory=get_system_memory();
+
s->memmap=tt_atlantis_memmap;
object_initialize_child(OBJECT(machine), "soc",&s->cpus,hw/riscv/tt_atlantis.c +0
-0@@ -504,7 +505,7 @@ static void tt_atlantis_machine_init(MachineState *machine) &error_abort); sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal);
-s->irqchip= riscv_create_aia(system_memory, +s->irqchip= riscv_create_aia(s->memory, true,TT_IMSIC_GUESTS,TT_IMSIC_STRIDE,TT_IMSIC_STRIDE,hw/riscv/tt_atlantis.c +0
-0@@ -517,7 +518,7 @@ static void tt_atlantis_machine_init(MachineState *machine) TT_IRQCHIP_NUM_MSIS, TT_IRQCHIP_NUM_PRIO_BITS);
- riscv_aclint_mtimer_create(system_memory,
+ riscv_aclint_mtimer_create(s->memory,
s->memmap[TT_ATL_ACLINT].base,
TT_ACLINT_MTIME_SIZE,
0,hart_count,hw/riscv/tt_atlantis.c +0
-0@@ -540,23 +541,23 @@ static voidtt_atlantis_machine_init (MachineState *machine)
memory_region_init_alias(ram_hi, OBJECT(machine), "ram.high",machine->ram,
0,machine->ram_size);
- memory_region_add_subregion(system_memory,
+memory_region_add_subregion(s->memory, s->memmap[TT_ATL_DDR_HI].base, ram_hi);
lo_ram_size= MIN(machine->ram_size, s-Quoted 1 line
memmap[TT_ATL_DDR_LO].size);
memory_region_init_alias(ram_lo, OBJECT(machine), "ram.low",
machine->ram,
0,lo_ram_size);
- memory_region_add_subregion(system_memory,
+memory_region_add_subregion(s->memory, s->memmap[TT_ATL_DDR_LO].base, ram_lo);
/* Boot ROM */
memory_region_init_rom(bootrom, NULL, "tt-atlantis.bootrom", s->memmap[TT_ATL_BOOTROM].size, &error_fatal);
- memory_region_add_subregion(system_memory, s-Quoted 1 line
memmap[TT_ATL_BOOTROM].base,
+ memory_region_add_subregion(s->memory, s-
Quoted 1 line
memmap[TT_ATL_BOOTROM].base,
bootrom);
/* UART1, the soc console (UART0 is for the boot microcontroller) */
- serial_mm_init(system_memory, s->memmap[TT_ATL_UART1].base, 2, + serial_mm_init(s->memory, s->memmap[TT_ATL_UART1].base, 2,qdev_get_gpio_in(s->irqchip, TT_ATL_UART1_IRQ), 115200,serial_hd(0),DEVICE_LITTLE_ENDIAN); /*hw/riscv/tt_atlantis.c +1
-1@@ -570,7 +571,7 @@ static void tt_atlantis_machine_init(MachineState*machine) */ object_initialize_child(OBJECT(s), "uart1", &s->uart1, TYPE_UNIMPLEMENTED_DEVICE); - mmio_map_unimplemented(system_memory, SYS_BUS_DEVICE(&s->uart1), + mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->uart1),"tt-atlantis.uart1", s-
Quoted 1 line
memmap[TT_ATL_UART1].base,
s->memmap[TT_ATL_UART1].size);
hw/riscv/tt_atlantis.c +1
-1@@ -582,7 +583,7 @@ static void tt_atlantis_machine_init(MachineState *machine) TYPE_DESIGNWARE_I2C); sbd = SYS_BUS_DEVICE(&s->i2c[i]); sysbus_realize(sbd, &error_fatal); - memory_region_add_subregion(system_memory, + memory_region_add_subregion(s->memory, s->memmap[TT_ATL_I2C0 + i].base, sysbus_mmio_get_region(sbd, 0));sysbus_connect_irq(sbd, 0,
PATCH v2 12/16 hw/riscv/atlantis: Decouple RAM size from MachineState
In reply to Joel StanleyKeep a reference to the machine's RAM MemoryRegion in TTAtlantisState, and get the MemoryRegion's size where the configured RAM size is required.
This allows reading the RAM size without needing a pointer to MachineState, decoupling the memory layout setup from the machine.
--- include/hw/riscv/tt_atlantis.h | 1 + hw/riscv/tt_atlantis.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-)
include/hw/riscv/tt_atlantis.h +1 -0
@@ -30,6 +30,7 @@ struct TTAtlantisState {const MemMapEntry *memmap;MemoryRegion *memory; +MemoryRegion *dram;RISCVHartArrayState cpus;DeviceState *irqchip;DesignWareI2CState i2c[TT_ATL_NUM_I2C ];
hw/riscv/tt_atlantis.c +12 -8
@@ -82,12 +82,13 @@ static uint32_t next_phandle(void)static void create_fdt_memory (void *fdt,TTAtlantisState *s) { -hwaddr size_lo =MACHINE (s)->ram_size; +hwaddr ram_size =memory_region_size (s->dram); +hwaddr size_lo = ram_size;hwaddr size_hi =0 ;if (size_lo > s->memmap[TT_ATL_DDR_LO ].size) { size_lo = s->memmap[TT_ATL_DDR_LO ].size; - size_hi =MACHINE (s)->ram_size - size_lo; + size_hi = ram_size - size_lo; } create_fdt_socket_memory(fdt, s->memmap[TT_ATL_DDR_LO].base, size_lo,
@@ -485,11 +486,14 @@ static void tt_atlantis_machine_init(MachineState *machine)MemoryRegion *ram_hi =g_new (MemoryRegion,1 );MemoryRegion *ram_lo =g_new (MemoryRegion,1 );MemoryRegion *bootrom =g_new (MemoryRegion,1 ); -ram_addr_t lo_ram_size; +ram_addr_t lo_ram_size, ram_size;int hart_count = machine->smp.cpus; s->memory =get_system_memory (); + s->dram = machine->ram; + ram_size =memory_region_size (s->dram); + s->memmap = tt_atlantis_memmap; object_initialize_child(OBJECT(machine), "soc", &s->cpus,
@@ -532,20 +536,20 @@ static void tt_atlantis_machine_init(MachineState *machine)* The high address is where RAM lives. It is always present and may be * up to 64GB. The low address is an alias of the first 2GB of that RAM. */ -if (machine->ram_size > s->memmap[TT_ATL_DDR_HI ].size) { +if (ram_size > s->memmap[TT_ATL_DDR_HI ].size) {char *sz =size_to_str (s->memmap[TT_ATL_DDR_HI ].size);error_report ("RAM size is too large, maximum is %s" , sz);g_free (sz);exit (EXIT_FAILURE ); } -memory_region_init_alias (ram_hi,OBJECT (machine),"ram.high" , machine->ram, -0 , machine->ram_size); +memory_region_init_alias (ram_hi,OBJECT (machine),"ram.high" , s->dram, +0 , ram_size);memory_region_add_subregion (s->memory, s->memmap[TT_ATL_DDR_HI ].base, ram_hi); - lo_ram_size =MIN (machine->ram_size, s->memmap[TT_ATL_DDR_LO ].size); -memory_region_init_alias (ram_lo,OBJECT (machine),"ram.low" , machine->ram, + lo_ram_size =MIN (ram_size, s->memmap[TT_ATL_DDR_LO ].size); +memory_region_init_alias (ram_lo,OBJECT (machine),"ram.low" , s->dram,0 , lo_ram_size);memory_region_add_subregion (s->memory, s->memmap[TT_ATL_DDR_LO ].base, ram_lo);
Signature · 1 line
2.47.3
Re: [PATCH v2 12/16] hw/riscv/atlantis: Decouple RAM size from MachineState
Quoted 4 lines · Joel Stanley
Keep a reference to the machine's RAM MemoryRegion in TTAtlantisState, and get the MemoryRegion's size where the configured RAM size is required.
Quoted 8 lines
This allows reading the RAM size without needing a pointer to MachineState, decoupling the memory layout setup from the machine.
Signed-off-by Joel Stanley <[email protected]>--- include/hw/riscv/tt_atlantis.h | 1 + hw/riscv/tt_atlantis.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-)
Re: [PATCH v2 12/16] hw/riscv/atlantis: Decouple RAM size from MachineState
In reply to Joel StanleyQuoted 9 lines · Joel Stanley
Keep a reference to the machine's RAM MemoryRegion in TTAtlantisState,
and get the MemoryRegion's size where the configured RAM size is required.This allows reading the RAM size without needing a pointer to MachineState, decoupling the memory layout setup from the machine.
Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 92 lines
---
include/hw/riscv/tt_atlantis.h | 1 + hw/riscv/tt_atlantis.c | 20 ++++++++++++--------2 files changed, 13 insertions(+), 8 deletions(-)include/hw/riscv/tt_atlantis.h +0
-0@@ -30,6 +30,7 @@ struct TTAtlantisState { const MemMapEntry *memmap;
MemoryRegion *memory;
+ MemoryRegion *dram;
RISCVHartArrayState cpus;
DeviceState *irqchip;
DesignWareI2CState i2c[TT_ATL_NUM_I2C];hw/riscv/tt_atlantis.c +0
-0@@ -82,12 +82,13 @@ static uint32_t next_phandle(void)
static voidcreate_fdt_memory(void *fdt, TTAtlantisState *s){
- hwaddrsize_lo= MACHINE(s)->ram_size;
+ hwaddrram_size=memory_region_size(s->dram);
+ hwaddrsize_lo=ram_size;
hwaddrsize_hi= 0;
if (size_lo> s->memmap[TT_ATL_DDR_LO].size) {size_lo= s->memmap[TT_ATL_DDR_LO].size;
-size_hi= MACHINE(s)->ram_size -size_lo;
+size_hi=ram_size-size_lo;
}
create_fdt_socket_memory(fdt, s->memmap[TT_ATL_DDR_LO].base,size_lo,hw/riscv/tt_atlantis.c +1
-1@@ -485,11 +486,14 @@ static voidtt_atlantis_machine_init (MachineState *machine) MemoryRegion *ram_hi = g_new(MemoryRegion, 1); MemoryRegion *ram_lo = g_new(MemoryRegion, 1); MemoryRegion *bootrom = g_new(MemoryRegion, 1); - ram_addr_t lo_ram_size; + ram_addr_t lo_ram_size, ram_size; int hart_count = machine->smp.cpus;
s->memory=get_system_memory();
+s->dram=machine->ram;
+ram_size=memory_region_size(s->dram);
+
s->memmap=tt_atlantis_memmap;
object_initialize_child(OBJECT(machine), "soc",&s->cpus,hw/riscv/tt_atlantis.c +0
-0@@ -532,20 +536,20 @@ static voidtt_atlantis_machine_init (MachineState *machine) * The high address is where RAM lives. It is always present andmay be
* up to 64GB. The low address is an alias of the first 2GB of that RAM.
*/
- if (machine->ram_size> s->memmap[TT_ATL_DDR_HI].size) { + if (ram_size> s->memmap[TT_ATL_DDR_HI].size) {
char *sz =size_to_str(s->memmap[TT_ATL_DDR_HI].size);error_report("RAM size is too large, maximum is %s", sz);g_free(sz);
exit(EXIT_FAILURE);
}
- memory_region_init_alias(ram_hi, OBJECT(machine), "ram.high",machine->ram,
- 0,machine->ram_size);
+ memory_region_init_alias(ram_hi, OBJECT(machine), "ram.high", s-Quoted 1 line
dram,
+ 0,
ram_size);memory_region_add_subregion(s->memory, s->memmap[TT_ATL_DDR_HI].base, ram_hi);
-lo_ram_size= MIN(machine->ram_size, s-Quoted 1 line
memmap[TT_ATL_DDR_LO].size);
- memory_region_init_alias(ram_lo, OBJECT(machine), "ram.low",
machine->ram,
+lo_ram_size=MIN(ram_size, s->memmap[TT_ATL_DDR_LO].size); + memory_region_init_alias(ram_lo, OBJECT(machine), "ram.low", s-Quoted 1 line
dram,
0,
lo_ram_size);memory_region_add_subregion(s->memory, s->memmap[TT_ATL_DDR_LO].base, ram_lo);
PATCH v2 13/16 hw/riscv/atlantis: Make TTAtlantisState own memory containers
In reply to Joel StanleyThe DRAM hi, DRAM low and bootrom memory containers can be owned by the TTAtlantisState.
--- include/hw/riscv/tt_atlantis.h | 4 ++++ hw/riscv/tt_atlantis.c | 15 ++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-)
include/hw/riscv/tt_atlantis.h +4 -0
@@ -31,10 +31,14 @@ struct TTAtlantisState {MemoryRegion *memory;MemoryRegion *dram; +MemoryRegion ram_hi; +MemoryRegion ram_lo; +RISCVHartArrayState cpus;DeviceState *irqchip;DesignWareI2CState i2c[TT_ATL_NUM_I2C ];UnimplementedDeviceState uart1; +MemoryRegion bootrom; };enum {
hw/riscv/tt_atlantis.c +6 -9
@@ -483,9 +483,6 @@ static void tt_atlantis_machine_init(MachineState *machine) {TTAtlantisState *s =TT_ATLANTIS_MACHINE (machine); -MemoryRegion *ram_hi =g_new (MemoryRegion,1 ); -MemoryRegion *ram_lo =g_new (MemoryRegion,1 ); -MemoryRegion *bootrom =g_new (MemoryRegion,1 );ram_addr_t lo_ram_size, ram_size;int hart_count = machine->smp.cpus;
@@ -543,22 +540,22 @@ static void tt_atlantis_machine_init(MachineState *machine)exit (EXIT_FAILURE ); } -memory_region_init_alias (ram_hi,OBJECT (machine),"ram.high" , s->dram, +memory_region_init_alias (&s->ram_hi,OBJECT (machine),"ram.high" , s->dram,0 , ram_size);memory_region_add_subregion (s->memory, - s->memmap[TT_ATL_DDR_HI ].base, ram_hi); + s->memmap[TT_ATL_DDR_HI ].base, &s->ram_hi); lo_ram_size =MIN (ram_size, s->memmap[TT_ATL_DDR_LO ].size); -memory_region_init_alias (ram_lo,OBJECT (machine),"ram.low" , s->dram, +memory_region_init_alias (&s->ram_lo,OBJECT (machine),"ram.low" , s->dram,0 , lo_ram_size);memory_region_add_subregion (s->memory, - s->memmap[TT_ATL_DDR_LO ].base, ram_lo); + s->memmap[TT_ATL_DDR_LO ].base, &s->ram_lo);/* Boot ROM */ -memory_region_init_rom (bootrom,NULL ,"tt-atlantis.bootrom" , +memory_region_init_rom (&s->bootrom,NULL ,"tt-atlantis.bootrom" , s->memmap[TT_ATL_BOOTROM ].size, &error_fatal);memory_region_add_subregion (s->memory, s->memmap[TT_ATL_BOOTROM ].base, - bootrom); + &s->bootrom);/* UART1, the soc console (UART0 is for the boot microcontroller) */ serial_mm_init(s->memory, s->memmap[TT_ATL_UART1].base, 2,
Signature · 1 line
2.47.3
Re: [PATCH v2 13/16] hw/riscv/atlantis: Make TTAtlantisState own memory containers
Quoted 8 lines · Joel Stanley
The DRAM hi, DRAM low and bootrom memory containers can be owned by the TTAtlantisState.
Signed-off-by Joel Stanley <[email protected]>--- include/hw/riscv/tt_atlantis.h | 4 ++++ hw/riscv/tt_atlantis.c | 15 ++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-)
Re: [PATCH v2 13/16] hw/riscv/atlantis: Make TTAtlantisState own memory containers
In reply to Joel StanleyQuoted 5 lines · Joel Stanley
The DRAM hi, DRAM low and bootrom memory containers can be owned by the
TTAtlantisState.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 81 lines
---
include/hw/riscv/tt_atlantis.h | 4 ++++ hw/riscv/tt_atlantis.c | 15 ++++++---------2 files changed, 10 insertions(+), 9 deletions(-)include/hw/riscv/tt_atlantis.h +0
-0@@ -31,10 +31,14 @@ struct TTAtlantisState {
MemoryRegion *memory;
MemoryRegion *dram;
+ MemoryRegionram_hi;
+ MemoryRegionram_lo;
+
RISCVHartArrayState cpus;
DeviceState *irqchip;
DesignWareI2CState i2c[TT_ATL_NUM_I2C];
UnimplementedDeviceState uart1;
+ MemoryRegion bootrom;
};
enum {hw/riscv/tt_atlantis.c +0
-0@@ -483,9 +483,6 @@ static void tt_atlantis_machine_init(MachineState *machine) { TTAtlantisState *s = TT_ATLANTIS_MACHINE(machine);
- MemoryRegion*ram_hi=g_new(MemoryRegion, 1); - MemoryRegion*ram_lo=g_new(MemoryRegion, 1); - MemoryRegion *bootrom =g_new(MemoryRegion, 1);ram_addr_tlo_ram_size,ram_size;
inthart_count=machine->smp.cpus;hw/riscv/tt_atlantis.c +0
-0@@ -543,22 +540,22 @@ static void tt_atlantis_machine_init(MachineState *machine) exit(EXIT_FAILURE); }
- memory_region_init_alias(ram_hi, OBJECT(machine), "ram.high", s-Quoted 1 line
dram,
+ memory_region_init_alias(&s->ram_hi, OBJECT(machine), "ram.high",
s->dram,
0,ram_size); memory_region_add_subregion(s->memory,
- s->memmap[TT_ATL_DDR_HI].base,ram_hi);
+ s->memmap[TT_ATL_DDR_HI].base, &s-Quoted 1 line
ram_hi);
lo_ram_size=MIN(ram_size, s->memmap[TT_ATL_DDR_LO].size); - memory_region_init_alias(ram_lo, OBJECT(machine), "ram.low", s-Quoted 1 line
dram,
+ memory_region_init_alias(&s->ram_lo, OBJECT(machine), "ram.low",
s->dram,
0,lo_ram_size); memory_region_add_subregion(s->memory,
- s->memmap[TT_ATL_DDR_LO].base,ram_lo);
+ s->memmap[TT_ATL_DDR_LO].base, &s-Quoted 1 line
ram_lo);
/* Boot ROM */
- memory_region_init_rom(bootrom, NULL, "tt-atlantis.bootrom", +memory_region_init_rom(&s->bootrom, NULL, "tt-atlantis.bootrom", s->memmap[TT_ATL_BOOTROM].size, &error_fatal);
memory_region_add_subregion(s->memory, s-Quoted 1 line
memmap[TT_ATL_BOOTROM].base,
- bootrom);
+&s->bootrom);
/* UART1, the soc console (UART0 is for the boot microcontroller) */
serial_mm_init(s->memory, s->memmap[TT_ATL_UART1].base, 2,
PATCH v2 14/16 hw/riscv: Add property to hart to allow private memory
In reply to Joel StanleyFrom: Portia Stephens <[email protected]>
There are platforms where CPUs have different mapping of system memory. The global system memory does not allow for this. This adds an optional property to assign a specific memory region to a hart. This allows for a machine to alias the hart's memory to system memory while the hart only views memory from its own memory region.
--- include/hw/riscv/riscv_hart.h | 2 ++ hw/riscv/riscv_hart.c | 8 ++++++++ 2 files changed, 10 insertions(+)
include/hw/riscv/riscv_hart.h +2 -0
@@ -42,6 +42,8 @@ struct RISCVHartArrayState {uint64_t *rnmi_irqvec;uint32_t num_rnmi_excpvec;uint64_t *rnmi_excpvec; +/* Optional private memory region for use instead of system memory */ +MemoryRegion *memory;RISCVCPU *harts; };
hw/riscv/riscv_hart.c +8 -0
@@ -53,6 +53,8 @@ static const Property riscv_harts_props[] = {DEFINE_PROP_ARRAY ("rnmi-exception-vector" , RISCVHartArrayState, num_rnmi_excpvec, rnmi_excpvec, qdev_prop_uint64, uint64_t), +DEFINE_PROP_LINK ("memory" , RISCVHartArrayState, memory, + TYPE_MEMORY_REGION, MemoryRegion *), };static void riscv_harts_cpu_reset (void *opaque)
@@ -117,6 +119,12 @@ static bool riscv_hart_realize(RISCVHartArrayState *s, int idx,object_initialize_child (OBJECT (s),"harts[*]" , &s->harts[idx], cpu_type);qdev_prop_set_uint64 (DEVICE (&s->harts[idx]),"resetvec" , s->resetvec); +/* Use private memory instead of system_memory if provided */ +if (s->memory) { +object_property_set_link (OBJECT (&s->harts[idx]),"memory" , +OBJECT (s->memory), &error_abort); + } +if (s->harts[idx].cfg.ext_smrnmi) {if (idx < s->num_rnmi_irqvec) { qdev_prop_set_uint64(DEVICE(&s->harts[idx]),
Signature · 1 line
2.47.3
Re: [PATCH v2 14/16] hw/riscv: Add property to hart to allow private memory
Quoted 12 lines · Joel Stanley
From: Portia Stephens <[email protected]>
There are platforms where CPUs have different mapping of system memory.
The global system memory does not allow for this. This adds an optional
property to assign a specific memory region to a hart. This allows for a
machine to alias the hart's memory to system memory while the hart only
views memory from its own memory region.
Quoted 2 lines
Signed-off-by Portia Stephens <[email protected]>Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 50 lines
---
include/hw/riscv/riscv_hart.h | 2 ++
hw/riscv/riscv_hart.c | 8 ++++++++2 files changed, 10 insertions(+)include/hw/riscv/riscv_hart.h +1
-0@@ -42,6 +42,8 @@ struct RISCVHartArrayState { uint64_t *rnmi_irqvec; uint32_t num_rnmi_excpvec; uint64_t *rnmi_excpvec; + /* Optional private memory region for use instead of systemmemory */
+ MemoryRegion *memory;
RISCVCPU *harts;
};hw/riscv/riscv_hart.c +2
-0@@ -53,6 +53,8 @@ static const Property riscv_harts_props[] = { DEFINE_PROP_ARRAY("rnmi-exception-vector", RISCVHartArrayState, num_rnmi_excpvec, rnmi_excpvec, qdev_prop_uint64, uint64_t), + DEFINE_PROP_LINK("memory", RISCVHartArrayState, memory, + TYPE_MEMORY_REGION, MemoryRegion *), };
static voidriscv_harts_cpu_reset(void *opaque)hw/riscv/riscv_hart.c +0
-0@@ -117,6 +119,12 @@ static bool riscv_hart_realize(RISCVHartArrayState *s, int idx, object_initialize_child(OBJECT(s), "harts[*]", &s->harts[idx], cpu_type);qdev_prop_set_uint64(DEVICE(&s->harts[idx]), "resetvec", s-
Quoted 1 line
resetvec);
+ /* Use private memory instead ofsystem_memoryif provided */ + if (s->memory) {
+ object_property_set_link(OBJECT(&s->harts[idx]), "memory", +OBJECT(s->memory),&error_abort); + }
+
if (s->harts[idx].cfg.ext_smrnmi) {
if (idx <s->num_rnmi_irqvec) { qdev_prop_set_uint64(DEVICE(&s->harts[idx]),
PATCH v2 15/16 hw/riscv/atlantis: Extract an Atlantis SoC device
In reply to Joel StanleyIntroduce TYPE_TT_ATLANTIS_SOC and move the hart array, AIA, ACLINT, boot ROM, UART and I2C controllers into the new TTAtlantisSoCState. The machine keeps ownership of RAM, device tree generation, firmware loading, and the board-level I2C slaves.
This makes it easier to compose the SoC into a more complex machine in the future.
--- include/hw/riscv/tt_atlantis.h | 21 ++++- hw/riscv/tt_atlantis.c | 144 +++++++++++++++++++++++---------- 2 files changed, 119 insertions(+), 46 deletions(-)
include/hw/riscv/tt_atlantis.h +18 -3
@@ -19,14 +19,16 @@#define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis") OBJECT_DECLARE_SIMPLE_TYPE(TTAtlantisState, TT_ATLANTIS_MACHINE) +#define TYPE_TT_ATLANTIS_SOC "tt-atlantis-soc" +OBJECT_DECLARE_SIMPLE_TYPE(TTAtlantisSoCState, TT_ATLANTIS_SOC) +#define TT_ATL_NUM_I2C 5 -struct TTAtlantisState { +struct TTAtlantisSoCState {/*< private >*/ -MachineState parent; +DeviceState parent;/*< public >*/ -Notifier machine_done;const MemMapEntry *memmap;MemoryRegion *memory;
@@ -39,6 +41,19 @@ struct TTAtlantisState {DesignWareI2CState i2c[TT_ATL_NUM_I2C ];UnimplementedDeviceState uart1;MemoryRegion bootrom; + +uint32_t num_harts; +char *cpu_type; +}; + +struct TTAtlantisState { +/*< private >*/ +MachineState parent; + +/*< public >*/ +Notifier machine_done; + +TTAtlantisSoCState soc; };enum {
hw/riscv/tt_atlantis.c +101 -43
301 lines not on this page · raw message
Signature · 1 line
2.47.3
Re: [PATCH v2 15/16] hw/riscv/atlantis: Extract an Atlantis SoC device
Quoted 11 lines · Joel Stanley
Introduce
TYPE_TT_ATLANTIS_SOCand move the hart array, AIA, ACLINT, boot ROM, UART and I2C controllers into the new TTAtlantisSoCState. The
machine keeps ownership of RAM, device tree generation, firmware loading, and the board-level I2C slaves.This makes it easier to compose the SoC into a more complex machine in
the future.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 419 lines
---
include/hw/riscv/tt_atlantis.h | 21 ++++- hw/riscv/tt_atlantis.c | 144 +++++++++++++++++++++++-------- --2 files changed, 119 insertions(+), 46 deletions(-)include/hw/riscv/tt_atlantis.h +0
-0@@ -19,14 +19,16 @@ #define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis") OBJECT_DECLARE_SIMPLE_TYPE(TTAtlantisState, TT_ATLANTIS_MACHINE)include/hw/riscv/tt_atlantis.h +3
-0+#define TYPE_TT_ATLANTIS_SOC "tt-atlantis-soc" +OBJECT_DECLARE_SIMPLE_TYPE (TTAtlantisSoCState,TT_ATLANTIS_SOC ) +#define
TT_ATL_NUM_I2C5include/hw/riscv/tt_atlantis.h +1
-1-struct TTAtlantisState { +struct TTAtlantisSoCState {/*< private >*/
- MachineState parent;
+ DeviceState parent;
/*< public >*/
- Notifiermachine_done;
const MemMapEntry *memmap;
MemoryRegion *memory;include/hw/riscv/tt_atlantis.h +13
-0@@ -39,6 +41,19 @@ struct TTAtlantisState { DesignWareI2CState i2c[TT_ATL_NUM_I2C]; UnimplementedDeviceState uart1; MemoryRegion bootrom; + + uint32_t num_harts; + char *cpu_type; +}; + +struct TTAtlantisState { + /*< private >*/ + MachineState parent; + + /*< public >*/ + Notifier machine_done; + + TTAtlantisSoCState soc; };
enum {hw/riscv/tt_atlantis.c +0
-0@@ -7,6 +7,7 @@*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "qemu/cutils.h"
#include "qemu/error-report.h"
#include "qemu/guest-random.h"hw/riscv/tt_atlantis.c +0
-0@@ -14,6 +15,7 @@
#include "hw/core/boards.h"
#include "hw/core/loader.h"
+#include "hw/core/qdev-properties.h"
#include "hw/core/sysbus.h"
#include "target/riscv/cpu.h"hw/riscv/tt_atlantis.c +0
-0@@ -67,7 +69,7 @@ static const MemMapEntry tt_atlantis_memmap[] = { [TT_ATL_DDR_HI] = { 0x100000000, 0x1000000000 }, };hw/riscv/tt_atlantis.c +1
-1-static I2CBus *i2c_get_bus (TTAtlantisState *s,unsigned busnr) +static I2CBus *i2c_get_bus (TTAtlantisSoCState *s,unsigned busnr){
assert(busnr < TT_ATL_NUM_I2C);hw/riscv/tt_atlantis.c +0
-0@@ -80,7 +82,7 @@ static uint32_t next_phandle(void) return fdt_phandle++; }hw/riscv/tt_atlantis.c +1
-1-static void create_fdt_memory (void *fdt,TTAtlantisState *s) +static void create_fdt_memory (void *fdt,TTAtlantisSoCState *s){
hwaddrram_size=memory_region_size(s->dram); hwaddrsize_lo=ram_size;hw/riscv/tt_atlantis.c +0
-0@@ -104,7 +106,7 @@ static void create_fdt_memory(void *fdt, TTAtlantisState *s) } }hw/riscv/tt_atlantis.c +1
-1-static void create_fdt_aclint(void *fdt, TTAtlantisState *s, +static void create_fdt_aclint(void *fdt, TTAtlantisSoCState *s,
uint32_t*intc_phandles) {
g_autofreechar *name = NULL;hw/riscv/tt_atlantis.c +0
-0@@ -206,7 +208,7 @@ static void create_fdt_one_aplic(void *fdt, qemu_fdt_setprop_cell(fdt, name, "phandle", aplic_phandle); }hw/riscv/tt_atlantis.c +1
-1-static void create_fdt_pmu (void *fdt,TTAtlantisState *s) +static void create_fdt_pmu (void *fdt,TTAtlantisSoCState *s){
char pmu_name[] = "/pmu";
RISCVCPU *hart = &s->cpus.harts[0];hw/riscv/tt_atlantis.c +0
-0@@ -216,7 +218,7 @@ static void create_fdt_pmu(void *fdt, TTAtlantisState *s) riscv_pmu_generate_fdt_node(fdt, hart->pmu_avail_ctrs,pmu_name ); }hw/riscv/tt_atlantis.c +1
-1-static void create_fdt_cpu(void *fdt, TTAtlantisState *s, +static void create_fdt_cpu(void *fdt, TTAtlantisSoCState *s,
uint32_taplic_s_phandle,uint32_timsic_s_phandle) {hw/riscv/tt_atlantis.c +0
-0@@ -313,7 +315,7 @@ static void create_fdt_i2c(void *fdt, const MemMapEntry *mem, uint32_t irq, qemu_fdt_setprop_cell(fdt, name, "#size-cells", 0); }
-static void create_fdt_i2c_device(void *fdt, TTAtlantisState *s, int bus,
+static void create_fdt_i2c_device(void *fdt, TTAtlantisSoCState *s, int bus,
const char *compat, int addr) {
hwaddr base = s->memmap[TT_ATL_I2C0 + bus].base;hw/riscv/tt_atlantis.c +0
-0@@ -325,7 +327,7 @@ static void create_fdt_i2c_device(void *fdt, TTAtlantisState *s, int bus, qemu_fdt_setprop_cell(fdt, name, "reg", addr); }hw/riscv/tt_atlantis.c +1
-1-static void finalize_fdt (void *fdt,TTAtlantisState *s) +static void finalize_fdt (void *fdt,TTAtlantisSoCState *s){
uint32_taplic_s_phandle=next_phandle();
uint32_timsic_s_phandle=next_phandle();hw/riscv/tt_atlantis.c +0
-0@@ -359,9 +361,9 @@ static void finalize_fdt(void *fdt, TTAtlantisState *s) create_fdt_i2c_device(fdt, s, 4, "ti,tmp105", 0x48); }hw/riscv/tt_atlantis.c +1
-1-static void create_fdt (TTAtlantisState *s) +static void create_fdt (TTAtlantisState *ams){
- MachineState *ms = MACHINE(s);
+ MachineState *ms = MACHINE(ams);
intfdt_size= 0;
ms->fdt= create_board_device_tree("Tenstorrent Atlantis RISC-V Machine",hw/riscv/tt_atlantis.c +0
-0@@ -373,12 +375,12 @@ static void create_fdt(TTAtlantisState *s)
qemu_fdt_add_subnode(ms->fdt, "/aliases");
-create_fdt_pmu(ms->fdt, s);
+create_fdt_pmu(ms->fdt, &ams->soc);
}hw/riscv/tt_atlantis.c +1
-1-static void load_fdt (TTAtlantisState *s) +static void load_fdt (TTAtlantisState *ams){
- MachineState *ms = MACHINE(s);
+ MachineState *ms = MACHINE(ams);
char **node_path;
Error *err = NULL;
intfdt_size= 0;hw/riscv/tt_atlantis.c +0
-0@@ -404,7 +406,7 @@ static void load_fdt(TTAtlantisState *s) g_strfreev(node_path); }
-create_fdt_memory(ms->fdt, s);
+create_fdt_memory(ms->fdt, &ams->soc);
}
static void mmio_map_unimplemented(MemoryRegion *memory, SysBusDevice *dev,hw/riscv/tt_atlantis.c +0
-0@@ -418,10 +420,11 @@ static void mmio_map_unimplemented(MemoryRegion *memory, SysBusDevice *dev, sysbus_mmio_get_region(dev, 0), -1000); }hw/riscv/tt_atlantis.c +1
-1-static void tt_atlantis_machine_done (Notifier *notifier,void *data) +static void tt_atlantis_machine_done (Notifier *n,void *data){
- TTAtlantisState *s =container_of(notifier, TTAtlantisState, machine_done);
- MachineState *machine = MACHINE(s);
+ TTAtlantisState *ams =container_of(n, TTAtlantisState, machine_done);
+ TTAtlantisSoCState *s =&ams->soc;
+ MachineState *machine = MACHINE(ams);
hwaddrstart_addr= s->memmap[TT_ATL_DDR_LO].base; hwaddrmem_size;
target_ulongfirmware_end_addr,kernel_start_addr;hw/riscv/tt_atlantis.c +0
-0@@ -479,23 +482,39 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data) fdt_load_addr); }hw/riscv/tt_atlantis.c +1
-1-static void tt_atlantis_machine_init (MachineState *machine) +static void tt_atlantis_soc_init (Object *obj){
- TTAtlantisState *s =TT_ATLANTIS_MACHINE(machine); + TTAtlantisSoCState *s =TT_ATLANTIS_SOC(obj); +
+object_initialize_child(obj, "cpus", &s->cpus, TYPE_RISCV_HART_ARRAY);
+
+ object_initialize_child(obj, "uart1",&s->uart1, +TYPE_UNIMPLEMENTED_DEVICE);
+ for (int i = 0; i <TT_ATL_NUM_I2C; i++) {
+ object_initialize_child(obj, "i2c[*]", &s->i2c[i], +TYPE_DESIGNWARE_I2C); + }hw/riscv/tt_atlantis.c +5
-0+} + +static void tt_atlantis_soc_realize (DeviceState *dev,Error **errp) +{ + TTAtlantisSoCState *s = TT_ATLANTIS_SOC(dev);
ram_addr_tlo_ram_size,ram_size;
- inthart_count=machine->smp.cpus;
+ inthart_count=s->num_harts;
s->memory=get_system_memory();
-s->dram=machine->ram;
+ if (!s->dram) {
+error_setg(errp, "'dram' link is not set");
+ return;
+ }
ram_size=memory_region_size(s->dram);
s->memmap=tt_atlantis_memmap;
- object_initialize_child(OBJECT(machine), "soc",&s->cpus, -TYPE_RISCV_HART_ARRAY);
- object_property_set_str(OBJECT(&s->cpus), "cpu-type", machine-Quoted 1 line
cpu_type,+ /* CPUs */
+ object_property_set_str(OBJECT(&s->cpus), "cpu-type", s-Quoted 1 line
cpu_type,
&error_abort);object_property_set_int(OBJECT(&s->cpus), "hartid-base", 0, &error_abort);hw/riscv/tt_atlantis.c +3
-1@@ -504,7 +523,9 @@ static void tt_atlantis_machine_init(MachineState *machine) object_property_set_int(OBJECT(&s->cpus), "resetvec", s->memmap[TT_ATL_BOOTROM].base, &error_abort); - sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->cpus), errp)) { + return; + }
s->irqchip= riscv_create_aia(s->memory, true,TT_IMSIC_GUESTS,hw/riscv/tt_atlantis.c +0
-0@@ -534,26 +555,27 @@ static voidtt_atlantis_machine_init (MachineState *machine) * up to 64GB. The low address is an alias of the first 2GB ofthat RAM.
*/
if (ram_size> s->memmap[TT_ATL_DDR_HI].size) {
- char *sz =size_to_str(s->memmap[TT_ATL_DDR_HI].size); -error_report("RAM size is too large, maximum is %s", sz); -g_free(sz);
-exit(EXIT_FAILURE);
+g_autofreechar *sz = size_to_str(s-Quoted 1 line
memmap[TT_ATL_DDR_HI].size);
+
error_setg(errp, "RAM size is too large, maximum is %s", sz);
+ return;
}
- memory_region_init_alias(&s->ram_hi, OBJECT(machine), "ram.high",s->dram,
+ memory_region_init_alias(&s->ram_hi, OBJECT(s), "ram.high", s-Quoted 1 line
dram,
0,
ram_size); memory_region_add_subregion(s->memory, s->memmap[TT_ATL_DDR_HI].base, &s-Quoted 1 line
ram_hi);
lo_ram_size=MIN(ram_size, s->memmap[TT_ATL_DDR_LO].size); - memory_region_init_alias(&s->ram_lo, OBJECT(machine), "ram.low",s->dram,
+ memory_region_init_alias(&s->ram_lo, OBJECT(s), "ram.low", s-Quoted 1 line
dram,
0,
lo_ram_size); memory_region_add_subregion(s->memory, s->memmap[TT_ATL_DDR_LO].base, &s-Quoted 1 line
ram_lo);
/* Boot ROM */
- memory_region_init_rom(&s->bootrom, NULL, "tt-atlantis.bootrom", - s->memmap[TT_ATL_BOOTROM].size,&error_fatal);
+ if (!memory_region_init_rom(&s->bootrom, OBJECT(s), "tt- atlantis.bootrom",
+ s->memmap[TT_ATL_BOOTROM].size, errp)) {
+ return;
+ }
memory_region_add_subregion(s->memory, s-Quoted 1 line
memmap[TT_ATL_BOOTROM].base,
&s->bootrom);hw/riscv/tt_atlantis.c +0
-2@@ -570,26 +592,56 @@ static voidtt_atlantis_machine_init(MachineState *machine) * Create an unimplemented device region so writes don't fault * and reads return zero, which keeps Linux happy. */ - object_initialize_child(OBJECT(s), "uart1", &s->uart1, - TYPE_UNIMPLEMENTED_DEVICE); mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->uart1),"tt-atlantis.uart1", s-
Quoted 1 line
memmap[TT_ATL_UART1].base,
s->memmap[TT_ATL_UART1].size);
/* I2C */
for (int i = 0; i <TT_ATL_NUM_I2C; i++) {
- SysBusDevice *sbd;
+ SysBusDevice *sbd =SYS_BUS_DEVICE(&s->i2c[i]);
- object_initialize_child(OBJECT(s), "i2c[*]", &s->i2c[i], -TYPE_DESIGNWARE_I2C);
- sbd =SYS_BUS_DEVICE(&s->i2c[i]);
-sysbus_realize(sbd, &error_fatal);
+ if (!sysbus_realize(sbd, errp)) {
+ return;
+ }
memory_region_add_subregion(s->memory, s->memmap[TT_ATL_I2C0 + i].base, sysbus_mmio_get_region(sbd, 0));sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(s->irqchip, TT_ATL_I2C0_IRQ + i));
}hw/riscv/tt_atlantis.c +5
-0+} + +static const Property tt_atlantis_soc_props[] = { + DEFINE_PROP_STRING("cpu-type", TTAtlantisSoCState, cpu_type), + DEFINE_PROP_UINT32("num-harts", TTAtlantisSoCState, num_harts,8),
+ DEFINE_PROP_LINK("dram", TTAtlantisSoCState, dram, +TYPE_MEMORY_REGION, MemoryRegion *),hw/riscv/tt_atlantis.c +3
-0+}; + +static void tt_atlantis_soc_class_init(ObjectClass *oc, const void*data)
hw/riscv/tt_atlantis.c +17
-0+{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->realize = tt_atlantis_soc_realize; + device_class_set_props(dc, tt_atlantis_soc_props); + /* The SoC can only be instantiated from the machine */ + dc->user_creatable = false; +} + +static void tt_atlantis_machine_init (MachineState *machine) +{ + TTAtlantisState *ams = TT_ATLANTIS_MACHINE(machine); + TTAtlantisSoCState *s = &ams->soc; + + object_initialize_child(OBJECT(machine), "soc", &ams->soc, + TYPE_TT_ATLANTIS_SOC); + object_property_set_str(OBJECT(&ams->soc), "cpu-type", machine-Quoted 1 line
cpu_type,+
&error_abort);
+ object_property_set_int(OBJECT(&ams->soc), "num-harts", machine-Quoted 1 line
smp.cpus,
+
&error_abort);
+ object_property_set_link(OBJECT(&ams->soc), "dram",OBJECT(machine->ram),
+&error_abort);
+qdev_realize(DEVICE(&ams->soc), NULL, &error_fatal);
/* I2C peripherals: qemu specific */i2c_slave_create_simple(i2c_get_bus(s, 0), "ds1338", 0x6f);hw/riscv/tt_atlantis.c +0
-0@@ -597,13 +649,13 @@ static voidtt_atlantis_machine_init (MachineState *machine)
/* Load or create device tree */
if (machine->dtb) {
-load_fdt(s);
+load_fdt(ams);
} else {
-create_fdt(s);
+create_fdt(ams);
}
-s->machine_done.notify=tt_atlantis_machine_done; -qemu_add_machine_init_done_notifier(&s->machine_done); +ams->machine_done.notify=tt_atlantis_machine_done; +qemu_add_machine_init_done_notifier(&ams->machine_done); }
static voidtt_atlantis_machine_class_init(ObjectClass *oc, const void *data)hw/riscv/tt_atlantis.c +0
-0@@ -623,6 +675,12 @@ static void tt_atlantis_machine_class_init(ObjectClass *oc, const void *data)
static const TypeInfo tt_atlantis_types[] = { {
+ .name =TYPE_TT_ATLANTIS_SOC,
+ .parent =TYPE_DEVICE,
+ .instance_size = sizeof(TTAtlantisSoCState), + .instance_init =tt_atlantis_soc_init, + .class_init =tt_atlantis_soc_class_init, + }, {
.name =MACHINE_TYPE_NAME("tt-atlantis"), .parent =TYPE_MACHINE, .class_init =tt_atlantis_machine_class_init,
PATCH v2 16/16 hw/riscv/atlantis: Map the SoC through a memory container
In reply to Joel StanleyGive the Atlantis SoC a 'memory' link property. The machine creates a container MemoryRegion, maps it at address 0 of system memory, and passes it to the SoC together with the machine RAM. The SoC maps devices into the 'memory' container instead of system memory, allowing TTAtlantisSoCState to be composed together with other SoCs in the future.
This prepares the machine for adding other microcontrollers that share the memory bus with the Ascalon complex (aka the Atlantis SoC), but with their own view of the address map.
--- include/hw/riscv/tt_atlantis.h | 1 + hw/riscv/tt_atlantis.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)
include/hw/riscv/tt_atlantis.h +1 -0
@@ -53,6 +53,7 @@ struct TTAtlantisState {/*< public >*/ Notifier machine_done; +MemoryRegion soc_memory;TTAtlantisSoCState soc; };
hw/riscv/tt_atlantis.c +15 -2
@@ -503,8 +503,10 @@ static void tt_atlantis_soc_realize(DeviceState *dev, Error **errp)ram_addr_t lo_ram_size, ram_size;int hart_count = s->num_harts; - s->memory =get_system_memory (); - +if (!s->memory) { +error_setg (errp,"'memory' link is not set" ); +return ; + }if (!s->dram) {error_setg (errp,"'dram' link is not set" );return ;
@@ -523,6 +525,8 @@ static void tt_atlantis_soc_realize(DeviceState *dev, Error **errp)object_property_set_int (OBJECT (&s->cpus),"resetvec" , s->memmap[TT_ATL_BOOTROM ].base, &error_abort); +object_property_set_link (OBJECT (&s->cpus),"memory" ,OBJECT (s->memory), + &error_abort);if (!sysbus_realize (SYS_BUS_DEVICE (&s->cpus), errp)) {return ; }
@@ -614,6 +618,8 @@ static void tt_atlantis_soc_realize(DeviceState *dev, Error **errp)static const Property tt_atlantis_soc_props[] = {DEFINE_PROP_STRING ("cpu-type" , TTAtlantisSoCState, cpu_type),DEFINE_PROP_UINT32 ("num-harts" , TTAtlantisSoCState, num_harts,8 ), +DEFINE_PROP_LINK ("memory" , TTAtlantisSoCState, memory, + TYPE_MEMORY_REGION, MemoryRegion *),DEFINE_PROP_LINK ("dram" , TTAtlantisSoCState, dram, TYPE_MEMORY_REGION, MemoryRegion *), };
@@ -633,12 +639,19 @@ static void tt_atlantis_machine_init(MachineState *machine)TTAtlantisState *ams =TT_ATLANTIS_MACHINE (machine);TTAtlantisSoCState *s = &ams->soc; +memory_region_init (&ams->soc_memory,OBJECT (machine), +"tt-atlantis.soc-memory" ,UINT64_MAX ); +memory_region_add_subregion (get_system_memory (),0 , &ams->soc_memory); +object_initialize_child (OBJECT (machine),"soc" , &ams->soc,TYPE_TT_ATLANTIS_SOC );object_property_set_str (OBJECT (&ams->soc),"cpu-type" , machine->cpu_type, &error_abort);object_property_set_int (OBJECT (&ams->soc),"num-harts" , machine->smp.cpus, &error_abort); + +object_property_set_link (OBJECT (&ams->soc),"memory" , +OBJECT (&ams->soc_memory), &error_abort);object_property_set_link (OBJECT (&ams->soc),"dram" ,OBJECT (machine->ram), &error_abort);qdev_realize (DEVICE (&ams->soc),NULL , &error_fatal);
Signature · 1 line
2.47.3
Re: [PATCH v2 16/16] hw/riscv/atlantis: Map the SoC through a memory container
Quoted 8 lines · Joel Stanley
Give the Atlantis SoC a 'memory' link property. The machine creates a container MemoryRegion, maps it at address 0 of system memory, and passes it to the SoC together with the machine RAM. The SoC maps devices
into the 'memory' container instead of system memory, allowing TTAtlantisSoCState to be composed together with other SoCs in the future.
Quoted 7 lines
This prepares the machine for adding other microcontrollers that share
the memory bus with the Ascalon complex (aka the Atlantis SoC), but with
their own view of the address map.Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 84 lines
---
include/hw/riscv/tt_atlantis.h | 1 + hw/riscv/tt_atlantis.c | 17 +++++++++++++++--2 files changed, 16 insertions(+), 2 deletions(-)include/hw/riscv/tt_atlantis.h +0
-0@@ -53,6 +53,7 @@ struct TTAtlantisState { /*< public >*/ Notifier machine_done;
+ MemoryRegionsoc_memory;
TTAtlantisSoCState soc;
};hw/riscv/tt_atlantis.c +0
-0@@ -503,8 +503,10 @@ static void tt_atlantis_soc_realize(DeviceState *dev, Error **errp) ram_addr_t lo_ram_size, ram_size; int hart_count = s->num_harts;
-s->memory=get_system_memory();
-
+ if (!s->memory) {
+error_setg(errp, "'memory' link is not set"); + return;
+ }
if (!s->dram) {
error_setg(errp, "'dram' link is not set"); return;hw/riscv/tt_atlantis.c +2
-0@@ -523,6 +525,8 @@ static void tt_atlantis_soc_realize(DeviceState *dev, Error **errp) object_property_set_int(OBJECT(&s->cpus), "resetvec", s->memmap[TT_ATL_BOOTROM].base, &error_abort); + object_property_set_link(OBJECT(&s->cpus), "memory", OBJECT(s- >memory), + &error_abort); if (!sysbus_realize(SYS_BUS_DEVICE(&s->cpus), errp)) {return;
}hw/riscv/tt_atlantis.c +2
-0@@ -614,6 +618,8 @@ static void tt_atlantis_soc_realize(DeviceState *dev, Error **errp) static const Property tt_atlantis_soc_props[] = { DEFINE_PROP_STRING("cpu-type", TTAtlantisSoCState, cpu_type), DEFINE_PROP_UINT32("num-harts", TTAtlantisSoCState, num_harts,8 ), + DEFINE_PROP_LINK("memory", TTAtlantisSoCState, memory, + TYPE_MEMORY_REGION, MemoryRegion *), DEFINE_PROP_LINK("dram", TTAtlantisSoCState, dram,
TYPE_MEMORY_REGION, MemoryRegion *), };hw/riscv/tt_atlantis.c +0
-0@@ -633,12 +639,19 @@ static voidtt_atlantis_machine_init (MachineState *machine) TTAtlantisState *ams = TT_ATLANTIS_MACHINE(machine); TTAtlantisSoCState *s = &ams->soc;
+ memory_region_init(&ams->soc_memory, OBJECT(machine), + "tt-atlantis.soc-memory",UINT64_MAX); + memory_region_add_subregion(get_system_memory(), 0, &ams-Quoted 1 line
soc_memory);+
object_initialize_child(OBJECT(machine), "soc", &ams->soc, TYPE_TT_ATLANTIS_SOC); object_property_set_str(OBJECT(&ams->soc), "cpu-type", machine-Quoted 1 line
cpu_type,
&error_abort); object_property_set_int(OBJECT(&ams->soc), "num-harts", machine-Quoted 1 line
smp.cpus,
&error_abort);
+
+ object_property_set_link(OBJECT(&ams->soc), "memory", +OBJECT(&ams->soc_memory),&error_abort); object_property_set_link(OBJECT(&ams->soc), "dram",OBJECT(machine->ram),
&error_abort);qdev_realize(DEVICE(&ams->soc), NULL, &error_fatal);
Quoted 38 lines · Joel Stanley
v1:
https://lore.kernel.org/qemu-riscv/[email protected]/Changes in v2:
- Reword patch 14 "hart private memory" commit message to clarify hart
vs hart array
- Fix indentation in patch 4 (riscv_aplicMemoryRegion)Thanks to Daniel and Philippe for the reviews.
Original commit message:
This addresses the review given by Cedric on v1 of the Atlantis patches,
where he suggested making the machine a SoC. This is the pattern followed by the Aspeed ARM machines, where the SoC represents the modelled hardware, attaching its devices to a memory container, with the
SoC instantiated by a QEMU machine that provides the memory container and the machine's RAM.Aside from the clean abstraction that this encourages, this pattern will
be useful in adding other SoCs to the Atlantis machine, such as the RCPU
(boot microcontroller) and CPL (Cluster Power Logic microcontroller).The series converts the RISC-V interrupt controllers to take a MemoryRegion for mapping themselves, with no change in behaviour for existing machines, and then cleans up the CPS device to place its devices in the memory container provided.
The next few patches clean up the Atlantis machine to make extracting the SoC device and mapping it in a container relatively straightforward.
Quoted 16 lines
Joel Stanley (15):
hw/riscv/aia: Take a MemoryRegion for the created devices hw/intc/riscv_aclint: Take a MemoryRegion for the created devices hw/intc/riscv_imsic: Take a MemoryRegion for the created device hw/intc/riscv_aplic: Take a MemoryRegion for the created device hw/intc/sifive_plic: Take a MemoryRegion for the created device hw/riscv/cps: Map interrupt controllers in SoC container hw/riscv/atlantis: Make UART unimp region a SoC device hw/riscv/atlantis: Remove unusedfdt_sizehw/riscv/atlantis: Rename hart array 'soc' to 'cpus' hw/riscv/atlantis: Rework device tree creation hw/riscv/atlantis: Use local reference for system memory hw/riscv/atlantis: Decouple RAM size from MachineState hw/riscv/atlantis: Make TTAtlantisState own memory containers hw/riscv/atlantis: Extract an Atlantis SoC device hw/riscv/atlantis: Map the SoC through a memory container
Thanks!
Partially applied to riscv-to-apply.next.
I applied the first few patches, after that I hit merge conflicts with the recent FDT changes. Should be pretty easy to fix, but I pulled in the first patches to keep the ball moving.
Alistair
Quoted 29 lines
Portia Stephens (1):
hw/riscv: Add property to hart to allow private memoryhw/riscv/aia.h | 2 +-
include/hw/intc/riscv_aclint.h | 7 +-include/hw/intc/riscv_aplic.h | 2 +- include/hw/intc/riscv_imsic.h | 3 +- include/hw/intc/sifive_plic.h | 3 +- include/hw/riscv/riscv_hart.h | 2 + include/hw/riscv/tt_atlantis.h | 32 +++- hw/intc/riscv_aclint.c | 12 +- hw/intc/riscv_aplic.c | 5 +- hw/intc/riscv_imsic.c | 6 +- hw/intc/sifive_plic.c | 6 +-hw/riscv/aia.c | 14 +-
hw/riscv/cps.c | 12 +-
hw/riscv/k230.c | 9 +-
hw/riscv/microchip_pfsoc.c | 8 +-
hw/riscv/riscv_hart.c | 8 +hw/riscv/shakti_c.c | 10 +- hw/riscv/sifive_e.c | 6 +- hw/riscv/sifive_u.c | 10 +-hw/riscv/spike.c | 4 +- hw/riscv/tt_atlantis.c | 277 +++++++++++++++++++++---------- --
hw/riscv/virt.c | 21 ++- hw/riscv/xiangshan_kmh.c | 17 +-23 files changed, 317 insertions(+), 159 deletions(-)
Quoted 57 lines · Alistair Francis
Quoted 38 lines · Joel Stanley
v1:
https://lore.kernel.org/qemu-riscv/[email protected]/Changes in v2:
- Reword patch 14 "hart private memory" commit message to clarify
hart
vs hart array
- Fix indentation in patch 4 (riscv_aplicMemoryRegion)Thanks to Daniel and Philippe for the reviews.
Original commit message:
This addresses the review given by Cedric on v1 of the Atlantis patches,
where he suggested making the machine a SoC. This is the pattern followed by the Aspeed ARM machines, where the SoC represents the modelled hardware, attaching its devices to a memory container, with the
SoC instantiated by a QEMU machine that provides the memory container and the machine's RAM.Aside from the clean abstraction that this encourages, this pattern will
be useful in adding other SoCs to the Atlantis machine, such as the RCPU
(boot microcontroller) and CPL (Cluster Power Logic microcontroller).The series converts the RISC-V interrupt controllers to take a MemoryRegion for mapping themselves, with no change in behaviour for existing machines, and then cleans up the CPS device to place its devices in the memory container provided.
The next few patches clean up the Atlantis machine to make extracting the SoC device and mapping it in a container relatively straightforward.
Quoted 16 lines
Joel Stanley (15):
hw/riscv/aia: Take a MemoryRegion for the created devices hw/intc/riscv_aclint: Take a MemoryRegion for the created devices hw/intc/riscv_imsic: Take a MemoryRegion for the created device hw/intc/riscv_aplic: Take a MemoryRegion for the created device hw/intc/sifive_plic: Take a MemoryRegion for the created device hw/riscv/cps: Map interrupt controllers in SoC container hw/riscv/atlantis: Make UART unimp region a SoC device hw/riscv/atlantis: Remove unusedfdt_sizehw/riscv/atlantis: Rename hart array 'soc' to 'cpus' hw/riscv/atlantis: Rework device tree creation hw/riscv/atlantis: Use local reference for system memory hw/riscv/atlantis: Decouple RAM size from MachineState hw/riscv/atlantis: Make TTAtlantisState own memory containers hw/riscv/atlantis: Extract an Atlantis SoC device hw/riscv/atlantis: Map the SoC through a memory container
Quoted 7 lines
Thanks!
Partially applied to riscv-to-apply.next.
I applied the first few patches, after that I hit merge conflicts with the recent FDT changes. Should be pretty easy to fix, but I pulled in the first patches to keep the ball moving.
No worries. I didn't see any of the patches when I pulled, so I sent the full series as a v3 rebased on the device tree patches you'd merged and pushed.
Cheers,
Joel