win-pvdrivers

view common/include/xen_public.h @ 497:312a41f82b8f

Updated to support the proposed patches to qemu from Steven Smith on ~20081216
author James Harper <james.harper@bendigoit.com.au>
date Fri Dec 19 22:08:17 2008 +1100 (2008-12-19)
parents a6e3f76419c3
children cb0b2da68686
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 #define INVALID_GRANT_REF 0xFFFFFFFF
31 typedef PHYSICAL_ADDRESS
32 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
34 typedef void
35 (*PXEN_FREEMEM)(PVOID Ptr);
37 typedef NTSTATUS
38 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
40 typedef NTSTATUS
41 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
43 typedef NTSTATUS
44 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
46 typedef NTSTATUS
47 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
49 typedef NTSTATUS
50 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
52 typedef evtchn_port_t
53 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
55 typedef BOOLEAN
56 (*PXEN_EVTCHN_ACK_EVENT)(PVOID context, evtchn_port_t port);
58 typedef grant_ref_t
59 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref);
61 typedef BOOLEAN
62 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
64 typedef VOID
65 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref);
67 typedef grant_ref_t
68 (*PXEN_GNTTBL_GETREF)(PVOID Context);
71 typedef VOID
72 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
74 typedef char *
75 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
77 typedef char *
78 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
80 typedef char *
81 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
83 typedef char *
84 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
86 typedef char *
87 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
89 typedef char *
90 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
92 typedef char *
93 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
95 typedef char *
96 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
98 typedef NTSTATUS
99 (*PXEN_XENPCI_XEN_CONFIG_DEVICE)(PVOID Context);
101 typedef NTSTATUS
102 (*PXEN_XENPCI_XEN_SHUTDOWN_DEVICE)(PVOID Context);
104 #ifndef XENPCI_POOL_TAG
105 #define XENPCI_POOL_TAG (ULONG) 'XenP'
106 #endif
108 static __inline VOID
109 XenPci_FreeMem(PVOID Ptr)
110 {
111 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
112 }
114 #define XEN_DATA_MAGIC 0x12345678
116 typedef struct {
117 ULONG magic;
118 USHORT length;
120 PVOID context;
121 PXEN_EVTCHN_BIND EvtChn_Bind;
122 PXEN_EVTCHN_BIND EvtChn_BindDpc;
123 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
124 PXEN_EVTCHN_MASK EvtChn_Mask;
125 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
126 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
127 PXEN_EVTCHN_ACK_EVENT EvtChn_AckEvent;
129 PXEN_GNTTBL_GETREF GntTbl_GetRef;
130 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
131 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
132 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
134 PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
135 PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
137 CHAR path[128];
138 CHAR backend_path[128];
140 evtchn_port_t pdo_event_channel;
142 PXEN_XENBUS_READ XenBus_Read;
143 PXEN_XENBUS_WRITE XenBus_Write;
144 PXEN_XENBUS_PRINTF XenBus_Printf;
145 PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
146 PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
147 PXEN_XENBUS_LIST XenBus_List;
148 PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
149 PXEN_XENBUS_REMWATCH XenBus_RemWatch;
151 } XENPCI_VECTORS, *PXENPCI_VECTORS;
153 #define RESUME_STATE_RUNNING 0
154 #define RESUME_STATE_SUSPENDING 1
155 #define RESUME_STATE_BACKEND_RESUME 2
156 #define RESUME_STATE_FRONTEND_RESUME 3
158 typedef struct {
159 ULONG magic;
160 USHORT length;
162 ULONG resume_state;
163 ULONG resume_state_ack;
164 } XENPCI_DEVICE_STATE, *PXENPCI_DEVICE_STATE;
166 #define XEN_INIT_DRIVER_EXTENSION_MAGIC ((ULONG)'XCFG')
168 #define XEN_INIT_TYPE_END 0
169 #define XEN_INIT_TYPE_WRITE_STRING 1
170 #define XEN_INIT_TYPE_RING 2
171 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
172 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
173 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
174 #define XEN_INIT_TYPE_READ_STRING_BACK 6
175 #define XEN_INIT_TYPE_VECTORS 7
176 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
177 //#define XEN_INIT_TYPE_COPY_PTR 9
178 #define XEN_INIT_TYPE_RUN 10
179 #define XEN_INIT_TYPE_STATE_PTR 11
180 #define XEN_INIT_TYPE_ACTIVE 12
181 #define XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION 13
183 static __inline VOID
184 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
185 {
186 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
187 *(PUCHAR)(*ptr) = val;
188 *ptr += sizeof(UCHAR);
189 }
191 static __inline VOID
192 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
193 {
194 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
195 *(PUSHORT)(*ptr) = val;
196 *ptr += sizeof(USHORT);
197 }
199 static __inline VOID
200 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
201 {
202 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
203 *(PULONG)(*ptr) = val;
204 *ptr += sizeof(ULONG);
205 }
207 static __inline VOID
208 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
209 {
210 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
211 *(PVOID *)(*ptr) = val;
212 *ptr += sizeof(PVOID);
213 }
215 static __inline VOID
216 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
217 {
218 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
219 RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
220 *ptr += strlen(val) + 1;
221 }
223 static __inline UCHAR
224 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
225 {
226 UCHAR retval;
227 retval = **ptr;
228 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
229 *ptr += sizeof(UCHAR);
230 return retval;
231 }
233 static __inline USHORT
234 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
235 {
236 USHORT retval;
237 retval = *(PUSHORT)*ptr;
238 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
239 *ptr += sizeof(USHORT);
240 return retval;
241 }
243 static __inline ULONG
244 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
245 {
246 ULONG retval;
247 retval = *(PLONG)*ptr;
248 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
249 *ptr += sizeof(ULONG);
250 return retval;
251 }
253 static __inline PCHAR
254 __GET_XEN_INIT_STRING(PUCHAR *ptr)
255 {
256 PCHAR retval;
257 retval = (PCHAR)*ptr;
258 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
259 *ptr += strlen((PCHAR)*ptr) + 1;
260 return retval;
261 }
263 static __inline PVOID
264 __GET_XEN_INIT_PTR(PUCHAR *ptr)
265 {
266 PVOID retval;
267 retval = *(PVOID *)(*ptr);
268 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
269 *ptr += sizeof(PVOID);
270 return retval;
271 }
273 static __inline VOID
274 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
275 {
276 __ADD_XEN_INIT_UCHAR(ptr, type);
277 switch (type)
278 {
279 case XEN_INIT_TYPE_END:
280 case XEN_INIT_TYPE_VECTORS:
281 case XEN_INIT_TYPE_RUN:
282 case XEN_INIT_TYPE_STATE_PTR:
283 case XEN_INIT_TYPE_ACTIVE:
284 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
285 break;
286 case XEN_INIT_TYPE_WRITE_STRING:
287 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
288 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
289 break;
290 case XEN_INIT_TYPE_RING:
291 case XEN_INIT_TYPE_EVENT_CHANNEL:
292 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
293 case XEN_INIT_TYPE_READ_STRING_FRONT:
294 case XEN_INIT_TYPE_READ_STRING_BACK:
295 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
296 break;
297 case XEN_INIT_TYPE_GRANT_ENTRIES:
298 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
299 break;
300 // case XEN_INIT_TYPE_COPY_PTR:
301 // __ADD_XEN_INIT_STRING(ptr, p1);
302 // __ADD_XEN_INIT_PTR(ptr, p2);
303 // break;
304 }
305 }
307 static __inline UCHAR
308 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2)
309 {
310 UCHAR retval;
312 retval = __GET_XEN_INIT_UCHAR(ptr);
313 switch (retval)
314 {
315 case XEN_INIT_TYPE_END:
316 case XEN_INIT_TYPE_VECTORS:
317 case XEN_INIT_TYPE_RUN:
318 case XEN_INIT_TYPE_STATE_PTR:
319 case XEN_INIT_TYPE_ACTIVE:
320 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
321 *p1 = NULL;
322 *p2 = NULL;
323 break;
324 case XEN_INIT_TYPE_WRITE_STRING:
325 *p1 = __GET_XEN_INIT_STRING(ptr);
326 *p2 = __GET_XEN_INIT_STRING(ptr);
327 break;
328 case XEN_INIT_TYPE_RING:
329 case XEN_INIT_TYPE_EVENT_CHANNEL:
330 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
331 case XEN_INIT_TYPE_READ_STRING_FRONT:
332 case XEN_INIT_TYPE_READ_STRING_BACK:
333 *p1 = __GET_XEN_INIT_STRING(ptr);
334 *p2 = NULL;
335 break;
336 case XEN_INIT_TYPE_GRANT_ENTRIES:
337 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
338 break;
339 // case XEN_INIT_TYPE_COPY_PTR:
340 // *p1 = __GET_XEN_INIT_STRING(ptr);
341 // *p2 = __GET_XEN_INIT_PTR(ptr);
342 // break;
343 }
344 return retval;
345 }
347 static __inline VOID
348 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
349 {
350 __ADD_XEN_INIT_UCHAR(ptr, type);
351 switch (type)
352 {
353 case XEN_INIT_TYPE_END:
354 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
355 case XEN_INIT_TYPE_RUN:
356 case XEN_INIT_TYPE_ACTIVE:
357 break;
358 case XEN_INIT_TYPE_RING:
359 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
360 __ADD_XEN_INIT_PTR(ptr, p2);
361 break;
362 case XEN_INIT_TYPE_EVENT_CHANNEL:
363 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
364 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
365 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
366 break;
367 case XEN_INIT_TYPE_READ_STRING_FRONT:
368 case XEN_INIT_TYPE_READ_STRING_BACK:
369 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
370 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
371 break;
372 case XEN_INIT_TYPE_VECTORS:
373 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
374 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
375 *ptr += sizeof(XENPCI_VECTORS);
376 break;
377 case XEN_INIT_TYPE_GRANT_ENTRIES:
378 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
379 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
380 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
381 break;
382 case XEN_INIT_TYPE_STATE_PTR:
383 __ADD_XEN_INIT_PTR(ptr, p2);
384 break;
385 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
386 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
387 break;
388 // case XEN_INIT_TYPE_COPY_PTR:
389 // __ADD_XEN_INIT_STRING(ptr, p1);
390 // __ADD_XEN_INIT_PTR(ptr, p2);
391 // break;
392 }
393 }
395 static __inline UCHAR
396 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2)
397 {
398 UCHAR retval;
400 retval = __GET_XEN_INIT_UCHAR(ptr);
401 switch (retval)
402 {
403 case XEN_INIT_TYPE_END:
404 case XEN_INIT_TYPE_RUN:
405 case XEN_INIT_TYPE_ACTIVE:
406 *p1 = NULL;
407 *p2 = NULL;
408 break;
409 case XEN_INIT_TYPE_WRITE_STRING:
410 // this shouldn't happen - no response here
411 break;
412 case XEN_INIT_TYPE_RING:
413 *p1 = __GET_XEN_INIT_STRING(ptr);
414 *p2 = __GET_XEN_INIT_PTR(ptr);
415 break;
416 case XEN_INIT_TYPE_EVENT_CHANNEL:
417 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
418 *p1 = __GET_XEN_INIT_STRING(ptr);
419 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
420 break;
421 case XEN_INIT_TYPE_READ_STRING_FRONT:
422 *p1 = __GET_XEN_INIT_STRING(ptr);
423 *p2 = __GET_XEN_INIT_STRING(ptr);
424 break;
425 case XEN_INIT_TYPE_READ_STRING_BACK:
426 *p1 = __GET_XEN_INIT_STRING(ptr);
427 *p2 = __GET_XEN_INIT_STRING(ptr);
428 break;
429 case XEN_INIT_TYPE_VECTORS:
430 *p1 = NULL;
431 *p2 = *ptr;
432 *ptr += ((PXENPCI_VECTORS)*p2)->length;
433 break;
434 case XEN_INIT_TYPE_GRANT_ENTRIES:
435 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
436 *p2 = *ptr;
437 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
438 break;
439 case XEN_INIT_TYPE_STATE_PTR:
440 *p2 = __GET_XEN_INIT_PTR(ptr);
441 break;
442 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
443 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
444 break;
445 // case XEN_INIT_TYPE_COPY_PTR:
446 // *p1 = __GET_XEN_INIT_STRING(ptr);
447 // *p2 = __GET_XEN_INIT_PTR(ptr);
448 }
449 return retval;
450 }
452 #endif