xref: /rk3399_ARM-atf/include/bl31/sync_handle.h (revision 1ae75529bc2e5a213c3e458898c219c34aa99f65)
1ccd81f1eSAndre Przywara /*
2ccd81f1eSAndre Przywara  * Copyright (c) 2022, ARM Limited. All rights reserved.
3ccd81f1eSAndre Przywara  *
4ccd81f1eSAndre Przywara  * SPDX-License-Identifier: BSD-3-Clause
5ccd81f1eSAndre Przywara  */
6ccd81f1eSAndre Przywara 
7ccd81f1eSAndre Przywara #ifndef TRAP_HANDLE_H
8ccd81f1eSAndre Przywara #define TRAP_HANDLE_H
9ccd81f1eSAndre Przywara 
10ccd81f1eSAndre Przywara #include <stdbool.h>
11ccd81f1eSAndre Przywara #include <context.h>
12ccd81f1eSAndre Przywara 
13ccd81f1eSAndre Przywara #define ISS_SYSREG_OPCODE_MASK		0x3ffc1eUL
14ccd81f1eSAndre Przywara #define ISS_SYSREG_REG_MASK		0x0003e0UL
15ccd81f1eSAndre Przywara #define ISS_SYSREG_REG_SHIFT		5U
16ccd81f1eSAndre Przywara #define ISS_SYSREG_DIRECTION_MASK	0x000001UL
17ccd81f1eSAndre Przywara 
18*1ae75529SAndre Przywara #define ISS_SYSREG_OPCODE_RNDR		0x30c808U
19*1ae75529SAndre Przywara #define ISS_SYSREG_OPCODE_RNDRRS	0x32c808U
20*1ae75529SAndre Przywara 
21ccd81f1eSAndre Przywara #define TRAP_RET_UNHANDLED		-1
22ccd81f1eSAndre Przywara #define TRAP_RET_REPEAT			0
23ccd81f1eSAndre Przywara #define TRAP_RET_CONTINUE		1
24ccd81f1eSAndre Przywara 
25ccd81f1eSAndre Przywara #ifndef __ASSEMBLER__
26ccd81f1eSAndre Przywara static inline unsigned int get_sysreg_iss_rt(uint64_t esr)
27ccd81f1eSAndre Przywara {
28ccd81f1eSAndre Przywara 	return (esr & ISS_SYSREG_REG_MASK) >> ISS_SYSREG_REG_SHIFT;
29ccd81f1eSAndre Przywara }
30ccd81f1eSAndre Przywara 
31ccd81f1eSAndre Przywara static inline bool is_sysreg_iss_write(uint64_t esr)
32ccd81f1eSAndre Przywara {
33ccd81f1eSAndre Przywara 	return !(esr & ISS_SYSREG_DIRECTION_MASK);
34ccd81f1eSAndre Przywara }
35ccd81f1eSAndre Przywara 
36ccd81f1eSAndre Przywara /**
37ccd81f1eSAndre Przywara  * handle_sysreg_trap() - Handle AArch64 system register traps from lower ELs
38ccd81f1eSAndre Przywara  * @esr_el3: The content of ESR_EL3, containing the trap syndrome information
39ccd81f1eSAndre Przywara  * @ctx: Pointer to the lower EL context, containing saved registers
40ccd81f1eSAndre Przywara  *
41ccd81f1eSAndre Przywara  * Called by the exception handler when a synchronous trap identifies as a
42ccd81f1eSAndre Przywara  * system register trap (EC=0x18). ESR contains the encoding of the op[x] and
43ccd81f1eSAndre Przywara  * CRm/CRn fields, to identify the system register, and the target/source
44ccd81f1eSAndre Przywara  * GPR plus the direction (MRS/MSR). The lower EL's context can be altered
45ccd81f1eSAndre Przywara  * by the function, to inject back the result of the emulation.
46ccd81f1eSAndre Przywara  *
47ccd81f1eSAndre Przywara  * Return: indication how to proceed with the trap:
48ccd81f1eSAndre Przywara  *   TRAP_RET_UNHANDLED(-1): trap is unhandled, trigger panic
49ccd81f1eSAndre Przywara  *   TRAP_RET_REPEAT(0): trap was handled, return to the trapping instruction
50ccd81f1eSAndre Przywara  *			 (repeating it)
51ccd81f1eSAndre Przywara  *   TRAP_RET_CONTINUE(1): trap was handled, return to the next instruction
52ccd81f1eSAndre Przywara  *		           (continuing after it)
53ccd81f1eSAndre Przywara  */
54ccd81f1eSAndre Przywara int handle_sysreg_trap(uint64_t esr_el3, cpu_context_t *ctx);
55ccd81f1eSAndre Przywara 
56*1ae75529SAndre Przywara /* Prototypes for system register emulation handlers provided by platforms. */
57*1ae75529SAndre Przywara int plat_handle_rng_trap(uint64_t esr_el3, cpu_context_t *ctx);
58*1ae75529SAndre Przywara 
59ccd81f1eSAndre Przywara #endif /* __ASSEMBLER__ */
60ccd81f1eSAndre Przywara 
61ccd81f1eSAndre Przywara #endif
62