1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2019 SiFive
6 #ifndef _ASM_RISCV_SET_MEMORY_H
7 #define _ASM_RISCV_SET_MEMORY_H
11 * Functions to change memory attributes.
14 int set_memory_ro(unsigned long addr, int numpages);
15 int set_memory_rw(unsigned long addr, int numpages);
16 int set_memory_x(unsigned long addr, int numpages);
17 int set_memory_nx(unsigned long addr, int numpages);
18 int set_memory_rw_nx(unsigned long addr, int numpages);
19 void protect_kernel_text_data(void);
21 static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; }
22 static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; }
23 static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }
24 static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; }
25 static inline void protect_kernel_text_data(void) {}
26 static inline int set_memory_rw_nx(unsigned long addr, int numpages) { return 0; }
29 #if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)
30 void protect_kernel_linear_mapping_text_rodata(void);
32 static inline void protect_kernel_linear_mapping_text_rodata(void) {}
35 int set_direct_map_invalid_noflush(struct page *page);
36 int set_direct_map_default_noflush(struct page *page);
37 bool kernel_page_present(struct page *page);
39 #endif /* __ASSEMBLY__ */
41 #ifdef CONFIG_STRICT_KERNEL_RWX
43 #define SECTION_ALIGN (1 << 21)
45 #define SECTION_ALIGN (1 << 22)
47 #else /* !CONFIG_STRICT_KERNEL_RWX */
48 #define SECTION_ALIGN L1_CACHE_BYTES
49 #endif /* CONFIG_STRICT_KERNEL_RWX */
51 #endif /* _ASM_RISCV_SET_MEMORY_H */