Manish Pandey | d27b37d | 2021-03-02 14:41:58 +0000 | [diff] [blame] | 1 | /* |
Madhukar Pappireddy | 7caaa4a | 2022-01-28 17:01:35 -0600 | [diff] [blame] | 2 | * Copyright (c) 2021-2022, Arm Limited. All rights reserved. |
Manish Pandey | d27b37d | 2021-03-02 14:41:58 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <debug.h> |
| 8 | |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 9 | #include "cactus_message_loop.h" |
| 10 | #include "cactus_test_cmds.h" |
| 11 | #include <drivers/arm/sp805.h> |
Manish Pandey | d27b37d | 2021-03-02 14:41:58 +0000 | [diff] [blame] | 12 | #include <ffa_helpers.h> |
| 13 | #include <sp_helpers.h> |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 14 | #include "spm_common.h" |
Manish Pandey | 58971b6 | 2020-09-21 21:10:38 +0100 | [diff] [blame] | 15 | #include <spm_helpers.h> |
Manish Pandey | d27b37d | 2021-03-02 14:41:58 +0000 | [diff] [blame] | 16 | |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 17 | #include <platform_def.h> |
Manish Pandey | f7aafef | 2021-03-03 11:31:47 +0000 | [diff] [blame] | 18 | |
J-Alves | a076d4c | 2021-10-19 16:06:15 +0100 | [diff] [blame] | 19 | #define NOTIFICATION_PENDING_INTERRUPT_INTID 5 |
| 20 | |
| 21 | extern void notification_pending_interrupt_handler(void); |
| 22 | |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 23 | extern ffa_id_t g_ffa_id; |
Manish Pandey | f7aafef | 2021-03-03 11:31:47 +0000 | [diff] [blame] | 24 | |
Madhukar Pappireddy | f4c8e8d | 2022-02-15 15:52:53 -0600 | [diff] [blame] | 25 | /* Secure virtual interrupt that was last handled by Cactus SP. */ |
| 26 | uint32_t last_serviced_interrupt[PLATFORM_CORE_COUNT]; |
| 27 | |
Madhukar Pappireddy | 7caaa4a | 2022-01-28 17:01:35 -0600 | [diff] [blame] | 28 | extern spinlock_t sp_handler_lock[NUM_VINT_ID]; |
| 29 | |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 30 | void cactus_interrupt_handler(void) |
Manish Pandey | f7aafef | 2021-03-03 11:31:47 +0000 | [diff] [blame] | 31 | { |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 32 | uint32_t intid = spm_interrupt_get(); |
Madhukar Pappireddy | f4c8e8d | 2022-02-15 15:52:53 -0600 | [diff] [blame] | 33 | unsigned int core_pos = get_current_core_id(); |
Manish Pandey | f7aafef | 2021-03-03 11:31:47 +0000 | [diff] [blame] | 34 | |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 35 | switch (intid) { |
| 36 | case MANAGED_EXIT_INTERRUPT_ID: |
| 37 | /* |
| 38 | * A secure partition performs its housekeeping and sends a |
| 39 | * direct response to signal interrupt completion. |
| 40 | * This is a pure virtual interrupt, no need for deactivation. |
| 41 | */ |
| 42 | cactus_response(g_ffa_id, HYP_ID, MANAGED_EXIT_INTERRUPT_ID); |
| 43 | break; |
| 44 | case IRQ_TWDOG_INTID: |
| 45 | /* |
| 46 | * Interrupt triggered due to Trusted watchdog timer expiry. |
| 47 | * Clear the interrupt and stop the timer. |
| 48 | */ |
Olivier Deprez | b92d91b | 2022-03-16 17:14:26 +0100 | [diff] [blame] | 49 | VERBOSE("Trusted WatchDog timer stopped\n"); |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 50 | sp805_twdog_stop(); |
Manish Pandey | d27b37d | 2021-03-02 14:41:58 +0000 | [diff] [blame] | 51 | |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 52 | /* Perform secure interrupt de-activation. */ |
| 53 | spm_interrupt_deactivate(intid); |
Manish Pandey | d27b37d | 2021-03-02 14:41:58 +0000 | [diff] [blame] | 54 | |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 55 | break; |
J-Alves | a076d4c | 2021-10-19 16:06:15 +0100 | [diff] [blame] | 56 | case NOTIFICATION_PENDING_INTERRUPT_INTID: |
| 57 | notification_pending_interrupt_handler(); |
| 58 | break; |
Madhukar Pappireddy | cd183ef | 2021-08-05 15:34:07 -0500 | [diff] [blame] | 59 | default: |
| 60 | /* |
| 61 | * Currently the only source of secure interrupt is Trusted |
| 62 | * Watchdog timer. |
| 63 | */ |
| 64 | ERROR("%s: Interrupt ID %x not handled!\n", __func__, |
| 65 | intid); |
| 66 | panic(); |
Manish Pandey | f7aafef | 2021-03-03 11:31:47 +0000 | [diff] [blame] | 67 | } |
Madhukar Pappireddy | 7caaa4a | 2022-01-28 17:01:35 -0600 | [diff] [blame] | 68 | |
Madhukar Pappireddy | f4c8e8d | 2022-02-15 15:52:53 -0600 | [diff] [blame] | 69 | last_serviced_interrupt[core_pos] = intid; |
| 70 | |
Madhukar Pappireddy | 7caaa4a | 2022-01-28 17:01:35 -0600 | [diff] [blame] | 71 | /* Invoke the tail end handler registered by the SP. */ |
| 72 | spin_lock(&sp_handler_lock[intid]); |
| 73 | if (sp_interrupt_tail_end_handler[intid]) { |
| 74 | sp_interrupt_tail_end_handler[intid](); |
| 75 | } |
| 76 | spin_unlock(&sp_handler_lock[intid]); |
Manish Pandey | d27b37d | 2021-03-02 14:41:58 +0000 | [diff] [blame] | 77 | } |