summaryrefslogtreecommitdiff
path: root/spm/scmi/aarch64/lib/exceptions/sync.c
blob: 49b6bd8d9e80f6ff12005cd2c21d36198de7808a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Copyright (c) 2022, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
#include <stdbool.h>

#include <arch_helpers.h>
#include <debug.h>
#include <sync.h>

static exception_handler_t custom_sync_exception_handler;

void register_custom_sync_exception_handler(exception_handler_t handler)
{
	custom_sync_exception_handler = handler;
}

void unregister_custom_sync_exception_handler(void)
{
	custom_sync_exception_handler = NULL;
}

bool tftf_sync_exception_handler(void)
{
	uint64_t elr_elx = IS_IN_EL2() ? read_elr_el2() : read_elr_el1();
	bool resume = false;

	if (custom_sync_exception_handler == NULL) {
		return false;
	}

	resume = custom_sync_exception_handler();

	if (resume) {
		/* Move ELR to next instruction to allow tftf to continue */
		if (IS_IN_EL2()) {
			write_elr_el2(elr_elx + 4U);
		} else {
			write_elr_el1(elr_elx + 4U);
		}
	}

	return resume;
}