blob: a847b6c7377b4abd2ab97f90513923a394b0bd8a [file] [log] [blame]
Achin Gupta76717892014-05-09 11:42:56 +01001/*
Achin Gupta6b4ec242021-10-04 20:13:36 +01002 * Copyright (c) 2014-2022, ARM Limited and Contributors. All rights reserved.
Achin Gupta76717892014-05-09 11:42:56 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta76717892014-05-09 11:42:56 +01005 */
6
Achin Gupta76717892014-05-09 11:42:56 +01007#include <assert.h>
Manish Pandey9b384b32021-11-12 12:59:09 +00008#include <inttypes.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
Dan Handleyed6ff952014-05-14 17:44:19 +010010#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011
12#include <arch_helpers.h>
13#include <bl32/tsp/tsp.h>
14#include <common/debug.h>
15#include <plat/common/platform.h>
16
Dan Handleye2c27f52014-08-01 17:58:27 +010017#include "tsp_private.h"
Achin Gupta76717892014-05-09 11:42:56 +010018
19/*******************************************************************************
Soby Mathewbec98512015-09-03 18:29:38 +010020 * This function updates the TSP statistics for S-EL1 interrupts handled
21 * synchronously i.e the ones that have been handed over by the TSPD. It also
22 * keeps count of the number of times control was passed back to the TSPD
23 * after handling the interrupt. In the future it will be possible that the
24 * TSPD hands over an S-EL1 interrupt to the TSP but does not expect it to
25 * return execution. This statistic will be useful to distinguish between these
26 * two models of synchronous S-EL1 interrupt handling. The 'elr_el3' parameter
27 * contains the address of the instruction in normal world where this S-EL1
28 * interrupt was generated.
Achin Gupta76717892014-05-09 11:42:56 +010029 ******************************************************************************/
Soby Mathewbec98512015-09-03 18:29:38 +010030void tsp_update_sync_sel1_intr_stats(uint32_t type, uint64_t elr_el3)
Achin Gupta76717892014-05-09 11:42:56 +010031{
Soby Mathewda43b662015-07-08 21:45:46 +010032 uint32_t linear_id = plat_my_core_pos();
Achin Gupta76717892014-05-09 11:42:56 +010033
Soby Mathewbec98512015-09-03 18:29:38 +010034 tsp_stats[linear_id].sync_sel1_intr_count++;
35 if (type == TSP_HANDLE_SEL1_INTR_AND_RETURN)
36 tsp_stats[linear_id].sync_sel1_intr_ret_count++;
Achin Gupta76717892014-05-09 11:42:56 +010037
Manish Pandey9b384b32021-11-12 12:59:09 +000038 VERBOSE("TSP: cpu 0x%lx sync s-el1 interrupt request from 0x%" PRIx64 "\n",
Soby Mathewda43b662015-07-08 21:45:46 +010039 read_mpidr(), elr_el3);
Soby Mathewbec98512015-09-03 18:29:38 +010040 VERBOSE("TSP: cpu 0x%lx: %d sync s-el1 interrupt requests,"
41 " %d sync s-el1 interrupt returns\n",
Soby Mathewda43b662015-07-08 21:45:46 +010042 read_mpidr(),
Soby Mathewbec98512015-09-03 18:29:38 +010043 tsp_stats[linear_id].sync_sel1_intr_count,
44 tsp_stats[linear_id].sync_sel1_intr_ret_count);
Achin Gupta76717892014-05-09 11:42:56 +010045}
46
Soby Mathewbc912822015-09-22 12:01:18 +010047/******************************************************************************
48 * This function is invoked when a non S-EL1 interrupt is received and causes
49 * the preemption of TSP. This function returns TSP_PREEMPTED and results
50 * in the control being handed over to EL3 for handling the interrupt.
51 *****************************************************************************/
52int32_t tsp_handle_preemption(void)
53{
54 uint32_t linear_id = plat_my_core_pos();
55
56 tsp_stats[linear_id].preempt_intr_count++;
Soby Mathewbc912822015-09-22 12:01:18 +010057 VERBOSE("TSP: cpu 0x%lx: %d preempt interrupt requests\n",
58 read_mpidr(), tsp_stats[linear_id].preempt_intr_count);
Soby Mathewbc912822015-09-22 12:01:18 +010059 return TSP_PREEMPTED;
60}
61
Achin Gupta76717892014-05-09 11:42:56 +010062/*******************************************************************************
Soby Mathewbec98512015-09-03 18:29:38 +010063 * TSP interrupt handler is called as a part of both synchronous and
64 * asynchronous handling of TSP interrupts. Currently the physical timer
65 * interrupt is the only S-EL1 interrupt that this handler expects. It returns
66 * 0 upon successfully handling the expected interrupt and all other
67 * interrupts are treated as normal world or EL3 interrupts.
Achin Gupta76717892014-05-09 11:42:56 +010068 ******************************************************************************/
Soby Mathewbec98512015-09-03 18:29:38 +010069int32_t tsp_common_int_handler(void)
Achin Gupta76717892014-05-09 11:42:56 +010070{
Soby Mathewda43b662015-07-08 21:45:46 +010071 uint32_t linear_id = plat_my_core_pos(), id;
Achin Gupta76717892014-05-09 11:42:56 +010072
73 /*
74 * Get the highest priority pending interrupt id and see if it is the
75 * secure physical generic timer interrupt in which case, handle it.
76 * Otherwise throw this interrupt at the EL3 firmware.
Soby Mathewbc912822015-09-22 12:01:18 +010077 *
78 * There is a small time window between reading the highest priority
79 * pending interrupt and acknowledging it during which another
80 * interrupt of higher priority could become the highest pending
81 * interrupt. This is not expected to happen currently for TSP.
Achin Gupta76717892014-05-09 11:42:56 +010082 */
Dan Handley701fea72014-05-27 16:17:21 +010083 id = plat_ic_get_pending_interrupt_id();
Achin Gupta76717892014-05-09 11:42:56 +010084
85 /* TSP can only handle the secure physical timer interrupt */
Achin Gupta6b4ec242021-10-04 20:13:36 +010086 if (id != TSP_IRQ_SEC_PHY_TIMER) {
87#if SPMC_AT_EL3
88 /*
89 * With the EL3 FF-A SPMC we expect only Timer secure interrupt to fire in
90 * the TSP, so panic if any other interrupt does.
91 */
92 ERROR("Unexpected interrupt id %u\n", id);
93 panic();
94#else
Soby Mathewbc912822015-09-22 12:01:18 +010095 return tsp_handle_preemption();
Achin Gupta6b4ec242021-10-04 20:13:36 +010096#endif
97 }
Achin Gupta76717892014-05-09 11:42:56 +010098
99 /*
Soby Mathewbc912822015-09-22 12:01:18 +0100100 * Acknowledge and handle the secure timer interrupt. Also sanity check
101 * if it has been preempted by another interrupt through an assertion.
Achin Gupta76717892014-05-09 11:42:56 +0100102 */
Dan Handley701fea72014-05-27 16:17:21 +0100103 id = plat_ic_acknowledge_interrupt();
Dan Handley4fd2f5c2014-08-04 11:41:20 +0100104 assert(id == TSP_IRQ_SEC_PHY_TIMER);
Achin Gupta76717892014-05-09 11:42:56 +0100105 tsp_generic_timer_handler();
Dan Handley701fea72014-05-27 16:17:21 +0100106 plat_ic_end_of_interrupt(id);
Achin Gupta76717892014-05-09 11:42:56 +0100107
108 /* Update the statistics and print some messages */
Soby Mathewbec98512015-09-03 18:29:38 +0100109 tsp_stats[linear_id].sel1_intr_count++;
Soby Mathewbec98512015-09-03 18:29:38 +0100110 VERBOSE("TSP: cpu 0x%lx handled S-EL1 interrupt %d\n",
Soby Mathewda43b662015-07-08 21:45:46 +0100111 read_mpidr(), id);
Soby Mathewbec98512015-09-03 18:29:38 +0100112 VERBOSE("TSP: cpu 0x%lx: %d S-EL1 requests\n",
113 read_mpidr(), tsp_stats[linear_id].sel1_intr_count);
Achin Gupta76717892014-05-09 11:42:56 +0100114 return 0;
115}