display: Add support for protected heaps

(cherry picked from commit c932690c5a9d0aedfd2580e5c5e9f79e32f54261)

Change-Id: Ibddab4252ecefa1c410430b89f94aba4d3ae1c96
This commit is contained in:
Naseer Ahmed 2011-12-29 15:17:39 +05:30 committed by Andrew Sutherland
parent cf67073149
commit 71e0e80dbd
7 changed files with 53 additions and 28 deletions

View File

@ -159,6 +159,8 @@ int IonController::allocate(alloc_data& data, int usage,
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;
}

View File

@ -302,6 +302,7 @@ struct private_handle_t {
PRIV_FLAGS_SW_LOCK = 0x00000080,
PRIV_FLAGS_NONCONTIGUOUS_MEM = 0x00000100,
PRIV_FLAGS_HWC_LOCK = 0x00000200, // Set by HWC when storing the handle
PRIV_FLAGS_SECURE_BUFFER = 0x00000400,
};
// file-descriptors

View File

@ -123,25 +123,29 @@ int IonAlloc::alloc_buffer(alloc_data& data)
return err;
}
base = mmap(0, ionAllocData.len, PROT_READ|PROT_WRITE,
MAP_SHARED, fd_data.fd, 0);
if(base == MAP_FAILED) {
LOGD("%s: Failed to map the allocated memory: %s",
__FUNCTION__, strerror(errno));
err = -errno;
ioctl(mIonFd, ION_IOC_FREE, &handle_data);
close_device();
ionSyncFd = FD_INIT;
return err;
if(!(data.flags & ION_SECURE)) {
base = mmap(0, ionAllocData.len, PROT_READ|PROT_WRITE,
MAP_SHARED, fd_data.fd, 0);
if(base == MAP_FAILED) {
LOGD("%s: Failed to map the allocated memory: %s",
__FUNCTION__, strerror(errno));
err = -errno;
ioctl(mIonFd, ION_IOC_FREE, &handle_data);
close_device();
ionSyncFd = FD_INIT;
return err;
}
memset(base, 0, ionAllocData.len);
// Clean cache after memset
clean_buffer(base, data.size, data.offset, fd_data.fd);
}
//Close the uncached FD since we no longer need it;
if(ionSyncFd >= 0)
close(ionSyncFd);
ionSyncFd = FD_INIT;
memset(base, 0, ionAllocData.len);
// Clean cache after memset
clean_buffer(base, data.size, data.offset, fd_data.fd);
data.base = base;
data.fd = fd_data.fd;
ioctl(mIonFd, ION_IOC_FREE, &handle_data);
@ -161,11 +165,8 @@ int IonAlloc::free_buffer(void* base, size_t size, int offset, int fd)
if (err)
return err;
if(!base) {
LOGE("Invalid free");
return -EINVAL;
}
err = unmap_buffer(base, size, offset);
if(base)
err = unmap_buffer(base, size, offset);
close(fd);
return err;
}

View File

