xref: /illumos-gate/usr/src/uts/common/xen/sys/xendev.h (revision 968633ad8faee931821fd6b656eb0d96d4b186c0)
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 2008 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 
31 #include <sys/hypervisor.h>
32 #include <sys/taskq.h>
33 #ifdef	XPV_HVM_DRIVER
34 #include <public/io/ring.h>
35 #include <public/event_channel.h>
36 #include <public/grant_table.h>
37 #endif
38 #include <xen/sys/xenbus_impl.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Xen device class codes
46  */
47 typedef enum {
48 	XEN_INVAL = -1,
49 	XEN_CONSOLE = 0,
50 	XEN_VNET,
51 	XEN_VBLK,
52 	XEN_XENBUS,
53 	XEN_DOMCAPS,
54 	XEN_BALLOON,
55 	XEN_EVTCHN,
56 	XEN_PRIVCMD,
57 	XEN_BLKTAP,
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 	kmutex_t		xd_evt_lk;
83 	int			xd_evtchn;
84 	struct intrspec		xd_ispec;
85 
86 	xendev_devclass_t	xd_devclass;
87 	domid_t			xd_domain;
88 	int			xd_vdevnum;
89 
90 	kmutex_t		xd_ndi_lk;
91 	struct xenbus_device	xd_xsdev;
92 	struct xenbus_watch	xd_hp_watch;
93 	struct xenbus_watch	xd_bepath_watch;
94 	ddi_callback_id_t	xd_oe_ehid;
95 	ddi_callback_id_t	xd_hp_ehid;
96 	ddi_taskq_t		*xd_oe_taskq;
97 	ddi_taskq_t		*xd_hp_taskq;
98 };
99 
100 #define	XS_OE_STATE	"SUNW,xendev:otherend_state"
101 #define	XS_HP_STATE	"SUNW,xendev:hotplug_state"
102 
103 /*
104  * A device with xd_vdevnum == VDEV_NOXS does not participate in
105  * xenstore.
106  */
107 #define	VDEV_NOXS	(-1)
108 
109 void	xendev_enum_class(dev_info_t *, xendev_devclass_t);
110 void	xendev_enum_all(dev_info_t *, boolean_t);
111 xendev_devclass_t	xendev_nodename_to_devclass(char *);
112 int	xendev_devclass_ipl(xendev_devclass_t);
113 struct intrspec *xendev_get_ispec(dev_info_t *, uint_t);
114 void	xvdi_suspend(dev_info_t *);
115 int	xvdi_resume(dev_info_t *);
116 int	xvdi_alloc_evtchn(dev_info_t *);
117 int	xvdi_bind_evtchn(dev_info_t *, evtchn_port_t);
118 void	xvdi_free_evtchn(dev_info_t *);
119 int	xvdi_add_event_handler(dev_info_t *, char *,
120 	void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *),
121 	void *arg);
122 void	xvdi_remove_event_handler(dev_info_t *, char *);
123 int	xvdi_get_evtchn(dev_info_t *);
124 int	xvdi_get_vdevnum(dev_info_t *);
125 char	*xvdi_get_xsname(dev_info_t *);
126 char	*xvdi_get_oename(dev_info_t *);
127 domid_t	xvdi_get_oeid(dev_info_t *);
128 void	xvdi_dev_error(dev_info_t *, int, char *);
129 void	xvdi_fatal_error(dev_info_t *, int, char *);
130 void	xvdi_notify_oe(dev_info_t *);
131 int	xvdi_post_event(dev_info_t *, xendev_hotplug_cmd_t);
132 struct  xenbus_device *xvdi_get_xsd(dev_info_t *);
133 int	xvdi_switch_state(dev_info_t *, xenbus_transaction_t, XenbusState);
134 dev_info_t	*xvdi_create_dev(dev_info_t *, xendev_devclass_t,
135     domid_t, int);
136 int	xvdi_init_dev(dev_info_t *);
137 void	xvdi_uninit_dev(dev_info_t *);
138 dev_info_t	*xvdi_find_dev(dev_info_t *, xendev_devclass_t, domid_t, int);
139 
140 /*
141  * common ring interfaces
142  */
143 
144 /*
145  * we need the pad between ring index
146  * and the real ring containing requests/responses,
147  * so that we can map comif_sring_t structure to
148  * any xxxif_sring_t structure defined via macros in ring.h
149  */
150 #define	SRINGPAD		48
151 
152 typedef struct comif_sring {
153 	RING_IDX req_prod, req_event;
154 	RING_IDX rsp_prod, rsp_event;
155 	uint8_t  pad[SRINGPAD];
156 	/*
157 	 * variable length
158 	 * stores real request/response entries
159 	 * entry size is fixed per ring
160 	 */
161 	char ring[1];
162 } comif_sring_t;
163 
164 typedef struct comif_ring_fe {
165 	/*
166 	 * keep the member names as defined in ring.h
167 	 * in order to make use of the pre-defined macros
168 	 */
169 	RING_IDX req_prod_pvt;
170 	RING_IDX rsp_cons;
171 	unsigned int nr_ents;
172 	comif_sring_t *sring;
173 } comif_ring_fe_t;
174 
175 typedef struct comif_ring_be {
176 	/*
177 	 * keep the member names as defined in ring.h
178 	 * in order to make use of the pre-defined macros
179 	 */
180 	RING_IDX rsp_prod_pvt;
181 	RING_IDX req_cons;
182 	unsigned int nr_ents;
183 	comif_sring_t  *sring;
184 } comif_ring_be_t;
185 
186 typedef union comif_ring {
187 	comif_ring_fe_t fr;
188 	comif_ring_be_t br;
189 } comif_ring_t;
190 
191 typedef struct xendev_req {
192 	unsigned long next;
193 	void *req;
194 } xendev_req_t;
195 
196 typedef struct xendev_ring {
197 	ddi_dma_handle_t xr_dma_hdl;
198 	ddi_acc_handle_t xr_acc_hdl;
199 	grant_handle_t xr_grant_hdl;
200 	caddr_t xr_vaddr;
201 	paddr_t xr_paddr;
202 	grant_ref_t xr_gref;
203 	int xr_entry_size;
204 	int xr_frontend;
205 	comif_ring_t xr_sring;
206 } xendev_ring_t;
207 
208 int	xvdi_alloc_ring(dev_info_t *, size_t, size_t, grant_ref_t *,
209 	xendev_ring_t **);
210 void	xvdi_free_ring(xendev_ring_t *);
211 int	xvdi_map_ring(dev_info_t *, size_t, size_t, grant_ref_t,
212 	xendev_ring_t **);
213 void	xvdi_unmap_ring(xendev_ring_t *);
214 uint_t	xvdi_ring_avail_slots(xendev_ring_t *);
215 int	xvdi_ring_has_unconsumed_requests(xendev_ring_t *);
216 int	xvdi_ring_has_incomp_request(xendev_ring_t *);
217 int	xvdi_ring_has_unconsumed_responses(xendev_ring_t *);
218 void*	xvdi_ring_get_request(xendev_ring_t *);
219 int	xvdi_ring_push_request(xendev_ring_t *);
220 void*	xvdi_ring_get_response(xendev_ring_t *);
221 int	xvdi_ring_push_response(xendev_ring_t *);
222 
223 #ifdef	__cplusplus
224 }
225 #endif
226 
227 #endif	/* _SYS_XENDEV_H */
228