xref: /openbmc/linux/arch/arc/include/asm/page.h (revision 4e0b6ca9)
1 /*
2  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8 #ifndef __ASM_ARC_PAGE_H
9 #define __ASM_ARC_PAGE_H
10 
11 #include <uapi/asm/page.h>
12 
13 
14 #ifndef __ASSEMBLY__
15 
16 #define clear_page(paddr)		memset((paddr), 0, PAGE_SIZE)
17 #define copy_page(to, from)		memcpy((to), (from), PAGE_SIZE)
18 
19 struct vm_area_struct;
20 struct page;
21 
22 #define __HAVE_ARCH_COPY_USER_HIGHPAGE
23 
24 void copy_user_highpage(struct page *to, struct page *from,
25 			unsigned long u_vaddr, struct vm_area_struct *vma);
26 void clear_user_page(void *to, unsigned long u_vaddr, struct page *page);
27 
28 #undef STRICT_MM_TYPECHECKS
29 
30 #ifdef STRICT_MM_TYPECHECKS
31 /*
32  * These are used to make use of C type-checking..
33  */
34 typedef struct {
35 	unsigned long pte;
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 #define ARCH_PFN_OFFSET     (CONFIG_LINUX_LINK_BASE >> PAGE_SHIFT)
77 
78 #define pfn_valid(pfn)      (((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
79 
80 /*
81  * __pa, __va, virt_to_page (ALERT: deprecated, don't use them)
82  *
83  * These macros have historically been misnamed
84  * virt here means link-address/program-address as embedded in object code.
85  * So if kernel img is linked at 0x8000_0000 onwards, 0x8010_0000 will be
86  * 128th page, and virt_to_page( ) will return the struct page corresp to it.
87  * mem_map[ ] is an array of struct page for each page frame in the system
88  *
89  * Independent of where linux is linked at, link-addr = physical address
90  * So the old macro  __pa = vaddr + PAGE_OFFSET - CONFIG_LINUX_LINK_BASE
91  * would have been wrong in case kernel is not at 0x8zs
92  */
93 #define __pa(vaddr)  ((unsigned long)vaddr)
94 #define __va(paddr)  ((void *)((unsigned long)(paddr)))
95 
96 #define virt_to_page(kaddr)	\
97 	(mem_map + ((__pa(kaddr) - CONFIG_LINUX_LINK_BASE) >> PAGE_SHIFT))
98 
99 #define virt_addr_valid(kaddr)  pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
100 
101 /* Default Permissions for stack/heaps pages (Non Executable) */
102 #define VM_DATA_DEFAULT_FLAGS   (VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE)
103 
104 #define WANT_PAGE_VIRTUAL   1
105 
106 #include <asm-generic/memory_model.h>   /* page_to_pfn, pfn_to_page */
107 #include <asm-generic/getorder.h>
108 
109 #endif /* !__ASSEMBLY__ */
110 
111 #endif
112