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) {