]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * highmem.c: virtual kernel memory mappings for high memory | |
3 | * | |
4 | * Provides kernel-static versions of atomic kmap functions originally | |
5 | * found as inlines in include/asm-sparc/highmem.h. These became | |
6 | * needed as kmap_atomic() and kunmap_atomic() started getting | |
7 | * called from within modules. | |
8 | * -- Tomas Szepe <szepe@pinerecords.com>, September 2002 | |
9 | * | |
10 | * But kmap_atomic() and kunmap_atomic() cannot be inlined in | |
11 | * modules because they are loaded with btfixup-ped functions. | |
12 | */ | |
13 | ||
14 | /* | |
15 | * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap | |
16 | * gives a more generic (and caching) interface. But kmap_atomic can | |
17 | * be used in IRQ contexts, so in some (very limited) cases we need it. | |
18 | * | |
19 | * XXX This is an old text. Actually, it's good to use atomic kmaps, | |
20 | * provided you remember that they are atomic and not try to sleep | |
21 | * with a kmap taken, much like a spinlock. Non-atomic kmaps are | |
22 | * shared by CPUs, and so precious, and establishing them requires IPI. | |
23 | * Atomic kmaps are lightweight and we may have NCPUS more of them. | |
24 | */ | |
25 | #include <linux/mm.h> | |
26 | #include <linux/highmem.h> | |
27 | #include <asm/pgalloc.h> | |
28 | #include <asm/cacheflush.h> | |
29 | #include <asm/tlbflush.h> | |
30 | #include <asm/fixmap.h> | |
31 | ||
32 | void *kmap_atomic(struct page *page, enum km_type type) | |
33 | { | |
34 | unsigned long idx; | |
35 | unsigned long vaddr; | |
36 | ||
37 | /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */ | |
a866374a | 38 | pagefault_disable(); |
1da177e4 LT |
39 | if (!PageHighMem(page)) |
40 | return page_address(page); | |
41 | ||
7ca43e75 | 42 | debug_kmap_atomic(type); |
1da177e4 LT |
43 | idx = type + KM_TYPE_NR*smp_processor_id(); |
44 | vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); | |
45 | ||
46 | /* XXX Fix - Anton */ | |
47 | #if 0 | |
48 | __flush_cache_one(vaddr); | |
49 | #else | |
50 | flush_cache_all(); | |
51 | #endif | |
52 | ||
53 | #ifdef CONFIG_DEBUG_HIGHMEM | |
54 | BUG_ON(!pte_none(*(kmap_pte-idx))); | |
55 | #endif | |
56 | set_pte(kmap_pte-idx, mk_pte(page, kmap_prot)); | |
57 | /* XXX Fix - Anton */ | |
58 | #if 0 | |
59 | __flush_tlb_one(vaddr); | |
60 | #else | |
61 | flush_tlb_all(); | |
62 | #endif | |
63 | ||
64 | return (void*) vaddr; | |
65 | } | |
6943f3da | 66 | EXPORT_SYMBOL(kmap_atomic); |
1da177e4 LT |
67 | |
68 | void kunmap_atomic(void *kvaddr, enum km_type type) | |
69 | { | |
70 | #ifdef CONFIG_DEBUG_HIGHMEM | |
71 | unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK; | |
72 | unsigned long idx = type + KM_TYPE_NR*smp_processor_id(); | |
73 | ||
74 | if (vaddr < FIXADDR_START) { // FIXME | |
a866374a | 75 | pagefault_enable(); |
1da177e4 LT |
76 | return; |
77 | } | |
78 | ||
79 | BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN+idx)); | |
80 | ||
81 | /* XXX Fix - Anton */ | |
82 | #if 0 | |
83 | __flush_cache_one(vaddr); | |
84 | #else | |
85 | flush_cache_all(); | |
86 | #endif | |
87 | ||
88 | /* | |
89 | * force other mappings to Oops if they'll try to access | |
90 | * this pte without first remap it | |
91 | */ | |
92 | pte_clear(&init_mm, vaddr, kmap_pte-idx); | |
93 | /* XXX Fix - Anton */ | |
94 | #if 0 | |
95 | __flush_tlb_one(vaddr); | |
96 | #else | |
97 | flush_tlb_all(); | |
98 | #endif | |
99 | #endif | |
100 | ||
a866374a | 101 | pagefault_enable(); |
1da177e4 | 102 | } |
6943f3da | 103 | EXPORT_SYMBOL(kunmap_atomic); |
1da177e4 LT |
104 | |
105 | /* We may be fed a pagetable here by ptep_to_xxx and others. */ | |
106 | struct page *kmap_atomic_to_page(void *ptr) | |
107 | { | |
108 | unsigned long idx, vaddr = (unsigned long)ptr; | |
109 | pte_t *pte; | |
110 | ||
111 | if (vaddr < SRMMU_NOCACHE_VADDR) | |
112 | return virt_to_page(ptr); | |
113 | if (vaddr < PKMAP_BASE) | |
114 | return pfn_to_page(__nocache_pa(vaddr) >> PAGE_SHIFT); | |
115 | BUG_ON(vaddr < FIXADDR_START); | |
116 | BUG_ON(vaddr > FIXADDR_TOP); | |
117 | ||
118 | idx = virt_to_fix(vaddr); | |
119 | pte = kmap_pte - (idx - FIX_KMAP_BEGIN); | |
120 | return pte_page(*pte); | |
121 | } |