patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-sparc / pgtsun4.h
1 /* $Id: pgtsun4.h,v 1.5 2000/06/05 06:08:46 anton Exp $
2  * pgtsun4.h:  Sun4 specific pgtable.h defines and code.
3  *
4  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5  * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6  */
7 #ifndef _SPARC_PGTSUN4C_H
8 #define _SPARC_PGTSUN4C_H
9
10 #include <asm/contregs.h>
11
12 /* PMD_SHIFT determines the size of the area a second-level page table can map */
13 #define SUN4C_PMD_SHIFT       23
14
15 /* PGDIR_SHIFT determines what a third-level page table entry can map */
16 #define SUN4C_PGDIR_SHIFT       23
17 #define SUN4C_PGDIR_SIZE        (1UL << SUN4C_PGDIR_SHIFT)
18 #define SUN4C_PGDIR_MASK        (~(SUN4C_PGDIR_SIZE-1))
19 #define SUN4C_PGDIR_ALIGN(addr) (((addr)+SUN4C_PGDIR_SIZE-1)&SUN4C_PGDIR_MASK)
20
21 /* To represent how the sun4c mmu really lays things out. */
22 #define SUN4C_REAL_PGDIR_SHIFT       18
23 #define SUN4C_REAL_PGDIR_SIZE        (1UL << SUN4C_REAL_PGDIR_SHIFT)
24 #define SUN4C_REAL_PGDIR_MASK        (~(SUN4C_REAL_PGDIR_SIZE-1))
25 #define SUN4C_REAL_PGDIR_ALIGN(addr) (((addr)+SUN4C_REAL_PGDIR_SIZE-1)&SUN4C_REAL_PGDIR_MASK)
26
27 /* 19 bit PFN on sun4 */
28 #define SUN4C_PFN_MASK 0x7ffff
29  
30 /* Don't increase these unless the structures in sun4c.c are fixed */
31 #define SUN4C_MAX_SEGMAPS 256
32 #define SUN4C_MAX_CONTEXTS 16
33
34 /*
35  * To be efficient, and not have to worry about allocating such
36  * a huge pgd, we make the kernel sun4c tables each hold 1024
37  * entries and the pgd similarly just like the i386 tables.
38  */
39 #define SUN4C_PTRS_PER_PTE    1024
40 #define SUN4C_PTRS_PER_PMD    1
41 #define SUN4C_PTRS_PER_PGD    1024
42
43 /*
44  * Sparc SUN4C pte fields.
45  */
46 #define _SUN4C_PAGE_VALID        0x80000000
47 #define _SUN4C_PAGE_SILENT_READ  0x80000000   /* synonym */
48 #define _SUN4C_PAGE_DIRTY        0x40000000
49 #define _SUN4C_PAGE_SILENT_WRITE 0x40000000   /* synonym */
50 #define _SUN4C_PAGE_PRIV         0x20000000   /* privileged page */
51 #define _SUN4C_PAGE_NOCACHE      0x10000000   /* non-cacheable page */
52 #define _SUN4C_PAGE_PRESENT      0x08000000   /* implemented in software */
53 #define _SUN4C_PAGE_IO           0x04000000   /* I/O page */
54 #define _SUN4C_PAGE_READ         0x00800000   /* implemented in software */
55 #define _SUN4C_PAGE_WRITE        0x00400000   /* implemented in software */
56 #define _SUN4C_PAGE_ACCESSED     0x00200000   /* implemented in software */
57 #define _SUN4C_PAGE_MODIFIED     0x00100000   /* implemented in software */
58
59 #define _SUN4C_READABLE         (_SUN4C_PAGE_READ|_SUN4C_PAGE_SILENT_READ|\
60                                  _SUN4C_PAGE_ACCESSED)
61 #define _SUN4C_WRITEABLE        (_SUN4C_PAGE_WRITE|_SUN4C_PAGE_SILENT_WRITE|\
62                                  _SUN4C_PAGE_MODIFIED)
63
64 #define _SUN4C_PAGE_CHG_MASK    (0xffff|_SUN4C_PAGE_ACCESSED|_SUN4C_PAGE_MODIFIED)
65
66 #define SUN4C_PAGE_NONE         __pgprot(_SUN4C_PAGE_PRESENT)
67 #define SUN4C_PAGE_SHARED       __pgprot(_SUN4C_PAGE_PRESENT|_SUN4C_READABLE|\
68                                          _SUN4C_PAGE_WRITE)
69 #define SUN4C_PAGE_COPY         __pgprot(_SUN4C_PAGE_PRESENT|_SUN4C_READABLE)
70 #define SUN4C_PAGE_READONLY     __pgprot(_SUN4C_PAGE_PRESENT|_SUN4C_READABLE)
71 #define SUN4C_PAGE_KERNEL       __pgprot(_SUN4C_READABLE|_SUN4C_WRITEABLE|\
72                                          _SUN4C_PAGE_DIRTY|_SUN4C_PAGE_PRIV)
73
74 #ifndef __ASSEMBLY__
75
76 static inline unsigned long sun4c_get_synchronous_error(void)
77 {
78         unsigned long sync_err;
79
80         __asm__ __volatile__("lda [%1] %2, %0\n\t" :
81                              "=r" (sync_err) :
82                              "r" (AC_SYNC_ERR), "i" (ASI_CONTROL));
83         return sync_err;
84 }
85
86 static inline unsigned long sun4c_get_synchronous_address(void)
87 {
88         unsigned long sync_addr;
89
90         __asm__ __volatile__("lda [%1] %2, %0\n\t" :
91                              "=r" (sync_addr) :
92                              "r" (AC_SYNC_VA), "i" (ASI_CONTROL));
93         return sync_addr;
94 }
95
96 /* SUN4 pte, segmap, and context manipulation */
97 static inline unsigned long sun4c_get_segmap(unsigned long addr)
98 {
99   register unsigned long entry;
100
101   __asm__ __volatile__("\n\tlduha [%1] %2, %0\n\t" : 
102                        "=r" (entry) :
103                        "r" (addr), "i" (ASI_SEGMAP));
104   return entry;
105 }
106
107 static inline void sun4c_put_segmap(unsigned long addr, unsigned long entry)
108 {
109   __asm__ __volatile__("\n\tstha %1, [%0] %2; nop; nop; nop;\n\t" : :
110                        "r" (addr), "r" (entry),
111                        "i" (ASI_SEGMAP)
112                        : "memory");
113 }
114
115 static inline unsigned long sun4c_get_pte(unsigned long addr)
116 {
117   register unsigned long entry;
118
119   __asm__ __volatile__("\n\tlda [%1] %2, %0\n\t" : 
120                        "=r" (entry) :
121                        "r" (addr), "i" (ASI_PTE));
122   return entry;
123 }
124
125 static inline void sun4c_put_pte(unsigned long addr, unsigned long entry)
126 {
127   __asm__ __volatile__("\n\tsta %1, [%0] %2; nop; nop; nop;\n\t" : :
128                        "r" (addr), 
129                        "r" ((entry & ~(_SUN4C_PAGE_PRESENT))), "i" (ASI_PTE)
130                        : "memory");
131 }
132
133 static inline int sun4c_get_context(void)
134 {
135   register int ctx;
136
137   __asm__ __volatile__("\n\tlduba [%1] %2, %0\n\t" :
138                        "=r" (ctx) :
139                        "r" (AC_CONTEXT), "i" (ASI_CONTROL));
140
141   return ctx;
142 }
143
144 static inline int sun4c_set_context(int ctx)
145 {
146   __asm__ __volatile__("\n\tstba %0, [%1] %2; nop; nop; nop;\n\t" : :
147                        "r" (ctx), "r" (AC_CONTEXT), "i" (ASI_CONTROL)
148                        : "memory");
149
150   return ctx;
151 }
152
153 #endif /* !(__ASSEMBLY__) */
154
155 #endif /* !(_SPARC_PGTSUN4_H) */