xref: /illumos-gate/usr/src/uts/common/xen/sys/xendev.h (revision 2850d85b7b93f31e578520dc3b3feb24db609c62)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_XENDEV_H
28 #define	_SYS_XENDEV_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/hypervisor.h>
33 #include <sys/taskq.h>
34 #ifdef	XPV_HVM_DRIVER
35 #include <public/io/ring.h>
36 #include <public/event_channel.h>
37 #include <public/grant_table.h>
38 #endif
39 #include <xen/sys/xenbus_impl.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * Xen device class codes
47  */
48 typedef enum {
49 	XEN_INVAL = -1,
50 	XEN_CONSOLE = 0,
51 	XEN_VNET,
52 	XEN_VBLK,
53 	XEN_XENBUS,
54 	XEN_DOMCAPS,
55 	XEN_BALLOON,
56 	XEN_EVTCHN,
57 	XEN_PRIVCMD,
58 	XEN_LASTCLASS
59 } xendev_devclass_t;
60 
61 /*
62  * Hotplug request sent to userland event handler.
63  */
64 typedef enum {
65 	XEN_HP_ADD,
66 	XEN_HP_REMOVE
67 } xendev_hotplug_cmd_t;
68 
69 /*
70  * Hotplug status.
71  *
72  * In fact, the Xen tools can write any arbitrary string into the
73  * hotplug-status node. We represent the known values here - anything
74  * else will be 'Unrecognized'.
75  */
76 typedef enum {
77 	Unrecognized,
78 	Connected
79 } xendev_hotplug_state_t;
80 
81 struct xendev_ppd {
82 	int			xd_evtchn;
83 	struct intrspec		xd_ispec;
84 	xendev_devclass_t	xd_devclass;
85 	domid_t			xd_domain;
86 	int			xd_vdevnum;
87 	struct xenbus_device	xd_xsdev;
88 	struct xenbus_watch	xd_hp_watch;
89 	struct xenbus_watch	xd_bepath_watch;
90 	kmutex_t		xd_lk;
91 	ddi_callback_id_t	xd_oe_ehid;
92 	ddi_callback_id_t	xd_hp_ehid;
93 	ddi_taskq_t		*xd_oe_taskq;
94 	ddi_taskq_t		*xd_hp_taskq;
95 };
96 
97 #define	XS_OE_STATE	"SUNW,xendev:otherend_state"
98 #define	XS_HP_STATE	"SUNW,xendev:hotplug_state"
99 
100 void	xendev_enum_class(dev_info_t *, xendev_devclass_t);
101 void	xendev_enum_all(dev_info_t *, boolean_t);
102 xendev_devclass_t	xendev_nodename_to_devclass(char *);
103 int	xendev_devclass_ipl(xendev_devclass_t);
104 struct intrspec *xendev_get_ispec(dev_info_t *, uint_t);
105 void	xvdi_suspend(dev_info_t *);
106 int	xvdi_resume(dev_info_t *);
107 int	xvdi_alloc_evtchn(dev_info_t *);
108 int	xvdi_bind_evtchn(dev_info_t *, evtchn_port_t);
109 void	xvdi_free_evtchn(dev_info_t *);
110 int	xvdi_add_event_handler(dev_info_t *, char *,
111 	void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *));
112 void	xvdi_remove_event_handler(dev_info_t *, char *);
113 int	xvdi_get_evtchn(dev_info_t *);
114 int	xvdi_get_vdevnum(dev_info_t *);
115 char	*xvdi_get_xsname(dev_info_t *);
116 char	*xvdi_get_oename(dev_info_t *);
117 domid_t	xvdi_get_oeid(dev_info_t *);
118 void	xvdi_dev_error(dev_info_t *, int, char *);
119 void	xvdi_fatal_error(dev_info_t *, int, char *);
120 void	xvdi_notify_oe(dev_info_t *);
121 int	xvdi_post_event(dev_info_t *, xendev_hotplug_cmd_t);
122 struct  xenbus_device *xvdi_get_xsd(dev_info_t *);
123 int	xvdi_switch_state(dev_info_t *, xenbus_transaction_t, XenbusState);
124 dev_info_t	*xvdi_create_dev(dev_info_t *, xendev_devclass_t,
125     domid_t, int);
126 int	xvdi_init_dev(dev_info_t *);
127 void	xvdi_uninit_dev(dev_info_t *);
128 dev_info_t	*xvdi_find_dev(dev_info_t *, xendev_devclass_t, domid_t, int);
129 
130 /*
131  * common ring interfaces
132  */
133 
134 /*
135  * we need the pad between ring index
136  * and the real ring containing requests/responses,
137  * so that we can map comif_sring_t structure to
138  * any xxxif_sring_t structure defined via macros in ring.h
139  */
140 #define	SRINGPAD		48
141 
142 typedef struct comif_sring {
143 	RING_IDX req_prod, req_event;
144 	RING_IDX rsp_prod, rsp_event;
145 	uint8_t  pad[SRINGPAD];
146 	/*
147 	 * variable length
148 	 * stores real request/response entries
149 	 * entry size is fixed per ring
150 	 */
151 	char ring[1];
152 } comif_sring_t;
153 
154 typedef struct comif_ring_fe {
155 	/*
156 	 * keep the member names as defined in ring.h
157 	 * in order to make use of the pre-defined macros
158 	 */
159 	RING_IDX req_prod_pvt;
160 	RING_IDX rsp_cons;
161 	unsigned int nr_ents;
162 	comif_sring_t *sring;
163 } comif_ring_fe_t;
164 
165 typedef struct comif_ring_be {
166 	/*
167 	 * keep the member names as defined in ring.h
168 	 * in order to make use of the pre-defined macros
169 	 */
170 	RING_IDX rsp_prod_pvt;
171 	RING_IDX req_cons;
172 	unsigned int nr_ents;
173 	comif_sring_t  *sring;
174 } comif_ring_be_t;
175 
176 typedef union comif_ring {
177 	comif_ring_fe_t fr;
178 	comif_ring_be_t br;
179 } comif_ring_t;
180 
181 typedef struct xendev_req {
182 	unsigned long next;
183 	void *req;
184 } xendev_req_t;
185 
186 typedef struct xendev_ring {
187 	ddi_dma_handle_t xr_dma_hdl;
188 	ddi_acc_handle_t xr_acc_hdl;
189 	grant_handle_t xr_grant_hdl;
190 	caddr_t xr_vaddr;
191 	paddr_t xr_paddr;
192 	grant_ref_t xr_gref;
193 	int xr_entry_size;
194 	int xr_frontend;
195 	comif_ring_t xr_sring;
196 } xendev_ring_t;
197 
198 int	xvdi_alloc_ring(dev_info_t *, size_t, size_t, grant_ref_t *,
199 	xendev_ring_t **);
200 void	xvdi_free_ring(xendev_ring_t *);
201 int	xvdi_map_ring(dev_info_t *, size_t, size_t, grant_ref_t,
202 	xendev_ring_t **);
203 void	xvdi_unmap_ring(xendev_ring_t *);
204 uint_t	xvdi_ring_avail_slots(xendev_ring_t *);
205 int	xvdi_ring_has_unconsumed_requests(xendev_ring_t *);
206 int	xvdi_ring_has_incomp_request(xendev_ring_t *);
207 int	xvdi_ring_has_unconsumed_responses(xendev_ring_t *);
208 void*	xvdi_ring_get_request(xendev_ring_t *);
209 int	xvdi_ring_push_request(xendev_ring_t *);
210 void*	xvdi_ring_get_response(xendev_ring_t *);
211 int	xvdi_ring_push_response(xendev_ring_t *);
212 
213 #ifdef	__cplusplus
214 }
215 #endif
216 
217 #endif	/* _SYS_XENDEV_H */
218