blob: 142b4c0aa343325b48dd95ed6c0e4ea746f4f285 [file] [log] [blame]
Jeenu Viswambharan10a67272017-09-22 08:32:10 +01001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __EHF_H__
8#define __EHF_H__
9
10#ifndef __ASSEMBLY__
11
12#include <stdint.h>
13#include <utils_def.h>
14
15/* Valid priorities set bit 0 of the priority handler. */
16#define _EHF_PRI_VALID (((uintptr_t) 1) << 0)
17
18/* Marker for no handler registered for a valid priority */
19#define _EHF_NO_HANDLER (0 | _EHF_PRI_VALID)
20
21/* Extract the specified number of top bits from 7 lower bits of priority */
22#define EHF_PRI_TO_IDX(pri, plat_bits) \
23 ((pri & 0x7f) >> (7 - plat_bits))
24
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)] = { \
28 .ehf_handler = _EHF_NO_HANDLER, \
29 }
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 = { \
34 .num_priorities = num, \
35 .ehf_priorities = priorities, \
36 .pri_bits = bits, \
37 }
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;
58} __aligned(sizeof(uint64_t)) pe_exc_data_t;
59
60typedef int (*ehf_handler_t)(uint32_t intr_raw, uint32_t flags, void *handle,
61 void *cookie);
62
63typedef struct ehf_pri_desc {
64 /*
65 * 4-byte-aligned exception handler. Bit 0 indicates the corresponding
66 * priority level is valid. This is effectively of ehf_handler_t type,
67 * but left as uintptr_t in order to make pointer arithmetic convenient.
68 */
69 uintptr_t ehf_handler;
70} ehf_pri_desc_t;
71
72typedef struct ehf_priorities {
73 ehf_pri_desc_t *ehf_priorities;
74 unsigned int num_priorities;
75 int pri_bits;
76} ehf_priorities_t;
77
78void ehf_init(void);
79void ehf_activate_priority(unsigned int priority);
80void ehf_deactivate_priority(unsigned int priority);
81void ehf_register_priority_handler(unsigned int pri, ehf_handler_t handler);
82
83#endif /* __ASSEMBLY__ */
84
85#endif /* __EHF_H__ */