From ea94363fdebfe4d47dac8fe21ed80f532361e011 Mon Sep 17 00:00:00 2001 From: Naseer Ahmed Date: Fri, 9 Dec 2011 00:20:26 +0530 Subject: [PATCH] Display: Use new ION heaps Use new ION heaps in gralloc and use them in rotator Change-Id: I4ff903fd48a90e19655a64c5a0abaeec35aa34c8 --- libgralloc/alloc_controller.cpp | 69 ++++++++++++++++++++++----------- libgralloc/gralloc_priv.h | 36 ++++++++++++----- libgralloc/mapper.cpp | 2 +- liboverlay/overlayLib.cpp | 5 ++- liboverlay/overlayLibUI.cpp | 8 +++- 5 files changed, 84 insertions(+), 36 deletions(-) diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp index b65db7b..2fa7e1a 100644 --- a/libgralloc/alloc_controller.cpp +++ b/libgralloc/alloc_controller.cpp @@ -40,26 +40,45 @@ using namespace gralloc; using android::sp; +const int GRALLOC_HEAP_MASK = GRALLOC_USAGE_PRIVATE_ADSP_HEAP | + GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP | + GRALLOC_USAGE_PRIVATE_SMI_HEAP | + GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP | + GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | + GRALLOC_USAGE_PRIVATE_MM_HEAP | + GRALLOC_USAGE_PRIVATE_WRITEBACK_HEAP | + GRALLOC_USAGE_PRIVATE_CAMERA_HEAP; + + //Common functions static bool canFallback(int compositionType, int usage, bool triedSystem) { // Fallback to system heap when alloc fails unless // 1. Composition type is MDP - // 2. Earlier alloc attempt was from system heap - // 3. Contiguous heap requsted explicitly + // 2. Alloc from system heap was already tried + // 3. The heap type is requsted explicitly + // 4. The heap type is protected if(compositionType == MDP_COMPOSITION) return false; if(triedSystem) return false; - if(usage &(GRALLOC_USAGE_PRIVATE_ADSP_HEAP| - GRALLOC_USAGE_PRIVATE_EBI_HEAP | - GRALLOC_USAGE_PRIVATE_SMI_HEAP)) + if(usage & (GRALLOC_HEAP_MASK | GRALLOC_USAGE_PROTECTED)) return false; //Return true by default return true; } +static bool useUncached(int usage) +{ + // System heaps cannot be uncached + if(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP) + return false; + if (usage & GRALLOC_USAGE_PRIVATE_UNCACHED) + return true; + return false; +} + sp IAllocController::sController = NULL; sp IAllocController::getInstance(bool useMasterHeap) { @@ -91,43 +110,47 @@ int IonController::allocate(alloc_data& data, int usage, int ret; bool noncontig = false; - //System heap cannot be uncached - if (usage & GRALLOC_USAGE_PRIVATE_UNCACHED && - !(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP)) - data.uncached = true; - else - data.uncached = false; + data.uncached = useUncached(usage); - if(usage & GRALLOC_USAGE_PRIVATE_ADSP_HEAP) - ionFlags |= 1 << ION_HEAP_ADSP_ID; - - if(usage & GRALLOC_USAGE_PRIVATE_SMI_HEAP) - ionFlags |= 1 << ION_HEAP_SMI_ID; - - if(usage & GRALLOC_USAGE_PRIVATE_EBI_HEAP) - ionFlags |= 1 << ION_HEAP_EBI_ID; + if(usage & GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP) + ionFlags |= ION_HEAP(ION_SF_HEAP_ID); if(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP) { - ionFlags |= 1 << ION_HEAP_SYSTEM_ID; + ionFlags |= ION_HEAP(ION_SYSTEM_HEAP_ID); noncontig = true; } + if(usage & GRALLOC_USAGE_PRIVATE_IOMMU_HEAP) + ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID); + + if(usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) + ionFlags |= ION_HEAP(ION_CP_MM_HEAP_ID); + + if(usage & GRALLOC_USAGE_PRIVATE_WRITEBACK_HEAP) + ionFlags |= ION_HEAP(ION_CP_WB_HEAP_ID); + + if(usage & GRALLOC_USAGE_PRIVATE_CAMERA_HEAP) + ionFlags |= ION_HEAP(ION_CAMERA_HEAP_ID); + + if(usage & GRALLOC_USAGE_PROTECTED) + ionFlags |= ION_SECURE; + // if no flags are set, default to // EBI heap, so that bypass can work // we can fall back to system heap if // we run out. if(!ionFlags) - ionFlags = 1 << ION_HEAP_EBI_ID; + ionFlags = ION_HEAP(ION_SF_HEAP_ID); data.flags = ionFlags; ret = mIonAlloc->alloc_buffer(data); // Fallback if(ret < 0 && canFallback(compositionType, usage, - (ionFlags & ION_HEAP_SYSTEM_ID))) + (ionFlags & ION_SYSTEM_HEAP_ID))) { LOGW("Falling back to system heap"); - data.flags = 1 << ION_HEAP_SYSTEM_ID; + data.flags = ION_HEAP(ION_SYSTEM_HEAP_ID); noncontig = true; ret = mIonAlloc->alloc_buffer(data); } diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h index 00039c4..eaa3b80 100644 --- a/libgralloc/gralloc_priv.h +++ b/libgralloc/gralloc_priv.h @@ -38,18 +38,34 @@ using namespace overlay; enum { /* gralloc usage bits indicating the type * of allocation that should be used */ - GRALLOC_USAGE_PRIVATE_ADSP_HEAP = GRALLOC_USAGE_PRIVATE_0, - GRALLOC_USAGE_PRIVATE_EBI_HEAP = GRALLOC_USAGE_PRIVATE_1, - GRALLOC_USAGE_PRIVATE_SMI_HEAP = GRALLOC_USAGE_PRIVATE_2, - GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP = GRALLOC_USAGE_PRIVATE_3, + + /* ADSP heap is deprecated, use only if using pmem */ + GRALLOC_USAGE_PRIVATE_ADSP_HEAP = GRALLOC_USAGE_PRIVATE_0, + /* SF heap is used for application buffers, is not secured */ + GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP = GRALLOC_USAGE_PRIVATE_1, + /* SMI heap is deprecated, use only if using pmem */ + GRALLOC_USAGE_PRIVATE_SMI_HEAP = GRALLOC_USAGE_PRIVATE_2, + /* SYSTEM heap comes from kernel vmalloc, + * can never be uncached, is not secured*/ + GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP = GRALLOC_USAGE_PRIVATE_3, + /* IOMMU heap comes from manually allocated pages, + * can be cached/uncached, is not secured */ + GRALLOC_USAGE_PRIVATE_IOMMU_HEAP = 0x01000000, + /* MM heap is a carveout heap for video, can be secured*/ + GRALLOC_USAGE_PRIVATE_MM_HEAP = 0x02000000, + /* WRITEBACK heap is a carveout heap for writeback, can be secured*/ + GRALLOC_USAGE_PRIVATE_WRITEBACK_HEAP = 0x04000000, + /* CAMERA heap is a carveout heap for camera, is not secured*/ + GRALLOC_USAGE_PRIVATE_CAMERA_HEAP = 0x08000000, + /* Set this for allocating uncached memory (using O_DSYNC) - * cannot be used with the system heap */ - GRALLOC_USAGE_PRIVATE_UNCACHED = 0x00010000, - /* This flag needs to be set when using a system heap - * from ION. If not set, the system heap is assumed - * to be coming from ashmem + * cannot be used with noncontiguous heaps */ + GRALLOC_USAGE_PRIVATE_UNCACHED = 0x00010000, + + /* This flag needs to be set when using a non-contiguous heap from ION. + * If not set, the system heap is assumed to be coming from ashmem */ - GRALLOC_USAGE_PRIVATE_ION = 0x00020000, + GRALLOC_USAGE_PRIVATE_ION = 0x00020000, }; enum { diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp index 5eaa0fe..0120ecd 100755 --- a/libgralloc/mapper.cpp +++ b/libgralloc/mapper.cpp @@ -327,7 +327,7 @@ int gralloc_perform(struct gralloc_module_t const* module, hnd->magic = private_handle_t::sMagic; hnd->fd = fd; unsigned int contigFlags = GRALLOC_USAGE_PRIVATE_ADSP_HEAP | - GRALLOC_USAGE_PRIVATE_EBI_HEAP | + GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP | GRALLOC_USAGE_PRIVATE_SMI_HEAP; if (memoryFlags & contigFlags) { diff --git a/liboverlay/overlayLib.cpp b/liboverlay/overlayLib.cpp index 7132edc..8a57457 100755 --- a/liboverlay/overlayLib.cpp +++ b/liboverlay/overlayLib.cpp @@ -1488,7 +1488,10 @@ bool OverlayDataChannel::mapRotatorMemory(int num_buffers, bool uiChannel, int r data.align = getpagesize(); data.uncached = true; - int allocFlags = GRALLOC_USAGE_PRIVATE_ADSP_HEAP; + int allocFlags = GRALLOC_USAGE_PRIVATE_MM_HEAP | + GRALLOC_USAGE_PRIVATE_WRITEBACK_HEAP | + GRALLOC_USAGE_PRIVATE_ADSP_HEAP | + GRALLOC_USAGE_PRIVATE_IOMMU_HEAP; if((requestType == NEW_REQUEST) && !uiChannel) allocFlags |= GRALLOC_USAGE_PRIVATE_SMI_HEAP; diff --git a/liboverlay/overlayLibUI.cpp b/liboverlay/overlayLibUI.cpp index 65d5d58..2836cb8 100755 --- a/liboverlay/overlayLibUI.cpp +++ b/liboverlay/overlayLibUI.cpp @@ -345,7 +345,13 @@ status_t Rotator::startRotSession(msm_rotator_img_info& rotInfo, data.align = getpagesize(); data.uncached = true; - int err = mAlloc->allocate(data, GRALLOC_USAGE_PRIVATE_SMI_HEAP, 0); + int allocFlags = GRALLOC_USAGE_PRIVATE_MM_HEAP | + GRALLOC_USAGE_PRIVATE_WRITEBACK_HEAP | + GRALLOC_USAGE_PRIVATE_ADSP_HEAP | + GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | + GRALLOC_USAGE_PRIVATE_SMI_HEAP; + + int err = mAlloc->allocate(data, allocFlags, 0); if(err) { LOGE("%s: Can't allocate rotator memory", __func__);