xref: /titanic_52/usr/src/uts/common/xen/sys/xendev.h (revision c1ecd8b9404ee0d96d93f02e82c441b9bb149a3d)
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 #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 /*
101  * A device with xd_vdevnum == VDEV_NOXS does not participate in
102  * xenstore.
103  */
104 #define	VDEV_NOXS	(-1)
105 
106 void	xendev_enum_class(dev_info_t *, xendev_devclass_t);
107 void	xendev_enum_all(dev_info_t *, boolean_t);
108 xendev_devclass_t	xendev_nodename_to_devclass(char *);
109 int	xendev_devclass_ipl(xendev_devclass_t);
110 struct intrspec *xendev_get_ispec(dev_info_t *, uint_t);
111 void	xvdi_suspend(dev_info_t *);
112 int	xvdi_resume(dev_info_t *);
113 int	xvdi_alloc_evtchn(dev_info_t *);
114 int	xvdi_bind_evtchn(dev_info_t *, evtchn_port_t);
115 void	xvdi_free_evtchn(dev_info_t *);
116 int	xvdi_add_event_handler(dev_info_t *, char *,
117 	void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *));
118 void	xvdi_remove_event_handler(dev_info_t *, char *);
119 int	xvdi_get_evtchn(dev_info_t *);
120 int	xvdi_get_vdevnum(dev_info_t *);
121 char	*xvdi_get_xsname(dev_info_t *);
122 char	*xvdi_get_oename(dev_info_t *);
123 domid_t	xvdi_get_oeid(dev_info_t *);
124 void	xvdi_dev_error(dev_info_t *, int, char *);
125 void	xvdi_fatal_error(dev_info_t *, int, char *);
126 void	xvdi_notify_oe(dev_info_t *);
127 int	xvdi_post_event(dev_info_t *, xendev_hotplug_cmd_t);
128 struct  xenbus_device *xvdi_get_xsd(dev_info_t *);
129 int	xvdi_switch_state(dev_info_t *, xenbus_transaction_t, XenbusState);
130 dev_info_t	*xvdi_create_dev(dev_info_t *, xendev_devclass_t,
131     domid_t, int);
132 int	xvdi_init_dev(dev_info_t *);
133 void	xvdi_uninit_dev(dev_info_t *);
134 dev_info_t	*xvdi_find_dev(dev_info_t *, xendev_devclass_t, domid_t, int);
135 
136 /*
137  * common ring interfaces
138  */
139 
140 /*
141  * we need the pad between ring index
142  * and the real ring containing requests/responses,
143  * so that we can map comif_sring_t structure to
144  * any xxxif_sring_t structure defined via macros in ring.h
145  */
146 #define	SRINGPAD		48
147 
148 typedef struct comif_sring {
149 	RING_IDX req_prod, req_event;
150 	RING_IDX rsp_prod, rsp_event;
151 	uint8_t  pad[SRINGPAD];
152 	/*
153 	 * variable length
154 	 * stores real request/response entries
155 	 * entry size is fixed per ring
156 	 */
157 	char ring[1];
158 } comif_sring_t;
159 
160 typedef struct comif_ring_fe {
161 	/*
162 	 * keep the member names as defined in ring.h
163 	 * in order to make use of the pre-defined macros
164 	 */
165 	RING_IDX req_prod_pvt;
166 	RING_IDX rsp_cons;
167 	unsigned int nr_ents;
168 	comif_sring_t *sring;
169 } comif_ring_fe_t;
170 
171 typedef struct comif_ring_be {
172 	/*
173 	 * keep the member names as defined in ring.h
174 	 * in order to make use of the pre-defined macros
175 	 */
176 	RING_IDX rsp_prod_pvt;
177 	RING_IDX req_cons;
178 	unsigned int nr_ents;
179 	comif_sring_t  *sring;
180 } comif_ring_be_t;
181 
182 typedef union comif_ring {
183 	comif_ring_fe_t fr;
184 	comif_ring_be_t br;
185 } comif_ring_t;
186 
187 typedef struct xendev_req {
188 	unsigned long next;
189 	void *req;
190 } xendev_req_t;
191 
192 typedef struct xendev_ring {
193 	ddi_dma_handle_t xr_dma_hdl;
194 	ddi_acc_handle_t xr_acc_hdl;
195 	grant_handle_t xr_grant_hdl;
196 	caddr_t xr_vaddr;
197 	paddr_t xr_paddr;
198 	grant_ref_t xr_gref;
199 	int xr_entry_size;
200 	int xr_frontend;
201 	comif_ring_t xr_sring;
202 } xendev_ring_t;
203 
204 int	xvdi_alloc_ring(dev_info_t *, size_t, size_t, grant_ref_t *,
205 	xendev_ring_t **);
206 void	xvdi_free_ring(xendev_ring_t *);
207 int	xvdi_map_ring(dev_info_t *, size_t, size_t, grant_ref_t,
208 	xendev_ring_t **);
209 void	xvdi_unmap_ring(xendev_ring_t *);
210 uint_t	xvdi_ring_avail_slots(xendev_ring_t *);
211 int	xvdi_ring_has_unconsumed_requests(xendev_ring_t *);
212 int	xvdi_ring_has_incomp_request(xendev_ring_t *);
213 int	xvdi_ring_has_unconsumed_responses(xendev_ring_t *);
214 void*	xvdi_ring_get_request(xendev_ring_t *);
215 int	xvdi_ring_push_request(xendev_ring_t *);
216 void*	xvdi_ring_get_response(xendev_ring_t *);
217 int	xvdi_ring_push_response(xendev_ring_t *);
218 
219 #ifdef	__cplusplus
220 }
221 #endif
222 
223 #endif	/* _SYS_XENDEV_H */
224