2 * highmem.c: virtual kernel memory mappings for high memory
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
10 * But kmap_atomic() and kunmap_atomic() cannot be inlined in
11 * modules because they are loaded with btfixup-ped functions.
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.
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.
25 #include <linux/highmem.h>
26 #include <linux/export.h>
29 #include <asm/cacheflush.h>
30 #include <asm/tlbflush.h>
31 #include <asm/pgalloc.h>
32 #include <asm/vaddrs.h>
34 void *kmap_atomic(struct page *page)
39 /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
41 if (!PageHighMem(page))
42 return page_address(page);
44 type = kmap_atomic_idx_push();
45 idx = type + KM_TYPE_NR*smp_processor_id();
46 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
50 __flush_cache_one(vaddr);
55 #ifdef CONFIG_DEBUG_HIGHMEM
56 BUG_ON(!pte_none(*(kmap_pte-idx)));
58 set_pte(kmap_pte-idx, mk_pte(page, kmap_prot));
61 __flush_tlb_one(vaddr);
68 EXPORT_SYMBOL(kmap_atomic);
70 void __kunmap_atomic(void *kvaddr)
72 unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
75 if (vaddr < FIXADDR_START) { // FIXME
80 type = kmap_atomic_idx();
82 #ifdef CONFIG_DEBUG_HIGHMEM
86 idx = type + KM_TYPE_NR * smp_processor_id();
87 BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN+idx));
91 __flush_cache_one(vaddr);
97 * force other mappings to Oops if they'll try to access
98 * this pte without first remap it
100 pte_clear(&init_mm, vaddr, kmap_pte-idx);
101 /* XXX Fix - Anton */
103 __flush_tlb_one(vaddr);
110 kmap_atomic_idx_pop();
113 EXPORT_SYMBOL(__kunmap_atomic);