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