xref: /openbmc/linux/arch/arc/include/asm/page.h (revision ccc319dc)
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 typedef struct {
38 	unsigned long pgd;
39 } pgd_t;
40 
41 #define pgd_val(x)	((x).pgd)
42 #define __pgd(x)	((pgd_t) { (x) })
43 
44 #if CONFIG_PGTABLE_LEVELS > 3
45 
46 typedef struct {
47 	unsigned long pud;
48 } pud_t;
49 
50 #define pud_val(x)      	((x).pud)
51 #define __pud(x)        	((pud_t) { (x) })
52 
53 #endif
54 
55 #if CONFIG_PGTABLE_LEVELS > 2
56 
57 typedef struct {
58 	unsigned long pmd;
59 } pmd_t;
60 
61 #define pmd_val(x)	((x).pmd)
62 #define __pmd(x)	((pmd_t) { (x) })
63 
64 #endif
65 
66 typedef struct {
67 #ifdef CONFIG_ARC_HAS_PAE40
68 	unsigned long long pte;
69 #else
70 	unsigned long pte;
71 #endif
72 } pte_t;
73 
74 #define pte_val(x)	((x).pte)
75 #define __pte(x)	((pte_t) { (x) })
76 
77 typedef struct {
78 	unsigned long pgprot;
79 } pgprot_t;
80 
81 #define pgprot_val(x)	((x).pgprot)
82 #define __pgprot(x)	((pgprot_t) { (x) })
83 #define pte_pgprot(x)	__pgprot(pte_val(x))
84 
85 typedef struct page *pgtable_t;
86 
87 /*
88  * Use virt_to_pfn with caution:
89  * If used in pte or paddr related macros, it could cause truncation
90  * in PAE40 builds
91  * As a rule of thumb, only use it in helpers starting with virt_
92  * You have been warned !
93  */
94 #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
95 
96 /*
97  * When HIGHMEM is enabled we have holes in the memory map so we need
98  * pfn_valid() that takes into account the actual extents of the physical
99  * memory
100  */
101 #ifdef CONFIG_HIGHMEM
102 
103 extern unsigned long arch_pfn_offset;
104 #define ARCH_PFN_OFFSET		arch_pfn_offset
105 
106 extern int pfn_valid(unsigned long pfn);
107 #define pfn_valid		pfn_valid
108 
109 #else /* CONFIG_HIGHMEM */
110 
111 #define ARCH_PFN_OFFSET		virt_to_pfn(CONFIG_LINUX_RAM_BASE)
112 #define pfn_valid(pfn)		(((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
113 
114 #endif /* CONFIG_HIGHMEM */
115 
116 /*
117  * __pa, __va, virt_to_page (ALERT: deprecated, don't use them)
118  *
119  * These macros have historically been misnamed
120  * virt here means link-address/program-address as embedded in object code.
121  * And for ARC, link-addr = physical address
122  */
123 #define __pa(vaddr)  		((unsigned long)(vaddr))
124 #define __va(paddr)  		((void *)((unsigned long)(paddr)))
125 
126 #define virt_to_page(kaddr)	pfn_to_page(virt_to_pfn(kaddr))
127 #define virt_addr_valid(kaddr)  pfn_valid(virt_to_pfn(kaddr))
128 
129 /* Default Permissions for stack/heaps pages (Non Executable) */
130 #define VM_DATA_DEFAULT_FLAGS	VM_DATA_FLAGS_NON_EXEC
131 
132 #define WANT_PAGE_VIRTUAL   1
133 
134 #include <asm-generic/memory_model.h>   /* page_to_pfn, pfn_to_page */
135 #include <asm-generic/getorder.h>
136 
137 #endif /* !__ASSEMBLY__ */
138 
139 #endif
140