summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnkit Goyal <layog@google.com>2023-04-07 20:52:17 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-04-07 20:52:17 +0000
commitcb7b2c0643e7eec8c59183ebdd0b1b64be56bc85 (patch)
tree31d7d476cb6102f3ab456f50d642d45b86dfaadf
parenta4d55d053ef4691e428388815e26b15148b2b71a (diff)
parent4180098644e9f51ed1b4ce6c0581035c65883461 (diff)
downloadgchips-cb7b2c0643e7eec8c59183ebdd0b1b64be56bc85.tar.gz
Merge changes from topic "gralloc-no-ion" into udc-dev
* changes: gralloc4: Choose framebuffer-secure for FB if available gralloc4: Remove redundant ion_device class and stale comments gralloc4: Remove dependence on libion_google gralloc4: Import system and vscaler heap from libion gralloc4: Remove dead code from ion
-rw-r--r--gralloc4/src/4.x/Android.bp1
-rw-r--r--gralloc4/src/4.x/GrallocMapper.cpp9
-rw-r--r--gralloc4/src/Android.bp1
-rw-r--r--gralloc4/src/aidl/GrallocAllocator.cpp4
-rw-r--r--gralloc4/src/allocator/Android.bp1
-rw-r--r--gralloc4/src/allocator/mali_gralloc_ion.cpp524
-rw-r--r--gralloc4/src/allocator/mali_gralloc_ion.h3
7 files changed, 99 insertions, 444 deletions
diff --git a/gralloc4/src/4.x/Android.bp b/gralloc4/src/4.x/Android.bp
index 88c7a01..16eec6a 100644
--- a/gralloc4/src/4.x/Android.bp
+++ b/gralloc4/src/4.x/Android.bp
@@ -50,7 +50,6 @@ cc_defaults {
"liblog",
"libcutils",
"libdmabufheap",
- "libion_google",
"libsync",
"libutils",
"libnativewindow",
diff --git a/gralloc4/src/4.x/GrallocMapper.cpp b/gralloc4/src/4.x/GrallocMapper.cpp
index e0ac1de..c0b5f5f 100644
--- a/gralloc4/src/4.x/GrallocMapper.cpp
+++ b/gralloc4/src/4.x/GrallocMapper.cpp
@@ -35,14 +35,9 @@ using android::hardware::hidl_vec;
using android::hardware::Void;
-GrallocMapper::GrallocMapper()
-{
-}
+GrallocMapper::GrallocMapper() {}
-GrallocMapper::~GrallocMapper()
-{
- mali_gralloc_ion_close();
-}
+GrallocMapper::~GrallocMapper() {}
Return<void> GrallocMapper::createDescriptor(const BufferDescriptorInfo &descriptorInfo, createDescriptor_cb hidl_cb)
{
diff --git a/gralloc4/src/Android.bp b/gralloc4/src/Android.bp
index 3511d12..a813fc8 100644
--- a/gralloc4/src/Android.bp
+++ b/gralloc4/src/Android.bp
@@ -68,7 +68,6 @@ cc_library_shared {
"libhidlbase",
"libhidltransport",
"libnativewindow",
- "libion_google",
"android.hardware.graphics.common@1.2",
"android.hardware.graphics.common-V4-ndk",
"android.hardware.graphics.mapper@4.0",
diff --git a/gralloc4/src/aidl/GrallocAllocator.cpp b/gralloc4/src/aidl/GrallocAllocator.cpp
index d7addc5..6945505 100644
--- a/gralloc4/src/aidl/GrallocAllocator.cpp
+++ b/gralloc4/src/aidl/GrallocAllocator.cpp
@@ -24,9 +24,7 @@ unsigned long callingPid() {
GrallocAllocator::GrallocAllocator() {}
-GrallocAllocator::~GrallocAllocator() {
- mali_gralloc_ion_close();
-}
+GrallocAllocator::~GrallocAllocator() {}
ndk::ScopedAStatus GrallocAllocator::allocate(const std::vector<uint8_t>& descriptor, int32_t count,
AidlAllocator::AllocationResult* result) {
diff --git a/gralloc4/src/allocator/Android.bp b/gralloc4/src/allocator/Android.bp
index 7a3cb31..fe42411 100644
--- a/gralloc4/src/allocator/Android.bp
+++ b/gralloc4/src/allocator/Android.bp
@@ -86,7 +86,6 @@ arm_gralloc_allocator_cc_defaults {
"liblog",
"libcutils",
"libdmabufheap",
- "libion_google",
"libsync",
"libutils",
"libnativewindow",
diff --git a/gralloc4/src/allocator/mali_gralloc_ion.cpp b/gralloc4/src/allocator/mali_gralloc_ion.cpp
index bfd92d7..8bfc6d8 100644
--- a/gralloc4/src/allocator/mali_gralloc_ion.cpp
+++ b/gralloc4/src/allocator/mali_gralloc_ion.cpp
@@ -29,7 +29,6 @@
#include <cutils/atomic.h>
#include <utils/Trace.h>
-
#include <linux/dma-buf.h>
#include <vector>
#include <sys/ioctl.h>
@@ -37,9 +36,6 @@
#include <hardware/hardware.h>
#include <hardware/gralloc1.h>
-#include <hardware/exynos/ion.h>
-#include <hardware/exynos/dmabuf_container.h>
-
#include <BufferAllocator/BufferAllocator.h>
#include "mali_gralloc_buffer.h"
#include "gralloc_helper.h"
@@ -54,17 +50,6 @@
#include <array>
#include <string>
-#define INIT_ZERO(obj) (memset(&(obj), 0, sizeof((obj))))
-
-#define HEAP_MASK_FROM_ID(id) (1 << id)
-#define HEAP_MASK_FROM_TYPE(type) (1 << type)
-
-#if defined(ION_HEAP_SECURE_MASK)
-#if (HEAP_MASK_FROM_TYPE(ION_HEAP_TYPE_SECURE) != ION_HEAP_SECURE_MASK)
-#error "ION_HEAP_TYPE_SECURE value is not compatible with ION_HEAP_SECURE_MASK"
-#endif
-#endif
-
static const char kDmabufSensorDirectHeapName[] = "sensor_direct_heap";
static const char kDmabufFaceauthTpuHeapName[] = "faceauth_tpu-secure";
static const char kDmabufFaceauthImgHeapName[] = "faimg-secure";
@@ -73,298 +58,144 @@ static const char kDmabufFaceauthPrevHeapName[] = "faprev-secure";
static const char kDmabufFaceauthModelHeapName[] = "famodel-secure";
static const char kDmabufVframeSecureHeapName[] = "vframe-secure";
static const char kDmabufVstreamSecureHeapName[] = "vstream-secure";
+static const char kDmabufVscalerSecureHeapName[] = "vscaler-secure";
+static const char kDmabufFramebufferSecureHeapName[] = "framebuffer-secure";
-struct ion_device
-{
- int client()
- {
- return ion_client;
- }
-
- static void close()
- {
- ion_device &dev = get_inst();
- if (dev.ion_client >= 0)
- {
- exynos_ion_close(dev.ion_client);
- dev.ion_client = -1;
- }
-
- dev.buffer_allocator.reset();
- }
-
- static ion_device *get()
- {
- ion_device &dev = get_inst();
- if (!dev.buffer_allocator)
- {
- dev.buffer_allocator = std::make_unique<BufferAllocator>();
- if (!dev.buffer_allocator)
- ALOGE("Unable to create BufferAllocator object");
- }
-
- if (dev.ion_client < 0)
- {
- if (dev.open_and_query_ion() != 0)
- {
- close();
- }
- }
-
- if (dev.ion_client < 0)
- {
- return nullptr;
- }
- return &dev;
- }
-
- /*
- * Identifies a heap and retrieves file descriptor from ION for allocation
- *
- * @param usage [in] Producer and consumer combined usage.
- * @param size [in] Requested buffer size (in bytes).
- * @param heap_type [in] Requested heap type.
- * @param flags [in] ION allocation attributes defined by ION_FLAG_*.
- * @param min_pgsz [out] Minimum page size (in bytes).
- * @buffer_name [in] Optional name specifying what the buffer is for.
- *
- * @return File handle which can be used for allocation, on success
- * -1, otherwise.
- */
- int alloc_from_ion_heap(uint64_t usage, size_t size, unsigned int flags, int *min_pgsz,
- const std::string& buffer_name = std::string());
-
- /*
- * 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;
-
- ion_device()
- : ion_client(-1)
- {
- }
-
- static ion_device& get_inst()
- {
- static ion_device dev;
- return dev;
- }
-
- /*
- * Opens the ION module. Queries heap information and stores it for later use
- *
- * @return 0 in case of success
- * -1 for all error cases
- */
- int open_and_query_ion();
-
- /*
- * Allocates in the DMA-BUF heap with name @heap_name. If allocation fails from
- * the DMA-BUF heap or if it does not exist, falls back to an ION heap of the
- * same name.
- *
- * @param heap_name [in] DMA-BUF heap name for allocation
- * @param size [in] Requested buffer size (in bytes).
- * @param flags [in] ION allocation attributes defined by ION_FLAG_* to
- * be used for ION allocations. Will not be used with
- * DMA-BUF heaps since the framework does not support
- * allocation flags.
- * @buffer_name [in] Name specifying what the buffer is for.
- *
- * @return fd of the allocated buffer on success, -1 otherwise;
- */
-
- int alloc_from_dmabuf_heap(const std::string& heap_name, size_t size, unsigned int flags,
- const std::string& buffer_name);
-};
-
-static void set_ion_flags(uint64_t usage, unsigned int *ion_flags)
-{
- if (ion_flags == nullptr)
- return;
+BufferAllocator& get_allocator() {
+ static BufferAllocator allocator;
+ return allocator;
+}
- if ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN)
- {
- *ion_flags |= ION_FLAG_CACHED;
- }
+std::string find_first_available_heap(const std::initializer_list<std::string>&& options) {
+ static auto available_heaps = BufferAllocator::GetDmabufHeapList();
- // DRM or Secure Camera
- if (usage & (GRALLOC_USAGE_PROTECTED))
- {
- *ion_flags |= ION_FLAG_PROTECTED;
- }
+ for (const auto& heap: options)
+ if (available_heaps.find(heap) != available_heaps.end())
+ return heap;
- /* TODO: used for exynos3830. Add this as an option to Android.bp */
-#if defined(GRALLOC_SCALER_WFD) && GRALLOC_SCALER_WFD == 1
- if (usage & GRALLOC_USAGE_PRIVATE_NONSECURE && usage & GRALLOC_USAGE_HW_COMPOSER)
- {
- *ion_flags |= ION_FLAG_PROTECTED;
- }
-#endif
- /* Sensor direct channels require uncached allocations. */
- if (usage & GRALLOC_USAGE_SENSOR_DIRECT_DATA)
- {
- *ion_flags &= ~ION_FLAG_CACHED;
- }
+ return "";
}
-static unsigned int select_faceauth_heap_mask(uint64_t usage)
+std::string select_dmabuf_heap(uint64_t usage)
{
struct HeapSpecifier
{
- uint64_t usage_bits; // exact match required
- unsigned int mask;
+ uint64_t usage_bits;
+ std::string name;
};
- static constexpr std::array<HeapSpecifier, 5> faceauth_heaps =
+ static const std::array<HeapSpecifier, 6> exact_usage_heaps =
{{
+ // Faceauth heaps
{ // isp_image_heap
GRALLOC_USAGE_PROTECTED | GRALLOC_USAGE_HW_CAMERA_WRITE | GS101_GRALLOC_USAGE_TPU_INPUT,
- EXYNOS_ION_HEAP_FA_IMG_MASK
+ kDmabufFaceauthImgHeapName
},
{ // isp_internal_heap
GRALLOC_USAGE_PROTECTED | GRALLOC_USAGE_HW_CAMERA_WRITE | GRALLOC_USAGE_HW_CAMERA_READ,
- EXYNOS_ION_HEAP_FA_RAWIMG_MASK
+ kDmabufFaceauthRawImgHeapName
},
{ // isp_preview_heap
GRALLOC_USAGE_PROTECTED | GRALLOC_USAGE_HW_CAMERA_WRITE | GRALLOC_USAGE_HW_COMPOSER |
GRALLOC_USAGE_HW_TEXTURE,
- EXYNOS_ION_HEAP_FA_PREV_MASK
+ kDmabufFaceauthPrevHeapName
},
{ // ml_model_heap
GRALLOC_USAGE_PROTECTED | GS101_GRALLOC_USAGE_TPU_INPUT,
- EXYNOS_ION_HEAP_FA_MODEL_MASK
+ kDmabufFaceauthModelHeapName
},
{ // tpu_heap
GRALLOC_USAGE_PROTECTED | GS101_GRALLOC_USAGE_TPU_OUTPUT | GS101_GRALLOC_USAGE_TPU_INPUT,
- EXYNOS_ION_HEAP_FA_TPU_MASK
- }
- }};
+ kDmabufFaceauthTpuHeapName
+ },
- for (const HeapSpecifier &heap : faceauth_heaps)
- {
- if (usage == heap.usage_bits)
{
- ALOGV("Using FaceAuth heap mask 0x%x for usage 0x%" PRIx64 "\n",
- heap.mask, usage);
- return heap.mask;
- }
- }
+ GRALLOC_USAGE_PROTECTED | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
+ GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB,
+ find_first_available_heap({kDmabufFramebufferSecureHeapName, kDmabufVframeSecureHeapName})
+ },
+ }};
- return 0;
-}
+ static const std::array<HeapSpecifier, 6> inexact_usage_heaps =
+ {{
+ // If GPU, use vframe-secure
+ {
+ GRALLOC_USAGE_PROTECTED | GRALLOC_USAGE_HW_TEXTURE,
+ kDmabufVframeSecureHeapName
+ },
+ {
+ GRALLOC_USAGE_PROTECTED | GRALLOC_USAGE_HW_RENDER,
+ kDmabufVframeSecureHeapName
+ },
-static unsigned int select_heap_mask(uint64_t usage)
-{
- if (unsigned int faceauth_heap_mask = select_faceauth_heap_mask(usage);
- faceauth_heap_mask != 0)
- {
- return faceauth_heap_mask;
- }
+ // If HWC but not GPU
+ {
+ GRALLOC_USAGE_PROTECTED | GRALLOC_USAGE_HW_COMPOSER,
+ kDmabufVscalerSecureHeapName
+ },
- unsigned int heap_mask;
+ // Catchall for protected
+ {
+ GRALLOC_USAGE_PROTECTED,
+ kDmabufVframeSecureHeapName
+ },
- if (usage & GRALLOC_USAGE_PROTECTED)
- {
- if (usage & GRALLOC_USAGE_PRIVATE_NONSECURE)
+ // Sensor heap
{
- heap_mask = EXYNOS_ION_HEAP_SYSTEM_MASK;
- }
- else if ((usage & GRALLOC_USAGE_HW_COMPOSER) &&
- !(usage & GRALLOC_USAGE_HW_TEXTURE) &&
- !(usage & GRALLOC_USAGE_HW_RENDER))
+ GRALLOC_USAGE_SENSOR_DIRECT_DATA,
+ kDmabufSensorDirectHeapName
+ },
+
+ // Catchall to system
{
- heap_mask = EXYNOS_ION_HEAP_VIDEO_SCALER_MASK;
+ 0,
+ kDmabufSystemUncachedHeapName
}
- else
+ }};
+
+ for (const HeapSpecifier &heap : exact_usage_heaps)
+ {
+ if (usage == heap.usage_bits)
{
- heap_mask = EXYNOS_ION_HEAP_VIDEO_FRAME_MASK;
+ return heap.name;
}
}
- /* TODO: used for exynos3830. Add this as a an option to Android.bp */
-#if defined(GRALLOC_SCALER_WFD) && GRALLOC_SCALER_WFD == 1
- else if (usage & GRALLOC_USAGE_PRIVATE_NONSECURE && usage & GRALLOC_USAGE_HW_COMPOSER)
- {
- heap_mask = EXYNOS_ION_HEAP_EXT_UI_MASK;
- }
-#endif
- else if (usage & GRALLOC_USAGE_SENSOR_DIRECT_DATA)
- {
- heap_mask = EXYNOS_ION_HEAP_SENSOR_DIRECT_MASK;
- }
- else
+
+ for (const HeapSpecifier &heap : inexact_usage_heaps)
{
- heap_mask = EXYNOS_ION_HEAP_SYSTEM_MASK;
+ if ((usage & heap.usage_bits) == heap.usage_bits)
+ {
+ if (heap.name == kDmabufSystemUncachedHeapName &&
+ ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN))
+ return kDmabufSystemHeapName;
+
+ return heap.name;
+ }
}
- return heap_mask;
+ return "";
}
-/*
- * Selects a DMA-BUF heap name.
- *
- * @param heap_mask [in] heap_mask for which the equivalent DMA-BUF heap
- * name must be found.
- *
- * @return the name of the DMA-BUF heap equivalent to the ION heap of mask
- * @heap_mask.
- *
- */
-static std::string select_dmabuf_heap(unsigned int heap_mask)
+int alloc_from_dmabuf_heap(uint64_t usage, size_t size, const std::string& buffer_name = "")
{
- switch (heap_mask) {
- case EXYNOS_ION_HEAP_SENSOR_DIRECT_MASK:
- return kDmabufSensorDirectHeapName;
- case EXYNOS_ION_HEAP_FA_TPU_MASK:
- return kDmabufFaceauthTpuHeapName;
- case EXYNOS_ION_HEAP_FA_IMG_MASK:
- return kDmabufFaceauthImgHeapName;
- case EXYNOS_ION_HEAP_FA_RAWIMG_MASK:
- return kDmabufFaceauthRawImgHeapName;
- case EXYNOS_ION_HEAP_FA_PREV_MASK:
- return kDmabufFaceauthPrevHeapName;
- case EXYNOS_ION_HEAP_FA_MODEL_MASK:
- return kDmabufFaceauthModelHeapName;
- case EXYNOS_ION_HEAP_VIDEO_FRAME_MASK:
- return kDmabufVframeSecureHeapName;
- case EXYNOS_ION_HEAP_VIDEO_STREAM_MASK:
- return kDmabufVstreamSecureHeapName;
- default:
- return {};
- }
-}
+ ATRACE_CALL();
+ if (size == 0) { return -1; }
-int ion_device::alloc_from_dmabuf_heap(const std::string& heap_name, size_t size,
- unsigned int flags, const std::string& buffer_name)
-{
- ATRACE_NAME(("alloc_from_dmabuf_heap " + heap_name).c_str());
- if (!buffer_allocator)
- {
- return -1;
+ auto heap_name = select_dmabuf_heap(usage);
+ if (heap_name.empty()) {
+ MALI_GRALLOC_LOGW("No heap found for usage: %s (0x%" PRIx64 ")", describe_usage(usage).c_str(), usage);
+ return -EINVAL;
}
- int shared_fd = buffer_allocator->Alloc(heap_name, size, flags);
+ ATRACE_NAME(("alloc_from_dmabuf_heap " + heap_name).c_str());
+ int shared_fd = get_allocator().Alloc(heap_name, size, 0);
if (shared_fd < 0)
{
ALOGE("Allocation failed for heap %s error: %d\n", heap_name.c_str(), shared_fd);
}
if (!buffer_name.empty()) {
- if (buffer_allocator->DmabufSetName(shared_fd, buffer_name)) {
+ if (get_allocator().DmabufSetName(shared_fd, buffer_name)) {
ALOGW("Unable to set buffer name %s: %s", buffer_name.c_str(), strerror(errno));
}
}
@@ -372,58 +203,7 @@ int ion_device::alloc_from_dmabuf_heap(const std::string& heap_name, size_t size
return shared_fd;
}
-int ion_device::alloc_from_ion_heap(uint64_t usage, size_t size, unsigned int flags, int *min_pgsz,
- const std::string& buffer_name)
-{
- ATRACE_CALL();
- /* TODO: remove min_pgsz? I don't think this is useful on Exynos */
- if (size == 0 || min_pgsz == NULL)
- {
- return -1;
- }
-
- unsigned int heap_mask = select_heap_mask(usage);
-
- int shared_fd;
- auto dmabuf_heap_name = select_dmabuf_heap(heap_mask);
- if (!dmabuf_heap_name.empty())
- {
- shared_fd = alloc_from_dmabuf_heap(dmabuf_heap_name, size, flags, buffer_name);
- }
- else
- {
- if (ion_client < 0)
- {
- return -1;
- }
-
- shared_fd = exynos_ion_alloc(ion_client, size, heap_mask, flags);
- }
-
- *min_pgsz = SZ_4K;
-
- return shared_fd;
-}
-
-int ion_device::open_and_query_ion()
-{
- if (ion_client >= 0)
- {
- MALI_GRALLOC_LOGW("ION device already open");
- return 0;
- }
-
- ion_client = exynos_ion_open();
- if (ion_client < 0)
- {
- MALI_GRALLOC_LOGE("ion_open failed with %s", strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-static SyncType sync_type_for_flags(const bool read, const bool write)
+SyncType sync_type_for_flags(const bool read, const bool write)
{
if (read && !write)
{
@@ -440,24 +220,19 @@ static SyncType sync_type_for_flags(const bool read, const bool write)
}
}
-int ion_device::sync(const int fd, const bool read, const bool write, const bool start)
+int 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));
+ return get_allocator().CpuSyncStart(fd, sync_type_for_flags(read, write));
}
else
{
- return buffer_allocator->CpuSyncEnd(fd, sync_type_for_flags(read, write));
+ return get_allocator().CpuSyncEnd(fd, sync_type_for_flags(read, write));
}
}
-static int mali_gralloc_ion_sync(const private_handle_t * const hnd,
+int mali_gralloc_ion_sync(const private_handle_t * const hnd,
const bool read,
const bool write,
const bool start)
@@ -467,16 +242,10 @@ static int mali_gralloc_ion_sync(const private_handle_t * const hnd,
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))
+ if (const int ret = sync(fd, read, write, start))
{
return ret;
}
@@ -486,16 +255,6 @@ static int mali_gralloc_ion_sync(const private_handle_t * const hnd,
}
-/*
- * Signal start of CPU access to the DMABUF exported from ION.
- *
- * @param hnd [in] Buffer handle
- * @param read [in] Flag indicating CPU read access to memory
- * @param write [in] Flag indicating CPU write access to memory
- *
- * @return 0 in case of success
- * errno for all error cases
- */
int mali_gralloc_ion_sync_start(const private_handle_t * const hnd,
const bool read,
const bool write)
@@ -504,16 +263,6 @@ int mali_gralloc_ion_sync_start(const private_handle_t * const hnd,
}
-/*
- * Signal end of CPU access to the DMABUF exported from ION.
- *
- * @param hnd [in] Buffer handle
- * @param read [in] Flag indicating CPU read access to memory
- * @param write [in] Flag indicating CPU write access to memory
- *
- * @return 0 in case of success
- * errno for all error cases
- */
int mali_gralloc_ion_sync_end(const private_handle_t * const hnd,
const bool read,
const bool write)
@@ -544,7 +293,7 @@ void mali_gralloc_ion_free(private_handle_t * const hnd)
delete hnd;
}
-static void mali_gralloc_ion_free_internal(buffer_handle_t * const pHandle,
+void mali_gralloc_ion_free_internal(buffer_handle_t * const pHandle,
const uint32_t num_hnds)
{
for (uint32_t i = 0; i < num_hnds; i++)
@@ -560,23 +309,14 @@ static void mali_gralloc_ion_free_internal(buffer_handle_t * const pHandle,
int mali_gralloc_ion_allocate_attr(private_handle_t *hnd)
{
ATRACE_CALL();
- ion_device *dev = ion_device::get();
- if (!dev)
- {
- return -1;
- }
int idx = hnd->get_share_attr_fd_index();
- int ion_flags = 0;
- int min_pgsz;
uint64_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
- ion_flags = ION_FLAG_CACHED;
-
- hnd->fds[idx] = dev->alloc_from_ion_heap(usage, hnd->attr_size, ion_flags, &min_pgsz);
+ hnd->fds[idx] = alloc_from_dmabuf_heap(usage, hnd->attr_size);
if (hnd->fds[idx] < 0)
{
- MALI_GRALLOC_LOGE("ion_alloc failed from client ( %d )", dev->client());
+ MALI_GRALLOC_LOGE("ion_alloc failed");
return -1;
}
@@ -605,36 +345,24 @@ int mali_gralloc_ion_allocate(const gralloc_buffer_descriptor_t *descriptors,
unsigned int priv_heap_flag = 0;
uint64_t usage;
uint32_t i;
- unsigned int ion_flags = 0;
- int min_pgsz = 0;
int fds[MAX_FDS];
std::fill(fds, fds + MAX_FDS, -1);
- ion_device *dev = ion_device::get();
- if (!dev)
- {
- return -1;
- }
-
for (i = 0; i < numDescriptors; i++)
{
buffer_descriptor_t *bufDescriptor = (buffer_descriptor_t *)(descriptors[i]);
usage = bufDescriptor->consumer_usage | bufDescriptor->producer_usage;
- ion_flags = 0;
- set_ion_flags(usage, &ion_flags);
-
for (int fidx = 0; fidx < bufDescriptor->fd_count; fidx++)
{
if (ion_fd >= 0 && fidx == 0) {
fds[fidx] = ion_fd;
} else {
- fds[fidx] = dev->alloc_from_ion_heap(usage, bufDescriptor->alloc_sizes[fidx], ion_flags,
- &min_pgsz, bufDescriptor->name);
+ fds[fidx] = alloc_from_dmabuf_heap(usage, bufDescriptor->alloc_sizes[fidx], bufDescriptor->name);
}
if (fds[fidx] < 0)
{
- MALI_GRALLOC_LOGE("ion_alloc failed from client ( %d )", dev->client());
+ MALI_GRALLOC_LOGE("ion_alloc failed");
for (int cidx = 0; cidx < fidx; cidx++)
{
@@ -692,7 +420,7 @@ int mali_gralloc_ion_allocate(const gralloc_buffer_descriptor_t *descriptors,
if (MAP_FAILED == cpu_ptr)
{
- MALI_GRALLOC_LOGE("mmap failed from client ( %d ), fd ( %d )", dev->client(), hnd->fds[0]);
+ MALI_GRALLOC_LOGE("mmap failed for fd ( %d )", hnd->fds[0]);
mali_gralloc_ion_free_internal(pHandle, numDescriptors);
return -1;
}
@@ -721,7 +449,6 @@ int mali_gralloc_ion_allocate(const gralloc_buffer_descriptor_t *descriptors,
return 0;
}
-
int mali_gralloc_ion_map(private_handle_t *hnd)
{
uint64_t usage = hnd->producer_usage | hnd->consumer_usage;
@@ -760,59 +487,6 @@ int mali_gralloc_ion_map(private_handle_t *hnd)
return 0;
}
-int import_exynos_ion_handles(private_handle_t *hnd)
-{
- int retval = -1;
-
- ion_device *dev = ion_device::get();
-
- for (int idx = 0; idx < hnd->fd_count; idx++)
- {
- if (hnd->fds[idx] >= 0)
- {
- retval = exynos_ion_import_handle(dev->client(), hnd->fds[idx], &hnd->ion_handles[idx]);
- if (retval)
- {
- MALI_GRALLOC_LOGE("error importing ion_handle. ion_client(%d), ion_handle[%d](%d) format(%s %#" PRIx64 ")",
- dev->client(), idx, hnd->ion_handles[idx], format_name(hnd->alloc_format), hnd->alloc_format);
- goto error;
- }
- }
- }
-
- return retval;
-
-error:
- for (int idx = 0; idx < hnd->fd_count; idx++)
- {
- if (hnd->ion_handles[idx])
- {
- exynos_ion_free_handle(dev->client(), hnd->ion_handles[idx]);
- }
- }
-
- return retval;
-}
-
-void free_exynos_ion_handles(private_handle_t *hnd)
-{
- ion_device *dev = ion_device::get();
-
- for (int idx = 0; idx < hnd->fd_count; idx++)
- {
- if (hnd->ion_handles[idx])
- {
- if (hnd->ion_handles[idx] &&
- exynos_ion_free_handle(dev->client(), hnd->ion_handles[idx]))
- {
- MALI_GRALLOC_LOGE("error freeing ion_handle. ion_client(%d), ion_handle[%d](%d) format(%s %#" PRIx64 ")",
- dev->client(), idx, hnd->ion_handles[idx], format_name(hnd->alloc_format), hnd->alloc_format);
- }
- }
- }
-}
-
-
void mali_gralloc_ion_unmap(private_handle_t *hnd)
{
for (int i = 0; i < hnd->fd_count; i++)
@@ -838,9 +512,3 @@ void mali_gralloc_ion_unmap(private_handle_t *hnd)
hnd->cpu_read = 0;
hnd->cpu_write = 0;
}
-
-void mali_gralloc_ion_close(void)
-{
- ion_device::close();
-}
-
diff --git a/gralloc4/src/allocator/mali_gralloc_ion.h b/gralloc4/src/allocator/mali_gralloc_ion.h
index 3877c5e..5f55c2f 100644
--- a/gralloc4/src/allocator/mali_gralloc_ion.h
+++ b/gralloc4/src/allocator/mali_gralloc_ion.h
@@ -32,9 +32,6 @@ int mali_gralloc_ion_sync_end(const private_handle_t * const hnd,
const bool read, const bool write);
int mali_gralloc_ion_map(private_handle_t *hnd);
void mali_gralloc_ion_unmap(private_handle_t *hnd);
-void mali_gralloc_ion_close(void);
int mali_gralloc_attr_allocate(void);
-int import_exynos_ion_handles(private_handle_t *hnd);
-void free_exynos_ion_handles(private_handle_t *hnd);
#endif /* MALI_GRALLOC_ION_H_ */