xref: /titanic_44/usr/src/uts/common/xen/sys/xendev.h (revision 416369f6ab2ab327f0e71cbdb854f9e5bdc6f5ec)
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 #include <xen/sys/xenbus_impl.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * Xen device class codes
42  */
43 typedef enum {
44 	XEN_INVAL = -1,
45 	XEN_CONSOLE = 0,
46 	XEN_VNET,
47 	XEN_VBLK,
48 	XEN_XENBUS,
49 	XEN_DOMCAPS,
50 	XEN_BALLOON,
51 	XEN_EVTCHN,
52 	XEN_PRIVCMD,
53 	XEN_LASTCLASS
54 } xendev_devclass_t;
55 
56 /*
57  * Hotplug request sent to userland event handler.
58  */
59 typedef enum {
60 	XEN_HP_ADD,
61 	XEN_HP_REMOVE
62 } xendev_hotplug_cmd_t;
63 
64 /*
65  * Hotplug status.
66  *
67  * In fact, the Xen tools can write any arbitrary string into the
68  * hotplug-status node. We represent the known values here - anything
69  * else will be 'Unrecognized'.
70  */
71 typedef enum {
72 	Unrecognized,
73 	Connected
74 } xendev_hotplug_state_t;
75 
76 struct xendev_ppd {
77 	int			xd_evtchn;
78 	struct intrspec		xd_ispec;
79 	xendev_devclass_t	xd_devclass;
80 	domid_t			xd_domain;
81 	int			xd_vdevnum;
82 	struct xenbus_device	xd_xsdev;
83 	struct xenbus_watch	xd_hp_watch;
84 	struct xenbus_watch	xd_bepath_watch;
85 	kmutex_t		xd_lk;
86 	ddi_callback_id_t	xd_oe_ehid;
87 	ddi_callback_id_t	xd_hp_ehid;
88 	ddi_taskq_t		*xd_oe_taskq;
89 	ddi_taskq_t		*xd_hp_taskq;
90 };
91 
92 #define	XS_OE_STATE	"SUNW,xendev:otherend_state"
93 #define	XS_HP_STATE	"SUNW,xendev:hotplug_state"
94 
95 void	xendev_enum_class(dev_info_t *, xendev_devclass_t);
96 void	xendev_enum_all(dev_info_t *, boolean_t);
97 xendev_devclass_t	xendev_nodename_to_devclass(char *);
98 int	xendev_devclass_ipl(xendev_devclass_t);
99 struct intrspec *xendev_get_ispec(dev_info_t *, uint_t);
100 void	xvdi_suspend(dev_info_t *);
101 int	xvdi_resume(dev_info_t *);
102 int	xvdi_alloc_evtchn(dev_info_t *);
103 int	xvdi_bind_evtchn(dev_info_t *, evtchn_port_t);
104 void	xvdi_free_evtchn(dev_info_t *);
105 int	xvdi_add_event_handler(dev_info_t *, char *,
106 	void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *));
107 void	xvdi_remove_event_handler(dev_info_t *, char *);
108 int	xvdi_get_evtchn(dev_info_t *);
109 int	xvdi_get_vdevnum(dev_info_t *);
110 char	*xvdi_get_xsname(dev_info_t *);
111 char	*xvdi_get_oename(dev_info_t *);
112 domid_t	xvdi_get_oeid(dev_info_t *);
113 void	xvdi_dev_error(dev_info_t *, int, char *);
114 void	xvdi_fatal_error(dev_info_t *, int, char *);
115 void	xvdi_notify_oe(dev_info_t *);
116 int	xvdi_post_event(dev_info_t *, xendev_hotplug_cmd_t);
117 struct  xenbus_device *xvdi_get_xsd(dev_info_t *);
118 int	xvdi_switch_state(dev_info_t *, xenbus_transaction_t, XenbusState);
119 dev_info_t	*xvdi_create_dev(dev_info_t *, xendev_devclass_t,
120     domid_t, int);
121 int	xvdi_init_dev(dev_info_t *);
122 void	xvdi_uninit_dev(dev_info_t *);
123 dev_info_t	*xvdi_find_dev(dev_info_t *, xendev_devclass_t, domid_t, int);
124 
125 /*
126  * common ring interfaces
127  */
128 
129 /*
130  * we need the pad between ring index
131  * and the real ring containing requests/responses,
132  * so that we can map comif_sring_t structure to
133  * any xxxif_sring_t structure defined via macros in ring.h
134  */
135 #define	SRINGPAD		48
136 
137 typedef struct comif_sring {
138 	RING_IDX req_prod, req_event;
139 	RING_IDX rsp_prod, rsp_event;
140 	uint8_t  pad[SRINGPAD];
141 	/*
142 	 * variable length
143 	 * stores real request/response entries
144 	 * entry size is fixed per ring
145 	 */
146 	char ring[1];
147 } comif_sring_t;
148 
149 typedef struct comif_ring_fe {
150 	/*
151 	 * keep the member names as defined in ring.h
152 	 * in order to make use of the pre-defined macros
153 	 */
154 	RING_IDX req_prod_pvt;
155 	RING_IDX rsp_cons;
156 	unsigned int nr_ents;
157 	comif_sring_t *sring;
158 } comif_ring_fe_t;
159 
160 typedef struct comif_ring_be {
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 rsp_prod_pvt;
166 	RING_IDX req_cons;
167 	unsigned int nr_ents;
168 	comif_sring_t  *sring;
169 } comif_ring_be_t;
170 
171 typedef union comif_ring {
172 	comif_ring_fe_t fr;
173 	comif_ring_be_t br;
174 } comif_ring_t;
175 
176 typedef struct xendev_req {
177 	unsigned long next;
178 	void *req;
179 } xendev_req_t;
180 
181 typedef struct xendev_ring {
182 	ddi_dma_handle_t xr_dma_hdl;
183 	ddi_acc_handle_t xr_acc_hdl;
184 	grant_handle_t xr_grant_hdl;
185 	caddr_t xr_vaddr;
186 	paddr_t xr_paddr;
187 	grant_ref_t xr_gref;
188 	int xr_entry_size;
189 	int xr_frontend;
190 	comif_ring_t xr_sring;
191 } xendev_ring_t;
192 
193 int	xvdi_alloc_ring(dev_info_t *, size_t, size_t, grant_ref_t *,
194 	xendev_ring_t **);
195 void	xvdi_free_ring(xendev_ring_t *);
196 int	xvdi_map_ring(dev_info_t *, size_t, size_t, grant_ref_t,
197 	xendev_ring_t **);
198 void	xvdi_unmap_ring(xendev_ring_t *);
199 uint_t	xvdi_ring_avail_slots(xendev_ring_t *);
200 int	xvdi_ring_has_unconsumed_requests(xendev_ring_t *);
201 int	xvdi_ring_has_incomp_request(xendev_ring_t *);
202 int	xvdi_ring_has_unconsumed_responses(xendev_ring_t *);
203 void*	xvdi_ring_get_request(xendev_ring_t *);
204 int	xvdi_ring_push_request(xendev_ring_t *);
205 void*	xvdi_ring_get_response(xendev_ring_t *);
206 int	xvdi_ring_push_response(xendev_ring_t *);
207 
208 #ifdef	__cplusplus
209 }
210 #endif
211 
212 #endif	/* _SYS_XENDEV_H */
213