Skip to content

Commit

Permalink
binder: update MemoryHeapIon
Browse files Browse the repository at this point in the history
* Update from ODROID-XU 04212014 BSP

Change-Id: Ifc2664bcde37a71d855e05e7c9e50288a4508892
  • Loading branch information
intervigilium committed Jun 30, 2014
1 parent af8b05e commit 5f550b2
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 9 deletions.
4 changes: 4 additions & 0 deletions include/binder/IMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class IMemoryHeap : public IInterface
// flags returned by getFlags()
enum {
READ_ONLY = 0x00000001,
#ifdef USE_MEMORY_HEAP_ION
USE_ION_FD = 0x00008000
#else
USE_ION_FD = 0x00000008
#endif
};

virtual int getHeapID() const = 0;
Expand Down
15 changes: 15 additions & 0 deletions include/binder/MemoryHeapIon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@
#include <binder/MemoryHeapBase.h>
#include <stdlib.h>

#define MHB_ION_HEAP_SYSTEM_CONTIG_MASK (1 << 1)
#define MHB_ION_HEAP_EXYNOS_CONTIG_MASK (1 << 4)
#define MHB_ION_HEAP_EXYNOS_MASK (1 << 5)
#define MHB_ION_HEAP_SYSTEM_MASK (1 << 6)

#define MHB_ION_FLAG_CACHED (1 << 16)
#define MHB_ION_FLAG_CACHED_NEEDS_SYNC (1 << 17)
#define MHB_ION_FLAG_PRESERVE_KMAP (1 << 18)

#define MHB_ION_EXYNOS_VIDEO_MASK (1 << 21)
#define MHB_ION_EXYNOS_MFC_INPUT_MASK (1 << 25)
#define MHB_ION_EXYNOS_MFC_OUTPUT_MASK (1 << 26)
#define MHB_ION_EXYNOS_GSC_MASK (1 << 27)
#define MHB_ION_EXYNOS_FIMD_VIDEO_MASK (1 << 28)

namespace android {

class MemoryHeapIon : public MemoryHeapBase
Expand Down
14 changes: 7 additions & 7 deletions libs/binder/IMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ void BpMemoryHeap::assertReallyMapped() const
asBinder().get(), parcel_fd, size, err, strerror(-err));

#ifdef USE_MEMORY_HEAP_ION
int ion_client = -1;
ion_client ion_client_num = -1;
if (flags & USE_ION_FD) {
ion_client = ion_client_create();
ALOGE_IF(ion_client < 0, "BpMemoryHeap : ion client creation error");
ion_client_num = ion_client_create();
ALOGE_IF(ion_client_num < 0, "BpMemoryHeap : ion client creation error");
}
#endif

Expand All @@ -326,7 +326,7 @@ void BpMemoryHeap::assertReallyMapped() const

#ifdef USE_MEMORY_HEAP_ION
if (flags & USE_ION_FD) {
if (ion_client < 0)
if (ion_client_num < 0)
mBase = MAP_FAILED;
else
mBase = ion_map(fd, size, offset);
Expand All @@ -345,10 +345,10 @@ void BpMemoryHeap::assertReallyMapped() const
}
}
#ifdef USE_MEMORY_HEAP_ION
if (ion_client < 0)
ion_client = -1;
if (ion_client_num < 0)
ion_client_num = -1;
else
ion_client_destroy(ion_client);
ion_client_destroy(ion_client_num);
#endif
}
}
Expand Down
80 changes: 78 additions & 2 deletions libs/binder/MemoryHeapIon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,96 @@
#include <sys/mman.h>
#include "ion.h"

#define HEAP_MASK_FILTER ((1 << 16) - (2))
#define FLAG_MASK_FILTER (~(HEAP_MASK_FILTER) - (1))

