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