Esempio n. 1
0
/* configure_shm - Negotiate Shared Memory configuration with teetz. */
static int configure_shm(void)
{
	struct smc_param param = { 0 };
	int ret = 0;

	if (shm_paddr)
		return -EINVAL;

	mutex_lock(&e_mutex_teez);
	param.a0 = TEESMC32_ST_FASTCALL_GET_SHM_CONFIG;
	tee_smc_call(&param);
	mutex_unlock(&e_mutex_teez);

	if (param.a0 != TEESMC_RETURN_OK) {
		dev_err(DEV, "shm service not available: %X", (uint)param.a0);
		ret = -EINVAL;
		goto out;
	}

	shm_paddr = param.a1;
	shm_size = param.a2;
	shm_cached = (bool)param.a3;

	if (shm_cached)
		shm_vaddr = ioremap_cached(shm_paddr, shm_size);
	else
		shm_vaddr = ioremap_nocache(shm_paddr, shm_size);

	if (shm_vaddr == NULL) {
		dev_err(DEV, "shm ioremap failed\n");
		ret = -ENOMEM;
		goto out;
	}

	TZop.Allocator = tee_shm_pool_create(
			DEV, shm_size, shm_vaddr, shm_paddr);

	if (!TZop.Allocator) {
		dev_err(DEV, "shm pool creation failed (%d)", shm_size);
		ret = -EINVAL;
		goto out;
	}

	if (shm_cached)
		tee_shm_pool_set_cached(TZop.Allocator);
out:
	if (ret)
		shm_paddr = 0;

	dev_dbg(DEV, "teetz shm: ret=%d pa=0x%lX va=0x%p size=%d, %scached",
		ret, shm_paddr, shm_vaddr, shm_size,
			shm_cached == 1 ? "" : "un");
	return ret;
}
Esempio n. 2
0
/* configure_shm - Negotiate Shared Memory configuration with teetz. */
static int configure_shm(struct tee_tz *ptee)
{
	struct smc_param param = { 0 };
	size_t shm_size = -1;
	int ret = 0;

	dev_dbg(DEV, ">\n");
	BUG_ON(!CAPABLE(ptee->tee));

	mutex_lock(&ptee->mutex);
	param.a0 = TEESMC32_ST_FASTCALL_GET_SHM_CONFIG;
	tee_smc_call(&param);
	mutex_unlock(&ptee->mutex);

	if (param.a0 != TEESMC_RETURN_OK) {
		dev_err(DEV, "shm service not available: %X", (uint)param.a0);
		ret = -EINVAL;
		goto out;
	}

	ptee->shm_paddr = param.a1;
	shm_size = param.a2;
	ptee->shm_cached = (bool)param.a3;

	if (ptee->shm_cached)
		ptee->shm_vaddr = ioremap_cache(ptee->shm_paddr, shm_size);
	else
		ptee->shm_vaddr = ioremap_nocache(ptee->shm_paddr, shm_size);

	if (ptee->shm_vaddr == NULL) {
		dev_err(DEV, "shm ioremap failed\n");
		ret = -ENOMEM;
		goto out;
	}

	ptee->shm_pool = tee_shm_pool_create(DEV, shm_size,
					     ptee->shm_vaddr, ptee->shm_paddr);

	if (!ptee->shm_pool) {
		dev_err(DEV, "shm pool creation failed (%zu)", shm_size);
		ret = -EINVAL;
		goto out;
	}

	if (ptee->shm_cached)
		tee_shm_pool_set_cached(ptee->shm_pool);
out:
	dev_dbg(DEV, "< ret=%d pa=0x%lX va=0x%p size=%zu, %scached",
		ret, ptee->shm_paddr, ptee->shm_vaddr, shm_size,
		(ptee->shm_cached == 1) ? "" : "un");
	return ret;
}