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