ia64/xen-unstable

view linux-2.6-xen-sparse/arch/ia64/xen/util.c @ 13991:c4ed5b740a8d

linux: remove {lock,unlock}_vm_area(). Instead use vmalloc_sync_all()
in alloc_vm_area().
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Feb 16 11:24:10 2007 +0000 (2007-02-16)
parents 5c97ef4c7147
children e47738923a05
line source
1 /******************************************************************************
2 * arch/ia64/xen/util.c
3 * This file is the ia64 counterpart of drivers/xen/util.c
4 *
5 * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
6 * VA Linux Systems Japan K.K.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
24 #include <linux/config.h>
25 #include <linux/mm.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <asm/uaccess.h>
30 #include <xen/driver_util.h>
31 #include <xen/interface/memory.h>
32 #include <asm/hypercall.h>
34 struct vm_struct *alloc_vm_area(unsigned long size)
35 {
36 int order;
37 unsigned long virt;
38 unsigned long nr_pages;
39 struct vm_struct* area;
41 order = get_order(size);
42 virt = __get_free_pages(GFP_KERNEL, order);
43 if (virt == 0) {
44 goto err0;
45 }
46 nr_pages = 1 << order;
47 scrub_pages(virt, nr_pages);
49 area = kmalloc(sizeof(*area), GFP_KERNEL);
50 if (area == NULL) {
51 goto err1;
52 }
54 area->flags = VM_IOREMAP;//XXX
55 area->addr = (void*)virt;
56 area->size = size;
57 area->pages = NULL; //XXX
58 area->nr_pages = nr_pages;
59 area->phys_addr = 0; /* xenbus_map_ring_valloc uses this field! */
61 return area;
63 err1:
64 free_pages(virt, order);
65 err0:
66 return NULL;
68 }
69 EXPORT_SYMBOL_GPL(alloc_vm_area);
71 void free_vm_area(struct vm_struct *area)
72 {
73 unsigned int order = get_order(area->size);
74 unsigned long i;
75 unsigned long phys_addr = __pa(area->addr);
77 // This area is used for foreign page mappping.
78 // So underlying machine page may not be assigned.
79 for (i = 0; i < (1 << order); i++) {
80 unsigned long ret;
81 unsigned long gpfn = (phys_addr >> PAGE_SHIFT) + i;
82 struct xen_memory_reservation reservation = {
83 .nr_extents = 1,
84 .address_bits = 0,
85 .extent_order = 0,
86 .domid = DOMID_SELF
87 };
88 set_xen_guest_handle(reservation.extent_start, &gpfn);
89 ret = HYPERVISOR_memory_op(XENMEM_populate_physmap,
90 &reservation);
91 BUG_ON(ret != 1);
92 }
93 free_pages((unsigned long)area->addr, order);
94 kfree(area);
95 }
96 EXPORT_SYMBOL_GPL(free_vm_area);
98 /*
99 * Local variables:
100 * c-file-style: "linux"
101 * indent-tabs-mode: t
102 * c-indent-level: 8
103 * c-basic-offset: 8
104 * tab-width: 8
105 * End:
106 */