xref: /openbmc/linux/arch/loongarch/include/asm/page.h (revision 2f164822)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #ifndef _ASM_PAGE_H
6 #define _ASM_PAGE_H
7 
8 #include <linux/const.h>
9 #include <asm/addrspace.h>
10 
11 /*
12  * PAGE_SHIFT determines the page size
13  */
14 #ifdef CONFIG_PAGE_SIZE_4KB
15 #define PAGE_SHIFT	12
16 #endif
17 #ifdef CONFIG_PAGE_SIZE_16KB
18 #define PAGE_SHIFT	14
19 #endif
20 #ifdef CONFIG_PAGE_SIZE_64KB
21 #define PAGE_SHIFT	16
22 #endif
23 #define PAGE_SIZE	(_AC(1, UL) << PAGE_SHIFT)
24 #define PAGE_MASK	(~(PAGE_SIZE - 1))
25 
26 #define HPAGE_SHIFT	(PAGE_SHIFT + PAGE_SHIFT - 3)
27 #define HPAGE_SIZE	(_AC(1, UL) << HPAGE_SHIFT)
28 #define HPAGE_MASK	(~(HPAGE_SIZE - 1))
29 #define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
30 
31 #ifndef __ASSEMBLY__
32 
33 #include <linux/kernel.h>
34 #include <linux/pfn.h>
35 
36 /*
37  * It's normally defined only for FLATMEM config but it's
38  * used in our early mem init code for all memory models.
39  * So always define it.
40  */
41 #define ARCH_PFN_OFFSET	PFN_UP(PHYS_OFFSET)
42 
43 extern void clear_page(void *page);
44 extern void copy_page(void *to, void *from);
45 
46 #define clear_user_page(page, vaddr, pg)	clear_page(page)
47 #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
48 
49 extern unsigned long shm_align_mask;
50 
51 struct page;
52 struct vm_area_struct;
53 void copy_user_highpage(struct page *to, struct page *from,
54 	      unsigned long vaddr, struct vm_area_struct *vma);
55 
56 #define __HAVE_ARCH_COPY_USER_HIGHPAGE
57 
58 typedef struct { unsigned long pte; } pte_t;
59 #define pte_val(x)	((x).pte)
60 #define __pte(x)	((pte_t) { (x) })
61 typedef struct page *pgtable_t;
62 
63 typedef struct { unsigned long pgd; } pgd_t;
64 #define pgd_val(x)	((x).pgd)
65 #define __pgd(x)	((pgd_t) { (x) })
66 
67 /*
68  * Manipulate page protection bits
69  */
70 typedef struct { unsigned long pgprot; } pgprot_t;
71 #define pgprot_val(x)	((x).pgprot)
72 #define __pgprot(x)	((pgprot_t) { (x) })
73 #define pte_pgprot(x)	__pgprot(pte_val(x) & ~_PFN_MASK)
74 
75 #define ptep_buddy(x)	((pte_t *)((unsigned long)(x) ^ sizeof(pte_t)))
76 
77 /*
78  * __pa()/__va() should be used only during mem init.
79  */
80 #define __pa(x)		PHYSADDR(x)
81 #define __va(x)		((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
82 
83 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
84 
85 #define virt_to_pfn(kaddr)	PFN_DOWN(PHYSADDR(kaddr))
86 #define virt_to_page(kaddr)	pfn_to_page(virt_to_pfn(kaddr))
87 
88 extern int __virt_addr_valid(volatile void *kaddr);
89 #define virt_addr_valid(kaddr)	__virt_addr_valid((volatile void *)(kaddr))
90 
91 #define VM_DATA_DEFAULT_FLAGS \
92 	(VM_READ | VM_WRITE | \
93 	 ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
94 	 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
95 
96 #include <asm-generic/memory_model.h>
97 #include <asm-generic/getorder.h>
98 
99 #endif /* !__ASSEMBLY__ */
100 
101 #endif /* _ASM_PAGE_H */
102