1214077Sgibbs/*- 2214077Sgibbs * Core definitions and data structures shareable across OS platforms. 3181624Skmacy * 4214077Sgibbs * Copyright (c) 2010 Spectra Logic Corporation 5185605Skmacy * Copyright (C) 2008 Doug Rabson 6214077Sgibbs * All rights reserved. 7214077Sgibbs * 8214077Sgibbs * Redistribution and use in source and binary forms, with or without 9214077Sgibbs * modification, are permitted provided that the following conditions 10214077Sgibbs * are met: 11214077Sgibbs * 1. Redistributions of source code must retain the above copyright 12214077Sgibbs * notice, this list of conditions, and the following disclaimer, 13214077Sgibbs * without modification. 14214077Sgibbs * 2. Redistributions in binary form must reproduce at minimum a disclaimer 15214077Sgibbs * substantially similar to the "NO WARRANTY" disclaimer below 16214077Sgibbs * ("Disclaimer") and any redistribution must be conditioned upon 17214077Sgibbs * including a substantially similar Disclaimer requirement for further 18214077Sgibbs * binary redistribution. 19214077Sgibbs * 20214077Sgibbs * NO WARRANTY 21214077Sgibbs * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22214077Sgibbs * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23214077Sgibbs * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 24214077Sgibbs * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25214077Sgibbs * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26214077Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27214077Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28214077Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29214077Sgibbs * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30214077Sgibbs * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31214077Sgibbs * POSSIBILITY OF SUCH DAMAGES. 32214077Sgibbs * 33214077Sgibbs * $FreeBSD: releng/11.0/sys/xen/xenbus/xenbusb.h 222975 2011-06-11 04:59:01Z gibbs $ 34181624Skmacy */ 35214077Sgibbs#ifndef _XEN_XENBUS_XENBUSB_H 36214077Sgibbs#define _XEN_XENBUS_XENBUSB_H 37181624Skmacy 38214077Sgibbs/** 39214077Sgibbs * \file xenbusb.h 40214077Sgibbs * 41214077Sgibbs * Datastructures and function declarations for use in implementing 42214077Sgibbs * bus attachements (e.g. frontend and backend device busses) for XenBus. 43214077Sgibbs */ 44181624Skmacy 45214077Sgibbs/** 46214077Sgibbs * Enumeration of state flag values for the xbs_flags field of 47214077Sgibbs * the xenbusb_softc structure. 48214077Sgibbs */ 49214077Sgibbstypedef enum { 50214077Sgibbs /** */ 51214077Sgibbs XBS_ATTACH_CH_ACTIVE = 0x01 52214077Sgibbs} xenbusb_softc_flag; 53181624Skmacy 54214077Sgibbs/** 55214077Sgibbs * \brief Container for all state needed to manage a Xenbus Bus 56214077Sgibbs * attachment. 57214077Sgibbs */ 58214077Sgibbsstruct xenbusb_softc { 59214077Sgibbs /** 60214077Sgibbs * XenStore watch used to monitor the subtree of the 61214077Sgibbs * XenStore where devices for this bus attachment arrive 62214077Sgibbs * and depart. 63214077Sgibbs */ 64214077Sgibbs struct xs_watch xbs_device_watch; 65181624Skmacy 66214077Sgibbs /** Mutex used to protect fields of the xenbusb_softc. */ 67214077Sgibbs struct mtx xbs_lock; 68181624Skmacy 69214077Sgibbs /** State flags. */ 70214077Sgibbs xenbusb_softc_flag xbs_flags; 71181624Skmacy 72214077Sgibbs /** 73214077Sgibbs * A dedicated task for processing child arrival and 74214077Sgibbs * departure events. 75214077Sgibbs */ 76214077Sgibbs struct task xbs_probe_children; 77181624Skmacy 78214077Sgibbs /** 79214077Sgibbs * Config Hook used to block boot processing until 80214077Sgibbs * XenBus devices complete their connection processing 81214077Sgibbs * with other VMs. 82214077Sgibbs */ 83214077Sgibbs struct intr_config_hook xbs_attach_ch; 84181624Skmacy 85214077Sgibbs /** 86214077Sgibbs * The number of children for this bus that are still 87214077Sgibbs * in the connecting (to other VMs) state. This variable 88214077Sgibbs * is used to determine when to release xbs_attach_ch. 89214077Sgibbs */ 90214077Sgibbs u_int xbs_connecting_children; 91181624Skmacy 92214077Sgibbs /** The NewBus device_t for this bus attachment. */ 93214077Sgibbs device_t xbs_dev; 94181624Skmacy 95214077Sgibbs /** 96214077Sgibbs * The VM relative path to the XenStore subtree this 97214077Sgibbs * bus attachment manages. 98214077Sgibbs */ 99214077Sgibbs const char *xbs_node; 100181624Skmacy 101214077Sgibbs /** 102214077Sgibbs * The number of path components (strings separated by the '/' 103214077Sgibbs * character) that make up the device ID on this bus. 104214077Sgibbs */ 105214077Sgibbs u_int xbs_id_components; 106214077Sgibbs}; 107181624Skmacy 108214077Sgibbs/** 109214077Sgibbs * Enumeration of state flag values for the xbs_flags field of 110214077Sgibbs * the xenbusb_softc structure. 111214077Sgibbs */ 112214077Sgibbstypedef enum { 113181624Skmacy 114214077Sgibbs /** 115214077Sgibbs * This device is contributing to the xbs_connecting_children 116214077Sgibbs * count of its parent bus. 117214077Sgibbs */ 118214077Sgibbs XDF_CONNECTING = 0x01 119214077Sgibbs} xenbus_dev_flag; 120181624Skmacy 121214077Sgibbs/** Instance variables for devices on a XenBus bus. */ 122214077Sgibbsstruct xenbus_device_ivars { 123214077Sgibbs /** 124214077Sgibbs * XenStore watch used to monitor the subtree of the 125214077Sgibbs * XenStore where information about the otherend of 126214077Sgibbs * the split Xen device this device instance represents. 127214077Sgibbs */ 128214077Sgibbs struct xs_watch xd_otherend_watch; 129185605Skmacy 130222975Sgibbs /** 131222975Sgibbs * XenStore watch used to monitor the XenStore sub-tree 132222975Sgibbs * associated with this device. This watch will fire 133222975Sgibbs * for modifications that we make from our domain as 134222975Sgibbs * well as for those made by the control domain. 135222975Sgibbs */ 136222975Sgibbs struct xs_watch xd_local_watch; 137222975Sgibbs 138214077Sgibbs /** Sleepable lock used to protect instance data. */ 139214077Sgibbs struct sx xd_lock; 140181624Skmacy 141214077Sgibbs /** State flags. */ 142214077Sgibbs xenbus_dev_flag xd_flags; 143181624Skmacy 144214077Sgibbs /** The NewBus device_t for this XenBus device instance. */ 145214077Sgibbs device_t xd_dev; 146181624Skmacy 147214077Sgibbs /** 148214077Sgibbs * The VM relative path to the XenStore subtree representing 149214077Sgibbs * this VMs half of this device. 150181624Skmacy */ 151214077Sgibbs char *xd_node; 152181624Skmacy 153222975Sgibbs /** The length of xd_node. */ 154222975Sgibbs int xd_node_len; 155222975Sgibbs 156214077Sgibbs /** XenBus device type ("vbd", "vif", etc.). */ 157214077Sgibbs char *xd_type; 158181624Skmacy 159214077Sgibbs /** 160214077Sgibbs * Cached version of <xd_node>/state node in the XenStore. 161185605Skmacy */ 162214077Sgibbs enum xenbus_state xd_state; 163185605Skmacy 164214077Sgibbs /** The VM identifier of the other end of this split device. */ 165214077Sgibbs int xd_otherend_id; 166185605Skmacy 167214077Sgibbs /** 168214077Sgibbs * The path to the subtree of the XenStore where information 169214077Sgibbs * about the otherend of this split device instance. 170186557Skmacy */ 171214077Sgibbs char *xd_otherend_path; 172222975Sgibbs 173222975Sgibbs /** The length of xd_otherend_path. */ 174222975Sgibbs int xd_otherend_path_len; 175214077Sgibbs}; 176186557Skmacy 177214077Sgibbs/** 178214077Sgibbs * \brief Identify instances of this device type in the system. 179214077Sgibbs * 180214077Sgibbs * \param driver The driver performing this identify action. 181214077Sgibbs * \param parent The NewBus parent device for any devices this method adds. 182214077Sgibbs */ 183214077Sgibbsvoid xenbusb_identify(driver_t *driver __unused, device_t parent); 184186557Skmacy 185214077Sgibbs/** 186214077Sgibbs * \brief Perform common XenBus bus attach processing. 187214077Sgibbs * 188214077Sgibbs * \param dev The NewBus device representing this XenBus bus. 189214077Sgibbs * \param bus_node The XenStore path to the XenStore subtree for 190214077Sgibbs * this XenBus bus. 191214077Sgibbs * \param id_components The number of '/' separated path components that 192214077Sgibbs * make up a unique device ID on this XenBus bus. 193214077Sgibbs * 194214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 195214077Sgibbs * type of failure. 196214077Sgibbs * 197214077Sgibbs * Intiailizes the softc for this bus, installs an interrupt driven 198214077Sgibbs * configuration hook to block boot processing until XenBus devices fully 199214077Sgibbs * configure, performs an initial probe/attach of the bus, and registers 200214077Sgibbs * a XenStore watch so we are notified when the bus topology changes. 201214077Sgibbs */ 202214077Sgibbsint xenbusb_attach(device_t dev, char *bus_node, u_int id_components); 203186557Skmacy 204214077Sgibbs/** 205214077Sgibbs * \brief Perform common XenBus bus resume handling. 206214077Sgibbs * 207214077Sgibbs * \param dev The NewBus device representing this XenBus bus. 208214077Sgibbs * 209214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 210214077Sgibbs * type of failure. 211214077Sgibbs */ 212214077Sgibbsint xenbusb_resume(device_t dev); 213186557Skmacy 214214077Sgibbs/** 215214077Sgibbs * \brief Pretty-prints information about a child of a XenBus bus. 216214077Sgibbs * 217214077Sgibbs * \param dev The NewBus device representing this XenBus bus. 218214077Sgibbs * \param child The NewBus device representing a child of dev%'s XenBus bus. 219214077Sgibbs * 220214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 221214077Sgibbs * type of failure. 222214077Sgibbs */ 223214077Sgibbsint xenbusb_print_child(device_t dev, device_t child); 224186557Skmacy 225214077Sgibbs/** 226214077Sgibbs * \brief Common XenBus child instance variable read access method. 227214077Sgibbs * 228214077Sgibbs * \param dev The NewBus device representing this XenBus bus. 229214077Sgibbs * \param child The NewBus device representing a child of dev%'s XenBus bus. 230214077Sgibbs * \param index The index of the instance variable to access. 231214077Sgibbs * \param result The value of the instance variable accessed. 232214077Sgibbs * 233214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 234214077Sgibbs * type of failure. 235214077Sgibbs */ 236214077Sgibbsint xenbusb_read_ivar(device_t dev, device_t child, int index, 237214077Sgibbs uintptr_t *result); 238186557Skmacy 239214077Sgibbs/** 240214077Sgibbs * \brief Common XenBus child instance variable write access method. 241214077Sgibbs * 242214077Sgibbs * \param dev The NewBus device representing this XenBus bus. 243214077Sgibbs * \param child The NewBus device representing a child of dev%'s XenBus bus. 244214077Sgibbs * \param index The index of the instance variable to access. 245214077Sgibbs * \param value The new value to set in the instance variable accessed. 246214077Sgibbs * 247214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 248214077Sgibbs * type of failure. 249214077Sgibbs */ 250214077Sgibbsint xenbusb_write_ivar(device_t dev, device_t child, int index, 251214077Sgibbs uintptr_t value); 252186557Skmacy 253214077Sgibbs/** 254222975Sgibbs * \brief Common XenBus method implementing responses to peer state changes. 255222975Sgibbs * 256222975Sgibbs * \param bus The XenBus bus parent of child. 257222975Sgibbs * \param child The XenBus child whose peer stat has changed. 258222975Sgibbs * \param state The current state of the peer. 259222975Sgibbs */ 260222975Sgibbsvoid xenbusb_otherend_changed(device_t bus, device_t child, 261222975Sgibbs enum xenbus_state state); 262222975Sgibbs 263222975Sgibbs/** 264222975Sgibbs * \brief Common XenBus method implementing responses to local XenStore changes. 265222975Sgibbs * 266222975Sgibbs * \param bus The XenBus bus parent of child. 267222975Sgibbs * \param child The XenBus child whose peer stat has changed. 268222975Sgibbs * \param path The tree relative sub-path to the modified node. The empty 269222975Sgibbs * string indicates the root of the tree was destroyed. 270222975Sgibbs */ 271222975Sgibbsvoid xenbusb_localend_changed(device_t bus, device_t child, const char *path); 272222975Sgibbs 273222975Sgibbs/** 274214077Sgibbs * \brief Attempt to add a XenBus device instance to this XenBus bus. 275214077Sgibbs * 276214077Sgibbs * \param dev The NewBus device representing this XenBus bus. 277214077Sgibbs * \param type The device type being added (e.g. "vbd", "vif"). 278214077Sgibbs * \param id The device ID for this device. 279214077Sgibbs * 280214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 281214077Sgibbs * type of failure. Failure indicates that either the 282214077Sgibbs * path to this device no longer exists or insufficient 283214077Sgibbs * information exists in the XenStore to create a new 284214077Sgibbs * device. 285214077Sgibbs * 286214077Sgibbs * If successful, this routine will add a device_t with instance 287214077Sgibbs * variable storage to the NewBus device topology. Probe/Attach 288214077Sgibbs * processing is not performed by this routine, but must be scheduled 289214077Sgibbs * via the xbs_probe_children task. This separation of responsibilities 290214077Sgibbs * is required to avoid hanging up the XenStore event delivery thread 291214077Sgibbs * with our probe/attach work in the event a device is added via 292214077Sgibbs * a callback from the XenStore. 293214077Sgibbs */ 294214077Sgibbsint xenbusb_add_device(device_t dev, const char *type, const char *id); 295186557Skmacy 296222975Sgibbs#include "xenbusb_if.h" 297222975Sgibbs 298214077Sgibbs#endif /* _XEN_XENBUS_XENBUSB_H */ 299