diff options
author | Sean Callanan <spyffe@google.com> | 2021-04-28 16:02:04 -0700 |
---|---|---|
committer | Sean Callanan <spyffe@google.com> | 2021-04-29 09:53:10 -0700 |
commit | 04198b0eb43d28aa4d8e4e985986b69c24d564d0 (patch) | |
tree | 8ce2677484d90977bd385e2f1c8dcd1d56d1bbd0 /gralloc4 | |
parent | 9f647cc0361d5c61056c07e34583115fe5bd2b48 (diff) | |
download | gchips-04198b0eb43d28aa4d8e4e985986b69c24d564d0.tar.gz |
gralloc4: sync ion buffers around CPU usage
mali_gralloc_ion_sync is called if BOARD_USES_GRALLOC_ION_SYNC is set,
but currently the implementation is empty. Added an implementation that
passes through to libdmabufheap's sync interface.
Test: Set camera permissions to "Ask every time"; reboot; launch camera
Test: RealCalc
Fixes: 185289225
Fixes: 186613737
Fixes: 183735780
Change-Id: I8425d2d94c0202fa2dabf8ff60d66bc8d40b6b86
Diffstat (limited to 'gralloc4')
-rw-r--r-- | gralloc4/src/allocator/mali_gralloc_ion.cpp | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/gralloc4/src/allocator/mali_gralloc_ion.cpp b/gralloc4/src/allocator/mali_gralloc_ion.cpp index 3b45c39..afb6620 100644 --- a/gralloc4/src/allocator/mali_gralloc_ion.cpp +++ b/gralloc4/src/allocator/mali_gralloc_ion.cpp @@ -127,6 +127,21 @@ struct ion_device */ int alloc_from_ion_heap(uint64_t usage, size_t size, unsigned int flags, int *min_pgsz); + /* + * Signals the start or end of a region where the CPU is accessing a + * buffer, allowing appropriate cache synchronization. + * + * @param fd [in] fd for the buffer + * @param read [in] True if the CPU is reading from the buffer + * @param write [in] True if the CPU is writing to the buffer + * @param start [in] True if the CPU has not yet performed the + * operations; false if the operations are + * completed. + * + * @return 0 on success; an error code otherwise. + */ + int sync(int fd, bool read, bool write, bool start); + private: int ion_client; std::unique_ptr<BufferAllocator> buffer_allocator; @@ -390,16 +405,65 @@ int ion_device::open_and_query_ion() return 0; } +static SyncType sync_type_for_flags(const bool read, const bool write) +{ + if (read && !write) + { + return SyncType::kSyncRead; + } + else if (write && !read) + { + return SyncType::kSyncWrite; + } + else + { + // Deliberately also allowing "not sure" to map to ReadWrite. + return SyncType::kSyncReadWrite; + } +} + +int ion_device::sync(const int fd, const bool read, const bool write, const bool start) +{ + if (!buffer_allocator) + { + return -1; + } + + if (start) + { + return buffer_allocator->CpuSyncStart(fd, sync_type_for_flags(read, write)); + } + else + { + return buffer_allocator->CpuSyncEnd(fd, sync_type_for_flags(read, write)); + } +} + static int mali_gralloc_ion_sync(const private_handle_t * const hnd, - const bool /* read */, - const bool /* write */, - const bool /* start */) + const bool read, + const bool write, + const bool start) { if (hnd == NULL) { return -EINVAL; } + ion_device *dev = ion_device::get(); + if (!dev) + { + return -1; + } + + for (int i = 0; i < hnd->fd_count; i++) + { + const int fd = hnd->fds[i]; + if (const int ret = dev->sync(fd, read, write, start)) + { + return ret; + } + } + return 0; } |