@ -63,7 +63,8 @@ static int gralloc_map(gralloc_module_t const* module,
{
private_handle_t* hnd = (private_handle_t*)handle;
void *mappedAddress;
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
!(hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER)) {
size_t size = hnd->size;
sp<IMemAlloc> memalloc = getAllocator(hnd->flags) ;
int err = memalloc->map_buffer(&mappedAddress, size,

View File

@ -279,6 +279,8 @@ static int prepareOverlay(hwc_context_t *ctx, hwc_layer_t *layer, const bool wai
info.height = hnd->height;
info.format = hnd->format;
info.size = hnd->size;
info.secure = (hnd->flags &
private_handle_t::PRIV_FLAGS_SECURE_BUFFER)? true:false;
ret = ovLibObject->setSource(info, layer->transform,
(ovLibObject->getHDMIStatus()?true:false), waitForVsync);
@ -461,6 +463,8 @@ static int prepareBypass(hwc_context_t *ctx, hwc_layer_t *layer, int index,
info.height = sourceCrop.bottom - sourceCrop.top;
info.format = hnd->format;
info.size = hnd->size;
info.secure = (hnd->flags &
private_handle_t::PRIV_FLAGS_SECURE_BUFFER)? true:false;
const bool useVGPipe = true;
//only last layer should wait for vsync
const bool waitForVsync = (index == lastLayerIndex);

View File

@ -308,6 +308,7 @@ Overlay::Overlay() : mChannelUP(false), mHDMIConnected(false),
mCroppedSrcHeight(0), mState(-1) {
mOVBufferInfo.width = mOVBufferInfo.height = 0;
mOVBufferInfo.format = mOVBufferInfo.size = 0;
mOVBufferInfo.secure = false;
}
Overlay::~Overlay() {
@ -345,7 +346,7 @@ bool Overlay::startChannel(const overlay_buffer_info& info, int fbnum,
}
objOvCtrlChannel[channel].setSize(info.size);
return objOvDataChannel[channel].startDataChannel(objOvCtrlChannel[channel], fbnum,
norot, uichannel, num_buffers);
norot, info.secure, uichannel, num_buffers);
}
bool Overlay::closeChannel() {
@ -373,6 +374,7 @@ bool Overlay::closeChannel() {
mOVBufferInfo.height = 0;
mOVBufferInfo.format = 0;
mOVBufferInfo.size = 0;
mOVBufferInfo.secure = false;
mState = -1;
return true;
}
@ -993,6 +995,11 @@ bool OverlayControlChannel::setOverlayInformation(const overlay_buffer_info& inf
else
mOVInfo.flags &= ~MDP_OV_PLAY_NOWAIT;
if(info.secure)
mOVInfo.flags |= MDP_SECURE_OVERLAY_SESSION;
else
mOVInfo.flags &= MDP_SECURE_OVERLAY_SESSION;
return true;
}
@ -1434,9 +1441,11 @@ OverlayDataChannel::~OverlayDataChannel() {
bool OverlayDataChannel::startDataChannel(
const OverlayControlChannel& objOvCtrlChannel,
int fbnum, bool norot, bool uichannel, int num_buffers) {
int fbnum, bool norot, bool secure, bool uichannel,
int num_buffers) {
int ovid, rotid, size;
mNoRot = norot;
mSecure = secure;
memset(&mOvData, 0, sizeof(mOvData));
memset(&mOvDataRot, 0, sizeof(mOvDataRot));
memset(&mRotData, 0, sizeof(mRotData));
@ -1489,12 +1498,17 @@ bool OverlayDataChannel::mapRotatorMemory(int num_buffers, bool uiChannel, int r
data.align = getpagesize();
data.uncached = true;
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;
int allocFlags = GRALLOC_USAGE_PRIVATE_MM_HEAP |
GRALLOC_USAGE_PRIVATE_WRITEBACK_HEAP;
if(mSecure) {
allocFlags |= GRALLOC_USAGE_PROTECTED;
} else {
allocFlags |= GRALLOC_USAGE_PRIVATE_ADSP_HEAP |
GRALLOC_USAGE_PRIVATE_IOMMU_HEAP;
if((requestType == NEW_REQUEST) && !uiChannel)
allocFlags |= GRALLOC_USAGE_PRIVATE_SMI_HEAP;
}
int err = mAlloc->allocate(data, allocFlags, 0);
if(err) {

View File

@ -108,6 +108,7 @@ struct overlay_buffer_info {
int height;
int format;
int size;
bool secure;
};
/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
@ -219,6 +220,7 @@ public:
class OverlayDataChannel {
bool mNoRot;
bool mSecure;
int mFD;
int mRotFD;
int mPmemFD;
@ -243,7 +245,7 @@ public:
OverlayDataChannel();
~OverlayDataChannel();
bool startDataChannel(const OverlayControlChannel& objOvCtrlChannel,
int fbnum, bool norot = false,
int fbnum, bool norot = false, bool secure = false,
bool uichannel = false, int num_buffers = 2);
bool startDataChannel(int ovid, int rotid, int size,
int fbnum, bool norot = false, bool uichannel = false,