本文整理汇总了C++中ION_HEAP函数的典型用法代码示例。如果您正苦于以下问题:C++ ION_HEAP函数的具体用法?C++ ION_HEAP怎么用?C++ ION_HEAP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ION_HEAP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: res_trk_close_secure_session
int res_trk_close_secure_session()
{
int rc;
if (res_trk_check_for_sec_session() == 1 &&
resource_context.sec_clk_heap) {
pr_err("Unsecuring....\n");
mutex_lock(&resource_context.secure_lock);
rc = res_trk_enable_iommu_clocks();
if (rc) {
pr_err("IOMMU clock enabled failed while close\n");
goto error_close;
}
msm_ion_unsecure_heap(ION_HEAP(resource_context.cmd_mem_type));
msm_ion_unsecure_heap(ION_HEAP(resource_context.memtype));
if (resource_context.vidc_platform_data->secure_wb_heap)
msm_ion_unsecure_heap(ION_HEAP(ION_CP_WB_HEAP_ID));
res_trk_disable_iommu_clocks();
resource_context.sec_clk_heap = 0;
mutex_unlock(&resource_context.secure_lock);
}
return 0;
error_close:
mutex_unlock(&resource_context.secure_lock);
return rc;
}
示例2: res_trk_get_mem_type
int res_trk_get_mem_type(void)
{
int mem_type = -1;
switch (resource_context.res_mem_type) {
case DDL_FW_MEM:
mem_type = ION_HEAP(resource_context.fw_mem_type);
return mem_type;
case DDL_MM_MEM:
mem_type = resource_context.memtype;
break;
case DDL_CMD_MEM:
if (res_trk_check_for_sec_session())
mem_type = resource_context.cmd_mem_type;
else
mem_type = resource_context.memtype;
break;
default:
return mem_type;
}
if (resource_context.vidc_platform_data->enable_ion) {
if (res_trk_check_for_sec_session()) {
mem_type = ION_HEAP(mem_type);
if (resource_context.res_mem_type != DDL_FW_MEM)
mem_type |= ION_SECURE;
else if (res_trk_is_cp_enabled())
mem_type |= ION_SECURE;
} else
mem_type = (ION_HEAP(mem_type) |
ION_HEAP(ION_IOMMU_HEAP_ID));
}
return mem_type;
}
示例3: alloc_ion_mem
int alloc_ion_mem(unsigned int size)
{
if (!overlay_supported)
return -EINVAL;
int result;
struct ion_fd_data fd_data;
struct ion_allocation_data ionAllocData;
mem_info.ion_fd = open("/dev/ion", O_RDWR|O_DSYNC);
if (mem_info.ion_fd < 0) {
perror("ERROR: Can't open ion ");
return -errno;
}
ionAllocData.flags = 0;
ionAllocData.len = size;
ionAllocData.align = sysconf(_SC_PAGESIZE);
#ifdef NEW_ION_HEAP
ionAllocData.heap_id_mask =
#else
ionAllocData.heap_mask =
#endif
ION_HEAP(ION_IOMMU_HEAP_ID) |
ION_HEAP(ION_SYSTEM_CONTIG_HEAP_ID);
result = ioctl(mem_info.ion_fd, ION_IOC_ALLOC, &ionAllocData);
if(result){
perror("ION_IOC_ALLOC Failed ");
close(mem_info.ion_fd);
return result;
}
fd_data.handle = ionAllocData.handle;
mem_info.handle_data.handle = ionAllocData.handle;
result = ioctl(mem_info.ion_fd, ION_IOC_MAP, &fd_data);
if (result) {
perror("ION_IOC_MAP Failed ");
free_ion_mem();
return result;
}
mem_info.mem_buf = (unsigned char *)mmap(NULL, size, PROT_READ |
PROT_WRITE, MAP_SHARED, fd_data.fd, 0);
mem_info.mem_fd = fd_data.fd;
if (!mem_info.mem_buf) {
perror("ERROR: mem_buf MAP_FAILED ");
free_ion_mem();
return -ENOMEM;
}
return 0;
}
示例4: alloc_ion_mem
static int alloc_ion_mem(struct fb_qcom_overlay_data *data, unsigned int size)
{
int result;
struct ion_fd_data fd_data;
struct ion_allocation_data ionAllocData;
data->ion_fd = open("/dev/ion", O_RDWR|O_DSYNC);
if (data->ion_fd < 0)
{
ERROR("ERROR: Can't open ion ");
return -errno;
}
ionAllocData.flags = 0;
ionAllocData.len = size;
ionAllocData.align = sysconf(_SC_PAGESIZE);
ionAllocData.heap_mask =
ION_HEAP(ION_IOMMU_HEAP_ID) |
ION_HEAP(21); // ION_SYSTEM_CONTIG_HEAP_ID
result = ioctl(data->ion_fd, ION_IOC_ALLOC, &ionAllocData);
if(result)
{
ERROR("ION_IOC_ALLOC Failed ");
close(data->ion_fd);
return result;
}
fd_data.handle = ionAllocData.handle;
data->handle_data.handle = ionAllocData.handle;
result = ioctl(data->ion_fd, ION_IOC_MAP, &fd_data);
if (result)
{
ERROR("ION_IOC_MAP Failed ");
free_ion_mem(data);
return result;
}
data->mem_buf = (uint8_t*)mmap(NULL, size, PROT_READ |
PROT_WRITE, MAP_SHARED, fd_data.fd, 0);
data->mem_fd = fd_data.fd;
if (!data->mem_buf)
{
ERROR("ERROR: mem_buf MAP_FAILED ");
free_ion_mem(data);
return -ENOMEM;
}
return 0;
}
示例5: ion_unsecure_heap
int ion_unsecure_heap(struct ion_device *dev, int heap_id, int version,
void *data)
{
struct rb_node *n;
int ret_val = 0;
/*
* traverse the list of heaps available in this system
* and find the heap that is specified.
*/
mutex_lock(&dev->lock);
for (n = rb_first(&dev->heaps); n != NULL; n = rb_next(n)) {
struct ion_heap *heap = rb_entry(n, struct ion_heap, node);
if (heap->type != ION_HEAP_TYPE_CP)
continue;
if (ION_HEAP(heap->id) != heap_id)
continue;
if (heap->ops->secure_heap)
ret_val = heap->ops->unsecure_heap(heap, version, data);
else
ret_val = -EINVAL;
break;
}
mutex_unlock(&dev->lock);
return ret_val;
}
示例6: alloc_ion_mem
static int alloc_ion_mem(struct smem_client *client, size_t size,
u32 align, u32 flags, struct msm_smem *mem)
{
struct ion_handle *hndl;
size_t len;
int rc = 0;
flags = flags | ION_HEAP(ION_CP_MM_HEAP_ID);
hndl = ion_alloc(client->clnt, size, align, flags);
if (IS_ERR_OR_NULL(hndl)) {
pr_err("Failed to allocate shared memory = %p, %d, %d, 0x%x\n",
client, size, align, flags);
rc = -ENOMEM;
goto fail_shared_mem_alloc;
}
mem->mem_type = client->mem_type;
mem->smem_priv = hndl;
if (ion_phys(client->clnt, hndl, &mem->paddr, &len)) {
pr_err("Failed to get physical address\n");
rc = -EIO;
goto fail_map;
}
mem->device_addr = mem->paddr;
mem->size = size;
mem->kvaddr = ion_map_kernel(client->clnt, hndl, 0);
if (!mem->kvaddr) {
pr_err("Failed to map shared mem in kernel\n");
rc = -EIO;
goto fail_map;
}
return rc;
fail_map:
ion_free(client->clnt, hndl);
fail_shared_mem_alloc:
return rc;
}
示例7: ion_secure_heap
int ion_secure_heap(struct ion_device *dev, int heap_id, int version,
void *data)
{
struct rb_node *n;
int ret_val = 0;
/*
* traverse the list of heaps available in this system
* and find the heap that is specified.
*/
#if defined(CONFIG_MACH_LGE_L9II_OPEN_EU)
down_write(&dev->lock);
#else
mutex_lock(&dev->lock);
#endif
for (n = rb_first(&dev->heaps); n != NULL; n = rb_next(n)) {
struct ion_heap *heap = rb_entry(n, struct ion_heap, node);
if (heap->type != ION_HEAP_TYPE_CP)
continue;
if (ION_HEAP(heap->id) != heap_id)
continue;
if (heap->ops->secure_heap)
ret_val = heap->ops->secure_heap(heap, version, data);
else
ret_val = -EINVAL;
break;
}
#if defined(CONFIG_MACH_LGE_L9II_OPEN_EU)
up_write(&dev->lock);
#else
mutex_unlock(&dev->lock);
#endif
return ret_val;
}
示例8: alloc_ion_mem
static int alloc_ion_mem(struct smem_client *client, size_t size,
u32 align, u32 flags, int domain, int partition,
struct msm_smem *mem)
{
struct ion_handle *hndl;
unsigned long iova = 0;
unsigned long buffer_size = 0;
unsigned long ionflags = 0;
unsigned long heap_mask = 0;
int rc = 0;
if (flags == SMEM_CACHED)
ionflags = ION_SET_CACHED(ionflags);
else
ionflags = ION_SET_UNCACHED(ionflags);
heap_mask = ION_HEAP(ION_CP_MM_HEAP_ID);
if (align < 4096)
align = 4096;
size = (size + 4095) & (~4095);
pr_debug("\n in %s domain: %d, Partition: %d\n",
__func__, domain, partition);
hndl = ion_alloc(client->clnt, size, align, heap_mask, ionflags);
if (IS_ERR_OR_NULL(hndl)) {
pr_err("Failed to allocate shared memory = %p, %d, %d, 0x%x\n",
client, size, align, ionflags);
rc = -ENOMEM;
goto fail_shared_mem_alloc;
}
mem->mem_type = client->mem_type;
mem->smem_priv = hndl;
mem->domain = domain;
mem->partition_num = partition;
mem->kvaddr = ion_map_kernel(client->clnt, hndl);
if (!mem->kvaddr) {
pr_err("Failed to map shared mem in kernel\n");
rc = -EIO;
goto fail_map;
}
rc = get_device_address(client->clnt, hndl, mem->domain,
mem->partition_num, align, &iova, &buffer_size);
if (rc) {
pr_err("Failed to get device address: %d\n", rc);
goto fail_device_address;
}
mem->device_addr = iova;
pr_debug("device_address = 0x%lx, kvaddr = 0x%p\n",
mem->device_addr, mem->kvaddr);
mem->size = size;
return rc;
fail_device_address:
ion_unmap_kernel(client->clnt, hndl);
fail_map:
ion_free(client->clnt, hndl);
fail_shared_mem_alloc:
return rc;
}
示例9: res_trk_close_secure_session
int res_trk_close_secure_session()
{
int rc;
mutex_lock(&resource_context.secure_lock);
rc = res_trk_enable_iommu_clocks();
if (rc) {
pr_err("IOMMU clock enabled failed while close");
goto error_close;
}
msm_ion_unsecure_heap(ION_HEAP(resource_context.memtype));
msm_ion_unsecure_heap(ION_HEAP(resource_context.cmd_mem_type));
res_trk_disable_iommu_clocks();
resource_context.secure_session = 0;
mutex_unlock(&resource_context.secure_lock);
return 0;
error_close:
mutex_unlock(&resource_context.secure_lock);
return rc;
}
示例10: res_trk_open_secure_session
int res_trk_open_secure_session()
{
int rc;
mutex_lock(&resource_context.secure_lock);
if (resource_context.secure_session) {
pr_err("Secure session already open");
rc = -EBUSY;
goto error_open;
}
resource_context.secure_session = 1;
rc = res_trk_enable_iommu_clocks();
if (rc) {
pr_err("IOMMU clock enabled failed while open");
goto error_open;
}
msm_ion_secure_heap(ION_HEAP(resource_context.memtype));
msm_ion_secure_heap(ION_HEAP(resource_context.cmd_mem_type));
res_trk_disable_iommu_clocks();
mutex_unlock(&resource_context.secure_lock);
return 0;
error_open:
mutex_unlock(&resource_context.secure_lock);
return rc;
}
示例11: ION_HEAP
uint8_t *do_mmap_ion(int ion_fd, struct ion_allocation_data *alloc,
struct ion_fd_data *ion_info_fd, int *mapFd)
{
void *ret; /* returned virtual address */
int rc = 0;
struct ion_handle_data handle_data;
/* to make it page size aligned */
alloc->len = (alloc->len + 4095) & (~4095);
#ifdef TARGET_7x27A
alloc->flags = ION_HEAP(CAMERA_ION_HEAP_ID);
#endif
rc = ioctl(ion_fd, ION_IOC_ALLOC, alloc);
if (rc < 0) {
CDBG_ERROR("ION allocation failed\n");
goto ION_ALLOC_FAILED;
}
ion_info_fd->handle = alloc->handle;
rc = ioctl(ion_fd, ION_IOC_SHARE, ion_info_fd);
if (rc < 0) {
CDBG_ERROR("ION map failed %s\n", strerror(errno));
goto ION_MAP_FAILED;
}
*mapFd = ion_info_fd->fd;
ret = mmap(NULL,
alloc->len,
PROT_READ | PROT_WRITE,
MAP_SHARED,
*mapFd,
0);
if (ret == MAP_FAILED) {
CDBG_ERROR("ION_MMAP_FAILED: %s (%d)\n", strerror(errno), errno);
goto ION_MAP_FAILED;
}
return ret;
ION_MAP_FAILED:
handle_data.handle = ion_info_fd->handle;
ioctl(ion_fd, ION_IOC_FREE, &handle_data);
ION_ALLOC_FAILED:
return NULL;
}
示例12: mpq_dmx_channel_mem_alloc
/**
* Allocate memory for channel output of specific TSIF.
*
* @tsif: The TSIF id to which memory should be allocated.
*
* Return error status
*/
static int mpq_dmx_channel_mem_alloc(int tsif)
{
int result;
size_t len;
MPQ_DVB_DBG_PRINT("%s(%d)\n", __func__, tsif);
mpq_dmx_tspp_info.tsif[tsif].ch_mem_heap_handle =
ion_alloc(mpq_dmx_tspp_info.ion_client,
(mpq_dmx_tspp_info.tsif[tsif].buffer_count *
TSPP_DESCRIPTOR_SIZE),
SZ_4K,
ION_HEAP(tspp_out_ion_heap),
0); /* non-cached */
if (IS_ERR_OR_NULL(mpq_dmx_tspp_info.tsif[tsif].ch_mem_heap_handle)) {
MPQ_DVB_ERR_PRINT("%s: ion_alloc() failed\n", __func__);
mpq_dmx_channel_mem_free(tsif);
return -ENOMEM;
}
/* save virtual base address of heap */
mpq_dmx_tspp_info.tsif[tsif].ch_mem_heap_virt_base =
ion_map_kernel(mpq_dmx_tspp_info.ion_client,
mpq_dmx_tspp_info.tsif[tsif].ch_mem_heap_handle);
if (IS_ERR_OR_NULL(mpq_dmx_tspp_info.tsif[tsif].
ch_mem_heap_virt_base)) {
MPQ_DVB_ERR_PRINT("%s: ion_map_kernel() failed\n", __func__);
mpq_dmx_channel_mem_free(tsif);
return -ENOMEM;
}
/* save physical base address of heap */
result = ion_phys(mpq_dmx_tspp_info.ion_client,
mpq_dmx_tspp_info.tsif[tsif].ch_mem_heap_handle,
&(mpq_dmx_tspp_info.tsif[tsif].ch_mem_heap_phys_base), &len);
if (result < 0) {
MPQ_DVB_ERR_PRINT("%s: ion_phys() failed\n", __func__);
mpq_dmx_channel_mem_free(tsif);
return -ENOMEM;
}
return 0;
}
示例13: ion_unsecure_heap
int ion_unsecure_heap(struct ion_device *dev, int heap_id, int version,
void *data)
{
struct rb_node *n;
int ret_val = 0;
mutex_lock(&dev->lock);
for (n = rb_first(&dev->heaps); n != NULL; n = rb_next(n)) {
struct ion_heap *heap = rb_entry(n, struct ion_heap, node);
if (heap->type != ION_HEAP_TYPE_CP)
continue;
if (ION_HEAP(heap->id) != heap_id)
continue;
if (heap->ops->secure_heap)
ret_val = heap->ops->unsecure_heap(heap, version, data);
else
ret_val = -EINVAL;
break;
}
mutex_unlock(&dev->lock);
return ret_val;
}
示例14: qcom_km_ION_memalloc
static int32_t qcom_km_ION_memalloc(struct qcom_km_ion_info_t *handle,
uint32_t size)
{
int32_t ret = 0;
int32_t iret = 0;
int32_t fd = 0;
unsigned char *v_addr;
struct ion_allocation_data ion_alloc_data;
int32_t ion_fd;
int32_t rc;
struct ion_fd_data ifd_data;
struct ion_handle_data handle_data;
/* open ION device for memory management
* O_DSYNC -> uncached memory
*/
if(handle == NULL){
ALOGE("Error:: null handle received");
return -1;
}
ion_fd = open("/dev/ion", O_RDONLY | O_DSYNC);
if (ion_fd < 0) {
ALOGE("Error::Cannot open ION device");
return -1;
}
handle->ion_sbuffer = NULL;
handle->ifd_data_fd = 0;
/* Size of allocation */
ion_alloc_data.len = (size + 4095) & (~4095);
/* 4K aligned */
ion_alloc_data.align = 4096;
/* memory is allocated from EBI heap */
ion_alloc_data.heap_mask= ION_HEAP(ION_QSECOM_HEAP_ID);
/* Set the memory to be uncached */
ion_alloc_data.flags = 0;
/* IOCTL call to ION for memory request */
rc = ioctl(ion_fd, ION_IOC_ALLOC, &ion_alloc_data);
if (rc) {
ret = -1;
goto alloc_fail;
}
if (ion_alloc_data.handle != NULL) {
ifd_data.handle = ion_alloc_data.handle;
} else {
ret = -1;
goto alloc_fail;
}
/* Call MAP ioctl to retrieve the ifd_data.fd file descriptor */
rc = ioctl(ion_fd, ION_IOC_MAP, &ifd_data);
if (rc) {
ret = -1;
goto ioctl_fail;
}
/* Make the ion mmap call */
v_addr = (unsigned char *)mmap(NULL, ion_alloc_data.len,
PROT_READ | PROT_WRITE,
MAP_SHARED, ifd_data.fd, 0);
if (v_addr == MAP_FAILED) {
ALOGE("Error::ION MMAP failed");
ret = -1;
goto map_fail;
}
handle->ion_fd = ion_fd;
handle->ifd_data_fd = ifd_data.fd;
handle->ion_sbuffer = v_addr;
handle->ion_alloc_handle.handle = ion_alloc_data.handle;
handle->sbuf_len = size;
return ret;
map_fail:
if (handle->ion_sbuffer != NULL) {
iret = munmap(handle->ion_sbuffer, ion_alloc_data.len);
if (iret)
ALOGE("Error::Failed to unmap memory for load image. ret = %d", ret);
}
ioctl_fail:
handle_data.handle = ion_alloc_data.handle;
if (handle->ifd_data_fd)
close(handle->ifd_data_fd);
iret = ioctl(ion_fd, ION_IOC_FREE, &handle_data);
if (iret) {
ALOGE("Error::ION FREE ioctl returned error = %d",iret);
}
alloc_fail:
if (ion_fd > 0)
close(ion_fd);
return ret;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_hardware_qcom_keymaster,代码行数:97,代码来源:keymaster_qcom.cpp
示例15: ion_memalloc
static int
ion_memalloc(struct ion_buf_handle *buf, uint32_t size, uint32_t heap)
{
struct ion_allocation_data alloc_data;
struct ion_fd_data fd_data;
unsigned char *va;
struct ion_handle_data handle_data;
int ion_fd;
int rc;
ion_fd = open("/dev/ion", O_RDONLY);
if (ion_fd < 0) {
fprintf(stderr, "Cannot open ION device (%s)\n", strerror(errno));
return -1;
}
alloc_data.len = (size + 4095) & ~4095;
alloc_data.align = 4096;
alloc_data.flags = 0;
alloc_data.heap_id_mask = ION_HEAP(heap);
/* Set the buffers to be uncached */
alloc_data.flags = 0;
rc = ioctl(ion_fd, ION_IOC_ALLOC, &alloc_data);
if (rc) {
fprintf(stderr, "ION buffer allocation failed (%s)\n",
strerror(errno));
goto alloc_fail;
}
if (alloc_data.handle) {
fd_data.handle = alloc_data.handle;
} else {
fprintf(stderr, "ION alloc data returned NULL\n");
rc = -1;
goto alloc_fail;
}
rc = ioctl(ion_fd, ION_IOC_MAP, &fd_data);
if (rc) {
fprintf(stderr, "ION map call failed(%s)\n", strerror(errno));
goto ioctl_fail;
}
va = mmap(NULL, alloc_data.len, PROT_READ | PROT_WRITE,
MAP_SHARED, fd_data.fd, 0);
if (va == MAP_FAILED) {
fprintf(stderr, "ION memory map failed (%s)\n", strerror(errno));
rc = -1;
goto map_fail;
}
buf->ion_fd = ion_fd;
buf->ifd_data_fd = fd_data.fd;
buf->buffer = va;
buf->ion_alloc_handle.handle = alloc_data.handle;
buf->buffer_len = alloc_data.len;
memset(buf->buffer, 0, buf->buffer_len);
return 0;
map_fail:
ioctl_fail:
handle_data.handle = alloc_data.handle;
if (buf->ifd_data_fd)
close(buf->ifd_data_fd);
rc = ioctl(ion_fd, ION_IOC_FREE, &handle_data);
if (rc)
fprintf(stderr, "ION free failed (%s)\n", strerror(errno));
alloc_fail:
if (ion_fd >= 0)
close(ion_fd);
buf->ion_fd = -1;
return rc;
}