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