ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c @ 13991:c4ed5b740a8d

linux: remove {lock,unlock}_vm_area(). Instead use vmalloc_sync_all()
in alloc_vm_area().
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Feb 16 11:24:10 2007 +0000 (2007-02-16)
parents 98a81d2ccf4c
children
line source
1 /******************************************************************************
2 * Backend-client-facing interface for the Xenbus driver. In other words, the
3 * interface between the Xenbus and the device-specific code in the backend
4 * driver.
5 *
6 * Copyright (C) 2005-2006 XenSource Ltd
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation; or, when distributed
11 * separately from the Linux kernel or incorporated into other
12 * software packages, subject to the following license:
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a copy
15 * of this source file (the "Software"), to deal in the Software without
16 * restriction, including without limitation the rights to use, copy, modify,
17 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18 * and to permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 * IN THE SOFTWARE.
31 */
33 #include <linux/err.h>
34 #include <xen/gnttab.h>
35 #include <xen/xenbus.h>
36 #include <xen/driver_util.h>
38 /* Based on Rusty Russell's skeleton driver's map_page */
39 struct vm_struct *xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref)
40 {
41 struct gnttab_map_grant_ref op;
42 struct vm_struct *area;
44 area = alloc_vm_area(PAGE_SIZE);
45 if (!area)
46 return ERR_PTR(-ENOMEM);
48 gnttab_set_map_op(&op, (unsigned long)area->addr, GNTMAP_host_map,
49 gnt_ref, dev->otherend_id);
51 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
52 BUG();
54 if (op.status != GNTST_okay) {
55 free_vm_area(area);
56 xenbus_dev_fatal(dev, op.status,
57 "mapping in shared page %d from domain %d",
58 gnt_ref, dev->otherend_id);
59 BUG_ON(!IS_ERR(ERR_PTR(op.status)));
60 return ERR_PTR(op.status);
61 }
63 /* Stuff the handle in an unused field */
64 area->phys_addr = (unsigned long)op.handle;
66 return area;
67 }
68 EXPORT_SYMBOL_GPL(xenbus_map_ring_valloc);
71 int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
72 grant_handle_t *handle, void *vaddr)
73 {
74 struct gnttab_map_grant_ref op;
76 gnttab_set_map_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
77 gnt_ref, dev->otherend_id);
78 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
79 BUG();
81 if (op.status != GNTST_okay) {
82 xenbus_dev_fatal(dev, op.status,
83 "mapping in shared page %d from domain %d",
84 gnt_ref, dev->otherend_id);
85 } else
86 *handle = op.handle;
88 return op.status;
89 }
90 EXPORT_SYMBOL_GPL(xenbus_map_ring);
93 /* Based on Rusty Russell's skeleton driver's unmap_page */
94 int xenbus_unmap_ring_vfree(struct xenbus_device *dev, struct vm_struct *area)
95 {
96 struct gnttab_unmap_grant_ref op;
98 gnttab_set_unmap_op(&op, (unsigned long)area->addr, GNTMAP_host_map,
99 (grant_handle_t)area->phys_addr);
101 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
102 BUG();
104 if (op.status == GNTST_okay)
105 free_vm_area(area);
106 else
107 xenbus_dev_error(dev, op.status,
108 "unmapping page at handle %d error %d",
109 (int16_t)area->phys_addr, op.status);
111 return op.status;
112 }
113 EXPORT_SYMBOL_GPL(xenbus_unmap_ring_vfree);
116 int xenbus_unmap_ring(struct xenbus_device *dev,
117 grant_handle_t handle, void *vaddr)
118 {
119 struct gnttab_unmap_grant_ref op;
121 gnttab_set_unmap_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
122 handle);
123 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
124 BUG();
126 if (op.status != GNTST_okay)
127 xenbus_dev_error(dev, op.status,
128 "unmapping page at handle %d error %d",
129 handle, op.status);
131 return op.status;
132 }
133 EXPORT_SYMBOL_GPL(xenbus_unmap_ring);
135 int xenbus_dev_is_online(struct xenbus_device *dev)
136 {
137 int rc, val;
139 rc = xenbus_scanf(XBT_NIL, dev->nodename, "online", "%d", &val);
140 if (rc != 1)
141 val = 0; /* no online node present */
143 return val;
144 }
145 EXPORT_SYMBOL_GPL(xenbus_dev_is_online);
147 MODULE_LICENSE("Dual BSD/GPL");