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 * When HIGHMEM is enabled we have holes in the memory map so we need
89 * pfn_valid() that takes into account the actual extents of the physical
90 * memory
91 */
92 #ifdef CONFIG_HIGHMEM
93
94 extern unsigned long arch_pfn_offset;
95 #define ARCH_PFN_OFFSET arch_pfn_offset
96
97 extern int pfn_valid(unsigned long pfn);
98 #define pfn_valid pfn_valid
99
100 #else /* CONFIG_HIGHMEM */
101
102 #define ARCH_PFN_OFFSET virt_to_pfn((void *)CONFIG_LINUX_RAM_BASE)
103
104 #endif /* CONFIG_HIGHMEM */
105
106 /*
107 * __pa, __va, virt_to_page (ALERT: deprecated, don't use them)
108 *
109 * These macros have historically been misnamed
110 * virt here means link-address/program-address as embedded in object code.
111 * And for ARC, link-addr = physical address
112 */
113 #define __pa(vaddr) ((unsigned long)(vaddr))
114 #define __va(paddr) ((void *)((unsigned long)(paddr)))
115
116 /*
117 * Use virt_to_pfn with caution:
118 * If used in pte or paddr related macros, it could cause truncation
119 * in PAE40 builds
120 * As a rule of thumb, only use it in helpers starting with virt_
121 * You have been warned !
122 */
virt_to_pfn(const void * kaddr)123 static inline unsigned long virt_to_pfn(const void *kaddr)
124 {
125 return __pa(kaddr) >> PAGE_SHIFT;
126 }
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