Hello Yu-Ping Wu, Julius Werner, build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35463
to look at the new patch set (#4).
Change subject: device/mmio.h: Add bit field helpers ......................................................................
device/mmio.h: Add bit field helpers
When accessing register with multiple bit fields, the common approach is to use clrsetbits_le32, for example:
clrsetbits(®, (1 << 0) | (0x3 << 1) | (0x7 << 10), (1 << 0) | (0x1 << 1) | (0x5 << 10));
This hard to maintain because we have to calculate the mask values manually, make sure the duplicated shift (offset) was set correctly. And it may be even worse if the value to set will be based on some runtime values (that many developers will do a if-block with two very similar argument list), and leaving lots of magic numbers.
We want to encourage developers always giving field names, and have a better way of setting fields. The proposed utility macros are:
DEFINE_BITFIELD(name, start, end) SET_BITFIELDS(addr, name, value, [name2, value2, ...])
Where a developer can easily convert from data sheet like
BITS NAME 26:24 SEC_VIO
Into a declaration
DEFINE_BITFIELD(SEC_VIO, 26, 24)
Then, a simple call can set the field as:
SET_BITFIELDS(®, SEC_VIO, 2);
That is much easier to understand than
clrsetbits(®, 0x7 << 24, 0x2 << 24);
Change-Id: I8a1b17142f7a7dc6c441b0b1ee67d60d73ec8cc8 Signed-off-by: Hung-Te Lin hungte@chromium.org --- M src/include/device/mmio.h 1 file changed, 81 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/63/35463/4