win-pvdrivers

view common/include/xen_public.h @ 495:a6e3f76419c3

Too many changes to mention. Mostly revolving around updating the way the pci ide and network adapters are disabled.
Also removed windows 2000 support, as it didn't work anyway.
Also fixes to XenSCSI.
author James Harper <james.harper@bendigoit.com.au>
date Mon Dec 15 19:17:13 2008 +1100 (2008-12-15)
parents 7776b0ac6048
children 312a41f82b8f
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
182 static __inline VOID
183 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
184 {
185 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
186 *(PUCHAR)(*ptr) = val;
187 *ptr += sizeof(UCHAR);
188 }
190 static __inline VOID
191 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
192 {
193 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
194 *(PUSHORT)(*ptr) = val;
195 *ptr += sizeof(USHORT);
196 }
198 static __inline VOID
199 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
200 {
201 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
202 *(PULONG)(*ptr) = val;
203 *ptr += sizeof(ULONG);
204 }
206 static __inline VOID
207 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
208 {
209 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
210 *(PVOID *)(*ptr) = val;
211 *ptr += sizeof(PVOID);
212 }
214 static __inline VOID
215 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
216 {
217 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
218 RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
219 *ptr += strlen(val) + 1;
220 }
222 static __inline UCHAR
223 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
224 {
225 UCHAR retval;
226 retval = **ptr;
227 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
228 *ptr += sizeof(UCHAR);
229 return retval;
230 }
232 static __inline USHORT
233 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
234 {
235 USHORT retval;
236 retval = *(PUSHORT)*ptr;
237 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
238 *ptr += sizeof(USHORT);
239 return retval;
240 }
242 static __inline ULONG
243 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
244 {
245 ULONG retval;
246 retval = *(PLONG)*ptr;
247 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
248 *ptr += sizeof(ULONG);
249 return retval;
250 }
252 static __inline PCHAR
253 __GET_XEN_INIT_STRING(PUCHAR *ptr)
254 {
255 PCHAR retval;
256 retval = (PCHAR)*ptr;
257 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
258 *ptr += strlen((PCHAR)*ptr) + 1;
259 return retval;
260 }
262 static __inline PVOID
263 __GET_XEN_INIT_PTR(PUCHAR *ptr)
264 {
265 PVOID retval;
266 retval = *(PVOID *)(*ptr);
267 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
268 *ptr += sizeof(PVOID);
269 return retval;
270 }
272 static __inline VOID
273 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
274 {
275 __ADD_XEN_INIT_UCHAR(ptr, type);
276 switch (type)
277 {
278 case XEN_INIT_TYPE_END:
279 case XEN_INIT_TYPE_VECTORS:
280 case XEN_INIT_TYPE_RUN:
281 case XEN_INIT_TYPE_STATE_PTR:
282 case XEN_INIT_TYPE_ACTIVE:
283 break;
284 case XEN_INIT_TYPE_WRITE_STRING:
285 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
286 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
287 break;
288 case XEN_INIT_TYPE_RING:
289 case XEN_INIT_TYPE_EVENT_CHANNEL:
290 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
291 case XEN_INIT_TYPE_READ_STRING_FRONT:
292 case XEN_INIT_TYPE_READ_STRING_BACK:
293 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
294 break;
295 case XEN_INIT_TYPE_GRANT_ENTRIES:
296 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
297 break;
298 // case XEN_INIT_TYPE_COPY_PTR:
299 // __ADD_XEN_INIT_STRING(ptr, p1);
300 // __ADD_XEN_INIT_PTR(ptr, p2);
301 // break;
302 }
303 }
305 static __inline UCHAR
306 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2)
307 {
308 UCHAR retval;
310 retval = __GET_XEN_INIT_UCHAR(ptr);
311 switch (retval)
312 {
313 case XEN_INIT_TYPE_END:
314 case XEN_INIT_TYPE_VECTORS:
315 case XEN_INIT_TYPE_RUN:
316 case XEN_INIT_TYPE_STATE_PTR:
317 case XEN_INIT_TYPE_ACTIVE:
318 *p1 = NULL;
319 *p2 = NULL;
320 break;
321 case XEN_INIT_TYPE_WRITE_STRING:
322 *p1 = __GET_XEN_INIT_STRING(ptr);
323 *p2 = __GET_XEN_INIT_STRING(ptr);
324 break;
325 case XEN_INIT_TYPE_RING:
326 case XEN_INIT_TYPE_EVENT_CHANNEL:
327 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
328 case XEN_INIT_TYPE_READ_STRING_FRONT:
329 case XEN_INIT_TYPE_READ_STRING_BACK:
330 *p1 = __GET_XEN_INIT_STRING(ptr);
331 *p2 = NULL;
332 break;
333 case XEN_INIT_TYPE_GRANT_ENTRIES:
334 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
335 break;
336 // case XEN_INIT_TYPE_COPY_PTR:
337 // *p1 = __GET_XEN_INIT_STRING(ptr);
338 // *p2 = __GET_XEN_INIT_PTR(ptr);
339 // break;
340 }
341 return retval;
342 }
344 static __inline VOID
345 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
346 {
347 __ADD_XEN_INIT_UCHAR(ptr, type);
348 switch (type)
349 {
350 case XEN_INIT_TYPE_END:
351 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
352 case XEN_INIT_TYPE_RUN:
353 case XEN_INIT_TYPE_ACTIVE:
354 break;
355 case XEN_INIT_TYPE_RING:
356 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
357 __ADD_XEN_INIT_PTR(ptr, p2);
358 break;
359 case XEN_INIT_TYPE_EVENT_CHANNEL:
360 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
361 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
362 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
363 break;
364 case XEN_INIT_TYPE_READ_STRING_FRONT:
365 case XEN_INIT_TYPE_READ_STRING_BACK:
366 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
367 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
368 break;
369 case XEN_INIT_TYPE_VECTORS:
370 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
371 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
372 *ptr += sizeof(XENPCI_VECTORS);
373 break;
374 case XEN_INIT_TYPE_GRANT_ENTRIES:
375 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
376 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
377 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
378 break;
379 case XEN_INIT_TYPE_STATE_PTR:
380 __ADD_XEN_INIT_PTR(ptr, p2);
381 break;
382 // case XEN_INIT_TYPE_COPY_PTR:
383 // __ADD_XEN_INIT_STRING(ptr, p1);
384 // __ADD_XEN_INIT_PTR(ptr, p2);
385 // break;
386 }
387 }
389 static __inline UCHAR
390 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2)
391 {
392 UCHAR retval;
394 retval = __GET_XEN_INIT_UCHAR(ptr);
395 switch (retval)
396 {
397 case XEN_INIT_TYPE_END:
398 case XEN_INIT_TYPE_RUN:
399 case XEN_INIT_TYPE_ACTIVE:
400 *p1 = NULL;
401 *p2 = NULL;
402 break;
403 case XEN_INIT_TYPE_WRITE_STRING:
404 // this shouldn't happen - no response here
405 break;
406 case XEN_INIT_TYPE_RING:
407 *p1 = __GET_XEN_INIT_STRING(ptr);
408 *p2 = __GET_XEN_INIT_PTR(ptr);
409 break;
410 case XEN_INIT_TYPE_EVENT_CHANNEL:
411 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
412 *p1 = __GET_XEN_INIT_STRING(ptr);
413 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
414 break;
415 case XEN_INIT_TYPE_READ_STRING_FRONT:
416 *p1 = __GET_XEN_INIT_STRING(ptr);
417 *p2 = __GET_XEN_INIT_STRING(ptr);
418 break;
419 case XEN_INIT_TYPE_READ_STRING_BACK:
420 *p1 = __GET_XEN_INIT_STRING(ptr);
421 *p2 = __GET_XEN_INIT_STRING(ptr);
422 break;
423 case XEN_INIT_TYPE_VECTORS:
424 *p1 = NULL;
425 *p2 = *ptr;
426 *ptr += ((PXENPCI_VECTORS)*p2)->length;
427 break;
428 case XEN_INIT_TYPE_GRANT_ENTRIES:
429 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
430 *p2 = *ptr;
431 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
432 break;
433 case XEN_INIT_TYPE_STATE_PTR:
434 *p2 = __GET_XEN_INIT_PTR(ptr);
435 break;
436 // case XEN_INIT_TYPE_COPY_PTR:
437 // *p1 = __GET_XEN_INIT_STRING(ptr);
438 // *p2 = __GET_XEN_INIT_PTR(ptr);
439 }
440 return retval;
441 }
443 #endif