1 /******************************************************************************
3 * This file is the ia64 counterpart of drivers/xen/util.c
5 * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
6 * VA Linux Systems Japan K.K.
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.
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.
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
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>
31 struct vm_struct *alloc_vm_area(unsigned long size)
35 unsigned long nr_pages;
36 struct vm_struct* area;
38 order = get_order(size);
39 virt = __get_free_pages(GFP_KERNEL, order);
43 nr_pages = 1 << order;
44 scrub_pages(virt, nr_pages);
46 area = kmalloc(sizeof(*area), GFP_KERNEL);
51 area->flags = VM_IOREMAP;//XXX
52 area->addr = (void*)virt;
54 area->pages = NULL; //XXX
55 area->nr_pages = nr_pages;
56 area->phys_addr = 0; /* xenbus_map_ring_valloc uses this field! */
61 free_pages(virt, order);
66 EXPORT_SYMBOL_GPL(alloc_vm_area);
68 void free_vm_area(struct vm_struct *area)
70 unsigned int order = get_order(area->size);
72 unsigned long phys_addr = __pa(area->addr);
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++) {
78 unsigned long gpfn = (phys_addr >> PAGE_SHIFT) + i;
79 struct xen_memory_reservation reservation = {
85 set_xen_guest_handle(reservation.extent_start, &gpfn);
86 ret = HYPERVISOR_memory_op(XENMEM_populate_physmap,
90 free_pages((unsigned long)area->addr, order);
93 EXPORT_SYMBOL_GPL(free_vm_area);
95 void lock_vm_area(struct vm_struct *area)
99 EXPORT_SYMBOL_GPL(lock_vm_area);
101 void unlock_vm_area(struct vm_struct *area)
105 EXPORT_SYMBOL_GPL(unlock_vm_area);
109 * c-file-style: "linux"
110 * indent-tabs-mode: t