Allow OP-TEE driver to work without static shared memory

-----BEGIN PGP SIGNATURE-----
 
 iQJOBAABCgA4FiEEcK3MsDvGvFp6zV9ztbC4QZeP7NMFAly3SxcaHGplbnMud2lr
 bGFuZGVyQGxpbmFyby5vcmcACgkQtbC4QZeP7NNkOQ//ZIjVjNcjd60pNQ9Khq6M
 MnsLdanD5HoiD9flT1N5jHxCq8XAvS8pGOKyKWChtvqxTxfDCAKrk8l8hHogVQkx
 2k0CCw5gdg3p2R16mZ7LoNFluP27JFr1RFZm7S3jkRylXdPM0izGixMYI0Zrzkrb
 GhBGUwx0IU1TfRKF6QdPiyTuNZL5oFxpOYArkUryH66KmLWVrfBVCMEuHDi6XOsN
 YZTPcwcssd6gtycPGwc0aEJxZ/zCuP626rGAp17kBXwhAfZ30xYvNfEyqL64khb7
 RDIRxRetfibDMbmnCBbR5xFxo4byzN0dRhSlyRKo//MZvvhOOwApvO6V7oq137/h
 Az/2lDnWu3K+eCXjAxT0rcw7ktrhrNyFDMGN41YskzUsJMVYDYG7JElhTgPQ7Y6K
 ehaAE7EWakQy2amjDQQ8AuG7iFmCnGCqoBMjwyz7yNnABZgFxBVKvPKNTDV1sZIh
 7RGyR3xBLJtD6ra2Aw82JGx9vOpFv7eUNTER8N8orLchKlggVt+GYH8OVcCFPFJK
 FOX2GVQ13u3Rfx+bTyfiABJST00ZuBQ2SK91kjCDK9fXzrAdAn+yhrv7n5uIKVt+
 pLWF8gRou3iuLFhr9AvxYTqkI2KvOIsWar1wKUHdGJWnkfJZ61on1S+E4DVw6iQ2
 K4Mvr3ldMi9inufZ6AGlfiA=
 =AE1r
 -----END PGP SIGNATURE-----

Merge tag 'tee-optee-for-5.2' of http://git.linaro.org:/people/jens.wiklander/linux-tee into arm/drivers

Allow OP-TEE driver to work without static shared memory

* tag 'tee-optee-for-5.2' of http://git.linaro.org:/people/jens.wiklander/linux-tee:
  optee: allow to work without static shared memory

Signed-off-by: Olof Johansson <olof@lixom.net>
This commit is contained in:
Olof Johansson 2019-04-28 23:21:27 -07:00
commit aaf75f2b53
1 changed files with 48 additions and 30 deletions

View File

@ -419,9 +419,35 @@ static bool optee_msg_exchange_capabilities(optee_invoke_fn *invoke_fn,
return true;
}
static struct tee_shm_pool *optee_config_dyn_shm(void)
{
struct tee_shm_pool_mgr *priv_mgr;
struct tee_shm_pool_mgr *dmabuf_mgr;
void *rc;
rc = optee_shm_pool_alloc_pages();
if (IS_ERR(rc))
return rc;
priv_mgr = rc;
rc = optee_shm_pool_alloc_pages();
if (IS_ERR(rc)) {
tee_shm_pool_mgr_destroy(priv_mgr);
return rc;
}
dmabuf_mgr = rc;
rc = tee_shm_pool_alloc(priv_mgr, dmabuf_mgr);
if (IS_ERR(rc)) {
tee_shm_pool_mgr_destroy(priv_mgr);
tee_shm_pool_mgr_destroy(dmabuf_mgr);
}
return rc;
}
static struct tee_shm_pool *
optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm,
u32 sec_caps)
optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm)
{
union {
struct arm_smccc_res smccc;
@ -436,10 +462,11 @@ optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm,
struct tee_shm_pool_mgr *priv_mgr;
struct tee_shm_pool_mgr *dmabuf_mgr;
void *rc;
const int sz = OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE;
invoke_fn(OPTEE_SMC_GET_SHM_CONFIG, 0, 0, 0, 0, 0, 0, 0, &res.smccc);
if (res.result.status != OPTEE_SMC_RETURN_OK) {
pr_info("shm service not available\n");
pr_err("static shm service not available\n");
return ERR_PTR(-ENOENT);
}
@ -465,28 +492,15 @@ optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm,
}
vaddr = (unsigned long)va;
/*
* If OP-TEE can work with unregistered SHM, we will use own pool
* for private shm
*/
if (sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) {
rc = optee_shm_pool_alloc_pages();
if (IS_ERR(rc))
goto err_memunmap;
priv_mgr = rc;
} else {
const size_t sz = OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE;
rc = tee_shm_pool_mgr_alloc_res_mem(vaddr, paddr, sz,
3 /* 8 bytes aligned */);
if (IS_ERR(rc))
goto err_memunmap;
priv_mgr = rc;
rc = tee_shm_pool_mgr_alloc_res_mem(vaddr, paddr, sz,
3 /* 8 bytes aligned */);
if (IS_ERR(rc))
goto err_memunmap;
priv_mgr = rc;
vaddr += sz;
paddr += sz;
size -= sz;
}
vaddr += sz;
paddr += sz;
size -= sz;
rc = tee_shm_pool_mgr_alloc_res_mem(vaddr, paddr, size, PAGE_SHIFT);
if (IS_ERR(rc))
@ -552,7 +566,7 @@ static optee_invoke_fn *get_invoke_func(struct device_node *np)
static struct optee *optee_probe(struct device_node *np)
{
optee_invoke_fn *invoke_fn;
struct tee_shm_pool *pool;
struct tee_shm_pool *pool = ERR_PTR(-EINVAL);
struct optee *optee = NULL;
void *memremaped_shm = NULL;
struct tee_device *teedev;
@ -581,13 +595,17 @@ static struct optee *optee_probe(struct device_node *np)
}
/*
* We have no other option for shared memory, if secure world
* doesn't have any reserved memory we can use we can't continue.
* Try to use dynamic shared memory if possible
*/
if (!(sec_caps & OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM))
return ERR_PTR(-EINVAL);
if (sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM)
pool = optee_config_dyn_shm();
/*
* If dynamic shared memory is not available or failed - try static one
*/
if (IS_ERR(pool) && (sec_caps & OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM))
pool = optee_config_shm_memremap(invoke_fn, &memremaped_shm);
pool = optee_config_shm_memremap(invoke_fn, &memremaped_shm, sec_caps);
if (IS_ERR(pool))
return (void *)pool;