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