xref: /linux/arch/arm64/include/asm/rsi.h (revision 60675d4ca1ef0857e44eba5849b74a3a998d0c0f)
1c077711fSSuzuki K Poulose /* SPDX-License-Identifier: GPL-2.0-only */
2c077711fSSuzuki K Poulose /*
3c077711fSSuzuki K Poulose  * Copyright (C) 2024 ARM Ltd.
4c077711fSSuzuki K Poulose  */
5c077711fSSuzuki K Poulose 
6c077711fSSuzuki K Poulose #ifndef __ASM_RSI_H_
7c077711fSSuzuki K Poulose #define __ASM_RSI_H_
8c077711fSSuzuki K Poulose 
9c077711fSSuzuki K Poulose #include <linux/errno.h>
10c077711fSSuzuki K Poulose #include <linux/jump_label.h>
11c077711fSSuzuki K Poulose #include <asm/rsi_cmds.h>
12c077711fSSuzuki K Poulose 
13c077711fSSuzuki K Poulose DECLARE_STATIC_KEY_FALSE(rsi_present);
14c077711fSSuzuki K Poulose 
15c077711fSSuzuki K Poulose void __init arm64_rsi_init(void);
16c077711fSSuzuki K Poulose 
17*37158943SSuzuki K Poulose bool __arm64_is_protected_mmio(phys_addr_t base, size_t size);
18*37158943SSuzuki K Poulose 
19c077711fSSuzuki K Poulose static inline bool is_realm_world(void)
20c077711fSSuzuki K Poulose {
21c077711fSSuzuki K Poulose 	return static_branch_unlikely(&rsi_present);
22c077711fSSuzuki K Poulose }
23c077711fSSuzuki K Poulose 
24c077711fSSuzuki K Poulose static inline int rsi_set_memory_range(phys_addr_t start, phys_addr_t end,
25c077711fSSuzuki K Poulose 				       enum ripas state, unsigned long flags)
26c077711fSSuzuki K Poulose {
27c077711fSSuzuki K Poulose 	unsigned long ret;
28c077711fSSuzuki K Poulose 	phys_addr_t top;
29c077711fSSuzuki K Poulose 
30c077711fSSuzuki K Poulose 	while (start != end) {
31c077711fSSuzuki K Poulose 		ret = rsi_set_addr_range_state(start, end, state, flags, &top);
32c077711fSSuzuki K Poulose 		if (ret || top < start || top > end)
33c077711fSSuzuki K Poulose 			return -EINVAL;
34c077711fSSuzuki K Poulose 		start = top;
35c077711fSSuzuki K Poulose 	}
36c077711fSSuzuki K Poulose 
37c077711fSSuzuki K Poulose 	return 0;
38c077711fSSuzuki K Poulose }
39c077711fSSuzuki K Poulose 
40c077711fSSuzuki K Poulose /*
41c077711fSSuzuki K Poulose  * Convert the specified range to RAM. Do not use this if you rely on the
42c077711fSSuzuki K Poulose  * contents of a page that may already be in RAM state.
43c077711fSSuzuki K Poulose  */
44c077711fSSuzuki K Poulose static inline int rsi_set_memory_range_protected(phys_addr_t start,
45c077711fSSuzuki K Poulose 						 phys_addr_t end)
46c077711fSSuzuki K Poulose {
47c077711fSSuzuki K Poulose 	return rsi_set_memory_range(start, end, RSI_RIPAS_RAM,
48c077711fSSuzuki K Poulose 				    RSI_CHANGE_DESTROYED);
49c077711fSSuzuki K Poulose }
50c077711fSSuzuki K Poulose 
51c077711fSSuzuki K Poulose /*
52c077711fSSuzuki K Poulose  * Convert the specified range to RAM. Do not convert any pages that may have
53c077711fSSuzuki K Poulose  * been DESTROYED, without our permission.
54c077711fSSuzuki K Poulose  */
55c077711fSSuzuki K Poulose static inline int rsi_set_memory_range_protected_safe(phys_addr_t start,
56c077711fSSuzuki K Poulose 						      phys_addr_t end)
57c077711fSSuzuki K Poulose {
58c077711fSSuzuki K Poulose 	return rsi_set_memory_range(start, end, RSI_RIPAS_RAM,
59c077711fSSuzuki K Poulose 				    RSI_NO_CHANGE_DESTROYED);
60c077711fSSuzuki K Poulose }
61c077711fSSuzuki K Poulose 
62c077711fSSuzuki K Poulose static inline int rsi_set_memory_range_shared(phys_addr_t start,
63c077711fSSuzuki K Poulose 					      phys_addr_t end)
64c077711fSSuzuki K Poulose {
65c077711fSSuzuki K Poulose 	return rsi_set_memory_range(start, end, RSI_RIPAS_EMPTY,
66c077711fSSuzuki K Poulose 				    RSI_CHANGE_DESTROYED);
67c077711fSSuzuki K Poulose }
68c077711fSSuzuki K Poulose #endif /* __ASM_RSI_H_ */
69