This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-frv / highmem.h
1 /* highmem.h: virtual kernel memory mappings for high memory
2  *
3  * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  * - Derived from include/asm-i386/highmem.h
6  *
7  * See Documentation/fujitsu/frv/mmu-layout.txt for more information.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version
12  * 2 of the License, or (at your option) any later version.
13  */
14
15 #ifndef _ASM_HIGHMEM_H
16 #define _ASM_HIGHMEM_H
17
18 #ifdef __KERNEL__
19
20 #include <linux/config.h>
21 #include <linux/init.h>
22 #include <asm/mem-layout.h>
23 #include <asm/spr-regs.h>
24 #include <asm/mb-regs.h>
25
26 #define NR_TLB_LINES            64      /* number of lines in the TLB */
27
28 #ifndef __ASSEMBLY__
29
30 #include <linux/interrupt.h>
31 #include <asm/kmap_types.h>
32 #include <asm/pgtable.h>
33
34 #ifdef CONFIG_DEBUG_HIGHMEM
35 #define HIGHMEM_DEBUG 1
36 #else
37 #define HIGHMEM_DEBUG 0
38 #endif
39
40 /* declarations for highmem.c */
41 extern unsigned long highstart_pfn, highend_pfn;
42
43 #define kmap_prot PAGE_KERNEL
44 #define kmap_pte ______kmap_pte_in_TLB
45 extern pte_t *pkmap_page_table;
46
47 extern void kmap_init(void);
48
49 #define flush_cache_kmaps()  do { } while (0)
50
51 /*
52  * Right now we initialize only a single pte table. It can be extended
53  * easily, subsequent pte tables have to be allocated in one physical
54  * chunk of RAM.
55  */
56 #define LAST_PKMAP      PTRS_PER_PTE
57 #define LAST_PKMAP_MASK (LAST_PKMAP - 1)
58 #define PKMAP_NR(virt)  ((virt - PKMAP_BASE) >> PAGE_SHIFT)
59 #define PKMAP_ADDR(nr)  (PKMAP_BASE + ((nr) << PAGE_SHIFT))
60
61 extern void *kmap_high(struct page *page);
62 extern void kunmap_high(struct page *page);
63
64 extern void *kmap(struct page *page);
65 extern void kunmap(struct page *page);
66
67 extern struct page *kmap_atomic_to_page(void *ptr);
68
69 #endif /* !__ASSEMBLY__ */
70
71 /*
72  * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
73  * gives a more generic (and caching) interface. But kmap_atomic can
74  * be used in IRQ contexts, so in some (very limited) cases we need
75  * it.
76  */
77 #define KMAP_ATOMIC_CACHE_DAMR          8
78
79 #ifndef __ASSEMBLY__
80
81 #define __kmap_atomic_primary(type, paddr, ampr)                                                \
82 ({                                                                                              \
83         unsigned long damlr, dampr;                                                             \
84                                                                                                 \
85         dampr = paddr | xAMPRx_L | xAMPRx_M | xAMPRx_S | xAMPRx_SS_16Kb | xAMPRx_V;             \
86                                                                                                 \
87         if (type != __KM_CACHE)                                                                 \
88                 asm volatile("movgs %0,dampr"#ampr :: "r"(dampr));                              \
89         else                                                                                    \
90                 asm volatile("movgs %0,iampr"#ampr"\n"                                          \
91                              "movgs %0,dampr"#ampr"\n"                                          \
92                              :: "r"(dampr)                                                      \
93                              );                                                                 \
94                                                                                                 \
95         asm("movsg damlr"#ampr",%0" : "=r"(damlr));                                             \
96                                                                                                 \
97         /*printk("DAMR"#ampr": PRIM sl=%d L=%08lx P=%08lx\n", type, damlr, dampr);*/            \
98                                                                                                 \
99         (void *) damlr;                                                                         \
100 })
101
102 #define __kmap_atomic_secondary(slot, paddr)                                                      \
103 ({                                                                                                \
104         unsigned long damlr = KMAP_ATOMIC_SECONDARY_FRAME + (slot) * PAGE_SIZE;                   \
105         unsigned long dampr = paddr | xAMPRx_L | xAMPRx_M | xAMPRx_S | xAMPRx_SS_16Kb | xAMPRx_V; \
106                                                                                                   \
107         asm volatile("movgs %0,tplr \n"                                                           \
108                      "movgs %1,tppr \n"                                                           \
109                      "tlbpr %0,gr0,#2,#1"                                                         \
110                      : : "r"(damlr), "r"(dampr));                                                 \
111                                                                                                   \
112         /*printk("TLB: SECN sl=%d L=%08lx P=%08lx\n", slot, damlr, dampr);*/                      \
113                                                                                                   \
114         (void *) damlr;                                                                           \
115 })
116
117 static inline void *kmap_atomic(struct page *page, enum km_type type)
118 {
119         unsigned long paddr;
120
121         preempt_disable();
122         paddr = page_to_phys(page);
123
124         switch (type) {
125         case 0:         return __kmap_atomic_primary(0, paddr, 2);
126         case 1:         return __kmap_atomic_primary(1, paddr, 3);
127         case 2:         return __kmap_atomic_primary(2, paddr, 4);
128         case 3:         return __kmap_atomic_primary(3, paddr, 5);
129         case 4:         return __kmap_atomic_primary(4, paddr, 6);
130         case 5:         return __kmap_atomic_primary(5, paddr, 7);
131         case 6:         return __kmap_atomic_primary(6, paddr, 8);
132         case 7:         return __kmap_atomic_primary(7, paddr, 9);
133         case 8:         return __kmap_atomic_primary(8, paddr, 10);
134
135         case 9 ... 9 + NR_TLB_LINES - 1:
136                 return __kmap_atomic_secondary(type - 9, paddr);
137
138         default:
139                 BUG();
140                 return 0;
141         }
142 }
143
144 #define __kunmap_atomic_primary(type, ampr)                     \
145 do {                                                            \
146         asm volatile("movgs gr0,dampr"#ampr"\n");               \
147         if (type == __KM_CACHE)                                 \
148                 asm volatile("movgs gr0,iampr"#ampr"\n");       \
149 } while(0)
150
151 #define __kunmap_atomic_secondary(slot, vaddr)                  \
152 do {                                                            \
153         asm volatile("tlbpr %0,gr0,#4,#1" : : "r"(vaddr));      \
154 } while(0)
155
156 static inline void kunmap_atomic(void *kvaddr, enum km_type type)
157 {
158         switch (type) {
159         case 0:         __kunmap_atomic_primary(0, 2);  break;
160         case 1:         __kunmap_atomic_primary(1, 3);  break;
161         case 2:         __kunmap_atomic_primary(2, 4);  break;
162         case 3:         __kunmap_atomic_primary(3, 5);  break;
163         case 4:         __kunmap_atomic_primary(4, 6);  break;
164         case 5:         __kunmap_atomic_primary(5, 7);  break;
165         case 6:         __kunmap_atomic_primary(6, 8);  break;
166         case 7:         __kunmap_atomic_primary(7, 9);  break;
167         case 8:         __kunmap_atomic_primary(8, 10); break;
168
169         case 9 ... 9 + NR_TLB_LINES - 1:
170                 __kunmap_atomic_secondary(type - 9, kvaddr);
171                 break;
172
173         default:
174                 BUG();
175         }
176         preempt_enable();
177 }
178
179 #endif /* !__ASSEMBLY__ */
180
181 #endif /* __KERNEL__ */
182
183 #endif /* _ASM_HIGHMEM_H */