From c0f1d7592013f52544f5dde393b39ad751b56272 Mon Sep 17 00:00:00 2001 From: Dima Zavin Date: Tue, 2 Mar 2010 15:09:54 -0800 Subject: [PATCH] libgralloc-qsd8k: flush SW_WRITE cached pmem regions in unlock Change-Id: I31d1257f031c6b9b8dae604c2c1a8aa246ce3b84 Signed-off-by: Dima Zavin --- libgralloc-qsd8k/gralloc_priv.h | 1 + libgralloc-qsd8k/mapper.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/libgralloc-qsd8k/gralloc_priv.h b/libgralloc-qsd8k/gralloc_priv.h index d74c1f2..28ea79b 100644 --- a/libgralloc-qsd8k/gralloc_priv.h +++ b/libgralloc-qsd8k/gralloc_priv.h @@ -71,6 +71,7 @@ struct private_handle_t { enum { PRIV_FLAGS_FRAMEBUFFER = 0x00000001, PRIV_FLAGS_USES_PMEM = 0x00000002, + PRIV_FLAGS_NEEDS_FLUSH = 0x00000004, }; enum { diff --git a/libgralloc-qsd8k/mapper.cpp b/libgralloc-qsd8k/mapper.cpp index d79d9fa..9e9fad0 100644 --- a/libgralloc-qsd8k/mapper.cpp +++ b/libgralloc-qsd8k/mapper.cpp @@ -235,6 +235,13 @@ int gralloc_lock(gralloc_module_t const* module, hnd->writeOwner = gettid(); } + // if requesting sw write for non-framebuffer handles, flag for + // flushing at unlock + if ((usage & GRALLOC_USAGE_SW_WRITE_MASK) && + !(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) { + hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH; + } + if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) { if (!(current_value & private_handle_t::LOCK_STATE_MAPPED)) { // we need to map for real @@ -264,6 +271,18 @@ int gralloc_unlock(gralloc_module_t const* module, private_handle_t* hnd = (private_handle_t*)handle; int32_t current_value, new_value; + if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) { + struct pmem_region region; + int err; + + region.offset = hnd->offset; + region.len = hnd->size; + err = ioctl(hnd->fd, PMEM_CACHE_FLUSH, ®ion); + LOGE_IF(err < 0, "cannot flush handle %p (offs=%x len=%x)\n", + hnd, hnd->offset, hnd->size); + hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH; + } + do { current_value = hnd->lockState; new_value = current_value;