WIP FPC-III support
[linux/fpc-iii.git] / arch / arm / mm / pageattr.c
blob9790ae3a8c6879ffb1132b9d83431c46e2f89007
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
4 */
5 #include <linux/mm.h>
6 #include <linux/module.h>
8 #include <asm/tlbflush.h>
9 #include <asm/set_memory.h>
11 struct page_change_data {
12 pgprot_t set_mask;
13 pgprot_t clear_mask;
16 static int change_page_range(pte_t *ptep, unsigned long addr, void *data)
18 struct page_change_data *cdata = data;
19 pte_t pte = *ptep;
21 pte = clear_pte_bit(pte, cdata->clear_mask);
22 pte = set_pte_bit(pte, cdata->set_mask);
24 set_pte_ext(ptep, pte, 0);
25 return 0;
28 static bool in_range(unsigned long start, unsigned long size,
29 unsigned long range_start, unsigned long range_end)
31 return start >= range_start && start < range_end &&
32 size <= range_end - start;
35 static int change_memory_common(unsigned long addr, int numpages,
36 pgprot_t set_mask, pgprot_t clear_mask)
38 unsigned long start = addr & PAGE_MASK;
39 unsigned long end = PAGE_ALIGN(addr) + numpages * PAGE_SIZE;
40 unsigned long size = end - start;
41 int ret;
42 struct page_change_data data;
44 WARN_ON_ONCE(start != addr);
46 if (!size)
47 return 0;
49 if (!in_range(start, size, MODULES_VADDR, MODULES_END) &&
50 !in_range(start, size, VMALLOC_START, VMALLOC_END))
51 return -EINVAL;
53 data.set_mask = set_mask;
54 data.clear_mask = clear_mask;
56 ret = apply_to_page_range(&init_mm, start, size, change_page_range,
57 &data);
59 flush_tlb_kernel_range(start, end);
60 return ret;
63 int set_memory_ro(unsigned long addr, int numpages)
65 return change_memory_common(addr, numpages,
66 __pgprot(L_PTE_RDONLY),
67 __pgprot(0));
70 int set_memory_rw(unsigned long addr, int numpages)
72 return change_memory_common(addr, numpages,
73 __pgprot(0),
74 __pgprot(L_PTE_RDONLY));
77 int set_memory_nx(unsigned long addr, int numpages)
79 return change_memory_common(addr, numpages,
80 __pgprot(L_PTE_XN),
81 __pgprot(0));
84 int set_memory_x(unsigned long addr, int numpages)
86 return change_memory_common(addr, numpages,
87 __pgprot(0),
88 __pgprot(L_PTE_XN));