summaryrefslogtreecommitdiff
path: root/gralloc
diff options
context:
space:
mode:
Diffstat (limited to 'gralloc')
-rw-r--r--gralloc/Android.bp16
-rw-r--r--gralloc/Android.mk4
-rw-r--r--gralloc/alloc_device.cpp206
-rw-r--r--gralloc/dma-heap.h53
4 files changed, 203 insertions, 76 deletions
diff --git a/gralloc/Android.bp b/gralloc/Android.bp
index a198df52..aaca7cbd 100644
--- a/gralloc/Android.bp
+++ b/gralloc/Android.bp
@@ -1,6 +1,18 @@
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "device_linaro_hikey_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ // SPDX-license-identifier-GPL-2.0
+ default_applicable_licenses: ["device_linaro_hikey_license"],
+}
+
cc_library_shared {
name: "hwcomposer.drm_hikey",
defaults: ["hwcomposer.drm_defaults"],
- srcs: [":drm_hwcomposer_platformhisi"],
- whole_static_libs: ["drm_hwcomposer"],
+ srcs: [
+ ":drm_hwcomposer_common",
+ ":drm_hwcomposer_platformhisi",
+ ],
}
diff --git a/gralloc/Android.mk b/gralloc/Android.mk
index 23a5a820..947a184c 100644
--- a/gralloc/Android.mk
+++ b/gralloc/Android.mk
@@ -29,6 +29,8 @@ LOCAL_VENDOR_MODULE := true
MALI_DDK_TEST_PATH := hardware/arm/
LOCAL_MODULE := gralloc.hikey
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-GPL-2.0
+LOCAL_LICENSE_CONDITIONS := notice restricted
LOCAL_MODULE_RELATIVE_PATH := hw
#LOCAL_MODULE_TAGS := optional
@@ -52,8 +54,6 @@ LOCAL_SRC_FILES := \
#LOCAL_CFLAGS+= -DMALI_VSYNC_EVENT_REPORT_ENABLE
-ifeq ($(HIKEY_USE_DRM_HWCOMPOSER), true)
LOCAL_CFLAGS += -DDISABLE_FRAMEBUFFER_HAL
-endif
include $(BUILD_SHARED_LIBRARY)
diff --git a/gralloc/alloc_device.cpp b/gralloc/alloc_device.cpp
index b6bd69ea..f458a624 100644
--- a/gralloc/alloc_device.cpp
+++ b/gralloc/alloc_device.cpp
@@ -20,6 +20,9 @@
#include <string.h>
#include <errno.h>
#include <pthread.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <cutils/log.h>
#include <cutils/atomic.h>
@@ -41,10 +44,22 @@
#if GRALLOC_ARM_DMA_BUF_MODULE
#include <ion/ion.h>
#include "ion_4.12.h"
+#include "dma-heap.h"
#define ION_SYSTEM (char*)"ion_system_heap"
#define ION_CMA (char*)"linux,cma"
+#define DMABUF_SYSTEM (char*)"system"
+#define DMABUF_CMA (char*)"linux,cma"
+static enum {
+ INTERFACE_UNKNOWN,
+ INTERFACE_ION_LEGACY,
+ INTERFACE_ION_MODERN,
+ INTERFACE_DMABUF_HEAPS
+} interface_ver;
+
+static int system_heap_id;
+static int cma_heap_id;
#endif
#if GRALLOC_SIMULATE_FAILURES
@@ -119,12 +134,73 @@ static int fb_get_framebuffer_dmabuf(private_module_t *m, private_handle_t *hnd)
}
#endif
+#if GRALLOC_ARM_DMA_BUF_MODULE
+#define DEVPATH "/dev/dma_heap"
+int dma_heap_open(const char* name)
+{
+ int ret, fd;
+ char buf[256];
+
+ ret = sprintf(buf, "%s/%s", DEVPATH, name);
+ if (ret < 0) {
+ AERR("sprintf failed!\n");
+ return ret;
+ }
+
+ fd = open(buf, O_RDONLY);
+ if (fd < 0)
+ AERR("open %s failed!\n", buf);
+ return fd;
+}
+
+int dma_heap_alloc(int fd, size_t len, unsigned int flags, int *dmabuf_fd)
+{
+ struct dma_heap_allocation_data data = {
+ .len = len,
+ .fd_flags = O_RDWR | O_CLOEXEC,
+ .heap_flags = flags,
+ };
+ int ret;
+
+ if (dmabuf_fd == NULL)
+ return -EINVAL;
+
+ ret = ioctl(fd, DMA_HEAP_IOCTL_ALLOC, &data);
+ if (ret < 0)
+ return ret;
+ *dmabuf_fd = (int)data.fd;
+ return ret;
+}
+
+static int alloc_ion_fd(int ion_fd, size_t size, unsigned int heap_mask, unsigned int flags, int *shared_fd)
+{
+ int heap;
+
+ if (interface_ver == INTERFACE_DMABUF_HEAPS) {
+ int fd = system_heap_id;
+ unsigned long flg = 0;
+ if (heap_mask == ION_HEAP_TYPE_DMA_MASK)
+ fd = cma_heap_id;
+
+ return dma_heap_alloc(fd, size, flg, shared_fd);
+ }
+
+ if (interface_ver == INTERFACE_ION_MODERN) {
+ heap = 1 << system_heap_id;
+ if (heap_mask == ION_HEAP_TYPE_DMA_MASK)
+ heap = 1 << cma_heap_id;
+ } else {
+ heap = heap_mask;
+ }
+ return ion_alloc_fd(ion_fd, size, 0, heap, flags, shared_fd);
+}
+#endif
+
static int gralloc_alloc_buffer(alloc_device_t *dev, size_t size, int usage, buffer_handle_t *pHandle)
{
#if GRALLOC_ARM_DMA_BUF_MODULE
{
private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module);
- ion_user_handle_t ion_hnd;
void *cpu_ptr = MAP_FAILED;
int shared_fd;
int ret;
@@ -132,8 +208,7 @@ static int gralloc_alloc_buffer(alloc_device_t *dev, size_t size, int usage, buf
int lock_state = 0;
int map_mask = 0;
- if (usage & GRALLOC_USAGE_PROTECTED)
- {
+ if (usage & GRALLOC_USAGE_PROTECTED) {
#if defined(ION_HEAP_SECURE_MASK)
heap_mask = ION_HEAP_SECURE_MASK;
#else
@@ -141,57 +216,17 @@ static int gralloc_alloc_buffer(alloc_device_t *dev, size_t size, int usage, buf
return -1;
#endif
}
- else
- {
- heap_mask = ION_HEAP_SYSTEM_MASK;
+ else if (usage & GRALLOC_USAGE_HW_FB) {
+ heap_mask = ION_HEAP_TYPE_DMA_MASK;
}
-
- if (m->gralloc_legacy_ion)
- {
- if (usage & GRALLOC_USAGE_HW_FB)
- ret = ion_alloc(m->ion_client, size, 0, ION_HEAP_TYPE_DMA_MASK, 0, &(ion_hnd));
- else
- ret = ion_alloc(m->ion_client, size, 0, ION_HEAP_SYSTEM_MASK, 0, &(ion_hnd));
-
- if (ret != 0)
- {
- AERR("Failed to ion_alloc from ion_client:%d", m->ion_client);
- return -1;
- }
-
- ret = ion_share(m->ion_client, ion_hnd, &shared_fd);
-
- if (ret != 0)
- {
- AERR("ion_share( %d ) failed", m->ion_client);
-
- if (0 != ion_free(m->ion_client, ion_hnd))
- {
- AERR("ion_free( %d ) failed", m->ion_client);
- }
-
- return -1;
- }
-
- // we do not need ion_hnd once we have shared_fd
- if (0 != ion_free(m->ion_client, ion_hnd))
- {
- AWAR("ion_free( %d ) failed", m->ion_client);
- }
- ion_hnd = ION_INVALID_HANDLE;
+ else {
+ heap_mask = ION_HEAP_SYSTEM_MASK;
}
- else
- {
- if (usage & GRALLOC_USAGE_HW_FB)
- ret = ion_alloc_fd(m->ion_client, size, 0, 1 << m->cma_heap_id, 0, &(shared_fd));
- else
- ret = ion_alloc_fd(m->ion_client, size, 0, 1 << m->system_heap_id, 0, &(shared_fd));
- if (ret != 0)
- {
- AERR("Failed to ion_alloc_fd from ion_client:%d", m->ion_client);
- return -1;
- }
+ ret = alloc_ion_fd(m->ion_client, size, heap_mask, 0, &shared_fd);
+ if (ret != 0) {
+ AERR("Failed to ion_alloc_fd from ion_client:%d", m->ion_client);
+ return -1;
}
if (!(usage & GRALLOC_USAGE_PROTECTED))
@@ -693,7 +728,7 @@ static int alloc_device_close(struct hw_device_t *device)
}
#if GRALLOC_ARM_DMA_BUF_MODULE
-static int find_ion_heap_id(int ion_client, char* name)
+static int find_heap_id(int ion_client, char* name)
{
int i, ret, cnt, heap_id = -1;
struct ion_heap_data *data;
@@ -740,6 +775,52 @@ static int find_ion_heap_id(int ion_client, char* name)
}
#endif
+static int initialize_interface(private_module_t *m)
+{
+ int fd;
+
+ if (interface_ver != INTERFACE_UNKNOWN)
+ return 0;
+
+ /* test for dma-heaps*/
+ fd = dma_heap_open(DMABUF_SYSTEM);
+ if (fd >= 0) {
+ AINF("Using DMA-BUF Heaps.\n");
+ interface_ver = INTERFACE_DMABUF_HEAPS;
+ system_heap_id = fd;
+ cma_heap_id = dma_heap_open(DMABUF_CMA);
+ /* Open other dma heaps here */
+ return 0;
+ }
+
+ /* test for modern vs legacy ION */
+ m->ion_client = ion_open();
+ if (m->ion_client < 0) {
+ AERR("ion_open failed with %s", strerror(errno));
+ return -1;
+ }
+ if (!ion_is_legacy(m->ion_client)) {
+ system_heap_id = find_heap_id(m->ion_client, ION_SYSTEM);
+ cma_heap_id = find_heap_id(m->ion_client, ION_CMA);
+ if (system_heap_id < 0) {
+ ion_close(m->ion_client);
+ m->ion_client = -1;
+ AERR( "ion_open failed: no system heap found" );
+ return -1;
+ }
+ if (cma_heap_id < 0) {
+ AERR("No cma heap found, falling back to system");
+ cma_heap_id = system_heap_id;
+ }
+ AINF("Using ION Modern interface.\n");
+ interface_ver = INTERFACE_ION_MODERN;
+ } else {
+ AINF("Using ION Legacy interface.\n");
+ interface_ver = INTERFACE_ION_LEGACY;
+ }
+ return 0;
+}
+
int alloc_device_open(hw_module_t const *module, const char *name, hw_device_t **device)
{
MALI_IGNORE(name);
@@ -777,30 +858,11 @@ int alloc_device_open(hw_module_t const *module, const char *name, hw_device_t *
#if GRALLOC_ARM_DMA_BUF_MODULE
private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module);
- m->ion_client = ion_open();
- if (m->ion_client < 0)
- {
- AERR("ion_open failed with %s", strerror(errno));
+ if (initialize_interface(m) < 0) {
delete dev;
return -1;
}
-
- m->gralloc_legacy_ion = ion_is_legacy(m->ion_client);
-
- if (!m->gralloc_legacy_ion)
- {
- m->system_heap_id = find_ion_heap_id(m->ion_client, ION_SYSTEM);
- m->cma_heap_id = find_ion_heap_id(m->ion_client, ION_CMA);
- if (m->system_heap_id < 0 || m->cma_heap_id < 0)
- {
- delete dev;
- ion_close(m->ion_client);
- m->ion_client = -1;
- return -1;
- }
- }
-
#endif
*device = &dev->common;
diff --git a/gralloc/dma-heap.h b/gralloc/dma-heap.h
new file mode 100644
index 00000000..6f84fa08
--- /dev/null
+++ b/gralloc/dma-heap.h
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * DMABUF Heaps Userspace API
+ *
+ * Copyright (C) 2011 Google, Inc.
+ * Copyright (C) 2019 Linaro Ltd.
+ */
+#ifndef _UAPI_LINUX_DMABUF_POOL_H
+#define _UAPI_LINUX_DMABUF_POOL_H
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+/**
+ * DOC: DMABUF Heaps Userspace API
+ */
+
+/* Valid FD_FLAGS are O_CLOEXEC, O_RDONLY, O_WRONLY, O_RDWR */
+#define DMA_HEAP_VALID_FD_FLAGS (O_CLOEXEC | O_ACCMODE)
+
+/* Currently no heap flags */
+#define DMA_HEAP_VALID_HEAP_FLAGS (0)
+
+/**
+ * struct dma_heap_allocation_data - metadata passed from userspace for
+ * allocations
+ * @len: size of the allocation
+ * @fd: will be populated with a fd which provides the
+ * handle to the allocated dma-buf
+ * @fd_flags: file descriptor flags used when allocating
+ * @heap_flags: flags passed to heap
+ *
+ * Provided by userspace as an argument to the ioctl
+ */
+struct dma_heap_allocation_data {
+ __u64 len;
+ __u32 fd;
+ __u32 fd_flags;
+ __u64 heap_flags;
+};
+
+#define DMA_HEAP_IOC_MAGIC 'H'
+
+/**
+ * DOC: DMA_HEAP_IOCTL_ALLOC - allocate memory from pool
+ *
+ * Takes a dma_heap_allocation_data struct and returns it with the fd field
+ * populated with the dmabuf handle of the allocation.
+ */
+#define DMA_HEAP_IOCTL_ALLOC _IOWR(DMA_HEAP_IOC_MAGIC, 0x0,\
+ struct dma_heap_allocation_data)
+
+#endif /* _UAPI_LINUX_DMABUF_POOL_H */