riscv-to-apply queue
Subsystems (2)
From: Alistair Francis <[email protected]>
The following changes since commit 239b8b0699a222fd21da1c5fdeba0a2456085a47:
Merge tag 'trivial-branch-for-8.0-pull-request' of https://gitlab.com/laurent_vivier/qemu into staging (2023-01-19 15:05:29 +0000)
are available in the Git repository at:
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20230120
for you to fetch changes up to b748352c555b42d497fe8ee00ee2e44eb8627660:
hw/riscv/virt.c: move create_fw_cfg() back to virt_machine_init() (2023-01-20 10:14:14 +1000)
----------------------------------------------------------------
Second RISC-V PR for QEMU 8.0
* riscv_htif: Support console output via proxy syscall
* Cleanup firmware and device tree loading
* Fix elen check when using vector extensions
* add RISC-V OpenSBI boot test
* Ensure we always follow MISA parsing
* Fix up masking of vsip/vsie accesses
* Trap on writes to stimecmp from VS when hvictl.VTI=1
* Introduce helper_set_rounding_mode_chkfrm
----------------------------------------------------------------
Andrew Bresticker (2):
target/riscv: Fix up masking of vsip/vsie accesses target/riscv: Trap on writes to stimecmp from VS when hvictl.VTI=1
Bin Meng (11):
hw/char: riscv_htif: Avoid using magic numbers
hw/char: riscv_htif: Drop {to, from}host_size in HTIFState hw/char: riscv_htif: Drop useless assignment of memory region hw/char: riscv_htif: Use conventional 's' for HTIFState hw/char: riscv_htif: Move registers from CPUArchState to HTIFState hw/char: riscv_htif: Remove forward declarations for non-existent variables hw/char: riscv_htif: Support console output via proxy syscall hw/riscv: spike: Remove the out-of-date comments hw/riscv/boot.c: Introduce riscv_find_firmware()
hw/riscv: spike: Decouple create_fdt() dependency to ELF loading target/riscv: Use TARGET_FMT_lx for env->mhartid
Daniel Henrique Barboza (20):
hw/riscv/boot.c: make riscv_find_firmware() static hw/riscv/boot.c: introduce riscv_default_firmware_name() tests/avocado: add RISC-V OpenSBI boot test
hw/riscv/spike: use 'fdt' from MachineState hw/riscv/sifive_u: use 'fdt' from MachineState hw/riscv/boot.c: exit early if filename is NULL in load functions hw/riscv/spike.c: load initrd right after riscv_load_kernel() hw/riscv: write initrd 'chosen' FDT inside riscv_load_initrd() hw/riscv: write bootargs 'chosen' FDT after riscv_load_kernel() hw/riscv/boot.c: use MachineState in riscv_load_initrd() hw/riscv/boot.c: use MachineState in riscv_load_kernel() target/riscv/cpu: set cpu->cfg in register_cpu_props() target/riscv/cpu.c: do not skip misa logic in riscv_cpu_realize() hw/riscv/spike.c: simplify create_fdt()
hw/riscv/virt.c: simplify create_fdt()
hw/riscv/sifive_u.c: simplify create_fdt()
hw/riscv/virt.c: remove 'is_32_bit' param from create_fdt_socket_cpus() hw/riscv: use MachineState::fdt in riscv_socket_fdt_write_id() hw/riscv: use ms->fdt in riscv_socket_fdt_write_distance_matrix() hw/riscv/virt.c: move create_fw_cfg() back to virt_machine_init()
Dongxue Zhang (1):
target/riscv/cpu.c: Fix elen check
Richard Henderson (3):
tcg/riscv: Use tcg_pcrel_diff in tcg_out_ldst target/riscv: Introduce helper_set_rounding_mode_chkfrm target/riscv: Remove helper_set_rod_rounding_mode
include/hw/char/riscv_htif.h | 19 +- include/hw/riscv/boot.h | 9 +- include/hw/riscv/numa.h | 10 +- include/hw/riscv/sifive_u.h | 3 - include/hw/riscv/spike.h | 2 - target/riscv/cpu.h | 8 +- target/riscv/helper.h | 2 +- hw/char/riscv_htif.c | 172 +++++++----- hw/riscv/boot.c | 105 +++++--- hw/riscv/microchip_pfsoc.c | 12 +- hw/riscv/numa.c | 14 +- hw/riscv/opentitan.c | 3 +- hw/riscv/sifive_e.c | 3 +- hw/riscv/sifive_u.c | 53 ++-- hw/riscv/spike.c | 108 ++++---- hw/riscv/virt.c | 86 +++--- target/riscv/cpu.c | 445 ++++++++++++++++++-------------- target/riscv/csr.c | 41 ++- target/riscv/fpu_helper.c | 36 ++- target/riscv/machine.c | 6 +- target/riscv/translate.c | 21 +- target/riscv/insn_trans/trans_rvv.c.inc | 24 +- tcg/riscv/tcg-target.c.inc | 2 +- tests/avocado/riscv_opensbi.py | 65 +++++ 24 files changed, 713 insertions(+), 536 deletions(-) create mode 100644 tests/avocado/riscv_opensbi.py
[PULL 01/37] hw/char: riscv_htif: Avoid using magic numbers
From: Bin Meng <[email protected]>
The Spike HTIF is poorly documented. The only relevant info we can get from the internet is from Andrew Waterman at [1].
Add a comment block before htif_handle_tohost_write() to explain the tohost register format, and use meaningful macros instead of magic numbers in the codes.
While we are here, correct 2 multi-line comment blocks that have wrong format.
Message-Id: <[email protected]>
--- hw/char/riscv_htif.c | 72 ++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 20 deletions(-)
hw/char/riscv_htif.c +52 -20
@@ -38,6 +38,16 @@ } \ } while (0) +#define HTIF_DEV_SHIFT 56 +#define HTIF_CMD_SHIFT 48 + +#define HTIF_DEV_SYSTEM 0 +#define HTIF_DEV_CONSOLE 1 + +#define HTIF_SYSTEM_CMD_SYSCALL 0 +#define HTIF_CONSOLE_CMD_GETC 0 +#define HTIF_CONSOLE_CMD_PUTC 1 +static uint64_t fromhost_addr, tohost_addr;static int address_symbol_set;
@@ -81,9 +91,11 @@ static void htif_recv(void *opaque, const uint8_t *buf, int size)return ; } -/* TODO - we need to check whether mfromhost is zero which indicates -the device is ready to receive. The current implementation -will drop characters */ +/* +* TODO - we need to check whether mfromhost is zero which indicates +* the device is ready to receive. The current implementation +* will drop characters +*/ uint64_t val_written = htifstate->pending_read;uint64_t resp =0x100 | *buf;
@@ -110,10 +122,30 @@ static int htif_be_change(void *opaque)return 0 ; } +/* +* See below the tohost register format. +* +* Bits 63:56 indicate the "device". +* Bits 55:48 indicate the "command". +* +* Device 0 is the syscall device, which is used to emulate Unixy syscalls. +* It only implements command 0, which has two subfunctions: +* - If bit 0 is clear, then bits 47:0 represent a pointer to a struct +* describing the syscall. +* - If bit 1 is set, then bits 47:1 represent an exit code, with a zero +* value indicating success and other values indicating failure. +* +* Device 1 is the blocking character device. +* - Command 0 reads a character +* - Command 1 writes a character from the 8 LSBs of tohost +* +* For RV32, the tohost register is zero-extended, so only device=0 and +* command=0 (i.e. HTIF syscalls/exit codes) are supported. +*/ static void htif_handle_tohost_write (HTIFState *htifstate,uint64_t val_written) { -uint8_t device = val_written >>56 ; -uint8_t cmd = val_written >>48 ; +uint8_t device = val_written >>HTIF_DEV_SHIFT ; +uint8_t cmd = val_written >>HTIF_CMD_SHIFT ;uint64_t payload = val_written &0xFFFFFFFFFFFFULL ;int resp =0 ;
@@ -125,9 +157,9 @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written)* 0: riscv-tests Pass/Fail Reporting Only (no syscall proxy) * 1: Console */ -if (unlikely (device ==0x0 )) { +if (unlikely (device ==HTIF_DEV_SYSTEM )) {/* frontend syscall handler, shutdown and exit code support */ -if (cmd ==0x0 ) { +if (cmd ==HTIF_SYSTEM_CMD_SYSCALL ) {if (payload &0x1 ) {/* exit code */ int exit_code = payload >>1 ;
@@ -138,14 +170,14 @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written) }else {qemu_log ("HTIF device %d: unknown command\n" , device); } - }else if (likely (device ==0x1 )) { + }else if (likely (device ==HTIF_DEV_CONSOLE )) {/* HTIF Console */ -if (cmd ==0x0 ) { +if (cmd ==HTIF_CONSOLE_CMD_GETC ) {/* this should be a queue, but not yet implemented as such */ htifstate->pending_read = val_written; htifstate->env->mtohost =0 ;/* clear to indicate we read */ return ; - }else if (cmd ==0x1 ) { + }else if (cmd ==HTIF_CONSOLE_CMD_PUTC ) {qemu_chr_fe_write (&htifstate->chr, (uint8_t *)&payload,1 ); resp =0x100 | (uint8_t )payload; }else {
@@ -157,15 +189,15 @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written) " payload: %016" PRIx64, device, cmd, payload & 0xFF, payload); }/* -* - latest bbl does not set fromhost to 0 if there is a value in tohost -* - with this code enabled, qemu hangs waiting for fromhost to go to 0 -* - with this code disabled, qemu works with bbl priv v1.9.1 and v1.10 -* - HTIF needs protocol documentation and a more complete state machine - -while (!htifstate->fromhost_inprogress && -htifstate->env->mfromhost != 0x0) { -} -*/ +* Latest bbl does not set fromhost to 0 if there is a value in tohost. +* With this code enabled, qemu hangs waiting for fromhost to go to 0. +* With this code disabled, qemu works with bbl priv v1.9.1 and v1.10. +* HTIF needs protocol documentation and a more complete state machine. +* +* while (!htifstate->fromhost_inprogress && +* htifstate->env->mfromhost != 0x0) { +* } +*/ htifstate->env->mfromhost = (val_written >>48 <<48 ) | (resp <<16 >>16 ); htifstate->env->mtohost =0 ;/* clear to indicate we read */ }
@@ -196,7 +228,7 @@ static uint64_t htif_mm_read(void *opaque, hwaddr addr, unsigned size)/* CPU wrote to an HTIF register */ static void htif_mm_write (void *opaque,hwaddr addr, -uint64_t value,unsigned size) +uint64_t value,unsigned size) {HTIFState *htifstate = opaque;if (addr ==TOHOST_OFFSET1 ) {
Signature · 1 line
2.39.0
[PULL 03/37] hw/char: riscv_htif: Drop useless assignment of memory region
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
struct HTIFState has 3 members for address space and memory region, and are initialized during htif_mm_init(). But they are actually useless. Drop them.
Message-Id: <[email protected]>
--- include/hw/char/riscv_htif.h | 7 ++----- hw/char/riscv_htif.c | 7 ++----- hw/riscv/spike.c | 5 ++--- 3 files changed, 6 insertions(+), 13 deletions(-)
include/hw/char/riscv_htif.h +2 -5
@@ -34,9 +34,6 @@ typedef struct HTIFState {hwaddr tohost_offset;hwaddr fromhost_offset;MemoryRegion mmio; -MemoryRegion *address_space; -MemoryRegion *main_mem; -void *main_mem_ram_ptr;CPURISCVState *env;CharBackend chr;
@@ -54,7 +51,7 @@ void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value,bool htif_uses_elf_symbols (void );/* legacy pre qom */ -HTIFState *htif_mm_init (MemoryRegion *address_space,MemoryRegion *main_mem, -CPURISCVState *env,Chardev *chr,uint64_t nonelf_base); +HTIFState *htif_mm_init (MemoryRegion *address_space,CPURISCVState *env, +Chardev *chr,uint64_t nonelf_base);#endif
hw/char/riscv_htif.c +2 -5
@@ -265,8 +265,8 @@ bool htif_uses_elf_symbols(void)return (address_symbol_set ==3 ) ? true : false; } -HTIFState *htif_mm_init (MemoryRegion *address_space,MemoryRegion *main_mem, -CPURISCVState *env,Chardev *chr,uint64_t nonelf_base) +HTIFState *htif_mm_init (MemoryRegion *address_space,CPURISCVState *env, +Chardev *chr,uint64_t nonelf_base) {uint64_t base, size, tohost_offset, fromhost_offset;
@@ -281,9 +281,6 @@ HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem, fromhost_offset = fromhost_addr - base;HTIFState *s =g_new0 (HTIFState,1 ); - s->address_space = address_space; - s->main_mem = main_mem; - s->main_mem_ram_ptr =memory_region_get_ram_ptr (main_mem); s->env = env; s->tohost_offset = tohost_offset; s->fromhost_offset = fromhost_offset;
hw/riscv/spike.c +2 -3
@@ -316,9 +316,8 @@ static void spike_board_init(MachineState *machine) fdt_load_addr);/* initialize HTIF using symbols found in load_kernel */ -htif_mm_init (system_memory, mask_rom, - &s->soc[0 ].harts[0 ].env,serial_hd (0 ), - memmap[SPIKE_HTIF ].base); +htif_mm_init (system_memory, &s->soc[0 ].harts[0 ].env, +serial_hd (0 ), memmap[SPIKE_HTIF ].base); }static void spike_machine_instance_init (Object *obj)
Signature · 1 line
2.39.0
[PULL 14/37] tests/avocado: add RISC-V OpenSBI boot test
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
This test is used to do a quick sanity check to ensure that we're able to run the existing QEMU FW image.
'sifive_u', 'spike' and 'virt' riscv64 machines, and 'sifive_u' and 'virt' 32 bit machines are able to run the default RISCV64_BIOS_BIN | RISCV32_BIOS_BIN firmware with minimal options.
The riscv32 'spike' machine isn't bootable at this moment, requiring an OpenSBI fix [1] and QEMU side changes [2]. We could just leave at that or add a 'skip' test to remind us about it. To work as a reminder that we have a riscv32 'spike' test that should be enabled as soon as OpenSBI QEMU rom receives the fix, we're adding a 'skip' test:
(06/18) tests/avocado/riscv_opensbi.py:RiscvOpenSBI.test_riscv32_spike:
SKIP: requires OpenSBI fix to work
[1] https://patchwork.ozlabs.org/project/opensbi/patch/[email protected]/
[2] https://patchwork.ozlabs.org/project/qemu-devel/list/?series=334159
Message-Id: <[email protected]>
--- tests/avocado/riscv_opensbi.py | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/avocado/riscv_opensbi.py
tests/avocado/riscv_opensbi.py new file +65 -0
@@ -0,0 +1,65 @@ +# OpenSBI boot test for RISC-V machines +# +# Copyright (c) 2022, Ventana Micro +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +from avocado_qemu import QemuSystemTest +from avocado import skip +from avocado_qemu import wait_for_console_pattern + +class RiscvOpenSBI(QemuSystemTest): + """ + :avocado: tags=accel:tcg + """ + timeout = 5 + + def boot_opensbi(self): + self.vm.set_console() + self.vm.launch() + wait_for_console_pattern(self, 'Platform Name') + wait_for_console_pattern(self, 'Boot HART MEDELEG') + + @skip("requires OpenSBI fix to work") + def test_riscv32_spike(self): + """ + :avocado: tags=arch:riscv32 + :avocado: tags=machine:spike + """ + self.boot_opensbi() + + def test_riscv64_spike(self): + """ + :avocado: tags=arch:riscv64 + :avocado: tags=machine:spike + """ + self.boot_opensbi() + + def test_riscv32_sifive_u(self): + """ + :avocado: tags=arch:riscv32 + :avocado: tags=machine:sifive_u + """ + self.boot_opensbi() + + def test_riscv64_sifive_u(self): + """ + :avocado: tags=arch:riscv64 + :avocado: tags=machine:sifive_u + """ + self.boot_opensbi() + + def test_riscv32_virt(self): + """ + :avocado: tags=arch:riscv32 + :avocado: tags=machine:virt + """ + self.boot_opensbi() + + def test_riscv64_virt(self): + """ + :avocado: tags=arch:riscv64 + :avocado: tags=machine:virt + """ + self.boot_opensbi()
Signature · 1 line
2.39.0
[PULL 06/37] hw/char: riscv_htif: Remove forward declarations for non-existent variables
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
There are forward declarations for 'vmstate_htif' and 'htif_io_ops' in riscv_htif.h however there are no definitions in the C codes.
Message-Id: <[email protected]>
--- include/hw/char/riscv_htif.h | 3 --- 1 file changed, 3 deletions(-)
include/hw/char/riscv_htif.h +0 -3
@@ -40,9 +40,6 @@ typedef struct HTIFState {uint64_t pending_read; } HTIFState; -extern const VMStateDescription vmstate_htif; -extern const MemoryRegionOps htif_io_ops; -/* HTIF symbol callback */ void htif_symbol_callback (const char *st_name,int st_info,uint64_t st_value,uint64_t st_size);
Signature · 1 line
2.39.0
[PULL 07/37] hw/char: riscv_htif: Support console output via proxy syscall
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
At present the HTIF proxy syscall is unsupported. On RV32, only device 0 is supported so there is no console device for RV32. The only way to implement console funtionality on RV32 is to support the SYS_WRITE syscall.
With this commit, the Spike machine is able to boot the 32-bit OpenSBI generic image.
Message-Id: <[email protected]>
--- hw/char/riscv_htif.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
hw/char/riscv_htif.c +16 -1
@@ -48,6 +48,9 @@#define HTIF_CONSOLE_CMD_GETC 0#define HTIF_CONSOLE_CMD_PUTC 1 +/* PK system call number */ +#define PK_SYS_WRITE 64 +static uint64_t fromhost_addr, tohost_addr;static int address_symbol_set;
@@ -165,7 +168,19 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written)int exit_code = payload >>1 ;exit (exit_code); }else { -qemu_log_mask (LOG_UNIMP ,"pk syscall proxy not supported\n" ); +uint64_t syscall[8 ]; +cpu_physical_memory_read (payload, syscall,sizeof (syscall)); +if (syscall[0 ] ==PK_SYS_WRITE && + syscall[1 ] ==HTIF_DEV_CONSOLE && + syscall[3 ] ==HTIF_CONSOLE_CMD_PUTC ) { +uint8_t ch; +cpu_physical_memory_read (syscall[2 ], &ch,1 ); +qemu_chr_fe_write (&s->chr, &ch,1 ); + resp =0x100 | (uint8_t )payload; + }else { +qemu_log_mask (LOG_UNIMP , +"pk syscall proxy not supported\n" ); + } } }else {qemu_log ("HTIF device %d: unknown command\n" , device);
Signature · 1 line
2.39.0
[PULL 05/37] hw/char: riscv_htif: Move registers from CPUArchState to HTIFState
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
At present for some unknown reason the HTIF registers (fromhost & tohost) are defined in the RISC-V CPUArchState. It should really be put in the HTIFState struct as it is only meaningful to HTIF.
Message-Id: <[email protected]>
--- include/hw/char/riscv_htif.h | 8 ++++---- target/riscv/cpu.h | 4 ---- hw/char/riscv_htif.c | 35 +++++++++++++++++------------------ hw/riscv/spike.c | 3 +-- target/riscv/machine.c | 6 ++---- 5 files changed, 24 insertions(+), 32 deletions(-)
include/hw/char/riscv_htif.h +4 -4
@@ -23,7 +23,6 @@#include "chardev/char.h" #include "chardev/char-fe.h" #include "exec/memory.h" -#include "target/riscv/cpu.h" #define TYPE_HTIF_UART "riscv.htif.uart"
@@ -31,11 +30,12 @@ typedef struct HTIFState {int allow_tohost;int fromhost_inprogress; +uint64_t tohost; +uint64_t fromhost;hwaddr tohost_offset;hwaddr fromhost_offset;MemoryRegion mmio; -CPURISCVState *env;CharBackend chr;uint64_t pending_read; } HTIFState;
@@ -51,7 +51,7 @@ void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value,bool htif_uses_elf_symbols (void );/* legacy pre qom */ -HTIFState *htif_mm_init (MemoryRegion *address_space,CPURISCVState *env, -Chardev *chr,uint64_t nonelf_base); +HTIFState *htif_mm_init (MemoryRegion *address_space,Chardev *chr, +uint64_t nonelf_base);#endif
target/riscv/cpu.h +0 -4
@@ -309,10 +309,6 @@ struct CPUArchState {target_ulong sscratch;target_ulong mscratch; -/* temporary htif regs */ -uint64_t mfromhost; -uint64_t mtohost; -/* Sstc CSRs */ uint64_t stimecmp;
hw/char/riscv_htif.c +17 -18
@@ -100,7 +100,7 @@ static void htif_recv(void *opaque, const uint8_t *buf, int size)uint64_t val_written = s->pending_read;uint64_t resp =0x100 | *buf; - s->env->mfromhost = (val_written >>48 <<48 ) | (resp <<16 >>16 ); + s->fromhost = (val_written >>48 <<48 ) | (resp <<16 >>16 ); }/*
@@ -175,7 +175,7 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written)if (cmd ==HTIF_CONSOLE_CMD_GETC ) {/* this should be a queue, but not yet implemented as such */ s->pending_read = val_written; - s->env->mtohost =0 ;/* clear to indicate we read */ + s->tohost =0 ;/* clear to indicate we read */ return ; }else if (cmd ==HTIF_CONSOLE_CMD_PUTC ) {qemu_chr_fe_write (&s->chr, (uint8_t *)&payload,1 );
@@ -195,11 +195,11 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written)* HTIF needs protocol documentation and a more complete state machine. * * while (!s->fromhost_inprogress && -* s->env->mfromhost != 0x0) { +* s->fromhost != 0x0) { * } */ - s->env->mfromhost = (val_written >>48 <<48 ) | (resp <<16 >>16 ); - s->env->mtohost =0 ;/* clear to indicate we read */ + s->fromhost = (val_written >>48 <<48 ) | (resp <<16 >>16 ); + s->tohost =0 ;/* clear to indicate we read */ }#define TOHOST_OFFSET1 (s->tohost_offset)
@@ -212,13 +212,13 @@ static uint64_t htif_mm_read(void *opaque, hwaddr addr, unsigned size) {HTIFState *s = opaque;if (addr ==TOHOST_OFFSET1 ) { -return s->env->mtohost &0xFFFFFFFF ; +return s->tohost &0xFFFFFFFF ; }else if (addr ==TOHOST_OFFSET2 ) { -return (s->env->mtohost >>32 ) &0xFFFFFFFF ; +return (s->tohost >>32 ) &0xFFFFFFFF ; }else if (addr ==FROMHOST_OFFSET1 ) { -return s->env->mfromhost &0xFFFFFFFF ; +return s->fromhost &0xFFFFFFFF ; }else if (addr ==FROMHOST_OFFSET2 ) { -return (s->env->mfromhost >>32 ) &0xFFFFFFFF ; +return (s->fromhost >>32 ) &0xFFFFFFFF ; }else {qemu_log ("Invalid htif read: address %016" PRIx64"\n" , (uint64_t )addr);
@@ -232,22 +232,22 @@ static void htif_mm_write(void *opaque, hwaddr addr, {HTIFState *s = opaque;if (addr ==TOHOST_OFFSET1 ) { -if (s->env->mtohost ==0x0 ) { +if (s->tohost ==0x0 ) { s->allow_tohost =1 ; - s->env->mtohost = value &0xFFFFFFFF ; + s->tohost = value &0xFFFFFFFF ; }else { s->allow_tohost =0 ; } }else if (addr ==TOHOST_OFFSET2 ) {if (s->allow_tohost) { - s->env->mtohost |= value <<32 ; -htif_handle_tohost_write (s, s->env->mtohost); + s->tohost |= value <<32 ; +htif_handle_tohost_write (s, s->tohost); } }else if (addr ==FROMHOST_OFFSET1 ) { s->fromhost_inprogress =1 ; - s->env->mfromhost = value &0xFFFFFFFF ; + s->fromhost = value &0xFFFFFFFF ; }else if (addr ==FROMHOST_OFFSET2 ) { - s->env->mfromhost |= value <<32 ; + s->fromhost |= value <<32 ; s->fromhost_inprogress =0 ; }else { qemu_log("Invalid htif write: address %016" PRIx64 "\n",
@@ -265,8 +265,8 @@ bool htif_uses_elf_symbols(void)return (address_symbol_set ==3 ) ? true : false; } -HTIFState *htif_mm_init (MemoryRegion *address_space,CPURISCVState *env, -Chardev *chr,uint64_t nonelf_base) +HTIFState *htif_mm_init (MemoryRegion *address_space,Chardev *chr, +uint64_t nonelf_base) {uint64_t base, size, tohost_offset, fromhost_offset;
@@ -281,7 +281,6 @@ HTIFState *htif_mm_init(MemoryRegion *address_space, CPURISCVState *env, fromhost_offset = fromhost_addr - base;HTIFState *s =g_new0 (HTIFState,1 ); - s->env = env; s->tohost_offset = tohost_offset; s->fromhost_offset = fromhost_offset; s->pending_read =0 ;
hw/riscv/spike.c +1 -2
@@ -316,8 +316,7 @@ static void spike_board_init(MachineState *machine) fdt_load_addr);/* initialize HTIF using symbols found in load_kernel */ -htif_mm_init (system_memory, &s->soc[0 ].harts[0 ].env, -serial_hd (0 ), memmap[SPIKE_HTIF ].base); +htif_mm_init (system_memory,serial_hd (0 ), memmap[SPIKE_HTIF ].base); }static void spike_machine_instance_init (Object *obj)
target/riscv/machine.c +2 -4
@@ -333,8 +333,8 @@ static const VMStateDescription vmstate_pmu_ctr_state = {const VMStateDescription vmstate_riscv_cpu = { .name ="cpu" , - .version_id =5 , - .minimum_version_id =5 , + .version_id =6 , + .minimum_version_id =6 , .post_load = riscv_cpu_post_load, .fields = (VMStateField []) {VMSTATE_UINTTL_ARRAY (env.gpr,RISCVCPU ,32 ),
@@ -384,8 +384,6 @@ const VMStateDescription vmstate_riscv_cpu = {VMSTATE_UINTTL_ARRAY (env.mhpmeventh_val,RISCVCPU ,RV_MAX_MHPMEVENTS ),VMSTATE_UINTTL (env.sscratch,RISCVCPU ),VMSTATE_UINTTL (env.mscratch,RISCVCPU ), -VMSTATE_UINT64 (env.mfromhost,RISCVCPU ), -VMSTATE_UINT64 (env.mtohost,RISCVCPU ),VMSTATE_UINT64 (env.stimecmp,RISCVCPU ),VMSTATE_END_OF_LIST ()
Signature · 1 line
2.39.0
[PULL 04/37] hw/char: riscv_htif: Use conventional 's' for HTIFState
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
QEMU source codes tend to use 's' to represent the hardware state. Let's use it for HTIFState.
Message-Id: <[email protected]>
--- hw/char/riscv_htif.c | 64 ++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 32 deletions(-)
hw/char/riscv_htif.c +32 -32
@@ -85,7 +85,7 @@ static int htif_can_recv(void *opaque)*/ static void htif_recv (void *opaque,const uint8_t *buf,int size) { -HTIFState *htifstate = opaque; +HTIFState *s = opaque;if (size !=1 ) {return ;
@@ -97,10 +97,10 @@ static void htif_recv(void *opaque, const uint8_t *buf, int size)* will drop characters */ -uint64_t val_written = htifstate->pending_read; +uint64_t val_written = s->pending_read;uint64_t resp =0x100 | *buf; - htifstate->env->mfromhost = (val_written >>48 <<48 ) | (resp <<16 >>16 ); + s->env->mfromhost = (val_written >>48 <<48 ) | (resp <<16 >>16 ); }/*
@@ -142,7 +142,7 @@ static int htif_be_change(void *opaque)* For RV32, the tohost register is zero-extended, so only device=0 and * command=0 (i.e. HTIF syscalls/exit codes) are supported. */ -static void htif_handle_tohost_write (HTIFState *htifstate,uint64_t val_written) +static void htif_handle_tohost_write (HTIFState *s,uint64_t val_written) {uint8_t device = val_written >>HTIF_DEV_SHIFT ;uint8_t cmd = val_written >>HTIF_CMD_SHIFT ;
@@ -174,11 +174,11 @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written)/* HTIF Console */ if (cmd ==HTIF_CONSOLE_CMD_GETC ) {/* this should be a queue, but not yet implemented as such */ - htifstate->pending_read = val_written; - htifstate->env->mtohost =0 ;/* clear to indicate we read */ + s->pending_read = val_written; + s->env->mtohost =0 ;/* clear to indicate we read */ return ; }else if (cmd ==HTIF_CONSOLE_CMD_PUTC ) { -qemu_chr_fe_write (&htifstate->chr, (uint8_t *)&payload,1 ); +qemu_chr_fe_write (&s->chr, (uint8_t *)&payload,1 ); resp =0x100 | (uint8_t )payload; }else {qemu_log ("HTIF device %d: unknown command\n" , device);
@@ -194,31 +194,31 @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written)* With this code disabled, qemu works with bbl priv v1.9.1 and v1.10. * HTIF needs protocol documentation and a more complete state machine. * -* while (!htifstate->fromhost_inprogress && -* htifstate->env->mfromhost != 0x0) { +* while (!s->fromhost_inprogress && +* s->env->mfromhost != 0x0) { * } */ - htifstate->env->mfromhost = (val_written >>48 <<48 ) | (resp <<16 >>16 ); - htifstate->env->mtohost =0 ;/* clear to indicate we read */ + s->env->mfromhost = (val_written >>48 <<48 ) | (resp <<16 >>16 ); + s->env->mtohost =0 ;/* clear to indicate we read */ } -#define TOHOST_OFFSET1 (htifstate->tohost_offset) -#define TOHOST_OFFSET2 (htifstate->tohost_offset + 4) -#define FROMHOST_OFFSET1 (htifstate->fromhost_offset) -#define FROMHOST_OFFSET2 (htifstate->fromhost_offset + 4) +#define TOHOST_OFFSET1 (s->tohost_offset) +#define TOHOST_OFFSET2 (s->tohost_offset + 4) +#define FROMHOST_OFFSET1 (s->fromhost_offset) +#define FROMHOST_OFFSET2 (s->fromhost_offset + 4)/* CPU wants to read an HTIF register */ static uint64_t htif_mm_read (void *opaque,hwaddr addr,unsigned size) { -HTIFState *htifstate = opaque; +HTIFState *s = opaque;if (addr ==TOHOST_OFFSET1 ) { -return htifstate->env->mtohost &0xFFFFFFFF ; +return s->env->mtohost &0xFFFFFFFF ; }else if (addr ==TOHOST_OFFSET2 ) { -return (htifstate->env->mtohost >>32 ) &0xFFFFFFFF ; +return (s->env->mtohost >>32 ) &0xFFFFFFFF ; }else if (addr ==FROMHOST_OFFSET1 ) { -return htifstate->env->mfromhost &0xFFFFFFFF ; +return s->env->mfromhost &0xFFFFFFFF ; }else if (addr ==FROMHOST_OFFSET2 ) { -return (htifstate->env->mfromhost >>32 ) &0xFFFFFFFF ; +return (s->env->mfromhost >>32 ) &0xFFFFFFFF ; }else {qemu_log ("Invalid htif read: address %016" PRIx64"\n" , (uint64_t )addr);
@@ -230,25 +230,25 @@ static uint64_t htif_mm_read(void *opaque, hwaddr addr, unsigned size)static void htif_mm_write (void *opaque,hwaddr addr,uint64_t value,unsigned size) { -HTIFState *htifstate = opaque; +HTIFState *s = opaque;if (addr ==TOHOST_OFFSET1 ) { -if (htifstate->env->mtohost ==0x0 ) { - htifstate->allow_tohost =1 ; - htifstate->env->mtohost = value &0xFFFFFFFF ; +if (s->env->mtohost ==0x0 ) { + s->allow_tohost =1 ; + s->env->mtohost = value &0xFFFFFFFF ; }else { - htifstate->allow_tohost =0 ; + s->allow_tohost =0 ; } }else if (addr ==TOHOST_OFFSET2 ) { -if (htifstate->allow_tohost) { - htifstate->env->mtohost |= value <<32 ; -htif_handle_tohost_write (htifstate, htifstate->env->mtohost); +if (s->allow_tohost) { + s->env->mtohost |= value <<32 ; +htif_handle_tohost_write (s, s->env->mtohost); } }else if (addr ==FROMHOST_OFFSET1 ) { - htifstate->fromhost_inprogress =1 ; - htifstate->env->mfromhost = value &0xFFFFFFFF ; + s->fromhost_inprogress =1 ; + s->env->mfromhost = value &0xFFFFFFFF ; }else if (addr ==FROMHOST_OFFSET2 ) { - htifstate->env->mfromhost |= value <<32 ; - htifstate->fromhost_inprogress =0 ; + s->env->mfromhost |= value <<32 ; + s->fromhost_inprogress =0 ; }else {qemu_log ("Invalid htif write: address %016" PRIx64"\n" , (uint64_t )addr);
Signature · 1 line
2.39.0
[PULL 15/37] hw/riscv/spike: use 'fdt' from MachineState
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
The MachineState object provides a 'fdt' pointer that is already being used by other RISC-V machines, and it's also used by the 'dumpdtb' QMP command.
Remove the 'fdt' pointer from SpikeState and use MachineState::fdt instead.
Message-Id: <[email protected]>
--- include/hw/riscv/spike.h | 2 -- hw/riscv/spike.c | 12 +++++------- 2 files changed, 5 insertions(+), 9 deletions(-)
include/hw/riscv/spike.h +0 -2
@@ -37,8 +37,6 @@ struct SpikeState {/*< public >*/ RISCVHartArrayState soc[SPIKE_SOCKETS_MAX ]; -void *fdt; -int fdt_size; };enum {
hw/riscv/spike.c +5 -7
@@ -53,6 +53,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, bool is_32_bit, bool htif_custom_base) {void *fdt; +int fdt_size;uint64_t addr, size;unsigned long clint_addr;int cpu, socket;
@@ -65,7 +66,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, "sifive,clint0", "riscv,clint0" }; - fdt = s->fdt =create_device_tree (&s->fdt_size); + fdt = mc->fdt =create_device_tree (&fdt_size);if (!fdt) {error_report ("create_device_tree() failed" );exit (1 );
@@ -327,18 +328,15 @@ static void spike_board_init(MachineState *machine)hwaddr end =riscv_load_initrd (machine->initrd_filename, machine->ram_size, kernel_entry, &start); -qemu_fdt_setprop_cell (s->fdt,"/chosen" , +qemu_fdt_setprop_cell (machine->fdt,"/chosen" ,"linux,initrd-start" , start); -qemu_fdt_setprop_cell (s->fdt,"/chosen" ,"linux,initrd-end" , +qemu_fdt_setprop_cell (machine->fdt,"/chosen" ,"linux,initrd-end" , end); }/* Compute the fdt load address in dram */ fdt_load_addr =riscv_load_fdt (memmap[SPIKE_DRAM ].base, - machine->ram_size, s->fdt); - -/* Set machine->fdt for 'dumpdtb' QMP/HMP command */ - machine->fdt = s->fdt; + machine->ram_size, machine->fdt);/* load the reset vector */ riscv_setup_rom_reset_vec(machine, &s->soc[0], memmap[SPIKE_DRAM].base,
Signature · 1 line
2.39.0
[PULL 18/37] hw/riscv/spike.c: load initrd right after riscv_load_kernel()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
This will make the code more in line with what the other boards are doing. We'll also avoid an extra check to machine->kernel_filename since we already checked that before executing riscv_load_kernel().
Message-Id: <[email protected]>
--- hw/riscv/spike.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
hw/riscv/spike.c +15 -16
@@ -302,6 +302,10 @@ static void spike_board_init(MachineState *machine)g_free (firmware_name); } +/* Create device tree */ +create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, +riscv_is_32bit (&s->soc[0 ]), htif_custom_base); +/* Load kernel */ if (machine->kernel_filename) { kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0],
@@ -310,6 +314,17 @@ static void spike_board_init(MachineState *machine) kernel_entry =riscv_load_kernel (machine->kernel_filename, kernel_start_addr, htif_symbol_callback); + +if (machine->initrd_filename) { +hwaddr start; +hwaddr end =riscv_load_initrd (machine->initrd_filename, + machine->ram_size, kernel_entry, + &start); +qemu_fdt_setprop_cell (machine->fdt,"/chosen" , +"linux,initrd-start" , start); +qemu_fdt_setprop_cell (machine->fdt,"/chosen" ,"linux,initrd-end" , + end); + } }else {/* * If dynamic firmware is used, it doesn't know where is the next mode
@@ -318,22 +333,6 @@ static void spike_board_init(MachineState *machine) kernel_entry =0 ; } -/* Create device tree */ -create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, -riscv_is_32bit (&s->soc[0 ]), htif_custom_base); - -/* Load initrd */ -if (machine->kernel_filename && machine->initrd_filename) { -hwaddr start; -hwaddr end =riscv_load_initrd (machine->initrd_filename, - machine->ram_size, kernel_entry, - &start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" , -"linux,initrd-start" , start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" ,"linux,initrd-end" , - end); - } -/* Compute the fdt load address in dram */ fdt_load_addr =riscv_load_fdt (memmap[SPIKE_DRAM ].base, machine->ram_size, machine->fdt);
Signature · 1 line
2.39.0
[PULL 09/37] hw/riscv/boot.c: make riscv_find_firmware() static
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
The only caller is riscv_find_and_load_firmware(), which is in the same file.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- include/hw/riscv/boot.h | 1 - hw/riscv/boot.c | 44 ++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 23 deletions(-)
include/hw/riscv/boot.h +0 -1
@@ -37,7 +37,6 @@ target_ulong riscv_find_and_load_firmware(MachineState *machine,const char *default_machine_firmware, hwaddr firmware_load_addr, symbol_fn_t sym_cb); -char *riscv_find_firmware (const char *firmware_filename);target_ulong riscv_load_firmware (const char *firmware_filename,hwaddr firmware_load_addr,symbol_fn_t sym_cb);
hw/riscv/boot.c +22 -22
56 lines not on this page · raw message
Signature · 1 line
2.39.0
[PULL 13/37] target/riscv/cpu.c: Fix elen check
In reply to Alistair FrancisFrom: Dongxue Zhang <[email protected]>
The elen check should be cpu->cfg.elen in range [8, 64].
Message-Id: <[email protected]> [ Changes by AF:
- Tidy up commit message
]
--- target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
@@ -882,7 +882,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "Vector extension ELEN must be power of 2");return ; } -if (cpu->cfg.elen >64 || cpu->cfg.vlen <8 ) { +if (cpu->cfg.elen >64 || cpu->cfg.elen <8 ) {error_setg (errp,"Vector extension implementation only supports ELEN " "in the range [8, 64]" );
Signature · 1 line
2.39.0
[PULL 10/37] hw/riscv/boot.c: introduce riscv_default_firmware_name()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
Some boards are duplicating the 'riscv_find_and_load_firmware' call because the 32 and 64 bits images have different names. Create a function to handle this detail instead of hardcoding it in the boards.
Ideally we would bake this logic inside riscv_find_and_load_firmware(), or even create a riscv_load_default_firmware(), but at this moment we cannot infer whether the machine is running 32 or 64 bits without accessing RISCVHartArrayState, which in turn can't be accessed via the common code from boot.c. In the end we would exchange 'firmware_name' for a flag with riscv_is_32bit(), which isn't much better than what we already have today.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- include/hw/riscv/boot.h | 1 + hw/riscv/boot.c | 9 +++++++++ hw/riscv/sifive_u.c | 11 ++++------- hw/riscv/spike.c | 14 +++++--------- hw/riscv/virt.c | 10 +++------- 5 files changed, 22 insertions(+), 23 deletions(-)
include/hw/riscv/boot.h +1 -0
@@ -37,6 +37,7 @@ target_ulong riscv_find_and_load_firmware(MachineState *machine,const char *default_machine_firmware, hwaddr firmware_load_addr, symbol_fn_t sym_cb); +const char *riscv_default_firmware_name (RISCVHartArrayState *harts);target_ulong riscv_load_firmware (const char *firmware_filename,hwaddr firmware_load_addr,symbol_fn_t sym_cb);
hw/riscv/boot.c +9 -0
@@ -75,6 +75,15 @@ target_ulong riscv_calc_kernel_start_addr(RISCVHartArrayState *harts, } } +const char *riscv_default_firmware_name (RISCVHartArrayState *harts) +{ +if (riscv_is_32bit (harts)) { +return RISCV32_BIOS_BIN ; + } + +return RISCV64_BIOS_BIN ; +} +static char *riscv_find_firmware (const char *firmware_filename) {char *filename;
hw/riscv/sifive_u.c +4 -7
@@ -533,6 +533,7 @@ static void sifive_u_machine_init(MachineState *machine)MemoryRegion *flash0 =g_new (MemoryRegion,1 );target_ulong start_addr = memmap[SIFIVE_U_DEV_DRAM ].base;target_ulong firmware_end_addr, kernel_start_addr; +const char *firmware_name;uint32_t start_addr_hi32 =0x00000000 ;int i;uint32_t fdt_load_addr;
@@ -595,13 +596,9 @@ static void sifive_u_machine_init(MachineState *machine)break ; } -if (riscv_is_32bit (&s->soc.u_cpus)) { - firmware_end_addr =riscv_find_and_load_firmware (machine, -RISCV32_BIOS_BIN , start_addr,NULL ); - }else { - firmware_end_addr =riscv_find_and_load_firmware (machine, -RISCV64_BIOS_BIN , start_addr,NULL ); - } + firmware_name =riscv_default_firmware_name (&s->soc.u_cpus); + firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, + start_addr,NULL );if (machine->kernel_filename) { kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc.u_cpus,
hw/riscv/spike.c +5 -9
@@ -190,6 +190,7 @@ static void spike_board_init(MachineState *machine)MemoryRegion *system_memory =get_system_memory ();MemoryRegion *mask_rom =g_new (MemoryRegion,1 );target_ulong firmware_end_addr, kernel_start_addr; +const char *firmware_name;uint32_t fdt_load_addr;uint64_t kernel_entry;char *soc_name;
@@ -255,15 +256,10 @@ static void spike_board_init(MachineState *machine)memory_region_add_subregion (system_memory, memmap[SPIKE_MROM ].base, mask_rom); -if (riscv_is_32bit (&s->soc[0 ])) { - firmware_end_addr =riscv_find_and_load_firmware (machine, -RISCV32_BIOS_BIN , memmap[SPIKE_DRAM ].base, - htif_symbol_callback); - }else { - firmware_end_addr =riscv_find_and_load_firmware (machine, -RISCV64_BIOS_BIN , memmap[SPIKE_DRAM ].base, - htif_symbol_callback); - } + firmware_name =riscv_default_firmware_name (&s->soc[0 ]); + firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, + memmap[SPIKE_DRAM ].base, + htif_symbol_callback);/* Load kernel */ if (machine->kernel_filename) {
hw/riscv/virt.c +3 -7
@@ -1237,6 +1237,7 @@ static void virt_machine_done(Notifier *notifier, void *data)MachineState *machine =MACHINE (s);target_ulong start_addr = memmap[VIRT_DRAM ].base;target_ulong firmware_end_addr, kernel_start_addr; +const char *firmware_name =riscv_default_firmware_name (&s->soc[0 ]);uint32_t fdt_load_addr;uint64_t kernel_entry;
@@ -1256,13 +1257,8 @@ static void virt_machine_done(Notifier *notifier, void *data) } } -if (riscv_is_32bit (&s->soc[0 ])) { - firmware_end_addr =riscv_find_and_load_firmware (machine, -RISCV32_BIOS_BIN , start_addr,NULL ); - }else { - firmware_end_addr =riscv_find_and_load_firmware (machine, -RISCV64_BIOS_BIN , start_addr,NULL ); - } + firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, + start_addr,NULL );/* * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device
Signature · 1 line
2.39.0
[PULL 16/37] hw/riscv/sifive_u: use 'fdt' from MachineState
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
The MachineState object provides a 'fdt' pointer that is already being used by other RISC-V machines, and it's also used by the 'dumpdtb' QMP command.
Remove the 'fdt' pointer from SiFiveUState and use MachineState::fdt instead.
Message-Id: <[email protected]>
--- include/hw/riscv/sifive_u.h | 3 --- hw/riscv/sifive_u.c | 15 ++++++--------- 2 files changed, 6 insertions(+), 12 deletions(-)
include/hw/riscv/sifive_u.h +0 -3
@@ -69,9 +69,6 @@ typedef struct SiFiveUState {/*< public >*/ SiFiveUSoCState soc; -void *fdt; -int fdt_size; -bool start_in_flash;uint32_t msel;uint32_t serial;
hw/riscv/sifive_u.c +6 -9
@@ -98,7 +98,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, {MachineState *ms =MACHINE (qdev_get_machine ());void *fdt; -int cpu; +int cpu, fdt_size;uint32_t *cells;char *nodename;uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle =1 ;
@@ -112,14 +112,14 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, };if (ms->dtb) { - fdt = s->fdt =load_device_tree (ms->dtb, &s->fdt_size); + fdt = ms->fdt =load_device_tree (ms->dtb, &fdt_size);if (!fdt) {error_report ("load_device_tree() failed" );exit (1 ); } goto update_bootargs; }else { - fdt = s->fdt =create_device_tree (&s->fdt_size); + fdt = ms->fdt =create_device_tree (&fdt_size);if (!fdt) {error_report ("create_device_tree() failed" );exit (1 );
@@ -612,9 +612,9 @@ static void sifive_u_machine_init(MachineState *machine)hwaddr end =riscv_load_initrd (machine->initrd_filename, machine->ram_size, kernel_entry, &start); -qemu_fdt_setprop_cell (s->fdt,"/chosen" , +qemu_fdt_setprop_cell (machine->fdt,"/chosen" ,"linux,initrd-start" , start); -qemu_fdt_setprop_cell (s->fdt,"/chosen" ,"linux,initrd-end" , +qemu_fdt_setprop_cell (machine->fdt,"/chosen" ,"linux,initrd-end" , end); } }else {
@@ -627,14 +627,11 @@ static void sifive_u_machine_init(MachineState *machine)/* Compute the fdt load address in dram */ fdt_load_addr =riscv_load_fdt (memmap[SIFIVE_U_DEV_DRAM ].base, - machine->ram_size, s->fdt); + machine->ram_size, machine->fdt);if (!riscv_is_32bit (&s->soc.u_cpus)) { start_addr_hi32 = (uint64_t )start_addr >>32 ; } -/* Set machine->fdt for 'dumpdtb' QMP/HMP command */ - machine->fdt = s->fdt; -/* reset vector */ uint32_t reset_vec[12 ] = { s->msel,/* MSEL pin state */
Signature · 1 line
2.39.0
[PULL 02/37] hw/char: riscv_htif: Drop {to, from}host_size in HTIFState
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
These are not used anywhere. Drop them.
Message-Id: <[email protected]>
--- include/hw/char/riscv_htif.h | 2 -- 1 file changed, 2 deletions(-)
include/hw/char/riscv_htif.h +0 -2
@@ -33,8 +33,6 @@ typedef struct HTIFState {hwaddr tohost_offset;hwaddr fromhost_offset; -uint64_t tohost_size; -uint64_t fromhost_size;MemoryRegion mmio;MemoryRegion *address_space;MemoryRegion *main_mem;
Signature · 1 line
2.39.0
[PULL 26/37] hw/riscv/spike.c: simplify create_fdt()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
'mem_size' and 'cmdline' are unused.
Message-Id: <[email protected]>
--- hw/riscv/spike.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/riscv/spike.c +1 -3
@@ -49,7 +49,6 @@ static const MemMapEntry spike_memmap[] = { };static void create_fdt (SpikeState *s,const MemMapEntry *memmap, -uint64_t mem_size,const char *cmdline,bool is_32_bit,bool htif_custom_base) {void *fdt;
@@ -299,8 +298,7 @@ static void spike_board_init(MachineState *machine) }/* Create device tree */ -create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, -riscv_is_32bit (&s->soc[0 ]), htif_custom_base); +create_fdt (s, memmap,riscv_is_32bit (&s->soc[0 ]), htif_custom_base);/* Load kernel */ if (machine->kernel_filename) {
Signature · 1 line
2.39.0
[PULL 31/37] hw/riscv: use ms->fdt in riscv_socket_fdt_write_distance_matrix()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
There's no need to use a MachineState pointer and a fdt pointer now that all RISC-V machines are using the FDT from the MachineState.
Message-Id: <[email protected]>
--- include/hw/riscv/numa.h | 4 ++-- hw/riscv/numa.c | 8 ++++---- hw/riscv/spike.c | 2 +- hw/riscv/virt.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-)
include/hw/riscv/numa.h +2 -2
@@ -100,9 +100,9 @@ void riscv_socket_fdt_write_id(const MachineState *ms, const char *node_name,* @ms: pointer to machine state * @socket_id: socket index * -* Write NUMA distance matrix in FDT for given machine +* Write NUMA distance matrix in MachineState->fdt */ -void riscv_socket_fdt_write_distance_matrix (const MachineState *ms,void *fdt); +void riscv_socket_fdt_write_distance_matrix (const MachineState *ms);CpuInstanceProperties riscv_numa_cpu_index_to_props (MachineState *ms,unsigned cpu_index);
hw/riscv/numa.c +4 -4
@@ -164,7 +164,7 @@ void riscv_socket_fdt_write_id(const MachineState *ms, const char *node_name, } } -void riscv_socket_fdt_write_distance_matrix (const MachineState *ms,void *fdt) +void riscv_socket_fdt_write_distance_matrix (const MachineState *ms) {int i, j, idx;uint32_t *dist_matrix, dist_matrix_size;
@@ -184,10 +184,10 @@ void riscv_socket_fdt_write_distance_matrix(const MachineState *ms, void *fdt) } } -qemu_fdt_add_subnode (fdt,"/distance-map" ); -qemu_fdt_setprop_string (fdt,"/distance-map" ,"compatible" , +qemu_fdt_add_subnode (ms->fdt,"/distance-map" ); +qemu_fdt_setprop_string (ms->fdt,"/distance-map" ,"compatible" ,"numa-distance-map-v1" ); -qemu_fdt_setprop (fdt,"/distance-map" ,"distance-matrix" , +qemu_fdt_setprop (ms->fdt,"/distance-map" ,"distance-matrix" , dist_matrix, dist_matrix_size);g_free (dist_matrix); }
hw/riscv/spike.c +1 -1
@@ -174,7 +174,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,g_free (clust_name); } -riscv_socket_fdt_write_distance_matrix (mc, fdt); +riscv_socket_fdt_write_distance_matrix (mc);qemu_fdt_add_subnode (fdt,"/chosen" );qemu_fdt_setprop_string (fdt,"/chosen" ,"stdout-path" ,"/htif" );
hw/riscv/virt.c +1 -1
@@ -805,7 +805,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, } } -riscv_socket_fdt_write_distance_matrix (mc, mc->fdt); +riscv_socket_fdt_write_distance_matrix (mc); } static void create_fdt_virtio(RISCVVirtState *s, const MemMapEntry *memmap,
Signature · 1 line
2.39.0
[PULL 25/37] target/riscv: Use TARGET_FMT_lx for env->mhartid
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
env->mhartid is currently casted to long before printed, which drops the high 32-bit for rv64 on 32-bit host. Use TARGET_FMT_lx instead.
Message-Id: <[email protected]>
--- target/riscv/cpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/riscv/cpu.c +3 -3
@@ -867,9 +867,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) (env->priv_ver < isa_edata_arr[i].min_version)) {isa_ext_update_enabled (cpu, &isa_edata_arr[i], false);#ifndef CONFIG_USER_ONLY -warn_report ("disabling %s extension for hart 0x%lx because " -"privilege spec version does not match" , - isa_edata_arr[i].name, (unsigned long )env->mhartid); +warn_report ("disabling %s extension for hart 0x" TARGET_FMT_lx +" because privilege spec version does not match" , + isa_edata_arr[i].name, env->mhartid);#else warn_report("disabling %s extension because " "privilege spec version does not match",
Signature · 1 line
2.39.0
[PULL 24/37] target/riscv/cpu.c: do not skip misa logic in riscv_cpu_realize()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
All RISCV CPUs are setting cpu->cfg during their cpu_init() functions, meaning that there's no reason to skip all the misa validation and setup if misa_ext was set beforehand - especially since we're setting an updated value in set_misa() in the end.
Put this code chunk into a new riscv_cpu_validate_set_extensions() helper and always execute it regardless of what the board set in env->misa_ext.
This will put more responsibility in how each board is going to init their attributes and extensions if they're not using the defaults. It'll also allow realize() to do its job looking only at the extensions enabled per se, not corner cases that some CPUs might have, and we won't have to change multiple code paths to fix or change how extensions work.
Message-Id: <[email protected]> [ Changes by AF:
- Rebase
]
--- target/riscv/cpu.c | 399 +++++++++++++++++++++++---------------------- 1 file changed, 205 insertions(+), 194 deletions(-)
target/riscv/cpu.c +205 -194
@@ -625,6 +625,207 @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) } } +/* +* Check consistency between chosen extensions while setting +* cpu->cfg accordingly, doing a set_misa() in the end. +*/ +static void riscv_cpu_validate_set_extensions (RISCVCPU *cpu,Error **errp) +{ +CPURISCVState *env = &cpu->env; +uint32_t ext =0 ; + +/* Do some ISA extension error checking */ +if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m && + cpu->cfg.ext_a && cpu->cfg.ext_f && + cpu->cfg.ext_d && + cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { +warn_report ("Setting G will also set IMAFD_Zicsr_Zifencei" ); + cpu->cfg.ext_i = true; + cpu->cfg.ext_m = true; + cpu->cfg.ext_a = true; + cpu->cfg.ext_f = true; + cpu->cfg.ext_d = true; + cpu->cfg.ext_icsr = true; + cpu->cfg.ext_ifencei = true; + } + +if (cpu->cfg.ext_i && cpu->cfg.ext_e) { +error_setg (errp, +"I and E extensions are incompatible" ); +return ; + } + +if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { +error_setg (errp, +"Either I or E extension must be set" ); +return ; + } + +if (cpu->cfg.ext_s && !cpu->cfg.ext_u) { +error_setg (errp, +"Setting S extension without U extension is illegal" ); +return ; + } + +if (cpu->cfg.ext_h && !cpu->cfg.ext_i) { +error_setg (errp, +"H depends on an I base integer ISA with 32 x registers" ); +return ; + } + +if (cpu->cfg.ext_h && !cpu->cfg.ext_s) { +error_setg (errp,"H extension implicitly requires S-mode" ); +return ; + } + +if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) { +error_setg (errp,"F extension requires Zicsr" ); +return ; + } + +if ((cpu->cfg.ext_zawrs) && !cpu->cfg.ext_a) { +error_setg (errp,"Zawrs extension requires A extension" ); +return ; + } + +if ((cpu->cfg.ext_zfh || cpu->cfg.ext_zfhmin) && !cpu->cfg.ext_f) { +error_setg (errp,"Zfh/Zfhmin extensions require F extension" ); +return ; + } + +if (cpu->cfg.ext_d && !cpu->cfg.ext_f) { +error_setg (errp,"D extension requires F extension" ); +return ; + } + +if (cpu->cfg.ext_v && !cpu->cfg.ext_d) { +error_setg (errp,"V extension requires D extension" ); +return ; + } + +if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) { +error_setg (errp,"Zve32f/Zve64f extensions require F extension" ); +return ; + } + +/* Set the ISA extensions, checks should have happened above */ +if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || + cpu->cfg.ext_zhinxmin) { + cpu->cfg.ext_zfinx = true; + } + +if (cpu->cfg.ext_zfinx) { +if (!cpu->cfg.ext_icsr) { +error_setg (errp,"Zfinx extension requires Zicsr" ); +return ; + } +if (cpu->cfg.ext_f) { +error_setg (errp, +"Zfinx cannot be supported together with F extension" ); +return ; + } + } + +if (cpu->cfg.ext_zk) { + cpu->cfg.ext_zkn = true; + cpu->cfg.ext_zkr = true; + cpu->cfg.ext_zkt = true; + } + +if (cpu->cfg.ext_zkn) { + cpu->cfg.ext_zbkb = true; + cpu->cfg.ext_zbkc = true; + cpu->cfg.ext_zbkx = true; + cpu->cfg.ext_zkne = true; + cpu->cfg.ext_zknd = true; + cpu->cfg.ext_zknh = true; + } + +if (cpu->cfg.ext_zks) { + cpu->cfg.ext_zbkb = true; + cpu->cfg.ext_zbkc = true; + cpu->cfg.ext_zbkx = true; + cpu->cfg.ext_zksed = true; + cpu->cfg.ext_zksh = true; + } + +if (cpu->cfg.ext_i) { + ext |=RVI ; + } +if (cpu->cfg.ext_e) { + ext |=RVE ; + } +if (cpu->cfg.ext_m) { + ext |=RVM ; + } +if (cpu->cfg.ext_a) { + ext |=RVA ; + } +if (cpu->cfg.ext_f) { + ext |=RVF ; + } +if (cpu->cfg.ext_d) { + ext |=RVD ; + } +if (cpu->cfg.ext_c) { + ext |=RVC ; + } +if (cpu->cfg.ext_s) { + ext |=RVS ; + } +if (cpu->cfg.ext_u) { + ext |=RVU ; + } +if (cpu->cfg.ext_h) { + ext |=RVH ; + } +if (cpu->cfg.ext_v) { +int vext_version =VEXT_VERSION_1_00_0 ; + ext |=RVV ; +if (!is_power_of_2 (cpu->cfg.vlen)) { +error_setg (errp, +"Vector extension VLEN must be power of 2" ); +return ; + } +if (cpu->cfg.vlen >RV_VLEN_MAX || cpu->cfg.vlen <128 ) { +error_setg (errp, +"Vector extension implementation only supports VLEN " +"in the range [128, %d]" ,RV_VLEN_MAX ); +return ; + } +if (!is_power_of_2 (cpu->cfg.elen)) { +error_setg (errp, +"Vector extension ELEN must be power of 2" ); +return ; + } +if (cpu->cfg.elen >64 || cpu->cfg.elen <8 ) { +error_setg (errp, +"Vector extension implementation only supports ELEN " +"in the range [8, 64]" ); +return ; + } +if (cpu->cfg.vext_spec) { +if (!g_strcmp0 (cpu->cfg.vext_spec,"v1.0" )) { + vext_version =VEXT_VERSION_1_00_0 ; + }else { +error_setg (errp, +"Unsupported vector spec version '%s'" , + cpu->cfg.vext_spec); +return ; + } + }else { +qemu_log ("vector version is not specified, " +"use the default value v1.0\n" ); + } +set_vext_version (env, vext_version); + } +if (cpu->cfg.ext_j) { + ext |=RVJ ; + } + +set_misa (env, env->misa_mxl, ext); +} +static void riscv_cpu_realize (DeviceState *dev,Error **errp) {CPUState *cs =CPU (dev);
@@ -720,200 +921,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) }assert (env->misa_mxl_max == env->misa_mxl); -/* If only MISA_EXT is unset for misa, then set it from properties */ -if (env->misa_ext ==0 ) { -uint32_t ext =0 ; - -/* Do some ISA extension error checking */ -if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m && - cpu->cfg.ext_a && cpu->cfg.ext_f && - cpu->cfg.ext_d && - cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { -warn_report ("Setting G will also set IMAFD_Zicsr_Zifencei" ); - cpu->cfg.ext_i = true; - cpu->cfg.ext_m = true; - cpu->cfg.ext_a = true; - cpu->cfg.ext_f = true; - cpu->cfg.ext_d = true; - cpu->cfg.ext_icsr = true; - cpu->cfg.ext_ifencei = true; - } - -if (cpu->cfg.ext_i && cpu->cfg.ext_e) { -error_setg (errp, -"I and E extensions are incompatible" ); -return ; - } - -if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { -error_setg (errp, -"Either I or E extension must be set" ); -return ; - } - -if (cpu->cfg.ext_s && !cpu->cfg.ext_u) { -error_setg (errp, -"Setting S extension without U extension is illegal" ); -return ; - } - -if (cpu->cfg.ext_h && !cpu->cfg.ext_i) { -error_setg (errp, -"H depends on an I base integer ISA with 32 x registers" ); -return ; - } - -if (cpu->cfg.ext_h && !cpu->cfg.ext_s) { -error_setg (errp,"H extension implicitly requires S-mode" ); -return ; - } - -if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) { -error_setg (errp,"F extension requires Zicsr" ); -return ; - } - -if ((cpu->cfg.ext_zawrs) && !cpu->cfg.ext_a) { -error_setg (errp,"Zawrs extension requires A extension" ); -return ; - } - -if ((cpu->cfg.ext_zfh || cpu->cfg.ext_zfhmin) && !cpu->cfg.ext_f) { -error_setg (errp,"Zfh/Zfhmin extensions require F extension" ); -return ; - } - -if (cpu->cfg.ext_d && !cpu->cfg.ext_f) { -error_setg (errp,"D extension requires F extension" ); -return ; - } - -if (cpu->cfg.ext_v && !cpu->cfg.ext_d) { -error_setg (errp,"V extension requires D extension" ); -return ; - } - -if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) { -error_setg (errp,"Zve32f/Zve64f extensions require F extension" ); -return ; - } - -/* Set the ISA extensions, checks should have happened above */ -if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || - cpu->cfg.ext_zhinxmin) { - cpu->cfg.ext_zfinx = true; - } - -if (cpu->cfg.ext_zfinx) { -if (!cpu->cfg.ext_icsr) { -error_setg (errp,"Zfinx extension requires Zicsr" ); -return ; - } -if (cpu->cfg.ext_f) { -error_setg (errp, -"Zfinx cannot be supported together with F extension" ); -return ; - } - } - -if (cpu->cfg.ext_zk) { - cpu->cfg.ext_zkn = true; - cpu->cfg.ext_zkr = true; - cpu->cfg.ext_zkt = true; - } - -if (cpu->cfg.ext_zkn) { - cpu->cfg.ext_zbkb = true; - cpu->cfg.ext_zbkc = true; - cpu->cfg.ext_zbkx = true; - cpu->cfg.ext_zkne = true; - cpu->cfg.ext_zknd = true; - cpu->cfg.ext_zknh = true; - } - -if (cpu->cfg.ext_zks) { - cpu->cfg.ext_zbkb = true; - cpu->cfg.ext_zbkc = true; - cpu->cfg.ext_zbkx = true; - cpu->cfg.ext_zksed = true; - cpu->cfg.ext_zksh = true; - } - -if (cpu->cfg.ext_i) { - ext |=RVI ; - } -if (cpu->cfg.ext_e) { - ext |=RVE ; - } -if (cpu->cfg.ext_m) { - ext |=RVM ; - } -if (cpu->cfg.ext_a) { - ext |=RVA ; - } -if (cpu->cfg.ext_f) { - ext |=RVF ; - } -if (cpu->cfg.ext_d) { - ext |=RVD ; - } -if (cpu->cfg.ext_c) { - ext |=RVC ; - } -if (cpu->cfg.ext_s) { - ext |=RVS ; - } -if (cpu->cfg.ext_u) { - ext |=RVU ; - } -if (cpu->cfg.ext_h) { - ext |=RVH ; - } -if (cpu->cfg.ext_v) { -int vext_version =VEXT_VERSION_1_00_0 ; - ext |=RVV ; -if (!is_power_of_2 (cpu->cfg.vlen)) { -error_setg (errp, -"Vector extension VLEN must be power of 2" ); -return ; - } -if (cpu->cfg.vlen >RV_VLEN_MAX || cpu->cfg.vlen <128 ) { -error_setg (errp, -"Vector extension implementation only supports VLEN " -"in the range [128, %d]" ,RV_VLEN_MAX ); -return ; - } -if (!is_power_of_2 (cpu->cfg.elen)) { -error_setg (errp, -"Vector extension ELEN must be power of 2" ); -return ; - } -if (cpu->cfg.elen >64 || cpu->cfg.elen <8 ) { -error_setg (errp, -"Vector extension implementation only supports ELEN " -"in the range [8, 64]" ); -return ; - } -if (cpu->cfg.vext_spec) { -if (!g_strcmp0 (cpu->cfg.vext_spec,"v1.0" )) { - vext_version =VEXT_VERSION_1_00_0 ; - }else { -error_setg (errp, -"Unsupported vector spec version '%s'" , - cpu->cfg.vext_spec); -return ; - } - }else { -qemu_log ("vector version is not specified, " -"use the default value v1.0\n" ); - } -set_vext_version (env, vext_version); - } -if (cpu->cfg.ext_j) { - ext |=RVJ ; - } - -set_misa (env, env->misa_mxl, ext); +riscv_cpu_validate_set_extensions (cpu, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; }#ifndef CONFIG_USER_ONLY
Signature · 1 line
2.39.0
[PULL 27/37] hw/riscv/virt.c: simplify create_fdt()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
'mem_size' and 'cmdline' aren't being used. Remove them.
Message-Id: <[email protected]>
--- hw/riscv/virt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/riscv/virt.c +2 -3
@@ -999,7 +999,7 @@ static void create_fdt_fw_cfg(RISCVVirtState *s, const MemMapEntry *memmap) }static void create_fdt (RISCVVirtState *s,const MemMapEntry *memmap, -uint64_t mem_size,const char *cmdline,bool is_32_bit) +bool is_32_bit) {MachineState *mc =MACHINE (s);uint32_t phandle =1 , irq_mmio_phandle =1 , msi_pcie_phandle =1 ;
@@ -1507,8 +1507,7 @@ static void virt_machine_init(MachineState *machine)virt_flash_map (s, system_memory);/* create device tree */ -create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, -riscv_is_32bit (&s->soc[0 ])); +create_fdt (s, memmap,riscv_is_32bit (&s->soc[0 ])); s->machine_done.notify = virt_machine_done;qemu_add_machine_init_done_notifier (&s->machine_done);
Signature · 1 line
2.39.0
[PULL 28/37] hw/riscv/sifive_u.c: simplify create_fdt()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
'cmdline' isn't being used. Remove it.
A MachineState pointer is being retrieved via a MACHINE() macro calling qdev_get_machine(). Use MACHINE(s) instead to avoid calling qdev().
'mem_size' is being set as machine->ram_size by the caller. Retrieve it
via ms->ram_size.
Message-Id: <[email protected]>
--- hw/riscv/sifive_u.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/riscv/sifive_u.c +4 -4
@@ -94,9 +94,10 @@ static const MemMapEntry sifive_u_memmap[] = {#define GEM_REVISION 0x10070109static void create_fdt (SiFiveUState *s,const MemMapEntry *memmap, -uint64_t mem_size,const char *cmdline,bool is_32_bit) +bool is_32_bit) { -MachineState *ms =MACHINE (qdev_get_machine ()); +MachineState *ms =MACHINE (s); +uint64_t mem_size = ms->ram_size;void *fdt;int cpu, fdt_size;uint32_t *cells;
@@ -560,8 +561,7 @@ static void sifive_u_machine_init(MachineState *machine) qemu_allocate_irq(sifive_u_machine_reset, NULL, 0));/* create device tree */ -create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, -riscv_is_32bit (&s->soc.u_cpus)); +create_fdt (s, memmap,riscv_is_32bit (&s->soc.u_cpus));if (s->start_in_flash) {/*
Signature · 1 line
2.39.0
[PULL 30/37] hw/riscv: use MachineState::fdt in riscv_socket_fdt_write_id()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
There's no need to use a MachineState pointer and a fdt pointer now that all RISC-V machines are using the FDT from the MachineState.
Message-Id: <[email protected]>
--- include/hw/riscv/numa.h | 6 +++--- hw/riscv/numa.c | 6 +++--- hw/riscv/spike.c | 6 +++--- hw/riscv/virt.c | 18 +++++++++--------- 4 files changed, 18 insertions(+), 18 deletions(-)
include/hw/riscv/numa.h +3 -3
@@ -90,10 +90,10 @@ bool riscv_socket_check_hartids(const MachineState *ms, int socket_id);* @ms: pointer to machine state * @socket_id: socket index * -* Write NUMA node-id FDT property for given FDT node +* Write NUMA node-id FDT property in MachineState->fdt */ -void riscv_socket_fdt_write_id (const MachineState *ms,void *fdt, -const char *node_name,int socket_id); +void riscv_socket_fdt_write_id (const MachineState *ms,const char *node_name, +int socket_id);/** * riscv_socket_fdt_write_distance_matrix:
hw/riscv/numa.c +3 -3
@@ -156,11 +156,11 @@ uint64_t riscv_socket_mem_size(const MachineState *ms, int socket_id) ms->numa_state->nodes[socket_id].node_mem : 0; } -void riscv_socket_fdt_write_id (const MachineState *ms,void *fdt, -const char *node_name,int socket_id) +void riscv_socket_fdt_write_id (const MachineState *ms,const char *node_name, +int socket_id) {if (numa_enabled (ms)) { -qemu_fdt_setprop_cell (fdt, node_name,"numa-node-id" , socket_id); +qemu_fdt_setprop_cell (ms->fdt, node_name,"numa-node-id" , socket_id); } }
hw/riscv/spike.c +3 -3
@@ -121,7 +121,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,qemu_fdt_setprop_cell (fdt, cpu_name,"reg" , s->soc[socket].hartid_base + cpu);qemu_fdt_setprop_string (fdt, cpu_name,"device_type" ,"cpu" ); -riscv_socket_fdt_write_id (mc, fdt, cpu_name, socket); +riscv_socket_fdt_write_id (mc, cpu_name, socket);qemu_fdt_setprop_cell (fdt, cpu_name,"phandle" , cpu_phandle); intc_name =g_strdup_printf ("%s/interrupt-controller" , cpu_name);
@@ -154,7 +154,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,qemu_fdt_setprop_cells (fdt, mem_name,"reg" , addr >>32 , addr, size >>32 , size);qemu_fdt_setprop_string (fdt, mem_name,"device_type" ,"memory" ); -riscv_socket_fdt_write_id (mc, fdt, mem_name, socket); +riscv_socket_fdt_write_id (mc, mem_name, socket);g_free (mem_name); clint_addr = memmap[SPIKE_CLINT].base +
@@ -167,7 +167,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, 0x0, clint_addr, 0x0, memmap[SPIKE_CLINT].size);qemu_fdt_setprop (fdt, clint_name,"interrupts-extended" , clint_cells, s->soc[socket].num_harts *sizeof (uint32_t ) *4 ); -riscv_socket_fdt_write_id (mc, fdt, clint_name, socket); +riscv_socket_fdt_write_id (mc, clint_name, socket);g_free (clint_name);g_free (clint_cells);
hw/riscv/virt.c +9 -9
@@ -253,7 +253,7 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket,qemu_fdt_setprop_cell (mc->fdt, cpu_name,"reg" , s->soc[socket].hartid_base + cpu);qemu_fdt_setprop_string (mc->fdt, cpu_name,"device_type" ,"cpu" ); -riscv_socket_fdt_write_id (mc, mc->fdt, cpu_name, socket); +riscv_socket_fdt_write_id (mc, cpu_name, socket);qemu_fdt_setprop_cell (mc->fdt, cpu_name,"phandle" , cpu_phandle); intc_phandles[cpu] = (*phandle)++;
@@ -291,7 +291,7 @@ static void create_fdt_socket_memory(RISCVVirtState *s,qemu_fdt_setprop_cells (mc->fdt, mem_name,"reg" , addr >>32 , addr, size >>32 , size);qemu_fdt_setprop_string (mc->fdt, mem_name,"device_type" ,"memory" ); -riscv_socket_fdt_write_id (mc, mc->fdt, mem_name, socket); +riscv_socket_fdt_write_id (mc, mem_name, socket);g_free (mem_name); }
@@ -327,7 +327,7 @@ static void create_fdt_socket_clint(RISCVVirtState *s, 0x0, clint_addr, 0x0, memmap[VIRT_CLINT].size);qemu_fdt_setprop (mc->fdt, clint_name,"interrupts-extended" , clint_cells, s->soc[socket].num_harts *sizeof (uint32_t ) *4 ); -riscv_socket_fdt_write_id (mc, mc->fdt, clint_name, socket); +riscv_socket_fdt_write_id (mc, clint_name, socket);g_free (clint_name);g_free (clint_cells);
@@ -372,7 +372,7 @@ static void create_fdt_socket_aclint(RISCVVirtState *s, aclint_mswi_cells, aclint_cells_size);qemu_fdt_setprop (mc->fdt, name,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop_cell (mc->fdt, name,"#interrupt-cells" ,0 ); -riscv_socket_fdt_write_id (mc, mc->fdt, name, socket); +riscv_socket_fdt_write_id (mc, name, socket);g_free (name); }
@@ -396,7 +396,7 @@ static void create_fdt_socket_aclint(RISCVVirtState *s, 0x0, RISCV_ACLINT_DEFAULT_MTIME);qemu_fdt_setprop (mc->fdt, name,"interrupts-extended" , aclint_mtimer_cells, aclint_cells_size); -riscv_socket_fdt_write_id (mc, mc->fdt, name, socket); +riscv_socket_fdt_write_id (mc, name, socket);g_free (name);if (s->aia_type !=VIRT_AIA_TYPE_APLIC_IMSIC ) {
@@ -412,7 +412,7 @@ static void create_fdt_socket_aclint(RISCVVirtState *s, aclint_sswi_cells, aclint_cells_size);qemu_fdt_setprop (mc->fdt, name,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop_cell (mc->fdt, name,"#interrupt-cells" ,0 ); -riscv_socket_fdt_write_id (mc, mc->fdt, name, socket); +riscv_socket_fdt_write_id (mc, name, socket);g_free (name); }
@@ -471,7 +471,7 @@ static void create_fdt_socket_plic(RISCVVirtState *s, 0x0, plic_addr, 0x0, memmap[VIRT_PLIC].size);qemu_fdt_setprop_cell (mc->fdt, plic_name,"riscv,ndev" ,VIRT_IRQCHIP_NUM_SOURCES -1 ); -riscv_socket_fdt_write_id (mc, mc->fdt, plic_name, socket); +riscv_socket_fdt_write_id (mc, plic_name, socket);qemu_fdt_setprop_cell (mc->fdt, plic_name,"phandle" , plic_phandles[socket]);
@@ -663,7 +663,7 @@ static void create_fdt_socket_aplic(RISCVVirtState *s, aplic_s_phandle);qemu_fdt_setprop_cells (mc->fdt, aplic_name,"riscv,delegate" , aplic_s_phandle,0x1 ,VIRT_IRQCHIP_NUM_SOURCES ); -riscv_socket_fdt_write_id (mc, mc->fdt, aplic_name, socket); +riscv_socket_fdt_write_id (mc, aplic_name, socket);qemu_fdt_setprop_cell (mc->fdt, aplic_name,"phandle" , aplic_m_phandle);g_free (aplic_name);
@@ -691,7 +691,7 @@ static void create_fdt_socket_aplic(RISCVVirtState *s, 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_S].size);qemu_fdt_setprop_cell (mc->fdt, aplic_name,"riscv,num-sources" ,VIRT_IRQCHIP_NUM_SOURCES ); -riscv_socket_fdt_write_id (mc, mc->fdt, aplic_name, socket); +riscv_socket_fdt_write_id (mc, aplic_name, socket);qemu_fdt_setprop_cell (mc->fdt, aplic_name,"phandle" , aplic_s_phandle);if (!socket) {
Signature · 1 line
2.39.0
[PULL 11/37] hw/riscv/boot.c: Introduce riscv_find_firmware()
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
Rename previous riscv_find_firmware() to riscv_find_bios(), and introduce a new riscv_find_firmware() to implement the first half part of the work done in riscv_find_and_load_firmware().
This new API is helpful for machine that wants to know the final chosen firmware file name but does not want to load it.
Message-Id: <[email protected]>
--- include/hw/riscv/boot.h | 2 ++ hw/riscv/boot.c | 39 +++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-)
include/hw/riscv/boot.h +2 -0
@@ -38,6 +38,8 @@ target_ulong riscv_find_and_load_firmware(MachineState *machine,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);target_ulong riscv_load_firmware (const char *firmware_filename,hwaddr firmware_load_addr,symbol_fn_t sym_cb);
hw/riscv/boot.c +25 -14
@@ -84,11 +84,11 @@ const char *riscv_default_firmware_name(RISCVHartArrayState *harts)return RISCV64_BIOS_BIN ; } -static char *riscv_find_firmware (const char *firmware_filename) +static char *riscv_find_bios (const char *bios_filename) {char *filename; - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , firmware_filename); + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_filename);if (filename ==NULL ) {if (!qtest_enabled ()) {/*
@@ -97,8 +97,8 @@ static char *riscv_find_firmware(const char *firmware_filename)* running QEMU test will complain hence let's suppress the error * report for QEMU testing. */ -error_report ("Unable to load the RISC-V firmware \"%s\"" , - firmware_filename); +error_report ("Unable to find the RISC-V BIOS \"%s\"" , + bios_filename);exit (1 ); } }
@@ -106,25 +106,36 @@ static char *riscv_find_firmware(const char *firmware_filename)return filename; } -target_ulong riscv_find_and_load_firmware (MachineState *machine, -const char *default_machine_firmware, -hwaddr firmware_load_addr, -symbol_fn_t sym_cb) +char *riscv_find_firmware (const char *firmware_filename, +const char *default_machine_firmware) { -char *firmware_filename =NULL ; -target_ulong firmware_end_addr = firmware_load_addr; +char *filename =NULL ; -if ((!machine->firmware) || (!strcmp (machine->firmware,"default" ))) { +if ((!firmware_filename) || (!strcmp (firmware_filename,"default" ))) {/* * The user didn't specify -bios, or has specified "-bios default". * That means we are going to load the OpenSBI binary included in * the QEMU source. */ - firmware_filename =riscv_find_firmware (default_machine_firmware); - }else if (strcmp (machine->firmware,"none" )) { - firmware_filename =riscv_find_firmware (machine->firmware); + filename =riscv_find_bios (default_machine_firmware); + }else if (strcmp (firmware_filename,"none" )) { + filename =riscv_find_bios (firmware_filename); } +return filename; +} + +target_ulong riscv_find_and_load_firmware (MachineState *machine, +const char *default_machine_firmware, +hwaddr firmware_load_addr, +symbol_fn_t sym_cb) +{ +char *firmware_filename; +target_ulong firmware_end_addr = firmware_load_addr; + + firmware_filename =riscv_find_firmware (machine->firmware, + default_machine_firmware); +if (firmware_filename) {/* If not "none" load the firmware */ firmware_end_addr = riscv_load_firmware(firmware_filename,
Signature · 1 line
2.39.0
[PULL 37/37] hw/riscv/virt.c: move create_fw_cfg() back to virt_machine_init()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
Commit 1c20d3ff6004 ("hw/riscv: virt: Add a machine done notifier") moved the initialization of fw_cfg to the virt_machine_done() callback.
Problem is that the validation of fw_cfg by devices such as ramfb is done before the machine done notifier is called. Moving create_fw_cfg() to machine_done() results in QEMU failing to boot when using a ramfb device:
./qemu-system-riscv64 -machine virt -device ramfb -serial stdio
qemu-system-riscv64: -device ramfb: ramfb device requires fw_cfg with DMA
The fix is simple: move create_fw_cfg() config back to virt_machine_init(). This happens to be the same way the ARM 'virt' machine deals with fw_cfg (see machvirt_init() and virt_machine_done() in hw/arm/virt.c), so we're keeping consistency with how other machines handle this device.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1343
Message-Id: <[email protected]>
--- hw/riscv/virt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
hw/riscv/virt.c +7 -7
@@ -1254,13 +1254,6 @@ static void virt_machine_done(Notifier *notifier, void *data) firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, start_addr,NULL ); -/* -* Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device -* tree cannot be altered and we get FDT_ERR_NOSPACE. -*/ - s->fw_cfg =create_fw_cfg (machine); -rom_set_fw (s->fw_cfg); -if (drive_get (IF_PFLASH ,0 ,1 )) {/* * S-mode FW like EDK2 will be kept in second plash (unit 1).
@@ -1468,6 +1461,13 @@ static void virt_machine_init(MachineState *machine)memory_region_add_subregion (system_memory, memmap[VIRT_MROM ].base, mask_rom); +/* +* Init fw_cfg. Must be done before riscv_load_fdt, otherwise the +* device tree cannot be altered and we get FDT_ERR_NOSPACE. +*/ + s->fw_cfg =create_fw_cfg (machine); +rom_set_fw (s->fw_cfg); +/* SiFive Test MMIO device */ sifive_test_create (memmap[VIRT_TEST ].base);
Signature · 1 line
2.39.0
[PULL 35/37] target/riscv: Introduce helper_set_rounding_mode_chkfrm
In reply to Alistair FrancisFrom: Richard Henderson <[email protected]>
The new helper always validates the contents of FRM, even if the new rounding mode is not DYN. This is required by the vector unit.
Track whether we've validated FRM separately from whether we've updated fp_status with a given rounding mode, so that we can elide calls correctly.
This partially reverts d6c4d3f2a69 which attempted the to do the same thing, but with two calls to gen_set_rm(), which is both inefficient and tickles an assertion in decode_save_opc.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1441
Message-Id: <[email protected]>
--- target/riscv/helper.h | 1 + target/riscv/fpu_helper.c | 37 +++++++++++++++++++++++++ target/riscv/translate.c | 19 +++++++++++++ target/riscv/insn_trans/trans_rvv.c.inc | 24 +++------------- 4 files changed, 61 insertions(+), 20 deletions(-)
target/riscv/helper.h +1 -0
@@ -3,6 +3,7 @@ DEF_HELPER_2(raise_exception, noreturn, env, i32)/* Floating Point - rounding mode */ DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_WG, void, env, i32) +DEF_HELPER_FLAGS_2(set_rounding_mode_chkfrm, TCG_CALL_NO_WG, void, env, i32)DEF_HELPER_FLAGS_1 (set_rod_rounding_mode,TCG_CALL_NO_WG , void, env)/* Floating Point - fused */
target/riscv/fpu_helper.c +37 -0
@@ -81,6 +81,43 @@ void helper_set_rounding_mode(CPURISCVState *env, uint32_t rm)set_float_rounding_mode (softrm, &env->fp_status); } +void helper_set_rounding_mode_chkfrm (CPURISCVState *env,uint32_t rm) +{ +int softrm; + +/* Always validate frm, even if rm != DYN. */ +if (unlikely (env->frm >=5 )) { +riscv_raise_exception (env,RISCV_EXCP_ILLEGAL_INST ,GETPC ()); + } +if (rm ==RISCV_FRM_DYN ) { + rm = env->frm; + } +switch (rm) { +case RISCV_FRM_RNE : + softrm = float_round_nearest_even; +break ; +case RISCV_FRM_RTZ : + softrm = float_round_to_zero; +break ; +case RISCV_FRM_RDN : + softrm = float_round_down; +break ; +case RISCV_FRM_RUP : + softrm = float_round_up; +break ; +case RISCV_FRM_RMM : + softrm = float_round_ties_away; +break ; +case RISCV_FRM_ROD : + softrm = float_round_to_odd; +break ; +default : +g_assert_not_reached (); + } + +set_float_rounding_mode (softrm, &env->fp_status); +} +void helper_set_rod_rounding_mode (CPURISCVState *env) {set_float_rounding_mode (float_round_to_odd, &env->fp_status);
target/riscv/translate.c +19 -0
@@ -114,6 +114,8 @@ typedef struct DisasContext {bool pm_base_enabled;/* Use icount trigger for native debug */ bool itrigger; +/* FRM is known to contain a valid value. */ +bool frm_valid;/* TCG of the current insn_start */ TCGOp *insn_start; } DisasContext;
@@ -674,12 +676,29 @@ static void gen_set_rm(DisasContext *ctx, int rm)gen_helper_set_rod_rounding_mode (cpu_env);return ; } +if (rm ==RISCV_FRM_DYN ) { +/* The helper will return only if frm valid. */ + ctx->frm_valid = true; + }/* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ decode_save_opc (ctx);gen_helper_set_rounding_mode (cpu_env,tcg_constant_i32 (rm)); } +static void gen_set_rm_chkfrm (DisasContext *ctx,int rm) +{ +if (ctx->frm == rm && ctx->frm_valid) { +return ; + } + ctx->frm = rm; + ctx->frm_valid = true; + +/* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ +decode_save_opc (ctx); +gen_helper_set_rounding_mode_chkfrm (cpu_env,tcg_constant_i32 (rm)); +} +static int ex_plus_1 (DisasContext *ctx,int nf) {return nf +1 ;
target/riscv/insn_trans/trans_rvv.c.inc +4 -20
@@ -2679,13 +2679,9 @@ static bool do_opfv(DisasContext *s, arg_rmr *a, int rm) { if (checkfn(s, a)) { - if (rm != RISCV_FRM_DYN) { - gen_set_rm(s, RISCV_FRM_DYN); - } - uint32_t data = 0; TCGLabel *over = gen_new_label(); - gen_set_rm(s, rm); + gen_set_rm_chkfrm(s, rm); tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over);
@@ -2882,17 +2878,13 @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a) static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ { \ if (CHECK(s, a)) { \ - if (FRM != RISCV_FRM_DYN) { \ - gen_set_rm(s, RISCV_FRM_DYN); \ - } \ - \ uint32_t data = 0; \ static gen_helper_gvec_3_ptr * const fns[2] = { \ gen_helper_##HELPER##_h, \ gen_helper_##HELPER##_w, \ }; \ TCGLabel *over = gen_new_label(); \ - gen_set_rm(s, FRM); \ + gen_set_rm_chkfrm(s, FRM); \ tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ \
@@ -3005,17 +2997,13 @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ { \ if (CHECK(s, a)) { \ - if (FRM != RISCV_FRM_DYN) { \ - gen_set_rm(s, RISCV_FRM_DYN); \ - } \ - \ uint32_t data = 0; \ static gen_helper_gvec_3_ptr * const fns[2] = { \ gen_helper_##HELPER##_h, \ gen_helper_##HELPER##_w, \ }; \ TCGLabel *over = gen_new_label(); \ - gen_set_rm(s, FRM); \ + gen_set_rm_chkfrm(s, FRM); \ tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ \
@@ -3060,10 +3048,6 @@ static bool opxfv_narrow_check(DisasContext *s, arg_rmr *a) static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ { \ if (opxfv_narrow_check(s, a)) { \ - if (FRM != RISCV_FRM_DYN) { \ - gen_set_rm(s, RISCV_FRM_DYN); \ - } \ - \ uint32_t data = 0; \ static gen_helper_gvec_3_ptr * const fns[3] = { \ gen_helper_##HELPER##_b, \
@@ -3071,7 +3055,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ gen_helper_##HELPER##_w, \ }; \ TCGLabel *over = gen_new_label(); \ - gen_set_rm(s, FRM); \ + gen_set_rm_chkfrm(s, FRM); \ tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ \
Signature · 1 line
2.39.0
[PULL 29/37] hw/riscv/virt.c: remove 'is_32_bit' param from create_fdt_socket_cpus()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
create_fdt_socket_cpus() writes a different 'mmu-type' value if we're running in 32 or 64 bits. However, the flag is being calculated during virt_machine_init(), and is passed around in create_fdt(), then create_fdt_socket(), and then finally create_fdt_socket_cpus(). None of the intermediate functions are using the flag, which is a bit misleading.
Remove 'is_32_bit' flag from create_fdt_socket_cpus() and calculate it using the already available RISCVVirtState pointer. This will also change the signature of create_fdt_socket() and create_fdt(), making it clear that these functions don't do anything special when we're running in 32 bit mode.
Message-Id: <[email protected]>
--- hw/riscv/virt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
hw/riscv/virt.c +9 -9
@@ -223,12 +223,13 @@ static void create_pcie_irq_map(RISCVVirtState *s, void *fdt, char *nodename,static void create_fdt_socket_cpus (RISCVVirtState *s,int socket,char *clust_name,uint32_t *phandle, -bool is_32_bit,uint32_t *intc_phandles) +uint32_t *intc_phandles) {int cpu;uint32_t cpu_phandle;MachineState *mc =MACHINE (s);char *name, *cpu_name, *core_name, *intc_name; +bool is_32_bit =riscv_is_32bit (&s->soc[0 ]);for (cpu = s->soc[socket].num_harts -1 ; cpu >=0 ; cpu--) { cpu_phandle = (*phandle)++;
@@ -721,7 +722,7 @@ static void create_fdt_pmu(RISCVVirtState *s) } static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, - bool is_32_bit, uint32_t *phandle, + uint32_t *phandle, uint32_t *irq_mmio_phandle, uint32_t *irq_pcie_phandle, uint32_t *irq_virtio_phandle,
@@ -750,7 +751,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap,qemu_fdt_add_subnode (mc->fdt, clust_name);create_fdt_socket_cpus (s, socket, clust_name, phandle, - is_32_bit, &intc_phandles[phandle_pos]); + &intc_phandles[phandle_pos]);create_fdt_socket_memory (s, memmap, socket);
@@ -998,8 +999,7 @@ static void create_fdt_fw_cfg(RISCVVirtState *s, const MemMapEntry *memmap)g_free (nodename); } -static void create_fdt (RISCVVirtState *s,const MemMapEntry *memmap, -bool is_32_bit) +static void create_fdt (RISCVVirtState *s,const MemMapEntry *memmap) {MachineState *mc =MACHINE (s);uint32_t phandle =1 , irq_mmio_phandle =1 , msi_pcie_phandle =1 ;
@@ -1031,9 +1031,9 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap,qemu_fdt_setprop_cell (mc->fdt,"/soc" ,"#size-cells" ,0x2 );qemu_fdt_setprop_cell (mc->fdt,"/soc" ,"#address-cells" ,0x2 ); -create_fdt_sockets (s, memmap, is_32_bit, &phandle, - &irq_mmio_phandle, &irq_pcie_phandle, &irq_virtio_phandle, - &msi_pcie_phandle); +create_fdt_sockets (s, memmap, &phandle, &irq_mmio_phandle, + &irq_pcie_phandle, &irq_virtio_phandle, + &msi_pcie_phandle);create_fdt_virtio (s, memmap, irq_virtio_phandle);
@@ -1507,7 +1507,7 @@ static void virt_machine_init(MachineState *machine)virt_flash_map (s, system_memory);/* create device tree */ -create_fdt (s, memmap,riscv_is_32bit (&s->soc[0 ])); +create_fdt (s, memmap); s->machine_done.notify = virt_machine_done;qemu_add_machine_init_done_notifier (&s->machine_done);
Signature · 1 line
2.39.0
[PULL 32/37] target/riscv: Fix up masking of vsip/vsie accesses
In reply to Alistair FrancisFrom: Andrew Bresticker <[email protected]>
The current logic attempts to shift the VS-level bits into their correct position in mip while leaving the remaining bits in-tact. This is both pointless and likely incorrect since one would expect that any new, future VS-level interrupts will get their own position in mip rather than sharing with their (H)S-level equivalent. Fix this, and make the logic more readable, by just making off the VS-level bits and shifting them into position.
This also fixes reads of vsip, which would only ever report vsip.VSSIP since the non-writable bits got masked off as well.
Message-Id: <[email protected]>
--- target/riscv/csr.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-)
target/riscv/csr.c +11 -24
@@ -2305,22 +2305,15 @@ static RISCVException rmw_vsie64(CPURISCVState *env, int csrno, uint64_t new_val, uint64_t wr_mask) {RISCVException ret; -uint64_t rval, vsbits, mask = env->hideleg &VS_MODE_INTERRUPTS ; +uint64_t rval, mask = env->hideleg &VS_MODE_INTERRUPTS ;/* Bring VS-level bits to correct position */ - vsbits = new_val & (VS_MODE_INTERRUPTS >>1 ); - new_val &= ~(VS_MODE_INTERRUPTS >>1 ); - new_val |= vsbits <<1 ; - vsbits = wr_mask & (VS_MODE_INTERRUPTS >>1 ); - wr_mask &= ~(VS_MODE_INTERRUPTS >>1 ); - wr_mask |= vsbits <<1 ; + new_val = (new_val & (VS_MODE_INTERRUPTS >>1 )) <<1 ; + wr_mask = (wr_mask & (VS_MODE_INTERRUPTS >>1 )) <<1 ; ret =rmw_mie64 (env, csrno, &rval, new_val, wr_mask & mask);if (ret_val) { - rval &= mask; - vsbits = rval &VS_MODE_INTERRUPTS ; - rval &= ~VS_MODE_INTERRUPTS ; - *ret_val = rval | (vsbits >>1 ); + *ret_val = (rval & mask) >>1 ; }return ret;
@@ -2521,22 +2514,16 @@ static RISCVException rmw_vsip64(CPURISCVState *env, int csrno, uint64_t new_val, uint64_t wr_mask) {RISCVException ret; -uint64_t rval, vsbits, mask = env->hideleg & vsip_writable_mask; +uint64_t rval, mask = env->hideleg &VS_MODE_INTERRUPTS ;/* Bring VS-level bits to correct position */ - vsbits = new_val & (VS_MODE_INTERRUPTS >>1 ); - new_val &= ~(VS_MODE_INTERRUPTS >>1 ); - new_val |= vsbits <<1 ; - vsbits = wr_mask & (VS_MODE_INTERRUPTS >>1 ); - wr_mask &= ~(VS_MODE_INTERRUPTS >>1 ); - wr_mask |= vsbits <<1 ; - - ret =rmw_mip64 (env, csrno, &rval, new_val, wr_mask & mask); + new_val = (new_val & (VS_MODE_INTERRUPTS >>1 )) <<1 ; + wr_mask = (wr_mask & (VS_MODE_INTERRUPTS >>1 )) <<1 ; + + ret =rmw_mip64 (env, csrno, &rval, new_val, + wr_mask & mask & vsip_writable_mask);if (ret_val) { - rval &= mask; - vsbits = rval &VS_MODE_INTERRUPTS ; - rval &= ~VS_MODE_INTERRUPTS ; - *ret_val = rval | (vsbits >>1 ); + *ret_val = (rval & mask) >>1 ; }return ret;
Signature · 1 line
2.39.0
[PULL 20/37] hw/riscv: write bootargs 'chosen' FDT after riscv_load_kernel()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
The sifive_u, spike and virt machines are writing the 'bootargs' FDT node during their respective create_fdt().
Given that bootargs is written only when '-append' is used, and this option is only allowed with the '-kernel' option, which in turn is already being check before executing riscv_load_kernel(), write 'bootargs' in the same code path as riscv_load_kernel().
Message-Id: <[email protected]>
--- hw/riscv/sifive_u.c | 11 +++++------ hw/riscv/spike.c | 9 +++++---- hw/riscv/virt.c | 11 +++++------ 3 files changed, 15 insertions(+), 16 deletions(-)
hw/riscv/sifive_u.c +5 -6
@@ -117,7 +117,6 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,error_report ("load_device_tree() failed" );exit (1 ); } - goto update_bootargs; }else { fdt = ms->fdt =create_device_tree (&fdt_size);if (!fdt) {
@@ -510,11 +509,6 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,qemu_fdt_setprop_string (fdt,"/aliases" ,"serial0" , nodename);g_free (nodename); - -update_bootargs: -if (cmdline && *cmdline) { -qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , cmdline); - } }static void sifive_u_machine_reset (void *opaque,int n,int level)
@@ -611,6 +605,11 @@ static void sifive_u_machine_init(MachineState *machine)riscv_load_initrd (machine->initrd_filename, machine->ram_size, kernel_entry, machine->fdt); } + +if (machine->kernel_cmdline && *machine->kernel_cmdline) { +qemu_fdt_setprop_string (machine->fdt,"/chosen" ,"bootargs" , + machine->kernel_cmdline); + } }else {/* * If dynamic firmware is used, it doesn't know where is the next mode
hw/riscv/spike.c +5 -4
@@ -179,10 +179,6 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,qemu_fdt_add_subnode (fdt,"/chosen" );qemu_fdt_setprop_string (fdt,"/chosen" ,"stdout-path" ,"/htif" ); - -if (cmdline && *cmdline) { -qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , cmdline); - } }static bool spike_test_elf_image (char *filename)
@@ -319,6 +315,11 @@ static void spike_board_init(MachineState *machine)riscv_load_initrd (machine->initrd_filename, machine->ram_size, kernel_entry, machine->fdt); } + +if (machine->kernel_cmdline && *machine->kernel_cmdline) { +qemu_fdt_setprop_string (machine->fdt,"/chosen" ,"bootargs" , + machine->kernel_cmdline); + } }else {/* * If dynamic firmware is used, it doesn't know where is the next mode
hw/riscv/virt.c +5 -6
@@ -1012,7 +1012,6 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap,error_report ("load_device_tree() failed" );exit (1 ); } - goto update_bootargs; }else { mc->fdt =create_device_tree (&s->fdt_size);if (!mc->fdt) {
@@ -1050,11 +1049,6 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap,create_fdt_fw_cfg (s, memmap);create_fdt_pmu (s); -update_bootargs: -if (cmdline && *cmdline) { -qemu_fdt_setprop_string (mc->fdt,"/chosen" ,"bootargs" , cmdline); - } -/* Pass seed to RNG */ qemu_guest_getrandom_nofail (rng_seed,sizeof (rng_seed));qemu_fdt_setprop (mc->fdt,"/chosen" ,"rng-seed" , rng_seed,sizeof (rng_seed));
@@ -1294,6 +1288,11 @@ static void virt_machine_done(Notifier *notifier, void *data)riscv_load_initrd (machine->initrd_filename, machine->ram_size, kernel_entry, machine->fdt); } + +if (machine->kernel_cmdline && *machine->kernel_cmdline) { +qemu_fdt_setprop_string (machine->fdt,"/chosen" ,"bootargs" , + machine->kernel_cmdline); + } }else {/* * If dynamic firmware is used, it doesn't know where is the next mode
Signature · 1 line
2.39.0
[PULL 17/37] hw/riscv/boot.c: exit early if filename is NULL in load functions
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
riscv_load_firmware(), riscv_load_initrd() and riscv_load_kernel() works under the assumption that a 'filename' parameter is always not NULL.
This is currently the case since all callers of these functions are checking for NULL before calling them. Add an g_assert() to make sure that a NULL value in these cases are to be considered a bug.
Message-Id: <[email protected]>
--- hw/riscv/boot.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/riscv/boot.c +6 -0
@@ -153,6 +153,8 @@ target_ulong riscv_load_firmware(const char *firmware_filename,uint64_t firmware_entry, firmware_end;ssize_t firmware_size; +g_assert (firmware_filename !=NULL ); +if (load_elf_ram_sym (firmware_filename,NULL ,NULL ,NULL , &firmware_entry,NULL , &firmware_end,NULL ,0 ,EM_RISCV ,1 ,0 ,NULL , true, sym_cb) >0 ) {
@@ -177,6 +179,8 @@ target_ulong riscv_load_kernel(const char *kernel_filename, {uint64_t kernel_load_base, kernel_entry; +g_assert (kernel_filename !=NULL ); +/* * NB: Use low address not ELF entry point to ensure that the fw_dynamic * behaviour when loading an ELF matches the fw_payload, fw_jump and BBL
@@ -209,6 +213,8 @@ hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size, {ssize_t size; +g_assert (filename !=NULL ); +/* * We want to put the initrd far enough into RAM that when the * kernel is uncompressed it will not clobber the initrd. However
Signature · 1 line
2.39.0
[PULL 08/37] hw/riscv: spike: Remove the out-of-date comments
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
Spike machine now supports OpenSBI plain binary bios image, so the comments are no longer valid.
Message-Id: <[email protected]>
--- hw/riscv/spike.c | 5 ----- 1 file changed, 5 deletions(-)
hw/riscv/spike.c +0 -5
@@ -255,11 +255,6 @@ static void spike_board_init(MachineState *machine)memory_region_add_subregion (system_memory, memmap[SPIKE_MROM ].base, mask_rom); -/* -* Not like other RISC-V machines that use plain binary bios images, -* keeping ELF files here was intentional because BIN files don't work -* for the Spike machine as HTIF emulation depends on ELF parsing. -*/ if (riscv_is_32bit (&s->soc[0 ])) { firmware_end_addr = riscv_find_and_load_firmware(machine, RISCV32_BIOS_BIN, memmap[SPIKE_DRAM].base,
Signature · 1 line
2.39.0
[PULL 22/37] hw/riscv/boot.c: use MachineState in riscv_load_kernel()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
All callers are using kernel_filename as machine->kernel_filename.
This will also simplify the changes in riscv_load_kernel() that we're going to do next.
Message-Id: <[email protected]>
--- include/hw/riscv/boot.h | 2 +- hw/riscv/boot.c | 3 ++- hw/riscv/microchip_pfsoc.c | 3 +-- hw/riscv/opentitan.c | 3 +-- hw/riscv/sifive_e.c | 3 +-- hw/riscv/sifive_u.c | 3 +-- hw/riscv/spike.c | 3 +-- hw/riscv/virt.c | 3 +-- 8 files changed, 9 insertions(+), 14 deletions(-)
include/hw/riscv/boot.h +1 -1
@@ -43,7 +43,7 @@ char *riscv_find_firmware(const char *firmware_filename,target_ulong riscv_load_firmware (const char *firmware_filename,hwaddr firmware_load_addr,symbol_fn_t sym_cb); -target_ulong riscv_load_kernel (const char *kernel_filename, +target_ulong riscv_load_kernel (MachineState *machine,target_ulong firmware_end_addr,symbol_fn_t sym_cb);void riscv_load_initrd (MachineState *machine,uint64_t kernel_entry);
hw/riscv/boot.c +2 -1
@@ -173,10 +173,11 @@ target_ulong riscv_load_firmware(const char *firmware_filename,exit (1 ); } -target_ulong riscv_load_kernel (const char *kernel_filename, +target_ulong riscv_load_kernel (MachineState *machine,target_ulong kernel_start_addr,symbol_fn_t sym_cb) { +const char *kernel_filename = machine->kernel_filename;uint64_t kernel_load_base, kernel_entry;g_assert (kernel_filename !=NULL );
hw/riscv/microchip_pfsoc.c +1 -2
@@ -629,8 +629,7 @@ static void microchip_icicle_kit_machine_init(MachineState *machine) kernel_start_addr =riscv_calc_kernel_start_addr (&s->soc.u_cpus, firmware_end_addr); - kernel_entry =riscv_load_kernel (machine->kernel_filename, - kernel_start_addr,NULL ); + kernel_entry =riscv_load_kernel (machine, kernel_start_addr,NULL );if (machine->initrd_filename) {riscv_load_initrd (machine, kernel_entry);
hw/riscv/opentitan.c +1 -2
@@ -101,8 +101,7 @@ static void opentitan_board_init(MachineState *machine) }if (machine->kernel_filename) { -riscv_load_kernel (machine->kernel_filename, - memmap[IBEX_DEV_RAM ].base,NULL ); +riscv_load_kernel (machine, memmap[IBEX_DEV_RAM ].base,NULL ); } }
hw/riscv/sifive_e.c +1 -2
@@ -114,8 +114,7 @@ static void sifive_e_machine_init(MachineState *machine) memmap[SIFIVE_E_DEV_MROM].base, &address_space_memory);if (machine->kernel_filename) { -riscv_load_kernel (machine->kernel_filename, - memmap[SIFIVE_E_DEV_DTIM ].base,NULL ); +riscv_load_kernel (machine, memmap[SIFIVE_E_DEV_DTIM ].base,NULL ); } }
hw/riscv/sifive_u.c +1 -2
@@ -598,8 +598,7 @@ static void sifive_u_machine_init(MachineState *machine) kernel_start_addr =riscv_calc_kernel_start_addr (&s->soc.u_cpus, firmware_end_addr); - kernel_entry =riscv_load_kernel (machine->kernel_filename, - kernel_start_addr,NULL ); + kernel_entry =riscv_load_kernel (machine, kernel_start_addr,NULL );if (machine->initrd_filename) {riscv_load_initrd (machine, kernel_entry);
hw/riscv/spike.c +1 -2
@@ -307,8 +307,7 @@ static void spike_board_init(MachineState *machine) kernel_start_addr =riscv_calc_kernel_start_addr (&s->soc[0 ], firmware_end_addr); - kernel_entry =riscv_load_kernel (machine->kernel_filename, - kernel_start_addr, + kernel_entry =riscv_load_kernel (machine, kernel_start_addr, htif_symbol_callback);if (machine->initrd_filename) {
hw/riscv/virt.c +1 -2
@@ -1281,8 +1281,7 @@ static void virt_machine_done(Notifier *notifier, void *data) kernel_start_addr =riscv_calc_kernel_start_addr (&s->soc[0 ], firmware_end_addr); - kernel_entry =riscv_load_kernel (machine->kernel_filename, - kernel_start_addr,NULL ); + kernel_entry =riscv_load_kernel (machine, kernel_start_addr,NULL );if (machine->initrd_filename) {riscv_load_initrd (machine, kernel_entry);
Signature · 1 line
2.39.0
[PULL 21/37] hw/riscv/boot.c: use MachineState in riscv_load_initrd()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
'filename', 'mem_size' and 'fdt' from riscv_load_initrd() can all be retrieved by the MachineState object for all callers.
Message-Id: <[email protected]>
--- include/hw/riscv/boot.h | 3 +-- hw/riscv/boot.c | 6 ++++-- hw/riscv/microchip_pfsoc.c | 3 +-- hw/riscv/sifive_u.c | 3 +-- hw/riscv/spike.c | 3 +-- hw/riscv/virt.c | 3 +-- 6 files changed, 9 insertions(+), 12 deletions(-)
include/hw/riscv/boot.h +1 -2
@@ -46,8 +46,7 @@ target_ulong riscv_load_firmware(const char *firmware_filename,target_ulong riscv_load_kernel (const char *kernel_filename,target_ulong firmware_end_addr,symbol_fn_t sym_cb); -void riscv_load_initrd (const char *filename,uint64_t mem_size, -uint64_t kernel_entry,void *fdt); +void riscv_load_initrd (MachineState *machine,uint64_t kernel_entry);uint64_t riscv_load_fdt (hwaddr dram_start,uint64_t dram_size,void *fdt); void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts, hwaddr saddr,
hw/riscv/boot.c +4 -2
@@ -208,9 +208,11 @@ target_ulong riscv_load_kernel(const char *kernel_filename,exit (1 ); } -void riscv_load_initrd (const char *filename,uint64_t mem_size, -uint64_t kernel_entry,void *fdt) +void riscv_load_initrd (MachineState *machine,uint64_t kernel_entry) { +const char *filename = machine->initrd_filename; +uint64_t mem_size = machine->ram_size; +void *fdt = machine->fdt;hwaddr start, end;ssize_t size;
hw/riscv/microchip_pfsoc.c +1 -2
@@ -633,8 +633,7 @@ static void microchip_icicle_kit_machine_init(MachineState *machine) kernel_start_addr, NULL);if (machine->initrd_filename) { -riscv_load_initrd (machine->initrd_filename, machine->ram_size, - kernel_entry, machine->fdt); +riscv_load_initrd (machine, kernel_entry); }if (machine->kernel_cmdline && *machine->kernel_cmdline) {
hw/riscv/sifive_u.c +1 -2
@@ -602,8 +602,7 @@ static void sifive_u_machine_init(MachineState *machine) kernel_start_addr, NULL);if (machine->initrd_filename) { -riscv_load_initrd (machine->initrd_filename, machine->ram_size, - kernel_entry, machine->fdt); +riscv_load_initrd (machine, kernel_entry); }if (machine->kernel_cmdline && *machine->kernel_cmdline) {
hw/riscv/spike.c +1 -2
@@ -312,8 +312,7 @@ static void spike_board_init(MachineState *machine) htif_symbol_callback);if (machine->initrd_filename) { -riscv_load_initrd (machine->initrd_filename, machine->ram_size, - kernel_entry, machine->fdt); +riscv_load_initrd (machine, kernel_entry); }if (machine->kernel_cmdline && *machine->kernel_cmdline) {
hw/riscv/virt.c +1 -2
@@ -1285,8 +1285,7 @@ static void virt_machine_done(Notifier *notifier, void *data) kernel_start_addr, NULL);if (machine->initrd_filename) { -riscv_load_initrd (machine->initrd_filename, machine->ram_size, - kernel_entry, machine->fdt); +riscv_load_initrd (machine, kernel_entry); }if (machine->kernel_cmdline && *machine->kernel_cmdline) {
Signature · 1 line
2.39.0
[PULL 19/37] hw/riscv: write initrd 'chosen' FDT inside riscv_load_initrd()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
riscv_load_initrd() returns the initrd end addr while also writing a 'start' var to mark the addr start. These informations are being used just to write the initrd FDT node. Every existing caller of riscv_load_initrd() is writing the FDT in the same manner.
We can simplify things by writing the FDT inside riscv_load_initrd(), sparing callers from having to manage start/end addrs to write the FDT themselves.
An 'if (fdt)' check is already inserted at the end of the function because we'll end up using it later on with other boards that doesn´t have a FDT.
Message-Id: <[email protected]>
--- include/hw/riscv/boot.h | 4 ++-- hw/riscv/boot.c | 18 ++++++++++++------ hw/riscv/microchip_pfsoc.c | 10 ++-------- hw/riscv/sifive_u.c | 10 ++-------- hw/riscv/spike.c | 10 ++-------- hw/riscv/virt.c | 10 ++-------- 6 files changed, 22 insertions(+), 40 deletions(-)
include/hw/riscv/boot.h +2 -2
@@ -46,8 +46,8 @@ target_ulong riscv_load_firmware(const char *firmware_filename,target_ulong riscv_load_kernel (const char *kernel_filename,target_ulong firmware_end_addr,symbol_fn_t sym_cb); -hwaddr riscv_load_initrd (const char *filename,uint64_t mem_size, -uint64_t kernel_entry,hwaddr *start); +void riscv_load_initrd (const char *filename,uint64_t mem_size, +uint64_t kernel_entry,void *fdt);uint64_t riscv_load_fdt (hwaddr dram_start,uint64_t dram_size,void *fdt); void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts, hwaddr saddr,
hw/riscv/boot.c +12 -6
@@ -208,9 +208,10 @@ target_ulong riscv_load_kernel(const char *kernel_filename,exit (1 ); } -hwaddr riscv_load_initrd (const char *filename,uint64_t mem_size, -uint64_t kernel_entry,hwaddr *start) +void riscv_load_initrd (const char *filename,uint64_t mem_size, +uint64_t kernel_entry,void *fdt) { +hwaddr start, end;ssize_t size;g_assert (filename !=NULL );
@@ -226,18 +227,23 @@ hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,* halfway into RAM, and for boards with 256MB of RAM or more we put * the initrd at 128MB. */ - *start = kernel_entry +MIN (mem_size /2 ,128 * MiB); + start = kernel_entry +MIN (mem_size /2 ,128 * MiB); - size =load_ramdisk (filename, *start, mem_size - *start); + size =load_ramdisk (filename, start, mem_size - start);if (size ==-1 ) { - size =load_image_targphys (filename, *start, mem_size - *start); + size =load_image_targphys (filename, start, mem_size - start);if (size ==-1 ) {error_report ("could not load ramdisk '%s'" , filename);exit (1 ); } } -return *start + size; +/* Some RISC-V machines (e.g. opentitan) don't have a fdt. */ +if (fdt) { + end = start + size; +qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , start); +qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , end); + } }uint64_t riscv_load_fdt (hwaddr dram_base,uint64_t mem_size,void *fdt)
hw/riscv/microchip_pfsoc.c +2 -8
@@ -633,14 +633,8 @@ static void microchip_icicle_kit_machine_init(MachineState *machine) kernel_start_addr, NULL);if (machine->initrd_filename) { -hwaddr start; -hwaddr end =riscv_load_initrd (machine->initrd_filename, - machine->ram_size, kernel_entry, - &start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" , -"linux,initrd-start" , start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" , -"linux,initrd-end" , end); +riscv_load_initrd (machine->initrd_filename, machine->ram_size, + kernel_entry, machine->fdt); }if (machine->kernel_cmdline && *machine->kernel_cmdline) {
hw/riscv/sifive_u.c +2 -8
@@ -608,14 +608,8 @@ static void sifive_u_machine_init(MachineState *machine) kernel_start_addr, NULL);if (machine->initrd_filename) { -hwaddr start; -hwaddr end =riscv_load_initrd (machine->initrd_filename, - machine->ram_size, kernel_entry, - &start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" , -"linux,initrd-start" , start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" ,"linux,initrd-end" , - end); +riscv_load_initrd (machine->initrd_filename, machine->ram_size, + kernel_entry, machine->fdt); } }else {/*
hw/riscv/spike.c +2 -8
@@ -316,14 +316,8 @@ static void spike_board_init(MachineState *machine) htif_symbol_callback);if (machine->initrd_filename) { -hwaddr start; -hwaddr end =riscv_load_initrd (machine->initrd_filename, - machine->ram_size, kernel_entry, - &start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" , -"linux,initrd-start" , start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" ,"linux,initrd-end" , - end); +riscv_load_initrd (machine->initrd_filename, machine->ram_size, + kernel_entry, machine->fdt); } }else {/*
hw/riscv/virt.c +2 -8
@@ -1291,14 +1291,8 @@ static void virt_machine_done(Notifier *notifier, void *data) kernel_start_addr, NULL);if (machine->initrd_filename) { -hwaddr start; -hwaddr end =riscv_load_initrd (machine->initrd_filename, - machine->ram_size, kernel_entry, - &start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" , -"linux,initrd-start" , start); -qemu_fdt_setprop_cell (machine->fdt,"/chosen" ,"linux,initrd-end" , - end); +riscv_load_initrd (machine->initrd_filename, machine->ram_size, + kernel_entry, machine->fdt); } }else {/*
Signature · 1 line
2.39.0
[PULL 36/37] target/riscv: Remove helper_set_rod_rounding_mode
In reply to Alistair FrancisFrom: Richard Henderson <[email protected]>
The only setting of RISCV_FRM_ROD is from the vector unit, and now handled by helper_set_rounding_mode_chkfrm. This helper is now unused.
Message-Id: <[email protected]>
--- target/riscv/helper.h | 1 - target/riscv/fpu_helper.c | 5 ----- target/riscv/translate.c | 4 ---- 3 files changed, 10 deletions(-)
target/riscv/helper.h +0 -1
@@ -4,7 +4,6 @@ DEF_HELPER_2(raise_exception, noreturn, env, i32)/* Floating Point - rounding mode */ DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_WG, void, env, i32)DEF_HELPER_FLAGS_2 (set_rounding_mode_chkfrm,TCG_CALL_NO_WG , void, env, i32) -DEF_HELPER_FLAGS_1 (set_rod_rounding_mode,TCG_CALL_NO_WG , void, env) /* Floating Point - fused */DEF_HELPER_FLAGS_4 (fmadd_s,TCG_CALL_NO_RWG , i64, env, i64, i64, i64)
target/riscv/fpu_helper.c +0 -5
@@ -118,11 +118,6 @@ void helper_set_rounding_mode_chkfrm(CPURISCVState *env, uint32_t rm)set_float_rounding_mode (softrm, &env->fp_status); } -void helper_set_rod_rounding_mode (CPURISCVState *env) -{ -set_float_rounding_mode (float_round_to_odd, &env->fp_status); -} -static uint64_t do_fmadd_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2,uint64_t rs3,int flags) {
target/riscv/translate.c +0 -4
@@ -672,10 +672,6 @@ static void gen_set_rm(DisasContext *ctx, int rm) } ctx->frm = rm; -if (rm ==RISCV_FRM_ROD ) { -gen_helper_set_rod_rounding_mode (cpu_env); -return ; - }if (rm ==RISCV_FRM_DYN ) {/* The helper will return only if frm valid. */ ctx->frm_valid = true;
Signature · 1 line
2.39.0
[PULL 34/37] tcg/riscv: Use tcg_pcrel_diff in tcg_out_ldst
In reply to Alistair FrancisFrom: Richard Henderson <[email protected]>
We failed to update this with the w^x split, so misses the fact that true pc-relative offsets are usually small.
Message-Id: <[email protected]>
--- tcg/riscv/tcg-target.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/riscv/tcg-target.c.inc +1 -1
@@ -599,7 +599,7 @@ static void tcg_out_ldst(TCGContext *s, RISCVInsn opc, TCGReg data, intptr_t imm12 = sextreg(offset, 0, 12); if (offset != imm12) { - intptr_t diff = offset - (uintptr_t)s->code_ptr; + intptr_t diff = tcg_pcrel_diff(s, (void *)offset); if (addr == TCG_REG_ZERO && diff == (int32_t)diff) { imm12 = sextreg(diff, 0, 12);
Signature · 1 line
2.39.0
[PULL 33/37] target/riscv: Trap on writes to stimecmp from VS when hvictl.VTI=1
In reply to Alistair FrancisFrom: Andrew Bresticker <[email protected]>
Per the AIA specification, writes to stimecmp from VS level should trap when hvictl.VTI is set since the write may cause vsip.STIP to become unset.
Message-Id: <[email protected]>
--- target/riscv/csr.c | 6 ++++++ 1 file changed, 6 insertions(+)
target/riscv/csr.c +6 -0
@@ -1037,6 +1037,9 @@ static RISCVException write_stimecmp(CPURISCVState *env, int csrno,RISCVCPU *cpu =env_archcpu (env);if (riscv_cpu_virt_enabled (env)) { +if (env->hvictl &HVICTL_VTI ) { +return RISCV_EXCP_VIRT_INSTRUCTION_FAULT ; + }return write_vstimecmp (env, csrno, val); }
@@ -1057,6 +1060,9 @@ static RISCVException write_stimecmph(CPURISCVState *env, int csrno,RISCVCPU *cpu =env_archcpu (env);if (riscv_cpu_virt_enabled (env)) { +if (env->hvictl &HVICTL_VTI ) { +return RISCV_EXCP_VIRT_INSTRUCTION_FAULT ; + }return write_vstimecmph (env, csrno, val); }
Signature · 1 line
2.39.0
[PULL 12/37] hw/riscv: spike: Decouple create_fdt() dependency to ELF loading
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
At present create_fdt() calls htif_uses_elf_symbols() to determine whether to insert a <reg> property for the HTIF. This unfortunately creates a hidden dependency to riscv_load_{firmware,kernel} that create_fdt() must be called after the ELF {firmware,kernel} image has been loaded.
Decouple such dependency be adding a new parameter to create_fdt(), whether custom HTIF base address is used. The flag will be set if non ELF {firmware,kernel} image is given by user.
Message-Id: <[email protected]>
--- include/hw/char/riscv_htif.h | 5 +-- hw/char/riscv_htif.c | 17 +++++----- hw/riscv/spike.c | 61 ++++++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 24 deletions(-)
include/hw/char/riscv_htif.h +1 -4
@@ -44,11 +44,8 @@ typedef struct HTIFState {void htif_symbol_callback (const char *st_name,int st_info,uint64_t st_value,uint64_t st_size); -/* Check if HTIF uses ELF symbols */ -bool htif_uses_elf_symbols (void ); -/* legacy pre qom */ HTIFState *htif_mm_init (MemoryRegion *address_space,Chardev *chr, -uint64_t nonelf_base); +uint64_t nonelf_base,bool custom_base);#endif
hw/char/riscv_htif.c +7 -10
@@ -52,20 +52,17 @@#define PK_SYS_WRITE 64static uint64_t fromhost_addr, tohost_addr; -static int address_symbol_set;void htif_symbol_callback (const char *st_name,int st_info,uint64_t st_value,uint64_t st_size) {if (strcmp ("fromhost" , st_name) ==0 ) { - address_symbol_set |=1 ; fromhost_addr = st_value;if (st_size !=8 ) {error_report ("HTIF fromhost must be 8 bytes" );exit (1 ); } }else if (strcmp ("tohost" , st_name) ==0 ) { - address_symbol_set |=2 ; tohost_addr = st_value;if (st_size !=8 ) {error_report ("HTIF tohost must be 8 bytes" );
@@ -275,19 +272,19 @@ static const MemoryRegionOps htif_mm_ops = { .write = htif_mm_write, }; -bool htif_uses_elf_symbols (void ) -{ -return (address_symbol_set ==3 ) ? true : false; -} -HTIFState *htif_mm_init (MemoryRegion *address_space,Chardev *chr, -uint64_t nonelf_base) +uint64_t nonelf_base,bool custom_base) {uint64_t base, size, tohost_offset, fromhost_offset; -if (!htif_uses_elf_symbols ()) { +if (custom_base) { fromhost_addr = nonelf_base; tohost_addr = nonelf_base +8 ; + }else { +if (!fromhost_addr || !tohost_addr) { +error_report ("Invalid HTIF fromhost or tohost address" ); +exit (1 ); + } } base =MIN (tohost_addr, fromhost_addr);
hw/riscv/spike.c +51 -10
107 lines not on this page · raw message
Signature · 1 line
2.39.0
[PULL 23/37] target/riscv/cpu: set cpu->cfg in register_cpu_props()
In reply to Alistair FrancisFrom: Daniel Henrique Barboza <[email protected]>
There is an informal contract between the cpu_init() functions and riscv_cpu_realize(): if cpu->env.misa_ext is zero, assume that the default settings were loaded via register_cpu_props() and do validations to set env.misa_ext. If it's not zero, skip this whole process and assume that the board somehow did everything.
At this moment, all SiFive CPUs are setting a non-zero misa_ext during their cpu_init() and skipping a good chunk of riscv_cpu_realize(). This causes problems when the code being skipped in riscv_cpu_realize() contains fixes or assumptions that affects all CPUs, meaning that SiFive CPUs are missing out.
To allow this code to not be skipped anymore, all the cpu->cfg.ext_* attributes needs to be set during cpu_init() time. At this moment this is being done in register_cpu_props(). The SiFive boards are setting their own extensions during cpu_init() though, meaning that they don't want all the defaults from register_cpu_props().
Let's move the contract between *_cpu_init() and riscv_cpu_realize() to register_cpu_props(). Inside this function we'll check if cpu->env.misa_ext was set and, if that's the case, set all relevant cpu->cfg.ext_* attributes, and only that. Leave the 'misa_ext' = 0 case as is today, i.e. loading all the defaults from riscv_cpu_extensions[].
register_cpu_props() can then be called by all the cpu_init() functions, including the SiFive ones. This will make all CPUs behave more in line with what riscv_cpu_realize() expects.
This will also make the cpu_init() functions even more alike, but at this moment we would need some design changes in how we're initializing extensions/attributes (e.g. some CPUs are setting cfg options after register_cpu_props(), so we can't simply add the function to a common post_init() hook) to make a common cpu_init() code across all CPUs.
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 4 ++++ target/riscv/cpu.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
target/riscv/cpu.h +4 -0
@@ -63,6 +63,10 @@#define RV (x) ((target_ulong)1 << (x - 'A')) +/* +* Consider updating register_cpu_props() when adding +* new MISA bits here. +*/ #define RVI RV('I')#define RVE RV('E')/* E and I are mutually exclusive */ #define RVM RV('M')
target/riscv/cpu.c +40 -0
@@ -256,6 +256,7 @@ static void rv64_sifive_u_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,MXL_RV64 ,RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); +register_cpu_props (DEVICE (obj));set_priv_version (env,PRIV_VERSION_1_10_0 ); }
@@ -265,6 +266,7 @@ static void rv64_sifive_e_cpu_init(Object *obj)RISCVCPU *cpu =RISCV_CPU (obj);set_misa (env,MXL_RV64 ,RVI |RVM |RVA |RVC |RVU ); +register_cpu_props (DEVICE (obj));set_priv_version (env,PRIV_VERSION_1_10_0 ); cpu->cfg.mmu = false; }
@@ -299,6 +301,7 @@ static void rv32_sifive_u_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,MXL_RV32 ,RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); +register_cpu_props (DEVICE (obj));set_priv_version (env,PRIV_VERSION_1_10_0 ); }
@@ -308,6 +311,7 @@ static void rv32_sifive_e_cpu_init(Object *obj)RISCVCPU *cpu =RISCV_CPU (obj);set_misa (env,MXL_RV32 ,RVI |RVM |RVA |RVC |RVU ); +register_cpu_props (DEVICE (obj));set_priv_version (env,PRIV_VERSION_1_10_0 ); cpu->cfg.mmu = false; }
@@ -318,6 +322,7 @@ static void rv32_ibex_cpu_init(Object *obj)RISCVCPU *cpu =RISCV_CPU (obj);set_misa (env,MXL_RV32 ,RVI |RVM |RVC |RVU ); +register_cpu_props (DEVICE (obj));set_priv_version (env,PRIV_VERSION_1_11_0 ); cpu->cfg.mmu = false; cpu->cfg.epmp = true;
@@ -329,6 +334,7 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj)RISCVCPU *cpu =RISCV_CPU (obj);set_misa (env,MXL_RV32 ,RVI |RVM |RVA |RVF |RVC |RVU ); +register_cpu_props (DEVICE (obj));set_priv_version (env,PRIV_VERSION_1_10_0 ); cpu->cfg.mmu = false; }
@@ -1083,10 +1089,44 @@ static Property riscv_cpu_extensions[] = { DEFINE_PROP_END_OF_LIST(), }; +/* +* Register CPU props based on env.misa_ext. If a non-zero +* value was set, register only the required cpu->cfg.ext_* +* properties and leave. env.misa_ext = 0 means that we want +* all the default properties to be registered. +*/ static void register_cpu_props (DeviceState *dev) { +RISCVCPU *cpu =RISCV_CPU (OBJECT (dev)); +uint32_t misa_ext = cpu->env.misa_ext;Property *prop; +/* +* If misa_ext is not zero, set cfg properties now to +* allow them to be read during riscv_cpu_realize() +* later on. +*/ +if (cpu->env.misa_ext !=0 ) { + cpu->cfg.ext_i = misa_ext &RVI ; + cpu->cfg.ext_e = misa_ext &RVE ; + cpu->cfg.ext_m = misa_ext &RVM ; + cpu->cfg.ext_a = misa_ext &RVA ; + cpu->cfg.ext_f = misa_ext &RVF ; + cpu->cfg.ext_d = misa_ext &RVD ; + cpu->cfg.ext_v = misa_ext &RVV ; + cpu->cfg.ext_c = misa_ext &RVC ; + cpu->cfg.ext_s = misa_ext &RVS ; + cpu->cfg.ext_u = misa_ext &RVU ; + cpu->cfg.ext_h = misa_ext &RVH ; + cpu->cfg.ext_j = misa_ext &RVJ ; + +/* +* We don't want to set the default riscv_cpu_extensions +* in this case. +*/ +return ; + } +for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {qdev_property_add_static (dev, prop); }
Signature · 1 line
2.39.0
Peter Maydell
AppliedQuoted 18 lines · Alistair Francis
From: Alistair Francis <[email protected]>
The following changes since commit
239b8b0699a222fd21da1c5fdeba0a2456085a47:Merge tag 'trivial-branch-for-8.0-pull-request' of https://gitlab.com/laurent_vivier/qemu into staging (2023-01-19 15:05:29 +0000)
are available in the Git repository at:
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20230120
for you to fetch changes up to
b748352c555b42d497fe8ee00ee2e44eb8627660:
hw/riscv/virt.c: movecreate_fw_cfg()back tovirt_machine_init()(2023-01-20 10:14:14 +1000)----------------------------------------------------------------
Second RISC-V PR for QEMU 8.0
Quoted 9 lines
*
riscv_htif: Support console output via proxy syscall
* Cleanup firmware and device tree loading
* Fix elen check when using vector extensions
* add RISC-V OpenSBI boot test
* Ensure we always follow MISA parsing
* Fix up masking of vsip/vsie accesses
* Trap on writes to stimecmp from VS when hvictl.VTI=1
* Introducehelper_set_rounding_mode_chkfrm
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/8.0
for any user-visible changes.
-- PMM