int gralloc_register_buffer(gralloc_module_t const* module,
                            buffer_handle_t handle)
{
    int err;
    if (private_handle_t::validate(handle) < 0)
        return -EINVAL;

    err = gralloc_map(module, handle);

    private_handle_t* hnd = (private_handle_t*)handle;
    ALOGV("%s: base %p %d %d %d %d\n", __func__, hnd->base, hnd->size,
          hnd->width, hnd->height, hnd->stride);

    int ret;
    ret = ion_import(getIonFd(module), hnd->fd, &hnd->handle);
    if (ret)
        ALOGE("error importing handle %d %x\n", hnd->fd, hnd->format);
    if (hnd->fd1 >= 0) {
        ret = ion_import(getIonFd(module), hnd->fd1, &hnd->handle1);
        if (ret)
            ALOGE("error importing handle1 %d %x\n", hnd->fd1, hnd->format);
    }
    if (hnd->fd2 >= 0) {
        ret = ion_import(getIonFd(module), hnd->fd2, &hnd->handle2);
        if (ret)
            ALOGE("error importing handle2 %d %x\n", hnd->fd2, hnd->format);
    }

    return err;
}
Exemple #2
0
uint32_t GuiExtIONDevice::import(int ion_fd)
{
    if (m_dev_fd <= 0) return 0;

    struct ion_handle* ion_hnd;
    if (ion_import(m_dev_fd, ion_fd, &ion_hnd))
    {
        GUIEXT_LOGE("Failed to import ION handle: %s ", strerror(errno));
        return 0;
    }

    return (unsigned int)ion_hnd;
}
unsigned int IonGetAddr(void *handle)
{
	  unsigned int phy_adr=0;
	  struct ion_handle *handle_ion;
		private_handle_t* hnd = NULL;
    SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
    Globctx->ion_fd = ion_open();		
    if( Globctx->ion_fd != -1 )
    {		
				hnd = (private_handle_t*)handle;
				ion_import(Globctx->ion_fd,hnd->share_fd, &handle_ion);
				phy_adr= (unsigned int)ion_getphyadr(Globctx->ion_fd,(void *)(handle_ion));
				ion_sync_fd(Globctx->ion_fd,hnd->share_fd);
				ion_close(Globctx->ion_fd);
				Globctx->ion_fd = -1;
		}
    return phy_adr;  
}
struct ion_handle *ion_import_fd(struct ion_client *client, int fd)
{
	struct file *file = fget(fd);
	struct ion_handle *handle;

	if (!file) {
		pr_err("%s: imported fd not found in file table.\n", __func__);
		return ERR_PTR(-EINVAL);
	}
	if (file->f_op != &ion_share_fops) {
		pr_err("%s: imported file %s is not a shared ion"
			" file.", __func__, file->f_dentry->d_name.name);
		handle = ERR_PTR(-EINVAL);
		goto end;
	}
	handle = ion_import(client, file->private_data);
end:
	fput(file);
	return handle;
}
Exemple #5
0
/*
 * Invokes a client command to the Secure World
 */
int tf_invoke_client_command(
	struct tf_connection *connection,
	union tf_command *command,
	union tf_answer *answer)
{
	int error = 0;
	struct tf_shmem_desc *shmem_desc[4] = {NULL};
	int i;
#ifdef CONFIG_TF_ION
	struct ion_handle *new_handle = NULL;
#endif /* CONFIG_TF_ION */

	dprintk(KERN_INFO "tf_invoke_client_command(%p)\n", connection);

	command->release_shared_memory.message_size =
		(sizeof(struct tf_command_invoke_client_command) -
			sizeof(struct tf_command_header)) / 4;

#ifdef CONFIG_TF_ZEBRA
	error = tf_crypto_try_shortcuted_update(connection,
		(struct tf_command_invoke_client_command *) command,
		(struct tf_answer_invoke_client_command *) answer);
	if (error == 0)
		return error;
#endif

