15084Sjohnlev /* 25084Sjohnlev * CDDL HEADER START 35084Sjohnlev * 45084Sjohnlev * The contents of this file are subject to the terms of the 55084Sjohnlev * Common Development and Distribution License (the "License"). 65084Sjohnlev * You may not use this file except in compliance with the License. 75084Sjohnlev * 85084Sjohnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95084Sjohnlev * or http://www.opensolaris.org/os/licensing. 105084Sjohnlev * See the License for the specific language governing permissions 115084Sjohnlev * and limitations under the License. 125084Sjohnlev * 135084Sjohnlev * When distributing Covered Code, include this CDDL HEADER in each 145084Sjohnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155084Sjohnlev * If applicable, add the following below this CDDL HEADER, with the 165084Sjohnlev * fields enclosed by brackets "[]" replaced with your own identifying 175084Sjohnlev * information: Portions Copyright [yyyy] [name of copyright owner] 185084Sjohnlev * 195084Sjohnlev * CDDL HEADER END 205084Sjohnlev */ 215084Sjohnlev 225084Sjohnlev /* 238863SEdward.Pilatowicz@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 245084Sjohnlev * Use is subject to license terms. 255084Sjohnlev */ 265084Sjohnlev 275084Sjohnlev /* 285084Sjohnlev * 295084Sjohnlev * xenbus.h (renamed to xenbus_impl.h) 305084Sjohnlev * 315084Sjohnlev * Talks to Xen Store to figure out what devices we have. 325084Sjohnlev * 335084Sjohnlev * Copyright (C) 2005 Rusty Russell, IBM Corporation 345084Sjohnlev * 355084Sjohnlev * This file may be distributed separately from the Linux kernel, or 365084Sjohnlev * incorporated into other software packages, subject to the following license: 375084Sjohnlev * 385084Sjohnlev * Permission is hereby granted, free of charge, to any person obtaining a copy 395084Sjohnlev * of this source file (the "Software"), to deal in the Software without 405084Sjohnlev * restriction, including without limitation the rights to use, copy, modify, 415084Sjohnlev * merge, publish, distribute, sublicense, and/or sell copies of the Software, 425084Sjohnlev * and to permit persons to whom the Software is furnished to do so, subject to 435084Sjohnlev * the following conditions: 445084Sjohnlev * 455084Sjohnlev * The above copyright notice and this permission notice shall be included in 465084Sjohnlev * all copies or substantial portions of the Software. 475084Sjohnlev * 485084Sjohnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 495084Sjohnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 505084Sjohnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 515084Sjohnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 525084Sjohnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 535084Sjohnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 545084Sjohnlev * IN THE SOFTWARE. 555084Sjohnlev */ 565084Sjohnlev 575084Sjohnlev #ifndef _SYS_XENBUS_H 585084Sjohnlev #define _SYS_XENBUS_H 595084Sjohnlev 605084Sjohnlev #include <sys/mutex.h> 615084Sjohnlev #include <sys/list.h> 625084Sjohnlev 635084Sjohnlev #ifdef __cplusplus 645084Sjohnlev extern "C" { 655084Sjohnlev #endif 665084Sjohnlev 675084Sjohnlev #define XBT_NULL 0 685084Sjohnlev 695084Sjohnlev typedef uint32_t xenbus_transaction_t; 705084Sjohnlev 715084Sjohnlev /* Register callback to watch this node. */ 728863SEdward.Pilatowicz@Sun.COM struct xenbus_watch; 738863SEdward.Pilatowicz@Sun.COM typedef void (*xenbus_watch_cb_t)(struct xenbus_watch *, 748863SEdward.Pilatowicz@Sun.COM const char **vec, unsigned int len); 758863SEdward.Pilatowicz@Sun.COM struct xenbus_watch { 76*10175SStuart.Maybee@Sun.COM list_node_t list; 778863SEdward.Pilatowicz@Sun.COM const char *node; /* path being watched */ 788863SEdward.Pilatowicz@Sun.COM xenbus_watch_cb_t callback; 798863SEdward.Pilatowicz@Sun.COM struct xenbus_device *dev; 805084Sjohnlev }; 815084Sjohnlev 825084Sjohnlev /* 835084Sjohnlev * Call this function when xenstore is available, i.e. the daemon is 845084Sjohnlev * connected to the xenbus device. 855084Sjohnlev */ 865084Sjohnlev struct xenbus_notify { 87*10175SStuart.Maybee@Sun.COM list_node_t list; 885084Sjohnlev void (*notify_func) (int); 895084Sjohnlev }; 905084Sjohnlev 915084Sjohnlev /* A xenbus device. */ 925084Sjohnlev struct xenbus_device { 935084Sjohnlev const char *devicetype; 945084Sjohnlev const char *nodename; 955084Sjohnlev const char *otherend; 965084Sjohnlev int otherend_id; 975084Sjohnlev int otherend_state; 985084Sjohnlev struct xenbus_watch otherend_watch; 995084Sjohnlev int has_error; 1005084Sjohnlev int frontend; 1015084Sjohnlev void (*otherend_changed)(struct xenbus_device *, XenbusState); 1025084Sjohnlev void *data; 1035084Sjohnlev }; 1045084Sjohnlev 1058863SEdward.Pilatowicz@Sun.COM typedef void (*xvdi_xb_watch_cb_t)(dev_info_t *dip, const char *path, 1068863SEdward.Pilatowicz@Sun.COM void *arg); 1078863SEdward.Pilatowicz@Sun.COM 1088863SEdward.Pilatowicz@Sun.COM typedef struct xd_xb_watches { 1098863SEdward.Pilatowicz@Sun.COM list_node_t xxw_list; 1108863SEdward.Pilatowicz@Sun.COM int xxw_ref; 1118863SEdward.Pilatowicz@Sun.COM struct xenbus_watch xxw_watch; 1128863SEdward.Pilatowicz@Sun.COM struct xendev_ppd *xxw_xppd; 1138863SEdward.Pilatowicz@Sun.COM xvdi_xb_watch_cb_t xxw_cb; 1148863SEdward.Pilatowicz@Sun.COM void *xxw_arg; 1158863SEdward.Pilatowicz@Sun.COM } xd_xb_watches_t; 1165084Sjohnlev 1175084Sjohnlev extern char **xenbus_directory(xenbus_transaction_t t, const char *dir, 1185084Sjohnlev const char *node, unsigned int *num); 1195084Sjohnlev extern int xenbus_read(xenbus_transaction_t t, const char *dir, 1205084Sjohnlev const char *node, void **rstr, unsigned int *len); 1218863SEdward.Pilatowicz@Sun.COM extern int xenbus_read_str(const char *dir, const char *node, char **rstr); 1225084Sjohnlev extern int xenbus_write(xenbus_transaction_t t, const char *dir, 1235084Sjohnlev const char *node, const char *string); 1245084Sjohnlev extern int xenbus_mkdir(xenbus_transaction_t t, const char *dir, 1255084Sjohnlev const char *node); 1268863SEdward.Pilatowicz@Sun.COM extern boolean_t xenbus_exists(const char *dir, const char *node); 1278863SEdward.Pilatowicz@Sun.COM extern boolean_t xenbus_exists_dir(const char *dir, const char *node); 1285084Sjohnlev extern int xenbus_rm(xenbus_transaction_t t, const char *dir, 1295084Sjohnlev const char *node); 1305084Sjohnlev extern int xenbus_transaction_start(xenbus_transaction_t *t); 1315084Sjohnlev extern int xenbus_transaction_end(xenbus_transaction_t t, int abort); 1325084Sjohnlev 1335084Sjohnlev /* Single read and scanf: returns errno or num scanned if > 0. */ 1345084Sjohnlev extern int xenbus_scanf(xenbus_transaction_t t, const char *dir, 1355084Sjohnlev const char *node, const char *fmt, ...); 1365084Sjohnlev 1375084Sjohnlev /* Single printf and write: returns errno or 0. */ 1385084Sjohnlev extern int xenbus_printf(xenbus_transaction_t t, const char *dir, 1395084Sjohnlev const char *node, const char *fmt, ...); 1405084Sjohnlev 1415084Sjohnlev /* 1425084Sjohnlev * Generic read function: NULL-terminated triples of name, 1435084Sjohnlev * sprintf-style type string, and pointer. Returns 0 or errno. 1445084Sjohnlev */ 1455084Sjohnlev extern int xenbus_gather(xenbus_transaction_t t, const char *dir, ...); 1465084Sjohnlev 1475084Sjohnlev extern int register_xenbus_watch(struct xenbus_watch *watch); 1485084Sjohnlev extern void unregister_xenbus_watch(struct xenbus_watch *watch); 1495084Sjohnlev extern void reregister_xenbus_watches(void); 1505084Sjohnlev 1515084Sjohnlev /* Called from xen core code. */ 1525084Sjohnlev extern void xenbus_suspend(void); 1535084Sjohnlev extern void xenbus_resume(void); 1545084Sjohnlev 1555084Sjohnlev #define XENBUS_EXIST_ERR(err) ((err) == ENOENT || (err) == ERANGE) 1565084Sjohnlev 1575084Sjohnlev /* 1585084Sjohnlev * Register a watch on the given path, using the given xenbus_watch structure 1595084Sjohnlev * for storage, and the given callback function as the callback. Return 0 on 1605084Sjohnlev * success, or errno on error. On success, the given path will be saved as 1615084Sjohnlev * watch->node, and remains the caller's to free. On error, watch->node will 1625084Sjohnlev * be NULL, the device will switch to XenbusStateClosing, and the error will 1635084Sjohnlev * be saved in the store. 1645084Sjohnlev */ 1655084Sjohnlev extern int xenbus_watch_path(struct xenbus_device *dev, const char *path, 1665084Sjohnlev struct xenbus_watch *watch, 1675084Sjohnlev void (*callback)(struct xenbus_watch *, 1685084Sjohnlev const char **, unsigned int)); 1695084Sjohnlev 1705084Sjohnlev 1715084Sjohnlev /* 1725084Sjohnlev * Register a watch on the given path/path2, using the given xenbus_watch 1735084Sjohnlev * structure for storage, and the given callback function as the callback. 1745084Sjohnlev * Return 0 on success, or errno on error. On success, the watched path 1755084Sjohnlev * (path/path2) will be saved as watch->node, and becomes the caller's to 1765084Sjohnlev * kfree(). On error, watch->node will be NULL, so the caller has nothing to 1775084Sjohnlev * free, the device will switch to XenbusStateClosing, and the error will be 1785084Sjohnlev * saved in the store. 1795084Sjohnlev */ 1805084Sjohnlev extern int xenbus_watch_path2(struct xenbus_device *dev, const char *path, 1815084Sjohnlev const char *path2, struct xenbus_watch *watch, 1825084Sjohnlev void (*callback)(struct xenbus_watch *, 1835084Sjohnlev const char **, unsigned int)); 1845084Sjohnlev 1855084Sjohnlev 1865084Sjohnlev /* 1875084Sjohnlev * Advertise in the store a change of the given driver to the given new_state. 1885084Sjohnlev * Perform the change inside the given transaction xbt. xbt may be NULL, in 1895084Sjohnlev * which case this is performed inside its own transaction. Return 0 on 1905084Sjohnlev * success, or errno on error. On error, the device will switch to 1915084Sjohnlev * XenbusStateClosing, and the error will be saved in the store. 1925084Sjohnlev */ 1935084Sjohnlev extern int xenbus_switch_state(struct xenbus_device *dev, 1945084Sjohnlev xenbus_transaction_t xbt, 1955084Sjohnlev XenbusState new_state); 1965084Sjohnlev 1975084Sjohnlev 1985084Sjohnlev /* 1995084Sjohnlev * Grant access to the given ring_mfn to the peer of the given device. Return 2005084Sjohnlev * 0 on success, or errno on error. On error, the device will switch to 2015084Sjohnlev * XenbusStateClosing, and the error will be saved in the store. 2025084Sjohnlev */ 2035084Sjohnlev extern int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn); 2045084Sjohnlev 2055084Sjohnlev 2065084Sjohnlev /* 2075084Sjohnlev * Allocate an event channel for the given xenbus_device, assigning the newly 2085084Sjohnlev * created local port to *port. Return 0 on success, or errno on error. On 2095084Sjohnlev * error, the device will switch to XenbusStateClosing, and the error will be 2105084Sjohnlev * saved in the store. 2115084Sjohnlev */ 2125084Sjohnlev extern int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port); 2135084Sjohnlev 2145084Sjohnlev 2155084Sjohnlev /* 2165084Sjohnlev * Return the state of the driver rooted at the given store path, or 2175084Sjohnlev * XenbusStateClosed if no state can be read. 2185084Sjohnlev */ 2195084Sjohnlev extern XenbusState xenbus_read_driver_state(const char *path); 2205084Sjohnlev 2215084Sjohnlev 2225084Sjohnlev /* 2235084Sjohnlev * Report the given negative errno into the store, along with the given 2245084Sjohnlev * formatted message. 2255084Sjohnlev */ 2265084Sjohnlev extern void xenbus_dev_error(struct xenbus_device *dev, int err, 2275084Sjohnlev const char *fmt, ...); 2285084Sjohnlev 2295084Sjohnlev 2305084Sjohnlev /* 2315084Sjohnlev * Equivalent to xenbus_dev_error(dev, err, fmt, args), followed by 2325084Sjohnlev * xenbus_switch_state(dev, NULL, XenbusStateClosing) to schedule an orderly 2335084Sjohnlev * closedown of this driver and its peer. 2345084Sjohnlev */ 2355084Sjohnlev extern void xenbus_dev_fatal(struct xenbus_device *dev, 2365084Sjohnlev int err, const char *fmt, ...); 2375084Sjohnlev 2385084Sjohnlev /* Clear any error. */ 2395084Sjohnlev extern void xenbus_dev_ok(struct xenbus_device *dev); 2405084Sjohnlev 2415084Sjohnlev /* 2425084Sjohnlev * Set up watches on other end of split device. 2435084Sjohnlev */ 2445084Sjohnlev extern int talk_to_otherend(struct xenbus_device *dev); 2455084Sjohnlev 2465084Sjohnlev #define XENSTORE_DOWN 0 /* xenstore is down */ 2475084Sjohnlev #define XENSTORE_UP 1 /* xenstore is up */ 2485084Sjohnlev 2495084Sjohnlev /* 2505084Sjohnlev * Register a notify callback function. 2515084Sjohnlev */ 2525084Sjohnlev extern int xs_register_xenbus_callback(void (*callback)(int)); 2535084Sjohnlev 2545084Sjohnlev /* 2555084Sjohnlev * Notify clients that xenstore is up 2565084Sjohnlev */ 2575084Sjohnlev extern void xs_notify_xenstore_up(void); 2585084Sjohnlev 2595084Sjohnlev /* 2605084Sjohnlev * Notify clients that xenstore is down 2615084Sjohnlev */ 2625084Sjohnlev extern void xs_notify_xenstore_down(void); 2635084Sjohnlev 2645084Sjohnlev struct xsd_sockmsg; 2655084Sjohnlev 2665084Sjohnlev extern int xenbus_dev_request_and_reply(struct xsd_sockmsg *, void **); 2675084Sjohnlev 2685084Sjohnlev #ifdef __cplusplus 2695084Sjohnlev } 2705084Sjohnlev #endif 2715084Sjohnlev 2725084Sjohnlev #endif /* _SYS_XENBUS_H */ 273