blob: 4e500b3caa20be05157bb9437e9e290a2da2c527 [file] [log] [blame]
Achin Gupta76717892014-05-09 11:42:56 +01001/*
Dan Handleyeb839ce2015-03-23 18:13:33 +00002 * Copyright (c) 2014-2015, 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>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Dan Handleyed6ff952014-05-14 17:44:19 +01009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <arch_helpers.h>
12#include <bl32/tsp/tsp.h>
13#include <common/debug.h>
14#include <plat/common/platform.h>
15
Dan Handleye2c27f52014-08-01 17:58:27 +010016#include "tsp_private.h"
Achin Gupta76717892014-05-09 11:42:56 +010017
18/*******************************************************************************
Soby Mathewbec98512015-09-03 18:29:38 +010019 * This function updates the TSP statistics for S-EL1 interrupts handled
20 * synchronously i.e the ones that have been handed over by the TSPD. It also
21 * keeps count of the number of times control was passed back to the TSPD
22 * after handling the interrupt. In the future it will be possible that the
23 * TSPD hands over an S-EL1 interrupt to the TSP but does not expect it to
24 * return execution. This statistic will be useful to distinguish between these
25 * two models of synchronous S-EL1 interrupt handling. The 'elr_el3' parameter
26 * contains the address of the instruction in normal world where this S-EL1
27 * interrupt was generated.
Achin Gupta76717892014-05-09 11:42:56 +010028 ******************************************************************************/
Soby Mathewbec98512015-09-03 18:29:38 +010029void tsp_update_sync_sel1_intr_stats(uint32_t type, uint64_t elr_el3)
Achin Gupta76717892014-05-09 11:42:56 +010030{
Soby Mathewda43b662015-07-08 21:45:46 +010031 uint32_t linear_id = plat_my_core_pos();
Achin Gupta76717892014-05-09 11:42:56 +010032
Soby Mathewbec98512015-09-03 18:29:38 +010033 tsp_stats[linear_id].sync_sel1_intr_count++;
34 if (type == TSP_HANDLE_SEL1_INTR_AND_RETURN)
35 tsp_stats[linear_id].sync_sel1_intr_ret_count++;
Achin Gupta76717892014-05-09 11:42:56 +010036
Dan Handley91b624e2014-07-29 17:14:00 +010037#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Achin Gupta76717892014-05-09 11:42:56 +010038 spin_lock(&console_lock);
Masahiro Yamadae93a0f42018-02-02 15:09:36 +090039 VERBOSE("TSP: cpu 0x%lx sync s-el1 interrupt request from 0x%llx\n",
Soby Mathewda43b662015-07-08 21:45:46 +010040 read_mpidr(), elr_el3);
Soby Mathewbec98512015-09-03 18:29:38 +010041 VERBOSE("TSP: cpu 0x%lx: %d sync s-el1 interrupt requests,"
42 " %d sync s-el1 interrupt returns\n",
Soby Mathewda43b662015-07-08 21:45:46 +010043 read_mpidr(),
Soby Mathewbec98512015-09-03 18:29:38 +010044 tsp_stats[linear_id].sync_sel1_intr_count,
45 tsp_stats[linear_id].sync_sel1_intr_ret_count);
Achin Gupta76717892014-05-09 11:42:56 +010046 spin_unlock(&console_lock);
Dan Handley91b624e2014-07-29 17:14:00 +010047#endif
Achin Gupta76717892014-05-09 11:42:56 +010048}
49
Soby Mathewbc912822015-09-22 12:01:18 +010050/******************************************************************************
51 * This function is invoked when a non S-EL1 interrupt is received and causes
52 * the preemption of TSP. This function returns TSP_PREEMPTED and results
53 * in the control being handed over to EL3 for handling the interrupt.
54 *****************************************************************************/
55int32_t tsp_handle_preemption(void)
56{
57 uint32_t linear_id = plat_my_core_pos();
58
59 tsp_stats[linear_id].preempt_intr_count++;
60#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
61 spin_lock(&console_lock);
62 VERBOSE("TSP: cpu 0x%lx: %d preempt interrupt requests\n",
63 read_mpidr(), tsp_stats[linear_id].preempt_intr_count);
64 spin_unlock(&console_lock);
65#endif
66 return TSP_PREEMPTED;
67}
68
Achin Gupta76717892014-05-09 11:42:56 +010069/*******************************************************************************
Soby Mathewbec98512015-09-03 18:29:38 +010070 * TSP interrupt handler is called as a part of both synchronous and
71 * asynchronous handling of TSP interrupts. Currently the physical timer
72 * interrupt is the only S-EL1 interrupt that this handler expects. It returns
73 * 0 upon successfully handling the expected interrupt and all other
74 * interrupts are treated as normal world or EL3 interrupts.
Achin Gupta76717892014-05-09 11:42:56 +010075 ******************************************************************************/
Soby Mathewbec98512015-09-03 18:29:38 +010076int32_t tsp_common_int_handler(void)
Achin Gupta76717892014-05-09 11:42:56 +010077{
Soby Mathewda43b662015-07-08 21:45:46 +010078 uint32_t linear_id = plat_my_core_pos(), id;
Achin Gupta76717892014-05-09 11:42:56 +010079
80 /*
81 * Get the highest priority pending interrupt id and see if it is the
82 * secure physical generic timer interrupt in which case, handle it.
83 * Otherwise throw this interrupt at the EL3 firmware.
Soby Mathewbc912822015-09-22 12:01:18 +010084 *
85 * There is a small time window between reading the highest priority
86 * pending interrupt and acknowledging it during which another
87 * interrupt of higher priority could become the highest pending
88 * interrupt. This is not expected to happen currently for TSP.
Achin Gupta76717892014-05-09 11:42:56 +010089 */
Dan Handley701fea72014-05-27 16:17:21 +010090 id = plat_ic_get_pending_interrupt_id();
Achin Gupta76717892014-05-09 11:42:56 +010091
92 /* TSP can only handle the secure physical timer interrupt */
Dan Handley4fd2f5c2014-08-04 11:41:20 +010093 if (id != TSP_IRQ_SEC_PHY_TIMER)
Soby Mathewbc912822015-09-22 12:01:18 +010094 return tsp_handle_preemption();
Achin Gupta76717892014-05-09 11:42:56 +010095
96 /*
Soby Mathewbc912822015-09-22 12:01:18 +010097 * Acknowledge and handle the secure timer interrupt. Also sanity check
98 * if it has been preempted by another interrupt through an assertion.
Achin Gupta76717892014-05-09 11:42:56 +010099 */
Dan Handley701fea72014-05-27 16:17:21 +0100100 id = plat_ic_acknowledge_interrupt();
Dan Handley4fd2f5c2014-08-04 11:41:20 +0100101 assert(id == TSP_IRQ_SEC_PHY_TIMER);
Achin Gupta76717892014-05-09 11:42:56 +0100102 tsp_generic_timer_handler();
Dan Handley701fea72014-05-27 16:17:21 +0100103 plat_ic_end_of_interrupt(id);
Achin Gupta76717892014-05-09 11:42:56 +0100104
105 /* Update the statistics and print some messages */
Soby Mathewbec98512015-09-03 18:29:38 +0100106 tsp_stats[linear_id].sel1_intr_count++;
Dan Handley91b624e2014-07-29 17:14:00 +0100107#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Achin Gupta76717892014-05-09 11:42:56 +0100108 spin_lock(&console_lock);
Soby Mathewbec98512015-09-03 18:29:38 +0100109 VERBOSE("TSP: cpu 0x%lx handled S-EL1 interrupt %d\n",
Soby Mathewda43b662015-07-08 21:45:46 +0100110 read_mpidr(), id);
Soby Mathewbec98512015-09-03 18:29:38 +0100111 VERBOSE("TSP: cpu 0x%lx: %d S-EL1 requests\n",
112 read_mpidr(), tsp_stats[linear_id].sel1_intr_count);
Achin Gupta76717892014-05-09 11:42:56 +0100113 spin_unlock(&console_lock);
Dan Handley91b624e2014-07-29 17:14:00 +0100114#endif
Achin Gupta76717892014-05-09 11:42:56 +0100115 return 0;
116}