ia64/xen-unstable

view xen/arch/x86/x86_32/domain_page.c @ 5303:d68bc64e2cfe

bitkeeper revision 1.1664 (42a064ddVMYCAab_WQM9CcyTOyYMgQ)

Simplify implementation of map_domain_mem.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jun 03 14:10:37 2005 +0000 (2005-06-03)
parents b51e4b4608f9
children 2d8e63df504a
line source
1 /******************************************************************************
2 * domain_page.h
3 *
4 * Allow temporary mapping of domain pages. Based on ideas from the
5 * Linux PKMAP code -- the copyrights and credits are retained below.
6 */
8 /*
9 * (C) 1999 Andrea Arcangeli, SuSE GmbH, andrea@suse.de
10 * Gerhard Wichert, Siemens AG, Gerhard.Wichert@pdb.siemens.de *
11 * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
12 */
14 #include <xen/config.h>
15 #include <xen/sched.h>
16 #include <xen/mm.h>
17 #include <xen/perfc.h>
18 #include <asm/current.h>
19 #include <asm/domain_page.h>
20 #include <asm/flushtlb.h>
21 #include <asm/hardirq.h>
23 l1_pgentry_t *mapcache;
24 static unsigned int map_idx, epoch, shadow_epoch[NR_CPUS];
25 static spinlock_t map_lock = SPIN_LOCK_UNLOCKED;
27 void *map_domain_mem(unsigned long pa)
28 {
29 unsigned long va;
30 unsigned int idx, cpu = smp_processor_id();
31 l1_pgentry_t *cache = mapcache;
32 #ifndef NDEBUG
33 unsigned int flush_count = 0;
34 #endif
36 ASSERT(!in_irq());
37 perfc_incrc(map_domain_mem_count);
39 spin_lock(&map_lock);
41 /* Has some other CPU caused a wrap? We must flush if so. */
42 if ( epoch != shadow_epoch[cpu] )
43 {
44 perfc_incrc(domain_page_tlb_flush);
45 local_flush_tlb();
46 shadow_epoch[cpu] = epoch;
47 }
49 do {
50 idx = map_idx = (map_idx + 1) & (MAPCACHE_ENTRIES - 1);
51 if ( unlikely(idx == 0) )
52 {
53 ASSERT(flush_count++ == 0);
54 perfc_incrc(domain_page_tlb_flush);
55 local_flush_tlb();
56 shadow_epoch[cpu] = ++epoch;
57 }
58 }
59 while ( l1e_get_flags(cache[idx]) & _PAGE_PRESENT );
61 cache[idx] = l1e_from_paddr(pa & PAGE_MASK, __PAGE_HYPERVISOR);
63 spin_unlock(&map_lock);
65 va = MAPCACHE_VIRT_START + (idx << PAGE_SHIFT) + (pa & ~PAGE_MASK);
66 return (void *)va;
67 }
69 void unmap_domain_mem(void *va)
70 {
71 unsigned int idx;
72 ASSERT((void *)MAPCACHE_VIRT_START <= va);
73 ASSERT(va < (void *)MAPCACHE_VIRT_END);
74 idx = ((unsigned long)va - MAPCACHE_VIRT_START) >> PAGE_SHIFT;
75 mapcache[idx] = l1e_empty();
76 }