xref: /illumos-gate/usr/src/uts/common/xen/sys/xendev.h (revision 349b53dd)
1843e1988Sjohnlev /*
2843e1988Sjohnlev  * CDDL HEADER START
3843e1988Sjohnlev  *
4843e1988Sjohnlev  * The contents of this file are subject to the terms of the
5843e1988Sjohnlev  * Common Development and Distribution License (the "License").
6843e1988Sjohnlev  * You may not use this file except in compliance with the License.
7843e1988Sjohnlev  *
8843e1988Sjohnlev  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9843e1988Sjohnlev  * or http://www.opensolaris.org/os/licensing.
10843e1988Sjohnlev  * See the License for the specific language governing permissions
11843e1988Sjohnlev  * and limitations under the License.
12843e1988Sjohnlev  *
13843e1988Sjohnlev  * When distributing Covered Code, include this CDDL HEADER in each
14843e1988Sjohnlev  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15843e1988Sjohnlev  * If applicable, add the following below this CDDL HEADER, with the
16843e1988Sjohnlev  * fields enclosed by brackets "[]" replaced with your own identifying
17843e1988Sjohnlev  * information: Portions Copyright [yyyy] [name of copyright owner]
18843e1988Sjohnlev  *
19843e1988Sjohnlev  * CDDL HEADER END
20843e1988Sjohnlev  */
21843e1988Sjohnlev 
22843e1988Sjohnlev /*
237f0b8309SEdward Pilatowicz  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24843e1988Sjohnlev  * Use is subject to license terms.
25843e1988Sjohnlev  */
26843e1988Sjohnlev 
27843e1988Sjohnlev #ifndef	_SYS_XENDEV_H
28843e1988Sjohnlev #define	_SYS_XENDEV_H
29843e1988Sjohnlev 
30843e1988Sjohnlev 
31843e1988Sjohnlev #include <sys/hypervisor.h>
32843e1988Sjohnlev #include <sys/taskq.h>
33*349b53ddSStuart Maybee #ifndef	__xpv
34551bc2a6Smrj #include <public/io/ring.h>
35551bc2a6Smrj #include <public/event_channel.h>
36551bc2a6Smrj #include <public/grant_table.h>
37551bc2a6Smrj #endif
38843e1988Sjohnlev #include <xen/sys/xenbus_impl.h>
39843e1988Sjohnlev 
40843e1988Sjohnlev #ifdef	__cplusplus
41843e1988Sjohnlev extern "C" {
42843e1988Sjohnlev #endif
43843e1988Sjohnlev 
447f0b8309SEdward Pilatowicz /*
457f0b8309SEdward Pilatowicz  * Xenbus property interfaces, initialized by framework
467f0b8309SEdward Pilatowicz  */
477f0b8309SEdward Pilatowicz #define	XBP_HP_STATUS		"hotplug-status"	/* backend prop: str */
487f0b8309SEdward Pilatowicz #define	XBV_HP_STATUS_CONN	"connected"		/* backend prop val */
497f0b8309SEdward Pilatowicz #define	XBP_DEV_TYPE		"device-type"		/* backend prop: str */
507f0b8309SEdward Pilatowicz #define	XBV_DEV_TYPE_CD		"cdrom"			/* backend prop val */
517f0b8309SEdward Pilatowicz 
527f0b8309SEdward Pilatowicz /*
537f0b8309SEdward Pilatowicz  * Xenbus property interfaces, initialized by backend disk driver
547f0b8309SEdward Pilatowicz  */
5565908c77Syu, larry liu - Sun Microsystems - Beijing China #define	XBP_SECTOR_SIZE	"sector-size"		/* backend prop: uint */
567f0b8309SEdward Pilatowicz #define	XBP_SECTORS	"sectors"		/* backend prop: uint64 */
577f0b8309SEdward Pilatowicz #define	XBP_INFO	"info"			/* backend prop: uint */
587f0b8309SEdward Pilatowicz #define	XBP_FB		"feature-barrier"	/* backend prop: boolean int */
597f0b8309SEdward Pilatowicz 
607f0b8309SEdward Pilatowicz /*
617f0b8309SEdward Pilatowicz  * Xenbus property interfaces, initialized by frontend disk driver
627f0b8309SEdward Pilatowicz  */
637f0b8309SEdward Pilatowicz #define	XBP_RING_REF	"ring-ref"		/* frontend prop: long */
647f0b8309SEdward Pilatowicz #define	XBP_EVENT_CHAN	"event-channel"		/* frontend prop: long */
657f0b8309SEdward Pilatowicz #define	XBP_PROTOCOL	"protocol"		/* frontend prop: string */
667f0b8309SEdward Pilatowicz 
677f0b8309SEdward Pilatowicz /*
687f0b8309SEdward Pilatowicz  * Xenbus CDROM property interfaces, used by backend and frontend
697f0b8309SEdward Pilatowicz  *
707f0b8309SEdward Pilatowicz  * XBP_MEDIA_REQ_SUP
717f0b8309SEdward Pilatowicz  *	- Backend xenbus property located at:
727f0b8309SEdward Pilatowicz  *		backend/vbd/<domU_id>/<domU_dev>/media-req-sup
737f0b8309SEdward Pilatowicz  *	- Set by the backend, consumed by the frontend.
747f0b8309SEdward Pilatowicz  *	- Cosumed by the frontend.
757f0b8309SEdward Pilatowicz  *	- A boolean integer property indicating backend support
767f0b8309SEdward Pilatowicz  *	  for the XBP_MEDIA_REQ property.
777f0b8309SEdward Pilatowicz  *
787f0b8309SEdward Pilatowicz  * XBP_MEDIA_REQ
797f0b8309SEdward Pilatowicz  *	- Frontend xenbus property located at:
807f0b8309SEdward Pilatowicz  *		/local/domain/<domU_id>/device/vbd/<domU_dev>/media-req
817f0b8309SEdward Pilatowicz  *	- Set and consumed by both the frontend and backend.
827f0b8309SEdward Pilatowicz  *	- Possible values:
837f0b8309SEdward Pilatowicz  *		XBV_MEDIA_REQ_NONE, XBV_MEDIA_REQ_LOCK, and XBV_MEDIA_REQ_EJECT
847f0b8309SEdward Pilatowicz  *	- Only applies to CDROM devices.
857f0b8309SEdward Pilatowicz  *
867f0b8309SEdward Pilatowicz  * XBV_MEDIA_REQ_NONE
877f0b8309SEdward Pilatowicz  * 	- XBP_MEDIA_REQ property valud
887f0b8309SEdward Pilatowicz  *	- Set and consumed by both the frontend and backend.
897f0b8309SEdward Pilatowicz  *	- Indicates that there are no currently outstanding media requet
907f0b8309SEdward Pilatowicz  *	  operations.
917f0b8309SEdward Pilatowicz  *
927f0b8309SEdward Pilatowicz  * XBV_MEDIA_REQ_LOCK
937f0b8309SEdward Pilatowicz  * 	- XBP_MEDIA_REQ property valud
947f0b8309SEdward Pilatowicz  *	- Set by the frontend, consumed by the backend.
957f0b8309SEdward Pilatowicz  *	- Indicates to the backend that the currenct media is locked
967f0b8309SEdward Pilatowicz  *	  and changes to the media (via xm block-configure for example)
977f0b8309SEdward Pilatowicz  *	  should not be allowed.
987f0b8309SEdward Pilatowicz  *
997f0b8309SEdward Pilatowicz  * XBV_MEDIA_REQ_EJECT
1007f0b8309SEdward Pilatowicz  * 	- XBP_MEDIA_REQ property valud
1017f0b8309SEdward Pilatowicz  *	- Set by the frontend, consumed by the backend.
1027f0b8309SEdward Pilatowicz  *	- Indicates to the backend that the currenct media should be ejected.
1037f0b8309SEdward Pilatowicz  *	  This means that the backend should close it's connection to
1047f0b8309SEdward Pilatowicz  *	  the frontend device, close it's current backing store device/file,
1057f0b8309SEdward Pilatowicz  *	  and then set the media-req property to XBV_MEDIA_REQ_NONE.  (to
1067f0b8309SEdward Pilatowicz  *	  indicate that the eject operation is complete.)
1077f0b8309SEdward Pilatowicz  */
1087f0b8309SEdward Pilatowicz #define	XBP_MEDIA_REQ_SUP	"media-req-sup"	/* backend prop: boolean int */
1097f0b8309SEdward Pilatowicz #define	XBP_MEDIA_REQ		"media-req"	/* frontend prop: str */
1107f0b8309SEdward Pilatowicz #define	XBV_MEDIA_REQ_NONE	"none"		/* frontend prop val */
1117f0b8309SEdward Pilatowicz #define	XBV_MEDIA_REQ_LOCK	"lock"		/* frontend prop val */
1127f0b8309SEdward Pilatowicz #define	XBV_MEDIA_REQ_EJECT	"eject"		/* frontend prop val */
1137f0b8309SEdward Pilatowicz 
114843e1988Sjohnlev /*
115843e1988Sjohnlev  * Xen device class codes
116843e1988Sjohnlev  */
117843e1988Sjohnlev typedef enum {
118843e1988Sjohnlev 	XEN_INVAL = -1,
119843e1988Sjohnlev 	XEN_CONSOLE = 0,
120843e1988Sjohnlev 	XEN_VNET,
121843e1988Sjohnlev 	XEN_VBLK,
122843e1988Sjohnlev 	XEN_XENBUS,
123843e1988Sjohnlev 	XEN_DOMCAPS,
124843e1988Sjohnlev 	XEN_BALLOON,
125843e1988Sjohnlev 	XEN_EVTCHN,
126843e1988Sjohnlev 	XEN_PRIVCMD,
1277eea693dSMark Johnson 	XEN_BLKTAP,
128843e1988Sjohnlev 	XEN_LASTCLASS
129843e1988Sjohnlev } xendev_devclass_t;
130843e1988Sjohnlev 
131843e1988Sjohnlev /*
132843e1988Sjohnlev  * Hotplug request sent to userland event handler.
133843e1988Sjohnlev  */
134843e1988Sjohnlev typedef enum {
135843e1988Sjohnlev 	XEN_HP_ADD,
136843e1988Sjohnlev 	XEN_HP_REMOVE
137843e1988Sjohnlev } xendev_hotplug_cmd_t;
138843e1988Sjohnlev 
139843e1988Sjohnlev /*
140843e1988Sjohnlev  * Hotplug status.
141843e1988Sjohnlev  *
142843e1988Sjohnlev  * In fact, the Xen tools can write any arbitrary string into the
143843e1988Sjohnlev  * hotplug-status node. We represent the known values here - anything
144843e1988Sjohnlev  * else will be 'Unrecognized'.
145843e1988Sjohnlev  */
146843e1988Sjohnlev typedef enum {
147843e1988Sjohnlev 	Unrecognized,
148843e1988Sjohnlev 	Connected
149843e1988Sjohnlev } xendev_hotplug_state_t;
150843e1988Sjohnlev 
151843e1988Sjohnlev struct xendev_ppd {
1527eea693dSMark Johnson 	kmutex_t		xd_evt_lk;
153843e1988Sjohnlev 	int			xd_evtchn;
154843e1988Sjohnlev 	struct intrspec		xd_ispec;
1557eea693dSMark Johnson 
156843e1988Sjohnlev 	xendev_devclass_t	xd_devclass;
157843e1988Sjohnlev 	domid_t			xd_domain;
158843e1988Sjohnlev 	int			xd_vdevnum;
1597eea693dSMark Johnson 
1607eea693dSMark Johnson 	kmutex_t		xd_ndi_lk;
161843e1988Sjohnlev 	struct xenbus_device	xd_xsdev;
162843e1988Sjohnlev 	struct xenbus_watch	xd_hp_watch;
163843e1988Sjohnlev 	struct xenbus_watch	xd_bepath_watch;
164843e1988Sjohnlev 	ddi_callback_id_t	xd_oe_ehid;
165843e1988Sjohnlev 	ddi_callback_id_t	xd_hp_ehid;
166843e1988Sjohnlev 	ddi_taskq_t		*xd_oe_taskq;
167843e1988Sjohnlev 	ddi_taskq_t		*xd_hp_taskq;
1687f0b8309SEdward Pilatowicz 	ddi_taskq_t		*xd_xb_watch_taskq;
1697f0b8309SEdward Pilatowicz 	list_t			xd_xb_watches;
170843e1988Sjohnlev };
171843e1988Sjohnlev 
172843e1988Sjohnlev #define	XS_OE_STATE	"SUNW,xendev:otherend_state"
173843e1988Sjohnlev #define	XS_HP_STATE	"SUNW,xendev:hotplug_state"
174843e1988Sjohnlev 
1751ca30e39Sjohnlev /*
1761ca30e39Sjohnlev  * A device with xd_vdevnum == VDEV_NOXS does not participate in
1771ca30e39Sjohnlev  * xenstore.
1781ca30e39Sjohnlev  */
1791ca30e39Sjohnlev #define	VDEV_NOXS	(-1)
1801ca30e39Sjohnlev 
181843e1988Sjohnlev void	xendev_enum_class(dev_info_t *, xendev_devclass_t);
182843e1988Sjohnlev void	xendev_enum_all(dev_info_t *, boolean_t);
183843e1988Sjohnlev xendev_devclass_t	xendev_nodename_to_devclass(char *);
184843e1988Sjohnlev int	xendev_devclass_ipl(xendev_devclass_t);
185843e1988Sjohnlev struct intrspec *xendev_get_ispec(dev_info_t *, uint_t);
186843e1988Sjohnlev void	xvdi_suspend(dev_info_t *);
187843e1988Sjohnlev int	xvdi_resume(dev_info_t *);
188843e1988Sjohnlev int	xvdi_alloc_evtchn(dev_info_t *);
189843e1988Sjohnlev int	xvdi_bind_evtchn(dev_info_t *, evtchn_port_t);
190843e1988Sjohnlev void	xvdi_free_evtchn(dev_info_t *);
191843e1988Sjohnlev int	xvdi_add_event_handler(dev_info_t *, char *,
1927eea693dSMark Johnson 	void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *),
1937eea693dSMark Johnson 	void *arg);
194843e1988Sjohnlev void	xvdi_remove_event_handler(dev_info_t *, char *);
195843e1988Sjohnlev int	xvdi_get_evtchn(dev_info_t *);
196843e1988Sjohnlev int	xvdi_get_vdevnum(dev_info_t *);
197843e1988Sjohnlev char	*xvdi_get_xsname(dev_info_t *);
198843e1988Sjohnlev char	*xvdi_get_oename(dev_info_t *);
199843e1988Sjohnlev domid_t	xvdi_get_oeid(dev_info_t *);
200843e1988Sjohnlev void	xvdi_dev_error(dev_info_t *, int, char *);
201843e1988Sjohnlev void	xvdi_fatal_error(dev_info_t *, int, char *);
202843e1988Sjohnlev void	xvdi_notify_oe(dev_info_t *);
203843e1988Sjohnlev int	xvdi_post_event(dev_info_t *, xendev_hotplug_cmd_t);
204843e1988Sjohnlev struct  xenbus_device *xvdi_get_xsd(dev_info_t *);
205843e1988Sjohnlev int	xvdi_switch_state(dev_info_t *, xenbus_transaction_t, XenbusState);
206843e1988Sjohnlev dev_info_t	*xvdi_create_dev(dev_info_t *, xendev_devclass_t,
207843e1988Sjohnlev     domid_t, int);
208843e1988Sjohnlev int	xvdi_init_dev(dev_info_t *);
209843e1988Sjohnlev void	xvdi_uninit_dev(dev_info_t *);
210843e1988Sjohnlev dev_info_t	*xvdi_find_dev(dev_info_t *, xendev_devclass_t, domid_t, int);
211843e1988Sjohnlev 
2127f0b8309SEdward Pilatowicz extern int xvdi_add_xb_watch_handler(dev_info_t *, const char *,
2137f0b8309SEdward Pilatowicz     const char *, xvdi_xb_watch_cb_t cb, void *);
2147f0b8309SEdward Pilatowicz extern void xvdi_remove_xb_watch_handlers(dev_info_t *);
2157f0b8309SEdward Pilatowicz 
216843e1988Sjohnlev /*
217843e1988Sjohnlev  * common ring interfaces
218843e1988Sjohnlev  */
219843e1988Sjohnlev 
220843e1988Sjohnlev /*
221843e1988Sjohnlev  * we need the pad between ring index
222843e1988Sjohnlev  * and the real ring containing requests/responses,
223843e1988Sjohnlev  * so that we can map comif_sring_t structure to
224843e1988Sjohnlev  * any xxxif_sring_t structure defined via macros in ring.h
225843e1988Sjohnlev  */
226843e1988Sjohnlev #define	SRINGPAD		48
227843e1988Sjohnlev 
228843e1988Sjohnlev typedef struct comif_sring {
229843e1988Sjohnlev 	RING_IDX req_prod, req_event;
230843e1988Sjohnlev 	RING_IDX rsp_prod, rsp_event;
231843e1988Sjohnlev 	uint8_t  pad[SRINGPAD];
232843e1988Sjohnlev 	/*
233843e1988Sjohnlev 	 * variable length
234843e1988Sjohnlev 	 * stores real request/response entries
235843e1988Sjohnlev 	 * entry size is fixed per ring
236843e1988Sjohnlev 	 */
237843e1988Sjohnlev 	char ring[1];
238843e1988Sjohnlev } comif_sring_t;
239843e1988Sjohnlev 
240843e1988Sjohnlev typedef struct comif_ring_fe {
241843e1988Sjohnlev 	/*
242843e1988Sjohnlev 	 * keep the member names as defined in ring.h
243843e1988Sjohnlev 	 * in order to make use of the pre-defined macros
244843e1988Sjohnlev 	 */
245843e1988Sjohnlev 	RING_IDX req_prod_pvt;
246843e1988Sjohnlev 	RING_IDX rsp_cons;
247843e1988Sjohnlev 	unsigned int nr_ents;
248843e1988Sjohnlev 	comif_sring_t *sring;
249843e1988Sjohnlev } comif_ring_fe_t;
250843e1988Sjohnlev 
251843e1988Sjohnlev typedef struct comif_ring_be {
252843e1988Sjohnlev 	/*
253843e1988Sjohnlev 	 * keep the member names as defined in ring.h
254843e1988Sjohnlev 	 * in order to make use of the pre-defined macros
255843e1988Sjohnlev 	 */
256843e1988Sjohnlev 	RING_IDX rsp_prod_pvt;
257843e1988Sjohnlev 	RING_IDX req_cons;
258843e1988Sjohnlev 	unsigned int nr_ents;
259843e1988Sjohnlev 	comif_sring_t  *sring;
260843e1988Sjohnlev } comif_ring_be_t;
261843e1988Sjohnlev 
262843e1988Sjohnlev typedef union comif_ring {
263843e1988Sjohnlev 	comif_ring_fe_t fr;
264843e1988Sjohnlev 	comif_ring_be_t br;
265843e1988Sjohnlev } comif_ring_t;
266843e1988Sjohnlev 
267843e1988Sjohnlev typedef struct xendev_req {
268843e1988Sjohnlev 	unsigned long next;
269843e1988Sjohnlev 	void *req;
270843e1988Sjohnlev } xendev_req_t;
271843e1988Sjohnlev 
272843e1988Sjohnlev typedef struct xendev_ring {
273843e1988Sjohnlev 	ddi_dma_handle_t xr_dma_hdl;
274843e1988Sjohnlev 	ddi_acc_handle_t xr_acc_hdl;
275843e1988Sjohnlev 	grant_handle_t xr_grant_hdl;
276843e1988Sjohnlev 	caddr_t xr_vaddr;
277843e1988Sjohnlev 	paddr_t xr_paddr;
278843e1988Sjohnlev 	grant_ref_t xr_gref;
279843e1988Sjohnlev 	int xr_entry_size;
280843e1988Sjohnlev 	int xr_frontend;
281843e1988Sjohnlev 	comif_ring_t xr_sring;
282843e1988Sjohnlev } xendev_ring_t;
283843e1988Sjohnlev 
284843e1988Sjohnlev int	xvdi_alloc_ring(dev_info_t *, size_t, size_t, grant_ref_t *,
285843e1988Sjohnlev 	xendev_ring_t **);
286843e1988Sjohnlev void	xvdi_free_ring(xendev_ring_t *);
287843e1988Sjohnlev int	xvdi_map_ring(dev_info_t *, size_t, size_t, grant_ref_t,
288843e1988Sjohnlev 	xendev_ring_t **);
289843e1988Sjohnlev void	xvdi_unmap_ring(xendev_ring_t *);
290843e1988Sjohnlev uint_t	xvdi_ring_avail_slots(xendev_ring_t *);
291843e1988Sjohnlev int	xvdi_ring_has_unconsumed_requests(xendev_ring_t *);
292843e1988Sjohnlev int	xvdi_ring_has_incomp_request(xendev_ring_t *);
293843e1988Sjohnlev int	xvdi_ring_has_unconsumed_responses(xendev_ring_t *);
294843e1988Sjohnlev void*	xvdi_ring_get_request(xendev_ring_t *);
295843e1988Sjohnlev int	xvdi_ring_push_request(xendev_ring_t *);
296843e1988Sjohnlev void*	xvdi_ring_get_response(xendev_ring_t *);
297843e1988Sjohnlev int	xvdi_ring_push_response(xendev_ring_t *);
298843e1988Sjohnlev 
299843e1988Sjohnlev #ifdef	__cplusplus
300843e1988Sjohnlev }
301843e1988Sjohnlev #endif
302843e1988Sjohnlev 
303843e1988Sjohnlev #endif	/* _SYS_XENDEV_H */
304