162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2019 SiFive
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef _ASM_RISCV_SET_MEMORY_H
762306a36Sopenharmony_ci#define _ASM_RISCV_SET_MEMORY_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef __ASSEMBLY__
1062306a36Sopenharmony_ci/*
1162306a36Sopenharmony_ci * Functions to change memory attributes.
1262306a36Sopenharmony_ci */
1362306a36Sopenharmony_ci#ifdef CONFIG_MMU
1462306a36Sopenharmony_ciint set_memory_ro(unsigned long addr, int numpages);
1562306a36Sopenharmony_ciint set_memory_rw(unsigned long addr, int numpages);
1662306a36Sopenharmony_ciint set_memory_x(unsigned long addr, int numpages);
1762306a36Sopenharmony_ciint set_memory_nx(unsigned long addr, int numpages);
1862306a36Sopenharmony_ciint set_memory_rw_nx(unsigned long addr, int numpages);
1962306a36Sopenharmony_cistatic __always_inline int set_kernel_memory(char *startp, char *endp,
2062306a36Sopenharmony_ci					     int (*set_memory)(unsigned long start,
2162306a36Sopenharmony_ci							       int num_pages))
2262306a36Sopenharmony_ci{
2362306a36Sopenharmony_ci	unsigned long start = (unsigned long)startp;
2462306a36Sopenharmony_ci	unsigned long end = (unsigned long)endp;
2562306a36Sopenharmony_ci	int num_pages = PAGE_ALIGN(end - start) >> PAGE_SHIFT;
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci	return set_memory(start, num_pages);
2862306a36Sopenharmony_ci}
2962306a36Sopenharmony_ci#else
3062306a36Sopenharmony_cistatic inline int set_memory_ro(unsigned long addr, int numpages) { return 0; }
3162306a36Sopenharmony_cistatic inline int set_memory_rw(unsigned long addr, int numpages) { return 0; }
3262306a36Sopenharmony_cistatic inline int set_memory_x(unsigned long addr, int numpages) { return 0; }
3362306a36Sopenharmony_cistatic inline int set_memory_nx(unsigned long addr, int numpages) { return 0; }
3462306a36Sopenharmony_cistatic inline int set_memory_rw_nx(unsigned long addr, int numpages) { return 0; }
3562306a36Sopenharmony_cistatic inline int set_kernel_memory(char *startp, char *endp,
3662306a36Sopenharmony_ci				    int (*set_memory)(unsigned long start,
3762306a36Sopenharmony_ci						      int num_pages))
3862306a36Sopenharmony_ci{
3962306a36Sopenharmony_ci	return 0;
4062306a36Sopenharmony_ci}
4162306a36Sopenharmony_ci#endif
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ciint set_direct_map_invalid_noflush(struct page *page);
4462306a36Sopenharmony_ciint set_direct_map_default_noflush(struct page *page);
4562306a36Sopenharmony_cibool kernel_page_present(struct page *page);
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#ifdef CONFIG_STRICT_KERNEL_RWX
5062306a36Sopenharmony_ci#ifdef CONFIG_64BIT
5162306a36Sopenharmony_ci#define SECTION_ALIGN (1 << 21)
5262306a36Sopenharmony_ci#else
5362306a36Sopenharmony_ci#define SECTION_ALIGN (1 << 22)
5462306a36Sopenharmony_ci#endif
5562306a36Sopenharmony_ci#else /* !CONFIG_STRICT_KERNEL_RWX */
5662306a36Sopenharmony_ci#define SECTION_ALIGN L1_CACHE_BYTES
5762306a36Sopenharmony_ci#endif /* CONFIG_STRICT_KERNEL_RWX */
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define PECOFF_SECTION_ALIGNMENT        0x1000
6062306a36Sopenharmony_ci#define PECOFF_FILE_ALIGNMENT           0x200
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#endif /* _ASM_RISCV_SET_MEMORY_H */
63