ehf.h 2.62 KB
Newer Older
1
/*
2
 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3
4
5
6
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
7
8
#ifndef EHF_H
#define EHF_H
9
10
11
12
13
14
15

#ifndef __ASSEMBLY__

#include <stdint.h>
#include <utils_def.h>

/* Valid priorities set bit 0 of the priority handler. */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
16
#define EHF_PRI_VALID_	(((uintptr_t) 1) << 0)
17
18

/* Marker for no handler registered for a valid priority */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
19
#define EHF_NO_HANDLER_	(0U | EHF_PRI_VALID_)
20
21
22

/* Extract the specified number of top bits from 7 lower bits of priority */
#define EHF_PRI_TO_IDX(pri, plat_bits) \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
23
	((((unsigned) (pri)) & 0x7fu) >> (7u - (plat_bits)))
24
25
26
27

/* Install exception priority descriptor at a suitable index */
#define EHF_PRI_DESC(plat_bits, priority) \
	[EHF_PRI_TO_IDX(priority, plat_bits)] = { \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
28
		.ehf_handler = EHF_NO_HANDLER_, \
29
30
31
32
33
	}

/* Macro for platforms to regiter its exception priorities */
#define EHF_REGISTER_PRIORITIES(priorities, num, bits) \
	const ehf_priorities_t exception_data = { \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
34
35
36
		.num_priorities = (num), \
		.ehf_priorities = (priorities), \
		.pri_bits = (bits), \
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
	}

/*
 * Priority stack, managed as a bitmap.
 *
 * Currently only supports 32 priority levels, allowing platforms to use up to 5
 * top bits of priority. But the type can be changed to uint64_t should need
 * arise to support 64 priority levels, allowing platforms to use up to 6 top
 * bits of priority.
 */
typedef uint32_t ehf_pri_bits_t;

/*
 * Per-PE exception data. The data for each PE is kept as a per-CPU data field.
 * See cpu_data.h.
 */
typedef struct {
	ehf_pri_bits_t active_pri_bits;

	/* Priority mask value before any priority levels were active */
	uint8_t init_pri_mask;
58
59
60

	/* Non-secure priority mask value stashed during Secure execution */
	uint8_t ns_pri_mask;
61
62
63
64
65
66
67
68
69
70
71
72
73
74
} __aligned(sizeof(uint64_t)) pe_exc_data_t;

typedef int (*ehf_handler_t)(uint32_t intr_raw, uint32_t flags, void *handle,
		void *cookie);

typedef struct ehf_pri_desc {
	/*
	 * 4-byte-aligned exception handler. Bit 0 indicates the corresponding
	 * priority level is valid. This is effectively of ehf_handler_t type,
	 * but left as uintptr_t in order to make pointer arithmetic convenient.
	 */
	uintptr_t ehf_handler;
} ehf_pri_desc_t;

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
75
typedef struct ehf_priority_type {
76
77
	ehf_pri_desc_t *ehf_priorities;
	unsigned int num_priorities;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
78
	unsigned int pri_bits;
79
80
81
82
83
84
} ehf_priorities_t;

void ehf_init(void);
void ehf_activate_priority(unsigned int priority);
void ehf_deactivate_priority(unsigned int priority);
void ehf_register_priority_handler(unsigned int pri, ehf_handler_t handler);
85
void ehf_allow_ns_preemption(uint64_t preempt_ret_code);
86
unsigned int ehf_is_ns_preemption_allowed(void);
87
88
89

#endif /* __ASSEMBLY__ */

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
90
#endif /* EHF_H */