From 1f81004bfc32e1200dc2224a73831248f5d38eeb Mon Sep 17 00:00:00 2001 From: nia Date: Sat, 4 May 2024 02:12:26 +0200 Subject: radeon_accel: Avoid unaligned access in RADEONCopySwap from NetBSD (via Martin Husemann), this helps the radeon driver work on sparc64 hardware. Signed-off-by: Nia Alarie Part-of: --- src/radeon_accel.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/radeon_accel.c b/src/radeon_accel.c index 8d4e76a5..a0dca68c 100644 --- a/src/radeon_accel.c +++ b/src/radeon_accel.c @@ -142,7 +142,30 @@ void RADEONCopySwap(uint8_t *dst, uint8_t *src, unsigned int size, int swap) return; } case RADEON_HOST_DATA_SWAP_32BIT: - { + if (((uintptr_t)dst & 1) || ((uintptr_t)src & 1)) { + uint8_t *d = (uint8_t *)dst; + uint8_t *s = (uint8_t *)src; + unsigned int nwords = size >> 2; + + for (; nwords > 0; --nwords, d+=4, s+=4) { + d[0] = s[3]; + d[1] = s[2]; + d[2] = s[1]; + d[3] = s[0]; + } + return; + } else if (((uintptr_t)dst & 3) || ((uintptr_t)src & 3)) { + /* copy 16bit wise */ + uint16_t *d = (uint16_t *)dst; + uint16_t *s = (uint16_t *)src; + unsigned int nwords = size >> 2; + + for (; nwords > 0; --nwords, d+=2, s+=2) { + d[0] = ((s[1] >> 8) & 0xff) | ((s[1] & 0xff) << 8); + d[1] = ((s[0] >> 8) & 0xff) | ((s[0] & 0xff) << 8); + } + return; + } else { unsigned int *d = (unsigned int *)dst; unsigned int *s = (unsigned int *)src; unsigned int nwords = size >> 2; -- cgit v1.2.3 From b65036af74bbb5084587d3d5743b8b97292235bc Mon Sep 17 00:00:00 2001 From: nia Date: Sat, 4 May 2024 02:47:08 +0200 Subject: Avoid namespace collision: rename bswap_XX to radeon_bswap_XX xorg-server includes its own bswap_16, bswap_32 etc macros in its misc.h. This is transcluded after radeon.h in some files. If the operating system defines bswap_XX in a way that is unsuitable for a function name (e.g. on NetBSD), this results in build failures. Signed-off-by: Nia Alarie Part-of: --- configure.ac | 6 +++--- src/radeon.h | 25 ++++++++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 58fb50eb..d44a2dda 100644 --- a/configure.ac +++ b/configure.ac @@ -254,11 +254,11 @@ b = bswap16(a); if test "$USE_SYS_ENDIAN_H" = "yes" ; then AC_DEFINE([USE_SYS_ENDIAN_H], 1, [Define to use byteswap macros from ]) - AC_DEFINE_UNQUOTED([bswap_16], ${BSWAP}16, + AC_DEFINE_UNQUOTED([radeon_bswap_16], ${BSWAP}16, [Define to 16-bit byteswap macro]) - AC_DEFINE_UNQUOTED([bswap_32], ${BSWAP}32, + AC_DEFINE_UNQUOTED([radeon_bswap_32], ${BSWAP}32, [Define to 32-bit byteswap macro]) - AC_DEFINE_UNQUOTED([bswap_64], ${BSWAP}64, + AC_DEFINE_UNQUOTED([radeon_bswap_64], ${BSWAP}64, [Define to 64-bit byteswap macro]) fi fi diff --git a/src/radeon.h b/src/radeon.h index 68d7756a..6d1d21ee 100644 --- a/src/radeon.h +++ b/src/radeon.h @@ -125,27 +125,30 @@ RegionDuplicate(RegionPtr pOld) #if HAVE_BYTESWAP_H #include +#define radeon_bswap_16 bswap_16 +#define radeon_bswap_32 bswap_32 +#define radeon_bswap_64 bswap_64 #elif defined(USE_SYS_ENDIAN_H) #include #else -#define bswap_16(value) \ +#define radeon_bswap_16(value) \ ((((value) & 0xff) << 8) | ((value) >> 8)) -#define bswap_32(value) \ - (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \ - (uint32_t)bswap_16((uint16_t)((value) >> 16))) +#define radeon_bswap_32(value) \ + (((uint32_t)radeon_bswap_16((uint16_t)((value) & 0xffff)) << 16) | \ + (uint32_t)radeon_bswap_16((uint16_t)((value) >> 16))) -#define bswap_64(value) \ - (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \ +#define radeon_bswap_64(value) \ + (((uint64_t)radeon_bswap_32((uint32_t)((value) & 0xffffffff)) \ << 32) | \ - (uint64_t)bswap_32((uint32_t)((value) >> 32))) + (uint64_t)radeon_bswap_32((uint32_t)((value) >> 32))) #endif #if X_BYTE_ORDER == X_BIG_ENDIAN -#define le32_to_cpu(x) bswap_32(x) -#define le16_to_cpu(x) bswap_16(x) -#define cpu_to_le32(x) bswap_32(x) -#define cpu_to_le16(x) bswap_16(x) +#define le32_to_cpu(x) radeon_bswap_32(x) +#define le16_to_cpu(x) radeon_bswap_16(x) +#define cpu_to_le32(x) radeon_bswap_32(x) +#define cpu_to_le16(x) radeon_bswap_16(x) #else #define le32_to_cpu(x) (x) #define le16_to_cpu(x) (x) -- cgit v1.2.3