mmio: Fix failure in bit field macro when accessing >30 bits
For bit fields with 31 bits (e.g: DEFINE_BITFIELD(MYREG, 30, 0) ), the calculation of mask value will go overflow: "error: integer overflow in expression '-2147483648 - 1' of type 'int' results in '2147483647'". And for bit fields with 32 bits (e.g: DEFINE_BITFIELD(MYREG, 31, 0) ), the error will be: "error: left shift count >= width of type [-Werror=shift-count-overflow]" To fix these issues, the bit field macros should always use unsigned integers, and use 64bit integer when creating mask value. Change-Id: Ie3cddf9df60b83de4e21243bfde6b79729fb06ef Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/40404 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
parent
38e386f2d0
commit
85ecdb1471
|
@ -131,10 +131,10 @@ static inline void buffer_to_fifo32(void *buffer, size_t size, void *fifo,
|
|||
#define DEFINE_BIT(name, bit) DEFINE_BITFIELD(name, bit, bit)
|
||||
|
||||
#define _BF_MASK(name, value) \
|
||||
(((1 << name##_BITFIELD_SIZE) - 1) << name##_BITFIELD_SHIFT)
|
||||
((u32)((1ULL << name##_BITFIELD_SIZE) - 1) << name##_BITFIELD_SHIFT)
|
||||
|
||||
#define _BF_VALUE(name, value) \
|
||||
((value) << name##_BITFIELD_SHIFT)
|
||||
(((u32)(value) << name##_BITFIELD_SHIFT) & _BF_MASK(name, 0))
|
||||
|
||||
#define _BF_APPLY1(op, name, value, ...) (op(name, value))
|
||||
#define _BF_APPLY2(op, name, value, ...) ((op(name, value)) | \
|
||||
|
|
Loading…
Reference in New Issue