riscv-to-apply queue
Subsystems (2)
From: Alistair Francis <[email protected]>
The following changes since commit da5006445a92bb7801f54a93452fac63ca2f634c:
Merge tag 'python-pull-request' of https://gitlab.com/jsnow/qemu into staging (2022-04-21 15:16:52 -0700)
are available in the Git repository at:
[email protected]:alistair23/qemu.git tags/pull-riscv-to-apply-20220422-1
for you to fetch changes up to faee5441a038898f64b335dbaecab102ba406552:
hw/riscv: boot: Support 64bit fdt address. (2022-04-22 10:35:16 +1000)
----------------------------------------------------------------
First RISC-V PR for QEMU 7.1
* Add support for Ibex SPI to OpenTitan
* Add support for privileged spec version 1.12.0
* Use privileged spec version 1.12.0 for virt machine by default
* Allow software access to MIP SEIP
* Add initial support for the Sdtrig extension
* Optimisations for vector extensions
* Improvements to the misa ISA string
* Add isa extenstion strings to the device tree
* Don't allow -bios options with KVM machines
* Fix NAPOT range computation overflow
* Fix DT property mmu-type when CPU mmu option is disabled
* Make RISC-V ACLINT mtime MMIO register writable
* Add and enable native debug feature
* Support 64bit fdt address.
----------------------------------------------------------------
Alistair Francis (2):
target/riscv: cpu: Fixup indentation target/riscv: Allow software access to MIP SEIP
Atish Patra (7):
target/riscv: Define simpler privileged spec version numbering target/riscv: Add the privileged spec version 1.12.0 target/riscv: Introduce privilege version field in the CSR ops. target/riscv: Add support for mconfigptr target/riscv: Add *envcfg* CSRs support target/riscv: Enable privileged spec version 1.12 target/riscv: Add isa extenstion strings to the device tree
Bin Meng (7):
target/riscv: Add initial support for the Sdtrig extension target/riscv: debug: Implement debug related TCGCPUOps target/riscv: cpu: Add a config option for native debug target/riscv: csr: Hook debug CSR read/write target/riscv: machine: Add debug state description target/riscv: cpu: Enable native debug feature
hw/core: tcg-cpu-ops.h: Update comments of debug_check_watchpoint()
Dylan Jhong (1):
hw/riscv: boot: Support 64bit fdt address.
Frank Chang (3):
hw/intc: Add .impl.[min|max]_access_size declaration in RISC-V ACLINT hw/intc: Support 32/64-bit mtimecmp and mtime accesses in RISC-V ACLINT hw/intc: Make RISC-V ACLINT mtime MMIO register writable
Jim Shu (1):
hw/intc: riscv_aclint: Add reset function of ACLINT devices
Nicolas Pitre (1):
target/riscv/pmp: fix NAPOT range computation overflow
Niklas Cassel (1):
hw/riscv: virt: fix DT property mmu-type when CPU mmu option is disabled
Ralf Ramsauer (1):
hw/riscv: virt: Exit if the user provided -bios in combination with KVM
Richard Henderson (1):
target/riscv: Use cpu_loop_exit_restore directly from mmu faults
Tsukasa OI (1):
target/riscv: misa to ISA string conversion fix
Weiwei Li (3):
target/riscv: optimize condition assign for scale < 0 target/riscv: optimize helper for vmv<nr>r.v target/riscv: fix start byte for vmv<nf>r.v when vstart != 0
Wilfred Mallawa (2):
hw/ssi: Add Ibex SPI device model
riscv: opentitan: Connect opentitan SPI Host
include/hw/core/tcg-cpu-ops.h | 1 + include/hw/intc/riscv_aclint.h | 1 + include/hw/riscv/boot.h | 4 +- include/hw/riscv/opentitan.h | 30 +- include/hw/ssi/ibex_spi_host.h | 94 +++++ target/riscv/cpu.h | 40 ++- target/riscv/cpu_bits.h | 40 +++ target/riscv/debug.h | 114 ++++++ target/riscv/helper.h | 5 +- hw/intc/riscv_aclint.c | 144 ++++++-- hw/riscv/boot.c | 12 +- hw/riscv/opentitan.c | 36 +- hw/riscv/virt.c | 24 +- hw/ssi/ibex_spi_host.c | 612 ++++++++++++++++++++++++++++++++ target/riscv/cpu.c | 120 ++++++- target/riscv/cpu_helper.c | 10 +- target/riscv/csr.c | 282 +++++++++++++-- target/riscv/debug.c | 441 +++++++++++++++++++++++ target/riscv/machine.c | 55 +++ target/riscv/pmp.c | 14 +- target/riscv/vector_helper.c | 31 +- target/riscv/insn_trans/trans_rvv.c.inc | 25 +- hw/ssi/meson.build | 1 + hw/ssi/trace-events | 7 + target/riscv/meson.build | 1 + 25 files changed, 1971 insertions(+), 173 deletions(-) create mode 100644 include/hw/ssi/ibex_spi_host.h create mode 100644 target/riscv/debug.h create mode 100644 hw/ssi/ibex_spi_host.c create mode 100644 target/riscv/debug.c
[PULL v2 02/31] riscv: opentitan: Connect opentitan SPI Host
From: Wilfred Mallawa <[email protected]>
Connect spi host[1/0] to opentitan.
Message-Id: <[email protected]>
--- include/hw/riscv/opentitan.h | 30 +++++++++++++++++++++--------- hw/riscv/opentitan.c | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 13 deletions(-)
include/hw/riscv/opentitan.h +21 -9
@@ -23,11 +23,18 @@#include "hw/intc/sifive_plic.h" #include "hw/char/ibex_uart.h" #include "hw/timer/ibex_timer.h" +#include "hw/ssi/ibex_spi_host.h" #include "qom/object.h" #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc" OBJECT_DECLARE_SIMPLE_TYPE(LowRISCIbexSoCState, RISCV_IBEX_SOC) +enum { +OPENTITAN_SPI_HOST0 , +OPENTITAN_SPI_HOST1 , +OPENTITAN_NUM_SPI_HOSTS , +}; +struct LowRISCIbexSoCState {/*< private >*/ SysBusDevice parent_obj;
@@ -37,6 +44,7 @@ struct LowRISCIbexSoCState {SiFivePLICState plic;IbexUartState uart;IbexTimerState timer; +IbexSPIHostState spi_host[OPENTITAN_NUM_SPI_HOSTS ];MemoryRegion flash_mem;MemoryRegion rom;
@@ -89,15 +97,19 @@ enum { };enum { -IBEX_TIMER_TIMEREXPIRED0_0 =126 , -IBEX_UART0_RX_PARITY_ERR_IRQ =8 , -IBEX_UART0_RX_TIMEOUT_IRQ =7 , -IBEX_UART0_RX_BREAK_ERR_IRQ =6 , -IBEX_UART0_RX_FRAME_ERR_IRQ =5 , -IBEX_UART0_RX_OVERFLOW_IRQ =4 , -IBEX_UART0_TX_EMPTY_IRQ =3 , -IBEX_UART0_RX_WATERMARK_IRQ =2 , -IBEX_UART0_TX_WATERMARK_IRQ =1 , +IBEX_UART0_TX_WATERMARK_IRQ =1 , +IBEX_UART0_RX_WATERMARK_IRQ =2 , +IBEX_UART0_TX_EMPTY_IRQ =3 , +IBEX_UART0_RX_OVERFLOW_IRQ =4 , +IBEX_UART0_RX_FRAME_ERR_IRQ =5 , +IBEX_UART0_RX_BREAK_ERR_IRQ =6 , +IBEX_UART0_RX_TIMEOUT_IRQ =7 , +IBEX_UART0_RX_PARITY_ERR_IRQ =8 , +IBEX_TIMER_TIMEREXPIRED0_0 =126 , +IBEX_SPI_HOST0_ERR_IRQ =150 , +IBEX_SPI_HOST0_SPI_EVENT_IRQ =151 , +IBEX_SPI_HOST1_ERR_IRQ =152 , +IBEX_SPI_HOST1_SPI_EVENT_IRQ =153 , };#endif
hw/riscv/opentitan.c +32 -4
@@ -120,11 +120,18 @@ static void lowrisc_ibex_soc_init(Object *obj)object_initialize_child (obj,"uart" , &s->uart,TYPE_IBEX_UART );object_initialize_child (obj,"timer" , &s->timer,TYPE_IBEX_TIMER ); + +for (int i =0 ; i <OPENTITAN_NUM_SPI_HOSTS ; i++) { +object_initialize_child (obj,"spi_host[*]" , &s->spi_host[i], +TYPE_IBEX_SPI_HOST ); + } }static void lowrisc_ibex_soc_realize (DeviceState *dev_soc,Error **errp) {const MemMapEntry *memmap = ibex_memmap; +DeviceState *dev; +SysBusDevice *busdev;MachineState *ms =MACHINE (qdev_get_machine ());LowRISCIbexSoCState *s =RISCV_IBEX_SOC (dev_soc);MemoryRegion *sys_mem =get_system_memory ();
@@ -209,14 +216,35 @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)qdev_get_gpio_in (DEVICE (qemu_get_cpu (0 )), IRQ_M_TIMER)); +/* SPI-Hosts */ +for (int i =0 ; i <OPENTITAN_NUM_SPI_HOSTS ; ++i) { + dev =DEVICE (&(s->spi_host[i])); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->spi_host[i]), errp)) { +return ; + } + busdev =SYS_BUS_DEVICE (dev); +sysbus_mmio_map (busdev,0 , memmap[IBEX_DEV_SPI_HOST0 + i].base); + +switch (i) { +case OPENTITAN_SPI_HOST0 : +sysbus_connect_irq (busdev,0 ,qdev_get_gpio_in (DEVICE (&s->plic), +IBEX_SPI_HOST0_ERR_IRQ )); +sysbus_connect_irq (busdev,1 ,qdev_get_gpio_in (DEVICE (&s->plic), +IBEX_SPI_HOST0_SPI_EVENT_IRQ )); +break ; +case OPENTITAN_SPI_HOST1 : +sysbus_connect_irq (busdev,0 ,qdev_get_gpio_in (DEVICE (&s->plic), +IBEX_SPI_HOST1_ERR_IRQ )); +sysbus_connect_irq (busdev,1 ,qdev_get_gpio_in (DEVICE (&s->plic), +IBEX_SPI_HOST1_SPI_EVENT_IRQ )); +break ; + } + } +create_unimplemented_device ("riscv.lowrisc.ibex.gpio" , memmap[IBEX_DEV_GPIO ].base, memmap[IBEX_DEV_GPIO ].size);create_unimplemented_device ("riscv.lowrisc.ibex.spi_device" , memmap[IBEX_DEV_SPI_DEVICE ].base, memmap[IBEX_DEV_SPI_DEVICE ].size); -create_unimplemented_device ("riscv.lowrisc.ibex.spi_host0" , - memmap[IBEX_DEV_SPI_HOST0 ].base, memmap[IBEX_DEV_SPI_HOST0 ].size); -create_unimplemented_device ("riscv.lowrisc.ibex.spi_host1" , - memmap[IBEX_DEV_SPI_HOST1 ].base, memmap[IBEX_DEV_SPI_HOST1 ].size);create_unimplemented_device ("riscv.lowrisc.ibex.i2c" , memmap[IBEX_DEV_I2C ].base, memmap[IBEX_DEV_I2C ].size); create_unimplemented_device("riscv.lowrisc.ibex.pattgen",
Signature · 1 line
2.35.1
[PULL v2 06/31] target/riscv: Add support for mconfigptr
In reply to Alistair FrancisFrom: Atish Patra <[email protected]>
RISC-V privileged specification v1.12 introduced a mconfigptr which will hold the physical address of a configuration data structure. As Qemu doesn't have a configuration data structure, is read as zero which is valid as per the priv spec.
Message-Id: <[email protected]>
--- target/riscv/cpu_bits.h | 1 + target/riscv/csr.c | 2 ++ 2 files changed, 3 insertions(+)
target/riscv/cpu_bits.h +1 -0
@@ -148,6 +148,7 @@#define CSR_MARCHID 0xf12#define CSR_MIMPID 0xf13#define CSR_MHARTID 0xf14 +#define CSR_MCONFIGPTR 0xf15/* Machine Trap Setup */ #define CSR_MSTATUS 0x300
target/riscv/csr.c +2 -0
@@ -3110,6 +3110,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MIMPID] = { "mimpid", any, read_zero }, [CSR_MHARTID] = { "mhartid", any, read_mhartid }, + [CSR_MCONFIGPTR] = { "mconfigptr", any, read_zero, + .min_priv_ver = PRIV_VERSION_1_12_0 }, /* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus, write_mstatus, NULL, read_mstatus_i128 },
Signature · 1 line
2.35.1
[PULL v2 01/31] hw/ssi: Add Ibex SPI device model
In reply to Alistair FrancisFrom: Wilfred Mallawa <[email protected]>
Adds the SPI_HOST device model for ibex. The device specification is as per [1]. The model has been tested on opentitan with spi_host unit tests written for TockOS.
[1] https://docs.opentitan.org/hw/ip/spi_host/doc/
Message-Id: <[email protected]>
--- include/hw/ssi/ibex_spi_host.h | 94 +++++ hw/ssi/ibex_spi_host.c | 612 +++++++++++++++++++++++++++++++++ hw/ssi/meson.build | 1 + hw/ssi/trace-events | 7 + 4 files changed, 714 insertions(+) create mode 100644 include/hw/ssi/ibex_spi_host.h create mode 100644 hw/ssi/ibex_spi_host.c
include/hw/ssi/ibex_spi_host.h new file +94 -0
@@ -0,0 +1,94 @@ + +/* +* QEMU model of the Ibex SPI Controller +* SPEC Reference: https://docs.opentitan.org/hw/ip/spi_host/doc/ +* +* Copyright (C) 2022 Western Digital +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef IBEX_SPI_HOST_H +#define IBEX_SPI_HOST_H + +#include "hw/sysbus.h" +#include "hw/hw.h" +#include "hw/ssi/ssi.h" +#include "qemu/fifo8.h" +#include "qom/object.h" +#include "hw/registerfields.h" +#include "qemu/timer.h" + +#define TYPE_IBEX_SPI_HOST "ibex-spi" +#define IBEX_SPI_HOST (obj) \ + OBJECT_CHECK(IbexSPIHostState, (obj), TYPE_IBEX_SPI_HOST) + +/* SPI Registers */ +#define IBEX_SPI_HOST_INTR_STATE (0x00 / 4)/* rw */ +#define IBEX_SPI_HOST_INTR_ENABLE (0x04 / 4)/* rw */ +#define IBEX_SPI_HOST_INTR_TEST (0x08 / 4)/* wo */ +#define IBEX_SPI_HOST_ALERT_TEST (0x0c / 4)/* wo */ +#define IBEX_SPI_HOST_CONTROL (0x10 / 4)/* rw */ +#define IBEX_SPI_HOST_STATUS (0x14 / 4)/* ro */ +#define IBEX_SPI_HOST_CONFIGOPTS (0x18 / 4)/* rw */ +#define IBEX_SPI_HOST_CSID (0x1c / 4)/* rw */ +#define IBEX_SPI_HOST_COMMAND (0x20 / 4)/* wo */ +/* RX/TX Modelled by FIFO */ +#define IBEX_SPI_HOST_RXDATA (0x24 / 4) +#define IBEX_SPI_HOST_TXDATA (0x28 / 4) + +#define IBEX_SPI_HOST_ERROR_ENABLE (0x2c / 4)/* rw */ +#define IBEX_SPI_HOST_ERROR_STATUS (0x30 / 4)/* rw */ +#define IBEX_SPI_HOST_EVENT_ENABLE (0x34 / 4)/* rw */ + +/* FIFO Len in Bytes */ +#define IBEX_SPI_HOST_TXFIFO_LEN 288 +#define IBEX_SPI_HOST_RXFIFO_LEN 256 + +/* Max Register (Based on addr) */ +#define IBEX_SPI_HOST_MAX_REGS (IBEX_SPI_HOST_EVENT_ENABLE + 1) + +/* MISC */ +#define TX_INTERRUPT_TRIGGER_DELAY_NS 100 +#define BIDIRECTIONAL_TRANSFER 3 + +typedef struct { +/* <private> */ +SysBusDevice parent_obj; + +/* <public> */ +MemoryRegion mmio; +uint32_t regs[IBEX_SPI_HOST_MAX_REGS ]; +/* Multi-reg that sets config opts per CS */ +uint32_t *config_opts; +Fifo8 rx_fifo; +Fifo8 tx_fifo; +QEMUTimer *fifo_trigger_handle; + +qemu_irq event; +qemu_irq host_err; +uint32_t num_cs; +qemu_irq *cs_lines; +SSIBus *ssi; + +/* Used to track the init status, for replicating TXDATA ghost writes */ +bool init_status; +}IbexSPIHostState ; + +#endif
hw/ssi/ibex_spi_host.c new file +612 -0
612 lines not on this page · raw message
hw/ssi/meson.build +1 -0
@@ -10,3 +10,4 @@ softmmu_ss.add(when: 'CONFIG_XILINX_SPIPS', if_true: files('xilinx_spips.c')) softmmu_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal-ospi.c')) softmmu_ss.add(when: 'CONFIG_IMX', if_true: files('imx_spi.c')) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_spi.c')) +softmmu_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_spi_host.c'))
hw/ssi/trace-events +7 -0
@@ -20,3 +20,10 @@ npcm7xx_fiu_ctrl_read(const char *id, uint64_t addr, uint32_t data) "%s offset: npcm7xx_fiu_ctrl_write(const char *id, uint64_t addr, uint32_t data) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 npcm7xx_fiu_flash_read(const char *id, int cs, uint64_t addr, unsigned int size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%" PRIx64 npcm7xx_fiu_flash_write(const char *id, unsigned cs, uint64_t addr, unsigned int size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%" PRIx64 + +# ibex_spi_host.c + +ibex_spi_host_reset(const char *msg) "%s" +ibex_spi_host_transfer(uint32_t tx_data, uint32_t rx_data) "tx_data: 0x%" PRIx32 " rx_data: @0x%" PRIx32 +ibex_spi_host_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64 +ibex_spi_host_read(uint64_t addr, uint32_t size) "@0x%" PRIx64 " size %u:"
Signature · 1 line
2.35.1
Re: [PULL v2 01/31] hw/ssi: Add Ibex SPI device model
Quoted 8 lines · Alistair Francis
From: Wilfred Mallawa <[email protected]>
Adds the
SPI_HOSTdevice model for ibex. The device specification is as per [1]. The model has been tested on opentitan withspi_hostunit tests written for TockOS.
Hi; Coverity points out a bug in this code (CID 1488107):
hw/ssi/ibex_spi_host.c line 55
Quoted 3 lines
hw/ssi/ibex_spi_host.c new file +3
-0+REG32(STATUS, 0x14) + FIELD(STATUS, TXQD, 0, 8) +FIELD (STATUS ,RXQD ,18 ,8 )
RXQD isn't at the bottom of this register, so the R_STATUS_RXQD_MASK define is a shifted-up mask...
Quoted 28 lines
hw/ssi/ibex_spi_host.c new file +28
-0+static void ibex_spi_host_transfer (IbexSPIHostState *s) +{ +uint32_t rx, tx; +/* Get num of one byte transfers */ +uint8_t segment_len = ((s->regs[IBEX_SPI_HOST_COMMAND ] &R_COMMAND_LEN_MASK ) + >>R_COMMAND_LEN_SHIFT ); +while (segment_len >0 ) { +if (fifo8_is_empty (&s->tx_fifo)) { +/* Assert Stall */ + s->regs[IBEX_SPI_HOST_STATUS ] |=R_STATUS_TXSTALL_MASK ; +break ; + }else if (fifo8_is_full (&s->rx_fifo)) { +/* Assert Stall */ + s->regs[IBEX_SPI_HOST_STATUS ] |=R_STATUS_RXSTALL_MASK ; +break ; + }else { + tx =fifo8_pop (&s->tx_fifo); + } + + rx =ssi_transfer (s->ssi, tx); + +trace_ibex_spi_host_transfer (tx, rx); + +if (!fifo8_is_full (&s->rx_fifo)) { +fifo8_push (&s->rx_fifo, rx); + }else { +/* Assert RXFULL */ + s->regs[IBEX_SPI_HOST_STATUS ] |=R_STATUS_RXFULL_MASK ;
hw/ssi/ibex_spi_host.c line 270
Quoted 10 lines
hw/ssi/ibex_spi_host.c new file +10
-0+ } + --segment_len; + } + +/* Assert Ready */ + s->regs[IBEX_SPI_HOST_STATUS ] |=R_STATUS_READY_MASK ; +/* Set RXQD */ + s->regs[IBEX_SPI_HOST_STATUS ] &= ~R_STATUS_RXQD_MASK ; + s->regs[IBEX_SPI_HOST_STATUS ] |= (R_STATUS_RXQD_MASK + &div4_round_up (segment_len));
...but here we don't shift div4_round_up(segment_len) up to the right place before ORing it with the MASK, so Coverity points out that the result is always zero.
hw/ssi/ibex_spi_host.c line 274
Quoted 4 lines
hw/ssi/ibex_spi_host.c new file +4
-0+/* Set TXQD */ + s->regs[IBEX_SPI_HOST_STATUS ] &= ~R_STATUS_TXQD_MASK ; + s->regs[IBEX_SPI_HOST_STATUS ] |= (fifo8_num_used (&s->tx_fifo) /4 ) + &R_STATUS_TXQD_MASK ;
This has the same issue, but avoids it by luck because TXQD does start at bit 0.
Since we're using the FIELD() macros, it would be clearer to write all this to use FIELD_DP32() rather than manual bit operations to clear the bits and then OR in the new ones. (True here and also in what looks like several other places through out the file, for deposit and extract operations.)
thanks
-- PMM
Re: [PULL v2 01/31] hw/ssi: Add Ibex SPI device model
Quoted 70 lines · Peter Maydell
Quoted 8 lines · Alistair Francis
From: Wilfred Mallawa <[email protected]>
Adds the
SPI_HOSTdevice model for ibex. The device specification is as per [1]. The model has been tested on opentitan withspi_hostunit tests written for TockOS.Hi; Coverity points out a bug in this code (CID 1488107):
hw/ssi/ibex_spi_host.c line 55
Quoted 3 lines
hw/ssi/ibex_spi_host.c new file +3
-0+REG32(STATUS, 0x14) + FIELD(STATUS, TXQD, 0, 8) +FIELD (STATUS ,RXQD ,18 ,8 )RXQD isn't at the bottom of this register, so the
R_STATUS_RXQD_MASKdefine is a shifted-up mask...Quoted 28 lines
hw/ssi/ibex_spi_host.c new file +28
-0+static void ibex_spi_host_transfer (IbexSPIHostState *s) +{ +uint32_t rx, tx; +/* Get num of one byte transfers */ +uint8_t segment_len = ((s->regs[IBEX_SPI_HOST_COMMAND ] &R_COMMAND_LEN_MASK ) + >>R_COMMAND_LEN_SHIFT ); +while (segment_len >0 ) { +if (fifo8_is_empty (&s->tx_fifo)) { +/* Assert Stall */ + s->regs[IBEX_SPI_HOST_STATUS ] |=R_STATUS_TXSTALL_MASK ; +break ; + }else if (fifo8_is_full (&s->rx_fifo)) { +/* Assert Stall */ + s->regs[IBEX_SPI_HOST_STATUS ] |=R_STATUS_RXSTALL_MASK ; +break ; + }else { + tx =fifo8_pop (&s->tx_fifo); + } + + rx =ssi_transfer (s->ssi, tx); + +trace_ibex_spi_host_transfer (tx, rx); + +if (!fifo8_is_full (&s->rx_fifo)) { +fifo8_push (&s->rx_fifo, rx); + }else { +/* Assert RXFULL */ + s->regs[IBEX_SPI_HOST_STATUS ] |=R_STATUS_RXFULL_MASK ;hw/ssi/ibex_spi_host.c line 270
Quoted 10 lines
hw/ssi/ibex_spi_host.c new file +10
-0+ } + --segment_len; + } + +/* Assert Ready */ + s->regs[IBEX_SPI_HOST_STATUS ] |=R_STATUS_READY_MASK ; +/* Set RXQD */ + s->regs[IBEX_SPI_HOST_STATUS ] &= ~R_STATUS_RXQD_MASK ; + s->regs[IBEX_SPI_HOST_STATUS ] |= (R_STATUS_RXQD_MASK + &div4_round_up (segment_len));...but here we don't shift
div4_round_up(segment_len)up to the right place before ORing it with the MASK, so Coverity points out that the result is always zero.hw/ssi/ibex_spi_host.c line 274
Quoted 4 lines
hw/ssi/ibex_spi_host.c new file +4
-0+/* Set TXQD */ + s->regs[IBEX_SPI_HOST_STATUS ] &= ~R_STATUS_TXQD_MASK ; + s->regs[IBEX_SPI_HOST_STATUS ] |= (fifo8_num_used (&s->tx_fifo) /4 ) + &R_STATUS_TXQD_MASK ;
Quoted 8 lines
This has the same issue, but avoids it by luck because TXQD does start at bit 0.
Since we're using the
FIELD()macros, it would be clearer to write all this to useFIELD_DP32()rather than manual bit operations to clear the bits and then OR in the new ones. (True here and also in what looks like several other places through out the file, for deposit and extract operations.)
Thanks Peter,
Wilfred is looking into it and should be sending patches soon.
Alistair
Quoted 3 lines
thanks
-- PMM
[PULL v2 04/31] target/riscv: Add the privileged spec version 1.12.0
In reply to Alistair FrancisFrom: Atish Patra <[email protected]>
Add the definition for ratified privileged specification version v1.12
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 1 + 1 file changed, 1 insertion(+)
target/riscv/cpu.h +1 -0
@@ -86,6 +86,7 @@ enum {enum {PRIV_VERSION_1_10_0 =0 ,PRIV_VERSION_1_11_0 , +PRIV_VERSION_1_12_0 , };#define VEXT_VERSION_1_00_0 0x00010000
Signature · 1 line
2.35.1
[PULL v2 03/31] target/riscv: Define simpler privileged spec version numbering
In reply to Alistair FrancisFrom: Atish Patra <[email protected]>
Currently, the privileged specification version are defined in a complex manner for no benefit.
Simplify it by changing it to a simple enum based on.
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
target/riscv/cpu.h +5 -2
@@ -82,8 +82,11 @@ enum { RISCV_FEATURE_AIA }; -#define PRIV_VERSION_1_10_0 0x00011000 -#define PRIV_VERSION_1_11_0 0x00011100 +/* Privileged specification version */ +enum { +PRIV_VERSION_1_10_0 =0 , +PRIV_VERSION_1_11_0 , +};#define VEXT_VERSION_1_00_0 0x00010000
Signature · 1 line
2.35.1
[PULL v2 10/31] target/riscv: Allow software access to MIP SEIP
In reply to Alistair FrancisFrom: Alistair Francis <[email protected]>
The RISC-V specification states that:
"Supervisor-level external interrupts are made pending based on the logical-OR of the software-writable SEIP bit and the signal from the external interrupt controller."
We currently only allow either the interrupt controller or software to set the bit, which is incorrect.
This patch removes the miclaim mask when writing MIP to allow M-mode software to inject interrupts, even with an interrupt controller.
We then also need to keep track of which source is setting MIP_SEIP. The final value is a OR of both, so we add two bools and use that to keep track of the current state. This way either source can change without losing the correct value.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/904
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 8 ++++++++ target/riscv/cpu.c | 10 +++++++++- target/riscv/csr.c | 8 ++++++-- 3 files changed, 23 insertions(+), 3 deletions(-)
target/riscv/cpu.h +8 -0
@@ -177,6 +177,14 @@ struct CPUArchState {uint64_t mstatus;uint64_t mip; +/* +* MIP contains the software writable version of SEIP ORed with the +* external interrupt value. The MIP register is always up-to-date. +* To keep track of the current source, we also save booleans of the values +* here. +*/ +bool external_seip; +bool software_seip;uint64_t miclaim;
target/riscv/cpu.c +9 -1
@@ -708,7 +708,6 @@ static void riscv_cpu_set_irq(void *opaque, int irq, int level)case IRQ_VS_TIMER :case IRQ_M_TIMER :case IRQ_U_EXT : -case IRQ_S_EXT :case IRQ_VS_EXT :case IRQ_M_EXT :if (kvm_enabled ()) {
@@ -717,6 +716,15 @@ static void riscv_cpu_set_irq(void *opaque, int irq, int level)riscv_cpu_update_mip (cpu,1 << irq,BOOL_TO_MASK (level)); }break ; +case IRQ_S_EXT : +if (kvm_enabled ()) { +kvm_riscv_set_irq (cpu, irq, level); + }else { + env->external_seip = level; +riscv_cpu_update_mip (cpu,1 << irq, +BOOL_TO_MASK (level | env->software_seip)); + } +break ;default :g_assert_not_reached (); }
target/riscv/csr.c +6 -2
@@ -1498,10 +1498,14 @@ static RISCVException rmw_mip64(CPURISCVState *env, int csrno, uint64_t new_val, uint64_t wr_mask) {RISCVCPU *cpu =env_archcpu (env); -/* Allow software control of delegable interrupts not claimed by hardware */ -uint64_t old_mip, mask = wr_mask & delegable_ints & ~env->miclaim; +uint64_t old_mip, mask = wr_mask & delegable_ints;uint32_t gin; +if (mask &MIP_SEIP ) { + env->software_seip = new_val &MIP_SEIP ; + new_val |= env->external_seip *MIP_SEIP ; + } +if (mask) { old_mip =riscv_cpu_update_mip (cpu, mask, (new_val & mask)); }else {
Signature · 1 line
2.35.1
[PULL v2 15/31] target/riscv: Add isa extenstion strings to the device tree
In reply to Alistair FrancisFrom: Atish Patra <[email protected]>
The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.
Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.
[1] https://lkml.org/lkml/2022/2/15/263
Message-Id: <[email protected]>
--- target/riscv/cpu.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
target/riscv/cpu.c +60 -0
@@ -36,6 +36,11 @@static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ; +struct isa_ext_data { +const char *name; +bool enabled; +}; +const char *const riscv_int_regnames[] = {"x0/zero" ,"x1/ra" ,"x2/sp" ,"x3/gp" ,"x4/tp" ,"x5/t0" ,"x6/t1" ,"x7/t2" ,"x8/s0" ,"x9/s1" ,"x10/a0" ,"x11/a1" ,"x12/a2" ,"x13/a3" ,
@@ -908,6 +913,60 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)device_class_set_props (dc, riscv_cpu_properties); } +#define ISA_EDATA_ENTRY (name, prop) {#name, cpu->cfg.prop} + +static void riscv_isa_string_ext (RISCVCPU *cpu,char **isa_str,int max_str_len) +{ +char *old = *isa_str; +char *new = *isa_str; +int i; + +/** +* Here are the ordering rules of extension naming defined by RISC-V +* specification : +* 1. All extensions should be separated from other multi-letter extensions +* by an underscore. +* 2. The first letter following the 'Z' conventionally indicates the most +* closely related alphabetical extension category, IMAFDQLCBKJTPVH. +* If multiple 'Z' extensions are named, they should be ordered first +* by category, then alphabetically within a category. +* 3. Standard supervisor-level extensions (starts with 'S') should be +* listed after standard unprivileged extensions. If multiple +* supervisor-level extensions are listed, they should be ordered +* alphabetically. +* 4. Non-standard extensions (starts with 'X') must be listed after all +* standard extensions. They must be separated from other multi-letter +* extensions by an underscore. +*/ +struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zfh, ext_zfh), +ISA_EDATA_ENTRY (zfhmin, ext_zfhmin), +ISA_EDATA_ENTRY (zfinx, ext_zfinx), +ISA_EDATA_ENTRY (zhinx, ext_zhinx), +ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin), +ISA_EDATA_ENTRY (zdinx, ext_zdinx), +ISA_EDATA_ENTRY (zba, ext_zba), +ISA_EDATA_ENTRY (zbb, ext_zbb), +ISA_EDATA_ENTRY (zbc, ext_zbc), +ISA_EDATA_ENTRY (zbs, ext_zbs), +ISA_EDATA_ENTRY (zve32f, ext_zve32f), +ISA_EDATA_ENTRY (zve64f, ext_zve64f), +ISA_EDATA_ENTRY (svinval, ext_svinval), +ISA_EDATA_ENTRY (svnapot, ext_svnapot), +ISA_EDATA_ENTRY (svpbmt, ext_svpbmt), + }; + +for (i =0 ; i <ARRAY_SIZE (isa_edata_arr); i++) { +if (isa_edata_arr[i].enabled) { + new =g_strconcat (old,"_" , isa_edata_arr[i].name,NULL ); +g_free (old); + old = new; + } + } + + *isa_str = new; +} +char *riscv_isa_string (RISCVCPU *cpu) {int i;
@@ -920,6 +979,7 @@ char *riscv_isa_string(RISCVCPU *cpu) } } *p ='\0' ; +riscv_isa_string_ext (cpu, &isa_str, maxlen);return isa_str; }
Signature · 1 line
2.35.1
[PULL v2 07/31] target/riscv: Add *envcfg* CSRs support
In reply to Alistair FrancisFrom: Atish Patra <[email protected]>
The RISC-V privileged specification v1.12 defines few execution environment configuration CSRs that can be used enable/disable extensions per privilege levels.
Add the basic support for these CSRs.
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 5 ++ target/riscv/cpu_bits.h | 39 +++++++++++++++ target/riscv/csr.c | 107 ++++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 23 +++++++++ 4 files changed, 174 insertions(+)
target/riscv/cpu.h +5 -0
@@ -304,6 +304,11 @@ struct CPUArchState {target_ulong spmbase;target_ulong upmmask;target_ulong upmbase; + +/* CSRs for execution enviornment configuration */ +uint64_t menvcfg; +target_ulong senvcfg; +uint64_t henvcfg;#endif target_ulong cur_pmmask;target_ulong cur_pmbase;
target/riscv/cpu_bits.h +39 -0
@@ -202,6 +202,9 @@#define CSR_STVEC 0x105#define CSR_SCOUNTEREN 0x106 +/* Supervisor Configuration CSRs */ +#define CSR_SENVCFG 0x10A +/* Supervisor Trap Handling */ #define CSR_SSCRATCH 0x140#define CSR_SEPC 0x141
@@ -247,6 +250,10 @@#define CSR_HTIMEDELTA 0x605#define CSR_HTIMEDELTAH 0x615 +/* Hypervisor Configuration CSRs */ +#define CSR_HENVCFG 0x60A +#define CSR_HENVCFGH 0x61A +/* Virtual CSRs */ #define CSR_VSSTATUS 0x200#define CSR_VSIE 0x204
@@ -290,6 +297,10 @@#define CSR_VSIEH 0x214#define CSR_VSIPH 0x254 +/* Machine Configuration CSRs */ +#define CSR_MENVCFG 0x30A +#define CSR_MENVCFGH 0x31A +/* Enhanced Physical Memory Protection (ePMP) */ #define CSR_MSECCFG 0x747#define CSR_MSECCFGH 0x757
@@ -663,6 +674,34 @@ typedef enum RISCVException {#define PM_EXT_CLEAN 0x00000002ULL#define PM_EXT_DIRTY 0x00000003ULL +/* Execution enviornment configuration bits */ +#define MENVCFG_FIOM BIT(0) +#define MENVCFG_CBIE (3UL << 4) +#define MENVCFG_CBCFE BIT(6) +#define MENVCFG_CBZE BIT(7) +#define MENVCFG_PBMTE (1ULL << 62) +#define MENVCFG_STCE (1ULL << 63) + +/* For RV32 */ +#define MENVCFGH_PBMTE BIT(30) +#define MENVCFGH_STCE BIT(31) + +#define SENVCFG_FIOM MENVCFG_FIOM +#define SENVCFG_CBIE MENVCFG_CBIE +#define SENVCFG_CBCFE MENVCFG_CBCFE +#define SENVCFG_CBZE MENVCFG_CBZE + +#define HENVCFG_FIOM MENVCFG_FIOM +#define HENVCFG_CBIE MENVCFG_CBIE +#define HENVCFG_CBCFE MENVCFG_CBCFE +#define HENVCFG_CBZE MENVCFG_CBZE +#define HENVCFG_PBMTE MENVCFG_PBMTE +#define HENVCFG_STCE MENVCFG_STCE + +/* For RV32 */ +#define HENVCFGH_PBMTE MENVCFGH_PBMTE +#define HENVCFGH_STCE MENVCFGH_STCE +/* Offsets for every pair of control bits per each priv level */ #define XS_OFFSET 0ULL#define U_OFFSET 2ULL
target/riscv/csr.c +107 -0
119 lines not on this page · raw message
target/riscv/machine.c +23 -0
@@ -231,6 +231,28 @@ static int riscv_cpu_post_load(void *opaque, int version_id)return 0 ; } +static bool envcfg_needed (void *opaque) +{ +RISCVCPU *cpu = opaque; +CPURISCVState *env = &cpu->env; + +return (env->priv_ver >=PRIV_VERSION_1_12_0 ?1 :0 ); +} + +static const VMStateDescription vmstate_envcfg = { + .name ="cpu/envcfg" , + .version_id =1 , + .minimum_version_id =1 , + .needed = envcfg_needed, + .fields = (VMStateField []) { +VMSTATE_UINT64 (env.menvcfg,RISCVCPU ), +VMSTATE_UINTTL (env.senvcfg,RISCVCPU ), +VMSTATE_UINT64 (env.henvcfg,RISCVCPU ), + +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_riscv_cpu = { .name ="cpu" , .version_id =3 ,
@@ -292,6 +314,7 @@ const VMStateDescription vmstate_riscv_cpu = { &vmstate_pointermasking, &vmstate_rv128, &vmstate_kvmtimer, + &vmstate_envcfg, NULL } };
Signature · 1 line
2.35.1
[PULL v2 05/31] target/riscv: Introduce privilege version field in the CSR ops.
In reply to Alistair FrancisFrom: Atish Patra <[email protected]>
To allow/disallow the CSR access based on the privilege spec, a new field in the csr_ops is introduced. It also adds the privileged specification version (v1.12) for the CSRs introduced in the v1.12. This includes the new ratified extensions such as Vector, Hypervisor and secconfig CSR. However, it doesn't enforce the privilege version in this commit.
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 2 + target/riscv/csr.c | 103 ++++++++++++++++++++++++++++++--------------- 2 files changed, 70 insertions(+), 35 deletions(-)
target/riscv/cpu.h +2 -0
@@ -658,6 +658,8 @@ typedef struct {riscv_csr_op_fn op;riscv_csr_read128_fn read128;riscv_csr_write128_fn write128; +/* The default priv spec version should be PRIV_VERSION_1_10_0 (i.e 0) */ +uint32_t min_priv_ver; } riscv_csr_operations;/* CSR function table constants */
target/riscv/csr.c +68 -35
121 lines not on this page · raw message
Signature · 1 line
2.35.1
[PULL v2 12/31] target/riscv: optimize condition assign for scale < 0
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
for some cases, scale is always equal or less than 0, since lmul is not larger than 3
Message-Id: <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +3 -5
@@ -1198,7 +1198,7 @@ GEN_LDST_WHOLE_TRANS(vs8r_v, 8, true) static inline uint32_t MAXSZ(DisasContext *s) { int scale = s->lmul - 3; - return scale < 0 ? s->cfg_ptr->vlen >> -scale : s->cfg_ptr->vlen << scale; + return s->cfg_ptr->vlen >> -scale; } static bool opivv_check(DisasContext *s, arg_rmrr *a)
@@ -3597,8 +3597,7 @@ static bool trans_vrgather_vx(DisasContext *s, arg_rmrr *a) if (a->vm && s->vl_eq_vlmax) { int scale = s->lmul - (s->sew + 3); - int vlmax = scale < 0 ? - s->cfg_ptr->vlen >> -scale : s->cfg_ptr->vlen << scale; + int vlmax = s->cfg_ptr->vlen >> -scale; TCGv_i64 dest = tcg_temp_new_i64(); if (a->rs1 == 0) {
@@ -3630,8 +3629,7 @@ static bool trans_vrgather_vi(DisasContext *s, arg_rmrr *a) if (a->vm && s->vl_eq_vlmax) { int scale = s->lmul - (s->sew + 3); - int vlmax = scale < 0 ? - s->cfg_ptr->vlen >> -scale : s->cfg_ptr->vlen << scale; + int vlmax = s->cfg_ptr->vlen >> -scale; if (a->rs1 >= vlmax) { tcg_gen_gvec_dup_imm(MO_64, vreg_ofs(s, a->rd), MAXSZ(s), MAXSZ(s), 0);
Signature · 1 line
2.35.1
[PULL v2 16/31] target/riscv: fix start byte for vmv<nf>r.v when vstart != 0
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
The spec for vmv<nf>r.v says: 'the instructions operate as if EEW=SEW, EMUL = NREG, effective length evl= EMUL * VLEN/SEW.'
So the start byte for vstart != 0 should take sew into account
Message-Id: <[email protected]>
--- target/riscv/vector_helper.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
target/riscv/vector_helper.c +5 -3
@@ -4890,13 +4890,15 @@ GEN_VEXT_VCOMPRESS_VM(vcompress_vm_d, uint64_t, H8)/* Vector Whole Register Move */ void HELPER (vmvr_v )(void *vd,void *vs2,CPURISCVState *env,uint32_t desc) { -/* EEW = 8 */ +/* EEW = SEW */ uint32_t maxsz =simd_maxsz (desc); -uint32_t i = env->vstart; +uint32_t sewb =1 <<FIELD_EX64 (env->vtype,VTYPE ,VSEW ); +uint32_t startb = env->vstart * sewb; +uint32_t i = startb;memcpy ((uint8_t *)vd +H1 (i), (uint8_t *)vs2 +H1 (i), - maxsz - env->vstart); + maxsz - startb); env->vstart =0 ; }
Signature · 1 line
2.35.1
[PULL v2 09/31] target/riscv: cpu: Fixup indentation
In reply to Alistair FrancisFrom: Alistair Francis <[email protected]>
Message-Id: <[email protected]>
--- target/riscv/cpu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
target/riscv/cpu.c +10 -10
@@ -569,18 +569,18 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)if (cpu->cfg.ext_i && cpu->cfg.ext_e) {error_setg (errp,"I and E extensions are incompatible" ); -return ; - } +return ; + }if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) {error_setg (errp,"Either I or E extension must be set" ); -return ; - } +return ; + } -if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m & - cpu->cfg.ext_a & cpu->cfg.ext_f & - cpu->cfg.ext_d)) { +if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m & + cpu->cfg.ext_a & cpu->cfg.ext_f & + cpu->cfg.ext_d)) {warn_report ("Setting G will also set IMAFD" ); cpu->cfg.ext_i = true; cpu->cfg.ext_m = true;
@@ -711,11 +711,11 @@ static void riscv_cpu_set_irq(void *opaque, int irq, int level)case IRQ_S_EXT :case IRQ_VS_EXT :case IRQ_M_EXT : -if (kvm_enabled ()) { +if (kvm_enabled ()) {kvm_riscv_set_irq (cpu, irq, level); - }else { + }else {riscv_cpu_update_mip (cpu,1 << irq,BOOL_TO_MASK (level)); - } + }break ;default :g_assert_not_reached ();
Signature · 1 line
2.35.1
[PULL v2 08/31] target/riscv: Enable privileged spec version 1.12
In reply to Alistair FrancisFrom: Atish Patra <[email protected]>
Virt machine uses privileged specification version 1.12 now. All other machine continue to use the default one defined for that machine unless changed to 1.12 by the user explicitly.
This commit enforces the privilege version for csrs introduced in v1.12 or after.
Message-Id: <[email protected]>
--- target/riscv/cpu.c | 8 +++++--- target/riscv/csr.c | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-)
target/riscv/cpu.c +5 -3
@@ -150,7 +150,7 @@ static void riscv_any_cpu_init(Object *obj)#elif defined(TARGET_RISCV64 )set_misa (env,MXL_RV64 ,RVI |RVM |RVA |RVF |RVD |RVC |RVU );#endif -set_priv_version (env,PRIV_VERSION_1_11_0 ); +set_priv_version (env,PRIV_VERSION_1_12_0 ); }#if defined(TARGET_RISCV64 )
@@ -503,7 +503,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) }if (cpu->cfg.priv_spec) { -if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.11.0" )) { +if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.12.0" )) { + priv_version =PRIV_VERSION_1_12_0 ; + }else if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.11.0" )) { priv_version =PRIV_VERSION_1_11_0 ; }else if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.10.0" )) { priv_version =PRIV_VERSION_1_10_0 ;
@@ -518,7 +520,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)if (priv_version) {set_priv_version (env, priv_version); }else if (!env->priv_ver) { -set_priv_version (env,PRIV_VERSION_1_11_0 ); +set_priv_version (env,PRIV_VERSION_1_12_0 ); }if (cpu->cfg.mmu) {
target/riscv/csr.c +5 -0
@@ -2975,6 +2975,7 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, {/* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */ int read_only =get_field (csrno,0xC00 ) ==3 ; +int csr_min_priv = csr_ops[csrno].min_priv_ver;#if !defined(CONFIG_USER_ONLY )int effective_priv = env->priv;
@@ -3007,6 +3008,10 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,return RISCV_EXCP_ILLEGAL_INST ; } +if (env->priv_ver < csr_min_priv) { +return RISCV_EXCP_ILLEGAL_INST ; + } +return csr_ops[csrno].predicate (env, csrno); }
Signature · 1 line
2.35.1
[PULL v2 21/31] hw/intc: Add .impl.[min|max]_access_size declaration in RISC-V ACLINT
In reply to Alistair FrancisFrom: Frank Chang <[email protected]>
If device's MemoryRegion doesn't have .impl.[min|max]_access_size declaration, the default access_size_min would be 1 byte and access_size_max would be 4 bytes (see: softmmu/memory.c). This will cause a 64-bit memory access to ACLINT to be splitted into two 32-bit memory accesses.
Message-Id: <[email protected]>
--- hw/intc/riscv_aclint.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/intc/riscv_aclint.c +4 -0
@@ -208,6 +208,10 @@ static const MemoryRegionOps riscv_aclint_mtimer_ops = { .valid = { .min_access_size = 4, .max_access_size = 8 + }, + .impl = { + .min_access_size = 4, + .max_access_size = 8, } };
Signature · 1 line
2.35.1
[PULL v2 19/31] target/riscv/pmp: fix NAPOT range computation overflow
In reply to Alistair FrancisFrom: Nicolas Pitre <[email protected]>
There is an overflow with the current code where a pmpaddr value of 0x1fffffff is decoded as sa=0 and ea=0 whereas it should be sa=0 and ea=0xffffffff.
Fix that by simplifying the computation. There is in fact no need for ctz64() nor special case for -1 to achieve proper results.
Message-Id: <[email protected]>
--- target/riscv/pmp.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
target/riscv/pmp.c +3 -11
@@ -141,17 +141,9 @@ static void pmp_decode_napot(target_ulong a, target_ulong *sa, target_ulong *ea)0111...1111 2^(XLEN+2)-byte NAPOT range 1111...1111 Reserved */ -if (a ==-1 ) { - *sa =0u ; - *ea =-1 ; -return ; - }else { -target_ulong t1 =ctz64 (~a); -target_ulong base = (a & ~(((target_ulong )1 << t1) -1 )) <<2 ; -target_ulong range = ((target_ulong )1 << (t1 +3 )) -1 ; - *sa = base; - *ea = base + range; - } + a = (a <<2 ) |0x3 ; + *sa = a & (a +1 ); + *ea = a | (a +1 ); }void pmp_update_rule_addr (CPURISCVState *env,uint32_t pmp_index)
Signature · 1 line
2.35.1
[PULL v2 13/31] target/riscv: optimize helper for vmv<nr>r.v
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
LEN is not used for GEN_VEXT_VMV_WHOLE macro, so vmv<nr>r.v can share the same helper
Message-Id: <[email protected]>
--- target/riscv/helper.h | 5 +---- target/riscv/vector_helper.c | 29 ++++++++++--------------- target/riscv/insn_trans/trans_rvv.c.inc | 17 +++++---------- 3 files changed, 18 insertions(+), 33 deletions(-)
target/riscv/helper.h +1 -4
@@ -1086,10 +1086,7 @@ DEF_HELPER_6(vcompress_vm_h, void, ptr, ptr, ptr, ptr, env, i32) DEF_HELPER_6(vcompress_vm_w, void, ptr, ptr, ptr, ptr, env, i32) DEF_HELPER_6(vcompress_vm_d, void, ptr, ptr, ptr, ptr, env, i32) -DEF_HELPER_4(vmv1r_v, void, ptr, ptr, env, i32) -DEF_HELPER_4(vmv2r_v, void, ptr, ptr, env, i32) -DEF_HELPER_4(vmv4r_v, void, ptr, ptr, env, i32) -DEF_HELPER_4(vmv8r_v, void, ptr, ptr, env, i32) +DEF_HELPER_4(vmvr_v, void, ptr, ptr, env, i32) DEF_HELPER_5(vzext_vf2_h, void, ptr, ptr, ptr, env, i32)DEF_HELPER_5 (vzext_vf2_w, void, ptr, ptr, ptr, env, i32)
target/riscv/vector_helper.c +11 -18
@@ -4888,25 +4888,18 @@ GEN_VEXT_VCOMPRESS_VM(vcompress_vm_w, uint32_t, H4)GEN_VEXT_VCOMPRESS_VM (vcompress_vm_d, uint64_t,H8 ) /* Vector Whole Register Move */ -#define GEN_VEXT_VMV_WHOLE (NAME ,LEN ) \ -void HELPER(NAME)(void *vd, void *vs2, CPURISCVState *env, \ - uint32_t desc) \ -{ \ -/* EEW = 8 */ \ -uint32_t maxsz =simd_maxsz (desc); \ -uint32_t i = env->vstart; \ - \ -memcpy ((uint8_t *)vd +H1 (i), \ - (uint8_t *)vs2 +H1 (i), \ - maxsz - env->vstart); \ - \ - env->vstart =0 ; \ -} +void HELPER (vmvr_v )(void *vd,void *vs2,CPURISCVState *env,uint32_t desc) +{ +/* EEW = 8 */ +uint32_t maxsz =simd_maxsz (desc); +uint32_t i = env->vstart; + +memcpy ((uint8_t *)vd +H1 (i), + (uint8_t *)vs2 +H1 (i), + maxsz - env->vstart); -GEN_VEXT_VMV_WHOLE(vmv1r_v, 1) -GEN_VEXT_VMV_WHOLE(vmv2r_v, 2) -GEN_VEXT_VMV_WHOLE(vmv4r_v, 4) -GEN_VEXT_VMV_WHOLE (vmv8r_v,8 ) + env->vstart =0 ; +}/* Vector Integer Extension */ #define GEN_VEXT_INT_EXT (NAME ,ETYPE ,DTYPE ,HD ,HS1 ) \
target/riscv/insn_trans/trans_rvv.c.inc +6 -11
@@ -3695,7 +3695,7 @@ static bool trans_vcompress_vm(DisasContext *s, arg_r *a) * Whole Vector Register Move Instructions ignore vtype and vl setting. * Thus, we don't need to check vill bit. (Section 16.6) */ -#define GEN_VMV_WHOLE_TRANS(NAME, LEN, SEQ) \ +#define GEN_VMV_WHOLE_TRANS(NAME, LEN) \ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ { \ if (require_rvv(s) && \
@@ -3710,13 +3710,8 @@ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ } else { \ TCGLabel *over = gen_new_label(); \ tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, maxsz, over); \ - \ - static gen_helper_gvec_2_ptr * const fns[4] = { \ - gen_helper_vmv1r_v, gen_helper_vmv2r_v, \ - gen_helper_vmv4r_v, gen_helper_vmv8r_v, \ - }; \ tcg_gen_gvec_2_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs2), \ - cpu_env, maxsz, maxsz, 0, fns[SEQ]); \ + cpu_env, maxsz, maxsz, 0, gen_helper_vmvr_v); \ mark_vs_dirty(s); \ gen_set_label(over); \ } \
@@ -3725,10 +3720,10 @@ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ return false; \ } -GEN_VMV_WHOLE_TRANS(vmv1r_v, 1, 0) -GEN_VMV_WHOLE_TRANS(vmv2r_v, 2, 1) -GEN_VMV_WHOLE_TRANS(vmv4r_v, 4, 2) -GEN_VMV_WHOLE_TRANS(vmv8r_v, 8, 3) +GEN_VMV_WHOLE_TRANS(vmv1r_v, 1) +GEN_VMV_WHOLE_TRANS(vmv2r_v, 2) +GEN_VMV_WHOLE_TRANS(vmv4r_v, 4) +GEN_VMV_WHOLE_TRANS(vmv8r_v, 8) static bool int_ext_check(DisasContext *s, arg_rmr *a, uint8_t div) {
Signature · 1 line
2.35.1
[PULL v2 14/31] target/riscv: misa to ISA string conversion fix
In reply to Alistair FrancisFrom: Tsukasa OI <[email protected]>
Some bits in RISC-V misa' CSR should not be reflected in the ISA string. For instance, S' and U' (represents existence of supervisor and user mode, respectively) in misa' CSR must not be copied since neither S' nor U' are valid single-letter extensions.
This commit also removes all reserved/dropped single-letter "extensions" from the list.
- "B": Not going to be a single-letter extension (misa.B is reserved). - "J": Not going to be a single-letter extension (misa.J is reserved). - "K": Not going to be a single-letter extension (misa.K is reserved). - "L": Dropped. - "N": Dropped. - "T": Dropped.
It also clarifies that the variable `riscv_single_letter_exts' is a single-letter extension order list.
Message-Id: <4a4c11213a161a7eedabe46abe58b351bb0e2ef2.1648473008.git.research_trasio@irq.a4lg.com>
--- target/riscv/cpu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
target/riscv/cpu.c +5 -5
@@ -34,7 +34,7 @@/* RISC-V CPU definitions */ -static const char riscv_exts[26 ] ="IEMAFDQCLBJTPVNSUHKORWXYZG" ; +static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ;const char *const riscv_int_regnames[] = {"x0/zero" ,"x1/ra" ,"x2/sp" ,"x3/gp" ,"x4/tp" ,"x5/t0" ,"x6/t1" ,
@@ -911,12 +911,12 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)char *riscv_isa_string (RISCVCPU *cpu) {int i; -const size_t maxlen =sizeof ("rv128" ) +sizeof (riscv_exts) +1 ; +const size_t maxlen =sizeof ("rv128" ) +sizeof (riscv_single_letter_exts);char *isa_str =g_new (char, maxlen);char *p = isa_str +snprintf (isa_str, maxlen,"rv%d" ,TARGET_LONG_BITS ); -for (i =0 ; i <sizeof (riscv_exts); i++) { -if (cpu->env.misa_ext &RV (riscv_exts[i])) { - *p++ =qemu_tolower (riscv_exts[i]); +for (i =0 ; i <sizeof (riscv_single_letter_exts) -1 ; i++) { +if (cpu->env.misa_ext &RV (riscv_single_letter_exts[i])) { + *p++ =qemu_tolower (riscv_single_letter_exts[i]); } } *p ='\0' ;
Signature · 1 line
2.35.1
[PULL v2 27/31] target/riscv: csr: Hook debug CSR read/write
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
This adds debug CSR read/write support to the RISC-V CSR RW table.
Message-Id: <[email protected]>
--- target/riscv/debug.h | 2 ++ target/riscv/cpu.c | 4 ++++ target/riscv/csr.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ target/riscv/debug.c | 27 +++++++++++++++++++++ 4 files changed, 90 insertions(+)
target/riscv/debug.h +2 -0
@@ -109,4 +109,6 @@ void riscv_cpu_debug_excp_handler(CPUState *cs);bool riscv_cpu_debug_check_breakpoint (CPUState *cs);bool riscv_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp); +void riscv_trigger_init (CPURISCVState *env); +#endif /* RISCV_DEBUG_H */
target/riscv/cpu.c +4 -0
@@ -466,6 +466,10 @@ static void riscv_cpu_reset(DeviceState *dev)set_default_nan_mode (1 , &env->fp_status);#ifndef CONFIG_USER_ONLY +if (riscv_feature (env,RISCV_FEATURE_DEBUG )) { +riscv_trigger_init (env); + } +if (kvm_enabled ()) {kvm_riscv_reset_vcpu (cpu); }
target/riscv/csr.c +57 -0
75 lines not on this page · raw message
target/riscv/debug.c +27 -0
@@ -412,3 +412,30 @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp)return false; } + +void riscv_trigger_init (CPURISCVState *env) +{ +target_ulong type2 =trigger_type (env,TRIGGER_TYPE_AD_MATCH ); +int i; + +/* type 2 triggers */ +for (i =0 ; i <TRIGGER_TYPE2_NUM ; i++) { +/* +* type = TRIGGER_TYPE_AD_MATCH +* dmode = 0 (both debug and M-mode can write tdata) +* maskmax = 0 (unimplemented, always 0) +* sizehi = 0 (match against any size, RV64 only) +* hit = 0 (unimplemented, always 0) +* select = 0 (always 0, perform match on address) +* timing = 0 (always 0, trigger before instruction) +* sizelo = 0 (match against any size) +* action = 0 (always 0, raise a breakpoint exception) +* chain = 0 (unimplemented, always 0) +* match = 0 (always 0, when any compare value equals tdata2) +*/ + env->type2_trig[i].mcontrol = type2; + env->type2_trig[i].maddress =0 ; + env->type2_trig[i].bp =NULL ; + env->type2_trig[i].wp =NULL ; + } +}
Signature · 1 line
2.35.1
[PULL v2 23/31] hw/intc: Make RISC-V ACLINT mtime MMIO register writable
In reply to Alistair FrancisFrom: Frank Chang <[email protected]>
RISC-V privilege spec defines that mtime is exposed as a memory-mapped machine-mode read-write register. However, as QEMU uses host monotonic timer as timer source, this makes mtime to be read-only in RISC-V ACLINT.
This patch makes mtime to be writable by recording the time delta value between the mtime value to be written and the timer value at the time mtime is written. Time delta value is then added back whenever the timer value is retrieved.
Message-Id: <[email protected]>
--- include/hw/intc/riscv_aclint.h | 1 + target/riscv/cpu.h | 8 ++-- hw/intc/riscv_aclint.c | 71 ++++++++++++++++++++++++---------- target/riscv/cpu_helper.c | 4 +- 4 files changed, 57 insertions(+), 27 deletions(-)
include/hw/intc/riscv_aclint.h +1 -0
@@ -31,6 +31,7 @@ typedef struct RISCVAclintMTimerState { /*< private >*/ SysBusDevice parent_obj; + uint64_t time_delta; /*< public >*/ MemoryRegion mmio;
target/riscv/cpu.h +4 -4
@@ -285,8 +285,8 @@ struct CPUArchState {type2_trigger_t type2_trig[TRIGGER_TYPE2_NUM ];/* machine specific rdtime callback */ -uint64_t (*rdtime_fn)(uint32_t ); -uint32_t rdtime_fn_arg; +uint64_t (*rdtime_fn)(void *); +void *rdtime_fn_arg;/* machine specific AIA ireg read-modify-write callback */ #define AIA_MAKE_IREG (__isel, __priv, __virt, __vgein, __xlen) \
@@ -496,8 +496,8 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env);int riscv_cpu_claim_interrupts (RISCVCPU *cpu,uint64_t interrupts);uint64_t riscv_cpu_update_mip (RISCVCPU *cpu,uint64_t mask,uint64_t value);#define BOOL_TO_MASK (x) (-!!(x))/* helper for riscv_cpu_update_mip value */ -void riscv_cpu_set_rdtime_fn (CPURISCVState *env,uint64_t (*fn)(uint32_t ), -uint32_t arg); +void riscv_cpu_set_rdtime_fn (CPURISCVState *env,uint64_t (*fn)(void *), +void *arg); void riscv_cpu_set_aia_ireg_rmw_fn(CPURISCVState *env, uint32_t priv, int (*rmw_fn)(void *arg, target_ulong reg,
hw/intc/riscv_aclint.c +50 -21
134 lines not on this page · raw message
target/riscv/cpu_helper.c +2 -2
@@ -632,8 +632,8 @@ uint64_t riscv_cpu_update_mip(RISCVCPU *cpu, uint64_t mask, uint64_t value)return old; } -void riscv_cpu_set_rdtime_fn (CPURISCVState *env,uint64_t (*fn)(uint32_t ), -uint32_t arg) +void riscv_cpu_set_rdtime_fn (CPURISCVState *env,uint64_t (*fn)(void *), +void *arg) { env->rdtime_fn = fn; env->rdtime_fn_arg = arg;
Signature · 1 line
2.35.1
[PULL v2 11/31] target/riscv: Add initial support for the Sdtrig extension
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
This adds initial support for the Sdtrig extension via the Trigger Module, as defined in the RISC-V Debug Specification [1].
Only "Address / Data Match" trigger (type 2) is implemented as of now, which is mainly used for hardware breakpoint and watchpoint. The number of type 2 triggers implemented is 2, which is the number that we can find in the SiFive U54/U74 cores.
[1] https://github.com/riscv/riscv-debug-spec/raw/master/riscv-debug-stable.pdf
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 5 + target/riscv/debug.h | 108 +++++++++++++ target/riscv/debug.c | 339 +++++++++++++++++++++++++++++++++++++++ target/riscv/meson.build | 1 + 4 files changed, 453 insertions(+) create mode 100644 target/riscv/debug.h create mode 100644 target/riscv/debug.c
target/riscv/cpu.h +5 -0
@@ -106,6 +106,7 @@ typedef struct CPUArchState CPURISCVState;#if !defined(CONFIG_USER_ONLY )#include "pmp.h" +#include "debug.h" #endif #define RV_VLEN_MAX 1024
@@ -279,6 +280,10 @@ struct CPUArchState {pmp_table_t pmp_state;target_ulong mseccfg; +/* trigger module */ +target_ulong trigger_cur; +type2_trigger_t type2_trig[TRIGGER_TYPE2_NUM ]; +/* machine specific rdtime callback */ uint64_t (*rdtime_fn)(uint32_t );uint32_t rdtime_fn_arg;
target/riscv/debug.h new file +108 -0
108 lines not on this page · raw message
target/riscv/debug.c new file +339 -0
339 lines not on this page · raw message
target/riscv/meson.build +1 -0
@@ -27,6 +27,7 @@ riscv_softmmu_ss = ss.source_set() riscv_softmmu_ss.add(files( 'arch_dump.c', 'pmp.c', + 'debug.c', 'monitor.c', 'machine.c' ))
Signature · 1 line
2.35.1
[PULL v2 17/31] target/riscv: Use cpu_loop_exit_restore directly from mmu faults
In reply to Alistair FrancisFrom: Richard Henderson <[email protected]>
The riscv_raise_exception function stores its argument into exception_index and then exits to the main loop. When we have already set exception_index, we can just exit directly.
Message-Id: <[email protected]>
--- target/riscv/cpu_helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/riscv/cpu_helper.c +3 -3
@@ -1150,7 +1150,7 @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, env->badaddr = addr; env->two_stage_lookup =riscv_cpu_virt_enabled (env) ||riscv_cpu_two_stage_lookup (mmu_idx); -riscv_raise_exception (&cpu->env, cs->exception_index, retaddr); +cpu_loop_exit_restore (cs, retaddr); } void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
@@ -1175,7 +1175,7 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, env->badaddr = addr; env->two_stage_lookup =riscv_cpu_virt_enabled (env) ||riscv_cpu_two_stage_lookup (mmu_idx); -riscv_raise_exception (env, cs->exception_index, retaddr); +cpu_loop_exit_restore (cs, retaddr); } bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
@@ -1311,7 +1311,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, first_stage_error,riscv_cpu_virt_enabled (env) || riscv_cpu_two_stage_lookup(mmu_idx)); -riscv_raise_exception (env, cs->exception_index, retaddr); +cpu_loop_exit_restore (cs, retaddr); }return true;
Signature · 1 line
2.35.1
[PULL v2 31/31] hw/riscv: boot: Support 64bit fdt address.
In reply to Alistair FrancisFrom: Dylan Jhong <[email protected]>
The current riscv_load_fdt() forces fdt_load_addr to be placed at a dram address within 3GB, but not all platforms have dram_base within 3GB.
This patch adds an exception for dram base not within 3GB, which will place fdt at dram_end align 16MB.
riscv_setup_rom_reset_vec() also needs to be modified
Message-Id: <[email protected]>
--- include/hw/riscv/boot.h | 4 ++-- hw/riscv/boot.c | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-)
include/hw/riscv/boot.h +2 -2
@@ -46,12 +46,12 @@ target_ulong riscv_load_kernel(const char *kernel_filename, symbol_fn_t sym_cb);hwaddr riscv_load_initrd (const char *filename,uint64_t mem_size,uint64_t kernel_entry,hwaddr *start); -uint32_t riscv_load_fdt (hwaddr dram_start,uint64_t dram_size,void *fdt); +uint64_t riscv_load_fdt (hwaddr dram_start,uint64_t dram_size,void *fdt);void riscv_setup_rom_reset_vec (MachineState *machine,RISCVHartArrayState *harts,hwaddr saddr,hwaddr rom_base,hwaddr rom_size,uint64_t kernel_entry, -uint32_t fdt_load_addr,void *fdt); +uint64_t fdt_load_addr,void *fdt); void riscv_rom_copy_firmware_info(MachineState *machine, hwaddr rom_base, hwaddr rom_size, uint32_t reset_vec_size,
hw/riscv/boot.c +7 -5
@@ -212,9 +212,9 @@ hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,return *start + size; } -uint32_t riscv_load_fdt (hwaddr dram_base,uint64_t mem_size,void *fdt) +uint64_t riscv_load_fdt (hwaddr dram_base,uint64_t mem_size,void *fdt) { -uint32_t temp, fdt_addr; +uint64_t temp, fdt_addr;hwaddr dram_end = dram_base + mem_size;int ret, fdtsize =fdt_totalsize (fdt);
@@ -229,7 +229,7 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)* Thus, put it at an 16MB aligned address that less than fdt size from the * end of dram or 3GB whichever is lesser. */ - temp =MIN (dram_end,3072 * MiB); + temp = (dram_base <3072 * MiB) ?MIN (dram_end,3072 * MiB) : dram_end; fdt_addr =QEMU_ALIGN_DOWN (temp - fdtsize,16 * MiB); ret =fdt_pack (fdt);
@@ -285,13 +285,15 @@ void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *hartshwaddr start_addr, hwaddr rom_base, hwaddr rom_size, uint64_t kernel_entry, - uint32_t fdt_load_addr, void *fdt) + uint64_t fdt_load_addr, void *fdt) { int i;uint32_t start_addr_hi32 =0x00000000 ; +uint32_t fdt_load_addr_hi32 =0x00000000 ;if (!riscv_is_32bit (harts)) { start_addr_hi32 = start_addr >>32 ; + fdt_load_addr_hi32 = fdt_load_addr >>32 ; }/* reset vector */ uint32_t reset_vec[10] = {
@@ -304,7 +306,7 @@ void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts start_addr,/* start: .dword */ start_addr_hi32, fdt_load_addr,/* fdt_laddr: .dword */ - 0x00000000, + fdt_load_addr_hi32, /* fw_dyn: */ };if (riscv_is_32bit (harts)) {
Signature · 1 line
2.35.1
[PULL v2 18/31] hw/riscv: virt: Exit if the user provided -bios in combination with KVM
In reply to Alistair FrancisFrom: Ralf Ramsauer <[email protected]>
The -bios option is silently ignored if used in combination with -enable-kvm. The reason is that the machine starts in S-Mode, and the bios typically runs in M-Mode.
Better exit in that case to not confuse the user.
Message-Id: <[email protected]>
--- hw/riscv/virt.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
hw/riscv/virt.c +10 -4
@@ -1308,12 +1308,18 @@ static void virt_machine_init(MachineState *machine)/* * Only direct boot kernel is currently supported for KVM VM, -* so the "-bios" parameter is ignored and treated like "-bios none" -* when KVM is enabled. +* so the "-bios" parameter is not supported when KVM is enabled. */ if (kvm_enabled ()) { -g_free (machine->firmware); - machine->firmware =g_strdup ("none" ); +if (machine->firmware) { +if (strcmp (machine->firmware,"none" )) { +error_report ("Machine mode firmware is not supported in " +"combination with KVM." ); +exit (1 ); + } + }else { + machine->firmware =g_strdup ("none" ); + } }if (riscv_is_32bit (&s->soc[0 ])) {
Signature · 1 line
2.35.1
[PULL v2 26/31] target/riscv: cpu: Add a config option for native debug
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
Add a config option to enable support for native M-mode debug. This is disabled by default and can be enabled with 'debug=true'.
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 4 +++- target/riscv/cpu.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-)
target/riscv/cpu.h +3 -1
@@ -79,7 +79,8 @@ enum {RISCV_FEATURE_PMP ,RISCV_FEATURE_EPMP ,RISCV_FEATURE_MISA , - RISCV_FEATURE_AIA +RISCV_FEATURE_AIA , + RISCV_FEATURE_DEBUG };/* Privileged specification version */
@@ -405,6 +406,7 @@ struct RISCVCPUConfig {bool pmp;bool epmp;bool aia; +bool debug;uint64_t resetvec; };
target/riscv/cpu.c +5 -0
@@ -548,6 +548,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)riscv_set_feature (env,RISCV_FEATURE_AIA ); } +if (cpu->cfg.debug) { +riscv_set_feature (env,RISCV_FEATURE_DEBUG ); + } +set_resetvec (env, cpu->cfg.resetvec);/* Validate that MISA_MXL is set properly. */
@@ -795,6 +799,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Zve64f" ,RISCVCPU , cfg.ext_zve64f, false),DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true),DEFINE_PROP_BOOL ("pmp" ,RISCVCPU , cfg.pmp, true), +DEFINE_PROP_BOOL ("debug" ,RISCVCPU , cfg.debug, false),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec), DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
Signature · 1 line
2.35.1
[PULL v2 20/31] hw/riscv: virt: fix DT property mmu-type when CPU mmu option is disabled
In reply to Alistair FrancisFrom: Niklas Cassel <[email protected]>
The device tree property "mmu-type" is currently exported as either "riscv,sv32" or "riscv,sv48".
However, the riscv cpu device tree binding [1] has a specific value "riscv,none" for a HART without a MMU.
Set the device tree property "mmu-type" to "riscv,none" when the CPU mmu option is disabled using rv32,mmu=off or rv64,mmu=off.
Message-Id: <[email protected]>
--- hw/riscv/virt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
hw/riscv/virt.c +8 -2
@@ -230,8 +230,14 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, cpu_name =g_strdup_printf ("/cpus/cpu@%d" , s->soc[socket].hartid_base + cpu);qemu_fdt_add_subnode (mc->fdt, cpu_name); -qemu_fdt_setprop_string (mc->fdt, cpu_name,"mmu-type" , - (is_32_bit) ?"riscv,sv32" :"riscv,sv48" ); +if (riscv_feature (&s->soc[socket].harts[cpu].env, +RISCV_FEATURE_MMU )) { +qemu_fdt_setprop_string (mc->fdt, cpu_name,"mmu-type" , + (is_32_bit) ?"riscv,sv32" :"riscv,sv48" ); + }else { +qemu_fdt_setprop_string (mc->fdt, cpu_name,"mmu-type" , +"riscv,none" ); + } name =riscv_isa_string (&s->soc[socket].harts[cpu]);qemu_fdt_setprop_string (mc->fdt, cpu_name,"riscv,isa" , name);g_free (name);
Signature · 1 line
2.35.1
[PULL v2 22/31] hw/intc: Support 32/64-bit mtimecmp and mtime accesses in RISC-V ACLINT
In reply to Alistair FrancisFrom: Frank Chang <[email protected]>
RISC-V privilege spec defines that:
* In RV32, memory-mapped writes to mtimecmp modify only one 32-bit part of the register.
* For RV64, naturally aligned 64-bit memory accesses to the mtime and mtimecmp registers are additionally supported and are atomic.
It's possible to perform both 32/64-bit read/write accesses to both mtimecmp and mtime registers.
Message-Id: <[email protected]>
--- hw/intc/riscv_aclint.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-)
hw/intc/riscv_aclint.c +27 -15
@@ -126,9 +126,9 @@ static uint64_t riscv_aclint_mtimer_read(void *opaque, hwaddr addr,qemu_log_mask (LOG_GUEST_ERROR ,"aclint-mtimer: invalid hartid: %zu" , hartid); }else if ((addr &0x7 ) ==0 ) { -/* timecmp_lo */ +/* timecmp_lo for RV32/RV64 or timecmp for RV64 */ uint64_t timecmp = env->timecmp; -return timecmp &0xFFFFFFFF ; +return (size ==4 ) ? (timecmp &0xFFFFFFFF ) : timecmp; }else if ((addr &0x7 ) ==4 ) {/* timecmp_hi */ uint64_t timecmp = env->timecmp;
@@ -139,8 +139,9 @@ static uint64_t riscv_aclint_mtimer_read(void *opaque, hwaddr addr,return 0 ; } }else if (addr == mtimer->time_base) { -/* time_lo */ -return cpu_riscv_read_rtc (mtimer->timebase_freq) &0xFFFFFFFF ; +/* time_lo for RV32/RV64 or timecmp for RV64 */ +uint64_t rtc =cpu_riscv_read_rtc (mtimer->timebase_freq); +return (size ==4 ) ? (rtc &0xFFFFFFFF ) : rtc; }else if (addr == mtimer->time_base +4 ) {/* time_hi */ return (cpu_riscv_read_rtc (mtimer->timebase_freq) >>32 ) &0xFFFFFFFF ;
@@ -167,18 +168,29 @@ static void riscv_aclint_mtimer_write(void *opaque, hwaddr addr,qemu_log_mask (LOG_GUEST_ERROR ,"aclint-mtimer: invalid hartid: %zu" , hartid); }else if ((addr &0x7 ) ==0 ) { -/* timecmp_lo */ -uint64_t timecmp_hi = env->timecmp >>32 ; -riscv_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), hartid, - timecmp_hi <<32 | (value &0xFFFFFFFF ), - mtimer->timebase_freq); -return ; +if (size ==4 ) { +/* timecmp_lo for RV32/RV64 */ +uint64_t timecmp_hi = env->timecmp >>32 ; +riscv_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), hartid, + timecmp_hi <<32 | (value &0xFFFFFFFF ), + mtimer->timebase_freq); + }else { +/* timecmp for RV64 */ +riscv_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), hartid, + value, mtimer->timebase_freq); + } }else if ((addr &0x7 ) ==4 ) { -/* timecmp_hi */ -uint64_t timecmp_lo = env->timecmp; -riscv_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), hartid, - value <<32 | (timecmp_lo &0xFFFFFFFF ), - mtimer->timebase_freq); +if (size ==4 ) { +/* timecmp_hi for RV32/RV64 */ +uint64_t timecmp_lo = env->timecmp; +riscv_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), hartid, + value <<32 | (timecmp_lo &0xFFFFFFFF ), + mtimer->timebase_freq); + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"aclint-mtimer: invalid timecmp_hi write: %08x" , + (uint32_t )addr); + } }else { qemu_log_mask(LOG_UNIMP, "aclint-mtimer: invalid timecmp write: %08x",
Signature · 1 line
2.35.1
[PULL v2 24/31] hw/intc: riscv_aclint: Add reset function of ACLINT devices
In reply to Alistair FrancisFrom: Jim Shu <[email protected]>
This commit implements reset function of all ACLINT devices. ACLINT device reset will clear MTIME and MSIP register to 0.
Depend on RISC-V ACLINT spec v1.0-rc4:
https://github.com/riscv/riscv-aclint/blob/v1.0-rc4/riscv-aclint.adoc
Message-Id: <[email protected]>
--- hw/intc/riscv_aclint.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
hw/intc/riscv_aclint.c +39 -0
@@ -293,11 +293,29 @@ static void riscv_aclint_mtimer_realize(DeviceState *dev, Error **errp) } } +static void riscv_aclint_mtimer_reset_enter (Object *obj,ResetType type) +{ +/* +* According to RISC-V ACLINT spec: +* - On MTIMER device reset, the MTIME register is cleared to zero. +* - On MTIMER device reset, the MTIMECMP registers are in unknown state. +*/ +RISCVAclintMTimerState *mtimer =RISCV_ACLINT_MTIMER (obj); + +/* +* Clear mtime register by writing to 0 it. +* Pending mtime interrupts will also be cleared at the same time. +*/ +riscv_aclint_mtimer_write (mtimer, mtimer->time_base,0 ,8 ); +} +static void riscv_aclint_mtimer_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); dc->realize = riscv_aclint_mtimer_realize;device_class_set_props (dc, riscv_aclint_mtimer_properties); +ResettableClass *rc =RESETTABLE_CLASS (klass); + rc->phases.enter = riscv_aclint_mtimer_reset_enter; }static const TypeInfo riscv_aclint_mtimer_info = {
@@ -452,11 +470,32 @@ static void riscv_aclint_swi_realize(DeviceState *dev, Error **errp) } } +static void riscv_aclint_swi_reset_enter (Object *obj,ResetType type) +{ +/* +* According to RISC-V ACLINT spec: +* - On MSWI device reset, each MSIP register is cleared to zero. +* +* p.s. SSWI device reset does nothing since SETSIP register always reads 0. +*/ +RISCVAclintSwiState *swi =RISCV_ACLINT_SWI (obj); +int i; + +if (!swi->sswi) { +for (i =0 ; i < swi->num_harts; i++) { +/* Clear MSIP registers by lowering software interrupts. */ +qemu_irq_lower (swi->soft_irqs[i]); + } + } +} +static void riscv_aclint_swi_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); dc->realize = riscv_aclint_swi_realize;device_class_set_props (dc, riscv_aclint_swi_properties); +ResettableClass *rc =RESETTABLE_CLASS (klass); + rc->phases.enter = riscv_aclint_swi_reset_enter; }static const TypeInfo riscv_aclint_swi_info = {
Signature · 1 line
2.35.1
[PULL v2 25/31] target/riscv: debug: Implement debug related TCGCPUOps
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
Implement .debug_excp_handler, .debug_check_{breakpoint, watchpoint} TCGCPUOps and hook them into riscv_tcg_ops.
Message-Id: <[email protected]>
--- target/riscv/debug.h | 4 +++ target/riscv/cpu.c | 3 ++ target/riscv/debug.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+)
target/riscv/debug.h +4 -0
@@ -105,4 +105,8 @@ void tselect_csr_write(CPURISCVState *env, target_ulong val);target_ulong tdata_csr_read (CPURISCVState *env,int tdata_index);void tdata_csr_write (CPURISCVState *env,int tdata_index,target_ulong val); +void riscv_cpu_debug_excp_handler (CPUState *cs); +bool riscv_cpu_debug_check_breakpoint (CPUState *cs); +bool riscv_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp); +#endif /* RISCV_DEBUG_H */
target/riscv/cpu.c +3 -0
@@ -880,6 +880,9 @@ static const struct TCGCPUOps riscv_tcg_ops = { .do_interrupt = riscv_cpu_do_interrupt, .do_transaction_failed = riscv_cpu_do_transaction_failed, .do_unaligned_access = riscv_cpu_do_unaligned_access, + .debug_excp_handler = riscv_cpu_debug_excp_handler, + .debug_check_breakpoint = riscv_cpu_debug_check_breakpoint, + .debug_check_watchpoint = riscv_cpu_debug_check_watchpoint,#endif /* !CONFIG_USER_ONLY */ };
target/riscv/debug.c +75 -0
78 lines not on this page · raw message
Signature · 1 line
2.35.1
[PULL v2 28/31] target/riscv: machine: Add debug state description
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
Add a subsection to machine.c to migrate debug CSR state.
Message-Id: <[email protected]>
--- target/riscv/machine.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
target/riscv/machine.c +32 -0
@@ -216,7 +216,38 @@ static const VMStateDescription vmstate_kvmtimer = {VMSTATE_UINT64 (env.kvm_timer_time,RISCVCPU ),VMSTATE_UINT64 (env.kvm_timer_compare,RISCVCPU ),VMSTATE_UINT64 (env.kvm_timer_state,RISCVCPU ), + VMSTATE_END_OF_LIST() + } +}; + +static bool debug_needed (void *opaque) +{ +RISCVCPU *cpu = opaque; +CPURISCVState *env = &cpu->env; + +return riscv_feature (env,RISCV_FEATURE_DEBUG ); +} +static const VMStateDescription vmstate_debug_type2 = { + .name ="cpu/debug/type2" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINTTL (mcontrol, type2_trigger_t), +VMSTATE_UINTTL (maddress, type2_trigger_t), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_debug = { + .name ="cpu/debug" , + .version_id =1 , + .minimum_version_id =1 , + .needed = debug_needed, + .fields = (VMStateField []) { +VMSTATE_UINTTL (env.trigger_cur,RISCVCPU ), +VMSTATE_STRUCT_ARRAY (env.type2_trig,RISCVCPU ,TRIGGER_TYPE2_NUM , +0 , vmstate_debug_type2, type2_trigger_t),VMSTATE_END_OF_LIST () } };
@@ -315,6 +346,7 @@ const VMStateDescription vmstate_riscv_cpu = { &vmstate_rv128, &vmstate_kvmtimer, &vmstate_envcfg, + &vmstate_debug, NULL } };
Signature · 1 line
2.35.1
[PULL v2 30/31] hw/core: tcg-cpu-ops.h: Update comments of debug_check_watchpoint()
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
This is now used by RISC-V as well. Update the comments.
Message-Id: <[email protected]>
--- include/hw/core/tcg-cpu-ops.h | 1 + 1 file changed, 1 insertion(+)
include/hw/core/tcg-cpu-ops.h +1 -0
@@ -90,6 +90,7 @@ struct TCGCPUOps {/** * @debug_check_watchpoint: return true if the architectural * watchpoint whose address has matched should really fire, used by ARM +* and RISC-V */ bool (*debug_check_watchpoint)(CPUState *cpu,CPUWatchpoint *wp);
Signature · 1 line
2.35.1
[PULL v2 29/31] target/riscv: cpu: Enable native debug feature
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
Turn on native debug feature by default for all CPUs.
Message-Id: <[email protected]>
--- target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
@@ -803,7 +803,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Zve64f" ,RISCVCPU , cfg.ext_zve64f, false),DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true),DEFINE_PROP_BOOL ("pmp" ,RISCVCPU , cfg.pmp, true), -DEFINE_PROP_BOOL ("debug" ,RISCVCPU , cfg.debug, false), +DEFINE_PROP_BOOL ("debug" ,RISCVCPU , cfg.debug, true),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec), DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
Signature · 1 line
2.35.1
Richard Henderson
AppliedQuoted 17 lines · Alistair Francis
From: Alistair Francis <[email protected]>
The following changes since commit
da5006445a92bb7801f54a93452fac63ca2f634c:Merge tag 'python-pull-request' of https://gitlab.com/jsnow/qemu into staging (2022-04-21 15:16:52 -0700)are available in the Git repository at:
[email protected]:alistair23/qemu.git tags/pull-riscv-to-apply-20220422-1for you to fetch changes up to
faee5441a038898f64b335dbaecab102ba406552:hw/riscv: boot: Support 64bit fdt address. (2022-04-22 10:35:16 +1000)----------------------------------------------------------------
First RISC-V PR for QEMU 7.1
Quoted 14 lines
* Add support for Ibex SPI to OpenTitan
* Add support for privileged spec version 1.12.0
* Use privileged spec version 1.12.0 for virt machine by default
* Allow software access to MIP SEIP
* Add initial support for the Sdtrig extension
* Optimisations for vector extensions
* Improvements to the misa ISA string
* Add isa extenstion strings to the device tree
* Don't allow-biosoptions with KVM machines
* Fix NAPOT range computation overflow
* Fix DT property mmu-type when CPU mmu option is disabled
* Make RISC-V ACLINT mtime MMIO register writable
* Add and enable native debug feature
* Support 64bit fdt address.
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.
r~
Quoted 90 lines
----------------------------------------------------------------
Alistair Francis (2):
target/riscv: cpu: Fixup indentation target/riscv: Allow software access to MIP SEIPAtish Patra (7):
target/riscv: Define simpler privileged spec version numbering target/riscv: Add the privileged spec version 1.12.0 target/riscv: Introduce privilege version field in the CSR ops. target/riscv: Add support for mconfigptr target/riscv: Add *envcfg* CSRs support target/riscv: Enable privileged spec version 1.12 target/riscv: Add isa extenstion strings to the device treeBin Meng (7):
target/riscv: Add initial support for the Sdtrig extension target/riscv: debug: Implement debug related TCGCPUOps target/riscv: cpu: Add a config option for native debug target/riscv: csr: Hook debug CSR read/write target/riscv: machine: Add debug state description target/riscv: cpu: Enable native debug feature
hw/core:tcg-cpu-ops.h: Update comments ofdebug_check_watchpoint()Dylan Jhong (1):
hw/riscv: boot: Support 64bit fdt address.Frank Chang (3):
hw/intc: Add .impl.[min|max]_access_size declaration in RISC-V ACLINT hw/intc: Support 32/64-bit mtimecmp and mtime accesses in RISC-V ACLINT hw/intc: Make RISC-V ACLINT mtime MMIO register writableJim Shu (1):
hw/intc:riscv_aclint: Add reset function of ACLINT devicesNicolas Pitre (1):
target/riscv/pmp: fix NAPOT range computation overflowNiklas Cassel (1):
hw/riscv: virt: fix DT property mmu-type when CPU mmu option is disabledRalf Ramsauer (1):
hw/riscv: virt: Exit if the user provided -bios in combination with KVMRichard Henderson (1):
target/riscv: Usecpu_loop_exit_restoredirectly from mmu faultsTsukasa OI (1):
target/riscv: misa to ISA string conversion fixWeiwei Li (3):
target/riscv: optimize condition assign for scale < 0 target/riscv: optimize helper for vmv<nr>r.v target/riscv: fix start byte for vmv<nf>r.v when vstart != 0Wilfred Mallawa (2):
hw/ssi: Add Ibex SPI device model
riscv: opentitan: Connect opentitan SPI Hostinclude/hw/core/tcg-cpu-ops.h | 1 + include/hw/intc/riscv_aclint.h | 1 + include/hw/riscv/boot.h | 4 +- include/hw/riscv/opentitan.h | 30 +- include/hw/ssi/ibex_spi_host.h | 94 +++++ target/riscv/cpu.h | 40 ++- target/riscv/cpu_bits.h | 40 +++ target/riscv/debug.h | 114 ++++++ target/riscv/helper.h | 5 +- hw/intc/riscv_aclint.c | 144 ++++++-- hw/riscv/boot.c | 12 +- hw/riscv/opentitan.c | 36 +- hw/riscv/virt.c | 24 +- hw/ssi/ibex_spi_host.c | 612 ++++++++++++++++++++++++++++++++ target/riscv/cpu.c | 120 ++++++- target/riscv/cpu_helper.c | 10 +- target/riscv/csr.c | 282 +++++++++++++-- target/riscv/debug.c | 441 +++++++++++++++++++++++ target/riscv/machine.c | 55 +++ target/riscv/pmp.c | 14 +- target/riscv/vector_helper.c | 31 +- target/riscv/insn_trans/trans_rvv.c.inc | 25 +- hw/ssi/meson.build | 1 + hw/ssi/trace-events | 7 + target/riscv/meson.build | 1 + 25 files changed, 1971 insertions(+), 173 deletions(-)create mode 100644
include/hw/ssi/ibex_spi_host.hcreate mode 100644target/riscv/debug.hcreate mode 100644hw/ssi/ibex_spi_host.ccreate mode 100644target/riscv/debug.c