win-pvdrivers

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