xref: /linux/arch/sparc/include/asm/page_32.h (revision fcc79e1714e8c2b8e216dc3149812edd37884eef)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * page.h:  Various defines and such for MMU operations on the Sparc for
4  *          the Linux kernel.
5  *
6  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7  */
8 
9 #ifndef _SPARC_PAGE_H
10 #define _SPARC_PAGE_H
11 
12 #include <linux/const.h>
13 
14 #include <vdso/page.h>
15 
16 #ifndef __ASSEMBLY__
17 
18 #define clear_page(page)	 memset((void *)(page), 0, PAGE_SIZE)
19 #define copy_page(to,from) 	memcpy((void *)(to), (void *)(from), PAGE_SIZE)
20 #define clear_user_page(addr, vaddr, page)	\
21 	do { 	clear_page(addr);		\
22 		sparc_flush_page_to_ram(page);	\
23 	} while (0)
24 #define copy_user_page(to, from, vaddr, page)	\
25 	do {	copy_page(to, from);		\
26 		sparc_flush_page_to_ram(page);	\
27 	} while (0)
28 
29 /* The following structure is used to hold the physical
30  * memory configuration of the machine.  This is filled in
31  * prom_meminit() and is later used by mem_init() to set up
32  * mem_map[].  We statically allocate SPARC_PHYS_BANKS+1 of
33  * these structs, this is arbitrary.  The entry after the
34  * last valid one has num_bytes==0.
35  */
36 struct sparc_phys_banks {
37   unsigned long base_addr;
38   unsigned long num_bytes;
39 };
40 
41 #define SPARC_PHYS_BANKS 32
42 
43 extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS+1];
44 
45 /* passing structs on the Sparc slow us down tremendously... */
46 
47 /* #define STRICT_MM_TYPECHECKS */
48 
49 #ifdef STRICT_MM_TYPECHECKS
50 /*
51  * These are used to make use of C type-checking..
52  */
53 typedef struct { unsigned long pte; } pte_t;
54 typedef struct { unsigned long iopte; } iopte_t;
55 typedef struct { unsigned long pmd; } pmd_t;
56 typedef struct { unsigned long pgd; } pgd_t;
57 typedef struct { unsigned long ctxd; } ctxd_t;
58 typedef struct { unsigned long pgprot; } pgprot_t;
59 typedef struct { unsigned long iopgprot; } iopgprot_t;
60 
61 #define pte_val(x)	((x).pte)
62 #define iopte_val(x)	((x).iopte)
63 #define pmd_val(x)      ((x).pmd)
64 #define pgd_val(x)	((x).pgd)
65 #define ctxd_val(x)	((x).ctxd)
66 #define pgprot_val(x)	((x).pgprot)
67 #define iopgprot_val(x)	((x).iopgprot)
68 
69 #define __pte(x)	((pte_t) { (x) } )
70 #define __pmd(x)	((pmd_t) { { (x) }, })
71 #define __iopte(x)	((iopte_t) { (x) } )
72 #define __pgd(x)	((pgd_t) { (x) } )
73 #define __ctxd(x)	((ctxd_t) { (x) } )
74 #define __pgprot(x)	((pgprot_t) { (x) } )
75 #define __iopgprot(x)	((iopgprot_t) { (x) } )
76 
77 #else
78 /*
79  * .. while these make it easier on the compiler
80  */
81 typedef unsigned long pte_t;
82 typedef unsigned long iopte_t;
83 typedef unsigned long pmd_t;
84 typedef unsigned long pgd_t;
85 typedef unsigned long ctxd_t;
86 typedef unsigned long pgprot_t;
87 typedef unsigned long iopgprot_t;
88 
89 #define pte_val(x)	(x)
90 #define iopte_val(x)	(x)
91 #define pmd_val(x)      (x)
92 #define pgd_val(x)	(x)
93 #define ctxd_val(x)	(x)
94 #define pgprot_val(x)	(x)
95 #define iopgprot_val(x)	(x)
96 
97 #define __pte(x)	(x)
98 #define __pmd(x)	(x)
99 #define __iopte(x)	(x)
100 #define __pgd(x)	(x)
101 #define __ctxd(x)	(x)
102 #define __pgprot(x)	(x)
103 #define __iopgprot(x)	(x)
104 
105 #endif
106 
107 typedef pte_t *pgtable_t;
108 
109 #define TASK_UNMAPPED_BASE	0x50000000
110 
111 #else /* !(__ASSEMBLY__) */
112 
113 #define __pgprot(x)	(x)
114 
115 #endif /* !(__ASSEMBLY__) */
116 
117 #define PAGE_OFFSET	0xf0000000
118 #ifndef __ASSEMBLY__
119 extern unsigned long phys_base;
120 extern unsigned long pfn_base;
121 #endif
122 #define __pa(x)			((unsigned long)(x) - PAGE_OFFSET + phys_base)
123 #define __va(x)			((void *)((unsigned long) (x) - phys_base + PAGE_OFFSET))
124 
125 #define virt_to_phys		__pa
126 #define phys_to_virt		__va
127 
128 #define ARCH_PFN_OFFSET		(pfn_base)
129 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
130 
131 #define virt_addr_valid(kaddr)	((((unsigned long)(kaddr)-PAGE_OFFSET)>>PAGE_SHIFT) < max_mapnr)
132 
133 #include <asm-generic/memory_model.h>
134 #include <asm-generic/getorder.h>
135 
136 #endif /* _SPARC_PAGE_H */
137