blob: 1446279866dee710720a743fa917b252a798f198 [file] [log] [blame]
Jeenu Viswambharan10a67272017-09-22 08:32:10 +01001/*
Jeenu Viswambharaneeb353c2018-01-22 12:29:12 +00002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Jeenu Viswambharan10a67272017-09-22 08:32:10 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +01007#ifndef EHF_H
8#define EHF_H
Jeenu Viswambharan10a67272017-09-22 08:32:10 +01009
10#ifndef __ASSEMBLY__
11
12#include <stdint.h>
13#include <utils_def.h>
14
15/* Valid priorities set bit 0 of the priority handler. */
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +010016#define EHF_PRI_VALID_ (((uintptr_t) 1) << 0)
Jeenu Viswambharan10a67272017-09-22 08:32:10 +010017
18/* Marker for no handler registered for a valid priority */
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +010019#define EHF_NO_HANDLER_ (0U | EHF_PRI_VALID_)
Jeenu Viswambharan10a67272017-09-22 08:32:10 +010020
21/* Extract the specified number of top bits from 7 lower bits of priority */
22#define EHF_PRI_TO_IDX(pri, plat_bits) \
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +010023 ((((unsigned) (pri)) & 0x7fu) >> (7u - (plat_bits)))
Jeenu Viswambharan10a67272017-09-22 08:32:10 +010024
25/* Install exception priority descriptor at a suitable index */
26#define EHF_PRI_DESC(plat_bits, priority) \
27 [EHF_PRI_TO_IDX(priority, plat_bits)] = { \
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +010028 .ehf_handler = EHF_NO_HANDLER_, \
Jeenu Viswambharan10a67272017-09-22 08:32:10 +010029 }
30
31/* Macro for platforms to regiter its exception priorities */
32#define EHF_REGISTER_PRIORITIES(priorities, num, bits) \
33 const ehf_priorities_t exception_data = { \
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +010034 .num_priorities = (num), \
35 .ehf_priorities = (priorities), \
36 .pri_bits = (bits), \
Jeenu Viswambharan10a67272017-09-22 08:32:10 +010037 }
38
39/*
40 * Priority stack, managed as a bitmap.
41 *
42 * Currently only supports 32 priority levels, allowing platforms to use up to 5
43 * top bits of priority. But the type can be changed to uint64_t should need
44 * arise to support 64 priority levels, allowing platforms to use up to 6 top
45 * bits of priority.
46 */
47typedef uint32_t ehf_pri_bits_t;
48
49/*
50 * Per-PE exception data. The data for each PE is kept as a per-CPU data field.
51 * See cpu_data.h.
52 */
53typedef struct {
54 ehf_pri_bits_t active_pri_bits;
55
56 /* Priority mask value before any priority levels were active */
57 uint8_t init_pri_mask;
Jeenu Viswambharan6c6f24d2017-10-04 12:21:34 +010058
59 /* Non-secure priority mask value stashed during Secure execution */
60 uint8_t ns_pri_mask;
Jeenu Viswambharan10a67272017-09-22 08:32:10 +010061} __aligned(sizeof(uint64_t)) pe_exc_data_t;
62
63typedef int (*ehf_handler_t)(uint32_t intr_raw, uint32_t flags, void *handle,
64 void *cookie);
65
66typedef struct ehf_pri_desc {
67 /*
68 * 4-byte-aligned exception handler. Bit 0 indicates the corresponding
69 * priority level is valid. This is effectively of ehf_handler_t type,
70 * but left as uintptr_t in order to make pointer arithmetic convenient.
71 */
72 uintptr_t ehf_handler;
73} ehf_pri_desc_t;
74
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +010075typedef struct ehf_priority_type {
Jeenu Viswambharan10a67272017-09-22 08:32:10 +010076 ehf_pri_desc_t *ehf_priorities;
77 unsigned int num_priorities;
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +010078 unsigned int pri_bits;
Jeenu Viswambharan10a67272017-09-22 08:32:10 +010079} ehf_priorities_t;
80
81void ehf_init(void);
82void ehf_activate_priority(unsigned int priority);
83void ehf_deactivate_priority(unsigned int priority);
84void ehf_register_priority_handler(unsigned int pri, ehf_handler_t handler);
Jeenu Viswambharaneeb353c2018-01-22 12:29:12 +000085void ehf_allow_ns_preemption(uint64_t preempt_ret_code);
Jeenu Viswambharan6c6f24d2017-10-04 12:21:34 +010086unsigned int ehf_is_ns_preemption_allowed(void);
Jeenu Viswambharan10a67272017-09-22 08:32:10 +010087
88#endif /* __ASSEMBLY__ */
89
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +010090#endif /* EHF_H */