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