[IA64] remove duplicate include iommu.h
[linux-2.6.git] / arch / ia64 / xen / grant-table.c
1 /******************************************************************************
2  * arch/ia64/xen/grant-table.c
3  *
4  * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
5  *                    VA Linux Systems Japan K.K.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include <linux/module.h>
24 #include <linux/vmalloc.h>
25 #include <linux/mm.h>
26
27 #include <xen/interface/xen.h>
28 #include <xen/interface/memory.h>
29 #include <xen/grant_table.h>
30
31 #include <asm/xen/hypervisor.h>
32
33 struct vm_struct *xen_alloc_vm_area(unsigned long size)
34 {
35         int order;
36         unsigned long virt;
37         unsigned long nr_pages;
38         struct vm_struct *area;
39
40         order = get_order(size);
41         virt = __get_free_pages(GFP_KERNEL, order);
42         if (virt == 0)
43                 goto err0;
44         nr_pages = 1 << order;
45         scrub_pages(virt, nr_pages);
46
47         area = kmalloc(sizeof(*area), GFP_KERNEL);
48         if (area == NULL)
49                 goto err1;
50
51         area->flags = VM_IOREMAP;
52         area->addr = (void *)virt;
53         area->size = size;
54         area->pages = NULL;
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 EXPORT_SYMBOL_GPL(xen_alloc_vm_area);
66
67 void xen_free_vm_area(struct vm_struct *area)
68 {
69         unsigned int order = get_order(area->size);
70         unsigned long i;
71         unsigned long phys_addr = __pa(area->addr);
72
73         /* This area is used for foreign page mappping.
74          * So underlying machine page may not be assigned. */
75         for (i = 0; i < (1 << order); i++) {
76                 unsigned long ret;
77                 unsigned long gpfn = (phys_addr >> PAGE_SHIFT) + i;
78                 struct xen_memory_reservation reservation = {
79                         .nr_extents   = 1,
80                         .address_bits = 0,
81                         .extent_order = 0,
82                         .domid        = DOMID_SELF
83                 };
84                 set_xen_guest_handle(reservation.extent_start, &gpfn);
85                 ret = HYPERVISOR_memory_op(XENMEM_populate_physmap,
86                                            &reservation);
87                 BUG_ON(ret != 1);
88         }
89         free_pages((unsigned long)area->addr, order);
90         kfree(area);
91 }
92 EXPORT_SYMBOL_GPL(xen_free_vm_area);
93
94
95 /****************************************************************************
96  * grant table hack
97  * cmd: GNTTABOP_xxx
98  */
99
100 int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
101                            unsigned long max_nr_gframes,
102                            struct grant_entry **__shared)
103 {
104         *__shared = __va(frames[0] << PAGE_SHIFT);
105         return 0;
106 }
107
108 void arch_gnttab_unmap_shared(struct grant_entry *shared,
109                               unsigned long nr_gframes)
110 {
111         /* nothing */
112 }
113
114 static void
115 gnttab_map_grant_ref_pre(struct gnttab_map_grant_ref *uop)
116 {
117         uint32_t flags;
118
119         flags = uop->flags;
120
121         if (flags & GNTMAP_host_map) {
122                 if (flags & GNTMAP_application_map) {
123                         printk(KERN_DEBUG
124                                "GNTMAP_application_map is not supported yet: "
125                                "flags 0x%x\n", flags);
126                         BUG();
127                 }
128                 if (flags & GNTMAP_contains_pte) {
129                         printk(KERN_DEBUG
130                                "GNTMAP_contains_pte is not supported yet: "
131                                "flags 0x%x\n", flags);
132                         BUG();
133                 }
134         } else if (flags & GNTMAP_device_map) {
135                 printk("GNTMAP_device_map is not supported yet 0x%x\n", flags);
136                 BUG();  /* not yet. actually this flag is not used. */
137         } else {
138                 BUG();
139         }
140 }
141
142 int
143 HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
144 {
145         if (cmd == GNTTABOP_map_grant_ref) {
146                 unsigned int i;
147                 for (i = 0; i < count; i++) {
148                         gnttab_map_grant_ref_pre(
149                                 (struct gnttab_map_grant_ref *)uop + i);
150                 }
151         }
152         return xencomm_hypercall_grant_table_op(cmd, uop, count);
153 }
154
155 EXPORT_SYMBOL(HYPERVISOR_grant_table_op);