coreboot/src/include
Hung-Te Lin 0962b1fa5d 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(&reg, (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, high_bit, low_bit)
 EXTRACT_BITFIELD(value, name)
 WRITE32_BITFIELDS(addr, name, value, [name2, value2, ...])
 READ32_BITFIELD(addr, name)

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:

 WRITE32_BITFIELDS(&reg, SEC_VIO, 2);

That is much easier to understand than

 clrsetbits_le32(&reg, 0x7 << 24, 0x2 << 24);

And to extract the value:

 READ32_BITFIELD(&reg, SEC_VIO)

That is equivalent to:

 (read32(&reg) & 0x3) >> 24

Change-Id: I8a1b17142f7a7dc6c441b0b1ee67d60d73ec8cc8
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35463
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2019-09-24 10:32:50 +00:00
..
boot
console console: Allow using vprintk() with disabled console 2019-06-11 17:29:02 +00:00
cpu cpu/x86/lapic: Refactor timer_fsb() 2019-09-19 09:28:55 +00:00
device device/mmio.h: Add bit field helpers 2019-09-24 10:32:50 +00:00
efi
pc80
smp
superio superio: Add ASpeed AST2400 2019-05-24 07:22:23 +00:00
sys
adainit.h
assert.h src/include/assert.h: add noreturn attribute to dead_code() 2019-05-17 07:16:50 +00:00
b64_decode.h
base3.h
bcd.h
boardid.h
boot_device.h boot_device: Constify argument 2019-05-12 07:47:45 +00:00
bootblock_common.h lib/bootblock: Add simplified entry with basetime 2019-08-26 21:11:31 +00:00
bootmem.h lib/bootmem: Prepare for OpenSBI 2019-07-31 10:57:30 +00:00
bootmode.h
bootsplash.h lib/coreboot_table: Show splashscreen in lb_table_init 2019-09-15 11:10:58 +00:00
bootstate.h
cbfs.h
cbmem.h arch/x86: Remove acpi_fail_wakeup() and cbmem_fail_resume() 2019-09-14 10:55:34 +00:00
cper.h
ctype.h add ctype.h header 2019-06-24 21:15:14 +00:00
delay.h cpu/x86/lapic: Refactor timer_fsb() 2019-09-19 09:28:55 +00:00
device_tree.h device_tree: Update comment style to C89 2019-06-21 09:23:19 +00:00
dimm_info_util.h
edid.h lib: edid: Move manufacturer name from private extra to public info 2019-08-15 03:04:08 +00:00
elog.h drivers/elog: Add elog_boot_notify() 2019-09-13 09:58:33 +00:00
endian.h endian.h: Add be32dec/be32enc family of functions 2019-05-23 08:42:44 +00:00
fallback.h
fit.h fit: Add overlay support 2019-06-21 09:22:31 +00:00
fit_payload.h
fmap.h lib/fmap: Add area read/write functions 2019-04-23 10:22:54 +00:00
gic.h
gpio.h
halt.h
imd.h
inttypes.h include, lib: Add <inttypes.h> printf macros 2019-08-10 08:47:08 +00:00
ip_checksum.h
kconfig.h kconfig: Drop IS_ENABLED() macro 2019-06-04 13:33:40 +00:00
lib.h
list.h
main_decl.h
memlayout.h src/: Replace some __PRE_RAM__ use 2019-09-14 11:16:17 +00:00
memory_info.h src/soc/intel/common/smbios: Add addtional infos to dimm_info 2019-06-06 11:32:52 +00:00
memrange.h
mrc_cache.h
nhlt.h
option.h
program_loading.h lib/bootmem: Prepare for OpenSBI 2019-07-31 10:57:30 +00:00
ramdetect.h lib: ramdetect: Register exception handlers for ARMv8 2019-08-26 07:14:03 +00:00
random.h
reg_script.h
region_file.h
reset.h
rmodule.h
romstage_handoff.h
rtc.h
rules.h security/vboot: Fix regression with VBOOT_STARTS_IN_ROMSTAGE 2019-09-17 08:17:23 +00:00
sar.h
sdram_mode.h
smbios.h src/arch/x86: Add automatic type41 entry creation 2019-05-28 11:52:27 +00:00
smmstore.h
spd.h
spd_bin.h lib/spd_bin: Extend DDR4 spd information 2019-09-09 13:30:10 +00:00
spd_ddr2.h
spi-generic.h drivers/spi/spi_flash.c: Add SPI vendor IDs 2019-09-04 22:40:46 +00:00
spi_bitbang.h
spi_flash.h spi_flash: Add Dual SPI support 2019-06-10 18:02:33 +00:00
stage_cache.h lib/stage_cache: Refactor Kconfig options 2019-08-08 04:50:33 +00:00
stddef.h Split MAYBE_STATIC to _BSS and _NONZERO variants 2019-08-26 20:56:29 +00:00
stdint.h include, lib: Add <inttypes.h> printf macros 2019-08-10 08:47:08 +00:00
stdlib.h
string.h string: implement strspn, strcspn, atol 2019-08-10 01:32:19 +00:00
swab.h
symbols.h x86: Introduce RESET_VECTOR_IN_RAM option 2019-08-26 22:53:07 +00:00
thread.h src/: Replace some __PRE_RAM__ use 2019-09-14 11:16:17 +00:00
timer.h
timestamp.h timestamps: Remove TIMESTAMP_CACHE_IN_BSS 2019-09-13 19:48:26 +00:00
trace.h lib/trace: Replace __PRE_RAM__ use 2019-09-23 21:38:50 +00:00
types.h ec/google/chromeec: Update ec_commands.h 2019-08-23 20:22:04 +00:00
uuid.h
vbe.h src/device/oprom: Fix bootsplash display code for optionroms 2019-07-26 08:40:23 +00:00
version.h
watchdog.h
wrdd.h