xref: /rk3399_ARM-atf/include/bl31/ehf.h (revision 4bd8c929b4bc6e1731c2892b38d4a8c43e8e89dc)
121b818c0SJeenu Viswambharan /*
2af34cd72SJeenu Viswambharan  * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
321b818c0SJeenu Viswambharan  *
421b818c0SJeenu Viswambharan  * SPDX-License-Identifier: BSD-3-Clause
521b818c0SJeenu Viswambharan  */
621b818c0SJeenu Viswambharan 
703b645edSJeenu Viswambharan #ifndef EHF_H
803b645edSJeenu Viswambharan #define EHF_H
921b818c0SJeenu Viswambharan 
10d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__
1121b818c0SJeenu Viswambharan 
1293c78ed2SAntonio Nino Diaz #include <cdefs.h>
1321b818c0SJeenu Viswambharan #include <stdint.h>
1409d40e0eSAntonio Nino Diaz 
1509d40e0eSAntonio Nino Diaz #include <lib/utils_def.h>
1621b818c0SJeenu Viswambharan 
1721b818c0SJeenu Viswambharan /* Valid priorities set bit 0 of the priority handler. */
18c9512bcaSAntonio Nino Diaz #define EHF_PRI_VALID_	BIT(0)
1921b818c0SJeenu Viswambharan 
2021b818c0SJeenu Viswambharan /* Marker for no handler registered for a valid priority */
2103b645edSJeenu Viswambharan #define EHF_NO_HANDLER_	(0U | EHF_PRI_VALID_)
2221b818c0SJeenu Viswambharan 
2321b818c0SJeenu Viswambharan /* Extract the specified number of top bits from 7 lower bits of priority */
2421b818c0SJeenu Viswambharan #define EHF_PRI_TO_IDX(pri, plat_bits) \
2503b645edSJeenu Viswambharan 	((((unsigned) (pri)) & 0x7fu) >> (7u - (plat_bits)))
2621b818c0SJeenu Viswambharan 
2721b818c0SJeenu Viswambharan /* Install exception priority descriptor at a suitable index */
2821b818c0SJeenu Viswambharan #define EHF_PRI_DESC(plat_bits, priority) \
2921b818c0SJeenu Viswambharan 	[EHF_PRI_TO_IDX(priority, plat_bits)] = { \
3003b645edSJeenu Viswambharan 		.ehf_handler = EHF_NO_HANDLER_, \
3121b818c0SJeenu Viswambharan 	}
3221b818c0SJeenu Viswambharan 
33*1b491eeaSElyes Haouas /* Macro for platforms to register its exception priorities */
3421b818c0SJeenu Viswambharan #define EHF_REGISTER_PRIORITIES(priorities, num, bits) \
3521b818c0SJeenu Viswambharan 	const ehf_priorities_t exception_data = { \
3603b645edSJeenu Viswambharan 		.num_priorities = (num), \
3703b645edSJeenu Viswambharan 		.ehf_priorities = (priorities), \
3803b645edSJeenu Viswambharan 		.pri_bits = (bits), \
3921b818c0SJeenu Viswambharan 	}
4021b818c0SJeenu Viswambharan 
4121b818c0SJeenu Viswambharan /*
4221b818c0SJeenu Viswambharan  * Priority stack, managed as a bitmap.
4321b818c0SJeenu Viswambharan  *
4421b818c0SJeenu Viswambharan  * Currently only supports 32 priority levels, allowing platforms to use up to 5
4521b818c0SJeenu Viswambharan  * top bits of priority. But the type can be changed to uint64_t should need
4621b818c0SJeenu Viswambharan  * arise to support 64 priority levels, allowing platforms to use up to 6 top
4721b818c0SJeenu Viswambharan  * bits of priority.
4821b818c0SJeenu Viswambharan  */
4921b818c0SJeenu Viswambharan typedef uint32_t ehf_pri_bits_t;
5021b818c0SJeenu Viswambharan 
5121b818c0SJeenu Viswambharan /*
5221b818c0SJeenu Viswambharan  * Per-PE exception data. The data for each PE is kept as a per-CPU data field.
5321b818c0SJeenu Viswambharan  * See cpu_data.h.
5421b818c0SJeenu Viswambharan  */
5521b818c0SJeenu Viswambharan typedef struct {
5621b818c0SJeenu Viswambharan 	ehf_pri_bits_t active_pri_bits;
5721b818c0SJeenu Viswambharan 
5821b818c0SJeenu Viswambharan 	/* Priority mask value before any priority levels were active */
5921b818c0SJeenu Viswambharan 	uint8_t init_pri_mask;
603d732e23SJeenu Viswambharan 
613d732e23SJeenu Viswambharan 	/* Non-secure priority mask value stashed during Secure execution */
623d732e23SJeenu Viswambharan 	uint8_t ns_pri_mask;
6321b818c0SJeenu Viswambharan } __aligned(sizeof(uint64_t)) pe_exc_data_t;
6421b818c0SJeenu Viswambharan 
6521b818c0SJeenu Viswambharan typedef int (*ehf_handler_t)(uint32_t intr_raw, uint32_t flags, void *handle,
6621b818c0SJeenu Viswambharan 		void *cookie);
6721b818c0SJeenu Viswambharan 
6821b818c0SJeenu Viswambharan typedef struct ehf_pri_desc {
6921b818c0SJeenu Viswambharan 	/*
7021b818c0SJeenu Viswambharan 	 * 4-byte-aligned exception handler. Bit 0 indicates the corresponding
7121b818c0SJeenu Viswambharan 	 * priority level is valid. This is effectively of ehf_handler_t type,
7221b818c0SJeenu Viswambharan 	 * but left as uintptr_t in order to make pointer arithmetic convenient.
7321b818c0SJeenu Viswambharan 	 */
7421b818c0SJeenu Viswambharan 	uintptr_t ehf_handler;
7521b818c0SJeenu Viswambharan } ehf_pri_desc_t;
7621b818c0SJeenu Viswambharan 
7703b645edSJeenu Viswambharan typedef struct ehf_priority_type {
7821b818c0SJeenu Viswambharan 	ehf_pri_desc_t *ehf_priorities;
7921b818c0SJeenu Viswambharan 	unsigned int num_priorities;
8003b645edSJeenu Viswambharan 	unsigned int pri_bits;
8121b818c0SJeenu Viswambharan } ehf_priorities_t;
8221b818c0SJeenu Viswambharan 
8321b818c0SJeenu Viswambharan void ehf_init(void);
8421b818c0SJeenu Viswambharan void ehf_activate_priority(unsigned int priority);
8521b818c0SJeenu Viswambharan void ehf_deactivate_priority(unsigned int priority);
8621b818c0SJeenu Viswambharan void ehf_register_priority_handler(unsigned int pri, ehf_handler_t handler);
87af34cd72SJeenu Viswambharan void ehf_allow_ns_preemption(uint64_t preempt_ret_code);
883d732e23SJeenu Viswambharan unsigned int ehf_is_ns_preemption_allowed(void);
8921b818c0SJeenu Viswambharan 
90d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */
9121b818c0SJeenu Viswambharan 
9203b645edSJeenu Viswambharan #endif /* EHF_H */
93