From a03e5456e68d8937f4c43ec112c1495ae26a6356 Mon Sep 17 00:00:00 2001 From: Yu-Ping Wu Date: Mon, 30 Sep 2024 14:45:48 +0800 Subject: libpayload/endian: Add read32p/write32p macros and friends Add {read,write}{8,16,32,64}p macros and similar macros for clrsetbits, setbits and clrbits. Change-Id: If01e38663ffc1c08c553850d3210604c9b240655 Signed-off-by: Yu-Ping Wu Reviewed-on: https://review.coreboot.org/c/coreboot/+/84592 Tested-by: build bot (Jenkins) Reviewed-by: Yidi Lin --- payloads/libpayload/include/endian.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'payloads') diff --git a/payloads/libpayload/include/endian.h b/payloads/libpayload/include/endian.h index 35fe0fd283..fd59af1b5c 100644 --- a/payloads/libpayload/include/endian.h +++ b/payloads/libpayload/include/endian.h @@ -193,6 +193,16 @@ static inline void le64enc(void *pp, uint32_t u) #define letohl(in) le32toh(in) #define letohll(in) le64toh(in) +/* read/write with uintptr_t address */ +#define read8p(addr) read8((void *)((uintptr_t)(addr))) +#define read16p(addr) read16((void *)((uintptr_t)(addr))) +#define read32p(addr) read32((void *)((uintptr_t)(addr))) +#define read64p(addr) read64((void *)((uintptr_t)(addr))) +#define write8p(addr, value) write8((void *)((uintptr_t)(addr)), value) +#define write16p(addr, value) write16((void *)((uintptr_t)(addr)), value) +#define write32p(addr, value) write32((void *)((uintptr_t)(addr)), value) +#define write64p(addr, value) write64((void *)((uintptr_t)(addr)), value) + /* Handy bit manipulation macros */ #define __clrsetbits(endian, bits, addr, clear, set) \ @@ -238,4 +248,19 @@ static inline void le64enc(void *pp, uint32_t u) #define clrbits32(addr, clear) clrsetbits32(addr, clear, 0) #define clrbits64(addr, clear) clrsetbits64(addr, clear, 0) +#define clrsetbits8p(addr, clear, set) clrsetbits8((void *)((uintptr_t)(addr)), clear, set) +#define clrsetbits16p(addr, clear, set) clrsetbits16((void *)((uintptr_t)(addr)), clear, set) +#define clrsetbits32p(addr, clear, set) clrsetbits32((void *)((uintptr_t)(addr)), clear, set) +#define clrsetbits64p(addr, clear, set) clrsetbits64((void *)((uintptr_t)(addr)), clear, set) + +#define setbits8p(addr, set) clrsetbits8((void *)((uintptr_t)(addr)), 0, set) +#define setbits16p(addr, set) clrsetbits16((void *)((uintptr_t)(addr)), 0, set) +#define setbits32p(addr, set) clrsetbits32((void *)((uintptr_t)(addr)), 0, set) +#define setbits64p(addr, set) clrsetbits64((void *)((uintptr_t)(addr)), 0, set) + +#define clrbits8p(addr, clear) clrsetbits8((void *)((uintptr_t)(addr)), clear, 0) +#define clrbits16p(addr, clear) clrsetbits16((void *)((uintptr_t)(addr)), clear, 0) +#define clrbits32p(addr, clear) clrsetbits32((void *)((uintptr_t)(addr)), clear, 0) +#define clrbits64p(addr, clear) clrsetbits64((void *)((uintptr_t)(addr)), clear, 0) + #endif /* _ENDIAN_H_ */ -- cgit v1.2.3