2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Core definitions and data structures shareable across OS platforms.
6 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
8 * Copyright (c) 2010 Spectra Logic Corporation
9 * Copyright (C) 2008 Doug Rabson
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGES.
39 #ifndef _XEN_XENBUS_XENBUSB_H
40 #define _XEN_XENBUS_XENBUSB_H
45 * Datastructures and function declarations for use in implementing
46 * bus attachements (e.g. frontend and backend device buses) for XenBus.
50 * Enumeration of state flag values for the xbs_flags field of
51 * the xenbusb_softc structure.
55 XBS_ATTACH_CH_ACTIVE = 0x01
59 * \brief Container for all state needed to manage a Xenbus Bus
62 struct xenbusb_softc {
64 * XenStore watch used to monitor the subtree of the
65 * XenStore where devices for this bus attachment arrive
68 struct xs_watch xbs_device_watch;
70 /** Mutex used to protect fields of the xenbusb_softc. */
74 xenbusb_softc_flag xbs_flags;
77 * A dedicated task for processing child arrival and
80 struct task xbs_probe_children;
83 * Config Hook used to block boot processing until
84 * XenBus devices complete their connection processing
87 struct intr_config_hook xbs_attach_ch;
90 * The number of children for this bus that are still
91 * in the connecting (to other VMs) state. This variable
92 * is used to determine when to release xbs_attach_ch.
94 u_int xbs_connecting_children;
96 /** The NewBus device_t for this bus attachment. */
100 * The VM relative path to the XenStore subtree this
101 * bus attachment manages.
103 const char *xbs_node;
106 * The number of path components (strings separated by the '/'
107 * character) that make up the device ID on this bus.
109 u_int xbs_id_components;
113 * Enumeration of state flag values for the xbs_flags field of
114 * the xenbusb_softc structure.
119 * This device is contributing to the xbs_connecting_children
120 * count of its parent bus.
122 XDF_CONNECTING = 0x01
125 /** Instance variables for devices on a XenBus bus. */
126 struct xenbus_device_ivars {
128 * XenStore watch used to monitor the subtree of the
129 * XenStore where information about the otherend of
130 * the split Xen device this device instance represents.
132 struct xs_watch xd_otherend_watch;
135 * XenStore watch used to monitor the XenStore sub-tree
136 * associated with this device. This watch will fire
137 * for modifications that we make from our domain as
138 * well as for those made by the control domain.
140 struct xs_watch xd_local_watch;
142 /** Sleepable lock used to protect instance data. */
146 xenbus_dev_flag xd_flags;
148 /** The NewBus device_t for this XenBus device instance. */
152 * The VM relative path to the XenStore subtree representing
153 * this VMs half of this device.
157 /** The length of xd_node. */
160 /** XenBus device type ("vbd", "vif", etc.). */
164 * Cached version of <xd_node>/state node in the XenStore.
166 enum xenbus_state xd_state;
168 /** The VM identifier of the other end of this split device. */
172 * The path to the subtree of the XenStore where information
173 * about the otherend of this split device instance.
175 char *xd_otherend_path;
177 /** The length of xd_otherend_path. */
178 int xd_otherend_path_len;
182 * \brief Identify instances of this device type in the system.
184 * \param driver The driver performing this identify action.
185 * \param parent The NewBus parent device for any devices this method adds.
187 void xenbusb_identify(driver_t *driver __unused, device_t parent);
190 * \brief Perform common XenBus bus attach processing.
192 * \param dev The NewBus device representing this XenBus bus.
193 * \param bus_node The XenStore path to the XenStore subtree for
195 * \param id_components The number of '/' separated path components that
196 * make up a unique device ID on this XenBus bus.
198 * \return On success, 0. Otherwise an errno value indicating the
201 * Intiailizes the softc for this bus, installs an interrupt driven
202 * configuration hook to block boot processing until XenBus devices fully
203 * configure, performs an initial probe/attach of the bus, and registers
204 * a XenStore watch so we are notified when the bus topology changes.
206 int xenbusb_attach(device_t dev, char *bus_node, u_int id_components);
209 * \brief Perform common XenBus bus resume handling.
211 * \param dev The NewBus device representing this XenBus bus.
213 * \return On success, 0. Otherwise an errno value indicating the
216 int xenbusb_resume(device_t dev);
219 * \brief Pretty-prints information about a child of a XenBus bus.
221 * \param dev The NewBus device representing this XenBus bus.
222 * \param child The NewBus device representing a child of dev%'s XenBus bus.
224 * \return On success, 0. Otherwise an errno value indicating the
227 int xenbusb_print_child(device_t dev, device_t child);
230 * \brief Common XenBus child instance variable read access method.
232 * \param dev The NewBus device representing this XenBus bus.
233 * \param child The NewBus device representing a child of dev%'s XenBus bus.
234 * \param index The index of the instance variable to access.
235 * \param result The value of the instance variable accessed.
237 * \return On success, 0. Otherwise an errno value indicating the
240 int xenbusb_read_ivar(device_t dev, device_t child, int index,
244 * \brief Common XenBus child instance variable write access method.
246 * \param dev The NewBus device representing this XenBus bus.
247 * \param child The NewBus device representing a child of dev%'s XenBus bus.
248 * \param index The index of the instance variable to access.
249 * \param value The new value to set in the instance variable accessed.
251 * \return On success, 0. Otherwise an errno value indicating the
254 int xenbusb_write_ivar(device_t dev, device_t child, int index,
258 * \brief Common XenBus method implementing responses to peer state changes.
260 * \param bus The XenBus bus parent of child.
261 * \param child The XenBus child whose peer stat has changed.
262 * \param state The current state of the peer.
264 void xenbusb_otherend_changed(device_t bus, device_t child,
265 enum xenbus_state state);
268 * \brief Common XenBus method implementing responses to local XenStore changes.
270 * \param bus The XenBus bus parent of child.
271 * \param child The XenBus child whose peer stat has changed.
272 * \param path The tree relative sub-path to the modified node. The empty
273 * string indicates the root of the tree was destroyed.
275 void xenbusb_localend_changed(device_t bus, device_t child, const char *path);
278 * \brief Attempt to add a XenBus device instance to this XenBus bus.
280 * \param dev The NewBus device representing this XenBus bus.
281 * \param type The device type being added (e.g. "vbd", "vif").
282 * \param id The device ID for this device.
284 * \return On success, 0. Otherwise an errno value indicating the
285 * type of failure. Failure indicates that either the
286 * path to this device no longer exists or insufficient
287 * information exists in the XenStore to create a new
290 * If successful, this routine will add a device_t with instance
291 * variable storage to the NewBus device topology. Probe/Attach
292 * processing is not performed by this routine, but must be scheduled
293 * via the xbs_probe_children task. This separation of responsibilities
294 * is required to avoid hanging up the XenStore event delivery thread
295 * with our probe/attach work in the event a device is added via
296 * a callback from the XenStore.
298 int xenbusb_add_device(device_t dev, const char *type, const char *id);
300 #include "xenbusb_if.h"
302 #endif /* _XEN_XENBUS_XENBUSB_H */