aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/ia64/include/asm/xen/grant_table.h29
-rw-r--r--arch/ia64/xen/grant-table.c62
-rw-r--r--arch/x86/include/asm/xen/grant_table.h7
-rw-r--r--arch/x86/xen/grant-table.c2
-rw-r--r--drivers/block/xen-blkback/common.h5
-rw-r--r--drivers/block/xen-blkback/xenbus.c54
-rw-r--r--drivers/net/xen-netback/common.h11
-rw-r--r--drivers/net/xen-netback/netback.c80
-rw-r--r--drivers/xen/xenbus/xenbus_client.c6
-rw-r--r--include/xen/grant_table.h1
10 files changed, 34 insertions, 223 deletions
diff --git a/arch/ia64/include/asm/xen/grant_table.h b/arch/ia64/include/asm/xen/grant_table.h
deleted file mode 100644
index 2b1fae0e2d11..000000000000
--- a/arch/ia64/include/asm/xen/grant_table.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/******************************************************************************
2 * arch/ia64/include/asm/xen/grant_table.h
3 *
4 * Copyright (c) 2008 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#ifndef _ASM_IA64_XEN_GRANT_TABLE_H
24#define _ASM_IA64_XEN_GRANT_TABLE_H
25
26struct vm_struct *xen_alloc_vm_area(unsigned long size);
27void xen_free_vm_area(struct vm_struct *area);
28
29#endif /* _ASM_IA64_XEN_GRANT_TABLE_H */
diff --git a/arch/ia64/xen/grant-table.c b/arch/ia64/xen/grant-table.c
index 48cca37625eb..c18281332f84 100644
--- a/arch/ia64/xen/grant-table.c
+++ b/arch/ia64/xen/grant-table.c
@@ -31,68 +31,6 @@
31 31
32#include <asm/xen/hypervisor.h> 32#include <asm/xen/hypervisor.h>
33 33
34struct vm_struct *xen_alloc_vm_area(unsigned long size)
35{
36 int order;
37 unsigned long virt;
38 unsigned long nr_pages;
39 struct vm_struct *area;
40
41 order = get_order(size);
42 virt = __get_free_pages(GFP_KERNEL, order);
43 if (virt == 0)
44 goto err0;
45 nr_pages = 1 << order;
46 scrub_pages(virt, nr_pages);
47
48 area = kmalloc(sizeof(*area), GFP_KERNEL);
49 if (area == NULL)
50 goto err1;
51
52 area->flags = VM_IOREMAP;
53 area->addr = (void *)virt;
54 area->size = size;
55 area->pages = NULL;
56 area->nr_pages = nr_pages;
57 area->phys_addr = 0; /* xenbus_map_ring_valloc uses this field! */
58
59 return area;
60
61err1:
62 free_pages(virt, order);
63err0:
64 return NULL;
65}
66EXPORT_SYMBOL_GPL(xen_alloc_vm_area);
67
68void xen_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}
93EXPORT_SYMBOL_GPL(xen_free_vm_area);
94
95
96/**************************************************************************** 34/****************************************************************************
97 * grant table hack 35 * grant table hack
98 * cmd: GNTTABOP_xxx 36 * cmd: GNTTABOP_xxx
diff --git a/arch/x86/include/asm/xen/grant_table.h b/arch/x86/include/asm/xen/grant_table.h
deleted file mode 100644
index fdbbb45767a6..000000000000
--- a/arch/x86/include/asm/xen/grant_table.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef _ASM_X86_XEN_GRANT_TABLE_H
2#define _ASM_X86_XEN_GRANT_TABLE_H
3
4#define xen_alloc_vm_area(size) alloc_vm_area(size)
5#define xen_free_vm_area(area) free_vm_area(area)
6
7#endif /* _ASM_X86_XEN_GRANT_TABLE_H */
diff --git a/arch/x86/xen/grant-table.c b/arch/x86/xen/grant-table.c
index 49ba9b5224d1..6bbfd7ac5e81 100644
--- a/arch/x86/xen/grant-table.c
+++ b/arch/x86/xen/grant-table.c
@@ -71,7 +71,7 @@ int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
71 71
72 if (shared == NULL) { 72 if (shared == NULL) {
73 struct vm_struct *area = 73 struct vm_struct *area =
74 xen_alloc_vm_area(PAGE_SIZE * max_nr_gframes); 74 alloc_vm_area(PAGE_SIZE * max_nr_gframes);
75 BUG_ON(area == NULL); 75 BUG_ON(area == NULL);
76 shared = area->addr; 76 shared = area->addr;
77 *__shared = shared; 77 *__shared = shared;
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
index de09f525d6c1..dfb1b3a43a5d 100644
--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -170,7 +170,7 @@ struct xen_blkif {
170 enum blkif_protocol blk_protocol; 170 enum blkif_protocol blk_protocol;
171 enum blkif_backend_type blk_backend_type; 171 enum blkif_backend_type blk_backend_type;
172 union blkif_back_rings blk_rings; 172 union blkif_back_rings blk_rings;
173 struct vm_struct *blk_ring_area; 173 void *blk_ring;
174 /* The VBD attached to this interface. */ 174 /* The VBD attached to this interface. */
175 struct xen_vbd vbd; 175 struct xen_vbd vbd;
176 /* Back pointer to the backend_info. */ 176 /* Back pointer to the backend_info. */
@@ -198,9 +198,6 @@ struct xen_blkif {
198 int st_wr_sect; 198 int st_wr_sect;
199 199
200 wait_queue_head_t waiting_to_free; 200 wait_queue_head_t waiting_to_free;
201
202 grant_handle_t shmem_handle;
203 grant_ref_t shmem_ref;
204}; 201};
205 202
206 203
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index 2c008afe63d9..f759ad4584c3 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -122,38 +122,6 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
122 return blkif; 122 return blkif;
123} 123}
124 124
125static int map_frontend_page(struct xen_blkif *blkif, unsigned long shared_page)
126{
127 struct gnttab_map_grant_ref op;
128
129 gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr,
130 GNTMAP_host_map, shared_page, blkif->domid);
131
132 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
133 BUG();
134
135 if (op.status) {
136 DPRINTK("Grant table operation failure !\n");
137 return op.status;
138 }
139
140 blkif->shmem_ref = shared_page;
141 blkif->shmem_handle = op.handle;
142
143 return 0;
144}
145
146static void unmap_frontend_page(struct xen_blkif *blkif)
147{
148 struct gnttab_unmap_grant_ref op;
149
150 gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr,
151 GNTMAP_host_map, blkif->shmem_handle);
152
153 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
154 BUG();
155}
156
157static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, 125static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
158 unsigned int evtchn) 126 unsigned int evtchn)
159{ 127{
@@ -163,35 +131,29 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
163 if (blkif->irq) 131 if (blkif->irq)
164 return 0; 132 return 0;
165 133
166 blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE); 134 err = xenbus_map_ring_valloc(blkif->be->dev, shared_page, &blkif->blk_ring);
167 if (!blkif->blk_ring_area) 135 if (err < 0)
168 return -ENOMEM;
169
170 err = map_frontend_page(blkif, shared_page);
171 if (err) {
172 free_vm_area(blkif->blk_ring_area);
173 return err; 136 return err;
174 }
175 137
176 switch (blkif->blk_protocol) { 138 switch (blkif->blk_protocol) {
177 case BLKIF_PROTOCOL_NATIVE: 139 case BLKIF_PROTOCOL_NATIVE:
178 { 140 {
179 struct blkif_sring *sring; 141 struct blkif_sring *sring;
180 sring = (struct blkif_sring *)blkif->blk_ring_area->addr; 142 sring = (struct blkif_sring *)blkif->blk_ring;
181 BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE); 143 BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE);
182 break; 144 break;
183 } 145 }
184 case BLKIF_PROTOCOL_X86_32: 146 case BLKIF_PROTOCOL_X86_32:
185 { 147 {
186 struct blkif_x86_32_sring *sring_x86_32; 148 struct blkif_x86_32_sring *sring_x86_32;
187 sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring_area->addr; 149 sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring;
188 BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE); 150 BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE);
189 break; 151 break;
190 } 152 }
191 case BLKIF_PROTOCOL_X86_64: 153 case BLKIF_PROTOCOL_X86_64:
192 { 154 {
193 struct blkif_x86_64_sring *sring_x86_64; 155 struct blkif_x86_64_sring *sring_x86_64;
194 sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring_area->addr; 156 sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring;
195 BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE); 157 BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE);
196 break; 158 break;
197 } 159 }
@@ -203,8 +165,7 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
203 xen_blkif_be_int, 0, 165 xen_blkif_be_int, 0,
204 "blkif-backend", blkif); 166 "blkif-backend", blkif);
205 if (err < 0) { 167 if (err < 0) {
206 unmap_frontend_page(blkif); 168 xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring);
207 free_vm_area(blkif->blk_ring_area);
208 blkif->blk_rings.common.sring = NULL; 169 blkif->blk_rings.common.sring = NULL;
209 return err; 170 return err;
210 } 171 }
@@ -230,8 +191,7 @@ static void xen_blkif_disconnect(struct xen_blkif *blkif)
230 } 191 }
231 192
232 if (blkif->blk_rings.common.sring) { 193 if (blkif->blk_rings.common.sring) {
233 unmap_frontend_page(blkif); 194 xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring);
234 free_vm_area(blkif->blk_ring_area);
235 blkif->blk_rings.common.sring = NULL; 195 blkif->blk_rings.common.sring = NULL;
236 } 196 }
237} 197}
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 161f207786a4..94b79c3338c4 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -58,10 +58,6 @@ struct xenvif {
58 u8 fe_dev_addr[6]; 58 u8 fe_dev_addr[6];
59 59
60 /* Physical parameters of the comms window. */ 60 /* Physical parameters of the comms window. */
61 grant_handle_t tx_shmem_handle;
62 grant_ref_t tx_shmem_ref;
63 grant_handle_t rx_shmem_handle;
64 grant_ref_t rx_shmem_ref;
65 unsigned int irq; 61 unsigned int irq;
66 62
67 /* List of frontends to notify after a batch of frames sent. */ 63 /* List of frontends to notify after a batch of frames sent. */
@@ -70,8 +66,6 @@ struct xenvif {
70 /* The shared rings and indexes. */ 66 /* The shared rings and indexes. */
71 struct xen_netif_tx_back_ring tx; 67 struct xen_netif_tx_back_ring tx;
72 struct xen_netif_rx_back_ring rx; 68 struct xen_netif_rx_back_ring rx;
73 struct vm_struct *tx_comms_area;
74 struct vm_struct *rx_comms_area;
75 69
76 /* Frontend feature information. */ 70 /* Frontend feature information. */
77 u8 can_sg:1; 71 u8 can_sg:1;
@@ -106,6 +100,11 @@ struct xenvif {
106 wait_queue_head_t waiting_to_free; 100 wait_queue_head_t waiting_to_free;
107}; 101};
108 102
103static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)
104{
105 return to_xenbus_device(vif->dev->dev.parent);
106}
107
109#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) 108#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE)
110#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) 109#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)
111 110
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index d5508957200e..0cb594c86090 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1589,88 +1589,42 @@ static int xen_netbk_kthread(void *data)
1589 1589
1590void xen_netbk_unmap_frontend_rings(struct xenvif *vif) 1590void xen_netbk_unmap_frontend_rings(struct xenvif *vif)
1591{ 1591{
1592 struct gnttab_unmap_grant_ref op; 1592 if (vif->tx.sring)
1593 1593 xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
1594 if (vif->tx.sring) { 1594 vif->tx.sring);
1595 gnttab_set_unmap_op(&op, (unsigned long)vif->tx_comms_area->addr, 1595 if (vif->rx.sring)
1596 GNTMAP_host_map, vif->tx_shmem_handle); 1596 xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
1597 1597 vif->rx.sring);
1598 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
1599 BUG();
1600 }
1601
1602 if (vif->rx.sring) {
1603 gnttab_set_unmap_op(&op, (unsigned long)vif->rx_comms_area->addr,
1604 GNTMAP_host_map, vif->rx_shmem_handle);
1605
1606 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
1607 BUG();
1608 }
1609 if (vif->rx_comms_area)
1610 free_vm_area(vif->rx_comms_area);
1611 if (vif->tx_comms_area)
1612 free_vm_area(vif->tx_comms_area);
1613} 1598}
1614 1599
1615int xen_netbk_map_frontend_rings(struct xenvif *vif, 1600int xen_netbk_map_frontend_rings(struct xenvif *vif,
1616 grant_ref_t tx_ring_ref, 1601 grant_ref_t tx_ring_ref,
1617 grant_ref_t rx_ring_ref) 1602 grant_ref_t rx_ring_ref)
1618{ 1603{
1619 struct gnttab_map_grant_ref op; 1604 void *addr;
1620 struct xen_netif_tx_sring *txs; 1605 struct xen_netif_tx_sring *txs;
1621 struct xen_netif_rx_sring *rxs; 1606 struct xen_netif_rx_sring *rxs;
1622 1607
1623 int err = -ENOMEM; 1608 int err = -ENOMEM;
1624 1609
1625 vif->tx_comms_area = alloc_vm_area(PAGE_SIZE); 1610 err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
1626 if (vif->tx_comms_area == NULL) 1611 tx_ring_ref, &addr);
1612 if (err)
1627 goto err; 1613 goto err;
1628 1614
1629 vif->rx_comms_area = alloc_vm_area(PAGE_SIZE); 1615 txs = (struct xen_netif_tx_sring *)addr;
1630 if (vif->rx_comms_area == NULL)
1631 goto err;
1632
1633 gnttab_set_map_op(&op, (unsigned long)vif->tx_comms_area->addr,
1634 GNTMAP_host_map, tx_ring_ref, vif->domid);
1635
1636 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
1637 BUG();
1638
1639 if (op.status) {
1640 netdev_warn(vif->dev,
1641 "failed to map tx ring. err=%d status=%d\n",
1642 err, op.status);
1643 err = op.status;
1644 goto err;
1645 }
1646
1647 vif->tx_shmem_ref = tx_ring_ref;
1648 vif->tx_shmem_handle = op.handle;
1649
1650 txs = (struct xen_netif_tx_sring *)vif->tx_comms_area->addr;
1651 BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE); 1616 BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE);
1652 1617
1653 gnttab_set_map_op(&op, (unsigned long)vif->rx_comms_area->addr, 1618 err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
1654 GNTMAP_host_map, rx_ring_ref, vif->domid); 1619 rx_ring_ref, &addr);
1655 1620 if (err)
1656 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
1657 BUG();
1658
1659 if (op.status) {
1660 netdev_warn(vif->dev,
1661 "failed to map rx ring. err=%d status=%d\n",
1662 err, op.status);
1663 err = op.status;
1664 goto err; 1621 goto err;
1665 }
1666
1667 vif->rx_shmem_ref = rx_ring_ref;
1668 vif->rx_shmem_handle = op.handle;
1669 vif->rx_req_cons_peek = 0;
1670 1622
1671 rxs = (struct xen_netif_rx_sring *)vif->rx_comms_area->addr; 1623 rxs = (struct xen_netif_rx_sring *)addr;
1672 BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE); 1624 BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE);
1673 1625
1626 vif->rx_req_cons_peek = 0;
1627
1674 return 0; 1628 return 0;
1675 1629
1676err: 1630err:
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index cdacf923e073..229d3adce85d 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -443,7 +443,7 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
443 443
444 *vaddr = NULL; 444 *vaddr = NULL;
445 445
446 area = xen_alloc_vm_area(PAGE_SIZE); 446 area = alloc_vm_area(PAGE_SIZE);
447 if (!area) 447 if (!area)
448 return -ENOMEM; 448 return -ENOMEM;
449 449
@@ -453,7 +453,7 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
453 BUG(); 453 BUG();
454 454
455 if (op.status != GNTST_okay) { 455 if (op.status != GNTST_okay) {
456 xen_free_vm_area(area); 456 free_vm_area(area);
457 xenbus_dev_fatal(dev, op.status, 457 xenbus_dev_fatal(dev, op.status,
458 "mapping in shared page %d from domain %d", 458 "mapping in shared page %d from domain %d",
459 gnt_ref, dev->otherend_id); 459 gnt_ref, dev->otherend_id);
@@ -552,7 +552,7 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
552 BUG(); 552 BUG();
553 553
554 if (op.status == GNTST_okay) 554 if (op.status == GNTST_okay)
555 xen_free_vm_area(area); 555 free_vm_area(area);
556 else 556 else
557 xenbus_dev_error(dev, op.status, 557 xenbus_dev_error(dev, op.status,
558 "unmapping page at handle %d error %d", 558 "unmapping page at handle %d error %d",
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 6b99bfbd785d..11e2dfce42f8 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -43,7 +43,6 @@
43#include <xen/interface/grant_table.h> 43#include <xen/interface/grant_table.h>
44 44
45#include <asm/xen/hypervisor.h> 45#include <asm/xen/hypervisor.h>
46#include <asm/xen/grant_table.h>
47 46
48#include <xen/features.h> 47#include <xen/features.h>
49 48