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