xref: /openbmc/linux/arch/csky/include/asm/page.h (revision b866371f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef __ASM_CSKY_PAGE_H
4 #define __ASM_CSKY_PAGE_H
5 
6 #include <asm/setup.h>
7 #include <asm/cache.h>
8 #include <linux/const.h>
9 
10 /*
11  * PAGE_SHIFT determines the page size: 4KB
12  */
13 #define PAGE_SHIFT	12
14 #define PAGE_SIZE	(_AC(1, UL) << PAGE_SHIFT)
15 #define PAGE_MASK	(~(PAGE_SIZE - 1))
16 #define THREAD_SIZE	(PAGE_SIZE * 2)
17 #define THREAD_MASK	(~(THREAD_SIZE - 1))
18 #define THREAD_SHIFT	(PAGE_SHIFT + 1)
19 
20 
21 /*
22  * For C-SKY "User-space:Kernel-space" is "2GB:2GB" fixed by hardware and there
23  * are two segment registers (MSA0 + MSA1) to mapping 512MB + 512MB physical
24  * address region. We use them mapping kernel 1GB direct-map address area and
25  * for more than 1GB of memory we use highmem.
26  */
27 #define PAGE_OFFSET	CONFIG_PAGE_OFFSET
28 #define SSEG_SIZE	0x20000000
29 #define LOWMEM_LIMIT	(SSEG_SIZE * 2)
30 
31 #define PHYS_OFFSET_OFFSET (CONFIG_DRAM_BASE & (SSEG_SIZE - 1))
32 
33 #ifndef __ASSEMBLY__
34 
35 #include <linux/pfn.h>
36 
37 #define virt_addr_valid(kaddr)  ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
38 			(void *)(kaddr) < high_memory)
39 
40 extern void *memset(void *dest, int c, size_t l);
41 extern void *memcpy(void *to, const void *from, size_t l);
42 
43 #define clear_page(page)	memset((page), 0, PAGE_SIZE)
44 #define copy_page(to, from)	memcpy((to), (from), PAGE_SIZE)
45 
46 #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
47 #define phys_to_page(paddr)	(pfn_to_page(PFN_DOWN(paddr)))
48 
49 struct page;
50 
51 #include <abi/page.h>
52 
53 struct vm_area_struct;
54 
55 typedef struct { unsigned long pte_low; } pte_t;
56 #define pte_val(x)	((x).pte_low)
57 
58 typedef struct { unsigned long pgd; } pgd_t;
59 typedef struct { unsigned long pgprot; } pgprot_t;
60 typedef struct page *pgtable_t;
61 
62 #define pgd_val(x)	((x).pgd)
63 #define pgprot_val(x)	((x).pgprot)
64 
65 #define ptep_buddy(x)	((pte_t *)((unsigned long)(x) ^ sizeof(pte_t)))
66 
67 #define __pte(x)	((pte_t) { (x) })
68 #define __pgd(x)	((pgd_t) { (x) })
69 #define __pgprot(x)	((pgprot_t) { (x) })
70 
71 extern unsigned long va_pa_offset;
72 
73 #define ARCH_PFN_OFFSET	PFN_DOWN(va_pa_offset + PHYS_OFFSET_OFFSET)
74 
75 #define __pa(x)		 ((unsigned long)(x) - PAGE_OFFSET + va_pa_offset)
76 #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - va_pa_offset))
77 
78 #define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x), 0))
79 
80 static inline unsigned long virt_to_pfn(const void *kaddr)
81 {
82 	return __pa(kaddr) >> PAGE_SHIFT;
83 }
84 
85 static inline void * pfn_to_virt(unsigned long pfn)
86 {
87 	return (void *)((unsigned long)__va(pfn) << PAGE_SHIFT);
88 }
89 
90 #define MAP_NR(x)	PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \
91 				 PHYS_OFFSET_OFFSET)
92 #define virt_to_page(x)	(mem_map + MAP_NR(x))
93 
94 #define pfn_to_kaddr(x)	__va(PFN_PHYS(x))
95 
96 #include <asm-generic/memory_model.h>
97 #include <asm-generic/getorder.h>
98 
99 #endif /* !__ASSEMBLY__ */
100 #endif /* __ASM_CSKY_PAGE_H */
101