gralloc: Align protected allocations with the spec

The specification for GRALLOC_USAGE_PROTECTED indicates that
allocations with that flag must be protected by securing with
hardware. If such protection is not possible, the buffer must not
be composited. In our current software only the MM_HEAP is
secured. If we allocate protected buffers from any other heap we
block those from being displayed.

CRs-fixed: 465012
Change-Id: I9d47aba3d28192db3fcc394fd6b38efe42ae118b
This commit is contained in:
Naseer Ahmed
2013-03-07 13:42:20 -05:00
committed by Gerrit - the friendly Code Review server
parent 9c301a18c6
commit c5e6fb0fd3
2 changed files with 21 additions and 28 deletions

View File

@@ -175,7 +175,6 @@ int IonController::allocate(alloc_data& data, int usage)
{ {
int ionFlags = 0; int ionFlags = 0;
int ret; int ret;
bool noncontig = false;
data.uncached = useUncached(usage); data.uncached = useUncached(usage);
data.allocType = 0; data.allocType = 0;
@@ -183,24 +182,33 @@ int IonController::allocate(alloc_data& data, int usage)
if(usage & GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP) if(usage & GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP)
ionFlags |= ION_HEAP(ION_SF_HEAP_ID); ionFlags |= ION_HEAP(ION_SF_HEAP_ID);
if(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP) { if(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP)
ionFlags |= ION_HEAP(ION_SYSTEM_HEAP_ID); ionFlags |= ION_HEAP(ION_SYSTEM_HEAP_ID);
noncontig = true;
}
if(usage & GRALLOC_USAGE_PRIVATE_IOMMU_HEAP) { if(usage & GRALLOC_USAGE_PRIVATE_IOMMU_HEAP)
ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID); ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
noncontig = true;
}
if(usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) //MM Heap is exclusively a secure heap.
ionFlags |= ION_HEAP(ION_CP_MM_HEAP_ID); if(usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) {
//XXX: Right now the MM heap is the only secure heap we have. When we
//have other secure heaps, we can change this.
if(usage & GRALLOC_USAGE_PROTECTED) {
ionFlags |= ION_HEAP(ION_CP_MM_HEAP_ID);
ionFlags |= ION_SECURE;
}
else {
ALOGW("GRALLOC_USAGE_PRIVATE_MM_HEAP \
cannot be used as an insecure heap!\
trying to use IOMMU instead !!");
ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
}
}
if(usage & GRALLOC_USAGE_PRIVATE_ADSP_HEAP) if(usage & GRALLOC_USAGE_PRIVATE_ADSP_HEAP)
ionFlags |= ION_HEAP(ION_ADSP_HEAP_ID); ionFlags |= ION_HEAP(ION_ADSP_HEAP_ID);
if(usage & GRALLOC_USAGE_PROTECTED && !noncontig) if(usage & GRALLOC_USAGE_PROTECTED)
ionFlags |= ION_SECURE; data.allocType |= private_handle_t::PRIV_FLAGS_SECURE_BUFFER;
// if no flags are set, default to // if no flags are set, default to
// SF + IOMMU heaps, so that bypass can work // SF + IOMMU heaps, so that bypass can work
@@ -218,16 +226,11 @@ int IonController::allocate(alloc_data& data, int usage)
{ {
ALOGW("Falling back to system heap"); ALOGW("Falling back to system heap");
data.flags = ION_HEAP(ION_SYSTEM_HEAP_ID); data.flags = ION_HEAP(ION_SYSTEM_HEAP_ID);
noncontig = true;
ret = mIonAlloc->alloc_buffer(data); ret = mIonAlloc->alloc_buffer(data);
} }
if(ret >= 0 ) { if(ret >= 0 ) {
data.allocType |= private_handle_t::PRIV_FLAGS_USES_ION; data.allocType |= private_handle_t::PRIV_FLAGS_USES_ION;
if(noncontig)
data.allocType |= private_handle_t::PRIV_FLAGS_NONCONTIGUOUS_MEM;
if(ionFlags & ION_SECURE)
data.allocType |= private_handle_t::PRIV_FLAGS_SECURE_BUFFER;
} }
return ret; return ret;

View File

@@ -138,21 +138,11 @@ inline bool OvMem::open(uint32_t numbufs,
data.uncached = true; data.uncached = true;
err = mAlloc->allocate(data, allocFlags); err = mAlloc->allocate(data, allocFlags);
//see if we can fallback to other heap if (err != 0) {
//we can try MM_HEAP once if it's not secure playback ALOGE("OvMem: Error allocating memory");
if (err != 0 && !isSecure) {
allocFlags |= GRALLOC_USAGE_PRIVATE_MM_HEAP;
err = mAlloc->allocate(data, allocFlags);
if (err != 0) {
ALOGE(" could not allocate from fallback heap");
return false;
}
} else if (err != 0) {
ALOGE("OvMem: error allocating memory can not fall back");
return false; return false;
} }
mFd = data.fd; mFd = data.fd;
mBaseAddr = data.base; mBaseAddr = data.base;
mAllocType = data.allocType; mAllocType = data.allocType;