1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2f15cbe6fSPaul Mundt #ifndef __ASM_SH_PAGE_H
3f15cbe6fSPaul Mundt #define __ASM_SH_PAGE_H
4f15cbe6fSPaul Mundt
5f15cbe6fSPaul Mundt /*
6f15cbe6fSPaul Mundt * Copyright (C) 1999 Niibe Yutaka
7f15cbe6fSPaul Mundt */
8f15cbe6fSPaul Mundt
9f15cbe6fSPaul Mundt #include <linux/const.h>
10f15cbe6fSPaul Mundt
11f15cbe6fSPaul Mundt /* PAGE_SHIFT determines the page size */
12f15cbe6fSPaul Mundt #if defined(CONFIG_PAGE_SIZE_4KB)
13f15cbe6fSPaul Mundt # define PAGE_SHIFT 12
14f15cbe6fSPaul Mundt #elif defined(CONFIG_PAGE_SIZE_8KB)
15f15cbe6fSPaul Mundt # define PAGE_SHIFT 13
16f15cbe6fSPaul Mundt #elif defined(CONFIG_PAGE_SIZE_16KB)
17f15cbe6fSPaul Mundt # define PAGE_SHIFT 14
18f15cbe6fSPaul Mundt #elif defined(CONFIG_PAGE_SIZE_64KB)
19f15cbe6fSPaul Mundt # define PAGE_SHIFT 16
20f15cbe6fSPaul Mundt #else
21f15cbe6fSPaul Mundt # error "Bogus kernel page size?"
22f15cbe6fSPaul Mundt #endif
23f15cbe6fSPaul Mundt
24f15cbe6fSPaul Mundt #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
25f15cbe6fSPaul Mundt #define PAGE_MASK (~(PAGE_SIZE-1))
26f15cbe6fSPaul Mundt #define PTE_MASK PAGE_MASK
27f15cbe6fSPaul Mundt
28f15cbe6fSPaul Mundt #if defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
29f15cbe6fSPaul Mundt #define HPAGE_SHIFT 16
30f15cbe6fSPaul Mundt #elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K)
31f15cbe6fSPaul Mundt #define HPAGE_SHIFT 18
32f15cbe6fSPaul Mundt #elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB)
33f15cbe6fSPaul Mundt #define HPAGE_SHIFT 20
34f15cbe6fSPaul Mundt #elif defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
35f15cbe6fSPaul Mundt #define HPAGE_SHIFT 22
36f15cbe6fSPaul Mundt #elif defined(CONFIG_HUGETLB_PAGE_SIZE_64MB)
37f15cbe6fSPaul Mundt #define HPAGE_SHIFT 26
38f15cbe6fSPaul Mundt #endif
39f15cbe6fSPaul Mundt
40f15cbe6fSPaul Mundt #ifdef CONFIG_HUGETLB_PAGE
41f15cbe6fSPaul Mundt #define HPAGE_SIZE (1UL << HPAGE_SHIFT)
42f15cbe6fSPaul Mundt #define HPAGE_MASK (~(HPAGE_SIZE-1))
43f15cbe6fSPaul Mundt #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT-PAGE_SHIFT)
44f15cbe6fSPaul Mundt #endif
45f15cbe6fSPaul Mundt
46f15cbe6fSPaul Mundt #ifndef __ASSEMBLY__
47d01447b3SPaul Mundt #include <asm/uncached.h>
48f15cbe6fSPaul Mundt
49f15cbe6fSPaul Mundt extern unsigned long shm_align_mask;
50f15cbe6fSPaul Mundt extern unsigned long max_low_pfn, min_low_pfn;
515e2ff328SPaul Mundt extern unsigned long memory_start, memory_end, memory_limit;
52f15cbe6fSPaul Mundt
532277ab4aSPaul Mundt static inline unsigned long
pages_do_alias(unsigned long addr1,unsigned long addr2)542277ab4aSPaul Mundt pages_do_alias(unsigned long addr1, unsigned long addr2)
552277ab4aSPaul Mundt {
562277ab4aSPaul Mundt return (addr1 ^ addr2) & shm_align_mask;
572277ab4aSPaul Mundt }
582277ab4aSPaul Mundt
59dfff0fa6SPaul Mundt #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
60f15cbe6fSPaul Mundt extern void copy_page(void *to, void *from);
61934ed25eSRoss Zwisler #define copy_user_page(to, from, vaddr, pg) __copy_user(to, from, PAGE_SIZE)
62f15cbe6fSPaul Mundt
63dfff0fa6SPaul Mundt struct page;
64dfff0fa6SPaul Mundt struct vm_area_struct;
65dfff0fa6SPaul Mundt
66f15cbe6fSPaul Mundt extern void copy_user_highpage(struct page *to, struct page *from,
67f15cbe6fSPaul Mundt unsigned long vaddr, struct vm_area_struct *vma);
68f15cbe6fSPaul Mundt #define __HAVE_ARCH_COPY_USER_HIGHPAGE
69dfff0fa6SPaul Mundt extern void clear_user_highpage(struct page *page, unsigned long vaddr);
70dfff0fa6SPaul Mundt #define clear_user_highpage clear_user_highpage
710dfae7d5SPaul Mundt
72f15cbe6fSPaul Mundt /*
73f15cbe6fSPaul Mundt * These are used to make use of C type-checking..
74f15cbe6fSPaul Mundt */
75f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB
76f15cbe6fSPaul Mundt typedef struct { unsigned long pte_low, pte_high; } pte_t;
77f15cbe6fSPaul Mundt typedef struct { unsigned long long pgprot; } pgprot_t;
78f15cbe6fSPaul Mundt typedef struct { unsigned long long pgd; } pgd_t;
79f15cbe6fSPaul Mundt #define pte_val(x) \
80f15cbe6fSPaul Mundt ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
81f15cbe6fSPaul Mundt #define __pte(x) \
82f15cbe6fSPaul Mundt ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
83*37744feeSArnd Bergmann #else
84f15cbe6fSPaul Mundt typedef struct { unsigned long pte_low; } pte_t;
85f15cbe6fSPaul Mundt typedef struct { unsigned long pgprot; } pgprot_t;
86f15cbe6fSPaul Mundt typedef struct { unsigned long pgd; } pgd_t;
87f15cbe6fSPaul Mundt #define pte_val(x) ((x).pte_low)
88f15cbe6fSPaul Mundt #define __pte(x) ((pte_t) { (x) } )
89f15cbe6fSPaul Mundt #endif
90f15cbe6fSPaul Mundt
91f15cbe6fSPaul Mundt #define pgd_val(x) ((x).pgd)
92f15cbe6fSPaul Mundt #define pgprot_val(x) ((x).pgprot)
93f15cbe6fSPaul Mundt
94f15cbe6fSPaul Mundt #define __pgd(x) ((pgd_t) { (x) } )
95f15cbe6fSPaul Mundt #define __pgprot(x) ((pgprot_t) { (x) } )
96f15cbe6fSPaul Mundt
97f15cbe6fSPaul Mundt typedef struct page *pgtable_t;
98f15cbe6fSPaul Mundt
99cb700aa4SPaul Mundt #define pte_pgprot(x) __pgprot(pte_val(x) & PTE_FLAGS_MASK)
100cb700aa4SPaul Mundt
101f15cbe6fSPaul Mundt #endif /* !__ASSEMBLY__ */
102f15cbe6fSPaul Mundt
103f15cbe6fSPaul Mundt /*
104f15cbe6fSPaul Mundt * __MEMORY_START and SIZE are the physical addresses and size of RAM.
105f15cbe6fSPaul Mundt */
106f15cbe6fSPaul Mundt #define __MEMORY_START CONFIG_MEMORY_START
107f15cbe6fSPaul Mundt #define __MEMORY_SIZE CONFIG_MEMORY_SIZE
108f15cbe6fSPaul Mundt
109f15cbe6fSPaul Mundt /*
110e66ac3f2SSimon Horman * PHYSICAL_OFFSET is the offset in physical memory where the base
111e66ac3f2SSimon Horman * of the kernel is loaded.
112e66ac3f2SSimon Horman */
113e66ac3f2SSimon Horman #ifdef CONFIG_PHYSICAL_START
114e66ac3f2SSimon Horman #define PHYSICAL_OFFSET (CONFIG_PHYSICAL_START - __MEMORY_START)
115e66ac3f2SSimon Horman #else
116e66ac3f2SSimon Horman #define PHYSICAL_OFFSET 0
117e66ac3f2SSimon Horman #endif
118e66ac3f2SSimon Horman
119e66ac3f2SSimon Horman /*
120f15cbe6fSPaul Mundt * PAGE_OFFSET is the virtual address of the start of kernel address
121f15cbe6fSPaul Mundt * space.
122f15cbe6fSPaul Mundt */
123f15cbe6fSPaul Mundt #define PAGE_OFFSET CONFIG_PAGE_OFFSET
124f15cbe6fSPaul Mundt
125f15cbe6fSPaul Mundt /*
126f15cbe6fSPaul Mundt * Virtual to physical RAM address translation.
127f15cbe6fSPaul Mundt *
128f15cbe6fSPaul Mundt * In 29 bit mode, the physical offset of RAM from address 0 is visible in
129f15cbe6fSPaul Mundt * the kernel virtual address space, and thus we don't have to take
130f15cbe6fSPaul Mundt * this into account when translating. However in 32 bit mode this offset
131f15cbe6fSPaul Mundt * is not visible (it is part of the PMB mapping) and so needs to be
132f15cbe6fSPaul Mundt * added or subtracted as required.
133f15cbe6fSPaul Mundt */
1341d5cfcdfSPaul Mundt #ifdef CONFIG_PMB
1357c4584d3SMatt Fleming #define ___pa(x) ((x)-PAGE_OFFSET+__MEMORY_START)
1367c4584d3SMatt Fleming #define ___va(x) ((x)+PAGE_OFFSET-__MEMORY_START)
137f15cbe6fSPaul Mundt #else
1387c4584d3SMatt Fleming #define ___pa(x) ((x)-PAGE_OFFSET)
1397c4584d3SMatt Fleming #define ___va(x) ((x)+PAGE_OFFSET)
140f15cbe6fSPaul Mundt #endif
141f15cbe6fSPaul Mundt
1427c4584d3SMatt Fleming #ifndef __ASSEMBLY__
1437c4584d3SMatt Fleming #define __pa(x) ___pa((unsigned long)x)
1447c4584d3SMatt Fleming #define __va(x) (void *)___va((unsigned long)x)
1457c4584d3SMatt Fleming #endif /* !__ASSEMBLY__ */
1467c4584d3SMatt Fleming
1479edef286SPaul Mundt #ifdef CONFIG_UNCACHED_MAPPING
148dfd3b596SNobuhiro Iwamatsu #if defined(CONFIG_29BIT)
149dfd3b596SNobuhiro Iwamatsu #define UNCAC_ADDR(addr) P2SEGADDR(addr)
150dfd3b596SNobuhiro Iwamatsu #define CAC_ADDR(addr) P1SEGADDR(addr)
151dfd3b596SNobuhiro Iwamatsu #else
1529edef286SPaul Mundt #define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + uncached_start)
1539edef286SPaul Mundt #define CAC_ADDR(addr) ((addr) - uncached_start + PAGE_OFFSET)
154dfd3b596SNobuhiro Iwamatsu #endif
1559edef286SPaul Mundt #else
1569edef286SPaul Mundt #define UNCAC_ADDR(addr) ((addr))
1579edef286SPaul Mundt #define CAC_ADDR(addr) ((addr))
1589edef286SPaul Mundt #endif
1599edef286SPaul Mundt
160f15cbe6fSPaul Mundt #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
161f15cbe6fSPaul Mundt #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
162f15cbe6fSPaul Mundt
163f15cbe6fSPaul Mundt /*
164f15cbe6fSPaul Mundt * PFN = physical frame number (ie PFN 0 == physical address 0)
165f15cbe6fSPaul Mundt * PFN_START is the PFN of the first page of RAM. By defining this we
166f15cbe6fSPaul Mundt * don't have struct page entries for the portion of address space
167f15cbe6fSPaul Mundt * between physical address 0 and the start of RAM.
168f15cbe6fSPaul Mundt */
169f15cbe6fSPaul Mundt #define PFN_START (__MEMORY_START >> PAGE_SHIFT)
170f15cbe6fSPaul Mundt #define ARCH_PFN_OFFSET (PFN_START)
171f15cbe6fSPaul Mundt #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
172f15cbe6fSPaul Mundt #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
173f15cbe6fSPaul Mundt
174f15cbe6fSPaul Mundt #include <asm-generic/memory_model.h>
1755b17e1cdSArnd Bergmann #include <asm-generic/getorder.h>
176f15cbe6fSPaul Mundt
177f15cbe6fSPaul Mundt #endif /* __ASM_SH_PAGE_H */
178