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