• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _METAG_PAGE_H
3 #define _METAG_PAGE_H
4 
5 #include <linux/const.h>
6 
7 #include <asm/metag_mem.h>
8 
9 /* PAGE_SHIFT determines the page size */
10 #if defined(CONFIG_PAGE_SIZE_4K)
11 #define PAGE_SHIFT	12
12 #elif defined(CONFIG_PAGE_SIZE_8K)
13 #define PAGE_SHIFT	13
14 #elif defined(CONFIG_PAGE_SIZE_16K)
15 #define PAGE_SHIFT	14
16 #endif
17 
18 #define PAGE_SIZE	(_AC(1, UL) << PAGE_SHIFT)
19 #define PAGE_MASK	(~(PAGE_SIZE-1))
20 
21 #if defined(CONFIG_HUGETLB_PAGE_SIZE_8K)
22 # define HPAGE_SHIFT	13
23 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_16K)
24 # define HPAGE_SHIFT	14
25 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_32K)
26 # define HPAGE_SHIFT	15
27 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
28 # define HPAGE_SHIFT	16
29 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_128K)
30 # define HPAGE_SHIFT	17
31 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K)
32 # define HPAGE_SHIFT	18
33 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
34 # define HPAGE_SHIFT	19
35 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_1M)
36 # define HPAGE_SHIFT	20
37 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_2M)
38 # define HPAGE_SHIFT	21
39 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_4M)
40 # define HPAGE_SHIFT	22
41 #endif
42 
43 #ifdef CONFIG_HUGETLB_PAGE
44 # define HPAGE_SIZE		(1UL << HPAGE_SHIFT)
45 # define HPAGE_MASK		(~(HPAGE_SIZE-1))
46 # define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT-PAGE_SHIFT)
47 /*
48  * We define our own hugetlb_get_unmapped_area so we don't corrupt 2nd level
49  * page tables with normal pages in them.
50  */
51 # define HUGEPT_SHIFT		(22)
52 # define HUGEPT_ALIGN		(1 << HUGEPT_SHIFT)
53 # define HUGEPT_MASK		(HUGEPT_ALIGN - 1)
54 # define ALIGN_HUGEPT(x)	ALIGN(x, HUGEPT_ALIGN)
55 # define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
56 #endif
57 
58 #ifndef __ASSEMBLY__
59 
60 /* On the Meta, we would like to know if the address (heap) we have is
61  * in local or global space.
62  */
63 #define is_global_space(addr)	((addr) > 0x7fffffff)
64 #define is_local_space(addr)	(!is_global_space(addr))
65 
66 extern void clear_page(void *to);
67 extern void copy_page(void *to, void *from);
68 
69 #define clear_user_page(page, vaddr, pg)        clear_page(page)
70 #define copy_user_page(to, from, vaddr, pg)     copy_page(to, from)
71 
72 /*
73  * These are used to make use of C type-checking..
74  */
75 typedef struct { unsigned long pte; } pte_t;
76 typedef struct { unsigned long pgd; } pgd_t;
77 typedef struct { unsigned long pgprot; } pgprot_t;
78 typedef struct page *pgtable_t;
79 
80 #define pte_val(x)	((x).pte)
81 #define pgd_val(x)	((x).pgd)
82 #define pgprot_val(x)	((x).pgprot)
83 
84 #define __pte(x)	((pte_t) { (x) })
85 #define __pgd(x)	((pgd_t) { (x) })
86 #define __pgprot(x)	((pgprot_t) { (x) })
87 
88 /* The kernel must now ALWAYS live at either 0xC0000000 or 0x40000000 - that
89  * being either global or local space.
90  */
91 #define PAGE_OFFSET		(CONFIG_PAGE_OFFSET)
92 
93 #if PAGE_OFFSET >= LINGLOBAL_BASE
94 #define META_MEMORY_BASE  LINGLOBAL_BASE
95 #define META_MEMORY_LIMIT LINGLOBAL_LIMIT
96 #else
97 #define META_MEMORY_BASE  LINLOCAL_BASE
98 #define META_MEMORY_LIMIT LINLOCAL_LIMIT
99 #endif
100 
101 /* Offset between physical and virtual mapping of kernel memory. */
102 extern unsigned int meta_memoffset;
103 
104 #define __pa(x) ((unsigned long)(((unsigned long)(x)) - meta_memoffset))
105 #define __va(x) ((void *)((unsigned long)(((unsigned long)(x)) + meta_memoffset)))
106 
107 extern unsigned long pfn_base;
108 #define ARCH_PFN_OFFSET         (pfn_base)
109 #define virt_to_page(kaddr)     pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
110 #define page_to_virt(page)      __va(page_to_pfn(page) << PAGE_SHIFT)
111 #define virt_addr_valid(kaddr)  pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
112 #define page_to_phys(page)      (page_to_pfn(page) << PAGE_SHIFT)
113 #ifdef CONFIG_FLATMEM
114 extern unsigned long max_pfn;
115 extern unsigned long min_low_pfn;
116 #define pfn_valid(pfn)		((pfn) >= min_low_pfn && (pfn) < max_pfn)
117 #endif
118 
119 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
120 
121 #define VM_DATA_DEFAULT_FLAGS   (VM_READ | VM_WRITE | VM_EXEC | \
122 				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
123 
124 #include <asm-generic/memory_model.h>
125 #include <asm-generic/getorder.h>
126 
127 #endif /* __ASSMEBLY__ */
128 
129 #endif /* _METAG_PAGE_H */
130