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