This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / ia64 / xen / util.c
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  */
23
24 #include <linux/mm.h>
25 #include <linux/module.h>
26 #include <linux/slab.h>
27 #include <linux/vmalloc.h>
28 #include <asm/uaccess.h>
29 #include <xen/driver_util.h>
30
31 struct vm_struct *alloc_vm_area(unsigned long size)
32 {
33         int order;
34         unsigned long virt;
35         unsigned long nr_pages;
36         struct vm_struct* area;
37         
38         order = get_order(size);
39         virt = __get_free_pages(GFP_KERNEL, order);
40         if (virt == 0) {
41                 goto err0;
42         }
43         nr_pages = 1 << order;
44         scrub_pages(virt, nr_pages);
45         
46         area = kmalloc(sizeof(*area), GFP_KERNEL);
47         if (area == NULL) {
48                 goto err1;
49         }
50         
51         area->flags = VM_IOREMAP;//XXX
52         area->addr = (void*)virt;
53         area->size = size;
54         area->pages = NULL; //XXX
55         area->nr_pages = nr_pages;
56         area->phys_addr = 0;    /* xenbus_map_ring_valloc uses this field!  */
57
58         return area;
59
60 err1:
61         free_pages(virt, order);
62 err0:
63         return NULL;
64         
65 }
66 EXPORT_SYMBOL_GPL(alloc_vm_area);
67
68 void free_vm_area(struct vm_struct *area)
69 {
70         unsigned int order = get_order(area->size);
71         unsigned long i;
72         unsigned long phys_addr = __pa(area->addr);
73
74         // This area is used for foreign page mappping.
75         // So underlying machine page may not be assigned.
76         for (i = 0; i < (1 << order); i++) {
77                 unsigned long ret;
78                 unsigned long gpfn = (phys_addr >> PAGE_SHIFT) + i;
79                 struct xen_memory_reservation reservation = {
80                         .nr_extents   = 1,
81                         .address_bits = 0,
82                         .extent_order = 0,
83                         .domid        = DOMID_SELF
84                 };
85                 set_xen_guest_handle(reservation.extent_start, &gpfn);
86                 ret = HYPERVISOR_memory_op(XENMEM_populate_physmap,
87                                            &reservation);
88                 BUG_ON(ret != 1);
89         }
90         free_pages((unsigned long)area->addr, order);
91         kfree(area);
92 }
93 EXPORT_SYMBOL_GPL(free_vm_area);
94
95 void lock_vm_area(struct vm_struct *area)
96 {
97         // nothing
98 }
99 EXPORT_SYMBOL_GPL(lock_vm_area);
100
101 void unlock_vm_area(struct vm_struct *area)
102 {
103         // nothing
104 }
105 EXPORT_SYMBOL_GPL(unlock_vm_area);
106
107 /*
108  * Local variables:
109  *  c-file-style: "linux"
110  *  indent-tabs-mode: t
111  *  c-indent-level: 8
112  *  c-basic-offset: 8
113  *  tab-width: 8
114  * End:
115  */