xref: /linux/arch/x86/include/asm/page.h (revision 6aacab308a5dfd222b2d23662bbae60c11007cfb)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_PAGE_H
3 #define _ASM_X86_PAGE_H
4 
5 #include <linux/types.h>
6 
7 #ifdef __KERNEL__
8 
9 #include <asm/page_types.h>
10 
11 #ifdef CONFIG_X86_64
12 #include <asm/page_64.h>
13 #else
14 #include <asm/page_32.h>
15 #endif	/* CONFIG_X86_64 */
16 
17 #ifndef __ASSEMBLER__
18 
19 struct page;
20 
21 #include <linux/range.h>
22 extern struct range pfn_mapped[];
23 extern int nr_pfn_mapped;
24 
25 static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
26 				  struct page *topage)
27 {
28 	copy_page(to, from);
29 }
30 
31 #define vma_alloc_zeroed_movable_folio(vma, vaddr) \
32 	vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr)
33 
34 #ifndef __pa
35 #define __pa(x)		__phys_addr((unsigned long)(x))
36 #endif
37 
38 #define __pa_nodebug(x)	__phys_addr_nodebug((unsigned long)(x))
39 /* __pa_symbol should be used for C visible symbols.
40    This seems to be the official gcc blessed way to do such arithmetic. */
41 /*
42  * We need __phys_reloc_hide() here because gcc may assume that there is no
43  * overflow during __pa() calculation and can optimize it unexpectedly.
44  * Newer versions of gcc provide -fno-strict-overflow switch to handle this
45  * case properly. Once all supported versions of gcc understand it, we can
46  * remove this Voodoo magic stuff. (i.e. once gcc3.x is deprecated)
47  */
48 #define __pa_symbol(x) \
49 	__phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
50 
51 #ifndef __va
52 #define __va(x)			((void *)((unsigned long)(x)+PAGE_OFFSET))
53 #endif
54 
55 #define __boot_va(x)		__va(x)
56 #define __boot_pa(x)		__pa(x)
57 
58 /*
59  * virt_to_page(kaddr) returns a valid pointer if and only if
60  * virt_addr_valid(kaddr) returns true.
61  */
62 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
63 extern bool __virt_addr_valid(unsigned long kaddr);
64 #define virt_addr_valid(kaddr)	__virt_addr_valid((unsigned long) (kaddr))
65 
66 static __always_inline void *pfn_to_kaddr(unsigned long pfn)
67 {
68 	return __va(pfn << PAGE_SHIFT);
69 }
70 
71 static __always_inline u64 __canonical_address(u64 vaddr, u8 vaddr_bits)
72 {
73 	return ((s64)vaddr << (64 - vaddr_bits)) >> (64 - vaddr_bits);
74 }
75 
76 static __always_inline u64 __is_canonical_address(u64 vaddr, u8 vaddr_bits)
77 {
78 	return __canonical_address(vaddr, vaddr_bits) == vaddr;
79 }
80 
81 #endif	/* __ASSEMBLER__ */
82 
83 #include <asm-generic/memory_model.h>
84 #include <asm-generic/getorder.h>
85 
86 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
87 
88 #endif	/* __KERNEL__ */
89 #endif /* _ASM_X86_PAGE_H */
90