diff --git a/libgralloc-qsd8k/gralloc.cpp b/libgralloc-qsd8k/gralloc.cpp index ab574a7..bfade0a 100755 --- a/libgralloc-qsd8k/gralloc.cpp +++ b/libgralloc-qsd8k/gralloc.cpp @@ -108,6 +108,14 @@ class PmemAllocatorDepsDeviceImpl : public PmemUserspaceAllocator::Deps, return ioctl(fd, PMEM_ALLOCATE_ALIGNED, &allocation); } + virtual int cleanPmem(int fd, unsigned long base, int offset, size_t size) { + struct pmem_addr pmem_addr; + pmem_addr.vaddr = base; + pmem_addr.offset = offset; + pmem_addr.length = size; + return ioctl(fd, PMEM_CLEAN_INV_CACHES, &pmem_addr); + } + virtual int getErrno() { return errno; } diff --git a/libgralloc-qsd8k/pmemalloc.cpp b/libgralloc-qsd8k/pmemalloc.cpp index fa5fc4b..f7f9059 100755 --- a/libgralloc-qsd8k/pmemalloc.cpp +++ b/libgralloc-qsd8k/pmemalloc.cpp @@ -181,6 +181,8 @@ int PmemUserspaceAllocator::alloc_pmem_buffer(size_t size, int usage, } else { LOGV("%s: mapped fd %d at offset %d, size %d", pmemdev, fd, offset, size); memset((char*)base + offset, 0, size); + //Clean cache before flushing to ensure pmem is properly flushed + deps.cleanPmem(fd, (unsigned long) base, offset, size); #ifdef HOST cacheflush(intptr_t(base) + offset, intptr_t(base) + offset + size, 0); #endif diff --git a/libgralloc-qsd8k/pmemalloc.h b/libgralloc-qsd8k/pmemalloc.h index c64d9be..2a1c6fd 100755 --- a/libgralloc-qsd8k/pmemalloc.h +++ b/libgralloc-qsd8k/pmemalloc.h @@ -69,6 +69,7 @@ class PmemUserspaceAllocator: public PmemAllocator { virtual int connectPmem(int fd, int master_fd) = 0; virtual int mapPmem(int fd, int offset, size_t size) = 0; virtual int unmapPmem(int fd, int offset, size_t size) = 0; + virtual int cleanPmem(int fd, unsigned long base, int offset, size_t size) = 0; // C99 virtual int getErrno() = 0;