ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/util.c @ 13665:140afd7a5462

merge with xen-unstable.hg
author awilliam@xenbuild2.aw
date Sat Jan 27 14:07:19 2007 -0700 (2007-01-27)
parents 48c0f5489d44
children c4ed5b740a8d
line source
1 #include <linux/config.h>
2 #include <linux/mm.h>
3 #include <linux/module.h>
4 #include <linux/slab.h>
5 #include <linux/vmalloc.h>
6 #include <asm/uaccess.h>
7 #include <xen/driver_util.h>
9 static int f(pte_t *pte, struct page *pmd_page, unsigned long addr, void *data)
10 {
11 /* apply_to_page_range() does all the hard work. */
12 return 0;
13 }
15 struct vm_struct *alloc_vm_area(unsigned long size)
16 {
17 struct vm_struct *area;
19 area = get_vm_area(size, VM_IOREMAP);
20 if (area == NULL)
21 return NULL;
23 /*
24 * This ensures that page tables are constructed for this region
25 * of kernel virtual address space and mapped into init_mm.
26 */
27 if (apply_to_page_range(&init_mm, (unsigned long)area->addr,
28 area->size, f, NULL)) {
29 free_vm_area(area);
30 return NULL;
31 }
33 return area;
34 }
35 EXPORT_SYMBOL_GPL(alloc_vm_area);
37 void free_vm_area(struct vm_struct *area)
38 {
39 struct vm_struct *ret;
40 ret = remove_vm_area(area->addr);
41 BUG_ON(ret != area);
42 kfree(area);
43 }
44 EXPORT_SYMBOL_GPL(free_vm_area);
46 void lock_vm_area(struct vm_struct *area)
47 {
48 unsigned long i;
49 char c;
51 /*
52 * Prevent context switch to a lazy mm that doesn't have this area
53 * mapped into its page tables.
54 */
55 preempt_disable();
57 /*
58 * Ensure that the page tables are mapped into the current mm. The
59 * page-fault path will copy the page directory pointers from init_mm.
60 */
61 for (i = 0; i < area->size; i += PAGE_SIZE)
62 (void)__get_user(c, (char __user *)area->addr + i);
63 }
64 EXPORT_SYMBOL_GPL(lock_vm_area);
66 void unlock_vm_area(struct vm_struct *area)
67 {
68 preempt_enable();
69 }
70 EXPORT_SYMBOL_GPL(unlock_vm_area);