xref: /freebsd/sys/xen/xenbus/xenbusb_if.m (revision 031beb4e239bfce798af17f5fe8dba8bcaf13d99)
1ff662b5cSJustin T. Gibbs#-
2ff662b5cSJustin T. Gibbs# Copyright (c) 2010 Spectra Logic Corporation
3ff662b5cSJustin T. Gibbs# All rights reserved.
4ff662b5cSJustin T. Gibbs#
5ff662b5cSJustin T. Gibbs# Redistribution and use in source and binary forms, with or without
6ff662b5cSJustin T. Gibbs# modification, are permitted provided that the following conditions
7ff662b5cSJustin T. Gibbs# are met:
8ff662b5cSJustin T. Gibbs# 1. Redistributions of source code must retain the above copyright
9ff662b5cSJustin T. Gibbs#    notice, this list of conditions, and the following disclaimer,
10ff662b5cSJustin T. Gibbs#    without modification.
11ff662b5cSJustin T. Gibbs# 2. Redistributions in binary form must reproduce at minimum a disclaimer
12ff662b5cSJustin T. Gibbs#    substantially similar to the "NO WARRANTY" disclaimer below
13ff662b5cSJustin T. Gibbs#    ("Disclaimer") and any redistribution must be conditioned upon
14ff662b5cSJustin T. Gibbs#    including a substantially similar Disclaimer requirement for further
15ff662b5cSJustin T. Gibbs#    binary redistribution.
16ff662b5cSJustin T. Gibbs#
17ff662b5cSJustin T. Gibbs# NO WARRANTY
18ff662b5cSJustin T. Gibbs# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19ff662b5cSJustin T. Gibbs# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20ff662b5cSJustin T. Gibbs# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21ff662b5cSJustin T. Gibbs# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22ff662b5cSJustin T. Gibbs# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23ff662b5cSJustin T. Gibbs# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24ff662b5cSJustin T. Gibbs# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25ff662b5cSJustin T. Gibbs# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26ff662b5cSJustin T. Gibbs# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27ff662b5cSJustin T. Gibbs# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28ff662b5cSJustin T. Gibbs# POSSIBILITY OF SUCH DAMAGES.
29ff662b5cSJustin T. Gibbs#
30ff662b5cSJustin T. Gibbs#
31ff662b5cSJustin T. Gibbs
32ff662b5cSJustin T. Gibbs#include <sys/bus.h>
33*283d6f72SJustin T. Gibbs#include <sys/lock.h>
34*283d6f72SJustin T. Gibbs#include <sys/sx.h>
35*283d6f72SJustin T. Gibbs#include <sys/taskqueue.h>
36ff662b5cSJustin T. Gibbs
37*283d6f72SJustin T. Gibbs#include <xen/xenstore/xenstorevar.h>
38*283d6f72SJustin T. Gibbs#include <xen/xenbus/xenbusb.h>
39ff662b5cSJustin T. Gibbs
40ff662b5cSJustin T. GibbsINTERFACE xenbusb;
41ff662b5cSJustin T. Gibbs
42ff662b5cSJustin T. Gibbs/**
43ff662b5cSJustin T. Gibbs * \brief Enumerate all devices of the given type on this bus.
44ff662b5cSJustin T. Gibbs *
45ff662b5cSJustin T. Gibbs * \param _dev  NewBus device_t for this XenBus (front/back) bus instance.
46ff662b5cSJustin T. Gibbs * \param _type String indicating the device sub-tree (e.g. "vfb", "vif")
47ff662b5cSJustin T. Gibbs *              to enumerate.
48ff662b5cSJustin T. Gibbs *
49ff662b5cSJustin T. Gibbs * \return  On success, 0. Otherwise an errno value indicating the
50ff662b5cSJustin T. Gibbs *          type of failure.
51ff662b5cSJustin T. Gibbs *
52ff662b5cSJustin T. Gibbs * Devices that are found should be entered into the NewBus hierarchy via
53ff662b5cSJustin T. Gibbs * xenbusb_add_device().  xenbusb_add_device() ignores duplicate detects
54ff662b5cSJustin T. Gibbs * and ignores duplicate devices, so it can be called unconditionally
55ff662b5cSJustin T. Gibbs * for any device found in the XenStore.
56ff662b5cSJustin T. Gibbs */
57ff662b5cSJustin T. GibbsMETHOD int enumerate_type {
58ff662b5cSJustin T. Gibbs	device_t _dev;
59ff662b5cSJustin T. Gibbs	const char *_type;
60ff662b5cSJustin T. Gibbs};
61ff662b5cSJustin T. Gibbs
62ff662b5cSJustin T. Gibbs/**
63ff662b5cSJustin T. Gibbs * \brief Determine and store the XenStore path for the other end of
64ff662b5cSJustin T. Gibbs *        a split device whose local end is represented by ivars.
65ff662b5cSJustin T. Gibbs *
66ff662b5cSJustin T. Gibbs * If successful, the xd_otherend_path field of the child's instance
67ff662b5cSJustin T. Gibbs * variables must be updated.
68ff662b5cSJustin T. Gibbs *
69ff662b5cSJustin T. Gibbs * \param _dev    NewBus device_t for this XenBus (front/back) bus instance.
70ff662b5cSJustin T. Gibbs * \param _ivars  Instance variables from the XenBus child device for
71ff662b5cSJustin T. Gibbs *                which to perform this function.
72ff662b5cSJustin T. Gibbs *
73ff662b5cSJustin T. Gibbs * \return  On success, 0. Otherwise an errno value indicating the
74ff662b5cSJustin T. Gibbs *          type of failure.
75ff662b5cSJustin T. Gibbs */
76ff662b5cSJustin T. GibbsMETHOD int get_otherend_node {
77ff662b5cSJustin T. Gibbs	device_t _dev;
78ff662b5cSJustin T. Gibbs	struct xenbus_device_ivars *_ivars;
79ff662b5cSJustin T. Gibbs}
80*283d6f72SJustin T. Gibbs
81*283d6f72SJustin T. Gibbs/**
82*283d6f72SJustin T. Gibbs * \brief Handle a XenStore change detected in the peer tree of a child
83*283d6f72SJustin T. Gibbs *        device of the bus.
84*283d6f72SJustin T. Gibbs *
85*283d6f72SJustin T. Gibbs * \param _bus       NewBus device_t for this XenBus (front/back) bus instance.
86*283d6f72SJustin T. Gibbs * \param _child     NewBus device_t for the child device whose peer XenStore
87*283d6f72SJustin T. Gibbs *                   tree has changed.
88*283d6f72SJustin T. Gibbs * \param _state     The current state of the peer.
89*283d6f72SJustin T. Gibbs */
90*283d6f72SJustin T. GibbsMETHOD void otherend_changed {
91*283d6f72SJustin T. Gibbs	device_t _bus;
92*283d6f72SJustin T. Gibbs	device_t _child;
93*283d6f72SJustin T. Gibbs	enum xenbus_state _state;
94*283d6f72SJustin T. Gibbs} DEFAULT xenbusb_otherend_changed;
95*283d6f72SJustin T. Gibbs
96*283d6f72SJustin T. Gibbs/**
97*283d6f72SJustin T. Gibbs * \brief Handle a XenStore change detected in the local tree of a child
98*283d6f72SJustin T. Gibbs *        device of the bus.
99*283d6f72SJustin T. Gibbs *
100*283d6f72SJustin T. Gibbs * \param _bus    NewBus device_t for this XenBus (front/back) bus instance.
101*283d6f72SJustin T. Gibbs * \param _child  NewBus device_t for the child device whose peer XenStore
102*283d6f72SJustin T. Gibbs *                tree has changed.
103*283d6f72SJustin T. Gibbs * \param _path   The tree relative sub-path to the modified node.  The empty
104*283d6f72SJustin T. Gibbs *                string indicates the root of the tree was destroyed.
105*283d6f72SJustin T. Gibbs */
106*283d6f72SJustin T. GibbsMETHOD void localend_changed {
107*283d6f72SJustin T. Gibbs	device_t _bus;
108*283d6f72SJustin T. Gibbs	device_t _child;
109*283d6f72SJustin T. Gibbs	const char * _path;
110*283d6f72SJustin T. Gibbs} DEFAULT xenbusb_localend_changed;
111