static int optee_rng_init(struct hwrng *rng) { struct optee_rng_private *pvt_data = to_optee_rng_private(rng); struct tee_shm *entropy_shm_pool = NULL; entropy_shm_pool = tee_shm_alloc(pvt_data->ctx, MAX_ENTROPY_REQ_SZ, TEE_SHM_MAPPED | TEE_SHM_DMA_BUF); if (IS_ERR(entropy_shm_pool)) { dev_err(pvt_data->dev, "tee_shm_alloc failed\n"); return PTR_ERR(entropy_shm_pool); } pvt_data->entropy_shm_pool = entropy_shm_pool; return 0; }
TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context, TEEC_SharedMemory *sharedMem) { struct tee_shm *tee_shm; struct tee_context *ctx; if (!context || !sharedMem) return TEEC_ERROR_BAD_PARAMETERS; /* TODO fixme will not work on 64-bit platform */ ctx = (struct tee_context *)(uintptr_t)context->fd; tee_shm = tee_shm_alloc(ctx, sharedMem->size, sharedMem->flags); if (IS_ERR_OR_NULL(tee_shm)) { pr_err ("TEEC_AllocateSharedMemory: tee_shm_allocate(%zu) failed\n", sharedMem->size); return TEEC_ERROR_OUT_OF_MEMORY; } pr_info("TEEC_AllocateSharedMemory (%zu) => paddr = %p, flags %x\n", sharedMem->size, (void *)tee_shm->paddr, tee_shm->flags); sharedMem->buffer = ioremap_nocache(tee_shm->paddr, sharedMem->size); if (!sharedMem->buffer) { pr_err("TEEC_AllocateSharedMemory: ioremap_nocache(%p, %zu) failed\n", (void *)tee_shm->paddr, sharedMem->size); tee_shm_free(tee_shm); return TEEC_ERROR_OUT_OF_MEMORY; } sharedMem->registered = 0; sharedMem->flags |= tee_shm->flags; /* TODO fixme will not work on 64-bit platform */ sharedMem->d.fd = (int)(uintptr_t)tee_shm; BUG_ON(tee_shm != (struct tee_shm *)(uintptr_t)sharedMem->d.fd); return TEEC_SUCCESS; }
struct tee_shm *tee_shm_alloc_from_rpc(struct tee *tee, size_t size) { struct tee_shm *shm; INMSG(); shm = tee_shm_alloc(tee, size, TEE_SHM_TEMP | TEE_SHM_FROM_RPC); if (IS_ERR_OR_NULL(shm)) { dev_err(_DEV(tee), "%s: buffer allocation failed (%ld)\n", __func__, PTR_ERR(shm)); goto out; } mutex_lock(&tee->lock); tee_inc_stats(&tee->stats[TEE_STATS_SHM_IDX]); list_add_tail(&shm->entry, &tee->list_rpc_shm); mutex_unlock(&tee->lock); shm->ctx = NULL; out: OUTMSGX(shm); return shm; }