1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_PAGE_H
3 #define __ASM_SH_PAGE_H
6 * Copyright (C) 1999 Niibe Yutaka
9 #include <linux/const.h>
11 #include <vdso/page.h>
13 #define PTE_MASK PAGE_MASK
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
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)
34 #include <asm/uncached.h>
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
;
40 static inline unsigned long
41 pages_do_alias(unsigned long addr1
, unsigned long addr2
)
43 return (addr1
^ addr2
) & shm_align_mask
;
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)
51 struct vm_area_struct
;
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
60 * These are used to make use of C type-checking..
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
;
67 ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
69 ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
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) } )
78 #define pgd_val(x) ((x).pgd)
79 #define pgprot_val(x) ((x).pgprot)
81 #define __pgd(x) ((pgd_t) { (x) } )
82 #define __pgprot(x) ((pgprot_t) { (x) } )
84 typedef struct page
*pgtable_t
;
86 #define pte_pgprot(x) __pgprot(pte_val(x) & PTE_FLAGS_MASK)
88 #endif /* !__ASSEMBLY__ */
91 * __MEMORY_START and SIZE are the physical addresses and size of RAM.
93 #define __MEMORY_START CONFIG_MEMORY_START
94 #define __MEMORY_SIZE CONFIG_MEMORY_SIZE
97 * PHYSICAL_OFFSET is the offset in physical memory where the base
98 * of the kernel is loaded.
100 #ifdef CONFIG_PHYSICAL_START
101 #define PHYSICAL_OFFSET (CONFIG_PHYSICAL_START - __MEMORY_START)
103 #define PHYSICAL_OFFSET 0
107 * PAGE_OFFSET is the virtual address of the start of kernel address
110 #define PAGE_OFFSET CONFIG_PAGE_OFFSET
113 * Virtual to physical RAM address translation.
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.
122 #define ___pa(x) ((x)-PAGE_OFFSET+__MEMORY_START)
123 #define ___va(x) ((x)+PAGE_OFFSET-__MEMORY_START)
125 #define ___pa(x) ((x)-PAGE_OFFSET)
126 #define ___va(x) ((x)+PAGE_OFFSET)
130 #define __pa(x) ___pa((unsigned long)x)
131 #define __va(x) (void *)___va((unsigned long)x)
132 #endif /* !__ASSEMBLY__ */
134 #ifdef CONFIG_UNCACHED_MAPPING
135 #if defined(CONFIG_29BIT)
136 #define UNCAC_ADDR(addr) P2SEGADDR(addr)
137 #define CAC_ADDR(addr) P1SEGADDR(addr)
139 #define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + uncached_start)
140 #define CAC_ADDR(addr) ((addr) - uncached_start + PAGE_OFFSET)
143 #define UNCAC_ADDR(addr) ((addr))
144 #define CAC_ADDR(addr) ((addr))
147 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
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.
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)
160 #include <asm-generic/memory_model.h>
161 #include <asm-generic/getorder.h>
163 #endif /* __ASM_SH_PAGE_H */