xenbusvar.h revision 222975
1185605Skmacy/****************************************************************************** 2185605Skmacy * Copyright (C) 2005 Rusty Russell, IBM Corporation 3185605Skmacy * Copyright (C) 2005 XenSource Ltd. 4185605Skmacy * 5185605Skmacy * This file may be distributed separately from the Linux kernel, or 6185605Skmacy * incorporated into other software packages, subject to the following license: 7185605Skmacy * 8185605Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy 9185605Skmacy * of this source file (the "Software"), to deal in the Software without 10185605Skmacy * restriction, including without limitation the rights to use, copy, modify, 11185605Skmacy * merge, publish, distribute, sublicense, and/or sell copies of the Software, 12185605Skmacy * and to permit persons to whom the Software is furnished to do so, subject to 13185605Skmacy * the following conditions: 14185605Skmacy * 15185605Skmacy * The above copyright notice and this permission notice shall be included in 16185605Skmacy * all copies or substantial portions of the Software. 17185605Skmacy * 18185605Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19185605Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20185605Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21185605Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22185605Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23185605Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 24185605Skmacy * IN THE SOFTWARE. 25185605Skmacy * 26185605Skmacy * $FreeBSD: head/sys/xen/xenbus/xenbusvar.h 222975 2011-06-11 04:59:01Z gibbs $ 27185605Skmacy */ 28185605Skmacy 29214077Sgibbs/** 30214077Sgibbs * \file xenbusvar.h 31214077Sgibbs * 32214077Sgibbs * \brief Datastructures and function declarations for usedby device 33214077Sgibbs * drivers operating on the XenBus. 34214077Sgibbs */ 35214077Sgibbs 36185605Skmacy#ifndef _XEN_XENBUS_XENBUSVAR_H 37185605Skmacy#define _XEN_XENBUS_XENBUSVAR_H 38185605Skmacy 39185605Skmacy#include <sys/queue.h> 40185605Skmacy#include <sys/bus.h> 41185605Skmacy#include <sys/eventhandler.h> 42214077Sgibbs#include <sys/malloc.h> 43214077Sgibbs#include <sys/sbuf.h> 44214077Sgibbs 45214077Sgibbs#include <machine/stdarg.h> 46185605Skmacy#include <machine/xen/xen-os.h> 47214077Sgibbs 48214077Sgibbs#include <xen/interface/grant_table.h> 49185605Skmacy#include <xen/interface/io/xenbus.h> 50185605Skmacy#include <xen/interface/io/xs_wire.h> 51185605Skmacy 52214077Sgibbs#include <xen/xenstore/xenstorevar.h> 53214077Sgibbs 54214077Sgibbs/* XenBus allocations including XenStore data returned to clients. */ 55214077SgibbsMALLOC_DECLARE(M_XENBUS); 56214077Sgibbs 57185605Skmacyenum { 58214077Sgibbs /** 59185605Skmacy * Path of this device node. 60185605Skmacy */ 61185605Skmacy XENBUS_IVAR_NODE, 62185605Skmacy 63214077Sgibbs /** 64185605Skmacy * The device type (e.g. vif, vbd). 65185605Skmacy */ 66185605Skmacy XENBUS_IVAR_TYPE, 67185605Skmacy 68214077Sgibbs /** 69185605Skmacy * The state of this device (not the otherend's state). 70185605Skmacy */ 71185605Skmacy XENBUS_IVAR_STATE, 72185605Skmacy 73214077Sgibbs /** 74185605Skmacy * Domain ID of the other end device. 75185605Skmacy */ 76185605Skmacy XENBUS_IVAR_OTHEREND_ID, 77185605Skmacy 78214077Sgibbs /** 79185605Skmacy * Path of the other end device. 80185605Skmacy */ 81185605Skmacy XENBUS_IVAR_OTHEREND_PATH 82185605Skmacy}; 83185605Skmacy 84214077Sgibbs/** 85185605Skmacy * Simplified accessors for xenbus devices 86185605Skmacy */ 87185605Skmacy#define XENBUS_ACCESSOR(var, ivar, type) \ 88185605Skmacy __BUS_ACCESSOR(xenbus, var, XENBUS, ivar, type) 89185605Skmacy 90185605SkmacyXENBUS_ACCESSOR(node, NODE, const char *) 91185605SkmacyXENBUS_ACCESSOR(type, TYPE, const char *) 92185605SkmacyXENBUS_ACCESSOR(state, STATE, enum xenbus_state) 93185605SkmacyXENBUS_ACCESSOR(otherend_id, OTHEREND_ID, int) 94185605SkmacyXENBUS_ACCESSOR(otherend_path, OTHEREND_PATH, const char *) 95185605Skmacy 96214077Sgibbs/** 97214077Sgibbs * Return the state of a XenBus device. 98214077Sgibbs * 99214077Sgibbs * \param path The root XenStore path for the device. 100214077Sgibbs * 101214077Sgibbs * \return The current state of the device or XenbusStateClosed if no 102214077Sgibbs * state can be read. 103186557Skmacy */ 104214077SgibbsXenbusState xenbus_read_driver_state(const char *path); 105185605Skmacy 106185605Skmacy/** 107214077Sgibbs * Initialize and register a watch on the given path (client suplied storage). 108214077Sgibbs * 109214077Sgibbs * \param dev The XenBus device requesting the watch service. 110214077Sgibbs * \param path The XenStore path of the object to be watched. The 111214077Sgibbs * storage for this string must be stable for the lifetime 112214077Sgibbs * of the watch. 113214077Sgibbs * \param watch The watch object to use for this request. This object 114214077Sgibbs * must be stable for the lifetime of the watch. 115214077Sgibbs * \param callback The function to call when XenStore objects at or below 116214077Sgibbs * path are modified. 117222975Sgibbs * \param cb_data Client data that can be retrieved from the watch object 118222975Sgibbs * during the callback. 119214077Sgibbs * 120214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 121214077Sgibbs * type of failure. 122214077Sgibbs * 123214077Sgibbs * \note On error, the device 'dev' will be switched to the XenbusStateClosing 124214077Sgibbs * state and the returned error is saved in the per-device error node 125214077Sgibbs * for dev in the XenStore. 126185605Skmacy */ 127185605Skmacyint xenbus_watch_path(device_t dev, char *path, 128214077Sgibbs struct xs_watch *watch, 129222975Sgibbs xs_watch_cb_t *callback, 130222975Sgibbs uintptr_t cb_data); 131185605Skmacy 132185605Skmacy/** 133214077Sgibbs * Initialize and register a watch at path/path2 in the XenStore. 134214077Sgibbs * 135214077Sgibbs * \param dev The XenBus device requesting the watch service. 136214077Sgibbs * \param path The base XenStore path of the object to be watched. 137214077Sgibbs * \param path2 The tail XenStore path of the object to be watched. 138214077Sgibbs * \param watch The watch object to use for this request. This object 139214077Sgibbs * must be stable for the lifetime of the watch. 140214077Sgibbs * \param callback The function to call when XenStore objects at or below 141214077Sgibbs * path are modified. 142222975Sgibbs * \param cb_data Client data that can be retrieved from the watch object 143222975Sgibbs * during the callback. 144214077Sgibbs * 145214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 146214077Sgibbs * type of failure. 147214077Sgibbs * 148214077Sgibbs * \note On error, \a dev will be switched to the XenbusStateClosing 149214077Sgibbs * state and the returned error is saved in the per-device error node 150214077Sgibbs * for \a dev in the XenStore. 151214077Sgibbs * 152214077Sgibbs * Similar to xenbus_watch_path, however the storage for the path to the 153214077Sgibbs * watched object is allocated from the heap and filled with "path '/' path2". 154214077Sgibbs * Should a call to this function succeed, it is the callers responsibility 155214077Sgibbs * to free watch->node using the M_XENBUS malloc type. 156185605Skmacy */ 157185605Skmacyint xenbus_watch_path2(device_t dev, const char *path, 158214077Sgibbs const char *path2, struct xs_watch *watch, 159222975Sgibbs xs_watch_cb_t *callback, 160222975Sgibbs uintptr_t cb_data); 161185605Skmacy 162214077Sgibbs/** 163214077Sgibbs * Grant access to the given ring_mfn to the peer of the given device. 164214077Sgibbs * 165214077Sgibbs * \param dev The device granting access to the ring page. 166214077Sgibbs * \param ring_mfn The guest machine page number of the page to grant 167214077Sgibbs * peer access rights. 168214077Sgibbs * \param refp[out] The grant reference for the page. 169214077Sgibbs * 170214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 171214077Sgibbs * type of failure. 172214077Sgibbs * 173214077Sgibbs * A successful call to xenbus_grant_ring should be paired with a call 174214077Sgibbs * to gnttab_end_foreign_access() when foregn access to this page is no 175214077Sgibbs * longer requried. 176214077Sgibbs * 177214077Sgibbs * \note On error, \a dev will be switched to the XenbusStateClosing 178214077Sgibbs * state and the returned error is saved in the per-device error node 179214077Sgibbs * for \a dev in the XenStore. 180214077Sgibbs */ 181214077Sgibbsint xenbus_grant_ring(device_t dev, unsigned long ring_mfn, grant_ref_t *refp); 182185605Skmacy 183185605Skmacy/** 184214077Sgibbs * Allocate an event channel for the given XenBus device. 185214077Sgibbs * 186214077Sgibbs * \param dev The device for which to allocate the event channel. 187214077Sgibbs * \param port[out] The port identifier for the allocated event channel. 188214077Sgibbs * 189214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 190214077Sgibbs * type of failure. 191214077Sgibbs * 192214077Sgibbs * A successfully allocated event channel should be free'd using 193214077Sgibbs * xenbus_free_evtchn(). 194214077Sgibbs * 195214077Sgibbs * \note On error, \a dev will be switched to the XenbusStateClosing 196214077Sgibbs * state and the returned error is saved in the per-device error node 197214077Sgibbs * for \a dev in the XenStore. 198185605Skmacy */ 199214077Sgibbsint xenbus_alloc_evtchn(device_t dev, evtchn_port_t *port); 200185605Skmacy 201214077Sgibbs/** 202214077Sgibbs * Free an existing event channel. 203214077Sgibbs * 204214077Sgibbs * \param dev The device which allocated this event channel. 205214077Sgibbs * \param port The port identifier for the event channel to free. 206214077Sgibbs * 207214077Sgibbs * \return On success, 0. Otherwise an errno value indicating the 208214077Sgibbs * type of failure. 209214077Sgibbs * 210214077Sgibbs * \note On error, \a dev will be switched to the XenbusStateClosing 211214077Sgibbs * state and the returned error is saved in the per-device error node 212214077Sgibbs * for \a dev in the XenStore. 213214077Sgibbs */ 214214077Sgibbsint xenbus_free_evtchn(device_t dev, evtchn_port_t port); 215185605Skmacy 216185605Skmacy/** 217214077Sgibbs * Record the given errno, along with the given, printf-style, formatted 218214077Sgibbs * message in dev's device specific error node in the XenStore. 219214077Sgibbs * 220214077Sgibbs * \param dev The device which encountered the error. 221214077Sgibbs * \param err The errno value corresponding to the error. 222214077Sgibbs * \param fmt Printf format string followed by a variable number of 223214077Sgibbs * printf arguments. 224185605Skmacy */ 225214077Sgibbsvoid xenbus_dev_error(device_t dev, int err, const char *fmt, ...) 226214077Sgibbs __attribute__((format(printf, 3, 4))); 227185605Skmacy 228185605Skmacy/** 229214077Sgibbs * va_list version of xenbus_dev_error(). 230214077Sgibbs * 231214077Sgibbs * \param dev The device which encountered the error. 232214077Sgibbs * \param err The errno value corresponding to the error. 233214077Sgibbs * \param fmt Printf format string. 234214077Sgibbs * \param ap Va_list of printf arguments. 235185605Skmacy */ 236214077Sgibbsvoid xenbus_dev_verror(device_t dev, int err, const char *fmt, va_list ap) 237214077Sgibbs __attribute__((format(printf, 3, 0))); 238185605Skmacy 239185605Skmacy/** 240214077Sgibbs * Equivalent to xenbus_dev_error(), followed by 241214077Sgibbs * xenbus_set_state(dev, XenbusStateClosing). 242214077Sgibbs * 243214077Sgibbs * \param dev The device which encountered the error. 244214077Sgibbs * \param err The errno value corresponding to the error. 245214077Sgibbs * \param fmt Printf format string followed by a variable number of 246214077Sgibbs * printf arguments. 247185605Skmacy */ 248214077Sgibbsvoid xenbus_dev_fatal(device_t dev, int err, const char *fmt, ...) 249214077Sgibbs __attribute__((format(printf, 3, 4))); 250185605Skmacy 251185605Skmacy/** 252214077Sgibbs * va_list version of xenbus_dev_fatal(). 253214077Sgibbs * 254214077Sgibbs * \param dev The device which encountered the error. 255214077Sgibbs * \param err The errno value corresponding to the error. 256214077Sgibbs * \param fmt Printf format string. 257214077Sgibbs * \param ap Va_list of printf arguments. 258185605Skmacy */ 259214077Sgibbsvoid xenbus_dev_vfatal(device_t dev, int err, const char *fmt, va_list) 260214077Sgibbs __attribute__((format(printf, 3, 0))); 261185605Skmacy 262214077Sgibbs/** 263214077Sgibbs * Convert a member of the xenbus_state enum into an ASCII string. 264214077Sgibbs * 265214077Sgibbs * /param state The XenBus state to lookup. 266214077Sgibbs * 267214077Sgibbs * /return A string representing state or, for unrecognized states, 268214077Sgibbs * the string "Unknown". 269185605Skmacy */ 270214077Sgibbsconst char *xenbus_strstate(enum xenbus_state state); 271185605Skmacy 272214077Sgibbs/** 273214077Sgibbs * Return the value of a XenBus device's "online" node within the XenStore. 274214077Sgibbs * 275214077Sgibbs * \param dev The XenBus device to query. 276214077Sgibbs * 277214077Sgibbs * \return The value of the "online" node for the device. If the node 278214077Sgibbs * does not exist, 0 (offline) is returned. 279185605Skmacy */ 280185605Skmacyint xenbus_dev_is_online(device_t dev); 281185605Skmacy 282222975Sgibbs/** 283222975Sgibbs * Default callback invoked when a change to the local XenStore sub-tree 284222975Sgibbs * for a device is modified. 285222975Sgibbs * 286222975Sgibbs * \param dev The XenBus device whose tree was modified. 287222975Sgibbs * \param path The tree relative sub-path to the modified node. The empty 288222975Sgibbs * string indicates the root of the tree was destroyed. 289222975Sgibbs */ 290222975Sgibbsvoid xenbus_localend_changed(device_t dev, const char *path); 291222975Sgibbs 292222975Sgibbs#include "xenbus_if.h" 293222975Sgibbs 294185605Skmacy#endif /* _XEN_XENBUS_XENBUSVAR_H */ 295