* [RFC v2] hw/registerfields: add `FIELDx_1CLEAR()` macro
@ 2022-09-27 0:54 Wilfred Mallawa
2022-10-10 1:29 ` Alistair Francis
0 siblings, 1 reply; 3+ messages in thread
From: Wilfred Mallawa @ 2022-09-27 0:54 UTC (permalink / raw)
To: alistair; +Cc: qemu-devel, Wilfred Mallawa
From: Wilfred Mallawa <wilfred.mallawa@wdc.com>
Changes from 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.
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.
Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
---
include/hw/registerfields.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/include/hw/registerfields.h b/include/hw/registerfields.h
index 1330ca77de..4a6a228339 100644
--- a/include/hw/registerfields.h
+++ b/include/hw/registerfields.h
@@ -115,6 +115,28 @@
R_ ## reg ## _ ## field ## _LENGTH, _v.v); \
_d; })
+/*
+ * Clear the specified field in reg_val if
+ * any field bits are set, else no changes made. Implements
+ * single/multi-bit `w1c`
+ *
+ */
+#define FIELD8_1CLEAR(reg_val, reg, field) \
+ (FIELD_EX8(reg_val, reg, field) ? \
+ FIELD_DP8(reg_val, reg, field, 0x00) : reg_val)
+
+#define FIELD16_1CLEAR(reg_val, reg, field) \
+ (FIELD_EX16(reg_val, reg, field) ? \
+ FIELD_DP16(reg_val, reg, field, 0x00) : reg_val)
+
+#define FIELD32_1CLEAR(reg_val, reg, field) \
+ (FIELD_EX32(reg_val, reg, field) ? \
+ FIELD_DP32(reg_val, reg, field, 0x00) : reg_val)
+
+#define FIELD64_1CLEAR(reg_val, reg, field) \
+ (FIELD_EX64(reg_val, reg, field) ? \
+ FIELD_DP64(reg_val, reg, field, 0x00) : reg_val)
+
#define FIELD_SDP8(storage, reg, field, val) ({ \
struct { \
signed int v:R_ ## reg ## _ ## field ## _LENGTH; \
--
2.37.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC v2] hw/registerfields: add `FIELDx_1CLEAR()` macro
2022-09-27 0:54 [RFC v2] hw/registerfields: add `FIELDx_1CLEAR()` macro Wilfred Mallawa
@ 2022-10-10 1:29 ` Alistair Francis
2022-10-10 1:53 ` Wilfred Mallawa
0 siblings, 1 reply; 3+ messages in thread
From: Alistair Francis @ 2022-10-10 1:29 UTC (permalink / raw)
To: Wilfred Mallawa; +Cc: alistair, qemu-devel, Wilfred Mallawa
On Tue, Sep 27, 2022 at 10:58 AM Wilfred Mallawa
<wilfred.mallawa@opensource.wdc.com> wrote:
>
> From: Wilfred Mallawa <wilfred.mallawa@wdc.com>
>
> Changes from 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.
The changelog should go
>
> 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.
>
> Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
> ---
Below this line.
Otherwise the patch looks good. Do you mind adding it to a series that
converts the OT SPI to use these macros?
> include/hw/registerfields.h | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/include/hw/registerfields.h b/include/hw/registerfields.h
> index 1330ca77de..4a6a228339 100644
> --- a/include/hw/registerfields.h
> +++ b/include/hw/registerfields.h
> @@ -115,6 +115,28 @@
> R_ ## reg ## _ ## field ## _LENGTH, _v.v); \
> _d; })
>
> +/*
> + * Clear the specified field in reg_val if
> + * any field bits are set, else no changes made. Implements
> + * single/multi-bit `w1c`
> + *
> + */
> +#define FIELD8_1CLEAR(reg_val, reg, field) \
These should probably match the other macros with:
(storage, reg, field)
Alistair
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC v2] hw/registerfields: add `FIELDx_1CLEAR()` macro
2022-10-10 1:29 ` Alistair Francis
@ 2022-10-10 1:53 ` Wilfred Mallawa
0 siblings, 0 replies; 3+ messages in thread
From: Wilfred Mallawa @ 2022-10-10 1:53 UTC (permalink / raw)
To: wilfred.mallawa, alistair23; +Cc: alistair, qemu-devel
On Mon, 2022-10-10 at 11:29 +1000, Alistair Francis wrote:
> On Tue, Sep 27, 2022 at 10:58 AM Wilfred Mallawa
> <wilfred.mallawa@opensource.wdc.com> wrote:
> >
> > From: Wilfred Mallawa <wilfred.mallawa@wdc.com>
> >
> > Changes from 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.
>
> The changelog should go
>
> >
> > 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.
> >
> > Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
> > ---
>
> Below this line.
>
> Otherwise the patch looks good. Do you mind adding it to a series
> that
> converts the OT SPI to use these macros?
>
Yep, that sounds good. I'll send a new series with this + SPI changes
with the macro implemented.
> > include/hw/registerfields.h | 22 ++++++++++++++++++++++
> > 1 file changed, 22 insertions(+)
> >
> > diff --git a/include/hw/registerfields.h
> > b/include/hw/registerfields.h
> > index 1330ca77de..4a6a228339 100644
> > --- a/include/hw/registerfields.h
> > +++ b/include/hw/registerfields.h
> > @@ -115,6 +115,28 @@
> > R_ ## reg ## _ ## field ## _LENGTH,
> > _v.v); \
> > _d; })
> >
> > +/*
> > + * Clear the specified field in reg_val if
> > + * any field bits are set, else no changes made. Implements
> > + * single/multi-bit `w1c`
> > + *
> > + */
> > +#define FIELD8_1CLEAR(reg_val, reg,
> > field) \
>
> These should probably match the other macros with:
>
> (storage, reg, field)
>
Will do!
> Alistair
Wilferd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-10 1:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27 0:54 [RFC v2] hw/registerfields: add `FIELDx_1CLEAR()` macro Wilfred Mallawa
2022-10-10 1:29 ` Alistair Francis
2022-10-10 1:53 ` Wilfred Mallawa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).