Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] core: implement OCALLs #3673

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion core/arch/arm/include/kernel/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define THREAD_ID_0 0
#define THREAD_ID_INVALID -1

#define THREAD_RPC_MAX_NUM_PARAMS 4
#define THREAD_RPC_MAX_NUM_PARAMS 6

#ifndef __ASSEMBLER__

Expand Down Expand Up @@ -740,6 +740,24 @@ struct mobj *thread_rpc_alloc_global_payload(size_t size);
*/
void thread_rpc_free_global_payload(struct mobj *mobj);

/**
* Request that the Client Application allocate shared memory for OCALL payload
* buffers.
*
* @size: size in bytes of payload buffer
*
* @returns mobj that describes allocated buffer or NULL on error
*/
struct mobj *thread_rpc_alloc_client_app_payload(size_t size);

/**
* Free physical memory previously allocated with
* thread_rpc_alloc_client_app_payload()
*
* @mobj: mobj that describes the buffer
*/
void thread_rpc_free_client_app_payload(struct mobj *mobj);

/*
* enum thread_shm_type - type of non-secure shared memory
* @THREAD_SHM_TYPE_APPLICATION - user space application shared memory
Expand Down
16 changes: 10 additions & 6 deletions core/arch/arm/include/sm/optee_smc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef OPTEE_SMC_H
#define OPTEE_SMC_H

#include <util.h>

/*
* This file is exported by OP-TEE and is in kept in sync between secure
* world and normal world kernel driver. We're following ARM SMC Calling
Expand Down Expand Up @@ -264,20 +266,22 @@
* a2-7 Preserved
*/
/* Normal world works as a uniprocessor system */
#define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR (1 << 0)
#define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR BIT(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <util.h> is needed for this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

/* Secure world has reserved shared memory for normal world to use */
#define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM (1 << 0)
#define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM BIT(0)
/* Secure world can communicate via previously unregistered shared memory */
#define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM (1 << 1)
#define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM BIT(1)
/*
* Secure world supports commands "register/unregister shared memory",
* secure world accepts command buffers located in any parts of non-secure RAM
*/
#define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM (1 << 2)
#define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM BIT(2)
/* Secure world is built with virtualization support */
#define OPTEE_SMC_SEC_CAP_VIRTUALIZATION (1 << 3)
#define OPTEE_SMC_SEC_CAP_VIRTUALIZATION BIT(3)
/* Secure world supports Shared Memory with a NULL reference */
#define OPTEE_SMC_SEC_CAP_MEMREF_NULL (1 << 4)
#define OPTEE_SMC_SEC_CAP_MEMREF_NULL BIT(4)
/* Secure world is built with OCALL support */
#define OPTEE_SMC_SEC_CAP_OCALL BIT(5)

#define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES 9
#define OPTEE_SMC_EXCHANGE_CAPABILITIES \
Expand Down
11 changes: 11 additions & 0 deletions core/arch/arm/kernel/thread_optee_smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,14 @@ void thread_rpc_free_global_payload(struct mobj *mobj)
thread_rpc_free(OPTEE_RPC_SHM_TYPE_GLOBAL, mobj_get_cookie(mobj),
mobj);
}

struct mobj *thread_rpc_alloc_client_app_payload(size_t size)
{
return thread_rpc_alloc(size, 8, OPTEE_RPC_SHM_TYPE_CLIENT_APP);
}

void thread_rpc_free_client_app_payload(struct mobj *mobj)
{
thread_rpc_free(OPTEE_RPC_SHM_TYPE_CLIENT_APP, mobj_get_cookie(mobj),
mobj);
}
3 changes: 3 additions & 0 deletions core/arch/arm/tee/entry_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ static void tee_entry_exchange_capabilities(struct thread_smc_args *args)
args->a1 |= OPTEE_SMC_SEC_CAP_VIRTUALIZATION;
#endif
args->a1 |= OPTEE_SMC_SEC_CAP_MEMREF_NULL;
#if defined(CFG_OCALL)
args->a1 |= OPTEE_SMC_SEC_CAP_OCALL;
#endif

#if defined(CFG_CORE_DYN_SHM)
dyn_shm_en = core_mmu_nsec_ddr_is_defined();
Expand Down
18 changes: 18 additions & 0 deletions core/include/optee_rpc_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
* space application
*/
#define OPTEE_RPC_SHM_TYPE_GLOBAL 2
/*
* Memory shared with the non-secure application that is the client of the TA
* that requests shared memory of this type; the client could be running in
* non-secure user-mode or in non-secure kernel-mode
*/
#define OPTEE_RPC_SHM_TYPE_CLIENT_APP 3

/*
* Free shared memory previously allocated with OPTEE_RPC_CMD_SHM_ALLOC
Expand Down Expand Up @@ -175,6 +181,18 @@
/* I2C master control flags */
#define OPTEE_RPC_I2C_FLAGS_TEN_BIT BIT(0)

/*
* Send an OCALL to the Client Application
*
* [in] value[0].a CA Command ID (i.e., OCALL# for the CA to execute)
* [out] value[0].b OCALL return value
* [out] value[0].c OCALL return value origin
* [in] value[1].a UUID of TA whence OCALL originated (HI bits)
* [out] value[1].b UUID of TA whence OCALL originated (LO bits)
* [in/out] any[2..5].* OCALL parameters as specified by the TA, if any
*/
#define OPTEE_RPC_CMD_OCALL 22

/*
* Definition of protocol for command OPTEE_RPC_CMD_FS
*/
Expand Down