summaryrefslogtreecommitdiffstats
path: root/sys/xen/xenbus/xenbusb.h
blob: 75abb983c3a4c7bb8937e613aef4aa2949da2004 (plain)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*-
 * Core definitions and data structures shareable across OS platforms.
 *
 * Copyright (c) 2010 Spectra Logic Corporation
 * Copyright (C) 2008 Doug Rabson
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * $FreeBSD$
 */
#ifndef _XEN_XENBUS_XENBUSB_H
#define _XEN_XENBUS_XENBUSB_H

/**
 * \file xenbusb.h
 *
 * Datastructures and function declarations for use in implementing
 * bus attachements (e.g. frontend and backend device busses) for XenBus.
 */
#include "xenbusb_if.h"

/**
 * Enumeration of state flag values for the xbs_flags field of
 * the xenbusb_softc structure.
 */
typedef enum {
	/** */
	XBS_ATTACH_CH_ACTIVE = 0x01
} xenbusb_softc_flag;

/**
 * \brief Container for all state needed to manage a Xenbus Bus
 *	  attachment.
 */
struct xenbusb_softc {
	/**
	 * XenStore watch used to monitor the subtree of the
	 * XenStore where devices for this bus attachment arrive	
	 * and depart.
	 *
	 * \note This field must be the first in the softc structure
	 *       so that a simple cast can be used to retrieve the
	 *	 softc from within a XenStore watch event callback.
	 */
	struct xs_watch	        xbs_device_watch;

	/** Mutex used to protect fields of the xenbusb_softc. */
	struct mtx		xbs_lock;

	/** State flags. */
	xenbusb_softc_flag	xbs_flags;

	/**
	 * A dedicated task for processing child arrival and
	 * departure events.
	 */
	struct task		xbs_probe_children;

	/**
	 * Config Hook used to block boot processing until
	 * XenBus devices complete their connection processing
	 * with other VMs.
	 */
	struct intr_config_hook xbs_attach_ch;

	/**
	 * The number of children for this bus that are still
	 * in the connecting (to other VMs) state.  This variable
	 * is used to determine when to release xbs_attach_ch.
	 */
	u_int			xbs_connecting_children;

	/** The NewBus device_t for this bus attachment. */
	device_t		xbs_dev;

	/**
	 * The VM relative path to the XenStore subtree this
	 * bus attachment manages.
	 */
	const char	       *xbs_node;

	/**
	 * The number of path components (strings separated by the '/'
	 * character) that make up the device ID on this bus.
	 */
	u_int			xbs_id_components;	
};

/**
 * Enumeration of state flag values for the xbs_flags field of
 * the xenbusb_softc structure.
 */
typedef enum {

	/**
	 * This device is contributing to the xbs_connecting_children
	 * count of its parent bus.
	 */
	XDF_CONNECTING = 0x01
} xenbus_dev_flag;

/** Instance variables for devices on a XenBus bus. */
struct xenbus_device_ivars {
	/**
	 * XenStore watch used to monitor the subtree of the
	 * XenStore where information about the otherend of
	 * the split Xen device this device instance represents.
	 *
	 * \note This field must be the first in the instance
	 *	 variable structure so that a simple cast can be
	 *	 used to retrieve ivar data from within a XenStore
	 *	 watch event callback.
	 */
	struct xs_watch		xd_otherend_watch;

	/** Sleepable lock used to protect instance data. */
	struct sx		xd_lock;

	/** State flags. */
	xenbus_dev_flag		xd_flags;

	/** The NewBus device_t for this XenBus device instance. */
	device_t		xd_dev;

	/**
	 * The VM relative path to the XenStore subtree representing
	 * this VMs half of this device.
	 */
	char		       *xd_node;

	/** XenBus device type ("vbd", "vif", etc.). */
	char		       *xd_type;

	/**
	 * Cached version of <xd_node>/state node in the XenStore.
	 */
	enum xenbus_state	xd_state;

