xref: /linux/arch/sh/include/asm/page.h (revision 6a4aee277740d04ac0fd54cfa17cc28261932ddc)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_PAGE_H
3 #define __ASM_SH_PAGE_H
4 
5 /*
6  * Copyright (C) 1999  Niibe Yutaka
7  */
8 
9 #include <linux/const.h>
10 
11 /* PAGE_SHIFT determines the page size */
12 #define PAGE_SHIFT	CONFIG_PAGE_SHIFT
13 #define PAGE_SIZE	(_AC(1, UL) << PAGE_SHIFT)
14 #define PAGE_MASK	(~(PAGE_SIZE-1))
15 #define PTE_MASK	PAGE_MASK
16 
17 #if defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
18 #define HPAGE_SHIFT	16
19 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K)
20 #define HPAGE_SHIFT	18
21 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB)
22 #define HPAGE_SHIFT	20
23 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
24 #define HPAGE_SHIFT	22
25 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_64MB)
26 #define HPAGE_SHIFT	26
27 #endif
28 
29 #ifdef CONFIG_HUGETLB_PAGE
30 #define HPAGE_SIZE		(1UL << HPAGE_SHIFT)
31 #define HPAGE_MASK		(~(HPAGE_SIZE-1))
32 #define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT-PAGE_SHIFT)
33 #endif
34 
35 #ifndef __ASSEMBLY__
36 #include <asm/uncached.h>
37 
38 extern unsigned long shm_align_mask;
39 extern unsigned long max_low_pfn, min_low_pfn;
40 extern unsigned long memory_start, memory_end, memory_limit;
41 
42 static inline unsigned long
43 pages_do_alias(unsigned long addr1, unsigned long addr2)
44 {
45 	return (addr1 ^ addr2) & shm_align_mask;
46 }
47 
48 #define clear_page(page)	memset((void *)(page), 0, PAGE_SIZE)
49 extern void copy_page(void *to, void *from);
50 #define copy_user_page(to, from, vaddr, pg)  __copy_user(to, from, PAGE_SIZE)
51 
52 struct page;
53 struct vm_area_struct;
54 
55 extern void copy_user_highpage(struct page *to, struct page *from,
56 			       unsigned long vaddr, struct vm_area_struct *vma);
57 #define __HAVE_ARCH_COPY_USER_HIGHPAGE
58 extern void clear_user_highpage(struct page *page, unsigned long vaddr);
59 #define clear_user_highpage	clear_user_highpage
60 
61 /*
62  * These are used to make use of C type-checking..
63  */
64 #ifdef CONFIG_X2TLB
65 typedef struct { unsigned long pte_low, pte_high; } pte_t;
66 typedef struct { unsigned long long pgprot; } pgprot_t;
67 typedef struct { unsigned long long pgd; } pgd_t;
68 #define pte_val(x) \
69 	((x).pte_low | ((unsigned long long)(x).pte_high << 32))
70 #define __pte(x) \
71 	({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
72 #else
73 typedef struct { unsigned long pte_low; } pte_t;
74 typedef struct { unsigned long pgprot; } pgprot_t;
75 typedef struct { unsigned long pgd; } pgd_t;
76 #define pte_val(x)	((x).pte_low)
77 #define __pte(x)	((pte_t) { (x) } )
78 #endif
79 
80 #define pgd_val(x)	((x).pgd)
81 #define pgprot_val(x)	((x).pgprot)
82 
83 #define __pgd(x) ((pgd_t) { (x) } )
84 #define __pgprot(x)	((pgprot_t) { (x) } )
85 
86 typedef struct page *pgtable_t;
87 
88 #define pte_pgprot(x) __pgprot(pte_val(x) & PTE_FLAGS_MASK)
89 
90 #endif /* !__ASSEMBLY__ */
91 
92 /*
93  * __MEMORY_START and SIZE are the physical addresses and size of RAM.
94  */
95 #define __MEMORY_START		CONFIG_MEMORY_START
96 #define __MEMORY_SIZE		CONFIG_MEMORY_SIZE
97 
98 /*
99  * PHYSICAL_OFFSET is the offset in physical memory where the base
100  * of the kernel is loaded.
101  */
102 #ifdef CONFIG_PHYSICAL_START
103 #define PHYSICAL_OFFSET (CONFIG_PHYSICAL_START - __MEMORY_START)
104 #else
105 #define PHYSICAL_OFFSET 0
106 #endif
107 
108 /*
109  * PAGE_OFFSET is the virtual address of the start of kernel address
110  * space.
111  */
112 #define PAGE_OFFSET		CONFIG_PAGE_OFFSET
113 
114 /*
115  * Virtual to physical RAM address translation.
116  *
117  * In 29 bit mode, the physical offset of RAM from address 0 is visible in
118  * the kernel virtual address space, and thus we don't have to take
119  * this into account when translating. However in 32 bit mode this offset
120  * is not visible (it is part of the PMB mapping) and so needs to be
121  * added or subtracted as required.
122  */
123 #ifdef CONFIG_PMB
124 #define ___pa(x)	((x)-PAGE_OFFSET+__MEMORY_START)
125 #define ___va(x)	((x)+PAGE_OFFSET-__MEMORY_START)
126 #else
127 #define ___pa(x)	((x)-PAGE_OFFSET)
128 #define ___va(x)	((x)+PAGE_OFFSET)
129 #endif
130 
131 #ifndef __ASSEMBLY__
132 #define __pa(x)		___pa((unsigned long)x)
133 #define __va(x)		(void *)___va((unsigned long)x)
134 #endif /* !__ASSEMBLY__ */
135 
136 #ifdef CONFIG_UNCACHED_MAPPING
137 #if defined(CONFIG_29BIT)
138 #define UNCAC_ADDR(addr)	P2SEGADDR(addr)
139 #define CAC_ADDR(addr)		P1SEGADDR(addr)
140 #else
141 #define UNCAC_ADDR(addr)	((addr) - PAGE_OFFSET + uncached_start)
142 #define CAC_ADDR(addr)		((addr) - uncached_start + PAGE_OFFSET)
143 #endif
144 #else
145 #define UNCAC_ADDR(addr)	((addr))
146 #define CAC_ADDR(addr)		((addr))
147 #endif
148 
149 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
150 #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
151 
152 /*
153  * PFN = physical frame number (ie PFN 0 == physical address 0)
154  * PFN_START is the PFN of the first page of RAM. By defining this we
155  * don't have struct page entries for the portion of address space
156  * between physical address 0 and the start of RAM.
157  */
158 #define PFN_START		(__MEMORY_START >> PAGE_SHIFT)
159 #define ARCH_PFN_OFFSET		(PFN_START)
160 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
161 #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
162 
163 #include <asm-generic/memory_model.h>
164 #include <asm-generic/getorder.h>
165 
166 #endif /* __ASM_SH_PAGE_H */
167