1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Talks to Xen Store to figure out what devices we have.
*
* Copyright (C) 2005 Rusty Russell, IBM Corporation
* Copyright (C) 2005 Mike Wray, Hewlett-Packard
* Copyright (C) 2005 XenSource Ltd
*
* This file may be distributed separately from the Linux kernel, or
* incorporated into other software packages, subject to the following license:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this source file (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifdef XPV_HVM_DRIVER
#include <sys/xpv_support.h>
#endif
#include <sys/hypervisor.h>
#include <xen/sys/xenbus_impl.h>
#include <xen/sys/xenbus_comms.h>
#include <xen/public/io/xs_wire.h>
static int
read_otherend_details(struct xenbus_device *xendev,
char *id_node, char *path_node)
{
int err = xenbus_gather(XBT_NULL, xendev->nodename,
id_node, "%i", &xendev->otherend_id, path_node, NULL,
&xendev->otherend, NULL);
if (err) {
xenbus_dev_fatal(xendev, err,
"reading other end details from %s", xendev->nodename);
return (err);
}
if (strlen(xendev->otherend) == 0 ||
!xenbus_exists_dir(xendev->otherend, "")) {
xenbus_dev_fatal(xendev, X_ENOENT, "missing other end from %s",
xendev->nodename);
kmem_free((void *)xendev->otherend,
strlen(xendev->otherend) + 1);
xendev->otherend = NULL;
return (X_ENOENT);
}
return (0);
}
static int
read_backend_details(struct xenbus_device *xendev)
{
return (read_otherend_details(xendev, "backend-id", "backend"));
}
static int
read_frontend_details(struct xenbus_device *xendev)
{
return (read_otherend_details(xendev, "frontend-id", "frontend"));
}
static void
free_otherend_details(struct xenbus_device *dev)
{
if (dev->otherend != NULL) {
kmem_free((void *)dev->otherend, strlen(dev->otherend) + 1);
dev->otherend = NULL;
}
}
static void
free_otherend_watch(struct xenbus_device *dev)
{
if (dev->otherend_watch.node) {
unregister_xenbus_watch(&dev->otherend_watch);
kmem_free((void *)dev->otherend_watch.node,
strlen(dev->otherend_watch.node) + 1);
dev->otherend_watch.node = NULL;
}
}
/*ARGSUSED2*/
static void
otherend_changed(struct xenbus_watch *watch, const char **vec, unsigned int len)
{
struct xenbus_device *dev = watch->dev;
XenbusState state;
/*
* Protect us against watches firing on old details when the otherend
* details change, say immediately after a resume.
*/
if (!dev->otherend ||
strncmp(dev->otherend, vec[XS_WATCH_PATH], strlen(dev->otherend))) {
#if 0
printf("Ignoring watch at %s", vec[XS_WATCH_PATH]);
#endif
return;
}
state = xenbus_read_driver_state(dev->otherend);
#if 0
printf("state is %d, %s, %s",
state, dev->otherend_watch.node, vec[XS_WATCH_PATH]);
#endif
if (dev->otherend_changed)
dev->otherend_changed(dev, state);
}
int
talk_to_otherend(struct xenbus_device *dev)
{
int err;
free_otherend_watch(dev);
free_otherend_details(dev);
if (dev->frontend)
err = read_backend_details(dev);
else
err = read_frontend_details(dev);
if (err)
return (err);
dev->otherend_watch.dev = dev;
return (xenbus_watch_path2(dev, dev->otherend, "state",
&dev->otherend_watch, otherend_changed));
}
/*
* Local variables:
* c-file-style: "solaris"
* indent-tabs-mode: t
* c-indent-level: 8
* c-basic-offset: 8
* tab-width: 8
* End:
*/
|