optee的Share Memory介绍
快速鏈接:
.
👉👉👉 個人博客筆記導讀目錄(全部) 👈👈👈
說明: 在默認的情況下,本文講述的是armv8 aarch64體系,optee 3.12.0代碼
文章目錄
- 1、shareMemory定義
- 2、兩種shareMemory:
- (1)、Contiguous shared buffers(也叫靜態共享內存)
- (2)、Noncontiguous shared buffers(也叫動態共享內存)
- 3、共享內存的使用
- (1)、From the Client Application
- (2)、From the Linux Driver
- (3)、From OP-TEE core/From TEE Supplicant
1、shareMemory定義
Share Memory是一塊內存區域,用于non-secure world和secure world的數據共享
在non-secure world中(如Linux kernel中optee的driver)申請和管理Share Memory。
在secure world中設別shared buffers(Not pool),secure world需要知道buf start、buf size、Cache attributes、如果是非連續內存還需知道List of chunks
2、兩種shareMemory:
(1)、Contiguous shared buffers(也叫靜態共享內存)
在optee中定義如下配置
- CFG_CORE_RESERVED_SHM=y
- CFG_SHMEM_START
- CFG_SHMEM_SIZE
該內存的屬性為:MEM_AREA_NSEC_SHM
REE通過OPTEE_SMC_GET_SHM_CONFIG的smc id獲得內存信息:物理地址、size、cache屬性
(2)、Noncontiguous shared buffers(也叫動態共享內存)
在optee中定義如下配置
- CFG_CORE_DYN_SHM=y
REE側注冊4kByte chunks lists的內存,然后調用OPTEE_MSG_CMD_REGISTER_SHM的smc id,通知TEE側建立map關系
在Linux driver側,如下宏控制的內存的申請方法:
- CONFIG_GENERIC_ALLOCATION
- CONFIG_DMA_SHARED_BUFFER
3、共享內存的使用
(1)、From the Client Application
調用GlobalPlatform Client API函數:TEEC_AllocateSharedMemory(…)
使用示例:
TEEC_SharedMemory bufferIn; TEEC_SharedMemory bufferOut;result = TEEC_AllocateSharedMemory(&context, &bufferIn);if (result != TEEC_SUCCESS) {LOGE("%s : TEEC_AllocateSharedMemory FAILED!",__func__);}result = TEEC_AllocateSharedMemory(&context, &bufferOut);if (result != TEEC_SUCCESS) {LOGE("%s : TEEC_AllocateSharedMemory FAILED!",__func__);}(2)、From the Linux Driver
在Linux Kernel使用TEEC_TempMemoryReference類型的buf
(3)、From OP-TEE core/From TEE Supplicant
在一些場景下,optee需要REE的信息(dynamic TA loading, REE time request,…),這個時候需要建立共享內存;
這個時候,需要發送OPTEE_SMC_RPC_FUNC_ALLOC構建共享內存,并構建optee_msg_arg結構體
在RPC調用到REE后,teei-supplicant處理完事情后,需要返回結果的,會使用OPTEE_MSG_RPC_CMD_SHM_ALLOC(OPTEE_MSG_RPC_SHM_TYPE_APPL,…)返回結果給TEE
總結
以上是生活随笔為你收集整理的optee的Share Memory介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: optee的栈指针和栈内存的介绍
- 下一篇: optee os中共享内存的类型