diff options
author | nia <nia@NetBSD.org> | 2024-05-04 02:12:26 +0200 |
---|---|---|
committer | nia <nia@NetBSD.org> | 2024-05-04 02:12:26 +0200 |
commit | 1f81004bfc32e1200dc2224a73831248f5d38eeb (patch) | |
tree | 47e57d7548cb44ef74858eb06ba175215672dacc | |
parent | 8e5a43d2481cc5e31358f648e3e8adb1f4467dc1 (diff) |
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 <nia@NetBSD.org>
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-video-ati/-/merge_requests/22>
-rw-r--r-- | src/radeon_accel.c | 25 |
1 files changed, 24 insertions, 1 deletions
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; |