Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / arch / loongarch / include / asm / page.h
blob7368f12b7cb1ec24890a1d86060aa3bca76e95d2
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
8 #include <linux/const.h>
9 #include <asm/addrspace.h>
11 #include <vdso/page.h>
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)
18 #ifndef __ASSEMBLY__
20 #include <linux/kernel.h>
21 #include <linux/pfn.h>
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.
28 #define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET)
30 extern void clear_page(void *page);
31 extern void copy_page(void *to, void *from);
33 #define clear_user_page(page, vaddr, pg) clear_page(page)
34 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
36 extern unsigned long shm_align_mask;
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);
43 #define __HAVE_ARCH_COPY_USER_HIGHPAGE
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;
50 typedef struct { unsigned long pgd; } pgd_t;
51 #define pgd_val(x) ((x).pgd)
52 #define __pgd(x) ((pgd_t) { (x) })
55 * Manipulate page protection bits
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)
62 #define ptep_buddy(x) ((pte_t *)((unsigned long)(x) ^ sizeof(pte_t)))
65 * __pa()/__va() should be used only during mem init.
67 #define __pa(x) PHYSADDR(x)
68 #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
70 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
71 #define sym_to_pfn(x) __phys_to_pfn(__pa_symbol(x))
73 struct page *dmw_virt_to_page(unsigned long kaddr);
74 struct page *tlb_virt_to_page(unsigned long kaddr);
76 #define pfn_to_phys(pfn) __pfn_to_phys(pfn)
77 #define phys_to_pfn(paddr) __phys_to_pfn(paddr)
79 #ifndef CONFIG_KFENCE
81 #define page_to_virt(page) __va(page_to_phys(page))
82 #define virt_to_page(kaddr) phys_to_page(__pa(kaddr))
84 #else
86 #define WANT_PAGE_VIRTUAL
88 #define page_to_virt(page) \
89 ({ \
90 extern char *__kfence_pool; \
91 (__kfence_pool == NULL) ? __va(page_to_phys(page)) : page_address(page); \
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);\
100 #endif
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))
105 extern int __virt_addr_valid(volatile void *kaddr);
106 #define virt_addr_valid(kaddr) __virt_addr_valid((volatile void *)(kaddr))
108 #define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC
110 #include <asm-generic/memory_model.h>
111 #include <asm-generic/getorder.h>
113 #endif /* !__ASSEMBLY__ */
115 #endif /* _ASM_PAGE_H */