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