Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | eb839ce | 2015-03-23 18:13:33 +0000 | [diff] [blame] | 2 | * Copyright (c) 2014-2015, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Manish Pandey | 9b384b3 | 2021-11-12 12:59:09 +0000 | [diff] [blame] | 8 | #include <inttypes.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 10 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | |
| 12 | #include <arch_helpers.h> |
| 13 | #include <bl32/tsp/tsp.h> |
| 14 | #include <common/debug.h> |
| 15 | #include <plat/common/platform.h> |
| 16 | |
Dan Handley | e2c27f5 | 2014-08-01 17:58:27 +0100 | [diff] [blame] | 17 | #include "tsp_private.h" |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 18 | |
| 19 | /******************************************************************************* |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 20 | * 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 Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 29 | ******************************************************************************/ |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 30 | void tsp_update_sync_sel1_intr_stats(uint32_t type, uint64_t elr_el3) |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 31 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 32 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 33 | |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 34 | 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 Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 37 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 38 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 39 | spin_lock(&console_lock); |
Manish Pandey | 9b384b3 | 2021-11-12 12:59:09 +0000 | [diff] [blame] | 40 | VERBOSE("TSP: cpu 0x%lx sync s-el1 interrupt request from 0x%" PRIx64 "\n", |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 41 | read_mpidr(), elr_el3); |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 42 | VERBOSE("TSP: cpu 0x%lx: %d sync s-el1 interrupt requests," |
| 43 | " %d sync s-el1 interrupt returns\n", |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 44 | read_mpidr(), |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 45 | tsp_stats[linear_id].sync_sel1_intr_count, |
| 46 | tsp_stats[linear_id].sync_sel1_intr_ret_count); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 47 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 48 | #endif |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 49 | } |
| 50 | |
Soby Mathew | bc91282 | 2015-09-22 12:01:18 +0100 | [diff] [blame] | 51 | /****************************************************************************** |
| 52 | * This function is invoked when a non S-EL1 interrupt is received and causes |
| 53 | * the preemption of TSP. This function returns TSP_PREEMPTED and results |
| 54 | * in the control being handed over to EL3 for handling the interrupt. |
| 55 | *****************************************************************************/ |
| 56 | int32_t tsp_handle_preemption(void) |
| 57 | { |
| 58 | uint32_t linear_id = plat_my_core_pos(); |
| 59 | |
| 60 | tsp_stats[linear_id].preempt_intr_count++; |
| 61 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
| 62 | spin_lock(&console_lock); |
| 63 | VERBOSE("TSP: cpu 0x%lx: %d preempt interrupt requests\n", |
| 64 | read_mpidr(), tsp_stats[linear_id].preempt_intr_count); |
| 65 | spin_unlock(&console_lock); |
| 66 | #endif |
| 67 | return TSP_PREEMPTED; |
| 68 | } |
| 69 | |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 70 | /******************************************************************************* |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 71 | * TSP interrupt handler is called as a part of both synchronous and |
| 72 | * asynchronous handling of TSP interrupts. Currently the physical timer |
| 73 | * interrupt is the only S-EL1 interrupt that this handler expects. It returns |
| 74 | * 0 upon successfully handling the expected interrupt and all other |
| 75 | * interrupts are treated as normal world or EL3 interrupts. |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 76 | ******************************************************************************/ |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 77 | int32_t tsp_common_int_handler(void) |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 78 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 79 | uint32_t linear_id = plat_my_core_pos(), id; |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * Get the highest priority pending interrupt id and see if it is the |
| 83 | * secure physical generic timer interrupt in which case, handle it. |
| 84 | * Otherwise throw this interrupt at the EL3 firmware. |
Soby Mathew | bc91282 | 2015-09-22 12:01:18 +0100 | [diff] [blame] | 85 | * |
| 86 | * There is a small time window between reading the highest priority |
| 87 | * pending interrupt and acknowledging it during which another |
| 88 | * interrupt of higher priority could become the highest pending |
| 89 | * interrupt. This is not expected to happen currently for TSP. |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 90 | */ |
Dan Handley | 701fea7 | 2014-05-27 16:17:21 +0100 | [diff] [blame] | 91 | id = plat_ic_get_pending_interrupt_id(); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 92 | |
| 93 | /* TSP can only handle the secure physical timer interrupt */ |
Dan Handley | 4fd2f5c | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 94 | if (id != TSP_IRQ_SEC_PHY_TIMER) |
Soby Mathew | bc91282 | 2015-09-22 12:01:18 +0100 | [diff] [blame] | 95 | return tsp_handle_preemption(); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 96 | |
| 97 | /* |
Soby Mathew | bc91282 | 2015-09-22 12:01:18 +0100 | [diff] [blame] | 98 | * Acknowledge and handle the secure timer interrupt. Also sanity check |
| 99 | * if it has been preempted by another interrupt through an assertion. |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 100 | */ |
Dan Handley | 701fea7 | 2014-05-27 16:17:21 +0100 | [diff] [blame] | 101 | id = plat_ic_acknowledge_interrupt(); |
Dan Handley | 4fd2f5c | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 102 | assert(id == TSP_IRQ_SEC_PHY_TIMER); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 103 | tsp_generic_timer_handler(); |
Dan Handley | 701fea7 | 2014-05-27 16:17:21 +0100 | [diff] [blame] | 104 | plat_ic_end_of_interrupt(id); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 105 | |
| 106 | /* Update the statistics and print some messages */ |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 107 | tsp_stats[linear_id].sel1_intr_count++; |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 108 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 109 | spin_lock(&console_lock); |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 110 | VERBOSE("TSP: cpu 0x%lx handled S-EL1 interrupt %d\n", |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 111 | read_mpidr(), id); |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 112 | VERBOSE("TSP: cpu 0x%lx: %d S-EL1 requests\n", |
| 113 | read_mpidr(), tsp_stats[linear_id].sel1_intr_count); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 114 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 115 | #endif |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 116 | return 0; |
| 117 | } |