xref: /linux/arch/um/include/asm/page.h (revision fcc79e1714e8c2b8e216dc3149812edd37884eef)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
4  * Copyright 2003 PathScale, Inc.
5  */
6 
7 #ifndef __UM_PAGE_H
8 #define __UM_PAGE_H
9 
10 #include <linux/const.h>
11 
12 #include <vdso/page.h>
13 
14 #ifndef __ASSEMBLY__
15 
16 struct page;
17 
18 #include <linux/pfn.h>
19 #include <linux/types.h>
20 #include <asm/vm-flags.h>
21 
22 /*
23  * These are used to make use of C type-checking..
24  */
25 
26 #define clear_page(page)	memset((void *)(page), 0, PAGE_SIZE)
27 #define copy_page(to,from)	memcpy((void *)(to), (void *)(from), PAGE_SIZE)
28 
29 #define clear_user_page(page, vaddr, pg)	clear_page(page)
30 #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
31 
32 #if defined(CONFIG_3_LEVEL_PGTABLES) && !defined(CONFIG_64BIT)
33 
34 typedef struct { unsigned long pte; } pte_t;
35 typedef struct { unsigned long pmd; } pmd_t;
36 typedef struct { unsigned long pgd; } pgd_t;
37 #define pte_val(p) ((p).pte)
38 
39 #define pte_get_bits(p, bits) ((p).pte & (bits))
40 #define pte_set_bits(p, bits) ((p).pte |= (bits))
41 #define pte_clear_bits(p, bits) ((p).pte &= ~(bits))
42 #define pte_copy(to, from) ({ (to).pte = (from).pte; })
43 #define pte_is_zero(p) (!((p).pte & ~_PAGE_NEWPAGE))
44 #define pte_set_val(p, phys, prot) \
45 	({ (p).pte = (phys) | pgprot_val(prot); })
46 
47 #define pmd_val(x)	((x).pmd)
48 #define __pmd(x) ((pmd_t) { (x) } )
49 
50 typedef unsigned long long phys_t;
51 
52 #else
53 
54 typedef struct { unsigned long pte; } pte_t;
55 typedef struct { unsigned long pgd; } pgd_t;
56 
57 #ifdef CONFIG_3_LEVEL_PGTABLES
58 typedef struct { unsigned long pmd; } pmd_t;
59 #define pmd_val(x)	((x).pmd)
60 #define __pmd(x) ((pmd_t) { (x) } )
61 #endif
62 
63 #define pte_val(x)	((x).pte)
64 
65 
66 #define pte_get_bits(p, bits) ((p).pte & (bits))
67 #define pte_set_bits(p, bits) ((p).pte |= (bits))
68 #define pte_clear_bits(p, bits) ((p).pte &= ~(bits))
69 #define pte_copy(to, from) ((to).pte = (from).pte)
70 #define pte_is_zero(p) (!((p).pte & ~_PAGE_NEWPAGE))
71 #define pte_set_val(p, phys, prot) (p).pte = (phys | pgprot_val(prot))
72 
73 typedef unsigned long phys_t;
74 
75 #endif
76 
77 typedef struct { unsigned long pgprot; } pgprot_t;
78 
79 typedef struct page *pgtable_t;
80 
81 #define pgd_val(x)	((x).pgd)
82 #define pgprot_val(x)	((x).pgprot)
83 
84 #define __pte(x) ((pte_t) { (x) } )
85 #define __pgd(x) ((pgd_t) { (x) } )
86 #define __pgprot(x)	((pgprot_t) { (x) } )
87 
88 extern unsigned long uml_physmem;
89 
90 #define PAGE_OFFSET (uml_physmem)
91 #define KERNELBASE PAGE_OFFSET
92 
93 #define __va_space (8*1024*1024)
94 
95 #include <mem.h>
96 
97 /* Cast to unsigned long before casting to void * to avoid a warning from
98  * mmap_kmem about cutting a long long down to a void *.  Not sure that
99  * casting is the right thing, but 32-bit UML can't have 64-bit virtual
100  * addresses
101  */
102 #define __pa(virt) uml_to_phys((void *) (unsigned long) (virt))
103 #define __va(phys) uml_to_virt((unsigned long) (phys))
104 
105 #define phys_to_pfn(p) ((p) >> PAGE_SHIFT)
106 #define pfn_to_phys(pfn) PFN_PHYS(pfn)
107 
108 #define virt_addr_valid(v) pfn_valid(phys_to_pfn(__pa(v)))
109 
110 #include <asm-generic/memory_model.h>
111 #include <asm-generic/getorder.h>
112 
113 #endif	/* __ASSEMBLY__ */
114 
115 #ifdef CONFIG_X86_32
116 #define __HAVE_ARCH_GATE_AREA 1
117 #endif
118 
119 #endif	/* __UM_PAGE_H */
120