hw/riscv: Add the Tenstorrent Atlantis machine
Subsystems (3)
v8 cover hw/riscv: Add the Tenstorrent Atlantis machine
Introducing Tenstorrent Atlantis!
The Tenstorrent Atlantis platform is a collaboration between Tenstorrent and CoreLab Technology. It is based on the Atlantis SoC, which includes the Ascalon-X CPU and other IP from Tenstorrent and CoreLab Technology.
The Tenstorrent Ascalon-X is a high performance 64-bit RVA23 compliant RISC-V CPU.
Thanks to Nick for sending the past few revs while I was on leave.
v7:
https://lore.kernel.org/qemu-riscv/[email protected]/
Changes since v7:
Fixes for booting an external device tree. Will add a test for this once the device tree is reviewed.
- Correct IMSIC memory layout to match hardware. Uses new patch 5.
- Bring Zkr patch back in, required for opensbi to not trap on csr access
- Address map corrections and ensure m-mode addresses are used for Linux devices
- Use UART1 as the console to match hardware
- Update /chosen so -append works
- Update /memory node to match -m
Others:
- Fix duplicate .unimp setting in designware i2c
- Avoid guest error warning at device reset time
Chris Rauer (1):
hw/i2c: Add DesignWare I2C Controller
Joel Stanley (6):
hw/riscv/virt: Move AIA initialisation to helper file hw/riscv/aia: Provide number of irq sources hw/riscv/aia: Configure stride for the M-mode IMSIC hw/riscv: Add Tenstorrent Atlantis machine hw/riscv/atlantis: Integrate i2c controllers hw/riscv/atlantis: Add some i2c peripherals
Nicholas Piggin (5):
hw/riscv/boot: Describe discontiguous memory in boot_info hw/riscv/boot: Account for discontiguous memory when loading firmware target/riscv: tt-ascalon: Enable Zkr extension hw/riscv/atlantis: Provide a simple halting payload tests/functional/riscv64: Add tt-atlantis tests
MAINTAINERS | 19 + docs/system/riscv/tt_atlantis.rst | 41 + docs/system/target-riscv.rst | 1 + hw/riscv/aia.h | 26 + include/hw/i2c/designware_i2c.h | 56 ++ include/hw/riscv/boot.h | 12 +- include/hw/riscv/tt_atlantis.h | 64 ++ include/hw/riscv/virt.h | 2 +- hw/i2c/designware_i2c.c | 745 +++++++++++++++++++ hw/riscv/aia.c | 94 +++ hw/riscv/boot.c | 34 +- hw/riscv/microchip_pfsoc.c | 8 +- hw/riscv/opentitan.c | 6 +- hw/riscv/shakti_c.c | 6 +- hw/riscv/sifive_u.c | 6 +- hw/riscv/spike.c | 6 +- hw/riscv/tt_atlantis.c | 706 ++++++++++++++++++ hw/riscv/virt-acpi-build.c | 27 +- hw/riscv/virt.c | 97 +-- hw/riscv/xiangshan_kmh.c | 6 +- target/riscv/cpu.c | 1 + hw/i2c/Kconfig | 5 + hw/i2c/meson.build | 1 + hw/riscv/Kconfig | 13 + hw/riscv/meson.build | 3 +- tests/functional/riscv64/meson.build | 1 + tests/functional/riscv64/test_opensbi.py | 4 + tests/functional/riscv64/test_tt_atlantis.py | 57 ++ 28 files changed, 1940 insertions(+), 107 deletions(-) create mode 100644 docs/system/riscv/tt_atlantis.rst create mode 100644 hw/riscv/aia.h create mode 100644 include/hw/i2c/designware_i2c.h create mode 100644 include/hw/riscv/tt_atlantis.h create mode 100644 hw/i2c/designware_i2c.c create mode 100644 hw/riscv/aia.c create mode 100644 hw/riscv/tt_atlantis.c create mode 100755 tests/functional/riscv64/test_tt_atlantis.py
Signature · 1 line
2.47.3
PATCH v8 1/12 hw/riscv/boot: Describe discontiguous memory in boot_info
From: Nicholas Piggin <[email protected]>
Machines that have discontiguous memory may need to adjust where firmware and images are loaded at boot. Provide an interface for machines to describe a discontiguous low/high RAM scheme for this purpose.
--- include/hw/riscv/boot.h | 7 +++++++ hw/riscv/boot.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+)
include/hw/riscv/boot.h +7 -0
@@ -28,6 +28,10 @@#define RISCV64_BIOS_BIN "opensbi-riscv64-generic-fw_dynamic.bin" typedef struct RISCVBootInfo { + /* First contiguous RAM region. If size is zero then assume entire RAM */ + hwaddr ram_low_start; + hwaddr ram_low_size; + ssize_t kernel_size; hwaddr image_low_addr; hwaddr image_high_addr;
@@ -43,6 +47,9 @@ bool riscv_is_32bit(RISCVHartArrayState *harts);char *riscv_plic_hart_config_string (int hart_count);void riscv_boot_info_init (RISCVBootInfo *info,RISCVHartArrayState *harts); +void riscv_boot_info_init_discontig_mem (RISCVBootInfo *info, +RISCVHartArrayState *harts, +hwaddr low_start,hwaddr low_size);vaddr riscv_calc_kernel_start_addr (RISCVBootInfo *info,hwaddr firmware_end_addr); hwaddr riscv_find_and_load_firmware(MachineState *machine,
hw/riscv/boot.c +16 -0
@@ -69,11 +69,27 @@ char *riscv_plic_hart_config_string(int hart_count)void riscv_boot_info_init (RISCVBootInfo *info,RISCVHartArrayState *harts) { + info->ram_low_start =0 ; + info->ram_low_size =0 ; info->kernel_size =0 ; info->initrd_size =0 ; info->is_32bit =riscv_is_32bit (harts); } +/* +* This can be used instead of riscv_boot_info_init() if the machine has +* discontiguous physical memory. The low memory range specified will be +* used to place firmware images. +*/ +void riscv_boot_info_init_discontig_mem (RISCVBootInfo *info, +RISCVHartArrayState *harts, +hwaddr low_start,hwaddr low_size) +{ +riscv_boot_info_init (info, harts); + info->ram_low_start = low_start; + info->ram_low_size = low_size; +} +vaddr riscv_calc_kernel_start_addr (RISCVBootInfo *info,hwaddr firmware_end_addr) {if (info->is_32bit) {
Signature · 1 line
2.47.3
PATCH v8 2/12 hw/riscv/boot: Account for discontiguous memory when loading firmware
In reply to Joel StanleyFrom: Nicholas Piggin <[email protected]>
This loads firmware into the first (low) memory range, accounting for machines having discontiguous memory regions.
--- include/hw/riscv/boot.h | 5 ++++- hw/riscv/boot.c | 18 ++++++++++++------ hw/riscv/microchip_pfsoc.c | 8 ++++++-- hw/riscv/opentitan.c | 6 ++++-- hw/riscv/shakti_c.c | 6 +++++- hw/riscv/sifive_u.c | 6 ++++-- hw/riscv/spike.c | 6 ++++-- hw/riscv/virt.c | 7 ++++--- hw/riscv/xiangshan_kmh.c | 6 +++++- 9 files changed, 48 insertions(+), 20 deletions(-)
include/hw/riscv/boot.h +4 -1
@@ -53,13 +53,16 @@ void riscv_boot_info_init_discontig_mem(RISCVBootInfo *info,vaddr riscv_calc_kernel_start_addr (RISCVBootInfo *info,hwaddr firmware_end_addr);hwaddr riscv_find_and_load_firmware (MachineState *machine, +RISCVBootInfo *info,const char *default_machine_firmware,hwaddr *firmware_load_addr,symbol_fn_t sym_cb);const char *riscv_default_firmware_name (RISCVHartArrayState *harts);char *riscv_find_firmware (const char *firmware_filename,const char *default_machine_firmware); -hwaddr riscv_load_firmware (const char *firmware_filename, +hwaddr riscv_load_firmware (MachineState *machine, +const RISCVBootInfo *info, +const char *firmware_filename,hwaddr *firmware_load_addr,symbol_fn_t sym_cb); void riscv_load_kernel(MachineState *machine,
hw/riscv/boot.c +12 -6
@@ -150,6 +150,7 @@ char *riscv_find_firmware(const char *firmware_filename, }hwaddr riscv_find_and_load_firmware (MachineState *machine, +RISCVBootInfo *info,const char *default_machine_firmware,hwaddr *firmware_load_addr,symbol_fn_t sym_cb)
@@ -162,7 +163,8 @@ hwaddr riscv_find_and_load_firmware(MachineState *machine,if (firmware_filename) {/* If not "none" load the firmware */ - firmware_end_addr =riscv_load_firmware (firmware_filename, + firmware_end_addr =riscv_load_firmware (machine, info, + firmware_filename, firmware_load_addr, sym_cb);g_free (firmware_filename); }
@@ -170,10 +172,13 @@ hwaddr riscv_find_and_load_firmware(MachineState *machine,return firmware_end_addr; } -hwaddr riscv_load_firmware (const char *firmware_filename, +hwaddr riscv_load_firmware (MachineState *machine, +const RISCVBootInfo *info, +const char *firmware_filename,hwaddr *firmware_load_addr,symbol_fn_t sym_cb) { +uint64_t mem_size = info->ram_low_size ?: machine->ram_size;uint64_t firmware_entry, firmware_end;ssize_t firmware_size;
@@ -202,7 +207,7 @@ hwaddr riscv_load_firmware(const char *firmware_filename, firmware_size =load_image_targphys_as (firmware_filename, *firmware_load_addr, - current_machine->ram_size,NULL , + mem_size,NULL ,NULL );if (firmware_size >0 ) {
@@ -217,7 +222,7 @@ hwaddr riscv_load_firmware(const char *firmware_filename,static void riscv_load_initrd (MachineState *machine,RISCVBootInfo *info) {const char *filename = machine->initrd_filename; -uint64_t mem_size = machine->ram_size; +uint64_t mem_size = info->ram_low_size ?: machine->ram_size;void *fdt = machine->fdt;hwaddr start, end;ssize_t size;
@@ -263,6 +268,7 @@ void riscv_load_kernel(MachineState *machine,bool load_initrd, symbol_fn_t sym_cb) { + uint64_t mem_size = info->ram_low_size ?: machine->ram_size;const char *kernel_filename = machine->kernel_filename;ssize_t kernel_size;void *fdt = machine->fdt;
@@ -294,7 +300,7 @@ void riscv_load_kernel(MachineState *machine, } kernel_size =load_image_targphys_as (kernel_filename, kernel_start_addr, - current_machine->ram_size,NULL ,NULL ); + mem_size,NULL ,NULL );if (kernel_size >0 ) { info->kernel_size = kernel_size; info->image_low_addr = kernel_start_addr;
@@ -390,7 +396,7 @@ uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, dtb_start =QEMU_ALIGN_DOWN (temp - fdtsize,2 * MiB);if (dtb_start_limit && (dtb_start < dtb_start_limit)) { -error_report ("No enough memory to place DTB after kernel/initrd" ); +error_report ("Not enough memory to place DTB after kernel/initrd" );exit (1 ); }
hw/riscv/microchip_pfsoc.c +6 -2
@@ -619,18 +619,22 @@ static void microchip_icicle_kit_machine_init(MachineState *machine) firmware_load_addr =RESET_VECTOR ; } +riscv_boot_info_init_discontig_mem (&boot_info, &s->soc.u_cpus, + memmap[MICROCHIP_PFSOC_DRAM_LO ].base, + mem_low_size); +/* Load the firmware if necessary */ firmware_end_addr = firmware_load_addr;if (firmware_name) {char *filename =riscv_find_firmware (firmware_name,NULL );if (filename) { - firmware_end_addr =riscv_load_firmware (filename, + firmware_end_addr =riscv_load_firmware (machine, &boot_info, + filename, &firmware_load_addr,NULL );g_free (filename); } } -riscv_boot_info_init (&boot_info, &s->soc.u_cpus);if (machine->kernel_filename) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);
hw/riscv/opentitan.c +4 -2
@@ -100,12 +100,14 @@ static void opentitan_machine_init(MachineState *machine)memory_region_add_subregion (sys_mem, memmap[IBEX_DEV_RAM ].base, machine->ram); +riscv_boot_info_init (&boot_info, &s->soc.cpus); +if (machine->firmware) {hwaddr firmware_load_addr = memmap[IBEX_DEV_RAM ].base; -riscv_load_firmware (machine->firmware, &firmware_load_addr,NULL ); +riscv_load_firmware (machine, &boot_info, machine->firmware, + &firmware_load_addr,NULL ); } -riscv_boot_info_init (&boot_info, &s->soc.cpus);if (machine->kernel_filename) { riscv_load_kernel(machine, &boot_info, memmap[IBEX_DEV_RAM].base,
hw/riscv/shakti_c.c +5 -1
@@ -46,6 +46,7 @@ static void shakti_c_machine_state_init(MachineState *mstate) {ShaktiCMachineState *sms =RISCV_SHAKTI_MACHINE (mstate);MemoryRegion *system_memory =get_system_memory (); +RISCVBootInfo boot_info;hwaddr firmware_load_addr = shakti_c_memmap[SHAKTI_C_RAM ].base;/* Initialize SoC */
@@ -58,8 +59,11 @@ static void shakti_c_machine_state_init(MachineState *mstate) shakti_c_memmap[SHAKTI_C_RAM ].base, mstate->ram); +riscv_boot_info_init (&boot_info, &sms->soc.cpus); +if (mstate->firmware) { -riscv_load_firmware (mstate->firmware, &firmware_load_addr,NULL ); +riscv_load_firmware (mstate, &boot_info, mstate->firmware, + &firmware_load_addr,NULL ); }/* ROM reset vector */
hw/riscv/sifive_u.c +4 -2
@@ -590,11 +590,13 @@ static void sifive_u_machine_init(MachineState *machine)break ; } +riscv_boot_info_init (&boot_info, &s->soc.u_cpus); + firmware_name =riscv_default_firmware_name (&s->soc.u_cpus); - firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, + firmware_end_addr =riscv_find_and_load_firmware (machine, &boot_info, + firmware_name, &start_addr,NULL ); -riscv_boot_info_init (&boot_info, &s->soc.u_cpus);if (machine->kernel_filename) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);
hw/riscv/spike.c +4 -2
@@ -282,9 +282,12 @@ static void spike_board_init(MachineState *machine) } } +riscv_boot_info_init (&boot_info, &s->soc[0 ]); +/* Load firmware */ if (firmware_name) { - firmware_end_addr =riscv_load_firmware (firmware_name, + firmware_end_addr =riscv_load_firmware (machine, &boot_info, + firmware_name, &firmware_load_addr, htif_symbol_callback);g_free (firmware_name);
@@ -294,7 +297,6 @@ static void spike_board_init(MachineState *machine)create_fdt (s, memmap,riscv_is_32bit (&s->soc[0 ]), htif_custom_base);/* Load kernel */ -riscv_boot_info_init (&boot_info, &s->soc[0 ]);if (machine->kernel_filename) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);
hw/riscv/virt.c +4 -3
@@ -1458,7 +1458,10 @@ static void virt_machine_done(Notifier *notifier, void *data) } } - firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, +riscv_boot_info_init (&boot_info, &s->soc[0 ]); + + firmware_end_addr =riscv_find_and_load_firmware (machine, &boot_info, + firmware_name, &start_addr,NULL ); pflash_blk0 =pflash_cfi01_get_blk (s->flash[0 ]);
@@ -1481,8 +1484,6 @@ static void virt_machine_done(Notifier *notifier, void *data) } } -riscv_boot_info_init (&boot_info, &s->soc[0 ]); -if (machine->kernel_filename && !kernel_entry) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);
hw/riscv/xiangshan_kmh.c +5 -1
@@ -167,6 +167,7 @@ static void xiangshan_kmh_machine_init(MachineState *machine)const MemMapEntry *memmap = xiangshan_kmh_memmap;MemoryRegion *system_memory =get_system_memory ();hwaddr start_addr = memmap[XIANGSHAN_KMH_DRAM ].base; +RISCVBootInfo boot_info;/* Initialize SoC */ object_initialize_child(OBJECT(machine), "soc", &s->soc,
@@ -178,13 +179,16 @@ static void xiangshan_kmh_machine_init(MachineState *machine) memmap[XIANGSHAN_KMH_DRAM ].base, machine->ram); +riscv_boot_info_init (&boot_info, &s->soc.cpus); +/* ROM reset vector */ riscv_setup_rom_reset_vec (machine, &s->soc.cpus, start_addr, memmap[XIANGSHAN_KMH_ROM ].base, memmap[XIANGSHAN_KMH_ROM ].size,0 ,0 );if (machine->firmware) { -riscv_load_firmware (machine->firmware, &start_addr,NULL ); +riscv_load_firmware (machine, &boot_info, machine->firmware, + &start_addr,NULL ); }/* Note: dtb has been integrated into firmware(OpenSBI) when compiling */
Signature · 1 line
2.47.3
Re: [PATCH v8 02/12] hw/riscv/boot: Account for discontiguous memory when loading firmware
Quoted 9 lines · Joel Stanley
From: Nicholas Piggin <[email protected]>
This loads firmware into the first (low) memory range, accounting for machines having discontiguous memory regions.
Reviewed-by Daniel Henrique Barboza <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 295 lines
--- include/hw/riscv/boot.h | 5 ++++- hw/riscv/boot.c | 18 ++++++++++++------ hw/riscv/microchip_pfsoc.c | 8 ++++++-- hw/riscv/opentitan.c | 6 ++++-- hw/riscv/shakti_c.c | 6 +++++- hw/riscv/sifive_u.c | 6 ++++-- hw/riscv/spike.c | 6 ++++-- hw/riscv/virt.c | 7 ++++--- hw/riscv/xiangshan_kmh.c | 6 +++++- 9 files changed, 48 insertions(+), 20 deletions(-)include/hw/riscv/boot.h +4
-1@@ -53,13 +53,16 @@ void riscv_boot_info_init_discontig_mem(RISCVBootInfo *info,vaddr riscv_calc_kernel_start_addr (RISCVBootInfo *info,hwaddr firmware_end_addr);hwaddr riscv_find_and_load_firmware (MachineState *machine, +RISCVBootInfo *info,const char *default_machine_firmware,hwaddr *firmware_load_addr,symbol_fn_t sym_cb);const char *riscv_default_firmware_name (RISCVHartArrayState *harts);char *riscv_find_firmware (const char *firmware_filename,const char *default_machine_firmware); -hwaddr riscv_load_firmware (const char *firmware_filename, +hwaddr riscv_load_firmware (MachineState *machine, +const RISCVBootInfo *info, +const char *firmware_filename,hwaddr *firmware_load_addr,symbol_fn_t sym_cb); void riscv_load_kernel(MachineState *machine,hw/riscv/boot.c +12
-6@@ -150,6 +150,7 @@ char *riscv_find_firmware(const char *firmware_filename, }hwaddr riscv_find_and_load_firmware (MachineState *machine, +RISCVBootInfo *info,const char *default_machine_firmware,hwaddr *firmware_load_addr,symbol_fn_t sym_cb)@@ -162,7 +163,8 @@ hwaddr riscv_find_and_load_firmware(MachineState *machine,if (firmware_filename) {/* If not "none" load the firmware */ - firmware_end_addr =riscv_load_firmware (firmware_filename, + firmware_end_addr =riscv_load_firmware (machine, info, + firmware_filename, firmware_load_addr, sym_cb);g_free (firmware_filename); }@@ -170,10 +172,13 @@ hwaddr riscv_find_and_load_firmware(MachineState *machine,return firmware_end_addr; } -hwaddr riscv_load_firmware (const char *firmware_filename, +hwaddr riscv_load_firmware (MachineState *machine, +const RISCVBootInfo *info, +const char *firmware_filename,hwaddr *firmware_load_addr,symbol_fn_t sym_cb) { +uint64_t mem_size = info->ram_low_size ?: machine->ram_size;uint64_t firmware_entry, firmware_end;ssize_t firmware_size;@@ -202,7 +207,7 @@ hwaddr riscv_load_firmware(const char *firmware_filename, firmware_size =load_image_targphys_as (firmware_filename, *firmware_load_addr, - current_machine->ram_size,NULL , + mem_size,NULL ,NULL );if (firmware_size >0 ) {@@ -217,7 +222,7 @@ hwaddr riscv_load_firmware(const char *firmware_filename,static void riscv_load_initrd (MachineState *machine,RISCVBootInfo *info) {const char *filename = machine->initrd_filename; -uint64_t mem_size = machine->ram_size; +uint64_t mem_size = info->ram_low_size ?: machine->ram_size;void *fdt = machine->fdt;hwaddr start, end;ssize_t size;@@ -263,6 +268,7 @@ void riscv_load_kernel(MachineState *machine,bool load_initrd, symbol_fn_t sym_cb) { + uint64_t mem_size = info->ram_low_size ?: machine->ram_size;const char *kernel_filename = machine->kernel_filename;ssize_t kernel_size;void *fdt = machine->fdt;@@ -294,7 +300,7 @@ void riscv_load_kernel(MachineState *machine, } kernel_size =load_image_targphys_as (kernel_filename, kernel_start_addr, - current_machine->ram_size,NULL ,NULL ); + mem_size,NULL ,NULL );if (kernel_size >0 ) { info->kernel_size = kernel_size; info->image_low_addr = kernel_start_addr;@@ -390,7 +396,7 @@ uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, dtb_start =QEMU_ALIGN_DOWN (temp - fdtsize,2 * MiB);if (dtb_start_limit && (dtb_start < dtb_start_limit)) { -error_report ("No enough memory to place DTB after kernel/initrd" ); +error_report ("Not enough memory to place DTB after kernel/initrd" );exit (1 ); }hw/riscv/microchip_pfsoc.c +6
-2@@ -619,18 +619,22 @@ static void microchip_icicle_kit_machine_init(MachineState *machine) firmware_load_addr =RESET_VECTOR ; } +riscv_boot_info_init_discontig_mem (&boot_info, &s->soc.u_cpus, + memmap[MICROCHIP_PFSOC_DRAM_LO ].base, + mem_low_size); +/* Load the firmware if necessary */ firmware_end_addr = firmware_load_addr;if (firmware_name) {char *filename =riscv_find_firmware (firmware_name,NULL );if (filename) { - firmware_end_addr =riscv_load_firmware (filename, + firmware_end_addr =riscv_load_firmware (machine, &boot_info, + filename, &firmware_load_addr,NULL );g_free (filename); } } -riscv_boot_info_init (&boot_info, &s->soc.u_cpus);if (machine->kernel_filename) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);hw/riscv/opentitan.c +4
-2@@ -100,12 +100,14 @@ static void opentitan_machine_init(MachineState *machine)memory_region_add_subregion (sys_mem, memmap[IBEX_DEV_RAM ].base, machine->ram); +riscv_boot_info_init (&boot_info, &s->soc.cpus); +if (machine->firmware) {hwaddr firmware_load_addr = memmap[IBEX_DEV_RAM ].base; -riscv_load_firmware (machine->firmware, &firmware_load_addr,NULL ); +riscv_load_firmware (machine, &boot_info, machine->firmware, + &firmware_load_addr,NULL ); } -riscv_boot_info_init (&boot_info, &s->soc.cpus);if (machine->kernel_filename) { riscv_load_kernel(machine, &boot_info, memmap[IBEX_DEV_RAM].base,hw/riscv/shakti_c.c +5
-1@@ -46,6 +46,7 @@ static void shakti_c_machine_state_init(MachineState *mstate) {ShaktiCMachineState *sms =RISCV_SHAKTI_MACHINE (mstate);MemoryRegion *system_memory =get_system_memory (); +RISCVBootInfo boot_info;hwaddr firmware_load_addr = shakti_c_memmap[SHAKTI_C_RAM ].base;/* Initialize SoC */ @@ -58,8 +59,11 @@ static void shakti_c_machine_state_init(MachineState *mstate) shakti_c_memmap[SHAKTI_C_RAM ].base, mstate->ram); +riscv_boot_info_init (&boot_info, &sms->soc.cpus); +if (mstate->firmware) { -riscv_load_firmware (mstate->firmware, &firmware_load_addr,NULL ); +riscv_load_firmware (mstate, &boot_info, mstate->firmware, + &firmware_load_addr,NULL ); }/* ROM reset vector */ hw/riscv/sifive_u.c +4
-2@@ -590,11 +590,13 @@ static void sifive_u_machine_init(MachineState *machine)break ; } +riscv_boot_info_init (&boot_info, &s->soc.u_cpus); + firmware_name =riscv_default_firmware_name (&s->soc.u_cpus); - firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, + firmware_end_addr =riscv_find_and_load_firmware (machine, &boot_info, + firmware_name, &start_addr,NULL ); -riscv_boot_info_init (&boot_info, &s->soc.u_cpus);if (machine->kernel_filename) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);hw/riscv/spike.c +4
-2@@ -282,9 +282,12 @@ static void spike_board_init(MachineState *machine) } } +riscv_boot_info_init (&boot_info, &s->soc[0 ]); +/* Load firmware */ if (firmware_name) { - firmware_end_addr =riscv_load_firmware (firmware_name, + firmware_end_addr =riscv_load_firmware (machine, &boot_info, + firmware_name, &firmware_load_addr, htif_symbol_callback);g_free (firmware_name);@@ -294,7 +297,6 @@ static void spike_board_init(MachineState *machine)create_fdt (s, memmap,riscv_is_32bit (&s->soc[0 ]), htif_custom_base);/* Load kernel */ -riscv_boot_info_init (&boot_info, &s->soc[0 ]);if (machine->kernel_filename) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);hw/riscv/virt.c +4
-3@@ -1458,7 +1458,10 @@ static void virt_machine_done(Notifier *notifier, void *data) } } - firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, +riscv_boot_info_init (&boot_info, &s->soc[0 ]); + + firmware_end_addr =riscv_find_and_load_firmware (machine, &boot_info, + firmware_name, &start_addr,NULL ); pflash_blk0 =pflash_cfi01_get_blk (s->flash[0 ]);@@ -1481,8 +1484,6 @@ static void virt_machine_done(Notifier *notifier, void *data) } } -riscv_boot_info_init (&boot_info, &s->soc[0 ]); -if (machine->kernel_filename && !kernel_entry) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);hw/riscv/xiangshan_kmh.c +5
-2@@ -167,6 +167,7 @@ static void xiangshan_kmh_machine_init(MachineState *machine)const MemMapEntry *memmap = xiangshan_kmh_memmap;MemoryRegion *system_memory =get_system_memory ();hwaddr start_addr = memmap[XIANGSHAN_KMH_DRAM ].base; +RISCVBootInfo boot_info;/* Initialize SoC */ object_initialize_child(OBJECT(machine), "soc", &s->soc,@@ -178,13 +179,16 @@ static void xiangshan_kmh_machine_init(MachineState *machine) memmap[XIANGSHAN_KMH_DRAM ].base, machine->ram); +riscv_boot_info_init (&boot_info, &s->soc.cpus); +/* ROM reset vector */ riscv_setup_rom_reset_vec (machine, &s->soc.cpus, start_addr, memmap[XIANGSHAN_KMH_ROM ].base, memmap[XIANGSHAN_KMH_ROM ].size,0 ,0 );if (machine->firmware) { -riscv_load_firmware (machine->firmware, &start_addr,NULL ); +riscv_load_firmware (machine, &boot_info, machine->firmware, + &start_addr,NULL ); }/* Note: dtb has been integrated into firmware(OpenSBI) when compiling */ --2.47.3
PATCH v8 3/12 hw/riscv/virt: Move AIA initialisation to helper file
In reply to Joel StanleyThe AIA init will be used by any server class riscv machine. Separate it out in order to share code with such systems.
The virt machine keeps machine specific #defines such as VIRT_IRQCHIP_NUM_MSIS, VIRT_IRQCHIP_NUM_PRIO_BITS.
--- hw/riscv/aia.h | 26 +++++++++++ include/hw/riscv/virt.h | 1 - hw/riscv/aia.c | 89 ++++++++++++++++++++++++++++++++++++++ hw/riscv/virt-acpi-build.c | 2 + hw/riscv/virt.c | 87 +++++-------------------------------- hw/riscv/meson.build | 2 +- 6 files changed, 129 insertions(+), 78 deletions(-) create mode 100644 hw/riscv/aia.h create mode 100644 hw/riscv/aia.c
hw/riscv/aia.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* QEMU RISC-V Advanced Interrupt Architecture (AIA) +* +* Copyright (C) 2019 Western Digital Corporation or its affiliates. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_RISCV_AIA_H +#define HW_RISCV_AIA_H + +#include "exec/hwaddr.h" + +#define VIRT_IRQCHIP_NUM_SOURCES 96 + +uint32_t imsic_num_bits (uint32_t count); + +DeviceState *riscv_create_aia (bool msimode,int aia_guests, +const MemMapEntry *aplic_m, +const MemMapEntry *aplic_s, +const MemMapEntry *imsic_m, +const MemMapEntry *imsic_s, +int socket,int base_hartid,int hart_count, +uint32_t num_msis,uint32_t num_prio_bits); + +#endif
include/hw/riscv/virt.h +0 -1
@@ -135,7 +135,6 @@ enum {bool virt_is_acpi_enabled (RISCVVirtState *s);bool virt_is_iommu_sys_enabled (RISCVVirtState *s);void virt_acpi_setup (RISCVVirtState *vms); -uint32_t imsic_num_bits (uint32_t count);/* * The virt machine physical address space used by some of the devices
hw/riscv/aia.c new file +89 -0
89 lines not on this page · raw message
hw/riscv/virt-acpi-build.c +2 -0
@@ -42,6 +42,8 @@#include "system/kvm.h" #include "system/reset.h" +#include "aia.h" +#define ACPI_BUILD_TABLE_SIZE 0x20000#define ACPI_BUILD_INTC_ID (socket, index) ((socket << 24) | (index))
hw/riscv/virt.c +11 -76
111 lines not on this page · raw message
hw/riscv/meson.build +1 -1
@@ -1,5 +1,5 @@ riscv_ss = ss.source_set() -riscv_ss.add(files('boot.c')) +riscv_ss.add(files('boot.c', 'aia.c')) riscv_ss.add(when: 'CONFIG_RISCV_NUMA', if_true: files('numa.c')) riscv_ss.add(files('riscv_hart.c')) riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c'))
Signature · 1 line
2.47.3
Re: [PATCH v8 03/12] hw/riscv/virt: Move AIA initialisation to helper file
Quoted 4 lines · Joel Stanley
The AIA init will be used by any server class riscv machine. Separate it out in order to share code with such systems.
Quoted 8 lines
The virt machine keeps machine specific #defines such as
VIRT_IRQCHIP_NUM_MSIS,VIRT_IRQCHIP_NUM_PRIO_BITS.Reviewed-by Daniel Henrique Barboza <[email protected]>Reviewed-by Nutty Liu <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 297 lines
--- hw/riscv/aia.h | 26 +++++++++++ include/hw/riscv/virt.h | 1 - hw/riscv/aia.c | 89 ++++++++++++++++++++++++++++++++++++++ hw/riscv/virt-acpi-build.c | 2 + hw/riscv/virt.c | 87 +++++-------------------------------- hw/riscv/meson.build | 2 +- 6 files changed, 129 insertions(+), 78 deletions(-) create mode 100644 hw/riscv/aia.h create mode 100644 hw/riscv/aia.chw/riscv/aia.h new file +26
-0@@ -0,0 +1,26 @@ +/* +* QEMU RISC-V Advanced Interrupt Architecture (AIA) +* +* Copyright (C) 2019 Western Digital Corporation or its affiliates. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_RISCV_AIA_H +#define HW_RISCV_AIA_H + +#include "exec/hwaddr.h" + +#define VIRT_IRQCHIP_NUM_SOURCES 96 + +uint32_t imsic_num_bits (uint32_t count); + +DeviceState *riscv_create_aia (bool msimode,int aia_guests, +const MemMapEntry *aplic_m, +const MemMapEntry *aplic_s, +const MemMapEntry *imsic_m, +const MemMapEntry *imsic_s, +int socket,int base_hartid,int hart_count, +uint32_t num_msis,uint32_t num_prio_bits); + +#endif include/hw/riscv/virt.h +0
-1@@ -135,7 +135,6 @@ enum {bool virt_is_acpi_enabled (RISCVVirtState *s);bool virt_is_iommu_sys_enabled (RISCVVirtState *s);void virt_acpi_setup (RISCVVirtState *vms); -uint32_t imsic_num_bits (uint32_t count);/* * The virt machine physical address space used by some of the devices hw/riscv/aia.c new file +89
-0@@ -0,0 +1,89 @@ +/* +* QEMU RISC-V Advanced Interrupt Architecture (AIA) +* +* Copyright (C) 2019 Western Digital Corporation or its affiliates. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "system/kvm.h" +#include "hw/intc/riscv_aplic.h" +#include "hw/intc/riscv_imsic.h" + +#include "aia.h" + +uint32_t imsic_num_bits (uint32_t count) +{ +uint32_t ret =0 ; + +while (BIT (ret) < count) { + ret++; + } + +return ret; +} + +DeviceState *riscv_create_aia (bool msimode,int aia_guests, +const MemMapEntry *aplic_m, +const MemMapEntry *aplic_s, +const MemMapEntry *imsic_m, +const MemMapEntry *imsic_s, +int socket,int base_hartid,int hart_count, +uint32_t num_msis,uint32_t num_prio_bits) +{ +int i; +hwaddr addr =0 ; +uint32_t guest_bits; +DeviceState *aplic_s_dev =NULL ; +DeviceState *aplic_m_dev =NULL ; + +if (msimode) { +if (!kvm_enabled ()) { +/* 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 *IMSIC_HART_SIZE (0 ), + base_hartid + i, true,1 , + num_msis); + } + } + +/* Per-socket S-level IMSICs */ + guest_bits =imsic_num_bits (aia_guests +1 ); + addr = imsic_s->base + socket * (1U <<IMSIC_MMIO_GROUP_MIN_SHIFT ); +for (i =0 ; i < hart_count; i++) { +riscv_imsic_create (addr + i *IMSIC_HART_SIZE (guest_bits), + base_hartid + i, false,1 + aia_guests, + num_msis); + } + } + +if (!kvm_enabled ()) { +/* Per-socket M-level APLIC */ + aplic_m_dev =riscv_aplic_create (aplic_m->base + + socket * aplic_m->size, + aplic_m->size, + (msimode) ?0 : base_hartid, + (msimode) ?0 : hart_count, +VIRT_IRQCHIP_NUM_SOURCES , + num_prio_bits, + msimode, true,NULL ); + } + +/* Per-socket S-level APLIC */ + aplic_s_dev =riscv_aplic_create (aplic_s->base + + socket * aplic_s->size, + aplic_s->size, + (msimode) ?0 : base_hartid, + (msimode) ?0 : hart_count, +VIRT_IRQCHIP_NUM_SOURCES , + num_prio_bits, + msimode, false, aplic_m_dev); + +if (kvm_enabled () && msimode) { +riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s_dev), addr); + } + +return kvm_enabled () ? aplic_s_dev : aplic_m_dev; +}hw/riscv/virt-acpi-build.c +2
-0@@ -42,6 +42,8 @@#include "system/kvm.h" #include "system/reset.h" +#include "aia.h" +#define ACPI_BUILD_TABLE_SIZE 0x20000#define ACPI_BUILD_INTC_ID (socket, index) ((socket << 24) | (index))hw/riscv/virt.c +11
-76@@ -60,6 +60,8 @@#include "hw/virtio/virtio-iommu.h" #include "hw/uefi/var-service-api.h" +#include "aia.h" +/* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ static bool virt_use_kvm_aia_aplic_imsic (RISCVVirtAIAType aia_type) {@@ -510,17 +512,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s, } } -uint32_t imsic_num_bits (uint32_t count) -{ -uint32_t ret =0 ; - -while (BIT (ret) < count) { - ret++; - } - -return ret; -} -static void create_fdt_one_imsic (RISCVVirtState *s,hwaddr base_addr,uint32_t *intc_phandles,uint32_t msi_phandle,bool m_mode,uint32_t imsic_guest_bits)@@ -1294,68 +1285,6 @@ static DeviceState *virt_create_plic(const MemMapEntry *memmap, int socket, memmap[VIRT_PLIC].size); } -static DeviceState *virt_create_aia (RISCVVirtAIAType aia_type,int aia_guests, -const MemMapEntry *memmap,int socket, -int base_hartid,int hart_count) -{ -int i; -hwaddr addr =0 ; -uint32_t guest_bits; -DeviceState *aplic_s =NULL ; -DeviceState *aplic_m =NULL ; -bool msimode = aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ; - -if (msimode) { -if (!kvm_enabled ()) { -/* Per-socket M-level IMSICs */ - addr = memmap[VIRT_IMSIC_M ].base + - socket *VIRT_IMSIC_GROUP_MAX_SIZE ; -for (i =0 ; i < hart_count; i++) { -riscv_imsic_create (addr + i *IMSIC_HART_SIZE (0 ), - base_hartid + i, true,1 , -VIRT_IRQCHIP_NUM_MSIS ); - } - } - -/* Per-socket S-level IMSICs */ - guest_bits =imsic_num_bits (aia_guests +1 ); - addr = memmap[VIRT_IMSIC_S ].base + socket *VIRT_IMSIC_GROUP_MAX_SIZE ; -for (i =0 ; i < hart_count; i++) { -riscv_imsic_create (addr + i *IMSIC_HART_SIZE (guest_bits), - base_hartid + i, false,1 + aia_guests, -VIRT_IRQCHIP_NUM_MSIS ); - } - } - -if (!kvm_enabled ()) { -/* Per-socket M-level APLIC */ - aplic_m =riscv_aplic_create (memmap[VIRT_APLIC_M ].base + - socket * memmap[VIRT_APLIC_M ].size, - memmap[VIRT_APLIC_M ].size, - (msimode) ?0 : base_hartid, - (msimode) ?0 : hart_count, -VIRT_IRQCHIP_NUM_SOURCES , -VIRT_IRQCHIP_NUM_PRIO_BITS , - msimode, true,NULL ); - } - -/* Per-socket S-level APLIC */ - aplic_s =riscv_aplic_create (memmap[VIRT_APLIC_S ].base + - socket * memmap[VIRT_APLIC_S ].size, - memmap[VIRT_APLIC_S ].size, - (msimode) ?0 : base_hartid, - (msimode) ?0 : hart_count, -VIRT_IRQCHIP_NUM_SOURCES , -VIRT_IRQCHIP_NUM_PRIO_BITS , - msimode, false, aplic_m); - -if (kvm_enabled () && msimode) { -riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s), addr); - } - -return kvm_enabled () ? aplic_s : aplic_m; -} -static void create_platform_bus (RISCVVirtState *s,DeviceState *irqchip) {DeviceState *dev;@@ -1618,9 +1547,15 @@ static void virt_machine_init(MachineState *machine) s->irqchip[i] =virt_create_plic (s->memmap, i, base_hartid, hart_count); }else { - s->irqchip[i] =virt_create_aia (s->aia_type, s->aia_guests, - s->memmap, i, base_hartid, - hart_count); + s->irqchip[i] =riscv_create_aia (s->aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC , + s->aia_guests, + &s->memmap[VIRT_APLIC_M ], + &s->memmap[VIRT_APLIC_S ], + &s->memmap[VIRT_IMSIC_M ], + &s->memmap[VIRT_IMSIC_S ], + i, base_hartid, hart_count, +VIRT_IRQCHIP_NUM_MSIS , +VIRT_IRQCHIP_NUM_PRIO_BITS ); }/* Try to use different IRQCHIP instance based device type */ hw/riscv/meson.build +1
-2@@ -1,5 +1,5 @@ riscv_ss = ss.source_set() -riscv_ss.add(files('boot.c')) +riscv_ss.add(files('boot.c', 'aia.c')) riscv_ss.add(when: 'CONFIG_RISCV_NUMA', if_true: files('numa.c')) riscv_ss.add(files('riscv_hart.c')) riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) --2.47.3
PATCH v8 4/12 hw/riscv/aia: Provide number of irq sources
In reply to Joel StanleyInstead of hard coding the number of IRQ sources used by the APLIC pass it in as a parameter. This allows other machines to configure this as required.
The maximum number of sources is 1023.
--- hw/riscv/aia.h | 3 +-- include/hw/riscv/virt.h | 1 + hw/riscv/aia.c | 8 ++++++-- hw/riscv/virt-acpi-build.c | 25 ++++++++++++++++--------- hw/riscv/virt.c | 2 ++ 5 files changed, 26 insertions(+), 13 deletions(-)
hw/riscv/aia.h +1 -2
@@ -11,11 +11,10 @@#include "exec/hwaddr.h" -#define VIRT_IRQCHIP_NUM_SOURCES 96 -uint32_t imsic_num_bits (uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s, const MemMapEntry *imsic_m,
include/hw/riscv/virt.h +1 -0
@@ -64,6 +64,7 @@ struct RISCVVirtState {struct GPEXHost *gpex_host;OnOffAuto iommu_sys;uint16_t pci_iommu_bdf; +uint16_t num_sources; };enum {
hw/riscv/aia.c +6 -2
@@ -25,6 +25,7 @@ uint32_t imsic_num_bits(uint32_t count) } DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s, const MemMapEntry *imsic_m,
@@ -38,6 +39,9 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,DeviceState *aplic_s_dev =NULL ;DeviceState *aplic_m_dev =NULL ; +/* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */ +g_assert (num_sources <=1023 ); +if (msimode) {if (!kvm_enabled ()) {/* Per-socket M-level IMSICs */
@@ -66,7 +70,7 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests, aplic_m->size, (msimode) ?0 : base_hartid, (msimode) ?0 : hart_count, -VIRT_IRQCHIP_NUM_SOURCES , + num_sources, num_prio_bits, msimode, true, NULL); }
@@ -77,7 +81,7 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests, aplic_s->size, (msimode) ?0 : base_hartid, (msimode) ?0 : hart_count, -VIRT_IRQCHIP_NUM_SOURCES , + num_sources, num_prio_bits, msimode, false, aplic_m_dev);
hw/riscv/virt-acpi-build.c +16 -9
@@ -146,6 +146,7 @@ static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s) }static void acpi_dsdt_add_plic_aplic (Aml *scope,uint8_t socket_count, +uint16_t num_sources,uint64_t mmio_base,uint64_t mmio_size,const char *hid) {
@@ -153,9 +154,12 @@ static void acpi_dsdt_add_plic_aplic(Aml *scope, uint8_t socket_count,uint32_t gsi_base;uint8_t socket; +/* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */ +g_assert (num_sources <=1023 ); +for (socket =0 ; socket < socket_count; socket++) { plic_aplic_addr = mmio_base + mmio_size * socket; - gsi_base =VIRT_IRQCHIP_NUM_SOURCES * socket; + gsi_base = num_sources * socket;Aml *dev =aml_device ("IC%.02X" , socket);aml_append (dev,aml_name_decl ("_HID" ,aml_string ("%s" , hid)));aml_append (dev,aml_name_decl ("_UID" ,aml_int (socket)));
@@ -474,10 +478,13 @@ static void build_dsdt(GArray *table_data, socket_count =riscv_socket_count (ms);if (s->aia_type ==VIRT_AIA_TYPE_NONE ) { -acpi_dsdt_add_plic_aplic (scope, socket_count, memmap[VIRT_PLIC ].base, - memmap[VIRT_PLIC ].size,"RSCV0001" ); +acpi_dsdt_add_plic_aplic (scope, socket_count, s->num_sources, + memmap[VIRT_PLIC ].base, + memmap[VIRT_PLIC ].size, +"RSCV0001" ); }else { -acpi_dsdt_add_plic_aplic (scope, socket_count, memmap[VIRT_APLIC_S ].base, +acpi_dsdt_add_plic_aplic (scope, socket_count, s->num_sources, + memmap[VIRT_APLIC_S ].base, memmap[VIRT_APLIC_S ].size,"RSCV0002" ); }
@@ -494,15 +501,15 @@ static void build_dsdt(GArray *table_data, }else if (socket_count ==2 ) {virtio_acpi_dsdt_add (scope, memmap[VIRT_VIRTIO ].base, memmap[VIRT_VIRTIO ].size, -VIRTIO_IRQ +VIRT_IRQCHIP_NUM_SOURCES ,0 , +VIRTIO_IRQ + s->num_sources,0 ,VIRTIO_COUNT ); -acpi_dsdt_add_gpex_host (scope,PCIE_IRQ +VIRT_IRQCHIP_NUM_SOURCES ); +acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources); }else {virtio_acpi_dsdt_add (scope, memmap[VIRT_VIRTIO ].base, memmap[VIRT_VIRTIO ].size, -VIRTIO_IRQ +VIRT_IRQCHIP_NUM_SOURCES ,0 , +VIRTIO_IRQ + s->num_sources,0 ,VIRTIO_COUNT ); -acpi_dsdt_add_gpex_host (scope,PCIE_IRQ +VIRT_IRQCHIP_NUM_SOURCES *2 ); +acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources *2 ); }aml_append (dsdt, scope);
@@ -581,7 +588,7 @@ static void build_madt(GArray *table_data,for (socket =0 ; socket <riscv_socket_count (ms); socket++) { aplic_addr = s->memmap[VIRT_APLIC_S ].base + s->memmap[VIRT_APLIC_S ].size * socket; - gsi_base =VIRT_IRQCHIP_NUM_SOURCES * socket; + gsi_base = s->num_sources * socket;build_append_int_noprefix (table_data,0x1A ,1 );/* Type */ build_append_int_noprefix (table_data,36 ,1 );/* Length */ build_append_int_noprefix (table_data,1 ,1 );/* Version */
hw/riscv/virt.c +2 -0
@@ -1549,6 +1549,7 @@ static void virt_machine_init(MachineState *machine) }else { s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC, s->aia_guests, + s->num_sources, &s->memmap[VIRT_APLIC_M], &s->memmap[VIRT_APLIC_S], &s->memmap[VIRT_IMSIC_M],
@@ -1705,6 +1706,7 @@ static void virt_machine_instance_init(Object *obj) s->oem_table_id =g_strndup (ACPI_BUILD_APPNAME8 ,8 ); s->acpi =ON_OFF_AUTO_AUTO ; s->iommu_sys =ON_OFF_AUTO_AUTO ; + s->num_sources =VIRT_IRQCHIP_NUM_SOURCES ; }static char *virt_get_aia_guests (Object *obj,Error **errp)
Signature · 1 line
2.47.3
Re: [PATCH v8 04/12] hw/riscv/aia: Provide number of irq sources
Quoted 5 lines · Joel Stanley
Instead of hard coding the number of IRQ sources used by the APLIC pass it in as a parameter. This allows other machines to configure this as required.
Quoted 7 lines
The maximum number of sources is 1023.
Reviewed-by Nutty Liu <[email protected]>Reviewed-by Daniel Henrique Barboza <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 173 lines
--- hw/riscv/aia.h | 3 +-- include/hw/riscv/virt.h | 1 + hw/riscv/aia.c | 8 ++++++-- hw/riscv/virt-acpi-build.c | 25 ++++++++++++++++--------- hw/riscv/virt.c | 2 ++ 5 files changed, 26 insertions(+), 13 deletions(-)hw/riscv/aia.h +1
-2@@ -11,11 +11,10 @@#include "exec/hwaddr.h" -#define VIRT_IRQCHIP_NUM_SOURCES 96 -uint32_t imsic_num_bits (uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s, const MemMapEntry *imsic_m,include/hw/riscv/virt.h +1
-0@@ -64,6 +64,7 @@ struct RISCVVirtState {struct GPEXHost *gpex_host;OnOffAuto iommu_sys;uint16_t pci_iommu_bdf; +uint16_t num_sources; };enum {hw/riscv/aia.c +6
-2@@ -25,6 +25,7 @@ uint32_t imsic_num_bits(uint32_t count) } DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s, const MemMapEntry *imsic_m,@@ -38,6 +39,9 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,DeviceState *aplic_s_dev =NULL ;DeviceState *aplic_m_dev =NULL ; +/* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */ +g_assert (num_sources <=1023 ); +if (msimode) {if (!kvm_enabled ()) {/* Per-socket M-level IMSICs */ @@ -66,7 +70,7 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests, aplic_m->size, (msimode) ?0 : base_hartid, (msimode) ?0 : hart_count, -VIRT_IRQCHIP_NUM_SOURCES , + num_sources, num_prio_bits, msimode, true, NULL); }@@ -77,7 +81,7 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests, aplic_s->size, (msimode) ?0 : base_hartid, (msimode) ?0 : hart_count, -VIRT_IRQCHIP_NUM_SOURCES , + num_sources, num_prio_bits, msimode, false, aplic_m_dev);hw/riscv/virt-acpi-build.c +16
-9@@ -146,6 +146,7 @@ static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s) }static void acpi_dsdt_add_plic_aplic (Aml *scope,uint8_t socket_count, +uint16_t num_sources,uint64_t mmio_base,uint64_t mmio_size,const char *hid) {@@ -153,9 +154,12 @@ static void acpi_dsdt_add_plic_aplic(Aml *scope, uint8_t socket_count,uint32_t gsi_base;uint8_t socket; +/* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */ +g_assert (num_sources <=1023 ); +for (socket =0 ; socket < socket_count; socket++) { plic_aplic_addr = mmio_base + mmio_size * socket; - gsi_base =VIRT_IRQCHIP_NUM_SOURCES * socket; + gsi_base = num_sources * socket;Aml *dev =aml_device ("IC%.02X" , socket);aml_append (dev,aml_name_decl ("_HID" ,aml_string ("%s" , hid)));aml_append (dev,aml_name_decl ("_UID" ,aml_int (socket)));@@ -474,10 +478,13 @@ static void build_dsdt(GArray *table_data, socket_count =riscv_socket_count (ms);if (s->aia_type ==VIRT_AIA_TYPE_NONE ) { -acpi_dsdt_add_plic_aplic (scope, socket_count, memmap[VIRT_PLIC ].base, - memmap[VIRT_PLIC ].size,"RSCV0001" ); +acpi_dsdt_add_plic_aplic (scope, socket_count, s->num_sources, + memmap[VIRT_PLIC ].base, + memmap[VIRT_PLIC ].size, +"RSCV0001" ); }else { -acpi_dsdt_add_plic_aplic (scope, socket_count, memmap[VIRT_APLIC_S ].base, +acpi_dsdt_add_plic_aplic (scope, socket_count, s->num_sources, + memmap[VIRT_APLIC_S ].base, memmap[VIRT_APLIC_S ].size,"RSCV0002" ); }@@ -494,15 +501,15 @@ static void build_dsdt(GArray *table_data, }else if (socket_count ==2 ) {virtio_acpi_dsdt_add (scope, memmap[VIRT_VIRTIO ].base, memmap[VIRT_VIRTIO ].size, -VIRTIO_IRQ +VIRT_IRQCHIP_NUM_SOURCES ,0 , +VIRTIO_IRQ + s->num_sources,0 ,VIRTIO_COUNT ); -acpi_dsdt_add_gpex_host (scope,PCIE_IRQ +VIRT_IRQCHIP_NUM_SOURCES ); +acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources); }else {virtio_acpi_dsdt_add (scope, memmap[VIRT_VIRTIO ].base, memmap[VIRT_VIRTIO ].size, -VIRTIO_IRQ +VIRT_IRQCHIP_NUM_SOURCES ,0 , +VIRTIO_IRQ + s->num_sources,0 ,VIRTIO_COUNT ); -acpi_dsdt_add_gpex_host (scope,PCIE_IRQ +VIRT_IRQCHIP_NUM_SOURCES *2 ); +acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources *2 ); }aml_append (dsdt, scope);@@ -581,7 +588,7 @@ static void build_madt(GArray *table_data,for (socket =0 ; socket <riscv_socket_count (ms); socket++) { aplic_addr = s->memmap[VIRT_APLIC_S ].base + s->memmap[VIRT_APLIC_S ].size * socket; - gsi_base =VIRT_IRQCHIP_NUM_SOURCES * socket; + gsi_base = s->num_sources * socket;build_append_int_noprefix (table_data,0x1A ,1 );/* Type */ build_append_int_noprefix (table_data,36 ,1 );/* Length */ build_append_int_noprefix (table_data,1 ,1 );/* Version */ hw/riscv/virt.c +2
-1@@ -1549,6 +1549,7 @@ static void virt_machine_init(MachineState *machine) }else { s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC, s->aia_guests, + s->num_sources, &s->memmap[VIRT_APLIC_M], &s->memmap[VIRT_APLIC_S], &s->memmap[VIRT_IMSIC_M],@@ -1705,6 +1706,7 @@ static void virt_machine_instance_init(Object *obj) s->oem_table_id =g_strndup (ACPI_BUILD_APPNAME8 ,8 ); s->acpi =ON_OFF_AUTO_AUTO ; s->iommu_sys =ON_OFF_AUTO_AUTO ; + s->num_sources =VIRT_IRQCHIP_NUM_SOURCES ; }static char *virt_get_aia_guests (Object *obj,Error **errp) --2.47.3
PATCH v8 5/12 hw/riscv/aia: Configure stride for the M-mode IMSIC
In reply to Joel Stanleyriscv_create_aia() currently hard-codes the M-IMSIC at one 4 KiB page per hart and gives callers no way to widen it.
Add an m_imsic_stride parameter that supplies the per hart byte stride directly. The virt machine passes IMSIC_HART_SIZE(0) (= 4 KiB), preserving its existing compact layout.
The parameter only changes how the slots are spaced, with the rest of each slot reserved. This allows future platforms that have different layouts to control the stride.
--- hw/riscv/aia.h | 1 + hw/riscv/aia.c | 3 ++- hw/riscv/virt.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-)
hw/riscv/aia.h +1 -0
@@ -14,6 +14,7 @@uint32_t imsic_num_bits (uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + hwaddr m_imsic_stride, uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,
hw/riscv/aia.c +2 -1
@@ -25,6 +25,7 @@ uint32_t imsic_num_bits(uint32_t count) } DeviceState *riscv_create_aia(bool msimode, int aia_guests, + hwaddr m_imsic_stride, uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,
@@ -47,7 +48,7 @@ DeviceState *riscv_create_aia(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 *IMSIC_HART_SIZE (0 ), +riscv_imsic_create (addr + i * m_imsic_stride, base_hartid + i, true,1 , num_msis); }
hw/riscv/virt.c +1 -0
@@ -1549,6 +1549,7 @@ static void virt_machine_init(MachineState *machine) }else { s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC, s->aia_guests, + IMSIC_HART_SIZE(0), s->num_sources, &s->memmap[VIRT_APLIC_M], &s->memmap[VIRT_APLIC_S],
Signature · 1 line
2.47.3
Re: [PATCH v8 05/12] hw/riscv/aia: Configure stride for the M-mode IMSIC
Quoted 23 lines · Joel Stanley
riscv_create_aia()currently hard-codes the M-IMSIC at one 4 KiB page per hart and gives callers no way to widen it.Add an
m_imsic_strideparameter that supplies the per hart byte stride directly. The virt machine passesIMSIC_HART_SIZE(0)(= 4 KiB), preserving its existing compact layout.The parameter only changes how the slots are spaced, with the rest of each slot reserved. This allows future platforms that have different layouts to control the stride.
Signed-off-by Joel Stanley <[email protected]>--- hw/riscv/aia.h | 1 + hw/riscv/aia.c | 3 ++- hw/riscv/virt.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-)hw/riscv/aia.h +0
-0
hw/riscv/aia.h line 17
Quoted 4 lines
hw/riscv/aia.h +1
-0@@ -14,6 +14,7 @@uint32_t imsic_num_bits (uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + hwaddr m_imsic_stride,
hw/riscv/virt-acpi-build.c:74: uint64_t imsic_socket_addr, imsic_addr;hw/riscv/virt.c:532: uint32_t imsic_max_hart_per_socket, imsic_addr, imsic_size;target/riscv/kvm/kvm-cpu.c:1829: uint64_t socket, base_hart, hart_count, socket_imsic_base, imsic_addr;
Why choose hwaddr for a stride (region size)?
Using uint64_t:
Quoted 36 lines
hw/riscv/aia.h +0
-0uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,hw/riscv/aia.c +2
-1@@ -25,6 +25,7 @@ uint32_t imsic_num_bits(uint32_t count) } DeviceState *riscv_create_aia(bool msimode, int aia_guests, + hwaddr m_imsic_stride, uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,@@ -47,7 +48,7 @@ DeviceState *riscv_create_aia(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 *IMSIC_HART_SIZE (0 ), +riscv_imsic_create (addr + i * m_imsic_stride, base_hartid + i, true,1 , num_msis); }hw/riscv/virt.c +1
-0@@ -1549,6 +1549,7 @@ static void virt_machine_init(MachineState *machine) }else { s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC, s->aia_guests, + IMSIC_HART_SIZE(0), s->num_sources, &s->memmap[VIRT_APLIC_M], &s->memmap[VIRT_APLIC_S],
Re: [PATCH v8 05/12] hw/riscv/aia: Configure stride for the M-mode IMSIC
Quoted 14 lines · Philippe Mathieu-Daudé
hw/riscv/aia.h line 17
Quoted 7 lines
hw/riscv/aia.h +1
-0@@ -14,6 +14,7 @@uint32_t imsic_num_bits (uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + hwaddr m_imsic_stride,
hw/riscv/virt-acpi-build.c:74:uint64_timsic_socket_addr,imsic_addr;hw/riscv/virt.c:532:uint32_timsic_max_hart_per_socket,imsic_addr,imsic_size;target/riscv/kvm/kvm-cpu.c:1829:uint64_tsocket,base_hart,hart_count,socket_imsic_base,imsic_addr;
Quoted 1 line
Why choose hwaddr for a stride (region size)?
Brain fart.
Quoted 2 lines
Using
uint64_t:Reviewed-by Philippe Mathieu-Daudé <[email protected]>
uint32_t would be more than sufficient too, do you agree?
Re: [PATCH v8 05/12] hw/riscv/aia: Configure stride for the M-mode IMSIC
Quoted 15 lines · Joel Stanley
Quoted 14 lines · Philippe Mathieu-Daudé
hw/riscv/aia.h line 17
Quoted 7 lines
hw/riscv/aia.h +1
-0@@ -14,6 +14,7 @@uint32_t imsic_num_bits (uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + hwaddr m_imsic_stride,
hw/riscv/virt-acpi-build.c:74:uint64_timsic_socket_addr,imsic_addr;hw/riscv/virt.c:532:uint32_timsic_max_hart_per_socket,imsic_addr,imsic_size;target/riscv/kvm/kvm-cpu.c:1829:uint64_tsocket,base_hart,hart_count,socket_imsic_base,imsic_addr;
Quoted 8 lines
Quoted 1 line
Why choose hwaddr for a stride (region size)?
Brain fart.
Quoted 2 lines
Using
uint64_t:Reviewed-by Philippe Mathieu-Daudé <[email protected]>
uint32_twould be more than sufficient too, do you agree?
Yes I was thinking the same, 32-bit is sufficient. But maybe we should update the other cases for consistency (as a separate patch)?
Re: [PATCH v8 05/12] hw/riscv/aia: Configure stride for the M-mode IMSIC
In reply to Joel StanleyQuoted 8 lines · Joel Stanley
riscv_create_aia()currently hard-codes the M-IMSIC at one 4 KiB page per hart and gives callers no way to widen it.Add an
m_imsic_strideparameter that supplies the per hart byte stride directly. The virt machine passesIMSIC_HART_SIZE(0)(= 4 KiB), preserving its existing compact layout.
Quoted 5 lines
The parameter only changes how the slots are spaced, with the rest of each slot reserved. This allows future platforms that have different layouts to control the stride.
Signed-off-by Joel Stanley <[email protected]>
With a uint32_t
Alistair
Quoted 55 lines
--- hw/riscv/aia.h | 1 + hw/riscv/aia.c | 3 ++- hw/riscv/virt.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-)hw/riscv/aia.h +1
-0@@ -14,6 +14,7 @@uint32_t imsic_num_bits (uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + hwaddr m_imsic_stride, uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,hw/riscv/aia.c +2
-1@@ -25,6 +25,7 @@ uint32_t imsic_num_bits(uint32_t count) } DeviceState *riscv_create_aia(bool msimode, int aia_guests, + hwaddr m_imsic_stride, uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,@@ -47,7 +48,7 @@ DeviceState *riscv_create_aia(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 *IMSIC_HART_SIZE (0 ), +riscv_imsic_create (addr + i * m_imsic_stride, base_hartid + i, true,1 , num_msis); }hw/riscv/virt.c +1
-1@@ -1549,6 +1549,7 @@ static void virt_machine_init(MachineState *machine) }else { s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC, s->aia_guests, + IMSIC_HART_SIZE(0), s->num_sources, &s->memmap[VIRT_APLIC_M], &s->memmap[VIRT_APLIC_S], --2.47.3
PATCH v8 6/12 target/riscv: tt-ascalon: Enable Zkr extension
In reply to Joel StanleyFrom: Nicholas Piggin <[email protected]>
Ascalon supports Zkr and the SEED CSR.
--- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+)
target/riscv/cpu.c +1 -0
@@ -3090,6 +3090,7 @@ static const TypeInfo riscv_cpu_type_infos[] = { .cfg.ext_zba = true, .cfg.ext_zbb = true, .cfg.ext_zbs = true, + .cfg.ext_zkr = true, .cfg.ext_zkt = true, .cfg.ext_zvbb = true, .cfg.ext_zvbc = true,
Signature · 1 line
2.47.3
PATCH v8 7/12 hw/riscv: Add Tenstorrent Atlantis machine
In reply to Joel StanleyThe Tenstorrent Atlantis platform is a collaboration between Tenstorrent and CoreLab Technology. It is based on the Atlantis SoC, which includes the Ascalon-X CPU and other IP from Tenstorrent and CoreLab Technology. The Tenstorrent Ascalon-X is a high performance 64-bit RVA23 compliant RISC-V CPU.
Add the tt-atlantis machine containing serial console, interrupt controllers, and device tree support.
The Atlantis boot images loaded from include OpenSBI and an initial DTB that is passed to OpenSBI. This is approximated in the model by having QEMU build the device tree rather than load a DTB image directly. Subsequent stages may use the modified DTB provided by OpenSBI or opt to supply their own.
qemu-system-riscv64 -M tt-atlantis -m 512M \ -kernel Image -initrd rootfs.cpio -nographic
--- MAINTAINERS | 10 + docs/system/riscv/tt_atlantis.rst | 41 +++ docs/system/target-riscv.rst | 1 + include/hw/riscv/tt_atlantis.h | 50 +++ hw/riscv/tt_atlantis.c | 593 ++++++++++++++++++++++++++++++ hw/riscv/Kconfig | 10 + hw/riscv/meson.build | 1 + 7 files changed, 706 insertions(+) create mode 100644 docs/system/riscv/tt_atlantis.rst create mode 100644 include/hw/riscv/tt_atlantis.h create mode 100644 hw/riscv/tt_atlantis.c
MAINTAINERS +10 -0
@@ -1784,6 +1784,16 @@ F: hw/*/*sifive*.c F: include/hw/*/*sifive*.h F: tests/functional/test_riscv64_sifive_u.py +Tenstorrent Machines +M: Joel Stanley <[email protected]> +R: Nicholas Piggin <[email protected]> +R: Michael Ellerman <[email protected]> +L: [email protected] +S: Supported +F: docs/system/riscv/tt_*.rst +F: hw/riscv/tt_*.c +F: include/hw/riscv/tt_*.h + AMD Microblaze-V Generic Board M: Sai Pavan Boddu <[email protected]> S: Maintained
docs/system/riscv/tt_atlantis.rst new file +41 -0
41 lines not on this page · raw message
docs/system/target-riscv.rst +1 -0
@@ -71,6 +71,7 @@ undocumented; you can get a complete list by running riscv/mips riscv/shakti-c riscv/sifive_u + riscv/tt_atlantis riscv/virt riscv/xiangshan-kunminghu
include/hw/riscv/tt_atlantis.h new file +50 -0
50 lines not on this page · raw message
hw/riscv/tt_atlantis.c new file +593 -0
593 lines not on this page · raw message
hw/riscv/Kconfig +10 -0
@@ -120,6 +120,16 @@ config SPIKE select RISCV_ACLINT select SIFIVE_PLIC +config TENSTORRENT + bool + default y + depends on RISCV64 + select RISCV_ACLINT + select RISCV_APLIC + select RISCV_IMSIC + select SERIAL_MM + select DEVICE_TREE + config XIANGSHAN_KUNMINGHU bool default y
hw/riscv/meson.build +1 -0
@@ -9,6 +9,7 @@ riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) +riscv_ss.add(when: 'CONFIG_TENSTORRENT', if_true: files('tt_atlantis.c')) riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files( 'riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c', 'riscv-iommu-hpm.c'))
Signature · 1 line
2.47.3
Re: [PATCH v8 07/12] hw/riscv: Add Tenstorrent Atlantis machine
Quoted 577 lines · Joel Stanley
The Tenstorrent Atlantis platform is a collaboration between Tenstorrent and CoreLab Technology. It is based on the Atlantis SoC, which includes the Ascalon-X CPU and other IP from Tenstorrent and CoreLab Technology. The Tenstorrent Ascalon-X is a high performance 64-bit RVA23 compliant RISC-V CPU.
Add the tt-atlantis machine containing serial console, interrupt controllers, and device tree support.
The Atlantis boot images loaded from include OpenSBI and an initial DTB that is passed to OpenSBI. This is approximated in the model by having QEMU build the device tree rather than load a DTB image directly. Subsequent stages may use the modified DTB provided by OpenSBI or opt to supply their own.
qemu-system-riscv64 -M tt-atlantis -m 512M \ -kernel Image -initrd rootfs.cpio -nographicCo-Developed-by Nicholas Piggin <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Chao Liu <[email protected]>Signed-off-by Joel Stanley <[email protected]>--- MAINTAINERS | 10 + docs/system/riscv/tt_atlantis.rst | 41 +++ docs/system/target-riscv.rst | 1 + include/hw/riscv/tt_atlantis.h | 50 +++ hw/riscv/tt_atlantis.c | 593 ++++++++++++++++++++++++++++++ hw/riscv/Kconfig | 10 + hw/riscv/meson.build | 1 + 7 files changed, 706 insertions(+) create mode 100644 docs/system/riscv/tt_atlantis.rst create mode 100644 include/hw/riscv/tt_atlantis.h create mode 100644 hw/riscv/tt_atlantis.cMAINTAINERS +10
-0@@ -1784,6 +1784,16 @@ F: hw/*/*sifive*.c F: include/hw/*/*sifive*.h F: tests/functional/test_riscv64_sifive_u.py +Tenstorrent Machines +M: Joel Stanley <[email protected]> +R: Nicholas Piggin <[email protected]> +R: Michael Ellerman <[email protected]> +L: [email protected] +S: Supported +F: docs/system/riscv/tt_*.rst +F: hw/riscv/tt_*.c +F: include/hw/riscv/tt_*.h + AMD Microblaze-V Generic Board M: Sai Pavan Boddu <[email protected]> S: Maintaineddocs/system/riscv/tt_atlantis.rst new file +41
-0@@ -0,0 +1,41 @@ +Tenstorrent Atlantis (``tt-atlantis``) +====================================== + +The Tenstorrent Atlantis platform is a collaboration between Tenstorrent +and CoreLab Technology. It is based on the Atlantis SoC, which includes +the Ascalon-X CPU and other IP from Tenstorrent and CoreLab Technology. + +The Tenstorrent Ascalon-X is a high performance 64-bit RVA23 compliant +RISC-V CPU. + +tt-atlantis QEMU model features +------------------------------- + +* 8-core Ascalon-X CPU Cluster +* RISC-V compliant Advanced Interrupt Architecture +* 16550A compatible UART + +Known limitations +----------------- + +The QEMU tt-atlantis machine does not yet model every device on the +real platform. Notably: + +* There is no PCI host bridge, so virtio-pci devices cannot be + attached. Boots that need block storage must use ``-initrd`` with + an initramfs. +* The DesignWare UART is modelled with QEMU's ns16550-compatible + ``serial_mm`` device; DesignWare-specific registers beyond that + set return 0. + +Supported software +------------------ + +The Tenstorrent Ascalon CPUs avoid proprietary or non-standard +extensions, so compatibility with existing software is generally +good. The QEMU tt-atlantis machine works with upstream OpenSBI +and Linux with default configurations. + +The development board hardware will require some implementation +specific setup in firmware which is being developed and may +become a requirement or option for the tt-atlantis machine.docs/system/target-riscv.rst +1
-0@@ -71,6 +71,7 @@ undocumented; you can get a complete list by running riscv/mips riscv/shakti-c riscv/sifive_u + riscv/tt_atlantis riscv/virt riscv/xiangshan-kunminghuinclude/hw/riscv/tt_atlantis.h new file +50
-0@@ -0,0 +1,50 @@ +/* +* Tenstorrent Atlantis RISC-V System on Chip +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright 2025 Tenstorrent, Joel Stanley <[email protected]> +*/ + +#ifndef HW_RISCV_TT_ATLANTIS_H +#define HW_RISCV_TT_ATLANTIS_H + +#include "hw/core/boards.h" +#include "hw/core/sysbus.h" +#include "hw/intc/riscv_imsic.h" +#include "hw/riscv/riscv_hart.h" + +#define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis") +OBJECT_DECLARE_SIMPLE_TYPE(TTAtlantisState, TT_ATLANTIS_MACHINE) + +struct TTAtlantisState { +/*< private >*/ +MachineState parent; + +/*< public >*/ +Notifier machine_done; +const MemMapEntry *memmap; + +RISCVHartArrayState soc; +DeviceState *irqchip; + +int fdt_size; +}; + +enum { +TT_ATL_UART1_IRQ =39 , +}; + +enum { +TT_ATL_ACLINT , +TT_ATL_BOOTROM , +TT_ATL_DDR_LO , +TT_ATL_DDR_HI , +TT_ATL_MAPLIC , +TT_ATL_MIMSIC , +TT_ATL_SAPLIC , +TT_ATL_SIMSIC , +TT_ATL_UART1 , +}; + +#endif hw/riscv/tt_atlantis.c new file +398
-0@@ -0,0 +1,593 @@ +/* +* Tenstorrent Atlantis RISC-V System on Chip +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright 2025 Tenstorrent, Joel Stanley <[email protected]> +*/ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "qemu/error-report.h" +#include "qemu/guest-random.h" +#include "qemu/units.h" + +#include "hw/core/boards.h" +#include "hw/core/loader.h" +#include "hw/core/sysbus.h" + +#include "target/riscv/cpu.h" +#include "target/riscv/pmu.h" + +#include "hw/riscv/boot.h" +#include "hw/riscv/machines-qom.h" +#include "hw/riscv/riscv_hart.h" + +#include "hw/char/serial-mm.h" +#include "hw/intc/riscv_aclint.h" +#include "hw/misc/unimp.h" + +#include "system/system.h" +#include "system/device_tree.h" + +#include "hw/riscv/tt_atlantis.h" + +#include "aia.h" + +#define TT_IRQCHIP_NUM_MSIS 255 +#define TT_IRQCHIP_NUM_SOURCES 128 +#define TT_IRQCHIP_NUM_PRIO_BITS 3 +#define TT_IRQCHIP_GUESTS 63/* aia_guests, gives guest_index_bits=6 */ +#define TT_IRQCHIP_MIMSIC_STRIDE 0x40000 + +#define TT_ACLINT_MTIME_SIZE 0x8050 +#define TT_ACLINT_MTIME 0x0 +#define TT_ACLINT_MTIMECMP 0x8000 +#define TT_ACLINT_TIMEBASE_FREQ 1000000000 + +static const MemMapEntry tt_atlantis_memmap[] = { +/* Keep sorted with :'<,'>!sort -g -k 4 */ + [TT_ATL_DDR_LO ] = {0x00000000 ,0x80000000 }, + [TT_ATL_BOOTROM ] = {0x80000000 ,0x2000 }, + [TT_ATL_MIMSIC ] = {0xa0000000 ,0x200000 }, + [TT_ATL_ACLINT ] = {0xa2180000 ,0x10000 }, + [TT_ATL_SIMSIC ] = {0xa4000000 ,0x200000 }, + [TT_ATL_MAPLIC ] = {0xcc000000 ,0x4000000 }, + [TT_ATL_UART1 ] = {0xd4110000 ,0x10000 }, + [TT_ATL_SAPLIC ] = {0xe8000000 ,0x4000000 }, + [TT_ATL_DDR_HI ] = {0x100000000 ,0x1000000000 }, +}; + +static uint32_t next_phandle (void ) +{ +static uint32_t phandle =1 ; +return phandle++; +} + +static void create_fdt_cpus (TTAtlantisState *s,uint32_t *intc_phandles) +{ +uint32_t cpu_phandle; +void *fdt =MACHINE (s)->fdt; + +for (int cpu = s->soc.num_harts -1 ; cpu >=0 ; cpu--) { +RISCVCPU *cpu_ptr = &s->soc.harts[cpu]; + g_autofree char *cpu_name = NULL; + g_autofree char *intc_name = NULL; + + cpu_phandle =next_phandle (); + + cpu_name =g_strdup_printf ("/cpus/cpu@%d" , s->soc.hartid_base + cpu); +qemu_fdt_add_subnode (fdt, cpu_name); + +qemu_fdt_setprop_string (fdt, cpu_name,"mmu-type" ,"riscv,sv57" ); + +riscv_isa_write_fdt (cpu_ptr, fdt, cpu_name); + +qemu_fdt_setprop_cell (fdt, cpu_name,"riscv,cbom-block-size" , + cpu_ptr->cfg.cbom_blocksize); + +qemu_fdt_setprop_cell (fdt, cpu_name,"riscv,cboz-block-size" , + cpu_ptr->cfg.cboz_blocksize); + +qemu_fdt_setprop_cell (fdt, cpu_name,"riscv,cbop-block-size" , + cpu_ptr->cfg.cbop_blocksize); + +qemu_fdt_setprop_string (fdt, cpu_name,"compatible" ,"riscv" ); +qemu_fdt_setprop_string (fdt, cpu_name,"status" ,"okay" ); +qemu_fdt_setprop_cell (fdt, cpu_name,"reg" , s->soc.hartid_base + cpu); +qemu_fdt_setprop_string (fdt, cpu_name,"device_type" ,"cpu" ); +qemu_fdt_setprop_cell (fdt, cpu_name,"phandle" , cpu_phandle); + + intc_phandles[cpu] =next_phandle (); + + intc_name =g_strdup_printf ("%s/interrupt-controller" , cpu_name); +qemu_fdt_add_subnode (fdt, intc_name); +qemu_fdt_setprop_cell (fdt, intc_name,"phandle" , + intc_phandles[cpu]); +qemu_fdt_setprop_string (fdt, intc_name,"compatible" , +"riscv,cpu-intc" ); +qemu_fdt_setprop (fdt, intc_name,"interrupt-controller" ,NULL ,0 ); +qemu_fdt_setprop_cell (fdt, intc_name,"#interrupt-cells" ,1 ); + } +} + +static void create_fdt_memory_node (TTAtlantisState *s, +hwaddr addr,hwaddr size) +{ +void *fdt =MACHINE (s)->fdt; + g_autofree char *name = g_strdup_printf("/memory@%"HWADDR_PRIX, addr); +qemu_fdt_add_subnode (fdt, name); +qemu_fdt_setprop_sized_cells (fdt, name,"reg" ,2 , addr,2 , size); +qemu_fdt_setprop_string (fdt, name,"device_type" ,"memory" ); +} + +static void create_fdt_memory (TTAtlantisState *s) +{ +hwaddr size_lo =MACHINE (s)->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; + } + +create_fdt_memory_node (s, s->memmap[TT_ATL_DDR_LO ].base, size_lo); +if (size_hi) { +/* +* The first part of the HI address is aliased at the LO address +* so do not include that as usable memory. Is there any way +* (or good reason) to describe that aliasing 2GB with DT? +*/ +create_fdt_memory_node (s, s->memmap[TT_ATL_DDR_HI ].base + size_lo, + size_hi); + } +} + +static void create_fdt_aclint (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; +hwaddr addr; + + aclint_mtimer_cells =g_new0 (uint32_t, s->soc.num_harts *2 ); + +for (int cpu =0 ; cpu < s->soc.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 ; + + addr = s->memmap[TT_ATL_ACLINT ].base; + + name =g_strdup_printf ("/soc/mtimer@%" HWADDR_PRIX , addr); +qemu_fdt_add_subnode (fdt, name); +qemu_fdt_setprop_string (fdt, name,"compatible" ,"riscv,aclint-mtimer" ); +qemu_fdt_setprop_sized_cells (fdt, name,"reg" , +2 , addr +TT_ACLINT_MTIME , +2 ,0x1000 , +2 , addr +TT_ACLINT_MTIMECMP , +2 ,0x1000 ); +qemu_fdt_setprop (fdt, name,"interrupts-extended" , + aclint_mtimer_cells, aclint_cells_size); +} + +static void create_fdt_one_imsic (void *fdt,const MemMapEntry *mem,int cpus, +uint32_t *intc_phandles,uint32_t msi_phandle, +int irq_line,uint32_t imsic_guest_bits) +{ + g_autofree char *name = NULL; + g_autofree uint32_t *imsic_cells = g_new0(uint32_t, cpus * 2); + +for (int cpu =0 ; cpu < cpus; cpu++) { + imsic_cells[cpu *2 +0 ] =cpu_to_be32 (intc_phandles[cpu]); + imsic_cells[cpu *2 +1 ] =cpu_to_be32 (irq_line); + } + + name =g_strdup_printf ("/soc/interrupt-controller@%" HWADDR_PRIX , mem->base); +qemu_fdt_add_subnode (fdt, name); +qemu_fdt_setprop_string (fdt, name,"compatible" ,"riscv,imsics" ); + +qemu_fdt_setprop_cell (fdt, name,"#interrupt-cells" ,0 ); +qemu_fdt_setprop (fdt, name,"interrupt-controller" ,NULL ,0 ); +qemu_fdt_setprop (fdt, name,"msi-controller" ,NULL ,0 ); +qemu_fdt_setprop (fdt, name,"interrupts-extended" , + imsic_cells,sizeof (uint32_t ) * cpus *2 ); +qemu_fdt_setprop_sized_cells (fdt, name,"reg" ,2 , mem->base,2 , mem->size); +qemu_fdt_setprop_cell (fdt, name,"riscv,num-ids" ,TT_IRQCHIP_NUM_MSIS ); + +if (imsic_guest_bits) { +qemu_fdt_setprop_cell (fdt, name,"riscv,guest-index-bits" , + imsic_guest_bits); + } +qemu_fdt_setprop_cell (fdt, name,"phandle" , msi_phandle); +} + +static void create_fdt_one_aplic (void *fdt, +const MemMapEntry *mem, +uint32_t msi_phandle, +uint32_t *intc_phandles, +uint32_t aplic_phandle, +uint32_t aplic_child_phandle, +int irq_line,int num_harts) +{ + g_autofree char *name = +g_strdup_printf ("/soc/interrupt-controller@%" HWADDR_PRIX , mem->base); + g_autofree uint32_t *aplic_cells = g_new0(uint32_t, num_harts * 2); + +for (int cpu =0 ; cpu < num_harts; cpu++) { + aplic_cells[cpu *2 +0 ] =cpu_to_be32 (intc_phandles[cpu]); + aplic_cells[cpu *2 +1 ] =cpu_to_be32 (irq_line); + } + +qemu_fdt_add_subnode (fdt, name); +qemu_fdt_setprop_string (fdt, name,"compatible" ,"riscv,aplic" ); +qemu_fdt_setprop_cell (fdt, name,"#address-cells" ,0 ); +qemu_fdt_setprop_cell (fdt, name,"#interrupt-cells" ,2 ); +qemu_fdt_setprop (fdt, name,"interrupt-controller" ,NULL ,0 ); + +qemu_fdt_setprop (fdt, name,"interrupts-extended" , + aplic_cells, num_harts *sizeof (uint32_t ) *2 ); +qemu_fdt_setprop_cell (fdt, name,"msi-parent" , msi_phandle); + +qemu_fdt_setprop_sized_cells (fdt, name,"reg" ,2 , mem->base,2 , mem->size); +qemu_fdt_setprop_cell (fdt, name,"riscv,num-sources" , +TT_IRQCHIP_NUM_SOURCES ); + +if (aplic_child_phandle) { +qemu_fdt_setprop_cell (fdt, name,"riscv,children" , + aplic_child_phandle); +qemu_fdt_setprop_cells (fdt, name,"riscv,delegation" , + aplic_child_phandle,1 ,TT_IRQCHIP_NUM_SOURCES ); + } + +qemu_fdt_setprop_cell (fdt, name,"phandle" , aplic_phandle); +} + +static void create_fdt_pmu (TTAtlantisState *s) +{ +char pmu_name[] ="/pmu" ; +void *fdt =MACHINE (s)->fdt; +RISCVCPU *hart = &s->soc.harts[0 ]; + +qemu_fdt_add_subnode (fdt, pmu_name); +qemu_fdt_setprop_string (fdt, pmu_name,"compatible" ,"riscv,pmu" ); +riscv_pmu_generate_fdt_node (fdt, hart->pmu_avail_ctrs, pmu_name); +} + +static void create_fdt_cpu (TTAtlantisState *s,const MemMapEntry *memmap, +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 = NULL; + +qemu_fdt_add_subnode (fdt,"/cpus" ); +qemu_fdt_setprop_cell (fdt,"/cpus" ,"timebase-frequency" , +TT_ACLINT_TIMEBASE_FREQ ); +qemu_fdt_setprop_cell (fdt,"/cpus" ,"#size-cells" ,0x0 ); +qemu_fdt_setprop_cell (fdt,"/cpus" ,"#address-cells" ,0x1 ); + + intc_phandles =g_new0 (uint32_t, ms->smp.cpus); + +create_fdt_cpus (s, intc_phandles); + +create_fdt_memory (s); + +create_fdt_aclint (s, intc_phandles); + +uint32_t imsic_guest_bits =imsic_num_bits (TT_IRQCHIP_GUESTS +1 ); + +/* M-level IMSIC node */ +uint32_t msi_m_phandle =next_phandle (); +create_fdt_one_imsic (fdt, &s->memmap[TT_ATL_MIMSIC ], ms->smp.cpus, + intc_phandles, msi_m_phandle, +IRQ_M_EXT , imsic_guest_bits); + +/* S-level IMSIC node */ +create_fdt_one_imsic (fdt, &s->memmap[TT_ATL_SIMSIC ], ms->smp.cpus, + intc_phandles, imsic_s_phandle, +IRQ_S_EXT , imsic_guest_bits); + +uint32_t aplic_m_phandle =next_phandle (); + +/* M-level APLIC node */ +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); + +/* 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); +} + +static void create_fdt_uart (void *fdt,const MemMapEntry *mem,int irq, +int irqchip_phandle) +{ + g_autofree char *name = g_strdup_printf("/soc/serial@%"HWADDR_PRIX, + mem->base); + +qemu_fdt_add_subnode (fdt, name); +qemu_fdt_setprop_string (fdt, name,"compatible" ,"ns16550a" ); +qemu_fdt_setprop_sized_cells (fdt, name,"reg" ,2 , mem->base,2 , mem->size); +qemu_fdt_setprop_cell (fdt, name,"reg-shift" ,2 ); +qemu_fdt_setprop_cell (fdt, name,"reg-io-width" ,4 ); +qemu_fdt_setprop_cell (fdt, name,"clock-frequency" ,3686400 ); +qemu_fdt_setprop_cell (fdt, name,"interrupt-parent" , irqchip_phandle); +qemu_fdt_setprop_cells (fdt, name,"interrupts" , irq,0x4 ); + +qemu_fdt_setprop_string (fdt,"/chosen" ,"stdout-path" , name); +qemu_fdt_setprop_string (fdt,"/aliases" ,"serial0" , name); +} + +static void create_fdt_rng (void *fdt) +{ +uint8_t rng_seed[32 ]; + +qemu_guest_getrandom_nofail (rng_seed,sizeof (rng_seed)); +qemu_fdt_setprop (fdt,"/chosen" ,"rng-seed" , rng_seed,sizeof (rng_seed)); +} + +static void finalize_fdt (TTAtlantisState *s) +{ +uint32_t aplic_s_phandle =next_phandle (); +uint32_t imsic_s_phandle =next_phandle (); +void *fdt =MACHINE (s)->fdt; + +create_fdt_cpu (s, s->memmap, aplic_s_phandle, imsic_s_phandle); + +/* +* We want to do this, but the Linux aplic driver was broken before v6.16 +* +* qemu_fdt_setprop_cell(MACHINE(s)->fdt, "/soc", "interrupt-parent", +* aplic_s_phandle); +*/ + +create_fdt_uart (fdt, &s->memmap[TT_ATL_UART1 ],TT_ATL_UART1_IRQ , + aplic_s_phandle); +} + +static void create_fdt (TTAtlantisState *s) +{ +MachineState *ms =MACHINE (s); +void *fdt; + + fdt =create_device_tree (&s->fdt_size); +if (!fdt) { +error_report ("create_device_tree() failed" ); +exit (1 ); + } + ms->fdt = fdt; + +qemu_fdt_setprop_string (fdt,"/" ,"model" , +"Tenstorrent Atlantis RISC-V Machine" ); +qemu_fdt_setprop_string (fdt,"/" ,"compatible" ,"tenstorrent,atlantis" ); +qemu_fdt_setprop_cell (fdt,"/" ,"#size-cells" ,0x2 ); +qemu_fdt_setprop_cell (fdt,"/" ,"#address-cells" ,0x2 ); + +qemu_fdt_add_subnode (fdt,"/soc" ); +qemu_fdt_setprop (fdt,"/soc" ,"ranges" ,NULL ,0 ); +qemu_fdt_setprop_string (fdt,"/soc" ,"compatible" ,"simple-bus" ); +qemu_fdt_setprop_cell (fdt,"/soc" ,"#size-cells" ,0x2 ); +qemu_fdt_setprop_cell (fdt,"/soc" ,"#address-cells" ,0x2 ); + +qemu_fdt_add_subnode (fdt,"/chosen" ); + +create_fdt_rng (fdt); + +qemu_fdt_add_subnode (fdt,"/aliases" ); + +create_fdt_pmu (s); +} + +static void load_fdt (TTAtlantisState *s) +{ +MachineState *ms =MACHINE (s); +char **node_path; +Error *err =NULL ; + + ms->fdt =load_device_tree (ms->dtb, &s->fdt_size); +if (!ms->fdt) { +error_report ("load_device_tree() failed" ); +exit (1 ); + }
hw/riscv/tt_atlantis.c line 408
Quoted 10 lines
hw/riscv/tt_atlantis.c new file +10
-0+ +qemu_fdt_add_path (ms->fdt,"/chosen" ); + +/* Clear memory nodes and update with the specified RAM size */ + node_path =qemu_fdt_node_unit_path (ms->fdt,"memory" , &err); +if (err) { +warn_report_err (err); + }else { +for (int i =0 ; node_path[i]; i++) { +qemu_fdt_nop_node (ms->fdt, node_path[i]);
Should we print a warning here to the user that we are doing this? I would be confused (and annoyed) if QEMU deleted my memory regions and I didn't know
Quoted 15 lines
hw/riscv/tt_atlantis.c new file +15
-0+ } +g_strfreev (node_path); + } + +create_fdt_memory (s); +} + +static void tt_atlantis_machine_done (Notifier *notifier,void *data) +{ +TTAtlantisState *s =container_of (notifier, TTAtlantisState, machine_done); +MachineState *machine =MACHINE (s); +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);
hw/riscv/tt_atlantis.c line 433
Quoted 10 lines
hw/riscv/tt_atlantis.c new file +10
-0+uint64_t fdt_load_addr; +uint64_t kernel_entry; +RISCVBootInfo boot_info; + +/* +* A user provided dtb must include everything, including +* dynamic sysbus devices. Our FDT needs to be finalized. +*/ +if (machine->dtb ==NULL ) { +finalize_fdt (s);
Was expecting a finalise here :)
Quoted 75 lines
hw/riscv/tt_atlantis.c new file +75
-0+ } + + mem_size = machine->ram_size; +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, + s->memmap[TT_ATL_DDR_LO ].base, + mem_size); + + firmware_end_addr =riscv_find_and_load_firmware (machine, &boot_info, + firmware_name, + &start_addr,NULL ); + + kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, + firmware_end_addr); +if (machine->kernel_filename) { +riscv_load_kernel (machine, &boot_info, kernel_start_addr, + true,NULL ); + } + kernel_entry = boot_info.image_low_addr; + + fdt_load_addr =riscv_compute_fdt_addr (s->memmap[TT_ATL_DDR_LO ].base, + s->memmap[TT_ATL_DDR_LO ].size, + machine, &boot_info); +riscv_load_fdt (fdt_load_addr, machine->fdt); + +/* load the reset vector */ +riscv_setup_rom_reset_vec (machine, &s->soc, start_addr, + s->memmap[TT_ATL_BOOTROM ].base, + s->memmap[TT_ATL_BOOTROM ].size, + kernel_entry, + fdt_load_addr); +} + +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, hi_ram_size; +int hart_count = machine->smp.cpus; + + s->memmap = tt_atlantis_memmap; + +object_initialize_child (OBJECT (machine),"soc" , &s->soc, +TYPE_RISCV_HART_ARRAY ); +object_property_set_str (OBJECT (&s->soc),"cpu-type" , machine->cpu_type, + &error_abort); +object_property_set_int (OBJECT (&s->soc),"hartid-base" ,0 , + &error_abort); +object_property_set_int (OBJECT (&s->soc),"num-harts" , hart_count, + &error_abort); +object_property_set_int (OBJECT (&s->soc),"resetvec" , + s->memmap[TT_ATL_BOOTROM ].base, + &error_abort); +sysbus_realize (SYS_BUS_DEVICE (&s->soc), &error_fatal); + + s->irqchip =riscv_create_aia (true,TT_IRQCHIP_GUESTS , +TT_IRQCHIP_MIMSIC_STRIDE , +TT_IRQCHIP_NUM_SOURCES , + &s->memmap[TT_ATL_MAPLIC ], + &s->memmap[TT_ATL_SAPLIC ], + &s->memmap[TT_ATL_MIMSIC ], + &s->memmap[TT_ATL_SIMSIC ], +0 ,0 , hart_count, +TT_IRQCHIP_NUM_MSIS , +TT_IRQCHIP_NUM_PRIO_BITS ); + + riscv_aclint_mtimer_create(s->memmap[TT_ATL_ACLINT].base, + TT_ACLINT_MTIME_SIZE, + 0, hart_count,
hw/riscv/tt_atlantis.c line 518
Quoted 10 lines
hw/riscv/tt_atlantis.c new file +10
-0+TT_ACLINT_MTIMECMP , +TT_ACLINT_MTIME , + TT_ACLINT_TIMEBASE_FREQ, true); + +/* DDR */ + +/* The high address covers all of RAM, the low address just the first 2GB */ + lo_ram_size = s->memmap[TT_ATL_DDR_LO ].size; + hi_ram_size = s->memmap[TT_ATL_DDR_HI ].size; +if (machine->ram_size > hi_ram_size) {
What if machine->ram_size is less then s->memmap[TT_ATL_DDR_HI].size? You will still allocate s->memmap[TT_ATL_DDR_HI].size instead of what the user asked for. You then report what the user asked for in the DT, so there is a bunch of wasted memory.
Memory is expensive these days, we can't waste it
Also, if the user asks for 2GB or less, you shouldn't create ram.high at all
Otherwise looks good
Alistair
Quoted 112 lines
hw/riscv/tt_atlantis.c new file +75
-0+char *sz =size_to_str (hi_ram_size); +error_report ("RAM size is too large, maximum is %s" , sz); +g_free (sz); +exit (EXIT_FAILURE ); + } + +memory_region_init_alias (ram_lo,OBJECT (machine),"ram.low" , machine->ram, +0 , lo_ram_size); +memory_region_init_alias (ram_hi,OBJECT (machine),"ram.high" , machine->ram, +0 , hi_ram_size); +memory_region_add_subregion (system_memory, + s->memmap[TT_ATL_DDR_LO ].base, ram_lo); +memory_region_add_subregion (system_memory, + s->memmap[TT_ATL_DDR_HI ].base, ram_hi); + +/* 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, + bootrom); + +/* UART1, the soc console (UART0 is for the boot microcontroller) */ +serial_mm_init (system_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 ); +/* +* Atlantis contains a DesignWare uart while the QEMU machine +* uses the serial_mm model with the base ns16550 register set. +* Linux's dw driver writes outside of serial_mm's 0x20 sized +* mapping and faults. +* +* 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); + +/* Load or create device tree */ +if (machine->dtb) { +load_fdt (s); + }else { +create_fdt (s); + } + + s->machine_done.notify = tt_atlantis_machine_done; +qemu_add_machine_init_done_notifier (&s->machine_done); +} + +static void tt_atlantis_machine_class_init (ObjectClass *oc,const void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->desc ="Tenstorrent Atlantis RISC-V SoC" ; + mc->init = tt_atlantis_machine_init; + mc->max_cpus =8 ; + mc->default_cpus =8 ; + mc->default_ram_size =4 * GiB; + mc->default_cpu_type =TYPE_RISCV_CPU_TT_ASCALON ; + mc->block_default_type =IF_VIRTIO ; + mc->no_cdrom =1 ; + mc->default_ram_id ="tt_atlantis.ram" ; +} + +static const TypeInfo tt_atlantis_types[] = { + { + .name =MACHINE_TYPE_NAME ("tt-atlantis" ), + .parent =TYPE_MACHINE , + .class_init = tt_atlantis_machine_class_init, + .instance_size =sizeof (TTAtlantisState), + .interfaces = riscv64_machine_interfaces, + }, +}; + +DEFINE_TYPES (tt_atlantis_types)hw/riscv/Kconfig +10
-0@@ -120,6 +120,16 @@ config SPIKE select RISCV_ACLINT select SIFIVE_PLIC +config TENSTORRENT + bool + default y + depends on RISCV64 + select RISCV_ACLINT + select RISCV_APLIC + select RISCV_IMSIC + select SERIAL_MM + select DEVICE_TREE + config XIANGSHAN_KUNMINGHU bool default yhw/riscv/meson.build +1
-1@@ -9,6 +9,7 @@ riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) +riscv_ss.add(when: 'CONFIG_TENSTORRENT', if_true: files('tt_atlantis.c')) riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files( 'riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c', 'riscv-iommu-hpm.c')) --2.47.3
Re: [PATCH v8 07/12] hw/riscv: Add Tenstorrent Atlantis machine
Quoted 20 lines · Alistair Francis
Quoted 17 lines · Joel Stanley
hw/riscv/tt_atlantis.c new file +17
-0+static void load_fdt (TTAtlantisState *s) +{ +MachineState *ms =MACHINE (s); +char **node_path; +Error *err =NULL ; + + ms->fdt =load_device_tree (ms->dtb, &s->fdt_size); +if (!ms->fdt) { +error_report ("load_device_tree() failed" ); +exit (1 ); + } + +qemu_fdt_add_path (ms->fdt,"/chosen" ); + +/* Clear memory nodes and update with the specified RAM size */ + node_path =qemu_fdt_node_unit_path (ms->fdt,"memory" , &err); +if (err) {
Quoted 8 lines
hw/riscv/tt_atlantis.c line 408
Quoted 4 lines
hw/riscv/tt_atlantis.c new file +4
-0+warn_report_err (err); + }else { +for (int i =0 ; node_path[i]; i++) { +qemu_fdt_nop_node (ms->fdt, node_path[i]);Should we print a warning here to the user that we are doing this? I would be confused (and annoyed) if QEMU deleted my memory regions and I didn't know
The code is the same for the arm machines; they silently update the device tree when provided one. I agree with you though, I will add a warning.
I added this as in testing the device tree was larger than what the machine had, which Linux happily tries to use and crashes during boot. I can see the argument for not touching the device tree at all but on balance I decided helping the user out is the right thing to do. If users complain I'm happy to change it.
Quoted 12 lines
Quoted 12 lines
hw/riscv/tt_atlantis.c new file +12
-0+static void tt_atlantis_machine_done (Notifier *notifier,void *data) +{ +TTAtlantisState *s =container_of (notifier, TTAtlantisState, machine_done); +MachineState *machine =MACHINE (s); +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); +uint64_t fdt_load_addr; +uint64_t kernel_entry; +RISCVBootInfo boot_info; +
Quoted 8 lines
hw/riscv/tt_atlantis.c line 433
Quoted 6 lines
hw/riscv/tt_atlantis.c new file +6
-0+/* +* A user provided dtb must include everything, including +* dynamic sysbus devices. Our FDT needs to be finalized. +*/ +if (machine->dtb ==NULL ) { +finalize_fdt (s);Was expecting a finalise here :)
Desensitized.
Quoted 7 lines
hw/riscv/tt_atlantis.c line 518
Quoted 6 lines
hw/riscv/tt_atlantis.c new file +6
-0+/* DDR */ + +/* The high address covers all of RAM, the low address just the first 2GB */ + lo_ram_size = s->memmap[TT_ATL_DDR_LO ].size; + hi_ram_size = s->memmap[TT_ATL_DDR_HI ].size; +if (machine->ram_size > hi_ram_size) {
Quoted 8 lines
What if
machine->ram_sizeis less then s->memmap[TT_ATL_DDR_HI].size? You will still allocate s->memmap[TT_ATL_DDR_HI].size instead of what the user asked for. You then report what the user asked for in the DT, so there is a bunch of wasted memory.Memory is expensive these days, we can't waste it
Also, if the user asks for 2GB or less, you shouldn't create ram.high at all
Good catch. There's an even better bug; ram.high and ram.low are aliases into the machine ram region and they are always sized to their default maximum, regardless of the machine ram size.
address-space: memory
0000000000000000-ffffffffffffffff (prio 0, container): system
0000000000000000-000000007fffffff (prio 0, ram): alias ram.low
@tt_atlantis.ram 0000000000000000-000000007fffffff
0000000100000000-00000010ffffffff (prio 0, ram): alias ram.high@tt_atlantis.ram 0000000000000000-0000000fffffffff
memory-region: tt_atlantis.ram
0000000000000000-00000000ffffffff (prio 0, ram): tt_atlantis.ram
They should be sized to the configured size.
The device tree is okay because it sets the region based on the configured ram size, and Linux politely doesn't write outside of that.
In hardware the high region is where the ram lives and low is an alias of the first 2GB. I'll fix up the modelling to match, and set the sizes appropriately.
Quoted 1 line
Otherwise looks good
Thanks for the review.
Cheers,
Joel
PATCH v8 8/12 hw/riscv/atlantis: Provide a simple halting payload
In reply to Joel StanleyFrom: Nicholas Piggin <[email protected]>
OpenSBI hangs before any console output if the domain init code sees the next stage is not in an executable region.
If no kernel payload is provided to QEMU, the next stage address is NULL, and the riscv virt machine memory map ends up covering the 0 address with the catch all S-mode RWX region and so OpenSBI prints console messages and does not hang until the next stage boot.
The Tenstorrent Atlantis machine address map has RAM starting at 0 and it loads OpenSBI there, so it is M-mode and not accessible by S-mode, tripping the early check and hang.
Add a helper to set up a simple payload that gets OpenSBI messages to console, until OpenSBI can be fixed.
--- hw/riscv/tt_atlantis.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
hw/riscv/tt_atlantis.c +27 -0
@@ -413,6 +413,30 @@ static void load_fdt(TTAtlantisState *s)create_fdt_memory (s); } +/* +* This works around a problem with OpenSBI hanging with no console output if +* no payload is provided. By chance, machines with memory at 0x80000000 do get +* output, but Atlantis memory begins at 0x0 which takes a different OpenSBI +* error path. +* +* This can be removed when OpenSBI is fixed in QEMU. +*/ +static void tt_atlantis_setup_halting_payload_opensbi_fixup ( +RISCVBootInfo *info,hwaddr addr) +{ +/* Store the payload vector in little_endian byte order */ +static const uint32_t payload_vec[] = { +const_le32 (0x10500073 ),/* 1: wfi */ +const_le32 (0xffdff06f ),/* j 1b */ + }; +rom_add_blob_fixed_as ("mrom.payload" , payload_vec,sizeof (payload_vec), + addr, &address_space_memory); + + info->kernel_size =sizeof (payload_vec); + info->image_low_addr = addr; + info->image_high_addr = info->image_low_addr + info->kernel_size; +} +static void tt_atlantis_machine_done (Notifier *notifier,void *data) {TTAtlantisState *s =container_of (notifier, TTAtlantisState, machine_done);
@@ -450,6 +474,9 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data)if (machine->kernel_filename) {riscv_load_kernel (machine, &boot_info, kernel_start_addr, true,NULL ); + }else { +tt_atlantis_setup_halting_payload_opensbi_fixup (&boot_info, + kernel_start_addr); } kernel_entry = boot_info.image_low_addr;
Signature · 1 line
2.47.3
Re: [PATCH v8 08/12] hw/riscv/atlantis: Provide a simple halting payload
Quoted 11 lines · Joel Stanley
From: Nicholas Piggin <[email protected]>
OpenSBI hangs before any console output if the domain init code sees the next stage is not in an executable region.
If no kernel payload is provided to QEMU, the next stage address is NULL, and the riscv virt machine memory map ends up covering the 0 address with the catch all S-mode RWX region and so OpenSBI prints console messages and does not hang until the next stage boot.
Quoted 6 lines
The Tenstorrent Atlantis machine address map has RAM starting at 0 and it loads OpenSBI there, so it is M-mode and not accessible by S-mode, tripping the early check and hang.
Add a helper to set up a simple payload that gets OpenSBI messages to console, until OpenSBI can be fixed.
I still don't like this. What is the status of the OpenSBI fix? Can we link to the upstream patch? I'm worried we are going to be stuck with this hack forever.
Alistair
Quoted 58 lines
Signed-off-by Nicholas Piggin <[email protected]>Reviewed-by Daniel Henrique Barboza <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Joel Stanley <[email protected]>--- hw/riscv/tt_atlantis.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)hw/riscv/tt_atlantis.c +27
-1@@ -413,6 +413,30 @@ static void load_fdt(TTAtlantisState *s)create_fdt_memory (s); } +/* +* This works around a problem with OpenSBI hanging with no console output if +* no payload is provided. By chance, machines with memory at 0x80000000 do get +* output, but Atlantis memory begins at 0x0 which takes a different OpenSBI +* error path. +* +* This can be removed when OpenSBI is fixed in QEMU. +*/ +static void tt_atlantis_setup_halting_payload_opensbi_fixup ( +RISCVBootInfo *info,hwaddr addr) +{ +/* Store the payload vector in little_endian byte order */ +static const uint32_t payload_vec[] = { +const_le32 (0x10500073 ),/* 1: wfi */ +const_le32 (0xffdff06f ),/* j 1b */ + }; +rom_add_blob_fixed_as ("mrom.payload" , payload_vec,sizeof (payload_vec), + addr, &address_space_memory); + + info->kernel_size =sizeof (payload_vec); + info->image_low_addr = addr; + info->image_high_addr = info->image_low_addr + info->kernel_size; +} +static void tt_atlantis_machine_done (Notifier *notifier,void *data) {TTAtlantisState *s =container_of (notifier, TTAtlantisState, machine_done);@@ -450,6 +474,9 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data)if (machine->kernel_filename) {riscv_load_kernel (machine, &boot_info, kernel_start_addr, true,NULL ); + }else { +tt_atlantis_setup_halting_payload_opensbi_fixup (&boot_info, + kernel_start_addr); } kernel_entry = boot_info.image_low_addr; --2.47.3
PATCH v8 9/12 tests/functional/riscv64: Add tt-atlantis tests
In reply to Joel StanleyFrom: Nicholas Piggin <[email protected]>
Add OpenSBI and Linux boot tests for the tt-atlantis machine. Based on tests/functional/riscv64/test_sifive_u.py.
--- MAINTAINERS | 1 + tests/functional/riscv64/meson.build | 1 + tests/functional/riscv64/test_opensbi.py | 4 ++ tests/functional/riscv64/test_tt_atlantis.py | 57 ++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100755 tests/functional/riscv64/test_tt_atlantis.py
MAINTAINERS +1 -0
@@ -1793,6 +1793,7 @@ S: Supported F: docs/system/riscv/tt_*.rst F: hw/riscv/tt_*.c F: include/hw/riscv/tt_*.h +F: tests/functional/riscv64/test_tt_*.py AMD Microblaze-V Generic Board M: Sai Pavan Boddu <[email protected]>
tests/functional/riscv64/meson.build +1 -0
@@ -13,5 +13,6 @@ tests_riscv64_system_quick = [ tests_riscv64_system_thorough = [ 'boston', 'sifive_u', + 'tt_atlantis', 'tuxrun', ]
tests/functional/riscv64/test_opensbi.py +4 -0
@@ -28,6 +28,10 @@ def test_riscv_sifive_u(self): self.set_machine('sifive_u') self.boot_opensbi() + def test_riscv_tt_atlantis(self): + self.set_machine('tt-atlantis') + self.boot_opensbi() + def test_riscv_virt(self): self.set_machine('virt') self.boot_opensbi()
tests/functional/riscv64/test_tt_atlantis.py new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.47.3
Re: [PATCH v8 09/12] tests/functional/riscv64: Add tt-atlantis tests
Quoted 9 lines · Joel Stanley
From: Nicholas Piggin <[email protected]>
Add OpenSBI and Linux boot tests for the tt-atlantis machine. Based on
tests/functional/riscv64/test_sifive_u.py.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 113 lines
--- MAINTAINERS | 1 + tests/functional/riscv64/meson.build | 1 + tests/functional/riscv64/test_opensbi.py | 4 ++ tests/functional/riscv64/test_tt_atlantis.py | 57 ++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100755 tests/functional/riscv64/test_tt_atlantis.pyMAINTAINERS +1
-0@@ -1793,6 +1793,7 @@ S: Supported F: docs/system/riscv/tt_*.rst F: hw/riscv/tt_*.c F: include/hw/riscv/tt_*.h +F: tests/functional/riscv64/test_tt_*.py AMD Microblaze-V Generic Board M: Sai Pavan Boddu <[email protected]>tests/functional/riscv64/meson.build +1
-0@@ -13,5 +13,6 @@ tests_riscv64_system_quick = [ tests_riscv64_system_thorough = [ 'boston', 'sifive_u', + 'tt_atlantis', 'tuxrun', ]tests/functional/riscv64/test_opensbi.py +4
-0@@ -28,6 +28,10 @@ def test_riscv_sifive_u(self): self.set_machine('sifive_u') self.boot_opensbi() + def test_riscv_tt_atlantis(self): + self.set_machine('tt-atlantis') + self.boot_opensbi() + def test_riscv_virt(self): self.set_machine('virt') self.boot_opensbi()tests/functional/riscv64/test_tt_atlantis.py new file +57
-1@@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# +# Functional test that boots a Linux kernel on a Tenstorrent Atlantis machine +# and checks the console +# +# Copyright (c) Linaro Ltd. +# Copyright 2026 Tenstorrent +# +# SPDX-License-Identifier: GPL-2.0-or-later + +from qemu_test import Asset, LinuxKernelTest + + +class TTAtlantis(LinuxKernelTest): + + ASSET_KERNEL = Asset( + 'https://storage.tuxboot.com/kernels/6.11.9/riscv64/Image', + '174f8bb87f08961e54fa3fcd954a8e31f4645f6d6af4dd43983d5e9841490fb0') + ASSET_ROOTFS = Asset( + ('https://github.com/groeck/linux-build-test/raw/' + '9819da19e6eef291686fdd7b029ea00e764dc62f/rootfs/riscv64/' + 'rootfs.ext2.gz'), + 'b6ed95610310b7956f9bf20c4c9c0c05fea647900df441da9dfe767d24e8b28b') + + def do_test_riscv64_tt_atlantis(self, connect_disk): + self.set_machine('tt-atlantis') + kernel_path = self.ASSET_KERNEL.fetch() + rootfs_path = self.uncompress(self.ASSET_ROOTFS) + + self.vm.set_console() + kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'earlycon=sbi ' + + if connect_disk: + kernel_command_line += 'root=/dev/vda panic=-1 noreboot rootwait ' + self.vm.add_args('-device', + 'virtio-blk,drive=drive0,serial=0x1234,bus=pcie.0') + self.vm.add_args('-drive', + f'file={rootfs_path},if=none,id=drive0,format=raw') + pattern = 'Boot successful.' + else: + kernel_command_line += 'panic=0 noreboot ' + pattern = 'Cannot open root device' + + self.vm.add_args('-kernel', kernel_path, + '-append', kernel_command_line, + '-no-reboot') + + self.vm.launch() + self.wait_for_console_pattern(pattern) + + def test_riscv64_tt_atlantis(self): + # tt-atlantis machine has no PCI host yet, so no disk + self.do_test_riscv64_tt_atlantis(False) + + +if __name__ == '__main__': + LinuxKernelTest.main() --2.47.3
PATCH v8 10/12 hw/i2c: Add DesignWare I2C Controller
In reply to Joel StanleyFrom: Chris Rauer <[email protected]>
Add a model for the Synopsys DesignWare Advanced I2C/SMBus Controller with sufficient functionality to be used by the Linux Designware I2C platform driver.
This IP is used in the Tenstorrent Atlantis RISC-V SoC and will be added to the QEMU tt-atlantis machine.
[npiggin: changelog, code cleanups and fixes as-per below link]
--- MAINTAINERS | 8 + include/hw/i2c/designware_i2c.h | 56 +++ hw/i2c/designware_i2c.c | 745 ++++++++++++++++++++++++++++++++ hw/i2c/Kconfig | 5 + hw/i2c/meson.build | 1 + 5 files changed, 815 insertions(+) create mode 100644 include/hw/i2c/designware_i2c.h create mode 100644 hw/i2c/designware_i2c.c
MAINTAINERS +8 -0
@@ -2742,6 +2742,14 @@ S: Orphan F: hw/gpio/pcf8574.c F: include/gpio/pcf8574.h +DesignWare I2C +M: Chris Rauer <[email protected]> +R: Alano Song <[email protected]> +R: Joel Stanley <[email protected]> +S: Maintained +F: hw/i2c/designware_i2c.c +F: include/hw/i2c/designware_i2c.h + Generic Loader M: Alistair Francis <[email protected]> S: Maintained
include/hw/i2c/designware_i2c.h new file +56 -0
56 lines not on this page · raw message
hw/i2c/designware_i2c.c new file +745 -0
745 lines not on this page · raw message
hw/i2c/Kconfig +5 -0
@@ -18,6 +18,11 @@ config ARM_SBCON_I2C bool select BITBANG_I2C +config DESIGNWARE_I2C + bool + select REGISTER + select I2C + config ACPI_SMBUS bool select SMBUS
hw/i2c/meson.build +1 -0
@@ -11,6 +11,7 @@ i2c_ss.add(when: 'CONFIG_MPC_I2C', if_true: files('mpc_i2c.c')) i2c_ss.add(when: 'CONFIG_ALLWINNER_I2C', if_true: files('allwinner-i2c.c')) i2c_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('microbit_i2c.c')) i2c_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_smbus.c')) +i2c_ss.add(when: 'CONFIG_DESIGNWARE_I2C', if_true: files('designware_i2c.c')) i2c_ss.add(when: 'CONFIG_SMBUS_EEPROM', if_true: files('smbus_eeprom.c')) i2c_ss.add(when: 'CONFIG_ARM_SBCON_I2C', if_true: files('arm_sbcon_i2c.c')) i2c_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_i2c.c'))
Signature · 1 line
2.47.3
Re:[PATCH v8 10/12] hw/i2c: Add DesignWare I2C Controller
Quoted 11 lines · Joel Stanley
From: Chris Rauer <[email protected]>
Add a model for the Synopsys DesignWare Advanced I2C/SMBus Controller with sufficient functionality to be used by the Linux Designware I2C platform driver.
This IP is used in the Tenstorrent Atlantis RISC-V SoC and will be added to the QEMU tt-atlantis machine.
[npiggin: changelog, code cleanups and fixes as-per below link]
Quoted 11 lines
Reviewed-by Hao Wu <[email protected]>Signed-off-by Chris Rauer <[email protected]>[jms: rebase and minor build fixes for class_init and reset callback]Signed-off-by Nicholas Piggin <[email protected]>Acked-by Alistair Francis <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Acked-by Corey Minyard <[email protected]>Tested-by Alano Song <[email protected]>Signed-off-by Joel Stanley <[email protected]>
Ping for code review :)
Alano.
PATCH v8 11/12 hw/riscv/atlantis: Integrate i2c controllers
In reply to Joel StanleyAdd DesignWare I2C controllers to the tt-atlantis machine.
Provide a fixed clock in the device tree so that the Linux driver probes without WARNing.
--- include/hw/riscv/tt_atlantis.h | 14 ++++++++ hw/riscv/tt_atlantis.c | 59 ++++++++++++++++++++++++++++++++++ hw/riscv/Kconfig | 1 + 3 files changed, 74 insertions(+)
include/hw/riscv/tt_atlantis.h +14 -0
@@ -11,12 +11,15 @@#include "hw/core/boards.h" #include "hw/core/sysbus.h" +#include "hw/i2c/designware_i2c.h" #include "hw/intc/riscv_imsic.h" #include "hw/riscv/riscv_hart.h" #define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis") OBJECT_DECLARE_SIMPLE_TYPE(TTAtlantisState, TT_ATLANTIS_MACHINE) +#define TT_ATL_NUM_I2C 5 +struct TTAtlantisState {/*< private >*/ MachineState parent;
@@ -27,11 +30,17 @@ struct TTAtlantisState {RISCVHartArrayState soc;DeviceState *irqchip; +DesignWareI2CState i2c[TT_ATL_NUM_I2C ];int fdt_size; };enum { +TT_ATL_I2C0_IRQ =33 , +TT_ATL_I2C1_IRQ =34 , +TT_ATL_I2C2_IRQ =35 , +TT_ATL_I2C3_IRQ =36 , +TT_ATL_I2C4_IRQ =37 ,TT_ATL_UART1_IRQ =39 , };
@@ -40,6 +49,11 @@ enum {TT_ATL_BOOTROM ,TT_ATL_DDR_LO ,TT_ATL_DDR_HI , +TT_ATL_I2C0 , +TT_ATL_I2C1 , +TT_ATL_I2C2 , +TT_ATL_I2C3 , +TT_ATL_I2C4 ,TT_ATL_MAPLIC ,TT_ATL_MIMSIC , TT_ATL_SAPLIC,
hw/riscv/tt_atlantis.c +59 -0
87 lines not on this page · raw message
hw/riscv/Kconfig +1 -0
@@ -129,6 +129,7 @@ config TENSTORRENT select RISCV_IMSIC select SERIAL_MM select DEVICE_TREE + select DESIGNWARE_I2C config XIANGSHAN_KUNMINGHU bool
Signature · 1 line
2.47.3
Re: [PATCH v8 11/12] hw/riscv/atlantis: Integrate i2c controllers
Quoted 9 lines · Joel Stanley
Add DesignWare I2C controllers to the tt-atlantis machine.
Provide a fixed clock in the device tree so that the Linux driver probes without WARNing.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>Signed-off-by Joel Stanley <[email protected]>
Alistair
Quoted 167 lines
--- include/hw/riscv/tt_atlantis.h | 14 ++++++++ hw/riscv/tt_atlantis.c | 59 ++++++++++++++++++++++++++++++++++ hw/riscv/Kconfig | 1 + 3 files changed, 74 insertions(+)include/hw/riscv/tt_atlantis.h +14
-0@@ -11,12 +11,15 @@#include "hw/core/boards.h" #include "hw/core/sysbus.h" +#include "hw/i2c/designware_i2c.h" #include "hw/intc/riscv_imsic.h" #include "hw/riscv/riscv_hart.h" #define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis") OBJECT_DECLARE_SIMPLE_TYPE(TTAtlantisState, TT_ATLANTIS_MACHINE) +#define TT_ATL_NUM_I2C 5 +struct TTAtlantisState {/*< private >*/ MachineState parent;@@ -27,11 +30,17 @@ struct TTAtlantisState {RISCVHartArrayState soc;DeviceState *irqchip; +DesignWareI2CState i2c[TT_ATL_NUM_I2C ];int fdt_size; };enum { +TT_ATL_I2C0_IRQ =33 , +TT_ATL_I2C1_IRQ =34 , +TT_ATL_I2C2_IRQ =35 , +TT_ATL_I2C3_IRQ =36 , +TT_ATL_I2C4_IRQ =37 ,TT_ATL_UART1_IRQ =39 , };@@ -40,6 +49,11 @@ enum {TT_ATL_BOOTROM ,TT_ATL_DDR_LO ,TT_ATL_DDR_HI , +TT_ATL_I2C0 , +TT_ATL_I2C1 , +TT_ATL_I2C2 , +TT_ATL_I2C3 , +TT_ATL_I2C4 ,TT_ATL_MAPLIC ,TT_ATL_MIMSIC , TT_ATL_SAPLIC,hw/riscv/tt_atlantis.c +59
-0@@ -53,6 +53,11 @@ static const MemMapEntry tt_atlantis_memmap[] = { [TT_ATL_ACLINT] = { 0xa2180000, 0x10000 }, [TT_ATL_SIMSIC] = { 0xa4000000, 0x200000 }, [TT_ATL_MAPLIC] = { 0xcc000000, 0x4000000 }, + [TT_ATL_I2C0] = { 0xd4040000, 0x10000 }, + [TT_ATL_I2C1] = { 0xd4050000, 0x10000 }, + [TT_ATL_I2C2] = { 0xd4060000, 0x10000 }, + [TT_ATL_I2C3] = { 0xd4070000, 0x10000 }, + [TT_ATL_I2C4] = { 0xd4080000, 0x10000 }, [TT_ATL_UART1] = { 0xd4110000, 0x10000 }, [TT_ATL_SAPLIC] = { 0xe8000000, 0x4000000 }, [TT_ATL_DDR_HI] = { 0x100000000, 0x1000000000 },@@ -333,10 +338,40 @@ static void create_fdt_rng(void *fdt)qemu_fdt_setprop (fdt,"/chosen" ,"rng-seed" , rng_seed,sizeof (rng_seed)); } +static void create_fdt_clk (void *fdt,const char *clock_name, +uint32_t freq,uint32_t phandle) +{ + g_autofree char *name = g_strdup_printf("/clocks/%s", clock_name); + +qemu_fdt_add_path (fdt, name); +qemu_fdt_setprop_string (fdt, name,"compatible" ,"fixed-clock" ); +qemu_fdt_setprop_string (fdt, name,"clock-output-names" , clock_name); +qemu_fdt_setprop_cell (fdt, name,"#clock-cells" ,0 ); +qemu_fdt_setprop_cell (fdt, name,"clock-frequency" , freq); +qemu_fdt_setprop_cell (fdt, name,"phandle" , phandle); +} + +static void create_fdt_i2c (void *fdt,const MemMapEntry *mem,uint32_t irq, +uint32_t irqchip_phandle,uint32_t clk_phandle) +{ + g_autofree char *name = g_strdup_printf("/soc/i2c@%"HWADDR_PRIX, mem->base); + +qemu_fdt_add_subnode (fdt, name); +qemu_fdt_setprop_string (fdt, name,"compatible" ,"snps,designware-i2c" ); +qemu_fdt_setprop_sized_cells (fdt, name,"reg" ,2 , mem->base,2 , mem->size); +qemu_fdt_setprop_cell (fdt, name,"interrupt-parent" , irqchip_phandle); +qemu_fdt_setprop_cells (fdt, name,"interrupts" , irq,0x4 ); +qemu_fdt_setprop_cell (fdt, name,"clocks" , clk_phandle); +qemu_fdt_setprop_cell (fdt, name,"clock-frequency" ,100000 ); +qemu_fdt_setprop_cell (fdt, name,"#address-cells" ,1 ); +qemu_fdt_setprop_cell (fdt, name,"#size-cells" ,0 ); +} +static void finalize_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);@@ -350,6 +385,15 @@ static void finalize_fdt(TTAtlantisState *s)create_fdt_uart (fdt, &s->memmap[TT_ATL_UART1 ],TT_ATL_UART1_IRQ , aplic_s_phandle); + +create_fdt_clk (fdt,"periph-clk" ,100000000 , periph_clk_phandle); + +for (int i =0 ; i <TT_ATL_NUM_I2C ; i++) { +create_fdt_i2c (fdt, + &s->memmap[TT_ATL_I2C0 + i], +TT_ATL_I2C0_IRQ + i, + aplic_s_phandle, periph_clk_phandle); + } }static void create_fdt (TTAtlantisState *s)@@ -581,6 +625,21 @@ static void tt_atlantis_machine_init(MachineState *machine) s->memmap[TT_ATL_UART1 ].base, s->memmap[TT_ATL_UART1].size); +/* I2C */ +for (int i =0 ; i <TT_ATL_NUM_I2C ; i++) { +SysBusDevice *sbd; + +object_initialize_child (OBJECT (s),"i2c[*]" , &s->i2c[i], +TYPE_DESIGNWARE_I2C ); + sbd =SYS_BUS_DEVICE (&s->i2c[i]); +sysbus_realize (sbd, &error_fatal); +memory_region_add_subregion (system_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)); + } +/* Load or create device tree */ if (machine->dtb) {load_fdt (s);hw/riscv/Kconfig +1
-1@@ -129,6 +129,7 @@ config TENSTORRENT select RISCV_IMSIC select SERIAL_MM select DEVICE_TREE + select DESIGNWARE_I2C config XIANGSHAN_KUNMINGHU bool --2.47.3
PATCH v8 12/12 hw/riscv/atlantis: Add some i2c peripherals
In reply to Joel StanleyAdd an I2C RTC device and a temperature sensor. These are not present on the board but help for testing.
The tmp105 is a lm75 compatible temperature sensor used by the SENSORS_LM75 Linux kernel driver.
The ds1338 is a RTC device that is used by the RTC_DRV_DS1307 Linux kernel driver.
--- hw/riscv/tt_atlantis.c | 27 +++++++++++++++++++++++++++ hw/riscv/Kconfig | 2 ++ 2 files changed, 29 insertions(+)
hw/riscv/tt_atlantis.c +27 -0
@@ -63,6 +63,13 @@ static const MemMapEntry tt_atlantis_memmap[] = { [TT_ATL_DDR_HI] = { 0x100000000, 0x1000000000 }, }; +static I2CBus *i2c_get_bus (TTAtlantisState *s,unsigned busnr) +{ +assert (busnr <TT_ATL_NUM_I2C ); + +return s->i2c[busnr].bus; +} +static uint32_t next_phandle (void ) {static uint32_t phandle =1 ;
@@ -367,6 +374,19 @@ 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, +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); + +qemu_fdt_add_subnode (fdt, name); +qemu_fdt_setprop_string (fdt, name,"compatible" , compat); +qemu_fdt_setprop_cell (fdt, name,"reg" , addr); +} +static void finalize_fdt (TTAtlantisState *s) {uint32_t aplic_s_phandle =next_phandle ();
@@ -394,6 +414,9 @@ static void finalize_fdt(TTAtlantisState *s)TT_ATL_I2C0_IRQ + i, aplic_s_phandle, periph_clk_phandle); } + +create_fdt_i2c_device (s,0 ,"dallas,ds1338" ,0x6f ); +create_fdt_i2c_device (s,4 ,"ti,tmp105" ,0x48 ); }static void create_fdt (TTAtlantisState *s)
@@ -640,6 +663,10 @@ static void tt_atlantis_machine_init(MachineState *machine) qdev_get_gpio_in(s->irqchip, TT_ATL_I2C0_IRQ + i)); } +/* I2C peripherals: qemu specific */ +i2c_slave_create_simple (i2c_get_bus (s,0 ),"ds1338" ,0x6f ); +i2c_slave_create_simple (i2c_get_bus (s,4 ),"tmp105" ,0x48 ); +/* Load or create device tree */ if (machine->dtb) {load_fdt (s);
hw/riscv/Kconfig +2 -0
@@ -130,6 +130,8 @@ config TENSTORRENT select SERIAL_MM select DEVICE_TREE select DESIGNWARE_I2C + select DS1338 + select TMP105 config XIANGSHAN_KUNMINGHU bool
Signature · 1 line
2.47.3
Re: [PATCH v8 12/12] hw/riscv/atlantis: Add some i2c peripherals
Quoted 3 lines · Joel Stanley
Add an I2C RTC device and a temperature sensor. These are not present on the board but help for testing.
It might be best to leave this out, if these aren't on the board should they really go upstream?
Alistair
Quoted 91 lines
The tmp105 is a lm75 compatible temperature sensor used by the
SENSORS_LM75Linux kernel driver.The ds1338 is a RTC device that is used by the
RTC_DRV_DS1307Linux kernel driver.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>Signed-off-by Joel Stanley <[email protected]>--- hw/riscv/tt_atlantis.c | 27 +++++++++++++++++++++++++++ hw/riscv/Kconfig | 2 ++ 2 files changed, 29 insertions(+)hw/riscv/tt_atlantis.c +27
-0@@ -63,6 +63,13 @@ static const MemMapEntry tt_atlantis_memmap[] = { [TT_ATL_DDR_HI] = { 0x100000000, 0x1000000000 }, }; +static I2CBus *i2c_get_bus (TTAtlantisState *s,unsigned busnr) +{ +assert (busnr <TT_ATL_NUM_I2C ); + +return s->i2c[busnr].bus; +} +static uint32_t next_phandle (void ) {static uint32_t phandle =1 ;@@ -367,6 +374,19 @@ 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, +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); + +qemu_fdt_add_subnode (fdt, name); +qemu_fdt_setprop_string (fdt, name,"compatible" , compat); +qemu_fdt_setprop_cell (fdt, name,"reg" , addr); +} +static void finalize_fdt (TTAtlantisState *s) {uint32_t aplic_s_phandle =next_phandle ();@@ -394,6 +414,9 @@ static void finalize_fdt(TTAtlantisState *s)TT_ATL_I2C0_IRQ + i, aplic_s_phandle, periph_clk_phandle); } + +create_fdt_i2c_device (s,0 ,"dallas,ds1338" ,0x6f ); +create_fdt_i2c_device (s,4 ,"ti,tmp105" ,0x48 ); }static void create_fdt (TTAtlantisState *s)@@ -640,6 +663,10 @@ static void tt_atlantis_machine_init(MachineState *machine) qdev_get_gpio_in(s->irqchip, TT_ATL_I2C0_IRQ + i)); } +/* I2C peripherals: qemu specific */ +i2c_slave_create_simple (i2c_get_bus (s,0 ),"ds1338" ,0x6f ); +i2c_slave_create_simple (i2c_get_bus (s,4 ),"tmp105" ,0x48 ); +/* Load or create device tree */ if (machine->dtb) {load_fdt (s);hw/riscv/Kconfig +2
-1@@ -130,6 +130,8 @@ config TENSTORRENT select SERIAL_MM select DEVICE_TREE select DESIGNWARE_I2C + select DS1338 + select TMP105 config XIANGSHAN_KUNMINGHU bool --2.47.3
Re: [PATCH v8 12/12] hw/riscv/atlantis: Add some i2c peripherals
Quoted 8 lines · Alistair Francis
Quoted 3 lines · Joel Stanley
Add an I2C RTC device and a temperature sensor. These are not present on the board but help for testing.
It might be best to leave this out, if these aren't on the board should they really go upstream?
Without something to stimulate the device we're not testing the designware model, nor the integration into the machine. IRQs, memory maps, as well as the model's state machine all get some coverage by having devices present. The specific devices were chosen as the existing test kernels have drivers built in.
We did something similar with the aspeed arm machines when adding them to qemu.
Cheers,
Joel