1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946: |
---|---|---|---|
2 | 2 | ||
3 | The following changes since commit 239b8b0699a222fd21da1c5fdeba0a2456085a47: | 3 | Merge tag 'pull-error-2024-05-27' of https://repo.or.cz/qemu/armbru into staging (2024-05-27 06:40:42 -0700) |
4 | |||
5 | 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) | ||
6 | 4 | ||
7 | are available in the Git repository at: | 5 | are available in the Git repository at: |
8 | 6 | ||
9 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20230120 | 7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528 |
10 | 8 | ||
11 | for you to fetch changes up to b748352c555b42d497fe8ee00ee2e44eb8627660: | 9 | for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393: |
12 | 10 | ||
13 | hw/riscv/virt.c: move create_fw_cfg() back to virt_machine_init() (2023-01-20 10:14:14 +1000) | 11 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR (2024-05-28 12:20:27 +1000) |
14 | 12 | ||
15 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
16 | Second RISC-V PR for QEMU 8.0 | 14 | RISC-V PR for 9.1 |
17 | 15 | ||
18 | * riscv_htif: Support console output via proxy syscall | 16 | * APLICs add child earlier than realize |
19 | * Cleanup firmware and device tree loading | 17 | * Fix exposure of Zkr |
20 | * Fix elen check when using vector extensions | 18 | * Raise exceptions on wrs.nto |
21 | * add RISC-V OpenSBI boot test | 19 | * Implement SBI debug console (DBCN) calls for KVM |
22 | * Ensure we always follow MISA parsing | 20 | * Support 64-bit addresses for initrd |
23 | * Fix up masking of vsip/vsie accesses | 21 | * Change RISCV_EXCP_SEMIHOST exception number to 63 |
24 | * Trap on writes to stimecmp from VS when hvictl.VTI=1 | 22 | * Tolerate KVM disable ext errors |
25 | * Introduce helper_set_rounding_mode_chkfrm | 23 | * Set tval in breakpoints |
24 | * Add support for Zve32x extension | ||
25 | * Add support for Zve64x extension | ||
26 | * Relax vector register check in RISCV gdbstub | ||
27 | * Fix the element agnostic Vector function problem | ||
28 | * Fix Zvkb extension config | ||
29 | * Implement dynamic establishment of custom decoder | ||
30 | * Add th.sxstatus CSR emulation | ||
31 | * Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions | ||
32 | * Check single width operator for vector fp widen instructions | ||
33 | * Check single width operator for vfncvt.rod.f.f.w | ||
34 | * Remove redudant SEW checking for vector fp narrow/widen instructions | ||
35 | * Prioritize pmp errors in raise_mmu_exception() | ||
36 | * Do not set mtval2 for non guest-page faults | ||
37 | * Remove experimental prefix from "B" extension | ||
38 | * Fixup CBO extension register calculation | ||
39 | * Fix the hart bit setting of AIA | ||
40 | * Fix reg_width in ricsv_gen_dynamic_vector_feature() | ||
41 | * Decode all of the pmpcfg and pmpaddr CSRs | ||
42 | * Raise an exception when CSRRS/CSRRC writes a read-only CSR | ||
26 | 43 | ||
27 | ---------------------------------------------------------------- | 44 | ---------------------------------------------------------------- |
28 | Andrew Bresticker (2): | 45 | Alexei Filippov (1): |
29 | target/riscv: Fix up masking of vsip/vsie accesses | 46 | target/riscv: do not set mtval2 for non guest-page faults |
30 | target/riscv: Trap on writes to stimecmp from VS when hvictl.VTI=1 | ||
31 | 47 | ||
32 | Bin Meng (11): | 48 | Alistair Francis (2): |
33 | hw/char: riscv_htif: Avoid using magic numbers | 49 | target/riscv: rvzicbo: Fixup CBO extension register calculation |
34 | hw/char: riscv_htif: Drop {to, from}host_size in HTIFState | 50 | disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs |
35 | hw/char: riscv_htif: Drop useless assignment of memory region | ||
36 | hw/char: riscv_htif: Use conventional 's' for HTIFState | ||
37 | hw/char: riscv_htif: Move registers from CPUArchState to HTIFState | ||
38 | hw/char: riscv_htif: Remove forward declarations for non-existent variables | ||
39 | hw/char: riscv_htif: Support console output via proxy syscall | ||
40 | hw/riscv: spike: Remove the out-of-date comments | ||
41 | hw/riscv/boot.c: Introduce riscv_find_firmware() | ||
42 | hw/riscv: spike: Decouple create_fdt() dependency to ELF loading | ||
43 | target/riscv: Use TARGET_FMT_lx for env->mhartid | ||
44 | 51 | ||
45 | Daniel Henrique Barboza (20): | 52 | Andrew Jones (2): |
46 | hw/riscv/boot.c: make riscv_find_firmware() static | 53 | target/riscv/kvm: Fix exposure of Zkr |
47 | hw/riscv/boot.c: introduce riscv_default_firmware_name() | 54 | target/riscv: Raise exceptions on wrs.nto |
48 | tests/avocado: add RISC-V OpenSBI boot test | ||
49 | hw/riscv/spike: use 'fdt' from MachineState | ||
50 | hw/riscv/sifive_u: use 'fdt' from MachineState | ||
51 | hw/riscv/boot.c: exit early if filename is NULL in load functions | ||
52 | hw/riscv/spike.c: load initrd right after riscv_load_kernel() | ||
53 | hw/riscv: write initrd 'chosen' FDT inside riscv_load_initrd() | ||
54 | hw/riscv: write bootargs 'chosen' FDT after riscv_load_kernel() | ||
55 | hw/riscv/boot.c: use MachineState in riscv_load_initrd() | ||
56 | hw/riscv/boot.c: use MachineState in riscv_load_kernel() | ||
57 | target/riscv/cpu: set cpu->cfg in register_cpu_props() | ||
58 | target/riscv/cpu.c: do not skip misa logic in riscv_cpu_realize() | ||
59 | hw/riscv/spike.c: simplify create_fdt() | ||
60 | hw/riscv/virt.c: simplify create_fdt() | ||
61 | hw/riscv/sifive_u.c: simplify create_fdt() | ||
62 | hw/riscv/virt.c: remove 'is_32_bit' param from create_fdt_socket_cpus() | ||
63 | hw/riscv: use MachineState::fdt in riscv_socket_fdt_write_id() | ||
64 | hw/riscv: use ms->fdt in riscv_socket_fdt_write_distance_matrix() | ||
65 | hw/riscv/virt.c: move create_fw_cfg() back to virt_machine_init() | ||
66 | 55 | ||
67 | Dongxue Zhang (1): | 56 | Cheng Yang (1): |
68 | target/riscv/cpu.c: Fix elen check | 57 | hw/riscv/boot.c: Support 64-bit address for initrd |
69 | 58 | ||
70 | Richard Henderson (3): | 59 | Christoph Müllner (1): |
71 | tcg/riscv: Use tcg_pcrel_diff in tcg_out_ldst | 60 | riscv: thead: Add th.sxstatus CSR emulation |
72 | target/riscv: Introduce helper_set_rounding_mode_chkfrm | ||
73 | target/riscv: Remove helper_set_rod_rounding_mode | ||
74 | 61 | ||
75 | include/hw/char/riscv_htif.h | 19 +- | 62 | Clément Léger (1): |
76 | include/hw/riscv/boot.h | 9 +- | 63 | target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63 |
77 | include/hw/riscv/numa.h | 10 +- | 64 | |
78 | include/hw/riscv/sifive_u.h | 3 - | 65 | Daniel Henrique Barboza (6): |
79 | include/hw/riscv/spike.h | 2 - | 66 | target/riscv/kvm: implement SBI debug console (DBCN) calls |
80 | target/riscv/cpu.h | 8 +- | 67 | target/riscv/kvm: tolerate KVM disable ext errors |
81 | target/riscv/helper.h | 2 +- | 68 | target/riscv/debug: set tval=pc in breakpoint exceptions |
82 | hw/char/riscv_htif.c | 172 +++++++----- | 69 | trans_privileged.c.inc: set (m|s)tval on ebreak breakpoint |
83 | hw/riscv/boot.c | 105 +++++--- | 70 | target/riscv: prioritize pmp errors in raise_mmu_exception() |
84 | hw/riscv/microchip_pfsoc.c | 12 +- | 71 | riscv, gdbstub.c: fix reg_width in ricsv_gen_dynamic_vector_feature() |
85 | hw/riscv/numa.c | 14 +- | 72 | |
86 | hw/riscv/opentitan.c | 3 +- | 73 | Huang Tao (2): |
87 | hw/riscv/sifive_e.c | 3 +- | 74 | target/riscv: Fix the element agnostic function problem |
88 | hw/riscv/sifive_u.c | 53 ++-- | 75 | target/riscv: Implement dynamic establishment of custom decoder |
89 | hw/riscv/spike.c | 108 ++++---- | 76 | |
90 | hw/riscv/virt.c | 86 +++--- | 77 | Jason Chien (3): |
91 | target/riscv/cpu.c | 445 ++++++++++++++++++-------------- | 78 | target/riscv: Add support for Zve32x extension |
92 | target/riscv/csr.c | 41 ++- | 79 | target/riscv: Add support for Zve64x extension |
93 | target/riscv/fpu_helper.c | 36 ++- | 80 | target/riscv: Relax vector register check in RISCV gdbstub |
94 | target/riscv/machine.c | 6 +- | 81 | |
95 | target/riscv/translate.c | 21 +- | 82 | Max Chou (4): |
96 | target/riscv/insn_trans/trans_rvv.c.inc | 24 +- | 83 | target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions |
97 | tcg/riscv/tcg-target.c.inc | 2 +- | 84 | target/riscv: rvv: Check single width operator for vector fp widen instructions |
98 | tests/avocado/riscv_opensbi.py | 65 +++++ | 85 | target/riscv: rvv: Check single width operator for vfncvt.rod.f.f.w |
99 | 24 files changed, 713 insertions(+), 536 deletions(-) | 86 | target/riscv: rvv: Remove redudant SEW checking for vector fp narrow/widen instructions |
100 | create mode 100644 tests/avocado/riscv_opensbi.py | 87 | |
88 | Rob Bradford (1): | ||
89 | target/riscv: Remove experimental prefix from "B" extension | ||
90 | |||
91 | Yangyu Chen (1): | ||
92 | target/riscv/cpu.c: fix Zvkb extension config | ||
93 | |||
94 | Yong-Xuan Wang (1): | ||
95 | target/riscv/kvm.c: Fix the hart bit setting of AIA | ||
96 | |||
97 | Yu-Ming Chang (1): | ||
98 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR | ||
99 | |||
100 | yang.zhang (1): | ||
101 | hw/intc/riscv_aplic: APLICs should add child earlier than realize | ||
102 | |||
103 | MAINTAINERS | 1 + | ||
104 | target/riscv/cpu.h | 11 ++ | ||
105 | target/riscv/cpu_bits.h | 2 +- | ||
106 | target/riscv/cpu_cfg.h | 2 + | ||
107 | target/riscv/helper.h | 1 + | ||
108 | target/riscv/sbi_ecall_interface.h | 17 +++ | ||
109 | target/riscv/tcg/tcg-cpu.h | 15 +++ | ||
110 | disas/riscv.c | 65 +++++++++- | ||
111 | hw/intc/riscv_aplic.c | 8 +- | ||
112 | hw/riscv/boot.c | 4 +- | ||
113 | target/riscv/cpu.c | 10 +- | ||
114 | target/riscv/cpu_helper.c | 37 +++--- | ||
115 | target/riscv/csr.c | 71 +++++++++-- | ||
116 | target/riscv/debug.c | 3 + | ||
117 | target/riscv/gdbstub.c | 8 +- | ||
118 | target/riscv/kvm/kvm-cpu.c | 157 ++++++++++++++++++++++++- | ||
119 | target/riscv/op_helper.c | 17 ++- | ||
120 | target/riscv/tcg/tcg-cpu.c | 50 +++++--- | ||
121 | target/riscv/th_csr.c | 79 +++++++++++++ | ||
122 | target/riscv/translate.c | 31 +++-- | ||
123 | target/riscv/vector_internals.c | 22 ++++ | ||
124 | target/riscv/insn_trans/trans_privileged.c.inc | 2 + | ||
125 | target/riscv/insn_trans/trans_rvv.c.inc | 46 +++++--- | ||
126 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 +++-- | ||
127 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++- | ||
128 | target/riscv/meson.build | 1 + | ||
129 | 26 files changed, 596 insertions(+), 109 deletions(-) | ||
130 | create mode 100644 target/riscv/th_csr.c | ||
131 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bin Meng <bmeng@tinylab.org> | ||
2 | 1 | ||
3 | The Spike HTIF is poorly documented. The only relevant info we can | ||
4 | get from the internet is from Andrew Waterman at [1]. | ||
5 | |||
6 | Add a comment block before htif_handle_tohost_write() to explain | ||
7 | the tohost register format, and use meaningful macros instead of | ||
8 | magic numbers in the codes. | ||
9 | |||
10 | While we are here, correct 2 multi-line comment blocks that have | ||
11 | wrong format. | ||
12 | |||
13 | Link: https://github.com/riscv-software-src/riscv-isa-sim/issues/364#issuecomment-607657754 [1] | ||
14 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
15 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | Message-Id: <20221229091828.1945072-2-bmeng@tinylab.org> | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | --- | ||
20 | hw/char/riscv_htif.c | 72 ++++++++++++++++++++++++++++++++------------ | ||
21 | 1 file changed, 52 insertions(+), 20 deletions(-) | ||
22 | |||
23 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/hw/char/riscv_htif.c | ||
26 | +++ b/hw/char/riscv_htif.c | ||
27 | @@ -XXX,XX +XXX,XX @@ | ||
28 | } \ | ||
29 | } while (0) | ||
30 | |||
31 | +#define HTIF_DEV_SHIFT 56 | ||
32 | +#define HTIF_CMD_SHIFT 48 | ||
33 | + | ||
34 | +#define HTIF_DEV_SYSTEM 0 | ||
35 | +#define HTIF_DEV_CONSOLE 1 | ||
36 | + | ||
37 | +#define HTIF_SYSTEM_CMD_SYSCALL 0 | ||
38 | +#define HTIF_CONSOLE_CMD_GETC 0 | ||
39 | +#define HTIF_CONSOLE_CMD_PUTC 1 | ||
40 | + | ||
41 | static uint64_t fromhost_addr, tohost_addr; | ||
42 | static int address_symbol_set; | ||
43 | |||
44 | @@ -XXX,XX +XXX,XX @@ static void htif_recv(void *opaque, const uint8_t *buf, int size) | ||
45 | return; | ||
46 | } | ||
47 | |||
48 | - /* TODO - we need to check whether mfromhost is zero which indicates | ||
49 | - the device is ready to receive. The current implementation | ||
50 | - will drop characters */ | ||
51 | + /* | ||
52 | + * TODO - we need to check whether mfromhost is zero which indicates | ||
53 | + * the device is ready to receive. The current implementation | ||
54 | + * will drop characters | ||
55 | + */ | ||
56 | |||
57 | uint64_t val_written = htifstate->pending_read; | ||
58 | uint64_t resp = 0x100 | *buf; | ||
59 | @@ -XXX,XX +XXX,XX @@ static int htif_be_change(void *opaque) | ||
60 | return 0; | ||
61 | } | ||
62 | |||
63 | +/* | ||
64 | + * See below the tohost register format. | ||
65 | + * | ||
66 | + * Bits 63:56 indicate the "device". | ||
67 | + * Bits 55:48 indicate the "command". | ||
68 | + * | ||
69 | + * Device 0 is the syscall device, which is used to emulate Unixy syscalls. | ||
70 | + * It only implements command 0, which has two subfunctions: | ||
71 | + * - If bit 0 is clear, then bits 47:0 represent a pointer to a struct | ||
72 | + * describing the syscall. | ||
73 | + * - If bit 1 is set, then bits 47:1 represent an exit code, with a zero | ||
74 | + * value indicating success and other values indicating failure. | ||
75 | + * | ||
76 | + * Device 1 is the blocking character device. | ||
77 | + * - Command 0 reads a character | ||
78 | + * - Command 1 writes a character from the 8 LSBs of tohost | ||
79 | + * | ||
80 | + * For RV32, the tohost register is zero-extended, so only device=0 and | ||
81 | + * command=0 (i.e. HTIF syscalls/exit codes) are supported. | ||
82 | + */ | ||
83 | static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written) | ||
84 | { | ||
85 | - uint8_t device = val_written >> 56; | ||
86 | - uint8_t cmd = val_written >> 48; | ||
87 | + uint8_t device = val_written >> HTIF_DEV_SHIFT; | ||
88 | + uint8_t cmd = val_written >> HTIF_CMD_SHIFT; | ||
89 | uint64_t payload = val_written & 0xFFFFFFFFFFFFULL; | ||
90 | int resp = 0; | ||
91 | |||
92 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written) | ||
93 | * 0: riscv-tests Pass/Fail Reporting Only (no syscall proxy) | ||
94 | * 1: Console | ||
95 | */ | ||
96 | - if (unlikely(device == 0x0)) { | ||
97 | + if (unlikely(device == HTIF_DEV_SYSTEM)) { | ||
98 | /* frontend syscall handler, shutdown and exit code support */ | ||
99 | - if (cmd == 0x0) { | ||
100 | + if (cmd == HTIF_SYSTEM_CMD_SYSCALL) { | ||
101 | if (payload & 0x1) { | ||
102 | /* exit code */ | ||
103 | int exit_code = payload >> 1; | ||
104 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written) | ||
105 | } else { | ||
106 | qemu_log("HTIF device %d: unknown command\n", device); | ||
107 | } | ||
108 | - } else if (likely(device == 0x1)) { | ||
109 | + } else if (likely(device == HTIF_DEV_CONSOLE)) { | ||
110 | /* HTIF Console */ | ||
111 | - if (cmd == 0x0) { | ||
112 | + if (cmd == HTIF_CONSOLE_CMD_GETC) { | ||
113 | /* this should be a queue, but not yet implemented as such */ | ||
114 | htifstate->pending_read = val_written; | ||
115 | htifstate->env->mtohost = 0; /* clear to indicate we read */ | ||
116 | return; | ||
117 | - } else if (cmd == 0x1) { | ||
118 | + } else if (cmd == HTIF_CONSOLE_CMD_PUTC) { | ||
119 | qemu_chr_fe_write(&htifstate->chr, (uint8_t *)&payload, 1); | ||
120 | resp = 0x100 | (uint8_t)payload; | ||
121 | } else { | ||
122 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written) | ||
123 | " payload: %016" PRIx64, device, cmd, payload & 0xFF, payload); | ||
124 | } | ||
125 | /* | ||
126 | - * - latest bbl does not set fromhost to 0 if there is a value in tohost | ||
127 | - * - with this code enabled, qemu hangs waiting for fromhost to go to 0 | ||
128 | - * - with this code disabled, qemu works with bbl priv v1.9.1 and v1.10 | ||
129 | - * - HTIF needs protocol documentation and a more complete state machine | ||
130 | - | ||
131 | - while (!htifstate->fromhost_inprogress && | ||
132 | - htifstate->env->mfromhost != 0x0) { | ||
133 | - } | ||
134 | - */ | ||
135 | + * Latest bbl does not set fromhost to 0 if there is a value in tohost. | ||
136 | + * With this code enabled, qemu hangs waiting for fromhost to go to 0. | ||
137 | + * With this code disabled, qemu works with bbl priv v1.9.1 and v1.10. | ||
138 | + * HTIF needs protocol documentation and a more complete state machine. | ||
139 | + * | ||
140 | + * while (!htifstate->fromhost_inprogress && | ||
141 | + * htifstate->env->mfromhost != 0x0) { | ||
142 | + * } | ||
143 | + */ | ||
144 | htifstate->env->mfromhost = (val_written >> 48 << 48) | (resp << 16 >> 16); | ||
145 | htifstate->env->mtohost = 0; /* clear to indicate we read */ | ||
146 | } | ||
147 | @@ -XXX,XX +XXX,XX @@ static uint64_t htif_mm_read(void *opaque, hwaddr addr, unsigned size) | ||
148 | |||
149 | /* CPU wrote to an HTIF register */ | ||
150 | static void htif_mm_write(void *opaque, hwaddr addr, | ||
151 | - uint64_t value, unsigned size) | ||
152 | + uint64_t value, unsigned size) | ||
153 | { | ||
154 | HTIFState *htifstate = opaque; | ||
155 | if (addr == TOHOST_OFFSET1) { | ||
156 | -- | ||
157 | 2.39.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bin Meng <bmeng@tinylab.org> | ||
2 | 1 | ||
3 | These are not used anywhere. Drop them. | ||
4 | |||
5 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
6 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-Id: <20221229091828.1945072-3-bmeng@tinylab.org> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | include/hw/char/riscv_htif.h | 2 -- | ||
12 | 1 file changed, 2 deletions(-) | ||
13 | |||
14 | diff --git a/include/hw/char/riscv_htif.h b/include/hw/char/riscv_htif.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/hw/char/riscv_htif.h | ||
17 | +++ b/include/hw/char/riscv_htif.h | ||
18 | @@ -XXX,XX +XXX,XX @@ typedef struct HTIFState { | ||
19 | |||
20 | hwaddr tohost_offset; | ||
21 | hwaddr fromhost_offset; | ||
22 | - uint64_t tohost_size; | ||
23 | - uint64_t fromhost_size; | ||
24 | MemoryRegion mmio; | ||
25 | MemoryRegion *address_space; | ||
26 | MemoryRegion *main_mem; | ||
27 | -- | ||
28 | 2.39.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bin Meng <bmeng@tinylab.org> | ||
2 | 1 | ||
3 | struct HTIFState has 3 members for address space and memory region, | ||
4 | and are initialized during htif_mm_init(). But they are actually | ||
5 | useless. Drop them. | ||
6 | |||
7 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-Id: <20221229091828.1945072-4-bmeng@tinylab.org> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | include/hw/char/riscv_htif.h | 7 ++----- | ||
14 | hw/char/riscv_htif.c | 7 ++----- | ||
15 | hw/riscv/spike.c | 5 ++--- | ||
16 | 3 files changed, 6 insertions(+), 13 deletions(-) | ||
17 | |||
18 | diff --git a/include/hw/char/riscv_htif.h b/include/hw/char/riscv_htif.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/include/hw/char/riscv_htif.h | ||
21 | +++ b/include/hw/char/riscv_htif.h | ||
22 | @@ -XXX,XX +XXX,XX @@ typedef struct HTIFState { | ||
23 | hwaddr tohost_offset; | ||
24 | hwaddr fromhost_offset; | ||
25 | MemoryRegion mmio; | ||
26 | - MemoryRegion *address_space; | ||
27 | - MemoryRegion *main_mem; | ||
28 | - void *main_mem_ram_ptr; | ||
29 | |||
30 | CPURISCVState *env; | ||
31 | CharBackend chr; | ||
32 | @@ -XXX,XX +XXX,XX @@ void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value, | ||
33 | bool htif_uses_elf_symbols(void); | ||
34 | |||
35 | /* legacy pre qom */ | ||
36 | -HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem, | ||
37 | - CPURISCVState *env, Chardev *chr, uint64_t nonelf_base); | ||
38 | +HTIFState *htif_mm_init(MemoryRegion *address_space, CPURISCVState *env, | ||
39 | + Chardev *chr, uint64_t nonelf_base); | ||
40 | |||
41 | #endif | ||
42 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/hw/char/riscv_htif.c | ||
45 | +++ b/hw/char/riscv_htif.c | ||
46 | @@ -XXX,XX +XXX,XX @@ bool htif_uses_elf_symbols(void) | ||
47 | return (address_symbol_set == 3) ? true : false; | ||
48 | } | ||
49 | |||
50 | -HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem, | ||
51 | - CPURISCVState *env, Chardev *chr, uint64_t nonelf_base) | ||
52 | +HTIFState *htif_mm_init(MemoryRegion *address_space, CPURISCVState *env, | ||
53 | + Chardev *chr, uint64_t nonelf_base) | ||
54 | { | ||
55 | uint64_t base, size, tohost_offset, fromhost_offset; | ||
56 | |||
57 | @@ -XXX,XX +XXX,XX @@ HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem, | ||
58 | fromhost_offset = fromhost_addr - base; | ||
59 | |||
60 | HTIFState *s = g_new0(HTIFState, 1); | ||
61 | - s->address_space = address_space; | ||
62 | - s->main_mem = main_mem; | ||
63 | - s->main_mem_ram_ptr = memory_region_get_ram_ptr(main_mem); | ||
64 | s->env = env; | ||
65 | s->tohost_offset = tohost_offset; | ||
66 | s->fromhost_offset = fromhost_offset; | ||
67 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/hw/riscv/spike.c | ||
70 | +++ b/hw/riscv/spike.c | ||
71 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
72 | fdt_load_addr); | ||
73 | |||
74 | /* initialize HTIF using symbols found in load_kernel */ | ||
75 | - htif_mm_init(system_memory, mask_rom, | ||
76 | - &s->soc[0].harts[0].env, serial_hd(0), | ||
77 | - memmap[SPIKE_HTIF].base); | ||
78 | + htif_mm_init(system_memory, &s->soc[0].harts[0].env, | ||
79 | + serial_hd(0), memmap[SPIKE_HTIF].base); | ||
80 | } | ||
81 | |||
82 | static void spike_machine_instance_init(Object *obj) | ||
83 | -- | ||
84 | 2.39.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bin Meng <bmeng@tinylab.org> | ||
2 | 1 | ||
3 | QEMU source codes tend to use 's' to represent the hardware state. | ||
4 | Let's use it for HTIFState. | ||
5 | |||
6 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-Id: <20221229091828.1945072-5-bmeng@tinylab.org> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | hw/char/riscv_htif.c | 64 ++++++++++++++++++++++---------------------- | ||
13 | 1 file changed, 32 insertions(+), 32 deletions(-) | ||
14 | |||
15 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/char/riscv_htif.c | ||
18 | +++ b/hw/char/riscv_htif.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static int htif_can_recv(void *opaque) | ||
20 | */ | ||
21 | static void htif_recv(void *opaque, const uint8_t *buf, int size) | ||
22 | { | ||
23 | - HTIFState *htifstate = opaque; | ||
24 | + HTIFState *s = opaque; | ||
25 | |||
26 | if (size != 1) { | ||
27 | return; | ||
28 | @@ -XXX,XX +XXX,XX @@ static void htif_recv(void *opaque, const uint8_t *buf, int size) | ||
29 | * will drop characters | ||
30 | */ | ||
31 | |||
32 | - uint64_t val_written = htifstate->pending_read; | ||
33 | + uint64_t val_written = s->pending_read; | ||
34 | uint64_t resp = 0x100 | *buf; | ||
35 | |||
36 | - htifstate->env->mfromhost = (val_written >> 48 << 48) | (resp << 16 >> 16); | ||
37 | + s->env->mfromhost = (val_written >> 48 << 48) | (resp << 16 >> 16); | ||
38 | } | ||
39 | |||
40 | /* | ||
41 | @@ -XXX,XX +XXX,XX @@ static int htif_be_change(void *opaque) | ||
42 | * For RV32, the tohost register is zero-extended, so only device=0 and | ||
43 | * command=0 (i.e. HTIF syscalls/exit codes) are supported. | ||
44 | */ | ||
45 | -static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written) | ||
46 | +static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) | ||
47 | { | ||
48 | uint8_t device = val_written >> HTIF_DEV_SHIFT; | ||
49 | uint8_t cmd = val_written >> HTIF_CMD_SHIFT; | ||
50 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written) | ||
51 | /* HTIF Console */ | ||
52 | if (cmd == HTIF_CONSOLE_CMD_GETC) { | ||
53 | /* this should be a queue, but not yet implemented as such */ | ||
54 | - htifstate->pending_read = val_written; | ||
55 | - htifstate->env->mtohost = 0; /* clear to indicate we read */ | ||
56 | + s->pending_read = val_written; | ||
57 | + s->env->mtohost = 0; /* clear to indicate we read */ | ||
58 | return; | ||
59 | } else if (cmd == HTIF_CONSOLE_CMD_PUTC) { | ||
60 | - qemu_chr_fe_write(&htifstate->chr, (uint8_t *)&payload, 1); | ||
61 | + qemu_chr_fe_write(&s->chr, (uint8_t *)&payload, 1); | ||
62 | resp = 0x100 | (uint8_t)payload; | ||
63 | } else { | ||
64 | qemu_log("HTIF device %d: unknown command\n", device); | ||
65 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *htifstate, uint64_t val_written) | ||
66 | * With this code disabled, qemu works with bbl priv v1.9.1 and v1.10. | ||
67 | * HTIF needs protocol documentation and a more complete state machine. | ||
68 | * | ||
69 | - * while (!htifstate->fromhost_inprogress && | ||
70 | - * htifstate->env->mfromhost != 0x0) { | ||
71 | + * while (!s->fromhost_inprogress && | ||
72 | + * s->env->mfromhost != 0x0) { | ||
73 | * } | ||
74 | */ | ||
75 | - htifstate->env->mfromhost = (val_written >> 48 << 48) | (resp << 16 >> 16); | ||
76 | - htifstate->env->mtohost = 0; /* clear to indicate we read */ | ||
77 | + s->env->mfromhost = (val_written >> 48 << 48) | (resp << 16 >> 16); | ||
78 | + s->env->mtohost = 0; /* clear to indicate we read */ | ||
79 | } | ||
80 | |||
81 | -#define TOHOST_OFFSET1 (htifstate->tohost_offset) | ||
82 | -#define TOHOST_OFFSET2 (htifstate->tohost_offset + 4) | ||
83 | -#define FROMHOST_OFFSET1 (htifstate->fromhost_offset) | ||
84 | -#define FROMHOST_OFFSET2 (htifstate->fromhost_offset + 4) | ||
85 | +#define TOHOST_OFFSET1 (s->tohost_offset) | ||
86 | +#define TOHOST_OFFSET2 (s->tohost_offset + 4) | ||
87 | +#define FROMHOST_OFFSET1 (s->fromhost_offset) | ||
88 | +#define FROMHOST_OFFSET2 (s->fromhost_offset + 4) | ||
89 | |||
90 | /* CPU wants to read an HTIF register */ | ||
91 | static uint64_t htif_mm_read(void *opaque, hwaddr addr, unsigned size) | ||
92 | { | ||
93 | - HTIFState *htifstate = opaque; | ||
94 | + HTIFState *s = opaque; | ||
95 | if (addr == TOHOST_OFFSET1) { | ||
96 | - return htifstate->env->mtohost & 0xFFFFFFFF; | ||
97 | + return s->env->mtohost & 0xFFFFFFFF; | ||
98 | } else if (addr == TOHOST_OFFSET2) { | ||
99 | - return (htifstate->env->mtohost >> 32) & 0xFFFFFFFF; | ||
100 | + return (s->env->mtohost >> 32) & 0xFFFFFFFF; | ||
101 | } else if (addr == FROMHOST_OFFSET1) { | ||
102 | - return htifstate->env->mfromhost & 0xFFFFFFFF; | ||
103 | + return s->env->mfromhost & 0xFFFFFFFF; | ||
104 | } else if (addr == FROMHOST_OFFSET2) { | ||
105 | - return (htifstate->env->mfromhost >> 32) & 0xFFFFFFFF; | ||
106 | + return (s->env->mfromhost >> 32) & 0xFFFFFFFF; | ||
107 | } else { | ||
108 | qemu_log("Invalid htif read: address %016" PRIx64 "\n", | ||
109 | (uint64_t)addr); | ||
110 | @@ -XXX,XX +XXX,XX @@ static uint64_t htif_mm_read(void *opaque, hwaddr addr, unsigned size) | ||
111 | static void htif_mm_write(void *opaque, hwaddr addr, | ||
112 | uint64_t value, unsigned size) | ||
113 | { | ||
114 | - HTIFState *htifstate = opaque; | ||
115 | + HTIFState *s = opaque; | ||
116 | if (addr == TOHOST_OFFSET1) { | ||
117 | - if (htifstate->env->mtohost == 0x0) { | ||
118 | - htifstate->allow_tohost = 1; | ||
119 | - htifstate->env->mtohost = value & 0xFFFFFFFF; | ||
120 | + if (s->env->mtohost == 0x0) { | ||
121 | + s->allow_tohost = 1; | ||
122 | + s->env->mtohost = value & 0xFFFFFFFF; | ||
123 | } else { | ||
124 | - htifstate->allow_tohost = 0; | ||
125 | + s->allow_tohost = 0; | ||
126 | } | ||
127 | } else if (addr == TOHOST_OFFSET2) { | ||
128 | - if (htifstate->allow_tohost) { | ||
129 | - htifstate->env->mtohost |= value << 32; | ||
130 | - htif_handle_tohost_write(htifstate, htifstate->env->mtohost); | ||
131 | + if (s->allow_tohost) { | ||
132 | + s->env->mtohost |= value << 32; | ||
133 | + htif_handle_tohost_write(s, s->env->mtohost); | ||
134 | } | ||
135 | } else if (addr == FROMHOST_OFFSET1) { | ||
136 | - htifstate->fromhost_inprogress = 1; | ||
137 | - htifstate->env->mfromhost = value & 0xFFFFFFFF; | ||
138 | + s->fromhost_inprogress = 1; | ||
139 | + s->env->mfromhost = value & 0xFFFFFFFF; | ||
140 | } else if (addr == FROMHOST_OFFSET2) { | ||
141 | - htifstate->env->mfromhost |= value << 32; | ||
142 | - htifstate->fromhost_inprogress = 0; | ||
143 | + s->env->mfromhost |= value << 32; | ||
144 | + s->fromhost_inprogress = 0; | ||
145 | } else { | ||
146 | qemu_log("Invalid htif write: address %016" PRIx64 "\n", | ||
147 | (uint64_t)addr); | ||
148 | -- | ||
149 | 2.39.0 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: "yang.zhang" <yang.zhang@hexintek.com> |
---|---|---|---|
2 | 2 | ||
3 | This will make the code more in line with what the other boards are | 3 | Since only root APLICs can have hw IRQ lines, aplic->parent should |
4 | doing. We'll also avoid an extra check to machine->kernel_filename since | 4 | be initialized first. |
5 | we already checked that before executing riscv_load_kernel(). | ||
6 | 5 | ||
7 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 6 | Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation") |
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Signed-off-by: yang.zhang <yang.zhang@hexintek.com> |
10 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | 9 | Cc: qemu-stable <qemu-stable@nongnu.org> |
11 | Message-Id: <20230102115241.25733-6-dbarboza@ventanamicro.com> | 10 | Message-ID: <20240409014445.278-1-gaoshanliukou@163.com> |
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 12 | --- |
14 | hw/riscv/spike.c | 31 +++++++++++++++---------------- | 13 | hw/intc/riscv_aplic.c | 8 ++++---- |
15 | 1 file changed, 15 insertions(+), 16 deletions(-) | 14 | 1 file changed, 4 insertions(+), 4 deletions(-) |
16 | 15 | ||
17 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 16 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c |
18 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/riscv/spike.c | 18 | --- a/hw/intc/riscv_aplic.c |
20 | +++ b/hw/riscv/spike.c | 19 | +++ b/hw/intc/riscv_aplic.c |
21 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | 20 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, |
22 | g_free(firmware_name); | 21 | qdev_prop_set_bit(dev, "msimode", msimode); |
22 | qdev_prop_set_bit(dev, "mmode", mmode); | ||
23 | |||
24 | + if (parent) { | ||
25 | + riscv_aplic_add_child(parent, dev); | ||
26 | + } | ||
27 | + | ||
28 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
29 | |||
30 | if (!is_kvm_aia(msimode)) { | ||
31 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); | ||
23 | } | 32 | } |
24 | 33 | ||
25 | + /* Create device tree */ | 34 | - if (parent) { |
26 | + create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | 35 | - riscv_aplic_add_child(parent, dev); |
27 | + riscv_is_32bit(&s->soc[0]), htif_custom_base); | ||
28 | + | ||
29 | /* Load kernel */ | ||
30 | if (machine->kernel_filename) { | ||
31 | kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0], | ||
32 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
33 | kernel_entry = riscv_load_kernel(machine->kernel_filename, | ||
34 | kernel_start_addr, | ||
35 | htif_symbol_callback); | ||
36 | + | ||
37 | + if (machine->initrd_filename) { | ||
38 | + hwaddr start; | ||
39 | + hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
40 | + machine->ram_size, kernel_entry, | ||
41 | + &start); | ||
42 | + qemu_fdt_setprop_cell(machine->fdt, "/chosen", | ||
43 | + "linux,initrd-start", start); | ||
44 | + qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-end", | ||
45 | + end); | ||
46 | + } | ||
47 | } else { | ||
48 | /* | ||
49 | * If dynamic firmware is used, it doesn't know where is the next mode | ||
50 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
51 | kernel_entry = 0; | ||
52 | } | ||
53 | |||
54 | - /* Create device tree */ | ||
55 | - create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | ||
56 | - riscv_is_32bit(&s->soc[0]), htif_custom_base); | ||
57 | - | ||
58 | - /* Load initrd */ | ||
59 | - if (machine->kernel_filename && machine->initrd_filename) { | ||
60 | - hwaddr start; | ||
61 | - hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
62 | - machine->ram_size, kernel_entry, | ||
63 | - &start); | ||
64 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", | ||
65 | - "linux,initrd-start", start); | ||
66 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-end", | ||
67 | - end); | ||
68 | - } | 36 | - } |
69 | - | 37 | - |
70 | /* Compute the fdt load address in dram */ | 38 | if (!msimode) { |
71 | fdt_load_addr = riscv_load_fdt(memmap[SPIKE_DRAM].base, | 39 | for (i = 0; i < num_harts; i++) { |
72 | machine->ram_size, machine->fdt); | 40 | CPUState *cpu = cpu_by_arch_id(hartid_base + i); |
73 | -- | 41 | -- |
74 | 2.39.0 | 42 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Andrew Bresticker <abrestic@rivosinc.com> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Per the AIA specification, writes to stimecmp from VS level should | 3 | The Zkr extension may only be exposed to KVM guests if the VMM |
4 | trap when hvictl.VTI is set since the write may cause vsip.STIP to | 4 | implements the SEED CSR. Use the same implementation as TCG. |
5 | become unset. | ||
6 | 5 | ||
7 | Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp support") | 6 | Without this patch, running with a KVM which does not forward the |
8 | Signed-off-by: Andrew Bresticker <abrestic@rivosinc.com> | 7 | SEED CSR access to QEMU will result in an ILL exception being |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | injected into the guest (this results in Linux guests crashing on |
10 | Message-Id: <20221215224541.1423431-2-abrestic@rivosinc.com> | 9 | boot). And, when running with a KVM which does forward the access, |
10 | QEMU will crash, since QEMU doesn't know what to do with the exit. | ||
11 | |||
12 | Fixes: 3108e2f1c69d ("target/riscv/kvm: update KVM exts to Linux 6.8") | ||
13 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> | ||
14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
15 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
16 | Message-ID: <20240422134605.534207-2-ajones@ventanamicro.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 18 | --- |
13 | target/riscv/csr.c | 6 ++++++ | 19 | target/riscv/cpu.h | 3 +++ |
14 | 1 file changed, 6 insertions(+) | 20 | target/riscv/csr.c | 18 ++++++++++++++---- |
21 | target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++ | ||
22 | 3 files changed, 42 insertions(+), 4 deletions(-) | ||
15 | 23 | ||
24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/target/riscv/cpu.h | ||
27 | +++ b/target/riscv/cpu.h | ||
28 | @@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); | ||
29 | |||
30 | void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); | ||
31 | |||
32 | +target_ulong riscv_new_csr_seed(target_ulong new_value, | ||
33 | + target_ulong write_mask); | ||
34 | + | ||
35 | uint8_t satp_mode_max_from_map(uint32_t map); | ||
36 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); | ||
37 | |||
16 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 38 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
17 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/csr.c | 40 | --- a/target/riscv/csr.c |
19 | +++ b/target/riscv/csr.c | 41 | +++ b/target/riscv/csr.c |
20 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_stimecmp(CPURISCVState *env, int csrno, | 42 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno, |
21 | RISCVCPU *cpu = env_archcpu(env); | 43 | #endif |
22 | 44 | ||
23 | if (riscv_cpu_virt_enabled(env)) { | 45 | /* Crypto Extension */ |
24 | + if (env->hvictl & HVICTL_VTI) { | 46 | -static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
25 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | 47 | - target_ulong *ret_value, |
26 | + } | 48 | - target_ulong new_value, |
27 | return write_vstimecmp(env, csrno, val); | 49 | - target_ulong write_mask) |
50 | +target_ulong riscv_new_csr_seed(target_ulong new_value, | ||
51 | + target_ulong write_mask) | ||
52 | { | ||
53 | uint16_t random_v; | ||
54 | Error *random_e = NULL; | ||
55 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, | ||
56 | rval = random_v | SEED_OPST_ES16; | ||
28 | } | 57 | } |
29 | 58 | ||
30 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_stimecmph(CPURISCVState *env, int csrno, | 59 | + return rval; |
31 | RISCVCPU *cpu = env_archcpu(env); | 60 | +} |
32 | 61 | + | |
33 | if (riscv_cpu_virt_enabled(env)) { | 62 | +static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
34 | + if (env->hvictl & HVICTL_VTI) { | 63 | + target_ulong *ret_value, |
35 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | 64 | + target_ulong new_value, |
36 | + } | 65 | + target_ulong write_mask) |
37 | return write_vstimecmph(env, csrno, val); | 66 | +{ |
67 | + target_ulong rval; | ||
68 | + | ||
69 | + rval = riscv_new_csr_seed(new_value, write_mask); | ||
70 | + | ||
71 | if (ret_value) { | ||
72 | *ret_value = rval; | ||
38 | } | 73 | } |
39 | 74 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | |
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/target/riscv/kvm/kvm-cpu.c | ||
77 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
78 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
79 | return ret; | ||
80 | } | ||
81 | |||
82 | +static int kvm_riscv_handle_csr(CPUState *cs, struct kvm_run *run) | ||
83 | +{ | ||
84 | + target_ulong csr_num = run->riscv_csr.csr_num; | ||
85 | + target_ulong new_value = run->riscv_csr.new_value; | ||
86 | + target_ulong write_mask = run->riscv_csr.write_mask; | ||
87 | + int ret = 0; | ||
88 | + | ||
89 | + switch (csr_num) { | ||
90 | + case CSR_SEED: | ||
91 | + run->riscv_csr.ret_value = riscv_new_csr_seed(new_value, write_mask); | ||
92 | + break; | ||
93 | + default: | ||
94 | + qemu_log_mask(LOG_UNIMP, | ||
95 | + "%s: un-handled CSR EXIT for CSR %lx\n", | ||
96 | + __func__, csr_num); | ||
97 | + ret = -1; | ||
98 | + break; | ||
99 | + } | ||
100 | + | ||
101 | + return ret; | ||
102 | +} | ||
103 | + | ||
104 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
105 | { | ||
106 | int ret = 0; | ||
107 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
108 | case KVM_EXIT_RISCV_SBI: | ||
109 | ret = kvm_riscv_handle_sbi(cs, run); | ||
110 | break; | ||
111 | + case KVM_EXIT_RISCV_CSR: | ||
112 | + ret = kvm_riscv_handle_csr(cs, run); | ||
113 | + break; | ||
114 | default: | ||
115 | qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", | ||
116 | __func__, run->exit_reason); | ||
40 | -- | 117 | -- |
41 | 2.39.0 | 118 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The only setting of RISCV_FRM_ROD is from the vector unit, | 3 | Implementing wrs.nto to always just return is consistent with the |
4 | and now handled by helper_set_rounding_mode_chkfrm. | 4 | specification, as the instruction is permitted to terminate the |
5 | This helper is now unused. | 5 | stall for any reason, but it's not useful for virtualization, where |
6 | we'd like the guest to trap to the hypervisor in order to allow | ||
7 | scheduling of the lock holding VCPU. Change to always immediately | ||
8 | raise exceptions when the appropriate conditions are present, | ||
9 | otherwise continue to just return. Note, immediately raising | ||
10 | exceptions is also consistent with the specification since the | ||
11 | time limit that should expire prior to the exception is | ||
12 | implementation-specific. | ||
6 | 13 | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 14 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> |
15 | Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu> | ||
8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-Id: <20230115160657.3169274-3-richard.henderson@linaro.org> | 18 | Message-ID: <20240424142808.62936-2-ajones@ventanamicro.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 20 | --- |
13 | target/riscv/helper.h | 1 - | 21 | target/riscv/helper.h | 1 + |
14 | target/riscv/fpu_helper.c | 5 ----- | 22 | target/riscv/op_helper.c | 11 ++++++++ |
15 | target/riscv/translate.c | 4 ---- | 23 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++------- |
16 | 3 files changed, 10 deletions(-) | 24 | 3 files changed, 32 insertions(+), 9 deletions(-) |
17 | 25 | ||
18 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 26 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
19 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/helper.h | 28 | --- a/target/riscv/helper.h |
21 | +++ b/target/riscv/helper.h | 29 | +++ b/target/riscv/helper.h |
22 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(raise_exception, noreturn, env, i32) | 30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl) |
23 | /* Floating Point - rounding mode */ | 31 | DEF_HELPER_1(sret, tl, env) |
24 | DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_WG, void, env, i32) | 32 | DEF_HELPER_1(mret, tl, env) |
25 | DEF_HELPER_FLAGS_2(set_rounding_mode_chkfrm, TCG_CALL_NO_WG, void, env, i32) | 33 | DEF_HELPER_1(wfi, void, env) |
26 | -DEF_HELPER_FLAGS_1(set_rod_rounding_mode, TCG_CALL_NO_WG, void, env) | 34 | +DEF_HELPER_1(wrs_nto, void, env) |
27 | 35 | DEF_HELPER_1(tlb_flush, void, env) | |
28 | /* Floating Point - fused */ | 36 | DEF_HELPER_1(tlb_flush_all, void, env) |
29 | DEF_HELPER_FLAGS_4(fmadd_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) | 37 | /* Native Debug */ |
30 | diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c | 38 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c |
31 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/riscv/fpu_helper.c | 40 | --- a/target/riscv/op_helper.c |
33 | +++ b/target/riscv/fpu_helper.c | 41 | +++ b/target/riscv/op_helper.c |
34 | @@ -XXX,XX +XXX,XX @@ void helper_set_rounding_mode_chkfrm(CPURISCVState *env, uint32_t rm) | 42 | @@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env) |
35 | set_float_rounding_mode(softrm, &env->fp_status); | 43 | } |
36 | } | 44 | } |
37 | 45 | ||
38 | -void helper_set_rod_rounding_mode(CPURISCVState *env) | 46 | +void helper_wrs_nto(CPURISCVState *env) |
39 | -{ | 47 | +{ |
40 | - set_float_rounding_mode(float_round_to_odd, &env->fp_status); | 48 | + if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) && |
49 | + get_field(env->hstatus, HSTATUS_VTW) && | ||
50 | + !get_field(env->mstatus, MSTATUS_TW)) { | ||
51 | + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); | ||
52 | + } else if (env->priv != PRV_M && get_field(env->mstatus, MSTATUS_TW)) { | ||
53 | + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); | ||
54 | + } | ||
55 | +} | ||
56 | + | ||
57 | void helper_tlb_flush(CPURISCVState *env) | ||
58 | { | ||
59 | CPUState *cs = env_cpu(env); | ||
60 | diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/target/riscv/insn_trans/trans_rvzawrs.c.inc | ||
63 | +++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc | ||
64 | @@ -XXX,XX +XXX,XX @@ | ||
65 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
66 | */ | ||
67 | |||
68 | -static bool trans_wrs(DisasContext *ctx) | ||
69 | +static bool trans_wrs_sto(DisasContext *ctx, arg_wrs_sto *a) | ||
70 | { | ||
71 | if (!ctx->cfg_ptr->ext_zawrs) { | ||
72 | return false; | ||
73 | @@ -XXX,XX +XXX,XX @@ static bool trans_wrs(DisasContext *ctx) | ||
74 | return true; | ||
75 | } | ||
76 | |||
77 | -#define GEN_TRANS_WRS(insn) \ | ||
78 | -static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \ | ||
79 | -{ \ | ||
80 | - (void)a; \ | ||
81 | - return trans_wrs(ctx); \ | ||
41 | -} | 82 | -} |
42 | - | 83 | +static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a) |
43 | static uint64_t do_fmadd_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2, | 84 | +{ |
44 | uint64_t rs3, int flags) | 85 | + if (!ctx->cfg_ptr->ext_zawrs) { |
45 | { | 86 | + return false; |
46 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 87 | + } |
47 | index XXXXXXX..XXXXXXX 100644 | 88 | |
48 | --- a/target/riscv/translate.c | 89 | -GEN_TRANS_WRS(wrs_nto) |
49 | +++ b/target/riscv/translate.c | 90 | -GEN_TRANS_WRS(wrs_sto) |
50 | @@ -XXX,XX +XXX,XX @@ static void gen_set_rm(DisasContext *ctx, int rm) | 91 | + /* |
51 | } | 92 | + * Depending on the mode of execution, mstatus.TW and hstatus.VTW, wrs.nto |
52 | ctx->frm = rm; | 93 | + * should raise an exception when the implementation-specific bounded time |
53 | 94 | + * limit has expired. Our time limit is zero, so we either return | |
54 | - if (rm == RISCV_FRM_ROD) { | 95 | + * immediately, as does our implementation of wrs.sto, or raise an |
55 | - gen_helper_set_rod_rounding_mode(cpu_env); | 96 | + * exception, as handled by the wrs.nto helper. |
56 | - return; | 97 | + */ |
57 | - } | 98 | +#ifndef CONFIG_USER_ONLY |
58 | if (rm == RISCV_FRM_DYN) { | 99 | + gen_helper_wrs_nto(tcg_env); |
59 | /* The helper will return only if frm valid. */ | 100 | +#endif |
60 | ctx->frm_valid = true; | 101 | + |
102 | + /* We only get here when helper_wrs_nto() doesn't raise an exception. */ | ||
103 | + return trans_wrs_sto(ctx, NULL); | ||
104 | +} | ||
61 | -- | 105 | -- |
62 | 2.39.0 | 106 | 2.45.1 |
107 | |||
108 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The MachineState object provides a 'fdt' pointer that is already being | 3 | SBI defines a Debug Console extension "DBCN" that will, in time, replace |
4 | used by other RISC-V machines, and it's also used by the 'dumpdtb' QMP | 4 | the legacy console putchar and getchar SBI extensions. |
5 | command. | 5 | |
6 | 6 | The appeal of the DBCN extension is that it allows multiple bytes to be | |
7 | Remove the 'fdt' pointer from SpikeState and use MachineState::fdt | 7 | read/written in the SBI console in a single SBI call. |
8 | instead. | 8 | |
9 | As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM | ||
10 | module to userspace. But this will only happens if the KVM module | ||
11 | actually supports this SBI extension and we activate it. | ||
12 | |||
13 | We'll check for DBCN support during init time, checking if get-reg-list | ||
14 | is advertising KVM_RISCV_SBI_EXT_DBCN. In that case, we'll enable it via | ||
15 | kvm_set_one_reg() during kvm_arch_init_vcpu(). | ||
16 | |||
17 | Finally, change kvm_riscv_handle_sbi() to handle the incoming calls for | ||
18 | SBI_EXT_DBCN, reading and writing as required. | ||
19 | |||
20 | A simple KVM guest with 'earlycon=sbi', running in an emulated RISC-V | ||
21 | host, takes around 20 seconds to boot without using DBCN. With this | ||
22 | patch we're taking around 14 seconds to boot due to the speed-up in the | ||
23 | terminal output. There's no change in boot time if the guest isn't | ||
24 | using earlycon. | ||
9 | 25 | ||
10 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 26 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
11 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 27 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 28 | Message-ID: <20240425155012.581366-1-dbarboza@ventanamicro.com> |
13 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | ||
14 | Message-Id: <20230102115241.25733-3-dbarboza@ventanamicro.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 30 | --- |
17 | include/hw/riscv/spike.h | 2 -- | 31 | target/riscv/sbi_ecall_interface.h | 17 +++++ |
18 | hw/riscv/spike.c | 12 +++++------- | 32 | target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++ |
19 | 2 files changed, 5 insertions(+), 9 deletions(-) | 33 | 2 files changed, 128 insertions(+) |
20 | 34 | ||
21 | diff --git a/include/hw/riscv/spike.h b/include/hw/riscv/spike.h | 35 | diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h |
22 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/include/hw/riscv/spike.h | 37 | --- a/target/riscv/sbi_ecall_interface.h |
24 | +++ b/include/hw/riscv/spike.h | 38 | +++ b/target/riscv/sbi_ecall_interface.h |
25 | @@ -XXX,XX +XXX,XX @@ struct SpikeState { | 39 | @@ -XXX,XX +XXX,XX @@ |
26 | 40 | ||
27 | /*< public >*/ | 41 | /* clang-format off */ |
28 | RISCVHartArrayState soc[SPIKE_SOCKETS_MAX]; | 42 | |
29 | - void *fdt; | 43 | +#define SBI_SUCCESS 0 |
30 | - int fdt_size; | 44 | +#define SBI_ERR_FAILED -1 |
45 | +#define SBI_ERR_NOT_SUPPORTED -2 | ||
46 | +#define SBI_ERR_INVALID_PARAM -3 | ||
47 | +#define SBI_ERR_DENIED -4 | ||
48 | +#define SBI_ERR_INVALID_ADDRESS -5 | ||
49 | +#define SBI_ERR_ALREADY_AVAILABLE -6 | ||
50 | +#define SBI_ERR_ALREADY_STARTED -7 | ||
51 | +#define SBI_ERR_ALREADY_STOPPED -8 | ||
52 | +#define SBI_ERR_NO_SHMEM -9 | ||
53 | + | ||
54 | /* SBI Extension IDs */ | ||
55 | #define SBI_EXT_0_1_SET_TIMER 0x0 | ||
56 | #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 | ||
57 | @@ -XXX,XX +XXX,XX @@ | ||
58 | #define SBI_EXT_IPI 0x735049 | ||
59 | #define SBI_EXT_RFENCE 0x52464E43 | ||
60 | #define SBI_EXT_HSM 0x48534D | ||
61 | +#define SBI_EXT_DBCN 0x4442434E | ||
62 | |||
63 | /* SBI function IDs for BASE extension */ | ||
64 | #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 | ||
65 | @@ -XXX,XX +XXX,XX @@ | ||
66 | #define SBI_EXT_HSM_HART_STOP 0x1 | ||
67 | #define SBI_EXT_HSM_HART_GET_STATUS 0x2 | ||
68 | |||
69 | +/* SBI function IDs for DBCN extension */ | ||
70 | +#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0 | ||
71 | +#define SBI_EXT_DBCN_CONSOLE_READ 0x1 | ||
72 | +#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2 | ||
73 | + | ||
74 | #define SBI_HSM_HART_STATUS_STARTED 0x0 | ||
75 | #define SBI_HSM_HART_STATUS_STOPPED 0x1 | ||
76 | #define SBI_HSM_HART_STATUS_START_PENDING 0x2 | ||
77 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/target/riscv/kvm/kvm-cpu.c | ||
80 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
81 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_v_vlenb = { | ||
82 | KVM_REG_RISCV_VECTOR_CSR_REG(vlenb) | ||
31 | }; | 83 | }; |
32 | 84 | ||
33 | enum { | 85 | +static KVMCPUConfig kvm_sbi_dbcn = { |
34 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 86 | + .name = "sbi_dbcn", |
35 | index XXXXXXX..XXXXXXX 100644 | 87 | + .kvm_reg_id = KVM_REG_RISCV | KVM_REG_SIZE_U64 | |
36 | --- a/hw/riscv/spike.c | 88 | + KVM_REG_RISCV_SBI_EXT | KVM_RISCV_SBI_EXT_DBCN |
37 | +++ b/hw/riscv/spike.c | 89 | +}; |
38 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | 90 | + |
39 | bool is_32_bit, bool htif_custom_base) | 91 | static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) |
40 | { | 92 | { |
41 | void *fdt; | 93 | CPURISCVState *env = &cpu->env; |
42 | + int fdt_size; | 94 | @@ -XXX,XX +XXX,XX @@ static int uint64_cmp(const void *a, const void *b) |
43 | uint64_t addr, size; | 95 | return 0; |
44 | unsigned long clint_addr; | 96 | } |
45 | int cpu, socket; | 97 | |
46 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | 98 | +static void kvm_riscv_check_sbi_dbcn_support(RISCVCPU *cpu, |
47 | "sifive,clint0", "riscv,clint0" | 99 | + KVMScratchCPU *kvmcpu, |
48 | }; | 100 | + struct kvm_reg_list *reglist) |
49 | 101 | +{ | |
50 | - fdt = s->fdt = create_device_tree(&s->fdt_size); | 102 | + struct kvm_reg_list *reg_search; |
51 | + fdt = mc->fdt = create_device_tree(&fdt_size); | 103 | + |
52 | if (!fdt) { | 104 | + reg_search = bsearch(&kvm_sbi_dbcn.kvm_reg_id, reglist->reg, reglist->n, |
53 | error_report("create_device_tree() failed"); | 105 | + sizeof(uint64_t), uint64_cmp); |
54 | exit(1); | 106 | + |
55 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | 107 | + if (reg_search) { |
56 | hwaddr end = riscv_load_initrd(machine->initrd_filename, | 108 | + kvm_sbi_dbcn.supported = true; |
57 | machine->ram_size, kernel_entry, | 109 | + } |
58 | &start); | 110 | +} |
59 | - qemu_fdt_setprop_cell(s->fdt, "/chosen", | 111 | + |
60 | + qemu_fdt_setprop_cell(machine->fdt, "/chosen", | 112 | static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu, |
61 | "linux,initrd-start", start); | 113 | struct kvm_reg_list *reglist) |
62 | - qemu_fdt_setprop_cell(s->fdt, "/chosen", "linux,initrd-end", | 114 | { |
63 | + qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-end", | 115 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) |
64 | end); | 116 | if (riscv_has_ext(&cpu->env, RVV)) { |
117 | kvm_riscv_read_vlenb(cpu, kvmcpu, reglist); | ||
65 | } | 118 | } |
66 | 119 | + | |
67 | /* Compute the fdt load address in dram */ | 120 | + kvm_riscv_check_sbi_dbcn_support(cpu, kvmcpu, reglist); |
68 | fdt_load_addr = riscv_load_fdt(memmap[SPIKE_DRAM].base, | 121 | } |
69 | - machine->ram_size, s->fdt); | 122 | |
70 | - | 123 | static void riscv_init_kvm_registers(Object *cpu_obj) |
71 | - /* Set machine->fdt for 'dumpdtb' QMP/HMP command */ | 124 | @@ -XXX,XX +XXX,XX @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs) |
72 | - machine->fdt = s->fdt; | 125 | return ret; |
73 | + machine->ram_size, machine->fdt); | 126 | } |
74 | 127 | ||
75 | /* load the reset vector */ | 128 | +static int kvm_vcpu_enable_sbi_dbcn(RISCVCPU *cpu, CPUState *cs) |
76 | riscv_setup_rom_reset_vec(machine, &s->soc[0], memmap[SPIKE_DRAM].base, | 129 | +{ |
130 | + target_ulong reg = 1; | ||
131 | + | ||
132 | + if (!kvm_sbi_dbcn.supported) { | ||
133 | + return 0; | ||
134 | + } | ||
135 | + | ||
136 | + return kvm_set_one_reg(cs, kvm_sbi_dbcn.kvm_reg_id, ®); | ||
137 | +} | ||
138 | + | ||
139 | int kvm_arch_init_vcpu(CPUState *cs) | ||
140 | { | ||
141 | int ret = 0; | ||
142 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) | ||
143 | kvm_riscv_update_cpu_misa_ext(cpu, cs); | ||
144 | kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs); | ||
145 | |||
146 | + ret = kvm_vcpu_enable_sbi_dbcn(cpu, cs); | ||
147 | + | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | @@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs) | ||
152 | return true; | ||
153 | } | ||
154 | |||
155 | +static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run) | ||
156 | +{ | ||
157 | + g_autofree uint8_t *buf = NULL; | ||
158 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
159 | + target_ulong num_bytes; | ||
160 | + uint64_t addr; | ||
161 | + unsigned char ch; | ||
162 | + int ret; | ||
163 | + | ||
164 | + switch (run->riscv_sbi.function_id) { | ||
165 | + case SBI_EXT_DBCN_CONSOLE_READ: | ||
166 | + case SBI_EXT_DBCN_CONSOLE_WRITE: | ||
167 | + num_bytes = run->riscv_sbi.args[0]; | ||
168 | + | ||
169 | + if (num_bytes == 0) { | ||
170 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
171 | + run->riscv_sbi.ret[1] = 0; | ||
172 | + break; | ||
173 | + } | ||
174 | + | ||
175 | + addr = run->riscv_sbi.args[1]; | ||
176 | + | ||
177 | + /* | ||
178 | + * Handle the case where a 32 bit CPU is running in a | ||
179 | + * 64 bit addressing env. | ||
180 | + */ | ||
181 | + if (riscv_cpu_mxl(&cpu->env) == MXL_RV32) { | ||
182 | + addr |= (uint64_t)run->riscv_sbi.args[2] << 32; | ||
183 | + } | ||
184 | + | ||
185 | + buf = g_malloc0(num_bytes); | ||
186 | + | ||
187 | + if (run->riscv_sbi.function_id == SBI_EXT_DBCN_CONSOLE_READ) { | ||
188 | + ret = qemu_chr_fe_read_all(serial_hd(0)->be, buf, num_bytes); | ||
189 | + if (ret < 0) { | ||
190 | + error_report("SBI_EXT_DBCN_CONSOLE_READ: error when " | ||
191 | + "reading chardev"); | ||
192 | + exit(1); | ||
193 | + } | ||
194 | + | ||
195 | + cpu_physical_memory_write(addr, buf, ret); | ||
196 | + } else { | ||
197 | + cpu_physical_memory_read(addr, buf, num_bytes); | ||
198 | + | ||
199 | + ret = qemu_chr_fe_write_all(serial_hd(0)->be, buf, num_bytes); | ||
200 | + if (ret < 0) { | ||
201 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE: error when " | ||
202 | + "writing chardev"); | ||
203 | + exit(1); | ||
204 | + } | ||
205 | + } | ||
206 | + | ||
207 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
208 | + run->riscv_sbi.ret[1] = ret; | ||
209 | + break; | ||
210 | + case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: | ||
211 | + ch = run->riscv_sbi.args[0]; | ||
212 | + ret = qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch)); | ||
213 | + | ||
214 | + if (ret < 0) { | ||
215 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: error when " | ||
216 | + "writing chardev"); | ||
217 | + exit(1); | ||
218 | + } | ||
219 | + | ||
220 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
221 | + run->riscv_sbi.ret[1] = 0; | ||
222 | + break; | ||
223 | + default: | ||
224 | + run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED; | ||
225 | + } | ||
226 | +} | ||
227 | + | ||
228 | static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
229 | { | ||
230 | int ret = 0; | ||
231 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
232 | } | ||
233 | ret = 0; | ||
234 | break; | ||
235 | + case SBI_EXT_DBCN: | ||
236 | + kvm_riscv_handle_sbi_dbcn(cs, run); | ||
237 | + break; | ||
238 | default: | ||
239 | qemu_log_mask(LOG_UNIMP, | ||
240 | "%s: un-handled SBI EXIT, specific reasons is %lu\n", | ||
77 | -- | 241 | -- |
78 | 2.39.0 | 242 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Cheng Yang <yangcheng.work@foxmail.com> |
---|---|---|---|
2 | 2 | ||
3 | All callers are using kernel_filename as machine->kernel_filename. | 3 | Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell() |
4 | to set the address of initrd in FDT to support 64-bit address. | ||
4 | 5 | ||
5 | This will also simplify the changes in riscv_load_kernel() that we're | 6 | Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com> |
6 | going to do next. | ||
7 | |||
8 | Cc: Palmer Dabbelt <palmer@dabbelt.com> | ||
9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
11 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Message-Id: <20230102115241.25733-10-dbarboza@ventanamicro.com> | 8 | Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com> |
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 10 | --- |
16 | include/hw/riscv/boot.h | 2 +- | 11 | hw/riscv/boot.c | 4 ++-- |
17 | hw/riscv/boot.c | 3 ++- | 12 | 1 file changed, 2 insertions(+), 2 deletions(-) |
18 | hw/riscv/microchip_pfsoc.c | 3 +-- | ||
19 | hw/riscv/opentitan.c | 3 +-- | ||
20 | hw/riscv/sifive_e.c | 3 +-- | ||
21 | hw/riscv/sifive_u.c | 3 +-- | ||
22 | hw/riscv/spike.c | 3 +-- | ||
23 | hw/riscv/virt.c | 3 +-- | ||
24 | 8 files changed, 9 insertions(+), 14 deletions(-) | ||
25 | 13 | ||
26 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/include/hw/riscv/boot.h | ||
29 | +++ b/include/hw/riscv/boot.h | ||
30 | @@ -XXX,XX +XXX,XX @@ char *riscv_find_firmware(const char *firmware_filename, | ||
31 | target_ulong riscv_load_firmware(const char *firmware_filename, | ||
32 | hwaddr firmware_load_addr, | ||
33 | symbol_fn_t sym_cb); | ||
34 | -target_ulong riscv_load_kernel(const char *kernel_filename, | ||
35 | +target_ulong riscv_load_kernel(MachineState *machine, | ||
36 | target_ulong firmware_end_addr, | ||
37 | symbol_fn_t sym_cb); | ||
38 | void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry); | ||
39 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | 14 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c |
40 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/hw/riscv/boot.c | 16 | --- a/hw/riscv/boot.c |
42 | +++ b/hw/riscv/boot.c | 17 | +++ b/hw/riscv/boot.c |
43 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_firmware(const char *firmware_filename, | 18 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) |
44 | exit(1); | 19 | /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */ |
45 | } | 20 | if (fdt) { |
46 | 21 | end = start + size; | |
47 | -target_ulong riscv_load_kernel(const char *kernel_filename, | 22 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start); |
48 | +target_ulong riscv_load_kernel(MachineState *machine, | 23 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end); |
49 | target_ulong kernel_start_addr, | 24 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start); |
50 | symbol_fn_t sym_cb) | 25 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end); |
51 | { | ||
52 | + const char *kernel_filename = machine->kernel_filename; | ||
53 | uint64_t kernel_load_base, kernel_entry; | ||
54 | |||
55 | g_assert(kernel_filename != NULL); | ||
56 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/hw/riscv/microchip_pfsoc.c | ||
59 | +++ b/hw/riscv/microchip_pfsoc.c | ||
60 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) | ||
61 | kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc.u_cpus, | ||
62 | firmware_end_addr); | ||
63 | |||
64 | - kernel_entry = riscv_load_kernel(machine->kernel_filename, | ||
65 | - kernel_start_addr, NULL); | ||
66 | + kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL); | ||
67 | |||
68 | if (machine->initrd_filename) { | ||
69 | riscv_load_initrd(machine, kernel_entry); | ||
70 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/hw/riscv/opentitan.c | ||
73 | +++ b/hw/riscv/opentitan.c | ||
74 | @@ -XXX,XX +XXX,XX @@ static void opentitan_board_init(MachineState *machine) | ||
75 | } | ||
76 | |||
77 | if (machine->kernel_filename) { | ||
78 | - riscv_load_kernel(machine->kernel_filename, | ||
79 | - memmap[IBEX_DEV_RAM].base, NULL); | ||
80 | + riscv_load_kernel(machine, memmap[IBEX_DEV_RAM].base, NULL); | ||
81 | } | 26 | } |
82 | } | 27 | } |
83 | 28 | ||
84 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/hw/riscv/sifive_e.c | ||
87 | +++ b/hw/riscv/sifive_e.c | ||
88 | @@ -XXX,XX +XXX,XX @@ static void sifive_e_machine_init(MachineState *machine) | ||
89 | memmap[SIFIVE_E_DEV_MROM].base, &address_space_memory); | ||
90 | |||
91 | if (machine->kernel_filename) { | ||
92 | - riscv_load_kernel(machine->kernel_filename, | ||
93 | - memmap[SIFIVE_E_DEV_DTIM].base, NULL); | ||
94 | + riscv_load_kernel(machine, memmap[SIFIVE_E_DEV_DTIM].base, NULL); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | ||
99 | index XXXXXXX..XXXXXXX 100644 | ||
100 | --- a/hw/riscv/sifive_u.c | ||
101 | +++ b/hw/riscv/sifive_u.c | ||
102 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
103 | kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc.u_cpus, | ||
104 | firmware_end_addr); | ||
105 | |||
106 | - kernel_entry = riscv_load_kernel(machine->kernel_filename, | ||
107 | - kernel_start_addr, NULL); | ||
108 | + kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL); | ||
109 | |||
110 | if (machine->initrd_filename) { | ||
111 | riscv_load_initrd(machine, kernel_entry); | ||
112 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
113 | index XXXXXXX..XXXXXXX 100644 | ||
114 | --- a/hw/riscv/spike.c | ||
115 | +++ b/hw/riscv/spike.c | ||
116 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
117 | kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0], | ||
118 | firmware_end_addr); | ||
119 | |||
120 | - kernel_entry = riscv_load_kernel(machine->kernel_filename, | ||
121 | - kernel_start_addr, | ||
122 | + kernel_entry = riscv_load_kernel(machine, kernel_start_addr, | ||
123 | htif_symbol_callback); | ||
124 | |||
125 | if (machine->initrd_filename) { | ||
126 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
127 | index XXXXXXX..XXXXXXX 100644 | ||
128 | --- a/hw/riscv/virt.c | ||
129 | +++ b/hw/riscv/virt.c | ||
130 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) | ||
131 | kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0], | ||
132 | firmware_end_addr); | ||
133 | |||
134 | - kernel_entry = riscv_load_kernel(machine->kernel_filename, | ||
135 | - kernel_start_addr, NULL); | ||
136 | + kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL); | ||
137 | |||
138 | if (machine->initrd_filename) { | ||
139 | riscv_load_initrd(machine, kernel_entry); | ||
140 | -- | 29 | -- |
141 | 2.39.0 | 30 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Clément Léger <cleger@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | create_fdt_socket_cpus() writes a different 'mmu-type' value if we're | 3 | The current semihost exception number (16) is a reserved number (range |
4 | running in 32 or 64 bits. However, the flag is being calculated during | 4 | [16-17]). The upcoming double trap specification uses that number for |
5 | virt_machine_init(), and is passed around in create_fdt(), then | 5 | the double trap exception. Since the privileged spec (Table 22) defines |
6 | create_fdt_socket(), and then finally create_fdt_socket_cpus(). None of | 6 | ranges for custom uses change the semihosting exception number to 63 |
7 | the intermediate functions are using the flag, which is a bit | 7 | which belongs to the range [48-63] in order to avoid any future |
8 | misleading. | 8 | collisions with reserved exception. |
9 | 9 | ||
10 | Remove 'is_32_bit' flag from create_fdt_socket_cpus() and calculate it | 10 | Signed-off-by: Clément Léger <cleger@rivosinc.com> |
11 | using the already available RISCVVirtState pointer. This will also | ||
12 | change the signature of create_fdt_socket() and create_fdt(), making it | ||
13 | clear that these functions don't do anything special when we're running | ||
14 | in 32 bit mode. | ||
15 | 11 | ||
16 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
17 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
18 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
19 | Message-Id: <20230111170948.316276-5-dbarboza@ventanamicro.com> | 13 | Message-ID: <20240422135840.1959967-1-cleger@rivosinc.com> |
20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
21 | --- | 15 | --- |
22 | hw/riscv/virt.c | 18 +++++++++--------- | 16 | target/riscv/cpu_bits.h | 2 +- |
23 | 1 file changed, 9 insertions(+), 9 deletions(-) | 17 | 1 file changed, 1 insertion(+), 1 deletion(-) |
24 | 18 | ||
25 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 19 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
26 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/riscv/virt.c | 21 | --- a/target/riscv/cpu_bits.h |
28 | +++ b/hw/riscv/virt.c | 22 | +++ b/target/riscv/cpu_bits.h |
29 | @@ -XXX,XX +XXX,XX @@ static void create_pcie_irq_map(RISCVVirtState *s, void *fdt, char *nodename, | 23 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { |
30 | 24 | RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */ | |
31 | static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, | 25 | RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */ |
32 | char *clust_name, uint32_t *phandle, | 26 | RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */ |
33 | - bool is_32_bit, uint32_t *intc_phandles) | 27 | - RISCV_EXCP_SEMIHOST = 0x10, |
34 | + uint32_t *intc_phandles) | 28 | RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14, |
35 | { | 29 | RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15, |
36 | int cpu; | 30 | RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16, |
37 | uint32_t cpu_phandle; | 31 | RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17, |
38 | MachineState *mc = MACHINE(s); | 32 | + RISCV_EXCP_SEMIHOST = 0x3f, |
39 | char *name, *cpu_name, *core_name, *intc_name; | 33 | } RISCVException; |
40 | + bool is_32_bit = riscv_is_32bit(&s->soc[0]); | 34 | |
41 | 35 | #define RISCV_EXCP_INT_FLAG 0x80000000 | |
42 | for (cpu = s->soc[socket].num_harts - 1; cpu >= 0; cpu--) { | ||
43 | cpu_phandle = (*phandle)++; | ||
44 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_pmu(RISCVVirtState *s) | ||
45 | } | ||
46 | |||
47 | static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, | ||
48 | - bool is_32_bit, uint32_t *phandle, | ||
49 | + uint32_t *phandle, | ||
50 | uint32_t *irq_mmio_phandle, | ||
51 | uint32_t *irq_pcie_phandle, | ||
52 | uint32_t *irq_virtio_phandle, | ||
53 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, | ||
54 | qemu_fdt_add_subnode(mc->fdt, clust_name); | ||
55 | |||
56 | create_fdt_socket_cpus(s, socket, clust_name, phandle, | ||
57 | - is_32_bit, &intc_phandles[phandle_pos]); | ||
58 | + &intc_phandles[phandle_pos]); | ||
59 | |||
60 | create_fdt_socket_memory(s, memmap, socket); | ||
61 | |||
62 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_fw_cfg(RISCVVirtState *s, const MemMapEntry *memmap) | ||
63 | g_free(nodename); | ||
64 | } | ||
65 | |||
66 | -static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, | ||
67 | - bool is_32_bit) | ||
68 | +static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap) | ||
69 | { | ||
70 | MachineState *mc = MACHINE(s); | ||
71 | uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1; | ||
72 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, | ||
73 | qemu_fdt_setprop_cell(mc->fdt, "/soc", "#size-cells", 0x2); | ||
74 | qemu_fdt_setprop_cell(mc->fdt, "/soc", "#address-cells", 0x2); | ||
75 | |||
76 | - create_fdt_sockets(s, memmap, is_32_bit, &phandle, | ||
77 | - &irq_mmio_phandle, &irq_pcie_phandle, &irq_virtio_phandle, | ||
78 | - &msi_pcie_phandle); | ||
79 | + create_fdt_sockets(s, memmap, &phandle, &irq_mmio_phandle, | ||
80 | + &irq_pcie_phandle, &irq_virtio_phandle, | ||
81 | + &msi_pcie_phandle); | ||
82 | |||
83 | create_fdt_virtio(s, memmap, irq_virtio_phandle); | ||
84 | |||
85 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
86 | virt_flash_map(s, system_memory); | ||
87 | |||
88 | /* create device tree */ | ||
89 | - create_fdt(s, memmap, riscv_is_32bit(&s->soc[0])); | ||
90 | + create_fdt(s, memmap); | ||
91 | |||
92 | s->machine_done.notify = virt_machine_done; | ||
93 | qemu_add_machine_init_done_notifier(&s->machine_done); | ||
94 | -- | 36 | -- |
95 | 2.39.0 | 37 | 2.45.1 |
38 | |||
39 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | There's no need to use a MachineState pointer and a fdt pointer now that | 3 | Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr |
4 | all RISC-V machines are using the FDT from the MachineState. | 4 | enabled, will fail with a kernel oops SIGILL right at the start. The |
5 | reason is that we can't expose zkr without implementing the SEED CSR. | ||
6 | Disabling zkr in the guest would be a workaround, but if the KVM doesn't | ||
7 | allow it we'll error out and never boot. | ||
5 | 8 | ||
9 | In hindsight this is too strict. If we keep proceeding, despite not | ||
10 | disabling the extension in the KVM vcpu, we'll not add the extension in | ||
11 | the riscv,isa. The guest kernel will be unaware of the extension, i.e. | ||
12 | it doesn't matter if the KVM vcpu has it enabled underneath or not. So | ||
13 | it's ok to keep booting in this case. | ||
14 | |||
15 | Change our current logic to not error out if we fail to disable an | ||
16 | extension in kvm_set_one_reg(), but show a warning and keep booting. It | ||
17 | is important to throw a warning because we must make the user aware that | ||
18 | the extension is still available in the vcpu, meaning that an | ||
19 | ill-behaved guest can ignore the riscv,isa settings and use the | ||
20 | extension. | ||
21 | |||
22 | The case we're handling happens with an EINVAL error code. If we fail to | ||
23 | disable the extension in KVM for any other reason, error out. | ||
24 | |||
25 | We'll also keep erroring out when we fail to enable an extension in KVM, | ||
26 | since adding the extension in riscv,isa at this point will cause a guest | ||
27 | malfunction because the extension isn't enabled in the vcpu. | ||
28 | |||
29 | Suggested-by: Andrew Jones <ajones@ventanamicro.com> | ||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 30 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 31 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 32 | Cc: qemu-stable <qemu-stable@nongnu.org> |
9 | Message-Id: <20230111170948.316276-7-dbarboza@ventanamicro.com> | 33 | Message-ID: <20240422171425.333037-2-dbarboza@ventanamicro.com> |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 34 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 35 | --- |
12 | include/hw/riscv/numa.h | 4 ++-- | 36 | target/riscv/kvm/kvm-cpu.c | 12 ++++++++---- |
13 | hw/riscv/numa.c | 8 ++++---- | 37 | 1 file changed, 8 insertions(+), 4 deletions(-) |
14 | hw/riscv/spike.c | 2 +- | ||
15 | hw/riscv/virt.c | 2 +- | ||
16 | 4 files changed, 8 insertions(+), 8 deletions(-) | ||
17 | 38 | ||
18 | diff --git a/include/hw/riscv/numa.h b/include/hw/riscv/numa.h | 39 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
19 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/include/hw/riscv/numa.h | 41 | --- a/target/riscv/kvm/kvm-cpu.c |
21 | +++ b/include/hw/riscv/numa.h | 42 | +++ b/target/riscv/kvm/kvm-cpu.c |
22 | @@ -XXX,XX +XXX,XX @@ void riscv_socket_fdt_write_id(const MachineState *ms, const char *node_name, | 43 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) |
23 | * @ms: pointer to machine state | 44 | reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg); |
24 | * @socket_id: socket index | 45 | ret = kvm_set_one_reg(cs, id, ®); |
25 | * | 46 | if (ret != 0) { |
26 | - * Write NUMA distance matrix in FDT for given machine | 47 | - error_report("Unable to %s extension %s in KVM, error %d", |
27 | + * Write NUMA distance matrix in MachineState->fdt | 48 | - reg ? "enable" : "disable", |
28 | */ | 49 | - multi_ext_cfg->name, ret); |
29 | -void riscv_socket_fdt_write_distance_matrix(const MachineState *ms, void *fdt); | 50 | - exit(EXIT_FAILURE); |
30 | +void riscv_socket_fdt_write_distance_matrix(const MachineState *ms); | 51 | + if (!reg && ret == -EINVAL) { |
31 | 52 | + warn_report("KVM cannot disable extension %s", | |
32 | CpuInstanceProperties | 53 | + multi_ext_cfg->name); |
33 | riscv_numa_cpu_index_to_props(MachineState *ms, unsigned cpu_index); | 54 | + } else { |
34 | diff --git a/hw/riscv/numa.c b/hw/riscv/numa.c | 55 | + error_report("Unable to enable extension %s in KVM, error %d", |
35 | index XXXXXXX..XXXXXXX 100644 | 56 | + multi_ext_cfg->name, ret); |
36 | --- a/hw/riscv/numa.c | 57 | + exit(EXIT_FAILURE); |
37 | +++ b/hw/riscv/numa.c | 58 | + } |
38 | @@ -XXX,XX +XXX,XX @@ void riscv_socket_fdt_write_id(const MachineState *ms, const char *node_name, | 59 | } |
39 | } | 60 | } |
40 | } | 61 | } |
41 | |||
42 | -void riscv_socket_fdt_write_distance_matrix(const MachineState *ms, void *fdt) | ||
43 | +void riscv_socket_fdt_write_distance_matrix(const MachineState *ms) | ||
44 | { | ||
45 | int i, j, idx; | ||
46 | uint32_t *dist_matrix, dist_matrix_size; | ||
47 | @@ -XXX,XX +XXX,XX @@ void riscv_socket_fdt_write_distance_matrix(const MachineState *ms, void *fdt) | ||
48 | } | ||
49 | } | ||
50 | |||
51 | - qemu_fdt_add_subnode(fdt, "/distance-map"); | ||
52 | - qemu_fdt_setprop_string(fdt, "/distance-map", "compatible", | ||
53 | + qemu_fdt_add_subnode(ms->fdt, "/distance-map"); | ||
54 | + qemu_fdt_setprop_string(ms->fdt, "/distance-map", "compatible", | ||
55 | "numa-distance-map-v1"); | ||
56 | - qemu_fdt_setprop(fdt, "/distance-map", "distance-matrix", | ||
57 | + qemu_fdt_setprop(ms->fdt, "/distance-map", "distance-matrix", | ||
58 | dist_matrix, dist_matrix_size); | ||
59 | g_free(dist_matrix); | ||
60 | } | ||
61 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/hw/riscv/spike.c | ||
64 | +++ b/hw/riscv/spike.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | ||
66 | g_free(clust_name); | ||
67 | } | ||
68 | |||
69 | - riscv_socket_fdt_write_distance_matrix(mc, fdt); | ||
70 | + riscv_socket_fdt_write_distance_matrix(mc); | ||
71 | |||
72 | qemu_fdt_add_subnode(fdt, "/chosen"); | ||
73 | qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif"); | ||
74 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/hw/riscv/virt.c | ||
77 | +++ b/hw/riscv/virt.c | ||
78 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, | ||
79 | } | ||
80 | } | ||
81 | |||
82 | - riscv_socket_fdt_write_distance_matrix(mc, mc->fdt); | ||
83 | + riscv_socket_fdt_write_distance_matrix(mc); | ||
84 | } | ||
85 | |||
86 | static void create_fdt_virtio(RISCVVirtState *s, const MemMapEntry *memmap, | ||
87 | -- | 62 | -- |
88 | 2.39.0 | 63 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | 'mem_size' and 'cmdline' aren't being used. Remove them. | 3 | We're not setting (s/m)tval when triggering breakpoints of type 2 |
4 | (mcontrol) and 6 (mcontrol6). According to the debug spec section | ||
5 | 5.7.12, "Match Control Type 6": | ||
6 | |||
7 | "The Privileged Spec says that breakpoint exceptions that occur on | ||
8 | instruction fetches, loads, or stores update the tval CSR with either | ||
9 | zero or the faulting virtual address. The faulting virtual address for | ||
10 | an mcontrol6 trigger with action = 0 is the address being accessed and | ||
11 | which caused that trigger to fire." | ||
12 | |||
13 | A similar text is also found in the Debug spec section 5.7.11 w.r.t. | ||
14 | mcontrol. | ||
15 | |||
16 | Note that what we're doing ATM is not violating the spec, but it's | ||
17 | simple enough to set mtval/stval and it makes life easier for any | ||
18 | software that relies on this info. | ||
19 | |||
20 | Given that we always use action = 0, save the faulting address for the | ||
21 | mcontrol and mcontrol6 trigger breakpoints into env->badaddr, which is | ||
22 | used as as scratch area for traps with address information. 'tval' is | ||
23 | then set during riscv_cpu_do_interrupt(). | ||
4 | 24 | ||
5 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 25 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 26 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-Id: <20230111170948.316276-3-dbarboza@ventanamicro.com> | 27 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
28 | Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 30 | --- |
11 | hw/riscv/virt.c | 5 ++--- | 31 | target/riscv/cpu_helper.c | 1 + |
12 | 1 file changed, 2 insertions(+), 3 deletions(-) | 32 | target/riscv/debug.c | 3 +++ |
33 | 2 files changed, 4 insertions(+) | ||
13 | 34 | ||
14 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 35 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
15 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/riscv/virt.c | 37 | --- a/target/riscv/cpu_helper.c |
17 | +++ b/hw/riscv/virt.c | 38 | +++ b/target/riscv/cpu_helper.c |
18 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_fw_cfg(RISCVVirtState *s, const MemMapEntry *memmap) | 39 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) |
19 | } | 40 | tval = env->bins; |
20 | 41 | break; | |
21 | static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, | 42 | case RISCV_EXCP_BREAKPOINT: |
22 | - uint64_t mem_size, const char *cmdline, bool is_32_bit) | 43 | + tval = env->badaddr; |
23 | + bool is_32_bit) | 44 | if (cs->watchpoint_hit) { |
24 | { | 45 | tval = cs->watchpoint_hit->hitaddr; |
25 | MachineState *mc = MACHINE(s); | 46 | cs->watchpoint_hit = NULL; |
26 | uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1; | 47 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c |
27 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | 48 | index XXXXXXX..XXXXXXX 100644 |
28 | virt_flash_map(s, system_memory); | 49 | --- a/target/riscv/debug.c |
29 | 50 | +++ b/target/riscv/debug.c | |
30 | /* create device tree */ | 51 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) |
31 | - create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | 52 | if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) { |
32 | - riscv_is_32bit(&s->soc[0])); | 53 | /* check U/S/M bit against current privilege level */ |
33 | + create_fdt(s, memmap, riscv_is_32bit(&s->soc[0])); | 54 | if ((ctrl >> 3) & BIT(env->priv)) { |
34 | 55 | + env->badaddr = pc; | |
35 | s->machine_done.notify = virt_machine_done; | 56 | return true; |
36 | qemu_add_machine_init_done_notifier(&s->machine_done); | 57 | } |
58 | } | ||
59 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) | ||
60 | if (env->virt_enabled) { | ||
61 | /* check VU/VS bit against current privilege level */ | ||
62 | if ((ctrl >> 23) & BIT(env->priv)) { | ||
63 | + env->badaddr = pc; | ||
64 | return true; | ||
65 | } | ||
66 | } else { | ||
67 | /* check U/S/M bit against current privilege level */ | ||
68 | if ((ctrl >> 3) & BIT(env->priv)) { | ||
69 | + env->badaddr = pc; | ||
70 | return true; | ||
71 | } | ||
72 | } | ||
37 | -- | 73 | -- |
38 | 2.39.0 | 74 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | 'mem_size' and 'cmdline' are unused. | 3 | Privileged spec section 4.1.9 mentions: |
4 | |||
5 | "When a trap is taken into S-mode, stval is written with | ||
6 | exception-specific information to assist software in handling the trap. | ||
7 | (...) | ||
8 | |||
9 | If stval is written with a nonzero value when a breakpoint, | ||
10 | address-misaligned, access-fault, or page-fault exception occurs on an | ||
11 | instruction fetch, load, or store, then stval will contain the faulting | ||
12 | virtual address." | ||
13 | |||
14 | A similar text is found for mtval in section 3.1.16. | ||
15 | |||
16 | Setting mtval/stval in this scenario is optional, but some softwares read | ||
17 | these regs when handling ebreaks. | ||
18 | |||
19 | Write 'badaddr' in all ebreak breakpoints to write the appropriate | ||
20 | 'tval' during riscv_do_cpu_interrrupt(). | ||
4 | 21 | ||
5 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 22 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-Id: <20230111170948.316276-2-dbarboza@ventanamicro.com> | 24 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
26 | Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 28 | --- |
11 | hw/riscv/spike.c | 4 +--- | 29 | target/riscv/insn_trans/trans_privileged.c.inc | 2 ++ |
12 | 1 file changed, 1 insertion(+), 3 deletions(-) | 30 | 1 file changed, 2 insertions(+) |
13 | 31 | ||
14 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 32 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc |
15 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/riscv/spike.c | 34 | --- a/target/riscv/insn_trans/trans_privileged.c.inc |
17 | +++ b/hw/riscv/spike.c | 35 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc |
18 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry spike_memmap[] = { | 36 | @@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) |
19 | }; | 37 | if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) { |
20 | 38 | generate_exception(ctx, RISCV_EXCP_SEMIHOST); | |
21 | static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | 39 | } else { |
22 | - uint64_t mem_size, const char *cmdline, | 40 | + tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env, |
23 | bool is_32_bit, bool htif_custom_base) | 41 | + offsetof(CPURISCVState, badaddr)); |
24 | { | 42 | generate_exception(ctx, RISCV_EXCP_BREAKPOINT); |
25 | void *fdt; | ||
26 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
27 | } | 43 | } |
28 | 44 | return true; | |
29 | /* Create device tree */ | ||
30 | - create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | ||
31 | - riscv_is_32bit(&s->soc[0]), htif_custom_base); | ||
32 | + create_fdt(s, memmap, riscv_is_32bit(&s->soc[0]), htif_custom_base); | ||
33 | |||
34 | /* Load kernel */ | ||
35 | if (machine->kernel_filename) { | ||
36 | -- | 45 | -- |
37 | 2.39.0 | 46 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Andrew Bresticker <abrestic@rivosinc.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The current logic attempts to shift the VS-level bits into their correct | 3 | Add support for Zve32x extension and replace some checks for Zve32f with |
4 | position in mip while leaving the remaining bits in-tact. This is both | 4 | Zve32x, since Zve32f depends on Zve32x. |
5 | pointless and likely incorrect since one would expect that any new, future | ||
6 | VS-level interrupts will get their own position in mip rather than sharing | ||
7 | with their (H)S-level equivalent. Fix this, and make the logic more | ||
8 | readable, by just making off the VS-level bits and shifting them into | ||
9 | position. | ||
10 | 5 | ||
11 | This also fixes reads of vsip, which would only ever report vsip.VSSIP | 6 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
12 | since the non-writable bits got masked off as well. | 7 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
13 | 8 | Reviewed-by: Max Chou <max.chou@sifive.com> | |
14 | Fixes: d028ac7512f1 ("arget/riscv: Implement AIA CSRs for 64 local interrupts on RV32") | 9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
15 | Signed-off-by: Andrew Bresticker <abrestic@rivosinc.com> | 10 | Message-ID: <20240328022343.6871-2-jason.chien@sifive.com> |
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | Message-Id: <20221215224541.1423431-1-abrestic@rivosinc.com> | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
19 | --- | 12 | --- |
20 | target/riscv/csr.c | 35 +++++++++++------------------------ | 13 | target/riscv/cpu_cfg.h | 1 + |
21 | 1 file changed, 11 insertions(+), 24 deletions(-) | 14 | target/riscv/cpu.c | 2 ++ |
15 | target/riscv/cpu_helper.c | 2 +- | ||
16 | target/riscv/csr.c | 2 +- | ||
17 | target/riscv/tcg/tcg-cpu.c | 16 ++++++++-------- | ||
18 | target/riscv/insn_trans/trans_rvv.c.inc | 4 ++-- | ||
19 | 6 files changed, 15 insertions(+), 12 deletions(-) | ||
22 | 20 | ||
21 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/riscv/cpu_cfg.h | ||
24 | +++ b/target/riscv/cpu_cfg.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
26 | bool ext_zhinx; | ||
27 | bool ext_zhinxmin; | ||
28 | bool ext_zve32f; | ||
29 | + bool ext_zve32x; | ||
30 | bool ext_zve64f; | ||
31 | bool ext_zve64d; | ||
32 | bool ext_zvbb; | ||
33 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/target/riscv/cpu.c | ||
36 | +++ b/target/riscv/cpu.c | ||
37 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | ||
38 | ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb), | ||
39 | ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc), | ||
40 | ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f), | ||
41 | + ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), | ||
42 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), | ||
43 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), | ||
44 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), | ||
45 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
46 | MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false), | ||
47 | MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false), | ||
48 | MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false), | ||
49 | + MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), | ||
50 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), | ||
51 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
52 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), | ||
53 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/target/riscv/cpu_helper.c | ||
56 | +++ b/target/riscv/cpu_helper.c | ||
57 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, | ||
58 | *pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc; | ||
59 | *cs_base = 0; | ||
60 | |||
61 | - if (cpu->cfg.ext_zve32f) { | ||
62 | + if (cpu->cfg.ext_zve32x) { | ||
63 | /* | ||
64 | * If env->vl equals to VLMAX, we can use generic vector operation | ||
65 | * expanders (GVEC) to accerlate the vector operations. | ||
23 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 66 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
24 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/target/riscv/csr.c | 68 | --- a/target/riscv/csr.c |
26 | +++ b/target/riscv/csr.c | 69 | +++ b/target/riscv/csr.c |
27 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_vsie64(CPURISCVState *env, int csrno, | 70 | @@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno) |
28 | uint64_t new_val, uint64_t wr_mask) | 71 | |
72 | static RISCVException vs(CPURISCVState *env, int csrno) | ||
29 | { | 73 | { |
30 | RISCVException ret; | 74 | - if (riscv_cpu_cfg(env)->ext_zve32f) { |
31 | - uint64_t rval, vsbits, mask = env->hideleg & VS_MODE_INTERRUPTS; | 75 | + if (riscv_cpu_cfg(env)->ext_zve32x) { |
32 | + uint64_t rval, mask = env->hideleg & VS_MODE_INTERRUPTS; | 76 | #if !defined(CONFIG_USER_ONLY) |
33 | 77 | if (!env->debugger && !riscv_cpu_vector_enabled(env)) { | |
34 | /* Bring VS-level bits to correct position */ | 78 | return RISCV_EXCP_ILLEGAL_INST; |
35 | - vsbits = new_val & (VS_MODE_INTERRUPTS >> 1); | 79 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
36 | - new_val &= ~(VS_MODE_INTERRUPTS >> 1); | 80 | index XXXXXXX..XXXXXXX 100644 |
37 | - new_val |= vsbits << 1; | 81 | --- a/target/riscv/tcg/tcg-cpu.c |
38 | - vsbits = wr_mask & (VS_MODE_INTERRUPTS >> 1); | 82 | +++ b/target/riscv/tcg/tcg-cpu.c |
39 | - wr_mask &= ~(VS_MODE_INTERRUPTS >> 1); | 83 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
40 | - wr_mask |= vsbits << 1; | 84 | return; |
41 | + new_val = (new_val & (VS_MODE_INTERRUPTS >> 1)) << 1; | ||
42 | + wr_mask = (wr_mask & (VS_MODE_INTERRUPTS >> 1)) << 1; | ||
43 | |||
44 | ret = rmw_mie64(env, csrno, &rval, new_val, wr_mask & mask); | ||
45 | if (ret_val) { | ||
46 | - rval &= mask; | ||
47 | - vsbits = rval & VS_MODE_INTERRUPTS; | ||
48 | - rval &= ~VS_MODE_INTERRUPTS; | ||
49 | - *ret_val = rval | (vsbits >> 1); | ||
50 | + *ret_val = (rval & mask) >> 1; | ||
51 | } | 85 | } |
52 | 86 | ||
53 | return ret; | 87 | - if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) { |
54 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_vsip64(CPURISCVState *env, int csrno, | 88 | - error_setg(errp, "Zve32f/Zve64f extensions require F extension"); |
55 | uint64_t new_val, uint64_t wr_mask) | 89 | - return; |
90 | + /* The Zve32f extension depends on the Zve32x extension */ | ||
91 | + if (cpu->cfg.ext_zve32f) { | ||
92 | + if (!riscv_has_ext(env, RVF)) { | ||
93 | + error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | ||
94 | + return; | ||
95 | + } | ||
96 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); | ||
97 | } | ||
98 | |||
99 | if (cpu->cfg.ext_zvfh) { | ||
100 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
101 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvbc), true); | ||
102 | } | ||
103 | |||
104 | - /* | ||
105 | - * In principle Zve*x would also suffice here, were they supported | ||
106 | - * in qemu | ||
107 | - */ | ||
108 | if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkb || cpu->cfg.ext_zvkg || | ||
109 | cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed || | ||
110 | - cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) { | ||
111 | + cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32x) { | ||
112 | error_setg(errp, | ||
113 | "Vector crypto extensions require V or Zve* extensions"); | ||
114 | return; | ||
115 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
118 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
119 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2) | ||
56 | { | 120 | { |
57 | RISCVException ret; | 121 | TCGv s1, dst; |
58 | - uint64_t rval, vsbits, mask = env->hideleg & vsip_writable_mask; | 122 | |
59 | + uint64_t rval, mask = env->hideleg & VS_MODE_INTERRUPTS; | 123 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { |
60 | 124 | + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) { | |
61 | /* Bring VS-level bits to correct position */ | 125 | return false; |
62 | - vsbits = new_val & (VS_MODE_INTERRUPTS >> 1); | ||
63 | - new_val &= ~(VS_MODE_INTERRUPTS >> 1); | ||
64 | - new_val |= vsbits << 1; | ||
65 | - vsbits = wr_mask & (VS_MODE_INTERRUPTS >> 1); | ||
66 | - wr_mask &= ~(VS_MODE_INTERRUPTS >> 1); | ||
67 | - wr_mask |= vsbits << 1; | ||
68 | - | ||
69 | - ret = rmw_mip64(env, csrno, &rval, new_val, wr_mask & mask); | ||
70 | + new_val = (new_val & (VS_MODE_INTERRUPTS >> 1)) << 1; | ||
71 | + wr_mask = (wr_mask & (VS_MODE_INTERRUPTS >> 1)) << 1; | ||
72 | + | ||
73 | + ret = rmw_mip64(env, csrno, &rval, new_val, | ||
74 | + wr_mask & mask & vsip_writable_mask); | ||
75 | if (ret_val) { | ||
76 | - rval &= mask; | ||
77 | - vsbits = rval & VS_MODE_INTERRUPTS; | ||
78 | - rval &= ~VS_MODE_INTERRUPTS; | ||
79 | - *ret_val = rval | (vsbits >> 1); | ||
80 | + *ret_val = (rval & mask) >> 1; | ||
81 | } | 126 | } |
82 | 127 | ||
83 | return ret; | 128 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2) |
129 | { | ||
130 | TCGv dst; | ||
131 | |||
132 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { | ||
133 | + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) { | ||
134 | return false; | ||
135 | } | ||
136 | |||
84 | -- | 137 | -- |
85 | 2.39.0 | 138 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | All RISCV CPUs are setting cpu->cfg during their cpu_init() functions, | 3 | Add support for Zve64x extension. Enabling Zve64f enables Zve64x and |
4 | meaning that there's no reason to skip all the misa validation and setup | 4 | enabling Zve64x enables Zve32x according to their dependency. |
5 | if misa_ext was set beforehand - especially since we're setting an | ||
6 | updated value in set_misa() in the end. | ||
7 | 5 | ||
8 | Put this code chunk into a new riscv_cpu_validate_set_extensions() | 6 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107 |
9 | helper and always execute it regardless of what the board set in | 7 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
10 | env->misa_ext. | 8 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
11 | 9 | Reviewed-by: Max Chou <max.chou@sifive.com> | |
12 | This will put more responsibility in how each board is going to init | 10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
13 | their attributes and extensions if they're not using the defaults. | 11 | Message-ID: <20240328022343.6871-3-jason.chien@sifive.com> |
14 | It'll also allow realize() to do its job looking only at the extensions | ||
15 | enabled per se, not corner cases that some CPUs might have, and we won't | ||
16 | have to change multiple code paths to fix or change how extensions work. | ||
17 | |||
18 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
19 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
20 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | ||
21 | Message-Id: <20230113175230.473975-3-dbarboza@ventanamicro.com> | ||
22 | [ Changes by AF: | ||
23 | - Rebase | ||
24 | ] | ||
25 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
26 | --- | 13 | --- |
27 | target/riscv/cpu.c | 399 +++++++++++++++++++++++---------------------- | 14 | target/riscv/cpu_cfg.h | 1 + |
28 | 1 file changed, 205 insertions(+), 194 deletions(-) | 15 | target/riscv/cpu.c | 2 ++ |
16 | target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------ | ||
17 | 3 files changed, 14 insertions(+), 6 deletions(-) | ||
29 | 18 | ||
19 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu_cfg.h | ||
22 | +++ b/target/riscv/cpu_cfg.h | ||
23 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
24 | bool ext_zve32x; | ||
25 | bool ext_zve64f; | ||
26 | bool ext_zve64d; | ||
27 | + bool ext_zve64x; | ||
28 | bool ext_zvbb; | ||
29 | bool ext_zvbc; | ||
30 | bool ext_zvkb; | ||
30 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
31 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/riscv/cpu.c | 33 | --- a/target/riscv/cpu.c |
33 | +++ b/target/riscv/cpu.c | 34 | +++ b/target/riscv/cpu.c |
34 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) | 35 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
35 | } | 36 | ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), |
36 | } | 37 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), |
37 | 38 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), | |
38 | +/* | 39 | + ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x), |
39 | + * Check consistency between chosen extensions while setting | 40 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), |
40 | + * cpu->cfg accordingly, doing a set_misa() in the end. | 41 | ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma), |
41 | + */ | 42 | ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh), |
42 | +static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | 43 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
43 | +{ | 44 | MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), |
44 | + CPURISCVState *env = &cpu->env; | 45 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), |
45 | + uint32_t ext = 0; | 46 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), |
46 | + | 47 | + MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false), |
47 | + /* Do some ISA extension error checking */ | 48 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), |
48 | + if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m && | 49 | MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false), |
49 | + cpu->cfg.ext_a && cpu->cfg.ext_f && | 50 | MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), |
50 | + cpu->cfg.ext_d && | 51 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
51 | + cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { | 52 | index XXXXXXX..XXXXXXX 100644 |
52 | + warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); | 53 | --- a/target/riscv/tcg/tcg-cpu.c |
53 | + cpu->cfg.ext_i = true; | 54 | +++ b/target/riscv/tcg/tcg-cpu.c |
54 | + cpu->cfg.ext_m = true; | 55 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
55 | + cpu->cfg.ext_a = true; | 56 | |
56 | + cpu->cfg.ext_f = true; | 57 | /* The Zve64d extension depends on the Zve64f extension */ |
57 | + cpu->cfg.ext_d = true; | 58 | if (cpu->cfg.ext_zve64d) { |
58 | + cpu->cfg.ext_icsr = true; | 59 | + if (!riscv_has_ext(env, RVD)) { |
59 | + cpu->cfg.ext_ifencei = true; | 60 | + error_setg(errp, "Zve64d/V extensions require D extension"); |
60 | + } | ||
61 | + | ||
62 | + if (cpu->cfg.ext_i && cpu->cfg.ext_e) { | ||
63 | + error_setg(errp, | ||
64 | + "I and E extensions are incompatible"); | ||
65 | + return; | ||
66 | + } | ||
67 | + | ||
68 | + if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { | ||
69 | + error_setg(errp, | ||
70 | + "Either I or E extension must be set"); | ||
71 | + return; | ||
72 | + } | ||
73 | + | ||
74 | + if (cpu->cfg.ext_s && !cpu->cfg.ext_u) { | ||
75 | + error_setg(errp, | ||
76 | + "Setting S extension without U extension is illegal"); | ||
77 | + return; | ||
78 | + } | ||
79 | + | ||
80 | + if (cpu->cfg.ext_h && !cpu->cfg.ext_i) { | ||
81 | + error_setg(errp, | ||
82 | + "H depends on an I base integer ISA with 32 x registers"); | ||
83 | + return; | ||
84 | + } | ||
85 | + | ||
86 | + if (cpu->cfg.ext_h && !cpu->cfg.ext_s) { | ||
87 | + error_setg(errp, "H extension implicitly requires S-mode"); | ||
88 | + return; | ||
89 | + } | ||
90 | + | ||
91 | + if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) { | ||
92 | + error_setg(errp, "F extension requires Zicsr"); | ||
93 | + return; | ||
94 | + } | ||
95 | + | ||
96 | + if ((cpu->cfg.ext_zawrs) && !cpu->cfg.ext_a) { | ||
97 | + error_setg(errp, "Zawrs extension requires A extension"); | ||
98 | + return; | ||
99 | + } | ||
100 | + | ||
101 | + if ((cpu->cfg.ext_zfh || cpu->cfg.ext_zfhmin) && !cpu->cfg.ext_f) { | ||
102 | + error_setg(errp, "Zfh/Zfhmin extensions require F extension"); | ||
103 | + return; | ||
104 | + } | ||
105 | + | ||
106 | + if (cpu->cfg.ext_d && !cpu->cfg.ext_f) { | ||
107 | + error_setg(errp, "D extension requires F extension"); | ||
108 | + return; | ||
109 | + } | ||
110 | + | ||
111 | + if (cpu->cfg.ext_v && !cpu->cfg.ext_d) { | ||
112 | + error_setg(errp, "V extension requires D extension"); | ||
113 | + return; | ||
114 | + } | ||
115 | + | ||
116 | + if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) { | ||
117 | + error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | ||
118 | + return; | ||
119 | + } | ||
120 | + | ||
121 | + /* Set the ISA extensions, checks should have happened above */ | ||
122 | + if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || | ||
123 | + cpu->cfg.ext_zhinxmin) { | ||
124 | + cpu->cfg.ext_zfinx = true; | ||
125 | + } | ||
126 | + | ||
127 | + if (cpu->cfg.ext_zfinx) { | ||
128 | + if (!cpu->cfg.ext_icsr) { | ||
129 | + error_setg(errp, "Zfinx extension requires Zicsr"); | ||
130 | + return; | 61 | + return; |
131 | + } | 62 | + } |
132 | + if (cpu->cfg.ext_f) { | 63 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); |
133 | + error_setg(errp, | ||
134 | + "Zfinx cannot be supported together with F extension"); | ||
135 | + return; | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
139 | + if (cpu->cfg.ext_zk) { | ||
140 | + cpu->cfg.ext_zkn = true; | ||
141 | + cpu->cfg.ext_zkr = true; | ||
142 | + cpu->cfg.ext_zkt = true; | ||
143 | + } | ||
144 | + | ||
145 | + if (cpu->cfg.ext_zkn) { | ||
146 | + cpu->cfg.ext_zbkb = true; | ||
147 | + cpu->cfg.ext_zbkc = true; | ||
148 | + cpu->cfg.ext_zbkx = true; | ||
149 | + cpu->cfg.ext_zkne = true; | ||
150 | + cpu->cfg.ext_zknd = true; | ||
151 | + cpu->cfg.ext_zknh = true; | ||
152 | + } | ||
153 | + | ||
154 | + if (cpu->cfg.ext_zks) { | ||
155 | + cpu->cfg.ext_zbkb = true; | ||
156 | + cpu->cfg.ext_zbkc = true; | ||
157 | + cpu->cfg.ext_zbkx = true; | ||
158 | + cpu->cfg.ext_zksed = true; | ||
159 | + cpu->cfg.ext_zksh = true; | ||
160 | + } | ||
161 | + | ||
162 | + if (cpu->cfg.ext_i) { | ||
163 | + ext |= RVI; | ||
164 | + } | ||
165 | + if (cpu->cfg.ext_e) { | ||
166 | + ext |= RVE; | ||
167 | + } | ||
168 | + if (cpu->cfg.ext_m) { | ||
169 | + ext |= RVM; | ||
170 | + } | ||
171 | + if (cpu->cfg.ext_a) { | ||
172 | + ext |= RVA; | ||
173 | + } | ||
174 | + if (cpu->cfg.ext_f) { | ||
175 | + ext |= RVF; | ||
176 | + } | ||
177 | + if (cpu->cfg.ext_d) { | ||
178 | + ext |= RVD; | ||
179 | + } | ||
180 | + if (cpu->cfg.ext_c) { | ||
181 | + ext |= RVC; | ||
182 | + } | ||
183 | + if (cpu->cfg.ext_s) { | ||
184 | + ext |= RVS; | ||
185 | + } | ||
186 | + if (cpu->cfg.ext_u) { | ||
187 | + ext |= RVU; | ||
188 | + } | ||
189 | + if (cpu->cfg.ext_h) { | ||
190 | + ext |= RVH; | ||
191 | + } | ||
192 | + if (cpu->cfg.ext_v) { | ||
193 | + int vext_version = VEXT_VERSION_1_00_0; | ||
194 | + ext |= RVV; | ||
195 | + if (!is_power_of_2(cpu->cfg.vlen)) { | ||
196 | + error_setg(errp, | ||
197 | + "Vector extension VLEN must be power of 2"); | ||
198 | + return; | ||
199 | + } | ||
200 | + if (cpu->cfg.vlen > RV_VLEN_MAX || cpu->cfg.vlen < 128) { | ||
201 | + error_setg(errp, | ||
202 | + "Vector extension implementation only supports VLEN " | ||
203 | + "in the range [128, %d]", RV_VLEN_MAX); | ||
204 | + return; | ||
205 | + } | ||
206 | + if (!is_power_of_2(cpu->cfg.elen)) { | ||
207 | + error_setg(errp, | ||
208 | + "Vector extension ELEN must be power of 2"); | ||
209 | + return; | ||
210 | + } | ||
211 | + if (cpu->cfg.elen > 64 || cpu->cfg.elen < 8) { | ||
212 | + error_setg(errp, | ||
213 | + "Vector extension implementation only supports ELEN " | ||
214 | + "in the range [8, 64]"); | ||
215 | + return; | ||
216 | + } | ||
217 | + if (cpu->cfg.vext_spec) { | ||
218 | + if (!g_strcmp0(cpu->cfg.vext_spec, "v1.0")) { | ||
219 | + vext_version = VEXT_VERSION_1_00_0; | ||
220 | + } else { | ||
221 | + error_setg(errp, | ||
222 | + "Unsupported vector spec version '%s'", | ||
223 | + cpu->cfg.vext_spec); | ||
224 | + return; | ||
225 | + } | ||
226 | + } else { | ||
227 | + qemu_log("vector version is not specified, " | ||
228 | + "use the default value v1.0\n"); | ||
229 | + } | ||
230 | + set_vext_version(env, vext_version); | ||
231 | + } | ||
232 | + if (cpu->cfg.ext_j) { | ||
233 | + ext |= RVJ; | ||
234 | + } | ||
235 | + | ||
236 | + set_misa(env, env->misa_mxl, ext); | ||
237 | +} | ||
238 | + | ||
239 | static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
240 | { | ||
241 | CPUState *cs = CPU(dev); | ||
242 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
243 | } | 64 | } |
244 | assert(env->misa_mxl_max == env->misa_mxl); | 65 | |
245 | 66 | - /* The Zve64f extension depends on the Zve32f extension */ | |
246 | - /* If only MISA_EXT is unset for misa, then set it from properties */ | 67 | + /* The Zve64f extension depends on the Zve64x and Zve32f extensions */ |
247 | - if (env->misa_ext == 0) { | 68 | if (cpu->cfg.ext_zve64f) { |
248 | - uint32_t ext = 0; | 69 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true); |
249 | - | 70 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); |
250 | - /* Do some ISA extension error checking */ | ||
251 | - if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m && | ||
252 | - cpu->cfg.ext_a && cpu->cfg.ext_f && | ||
253 | - cpu->cfg.ext_d && | ||
254 | - cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { | ||
255 | - warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); | ||
256 | - cpu->cfg.ext_i = true; | ||
257 | - cpu->cfg.ext_m = true; | ||
258 | - cpu->cfg.ext_a = true; | ||
259 | - cpu->cfg.ext_f = true; | ||
260 | - cpu->cfg.ext_d = true; | ||
261 | - cpu->cfg.ext_icsr = true; | ||
262 | - cpu->cfg.ext_ifencei = true; | ||
263 | - } | ||
264 | - | ||
265 | - if (cpu->cfg.ext_i && cpu->cfg.ext_e) { | ||
266 | - error_setg(errp, | ||
267 | - "I and E extensions are incompatible"); | ||
268 | - return; | ||
269 | - } | ||
270 | - | ||
271 | - if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { | ||
272 | - error_setg(errp, | ||
273 | - "Either I or E extension must be set"); | ||
274 | - return; | ||
275 | - } | ||
276 | - | ||
277 | - if (cpu->cfg.ext_s && !cpu->cfg.ext_u) { | ||
278 | - error_setg(errp, | ||
279 | - "Setting S extension without U extension is illegal"); | ||
280 | - return; | ||
281 | - } | ||
282 | - | ||
283 | - if (cpu->cfg.ext_h && !cpu->cfg.ext_i) { | ||
284 | - error_setg(errp, | ||
285 | - "H depends on an I base integer ISA with 32 x registers"); | ||
286 | - return; | ||
287 | - } | ||
288 | - | ||
289 | - if (cpu->cfg.ext_h && !cpu->cfg.ext_s) { | ||
290 | - error_setg(errp, "H extension implicitly requires S-mode"); | ||
291 | - return; | ||
292 | - } | ||
293 | - | ||
294 | - if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) { | ||
295 | - error_setg(errp, "F extension requires Zicsr"); | ||
296 | - return; | ||
297 | - } | ||
298 | - | ||
299 | - if ((cpu->cfg.ext_zawrs) && !cpu->cfg.ext_a) { | ||
300 | - error_setg(errp, "Zawrs extension requires A extension"); | ||
301 | - return; | ||
302 | - } | ||
303 | - | ||
304 | - if ((cpu->cfg.ext_zfh || cpu->cfg.ext_zfhmin) && !cpu->cfg.ext_f) { | ||
305 | - error_setg(errp, "Zfh/Zfhmin extensions require F extension"); | ||
306 | - return; | ||
307 | - } | ||
308 | - | ||
309 | - if (cpu->cfg.ext_d && !cpu->cfg.ext_f) { | ||
310 | - error_setg(errp, "D extension requires F extension"); | ||
311 | - return; | ||
312 | - } | ||
313 | - | ||
314 | - if (cpu->cfg.ext_v && !cpu->cfg.ext_d) { | ||
315 | - error_setg(errp, "V extension requires D extension"); | ||
316 | - return; | ||
317 | - } | ||
318 | - | ||
319 | - if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) { | ||
320 | - error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | ||
321 | - return; | ||
322 | - } | ||
323 | - | ||
324 | - /* Set the ISA extensions, checks should have happened above */ | ||
325 | - if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || | ||
326 | - cpu->cfg.ext_zhinxmin) { | ||
327 | - cpu->cfg.ext_zfinx = true; | ||
328 | - } | ||
329 | - | ||
330 | - if (cpu->cfg.ext_zfinx) { | ||
331 | - if (!cpu->cfg.ext_icsr) { | ||
332 | - error_setg(errp, "Zfinx extension requires Zicsr"); | ||
333 | - return; | ||
334 | - } | ||
335 | - if (cpu->cfg.ext_f) { | ||
336 | - error_setg(errp, | ||
337 | - "Zfinx cannot be supported together with F extension"); | ||
338 | - return; | ||
339 | - } | ||
340 | - } | ||
341 | - | ||
342 | - if (cpu->cfg.ext_zk) { | ||
343 | - cpu->cfg.ext_zkn = true; | ||
344 | - cpu->cfg.ext_zkr = true; | ||
345 | - cpu->cfg.ext_zkt = true; | ||
346 | - } | ||
347 | - | ||
348 | - if (cpu->cfg.ext_zkn) { | ||
349 | - cpu->cfg.ext_zbkb = true; | ||
350 | - cpu->cfg.ext_zbkc = true; | ||
351 | - cpu->cfg.ext_zbkx = true; | ||
352 | - cpu->cfg.ext_zkne = true; | ||
353 | - cpu->cfg.ext_zknd = true; | ||
354 | - cpu->cfg.ext_zknh = true; | ||
355 | - } | ||
356 | - | ||
357 | - if (cpu->cfg.ext_zks) { | ||
358 | - cpu->cfg.ext_zbkb = true; | ||
359 | - cpu->cfg.ext_zbkc = true; | ||
360 | - cpu->cfg.ext_zbkx = true; | ||
361 | - cpu->cfg.ext_zksed = true; | ||
362 | - cpu->cfg.ext_zksh = true; | ||
363 | - } | ||
364 | - | ||
365 | - if (cpu->cfg.ext_i) { | ||
366 | - ext |= RVI; | ||
367 | - } | ||
368 | - if (cpu->cfg.ext_e) { | ||
369 | - ext |= RVE; | ||
370 | - } | ||
371 | - if (cpu->cfg.ext_m) { | ||
372 | - ext |= RVM; | ||
373 | - } | ||
374 | - if (cpu->cfg.ext_a) { | ||
375 | - ext |= RVA; | ||
376 | - } | ||
377 | - if (cpu->cfg.ext_f) { | ||
378 | - ext |= RVF; | ||
379 | - } | ||
380 | - if (cpu->cfg.ext_d) { | ||
381 | - ext |= RVD; | ||
382 | - } | ||
383 | - if (cpu->cfg.ext_c) { | ||
384 | - ext |= RVC; | ||
385 | - } | ||
386 | - if (cpu->cfg.ext_s) { | ||
387 | - ext |= RVS; | ||
388 | - } | ||
389 | - if (cpu->cfg.ext_u) { | ||
390 | - ext |= RVU; | ||
391 | - } | ||
392 | - if (cpu->cfg.ext_h) { | ||
393 | - ext |= RVH; | ||
394 | - } | ||
395 | - if (cpu->cfg.ext_v) { | ||
396 | - int vext_version = VEXT_VERSION_1_00_0; | ||
397 | - ext |= RVV; | ||
398 | - if (!is_power_of_2(cpu->cfg.vlen)) { | ||
399 | - error_setg(errp, | ||
400 | - "Vector extension VLEN must be power of 2"); | ||
401 | - return; | ||
402 | - } | ||
403 | - if (cpu->cfg.vlen > RV_VLEN_MAX || cpu->cfg.vlen < 128) { | ||
404 | - error_setg(errp, | ||
405 | - "Vector extension implementation only supports VLEN " | ||
406 | - "in the range [128, %d]", RV_VLEN_MAX); | ||
407 | - return; | ||
408 | - } | ||
409 | - if (!is_power_of_2(cpu->cfg.elen)) { | ||
410 | - error_setg(errp, | ||
411 | - "Vector extension ELEN must be power of 2"); | ||
412 | - return; | ||
413 | - } | ||
414 | - if (cpu->cfg.elen > 64 || cpu->cfg.elen < 8) { | ||
415 | - error_setg(errp, | ||
416 | - "Vector extension implementation only supports ELEN " | ||
417 | - "in the range [8, 64]"); | ||
418 | - return; | ||
419 | - } | ||
420 | - if (cpu->cfg.vext_spec) { | ||
421 | - if (!g_strcmp0(cpu->cfg.vext_spec, "v1.0")) { | ||
422 | - vext_version = VEXT_VERSION_1_00_0; | ||
423 | - } else { | ||
424 | - error_setg(errp, | ||
425 | - "Unsupported vector spec version '%s'", | ||
426 | - cpu->cfg.vext_spec); | ||
427 | - return; | ||
428 | - } | ||
429 | - } else { | ||
430 | - qemu_log("vector version is not specified, " | ||
431 | - "use the default value v1.0\n"); | ||
432 | - } | ||
433 | - set_vext_version(env, vext_version); | ||
434 | - } | ||
435 | - if (cpu->cfg.ext_j) { | ||
436 | - ext |= RVJ; | ||
437 | - } | ||
438 | - | ||
439 | - set_misa(env, env->misa_mxl, ext); | ||
440 | + riscv_cpu_validate_set_extensions(cpu, &local_err); | ||
441 | + if (local_err != NULL) { | ||
442 | + error_propagate(errp, local_err); | ||
443 | + return; | ||
444 | } | 71 | } |
445 | 72 | ||
446 | #ifndef CONFIG_USER_ONLY | 73 | - if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) { |
74 | - error_setg(errp, "Zve64d/V extensions require D extension"); | ||
75 | - return; | ||
76 | + /* The Zve64x extension depends on the Zve32x extension */ | ||
77 | + if (cpu->cfg.ext_zve64x) { | ||
78 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); | ||
79 | } | ||
80 | |||
81 | /* The Zve32f extension depends on the Zve32x extension */ | ||
82 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | - if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) { | ||
87 | + if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) { | ||
88 | error_setg( | ||
89 | errp, | ||
90 | - "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions"); | ||
91 | + "Zvbc and Zvknhb extensions require V or Zve64x extensions"); | ||
92 | return; | ||
93 | } | ||
94 | |||
447 | -- | 95 | -- |
448 | 2.39.0 | 96 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | We failed to update this with the w^x split, so misses the fact | 3 | In current implementation, the gdbstub allows reading vector registers |
4 | that true pc-relative offsets are usually small. | 4 | only if V extension is supported. However, all vector extensions and |
5 | vector crypto extensions have the vector registers and they all depend | ||
6 | on Zve32x. The gdbstub should check for Zve32x instead. | ||
5 | 7 | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
8 | Message-Id: <20230117230415.354239-1-richard.henderson@linaro.org> | 10 | Reviewed-by: Max Chou <max.chou@sifive.com> |
11 | Message-ID: <20240328022343.6871-4-jason.chien@sifive.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 13 | --- |
11 | tcg/riscv/tcg-target.c.inc | 2 +- | 14 | target/riscv/gdbstub.c | 2 +- |
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 16 | ||
14 | diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc | 17 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
15 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tcg/riscv/tcg-target.c.inc | 19 | --- a/target/riscv/gdbstub.c |
17 | +++ b/tcg/riscv/tcg-target.c.inc | 20 | +++ b/target/riscv/gdbstub.c |
18 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_ldst(TCGContext *s, RISCVInsn opc, TCGReg data, | 21 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) |
19 | intptr_t imm12 = sextreg(offset, 0, 12); | 22 | gdb_find_static_feature("riscv-32bit-fpu.xml"), |
20 | 23 | 0); | |
21 | if (offset != imm12) { | 24 | } |
22 | - intptr_t diff = offset - (uintptr_t)s->code_ptr; | 25 | - if (env->misa_ext & RVV) { |
23 | + intptr_t diff = tcg_pcrel_diff(s, (void *)offset); | 26 | + if (cpu->cfg.ext_zve32x) { |
24 | 27 | gdb_register_coprocessor(cs, riscv_gdb_get_vector, | |
25 | if (addr == TCG_REG_ZERO && diff == (int32_t)diff) { | 28 | riscv_gdb_set_vector, |
26 | imm12 = sextreg(diff, 0, 12); | 29 | ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs), |
27 | -- | 30 | -- |
28 | 2.39.0 | 31 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | 'filename', 'mem_size' and 'fdt' from riscv_load_initrd() can all be | 3 | In RVV and vcrypto instructions, the masked and tail elements are set to 1s |
4 | retrieved by the MachineState object for all callers. | 4 | using vext_set_elems_1s function if the vma/vta bit is set. It is the element |
5 | agnostic policy. | ||
5 | 6 | ||
6 | Cc: Palmer Dabbelt <palmer@dabbelt.com> | 7 | However, this function can't deal the big endian situation. This patch fixes |
7 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 8 | the problem by adding handling of such case. |
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 9 | |
9 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | 10 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> |
11 | Message-Id: <20230102115241.25733-9-dbarboza@ventanamicro.com> | 12 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
14 | Message-ID: <20240325021654.6594-1-eric.huang@linux.alibaba.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 16 | --- |
14 | include/hw/riscv/boot.h | 3 +-- | 17 | target/riscv/vector_internals.c | 22 ++++++++++++++++++++++ |
15 | hw/riscv/boot.c | 6 ++++-- | 18 | 1 file changed, 22 insertions(+) |
16 | hw/riscv/microchip_pfsoc.c | 3 +-- | ||
17 | hw/riscv/sifive_u.c | 3 +-- | ||
18 | hw/riscv/spike.c | 3 +-- | ||
19 | hw/riscv/virt.c | 3 +-- | ||
20 | 6 files changed, 9 insertions(+), 12 deletions(-) | ||
21 | 19 | ||
22 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h | 20 | diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c |
23 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/riscv/boot.h | 22 | --- a/target/riscv/vector_internals.c |
25 | +++ b/include/hw/riscv/boot.h | 23 | +++ b/target/riscv/vector_internals.c |
26 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_firmware(const char *firmware_filename, | 24 | @@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, |
27 | target_ulong riscv_load_kernel(const char *kernel_filename, | 25 | if (tot - cnt == 0) { |
28 | target_ulong firmware_end_addr, | 26 | return ; |
29 | symbol_fn_t sym_cb); | 27 | } |
30 | -void riscv_load_initrd(const char *filename, uint64_t mem_size, | 28 | + |
31 | - uint64_t kernel_entry, void *fdt); | 29 | + if (HOST_BIG_ENDIAN) { |
32 | +void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry); | 30 | + /* |
33 | uint64_t riscv_load_fdt(hwaddr dram_start, uint64_t dram_size, void *fdt); | 31 | + * Deal the situation when the elements are insdie |
34 | void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts, | 32 | + * only one uint64 block including setting the |
35 | hwaddr saddr, | 33 | + * masked-off element. |
36 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | 34 | + */ |
37 | index XXXXXXX..XXXXXXX 100644 | 35 | + if (((tot - 1) ^ cnt) < 8) { |
38 | --- a/hw/riscv/boot.c | 36 | + memset(base + H1(tot - 1), -1, tot - cnt); |
39 | +++ b/hw/riscv/boot.c | 37 | + return; |
40 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_kernel(const char *kernel_filename, | 38 | + } |
41 | exit(1); | 39 | + /* |
40 | + * Otherwise, at least cross two uint64_t blocks. | ||
41 | + * Set first unaligned block. | ||
42 | + */ | ||
43 | + if (cnt % 8 != 0) { | ||
44 | + uint32_t j = ROUND_UP(cnt, 8); | ||
45 | + memset(base + H1(j - 1), -1, j - cnt); | ||
46 | + cnt = j; | ||
47 | + } | ||
48 | + /* Set other 64bit aligend blocks */ | ||
49 | + } | ||
50 | memset(base + cnt, -1, tot - cnt); | ||
42 | } | 51 | } |
43 | 52 | ||
44 | -void riscv_load_initrd(const char *filename, uint64_t mem_size, | ||
45 | - uint64_t kernel_entry, void *fdt) | ||
46 | +void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) | ||
47 | { | ||
48 | + const char *filename = machine->initrd_filename; | ||
49 | + uint64_t mem_size = machine->ram_size; | ||
50 | + void *fdt = machine->fdt; | ||
51 | hwaddr start, end; | ||
52 | ssize_t size; | ||
53 | |||
54 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/hw/riscv/microchip_pfsoc.c | ||
57 | +++ b/hw/riscv/microchip_pfsoc.c | ||
58 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) | ||
59 | kernel_start_addr, NULL); | ||
60 | |||
61 | if (machine->initrd_filename) { | ||
62 | - riscv_load_initrd(machine->initrd_filename, machine->ram_size, | ||
63 | - kernel_entry, machine->fdt); | ||
64 | + riscv_load_initrd(machine, kernel_entry); | ||
65 | } | ||
66 | |||
67 | if (machine->kernel_cmdline && *machine->kernel_cmdline) { | ||
68 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/hw/riscv/sifive_u.c | ||
71 | +++ b/hw/riscv/sifive_u.c | ||
72 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
73 | kernel_start_addr, NULL); | ||
74 | |||
75 | if (machine->initrd_filename) { | ||
76 | - riscv_load_initrd(machine->initrd_filename, machine->ram_size, | ||
77 | - kernel_entry, machine->fdt); | ||
78 | + riscv_load_initrd(machine, kernel_entry); | ||
79 | } | ||
80 | |||
81 | if (machine->kernel_cmdline && *machine->kernel_cmdline) { | ||
82 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/hw/riscv/spike.c | ||
85 | +++ b/hw/riscv/spike.c | ||
86 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
87 | htif_symbol_callback); | ||
88 | |||
89 | if (machine->initrd_filename) { | ||
90 | - riscv_load_initrd(machine->initrd_filename, machine->ram_size, | ||
91 | - kernel_entry, machine->fdt); | ||
92 | + riscv_load_initrd(machine, kernel_entry); | ||
93 | } | ||
94 | |||
95 | if (machine->kernel_cmdline && *machine->kernel_cmdline) { | ||
96 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/hw/riscv/virt.c | ||
99 | +++ b/hw/riscv/virt.c | ||
100 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) | ||
101 | kernel_start_addr, NULL); | ||
102 | |||
103 | if (machine->initrd_filename) { | ||
104 | - riscv_load_initrd(machine->initrd_filename, machine->ram_size, | ||
105 | - kernel_entry, machine->fdt); | ||
106 | + riscv_load_initrd(machine, kernel_entry); | ||
107 | } | ||
108 | |||
109 | if (machine->kernel_cmdline && *machine->kernel_cmdline) { | ||
110 | -- | 53 | -- |
111 | 2.39.0 | 54 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Dongxue Zhang <elta.era@gmail.com> | 1 | From: Yangyu Chen <cyy@cyyself.name> |
---|---|---|---|
2 | 2 | ||
3 | The elen check should be cpu->cfg.elen in range [8, 64]. | 3 | This code has a typo that writes zvkb to zvkg, causing users can't |
4 | enable zvkb through the config. This patch gets this fixed. | ||
4 | 5 | ||
5 | Signed-off-by: Dongxue Zhang <elta.era@gmail.com> | 6 | Signed-off-by: Yangyu Chen <cyy@cyyself.name> |
6 | Reviewed-by: LIU Zhiwei <zhiwe_liu@linux.alibaba.com> | 7 | Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions") |
7 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | 8 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <167236721596.15277.2653405273227256289-0@git.sr.ht> | 10 | Reviewed-by: Max Chou <max.chou@sifive.com> |
10 | [ Changes by AF: | 11 | Reviewed-by: Weiwei Li <liwei1518@gmail.com> |
11 | - Tidy up commit message | 12 | Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com> |
12 | ] | 13 | Cc: qemu-stable <qemu-stable@nongnu.org> |
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 15 | --- |
15 | target/riscv/cpu.c | 2 +- | 16 | target/riscv/cpu.c | 2 +- |
16 | 1 file changed, 1 insertion(+), 1 deletion(-) | 17 | 1 file changed, 1 insertion(+), 1 deletion(-) |
17 | 18 | ||
18 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 19 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
19 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/cpu.c | 21 | --- a/target/riscv/cpu.c |
21 | +++ b/target/riscv/cpu.c | 22 | +++ b/target/riscv/cpu.c |
22 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 23 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
23 | "Vector extension ELEN must be power of 2"); | 24 | /* Vector cryptography extensions */ |
24 | return; | 25 | MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false), |
25 | } | 26 | MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false), |
26 | - if (cpu->cfg.elen > 64 || cpu->cfg.vlen < 8) { | 27 | - MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false), |
27 | + if (cpu->cfg.elen > 64 || cpu->cfg.elen < 8) { | 28 | + MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false), |
28 | error_setg(errp, | 29 | MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false), |
29 | "Vector extension implementation only supports ELEN " | 30 | MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false), |
30 | "in the range [8, 64]"); | 31 | MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false), |
31 | -- | 32 | -- |
32 | 2.39.0 | 33 | 2.45.1 |
34 | |||
35 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | The only caller is riscv_find_and_load_firmware(), which is in the same | 3 | In this patch, we modify the decoder to be a freely composable data |
4 | file. | 4 | structure instead of a hardcoded one. It can be dynamically builded up |
5 | according to the extensions. | ||
6 | This approach has several benefits: | ||
7 | 1. Provides support for heterogeneous cpu architectures. As we add decoder in | ||
8 | RISCVCPU, each cpu can have their own decoder, and the decoders can be | ||
9 | different due to cpu's features. | ||
10 | 2. Improve the decoding efficiency. We run the guard_func to see if the decoder | ||
11 | can be added to the dynamic_decoder when building up the decoder. Therefore, | ||
12 | there is no need to run the guard_func when decoding each instruction. It can | ||
13 | improve the decoding efficiency | ||
14 | 3. For vendor or dynamic cpus, it allows them to customize their own decoder | ||
15 | functions to improve decoding efficiency, especially when vendor-defined | ||
16 | instruction sets increase. Because of dynamic building up, it can skip the other | ||
17 | decoder guard functions when decoding. | ||
18 | 4. Pre patch for allowing adding a vendor decoder before decode_insn32() with minimal | ||
19 | overhead for users that don't need this particular vendor decoder. | ||
5 | 20 | ||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 21 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 22 | Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu> |
23 | Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 25 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | 26 | Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com> |
10 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
11 | Message-Id: <20221221182300.307900-5-dbarboza@ventanamicro.com> | ||
12 | Message-Id: <20221229091828.1945072-10-bmeng@tinylab.org> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 28 | --- |
15 | include/hw/riscv/boot.h | 1 - | 29 | target/riscv/cpu.h | 1 + |
16 | hw/riscv/boot.c | 44 ++++++++++++++++++++--------------------- | 30 | target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++ |
17 | 2 files changed, 22 insertions(+), 23 deletions(-) | 31 | target/riscv/cpu.c | 1 + |
32 | target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++ | ||
33 | target/riscv/translate.c | 31 +++++++++++++++---------------- | ||
34 | 5 files changed, 47 insertions(+), 16 deletions(-) | ||
18 | 35 | ||
19 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h | 36 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
20 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/hw/riscv/boot.h | 38 | --- a/target/riscv/cpu.h |
22 | +++ b/include/hw/riscv/boot.h | 39 | +++ b/target/riscv/cpu.h |
23 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_find_and_load_firmware(MachineState *machine, | 40 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { |
24 | const char *default_machine_firmware, | 41 | uint32_t pmu_avail_ctrs; |
25 | hwaddr firmware_load_addr, | 42 | /* Mapping of events to counters */ |
26 | symbol_fn_t sym_cb); | 43 | GHashTable *pmu_event_ctr_map; |
27 | -char *riscv_find_firmware(const char *firmware_filename); | 44 | + const GPtrArray *decoders; |
28 | target_ulong riscv_load_firmware(const char *firmware_filename, | 45 | }; |
29 | hwaddr firmware_load_addr, | 46 | |
30 | symbol_fn_t sym_cb); | 47 | /** |
31 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | 48 | diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h |
32 | index XXXXXXX..XXXXXXX 100644 | 49 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/hw/riscv/boot.c | 50 | --- a/target/riscv/tcg/tcg-cpu.h |
34 | +++ b/hw/riscv/boot.c | 51 | +++ b/target/riscv/tcg/tcg-cpu.h |
35 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_calc_kernel_start_addr(RISCVHartArrayState *harts, | 52 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); |
53 | void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp); | ||
54 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu); | ||
55 | |||
56 | +struct DisasContext; | ||
57 | +struct RISCVCPUConfig; | ||
58 | +typedef struct RISCVDecoder { | ||
59 | + bool (*guard_func)(const struct RISCVCPUConfig *); | ||
60 | + bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | ||
61 | +} RISCVDecoder; | ||
62 | + | ||
63 | +typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | ||
64 | + | ||
65 | +extern const size_t decoder_table_size; | ||
66 | + | ||
67 | +extern const RISCVDecoder decoder_table[]; | ||
68 | + | ||
69 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu); | ||
70 | + | ||
71 | #endif | ||
72 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/target/riscv/cpu.c | ||
75 | +++ b/target/riscv/cpu.c | ||
76 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) | ||
77 | error_propagate(errp, local_err); | ||
78 | return; | ||
79 | } | ||
80 | + riscv_tcg_cpu_finalize_dynamic_decoder(cpu); | ||
81 | } else if (kvm_enabled()) { | ||
82 | riscv_kvm_cpu_finalize_features(cpu, &local_err); | ||
83 | if (local_err != NULL) { | ||
84 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/target/riscv/tcg/tcg-cpu.c | ||
87 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
88 | @@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp) | ||
36 | } | 89 | } |
37 | } | 90 | } |
38 | 91 | ||
39 | +static char *riscv_find_firmware(const char *firmware_filename) | 92 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu) |
40 | +{ | 93 | +{ |
41 | + char *filename; | 94 | + GPtrArray *dynamic_decoders; |
42 | + | 95 | + dynamic_decoders = g_ptr_array_sized_new(decoder_table_size); |
43 | + filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware_filename); | 96 | + for (size_t i = 0; i < decoder_table_size; ++i) { |
44 | + if (filename == NULL) { | 97 | + if (decoder_table[i].guard_func && |
45 | + if (!qtest_enabled()) { | 98 | + decoder_table[i].guard_func(&cpu->cfg)) { |
46 | + /* | 99 | + g_ptr_array_add(dynamic_decoders, |
47 | + * We only ship OpenSBI binary bios images in the QEMU source. | 100 | + (gpointer)decoder_table[i].riscv_cpu_decode_fn); |
48 | + * For machines that use images other than the default bios, | ||
49 | + * running QEMU test will complain hence let's suppress the error | ||
50 | + * report for QEMU testing. | ||
51 | + */ | ||
52 | + error_report("Unable to load the RISC-V firmware \"%s\"", | ||
53 | + firmware_filename); | ||
54 | + exit(1); | ||
55 | + } | 101 | + } |
56 | + } | 102 | + } |
57 | + | 103 | + |
58 | + return filename; | 104 | + cpu->decoders = dynamic_decoders; |
59 | +} | 105 | +} |
60 | + | 106 | + |
61 | target_ulong riscv_find_and_load_firmware(MachineState *machine, | 107 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu) |
62 | const char *default_machine_firmware, | 108 | { |
63 | hwaddr firmware_load_addr, | 109 | return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL; |
64 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_find_and_load_firmware(MachineState *machine, | 110 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
65 | return firmware_end_addr; | 111 | index XXXXXXX..XXXXXXX 100644 |
112 | --- a/target/riscv/translate.c | ||
113 | +++ b/target/riscv/translate.c | ||
114 | @@ -XXX,XX +XXX,XX @@ | ||
115 | #include "exec/helper-info.c.inc" | ||
116 | #undef HELPER_H | ||
117 | |||
118 | +#include "tcg/tcg-cpu.h" | ||
119 | + | ||
120 | /* global register indices */ | ||
121 | static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart; | ||
122 | static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */ | ||
123 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
124 | /* FRM is known to contain a valid value. */ | ||
125 | bool frm_valid; | ||
126 | bool insn_start_updated; | ||
127 | + const GPtrArray *decoders; | ||
128 | } DisasContext; | ||
129 | |||
130 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) | ||
131 | @@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word) | ||
132 | return (first_word & 3) == 3 ? 4 : 2; | ||
66 | } | 133 | } |
67 | 134 | ||
68 | -char *riscv_find_firmware(const char *firmware_filename) | 135 | +const RISCVDecoder decoder_table[] = { |
69 | -{ | 136 | + { always_true_p, decode_insn32 }, |
70 | - char *filename; | 137 | + { has_xthead_p, decode_xthead}, |
138 | + { has_XVentanaCondOps_p, decode_XVentanaCodeOps}, | ||
139 | +}; | ||
140 | + | ||
141 | +const size_t decoder_table_size = ARRAY_SIZE(decoder_table); | ||
142 | + | ||
143 | static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | ||
144 | { | ||
145 | - /* | ||
146 | - * A table with predicate (i.e., guard) functions and decoder functions | ||
147 | - * that are tested in-order until a decoder matches onto the opcode. | ||
148 | - */ | ||
149 | - static const struct { | ||
150 | - bool (*guard_func)(const RISCVCPUConfig *); | ||
151 | - bool (*decode_func)(DisasContext *, uint32_t); | ||
152 | - } decoders[] = { | ||
153 | - { always_true_p, decode_insn32 }, | ||
154 | - { has_xthead_p, decode_xthead }, | ||
155 | - { has_XVentanaCondOps_p, decode_XVentanaCodeOps }, | ||
156 | - }; | ||
71 | - | 157 | - |
72 | - filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware_filename); | 158 | ctx->virt_inst_excp = false; |
73 | - if (filename == NULL) { | 159 | ctx->cur_insn_len = insn_len(opcode); |
74 | - if (!qtest_enabled()) { | 160 | /* Check for compressed insn */ |
75 | - /* | 161 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) |
76 | - * We only ship OpenSBI binary bios images in the QEMU source. | 162 | ctx->base.pc_next + 2)); |
77 | - * For machines that use images other than the default bios, | 163 | ctx->opcode = opcode32; |
78 | - * running QEMU test will complain hence let's suppress the error | 164 | |
79 | - * report for QEMU testing. | 165 | - for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i) { |
80 | - */ | 166 | - if (decoders[i].guard_func(ctx->cfg_ptr) && |
81 | - error_report("Unable to load the RISC-V firmware \"%s\"", | 167 | - decoders[i].decode_func(ctx, opcode32)) { |
82 | - firmware_filename); | 168 | + for (guint i = 0; i < ctx->decoders->len; ++i) { |
83 | - exit(1); | 169 | + riscv_cpu_decode_fn func = g_ptr_array_index(ctx->decoders, i); |
84 | - } | 170 | + if (func(ctx, opcode32)) { |
85 | - } | 171 | return; |
86 | - | 172 | } |
87 | - return filename; | 173 | } |
88 | -} | 174 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) |
89 | - | 175 | ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); |
90 | target_ulong riscv_load_firmware(const char *firmware_filename, | 176 | ctx->zero = tcg_constant_tl(0); |
91 | hwaddr firmware_load_addr, | 177 | ctx->virt_inst_excp = false; |
92 | symbol_fn_t sym_cb) | 178 | + ctx->decoders = cpu->decoders; |
179 | } | ||
180 | |||
181 | static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) | ||
93 | -- | 182 | -- |
94 | 2.39.0 | 183 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Christoph Müllner <christoph.muellner@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | There is an informal contract between the cpu_init() functions and | 3 | The th.sxstatus CSR can be used to identify available custom extension |
4 | riscv_cpu_realize(): if cpu->env.misa_ext is zero, assume that the | 4 | on T-Head CPUs. The CSR is documented here: |
5 | default settings were loaded via register_cpu_props() and do validations | 5 | https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc |
6 | to set env.misa_ext. If it's not zero, skip this whole process and | ||
7 | assume that the board somehow did everything. | ||
8 | 6 | ||
9 | At this moment, all SiFive CPUs are setting a non-zero misa_ext during | 7 | An important property of this patch is, that the th.sxstatus MAEE field |
10 | their cpu_init() and skipping a good chunk of riscv_cpu_realize(). This | 8 | is not set (indicating that XTheadMae is not available). |
11 | causes problems when the code being skipped in riscv_cpu_realize() | 9 | XTheadMae is a memory attribute extension (similar to Svpbmt) which is |
12 | contains fixes or assumptions that affects all CPUs, meaning that SiFive | 10 | implemented in many T-Head CPUs (C906, C910, etc.) and utilizes bits |
13 | CPUs are missing out. | 11 | in PTEs that are marked as reserved. QEMU maintainers prefer to not |
12 | implement XTheadMae, so we need give kernels a mechanism to identify | ||
13 | if XTheadMae is available in a system or not. And this patch introduces | ||
14 | this mechanism in QEMU in a way that's compatible with real HW | ||
15 | (i.e., probing the th.sxstatus.MAEE bit). | ||
14 | 16 | ||
15 | To allow this code to not be skipped anymore, all the cpu->cfg.ext_* | 17 | Further context can be found on the list: |
16 | attributes needs to be set during cpu_init() time. At this moment this | 18 | https://lists.gnu.org/archive/html/qemu-devel/2024-02/msg00775.html |
17 | is being done in register_cpu_props(). The SiFive boards are setting | ||
18 | their own extensions during cpu_init() though, meaning that they don't | ||
19 | want all the defaults from register_cpu_props(). | ||
20 | 19 | ||
21 | Let's move the contract between *_cpu_init() and riscv_cpu_realize() to | 20 | Reviewed-by: LIU Zhiwei <zhiwe_liu@linux.alibaba.com> |
22 | register_cpu_props(). Inside this function we'll check if | ||
23 | cpu->env.misa_ext was set and, if that's the case, set all relevant | ||
24 | cpu->cfg.ext_* attributes, and only that. Leave the 'misa_ext' = 0 case | ||
25 | as is today, i.e. loading all the defaults from riscv_cpu_extensions[]. | ||
26 | |||
27 | register_cpu_props() can then be called by all the cpu_init() functions, | ||
28 | including the SiFive ones. This will make all CPUs behave more in line | ||
29 | with what riscv_cpu_realize() expects. | ||
30 | |||
31 | This will also make the cpu_init() functions even more alike, but at this | ||
32 | moment we would need some design changes in how we're initializing | ||
33 | extensions/attributes (e.g. some CPUs are setting cfg options after | ||
34 | register_cpu_props(), so we can't simply add the function to a common | ||
35 | post_init() hook) to make a common cpu_init() code across all CPUs. | ||
36 | |||
37 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
38 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
39 | Message-Id: <20230113175230.473975-2-dbarboza@ventanamicro.com> | 22 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> |
23 | Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu> | ||
40 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
41 | --- | 25 | --- |
42 | target/riscv/cpu.h | 4 ++++ | 26 | MAINTAINERS | 1 + |
43 | target/riscv/cpu.c | 40 ++++++++++++++++++++++++++++++++++++++++ | 27 | target/riscv/cpu.h | 3 ++ |
44 | 2 files changed, 44 insertions(+) | 28 | target/riscv/cpu.c | 1 + |
29 | target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++ | ||
30 | target/riscv/meson.build | 1 + | ||
31 | 5 files changed, 85 insertions(+) | ||
32 | create mode 100644 target/riscv/th_csr.c | ||
45 | 33 | ||
34 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/MAINTAINERS | ||
37 | +++ b/MAINTAINERS | ||
38 | @@ -XXX,XX +XXX,XX @@ L: qemu-riscv@nongnu.org | ||
39 | S: Supported | ||
40 | F: target/riscv/insn_trans/trans_xthead.c.inc | ||
41 | F: target/riscv/xthead*.decode | ||
42 | +F: target/riscv/th_* | ||
43 | F: disas/riscv-xthead* | ||
44 | |||
45 | RISC-V XVentanaCondOps extension | ||
46 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 46 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
47 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/target/riscv/cpu.h | 48 | --- a/target/riscv/cpu.h |
49 | +++ b/target/riscv/cpu.h | 49 | +++ b/target/riscv/cpu.h |
50 | @@ -XXX,XX +XXX,XX @@ | 50 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value, |
51 | 51 | uint8_t satp_mode_max_from_map(uint32_t map); | |
52 | #define RV(x) ((target_ulong)1 << (x - 'A')) | 52 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); |
53 | 53 | ||
54 | +/* | 54 | +/* Implemented in th_csr.c */ |
55 | + * Consider updating register_cpu_props() when adding | 55 | +void th_register_custom_csrs(RISCVCPU *cpu); |
56 | + * new MISA bits here. | 56 | + |
57 | + */ | 57 | #endif /* RISCV_CPU_H */ |
58 | #define RVI RV('I') | ||
59 | #define RVE RV('E') /* E and I are mutually exclusive */ | ||
60 | #define RVM RV('M') | ||
61 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 58 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
62 | index XXXXXXX..XXXXXXX 100644 | 59 | index XXXXXXX..XXXXXXX 100644 |
63 | --- a/target/riscv/cpu.c | 60 | --- a/target/riscv/cpu.c |
64 | +++ b/target/riscv/cpu.c | 61 | +++ b/target/riscv/cpu.c |
65 | @@ -XXX,XX +XXX,XX @@ static void rv64_sifive_u_cpu_init(Object *obj) | 62 | @@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj) |
66 | { | 63 | cpu->cfg.mvendorid = THEAD_VENDOR_ID; |
67 | CPURISCVState *env = &RISCV_CPU(obj)->env; | 64 | #ifndef CONFIG_USER_ONLY |
68 | set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); | 65 | set_satp_mode_max_supported(cpu, VM_1_10_SV39); |
69 | + register_cpu_props(DEVICE(obj)); | 66 | + th_register_custom_csrs(cpu); |
70 | set_priv_version(env, PRIV_VERSION_1_10_0); | 67 | #endif |
71 | } | 68 | |
72 | 69 | /* inherited from parent obj via riscv_cpu_init() */ | |
73 | @@ -XXX,XX +XXX,XX @@ static void rv64_sifive_e_cpu_init(Object *obj) | 70 | diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c |
74 | RISCVCPU *cpu = RISCV_CPU(obj); | 71 | new file mode 100644 |
75 | 72 | index XXXXXXX..XXXXXXX | |
76 | set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); | 73 | --- /dev/null |
77 | + register_cpu_props(DEVICE(obj)); | 74 | +++ b/target/riscv/th_csr.c |
78 | set_priv_version(env, PRIV_VERSION_1_10_0); | 75 | @@ -XXX,XX +XXX,XX @@ |
79 | cpu->cfg.mmu = false; | ||
80 | } | ||
81 | @@ -XXX,XX +XXX,XX @@ static void rv32_sifive_u_cpu_init(Object *obj) | ||
82 | { | ||
83 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
84 | set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); | ||
85 | + register_cpu_props(DEVICE(obj)); | ||
86 | set_priv_version(env, PRIV_VERSION_1_10_0); | ||
87 | } | ||
88 | |||
89 | @@ -XXX,XX +XXX,XX @@ static void rv32_sifive_e_cpu_init(Object *obj) | ||
90 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
91 | |||
92 | set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); | ||
93 | + register_cpu_props(DEVICE(obj)); | ||
94 | set_priv_version(env, PRIV_VERSION_1_10_0); | ||
95 | cpu->cfg.mmu = false; | ||
96 | } | ||
97 | @@ -XXX,XX +XXX,XX @@ static void rv32_ibex_cpu_init(Object *obj) | ||
98 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
99 | |||
100 | set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); | ||
101 | + register_cpu_props(DEVICE(obj)); | ||
102 | set_priv_version(env, PRIV_VERSION_1_11_0); | ||
103 | cpu->cfg.mmu = false; | ||
104 | cpu->cfg.epmp = true; | ||
105 | @@ -XXX,XX +XXX,XX @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) | ||
106 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
107 | |||
108 | set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); | ||
109 | + register_cpu_props(DEVICE(obj)); | ||
110 | set_priv_version(env, PRIV_VERSION_1_10_0); | ||
111 | cpu->cfg.mmu = false; | ||
112 | } | ||
113 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
114 | DEFINE_PROP_END_OF_LIST(), | ||
115 | }; | ||
116 | |||
117 | +/* | 76 | +/* |
118 | + * Register CPU props based on env.misa_ext. If a non-zero | 77 | + * T-Head-specific CSRs. |
119 | + * value was set, register only the required cpu->cfg.ext_* | 78 | + * |
120 | + * properties and leave. env.misa_ext = 0 means that we want | 79 | + * Copyright (c) 2024 VRULL GmbH |
121 | + * all the default properties to be registered. | 80 | + * |
81 | + * This program is free software; you can redistribute it and/or modify it | ||
82 | + * under the terms and conditions of the GNU General Public License, | ||
83 | + * version 2 or later, as published by the Free Software Foundation. | ||
84 | + * | ||
85 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
86 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
87 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
88 | + * more details. | ||
89 | + * | ||
90 | + * You should have received a copy of the GNU General Public License along with | ||
91 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
122 | + */ | 92 | + */ |
123 | static void register_cpu_props(DeviceState *dev) | ||
124 | { | ||
125 | + RISCVCPU *cpu = RISCV_CPU(OBJECT(dev)); | ||
126 | + uint32_t misa_ext = cpu->env.misa_ext; | ||
127 | Property *prop; | ||
128 | |||
129 | + /* | ||
130 | + * If misa_ext is not zero, set cfg properties now to | ||
131 | + * allow them to be read during riscv_cpu_realize() | ||
132 | + * later on. | ||
133 | + */ | ||
134 | + if (cpu->env.misa_ext != 0) { | ||
135 | + cpu->cfg.ext_i = misa_ext & RVI; | ||
136 | + cpu->cfg.ext_e = misa_ext & RVE; | ||
137 | + cpu->cfg.ext_m = misa_ext & RVM; | ||
138 | + cpu->cfg.ext_a = misa_ext & RVA; | ||
139 | + cpu->cfg.ext_f = misa_ext & RVF; | ||
140 | + cpu->cfg.ext_d = misa_ext & RVD; | ||
141 | + cpu->cfg.ext_v = misa_ext & RVV; | ||
142 | + cpu->cfg.ext_c = misa_ext & RVC; | ||
143 | + cpu->cfg.ext_s = misa_ext & RVS; | ||
144 | + cpu->cfg.ext_u = misa_ext & RVU; | ||
145 | + cpu->cfg.ext_h = misa_ext & RVH; | ||
146 | + cpu->cfg.ext_j = misa_ext & RVJ; | ||
147 | + | 93 | + |
148 | + /* | 94 | +#include "qemu/osdep.h" |
149 | + * We don't want to set the default riscv_cpu_extensions | 95 | +#include "cpu.h" |
150 | + * in this case. | 96 | +#include "cpu_vendorid.h" |
151 | + */ | 97 | + |
152 | + return; | 98 | +#define CSR_TH_SXSTATUS 0x5c0 |
99 | + | ||
100 | +/* TH_SXSTATUS bits */ | ||
101 | +#define TH_SXSTATUS_UCME BIT(16) | ||
102 | +#define TH_SXSTATUS_MAEE BIT(21) | ||
103 | +#define TH_SXSTATUS_THEADISAEE BIT(22) | ||
104 | + | ||
105 | +typedef struct { | ||
106 | + int csrno; | ||
107 | + int (*insertion_test)(RISCVCPU *cpu); | ||
108 | + riscv_csr_operations csr_ops; | ||
109 | +} riscv_csr; | ||
110 | + | ||
111 | +static RISCVException smode(CPURISCVState *env, int csrno) | ||
112 | +{ | ||
113 | + if (riscv_has_ext(env, RVS)) { | ||
114 | + return RISCV_EXCP_NONE; | ||
153 | + } | 115 | + } |
154 | + | 116 | + |
155 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | 117 | + return RISCV_EXCP_ILLEGAL_INST; |
156 | qdev_property_add_static(dev, prop); | 118 | +} |
157 | } | 119 | + |
120 | +static int test_thead_mvendorid(RISCVCPU *cpu) | ||
121 | +{ | ||
122 | + if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) { | ||
123 | + return -1; | ||
124 | + } | ||
125 | + | ||
126 | + return 0; | ||
127 | +} | ||
128 | + | ||
129 | +static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno, | ||
130 | + target_ulong *val) | ||
131 | +{ | ||
132 | + /* We don't set MAEE here, because QEMU does not implement MAEE. */ | ||
133 | + *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE; | ||
134 | + return RISCV_EXCP_NONE; | ||
135 | +} | ||
136 | + | ||
137 | +static riscv_csr th_csr_list[] = { | ||
138 | + { | ||
139 | + .csrno = CSR_TH_SXSTATUS, | ||
140 | + .insertion_test = test_thead_mvendorid, | ||
141 | + .csr_ops = { "th.sxstatus", smode, read_th_sxstatus } | ||
142 | + } | ||
143 | +}; | ||
144 | + | ||
145 | +void th_register_custom_csrs(RISCVCPU *cpu) | ||
146 | +{ | ||
147 | + for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) { | ||
148 | + int csrno = th_csr_list[i].csrno; | ||
149 | + riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops; | ||
150 | + if (!th_csr_list[i].insertion_test(cpu)) { | ||
151 | + riscv_set_csr_ops(csrno, csr_ops); | ||
152 | + } | ||
153 | + } | ||
154 | +} | ||
155 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
156 | index XXXXXXX..XXXXXXX 100644 | ||
157 | --- a/target/riscv/meson.build | ||
158 | +++ b/target/riscv/meson.build | ||
159 | @@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files( | ||
160 | 'monitor.c', | ||
161 | 'machine.c', | ||
162 | 'pmu.c', | ||
163 | + 'th_csr.c', | ||
164 | 'time_helper.c', | ||
165 | 'riscv-qmp-cmds.c', | ||
166 | )) | ||
158 | -- | 167 | -- |
159 | 2.39.0 | 168 | 2.45.1 |
169 | |||
170 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Some boards are duplicating the 'riscv_find_and_load_firmware' call | 3 | According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w |
4 | because the 32 and 64 bits images have different names. Create | 4 | instructions will be affected by Zvfhmin extension. |
5 | a function to handle this detail instead of hardcoding it in the boards. | 5 | And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the |
6 | conversions of | ||
6 | 7 | ||
7 | Ideally we would bake this logic inside riscv_find_and_load_firmware(), | 8 | * From 1*SEW(16/32) to 2*SEW(32/64) |
8 | or even create a riscv_load_default_firmware(), but at this moment we | 9 | * From 2*SEW(32/64) to 1*SEW(16/32) |
9 | cannot infer whether the machine is running 32 or 64 bits without | ||
10 | accessing RISCVHartArrayState, which in turn can't be accessed via the | ||
11 | common code from boot.c. In the end we would exchange 'firmware_name' | ||
12 | for a flag with riscv_is_32bit(), which isn't much better than what we | ||
13 | already have today. | ||
14 | 10 | ||
15 | Cc: Palmer Dabbelt <palmer@dabbelt.com> | 11 | Signed-off-by: Max Chou <max.chou@sifive.com> |
16 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Cc: qemu-stable <qemu-stable@nongnu.org> |
18 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | 14 | Message-ID: <20240322092600.1198921-2-max.chou@sifive.com> |
19 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
20 | Message-Id: <20221221182300.307900-6-dbarboza@ventanamicro.com> | ||
21 | Message-Id: <20221229091828.1945072-11-bmeng@tinylab.org> | ||
22 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
23 | --- | 16 | --- |
24 | include/hw/riscv/boot.h | 1 + | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++-- |
25 | hw/riscv/boot.c | 9 +++++++++ | 18 | 1 file changed, 18 insertions(+), 2 deletions(-) |
26 | hw/riscv/sifive_u.c | 11 ++++------- | ||
27 | hw/riscv/spike.c | 14 +++++--------- | ||
28 | hw/riscv/virt.c | 10 +++------- | ||
29 | 5 files changed, 22 insertions(+), 23 deletions(-) | ||
30 | 19 | ||
31 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h | 20 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
32 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/include/hw/riscv/boot.h | 22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
34 | +++ b/include/hw/riscv/boot.h | 23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
35 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_find_and_load_firmware(MachineState *machine, | 24 | @@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s) |
36 | const char *default_machine_firmware, | ||
37 | hwaddr firmware_load_addr, | ||
38 | symbol_fn_t sym_cb); | ||
39 | +const char *riscv_default_firmware_name(RISCVHartArrayState *harts); | ||
40 | target_ulong riscv_load_firmware(const char *firmware_filename, | ||
41 | hwaddr firmware_load_addr, | ||
42 | symbol_fn_t sym_cb); | ||
43 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/hw/riscv/boot.c | ||
46 | +++ b/hw/riscv/boot.c | ||
47 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_calc_kernel_start_addr(RISCVHartArrayState *harts, | ||
48 | } | 25 | } |
49 | } | 26 | } |
50 | 27 | ||
51 | +const char *riscv_default_firmware_name(RISCVHartArrayState *harts) | 28 | +static bool require_rvfmin(DisasContext *s) |
52 | +{ | 29 | +{ |
53 | + if (riscv_is_32bit(harts)) { | 30 | + if (s->mstatus_fs == EXT_STATUS_DISABLED) { |
54 | + return RISCV32_BIOS_BIN; | 31 | + return false; |
55 | + } | 32 | + } |
56 | + | 33 | + |
57 | + return RISCV64_BIOS_BIN; | 34 | + switch (s->sew) { |
35 | + case MO_16: | ||
36 | + return s->cfg_ptr->ext_zvfhmin; | ||
37 | + case MO_32: | ||
38 | + return s->cfg_ptr->ext_zve32f; | ||
39 | + default: | ||
40 | + return false; | ||
41 | + } | ||
58 | +} | 42 | +} |
59 | + | 43 | + |
60 | static char *riscv_find_firmware(const char *firmware_filename) | 44 | static bool require_scale_rvf(DisasContext *s) |
61 | { | 45 | { |
62 | char *filename; | 46 | if (s->mstatus_fs == EXT_STATUS_DISABLED) { |
63 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | 47 | @@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s) |
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/hw/riscv/sifive_u.c | ||
66 | +++ b/hw/riscv/sifive_u.c | ||
67 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
68 | MemoryRegion *flash0 = g_new(MemoryRegion, 1); | ||
69 | target_ulong start_addr = memmap[SIFIVE_U_DEV_DRAM].base; | ||
70 | target_ulong firmware_end_addr, kernel_start_addr; | ||
71 | + const char *firmware_name; | ||
72 | uint32_t start_addr_hi32 = 0x00000000; | ||
73 | int i; | ||
74 | uint32_t fdt_load_addr; | ||
75 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
76 | break; | ||
77 | } | 48 | } |
78 | 49 | ||
79 | - if (riscv_is_32bit(&s->soc.u_cpus)) { | 50 | switch (s->sew) { |
80 | - firmware_end_addr = riscv_find_and_load_firmware(machine, | 51 | - case MO_8: |
81 | - RISCV32_BIOS_BIN, start_addr, NULL); | 52 | - return s->cfg_ptr->ext_zvfhmin; |
82 | - } else { | 53 | case MO_16: |
83 | - firmware_end_addr = riscv_find_and_load_firmware(machine, | 54 | return s->cfg_ptr->ext_zve32f; |
84 | - RISCV64_BIOS_BIN, start_addr, NULL); | 55 | case MO_32: |
85 | - } | 56 | @@ -XXX,XX +XXX,XX @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a) |
86 | + firmware_name = riscv_default_firmware_name(&s->soc.u_cpus); | 57 | static bool opffv_widen_check(DisasContext *s, arg_rmr *a) |
87 | + firmware_end_addr = riscv_find_and_load_firmware(machine, firmware_name, | 58 | { |
88 | + start_addr, NULL); | 59 | return opfv_widen_check(s, a) && |
89 | 60 | + require_rvfmin(s) && | |
90 | if (machine->kernel_filename) { | 61 | require_scale_rvfmin(s) && |
91 | kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc.u_cpus, | 62 | (s->sew != MO_8); |
92 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 63 | } |
93 | index XXXXXXX..XXXXXXX 100644 | 64 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) |
94 | --- a/hw/riscv/spike.c | 65 | static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
95 | +++ b/hw/riscv/spike.c | 66 | { |
96 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | 67 | return opfv_narrow_check(s, a) && |
97 | MemoryRegion *system_memory = get_system_memory(); | 68 | + require_rvfmin(s) && |
98 | MemoryRegion *mask_rom = g_new(MemoryRegion, 1); | 69 | require_scale_rvfmin(s) && |
99 | target_ulong firmware_end_addr, kernel_start_addr; | 70 | (s->sew != MO_8); |
100 | + const char *firmware_name; | 71 | } |
101 | uint32_t fdt_load_addr; | ||
102 | uint64_t kernel_entry; | ||
103 | char *soc_name; | ||
104 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
105 | memory_region_add_subregion(system_memory, memmap[SPIKE_MROM].base, | ||
106 | mask_rom); | ||
107 | |||
108 | - if (riscv_is_32bit(&s->soc[0])) { | ||
109 | - firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
110 | - RISCV32_BIOS_BIN, memmap[SPIKE_DRAM].base, | ||
111 | - htif_symbol_callback); | ||
112 | - } else { | ||
113 | - firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
114 | - RISCV64_BIOS_BIN, memmap[SPIKE_DRAM].base, | ||
115 | - htif_symbol_callback); | ||
116 | - } | ||
117 | + firmware_name = riscv_default_firmware_name(&s->soc[0]); | ||
118 | + firmware_end_addr = riscv_find_and_load_firmware(machine, firmware_name, | ||
119 | + memmap[SPIKE_DRAM].base, | ||
120 | + htif_symbol_callback); | ||
121 | |||
122 | /* Load kernel */ | ||
123 | if (machine->kernel_filename) { | ||
124 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
125 | index XXXXXXX..XXXXXXX 100644 | ||
126 | --- a/hw/riscv/virt.c | ||
127 | +++ b/hw/riscv/virt.c | ||
128 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) | ||
129 | MachineState *machine = MACHINE(s); | ||
130 | target_ulong start_addr = memmap[VIRT_DRAM].base; | ||
131 | target_ulong firmware_end_addr, kernel_start_addr; | ||
132 | + const char *firmware_name = riscv_default_firmware_name(&s->soc[0]); | ||
133 | uint32_t fdt_load_addr; | ||
134 | uint64_t kernel_entry; | ||
135 | |||
136 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) | ||
137 | } | ||
138 | } | ||
139 | |||
140 | - if (riscv_is_32bit(&s->soc[0])) { | ||
141 | - firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
142 | - RISCV32_BIOS_BIN, start_addr, NULL); | ||
143 | - } else { | ||
144 | - firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
145 | - RISCV64_BIOS_BIN, start_addr, NULL); | ||
146 | - } | ||
147 | + firmware_end_addr = riscv_find_and_load_firmware(machine, firmware_name, | ||
148 | + start_addr, NULL); | ||
149 | |||
150 | /* | ||
151 | * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device | ||
152 | -- | 72 | -- |
153 | 2.39.0 | 73 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | 'cmdline' isn't being used. Remove it. | 3 | The require_scale_rvf function only checks the double width operator for |
4 | the vector floating point widen instructions, so most of the widen | ||
5 | checking functions need to add require_rvf for single width operator. | ||
4 | 6 | ||
5 | A MachineState pointer is being retrieved via a MACHINE() macro calling | 7 | The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width |
6 | qdev_get_machine(). Use MACHINE(s) instead to avoid calling qdev(). | 8 | integer to double width float, so the opfxv_widen_check function doesn’t |
9 | need require_rvf for the single width operator(integer). | ||
7 | 10 | ||
8 | 'mem_size' is being set as machine->ram_size by the caller. Retrieve it | 11 | Signed-off-by: Max Chou <max.chou@sifive.com> |
9 | via ms->ram_size. | 12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | 13 | Cc: qemu-stable <qemu-stable@nongnu.org> | |
11 | Cc: Palmer Dabbelt <palmer@dabbelt.com> | 14 | Message-ID: <20240322092600.1198921-3-max.chou@sifive.com> |
12 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | Message-Id: <20230111170948.316276-4-dbarboza@ventanamicro.com> | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 16 | --- |
18 | hw/riscv/sifive_u.c | 8 ++++---- | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++ |
19 | 1 file changed, 4 insertions(+), 4 deletions(-) | 18 | 1 file changed, 5 insertions(+) |
20 | 19 | ||
21 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | 20 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
22 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/riscv/sifive_u.c | 22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
24 | +++ b/hw/riscv/sifive_u.c | 23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
25 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry sifive_u_memmap[] = { | 24 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check) |
26 | #define GEM_REVISION 0x10070109 | 25 | static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) |
27 | |||
28 | static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, | ||
29 | - uint64_t mem_size, const char *cmdline, bool is_32_bit) | ||
30 | + bool is_32_bit) | ||
31 | { | 26 | { |
32 | - MachineState *ms = MACHINE(qdev_get_machine()); | 27 | return require_rvv(s) && |
33 | + MachineState *ms = MACHINE(s); | 28 | + require_rvf(s) && |
34 | + uint64_t mem_size = ms->ram_size; | 29 | require_scale_rvf(s) && |
35 | void *fdt; | 30 | (s->sew != MO_8) && |
36 | int cpu, fdt_size; | 31 | vext_check_isa_ill(s) && |
37 | uint32_t *cells; | 32 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check) |
38 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | 33 | static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) |
39 | qemu_allocate_irq(sifive_u_machine_reset, NULL, 0)); | 34 | { |
40 | 35 | return require_rvv(s) && | |
41 | /* create device tree */ | 36 | + require_rvf(s) && |
42 | - create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | 37 | require_scale_rvf(s) && |
43 | - riscv_is_32bit(&s->soc.u_cpus)); | 38 | (s->sew != MO_8) && |
44 | + create_fdt(s, memmap, riscv_is_32bit(&s->soc.u_cpus)); | 39 | vext_check_isa_ill(s) && |
45 | 40 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf) | |
46 | if (s->start_in_flash) { | 41 | static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) |
47 | /* | 42 | { |
43 | return require_rvv(s) && | ||
44 | + require_rvf(s) && | ||
45 | require_scale_rvf(s) && | ||
46 | (s->sew != MO_8) && | ||
47 | vext_check_isa_ill(s) && | ||
48 | @@ -XXX,XX +XXX,XX @@ GEN_OPFWV_WIDEN_TRANS(vfwsub_wv) | ||
49 | static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
50 | { | ||
51 | return require_rvv(s) && | ||
52 | + require_rvf(s) && | ||
53 | require_scale_rvf(s) && | ||
54 | (s->sew != MO_8) && | ||
55 | vext_check_isa_ill(s) && | ||
56 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_TRANS(vfredmin_vs, freduction_check) | ||
57 | static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) | ||
58 | { | ||
59 | return reduction_widen_check(s, a) && | ||
60 | + require_rvf(s) && | ||
61 | require_scale_rvf(s) && | ||
62 | (s->sew != MO_8); | ||
63 | } | ||
48 | -- | 64 | -- |
49 | 2.39.0 | 65 | 2.45.1 |
66 | |||
67 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The new helper always validates the contents of FRM, even | 3 | The opfv_narrow_check needs to check the single width float operator by |
4 | if the new rounding mode is not DYN. This is required by | 4 | require_rvf. |
5 | the vector unit. | ||
6 | 5 | ||
7 | Track whether we've validated FRM separately from whether | 6 | Signed-off-by: Max Chou <max.chou@sifive.com> |
8 | we've updated fp_status with a given rounding mode, so that | ||
9 | we can elide calls correctly. | ||
10 | |||
11 | This partially reverts d6c4d3f2a69 which attempted the to do | ||
12 | the same thing, but with two calls to gen_set_rm(), which is | ||
13 | both inefficient and tickles an assertion in decode_save_opc. | ||
14 | |||
15 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1441 | ||
16 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
17 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
18 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Cc: qemu-stable <qemu-stable@nongnu.org> |
19 | Message-Id: <20230115160657.3169274-2-richard.henderson@linaro.org> | 9 | Message-ID: <20240322092600.1198921-4-max.chou@sifive.com> |
20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
21 | --- | 11 | --- |
22 | target/riscv/helper.h | 1 + | 12 | target/riscv/insn_trans/trans_rvv.c.inc | 1 + |
23 | target/riscv/fpu_helper.c | 37 +++++++++++++++++++++++++ | 13 | 1 file changed, 1 insertion(+) |
24 | target/riscv/translate.c | 19 +++++++++++++ | ||
25 | target/riscv/insn_trans/trans_rvv.c.inc | 24 +++------------- | ||
26 | 4 files changed, 61 insertions(+), 20 deletions(-) | ||
27 | 14 | ||
28 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/target/riscv/helper.h | ||
31 | +++ b/target/riscv/helper.h | ||
32 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(raise_exception, noreturn, env, i32) | ||
33 | |||
34 | /* Floating Point - rounding mode */ | ||
35 | DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_WG, void, env, i32) | ||
36 | +DEF_HELPER_FLAGS_2(set_rounding_mode_chkfrm, TCG_CALL_NO_WG, void, env, i32) | ||
37 | DEF_HELPER_FLAGS_1(set_rod_rounding_mode, TCG_CALL_NO_WG, void, env) | ||
38 | |||
39 | /* Floating Point - fused */ | ||
40 | diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/target/riscv/fpu_helper.c | ||
43 | +++ b/target/riscv/fpu_helper.c | ||
44 | @@ -XXX,XX +XXX,XX @@ void helper_set_rounding_mode(CPURISCVState *env, uint32_t rm) | ||
45 | set_float_rounding_mode(softrm, &env->fp_status); | ||
46 | } | ||
47 | |||
48 | +void helper_set_rounding_mode_chkfrm(CPURISCVState *env, uint32_t rm) | ||
49 | +{ | ||
50 | + int softrm; | ||
51 | + | ||
52 | + /* Always validate frm, even if rm != DYN. */ | ||
53 | + if (unlikely(env->frm >= 5)) { | ||
54 | + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); | ||
55 | + } | ||
56 | + if (rm == RISCV_FRM_DYN) { | ||
57 | + rm = env->frm; | ||
58 | + } | ||
59 | + switch (rm) { | ||
60 | + case RISCV_FRM_RNE: | ||
61 | + softrm = float_round_nearest_even; | ||
62 | + break; | ||
63 | + case RISCV_FRM_RTZ: | ||
64 | + softrm = float_round_to_zero; | ||
65 | + break; | ||
66 | + case RISCV_FRM_RDN: | ||
67 | + softrm = float_round_down; | ||
68 | + break; | ||
69 | + case RISCV_FRM_RUP: | ||
70 | + softrm = float_round_up; | ||
71 | + break; | ||
72 | + case RISCV_FRM_RMM: | ||
73 | + softrm = float_round_ties_away; | ||
74 | + break; | ||
75 | + case RISCV_FRM_ROD: | ||
76 | + softrm = float_round_to_odd; | ||
77 | + break; | ||
78 | + default: | ||
79 | + g_assert_not_reached(); | ||
80 | + } | ||
81 | + | ||
82 | + set_float_rounding_mode(softrm, &env->fp_status); | ||
83 | +} | ||
84 | + | ||
85 | void helper_set_rod_rounding_mode(CPURISCVState *env) | ||
86 | { | ||
87 | set_float_rounding_mode(float_round_to_odd, &env->fp_status); | ||
88 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
89 | index XXXXXXX..XXXXXXX 100644 | ||
90 | --- a/target/riscv/translate.c | ||
91 | +++ b/target/riscv/translate.c | ||
92 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
93 | bool pm_base_enabled; | ||
94 | /* Use icount trigger for native debug */ | ||
95 | bool itrigger; | ||
96 | + /* FRM is known to contain a valid value. */ | ||
97 | + bool frm_valid; | ||
98 | /* TCG of the current insn_start */ | ||
99 | TCGOp *insn_start; | ||
100 | } DisasContext; | ||
101 | @@ -XXX,XX +XXX,XX @@ static void gen_set_rm(DisasContext *ctx, int rm) | ||
102 | gen_helper_set_rod_rounding_mode(cpu_env); | ||
103 | return; | ||
104 | } | ||
105 | + if (rm == RISCV_FRM_DYN) { | ||
106 | + /* The helper will return only if frm valid. */ | ||
107 | + ctx->frm_valid = true; | ||
108 | + } | ||
109 | |||
110 | /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ | ||
111 | decode_save_opc(ctx); | ||
112 | gen_helper_set_rounding_mode(cpu_env, tcg_constant_i32(rm)); | ||
113 | } | ||
114 | |||
115 | +static void gen_set_rm_chkfrm(DisasContext *ctx, int rm) | ||
116 | +{ | ||
117 | + if (ctx->frm == rm && ctx->frm_valid) { | ||
118 | + return; | ||
119 | + } | ||
120 | + ctx->frm = rm; | ||
121 | + ctx->frm_valid = true; | ||
122 | + | ||
123 | + /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ | ||
124 | + decode_save_opc(ctx); | ||
125 | + gen_helper_set_rounding_mode_chkfrm(cpu_env, tcg_constant_i32(rm)); | ||
126 | +} | ||
127 | + | ||
128 | static int ex_plus_1(DisasContext *ctx, int nf) | ||
129 | { | ||
130 | return nf + 1; | ||
131 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | 15 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
132 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
133 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | 17 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
134 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 18 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
135 | @@ -XXX,XX +XXX,XX @@ static bool do_opfv(DisasContext *s, arg_rmr *a, | 19 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
136 | int rm) | 20 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) |
137 | { | 21 | { |
138 | if (checkfn(s, a)) { | 22 | return opfv_narrow_check(s, a) && |
139 | - if (rm != RISCV_FRM_DYN) { | 23 | + require_rvf(s) && |
140 | - gen_set_rm(s, RISCV_FRM_DYN); | 24 | require_scale_rvf(s) && |
141 | - } | 25 | (s->sew != MO_8); |
142 | - | 26 | } |
143 | uint32_t data = 0; | ||
144 | TCGLabel *over = gen_new_label(); | ||
145 | - gen_set_rm(s, rm); | ||
146 | + gen_set_rm_chkfrm(s, rm); | ||
147 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
148 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
149 | |||
150 | @@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
151 | static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ | ||
152 | { \ | ||
153 | if (CHECK(s, a)) { \ | ||
154 | - if (FRM != RISCV_FRM_DYN) { \ | ||
155 | - gen_set_rm(s, RISCV_FRM_DYN); \ | ||
156 | - } \ | ||
157 | - \ | ||
158 | uint32_t data = 0; \ | ||
159 | static gen_helper_gvec_3_ptr * const fns[2] = { \ | ||
160 | gen_helper_##HELPER##_h, \ | ||
161 | gen_helper_##HELPER##_w, \ | ||
162 | }; \ | ||
163 | TCGLabel *over = gen_new_label(); \ | ||
164 | - gen_set_rm(s, FRM); \ | ||
165 | + gen_set_rm_chkfrm(s, FRM); \ | ||
166 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
167 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
168 | \ | ||
169 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) | ||
170 | static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ | ||
171 | { \ | ||
172 | if (CHECK(s, a)) { \ | ||
173 | - if (FRM != RISCV_FRM_DYN) { \ | ||
174 | - gen_set_rm(s, RISCV_FRM_DYN); \ | ||
175 | - } \ | ||
176 | - \ | ||
177 | uint32_t data = 0; \ | ||
178 | static gen_helper_gvec_3_ptr * const fns[2] = { \ | ||
179 | gen_helper_##HELPER##_h, \ | ||
180 | gen_helper_##HELPER##_w, \ | ||
181 | }; \ | ||
182 | TCGLabel *over = gen_new_label(); \ | ||
183 | - gen_set_rm(s, FRM); \ | ||
184 | + gen_set_rm_chkfrm(s, FRM); \ | ||
185 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
186 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
187 | \ | ||
188 | @@ -XXX,XX +XXX,XX @@ static bool opxfv_narrow_check(DisasContext *s, arg_rmr *a) | ||
189 | static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ | ||
190 | { \ | ||
191 | if (opxfv_narrow_check(s, a)) { \ | ||
192 | - if (FRM != RISCV_FRM_DYN) { \ | ||
193 | - gen_set_rm(s, RISCV_FRM_DYN); \ | ||
194 | - } \ | ||
195 | - \ | ||
196 | uint32_t data = 0; \ | ||
197 | static gen_helper_gvec_3_ptr * const fns[3] = { \ | ||
198 | gen_helper_##HELPER##_b, \ | ||
199 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ | ||
200 | gen_helper_##HELPER##_w, \ | ||
201 | }; \ | ||
202 | TCGLabel *over = gen_new_label(); \ | ||
203 | - gen_set_rm(s, FRM); \ | ||
204 | + gen_set_rm_chkfrm(s, FRM); \ | ||
205 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
206 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
207 | \ | ||
208 | -- | 27 | -- |
209 | 2.39.0 | 28 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Bin Meng <bmeng@tinylab.org> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | At present create_fdt() calls htif_uses_elf_symbols() to determine | 3 | If the checking functions check both the single and double width |
4 | whether to insert a <reg> property for the HTIF. This unfortunately | 4 | operators at the same time, then the single width operator checking |
5 | creates a hidden dependency to riscv_load_{firmware,kernel} that | 5 | functions (require_rvf[min]) will check whether the SEW is 8. |
6 | create_fdt() must be called after the ELF {firmware,kernel} image | ||
7 | has been loaded. | ||
8 | 6 | ||
9 | Decouple such dependency be adding a new parameter to create_fdt(), | 7 | Signed-off-by: Max Chou <max.chou@sifive.com> |
10 | whether custom HTIF base address is used. The flag will be set if | ||
11 | non ELF {firmware,kernel} image is given by user. | ||
12 | |||
13 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
15 | Message-Id: <20221229091828.1945072-13-bmeng@tinylab.org> | 9 | Cc: qemu-stable <qemu-stable@nongnu.org> |
10 | Message-ID: <20240322092600.1198921-5-max.chou@sifive.com> | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 12 | --- |
18 | include/hw/char/riscv_htif.h | 5 +-- | 13 | target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------ |
19 | hw/char/riscv_htif.c | 17 +++++----- | 14 | 1 file changed, 4 insertions(+), 12 deletions(-) |
20 | hw/riscv/spike.c | 61 ++++++++++++++++++++++++++++++------ | ||
21 | 3 files changed, 59 insertions(+), 24 deletions(-) | ||
22 | 15 | ||
23 | diff --git a/include/hw/char/riscv_htif.h b/include/hw/char/riscv_htif.h | 16 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
24 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/hw/char/riscv_htif.h | 18 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
26 | +++ b/include/hw/char/riscv_htif.h | 19 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
27 | @@ -XXX,XX +XXX,XX @@ typedef struct HTIFState { | 20 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) |
28 | void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value, | 21 | return require_rvv(s) && |
29 | uint64_t st_size); | 22 | require_rvf(s) && |
30 | 23 | require_scale_rvf(s) && | |
31 | -/* Check if HTIF uses ELF symbols */ | 24 | - (s->sew != MO_8) && |
32 | -bool htif_uses_elf_symbols(void); | 25 | vext_check_isa_ill(s) && |
33 | - | 26 | vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm); |
34 | /* legacy pre qom */ | 27 | } |
35 | HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr, | 28 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) |
36 | - uint64_t nonelf_base); | 29 | return require_rvv(s) && |
37 | + uint64_t nonelf_base, bool custom_base); | 30 | require_rvf(s) && |
38 | 31 | require_scale_rvf(s) && | |
39 | #endif | 32 | - (s->sew != MO_8) && |
40 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c | 33 | vext_check_isa_ill(s) && |
41 | index XXXXXXX..XXXXXXX 100644 | 34 | vext_check_ds(s, a->rd, a->rs2, a->vm); |
42 | --- a/hw/char/riscv_htif.c | 35 | } |
43 | +++ b/hw/char/riscv_htif.c | 36 | @@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) |
44 | @@ -XXX,XX +XXX,XX @@ | 37 | return require_rvv(s) && |
45 | #define PK_SYS_WRITE 64 | 38 | require_rvf(s) && |
46 | 39 | require_scale_rvf(s) && | |
47 | static uint64_t fromhost_addr, tohost_addr; | 40 | - (s->sew != MO_8) && |
48 | -static int address_symbol_set; | 41 | vext_check_isa_ill(s) && |
49 | 42 | vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm); | |
50 | void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value, | 43 | } |
51 | uint64_t st_size) | 44 | @@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) |
45 | return require_rvv(s) && | ||
46 | require_rvf(s) && | ||
47 | require_scale_rvf(s) && | ||
48 | - (s->sew != MO_8) && | ||
49 | vext_check_isa_ill(s) && | ||
50 | vext_check_dd(s, a->rd, a->rs2, a->vm); | ||
51 | } | ||
52 | @@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
52 | { | 53 | { |
53 | if (strcmp("fromhost", st_name) == 0) { | 54 | return opfv_widen_check(s, a) && |
54 | - address_symbol_set |= 1; | 55 | require_rvfmin(s) && |
55 | fromhost_addr = st_value; | 56 | - require_scale_rvfmin(s) && |
56 | if (st_size != 8) { | 57 | - (s->sew != MO_8); |
57 | error_report("HTIF fromhost must be 8 bytes"); | 58 | + require_scale_rvfmin(s); |
58 | exit(1); | 59 | } |
59 | } | 60 | |
60 | } else if (strcmp("tohost", st_name) == 0) { | 61 | #define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \ |
61 | - address_symbol_set |= 2; | 62 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
62 | tohost_addr = st_value; | ||
63 | if (st_size != 8) { | ||
64 | error_report("HTIF tohost must be 8 bytes"); | ||
65 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps htif_mm_ops = { | ||
66 | .write = htif_mm_write, | ||
67 | }; | ||
68 | |||
69 | -bool htif_uses_elf_symbols(void) | ||
70 | -{ | ||
71 | - return (address_symbol_set == 3) ? true : false; | ||
72 | -} | ||
73 | - | ||
74 | HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr, | ||
75 | - uint64_t nonelf_base) | ||
76 | + uint64_t nonelf_base, bool custom_base) | ||
77 | { | 63 | { |
78 | uint64_t base, size, tohost_offset, fromhost_offset; | 64 | return opfv_narrow_check(s, a) && |
79 | 65 | require_rvfmin(s) && | |
80 | - if (!htif_uses_elf_symbols()) { | 66 | - require_scale_rvfmin(s) && |
81 | + if (custom_base) { | 67 | - (s->sew != MO_8); |
82 | fromhost_addr = nonelf_base; | 68 | + require_scale_rvfmin(s); |
83 | tohost_addr = nonelf_base + 8; | 69 | } |
84 | + } else { | 70 | |
85 | + if (!fromhost_addr || !tohost_addr) { | 71 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) |
86 | + error_report("Invalid HTIF fromhost or tohost address"); | ||
87 | + exit(1); | ||
88 | + } | ||
89 | } | ||
90 | |||
91 | base = MIN(tohost_addr, fromhost_addr); | ||
92 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/hw/riscv/spike.c | ||
95 | +++ b/hw/riscv/spike.c | ||
96 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry spike_memmap[] = { | ||
97 | }; | ||
98 | |||
99 | static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | ||
100 | - uint64_t mem_size, const char *cmdline, bool is_32_bit) | ||
101 | + uint64_t mem_size, const char *cmdline, | ||
102 | + bool is_32_bit, bool htif_custom_base) | ||
103 | { | 72 | { |
104 | void *fdt; | 73 | return opfv_narrow_check(s, a) && |
105 | uint64_t addr, size; | 74 | require_rvf(s) && |
106 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | 75 | - require_scale_rvf(s) && |
107 | 76 | - (s->sew != MO_8); | |
108 | qemu_fdt_add_subnode(fdt, "/htif"); | 77 | + require_scale_rvf(s); |
109 | qemu_fdt_setprop_string(fdt, "/htif", "compatible", "ucb,htif0"); | ||
110 | - if (!htif_uses_elf_symbols()) { | ||
111 | + if (htif_custom_base) { | ||
112 | qemu_fdt_setprop_cells(fdt, "/htif", "reg", | ||
113 | 0x0, memmap[SPIKE_HTIF].base, 0x0, memmap[SPIKE_HTIF].size); | ||
114 | } | ||
115 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | ||
116 | } | ||
117 | } | 78 | } |
118 | 79 | ||
119 | +static bool spike_test_elf_image(char *filename) | 80 | #define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \ |
120 | +{ | 81 | @@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) |
121 | + Error *err = NULL; | ||
122 | + | ||
123 | + load_elf_hdr(filename, NULL, NULL, &err); | ||
124 | + if (err) { | ||
125 | + error_free(err); | ||
126 | + return false; | ||
127 | + } else { | ||
128 | + return true; | ||
129 | + } | ||
130 | +} | ||
131 | + | ||
132 | static void spike_board_init(MachineState *machine) | ||
133 | { | 82 | { |
134 | const MemMapEntry *memmap = spike_memmap; | 83 | return reduction_widen_check(s, a) && |
135 | SpikeState *s = SPIKE_MACHINE(machine); | 84 | require_rvf(s) && |
136 | MemoryRegion *system_memory = get_system_memory(); | 85 | - require_scale_rvf(s) && |
137 | MemoryRegion *mask_rom = g_new(MemoryRegion, 1); | 86 | - (s->sew != MO_8); |
138 | - target_ulong firmware_end_addr, kernel_start_addr; | 87 | + require_scale_rvf(s); |
139 | - const char *firmware_name; | ||
140 | + target_ulong firmware_end_addr = memmap[SPIKE_DRAM].base; | ||
141 | + target_ulong kernel_start_addr; | ||
142 | + char *firmware_name; | ||
143 | uint32_t fdt_load_addr; | ||
144 | uint64_t kernel_entry; | ||
145 | char *soc_name; | ||
146 | int i, base_hartid, hart_count; | ||
147 | + bool htif_custom_base = false; | ||
148 | |||
149 | /* Check socket count limit */ | ||
150 | if (SPIKE_SOCKETS_MAX < riscv_socket_count(machine)) { | ||
151 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
152 | memory_region_add_subregion(system_memory, memmap[SPIKE_MROM].base, | ||
153 | mask_rom); | ||
154 | |||
155 | - firmware_name = riscv_default_firmware_name(&s->soc[0]); | ||
156 | - firmware_end_addr = riscv_find_and_load_firmware(machine, firmware_name, | ||
157 | - memmap[SPIKE_DRAM].base, | ||
158 | - htif_symbol_callback); | ||
159 | + /* Find firmware */ | ||
160 | + firmware_name = riscv_find_firmware(machine->firmware, | ||
161 | + riscv_default_firmware_name(&s->soc[0])); | ||
162 | + | ||
163 | + /* | ||
164 | + * Test the given firmware or kernel file to see if it is an ELF image. | ||
165 | + * If it is an ELF, we assume it contains the symbols required for | ||
166 | + * the HTIF console, otherwise we fall back to use the custom base | ||
167 | + * passed from device tree for the HTIF console. | ||
168 | + */ | ||
169 | + if (!firmware_name && !machine->kernel_filename) { | ||
170 | + htif_custom_base = true; | ||
171 | + } else { | ||
172 | + if (firmware_name) { | ||
173 | + htif_custom_base = !spike_test_elf_image(firmware_name); | ||
174 | + } | ||
175 | + if (!htif_custom_base && machine->kernel_filename) { | ||
176 | + htif_custom_base = !spike_test_elf_image(machine->kernel_filename); | ||
177 | + } | ||
178 | + } | ||
179 | + | ||
180 | + /* Load firmware */ | ||
181 | + if (firmware_name) { | ||
182 | + firmware_end_addr = riscv_load_firmware(firmware_name, | ||
183 | + memmap[SPIKE_DRAM].base, | ||
184 | + htif_symbol_callback); | ||
185 | + g_free(firmware_name); | ||
186 | + } | ||
187 | |||
188 | /* Load kernel */ | ||
189 | if (machine->kernel_filename) { | ||
190 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
191 | |||
192 | /* Create device tree */ | ||
193 | create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | ||
194 | - riscv_is_32bit(&s->soc[0])); | ||
195 | + riscv_is_32bit(&s->soc[0]), htif_custom_base); | ||
196 | |||
197 | /* Load initrd */ | ||
198 | if (machine->kernel_filename && machine->initrd_filename) { | ||
199 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
200 | fdt_load_addr); | ||
201 | |||
202 | /* initialize HTIF using symbols found in load_kernel */ | ||
203 | - htif_mm_init(system_memory, serial_hd(0), memmap[SPIKE_HTIF].base); | ||
204 | + htif_mm_init(system_memory, serial_hd(0), memmap[SPIKE_HTIF].base, | ||
205 | + htif_custom_base); | ||
206 | } | 88 | } |
207 | 89 | ||
208 | static void spike_machine_instance_init(Object *obj) | 90 | GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check) |
209 | -- | 91 | -- |
210 | 2.39.0 | 92 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Commit 1c20d3ff6004 ("hw/riscv: virt: Add a machine done notifier") | 3 | raise_mmu_exception(), as is today, is prioritizing guest page faults by |
4 | moved the initialization of fw_cfg to the virt_machine_done() callback. | 4 | checking first if virt_enabled && !first_stage, and then considering the |
5 | regular inst/load/store faults. | ||
5 | 6 | ||
6 | Problem is that the validation of fw_cfg by devices such as ramfb is | 7 | There's no mention in the spec about guest page fault being a higher |
7 | done before the machine done notifier is called. Moving create_fw_cfg() | 8 | priority that PMP faults. In fact, privileged spec section 3.7.1 says: |
8 | to machine_done() results in QEMU failing to boot when using a ramfb | ||
9 | device: | ||
10 | 9 | ||
11 | ./qemu-system-riscv64 -machine virt -device ramfb -serial stdio | 10 | "Attempting to fetch an instruction from a PMP region that does not have |
12 | qemu-system-riscv64: -device ramfb: ramfb device requires fw_cfg with DMA | 11 | execute permissions raises an instruction access-fault exception. |
12 | Attempting to execute a load or load-reserved instruction which accesses | ||
13 | a physical address within a PMP region without read permissions raises a | ||
14 | load access-fault exception. Attempting to execute a store, | ||
15 | store-conditional, or AMO instruction which accesses a physical address | ||
16 | within a PMP region without write permissions raises a store | ||
17 | access-fault exception." | ||
13 | 18 | ||
14 | The fix is simple: move create_fw_cfg() config back to | 19 | So, in fact, we're doing it wrong - PMP faults should always be thrown, |
15 | virt_machine_init(). This happens to be the same way the ARM 'virt' | 20 | regardless of also being a first or second stage fault. |
16 | machine deals with fw_cfg (see machvirt_init() and virt_machine_done() | ||
17 | in hw/arm/virt.c), so we're keeping consistency with how other machines | ||
18 | handle this device. | ||
19 | 21 | ||
20 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1343 | 22 | The way riscv_cpu_tlb_fill() and get_physical_address() work is |
23 | adequate: a TRANSLATE_PMP_FAIL error is immediately reported and | ||
24 | reflected in the 'pmp_violation' flag. What we need is to change | ||
25 | raise_mmu_exception() to prioritize it. | ||
26 | |||
27 | Reported-by: Joseph Chan <jchan@ventanamicro.com> | ||
28 | Fixes: 82d53adfbb ("target/riscv/cpu_helper.c: Invalid exception on MMU translation stage") | ||
21 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 29 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
22 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 30 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
23 | Message-Id: <20230117132751.229738-2-dbarboza@ventanamicro.com> | 31 | Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com> |
32 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
25 | --- | 34 | --- |
26 | hw/riscv/virt.c | 14 +++++++------- | 35 | target/riscv/cpu_helper.c | 22 ++++++++++++---------- |
27 | 1 file changed, 7 insertions(+), 7 deletions(-) | 36 | 1 file changed, 12 insertions(+), 10 deletions(-) |
28 | 37 | ||
29 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 38 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
30 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/hw/riscv/virt.c | 40 | --- a/target/riscv/cpu_helper.c |
32 | +++ b/hw/riscv/virt.c | 41 | +++ b/target/riscv/cpu_helper.c |
33 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) | 42 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, |
34 | firmware_end_addr = riscv_find_and_load_firmware(machine, firmware_name, | 43 | |
35 | start_addr, NULL); | 44 | switch (access_type) { |
36 | 45 | case MMU_INST_FETCH: | |
37 | - /* | 46 | - if (env->virt_enabled && !first_stage) { |
38 | - * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device | 47 | + if (pmp_violation) { |
39 | - * tree cannot be altered and we get FDT_ERR_NOSPACE. | 48 | + cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT; |
40 | - */ | 49 | + } else if (env->virt_enabled && !first_stage) { |
41 | - s->fw_cfg = create_fw_cfg(machine); | 50 | cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT; |
42 | - rom_set_fw(s->fw_cfg); | 51 | } else { |
43 | - | 52 | - cs->exception_index = pmp_violation ? |
44 | if (drive_get(IF_PFLASH, 0, 1)) { | 53 | - RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT; |
45 | /* | 54 | + cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT; |
46 | * S-mode FW like EDK2 will be kept in second plash (unit 1). | 55 | } |
47 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | 56 | break; |
48 | memory_region_add_subregion(system_memory, memmap[VIRT_MROM].base, | 57 | case MMU_DATA_LOAD: |
49 | mask_rom); | 58 | - if (two_stage && !first_stage) { |
50 | 59 | + if (pmp_violation) { | |
51 | + /* | 60 | + cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT; |
52 | + * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the | 61 | + } else if (two_stage && !first_stage) { |
53 | + * device tree cannot be altered and we get FDT_ERR_NOSPACE. | 62 | cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT; |
54 | + */ | 63 | } else { |
55 | + s->fw_cfg = create_fw_cfg(machine); | 64 | - cs->exception_index = pmp_violation ? |
56 | + rom_set_fw(s->fw_cfg); | 65 | - RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT; |
57 | + | 66 | + cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT; |
58 | /* SiFive Test MMIO device */ | 67 | } |
59 | sifive_test_create(memmap[VIRT_TEST].base); | 68 | break; |
60 | 69 | case MMU_DATA_STORE: | |
70 | - if (two_stage && !first_stage) { | ||
71 | + if (pmp_violation) { | ||
72 | + cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT; | ||
73 | + } else if (two_stage && !first_stage) { | ||
74 | cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT; | ||
75 | } else { | ||
76 | - cs->exception_index = pmp_violation ? | ||
77 | - RISCV_EXCP_STORE_AMO_ACCESS_FAULT : | ||
78 | - RISCV_EXCP_STORE_PAGE_FAULT; | ||
79 | + cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT; | ||
80 | } | ||
81 | break; | ||
82 | default: | ||
61 | -- | 83 | -- |
62 | 2.39.0 | 84 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Bin Meng <bmeng@tinylab.org> | 1 | From: Alexei Filippov <alexei.filippov@syntacore.com> |
---|---|---|---|
2 | 2 | ||
3 | At present the HTIF proxy syscall is unsupported. On RV32, only | 3 | Previous patch fixed the PMP priority in raise_mmu_exception() but we're still |
4 | device 0 is supported so there is no console device for RV32. | 4 | setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage |
5 | The only way to implement console funtionality on RV32 is to | 5 | translation part, mtval2 will be set in case of successes 2 stage translation but |
6 | support the SYS_WRITE syscall. | 6 | failed pmp check. |
7 | 7 | ||
8 | With this commit, the Spike machine is able to boot the 32-bit | 8 | In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of |
9 | OpenSBI generic image. | 9 | riscv_cpu_tlb_fill(), as this was a guest-page-fault, but it didn't and mtval2 |
10 | should be zero, according to RISCV privileged spec sect. 9.4.4: When a guest | ||
11 | page-fault is taken into M-mode, mtval2 is written with either zero or guest | ||
12 | physical address that faulted, shifted by 2 bits. *For other traps, mtval2 | ||
13 | is set to zero...* | ||
10 | 14 | ||
11 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | 15 | Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com> |
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Message-Id: <20221229091828.1945072-8-bmeng@tinylab.org> | 18 | Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com> |
19 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 21 | --- |
17 | hw/char/riscv_htif.c | 17 ++++++++++++++++- | 22 | target/riscv/cpu_helper.c | 12 ++++++------ |
18 | 1 file changed, 16 insertions(+), 1 deletion(-) | 23 | 1 file changed, 6 insertions(+), 6 deletions(-) |
19 | 24 | ||
20 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c | 25 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
21 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/hw/char/riscv_htif.c | 27 | --- a/target/riscv/cpu_helper.c |
23 | +++ b/hw/char/riscv_htif.c | 28 | +++ b/target/riscv/cpu_helper.c |
24 | @@ -XXX,XX +XXX,XX @@ | 29 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, |
25 | #define HTIF_CONSOLE_CMD_GETC 0 | 30 | __func__, pa, ret, prot_pmp, tlb_size); |
26 | #define HTIF_CONSOLE_CMD_PUTC 1 | 31 | |
27 | 32 | prot &= prot_pmp; | |
28 | +/* PK system call number */ | 33 | - } |
29 | +#define PK_SYS_WRITE 64 | 34 | - |
30 | + | 35 | - if (ret != TRANSLATE_SUCCESS) { |
31 | static uint64_t fromhost_addr, tohost_addr; | 36 | + } else { |
32 | static int address_symbol_set; | 37 | /* |
33 | 38 | * Guest physical address translation failed, this is a HS | |
34 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) | 39 | * level exception |
35 | int exit_code = payload >> 1; | 40 | */ |
36 | exit(exit_code); | 41 | first_stage_error = false; |
37 | } else { | 42 | - env->guest_phys_fault_addr = (im_address | |
38 | - qemu_log_mask(LOG_UNIMP, "pk syscall proxy not supported\n"); | 43 | - (address & |
39 | + uint64_t syscall[8]; | 44 | - (TARGET_PAGE_SIZE - 1))) >> 2; |
40 | + cpu_physical_memory_read(payload, syscall, sizeof(syscall)); | 45 | + if (ret != TRANSLATE_PMP_FAIL) { |
41 | + if (syscall[0] == PK_SYS_WRITE && | 46 | + env->guest_phys_fault_addr = (im_address | |
42 | + syscall[1] == HTIF_DEV_CONSOLE && | 47 | + (address & |
43 | + syscall[3] == HTIF_CONSOLE_CMD_PUTC) { | 48 | + (TARGET_PAGE_SIZE - 1))) >> 2; |
44 | + uint8_t ch; | ||
45 | + cpu_physical_memory_read(syscall[2], &ch, 1); | ||
46 | + qemu_chr_fe_write(&s->chr, &ch, 1); | ||
47 | + resp = 0x100 | (uint8_t)payload; | ||
48 | + } else { | ||
49 | + qemu_log_mask(LOG_UNIMP, | ||
50 | + "pk syscall proxy not supported\n"); | ||
51 | + } | 49 | + } |
52 | } | 50 | } |
53 | } else { | 51 | } |
54 | qemu_log("HTIF device %d: unknown command\n", device); | 52 | } else { |
55 | -- | 53 | -- |
56 | 2.39.0 | 54 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Bin Meng <bmeng@tinylab.org> | 1 | From: Rob Bradford <rbradford@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | env->mhartid is currently casted to long before printed, which drops | 3 | This extension has now been ratified: |
4 | the high 32-bit for rv64 on 32-bit host. Use TARGET_FMT_lx instead. | 4 | https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be |
5 | removed. | ||
5 | 6 | ||
6 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | 7 | Since this is now a ratified extension add it to the list of extensions |
8 | included in the "max" CPU variant. | ||
9 | |||
10 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> | ||
11 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-Id: <20230109152655.340114-1-bmeng@tinylab.org> | 13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
14 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
15 | Message-ID: <20240514110217.22516-1-rbradford@rivosinc.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 17 | --- |
11 | target/riscv/cpu.c | 6 +++--- | 18 | target/riscv/cpu.c | 2 +- |
12 | 1 file changed, 3 insertions(+), 3 deletions(-) | 19 | target/riscv/tcg/tcg-cpu.c | 2 +- |
20 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
13 | 21 | ||
14 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 22 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
15 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/cpu.c | 24 | --- a/target/riscv/cpu.c |
17 | +++ b/target/riscv/cpu.c | 25 | +++ b/target/riscv/cpu.c |
18 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 26 | @@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = { |
19 | (env->priv_ver < isa_edata_arr[i].min_version)) { | 27 | MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"), |
20 | isa_ext_update_enabled(cpu, &isa_edata_arr[i], false); | 28 | MISA_EXT_INFO(RVV, "v", "Vector operations"), |
21 | #ifndef CONFIG_USER_ONLY | 29 | MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"), |
22 | - warn_report("disabling %s extension for hart 0x%lx because " | 30 | - MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") |
23 | - "privilege spec version does not match", | 31 | + MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)") |
24 | - isa_edata_arr[i].name, (unsigned long)env->mhartid); | 32 | }; |
25 | + warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx | 33 | |
26 | + " because privilege spec version does not match", | 34 | static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc) |
27 | + isa_edata_arr[i].name, env->mhartid); | 35 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
28 | #else | 36 | index XXXXXXX..XXXXXXX 100644 |
29 | warn_report("disabling %s extension because " | 37 | --- a/target/riscv/tcg/tcg-cpu.c |
30 | "privilege spec version does not match", | 38 | +++ b/target/riscv/tcg/tcg-cpu.c |
39 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) | ||
40 | const RISCVCPUMultiExtConfig *prop; | ||
41 | |||
42 | /* Enable RVG, RVJ and RVV that are disabled by default */ | ||
43 | - riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV); | ||
44 | + riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV); | ||
45 | |||
46 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
47 | isa_ext_update_enabled(cpu, prop->offset, true); | ||
31 | -- | 48 | -- |
32 | 2.39.0 | 49 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | There's no need to use a MachineState pointer and a fdt pointer now that | 3 | When running the instruction |
4 | all RISC-V machines are using the FDT from the MachineState. | ||
5 | 4 | ||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 5 | ``` |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 6 | cbo.flush 0(x0) |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | ``` |
9 | Message-Id: <20230111170948.316276-6-dbarboza@ventanamicro.com> | 8 | |
9 | QEMU would segfault. | ||
10 | |||
11 | The issue was in cpu_gpr[a->rs1] as QEMU does not have cpu_gpr[0] | ||
12 | allocated. | ||
13 | |||
14 | In order to fix this let's use the existing get_address() | ||
15 | helper. This also has the benefit of performing pointer mask | ||
16 | calculations on the address specified in rs1. | ||
17 | |||
18 | The pointer masking specificiation specifically states: | ||
19 | |||
20 | """ | ||
21 | Cache Management Operations: All instructions in Zicbom, Zicbop and Zicboz | ||
22 | """ | ||
23 | |||
24 | So this is the correct behaviour and we previously have been incorrectly | ||
25 | not masking the address. | ||
26 | |||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | Reported-by: Fabian Thomas <fabian.thomas@cispa.de> | ||
29 | Fixes: e05da09b7cfd ("target/riscv: implement Zicbom extension") | ||
30 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
31 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
32 | Message-ID: <20240514023910.301766-1-alistair.francis@wdc.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 34 | --- |
12 | include/hw/riscv/numa.h | 6 +++--- | 35 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++---- |
13 | hw/riscv/numa.c | 6 +++--- | 36 | 1 file changed, 12 insertions(+), 4 deletions(-) |
14 | hw/riscv/spike.c | 6 +++--- | ||
15 | hw/riscv/virt.c | 18 +++++++++--------- | ||
16 | 4 files changed, 18 insertions(+), 18 deletions(-) | ||
17 | 37 | ||
18 | diff --git a/include/hw/riscv/numa.h b/include/hw/riscv/numa.h | 38 | diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc |
19 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/include/hw/riscv/numa.h | 40 | --- a/target/riscv/insn_trans/trans_rvzicbo.c.inc |
21 | +++ b/include/hw/riscv/numa.h | 41 | +++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc |
22 | @@ -XXX,XX +XXX,XX @@ bool riscv_socket_check_hartids(const MachineState *ms, int socket_id); | 42 | @@ -XXX,XX +XXX,XX @@ |
23 | * @ms: pointer to machine state | 43 | static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a) |
24 | * @socket_id: socket index | 44 | { |
25 | * | 45 | REQUIRE_ZICBOM(ctx); |
26 | - * Write NUMA node-id FDT property for given FDT node | 46 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); |
27 | + * Write NUMA node-id FDT property in MachineState->fdt | 47 | + TCGv src = get_address(ctx, a->rs1, 0); |
28 | */ | 48 | + |
29 | -void riscv_socket_fdt_write_id(const MachineState *ms, void *fdt, | 49 | + gen_helper_cbo_clean_flush(tcg_env, src); |
30 | - const char *node_name, int socket_id); | 50 | return true; |
31 | +void riscv_socket_fdt_write_id(const MachineState *ms, const char *node_name, | ||
32 | + int socket_id); | ||
33 | |||
34 | /** | ||
35 | * riscv_socket_fdt_write_distance_matrix: | ||
36 | diff --git a/hw/riscv/numa.c b/hw/riscv/numa.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/hw/riscv/numa.c | ||
39 | +++ b/hw/riscv/numa.c | ||
40 | @@ -XXX,XX +XXX,XX @@ uint64_t riscv_socket_mem_size(const MachineState *ms, int socket_id) | ||
41 | ms->numa_state->nodes[socket_id].node_mem : 0; | ||
42 | } | 51 | } |
43 | 52 | ||
44 | -void riscv_socket_fdt_write_id(const MachineState *ms, void *fdt, | 53 | static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a) |
45 | - const char *node_name, int socket_id) | ||
46 | +void riscv_socket_fdt_write_id(const MachineState *ms, const char *node_name, | ||
47 | + int socket_id) | ||
48 | { | 54 | { |
49 | if (numa_enabled(ms)) { | 55 | REQUIRE_ZICBOM(ctx); |
50 | - qemu_fdt_setprop_cell(fdt, node_name, "numa-node-id", socket_id); | 56 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); |
51 | + qemu_fdt_setprop_cell(ms->fdt, node_name, "numa-node-id", socket_id); | 57 | + TCGv src = get_address(ctx, a->rs1, 0); |
52 | } | 58 | + |
59 | + gen_helper_cbo_clean_flush(tcg_env, src); | ||
60 | return true; | ||
53 | } | 61 | } |
54 | 62 | ||
55 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 63 | static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a) |
56 | index XXXXXXX..XXXXXXX 100644 | 64 | { |
57 | --- a/hw/riscv/spike.c | 65 | REQUIRE_ZICBOM(ctx); |
58 | +++ b/hw/riscv/spike.c | 66 | - gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]); |
59 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | 67 | + TCGv src = get_address(ctx, a->rs1, 0); |
60 | qemu_fdt_setprop_cell(fdt, cpu_name, "reg", | 68 | + |
61 | s->soc[socket].hartid_base + cpu); | 69 | + gen_helper_cbo_inval(tcg_env, src); |
62 | qemu_fdt_setprop_string(fdt, cpu_name, "device_type", "cpu"); | 70 | return true; |
63 | - riscv_socket_fdt_write_id(mc, fdt, cpu_name, socket); | ||
64 | + riscv_socket_fdt_write_id(mc, cpu_name, socket); | ||
65 | qemu_fdt_setprop_cell(fdt, cpu_name, "phandle", cpu_phandle); | ||
66 | |||
67 | intc_name = g_strdup_printf("%s/interrupt-controller", cpu_name); | ||
68 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | ||
69 | qemu_fdt_setprop_cells(fdt, mem_name, "reg", | ||
70 | addr >> 32, addr, size >> 32, size); | ||
71 | qemu_fdt_setprop_string(fdt, mem_name, "device_type", "memory"); | ||
72 | - riscv_socket_fdt_write_id(mc, fdt, mem_name, socket); | ||
73 | + riscv_socket_fdt_write_id(mc, mem_name, socket); | ||
74 | g_free(mem_name); | ||
75 | |||
76 | clint_addr = memmap[SPIKE_CLINT].base + | ||
77 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | ||
78 | 0x0, clint_addr, 0x0, memmap[SPIKE_CLINT].size); | ||
79 | qemu_fdt_setprop(fdt, clint_name, "interrupts-extended", | ||
80 | clint_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 4); | ||
81 | - riscv_socket_fdt_write_id(mc, fdt, clint_name, socket); | ||
82 | + riscv_socket_fdt_write_id(mc, clint_name, socket); | ||
83 | |||
84 | g_free(clint_name); | ||
85 | g_free(clint_cells); | ||
86 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/hw/riscv/virt.c | ||
89 | +++ b/hw/riscv/virt.c | ||
90 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, | ||
91 | qemu_fdt_setprop_cell(mc->fdt, cpu_name, "reg", | ||
92 | s->soc[socket].hartid_base + cpu); | ||
93 | qemu_fdt_setprop_string(mc->fdt, cpu_name, "device_type", "cpu"); | ||
94 | - riscv_socket_fdt_write_id(mc, mc->fdt, cpu_name, socket); | ||
95 | + riscv_socket_fdt_write_id(mc, cpu_name, socket); | ||
96 | qemu_fdt_setprop_cell(mc->fdt, cpu_name, "phandle", cpu_phandle); | ||
97 | |||
98 | intc_phandles[cpu] = (*phandle)++; | ||
99 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_memory(RISCVVirtState *s, | ||
100 | qemu_fdt_setprop_cells(mc->fdt, mem_name, "reg", | ||
101 | addr >> 32, addr, size >> 32, size); | ||
102 | qemu_fdt_setprop_string(mc->fdt, mem_name, "device_type", "memory"); | ||
103 | - riscv_socket_fdt_write_id(mc, mc->fdt, mem_name, socket); | ||
104 | + riscv_socket_fdt_write_id(mc, mem_name, socket); | ||
105 | g_free(mem_name); | ||
106 | } | 71 | } |
107 | 72 | ||
108 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_clint(RISCVVirtState *s, | 73 | static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a) |
109 | 0x0, clint_addr, 0x0, memmap[VIRT_CLINT].size); | 74 | { |
110 | qemu_fdt_setprop(mc->fdt, clint_name, "interrupts-extended", | 75 | REQUIRE_ZICBOZ(ctx); |
111 | clint_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 4); | 76 | - gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]); |
112 | - riscv_socket_fdt_write_id(mc, mc->fdt, clint_name, socket); | 77 | + TCGv src = get_address(ctx, a->rs1, 0); |
113 | + riscv_socket_fdt_write_id(mc, clint_name, socket); | 78 | + |
114 | g_free(clint_name); | 79 | + gen_helper_cbo_zero(tcg_env, src); |
115 | 80 | return true; | |
116 | g_free(clint_cells); | 81 | } |
117 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aclint(RISCVVirtState *s, | ||
118 | aclint_mswi_cells, aclint_cells_size); | ||
119 | qemu_fdt_setprop(mc->fdt, name, "interrupt-controller", NULL, 0); | ||
120 | qemu_fdt_setprop_cell(mc->fdt, name, "#interrupt-cells", 0); | ||
121 | - riscv_socket_fdt_write_id(mc, mc->fdt, name, socket); | ||
122 | + riscv_socket_fdt_write_id(mc, name, socket); | ||
123 | g_free(name); | ||
124 | } | ||
125 | |||
126 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aclint(RISCVVirtState *s, | ||
127 | 0x0, RISCV_ACLINT_DEFAULT_MTIME); | ||
128 | qemu_fdt_setprop(mc->fdt, name, "interrupts-extended", | ||
129 | aclint_mtimer_cells, aclint_cells_size); | ||
130 | - riscv_socket_fdt_write_id(mc, mc->fdt, name, socket); | ||
131 | + riscv_socket_fdt_write_id(mc, name, socket); | ||
132 | g_free(name); | ||
133 | |||
134 | if (s->aia_type != VIRT_AIA_TYPE_APLIC_IMSIC) { | ||
135 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aclint(RISCVVirtState *s, | ||
136 | aclint_sswi_cells, aclint_cells_size); | ||
137 | qemu_fdt_setprop(mc->fdt, name, "interrupt-controller", NULL, 0); | ||
138 | qemu_fdt_setprop_cell(mc->fdt, name, "#interrupt-cells", 0); | ||
139 | - riscv_socket_fdt_write_id(mc, mc->fdt, name, socket); | ||
140 | + riscv_socket_fdt_write_id(mc, name, socket); | ||
141 | g_free(name); | ||
142 | } | ||
143 | |||
144 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_plic(RISCVVirtState *s, | ||
145 | 0x0, plic_addr, 0x0, memmap[VIRT_PLIC].size); | ||
146 | qemu_fdt_setprop_cell(mc->fdt, plic_name, "riscv,ndev", | ||
147 | VIRT_IRQCHIP_NUM_SOURCES - 1); | ||
148 | - riscv_socket_fdt_write_id(mc, mc->fdt, plic_name, socket); | ||
149 | + riscv_socket_fdt_write_id(mc, plic_name, socket); | ||
150 | qemu_fdt_setprop_cell(mc->fdt, plic_name, "phandle", | ||
151 | plic_phandles[socket]); | ||
152 | |||
153 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aplic(RISCVVirtState *s, | ||
154 | aplic_s_phandle); | ||
155 | qemu_fdt_setprop_cells(mc->fdt, aplic_name, "riscv,delegate", | ||
156 | aplic_s_phandle, 0x1, VIRT_IRQCHIP_NUM_SOURCES); | ||
157 | - riscv_socket_fdt_write_id(mc, mc->fdt, aplic_name, socket); | ||
158 | + riscv_socket_fdt_write_id(mc, aplic_name, socket); | ||
159 | qemu_fdt_setprop_cell(mc->fdt, aplic_name, "phandle", aplic_m_phandle); | ||
160 | g_free(aplic_name); | ||
161 | |||
162 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aplic(RISCVVirtState *s, | ||
163 | 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_S].size); | ||
164 | qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,num-sources", | ||
165 | VIRT_IRQCHIP_NUM_SOURCES); | ||
166 | - riscv_socket_fdt_write_id(mc, mc->fdt, aplic_name, socket); | ||
167 | + riscv_socket_fdt_write_id(mc, aplic_name, socket); | ||
168 | qemu_fdt_setprop_cell(mc->fdt, aplic_name, "phandle", aplic_s_phandle); | ||
169 | |||
170 | if (!socket) { | ||
171 | -- | 82 | -- |
172 | 2.39.0 | 83 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | riscv_load_initrd() returns the initrd end addr while also writing a | 3 | In AIA spec, each hart (or each hart within a group) has a unique hart |
4 | 'start' var to mark the addr start. These informations are being used | 4 | number to locate the memory pages of interrupt files in the address |
5 | just to write the initrd FDT node. Every existing caller of | 5 | space. The number of bits required to represent any hart number is equal |
6 | riscv_load_initrd() is writing the FDT in the same manner. | 6 | to ceil(log2(hmax + 1)), where hmax is the largest hart number among |
7 | groups. | ||
7 | 8 | ||
8 | We can simplify things by writing the FDT inside riscv_load_initrd(), | 9 | However, if the largest hart number among groups is a power of 2, QEMU |
9 | sparing callers from having to manage start/end addrs to write the FDT | 10 | will pass an inaccurate hart-index-bit setting to Linux. For example, when |
10 | themselves. | 11 | the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient |
12 | to represent 4 harts, but we passes 3 to Linux. The code needs to be | ||
13 | updated to ensure accurate hart-index-bit settings. | ||
11 | 14 | ||
12 | An 'if (fdt)' check is already inserted at the end of the function | 15 | Additionally, a Linux patch[1] is necessary to correctly recover the hart |
13 | because we'll end up using it later on with other boards that doesn´t | 16 | index when the guest OS has only 1 hart, where the hart-index-bit is 0. |
14 | have a FDT. | ||
15 | 17 | ||
16 | Cc: Palmer Dabbelt <palmer@dabbelt.com> | 18 | [1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/ |
17 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 19 | |
18 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | 20 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
19 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 21 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
20 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 22 | Cc: qemu-stable <qemu-stable@nongnu.org> |
21 | Message-Id: <20230102115241.25733-7-dbarboza@ventanamicro.com> | 23 | Message-ID: <20240515091129.28116-1-yongxuan.wang@sifive.com> |
22 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
23 | --- | 25 | --- |
24 | include/hw/riscv/boot.h | 4 ++-- | 26 | target/riscv/kvm/kvm-cpu.c | 9 ++++++++- |
25 | hw/riscv/boot.c | 18 ++++++++++++------ | 27 | 1 file changed, 8 insertions(+), 1 deletion(-) |
26 | hw/riscv/microchip_pfsoc.c | 10 ++-------- | ||
27 | hw/riscv/sifive_u.c | 10 ++-------- | ||
28 | hw/riscv/spike.c | 10 ++-------- | ||
29 | hw/riscv/virt.c | 10 ++-------- | ||
30 | 6 files changed, 22 insertions(+), 40 deletions(-) | ||
31 | 28 | ||
32 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h | 29 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
33 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/include/hw/riscv/boot.h | 31 | --- a/target/riscv/kvm/kvm-cpu.c |
35 | +++ b/include/hw/riscv/boot.h | 32 | +++ b/target/riscv/kvm/kvm-cpu.c |
36 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_firmware(const char *firmware_filename, | 33 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, |
37 | target_ulong riscv_load_kernel(const char *kernel_filename, | ||
38 | target_ulong firmware_end_addr, | ||
39 | symbol_fn_t sym_cb); | ||
40 | -hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size, | ||
41 | - uint64_t kernel_entry, hwaddr *start); | ||
42 | +void riscv_load_initrd(const char *filename, uint64_t mem_size, | ||
43 | + uint64_t kernel_entry, void *fdt); | ||
44 | uint64_t riscv_load_fdt(hwaddr dram_start, uint64_t dram_size, void *fdt); | ||
45 | void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts, | ||
46 | hwaddr saddr, | ||
47 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/hw/riscv/boot.c | ||
50 | +++ b/hw/riscv/boot.c | ||
51 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_kernel(const char *kernel_filename, | ||
52 | exit(1); | ||
53 | } | ||
54 | |||
55 | -hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size, | ||
56 | - uint64_t kernel_entry, hwaddr *start) | ||
57 | +void riscv_load_initrd(const char *filename, uint64_t mem_size, | ||
58 | + uint64_t kernel_entry, void *fdt) | ||
59 | { | ||
60 | + hwaddr start, end; | ||
61 | ssize_t size; | ||
62 | |||
63 | g_assert(filename != NULL); | ||
64 | @@ -XXX,XX +XXX,XX @@ hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size, | ||
65 | * halfway into RAM, and for boards with 256MB of RAM or more we put | ||
66 | * the initrd at 128MB. | ||
67 | */ | ||
68 | - *start = kernel_entry + MIN(mem_size / 2, 128 * MiB); | ||
69 | + start = kernel_entry + MIN(mem_size / 2, 128 * MiB); | ||
70 | |||
71 | - size = load_ramdisk(filename, *start, mem_size - *start); | ||
72 | + size = load_ramdisk(filename, start, mem_size - start); | ||
73 | if (size == -1) { | ||
74 | - size = load_image_targphys(filename, *start, mem_size - *start); | ||
75 | + size = load_image_targphys(filename, start, mem_size - start); | ||
76 | if (size == -1) { | ||
77 | error_report("could not load ramdisk '%s'", filename); | ||
78 | exit(1); | ||
79 | } | 34 | } |
80 | } | 35 | } |
81 | 36 | ||
82 | - return *start + size; | 37 | - hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; |
83 | + /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */ | 38 | + |
84 | + if (fdt) { | 39 | + if (max_hart_per_socket > 1) { |
85 | + end = start + size; | 40 | + max_hart_per_socket--; |
86 | + qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start); | 41 | + hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; |
87 | + qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end); | 42 | + } else { |
43 | + hart_bits = 0; | ||
88 | + } | 44 | + } |
89 | } | 45 | + |
90 | 46 | ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | |
91 | uint64_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt) | 47 | KVM_DEV_RISCV_AIA_CONFIG_HART_BITS, |
92 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | 48 | &hart_bits, true, NULL); |
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/hw/riscv/microchip_pfsoc.c | ||
95 | +++ b/hw/riscv/microchip_pfsoc.c | ||
96 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) | ||
97 | kernel_start_addr, NULL); | ||
98 | |||
99 | if (machine->initrd_filename) { | ||
100 | - hwaddr start; | ||
101 | - hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
102 | - machine->ram_size, kernel_entry, | ||
103 | - &start); | ||
104 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", | ||
105 | - "linux,initrd-start", start); | ||
106 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", | ||
107 | - "linux,initrd-end", end); | ||
108 | + riscv_load_initrd(machine->initrd_filename, machine->ram_size, | ||
109 | + kernel_entry, machine->fdt); | ||
110 | } | ||
111 | |||
112 | if (machine->kernel_cmdline && *machine->kernel_cmdline) { | ||
113 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/hw/riscv/sifive_u.c | ||
116 | +++ b/hw/riscv/sifive_u.c | ||
117 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
118 | kernel_start_addr, NULL); | ||
119 | |||
120 | if (machine->initrd_filename) { | ||
121 | - hwaddr start; | ||
122 | - hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
123 | - machine->ram_size, kernel_entry, | ||
124 | - &start); | ||
125 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", | ||
126 | - "linux,initrd-start", start); | ||
127 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-end", | ||
128 | - end); | ||
129 | + riscv_load_initrd(machine->initrd_filename, machine->ram_size, | ||
130 | + kernel_entry, machine->fdt); | ||
131 | } | ||
132 | } else { | ||
133 | /* | ||
134 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
135 | index XXXXXXX..XXXXXXX 100644 | ||
136 | --- a/hw/riscv/spike.c | ||
137 | +++ b/hw/riscv/spike.c | ||
138 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
139 | htif_symbol_callback); | ||
140 | |||
141 | if (machine->initrd_filename) { | ||
142 | - hwaddr start; | ||
143 | - hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
144 | - machine->ram_size, kernel_entry, | ||
145 | - &start); | ||
146 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", | ||
147 | - "linux,initrd-start", start); | ||
148 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-end", | ||
149 | - end); | ||
150 | + riscv_load_initrd(machine->initrd_filename, machine->ram_size, | ||
151 | + kernel_entry, machine->fdt); | ||
152 | } | ||
153 | } else { | ||
154 | /* | ||
155 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
156 | index XXXXXXX..XXXXXXX 100644 | ||
157 | --- a/hw/riscv/virt.c | ||
158 | +++ b/hw/riscv/virt.c | ||
159 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) | ||
160 | kernel_start_addr, NULL); | ||
161 | |||
162 | if (machine->initrd_filename) { | ||
163 | - hwaddr start; | ||
164 | - hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
165 | - machine->ram_size, kernel_entry, | ||
166 | - &start); | ||
167 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", | ||
168 | - "linux,initrd-start", start); | ||
169 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-end", | ||
170 | - end); | ||
171 | + riscv_load_initrd(machine->initrd_filename, machine->ram_size, | ||
172 | + kernel_entry, machine->fdt); | ||
173 | } | ||
174 | } else { | ||
175 | /* | ||
176 | -- | 49 | -- |
177 | 2.39.0 | 50 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The MachineState object provides a 'fdt' pointer that is already being | 3 | Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length |
4 | used by other RISC-V machines, and it's also used by the 'dumpdtb' QMP | 4 | in bytes, when in this context we want 'reg_width' as the length in |
5 | command. | 5 | bits. |
6 | 6 | ||
7 | Remove the 'fdt' pointer from SiFiveUState and use MachineState::fdt | 7 | Fix 'reg_width' back to the value in bits like 7cb59921c05a |
8 | instead. | 8 | ("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set |
9 | beforehand. | ||
9 | 10 | ||
10 | Cc: Palmer Dabbelt <palmer@dabbelt.com> | 11 | While we're at it, rename 'reg_width' to 'bitsize' to provide a bit more |
12 | clarity about what the variable represents. 'bitsize' is also used in | ||
13 | riscv_gen_dynamic_csr_feature() with the same purpose, i.e. as an input to | ||
14 | gdb_feature_builder_append_reg(). | ||
15 | |||
16 | Cc: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
17 | Cc: Alex Bennée <alex.bennee@linaro.org> | ||
18 | Reported-by: Robin Dapp <rdapp.gcc@gmail.com> | ||
19 | Fixes: 33a24910ae ("target/riscv: Use GDBFeature for dynamic XML") | ||
11 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 20 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
12 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 21 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
22 | Acked-by: Alex Bennée <alex.bennee@linaro.org> | ||
23 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | 25 | Cc: qemu-stable <qemu-stable@nongnu.org> |
15 | Message-Id: <20230102115241.25733-4-dbarboza@ventanamicro.com> | 26 | Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com> |
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 28 | --- |
18 | include/hw/riscv/sifive_u.h | 3 --- | 29 | target/riscv/gdbstub.c | 6 +++--- |
19 | hw/riscv/sifive_u.c | 15 ++++++--------- | 30 | 1 file changed, 3 insertions(+), 3 deletions(-) |
20 | 2 files changed, 6 insertions(+), 12 deletions(-) | ||
21 | 31 | ||
22 | diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h | 32 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
23 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/riscv/sifive_u.h | 34 | --- a/target/riscv/gdbstub.c |
25 | +++ b/include/hw/riscv/sifive_u.h | 35 | +++ b/target/riscv/gdbstub.c |
26 | @@ -XXX,XX +XXX,XX @@ typedef struct SiFiveUState { | 36 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg) |
27 | /*< public >*/ | 37 | static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
28 | SiFiveUSoCState soc; | ||
29 | |||
30 | - void *fdt; | ||
31 | - int fdt_size; | ||
32 | - | ||
33 | bool start_in_flash; | ||
34 | uint32_t msel; | ||
35 | uint32_t serial; | ||
36 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/hw/riscv/sifive_u.c | ||
39 | +++ b/hw/riscv/sifive_u.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, | ||
41 | { | 38 | { |
42 | MachineState *ms = MACHINE(qdev_get_machine()); | 39 | RISCVCPU *cpu = RISCV_CPU(cs); |
43 | void *fdt; | 40 | - int reg_width = cpu->cfg.vlenb; |
44 | - int cpu; | 41 | + int bitsize = cpu->cfg.vlenb << 3; |
45 | + int cpu, fdt_size; | 42 | GDBFeatureBuilder builder; |
46 | uint32_t *cells; | 43 | int i; |
47 | char *nodename; | 44 | |
48 | uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle = 1; | 45 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
49 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, | 46 | |
50 | }; | 47 | /* First define types and totals in a whole VL */ |
51 | 48 | for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { | |
52 | if (ms->dtb) { | 49 | - int count = reg_width / vec_lanes[i].size; |
53 | - fdt = s->fdt = load_device_tree(ms->dtb, &s->fdt_size); | 50 | + int count = bitsize / vec_lanes[i].size; |
54 | + fdt = ms->fdt = load_device_tree(ms->dtb, &fdt_size); | 51 | gdb_feature_builder_append_tag( |
55 | if (!fdt) { | 52 | &builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>", |
56 | error_report("load_device_tree() failed"); | 53 | vec_lanes[i].id, vec_lanes[i].gdb_type, count); |
57 | exit(1); | 54 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
58 | } | 55 | /* Define vector registers */ |
59 | goto update_bootargs; | 56 | for (i = 0; i < 32; i++) { |
60 | } else { | 57 | gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i), |
61 | - fdt = s->fdt = create_device_tree(&s->fdt_size); | 58 | - reg_width, i, "riscv_vector", "vector"); |
62 | + fdt = ms->fdt = create_device_tree(&fdt_size); | 59 | + bitsize, i, "riscv_vector", "vector"); |
63 | if (!fdt) { | ||
64 | error_report("create_device_tree() failed"); | ||
65 | exit(1); | ||
66 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
67 | hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
68 | machine->ram_size, kernel_entry, | ||
69 | &start); | ||
70 | - qemu_fdt_setprop_cell(s->fdt, "/chosen", | ||
71 | + qemu_fdt_setprop_cell(machine->fdt, "/chosen", | ||
72 | "linux,initrd-start", start); | ||
73 | - qemu_fdt_setprop_cell(s->fdt, "/chosen", "linux,initrd-end", | ||
74 | + qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-end", | ||
75 | end); | ||
76 | } | ||
77 | } else { | ||
78 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
79 | |||
80 | /* Compute the fdt load address in dram */ | ||
81 | fdt_load_addr = riscv_load_fdt(memmap[SIFIVE_U_DEV_DRAM].base, | ||
82 | - machine->ram_size, s->fdt); | ||
83 | + machine->ram_size, machine->fdt); | ||
84 | if (!riscv_is_32bit(&s->soc.u_cpus)) { | ||
85 | start_addr_hi32 = (uint64_t)start_addr >> 32; | ||
86 | } | 60 | } |
87 | 61 | ||
88 | - /* Set machine->fdt for 'dumpdtb' QMP/HMP command */ | 62 | gdb_feature_builder_end(&builder); |
89 | - machine->fdt = s->fdt; | ||
90 | - | ||
91 | /* reset vector */ | ||
92 | uint32_t reset_vec[12] = { | ||
93 | s->msel, /* MSEL pin state */ | ||
94 | -- | 63 | -- |
95 | 2.39.0 | 64 | 2.45.1 |
65 | |||
66 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | The sifive_u, spike and virt machines are writing the 'bootargs' FDT | 3 | Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr |
4 | node during their respective create_fdt(). | 4 | CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr |
5 | CSRs are part of the disassembly. | ||
5 | 6 | ||
6 | Given that bootargs is written only when '-append' is used, and this | 7 | Reported-by: Eric DeVolder <eric_devolder@yahoo.com> |
7 | option is only allowed with the '-kernel' option, which in turn is | 8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
8 | already being check before executing riscv_load_kernel(), write | 9 | Fixes: ea10325917 ("RISC-V Disassembler") |
9 | 'bootargs' in the same code path as riscv_load_kernel(). | 10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | 11 | Cc: qemu-stable <qemu-stable@nongnu.org> | |
11 | Cc: Palmer Dabbelt <palmer@dabbelt.com> | 12 | Message-ID: <20240514051615.330979-1-alistair.francis@wdc.com> |
12 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Message-Id: <20230102115241.25733-8-dbarboza@ventanamicro.com> | ||
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 14 | --- |
19 | hw/riscv/sifive_u.c | 11 +++++------ | 15 | disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- |
20 | hw/riscv/spike.c | 9 +++++---- | 16 | 1 file changed, 64 insertions(+), 1 deletion(-) |
21 | hw/riscv/virt.c | 11 +++++------ | ||
22 | 3 files changed, 15 insertions(+), 16 deletions(-) | ||
23 | 17 | ||
24 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | 18 | diff --git a/disas/riscv.c b/disas/riscv.c |
25 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/riscv/sifive_u.c | 20 | --- a/disas/riscv.c |
27 | +++ b/hw/riscv/sifive_u.c | 21 | +++ b/disas/riscv.c |
28 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, | 22 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) |
29 | error_report("load_device_tree() failed"); | 23 | case 0x0383: return "mibound"; |
30 | exit(1); | 24 | case 0x0384: return "mdbase"; |
31 | } | 25 | case 0x0385: return "mdbound"; |
32 | - goto update_bootargs; | 26 | - case 0x03a0: return "pmpcfg3"; |
33 | } else { | 27 | + case 0x03a0: return "pmpcfg0"; |
34 | fdt = ms->fdt = create_device_tree(&fdt_size); | 28 | + case 0x03a1: return "pmpcfg1"; |
35 | if (!fdt) { | 29 | + case 0x03a2: return "pmpcfg2"; |
36 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, | 30 | + case 0x03a3: return "pmpcfg3"; |
37 | qemu_fdt_setprop_string(fdt, "/aliases", "serial0", nodename); | 31 | + case 0x03a4: return "pmpcfg4"; |
38 | 32 | + case 0x03a5: return "pmpcfg5"; | |
39 | g_free(nodename); | 33 | + case 0x03a6: return "pmpcfg6"; |
40 | - | 34 | + case 0x03a7: return "pmpcfg7"; |
41 | -update_bootargs: | 35 | + case 0x03a8: return "pmpcfg8"; |
42 | - if (cmdline && *cmdline) { | 36 | + case 0x03a9: return "pmpcfg9"; |
43 | - qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); | 37 | + case 0x03aa: return "pmpcfg10"; |
44 | - } | 38 | + case 0x03ab: return "pmpcfg11"; |
45 | } | 39 | + case 0x03ac: return "pmpcfg12"; |
46 | 40 | + case 0x03ad: return "pmpcfg13"; | |
47 | static void sifive_u_machine_reset(void *opaque, int n, int level) | 41 | + case 0x03ae: return "pmpcfg14"; |
48 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | 42 | + case 0x03af: return "pmpcfg15"; |
49 | riscv_load_initrd(machine->initrd_filename, machine->ram_size, | 43 | case 0x03b0: return "pmpaddr0"; |
50 | kernel_entry, machine->fdt); | 44 | case 0x03b1: return "pmpaddr1"; |
51 | } | 45 | case 0x03b2: return "pmpaddr2"; |
52 | + | 46 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) |
53 | + if (machine->kernel_cmdline && *machine->kernel_cmdline) { | 47 | case 0x03bd: return "pmpaddr13"; |
54 | + qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs", | 48 | case 0x03be: return "pmpaddr14"; |
55 | + machine->kernel_cmdline); | 49 | case 0x03bf: return "pmpaddr15"; |
56 | + } | 50 | + case 0x03c0: return "pmpaddr16"; |
57 | } else { | 51 | + case 0x03c1: return "pmpaddr17"; |
58 | /* | 52 | + case 0x03c2: return "pmpaddr18"; |
59 | * If dynamic firmware is used, it doesn't know where is the next mode | 53 | + case 0x03c3: return "pmpaddr19"; |
60 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 54 | + case 0x03c4: return "pmpaddr20"; |
61 | index XXXXXXX..XXXXXXX 100644 | 55 | + case 0x03c5: return "pmpaddr21"; |
62 | --- a/hw/riscv/spike.c | 56 | + case 0x03c6: return "pmpaddr22"; |
63 | +++ b/hw/riscv/spike.c | 57 | + case 0x03c7: return "pmpaddr23"; |
64 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | 58 | + case 0x03c8: return "pmpaddr24"; |
65 | 59 | + case 0x03c9: return "pmpaddr25"; | |
66 | qemu_fdt_add_subnode(fdt, "/chosen"); | 60 | + case 0x03ca: return "pmpaddr26"; |
67 | qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif"); | 61 | + case 0x03cb: return "pmpaddr27"; |
68 | - | 62 | + case 0x03cc: return "pmpaddr28"; |
69 | - if (cmdline && *cmdline) { | 63 | + case 0x03cd: return "pmpaddr29"; |
70 | - qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); | 64 | + case 0x03ce: return "pmpaddr30"; |
71 | - } | 65 | + case 0x03cf: return "pmpaddr31"; |
72 | } | 66 | + case 0x03d0: return "pmpaddr32"; |
73 | 67 | + case 0x03d1: return "pmpaddr33"; | |
74 | static bool spike_test_elf_image(char *filename) | 68 | + case 0x03d2: return "pmpaddr34"; |
75 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | 69 | + case 0x03d3: return "pmpaddr35"; |
76 | riscv_load_initrd(machine->initrd_filename, machine->ram_size, | 70 | + case 0x03d4: return "pmpaddr36"; |
77 | kernel_entry, machine->fdt); | 71 | + case 0x03d5: return "pmpaddr37"; |
78 | } | 72 | + case 0x03d6: return "pmpaddr38"; |
79 | + | 73 | + case 0x03d7: return "pmpaddr39"; |
80 | + if (machine->kernel_cmdline && *machine->kernel_cmdline) { | 74 | + case 0x03d8: return "pmpaddr40"; |
81 | + qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs", | 75 | + case 0x03d9: return "pmpaddr41"; |
82 | + machine->kernel_cmdline); | 76 | + case 0x03da: return "pmpaddr42"; |
83 | + } | 77 | + case 0x03db: return "pmpaddr43"; |
84 | } else { | 78 | + case 0x03dc: return "pmpaddr44"; |
85 | /* | 79 | + case 0x03dd: return "pmpaddr45"; |
86 | * If dynamic firmware is used, it doesn't know where is the next mode | 80 | + case 0x03de: return "pmpaddr46"; |
87 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 81 | + case 0x03df: return "pmpaddr47"; |
88 | index XXXXXXX..XXXXXXX 100644 | 82 | + case 0x03e0: return "pmpaddr48"; |
89 | --- a/hw/riscv/virt.c | 83 | + case 0x03e1: return "pmpaddr49"; |
90 | +++ b/hw/riscv/virt.c | 84 | + case 0x03e2: return "pmpaddr50"; |
91 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, | 85 | + case 0x03e3: return "pmpaddr51"; |
92 | error_report("load_device_tree() failed"); | 86 | + case 0x03e4: return "pmpaddr52"; |
93 | exit(1); | 87 | + case 0x03e5: return "pmpaddr53"; |
94 | } | 88 | + case 0x03e6: return "pmpaddr54"; |
95 | - goto update_bootargs; | 89 | + case 0x03e7: return "pmpaddr55"; |
96 | } else { | 90 | + case 0x03e8: return "pmpaddr56"; |
97 | mc->fdt = create_device_tree(&s->fdt_size); | 91 | + case 0x03e9: return "pmpaddr57"; |
98 | if (!mc->fdt) { | 92 | + case 0x03ea: return "pmpaddr58"; |
99 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, | 93 | + case 0x03eb: return "pmpaddr59"; |
100 | create_fdt_fw_cfg(s, memmap); | 94 | + case 0x03ec: return "pmpaddr60"; |
101 | create_fdt_pmu(s); | 95 | + case 0x03ed: return "pmpaddr61"; |
102 | 96 | + case 0x03ee: return "pmpaddr62"; | |
103 | -update_bootargs: | 97 | + case 0x03ef: return "pmpaddr63"; |
104 | - if (cmdline && *cmdline) { | 98 | case 0x0780: return "mtohost"; |
105 | - qemu_fdt_setprop_string(mc->fdt, "/chosen", "bootargs", cmdline); | 99 | case 0x0781: return "mfromhost"; |
106 | - } | 100 | case 0x0782: return "mreset"; |
107 | - | ||
108 | /* Pass seed to RNG */ | ||
109 | qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); | ||
110 | qemu_fdt_setprop(mc->fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed)); | ||
111 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) | ||
112 | riscv_load_initrd(machine->initrd_filename, machine->ram_size, | ||
113 | kernel_entry, machine->fdt); | ||
114 | } | ||
115 | + | ||
116 | + if (machine->kernel_cmdline && *machine->kernel_cmdline) { | ||
117 | + qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs", | ||
118 | + machine->kernel_cmdline); | ||
119 | + } | ||
120 | } else { | ||
121 | /* | ||
122 | * If dynamic firmware is used, it doesn't know where is the next mode | ||
123 | -- | 101 | -- |
124 | 2.39.0 | 102 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Bin Meng <bmeng@tinylab.org> | 1 | From: Yu-Ming Chang <yumin686@andestech.com> |
---|---|---|---|
2 | 2 | ||
3 | At present for some unknown reason the HTIF registers (fromhost & | 3 | Both CSRRS and CSRRC always read the addressed CSR and cause any read side |
4 | tohost) are defined in the RISC-V CPUArchState. It should really | 4 | effects regardless of rs1 and rd fields. Note that if rs1 specifies a register |
5 | be put in the HTIFState struct as it is only meaningful to HTIF. | 5 | holding a zero value other than x0, the instruction will still attempt to write |
6 | the unmodified value back to the CSR and will cause any attendant side effects. | ||
6 | 7 | ||
7 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | 8 | So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies |
8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 9 | a register holding a zero value, an illegal instruction exception should be |
10 | raised. | ||
11 | |||
12 | Signed-off-by: Yu-Ming Chang <yumin686@andestech.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-Id: <20221229091828.1945072-6-bmeng@tinylab.org> | 14 | Message-ID: <20240403070823.80897-1-yumin686@andestech.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 16 | --- |
13 | include/hw/char/riscv_htif.h | 8 ++++---- | 17 | target/riscv/cpu.h | 4 ++++ |
14 | target/riscv/cpu.h | 4 ---- | 18 | target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++---- |
15 | hw/char/riscv_htif.c | 35 +++++++++++++++++------------------ | 19 | target/riscv/op_helper.c | 6 ++--- |
16 | hw/riscv/spike.c | 3 +-- | 20 | 3 files changed, 53 insertions(+), 8 deletions(-) |
17 | target/riscv/machine.c | 6 ++---- | ||
18 | 5 files changed, 24 insertions(+), 32 deletions(-) | ||
19 | 21 | ||
20 | diff --git a/include/hw/char/riscv_htif.h b/include/hw/char/riscv_htif.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/include/hw/char/riscv_htif.h | ||
23 | +++ b/include/hw/char/riscv_htif.h | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | #include "chardev/char.h" | ||
26 | #include "chardev/char-fe.h" | ||
27 | #include "exec/memory.h" | ||
28 | -#include "target/riscv/cpu.h" | ||
29 | |||
30 | #define TYPE_HTIF_UART "riscv.htif.uart" | ||
31 | |||
32 | @@ -XXX,XX +XXX,XX @@ typedef struct HTIFState { | ||
33 | int allow_tohost; | ||
34 | int fromhost_inprogress; | ||
35 | |||
36 | + uint64_t tohost; | ||
37 | + uint64_t fromhost; | ||
38 | hwaddr tohost_offset; | ||
39 | hwaddr fromhost_offset; | ||
40 | MemoryRegion mmio; | ||
41 | |||
42 | - CPURISCVState *env; | ||
43 | CharBackend chr; | ||
44 | uint64_t pending_read; | ||
45 | } HTIFState; | ||
46 | @@ -XXX,XX +XXX,XX @@ void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value, | ||
47 | bool htif_uses_elf_symbols(void); | ||
48 | |||
49 | /* legacy pre qom */ | ||
50 | -HTIFState *htif_mm_init(MemoryRegion *address_space, CPURISCVState *env, | ||
51 | - Chardev *chr, uint64_t nonelf_base); | ||
52 | +HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr, | ||
53 | + uint64_t nonelf_base); | ||
54 | |||
55 | #endif | ||
56 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 22 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
57 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
58 | --- a/target/riscv/cpu.h | 24 | --- a/target/riscv/cpu.h |
59 | +++ b/target/riscv/cpu.h | 25 | +++ b/target/riscv/cpu.h |
60 | @@ -XXX,XX +XXX,XX @@ struct CPUArchState { | 26 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, |
61 | target_ulong sscratch; | 27 | void riscv_cpu_update_mask(CPURISCVState *env); |
62 | target_ulong mscratch; | 28 | bool riscv_cpu_is_32bit(RISCVCPU *cpu); |
63 | 29 | ||
64 | - /* temporary htif regs */ | 30 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
65 | - uint64_t mfromhost; | 31 | + target_ulong *ret_value); |
66 | - uint64_t mtohost; | 32 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, |
67 | - | 33 | target_ulong *ret_value, |
68 | /* Sstc CSRs */ | 34 | target_ulong new_value, target_ulong write_mask); |
69 | uint64_t stimecmp; | 35 | @@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, |
70 | 36 | target_ulong new_value, | |
71 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c | 37 | target_ulong write_mask); |
38 | |||
39 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, | ||
40 | + Int128 *ret_value); | ||
41 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, | ||
42 | Int128 *ret_value, | ||
43 | Int128 new_value, Int128 write_mask); | ||
44 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
72 | index XXXXXXX..XXXXXXX 100644 | 45 | index XXXXXXX..XXXXXXX 100644 |
73 | --- a/hw/char/riscv_htif.c | 46 | --- a/target/riscv/csr.c |
74 | +++ b/hw/char/riscv_htif.c | 47 | +++ b/target/riscv/csr.c |
75 | @@ -XXX,XX +XXX,XX @@ static void htif_recv(void *opaque, const uint8_t *buf, int size) | 48 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
76 | uint64_t val_written = s->pending_read; | 49 | |
77 | uint64_t resp = 0x100 | *buf; | 50 | static inline RISCVException riscv_csrrw_check(CPURISCVState *env, |
78 | 51 | int csrno, | |
79 | - s->env->mfromhost = (val_written >> 48 << 48) | (resp << 16 >> 16); | 52 | - bool write_mask) |
80 | + s->fromhost = (val_written >> 48 << 48) | (resp << 16 >> 16); | 53 | + bool write) |
54 | { | ||
55 | /* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */ | ||
56 | bool read_only = get_field(csrno, 0xC00) == 3; | ||
57 | @@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, | ||
58 | } | ||
59 | |||
60 | /* read / write check */ | ||
61 | - if (write_mask && read_only) { | ||
62 | + if (write && read_only) { | ||
63 | return RISCV_EXCP_ILLEGAL_INST; | ||
64 | } | ||
65 | |||
66 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do64(CPURISCVState *env, int csrno, | ||
67 | return RISCV_EXCP_NONE; | ||
81 | } | 68 | } |
82 | 69 | ||
83 | /* | 70 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
84 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) | 71 | + target_ulong *ret_value) |
85 | if (cmd == HTIF_CONSOLE_CMD_GETC) { | 72 | +{ |
86 | /* this should be a queue, but not yet implemented as such */ | 73 | + RISCVException ret = riscv_csrrw_check(env, csrno, false); |
87 | s->pending_read = val_written; | 74 | + if (ret != RISCV_EXCP_NONE) { |
88 | - s->env->mtohost = 0; /* clear to indicate we read */ | 75 | + return ret; |
89 | + s->tohost = 0; /* clear to indicate we read */ | 76 | + } |
90 | return; | 77 | + |
91 | } else if (cmd == HTIF_CONSOLE_CMD_PUTC) { | 78 | + return riscv_csrrw_do64(env, csrno, ret_value, 0, 0); |
92 | qemu_chr_fe_write(&s->chr, (uint8_t *)&payload, 1); | 79 | +} |
93 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) | 80 | + |
94 | * HTIF needs protocol documentation and a more complete state machine. | 81 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, |
95 | * | 82 | target_ulong *ret_value, |
96 | * while (!s->fromhost_inprogress && | 83 | target_ulong new_value, target_ulong write_mask) |
97 | - * s->env->mfromhost != 0x0) { | 84 | { |
98 | + * s->fromhost != 0x0) { | 85 | - RISCVException ret = riscv_csrrw_check(env, csrno, write_mask); |
99 | * } | 86 | + RISCVException ret = riscv_csrrw_check(env, csrno, true); |
100 | */ | 87 | if (ret != RISCV_EXCP_NONE) { |
101 | - s->env->mfromhost = (val_written >> 48 << 48) | (resp << 16 >> 16); | 88 | return ret; |
102 | - s->env->mtohost = 0; /* clear to indicate we read */ | 89 | } |
103 | + s->fromhost = (val_written >> 48 << 48) | (resp << 16 >> 16); | 90 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno, |
104 | + s->tohost = 0; /* clear to indicate we read */ | 91 | return RISCV_EXCP_NONE; |
105 | } | 92 | } |
106 | 93 | ||
107 | #define TOHOST_OFFSET1 (s->tohost_offset) | 94 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, |
108 | @@ -XXX,XX +XXX,XX @@ static uint64_t htif_mm_read(void *opaque, hwaddr addr, unsigned size) | 95 | + Int128 *ret_value) |
96 | +{ | ||
97 | + RISCVException ret; | ||
98 | + | ||
99 | + ret = riscv_csrrw_check(env, csrno, false); | ||
100 | + if (ret != RISCV_EXCP_NONE) { | ||
101 | + return ret; | ||
102 | + } | ||
103 | + | ||
104 | + if (csr_ops[csrno].read128) { | ||
105 | + return riscv_csrrw_do128(env, csrno, ret_value, | ||
106 | + int128_zero(), int128_zero()); | ||
107 | + } | ||
108 | + | ||
109 | + /* | ||
110 | + * Fall back to 64-bit version for now, if the 128-bit alternative isn't | ||
111 | + * at all defined. | ||
112 | + * Note, some CSRs don't need to extend to MXLEN (64 upper bits non | ||
113 | + * significant), for those, this fallback is correctly handling the | ||
114 | + * accesses | ||
115 | + */ | ||
116 | + target_ulong old_value; | ||
117 | + ret = riscv_csrrw_do64(env, csrno, &old_value, | ||
118 | + (target_ulong)0, | ||
119 | + (target_ulong)0); | ||
120 | + if (ret == RISCV_EXCP_NONE && ret_value) { | ||
121 | + *ret_value = int128_make64(old_value); | ||
122 | + } | ||
123 | + return ret; | ||
124 | +} | ||
125 | + | ||
126 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, | ||
127 | Int128 *ret_value, | ||
128 | Int128 new_value, Int128 write_mask) | ||
109 | { | 129 | { |
110 | HTIFState *s = opaque; | 130 | RISCVException ret; |
111 | if (addr == TOHOST_OFFSET1) { | 131 | |
112 | - return s->env->mtohost & 0xFFFFFFFF; | 132 | - ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask)); |
113 | + return s->tohost & 0xFFFFFFFF; | 133 | + ret = riscv_csrrw_check(env, csrno, true); |
114 | } else if (addr == TOHOST_OFFSET2) { | 134 | if (ret != RISCV_EXCP_NONE) { |
115 | - return (s->env->mtohost >> 32) & 0xFFFFFFFF; | 135 | return ret; |
116 | + return (s->tohost >> 32) & 0xFFFFFFFF; | 136 | } |
117 | } else if (addr == FROMHOST_OFFSET1) { | 137 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c |
118 | - return s->env->mfromhost & 0xFFFFFFFF; | 138 | index XXXXXXX..XXXXXXX 100644 |
119 | + return s->fromhost & 0xFFFFFFFF; | 139 | --- a/target/riscv/op_helper.c |
120 | } else if (addr == FROMHOST_OFFSET2) { | 140 | +++ b/target/riscv/op_helper.c |
121 | - return (s->env->mfromhost >> 32) & 0xFFFFFFFF; | 141 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr) |
122 | + return (s->fromhost >> 32) & 0xFFFFFFFF; | 142 | } |
123 | } else { | 143 | |
124 | qemu_log("Invalid htif read: address %016" PRIx64 "\n", | 144 | target_ulong val = 0; |
125 | (uint64_t)addr); | 145 | - RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0); |
126 | @@ -XXX,XX +XXX,XX @@ static void htif_mm_write(void *opaque, hwaddr addr, | 146 | + RISCVException ret = riscv_csrr(env, csr, &val); |
147 | |||
148 | if (ret != RISCV_EXCP_NONE) { | ||
149 | riscv_raise_exception(env, ret, GETPC()); | ||
150 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, int csr, | ||
151 | target_ulong helper_csrr_i128(CPURISCVState *env, int csr) | ||
127 | { | 152 | { |
128 | HTIFState *s = opaque; | 153 | Int128 rv = int128_zero(); |
129 | if (addr == TOHOST_OFFSET1) { | 154 | - RISCVException ret = riscv_csrrw_i128(env, csr, &rv, |
130 | - if (s->env->mtohost == 0x0) { | 155 | - int128_zero(), |
131 | + if (s->tohost == 0x0) { | 156 | - int128_zero()); |
132 | s->allow_tohost = 1; | 157 | + RISCVException ret = riscv_csrr_i128(env, csr, &rv); |
133 | - s->env->mtohost = value & 0xFFFFFFFF; | 158 | |
134 | + s->tohost = value & 0xFFFFFFFF; | 159 | if (ret != RISCV_EXCP_NONE) { |
135 | } else { | 160 | riscv_raise_exception(env, ret, GETPC()); |
136 | s->allow_tohost = 0; | ||
137 | } | ||
138 | } else if (addr == TOHOST_OFFSET2) { | ||
139 | if (s->allow_tohost) { | ||
140 | - s->env->mtohost |= value << 32; | ||
141 | - htif_handle_tohost_write(s, s->env->mtohost); | ||
142 | + s->tohost |= value << 32; | ||
143 | + htif_handle_tohost_write(s, s->tohost); | ||
144 | } | ||
145 | } else if (addr == FROMHOST_OFFSET1) { | ||
146 | s->fromhost_inprogress = 1; | ||
147 | - s->env->mfromhost = value & 0xFFFFFFFF; | ||
148 | + s->fromhost = value & 0xFFFFFFFF; | ||
149 | } else if (addr == FROMHOST_OFFSET2) { | ||
150 | - s->env->mfromhost |= value << 32; | ||
151 | + s->fromhost |= value << 32; | ||
152 | s->fromhost_inprogress = 0; | ||
153 | } else { | ||
154 | qemu_log("Invalid htif write: address %016" PRIx64 "\n", | ||
155 | @@ -XXX,XX +XXX,XX @@ bool htif_uses_elf_symbols(void) | ||
156 | return (address_symbol_set == 3) ? true : false; | ||
157 | } | ||
158 | |||
159 | -HTIFState *htif_mm_init(MemoryRegion *address_space, CPURISCVState *env, | ||
160 | - Chardev *chr, uint64_t nonelf_base) | ||
161 | +HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr, | ||
162 | + uint64_t nonelf_base) | ||
163 | { | ||
164 | uint64_t base, size, tohost_offset, fromhost_offset; | ||
165 | |||
166 | @@ -XXX,XX +XXX,XX @@ HTIFState *htif_mm_init(MemoryRegion *address_space, CPURISCVState *env, | ||
167 | fromhost_offset = fromhost_addr - base; | ||
168 | |||
169 | HTIFState *s = g_new0(HTIFState, 1); | ||
170 | - s->env = env; | ||
171 | s->tohost_offset = tohost_offset; | ||
172 | s->fromhost_offset = fromhost_offset; | ||
173 | s->pending_read = 0; | ||
174 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
175 | index XXXXXXX..XXXXXXX 100644 | ||
176 | --- a/hw/riscv/spike.c | ||
177 | +++ b/hw/riscv/spike.c | ||
178 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
179 | fdt_load_addr); | ||
180 | |||
181 | /* initialize HTIF using symbols found in load_kernel */ | ||
182 | - htif_mm_init(system_memory, &s->soc[0].harts[0].env, | ||
183 | - serial_hd(0), memmap[SPIKE_HTIF].base); | ||
184 | + htif_mm_init(system_memory, serial_hd(0), memmap[SPIKE_HTIF].base); | ||
185 | } | ||
186 | |||
187 | static void spike_machine_instance_init(Object *obj) | ||
188 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | ||
189 | index XXXXXXX..XXXXXXX 100644 | ||
190 | --- a/target/riscv/machine.c | ||
191 | +++ b/target/riscv/machine.c | ||
192 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pmu_ctr_state = { | ||
193 | |||
194 | const VMStateDescription vmstate_riscv_cpu = { | ||
195 | .name = "cpu", | ||
196 | - .version_id = 5, | ||
197 | - .minimum_version_id = 5, | ||
198 | + .version_id = 6, | ||
199 | + .minimum_version_id = 6, | ||
200 | .post_load = riscv_cpu_post_load, | ||
201 | .fields = (VMStateField[]) { | ||
202 | VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32), | ||
203 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = { | ||
204 | VMSTATE_UINTTL_ARRAY(env.mhpmeventh_val, RISCVCPU, RV_MAX_MHPMEVENTS), | ||
205 | VMSTATE_UINTTL(env.sscratch, RISCVCPU), | ||
206 | VMSTATE_UINTTL(env.mscratch, RISCVCPU), | ||
207 | - VMSTATE_UINT64(env.mfromhost, RISCVCPU), | ||
208 | - VMSTATE_UINT64(env.mtohost, RISCVCPU), | ||
209 | VMSTATE_UINT64(env.stimecmp, RISCVCPU), | ||
210 | |||
211 | VMSTATE_END_OF_LIST() | ||
212 | -- | 161 | -- |
213 | 2.39.0 | 162 | 2.45.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bin Meng <bmeng@tinylab.org> | ||
2 | 1 | ||
3 | There are forward declarations for 'vmstate_htif' and 'htif_io_ops' | ||
4 | in riscv_htif.h however there are no definitions in the C codes. | ||
5 | |||
6 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-Id: <20221229091828.1945072-7-bmeng@tinylab.org> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | include/hw/char/riscv_htif.h | 3 --- | ||
13 | 1 file changed, 3 deletions(-) | ||
14 | |||
15 | diff --git a/include/hw/char/riscv_htif.h b/include/hw/char/riscv_htif.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/hw/char/riscv_htif.h | ||
18 | +++ b/include/hw/char/riscv_htif.h | ||
19 | @@ -XXX,XX +XXX,XX @@ typedef struct HTIFState { | ||
20 | uint64_t pending_read; | ||
21 | } HTIFState; | ||
22 | |||
23 | -extern const VMStateDescription vmstate_htif; | ||
24 | -extern const MemoryRegionOps htif_io_ops; | ||
25 | - | ||
26 | /* HTIF symbol callback */ | ||
27 | void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value, | ||
28 | uint64_t st_size); | ||
29 | -- | ||
30 | 2.39.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bin Meng <bmeng@tinylab.org> | ||
2 | 1 | ||
3 | Spike machine now supports OpenSBI plain binary bios image, so the | ||
4 | comments are no longer valid. | ||
5 | |||
6 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-Id: <20221229091828.1945072-9-bmeng@tinylab.org> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | hw/riscv/spike.c | 5 ----- | ||
13 | 1 file changed, 5 deletions(-) | ||
14 | |||
15 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/riscv/spike.c | ||
18 | +++ b/hw/riscv/spike.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
20 | memory_region_add_subregion(system_memory, memmap[SPIKE_MROM].base, | ||
21 | mask_rom); | ||
22 | |||
23 | - /* | ||
24 | - * Not like other RISC-V machines that use plain binary bios images, | ||
25 | - * keeping ELF files here was intentional because BIN files don't work | ||
26 | - * for the Spike machine as HTIF emulation depends on ELF parsing. | ||
27 | - */ | ||
28 | if (riscv_is_32bit(&s->soc[0])) { | ||
29 | firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
30 | RISCV32_BIOS_BIN, memmap[SPIKE_DRAM].base, | ||
31 | -- | ||
32 | 2.39.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bin Meng <bmeng@tinylab.org> | ||
2 | 1 | ||
3 | Rename previous riscv_find_firmware() to riscv_find_bios(), and | ||
4 | introduce a new riscv_find_firmware() to implement the first half | ||
5 | part of the work done in riscv_find_and_load_firmware(). | ||
6 | |||
7 | This new API is helpful for machine that wants to know the final | ||
8 | chosen firmware file name but does not want to load it. | ||
9 | |||
10 | Signed-off-by: Bin Meng <bmeng@tinylab.org> | ||
11 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Message-Id: <20221229091828.1945072-12-bmeng@tinylab.org> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | include/hw/riscv/boot.h | 2 ++ | ||
17 | hw/riscv/boot.c | 39 +++++++++++++++++++++++++-------------- | ||
18 | 2 files changed, 27 insertions(+), 14 deletions(-) | ||
19 | |||
20 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/include/hw/riscv/boot.h | ||
23 | +++ b/include/hw/riscv/boot.h | ||
24 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_find_and_load_firmware(MachineState *machine, | ||
25 | hwaddr firmware_load_addr, | ||
26 | symbol_fn_t sym_cb); | ||
27 | const char *riscv_default_firmware_name(RISCVHartArrayState *harts); | ||
28 | +char *riscv_find_firmware(const char *firmware_filename, | ||
29 | + const char *default_machine_firmware); | ||
30 | target_ulong riscv_load_firmware(const char *firmware_filename, | ||
31 | hwaddr firmware_load_addr, | ||
32 | symbol_fn_t sym_cb); | ||
33 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/hw/riscv/boot.c | ||
36 | +++ b/hw/riscv/boot.c | ||
37 | @@ -XXX,XX +XXX,XX @@ const char *riscv_default_firmware_name(RISCVHartArrayState *harts) | ||
38 | return RISCV64_BIOS_BIN; | ||
39 | } | ||
40 | |||
41 | -static char *riscv_find_firmware(const char *firmware_filename) | ||
42 | +static char *riscv_find_bios(const char *bios_filename) | ||
43 | { | ||
44 | char *filename; | ||
45 | |||
46 | - filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware_filename); | ||
47 | + filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_filename); | ||
48 | if (filename == NULL) { | ||
49 | if (!qtest_enabled()) { | ||
50 | /* | ||
51 | @@ -XXX,XX +XXX,XX @@ static char *riscv_find_firmware(const char *firmware_filename) | ||
52 | * running QEMU test will complain hence let's suppress the error | ||
53 | * report for QEMU testing. | ||
54 | */ | ||
55 | - error_report("Unable to load the RISC-V firmware \"%s\"", | ||
56 | - firmware_filename); | ||
57 | + error_report("Unable to find the RISC-V BIOS \"%s\"", | ||
58 | + bios_filename); | ||
59 | exit(1); | ||
60 | } | ||
61 | } | ||
62 | @@ -XXX,XX +XXX,XX @@ static char *riscv_find_firmware(const char *firmware_filename) | ||
63 | return filename; | ||
64 | } | ||
65 | |||
66 | -target_ulong riscv_find_and_load_firmware(MachineState *machine, | ||
67 | - const char *default_machine_firmware, | ||
68 | - hwaddr firmware_load_addr, | ||
69 | - symbol_fn_t sym_cb) | ||
70 | +char *riscv_find_firmware(const char *firmware_filename, | ||
71 | + const char *default_machine_firmware) | ||
72 | { | ||
73 | - char *firmware_filename = NULL; | ||
74 | - target_ulong firmware_end_addr = firmware_load_addr; | ||
75 | + char *filename = NULL; | ||
76 | |||
77 | - if ((!machine->firmware) || (!strcmp(machine->firmware, "default"))) { | ||
78 | + if ((!firmware_filename) || (!strcmp(firmware_filename, "default"))) { | ||
79 | /* | ||
80 | * The user didn't specify -bios, or has specified "-bios default". | ||
81 | * That means we are going to load the OpenSBI binary included in | ||
82 | * the QEMU source. | ||
83 | */ | ||
84 | - firmware_filename = riscv_find_firmware(default_machine_firmware); | ||
85 | - } else if (strcmp(machine->firmware, "none")) { | ||
86 | - firmware_filename = riscv_find_firmware(machine->firmware); | ||
87 | + filename = riscv_find_bios(default_machine_firmware); | ||
88 | + } else if (strcmp(firmware_filename, "none")) { | ||
89 | + filename = riscv_find_bios(firmware_filename); | ||
90 | } | ||
91 | |||
92 | + return filename; | ||
93 | +} | ||
94 | + | ||
95 | +target_ulong riscv_find_and_load_firmware(MachineState *machine, | ||
96 | + const char *default_machine_firmware, | ||
97 | + hwaddr firmware_load_addr, | ||
98 | + symbol_fn_t sym_cb) | ||
99 | +{ | ||
100 | + char *firmware_filename; | ||
101 | + target_ulong firmware_end_addr = firmware_load_addr; | ||
102 | + | ||
103 | + firmware_filename = riscv_find_firmware(machine->firmware, | ||
104 | + default_machine_firmware); | ||
105 | + | ||
106 | if (firmware_filename) { | ||
107 | /* If not "none" load the firmware */ | ||
108 | firmware_end_addr = riscv_load_firmware(firmware_filename, | ||
109 | -- | ||
110 | 2.39.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | This test is used to do a quick sanity check to ensure that we're able | ||
4 | to run the existing QEMU FW image. | ||
5 | |||
6 | 'sifive_u', 'spike' and 'virt' riscv64 machines, and 'sifive_u' and | ||
7 | 'virt' 32 bit machines are able to run the default RISCV64_BIOS_BIN | | ||
8 | RISCV32_BIOS_BIN firmware with minimal options. | ||
9 | |||
10 | The riscv32 'spike' machine isn't bootable at this moment, requiring an | ||
11 | OpenSBI fix [1] and QEMU side changes [2]. We could just leave at that | ||
12 | or add a 'skip' test to remind us about it. To work as a reminder that | ||
13 | we have a riscv32 'spike' test that should be enabled as soon as OpenSBI | ||
14 | QEMU rom receives the fix, we're adding a 'skip' test: | ||
15 | |||
16 | (06/18) tests/avocado/riscv_opensbi.py:RiscvOpenSBI.test_riscv32_spike: | ||
17 | SKIP: requires OpenSBI fix to work | ||
18 | |||
19 | [1] https://patchwork.ozlabs.org/project/opensbi/patch/20221226033603.1860569-1-bmeng@tinylab.org/ | ||
20 | [2] https://patchwork.ozlabs.org/project/qemu-devel/list/?series=334159 | ||
21 | |||
22 | Cc: Cleber Rosa <crosa@redhat.com> | ||
23 | Cc: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
24 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | ||
25 | Tested-by: Bin Meng <bmeng@tinylab.org> | ||
26 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
27 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
28 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
29 | Message-Id: <20230102115241.25733-2-dbarboza@ventanamicro.com> | ||
30 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
31 | --- | ||
32 | tests/avocado/riscv_opensbi.py | 65 ++++++++++++++++++++++++++++++++++ | ||
33 | 1 file changed, 65 insertions(+) | ||
34 | create mode 100644 tests/avocado/riscv_opensbi.py | ||
35 | |||
36 | diff --git a/tests/avocado/riscv_opensbi.py b/tests/avocado/riscv_opensbi.py | ||
37 | new file mode 100644 | ||
38 | index XXXXXXX..XXXXXXX | ||
39 | --- /dev/null | ||
40 | +++ b/tests/avocado/riscv_opensbi.py | ||
41 | @@ -XXX,XX +XXX,XX @@ | ||
42 | +# OpenSBI boot test for RISC-V machines | ||
43 | +# | ||
44 | +# Copyright (c) 2022, Ventana Micro | ||
45 | +# | ||
46 | +# This work is licensed under the terms of the GNU GPL, version 2 or | ||
47 | +# later. See the COPYING file in the top-level directory. | ||
48 | + | ||
49 | +from avocado_qemu import QemuSystemTest | ||
50 | +from avocado import skip | ||
51 | +from avocado_qemu import wait_for_console_pattern | ||
52 | + | ||
53 | +class RiscvOpenSBI(QemuSystemTest): | ||
54 | + """ | ||
55 | + :avocado: tags=accel:tcg | ||
56 | + """ | ||
57 | + timeout = 5 | ||
58 | + | ||
59 | + def boot_opensbi(self): | ||
60 | + self.vm.set_console() | ||
61 | + self.vm.launch() | ||
62 | + wait_for_console_pattern(self, 'Platform Name') | ||
63 | + wait_for_console_pattern(self, 'Boot HART MEDELEG') | ||
64 | + | ||
65 | + @skip("requires OpenSBI fix to work") | ||
66 | + def test_riscv32_spike(self): | ||
67 | + """ | ||
68 | + :avocado: tags=arch:riscv32 | ||
69 | + :avocado: tags=machine:spike | ||
70 | + """ | ||
71 | + self.boot_opensbi() | ||
72 | + | ||
73 | + def test_riscv64_spike(self): | ||
74 | + """ | ||
75 | + :avocado: tags=arch:riscv64 | ||
76 | + :avocado: tags=machine:spike | ||
77 | + """ | ||
78 | + self.boot_opensbi() | ||
79 | + | ||
80 | + def test_riscv32_sifive_u(self): | ||
81 | + """ | ||
82 | + :avocado: tags=arch:riscv32 | ||
83 | + :avocado: tags=machine:sifive_u | ||
84 | + """ | ||
85 | + self.boot_opensbi() | ||
86 | + | ||
87 | + def test_riscv64_sifive_u(self): | ||
88 | + """ | ||
89 | + :avocado: tags=arch:riscv64 | ||
90 | + :avocado: tags=machine:sifive_u | ||
91 | + """ | ||
92 | + self.boot_opensbi() | ||
93 | + | ||
94 | + def test_riscv32_virt(self): | ||
95 | + """ | ||
96 | + :avocado: tags=arch:riscv32 | ||
97 | + :avocado: tags=machine:virt | ||
98 | + """ | ||
99 | + self.boot_opensbi() | ||
100 | + | ||
101 | + def test_riscv64_virt(self): | ||
102 | + """ | ||
103 | + :avocado: tags=arch:riscv64 | ||
104 | + :avocado: tags=machine:virt | ||
105 | + """ | ||
106 | + self.boot_opensbi() | ||
107 | -- | ||
108 | 2.39.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | riscv_load_firmware(), riscv_load_initrd() and riscv_load_kernel() works | ||
4 | under the assumption that a 'filename' parameter is always not NULL. | ||
5 | |||
6 | This is currently the case since all callers of these functions are | ||
7 | checking for NULL before calling them. Add an g_assert() to make sure | ||
8 | that a NULL value in these cases are to be considered a bug. | ||
9 | |||
10 | Suggested-by: Alex Bennée <alex.bennee@linaro.org> | ||
11 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
12 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | ||
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | Message-Id: <20230102115241.25733-5-dbarboza@ventanamicro.com> | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | --- | ||
18 | hw/riscv/boot.c | 6 ++++++ | ||
19 | 1 file changed, 6 insertions(+) | ||
20 | |||
21 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/hw/riscv/boot.c | ||
24 | +++ b/hw/riscv/boot.c | ||
25 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_firmware(const char *firmware_filename, | ||
26 | uint64_t firmware_entry, firmware_end; | ||
27 | ssize_t firmware_size; | ||
28 | |||
29 | + g_assert(firmware_filename != NULL); | ||
30 | + | ||
31 | if (load_elf_ram_sym(firmware_filename, NULL, NULL, NULL, | ||
32 | &firmware_entry, NULL, &firmware_end, NULL, | ||
33 | 0, EM_RISCV, 1, 0, NULL, true, sym_cb) > 0) { | ||
34 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_kernel(const char *kernel_filename, | ||
35 | { | ||
36 | uint64_t kernel_load_base, kernel_entry; | ||
37 | |||
38 | + g_assert(kernel_filename != NULL); | ||
39 | + | ||
40 | /* | ||
41 | * NB: Use low address not ELF entry point to ensure that the fw_dynamic | ||
42 | * behaviour when loading an ELF matches the fw_payload, fw_jump and BBL | ||
43 | @@ -XXX,XX +XXX,XX @@ hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size, | ||
44 | { | ||
45 | ssize_t size; | ||
46 | |||
47 | + g_assert(filename != NULL); | ||
48 | + | ||
49 | /* | ||
50 | * We want to put the initrd far enough into RAM that when the | ||
51 | * kernel is uncompressed it will not clobber the initrd. However | ||
52 | -- | ||
53 | 2.39.0 | diff view generated by jsdifflib |