ia64/xen-unstable

view linux-2.6-xen-sparse/arch/xen/i386/mm/highmem.c @ 6552:a9873d384da4

Merge.
author adsharma@los-vmm.sc.intel.com
date Thu Aug 25 12:24:48 2005 -0700 (2005-08-25)
parents 112d44270733 fa0754a9f64f
children dfaf788ab18c
line source
1 #include <linux/highmem.h>
3 void *kmap(struct page *page)
4 {
5 might_sleep();
6 if (!PageHighMem(page))
7 return page_address(page);
8 return kmap_high(page);
9 }
11 void kunmap(struct page *page)
12 {
13 if (in_interrupt())
14 BUG();
15 if (!PageHighMem(page))
16 return;
17 kunmap_high(page);
18 }
20 /*
21 * kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap because
22 * no global lock is needed and because the kmap code must perform a global TLB
23 * invalidation when the kmap pool wraps.
24 *
25 * However when holding an atomic kmap is is not legal to sleep, so atomic
26 * kmaps are appropriate for short, tight code paths only.
27 */
28 static void *__kmap_atomic(struct page *page, enum km_type type, pgprot_t prot)
29 {
30 enum fixed_addresses idx;
31 unsigned long vaddr;
33 /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
34 inc_preempt_count();
35 if (!PageHighMem(page))
36 return page_address(page);
38 idx = type + KM_TYPE_NR*smp_processor_id();
39 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
40 #ifdef CONFIG_DEBUG_HIGHMEM
41 if (!pte_none(*(kmap_pte-idx)))
42 BUG();
43 #endif
44 set_pte_at_sync(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot));
46 return (void*) vaddr;
47 }
49 void *kmap_atomic(struct page *page, enum km_type type)
50 {
51 return __kmap_atomic(page, type, kmap_prot);
52 }
54 /* Same as kmap_atomic but with PAGE_KERNEL_RO page protection. */
55 void *kmap_atomic_pte(struct page *page, enum km_type type)
56 {
57 return __kmap_atomic(page, type, PAGE_KERNEL_RO);
58 }
60 void kunmap_atomic(void *kvaddr, enum km_type type)
61 {
62 #ifdef CONFIG_DEBUG_HIGHMEM
63 unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
64 enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
66 if (vaddr < FIXADDR_START) { // FIXME
67 dec_preempt_count();
68 preempt_check_resched();
69 return;
70 }
72 if (vaddr != __fix_to_virt(FIX_KMAP_BEGIN+idx))
73 BUG();
75 /*
76 * force other mappings to Oops if they'll try to access
77 * this pte without first remap it
78 */
79 pte_clear(&init_mm, vaddr, kmap_pte-idx);
80 __flush_tlb_one(vaddr);
81 #endif
83 dec_preempt_count();
84 preempt_check_resched();
85 }
87 struct page *kmap_atomic_to_page(void *ptr)
88 {
89 unsigned long idx, vaddr = (unsigned long)ptr;
90 pte_t *pte;
92 if (vaddr < FIXADDR_START)
93 return virt_to_page(ptr);
95 idx = virt_to_fix(vaddr);
96 pte = kmap_pte - (idx - FIX_KMAP_BEGIN);
97 return pte_page(*pte);
98 }