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 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <arch_helpers.h> |
| 32 | #include <assert.h> |
| 33 | #include <debug.h> |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 34 | #include <platform.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 35 | #include <platform_def.h> |
Dan Handley | e2c27f5 | 2014-08-01 17:58:27 +0100 | [diff] [blame] | 36 | #include <tsp.h> |
| 37 | #include "tsp_private.h" |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 38 | |
| 39 | /******************************************************************************* |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 40 | * This function updates the TSP statistics for S-EL1 interrupts handled |
| 41 | * synchronously i.e the ones that have been handed over by the TSPD. It also |
| 42 | * keeps count of the number of times control was passed back to the TSPD |
| 43 | * after handling the interrupt. In the future it will be possible that the |
| 44 | * TSPD hands over an S-EL1 interrupt to the TSP but does not expect it to |
| 45 | * return execution. This statistic will be useful to distinguish between these |
| 46 | * two models of synchronous S-EL1 interrupt handling. The 'elr_el3' parameter |
| 47 | * contains the address of the instruction in normal world where this S-EL1 |
| 48 | * interrupt was generated. |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 49 | ******************************************************************************/ |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 50 | 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] | 51 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 52 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 53 | |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 54 | tsp_stats[linear_id].sync_sel1_intr_count++; |
| 55 | if (type == TSP_HANDLE_SEL1_INTR_AND_RETURN) |
| 56 | tsp_stats[linear_id].sync_sel1_intr_ret_count++; |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 57 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 58 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 59 | spin_lock(&console_lock); |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 60 | VERBOSE("TSP: cpu 0x%lx sync s-el1 interrupt request from 0x%lx\n", |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 61 | read_mpidr(), elr_el3); |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 62 | VERBOSE("TSP: cpu 0x%lx: %d sync s-el1 interrupt requests," |
| 63 | " %d sync s-el1 interrupt returns\n", |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 64 | read_mpidr(), |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 65 | tsp_stats[linear_id].sync_sel1_intr_count, |
| 66 | tsp_stats[linear_id].sync_sel1_intr_ret_count); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 67 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 68 | #endif |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Soby Mathew | bc91282 | 2015-09-22 12:01:18 +0100 | [diff] [blame] | 71 | /****************************************************************************** |
| 72 | * This function is invoked when a non S-EL1 interrupt is received and causes |
| 73 | * the preemption of TSP. This function returns TSP_PREEMPTED and results |
| 74 | * in the control being handed over to EL3 for handling the interrupt. |
| 75 | *****************************************************************************/ |
| 76 | int32_t tsp_handle_preemption(void) |
| 77 | { |
| 78 | uint32_t linear_id = plat_my_core_pos(); |
| 79 | |
| 80 | tsp_stats[linear_id].preempt_intr_count++; |
| 81 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
| 82 | spin_lock(&console_lock); |
| 83 | VERBOSE("TSP: cpu 0x%lx: %d preempt interrupt requests\n", |
| 84 | read_mpidr(), tsp_stats[linear_id].preempt_intr_count); |
| 85 | spin_unlock(&console_lock); |
| 86 | #endif |
| 87 | return TSP_PREEMPTED; |
| 88 | } |
| 89 | |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 90 | /******************************************************************************* |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 91 | * TSP interrupt handler is called as a part of both synchronous and |
| 92 | * asynchronous handling of TSP interrupts. Currently the physical timer |
| 93 | * interrupt is the only S-EL1 interrupt that this handler expects. It returns |
| 94 | * 0 upon successfully handling the expected interrupt and all other |
| 95 | * interrupts are treated as normal world or EL3 interrupts. |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 96 | ******************************************************************************/ |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 97 | int32_t tsp_common_int_handler(void) |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 98 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 99 | uint32_t linear_id = plat_my_core_pos(), id; |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 100 | |
| 101 | /* |
| 102 | * Get the highest priority pending interrupt id and see if it is the |
| 103 | * secure physical generic timer interrupt in which case, handle it. |
| 104 | * Otherwise throw this interrupt at the EL3 firmware. |
Soby Mathew | bc91282 | 2015-09-22 12:01:18 +0100 | [diff] [blame] | 105 | * |
| 106 | * There is a small time window between reading the highest priority |
| 107 | * pending interrupt and acknowledging it during which another |
| 108 | * interrupt of higher priority could become the highest pending |
| 109 | * interrupt. This is not expected to happen currently for TSP. |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 110 | */ |
Dan Handley | 701fea7 | 2014-05-27 16:17:21 +0100 | [diff] [blame] | 111 | id = plat_ic_get_pending_interrupt_id(); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 112 | |
| 113 | /* TSP can only handle the secure physical timer interrupt */ |
Dan Handley | 4fd2f5c | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 114 | if (id != TSP_IRQ_SEC_PHY_TIMER) |
Soby Mathew | bc91282 | 2015-09-22 12:01:18 +0100 | [diff] [blame] | 115 | return tsp_handle_preemption(); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 116 | |
| 117 | /* |
Soby Mathew | bc91282 | 2015-09-22 12:01:18 +0100 | [diff] [blame] | 118 | * Acknowledge and handle the secure timer interrupt. Also sanity check |
| 119 | * if it has been preempted by another interrupt through an assertion. |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 120 | */ |
Dan Handley | 701fea7 | 2014-05-27 16:17:21 +0100 | [diff] [blame] | 121 | id = plat_ic_acknowledge_interrupt(); |
Dan Handley | 4fd2f5c | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 122 | assert(id == TSP_IRQ_SEC_PHY_TIMER); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 123 | tsp_generic_timer_handler(); |
Dan Handley | 701fea7 | 2014-05-27 16:17:21 +0100 | [diff] [blame] | 124 | plat_ic_end_of_interrupt(id); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 125 | |
| 126 | /* Update the statistics and print some messages */ |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 127 | tsp_stats[linear_id].sel1_intr_count++; |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 128 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 129 | spin_lock(&console_lock); |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 130 | VERBOSE("TSP: cpu 0x%lx handled S-EL1 interrupt %d\n", |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 131 | read_mpidr(), id); |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 132 | VERBOSE("TSP: cpu 0x%lx: %d S-EL1 requests\n", |
| 133 | read_mpidr(), tsp_stats[linear_id].sel1_intr_count); |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 134 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 135 | #endif |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 136 | return 0; |
| 137 | } |