implement `FIELDx_1CLEAR() macro
v3 cover implement `FIELDx_1CLEAR() macro
From: Wilfred Mallawa <[email protected]>
This patch series implements a FIELDx_1CLEAR() macro and implements it in the hw/ssi/ibex_spi.c model.
*** Changelog ***
Since v2:
- change the macro arguments name to match the existing macros.
(reg_val, reg, field) -> (storage, reg, field)
- Add the use of this macro to ibex_spi
Since v1:
- Instead of needing all field bits to be set we clear the field if any are set. If the field is 0/clear then no change.
Wilfred Mallawa (2):
hw/registerfields: add FIELDx_1CLEAR() macro hw/ssi/ibex_spi: implement FIELD32_1CLEAR macro
hw/ssi/ibex_spi_host.c | 21 +++++++++------------ include/hw/registerfields.h | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-)
Signature · 1 line
2.37.3
PATCH v3 1/2 hw/registerfields: add `FIELDx_1CLEAR()` macro
From: Wilfred Mallawa <[email protected]>
Adds a helper macro that implements the register w1c functionality.
Ex:
uint32_t data = FIELD32_1CLEAR(val, REG, FIELD);
If ANY bits of the specified FIELD is set
then the respective field is cleared and returned to data.
If the field is cleared (0), then no change and
val is returned.
--- include/hw/registerfields.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
include/hw/registerfields.h +22 -0
@@ -115,6 +115,28 @@ R_ ## reg ## _ ## field ## _LENGTH, _v.v); \ _d; }) +/* +* Clear the specified field in storage if +* any field bits are set, else no changes made. Implements +* single/multi-bit `w1c` +* +*/ +#define FIELD8_1CLEAR (storage, reg, field) \ + (FIELD_EX8(storage, reg, field) ? \ + FIELD_DP8(storage, reg, field, 0x00) : storage) + +#define FIELD16_1CLEAR (storage, reg, field) \ + (FIELD_EX16(storage, reg, field) ? \ + FIELD_DP16(storage, reg, field, 0x00) : storage) + +#define FIELD32_1CLEAR (storage, reg, field) \ + (FIELD_EX32(storage, reg, field) ? \ + FIELD_DP32(storage, reg, field, 0x00) : storage) + +#define FIELD64_1CLEAR (storage, reg, field) \ + (FIELD_EX64(storage, reg, field) ? \ + FIELD_DP64(storage, reg, field, 0x00) : storage) +#define FIELD_SDP8 (storage, reg, field, val) ({ \ struct { \ signed int v:R_ ## reg ## _ ## field ## _LENGTH; \
Signature · 1 line
2.37.3
Re: [PATCH v3 1/2] hw/registerfields: add `FIELDx_1CLEAR()` macro
Quoted 9 lines · Wilfred Mallawa
From: Wilfred Mallawa <[email protected]>
Adds a helper macro that implements the register
w1cfunctionality.Ex:
uint32_tdata =FIELD32_1CLEAR(val, REG, FIELD);
Quoted 7 lines
If ANY bits of the specified
FIELDis set
then the respective field is cleared and returned todata.If the field is cleared (0), then no change and
val is returned.Signed-off-by Wilfred Mallawa <[email protected]>
Alistair
Quoted 41 lines
--- include/hw/registerfields.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)include/hw/registerfields.h +22
-1@@ -115,6 +115,28 @@ R_ ## reg ## _ ## field ## _LENGTH, _v.v); \ _d; }) +/* +* Clear the specified field in storage if +* any field bits are set, else no changes made. Implements +* single/multi-bit `w1c` +* +*/ +#define FIELD8_1CLEAR (storage, reg, field) \ + (FIELD_EX8(storage, reg, field) ? \ + FIELD_DP8(storage, reg, field, 0x00) : storage) + +#define FIELD16_1CLEAR (storage, reg, field) \ + (FIELD_EX16(storage, reg, field) ? \ + FIELD_DP16(storage, reg, field, 0x00) : storage) + +#define FIELD32_1CLEAR (storage, reg, field) \ + (FIELD_EX32(storage, reg, field) ? \ + FIELD_DP32(storage, reg, field, 0x00) : storage) + +#define FIELD64_1CLEAR (storage, reg, field) \ + (FIELD_EX64(storage, reg, field) ? \ + FIELD_DP64(storage, reg, field, 0x00) : storage) +#define FIELD_SDP8 (storage, reg, field, val) ({ \ struct { \ signed int v:R_ ## reg ## _ ## field ## _LENGTH; \ --2.37.3
PATCH v3 2/2 hw/ssi/ibex_spi: implement `FIELD32_1CLEAR` macro
In reply to Wilfred MallawaFrom: Wilfred Mallawa <[email protected]>
use the FIELD32_1CLEAR macro to implement register rw1c functionality to ibex_spi.
This change was tested by running the SPI_HOST from TockOS.
--- hw/ssi/ibex_spi_host.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
hw/ssi/ibex_spi_host.c +9 -12
@@ -342,7 +342,7 @@ static void ibex_spi_host_write(void *opaque, hwaddr addr, {IbexSPIHostState *s = opaque;uint32_t val32 = val64; -uint32_t shift_mask =0xff , status =0 , data =0 ; +uint32_t shift_mask =0xff , status =0 ;uint8_t txqd_len;trace_ibex_spi_host_write (addr, size, val64);
@@ -355,12 +355,11 @@ static void ibex_spi_host_write(void *opaque, hwaddr addr,case IBEX_SPI_HOST_INTR_STATE :/* rw1c status register */ if (FIELD_EX32 (val32,INTR_STATE ,ERROR )) { - data =FIELD_DP32 (data,INTR_STATE ,ERROR ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],INTR_STATE ,ERROR ); }if (FIELD_EX32 (val32,INTR_STATE ,SPI_EVENT )) { - data =FIELD_DP32 (data,INTR_STATE ,SPI_EVENT ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],INTR_STATE ,SPI_EVENT ); } - s->regs[addr] = data;break ;case IBEX_SPI_HOST_INTR_ENABLE : s->regs[addr] = val32;
@@ -505,27 +504,25 @@ static void ibex_spi_host_write(void *opaque, hwaddr addr,* When an error occurs, the corresponding bit must be cleared * here before issuing any further commands */ - status = s->regs[addr];/* rw1c status register */ if (FIELD_EX32 (val32,ERROR_STATUS ,CMDBUSY )) { - status =FIELD_DP32 (status,ERROR_STATUS ,CMDBUSY ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,CMDBUSY ); }if (FIELD_EX32 (val32,ERROR_STATUS ,OVERFLOW )) { - status =FIELD_DP32 (status,ERROR_STATUS ,OVERFLOW ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,OVERFLOW ); }if (FIELD_EX32 (val32,ERROR_STATUS ,UNDERFLOW )) { - status =FIELD_DP32 (status,ERROR_STATUS ,UNDERFLOW ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,UNDERFLOW ); }if (FIELD_EX32 (val32,ERROR_STATUS ,CMDINVAL )) { - status =FIELD_DP32 (status,ERROR_STATUS ,CMDINVAL ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,CMDINVAL ); }if (FIELD_EX32 (val32,ERROR_STATUS ,CSIDINVAL )) { - status =FIELD_DP32 (status,ERROR_STATUS ,CSIDINVAL ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,CSIDINVAL ); }if (FIELD_EX32 (val32,ERROR_STATUS ,ACCESSINVAL )) { - status =FIELD_DP32 (status,ERROR_STATUS ,ACCESSINVAL ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,ACCESSINVAL ); } - s->regs[addr] = status;break ;case IBEX_SPI_HOST_EVENT_ENABLE :/* Controls which classes of SPI events raise an interrupt. */
Signature · 1 line
2.37.3
Re: [PATCH v3 2/2] hw/ssi/ibex_spi: implement `FIELD32_1CLEAR` macro
Quoted 9 lines · Wilfred Mallawa
From: Wilfred Mallawa <[email protected]>
use the
FIELD32_1CLEARmacro to implement registerrw1cfunctionality toibex_spi.This change was tested by running the
SPI_HOSTfrom TockOS.Signed-off-by Wilfred Mallawa <[email protected]>
Alistair
Quoted 70 lines
--- hw/ssi/ibex_spi_host.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)hw/ssi/ibex_spi_host.c +9
-13@@ -342,7 +342,7 @@ static void ibex_spi_host_write(void *opaque, hwaddr addr, {IbexSPIHostState *s = opaque;uint32_t val32 = val64; -uint32_t shift_mask =0xff , status =0 , data =0 ; +uint32_t shift_mask =0xff , status =0 ;uint8_t txqd_len;trace_ibex_spi_host_write (addr, size, val64);@@ -355,12 +355,11 @@ static void ibex_spi_host_write(void *opaque, hwaddr addr,case IBEX_SPI_HOST_INTR_STATE :/* rw1c status register */ if (FIELD_EX32 (val32,INTR_STATE ,ERROR )) { - data =FIELD_DP32 (data,INTR_STATE ,ERROR ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],INTR_STATE ,ERROR ); }if (FIELD_EX32 (val32,INTR_STATE ,SPI_EVENT )) { - data =FIELD_DP32 (data,INTR_STATE ,SPI_EVENT ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],INTR_STATE ,SPI_EVENT ); } - s->regs[addr] = data;break ;case IBEX_SPI_HOST_INTR_ENABLE : s->regs[addr] = val32;@@ -505,27 +504,25 @@ static void ibex_spi_host_write(void *opaque, hwaddr addr,* When an error occurs, the corresponding bit must be cleared * here before issuing any further commands */ - status = s->regs[addr];/* rw1c status register */ if (FIELD_EX32 (val32,ERROR_STATUS ,CMDBUSY )) { - status =FIELD_DP32 (status,ERROR_STATUS ,CMDBUSY ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,CMDBUSY ); }if (FIELD_EX32 (val32,ERROR_STATUS ,OVERFLOW )) { - status =FIELD_DP32 (status,ERROR_STATUS ,OVERFLOW ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,OVERFLOW ); }if (FIELD_EX32 (val32,ERROR_STATUS ,UNDERFLOW )) { - status =FIELD_DP32 (status,ERROR_STATUS ,UNDERFLOW ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,UNDERFLOW ); }if (FIELD_EX32 (val32,ERROR_STATUS ,CMDINVAL )) { - status =FIELD_DP32 (status,ERROR_STATUS ,CMDINVAL ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,CMDINVAL ); }if (FIELD_EX32 (val32,ERROR_STATUS ,CSIDINVAL )) { - status =FIELD_DP32 (status,ERROR_STATUS ,CSIDINVAL ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,CSIDINVAL ); }if (FIELD_EX32 (val32,ERROR_STATUS ,ACCESSINVAL )) { - status =FIELD_DP32 (status,ERROR_STATUS ,ACCESSINVAL ,0 ); + s->regs[addr] =FIELD32_1CLEAR (s->regs[addr],ERROR_STATUS ,ACCESSINVAL ); } - s->regs[addr] = status;break ;case IBEX_SPI_HOST_EVENT_ENABLE :/* Controls which classes of SPI events raise an interrupt. */ --2.37.3
Alistair Francis
AppliedQuoted 14 lines · Wilfred Mallawa
From: Wilfred Mallawa <[email protected]>
This patch series implements a
FIELDx_1CLEAR()macro and implements it in thehw/ssi/ibex_spi.cmodel.*** Changelog ***Since v2:
- change the macro arguments name to match the existing macros.
(reg_val, reg, field) -> (storage, reg, field)- Add the use of this macro to
ibex_spi
Quoted 8 lines
Since v1:
- Instead of needing all field bits to be set we clear the field if any are set. If the field is 0/clear then no change.Wilfred Mallawa (2):
hw/registerfields: addFIELDx_1CLEAR()macro hw/ssi/ibex_spi: implementFIELD32_1CLEARmacro
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 9 lines
hw/ssi/ibex_spi_host.c | 21 +++++++++------------ include/hw/registerfields.h | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-)--
2.37.3