	/* Map the tmprefs */
	for (i = 0; i < 4; i++) {
		int param_type = TF_GET_PARAM_TYPE(
			command->invoke_client_command.param_types, i);

		if ((param_type & (TF_PARAM_TYPE_MEMREF_FLAG |
					TF_PARAM_TYPE_REGISTERED_MEMREF_FLAG))
				== TF_PARAM_TYPE_MEMREF_FLAG) {
			/* A temporary memref: map it */
			error = tf_map_temp_shmem(connection,
					&command->invoke_client_command.
						params[i].temp_memref,
					param_type, &shmem_desc[i]);
			if (error != 0) {
				dprintk(KERN_ERR
					"tf_invoke_client_command: "
					"unable to map temporary memory "
					"block\n (%08X)", error);
				goto error;
			}
		}
#ifdef CONFIG_TF_ION
		else if (param_type == TF_PARAM_TYPE_MEMREF_ION_HANDLE) {
			struct tf_command_invoke_client_command *invoke;
			ion_phys_addr_t ion_addr;
			size_t ion_len;
			struct ion_buffer *buffer;

			if (connection->ion_client == NULL) {
				connection->ion_client = ion_client_create(
					zebra_ion_device,
					(1 << ION_HEAP_TYPE_CARVEOUT),
					"tf");
			}
			if (connection->ion_client == NULL) {
				dprintk(KERN_ERR "%s(%p): "
					"unable to create ion client\n",
					__func__, connection);
				error = -EFAULT;
				goto error;
			}

			invoke = &command->invoke_client_command;

			dprintk(KERN_INFO "ion_handle %x",
				invoke->params[i].value.a);
			buffer = ion_share(connection->ion_client,
				(struct ion_handle *)invoke->params[i].value.a);
			if (buffer == NULL) {
				dprintk(KERN_ERR "%s(%p): "
					"unable to share ion handle\n",
					__func__, connection);
				error = -EFAULT;
				goto error;
			}

			dprintk(KERN_INFO "ion_buffer %p", buffer);
			new_handle = ion_import(connection->ion_client, buffer);
			if (new_handle == NULL) {
				dprintk(KERN_ERR "%s(%p): "
					"unable to import ion buffer\n",
					__func__, connection);
				error = -EFAULT;
				goto error;
			}

			dprintk(KERN_INFO "new_handle %x", new_handle);
			error = ion_phys(connection->ion_client,
					new_handle,
					&ion_addr,
					&ion_len);
			if (error) {
				dprintk(KERN_ERR
				"%s: unable to convert ion handle "
				"0x%08X (error code 0x%08X)\n",
				__func__,
				new_handle,
				error);
				error = -EINVAL;
				goto error;
			}
			dprintk(KERN_INFO
			"%s: handle=0x%08x phys_add=0x%08x length=0x%08x\n",
			__func__, invoke->params[i].value.a, ion_addr, ion_len);

			invoke->params[i].value.a = (u32) ion_addr;
			invoke->params[i].value.b = (u32) ion_len;

			invoke->param_types &= ~((0xF) << (4*i));
			invoke->param_types |=
				TF_PARAM_TYPE_VALUE_INPUT << (4*i);
		}
#endif /* CONFIG_TF_ION */
	}

	command->invoke_client_command.device_context =
		connection->device_context;

	error = tf_send_receive(&connection->dev->sm, command,
		answer, connection, true);

error:
#ifdef CONFIG_TF_ION
	if (new_handle != NULL)
		ion_free(connection->ion_client, new_handle);
#endif /* CONFIG_TF_ION */
	/* Unmap de temp mem refs */
	for (i = 0; i < 4; i++) {
		if (shmem_desc[i] != NULL) {
			dprintk(KERN_INFO "tf_invoke_client_command: "
				"UnMatemp_memref %d\n ", i);

			tf_unmap_shmem(connection, shmem_desc[i], 0);
		}
	}

