xref: /freebsd/sys/xen/xenbus/xenbusb.h (revision 283d6f7287515a67a3cf38b2a76101ca15380d14)
1ff662b5cSJustin T. Gibbs /*-
2ff662b5cSJustin T. Gibbs  * Core definitions and data structures shareable across OS platforms.
3ff662b5cSJustin T. Gibbs  *
4ff662b5cSJustin T. Gibbs  * Copyright (c) 2010 Spectra Logic Corporation
5ff662b5cSJustin T. Gibbs  * Copyright (C) 2008 Doug Rabson
6ff662b5cSJustin T. Gibbs  * All rights reserved.
7ff662b5cSJustin T. Gibbs  *
8ff662b5cSJustin T. Gibbs  * Redistribution and use in source and binary forms, with or without
9ff662b5cSJustin T. Gibbs  * modification, are permitted provided that the following conditions
10ff662b5cSJustin T. Gibbs  * are met:
11ff662b5cSJustin T. Gibbs  * 1. Redistributions of source code must retain the above copyright
12ff662b5cSJustin T. Gibbs  *    notice, this list of conditions, and the following disclaimer,
13ff662b5cSJustin T. Gibbs  *    without modification.
14ff662b5cSJustin T. Gibbs  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15ff662b5cSJustin T. Gibbs  *    substantially similar to the "NO WARRANTY" disclaimer below
16ff662b5cSJustin T. Gibbs  *    ("Disclaimer") and any redistribution must be conditioned upon
17ff662b5cSJustin T. Gibbs  *    including a substantially similar Disclaimer requirement for further
18ff662b5cSJustin T. Gibbs  *    binary redistribution.
19ff662b5cSJustin T. Gibbs  *
20ff662b5cSJustin T. Gibbs  * NO WARRANTY
21ff662b5cSJustin T. Gibbs  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22ff662b5cSJustin T. Gibbs  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23ff662b5cSJustin T. Gibbs  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
24ff662b5cSJustin T. Gibbs  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25ff662b5cSJustin T. Gibbs  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26ff662b5cSJustin T. Gibbs  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27ff662b5cSJustin T. Gibbs  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28ff662b5cSJustin T. Gibbs  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29ff662b5cSJustin T. Gibbs  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30ff662b5cSJustin T. Gibbs  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31ff662b5cSJustin T. Gibbs  * POSSIBILITY OF SUCH DAMAGES.
32ff662b5cSJustin T. Gibbs  *
33ff662b5cSJustin T. Gibbs  * $FreeBSD$
34ff662b5cSJustin T. Gibbs  */
35ff662b5cSJustin T. Gibbs #ifndef _XEN_XENBUS_XENBUSB_H
36ff662b5cSJustin T. Gibbs #define _XEN_XENBUS_XENBUSB_H
37ff662b5cSJustin T. Gibbs 
38ff662b5cSJustin T. Gibbs /**
39ff662b5cSJustin T. Gibbs  * \file xenbusb.h
40ff662b5cSJustin T. Gibbs  *
41ff662b5cSJustin T. Gibbs  * Datastructures and function declarations for use in implementing
42ff662b5cSJustin T. Gibbs  * bus attachements (e.g. frontend and backend device busses) for XenBus.
43ff662b5cSJustin T. Gibbs  */
44ff662b5cSJustin T. Gibbs 
45ff662b5cSJustin T. Gibbs /**
46ff662b5cSJustin T. Gibbs  * Enumeration of state flag values for the xbs_flags field of
47ff662b5cSJustin T. Gibbs  * the xenbusb_softc structure.
48ff662b5cSJustin T. Gibbs  */
49ff662b5cSJustin T. Gibbs typedef enum {
50ff662b5cSJustin T. Gibbs 	/** */
51ff662b5cSJustin T. Gibbs 	XBS_ATTACH_CH_ACTIVE = 0x01
52ff662b5cSJustin T. Gibbs } xenbusb_softc_flag;
53ff662b5cSJustin T. Gibbs 
54ff662b5cSJustin T. Gibbs /**
55ff662b5cSJustin T. Gibbs  * \brief Container for all state needed to manage a Xenbus Bus
56ff662b5cSJustin T. Gibbs  *	  attachment.
57ff662b5cSJustin T. Gibbs  */
58ff662b5cSJustin T. Gibbs struct xenbusb_softc {
59ff662b5cSJustin T. Gibbs 	/**
60ff662b5cSJustin T. Gibbs 	 * XenStore watch used to monitor the subtree of the
61ff662b5cSJustin T. Gibbs 	 * XenStore where devices for this bus attachment arrive
62ff662b5cSJustin T. Gibbs 	 * and depart.
63ff662b5cSJustin T. Gibbs 	 */
64ff662b5cSJustin T. Gibbs 	struct xs_watch	        xbs_device_watch;
65ff662b5cSJustin T. Gibbs 
66ff662b5cSJustin T. Gibbs 	/** Mutex used to protect fields of the xenbusb_softc. */
67ff662b5cSJustin T. Gibbs 	struct mtx		xbs_lock;
68ff662b5cSJustin T. Gibbs 
69ff662b5cSJustin T. Gibbs 	/** State flags. */
70ff662b5cSJustin T. Gibbs 	xenbusb_softc_flag	xbs_flags;
71ff662b5cSJustin T. Gibbs 
72ff662b5cSJustin T. Gibbs 	/**
73ff662b5cSJustin T. Gibbs 	 * A dedicated task for processing child arrival and
74ff662b5cSJustin T. Gibbs 	 * departure events.
75ff662b5cSJustin T. Gibbs 	 */
76ff662b5cSJustin T. Gibbs 	struct task		xbs_probe_children;
77ff662b5cSJustin T. Gibbs 
78ff662b5cSJustin T. Gibbs 	/**
79ff662b5cSJustin T. Gibbs 	 * Config Hook used to block boot processing until
80ff662b5cSJustin T. Gibbs 	 * XenBus devices complete their connection processing
81ff662b5cSJustin T. Gibbs 	 * with other VMs.
82ff662b5cSJustin T. Gibbs 	 */
83ff662b5cSJustin T. Gibbs 	struct intr_config_hook xbs_attach_ch;
84ff662b5cSJustin T. Gibbs 
85ff662b5cSJustin T. Gibbs 	/**
86ff662b5cSJustin T. Gibbs 	 * The number of children for this bus that are still
87ff662b5cSJustin T. Gibbs 	 * in the connecting (to other VMs) state.  This variable
88ff662b5cSJustin T. Gibbs 	 * is used to determine when to release xbs_attach_ch.
89ff662b5cSJustin T. Gibbs 	 */
90ff662b5cSJustin T. Gibbs 	u_int			xbs_connecting_children;
91ff662b5cSJustin T. Gibbs 
92ff662b5cSJustin T. Gibbs 	/** The NewBus device_t for this bus attachment. */
93ff662b5cSJustin T. Gibbs 	device_t		xbs_dev;
94ff662b5cSJustin T. Gibbs 
95ff662b5cSJustin T. Gibbs 	/**
96ff662b5cSJustin T. Gibbs 	 * The VM relative path to the XenStore subtree this
97ff662b5cSJustin T. Gibbs 	 * bus attachment manages.
98ff662b5cSJustin T. Gibbs 	 */
99ff662b5cSJustin T. Gibbs 	const char	       *xbs_node;
100ff662b5cSJustin T. Gibbs 
101ff662b5cSJustin T. Gibbs 	/**
102ff662b5cSJustin T. Gibbs 	 * The number of path components (strings separated by the '/'
103ff662b5cSJustin T. Gibbs 	 * character) that make up the device ID on this bus.
104ff662b5cSJustin T. Gibbs 	 */
105ff662b5cSJustin T. Gibbs 	u_int			xbs_id_components;
106ff662b5cSJustin T. Gibbs };
107ff662b5cSJustin T. Gibbs 
108ff662b5cSJustin T. Gibbs /**
109ff662b5cSJustin T. Gibbs  * Enumeration of state flag values for the xbs_flags field of
110ff662b5cSJustin T. Gibbs  * the xenbusb_softc structure.
111ff662b5cSJustin T. Gibbs  */
112ff662b5cSJustin T. Gibbs typedef enum {
113ff662b5cSJustin T. Gibbs 
114ff662b5cSJustin T. Gibbs 	/**
115ff662b5cSJustin T. Gibbs 	 * This device is contributing to the xbs_connecting_children
116ff662b5cSJustin T. Gibbs 	 * count of its parent bus.
117ff662b5cSJustin T. Gibbs 	 */
118ff662b5cSJustin T. Gibbs 	XDF_CONNECTING = 0x01
119ff662b5cSJustin T. Gibbs } xenbus_dev_flag;
120ff662b5cSJustin T. Gibbs 
121ff662b5cSJustin T. Gibbs /** Instance variables for devices on a XenBus bus. */
122ff662b5cSJustin T. Gibbs struct xenbus_device_ivars {
123ff662b5cSJustin T. Gibbs 	/**
124ff662b5cSJustin T. Gibbs 	 * XenStore watch used to monitor the subtree of the
125ff662b5cSJustin T. Gibbs 	 * XenStore where information about the otherend of
126ff662b5cSJustin T. Gibbs 	 * the split Xen device this device instance represents.
127ff662b5cSJustin T. Gibbs 	 */
128ff662b5cSJustin T. Gibbs 	struct xs_watch		xd_otherend_watch;
129ff662b5cSJustin T. Gibbs 
130*283d6f72SJustin T. Gibbs 	/**
131*283d6f72SJustin T. Gibbs 	 * XenStore watch used to monitor the XenStore sub-tree
132*283d6f72SJustin T. Gibbs 	 * associated with this device.  This watch will fire
133*283d6f72SJustin T. Gibbs 	 * for modifications that we make from our domain as
134*283d6f72SJustin T. Gibbs 	 * well as for those made by the control domain.
135*283d6f72SJustin T. Gibbs 	 */
136*283d6f72SJustin T. Gibbs 	struct xs_watch		xd_local_watch;
137*283d6f72SJustin T. Gibbs 
138ff662b5cSJustin T. Gibbs 	/** Sleepable lock used to protect instance data. */
139ff662b5cSJustin T. Gibbs 	struct sx		xd_lock;
140ff662b5cSJustin T. Gibbs 
141ff662b5cSJustin T. Gibbs 	/** State flags. */
142ff662b5cSJustin T. Gibbs 	xenbus_dev_flag		xd_flags;
143ff662b5cSJustin T. Gibbs 
144ff662b5cSJustin T. Gibbs 	/** The NewBus device_t for this XenBus device instance. */
145ff662b5cSJustin T. Gibbs 	device_t		xd_dev;
146ff662b5cSJustin T. Gibbs 
147ff662b5cSJustin T. Gibbs 	/**
148ff662b5cSJustin T. Gibbs 	 * The VM relative path to the XenStore subtree representing
149ff662b5cSJustin T. Gibbs 	 * this VMs half of this device.
150ff662b5cSJustin T. Gibbs 	 */
151ff662b5cSJustin T. Gibbs 	char		       *xd_node;
152ff662b5cSJustin T. Gibbs 
153*283d6f72SJustin T. Gibbs 	/** The length of xd_node.  */
154*283d6f72SJustin T. Gibbs 	int			xd_node_len;
155*283d6f72SJustin T. Gibbs 
156ff662b5cSJustin T. Gibbs 	/** XenBus device type ("vbd", "vif", etc.). */
157ff662b5cSJustin T. Gibbs 	char		       *xd_type;
158ff662b5cSJustin T. Gibbs 
159ff662b5cSJustin T. Gibbs 	/**
160ff662b5cSJustin T. Gibbs 	 * Cached version of <xd_node>/state node in the XenStore.
161ff662b5cSJustin T. Gibbs 	 */
162ff662b5cSJustin T. Gibbs 	enum xenbus_state	xd_state;
163ff662b5cSJustin T. Gibbs 
164ff662b5cSJustin T. Gibbs 	/** The VM identifier of the other end of this split device. */
165ff662b5cSJustin T. Gibbs 	int			xd_otherend_id;
166ff662b5cSJustin T. Gibbs 
167ff662b5cSJustin T. Gibbs 	/**
168ff662b5cSJustin T. Gibbs 	 * The path to the subtree of the XenStore where information
169ff662b5cSJustin T. Gibbs 	 * about the otherend of this split device instance.
170ff662b5cSJustin T. Gibbs 	 */
171ff662b5cSJustin T. Gibbs 	char		       *xd_otherend_path;
172*283d6f72SJustin T. Gibbs 
173*283d6f72SJustin T. Gibbs 	/** The length of xd_otherend_path.  */
174*283d6f72SJustin T. Gibbs 	int			xd_otherend_path_len;
175ff662b5cSJustin T. Gibbs };
176ff662b5cSJustin T. Gibbs 
177ff662b5cSJustin T. Gibbs /**
178ff662b5cSJustin T. Gibbs  * \brief Identify instances of this device type in the system.
179ff662b5cSJustin T. Gibbs  *
180ff662b5cSJustin T. Gibbs  * \param driver  The driver performing this identify action.
181ff662b5cSJustin T. Gibbs  * \param parent  The NewBus parent device for any devices this method adds.
182ff662b5cSJustin T. Gibbs  */
183ff662b5cSJustin T. Gibbs void xenbusb_identify(driver_t *driver __unused, device_t parent);
184ff662b5cSJustin T. Gibbs 
185ff662b5cSJustin T. Gibbs /**
186ff662b5cSJustin T. Gibbs  * \brief Perform common XenBus bus attach processing.
187ff662b5cSJustin T. Gibbs  *
188ff662b5cSJustin T. Gibbs  * \param dev            The NewBus device representing this XenBus bus.
189ff662b5cSJustin T. Gibbs  * \param bus_node       The XenStore path to the XenStore subtree for
190ff662b5cSJustin T. Gibbs  *                       this XenBus bus.
191ff662b5cSJustin T. Gibbs  * \param id_components  The number of '/' separated path components that
192ff662b5cSJustin T. Gibbs  *                       make up a unique device ID on this XenBus bus.
193ff662b5cSJustin T. Gibbs  *
194ff662b5cSJustin T. Gibbs  * \return  On success, 0. Otherwise an errno value indicating the
195ff662b5cSJustin T. Gibbs  *          type of failure.
196ff662b5cSJustin T. Gibbs  *
197ff662b5cSJustin T. Gibbs  * Intiailizes the softc for this bus, installs an interrupt driven
198ff662b5cSJustin T. Gibbs  * configuration hook to block boot processing until XenBus devices fully
199ff662b5cSJustin T. Gibbs  * configure, performs an initial probe/attach of the bus, and registers
200ff662b5cSJustin T. Gibbs  * a XenStore watch so we are notified when the bus topology changes.
201ff662b5cSJustin T. Gibbs  */
202ff662b5cSJustin T. Gibbs int xenbusb_attach(device_t dev, char *bus_node, u_int id_components);
203ff662b5cSJustin T. Gibbs 
204ff662b5cSJustin T. Gibbs /**
205ff662b5cSJustin T. Gibbs  * \brief Perform common XenBus bus resume handling.
206ff662b5cSJustin T. Gibbs  *
207ff662b5cSJustin T. Gibbs  * \param dev  The NewBus device representing this XenBus bus.
208ff662b5cSJustin T. Gibbs  *
209ff662b5cSJustin T. Gibbs  * \return  On success, 0. Otherwise an errno value indicating the
210ff662b5cSJustin T. Gibbs  *          type of failure.
211ff662b5cSJustin T. Gibbs  */
212ff662b5cSJustin T. Gibbs int xenbusb_resume(device_t dev);
213ff662b5cSJustin T. Gibbs 
214ff662b5cSJustin T. Gibbs /**
215ff662b5cSJustin T. Gibbs  * \brief Pretty-prints information about a child of a XenBus bus.
216ff662b5cSJustin T. Gibbs  *
217ff662b5cSJustin T. Gibbs  * \param dev    The NewBus device representing this XenBus bus.
218ff662b5cSJustin T. Gibbs  * \param child	 The NewBus device representing a child of dev%'s XenBus bus.
219ff662b5cSJustin T. Gibbs  *
220ff662b5cSJustin T. Gibbs  * \return  On success, 0. Otherwise an errno value indicating the
221ff662b5cSJustin T. Gibbs  *          type of failure.
222ff662b5cSJustin T. Gibbs  */
223ff662b5cSJustin T. Gibbs int xenbusb_print_child(device_t dev, device_t child);
224ff662b5cSJustin T. Gibbs 
225ff662b5cSJustin T. Gibbs /**
226ff662b5cSJustin T. Gibbs  * \brief Common XenBus child instance variable read access method.
227ff662b5cSJustin T. Gibbs  *
228ff662b5cSJustin T. Gibbs  * \param dev     The NewBus device representing this XenBus bus.
229ff662b5cSJustin T. Gibbs  * \param child	  The NewBus device representing a child of dev%'s XenBus bus.
230ff662b5cSJustin T. Gibbs  * \param index	  The index of the instance variable to access.
231ff662b5cSJustin T. Gibbs  * \param result  The value of the instance variable accessed.
232ff662b5cSJustin T. Gibbs  *
233ff662b5cSJustin T. Gibbs  * \return  On success, 0. Otherwise an errno value indicating the
234ff662b5cSJustin T. Gibbs  *          type of failure.
235ff662b5cSJustin T. Gibbs  */
236ff662b5cSJustin T. Gibbs int xenbusb_read_ivar(device_t dev, device_t child, int index,
237ff662b5cSJustin T. Gibbs 		      uintptr_t *result);
238ff662b5cSJustin T. Gibbs 
239ff662b5cSJustin T. Gibbs /**
240ff662b5cSJustin T. Gibbs  * \brief Common XenBus child instance variable write access method.
241ff662b5cSJustin T. Gibbs  *
242ff662b5cSJustin T. Gibbs  * \param dev    The NewBus device representing this XenBus bus.
243ff662b5cSJustin T. Gibbs  * \param child	 The NewBus device representing a child of dev%'s XenBus bus.
244ff662b5cSJustin T. Gibbs  * \param index	 The index of the instance variable to access.
245ff662b5cSJustin T. Gibbs  * \param value  The new value to set in the instance variable accessed.
246ff662b5cSJustin T. Gibbs  *
247ff662b5cSJustin T. Gibbs  * \return  On success, 0. Otherwise an errno value indicating the
248ff662b5cSJustin T. Gibbs  *          type of failure.
249ff662b5cSJustin T. Gibbs  */
250ff662b5cSJustin T. Gibbs int xenbusb_write_ivar(device_t dev, device_t child, int index,
251ff662b5cSJustin T. Gibbs 		       uintptr_t value);
252ff662b5cSJustin T. Gibbs 
253ff662b5cSJustin T. Gibbs /**
254*283d6f72SJustin T. Gibbs  * \brief Common XenBus method implementing responses to peer state changes.
255*283d6f72SJustin T. Gibbs  *
256*283d6f72SJustin T. Gibbs  * \param bus       The XenBus bus parent of child.
257*283d6f72SJustin T. Gibbs  * \param child     The XenBus child whose peer stat has changed.
258*283d6f72SJustin T. Gibbs  * \param state     The current state of the peer.
259*283d6f72SJustin T. Gibbs  */
260*283d6f72SJustin T. Gibbs void xenbusb_otherend_changed(device_t bus, device_t child,
261*283d6f72SJustin T. Gibbs 			      enum xenbus_state state);
262*283d6f72SJustin T. Gibbs 
263*283d6f72SJustin T. Gibbs /**
264*283d6f72SJustin T. Gibbs  * \brief Common XenBus method implementing responses to local XenStore changes.
265*283d6f72SJustin T. Gibbs  *
266*283d6f72SJustin T. Gibbs  * \param bus    The XenBus bus parent of child.
267*283d6f72SJustin T. Gibbs  * \param child  The XenBus child whose peer stat has changed.
268*283d6f72SJustin T. Gibbs  * \param path   The tree relative sub-path to the modified node.  The empty
269*283d6f72SJustin T. Gibbs  *               string indicates the root of the tree was destroyed.
270*283d6f72SJustin T. Gibbs  */
271*283d6f72SJustin T. Gibbs void xenbusb_localend_changed(device_t bus, device_t child, const char *path);
272*283d6f72SJustin T. Gibbs 
273*283d6f72SJustin T. Gibbs /**
274ff662b5cSJustin T. Gibbs  * \brief Attempt to add a XenBus device instance to this XenBus bus.
275ff662b5cSJustin T. Gibbs  *
276ff662b5cSJustin T. Gibbs  * \param dev   The NewBus device representing this XenBus bus.
277ff662b5cSJustin T. Gibbs  * \param type  The device type being added (e.g. "vbd", "vif").
278ff662b5cSJustin T. Gibbs  * \param id	The device ID for this device.
279ff662b5cSJustin T. Gibbs  *
280ff662b5cSJustin T. Gibbs  * \return  On success, 0. Otherwise an errno value indicating the
281ff662b5cSJustin T. Gibbs  *          type of failure.  Failure indicates that either the
282ff662b5cSJustin T. Gibbs  *          path to this device no longer exists or insufficient
283ff662b5cSJustin T. Gibbs  *          information exists in the XenStore to create a new
284ff662b5cSJustin T. Gibbs  *          device.
285ff662b5cSJustin T. Gibbs  *
286ff662b5cSJustin T. Gibbs  * If successful, this routine will add a device_t with instance
287ff662b5cSJustin T. Gibbs  * variable storage to the NewBus device topology.  Probe/Attach
288ff662b5cSJustin T. Gibbs  * processing is not performed by this routine, but must be scheduled
289ff662b5cSJustin T. Gibbs  * via the xbs_probe_children task.  This separation of responsibilities
290ff662b5cSJustin T. Gibbs  * is required to avoid hanging up the XenStore event delivery thread
291ff662b5cSJustin T. Gibbs  * with our probe/attach work in the event a device is added via
292ff662b5cSJustin T. Gibbs  * a callback from the XenStore.
293ff662b5cSJustin T. Gibbs  */
294ff662b5cSJustin T. Gibbs int xenbusb_add_device(device_t dev, const char *type, const char *id);
295ff662b5cSJustin T. Gibbs 
296*283d6f72SJustin T. Gibbs #include "xenbusb_if.h"
297*283d6f72SJustin T. Gibbs 
298ff662b5cSJustin T. Gibbs #endif /* _XEN_XENBUS_XENBUSB_H */
299