xref: /openbmc/linux/arch/csky/include/asm/page.h (revision 2a598d0b)
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_to_pfn(kaddr)      (__pa(kaddr) >> PAGE_SHIFT)
38 #define pfn_to_virt(pfn)        __va((pfn) << PAGE_SHIFT)
39 
40 #define virt_addr_valid(kaddr)  ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
41 			(void *)(kaddr) < high_memory)
42 
43 extern void *memset(void *dest, int c, size_t l);
44 extern void *memcpy(void *to, const void *from, size_t l);
45 
46 #define clear_page(page)	memset((page), 0, PAGE_SIZE)
47 #define copy_page(to, from)	memcpy((to), (from), PAGE_SIZE)
48 
49 #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
50 #define phys_to_page(paddr)	(pfn_to_page(PFN_DOWN(paddr)))
51 
52 struct page;
53 
54 #include <abi/page.h>
55 
56 struct vm_area_struct;
57 
58 typedef struct { unsigned long pte_low; } pte_t;
59 #define pte_val(x)	((x).pte_low)
60 
61 typedef struct { unsigned long pgd; } pgd_t;
62 typedef struct { unsigned long pgprot; } pgprot_t;
63 typedef struct page *pgtable_t;
64 
65 #define pgd_val(x)	((x).pgd)
66 #define pgprot_val(x)	((x).pgprot)
67 
68 #define ptep_buddy(x)	((pte_t *)((unsigned long)(x) ^ sizeof(pte_t)))
69 
70 #define __pte(x)	((pte_t) { (x) })
71 #define __pgd(x)	((pgd_t) { (x) })
72 #define __pgprot(x)	((pgprot_t) { (x) })
73 
74 extern unsigned long va_pa_offset;
75 
76 #define ARCH_PFN_OFFSET	PFN_DOWN(va_pa_offset + PHYS_OFFSET_OFFSET)
77 
78 #define __pa(x)		 ((unsigned long)(x) - PAGE_OFFSET + va_pa_offset)
79 #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - va_pa_offset))
80 
81 #define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x), 0))
82 
83 #define MAP_NR(x)	PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \
84 				 PHYS_OFFSET_OFFSET)
85 #define virt_to_page(x)	(mem_map + MAP_NR(x))
86 
87 #define pfn_to_kaddr(x)	__va(PFN_PHYS(x))
88 
89 #include <asm-generic/memory_model.h>
90 #include <asm-generic/getorder.h>
91 
92 #endif /* !__ASSEMBLY__ */
93 #endif /* __ASM_CSKY_PAGE_H */
94