xref: /openbmc/linux/arch/csky/include/asm/page.h (revision 0c8a32eed1625a65798286fb73fea8710a908545)
1013de2d6SGuo Ren /* SPDX-License-Identifier: GPL-2.0 */
2013de2d6SGuo Ren 
3013de2d6SGuo Ren #ifndef __ASM_CSKY_PAGE_H
4013de2d6SGuo Ren #define __ASM_CSKY_PAGE_H
5013de2d6SGuo Ren 
6013de2d6SGuo Ren #include <asm/setup.h>
7013de2d6SGuo Ren #include <asm/cache.h>
8013de2d6SGuo Ren #include <linux/const.h>
9013de2d6SGuo Ren 
10013de2d6SGuo Ren /*
11f62e3162SGuo Ren  * PAGE_SHIFT determines the page size: 4KB
12013de2d6SGuo Ren  */
13013de2d6SGuo Ren #define PAGE_SHIFT	12
14013de2d6SGuo Ren #define PAGE_SIZE	(_AC(1, UL) << PAGE_SHIFT)
15013de2d6SGuo Ren #define PAGE_MASK	(~(PAGE_SIZE - 1))
16013de2d6SGuo Ren #define THREAD_SIZE	(PAGE_SIZE * 2)
17013de2d6SGuo Ren #define THREAD_MASK	(~(THREAD_SIZE - 1))
18013de2d6SGuo Ren #define THREAD_SHIFT	(PAGE_SHIFT + 1)
19013de2d6SGuo Ren 
20f62e3162SGuo Ren 
21013de2d6SGuo Ren /*
22f62e3162SGuo Ren  * For C-SKY "User-space:Kernel-space" is "2GB:2GB" fixed by hardware and there
23f62e3162SGuo Ren  * are two segment registers (MSA0 + MSA1) to mapping 512MB + 512MB physical
24f62e3162SGuo Ren  * address region. We use them mapping kernel 1GB direct-map address area and
25f62e3162SGuo Ren  * for more than 1GB of memory we use highmem.
26013de2d6SGuo Ren  */
27*0c8a32eeSGuo Ren #define PAGE_OFFSET	CONFIG_PAGE_OFFSET
28f62e3162SGuo Ren #define SSEG_SIZE	0x20000000
29f62e3162SGuo Ren #define LOWMEM_LIMIT	(SSEG_SIZE * 2)
30f62e3162SGuo Ren 
31f62e3162SGuo Ren #define PHYS_OFFSET_OFFSET (CONFIG_RAM_BASE & (SSEG_SIZE - 1))
32013de2d6SGuo Ren 
33013de2d6SGuo Ren #ifndef __ASSEMBLY__
34013de2d6SGuo Ren 
35013de2d6SGuo Ren #include <linux/pfn.h>
36013de2d6SGuo Ren 
37013de2d6SGuo Ren #define virt_to_pfn(kaddr)      (__pa(kaddr) >> PAGE_SHIFT)
38013de2d6SGuo Ren #define pfn_to_virt(pfn)        __va((pfn) << PAGE_SHIFT)
39013de2d6SGuo Ren 
40013de2d6SGuo Ren #define virt_addr_valid(kaddr)  ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
41013de2d6SGuo Ren 			(void *)(kaddr) < high_memory)
42013de2d6SGuo Ren #define pfn_valid(pfn)		((pfn) >= ARCH_PFN_OFFSET && ((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
43013de2d6SGuo Ren 
44013de2d6SGuo Ren extern void *memset(void *dest, int c, size_t l);
45013de2d6SGuo Ren extern void *memcpy(void *to, const void *from, size_t l);
46013de2d6SGuo Ren 
47013de2d6SGuo Ren #define clear_page(page)	memset((page), 0, PAGE_SIZE)
48013de2d6SGuo Ren #define copy_page(to, from)	memcpy((to), (from), PAGE_SIZE)
49013de2d6SGuo Ren 
50013de2d6SGuo Ren #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
51013de2d6SGuo Ren #define phys_to_page(paddr)	(pfn_to_page(PFN_DOWN(paddr)))
52013de2d6SGuo Ren 
53013de2d6SGuo Ren struct page;
54013de2d6SGuo Ren 
55013de2d6SGuo Ren #include <abi/page.h>
56013de2d6SGuo Ren 
57013de2d6SGuo Ren struct vm_area_struct;
58013de2d6SGuo Ren 
59013de2d6SGuo Ren typedef struct { unsigned long pte_low; } pte_t;
60013de2d6SGuo Ren #define pte_val(x)	((x).pte_low)
61013de2d6SGuo Ren 
62013de2d6SGuo Ren typedef struct { unsigned long pgd; } pgd_t;
63013de2d6SGuo Ren typedef struct { unsigned long pgprot; } pgprot_t;
64013de2d6SGuo Ren typedef struct page *pgtable_t;
65013de2d6SGuo Ren 
66013de2d6SGuo Ren #define pgd_val(x)	((x).pgd)
67013de2d6SGuo Ren #define pgprot_val(x)	((x).pgprot)
68013de2d6SGuo Ren 
69013de2d6SGuo Ren #define ptep_buddy(x)	((pte_t *)((unsigned long)(x) ^ sizeof(pte_t)))
70013de2d6SGuo Ren 
71013de2d6SGuo Ren #define __pte(x)	((pte_t) { (x) })
72013de2d6SGuo Ren #define __pgd(x)	((pgd_t) { (x) })
73013de2d6SGuo Ren #define __pgprot(x)	((pgprot_t) { (x) })
74013de2d6SGuo Ren 
75683fafebSGuo Ren extern unsigned long va_pa_offset;
76013de2d6SGuo Ren 
77683fafebSGuo Ren #define ARCH_PFN_OFFSET	PFN_DOWN(va_pa_offset + PHYS_OFFSET_OFFSET)
78013de2d6SGuo Ren 
79683fafebSGuo Ren #define __pa(x)		 ((unsigned long)(x) - PAGE_OFFSET + va_pa_offset)
80683fafebSGuo Ren #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - va_pa_offset))
81683fafebSGuo Ren 
82013de2d6SGuo Ren #define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x), 0))
83013de2d6SGuo Ren 
84013de2d6SGuo Ren #define MAP_NR(x)	PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \
85013de2d6SGuo Ren 				 PHYS_OFFSET_OFFSET)
86013de2d6SGuo Ren #define virt_to_page(x)	(mem_map + MAP_NR(x))
87013de2d6SGuo Ren 
88013de2d6SGuo Ren #define pfn_to_kaddr(x)	__va(PFN_PHYS(x))
89013de2d6SGuo Ren 
90013de2d6SGuo Ren #include <asm-generic/memory_model.h>
91013de2d6SGuo Ren #include <asm-generic/getorder.h>
92013de2d6SGuo Ren 
93f62e3162SGuo Ren #endif /* !__ASSEMBLY__ */
94013de2d6SGuo Ren #endif /* __ASM_CSKY_PAGE_H */
95