ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/util.c @ 8672:2e82fd7a6921

Need to include module.h to get EXPORT_SYMBOL macros.
Export xen driver util functions with GPL tag.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jan 27 12:48:32 2006 +0100 (2006-01-27)
parents 709bce2f08d6
children fd9b2c1bb577
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 <asm-xen/driver_util.h>
9 static int f(pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
10 {
11 /* generic_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 (generic_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);
72 /*
73 * Local variables:
74 * c-file-style: "linux"
75 * indent-tabs-mode: t
76 * c-indent-level: 8
77 * c-basic-offset: 8
78 * tab-width: 8
79 * End:
80 */