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 #include <vdso/page.h> 12 13 #define HPAGE_SHIFT (PAGE_SHIFT + PAGE_SHIFT - 3) 14 #define HPAGE_SIZE (_AC(1, UL) << HPAGE_SHIFT) 15 #define HPAGE_MASK (~(HPAGE_SIZE - 1)) 16 #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) 17 18 #ifndef __ASSEMBLY__ 19 20 #include <linux/kernel.h> 21 #include <linux/pfn.h> 22 23 /* 24 * It's normally defined only for FLATMEM config but it's 25 * used in our early mem init code for all memory models. 26 * So always define it. 27 */ 28 #define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET) 29 30 extern void clear_page(void *page); 31 extern void copy_page(void *to, void *from); 32 33 #define clear_user_page(page, vaddr, pg) clear_page(page) 34 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) 35 36 extern unsigned long shm_align_mask; 37 38 struct page; 39 struct vm_area_struct; 40 void copy_user_highpage(struct page *to, struct page *from, 41 unsigned long vaddr, struct vm_area_struct *vma); 42 43 #define __HAVE_ARCH_COPY_USER_HIGHPAGE 44 45 typedef struct { unsigned long pte; } pte_t; 46 #define pte_val(x) ((x).pte) 47 #define __pte(x) ((pte_t) { (x) }) 48 typedef struct page *pgtable_t; 49 50 typedef struct { unsigned long pgd; } pgd_t; 51 #define pgd_val(x) ((x).pgd) 52 #define __pgd(x) ((pgd_t) { (x) }) 53 54 /* 55 * Manipulate page protection bits 56 */ 57 typedef struct { unsigned long pgprot; } pgprot_t; 58 #define pgprot_val(x) ((x).pgprot) 59 #define __pgprot(x) ((pgprot_t) { (x) }) 60 #define pte_pgprot(x) __pgprot(pte_val(x) & ~_PFN_MASK) 61 62 #define ptep_buddy(x) ((pte_t *)((unsigned long)(x) ^ sizeof(pte_t))) 63 64 /* 65 * __pa()/__va() should be used only during mem init. 66 */ 67 #define __pa(x) PHYSADDR(x) 68 #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET)) 69 70 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) 71 #define sym_to_pfn(x) __phys_to_pfn(__pa_symbol(x)) 72 73 struct page *dmw_virt_to_page(unsigned long kaddr); 74 struct page *tlb_virt_to_page(unsigned long kaddr); 75 76 #define pfn_to_phys(pfn) __pfn_to_phys(pfn) 77 #define phys_to_pfn(paddr) __phys_to_pfn(paddr) 78 79 #ifndef CONFIG_KFENCE 80 81 #define page_to_virt(page) __va(page_to_phys(page)) 82 #define virt_to_page(kaddr) phys_to_page(__pa(kaddr)) 83 84 #else 85 86 #define WANT_PAGE_VIRTUAL 87 88 #define page_to_virt(page) \ 89 ({ \ 90 extern char *__kfence_pool; \ 91 (__kfence_pool == NULL) ? __va(page_to_phys(page)) : page_address(page); \ 92 }) 93 94 #define virt_to_page(kaddr) \ 95 ({ \ 96 (likely((unsigned long)kaddr < vm_map_base)) ? \ 97 dmw_virt_to_page((unsigned long)kaddr) : tlb_virt_to_page((unsigned long)kaddr);\ 98 }) 99 100 #endif 101 102 #define pfn_to_virt(pfn) page_to_virt(pfn_to_page(pfn)) 103 #define virt_to_pfn(kaddr) page_to_pfn(virt_to_page(kaddr)) 104 105 extern int __virt_addr_valid(volatile void *kaddr); 106 #define virt_addr_valid(kaddr) __virt_addr_valid((volatile void *)(kaddr)) 107 108 #define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC 109 110 #include <asm-generic/memory_model.h> 111 #include <asm-generic/getorder.h> 112 113 #endif /* !__ASSEMBLY__ */ 114 115 #endif /* _ASM_PAGE_H */ 116