Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

optee: smc abi: dynamic protected memory allocation

Add support in the OP-TEE backend driver for dynamic protected memory
allocation using the SMC ABI.

Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>

+75 -3
+75 -3
drivers/tee/optee/smc_abi.c
··· 965 965 return rc; 966 966 } 967 967 968 + static int optee_smc_lend_protmem(struct optee *optee, struct tee_shm *protmem, 969 + u32 *mem_attrs, unsigned int ma_count, 970 + u32 use_case) 971 + { 972 + struct optee_shm_arg_entry *entry; 973 + struct optee_msg_arg *msg_arg; 974 + struct tee_shm *shm; 975 + u_int offs; 976 + int rc; 977 + 978 + msg_arg = optee_get_msg_arg(optee->ctx, 2, &entry, &shm, &offs); 979 + if (IS_ERR(msg_arg)) 980 + return PTR_ERR(msg_arg); 981 + 982 + msg_arg->cmd = OPTEE_MSG_CMD_LEND_PROTMEM; 983 + msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT; 984 + msg_arg->params[0].u.value.a = use_case; 985 + msg_arg->params[1].attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT; 986 + msg_arg->params[1].u.tmem.buf_ptr = protmem->paddr; 987 + msg_arg->params[1].u.tmem.size = protmem->size; 988 + msg_arg->params[1].u.tmem.shm_ref = (u_long)protmem; 989 + 990 + rc = optee->ops->do_call_with_arg(optee->ctx, shm, offs, false); 991 + if (rc) 992 + goto out; 993 + if (msg_arg->ret != TEEC_SUCCESS) { 994 + rc = -EINVAL; 995 + goto out; 996 + } 997 + protmem->sec_world_id = (u_long)protmem; 998 + 999 + out: 1000 + optee_free_msg_arg(optee->ctx, entry, offs); 1001 + return rc; 1002 + } 1003 + 1004 + static int optee_smc_reclaim_protmem(struct optee *optee, 1005 + struct tee_shm *protmem) 1006 + { 1007 + struct optee_shm_arg_entry *entry; 1008 + struct optee_msg_arg *msg_arg; 1009 + struct tee_shm *shm; 1010 + u_int offs; 1011 + int rc; 1012 + 1013 + msg_arg = optee_get_msg_arg(optee->ctx, 1, &entry, &shm, &offs); 1014 + if (IS_ERR(msg_arg)) 1015 + return PTR_ERR(msg_arg); 1016 + 1017 + msg_arg->cmd = OPTEE_MSG_CMD_RECLAIM_PROTMEM; 1018 + msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT; 1019 + msg_arg->params[0].u.rmem.shm_ref = (u_long)protmem; 1020 + 1021 + rc = optee->ops->do_call_with_arg(optee->ctx, shm, offs, false); 1022 + if (rc) 1023 + goto out; 1024 + if (msg_arg->ret != TEEC_SUCCESS) 1025 + rc = -EINVAL; 1026 + 1027 + out: 1028 + optee_free_msg_arg(optee->ctx, entry, offs); 1029 + return rc; 1030 + } 1031 + 968 1032 /* 969 1033 * 5. Asynchronous notification 970 1034 */ ··· 1280 1216 .do_call_with_arg = optee_smc_do_call_with_arg, 1281 1217 .to_msg_param = optee_to_msg_param, 1282 1218 .from_msg_param = optee_from_msg_param, 1219 + .lend_protmem = optee_smc_lend_protmem, 1220 + .reclaim_protmem = optee_smc_reclaim_protmem, 1283 1221 }; 1284 1222 1285 1223 static int enable_async_notif(optee_invoke_fn *invoke_fn) ··· 1693 1627 1694 1628 static int optee_protmem_pool_init(struct optee *optee) 1695 1629 { 1630 + bool protm = optee->smc.sec_caps & OPTEE_SMC_SEC_CAP_PROTMEM; 1631 + bool dyn_protm = optee->smc.sec_caps & 1632 + OPTEE_SMC_SEC_CAP_DYNAMIC_PROTMEM; 1696 1633 enum tee_dma_heap_id heap_id = TEE_DMA_HEAP_SECURE_VIDEO_PLAY; 1697 1634 struct tee_protmem_pool *pool = ERR_PTR(-EINVAL); 1698 - int rc; 1635 + int rc = -EINVAL; 1699 1636 1700 - if (!(optee->smc.sec_caps & OPTEE_SMC_SEC_CAP_PROTMEM)) 1637 + if (!protm && !dyn_protm) 1701 1638 return 0; 1702 1639 1703 - pool = static_protmem_pool_init(optee); 1640 + if (protm) 1641 + pool = static_protmem_pool_init(optee); 1642 + if (dyn_protm && IS_ERR(pool)) 1643 + pool = optee_protmem_alloc_dyn_pool(optee, heap_id); 1704 1644 if (IS_ERR(pool)) 1705 1645 return PTR_ERR(pool); 1706 1646