summaryrefslogtreecommitdiff
path: root/gralloc/alloc_device.cpp
diff options
context:
space:
mode:
authorLaura Abbott <labbott@redhat.com>2017-06-30 11:39:35 +0530
committerJohn Stultz <john.stultz@linaro.org>2018-03-30 11:05:54 -0700
commit311955b81a982e4dfdf302782a2721e37e5b93b3 (patch)
tree9603e9377579da9022e2a92ab82ff9a323688e27 /gralloc/alloc_device.cpp
parent6e403d08fb9f10f09c4f635988d4af09ca8431b1 (diff)
downloadhikey-311955b81a982e4dfdf302782a2721e37e5b93b3.tar.gz
hikey: gralloc Update for new ION interface
4.12+ kernels have an updated ION interface; this adapts hikey's gralloc to work seemlessly with both old and new kernels' interfaces. Test: validated with both new and old kernels on hikey, with aosp master Change-Id: Ia019fd7f3f5b3e9765c8f26032ff0063e5391f56 Signed-off-by: Laura Abbott <labbott@redhat.com> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> [sumits: maintain compatibility with older kernels]
Diffstat (limited to 'gralloc/alloc_device.cpp')
-rw-r--r--gralloc/alloc_device.cpp116
1 files changed, 96 insertions, 20 deletions
diff --git a/gralloc/alloc_device.cpp b/gralloc/alloc_device.cpp
index 33c3a097..076cb5ce 100644
--- a/gralloc/alloc_device.cpp
+++ b/gralloc/alloc_device.cpp
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+#include <cstdlib>
#include <string.h>
#include <errno.h>
#include <pthread.h>
@@ -40,9 +41,9 @@
#if GRALLOC_ARM_DMA_BUF_MODULE
#include <linux/ion.h>
#include <ion/ion.h>
+#include "ion_4.12.h"
#endif
-
#if GRALLOC_SIMULATE_FAILURES
#include <cutils/properties.h>
@@ -142,26 +143,46 @@ static int gralloc_alloc_buffer(alloc_device_t *dev, size_t size, int usage, buf
heap_mask = ION_HEAP_SYSTEM_MASK;
}
- ret = ion_alloc(m->ion_client, size, 0, heap_mask, 0, &(ion_hnd));
-
- if (ret != 0)
+ if (m->gralloc_legacy_ion)
{
- AERR("Failed to ion_alloc from ion_client:%d", m->ion_client);
- return -1;
- }
+ ret = ion_alloc(m->ion_client, size, 0, ION_HEAP_SYSTEM_MASK, 0, &(ion_hnd));
- ret = ion_share(m->ion_client, ion_hnd, &shared_fd);
+ if (ret != 0)
+ {
+ AERR("Failed to ion_alloc from ion_client:%d", m->ion_client);
+ return -1;
+ }
- if (ret != 0)
- {
- AERR("ion_share( %d ) failed", m->ion_client);
+ 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))
{
- AERR("ion_free( %d ) failed", m->ion_client);
+ AWAR("ion_free( %d ) failed", m->ion_client);
}
+ ion_hnd = ION_INVALID_HANDLE;
+ }
+ else
+ {
+ ret = ion_alloc_fd(m->ion_client, size, 0, 1 << m->system_heap_id, 0, &(shared_fd));
- return -1;
+ if (ret != 0)
+ {
+ AERR("Failed to ion_alloc_fd from ion_client:%d", m->ion_client);
+ return -1;
+ }
}
if (!(usage & GRALLOC_USAGE_PROTECTED))
@@ -172,13 +193,6 @@ static int gralloc_alloc_buffer(alloc_device_t *dev, size_t size, int usage, buf
{
map_mask = PROT_WRITE;
}
- // ion_hnd is no longer needed once we acquire shared_fd.
- if (0 != ion_free(m->ion_client, ion_hnd))
- {
- AWAR("ion_free( %d ) failed", m->ion_client);
- }
-
- ion_hnd = ION_INVALID_HANDLE;
cpu_ptr = mmap(NULL, size, map_mask, MAP_SHARED, shared_fd, 0);
@@ -667,6 +681,54 @@ static int alloc_device_close(struct hw_device_t *device)
return 0;
}
+#if GRALLOC_ARM_DMA_BUF_MODULE
+static int find_system_heap_id(int ion_client)
+{
+ int i, ret, cnt, system_heap_id = -1;
+ struct ion_heap_data *data;
+
+ ret = ion_query_heap_cnt(ion_client, &cnt);
+
+ if (ret)
+ {
+ AERR("ion count query failed with %s", strerror(errno));
+ return -1;
+ }
+
+ data = (struct ion_heap_data *)malloc(cnt * sizeof(*data));
+ if (!data)
+ {
+ AERR("Error allocating data %s\n", strerror(errno));
+ return -1;
+ }
+
+ ret = ion_query_get_heaps(ion_client, cnt, data);
+ if (ret)
+ {
+ AERR("Error querying heaps from ion %s", strerror(errno));
+ }
+ else
+ {
+ for (i = 0; i < cnt; i++) {
+ struct ion_heap_data *dat = (struct ion_heap_data *)data;
+ if (strcmp(dat[i].name, "ion_system_heap") == 0) {
+ system_heap_id = dat[i].heap_id;
+ break;
+ }
+ }
+
+ if (i > cnt)
+ {
+ AERR("No System Heap Found amongst %d heaps\n", cnt);
+ system_heap_id = -1;
+ }
+ }
+
+ free(data);
+ return system_heap_id;
+}
+#endif
+
int alloc_device_open(hw_module_t const *module, const char *name, hw_device_t **device)
{
MALI_IGNORE(name);
@@ -713,6 +775,20 @@ int alloc_device_open(hw_module_t const *module, const char *name, hw_device_t *
return -1;
}
+ m->gralloc_legacy_ion = ion_is_legacy(m->ion_client);
+
+ if (!m->gralloc_legacy_ion)
+ {
+ m->system_heap_id = find_system_heap_id(m->ion_client);
+ if (m->system_heap_id < 0)
+ {
+ delete dev;
+ ion_close(m->ion_client);
+ m->ion_client = -1;
+ return -1;
+ }
+ }
+
#endif
*device = &dev->common;