win-pvdrivers

view common/include/xen_public.h @ 310:60372bd2582d

First cut of putting xenbus config details in the .inf file - xenvbd may yet pass WHQL
author James Harper <james.harper@bendigoit.com.au>
date Fri Jun 13 14:16:50 2008 +1000 (2008-06-13)
parents 094537c517f5
children a55d72ac422f
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #if !defined(_XEN_PUBLIC_H_)
21 #define _XEN_PUBLIC_H_
23 #include <grant_table.h>
24 #include <event_channel.h>
25 #include <xen_guids.h>
26 //{5C568AC5-9DDF-4FA5-A94A-39D67077819C}
27 DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
29 typedef PHYSICAL_ADDRESS
30 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
32 typedef void
33 (*PXEN_FREEMEM)(PVOID Ptr);
35 typedef NTSTATUS
36 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
38 typedef NTSTATUS
39 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
41 typedef NTSTATUS
42 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
44 typedef NTSTATUS
45 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
47 typedef NTSTATUS
48 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
50 typedef evtchn_port_t
51 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
53 typedef grant_ref_t
54 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref);
56 typedef BOOLEAN
57 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
59 typedef VOID
60 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref);
62 typedef grant_ref_t
63 (*PXEN_GNTTBL_GETREF)(PVOID Context);
66 typedef VOID
67 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
69 typedef char *
70 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
72 typedef char *
73 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
75 typedef char *
76 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
78 typedef char *
79 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
81 typedef char *
82 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
84 typedef char *
85 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
87 typedef char *
88 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
90 typedef char *
91 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
93 typedef NTSTATUS
94 (*PXEN_XENPCI_SHUTDOWN_DEVICE)(PVOID Context);
96 #if 0
97 typedef struct _XEN_IFACE {
98 INTERFACE InterfaceHeader;
100 PXEN_ALLOCMMIO AllocMMIO;
101 PXEN_FREEMEM FreeMem;
103 PXEN_EVTCHN_BIND EvtChn_Bind;
104 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
105 PXEN_EVTCHN_MASK EvtChn_Mask;
106 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
107 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
108 PXEN_EVTCHN_ALLOCUNBOUND EvtChn_AllocUnbound;
109 PXEN_EVTCHN_BIND EvtChn_BindDpc;
111 PXEN_GNTTBL_GETREF GntTbl_GetRef;
112 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
113 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
114 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
116 PXEN_XENBUS_READ XenBus_Read;
117 PXEN_XENBUS_WRITE XenBus_Write;
118 PXEN_XENBUS_PRINTF XenBus_Printf;
119 PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
120 PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
121 PXEN_XENBUS_LIST XenBus_List;
122 PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
123 PXEN_XENBUS_REMWATCH XenBus_RemWatch;
124 } XEN_IFACE, *PXEN_IFACE;
126 typedef struct _XENPCI_IDENTIFICATION_DESCRIPTION
127 {
128 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER Header;
129 char DeviceType[128]; //UNICODE_STRING DeviceType;
130 char Path[128];
131 ULONG DeviceIndex;
132 } XENPCI_IDENTIFICATION_DESCRIPTION, *PXENPCI_IDENTIFICATION_DESCRIPTION;
133 #endif
136 #define XEN_DATA_MAGIC 0x12345678
138 typedef struct {
139 ULONG magic;
140 USHORT length;
142 PVOID context;
143 PXEN_EVTCHN_BIND EvtChn_Bind;
144 PXEN_EVTCHN_BIND EvtChn_BindDpc;
145 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
146 PXEN_EVTCHN_MASK EvtChn_Mask;
147 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
148 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
149 PXEN_GNTTBL_GETREF GntTbl_GetRef;
150 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
151 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
152 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
153 PXEN_XENPCI_SHUTDOWN_DEVICE XenPci_ShutdownDevice;
154 } XENPCI_VECTORS, *PXENPCI_VECTORS;
157 #define XEN_INIT_TYPE_END 0
158 #define XEN_INIT_TYPE_WRITE_STRING 1
159 #define XEN_INIT_TYPE_RING 2
160 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
161 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
162 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
163 #define XEN_INIT_TYPE_READ_STRING_BACK 6
164 #define XEN_INIT_TYPE_VECTORS 7
165 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
166 #define XEN_INIT_TYPE_COPY_PTR 9
168 static __inline VOID
169 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
170 {
171 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
172 *(PUCHAR)(*ptr) = val;
173 *ptr += sizeof(UCHAR);
174 }
176 static __inline VOID
177 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
178 {
179 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
180 *(PUSHORT)(*ptr) = val;
181 *ptr += sizeof(USHORT);
182 }
184 static __inline VOID
185 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
186 {
187 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
188 *(PULONG)(*ptr) = val;
189 *ptr += sizeof(ULONG);
190 }
192 static __inline VOID
193 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
194 {
195 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
196 *(PVOID *)(*ptr) = val;
197 *ptr += sizeof(PVOID);
198 }
200 static __inline VOID
201 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
202 {
203 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
204 //RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
205 // using strcpy instead of above needed for mingw32
206 strcpy((char *)*ptr, val);
207 *ptr += strlen(val) + 1;
208 }
210 static __inline UCHAR
211 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
212 {
213 UCHAR retval;
214 retval = **ptr;
215 KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
216 *ptr += sizeof(UCHAR);
217 return retval;
218 }
220 static __inline USHORT
221 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
222 {
223 USHORT retval;
224 retval = *(PUSHORT)*ptr;
225 KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
226 *ptr += sizeof(USHORT);
227 return retval;
228 }
230 static __inline ULONG
231 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
232 {
233 ULONG retval;
234 retval = *(PLONG)*ptr;
235 KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
236 *ptr += sizeof(ULONG);
237 return retval;
238 }
240 static __inline PCHAR
241 __GET_XEN_INIT_STRING(PUCHAR *ptr)
242 {
243 PCHAR retval;
244 retval = (PCHAR)*ptr;
245 KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
246 *ptr += strlen((PCHAR)*ptr) + 1;
247 return retval;
248 }
250 static __inline PVOID
251 __GET_XEN_INIT_PTR(PUCHAR *ptr)
252 {
253 PVOID retval;
254 retval = *(PVOID *)(*ptr);
255 KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
256 *ptr += sizeof(PVOID);
257 return retval;
258 }
260 static __inline VOID
261 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
262 {
263 __ADD_XEN_INIT_UCHAR(ptr, type);
264 switch (type)
265 {
266 case XEN_INIT_TYPE_END:
267 case XEN_INIT_TYPE_VECTORS:
268 break;
269 case XEN_INIT_TYPE_WRITE_STRING:
270 __ADD_XEN_INIT_STRING(ptr, p1);
271 __ADD_XEN_INIT_STRING(ptr, p2);
272 break;
273 case XEN_INIT_TYPE_RING:
274 case XEN_INIT_TYPE_EVENT_CHANNEL:
275 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
276 case XEN_INIT_TYPE_READ_STRING_FRONT:
277 case XEN_INIT_TYPE_READ_STRING_BACK:
278 __ADD_XEN_INIT_STRING(ptr, p1);
279 break;
280 case XEN_INIT_TYPE_GRANT_ENTRIES:
281 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
282 break;
283 case XEN_INIT_TYPE_COPY_PTR:
284 __ADD_XEN_INIT_STRING(ptr, p1);
285 __ADD_XEN_INIT_PTR(ptr, p2);
286 }
287 }
289 static __inline UCHAR
290 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2)
291 {
292 UCHAR retval;
294 retval = __GET_XEN_INIT_UCHAR(ptr);
295 switch (retval)
296 {
297 case XEN_INIT_TYPE_END:
298 case XEN_INIT_TYPE_VECTORS:
299 *p1 = NULL;
300 *p2 = NULL;
301 break;
302 case XEN_INIT_TYPE_WRITE_STRING:
303 *p1 = __GET_XEN_INIT_STRING(ptr);
304 *p2 = __GET_XEN_INIT_STRING(ptr);
305 break;
306 case XEN_INIT_TYPE_RING:
307 case XEN_INIT_TYPE_EVENT_CHANNEL:
308 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
309 case XEN_INIT_TYPE_READ_STRING_FRONT:
310 case XEN_INIT_TYPE_READ_STRING_BACK:
311 *p1 = __GET_XEN_INIT_STRING(ptr);
312 *p2 = NULL;
313 break;
314 case XEN_INIT_TYPE_GRANT_ENTRIES:
315 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
316 break;
317 case XEN_INIT_TYPE_COPY_PTR:
318 *p1 = __GET_XEN_INIT_STRING(ptr);
319 *p2 = __GET_XEN_INIT_PTR(ptr);
320 }
321 return retval;
322 }
324 static __inline VOID
325 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
326 {
327 __ADD_XEN_INIT_UCHAR(ptr, type);
328 switch (type)
329 {
330 case XEN_INIT_TYPE_END:
331 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
332 break;
333 case XEN_INIT_TYPE_RING:
334 __ADD_XEN_INIT_STRING(ptr, p1);
335 __ADD_XEN_INIT_PTR(ptr, p2);
336 break;
337 case XEN_INIT_TYPE_EVENT_CHANNEL:
338 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
339 __ADD_XEN_INIT_STRING(ptr, p1);
340 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
341 break;
342 case XEN_INIT_TYPE_READ_STRING_FRONT:
343 case XEN_INIT_TYPE_READ_STRING_BACK:
344 __ADD_XEN_INIT_STRING(ptr, p1);
345 __ADD_XEN_INIT_STRING(ptr, p2);
346 break;
347 case XEN_INIT_TYPE_VECTORS:
348 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
349 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
350 *ptr += sizeof(XENPCI_VECTORS);
351 break;
352 case XEN_INIT_TYPE_GRANT_ENTRIES:
353 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
354 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
355 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
356 break;
357 case XEN_INIT_TYPE_COPY_PTR:
358 __ADD_XEN_INIT_STRING(ptr, p1);
359 __ADD_XEN_INIT_PTR(ptr, p2);
360 break;
361 }
362 }
364 static __inline UCHAR
365 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2)
366 {
367 UCHAR retval;
369 retval = __GET_XEN_INIT_UCHAR(ptr);
370 switch (retval)
371 {
372 case XEN_INIT_TYPE_END:
373 *p1 = NULL;
374 *p2 = NULL;
375 break;
376 case XEN_INIT_TYPE_WRITE_STRING:
377 // this shouldn't happen - no response here
378 break;
379 case XEN_INIT_TYPE_RING:
380 *p1 = __GET_XEN_INIT_STRING(ptr);
381 *p2 = __GET_XEN_INIT_PTR(ptr);
382 break;
383 case XEN_INIT_TYPE_EVENT_CHANNEL:
384 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
385 *p1 = __GET_XEN_INIT_STRING(ptr);
386 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
387 break;
388 case XEN_INIT_TYPE_READ_STRING_FRONT:
389 *p1 = __GET_XEN_INIT_STRING(ptr);
390 *p2 = __GET_XEN_INIT_STRING(ptr);
391 break;
392 case XEN_INIT_TYPE_READ_STRING_BACK:
393 *p1 = __GET_XEN_INIT_STRING(ptr);
394 *p2 = __GET_XEN_INIT_STRING(ptr);
395 break;
396 case XEN_INIT_TYPE_VECTORS:
397 *p1 = NULL;
398 *p2 = *ptr;
399 *ptr += ((PXENPCI_VECTORS)*p2)->length;
400 break;
401 case XEN_INIT_TYPE_GRANT_ENTRIES:
402 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
403 *p2 = *ptr;
404 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
405 break;
406 case XEN_INIT_TYPE_COPY_PTR:
407 *p1 = __GET_XEN_INIT_STRING(ptr);
408 *p2 = __GET_XEN_INIT_PTR(ptr);
409 }
410 return retval;
411 }
413 #endif