162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Private include for xenbus communications.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2005 Rusty Russell, IBM Corporation
562306a36Sopenharmony_ci * Copyright (C) 2005 XenSource Ltd.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or
862306a36Sopenharmony_ci * modify it under the terms of the GNU General Public License version 2
962306a36Sopenharmony_ci * as published by the Free Software Foundation; or, when distributed
1062306a36Sopenharmony_ci * separately from the Linux kernel or incorporated into other
1162306a36Sopenharmony_ci * software packages, subject to the following license:
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
1462306a36Sopenharmony_ci * of this source file (the "Software"), to deal in the Software without
1562306a36Sopenharmony_ci * restriction, including without limitation the rights to use, copy, modify,
1662306a36Sopenharmony_ci * merge, publish, distribute, sublicense, and/or sell copies of the Software,
1762306a36Sopenharmony_ci * and to permit persons to whom the Software is furnished to do so, subject to
1862306a36Sopenharmony_ci * the following conditions:
1962306a36Sopenharmony_ci *
2062306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
2162306a36Sopenharmony_ci * all copies or substantial portions of the Software.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2462306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2562306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2662306a36Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2762306a36Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2862306a36Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2962306a36Sopenharmony_ci * IN THE SOFTWARE.
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#ifndef _XENBUS_XENBUS_H
3362306a36Sopenharmony_ci#define _XENBUS_XENBUS_H
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#include <linux/mutex.h>
3662306a36Sopenharmony_ci#include <linux/uio.h>
3762306a36Sopenharmony_ci#include <xen/xenbus.h>
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define XEN_BUS_ID_SIZE			20
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_cistruct xen_bus_type {
4262306a36Sopenharmony_ci	char *root;
4362306a36Sopenharmony_ci	unsigned int levels;
4462306a36Sopenharmony_ci	int (*get_bus_id)(char bus_id[XEN_BUS_ID_SIZE], const char *nodename);
4562306a36Sopenharmony_ci	int (*probe)(struct xen_bus_type *bus, const char *type,
4662306a36Sopenharmony_ci		     const char *dir);
4762306a36Sopenharmony_ci	bool (*otherend_will_handle)(struct xenbus_watch *watch,
4862306a36Sopenharmony_ci				     const char *path, const char *token);
4962306a36Sopenharmony_ci	void (*otherend_changed)(struct xenbus_watch *watch, const char *path,
5062306a36Sopenharmony_ci				 const char *token);
5162306a36Sopenharmony_ci	struct bus_type bus;
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cienum xenstore_init {
5562306a36Sopenharmony_ci	XS_UNKNOWN,
5662306a36Sopenharmony_ci	XS_PV,
5762306a36Sopenharmony_ci	XS_HVM,
5862306a36Sopenharmony_ci	XS_LOCAL,
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistruct xs_watch_event {
6262306a36Sopenharmony_ci	struct list_head list;
6362306a36Sopenharmony_ci	unsigned int len;
6462306a36Sopenharmony_ci	struct xenbus_watch *handle;
6562306a36Sopenharmony_ci	const char *path;
6662306a36Sopenharmony_ci	const char *token;
6762306a36Sopenharmony_ci	char body[];
6862306a36Sopenharmony_ci};
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cienum xb_req_state {
7162306a36Sopenharmony_ci	xb_req_state_queued,
7262306a36Sopenharmony_ci	xb_req_state_wait_reply,
7362306a36Sopenharmony_ci	xb_req_state_got_reply,
7462306a36Sopenharmony_ci	xb_req_state_aborted
7562306a36Sopenharmony_ci};
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cistruct xb_req_data {
7862306a36Sopenharmony_ci	struct list_head list;
7962306a36Sopenharmony_ci	wait_queue_head_t wq;
8062306a36Sopenharmony_ci	struct xsd_sockmsg msg;
8162306a36Sopenharmony_ci	uint32_t caller_req_id;
8262306a36Sopenharmony_ci	enum xsd_sockmsg_type type;
8362306a36Sopenharmony_ci	char *body;
8462306a36Sopenharmony_ci	const struct kvec *vec;
8562306a36Sopenharmony_ci	int num_vecs;
8662306a36Sopenharmony_ci	int err;
8762306a36Sopenharmony_ci	enum xb_req_state state;
8862306a36Sopenharmony_ci	bool user_req;
8962306a36Sopenharmony_ci	void (*cb)(struct xb_req_data *);
9062306a36Sopenharmony_ci	void *par;
9162306a36Sopenharmony_ci};
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ciextern enum xenstore_init xen_store_domain_type;
9462306a36Sopenharmony_ciextern const struct attribute_group *xenbus_dev_groups[];
9562306a36Sopenharmony_ciextern struct mutex xs_response_mutex;
9662306a36Sopenharmony_ciextern struct list_head xs_reply_list;
9762306a36Sopenharmony_ciextern struct list_head xb_write_list;
9862306a36Sopenharmony_ciextern wait_queue_head_t xb_waitq;
9962306a36Sopenharmony_ciextern struct mutex xb_write_mutex;
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ciint xs_init(void);
10262306a36Sopenharmony_ciint xb_init_comms(void);
10362306a36Sopenharmony_civoid xb_deinit_comms(void);
10462306a36Sopenharmony_ciint xs_watch_msg(struct xs_watch_event *event);
10562306a36Sopenharmony_civoid xs_request_exit(struct xb_req_data *req);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ciint xenbus_match(struct device *_dev, struct device_driver *_drv);
10862306a36Sopenharmony_ciint xenbus_dev_probe(struct device *_dev);
10962306a36Sopenharmony_civoid xenbus_dev_remove(struct device *_dev);
11062306a36Sopenharmony_ciint xenbus_register_driver_common(struct xenbus_driver *drv,
11162306a36Sopenharmony_ci				  struct xen_bus_type *bus,
11262306a36Sopenharmony_ci				  struct module *owner,
11362306a36Sopenharmony_ci				  const char *mod_name);
11462306a36Sopenharmony_ciint xenbus_probe_node(struct xen_bus_type *bus,
11562306a36Sopenharmony_ci		      const char *type,
11662306a36Sopenharmony_ci		      const char *nodename);
11762306a36Sopenharmony_ciint xenbus_probe_devices(struct xen_bus_type *bus);
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_civoid xenbus_dev_changed(const char *node, struct xen_bus_type *bus);
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ciint xenbus_dev_suspend(struct device *dev);
12262306a36Sopenharmony_ciint xenbus_dev_resume(struct device *dev);
12362306a36Sopenharmony_ciint xenbus_dev_cancel(struct device *dev);
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_civoid xenbus_otherend_changed(struct xenbus_watch *watch,
12662306a36Sopenharmony_ci			     const char *path, const char *token,
12762306a36Sopenharmony_ci			     int ignore_on_shutdown);
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ciint xenbus_read_otherend_details(struct xenbus_device *xendev,
13062306a36Sopenharmony_ci				 char *id_node, char *path_node);
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_civoid xenbus_ring_ops_init(void);
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ciint xenbus_dev_request_and_reply(struct xsd_sockmsg *msg, void *par);
13562306a36Sopenharmony_civoid xenbus_dev_queue_reply(struct xb_req_data *req);
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ciextern unsigned int xb_dev_generation_id;
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci#endif
140