hw/riscv: Add Microblaze V 32bit virt board
Subsystems (2)
PATCH v2 1/1 hw/riscv: Add Microblaze V 32bit virt board
Add a basic board with interrupt controller (intc), timer, serial (uartlite), small memory called LMB@0 (128kB) and DDR@0x80000000 (configured via command line eg. -m 2g).
This is basic configuration which matches HW generated out of AMD Vivado (design tools). But initial configuration is going beyond what it is configured by default because validation should be done on other configurations too. That's why wire also additional uart16500, axi ethernet(with axi dma).
GPIOs, i2c and qspi is also listed for completeness.
IRQ map is: (addr)
0 - timer (0x41c00000)
1 - uartlite (0x40600000)
2 - i2c (0x40800000)
3 - qspi (0x44a00000)
4 - uart16550 (0x44a10000)
5 - emaclite (0x40e00000)
6 - timer2 (0x41c10000)
7 - axi emac (0x40c00000)
8 - axi dma (0x41e00000)
9 - axi dma
10 - gpio (0x40000000)
11 - gpio2 (0x40010000)
12 - gpio3 (0x40020000)
---
Changes for V2:
Make changes to support -cpu switch
Remove setting of default board
Include doc to toctree
Remove setting of 'imac' extensions as they are available by default.
MAINTAINERS | 6 + docs/system/riscv/microblaze-v-virt.rst | 39 +++++ docs/system/target-riscv.rst | 1 + hw/riscv/microblaze-v-virt.c | 181 ++++++++++++++++++++++++ hw/riscv/Kconfig | 8 ++ hw/riscv/meson.build | 1 + 6 files changed, 236 insertions(+) create mode 100644 docs/system/riscv/microblaze-v-virt.rst create mode 100644 hw/riscv/microblaze-v-virt.c
MAINTAINERS +6 -0
@@ -1274,6 +1274,12 @@ M: Edgar E. Iglesias <[email protected]> S: Maintained F: hw/microblaze/petalogix_ml605_mmu.c +amd-microblaze-v-virt +M: Sai Pavan Boddu <[email protected]> +S: Maintained +F: hw/riscv/microblaze-v-virt.c +F: docs/system/riscv/microblaze-v-virt.rst + MIPS Machines ------------- Overall MIPS Machines
docs/system/riscv/microblaze-v-virt.rst new file +39 -0
@@ -0,0 +1,39 @@ +Microblaze-V virt board (``amd-microblaze-v-virt``) +=================================================== +The AMD MicroBlaze™ V processor is a soft-core RISC-V processor IP for AMD adaptive SoCs and FPGAs. +The MicroBlaze V processor is based on a 32-bit RISC-V instruction set architecture (ISA). + +More details here: +https://docs.amd.com/r/en-US/ug1629-microblaze-v-user-guide/MicroBlaze-V-Architecture + +The microblaze-v virt board in QEMU is a virtual board with +following supported devices + +Implemented CPU cores: + +1 RISCV32 core + +Implemented devices: + + - timer + - uartlite + - uart16550 + - emaclite + - timer2 + - axi emac + - axi dma + +Running +""""""" +Running U-boot + +.. code-block:: bash + + + $ qemu-system-riscv32 -M amd-microblaze-v-virt \ + -display none \ + -device loader,addr=0x80000000,file=u-boot-spl.bin,cpu-num=0 \ + -device loader,addr=0x80200000,file=u-boot.img \ + -serial mon:stdio \ + -device loader,addr=0x83000000,file=system.dtb \ + -m 2g
docs/system/target-riscv.rst +1 -0
@@ -66,6 +66,7 @@ undocumented; you can get a complete list by running .. toctree:: :maxdepth: 1 + riscv/microblaze-v-virt riscv/microchip-icicle-kit riscv/shakti-c riscv/sifive_u
hw/riscv/microblaze-v-virt.c new file +181 -0
181 lines not on this page · raw message
hw/riscv/Kconfig +8 -0
@@ -22,6 +22,14 @@ config MICROCHIP_PFSOC select SIFIVE_PLIC select UNIMP +config MICROBLAZE_V + bool + default y + depends on RISCV32 + select XILINX + select XILINX_AXI + select XILINX_ETHLITE + config OPENTITAN bool default y
hw/riscv/meson.build +1 -0
@@ -10,5 +10,6 @@ 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_ACPI', if_true: files('virt-acpi-build.c')) +riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-virt.c')) hw_arch += {'riscv': riscv_ss}
Signature · 1 line
2.34.1
Quoted 25 lines · Sai Pavan Boddu
Add a basic board with interrupt controller (intc), timer, serial (uartlite), small memory called LMB@0 (128kB) and DDR@0x80000000 (configured via command line eg. -m 2g).
This is basic configuration which matches HW generated out of AMD Vivado (design tools). But initial configuration is going beyond what it is configured by default because validation should be done on other configurations too. That's why wire also additional uart16500, axi ethernet(with axi dma).
GPIOs, i2c and qspi is also listed for completeness.IRQ map is: (addr)
0 - timer (0x41c00000)
1 - uartlite (0x40600000)
2 - i2c (0x40800000)
3 - qspi (0x44a00000)
4 - uart16550 (0x44a10000)
5 - emaclite (0x40e00000)
6 - timer2 (0x41c10000)
7 - axi emac (0x40c00000)
8 - axi dma (0x41e00000)
9 - axi dma
10 - gpio (0x40000000)
11 - gpio2 (0x40010000)
12 - gpio3 (0x40020000)
Quoted 2 lines
Signed-off-by Sai Pavan Boddu <[email protected]>Signed-off-by Michal Simek <[email protected]>
Quoted 312 lines
---
Changes for V2:
Make changes to support -cpu switch
Remove setting of default board
Include doc to toctree
Remove setting of 'imac' extensions as they are available by default.MAINTAINERS | 6 + docs/system/riscv/microblaze-v-virt.rst | 39 +++++ docs/system/target-riscv.rst | 1 + hw/riscv/microblaze-v-virt.c | 181 ++++++++++++++++++++++++ hw/riscv/Kconfig | 8 ++ hw/riscv/meson.build | 1 + 6 files changed, 236 insertions(+) create mode 100644 docs/system/riscv/microblaze-v-virt.rst create mode 100644 hw/riscv/microblaze-v-virt.cMAINTAINERS +6
-0@@ -1274,6 +1274,12 @@ M: Edgar E. Iglesias <[email protected]> S: Maintained F: hw/microblaze/petalogix_ml605_mmu.c +amd-microblaze-v-virt +M: Sai Pavan Boddu <[email protected]> +S: Maintained +F: hw/riscv/microblaze-v-virt.c +F: docs/system/riscv/microblaze-v-virt.rst + MIPS Machines ------------- Overall MIPS Machinesdocs/system/riscv/microblaze-v-virt.rst new file +39
-0@@ -0,0 +1,39 @@ +Microblaze-V virt board (``amd-microblaze-v-virt``) +=================================================== +The AMD MicroBlaze™ V processor is a soft-core RISC-V processor IP for AMD adaptive SoCs and FPGAs. +The MicroBlaze V processor is based on a 32-bit RISC-V instruction set architecture (ISA). + +More details here: +https://docs.amd.com/r/en-US/ug1629-microblaze-v-user-guide/MicroBlaze-V-Architecture + +The microblaze-v virt board in QEMU is a virtual board with +following supported devices + +Implemented CPU cores: + +1 RISCV32 core + +Implemented devices: + + - timer + - uartlite + - uart16550 + - emaclite + - timer2 + - axi emac + - axi dma + +Running +""""""" +Running U-boot + +.. code-block:: bash + + + $ qemu-system-riscv32 -M amd-microblaze-v-virt \ + -display none \ + -device loader,addr=0x80000000,file=u-boot-spl.bin,cpu-num=0 \ + -device loader,addr=0x80200000,file=u-boot.img \ + -serial mon:stdio \ + -device loader,addr=0x83000000,file=system.dtb \ + -m 2gdocs/system/target-riscv.rst +1
-0@@ -66,6 +66,7 @@ undocumented; you can get a complete list by running .. toctree:: :maxdepth: 1 + riscv/microblaze-v-virt riscv/microchip-icicle-kit riscv/shakti-c riscv/sifive_uhw/riscv/microblaze-v-virt.c new file +181
-0@@ -0,0 +1,181 @@ +/* +* QEMU model of Microblaze V (32bit version) +* +* based on hw/microblaze/petalogix_ml605_mmu.c +* +* Copyright (c) 2011 Michal Simek <[email protected]> +* Copyright (c) 2011 PetaLogix +* Copyright (c) 2009 Edgar E. Iglesias. +* Copyright (C) 2024, Advanced Micro Devices, Inc. +* SPDX-License-Identifier: GPL-2.0-or-later +* Written by Sai Pavan Boddu <[email protected]> +* and by Michal Simek <[email protected]>. +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qapi/error.h" +#include "cpu.h" +#include "hw/sysbus.h" +#include "sysemu/sysemu.h" +#include "net/net.h" +#include "hw/boards.h" +#include "hw/char/serial-mm.h" +#include "exec/address-spaces.h" +#include "hw/char/xilinx_uartlite.h" +#include "hw/misc/unimp.h" + +#define LMB_BRAM_SIZE (128 * KiB) +#define MEMORY_BASEADDR 0x80000000 +#define INTC_BASEADDR 0x41200000 +#define TIMER_BASEADDR 0x41c00000 +#define TIMER_BASEADDR2 0x41c10000 +#define UARTLITE_BASEADDR 0x40600000 +#define ETHLITE_BASEADDR 0x40e00000 +#define UART16550_BASEADDR 0x44a10000 +#define AXIENET_BASEADDR 0x40c00000 +#define AXIDMA_BASEADDR 0x41e00000 +#define GPIO_BASEADDR 0x40000000 +#define GPIO_BASEADDR2 0x40010000 +#define GPIO_BASEADDR3 0x40020000 +#define I2C_BASEADDR 0x40800000 +#define QSPI_BASEADDR 0x44a00000 + +#define TIMER_IRQ 0 +#define UARTLITE_IRQ 1 +#define UART16550_IRQ 4 +#define ETHLITE_IRQ 5 +#define TIMER_IRQ2 6 +#define AXIENET_IRQ 7 +#define AXIDMA_IRQ1 8 +#define AXIDMA_IRQ0 9 + +static void mb_v_virt_init (MachineState *machine) +{ +ram_addr_t ram_size = machine->ram_size; +DeviceState *dev, *dma, *eth0; +Object *ds, *cs; +int i; +RISCVCPU *cpu; +hwaddr ddr_base =MEMORY_BASEADDR ; +MemoryRegion *phys_lmb_bram =g_new (MemoryRegion,1 ); +MemoryRegion *phys_ram =g_new (MemoryRegion,1 ); +qemu_irq irq[32 ]; +MemoryRegion *sysmem =get_system_memory (); + + cpu =RISCV_CPU (object_new (machine->cpu_type)); +qdev_realize (DEVICE (cpu),NULL , &error_abort); +/* Attach emulated BRAM through the LMB. */ +memory_region_init_ram (phys_lmb_bram,NULL , +"mb_v.lmb_bram" ,LMB_BRAM_SIZE , + &error_fatal); +memory_region_add_subregion (sysmem,0x00000000 , phys_lmb_bram); + +memory_region_init_ram (phys_ram,NULL ,"mb_v.ram" , + ram_size, &error_fatal); +memory_region_add_subregion (sysmem, ddr_base, phys_ram); + + dev =qdev_new ("xlnx.xps-intc" ); +qdev_prop_set_uint32 (dev,"kind-of-intr" , +1 <<UARTLITE_IRQ ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,INTC_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , +qdev_get_gpio_in (DEVICE (cpu),11 )); +for (i =0 ; i <32 ; i++) { + irq[i] =qdev_get_gpio_in (dev, i); + } + +/* Uartlite */ + dev =qdev_new (TYPE_XILINX_UARTLITE ); +qdev_prop_set_chr (dev,"chardev" ,serial_hd (0 )); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,UARTLITE_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[UARTLITE_IRQ ]); + +/* Full uart */ +serial_mm_init (sysmem,UART16550_BASEADDR +0x1000 ,2 , + irq[UART16550_IRQ ],115200 ,serial_hd (1 ), +DEVICE_LITTLE_ENDIAN ); + +/* 2 timers at irq 0 @ 100 Mhz. */ + dev =qdev_new ("xlnx.xps-timer" ); +qdev_prop_set_uint32 (dev,"one-timer-only" ,0 ); +qdev_prop_set_uint32 (dev,"clock-frequency" ,100000000 ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,TIMER_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[TIMER_IRQ ]); + +/* 2 timers at irq 3 @ 100 Mhz. */ + dev =qdev_new ("xlnx.xps-timer" ); +qdev_prop_set_uint32 (dev,"one-timer-only" ,0 ); +qdev_prop_set_uint32 (dev,"clock-frequency" ,100000000 ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,TIMER_BASEADDR2 ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[TIMER_IRQ2 ]); + +/* Emaclite */ + dev =qdev_new ("xlnx.xps-ethernetlite" ); +qemu_configure_nic_device (dev, true,NULL ); +qdev_prop_set_uint32 (dev,"tx-ping-pong" ,0 ); +qdev_prop_set_uint32 (dev,"rx-ping-pong" ,0 ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,ETHLITE_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[ETHLITE_IRQ ]); + +/* axi ethernet and dma initialization. */ + eth0 =qdev_new ("xlnx.axi-ethernet" ); + dma =qdev_new ("xlnx.axi-dma" ); + +/* FIXME: attach to the sysbus instead */ +object_property_add_child (qdev_get_machine (),"xilinx-eth" ,OBJECT (eth0)); +object_property_add_child (qdev_get_machine (),"xilinx-dma" ,OBJECT (dma)); + + ds =object_property_get_link (OBJECT (dma), +"axistream-connected-target" ,NULL ); + cs =object_property_get_link (OBJECT (dma), +"axistream-control-connected-target" ,NULL ); +qemu_configure_nic_device (eth0, true,NULL ); +qdev_prop_set_uint32 (eth0,"rxmem" ,0x1000 ); +qdev_prop_set_uint32 (eth0,"txmem" ,0x1000 ); +object_property_set_link (OBJECT (eth0),"axistream-connected" , ds, + &error_abort); +object_property_set_link (OBJECT (eth0),"axistream-control-connected" , cs, + &error_abort); +sysbus_realize_and_unref (SYS_BUS_DEVICE (eth0), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (eth0),0 ,AXIENET_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (eth0),0 , irq[AXIENET_IRQ ]); + + ds =object_property_get_link (OBJECT (eth0), +"axistream-connected-target" ,NULL ); + cs =object_property_get_link (OBJECT (eth0), +"axistream-control-connected-target" ,NULL ); +qdev_prop_set_uint32 (dma,"freqhz" ,100000000 ); +object_property_set_link (OBJECT (dma),"axistream-connected" , ds, + &error_abort); +object_property_set_link (OBJECT (dma),"axistream-control-connected" , cs, + &error_abort); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dma), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dma),0 ,AXIDMA_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dma),0 , irq[AXIDMA_IRQ0 ]); +sysbus_connect_irq (SYS_BUS_DEVICE (dma),1 , irq[AXIDMA_IRQ1 ]); + +/* unimplemented devices */ +create_unimplemented_device ("gpio" ,GPIO_BASEADDR ,0x10000 ); +create_unimplemented_device ("gpio2" ,GPIO_BASEADDR2 ,0x10000 ); +create_unimplemented_device ("gpio3" ,GPIO_BASEADDR3 ,0x10000 ); +create_unimplemented_device ("i2c" ,I2C_BASEADDR ,0x10000 ); +create_unimplemented_device ("qspi" ,QSPI_BASEADDR ,0x10000 ); +} + +static void mb_v_virt_machine_init (MachineClass *mc) +{ + mc->desc ="AMD Microblaze-V Virt platform" ; + mc->init = mb_v_virt_init; + mc->min_cpus =1 ; + mc->max_cpus =1 ; + mc->default_cpu_type =TYPE_RISCV_CPU_BASE32 ; + mc->default_cpus =1 ; +} + +DEFINE_MACHINE ("amd-microblaze-v-virt" , mb_v_virt_machine_init)hw/riscv/Kconfig +8
-0@@ -22,6 +22,14 @@ config MICROCHIP_PFSOC select SIFIVE_PLIC select UNIMP +config MICROBLAZE_V + bool + default y + depends on RISCV32 + select XILINX + select XILINX_AXI + select XILINX_ETHLITE + config OPENTITAN bool default yhw/riscv/meson.build +1
-0@@ -10,5 +10,6 @@ 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_ACPI', if_true: files('virt-acpi-build.c')) +riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-virt.c')) hw_arch += {'riscv': riscv_ss}Signature · 1 line
2.34.1
Quoted 50 lines · Sai Pavan Boddu
Add a basic board with interrupt controller (intc), timer, serial (uartlite), small memory called LMB@0 (128kB) and DDR@0x80000000 (configured via command line eg. -m 2g).
This is basic configuration which matches HW generated out of AMD Vivado (design tools). But initial configuration is going beyond what it is configured by default because validation should be done on other configurations too. That's why wire also additional uart16500, axi ethernet(with axi dma).
GPIOs, i2c and qspi is also listed for completeness.IRQ map is: (addr)
0 - timer (0x41c00000)
1 - uartlite (0x40600000)
2 - i2c (0x40800000)
3 - qspi (0x44a00000)
4 - uart16550 (0x44a10000)
5 - emaclite (0x40e00000)
6 - timer2 (0x41c10000)
7 - axi emac (0x40c00000)
8 - axi dma (0x41e00000)
9 - axi dma
10 - gpio (0x40000000)
11 - gpio2 (0x40010000)
12 - gpio3 (0x40020000)Signed-off-by Sai Pavan Boddu <[email protected]>Signed-off-by Michal Simek <[email protected]>---
Changes for V2:
Make changes to support -cpu switch
Remove setting of default board
Include doc to toctree
Remove setting of 'imac' extensions as they are available by default.MAINTAINERS | 6 + docs/system/riscv/microblaze-v-virt.rst | 39 +++++ docs/system/target-riscv.rst | 1 + hw/riscv/microblaze-v-virt.c | 181 ++++++++++++++++++++++++ hw/riscv/Kconfig | 8 ++ hw/riscv/meson.build | 1 + 6 files changed, 236 insertions(+) create mode 100644 docs/system/riscv/microblaze-v-virt.rst create mode 100644 hw/riscv/microblaze-v-virt.cMAINTAINERS +0
-0
MAINTAINERS M: Edgar E. Iglesias <[email protected]> · line 1277
Quoted 4 lines
MAINTAINERS +1
-0@@ -1274,6 +1274,12 @@ M: Edgar E. Iglesias <[email protected]> S: Maintained F: hw/microblaze/petalogix_ml605_mmu.c +amd-microblaze-v-virt
This should probably be more like
"AMD Microblaze-V Virt Board"
Also, this should be with the RISC-V boards
Quoted 18 lines
MAINTAINERS +5
-0+M: Sai Pavan Boddu <[email protected]> +S: Maintained +F: hw/riscv/microblaze-v-virt.c +F: docs/system/riscv/microblaze-v-virt.rst + MIPS Machines ------------- Overall MIPS Machinesdocs/system/riscv/microblaze-v-virt.rst new file +4
-0@@ -0,0 +1,39 @@ +Microblaze-V virt board (``amd-microblaze-v-virt``) +=================================================== +The AMD MicroBlaze™ V processor is a soft-core RISC-V processor IP for AMD adaptive SoCs and FPGAs. +The MicroBlaze V processor is based on a 32-bit RISC-V instruction set architecture (ISA).
docs/system/riscv/microblaze-v-virt.rst line 14
Quoted 10 lines
docs/system/riscv/microblaze-v-virt.rst new file +10
-0+ +More details here: +https://docs.amd.com/r/en-US/ug1629-microblaze-v-user-guide/MicroBlaze-V-Architecture + +The microblaze-v virt board in QEMU is a virtual board with +following supported devices + +Implemented CPU cores: + +1 RISCV32 core
Maybe details on the extensions supported?
Quoted 43 lines
docs/system/riscv/microblaze-v-virt.rst new file +25
-0+ +Implemented devices: + + - timer + - uartlite + - uart16550 + - emaclite + - timer2 + - axi emac + - axi dma + +Running +""""""" +Running U-boot + +.. code-block:: bash + + + $ qemu-system-riscv32 -M amd-microblaze-v-virt \ + -display none \ + -device loader,addr=0x80000000,file=u-boot-spl.bin,cpu-num=0 \ + -device loader,addr=0x80200000,file=u-boot.img \ + -serial mon:stdio \ + -device loader,addr=0x83000000,file=system.dtb \ + -m 2gdocs/system/target-riscv.rst +1
-0@@ -66,6 +66,7 @@ undocumented; you can get a complete list by running .. toctree:: :maxdepth: 1 + riscv/microblaze-v-virt riscv/microchip-icicle-kit riscv/shakti-c riscv/sifive_uhw/riscv/microblaze-v-virt.c new file +0
-0
hw/riscv/microblaze-v-virt.c line 4
Quoted 4 lines
hw/riscv/microblaze-v-virt.c new file +4
-0@@ -0,0 +1,181 @@ +/* +* QEMU model of Microblaze V (32bit version) +* +* based on hw/microblaze/petalogix_ml605_mmu.c
Just a question, are you sure the virt board should be based on the petalogix_ml605_mmu?
This will be the reference Microblaze V implementation in QEMU, and the petalogix_ml605_mmu might be a bit old now. It also uses a lot of the Microblaze architecture components (like the interrupt controller) compared to the RISC-V architecture components which might cause issues for you in the future.
Just something to keep in mind
hw/riscv/microblaze-v-virt.c line 10
Quoted 6 lines
hw/riscv/microblaze-v-virt.c new file +6
-0+* +* Copyright (c) 2011 Michal Simek <[email protected]> +* Copyright (c) 2011 PetaLogix +* Copyright (c) 2009 Edgar E. Iglesias. +* Copyright (C) 2024, Advanced Micro Devices, Inc. +* SPDX-License-Identifier: GPL-2.0-or-later
I think the SPDX-License-Identifier should be at the top of the file
Quoted 205 lines
hw/riscv/microblaze-v-virt.c new file +171
-0+* Written by Sai Pavan Boddu <[email protected]> +* and by Michal Simek <[email protected]>. +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qapi/error.h" +#include "cpu.h" +#include "hw/sysbus.h" +#include "sysemu/sysemu.h" +#include "net/net.h" +#include "hw/boards.h" +#include "hw/char/serial-mm.h" +#include "exec/address-spaces.h" +#include "hw/char/xilinx_uartlite.h" +#include "hw/misc/unimp.h" + +#define LMB_BRAM_SIZE (128 * KiB) +#define MEMORY_BASEADDR 0x80000000 +#define INTC_BASEADDR 0x41200000 +#define TIMER_BASEADDR 0x41c00000 +#define TIMER_BASEADDR2 0x41c10000 +#define UARTLITE_BASEADDR 0x40600000 +#define ETHLITE_BASEADDR 0x40e00000 +#define UART16550_BASEADDR 0x44a10000 +#define AXIENET_BASEADDR 0x40c00000 +#define AXIDMA_BASEADDR 0x41e00000 +#define GPIO_BASEADDR 0x40000000 +#define GPIO_BASEADDR2 0x40010000 +#define GPIO_BASEADDR3 0x40020000 +#define I2C_BASEADDR 0x40800000 +#define QSPI_BASEADDR 0x44a00000 + +#define TIMER_IRQ 0 +#define UARTLITE_IRQ 1 +#define UART16550_IRQ 4 +#define ETHLITE_IRQ 5 +#define TIMER_IRQ2 6 +#define AXIENET_IRQ 7 +#define AXIDMA_IRQ1 8 +#define AXIDMA_IRQ0 9 + +static void mb_v_virt_init (MachineState *machine) +{ +ram_addr_t ram_size = machine->ram_size; +DeviceState *dev, *dma, *eth0; +Object *ds, *cs; +int i; +RISCVCPU *cpu; +hwaddr ddr_base =MEMORY_BASEADDR ; +MemoryRegion *phys_lmb_bram =g_new (MemoryRegion,1 ); +MemoryRegion *phys_ram =g_new (MemoryRegion,1 ); +qemu_irq irq[32 ]; +MemoryRegion *sysmem =get_system_memory (); + + cpu =RISCV_CPU (object_new (machine->cpu_type)); +qdev_realize (DEVICE (cpu),NULL , &error_abort); +/* Attach emulated BRAM through the LMB. */ +memory_region_init_ram (phys_lmb_bram,NULL , +"mb_v.lmb_bram" ,LMB_BRAM_SIZE , + &error_fatal); +memory_region_add_subregion (sysmem,0x00000000 , phys_lmb_bram); + +memory_region_init_ram (phys_ram,NULL ,"mb_v.ram" , + ram_size, &error_fatal); +memory_region_add_subregion (sysmem, ddr_base, phys_ram); + + dev =qdev_new ("xlnx.xps-intc" ); +qdev_prop_set_uint32 (dev,"kind-of-intr" , +1 <<UARTLITE_IRQ ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,INTC_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , +qdev_get_gpio_in (DEVICE (cpu),11 )); +for (i =0 ; i <32 ; i++) { + irq[i] =qdev_get_gpio_in (dev, i); + } + +/* Uartlite */ + dev =qdev_new (TYPE_XILINX_UARTLITE ); +qdev_prop_set_chr (dev,"chardev" ,serial_hd (0 )); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,UARTLITE_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[UARTLITE_IRQ ]); + +/* Full uart */ +serial_mm_init (sysmem,UART16550_BASEADDR +0x1000 ,2 , + irq[UART16550_IRQ ],115200 ,serial_hd (1 ), +DEVICE_LITTLE_ENDIAN ); + +/* 2 timers at irq 0 @ 100 Mhz. */ + dev =qdev_new ("xlnx.xps-timer" ); +qdev_prop_set_uint32 (dev,"one-timer-only" ,0 ); +qdev_prop_set_uint32 (dev,"clock-frequency" ,100000000 ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,TIMER_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[TIMER_IRQ ]); + +/* 2 timers at irq 3 @ 100 Mhz. */ + dev =qdev_new ("xlnx.xps-timer" ); +qdev_prop_set_uint32 (dev,"one-timer-only" ,0 ); +qdev_prop_set_uint32 (dev,"clock-frequency" ,100000000 ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,TIMER_BASEADDR2 ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[TIMER_IRQ2 ]); + +/* Emaclite */ + dev =qdev_new ("xlnx.xps-ethernetlite" ); +qemu_configure_nic_device (dev, true,NULL ); +qdev_prop_set_uint32 (dev,"tx-ping-pong" ,0 ); +qdev_prop_set_uint32 (dev,"rx-ping-pong" ,0 ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,ETHLITE_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[ETHLITE_IRQ ]); + +/* axi ethernet and dma initialization. */ + eth0 =qdev_new ("xlnx.axi-ethernet" ); + dma =qdev_new ("xlnx.axi-dma" ); + +/* FIXME: attach to the sysbus instead */ +object_property_add_child (qdev_get_machine (),"xilinx-eth" ,OBJECT (eth0)); +object_property_add_child (qdev_get_machine (),"xilinx-dma" ,OBJECT (dma)); + + ds =object_property_get_link (OBJECT (dma), +"axistream-connected-target" ,NULL ); + cs =object_property_get_link (OBJECT (dma), +"axistream-control-connected-target" ,NULL ); +qemu_configure_nic_device (eth0, true,NULL ); +qdev_prop_set_uint32 (eth0,"rxmem" ,0x1000 ); +qdev_prop_set_uint32 (eth0,"txmem" ,0x1000 ); +object_property_set_link (OBJECT (eth0),"axistream-connected" , ds, + &error_abort); +object_property_set_link (OBJECT (eth0),"axistream-control-connected" , cs, + &error_abort); +sysbus_realize_and_unref (SYS_BUS_DEVICE (eth0), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (eth0),0 ,AXIENET_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (eth0),0 , irq[AXIENET_IRQ ]); + + ds =object_property_get_link (OBJECT (eth0), +"axistream-connected-target" ,NULL ); + cs =object_property_get_link (OBJECT (eth0), +"axistream-control-connected-target" ,NULL ); +qdev_prop_set_uint32 (dma,"freqhz" ,100000000 ); +object_property_set_link (OBJECT (dma),"axistream-connected" , ds, + &error_abort); +object_property_set_link (OBJECT (dma),"axistream-control-connected" , cs, + &error_abort); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dma), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dma),0 ,AXIDMA_BASEADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (dma),0 , irq[AXIDMA_IRQ0 ]); +sysbus_connect_irq (SYS_BUS_DEVICE (dma),1 , irq[AXIDMA_IRQ1 ]); + +/* unimplemented devices */ +create_unimplemented_device ("gpio" ,GPIO_BASEADDR ,0x10000 ); +create_unimplemented_device ("gpio2" ,GPIO_BASEADDR2 ,0x10000 ); +create_unimplemented_device ("gpio3" ,GPIO_BASEADDR3 ,0x10000 ); +create_unimplemented_device ("i2c" ,I2C_BASEADDR ,0x10000 ); +create_unimplemented_device ("qspi" ,QSPI_BASEADDR ,0x10000 ); +} + +static void mb_v_virt_machine_init (MachineClass *mc) +{ + mc->desc ="AMD Microblaze-V Virt platform" ; + mc->init = mb_v_virt_init; + mc->min_cpus =1 ; + mc->max_cpus =1 ; + mc->default_cpu_type =TYPE_RISCV_CPU_BASE32 ; + mc->default_cpus =1 ; +} + +DEFINE_MACHINE ("amd-microblaze-v-virt" , mb_v_virt_machine_init)hw/riscv/Kconfig +8
-0@@ -22,6 +22,14 @@ config MICROCHIP_PFSOC select SIFIVE_PLIC select UNIMP +config MICROBLAZE_V + bool + default y + depends on RISCV32 + select XILINX + select XILINX_AXI + select XILINX_ETHLITE + config OPENTITAN bool default yhw/riscv/meson.build +1
-1@@ -10,5 +10,6 @@ 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_ACPI', if_true: files('virt-acpi-build.c')) +riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-virt.c')) hw_arch += {'riscv': riscv_ss} --2.34.1
Hi Alistair,
Quoted 15 lines · Alistair Francis
hw/riscv/microblaze-v-virt.c line 4
Quoted 10 lines · Sai Pavan Boddu
hw/riscv/microblaze-v-virt.c new file +4
-0@@ -0,0 +1,181 @@ +/* +* QEMU model of Microblaze V (32bit version) +* +* based on hw/microblaze/petalogix_ml605_mmu.c Just a question, are you sure the virt board should be based on the
petalogix_ml605_mmu?
It is definitely based on ml605 and it is fair to say it and keep origin copyrights around.
Quoted 7 lines
This will be the reference Microblaze V implementation in QEMU, and the
petalogix_ml605_mmumight be a bit old now. It also uses a lot of the Microblaze architecture components (like the interrupt controller) compared to the RISC-V architecture components which might cause issues for you in the future.Just something to keep in mind
And the reason is that it is really design like that in design tool (Vivado).
There is no risc-v specific interrupt controller use but origin axi intc used in origin Microblaze designs. Timer is the same story.
ml605 board and it's chip is old but IPs which are used are still supported and used in new designs.
And regarding using virt in name. We can create design like it is described but it is not going to work on standard evaluation boards without extra fmc cards for example. It means word virt is just description that it is not really target any specific board. Definitely name can change and suggestions are welcome.
Thanks,
Michal
Hi Michal,
Quoted 5 lines · Michal Simek
Hi Alistair,
Quoted 1 line · Alistair Francis
On Thu, Oct 17, 2024 at 5:26 PM Sai Pavan Boddu <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
hw/riscv/microblaze-v-virt.c line 2
Quoted 8 lines
hw/riscv/microblaze-v-virt.c new file +2
-0@@ -0,0 +1,181 @@ +/* +* QEMU model of Microblaze V (32bit version)
Is there a 64-bit model planned?
Quoted 16 lines
Quoted 5 lines
hw/riscv/microblaze-v-virt.c line 4
Quoted 2 lines
hw/riscv/microblaze-v-virt.c new file +2
-0+* +* based on hw/microblaze/petalogix_ml605_mmu.c Just a question, are you sure the virt board should be based on the
petalogix_ml605_mmu?It is definitely based on ml605 and it is fair to say it and keep origin copyrights around.
Quoted 7 lines
This will be the reference Microblaze V implementation in QEMU, and the
petalogix_ml605_mmumight be a bit old now. It also uses a lot of the Microblaze architecture components (like the interrupt controller) compared to the RISC-V architecture components which might cause issues for you in the future.Just something to keep in mind
Quoted 7 lines
And the reason is that it is really design like that in design tool (Vivado).
There is no risc-v specific interrupt controller use but origin axi intc used in origin Microblaze designs. Timer is the same story.ml605 board and it's chip is old but IPs which are used are still supported and used in new designs.
And regarding using virt in name. We can create design like it is described but it is not going to work on standard evaluation boards without extra fmc cards for example. It means word virt is just description that it is not really target any specific board. Definitely name can change and suggestions are welcome.
What about 'generic'?
Quoted 10 lines · Philippe Mathieu-Daudé
Hi Michal,
Quoted 6 lines · Michal Simek
Hi Alistair,
Quoted 2 lines · Alistair Francis
On Thu, Oct 17, 2024 at 5:26 PM Sai Pavan Boddu
<[email protected]> wrote:
Quoted 35 lines
Quoted 8 lines
Quoted 8 lines
hw/riscv/microblaze-v-virt.c line 2
Quoted 8 lines
hw/riscv/microblaze-v-virt.c new file +2
-0@@ -0,0 +1,181 @@ +/* +* QEMU model of Microblaze V (32bit version) Is there a 64-bit model planned?
Quoted 24 lines
Quoted 5 lines
hw/riscv/microblaze-v-virt.c line 4
Quoted 2 lines
hw/riscv/microblaze-v-virt.c new file +2
-0+* +* based on hw/microblaze/petalogix_ml605_mmu.c Just a question, are you sure the virt board should be based on the
petalogix_ml605_mmu?It is definitely based on ml605 and it is fair to say it and keep origin copyrights around.
Quoted 7 lines
This will be the reference Microblaze V implementation in QEMU, and the
petalogix_ml605_mmumight be a bit old now. It also uses a lot of the Microblaze architecture components (like the interrupt controller) compared to the RISC-V architecture components which might cause issues for you in the future.Just something to keep in mind
And the reason is that it is really design like that in design tool (Vivado).
There is no risc-v specific interrupt controller use but origin axi intc used in origin Microblaze designs. Timer is the same story.ml605 board and it's chip is old but IPs which are used are still supported and used in new designs.
Fine with me, just wanted to check.
It's probably worth stating all of this in the board's documentation, just to be clear that it's an abstract board.
Quoted 8 lines
Quoted 6 lines
And regarding using virt in name. We can create design like it is described but it is not going to work on standard evaluation boards without extra fmc cards for example.
It means word virt is just description that it is not really target any specific board. Definitely name can change and suggestions are welcome.What about 'generic'?
Yeah, I think we should avoid virt. generic seems better. Or something like "example" or "base". Names are hard
Alistair
Hi Alistair,
Thanks for the review, I will send a v3 as follow-up.
Regards,
Sai Pavan
Quoted 78 lines
-----Original Message-----
From: Alistair Francis <[email protected]>
Sent: Thursday, October 31, 2024 10:01 AM
To: Philippe Mathieu-Daudé <[email protected]>
Cc: Simek, Michal <[email protected]>; Boddu, Sai Pavan <[email protected]>; [email protected]; [email protected]; Paolo Bonzini <[email protected]>; Palmer Dabbelt <[email protected]>; Alistair Francis <[email protected]>; Bin Meng <[email protected]>; Weiwei Li <[email protected]>; Daniel Henrique Barboza <[email protected]>; Liu Zhiwei <[email protected]>
Subject: Re: [PATCH v2] hw/riscv: Add Microblaze V 32bit virt boardQuoted 10 lines · Philippe Mathieu-Daudé
Hi Michal,
Quoted 6 lines · Michal Simek
Hi Alistair,
Quoted 2 lines · Alistair Francis
On Thu, Oct 17, 2024 at 5:26 PM Sai Pavan Boddu
<[email protected]> wrote:Quoted 35 lines
Quoted 8 lines
Quoted 8 lines
hw/riscv/microblaze-v-virt.c line 2
Quoted 8 lines
(quoted diff) +0
-0
b/hw/riscv/microblaze-v-virt.cnew file mode 100644 index 00000000000..6603e6d6b06hw/riscv/microblaze-v-virt.c new file +2
-0@@ -0,0 +1,181 @@ +/* +* QEMU model of Microblaze V (32bit version) Is there a 64-bit model planned?
Quoted 24 lines
Quoted 5 lines
hw/riscv/microblaze-v-virt.c line 4
Quoted 2 lines
hw/riscv/microblaze-v-virt.c new file +2
-0+* +* based on hw/microblaze/petalogix_ml605_mmu.c Just a question, are you sure the virt board should be based on the
petalogix_ml605_mmu?It is definitely based on ml605 and it is fair to say it and keep origin copyrights around.
Quoted 7 lines
This will be the reference Microblaze V implementation in QEMU, and the
petalogix_ml605_mmumight be a bit old now. It also uses a lot of the Microblaze architecture components (like the interrupt controller) compared to the RISC-V architecture components which might cause issues for you in the future.Just something to keep in mind
And the reason is that it is really design like that in design tool (Vivado).
There is no risc-v specific interrupt controller use but origin axi intc used in origin Microblaze designs. Timer is the same story.ml605 board and it's chip is old but IPs which are used are still supported and used in new designs.
Fine with me, just wanted to check.
It's probably worth stating all of this in the board's documentation, just to be clear that it's an abstract board.
Quoted 8 lines
Quoted 6 lines
And regarding using virt in name. We can create design like it is described but it is not going to work on standard evaluation boards without extra fmc cards for example.
It means word virt is just description that it is not really target any specific board. Definitely name can change and suggestions are welcome.What about 'generic'?
Yeah, I think we should avoid virt. generic seems better. Or something like "example" or "base". Names are hard
Alistair
Hi,
Quoted 8 lines · Philippe Mathieu-Daudé
Hi Michal,
Quoted 5 lines · Michal Simek
Hi Alistair,
Quoted 1 line · Alistair Francis
On Thu, Oct 17, 2024 at 5:26 PM Sai Pavan Boddu <[email protected]> wrote:
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
hw/riscv/microblaze-v-virt.c line 2
Quoted 8 lines
hw/riscv/microblaze-v-virt.c new file +2
-0@@ -0,0 +1,181 @@ +/* +* QEMU model of Microblaze V (32bit version) Is there a 64-bit model planned?
This guide is talking about 64bit too
https://docs.amd.com/r/en-US/ug1629-microblaze-v-user-guide
It means answer is yes. And pretty much this generic model with the same layout should be possible to use with generic 64bit version too.
I expect that means that default_cpu_type should be TYPE_RISCV_CPU_BASE. and Kconfig should be extended
+ depends on RISCV32 || RISCV64
Also some small updates in documentation to cover it.
Is there something else what should be updated?
Thanks,
Michal
Quoted 22 lines · Michal Simek
Hi,
Quoted 8 lines · Philippe Mathieu-Daudé
Hi Michal,
Quoted 5 lines · Michal Simek
Hi Alistair,
Quoted 1 line · Alistair Francis
On Thu, Oct 17, 2024 at 5:26 PM Sai Pavan Boddu <[email protected]> wrote:
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
hw/riscv/microblaze-v-virt.c line 2
Quoted 8 lines
hw/riscv/microblaze-v-virt.c new file +2
-0@@ -0,0 +1,181 @@ +/* +* QEMU model of Microblaze V (32bit version) Is there a 64-bit model planned?
Quoted 2 lines
This guide is talking about 64bit too
https://docs.amd.com/r/en-US/ug1629-microblaze-v-user-guide
Same board, different core (synthesized with C_DATA_SIZE = 64).
Quoted 9 lines
It means answer is yes. And pretty much this generic model with the same layout should be possible to use with generic 64bit version too.
I expect that means that
default_cpu_typeshould beTYPE_RISCV_CPU_BASE. andKconfigshould be extended
+ depends on RISCV32 || RISCV64Also some small updates in documentation to cover it.
Is there something else what should be updated?
No issue, I was just checking.
Regards,
Phil.
Thanks Phil, I will send a v3 for follow-up.
Regards,
Sai Pavan
Quoted 57 lines
-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Thursday, October 31, 2024 9:30 PM
To: Simek, Michal <[email protected]>; Alistair Francis <[email protected]>; Boddu, Sai Pavan <[email protected]>
Cc: [email protected]; [email protected]; Paolo Bonzini <[email protected]>; Palmer Dabbelt <[email protected]>; Alistair Francis <[email protected]>; Bin Meng <[email protected]>; Weiwei Li <[email protected]>; Daniel Henrique Barboza <[email protected]>; Liu Zhiwei <[email protected]>
Subject: Re: [PATCH v2] hw/riscv: Add Microblaze V 32bit virt boardQuoted 23 lines · Michal Simek
Hi,
Quoted 9 lines · Philippe Mathieu-Daudé
Hi Michal,
Quoted 6 lines · Michal Simek
Hi Alistair,
Quoted 2 lines · Alistair Francis
On Thu, Oct 17, 2024 at 5:26 PM Sai Pavan Boddu
<[email protected]> wrote:Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
hw/riscv/microblaze-v-virt.c line 2
Quoted 8 lines
(quoted diff) +0
-0
b/hw/riscv/microblaze-v-virt.cnew file mode 100644 index 00000000000..6603e6d6b06hw/riscv/microblaze-v-virt.c new file +2
-0@@ -0,0 +1,181 @@ +/* +* QEMU model of Microblaze V (32bit version) Is there a 64-bit model planned?
Quoted 2 lines
This guide is talking about 64bit too
https://docs.amd.com/r/en-US/ug1629-microblaze-v-user-guideSame board, different core (synthesized with
C_DATA_SIZE= 64).Quoted 10 lines
It means answer is yes. And pretty much this generic model with the same layout should be possible to use with generic 64bit version too.
I expect that means that
default_cpu_typeshould beTYPE_RISCV_CPU_BASE. andKconfigshould be extended
+ depends on RISCV32 || RISCV64Also some small updates in documentation to cover it.
Is there something else what should be updated?
No issue, I was just checking.
Regards,
Phil.