xref: /linux/arch/parisc/include/asm/page.h (revision 4b660dbd9ee2059850fd30e0df420ca7a38a1856)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PARISC_PAGE_H
3 #define _PARISC_PAGE_H
4 
5 #include <linux/const.h>
6 
7 #define PAGE_SHIFT	CONFIG_PAGE_SHIFT
8 #define PAGE_SIZE	(_AC(1,UL) << PAGE_SHIFT)
9 #define PAGE_MASK	(~(PAGE_SIZE-1))
10 
11 
12 #ifndef __ASSEMBLY__
13 
14 #include <asm/types.h>
15 #include <asm/cache.h>
16 
17 #define clear_page(page)	clear_page_asm((void *)(page))
18 #define copy_page(to, from)	copy_page_asm((void *)(to), (void *)(from))
19 
20 struct page;
21 struct vm_area_struct;
22 
23 void clear_page_asm(void *page);
24 void copy_page_asm(void *to, void *from);
25 #define clear_user_page(vto, vaddr, page) clear_page_asm(vto)
26 void copy_user_highpage(struct page *to, struct page *from, unsigned long vaddr,
27 		struct vm_area_struct *vma);
28 #define __HAVE_ARCH_COPY_USER_HIGHPAGE
29 
30 /*
31  * These are used to make use of C type-checking..
32  */
33 #define STRICT_MM_TYPECHECKS
34 #ifdef STRICT_MM_TYPECHECKS
35 typedef struct { unsigned long pte; } pte_t; /* either 32 or 64bit */
36 
37 /* NOTE: even on 64 bits, these entries are __u32 because we allocate
38  * the pmd and pgd in ZONE_DMA (i.e. under 4GB) */
39 typedef struct { __u32 pgd; } pgd_t;
40 typedef struct { unsigned long pgprot; } pgprot_t;
41 
42 #if CONFIG_PGTABLE_LEVELS == 3
43 typedef struct { __u32 pmd; } pmd_t;
44 #define __pmd(x)	((pmd_t) { (x) } )
45 /* pXd_val() do not work as lvalues, so make sure we don't use them as such. */
46 #define pmd_val(x)	((x).pmd + 0)
47 #endif
48 
49 #define pte_val(x)	((x).pte)
50 #define pgd_val(x)	((x).pgd + 0)
51 #define pgprot_val(x)	((x).pgprot)
52 
53 #define __pte(x)	((pte_t) { (x) } )
54 #define __pgd(x)	((pgd_t) { (x) } )
55 #define __pgprot(x)	((pgprot_t) { (x) } )
56 
57 #else
58 /*
59  * .. while these make it easier on the compiler
60  */
61 typedef unsigned long pte_t;
62 
63 #if CONFIG_PGTABLE_LEVELS == 3
64 typedef         __u32 pmd_t;
65 #define pmd_val(x)      (x)
66 #define __pmd(x)	(x)
67 #endif
68 
69 typedef         __u32 pgd_t;
70 typedef unsigned long pgprot_t;
71 
72 #define pte_val(x)      (x)
73 #define pgd_val(x)      (x)
74 #define pgprot_val(x)   (x)
75 
76 #define __pte(x)        (x)
77 #define __pgd(x)        (x)
78 #define __pgprot(x)     (x)
79 
80 #endif /* STRICT_MM_TYPECHECKS */
81 
82 #define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval))
83 #if CONFIG_PGTABLE_LEVELS == 3
84 #define set_pud(pudptr, pudval) (*(pudptr) = (pudval))
85 #endif
86 
87 typedef struct page *pgtable_t;
88 
89 typedef struct __physmem_range {
90 	unsigned long start_pfn;
91 	unsigned long pages;       /* PAGE_SIZE pages */
92 } physmem_range_t;
93 
94 extern physmem_range_t pmem_ranges[];
95 extern int npmem_ranges;
96 
97 #endif /* !__ASSEMBLY__ */
98 
99 /* WARNING: The definitions below must match exactly to sizeof(pte_t)
100  * etc
101  */
102 #ifdef CONFIG_64BIT
103 #define BITS_PER_PTE_ENTRY	3
104 #define BITS_PER_PMD_ENTRY	2
105 #define BITS_PER_PGD_ENTRY	2
106 #else
107 #define BITS_PER_PTE_ENTRY	2
108 #define BITS_PER_PMD_ENTRY	2
109 #define BITS_PER_PGD_ENTRY	2
110 #endif
111 #define PGD_ENTRY_SIZE	(1UL << BITS_PER_PGD_ENTRY)
112 #define PMD_ENTRY_SIZE	(1UL << BITS_PER_PMD_ENTRY)
113 #define PTE_ENTRY_SIZE	(1UL << BITS_PER_PTE_ENTRY)
114 
115 #define LINUX_GATEWAY_SPACE     0
116 
117 /* This governs the relationship between virtual and physical addresses.
118  * If you alter it, make sure to take care of our various fixed mapping
119  * segments in fixmap.h */
120 #ifdef CONFIG_64BIT
121 #define __PAGE_OFFSET_DEFAULT	(0x40000000)	/* 1GB */
122 #else
123 #define __PAGE_OFFSET_DEFAULT	(0x10000000)	/* 256MB */
124 #endif
125 
126 #if defined(BOOTLOADER)
127 #define __PAGE_OFFSET	(0)	/* bootloader uses physical addresses */
128 #else
129 #define __PAGE_OFFSET	__PAGE_OFFSET_DEFAULT
130 #endif /* BOOTLOADER */
131 
132 #define PAGE_OFFSET		((unsigned long)__PAGE_OFFSET)
133 
134 /* The size of the gateway page (we leave lots of room for expansion) */
135 #define GATEWAY_PAGE_SIZE	0x4000
136 
137 /* The start of the actual kernel binary---used in vmlinux.lds.S
138  * Leave some space after __PAGE_OFFSET for detecting kernel null
139  * ptr derefs */
140 #define KERNEL_BINARY_TEXT_START	(__PAGE_OFFSET + 0x100000)
141 
142 /* These macros don't work for 64-bit C code -- don't allow in C at all */
143 #ifdef __ASSEMBLY__
144 #   define PA(x)	((x)-__PAGE_OFFSET)
145 #   define VA(x)	((x)+__PAGE_OFFSET)
146 #endif
147 #define __pa(x)			((unsigned long)(x)-PAGE_OFFSET)
148 #define __va(x)			((void *)((unsigned long)(x)+PAGE_OFFSET))
149 
150 #ifdef CONFIG_HUGETLB_PAGE
151 #define HPAGE_SHIFT		PMD_SHIFT /* fixed for transparent huge pages */
152 #define HPAGE_SIZE      	((1UL) << HPAGE_SHIFT)
153 #define HPAGE_MASK		(~(HPAGE_SIZE - 1))
154 #define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
155 
156 #if defined(CONFIG_64BIT) && defined(CONFIG_PARISC_PAGE_SIZE_4KB)
157 # define REAL_HPAGE_SHIFT	20 /* 20 = 1MB */
158 # define _HUGE_PAGE_SIZE_ENCODING_DEFAULT _PAGE_SIZE_ENCODING_1M
159 #elif !defined(CONFIG_64BIT) && defined(CONFIG_PARISC_PAGE_SIZE_4KB)
160 # define REAL_HPAGE_SHIFT	22 /* 22 = 4MB */
161 # define _HUGE_PAGE_SIZE_ENCODING_DEFAULT _PAGE_SIZE_ENCODING_4M
162 #else
163 # define REAL_HPAGE_SHIFT	24 /* 24 = 16MB */
164 # define _HUGE_PAGE_SIZE_ENCODING_DEFAULT _PAGE_SIZE_ENCODING_16M
165 #endif
166 #endif /* CONFIG_HUGETLB_PAGE */
167 
168 #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
169 
170 #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
171 #define virt_to_page(kaddr)     pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
172 
173 #include <asm-generic/memory_model.h>
174 #include <asm-generic/getorder.h>
175 #include <asm/pdc.h>
176 
177 #define PAGE0   ((struct zeropage *)absolute_pointer(__PAGE_OFFSET))
178 
179 /* DEFINITION OF THE ZERO-PAGE (PAG0) */
180 /* based on work by Jason Eckhardt (jason@equator.com) */
181 
182 #endif /* _PARISC_PAGE_H */
183