Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 1 | /* |
Jeenu Viswambharan | eeb353c | 2018-01-22 12:29:12 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Jeenu Viswambharan | 837cc9c | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 7 | #ifndef EHF_H |
| 8 | #define EHF_H |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 9 | |
| 10 | #ifndef __ASSEMBLY__ |
| 11 | |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 12 | #include <cdefs.h> |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 13 | #include <stdint.h> |
| 14 | #include <utils_def.h> |
| 15 | |
| 16 | /* Valid priorities set bit 0 of the priority handler. */ |
Antonio Nino Diaz | e0b757d | 2018-08-24 16:30:29 +0100 | [diff] [blame] | 17 | #define EHF_PRI_VALID_ BIT(0) |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 18 | |
| 19 | /* Marker for no handler registered for a valid priority */ |
Jeenu Viswambharan | 837cc9c | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 20 | #define EHF_NO_HANDLER_ (0U | EHF_PRI_VALID_) |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 21 | |
| 22 | /* Extract the specified number of top bits from 7 lower bits of priority */ |
| 23 | #define EHF_PRI_TO_IDX(pri, plat_bits) \ |
Jeenu Viswambharan | 837cc9c | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 24 | ((((unsigned) (pri)) & 0x7fu) >> (7u - (plat_bits))) |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 25 | |
| 26 | /* Install exception priority descriptor at a suitable index */ |
| 27 | #define EHF_PRI_DESC(plat_bits, priority) \ |
| 28 | [EHF_PRI_TO_IDX(priority, plat_bits)] = { \ |
Jeenu Viswambharan | 837cc9c | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 29 | .ehf_handler = EHF_NO_HANDLER_, \ |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | /* Macro for platforms to regiter its exception priorities */ |
| 33 | #define EHF_REGISTER_PRIORITIES(priorities, num, bits) \ |
| 34 | const ehf_priorities_t exception_data = { \ |
Jeenu Viswambharan | 837cc9c | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 35 | .num_priorities = (num), \ |
| 36 | .ehf_priorities = (priorities), \ |
| 37 | .pri_bits = (bits), \ |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /* |
| 41 | * Priority stack, managed as a bitmap. |
| 42 | * |
| 43 | * Currently only supports 32 priority levels, allowing platforms to use up to 5 |
| 44 | * top bits of priority. But the type can be changed to uint64_t should need |
| 45 | * arise to support 64 priority levels, allowing platforms to use up to 6 top |
| 46 | * bits of priority. |
| 47 | */ |
| 48 | typedef uint32_t ehf_pri_bits_t; |
| 49 | |
| 50 | /* |
| 51 | * Per-PE exception data. The data for each PE is kept as a per-CPU data field. |
| 52 | * See cpu_data.h. |
| 53 | */ |
| 54 | typedef struct { |
| 55 | ehf_pri_bits_t active_pri_bits; |
| 56 | |
| 57 | /* Priority mask value before any priority levels were active */ |
| 58 | uint8_t init_pri_mask; |
Jeenu Viswambharan | 6c6f24d | 2017-10-04 12:21:34 +0100 | [diff] [blame] | 59 | |
| 60 | /* Non-secure priority mask value stashed during Secure execution */ |
| 61 | uint8_t ns_pri_mask; |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 62 | } __aligned(sizeof(uint64_t)) pe_exc_data_t; |
| 63 | |
| 64 | typedef int (*ehf_handler_t)(uint32_t intr_raw, uint32_t flags, void *handle, |
| 65 | void *cookie); |
| 66 | |
| 67 | typedef struct ehf_pri_desc { |
| 68 | /* |
| 69 | * 4-byte-aligned exception handler. Bit 0 indicates the corresponding |
| 70 | * priority level is valid. This is effectively of ehf_handler_t type, |
| 71 | * but left as uintptr_t in order to make pointer arithmetic convenient. |
| 72 | */ |
| 73 | uintptr_t ehf_handler; |
| 74 | } ehf_pri_desc_t; |
| 75 | |
Jeenu Viswambharan | 837cc9c | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 76 | typedef struct ehf_priority_type { |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 77 | ehf_pri_desc_t *ehf_priorities; |
| 78 | unsigned int num_priorities; |
Jeenu Viswambharan | 837cc9c | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 79 | unsigned int pri_bits; |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 80 | } ehf_priorities_t; |
| 81 | |
| 82 | void ehf_init(void); |
| 83 | void ehf_activate_priority(unsigned int priority); |
| 84 | void ehf_deactivate_priority(unsigned int priority); |
| 85 | void ehf_register_priority_handler(unsigned int pri, ehf_handler_t handler); |
Jeenu Viswambharan | eeb353c | 2018-01-22 12:29:12 +0000 | [diff] [blame] | 86 | void ehf_allow_ns_preemption(uint64_t preempt_ret_code); |
Jeenu Viswambharan | 6c6f24d | 2017-10-04 12:21:34 +0100 | [diff] [blame] | 87 | unsigned int ehf_is_ns_preemption_allowed(void); |
Jeenu Viswambharan | 10a6727 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 88 | |
| 89 | #endif /* __ASSEMBLY__ */ |
| 90 | |
Jeenu Viswambharan | 837cc9c | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 91 | #endif /* EHF_H */ |