spd: tlkd: secure timer interrupt handler

This patch adds an interrupt handler for TLK. On receiving an
interrupt, the source of the interrupt is determined and the
interrupt is marked complete. The IRQ number is passed to
TLK along with a special SMC function ID. TLK issues an SMC
to notify completion of the interrupt handler in the S-EL1
world.

Change-Id: I76f28cee6537245c5e448d2078f86312219cea1a
Signed-off-by: Varun Wadekar <vwadekar@nvidia.com>
This commit is contained in:
Varun Wadekar 2018-08-10 09:55:25 -07:00
parent 91dd7edd31
commit d205cda6fd
2 changed files with 90 additions and 1 deletions

View File

@ -27,6 +27,7 @@
#define TLK_SYSTEM_SUSPEND TLK_TOS_YIELD_FID(0xE001)
#define TLK_SYSTEM_RESUME TLK_TOS_YIELD_FID(0xE002)
#define TLK_SYSTEM_OFF TLK_TOS_YIELD_FID(0xE003)
#define TLK_IRQ_FIRED TLK_TOS_YIELD_FID(0xE004)
/*
* SMC function IDs that TLK uses to signal various forms of completions
@ -39,6 +40,7 @@
#define TLK_SUSPEND_DONE (0x32000005 | (ULL(1) << 31))
#define TLK_RESUME_DONE (0x32000006 | (ULL(1) << 31))
#define TLK_SYSTEM_OFF_DONE (0x32000007 | (ULL(1) << 31))
#define TLK_IRQ_DONE (0x32000008 | (ULL(1) << 31))
/*
* Trusted Application specific function IDs

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -14,6 +14,7 @@
* responsible for initialising and maintaining communication with the SP.
******************************************************************************/
#include <assert.h>
#include <bl31/interrupt_mgmt.h>
#include <errno.h>
#include <stddef.h>
@ -48,6 +49,50 @@ DEFINE_SVC_UUID2(tlk_uuid,
static int32_t tlkd_init(void);
/*******************************************************************************
* Secure Payload Dispatcher's timer interrupt handler
******************************************************************************/
static uint64_t tlkd_interrupt_handler(uint32_t id,
uint32_t flags,
void *handle,
void *cookie)
{
cpu_context_t *s_cpu_context;
int irq = plat_ic_get_pending_interrupt_id();
/* acknowledge the interrupt and mark it complete */
(void)plat_ic_acknowledge_interrupt();
plat_ic_end_of_interrupt(irq);
/*
* Disable the routing of NS interrupts from secure world to
* EL3 while interrupted on this core.
*/
disable_intr_rm_local(INTR_TYPE_S_EL1, SECURE);
/* Check the security state when the exception was generated */
assert(get_interrupt_src_ss(flags) == NON_SECURE);
assert(handle == cm_get_context(NON_SECURE));
/* Save non-secure state */
cm_el1_sysregs_context_save(NON_SECURE);
/* Get a reference to the secure context */
s_cpu_context = cm_get_context(SECURE);
assert(s_cpu_context);
/*
* Restore non-secure state. There is no need to save the
* secure system register context since the SP was supposed
* to preserve it during S-EL1 interrupt handling.
*/
cm_el1_sysregs_context_restore(SECURE);
cm_set_next_eret_context(SECURE);
/* Provide the IRQ number to the SPD */
SMC_RET4(s_cpu_context, (uint32_t)TLK_IRQ_FIRED, 0, (uint32_t)irq, 0);
}
/*******************************************************************************
* Secure Payload Dispatcher setup. The SPD finds out the SP entrypoint and type
* (aarch32/aarch64) if not already known and initialises the context for entry
@ -56,6 +101,8 @@ static int32_t tlkd_init(void);
static int32_t tlkd_setup(void)
{
entry_point_info_t *tlk_ep_info;
uint32_t flags;
int32_t ret;
/*
* Get information about the Secure Payload (BL32) image. Its
@ -86,6 +133,18 @@ static int32_t tlkd_setup(void)
tlk_ep_info->pc,
&tlk_ctx);
/* get a list of all S-EL1 IRQs from the platform */
/* register interrupt handler */
flags = 0;
set_interrupt_rm_flag(flags, NON_SECURE);
ret = register_interrupt_type_handler(INTR_TYPE_S_EL1,
tlkd_interrupt_handler,
flags);
if (ret != 0) {
ERROR("failed to register tlkd interrupt handler (%d)\n", ret);
}
/*
* All TLK SPD initialization done. Now register our init function
* with BL31 for deferred invocation
@ -384,6 +443,34 @@ static uintptr_t tlkd_smc_handler(uint32_t smc_fid,
tlkd_synchronous_sp_exit(&tlk_ctx, x1);
break;
/*
* This function ID is used by SP to indicate that it has completed
* handling the secure interrupt.
*/
case TLK_IRQ_DONE:
if (ns)
SMC_RET1(handle, SMC_UNK);
assert(handle == cm_get_context(SECURE));
/* save secure world context */
cm_el1_sysregs_context_save(SECURE);
/* Get a reference to the non-secure context */
ns_cpu_context = cm_get_context(NON_SECURE);
assert(ns_cpu_context);
/*
* Restore non-secure state. There is no need to save the
* secure system register context since the SP was supposed
* to preserve it during S-EL1 interrupt handling.
*/
cm_el1_sysregs_context_restore(NON_SECURE);
cm_set_next_eret_context(NON_SECURE);
SMC_RET0(ns_cpu_context);
/*
* Return the number of service function IDs implemented to
* provide service to non-secure