namespace android {

uint32_t ion_HeapMask_valid_check(uint32_t flags)
{
uint32_t heap_mask, result;
result = 0;

heap_mask = flags & HEAP_MASK_FILTER;

switch(heap_mask) {
case MHB_ION_HEAP_SYSTEM_MASK:
return ION_HEAP_SYSTEM_MASK;
case MHB_ION_HEAP_SYSTEM_CONTIG_MASK:
return ION_HEAP_SYSTEM_CONTIG_MASK;
case MHB_ION_HEAP_EXYNOS_CONTIG_MASK:
return ION_HEAP_EXYNOS_CONTIG_MASK;
case MHB_ION_HEAP_EXYNOS_MASK:
return ION_HEAP_EXYNOS_MASK;
default:
ALOGE("MemoryHeapIon : Heap Mask flag is default (flags:%x)", flags);
return 0;
break;
}
ALOGE("MemoryHeapIon : Heap Mask flag is wrong (flags:%x)", flags);
return 0;
}

uint32_t ion_FlagMask_valid_check(uint32_t flags)
{
uint32_t flag_mask, result;
result = 0;

flag_mask = flags & FLAG_MASK_FILTER;

if (flag_mask & MHB_ION_FLAG_CACHED)
result |= ION_FLAG_CACHED;
if (flag_mask & MHB_ION_FLAG_CACHED_NEEDS_SYNC)
result |= ION_FLAG_CACHED_NEEDS_SYNC;
if (flag_mask & MHB_ION_FLAG_PRESERVE_KMAP)
result |= ION_FLAG_PRESERVE_KMAP;
if (flag_mask & MHB_ION_EXYNOS_VIDEO_MASK)
result |= ION_EXYNOS_VIDEO_MASK;
if (flag_mask & MHB_ION_EXYNOS_MFC_INPUT_MASK)
result |= ION_EXYNOS_MFC_INPUT_MASK;
if (flag_mask & MHB_ION_EXYNOS_MFC_OUTPUT_MASK)
result |= ION_EXYNOS_MFC_OUTPUT_MASK;
if (flag_mask & MHB_ION_EXYNOS_GSC_MASK)
result |= ION_EXYNOS_GSC_MASK;
if (flag_mask & MHB_ION_EXYNOS_FIMD_VIDEO_MASK)
result |= ION_EXYNOS_FIMD_VIDEO_MASK;

return result;
}

MemoryHeapIon::MemoryHeapIon(size_t size, uint32_t flags, char const *name):MemoryHeapBase()
{
void* base = NULL;
int fd = -1;
uint32_t isReadOnly, heapMask, flagMask;

mIonClient = ion_client_create();

if (mIonClient < 0) {
ALOGE("MemoryHeapIon : ION client creation failed : %s", strerror(errno));
mIonClient = -1;
} else {
fd = ion_alloc(mIonClient, size, 0, ION_HEAP_SYSTEM_MASK, ION_FLAG_CACHED | ION_FLAG_CACHED_NEEDS_SYNC | ION_FLAG_PRESERVE_KMAP);
isReadOnly = flags & (IMemoryHeap::READ_ONLY);
heapMask = ion_HeapMask_valid_check(flags);
flagMask = ion_FlagMask_valid_check(flags);

if (heapMask) {
ALOGD("MemoryHeapIon : Allocated with size:%d, heap:0x%X , flag:0x%X", size, heapMask, flagMask);
fd = ion_alloc(mIonClient, size, 0, heapMask, flagMask);
if (fd < 0) {
ALOGE("MemoryHeapIon : ION Reserve memory allocation failed(size[%u]) : %s", size, strerror(errno));
if (errno == ENOMEM) { // Out of reserve memory. So re-try allocating in system heap
ALOGD("MemoryHeapIon : Re-try Allocating in default heap - SYSTEM heap");
fd = ion_alloc(mIonClient, size, 0, ION_HEAP_SYSTEM_MASK, ION_FLAG_CACHED | ION_FLAG_CACHED_NEEDS_SYNC | ION_FLAG_PRESERVE_KMAP);
}
}
} else {
fd = ion_alloc(mIonClient, size, 0, ION_HEAP_SYSTEM_MASK, ION_FLAG_CACHED | ION_FLAG_CACHED_NEEDS_SYNC | ION_FLAG_PRESERVE_KMAP);
ALOGD("MemoryHeapIon : Allocated with default heap - SYSTEM heap");
}

flags = isReadOnly | heapMask | flagMask;

if (fd < 0) {
ALOGE("MemoryHeapIon : ION memory allocation failed(size[%u]) : %s", size, strerror(errno));
} else {
Expand All @@ -63,7 +139,7 @@ MemoryHeapIon::MemoryHeapIon(size_t size, uint32_t flags, char const *name):Memo
if (base != MAP_FAILED) {
init(fd, base, size, flags, NULL);
} else {
ALOGE("MemoryHeapIon : mmap failed(size[%u], fd[%d]) : %s", size, fd, strerror(errno));
ALOGE("MemoryHeapIon : ION mmap failed(size[%u], fd[%d]) : %s", size, fd, strerror(errno));
ion_free(fd);
}
}
Expand Down

0 comments on commit 5f550b2

Please sign in to comment.