	/** The VM identifier of the other end of this split device. */
	int			xd_otherend_id;

	/**
	 * The path to the subtree of the XenStore where information
	 * about the otherend of this split device instance.
	 */
	char		       *xd_otherend_path;
};

/**
 * \brief Identify instances of this device type in the system.
 *
 * \param driver  The driver performing this identify action.
 * \param parent  The NewBus parent device for any devices this method adds.
 */
void xenbusb_identify(driver_t *driver __unused, device_t parent);

/**
 * \brief Perform common XenBus bus attach processing.
 *
 * \param dev            The NewBus device representing this XenBus bus.
 * \param bus_node       The XenStore path to the XenStore subtree for
 *                       this XenBus bus.
 * \param id_components  The number of '/' separated path components that
 *                       make up a unique device ID on this XenBus bus.
 *
 * \return  On success, 0. Otherwise an errno value indicating the
 *          type of failure.
 *
 * Intiailizes the softc for this bus, installs an interrupt driven
 * configuration hook to block boot processing until XenBus devices fully
 * configure, performs an initial probe/attach of the bus, and registers
 * a XenStore watch so we are notified when the bus topology changes.
 */
int xenbusb_attach(device_t dev, char *bus_node, u_int id_components);

/**
 * \brief Perform common XenBus bus resume handling.
 *
 * \param dev  The NewBus device representing this XenBus bus.
 *
 * \return  On success, 0. Otherwise an errno value indicating the
 *          type of failure.
 */
int xenbusb_resume(device_t dev);

/**
 * \brief Pretty-prints information about a child of a XenBus bus.
 *
 * \param dev    The NewBus device representing this XenBus bus.
 * \param child	 The NewBus device representing a child of dev%'s XenBus bus.
 *
 * \return  On success, 0. Otherwise an errno value indicating the
 *          type of failure.
 */
int xenbusb_print_child(device_t dev, device_t child);

/**
 * \brief Common XenBus child instance variable read access method.
 *
 * \param dev     The NewBus device representing this XenBus bus.
 * \param child	  The NewBus device representing a child of dev%'s XenBus bus.
 * \param index	  The index of the instance variable to access.
 * \param result  The value of the instance variable accessed.
 *
 * \return  On success, 0. Otherwise an errno value indicating the
 *          type of failure.
 */
int xenbusb_read_ivar(device_t dev, device_t child, int index,
		      uintptr_t *result);

/**
 * \brief Common XenBus child instance variable write access method.
 *
 * \param dev    The NewBus device representing this XenBus bus.
 * \param child	 The NewBus device representing a child of dev%'s XenBus bus.
 * \param index	 The index of the instance variable to access.
 * \param value  The new value to set in the instance variable accessed.
 *
 * \return  On success, 0. Otherwise an errno value indicating the
 *          type of failure.
 */
int xenbusb_write_ivar(device_t dev, device_t child, int index,
		       uintptr_t value);

/**
 * \brief Attempt to add a XenBus device instance to this XenBus bus.
 *
 * \param dev   The NewBus device representing this XenBus bus.
 * \param type  The device type being added (e.g. "vbd", "vif").
 * \param id	The device ID for this device.
 *
 * \return  On success, 0. Otherwise an errno value indicating the
 *          type of failure.  Failure indicates that either the
 *          path to this device no longer exists or insufficient
 *          information exists in the XenStore to create a new
 *          device.
 *
 * If successful, this routine will add a device_t with instance
 * variable storage to the NewBus device topology.  Probe/Attach
 * processing is not performed by this routine, but must be scheduled
 * via the xbs_probe_children task.  This separation of responsibilities
 * is required to avoid hanging up the XenStore event delivery thread
 * with our probe/attach work in the event a device is added via
 * a callback from the XenStore.
 */
int xenbusb_add_device(device_t dev, const char *type, const char *id);

#endif /* _XEN_XENBUS_XENBUSB_H */
OpenPOWER on IntegriCloud