From 0e03d3bc704da949da044519c32ecf9b6e09de09 Mon Sep 17 00:00:00 2001 From: Yandong Lin Date: Fri, 12 Jan 2024 10:10:34 +0800 Subject: [PATCH] fix[mpp_dmabuf]: fix align cache line size calculate err Signed-off-by: Yandong Lin Change-Id: Ide7daa58b12b22dc115acbbb7a9b8e305a167d57 --- osal/inc/mpp_common.h | 1 + osal/mpp_dmabuf.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/osal/inc/mpp_common.h b/osal/inc/mpp_common.h index b4d29e01..60a0b20f 100644 --- a/osal/inc/mpp_common.h +++ b/osal/inc/mpp_common.h @@ -40,6 +40,7 @@ #define MPP_SWAP(type, a, b) do {type SWAP_tmp = b; b = a; a = SWAP_tmp;} while(0) #define MPP_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) #define MPP_ALIGN(x, a) (((x)+(a)-1)&~((a)-1)) +#define MPP_ALIGN_DOWN(x, a) ((x)&~((a)-1)) #define MPP_ALIGN_GEN(x, a) (((x)+(a)-1)/(a)*(a)) #define MPP_VSWAP(a, b) { a ^= b; b ^= a; a ^= b; } diff --git a/osal/mpp_dmabuf.cpp b/osal/mpp_dmabuf.cpp index 8140a883..c800dc6e 100644 --- a/osal/mpp_dmabuf.cpp +++ b/osal/mpp_dmabuf.cpp @@ -72,8 +72,8 @@ MPP_RET mpp_dmabuf_sync_partial_begin(RK_S32 fd, RK_S32 ro, RK_U32 offset, RK_U3 return MPP_OK; sync.flags = DMA_BUF_SYNC_START | (ro ? DMA_BUF_SYNC_READ : DMA_BUF_SYNC_RW); - sync.offset = offset / CACHE_LINE_SIZE; - sync.len = MPP_ALIGN(length, CACHE_LINE_SIZE); + sync.offset = MPP_ALIGN_DOWN(offset, CACHE_LINE_SIZE); + sync.len = MPP_ALIGN(length + offset - sync.offset, CACHE_LINE_SIZE); ret = ioctl(fd, DMA_BUF_IOCTL_SYNC_PARTIAL, &sync); if (ret) { @@ -103,8 +103,8 @@ MPP_RET mpp_dmabuf_sync_partial_end(RK_S32 fd, RK_S32 ro, RK_U32 offset, RK_U32 return MPP_OK; sync.flags = DMA_BUF_SYNC_END | (ro ? DMA_BUF_SYNC_READ : DMA_BUF_SYNC_RW); - sync.offset = offset / CACHE_LINE_SIZE; - sync.len = MPP_ALIGN(length, CACHE_LINE_SIZE); + sync.offset = MPP_ALIGN_DOWN(offset, CACHE_LINE_SIZE); + sync.len = MPP_ALIGN(length + offset - sync.offset, CACHE_LINE_SIZE); ret = ioctl(fd, DMA_BUF_IOCTL_SYNC_PARTIAL, &sync); if (ret) {