xref: /linux/arch/csky/include/asm/page.h (revision 18f90d372cf35b387663f1567de701e5393f6eb5)
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
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  * NOTE: virtual isn't really correct, actually it should be the offset into the
22  * memory node, but we have no highmem, so that works for now.
23  * TODO: implement (fast) pfn<->pgdat_idx conversion functions, this makes lots
24  * of the shifts unnecessary.
25  */
26 
27 #ifndef __ASSEMBLY__
28 
29 #include <linux/pfn.h>
30 
31 #define virt_to_pfn(kaddr)      (__pa(kaddr) >> PAGE_SHIFT)
32 #define pfn_to_virt(pfn)        __va((pfn) << PAGE_SHIFT)
33 
34 #define virt_addr_valid(kaddr)  ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
35 			(void *)(kaddr) < high_memory)
36 #define pfn_valid(pfn)		((pfn) >= ARCH_PFN_OFFSET && ((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
37 
38 extern void *memset(void *dest, int c, size_t l);
39 extern void *memcpy(void *to, const void *from, size_t l);
40 
41 #define clear_page(page)	memset((page), 0, PAGE_SIZE)
42 #define copy_page(to, from)	memcpy((to), (from), PAGE_SIZE)
43 
44 #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
45 #define phys_to_page(paddr)	(pfn_to_page(PFN_DOWN(paddr)))
46 
47 struct page;
48 
49 #include <abi/page.h>
50 
51 struct vm_area_struct;
52 
53 /*
54  * These are used to make use of C type-checking..
55  */
56 typedef struct { unsigned long pte_low; } pte_t;
57 #define pte_val(x)	((x).pte_low)
58 
59 typedef struct { unsigned long pgd; } pgd_t;
60 typedef struct { unsigned long pgprot; } pgprot_t;
61 typedef struct page *pgtable_t;
62 
63 #define pgd_val(x)	((x).pgd)
64 #define pgprot_val(x)	((x).pgprot)
65 
66 #define ptep_buddy(x)	((pte_t *)((unsigned long)(x) ^ sizeof(pte_t)))
67 
68 #define __pte(x)	((pte_t) { (x) })
69 #define __pgd(x)	((pgd_t) { (x) })
70 #define __pgprot(x)	((pgprot_t) { (x) })
71 
72 #endif /* !__ASSEMBLY__ */
73 
74 #define PHYS_OFFSET		(CONFIG_RAM_BASE & ~(LOWMEM_LIMIT - 1))
75 #define PHYS_OFFSET_OFFSET	(CONFIG_RAM_BASE & (LOWMEM_LIMIT - 1))
76 #define ARCH_PFN_OFFSET		PFN_DOWN(CONFIG_RAM_BASE)
77 
78 #define	PAGE_OFFSET	0x80000000
79 #define LOWMEM_LIMIT	0x40000000
80 
81 #define __pa(x)		((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
82 #define __va(x)		((void *)((unsigned long)(x) + PAGE_OFFSET - \
83 				  PHYS_OFFSET))
84 #define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x), 0))
85 
86 #define MAP_NR(x)	PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \
87 				 PHYS_OFFSET_OFFSET)
88 #define virt_to_page(x)	(mem_map + MAP_NR(x))
89 
90 #define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
91 				VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
92 
93 /*
94  * main RAM and kernel working space are coincident at 0x80000000, but to make
95  * life more interesting, there's also an uncached virtual shadow at 0xb0000000
96  * - these mappings are fixed in the MMU
97  */
98 
99 #define pfn_to_kaddr(x)	__va(PFN_PHYS(x))
100 
101 #include <asm-generic/memory_model.h>
102 #include <asm-generic/getorder.h>
103 
104 #endif /* __ASM_CSKY_PAGE_H */
105