win-pvdrivers

view common/include/xen_public.h @ 308:094537c517f5

Fixed pointer error
author James Harper <james.harper@bendigoit.com.au>
date Wed Jun 11 21:04:54 2008 +1000 (2008-06-11)
parents 7879ec15f2a1
children 60372bd2582d
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 <xen_guids.h>
24 //{5C568AC5-9DDF-4FA5-A94A-39D67077819C}
25 DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
27 typedef PHYSICAL_ADDRESS
28 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
30 typedef void
31 (*PXEN_FREEMEM)(PVOID Ptr);
33 typedef NTSTATUS
34 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
36 typedef NTSTATUS
37 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
39 typedef NTSTATUS
40 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
42 typedef NTSTATUS
43 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
45 typedef NTSTATUS
46 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
48 typedef evtchn_port_t
49 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
51 typedef grant_ref_t
52 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref);
54 typedef BOOLEAN
55 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
57 typedef VOID
58 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref);
60 typedef grant_ref_t
61 (*PXEN_GNTTBL_GETREF)(PVOID Context);
64 typedef VOID
65 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
67 typedef char *
68 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
70 typedef char *
71 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
73 typedef char *
74 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
76 typedef char *
77 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
79 typedef char *
80 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
82 typedef char *
83 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
85 typedef char *
86 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
88 typedef char *
89 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
91 typedef NTSTATUS
92 (*PXEN_XENPCI_SHUTDOWN_DEVICE)(PVOID Context);
94 #if 0
95 typedef struct _XEN_IFACE {
96 INTERFACE InterfaceHeader;
98 PXEN_ALLOCMMIO AllocMMIO;
99 PXEN_FREEMEM FreeMem;
101 PXEN_EVTCHN_BIND EvtChn_Bind;
102 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
103 PXEN_EVTCHN_MASK EvtChn_Mask;
104 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
105 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
106 PXEN_EVTCHN_ALLOCUNBOUND EvtChn_AllocUnbound;
107 PXEN_EVTCHN_BIND EvtChn_BindDpc;
109 PXEN_GNTTBL_GETREF GntTbl_GetRef;
110 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
111 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
112 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
114 PXEN_XENBUS_READ XenBus_Read;
115 PXEN_XENBUS_WRITE XenBus_Write;
116 PXEN_XENBUS_PRINTF XenBus_Printf;
117 PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
118 PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
119 PXEN_XENBUS_LIST XenBus_List;
120 PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
121 PXEN_XENBUS_REMWATCH XenBus_RemWatch;
122 } XEN_IFACE, *PXEN_IFACE;
124 typedef struct _XENPCI_IDENTIFICATION_DESCRIPTION
125 {
126 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER Header;
127 char DeviceType[128]; //UNICODE_STRING DeviceType;
128 char Path[128];
129 ULONG DeviceIndex;
130 } XENPCI_IDENTIFICATION_DESCRIPTION, *PXENPCI_IDENTIFICATION_DESCRIPTION;
131 #endif
134 #define XEN_DATA_MAGIC 0x12345678
136 typedef struct {
137 ULONG magic;
138 USHORT length;
140 PVOID context;
141 PXEN_EVTCHN_BIND EvtChn_Bind;
142 PXEN_EVTCHN_BIND EvtChn_BindDpc;
143 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
144 PXEN_EVTCHN_MASK EvtChn_Mask;
145 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
146 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
147 PXEN_GNTTBL_GETREF GntTbl_GetRef;
148 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
149 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
150 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
151 PXEN_XENPCI_SHUTDOWN_DEVICE XenPci_ShutdownDevice;
152 } XENPCI_VECTORS, *PXENPCI_VECTORS;
155 #define XEN_INIT_TYPE_END 0
156 #define XEN_INIT_TYPE_WRITE_STRING 1
157 #define XEN_INIT_TYPE_RING 2
158 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
159 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
160 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
161 #define XEN_INIT_TYPE_READ_STRING_BACK 6
162 #define XEN_INIT_TYPE_VECTORS 7
163 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
164 #define XEN_INIT_TYPE_COPY_PTR 9
166 static __inline VOID
167 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
168 {
169 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
170 *(PUCHAR)(*ptr) = val;
171 *ptr += sizeof(UCHAR);
172 }
174 static __inline VOID
175 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
176 {
177 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
178 *(PUSHORT)(*ptr) = val;
179 *ptr += sizeof(USHORT);
180 }
182 static __inline VOID
183 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
184 {
185 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
186 *(PULONG)(*ptr) = val;
187 *ptr += sizeof(ULONG);
188 }
190 static __inline VOID
191 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
192 {
193 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
194 *(PVOID *)(*ptr) = val;
195 *ptr += sizeof(PVOID);
196 }
198 static __inline VOID
199 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
200 {
201 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
202 //RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
203 // using strcpy instead of above needed for mingw32
204 strcpy((char *)*ptr, val);
205 *ptr += strlen(val) + 1;
206 }
208 static __inline UCHAR
209 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
210 {
211 UCHAR retval;
212 retval = **ptr;
213 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
214 *ptr += sizeof(UCHAR);
215 return retval;
216 }
218 static __inline USHORT
219 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
220 {
221 USHORT retval;
222 retval = *(PUSHORT)*ptr;
223 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
224 *ptr += sizeof(USHORT);
225 return retval;
226 }
228 static __inline ULONG
229 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
230 {
231 ULONG retval;
232 retval = *(PLONG)*ptr;
233 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
234 *ptr += sizeof(ULONG);
235 return retval;
236 }
238 static __inline PCHAR
239 __GET_XEN_INIT_STRING(PUCHAR *ptr)
240 {
241 PCHAR retval;
242 retval = (PCHAR)*ptr;
243 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
244 *ptr += strlen((PCHAR)*ptr) + 1;
245 return retval;
246 }
248 static __inline PVOID
249 __GET_XEN_INIT_PTR(PUCHAR *ptr)
250 {
251 PVOID retval;
252 retval = *(PVOID *)(*ptr);
253 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
254 *ptr += sizeof(PVOID);
255 return retval;
256 }
258 static __inline VOID
259 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
260 {
261 __ADD_XEN_INIT_UCHAR(ptr, type);
262 switch (type)
263 {
264 case XEN_INIT_TYPE_END:
265 case XEN_INIT_TYPE_VECTORS:
266 break;
267 case XEN_INIT_TYPE_WRITE_STRING:
268 __ADD_XEN_INIT_STRING(ptr, p1);
269 __ADD_XEN_INIT_STRING(ptr, p2);
270 break;
271 case XEN_INIT_TYPE_RING:
272 case XEN_INIT_TYPE_EVENT_CHANNEL:
273 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
274 case XEN_INIT_TYPE_READ_STRING_FRONT:
275 case XEN_INIT_TYPE_READ_STRING_BACK:
276 __ADD_XEN_INIT_STRING(ptr, p1);
277 break;
278 case XEN_INIT_TYPE_GRANT_ENTRIES:
279 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
280 break;
281 case XEN_INIT_TYPE_COPY_PTR:
282 __ADD_XEN_INIT_STRING(ptr, p1);
283 __ADD_XEN_INIT_PTR(ptr, p2);
284 }
285 }
287 static __inline UCHAR
288 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2)
289 {
290 UCHAR retval;
292 retval = __GET_XEN_INIT_UCHAR(ptr);
293 switch (retval)
294 {
295 case XEN_INIT_TYPE_END:
296 case XEN_INIT_TYPE_VECTORS:
297 *p1 = NULL;
298 *p2 = NULL;
299 break;
300 case XEN_INIT_TYPE_WRITE_STRING:
301 *p1 = __GET_XEN_INIT_STRING(ptr);
302 *p2 = __GET_XEN_INIT_STRING(ptr);
303 break;
304 case XEN_INIT_TYPE_RING:
305 case XEN_INIT_TYPE_EVENT_CHANNEL:
306 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
307 case XEN_INIT_TYPE_READ_STRING_FRONT:
308 case XEN_INIT_TYPE_READ_STRING_BACK:
309 *p1 = __GET_XEN_INIT_STRING(ptr);
310 *p2 = NULL;
311 break;
312 case XEN_INIT_TYPE_GRANT_ENTRIES:
313 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
314 break;
315 case XEN_INIT_TYPE_COPY_PTR:
316 *p1 = __GET_XEN_INIT_STRING(ptr);
317 *p2 = __GET_XEN_INIT_PTR(ptr);
318 }
319 return retval;
320 }
322 static __inline VOID
323 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
324 {
325 __ADD_XEN_INIT_UCHAR(ptr, type);
326 switch (type)
327 {
328 case XEN_INIT_TYPE_END:
329 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
330 break;
331 case XEN_INIT_TYPE_RING:
332 __ADD_XEN_INIT_STRING(ptr, p1);
333 __ADD_XEN_INIT_PTR(ptr, p2);
334 break;
335 case XEN_INIT_TYPE_EVENT_CHANNEL:
336 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
337 __ADD_XEN_INIT_STRING(ptr, p1);
338 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
339 break;
340 case XEN_INIT_TYPE_READ_STRING_FRONT:
341 case XEN_INIT_TYPE_READ_STRING_BACK:
342 __ADD_XEN_INIT_STRING(ptr, p1);
343 __ADD_XEN_INIT_STRING(ptr, p2);
344 break;
345 case XEN_INIT_TYPE_VECTORS:
346 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
347 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
348 *ptr += sizeof(XENPCI_VECTORS);
349 break;
350 case XEN_INIT_TYPE_GRANT_ENTRIES:
351 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
352 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
353 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
354 break;
355 case XEN_INIT_TYPE_COPY_PTR:
356 __ADD_XEN_INIT_STRING(ptr, p1);
357 __ADD_XEN_INIT_PTR(ptr, p2);
358 }
359 }
361 static __inline UCHAR
362 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2)
363 {
364 UCHAR retval;
366 retval = __GET_XEN_INIT_UCHAR(ptr);
367 switch (retval)
368 {
369 case XEN_INIT_TYPE_END:
370 *p1 = NULL;
371 *p2 = NULL;
372 break;
373 case XEN_INIT_TYPE_WRITE_STRING:
374 // this shouldn't happen - no response here
375 break;
376 case XEN_INIT_TYPE_RING:
377 *p1 = __GET_XEN_INIT_STRING(ptr);
378 *p2 = __GET_XEN_INIT_PTR(ptr);
379 break;
380 case XEN_INIT_TYPE_EVENT_CHANNEL:
381 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
382 *p1 = __GET_XEN_INIT_STRING(ptr);
383 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
384 break;
385 case XEN_INIT_TYPE_READ_STRING_FRONT:
386 *p1 = __GET_XEN_INIT_STRING(ptr);
387 *p2 = __GET_XEN_INIT_STRING(ptr);
388 break;
389 case XEN_INIT_TYPE_READ_STRING_BACK:
390 *p1 = __GET_XEN_INIT_STRING(ptr);
391 *p2 = __GET_XEN_INIT_STRING(ptr);
392 break;
393 case XEN_INIT_TYPE_VECTORS:
394 *p1 = NULL;
395 *p2 = *ptr;
396 *ptr += ((PXENPCI_VECTORS)*p2)->length;
397 break;
398 case XEN_INIT_TYPE_GRANT_ENTRIES:
399 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
400 *p2 = *ptr;
401 *ptr += PtrToUlong(*p1) * sizeof(grant_entry_t);
402 break;
403 case XEN_INIT_TYPE_COPY_PTR:
404 *p1 = __GET_XEN_INIT_STRING(ptr);
405 *p2 = __GET_XEN_INIT_PTR(ptr);
406 }
407 return retval;
408 }
410 #endif