	if (error != 0)
		dprintk(KERN_ERR "tf_invoke_client_command returns %d\n",
			error);
	else
		dprintk(KERN_ERR "tf_invoke_client_command returns "
			"error_code 0x%08X\n",
			answer->invoke_client_command.error_code);

	return error;
}
Exemple #6
0
//-----------------------------------------------------------------------------
MINT32 IMemDrvImp::freeVirtBuf(
    IMEM_BUF_INFO* pInfo)
{
	IMEM_INF("mID[0x%x]/size[0x%x]/VA[0x%x]/PA[0x%x]",pInfo->memID,pInfo->size,pInfo->virtAddr,pInfo->phyAddr);
    IMEM_DRV_DELAY

#if defined (__ISP_USE_PMEM__)
    //
    //if ( BUF_TYPE_PMEM != pInfo->type ) {
    //    IMEM_ERR("ERROR:mem type(%d)",pInfo->type);
    //    return -1;
    //}
    //
    IMEM_DBG("pmem ID[0x%x]",pInfo->memID);
    //
	if( pInfo->virtAddr != 0 )
	{
		::pmem_free(
			(MUINT8*)(pInfo->virtAddr),
			pInfo->size,
			pInfo->memID);
	}
//#elif defined (__ISP_USE_STD_M4U__) || defined (__ISP_USE_ION__)
#else
    //
    //if ( BUF_TYPE_STD_M4U == pInfo->type ) {
    if ( IMEM_MIN_ION_FD > pInfo->memID ) {
        if ( pInfo->virtAddr != 0 ) {
            ::free((MUINT8 *)pInfo->virtAddr);
        }

    }
    //
#if defined (__ISP_USE_ION__)
    //
    else /*if ( BUF_TYPE_ION == pInfo->type )*/ {
        struct ion_handle *pIonHandle;
        MINT32 IonBufFd;

        //struct ion_handle_data handle_data;
        //struct ion_fd_data fd_data;
        //
        //if ( BUF_TYPE_ION != pInfo->type ) {
        //    IMEM_ERR("ERROR:mem type(%d)",pInfo->type);
        //    return -1;
        //}
        //
        IMEM_DBG("ionFd[0x%x]",pInfo->memID);
        //a. get handle of ION_IOC_SHARE from fd_data.fd
        IonBufFd = pInfo->memID;
        if(ion_import(
            mIonDrv,
            IonBufFd,
            &pIonHandle))
        {
            IMEM_ERR("ion_import fail(0x%x)",IonBufFd);
			IMEM_ERR("cBuf ID[0x%x]/size[0x%x]/VA[0x%x]/PA[0x%x]/S[%d]/C[%d]",pInfo->memID,pInfo->size,pInfo->virtAddr,pInfo->phyAddr,pInfo->bufSecu,pInfo->bufCohe);
            return -1;
        }
        //free for IMPORT ref cnt
        if(ion_free(
            mIonDrv,
            pIonHandle))
        {
            IMEM_ERR("ion_free fail");
			IMEM_ERR("cBuf ID[0x%x]/size[0x%x]/VA[0x%x]/PA[0x%x]/S[%d]/C[%d]",pInfo->memID,pInfo->size,pInfo->virtAddr,pInfo->phyAddr,pInfo->bufSecu,pInfo->bufCohe);
            return -1;
        }
        //b. pair of mmap
        ion_munmap(mIonDrv, (char*)pInfo->virtAddr, pInfo->size);
        //c. pair of ION_IOC_SHARE
        ion_share_close(mIonDrv, pInfo->memID);
        //d. pair of ION_IOC_ALLOC
        if(ion_free(
            mIonDrv,
            pIonHandle))
        {
            IMEM_ERR("ion_free fail");
			IMEM_ERR("cBuf ID[0x%x]/size[0x%x]/VA[0x%x]/PA[0x%x]/S[%d]/C[%d]",pInfo->memID,pInfo->size,pInfo->virtAddr,pInfo->phyAddr,pInfo->bufSecu,pInfo->bufCohe);
            return -1;
        }
    }
#else
    else{