d8ffaa47ad2ce60991a9a7faaa9d5c5c85bb4455
[linux-2.4.21-pre4.git] / highmem.h
1 /*
2  * highmem.h: virtual kernel memory mappings for high memory
3  *
4  * Used in CONFIG_HIGHMEM systems for memory pages which
5  * are not addressable by direct kernel virtual addresses.
6  *
7  * Copyright (C) 1999 Gerhard Wichert, Siemens AG
8  *                    Gerhard.Wichert@pdb.siemens.de
9  *
10  *
11  * Redesigned the x86 32-bit VM architecture to deal with 
12  * up to 16 Terabyte physical memory. With current x86 CPUs
13  * we now support up to 64 Gigabytes physical RAM.
14  *
15  * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
16  */
17
18 #ifndef _ASM_HIGHMEM_H
19 #define _ASM_HIGHMEM_H
20
21 #ifdef __KERNEL__
22
23 #include <linux/config.h>
24 #include <linux/init.h>
25 #include <linux/interrupt.h>
26 #include <asm/kmap_types.h>
27 #include <asm/pgtable.h>
28
29 #ifdef CONFIG_DEBUG_HIGHMEM
30 #define HIGHMEM_DEBUG 1
31 #else
32 #define HIGHMEM_DEBUG 0
33 #endif
34
35 /* declarations for highmem.c */
36 extern unsigned long highstart_pfn, highend_pfn;
37
38 extern pte_t *kmap_pte;
39 extern pgprot_t kmap_prot;
40 extern pte_t *pkmap_page_table;
41
42 extern void kmap_init(void) __init;
43
44 /*
45  * Right now we initialize only a single pte table. It can be extended
46  * easily, subsequent pte tables have to be allocated in one physical
47  * chunk of RAM.
48  */
49 #define PKMAP_BASE (0xfe000000UL)
50 #ifdef CONFIG_X86_PAE
51 #define LAST_PKMAP 512
52 #else
53 #define LAST_PKMAP 1024
54 #endif
55 #define LAST_PKMAP_MASK (LAST_PKMAP-1)
56 #define PKMAP_NR(virt)  ((virt-PKMAP_BASE) >> PAGE_SHIFT)
57 #define PKMAP_ADDR(nr)  (PKMAP_BASE + ((nr) << PAGE_SHIFT))
58
59 extern void * FASTCALL(kmap_high(struct page *page));
60 extern void FASTCALL(kunmap_high(struct page *page));
61
62 static inline void *kmap(struct page *page)
63 {
64         if (in_interrupt())
65                 out_of_line_bug();
66         if (page < highmem_start_page)
67                 return page_address(page);
68         return kmap_high(page);
69 }
70
71 static inline void kunmap(struct page *page)
72 {
73         if (in_interrupt())
74                 out_of_line_bug();
75         if (page < highmem_start_page)
76                 return;
77         kunmap_high(page);
78 }
79
80 /*
81  * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
82  * gives a more generic (and caching) interface. But kmap_atomic can
83  * be used in IRQ contexts, so in some (very limited) cases we need
84  * it.
85  */
86 static inline void *kmap_atomic(struct page *page, enum km_type type)
87 {
88         enum fixed_addresses idx;
89         unsigned long vaddr;
90
91         if (page < highmem_start_page)
92                 return page_address(page);
93
94         idx = type + KM_TYPE_NR*smp_processor_id();
95         vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
96 #if HIGHMEM_DEBUG
97         if (!pte_none(*(kmap_pte-idx)))
98                 out_of_line_bug();
99 #endif
100         set_pte(kmap_pte-idx, mk_pte(page, kmap_prot));
101         __flush_tlb_one(vaddr);
102
103         return (void*) vaddr;
104 }
105
106 static inline void kunmap_atomic(void *kvaddr, enum km_type type)
107 {
108 #if HIGHMEM_DEBUG
109         unsigned long vaddr = (unsigned long) kvaddr;
110         enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
111
112         if (vaddr < FIXADDR_START) // FIXME
113                 return;
114
115         if (vaddr != __fix_to_virt(FIX_KMAP_BEGIN+idx))
116                 out_of_line_bug();
117
118         /*
119          * force other mappings to Oops if they'll try to access
120          * this pte without first remap it
121          */
122         pte_clear(kmap_pte-idx);
123         __flush_tlb_one(vaddr);
124 #endif
125 }
126
127 #endif /* __KERNEL__ */
128
129 #endif /* _ASM_HIGHMEM_H */