Misc RISC-V fixes
Subsystems (2)
cover Misc RISC-V fixes
This series is another go at reducing the diff between the RISC-V fork
(https://github.com/riscv/riscv-qemu/) and mainline QEMU.
This is a small series with only a handful of changes as I don't want to have to deal with too many conflicts all at once and I don't want to create too much conflict with the ongoing decode tree work.
Once the decode tree work goes in we can look at rebasing the changes in the RISC-V fork that touch translate.c.
Michael Clark (4):
RISC-V: Add hartid and \n to interrupt logging
RISC-V: Fix CLINT timecmp low 32-bit writes
RISC-V: Fix PLIC pending bitfield reads
RISC-V: Enable second UART on sifive_e and sifive_u
Nathaniel Graff (1):
sifive_uart: Implement interrupt pending register
hw/riscv/sifive_clint.c | 8 ++++---- hw/riscv/sifive_e.c | 5 ++--- hw/riscv/sifive_plic.c | 2 +- hw/riscv/sifive_u.c | 5 ++--- hw/riscv/sifive_uart.c | 24 +++++++++++++++++++----- include/hw/riscv/sifive_uart.h | 3 +++ target/riscv/cpu_helper.c | 18 ++++++++++-------- 7 files changed, 41 insertions(+), 24 deletions(-)
Signature · 1 line
2.19.1
PATCH 1/5 RISC-V: Add hartid and \n to interrupt logging
From: Michael Clark <[email protected]>
Add carriage return that was erroneously removed when converting to qemu_log. Change hard coded core number to the actual hartid.
--- target/riscv/cpu_helper.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
target/riscv/cpu_helper.c +10 -8
@@ -445,11 +445,13 @@ void riscv_cpu_do_interrupt(CPUState *cs)if (RISCV_DEBUG_INTERRUPT ) {int log_cause = cs->exception_index &RISCV_EXCP_INT_MASK ;if (cs->exception_index &RISCV_EXCP_INT_FLAG ) { -qemu_log_mask (LOG_TRACE ,"core 0: trap %s, epc 0x" TARGET_FMT_lx, - riscv_intr_names[log_cause], env->pc); +qemu_log_mask (LOG_TRACE ,"core " + TARGET_FMT_ld": trap %s, epc 0x" TARGET_FMT_lx"\n" , + env->mhartid, riscv_intr_names[log_cause], env->pc); }else { -qemu_log_mask (LOG_TRACE ,"core 0: intr %s, epc 0x" TARGET_FMT_lx, - riscv_excp_names[log_cause], env->pc); +qemu_log_mask (LOG_TRACE ,"core " + TARGET_FMT_ld": intr %s, epc 0x" TARGET_FMT_lx"\n" , + env->mhartid, riscv_excp_names[log_cause], env->pc); } }
@@ -511,8 +513,8 @@ void riscv_cpu_do_interrupt(CPUState *cs)if (hasbadaddr) {if (RISCV_DEBUG_INTERRUPT ) { -qemu_log_mask (LOG_TRACE ,"core " TARGET_FMT_ld -": badaddr 0x" TARGET_FMT_lx, env->mhartid, env->badaddr); +qemu_log_mask (LOG_TRACE ,"core " TARGET_FMT_ld": badaddr 0x" + TARGET_FMT_lx"\n" , env->mhartid, env->badaddr); } env->sbadaddr = env->badaddr; }else {
@@ -536,8 +538,8 @@ void riscv_cpu_do_interrupt(CPUState *cs)if (hasbadaddr) {if (RISCV_DEBUG_INTERRUPT ) { -qemu_log_mask (LOG_TRACE ,"core " TARGET_FMT_ld -": badaddr 0x" TARGET_FMT_lx, env->mhartid, env->badaddr); +qemu_log_mask (LOG_TRACE ,"core " TARGET_FMT_ld": badaddr 0x" + TARGET_FMT_lx"\n" , env->mhartid, env->badaddr); } env->mbadaddr = env->badaddr; }else {
Signature · 1 line
2.19.1
PATCH 2/5 RISC-V: Fix CLINT timecmp low 32-bit writes
In reply to Alistair FrancisFrom: Michael Clark <[email protected]>
A missing shift made updates to the low order bits of timecmp erroneously copy the old low order bits into the high order bits of the 64-bit timecmp register. Add the missing shift and rename timecmp local variables to timecmp_hi and timecmp_lo.
This bug didn't show up as the low order bits are usually written first followed by the high order bits meaning the high order bits contained an invalid value between the timecmp_lo and timecmp_hi update.
--- hw/riscv/sifive_clint.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/riscv/sifive_clint.c +4 -4
@@ -146,15 +146,15 @@ static void sifive_clint_write(void *opaque, hwaddr addr, uint64_t value,error_report ("clint: invalid timecmp hartid: %zu" , hartid); }else if ((addr &0x7 ) ==0 ) {/* timecmp_lo */ -uint64_t timecmp = env->timecmp; +uint64_t timecmp_hi = env->timecmp >>32 ;sifive_clint_write_timecmp (RISCV_CPU (cpu), - timecmp <<32 | (value &0xFFFFFFFF )); + timecmp_hi <<32 | (value &0xFFFFFFFF ));return ; }else if ((addr &0x7 ) ==4 ) {/* timecmp_hi */ -uint64_t timecmp = env->timecmp; +uint64_t timecmp_lo = env->timecmp;sifive_clint_write_timecmp (RISCV_CPU (cpu), - value <<32 | (timecmp &0xFFFFFFFF )); + value <<32 | (timecmp_lo &0xFFFFFFFF )); }else {error_report ("clint: invalid timecmp write: %08x" , (uint32_t )addr); }
Signature · 1 line
2.19.1
PATCH 3/5 RISC-V: Fix PLIC pending bitfield reads
In reply to Alistair FrancisFrom: Michael Clark <[email protected]>
The address calculation for the pending bitfield had a copy paste bug. This bug went unnoticed because the Linux PLIC driver does not read the pending bitfield, rather it reads pending interrupt numbers from the claim register and writes acknowledgements back to the claim register.
--- hw/riscv/sifive_plic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/sifive_plic.c +1 -1
@@ -214,7 +214,7 @@ static uint64_t sifive_plic_read(void *opaque, hwaddr addr, unsigned size) }else if (addr >= plic->pending_base &&/* 1 bit per source */ addr < plic->pending_base + (plic->num_sources >>3 )) { -uint32_t word = (addr - plic->priority_base) >>2 ; +uint32_t word = (addr - plic->pending_base) >>2 ;if (RISCV_DEBUG_PLIC ) {qemu_log ("plic: read pending: word=%d value=%d\n" , word, plic->pending[word]);
Signature · 1 line
2.19.1
PATCH 4/5 RISC-V: Enable second UART on sifive_e and sifive_u
In reply to Alistair FrancisFrom: Michael Clark <[email protected]>
Previously the second UARTs on the sifive_e and sifive_u machines where disabled due to check-qtest-riscv32 and check-qtest-riscv64 failures. Recent changes in the QEMU core serial code have resolved these failures so the second UARTs can be instantiated.
--- hw/riscv/sifive_e.c | 5 ++--- hw/riscv/sifive_u.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
hw/riscv/sifive_e.c +2 -3
@@ -192,9 +192,8 @@ static void riscv_sifive_e_soc_realize(DeviceState *dev, Error **errp) memmap[SIFIVE_E_QSPI0].base, memmap[SIFIVE_E_QSPI0].size);sifive_mmio_emulate (sys_mem,"riscv.sifive.e.pwm0" , memmap[SIFIVE_E_PWM0 ].base, memmap[SIFIVE_E_PWM0 ].size); -/* sifive_uart_create(sys_mem, memmap[SIFIVE_E_UART1].base, -serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), -SIFIVE_E_UART1_IRQ)); */ +sifive_uart_create (sys_mem, memmap[SIFIVE_E_UART1 ].base, +serial_hd (1 ),qdev_get_gpio_in (DEVICE (s->plic),SIFIVE_E_UART1_IRQ ));sifive_mmio_emulate (sys_mem,"riscv.sifive.e.qspi1" , memmap[SIFIVE_E_QSPI1 ].base, memmap[SIFIVE_E_QSPI1 ].size); sifive_mmio_emulate(sys_mem, "riscv.sifive.e.pwm1",
hw/riscv/sifive_u.c +2 -3
@@ -350,9 +350,8 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp) memmap[SIFIVE_U_PLIC].size);sifive_uart_create (system_memory, memmap[SIFIVE_U_UART0 ].base,serial_hd (0 ),qdev_get_gpio_in (DEVICE (s->plic),SIFIVE_U_UART0_IRQ )); -/* sifive_uart_create(system_memory, memmap[SIFIVE_U_UART1].base, -serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), -SIFIVE_U_UART1_IRQ)); */ +sifive_uart_create (system_memory, memmap[SIFIVE_U_UART1 ].base, +serial_hd (1 ),qdev_get_gpio_in (DEVICE (s->plic),SIFIVE_U_UART1_IRQ ));sifive_clint_create (memmap[SIFIVE_U_CLINT ].base, memmap[SIFIVE_U_CLINT ].size, smp_cpus,SIFIVE_SIP_BASE ,SIFIVE_TIMECMP_BASE ,SIFIVE_TIME_BASE );
Signature · 1 line
2.19.1
PATCH 5/5 sifive_uart: Implement interrupt pending register
In reply to Alistair FrancisFrom: Nathaniel Graff <[email protected]>
The watermark bits are set in the interrupt pending register according to the configuration of txcnt and rxcnt in the txctrl and rxctrl registers.
Since the UART TX does not implement a FIFO, the txwm bit is set as long as the TX watermark level is greater than zero.
--- hw/riscv/sifive_uart.c | 24 +++++++++++++++++++----- include/hw/riscv/sifive_uart.h | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-)
hw/riscv/sifive_uart.c +19 -5
@@ -28,12 +28,26 @@* Not yet implemented: * * Transmit FIFO using "qemu/fifo8.h" -* SIFIVE_UART_IE_TXWM interrupts -* SIFIVE_UART_IE_RXWM interrupts must honor fifo watermark -* Rx FIFO watermark interrupt trigger threshold -* Tx FIFO watermark interrupt trigger threshold. */ +/* Returns the state of the IP (interrupt pending) register */ +static uint64_t uart_ip (SiFiveUARTState *s) +{ +uint64_t ret =0 ; + +uint64_t txcnt =SIFIVE_UART_GET_TXCNT (s->txctrl); +uint64_t rxcnt =SIFIVE_UART_GET_RXCNT (s->rxctrl); + +if (txcnt !=0 ) { + ret |=SIFIVE_UART_IP_TXWM ; + } +if (s->rx_fifo_len > rxcnt) { + ret |=SIFIVE_UART_IP_RXWM ; + } + +return ret; +} +static void update_irq (SiFiveUARTState *s) {int cond =0 ;
@@ -69,7 +83,7 @@ uart_read(void *opaque, hwaddr addr, unsigned int size)case SIFIVE_UART_IE :return s->ie;case SIFIVE_UART_IP : -return s->rx_fifo_len ?SIFIVE_UART_IP_RXWM :0 ; +return uart_ip (s);case SIFIVE_UART_TXCTRL :return s->txctrl;case SIFIVE_UART_RXCTRL :
include/hw/riscv/sifive_uart.h +3 -0
@@ -43,6 +43,9 @@ enum { SIFIVE_UART_IP_RXWM = 2 /* Receive watermark interrupt pending */ }; +#define SIFIVE_UART_GET_TXCNT (txctrl) ((txctrl >> 16) & 0x7) +#define SIFIVE_UART_GET_RXCNT (rxctrl) ((rxctrl >> 16) & 0x7) +#define TYPE_SIFIVE_UART "riscv.sifive.uart"#define SIFIVE_UART (obj) \
Signature · 1 line
2.19.1