xen/arm: optee: add std call handling
authorVolodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Tue, 11 Jun 2019 18:46:33 +0000 (18:46 +0000)
committerJulien Grall <julien.grall@arm.com>
Wed, 19 Jun 2019 11:05:04 +0000 (12:05 +0100)
commitc688a8afb2649d955139e7d0d2a86a75fe93fa7e
treeb251fced08ffc8036d0b591933efdb6ebb02a8d3
parent40decd926640901f186b60c2449ec54f4179c080
xen/arm: optee: add std call handling

The main way to communicate with OP-TEE is to issue standard SMCCC
call. "Standard" is a SMCCC term and it means that call can be
interrupted and OP-TEE can return control to NW before completing
the call.

In contrast with fast calls, where arguments and return values
are passed in registers, standard calls use shared memory. Register
pair a1,a2 holds 64-bit PA of command buffer, where all arguments
are stored and which is used to return data. OP-TEE internally
copies contents of this buffer into own secure memory before accessing
and validating any data in command buffer. This is done to make sure
that NW will not change contents of the validated parameters.

Mediator needs to do the same for number of reasons:

1. To make sure that guest will not change data after validation.
2. To translate IPAs to PAs in the command buffer (this is not done
   in this patch).
3. To hide translated address from guest, so it will not be able
   to do IPA->PA translation by misusing mediator.

During standard call OP-TEE can issue multiple "RPC returns", asking
NW to do some work for OP-TEE. NW then issues special call
OPTEE_SMC_CALL_RETURN_FROM_RPC to resume handling of the original call.
Thus, mediator needs to maintain context for original standard call
during multiple SMCCC calls.

Standard call is considered complete, when returned value is
not a RPC request.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Acked-by: Julien Grall <julien.grall@arm.com>
xen/arch/arm/tee/optee.c