xref: /openbmc/linux/arch/arc/include/asm/page.h (revision 29d97219)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
4  */
5 #ifndef __ASM_ARC_PAGE_H
6 #define __ASM_ARC_PAGE_H
7 
8 #include <uapi/asm/page.h>
9 
10 #ifdef CONFIG_ARC_HAS_PAE40
11 
12 #define MAX_POSSIBLE_PHYSMEM_BITS	40
13 #define PAGE_MASK_PHYS			(0xff00000000ull | PAGE_MASK)
14 
15 #else /* CONFIG_ARC_HAS_PAE40 */
16 
17 #define MAX_POSSIBLE_PHYSMEM_BITS	32
18 #define PAGE_MASK_PHYS			PAGE_MASK
19 
20 #endif /* CONFIG_ARC_HAS_PAE40 */
21 
22 #ifndef __ASSEMBLY__
23 
24 #define clear_page(paddr)		memset((paddr), 0, PAGE_SIZE)
25 #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
26 #define copy_page(to, from)		memcpy((to), (from), PAGE_SIZE)
27 
28 struct vm_area_struct;
29 struct page;
30 
31 #define __HAVE_ARCH_COPY_USER_HIGHPAGE
32 
33 void copy_user_highpage(struct page *to, struct page *from,
34 			unsigned long u_vaddr, struct vm_area_struct *vma);
35 void clear_user_page(void *to, unsigned long u_vaddr, struct page *page);
36 
37 #undef STRICT_MM_TYPECHECKS
38 
39 #ifdef STRICT_MM_TYPECHECKS
40 /*
41  * These are used to make use of C type-checking..
42  */
43 typedef struct {
44 #ifdef CONFIG_ARC_HAS_PAE40
45 	unsigned long long pte;
46 #else
47 	unsigned long pte;
48 #endif
49 } pte_t;
50 typedef struct {
51 	unsigned long pgd;
52 } pgd_t;
53 typedef struct {
54 	unsigned long pgprot;
55 } pgprot_t;
56 
57 #define pte_val(x)      ((x).pte)
58 #define pgd_val(x)      ((x).pgd)
59 #define pgprot_val(x)   ((x).pgprot)
60 
61 #define __pte(x)        ((pte_t) { (x) })
62 #define __pgd(x)        ((pgd_t) { (x) })
63 #define __pgprot(x)     ((pgprot_t) { (x) })
64 
65 #define pte_pgprot(x) __pgprot(pte_val(x))
66 
67 #else /* !STRICT_MM_TYPECHECKS */
68 
69 #ifdef CONFIG_ARC_HAS_PAE40
70 typedef unsigned long long pte_t;
71 #else
72 typedef unsigned long pte_t;
73 #endif
74 typedef unsigned long pgd_t;
75 typedef unsigned long pgprot_t;
76 
77 #define pte_val(x)	(x)
78 #define pgd_val(x)	(x)
79 #define pgprot_val(x)	(x)
80 #define __pte(x)	(x)
81 #define __pgd(x)	(x)
82 #define __pgprot(x)	(x)
83 #define pte_pgprot(x)	(x)
84 
85 #endif
86 
87 typedef pte_t * pgtable_t;
88 
89 /*
90  * Use virt_to_pfn with caution:
91  * If used in pte or paddr related macros, it could cause truncation
92  * in PAE40 builds
93  * As a rule of thumb, only use it in helpers starting with virt_
94  * You have been warned !
95  */
96 #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
97 
98 /*
99  * When HIGHMEM is enabled we have holes in the memory map so we need
100  * pfn_valid() that takes into account the actual extents of the physical
101  * memory
102  */
103 #ifdef CONFIG_HIGHMEM
104 
105 extern unsigned long arch_pfn_offset;
106 #define ARCH_PFN_OFFSET		arch_pfn_offset
107 
108 extern int pfn_valid(unsigned long pfn);
109 #define pfn_valid		pfn_valid
110 
111 #else /* CONFIG_HIGHMEM */
112 
113 #define ARCH_PFN_OFFSET		virt_to_pfn(CONFIG_LINUX_RAM_BASE)
114 #define pfn_valid(pfn)		(((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
115 
116 #endif /* CONFIG_HIGHMEM */
117 
118 /*
119  * __pa, __va, virt_to_page (ALERT: deprecated, don't use them)
120  *
121  * These macros have historically been misnamed
122  * virt here means link-address/program-address as embedded in object code.
123  * And for ARC, link-addr = physical address
124  */
125 #define __pa(vaddr)  ((unsigned long)(vaddr))
126 #define __va(paddr)  ((void *)((unsigned long)(paddr)))
127 
128 #define virt_to_page(kaddr)	pfn_to_page(virt_to_pfn(kaddr))
129 #define virt_addr_valid(kaddr)  pfn_valid(virt_to_pfn(kaddr))
130 
131 /* Default Permissions for stack/heaps pages (Non Executable) */
132 #define VM_DATA_DEFAULT_FLAGS	VM_DATA_FLAGS_NON_EXEC
133 
134 #define WANT_PAGE_VIRTUAL   1
135 
136 #include <asm-generic/memory_model.h>   /* page_to_pfn, pfn_to_page */
137 #include <asm-generic/getorder.h>
138 
139 #endif /* !__ASSEMBLY__ */
140 
141 #endif
142