blob: c13d28c357b957c77c941183bfbb430618511fd8 [file] [log] [blame]
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +01001/*
Jeenu Viswambharanaf34cd72018-01-22 12:29:12 +00002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Jeenu Viswambharan03b645e2018-08-02 10:14:12 +01007#ifndef EHF_H
8#define EHF_H
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +01009
Julius Wernerd5dfdeb2019-07-09 13:49:11 -070010#ifndef __ASSEMBLER__
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010011
Antonio Nino Diaz93c78ed2018-08-16 16:52:57 +010012#include <cdefs.h>
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010013#include <stdint.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000014
15#include <lib/utils_def.h>
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010016
17/* Valid priorities set bit 0 of the priority handler. */
Antonio Nino Diazc9512bc2018-08-24 16:30:29 +010018#define EHF_PRI_VALID_ BIT(0)
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010019
20/* Marker for no handler registered for a valid priority */
Jeenu Viswambharan03b645e2018-08-02 10:14:12 +010021#define EHF_NO_HANDLER_ (0U | EHF_PRI_VALID_)
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010022
23/* Extract the specified number of top bits from 7 lower bits of priority */
24#define EHF_PRI_TO_IDX(pri, plat_bits) \
Jeenu Viswambharan03b645e2018-08-02 10:14:12 +010025 ((((unsigned) (pri)) & 0x7fu) >> (7u - (plat_bits)))
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010026
27/* Install exception priority descriptor at a suitable index */
28#define EHF_PRI_DESC(plat_bits, priority) \
29 [EHF_PRI_TO_IDX(priority, plat_bits)] = { \
Jeenu Viswambharan03b645e2018-08-02 10:14:12 +010030 .ehf_handler = EHF_NO_HANDLER_, \
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010031 }
32
33/* Macro for platforms to regiter its exception priorities */
34#define EHF_REGISTER_PRIORITIES(priorities, num, bits) \
35 const ehf_priorities_t exception_data = { \
Jeenu Viswambharan03b645e2018-08-02 10:14:12 +010036 .num_priorities = (num), \
37 .ehf_priorities = (priorities), \
38 .pri_bits = (bits), \
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010039 }
40
41/*
42 * Priority stack, managed as a bitmap.
43 *
44 * Currently only supports 32 priority levels, allowing platforms to use up to 5
45 * top bits of priority. But the type can be changed to uint64_t should need
46 * arise to support 64 priority levels, allowing platforms to use up to 6 top
47 * bits of priority.
48 */
49typedef uint32_t ehf_pri_bits_t;
50
51/*
52 * Per-PE exception data. The data for each PE is kept as a per-CPU data field.
53 * See cpu_data.h.
54 */
55typedef struct {
56 ehf_pri_bits_t active_pri_bits;
57
58 /* Priority mask value before any priority levels were active */
59 uint8_t init_pri_mask;
Jeenu Viswambharan3d732e22017-10-04 12:21:34 +010060
61 /* Non-secure priority mask value stashed during Secure execution */
62 uint8_t ns_pri_mask;
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010063} __aligned(sizeof(uint64_t)) pe_exc_data_t;
64
65typedef int (*ehf_handler_t)(uint32_t intr_raw, uint32_t flags, void *handle,
66 void *cookie);
67
68typedef struct ehf_pri_desc {
69 /*
70 * 4-byte-aligned exception handler. Bit 0 indicates the corresponding
71 * priority level is valid. This is effectively of ehf_handler_t type,
72 * but left as uintptr_t in order to make pointer arithmetic convenient.
73 */
74 uintptr_t ehf_handler;
75} ehf_pri_desc_t;
76
Jeenu Viswambharan03b645e2018-08-02 10:14:12 +010077typedef struct ehf_priority_type {
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010078 ehf_pri_desc_t *ehf_priorities;
79 unsigned int num_priorities;
Jeenu Viswambharan03b645e2018-08-02 10:14:12 +010080 unsigned int pri_bits;
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010081} ehf_priorities_t;
82
83void ehf_init(void);
84void ehf_activate_priority(unsigned int priority);
85void ehf_deactivate_priority(unsigned int priority);
86void ehf_register_priority_handler(unsigned int pri, ehf_handler_t handler);
Jeenu Viswambharanaf34cd72018-01-22 12:29:12 +000087void ehf_allow_ns_preemption(uint64_t preempt_ret_code);
Jeenu Viswambharan3d732e22017-10-04 12:21:34 +010088unsigned int ehf_is_ns_preemption_allowed(void);
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010089
Julius Wernerd5dfdeb2019-07-09 13:49:11 -070090#endif /* __ASSEMBLER__ */
Jeenu Viswambharan21b818c2017-09-22 08:32:10 +010091
Jeenu Viswambharan03b645e2018-08-02 10:14:12 +010092#endif /* EHF_H */