ia64/xen-unstable

view linux-2.6-xen-sparse/arch/ia64/xen/util.c @ 10788:4e7318b0c1e0

[IA64] nasty bug fix

Bug fix: restore phys_addr field, because some other Xen
functions consider it as unused.

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author awilliam@xenbuild.aw
date Wed Jul 26 09:41:24 2006 -0600 (2006-07-26)
parents 6a49e02dc169
children 86ff604d8e20
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>
32 struct vm_struct *alloc_vm_area(unsigned long size)
33 {
34 int order;
35 unsigned long virt;
36 unsigned long nr_pages;
37 struct vm_struct* area;
39 order = get_order(size);
40 virt = __get_free_pages(GFP_KERNEL, order);
41 if (virt == 0) {
42 goto err0;
43 }
44 nr_pages = 1 << order;
45 scrub_pages(virt, nr_pages);
47 area = kmalloc(sizeof(*area), GFP_KERNEL);
48 if (area == NULL) {
49 goto err1;
50 }
52 area->flags = VM_IOREMAP;//XXX
53 area->addr = (void*)virt;
54 area->size = size;
55 area->pages = NULL; //XXX
56 area->nr_pages = nr_pages;
57 area->phys_addr = __pa(virt);
59 return area;
61 err1:
62 free_pages(virt, order);
63 err0:
64 return NULL;
66 }
67 EXPORT_SYMBOL_GPL(alloc_vm_area);
69 void free_vm_area(struct vm_struct *area)
70 {
71 unsigned int order = get_order(area->size);
72 unsigned long i;
74 /* xenbus_map_ring_valloc overrides this field! */
75 area->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 = (area->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 void lock_vm_area(struct vm_struct *area)
99 {
100 // nothing
101 }
102 EXPORT_SYMBOL_GPL(lock_vm_area);
104 void unlock_vm_area(struct vm_struct *area)
105 {
106 // nothing
107 }
108 EXPORT_SYMBOL_GPL(unlock_vm_area);
110 #ifndef CONFIG_XEN_IA64_DOM0_VP
111 /* We just need a range of legal va here, though finally identity
112 * mapped one is instead used for gnttab mapping.
113 */
114 unsigned long alloc_empty_foreign_map_page_range(unsigned long pages)
115 {
116 struct vm_struct *vma;
118 if ( (vma = get_vm_area(PAGE_SIZE * pages, VM_ALLOC)) == NULL )
119 return NULL;
121 return (unsigned long)vma->addr;
122 }
123 #endif
125 /*
126 * Local variables:
127 * c-file-style: "linux"
128 * indent-tabs-mode: t
129 * c-indent-level: 8
130 * c-basic-offset: 8
131 * tab-width: 8
132 * End:
133 */