Hello Patrick Rudolph,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/32856
to review the following change.
Change subject: endian.h: Add be32dec/be32enc family of functions ......................................................................
endian.h: Add be32dec/be32enc family of functions
Libpayload has a family of functions that can "encode" or "decode" an endian-specific integer onto a byte stream pointer. These allow writing more pretty code than a raw be32_to_cpu/cpu_to_be32 with pointer casts in many (de-)serialization scenarios, so let's add them to coreboot as well.
Change-Id: I049c5665484da12b3cf977a529310b0bde177d2d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/include/endian.h 1 file changed, 24 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/56/32856/1
diff --git a/src/include/endian.h b/src/include/endian.h index 08636f3..4bd30f1 100644 --- a/src/include/endian.h +++ b/src/include/endian.h @@ -84,6 +84,30 @@ #define clrbits_8(addr, clear) clrsetbits_8(addr, clear, 0) #define setbits_8(addr, set) setbits_8(addr, 0, set)
+/* be16dec/be32dec/be64dec/le16dec/le32dec/le64dec family of functions. */ +#define DEFINE_ENDIAN_DEC(endian, width) \ + static inline uint##width##_t endian##width##dec(const void *p) { \ + return endian##width##_to_cpu(*(uint##width##_t *)p); \ + } +DEFINE_ENDIAN_DEC(be, 16) +DEFINE_ENDIAN_DEC(be, 32) +DEFINE_ENDIAN_DEC(be, 64) +DEFINE_ENDIAN_DEC(le, 16) +DEFINE_ENDIAN_DEC(le, 32) +DEFINE_ENDIAN_DEC(le, 64) + +/* be16enc/be32enc/be64enc/le16enc/le32enc/le64enc family of functions. */ +#define DEFINE_ENDIAN_ENC(endian, width) \ + static inline void endian##width##enc(void *p, uint##width##_t u) { \ + *(uint##width##_t *)p = cpu_to_##endian##width(u); \ + } +DEFINE_ENDIAN_ENC(be, 16) +DEFINE_ENDIAN_ENC(be, 32) +DEFINE_ENDIAN_ENC(be, 64) +DEFINE_ENDIAN_ENC(le, 16) +DEFINE_ENDIAN_ENC(le, 32) +DEFINE_ENDIAN_ENC(le, 64) + #ifndef __ROMCC__ /* * Portable (API) endian support that can be used in code that is shared
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32856 )
Change subject: endian.h: Add be32dec/be32enc family of functions ......................................................................
Patch Set 1:
(1 comment)
https://review.coreboot.org/#/c/32856/1/src/include/endian.h File src/include/endian.h:
https://review.coreboot.org/#/c/32856/1/src/include/endian.h@101 PS1, Line 101: static inline void endian##width##enc(void *p, uint##width##_t u) { \ open brace '{' following function definitions go on the next line
Hello Aaron Durbin, Patrick Rudolph, build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32856
to look at the new patch set (#2).
Change subject: endian.h: Add be32dec/be32enc family of functions ......................................................................
endian.h: Add be32dec/be32enc family of functions
Libpayload has a family of functions that can "encode" or "decode" an endian-specific integer onto a byte stream pointer. These allow writing more pretty code than a raw be32_to_cpu/cpu_to_be32 with pointer casts in many (de-)serialization scenarios, so let's add them to coreboot as well.
Change-Id: I049c5665484da12b3cf977a529310b0bde177d2d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/include/endian.h 1 file changed, 26 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/56/32856/2
Hello Aaron Durbin, Patrick Rudolph, build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32856
to look at the new patch set (#3).
Change subject: endian.h: Add be32dec/be32enc family of functions ......................................................................
endian.h: Add be32dec/be32enc family of functions
Libpayload has a family of functions that can "encode" or "decode" an endian-specific integer onto a byte stream pointer. These allow writing more pretty code than a raw be32_to_cpu/cpu_to_be32 with pointer casts in many (de-)serialization scenarios, so let's add them to coreboot as well.
Change-Id: I049c5665484da12b3cf977a529310b0bde177d2d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/include/endian.h 1 file changed, 26 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/56/32856/3
Aaron Durbin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32856 )
Change subject: endian.h: Add be32dec/be32enc family of functions ......................................................................
Patch Set 4: Code-Review+2
Patrick Georgi has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/32856 )
Change subject: endian.h: Add be32dec/be32enc family of functions ......................................................................
endian.h: Add be32dec/be32enc family of functions
Libpayload has a family of functions that can "encode" or "decode" an endian-specific integer onto a byte stream pointer. These allow writing more pretty code than a raw be32_to_cpu/cpu_to_be32 with pointer casts in many (de-)serialization scenarios, so let's add them to coreboot as well.
Change-Id: I049c5665484da12b3cf977a529310b0bde177d2d Signed-off-by: Julius Werner jwerner@chromium.org Reviewed-on: https://review.coreboot.org/c/coreboot/+/32856 Reviewed-by: Aaron Durbin adurbin@chromium.org Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M src/include/endian.h 1 file changed, 26 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Aaron Durbin: Looks good to me, approved
diff --git a/src/include/endian.h b/src/include/endian.h index 08636f3..8dc1854 100644 --- a/src/include/endian.h +++ b/src/include/endian.h @@ -85,6 +85,32 @@ #define setbits_8(addr, set) setbits_8(addr, 0, set)
#ifndef __ROMCC__ +/* be16dec/be32dec/be64dec/le16dec/le32dec/le64dec family of functions. */ +#define DEFINE_ENDIAN_DEC(endian, width) \ + static inline uint##width##_t endian##width##dec(const void *p) \ + { \ + return endian##width##_to_cpu(*(uint##width##_t *)p); \ + } +DEFINE_ENDIAN_DEC(be, 16) +DEFINE_ENDIAN_DEC(be, 32) +DEFINE_ENDIAN_DEC(be, 64) +DEFINE_ENDIAN_DEC(le, 16) +DEFINE_ENDIAN_DEC(le, 32) +DEFINE_ENDIAN_DEC(le, 64) + +/* be16enc/be32enc/be64enc/le16enc/le32enc/le64enc family of functions. */ +#define DEFINE_ENDIAN_ENC(endian, width) \ + static inline void endian##width##enc(void *p, uint##width##_t u) \ + { \ + *(uint##width##_t *)p = cpu_to_##endian##width(u); \ + } +DEFINE_ENDIAN_ENC(be, 16) +DEFINE_ENDIAN_ENC(be, 32) +DEFINE_ENDIAN_ENC(be, 64) +DEFINE_ENDIAN_ENC(le, 16) +DEFINE_ENDIAN_ENC(le, 32) +DEFINE_ENDIAN_ENC(le, 64) + /* * Portable (API) endian support that can be used in code that is shared * with userspace (man 3 endian) tools.