win-pvdrivers

changeset 671:1bae3638ab55

Reshuffle of code to allow adding of different device interfaces (eg /dev/evtchn and /dev/gntdev implementations)
author James Harper <james.harper@bendigoit.com.au>
date Fri Oct 02 13:53:13 2009 +1000 (2009-10-02)
parents b59c7dfdee9b
children 63b0eb3f9d44
files common/include/xen_public.h xenpci/sources xenpci/xenbus_device_interface.c xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci_device_interface.c
line diff
     1.1 --- a/common/include/xen_public.h	Wed Sep 23 17:06:30 2009 +1000
     1.2 +++ b/common/include/xen_public.h	Fri Oct 02 13:53:13 2009 +1000
     1.3 @@ -24,7 +24,13 @@ Foundation, Inc., 51 Franklin Street, Fi
     1.4  DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
     1.5  
     1.6  // {14CE175A-3EE2-4fae-9252-00DBD84F018E}
     1.7 -DEFINE_GUID(GUID_DEVINTERFACE_XENBUS, 0x14ce175a, 0x3ee2, 0x4fae, 0x92, 0x52, 0x0, 0xdb, 0xd8, 0x4f, 0x1, 0x8e);
     1.8 +DEFINE_GUID(GUID_DEVINTERFACE_XENBUS, 0x14ce175a, 0x3ee2, 0x4fae, 0x92, 0x52, 0x00, 0xdb, 0xd8, 0x4f, 0x01, 0x8e);
     1.9 +
    1.10 +// {CC8B3D31-0D8C-474c-94D4-8D5F76FF9727}
    1.11 +DEFINE_GUID(GUID_DEVINTERFACE_EVTCHN, 0xcc8b3d31, 0x0d8c, 0x474c, 0x94, 0xd4, 0x8d, 0x5f, 0x76, 0xff, 0x97, 0x27);
    1.12 +
    1.13 +// {0B66CEF6-7B6B-4324-BF31-D0F57EA22D30}
    1.14 +DEFINE_GUID(GUID_DEVINTERFACE_GNTDEV, 0x0b66cef6, 0x7b6b, 0x4324, 0xbf, 0x31, 0xd0, 0xf5, 0x7e, 0xa2, 0x2d, 0x30);
    1.15  
    1.16  
    1.17  #endif
     2.1 --- a/xenpci/sources	Wed Sep 23 17:06:30 2009 +1000
     2.2 +++ b/xenpci/sources	Fri Oct 02 13:53:13 2009 +1000
     2.3 @@ -7,4 +7,4 @@ TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)
     2.4  AMD64_SOURCES=hypercall.asm
     2.5  I386_SOURCES=tpr_emulate.asm
     2.6  
     2.7 -SOURCES=xenpci.rc xenpci.c xenpci_fdo.c xenpci_pdo.c evtchn.c gnttbl.c xenbus.c memory.c xenbus_device_interface.c xenpci_highsync.c xenpci_patch_kernel.c
     2.8 +SOURCES=xenpci.rc xenpci.c xenpci_fdo.c xenpci_pdo.c evtchn.c gnttbl.c xenbus.c memory.c xenpci_device_interface.c xenbus_device_interface.c xenpci_highsync.c xenpci_patch_kernel.c
     3.1 --- a/xenpci/xenbus_device_interface.c	Wed Sep 23 17:06:30 2009 +1000
     3.2 +++ b/xenpci/xenbus_device_interface.c	Fri Oct 02 13:53:13 2009 +1000
     3.3 @@ -34,36 +34,8 @@ typedef struct
     3.4    WDFFILEOBJECT file_object;
     3.5  } watch_context_t;
     3.6  
     3.7 -VOID
     3.8 -XenPci_EvtDeviceFileCreate(WDFDEVICE device, WDFREQUEST request, WDFFILEOBJECT file_object)
     3.9 -{
    3.10 -  NTSTATUS status;
    3.11 -  PXENPCI_DEVICE_INTERFACE_DATA xpdid = GetXpdid(file_object);
    3.12 -  WDF_IO_QUEUE_CONFIG queue_config;
    3.13 -  
    3.14 -  FUNCTION_ENTER();
    3.15 -  
    3.16 -  xpdid->type = DEVICE_INTERFACE_TYPE_XENBUS;
    3.17 -  KeInitializeSpinLock(&xpdid->lock);
    3.18 -  InitializeListHead(&xpdid->read_list_head);
    3.19 -  InitializeListHead(&xpdid->watch_list_head);
    3.20 -  xpdid->len = 0;
    3.21 -  WDF_IO_QUEUE_CONFIG_INIT(&queue_config, WdfIoQueueDispatchManual);
    3.22 -  //queue_config.EvtIoRead = XenPci_EvtIoRead;
    3.23 -  status = WdfIoQueueCreate(device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xpdid->io_queue);
    3.24 -  if (!NT_SUCCESS(status)) {
    3.25 -      KdPrint(("Error creating queue 0x%x\n", status));
    3.26 -      WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    3.27 -  }
    3.28 -  //WdfIoQueueStop(xpdid->io_queue, NULL, NULL);
    3.29 -
    3.30 -  WdfRequestComplete(request, STATUS_SUCCESS);
    3.31 -  
    3.32 -  FUNCTION_EXIT();
    3.33 -}
    3.34 -
    3.35 -VOID
    3.36 -XenPci_ProcessReadRequest(WDFQUEUE queue, WDFREQUEST request, size_t length)
    3.37 +static VOID
    3.38 +XenBus_ProcessReadRequest(WDFQUEUE queue, WDFREQUEST request, size_t length)
    3.39  {
    3.40    NTSTATUS status;
    3.41    WDFFILEOBJECT file_object = WdfRequestGetFileObject(request);
    3.42 @@ -85,7 +57,7 @@ XenPci_ProcessReadRequest(WDFQUEUE queue
    3.43    }
    3.44    ASSERT(NT_SUCCESS(status)); // lazy?
    3.45  
    3.46 -  while(dst_offset < dst_length && (list_entry = (xenbus_read_queue_item_t *)RemoveHeadList(&xpdid->read_list_head)) != (xenbus_read_queue_item_t *)&xpdid->read_list_head)
    3.47 +  while(dst_offset < dst_length && (list_entry = (xenbus_read_queue_item_t *)RemoveHeadList(&xpdid->xenbus.read_list_head)) != (xenbus_read_queue_item_t *)&xpdid->xenbus.read_list_head)
    3.48    {
    3.49      copy_length = min(list_entry->length - list_entry->offset, dst_length - dst_offset);
    3.50      memcpy((PUCHAR)buffer + dst_offset, (PUCHAR)list_entry->data + list_entry->offset, copy_length);
    3.51 @@ -98,7 +70,7 @@ XenPci_ProcessReadRequest(WDFQUEUE queue
    3.52      }
    3.53      else
    3.54      {
    3.55 -      InsertHeadList(&xpdid->read_list_head, (PLIST_ENTRY)list_entry);
    3.56 +      InsertHeadList(&xpdid->xenbus.read_list_head, (PLIST_ENTRY)list_entry);
    3.57      }      
    3.58    }
    3.59    WdfRequestSetInformation(request, dst_offset);
    3.60 @@ -138,9 +110,9 @@ XenPci_IoWatch(char *path, PVOID context
    3.61    list_entry->data = rep;
    3.62    list_entry->length = sizeof(*rep) + rep->len;
    3.63    list_entry->offset = 0;
    3.64 -  InsertTailList(&xpdid->read_list_head, (PLIST_ENTRY)list_entry);
    3.65 +  InsertTailList(&xpdid->xenbus.read_list_head, (PLIST_ENTRY)list_entry);
    3.66      
    3.67 -  status = WdfIoQueueRetrieveNextRequest(xpdid->io_queue, &request);
    3.68 +  status = WdfIoQueueRetrieveNextRequest(xpdid->xenbus.io_queue, &request);
    3.69    if (NT_SUCCESS(status))
    3.70    {
    3.71      WDF_REQUEST_PARAMETERS parameters;
    3.72 @@ -148,7 +120,7 @@ XenPci_IoWatch(char *path, PVOID context
    3.73      WdfRequestGetParameters(request, &parameters);
    3.74      
    3.75      KdPrint((__DRIVER_NAME "     found pending read - MinorFunction = %d, length = %d\n", (ULONG)parameters.MinorFunction, (ULONG)parameters.Parameters.Read.Length));
    3.76 -    XenPci_ProcessReadRequest(xpdid->io_queue, request, parameters.Parameters.Read.Length);
    3.77 +    XenBus_ProcessReadRequest(xpdid->xenbus.io_queue, request, parameters.Parameters.Read.Length);
    3.78      KeReleaseSpinLock(&xpdid->lock, old_irql);
    3.79      WdfRequestComplete(request, STATUS_SUCCESS);
    3.80    }
    3.81 @@ -161,8 +133,8 @@ XenPci_IoWatch(char *path, PVOID context
    3.82    FUNCTION_EXIT();
    3.83  }
    3.84  
    3.85 -VOID
    3.86 -XenPci_EvtFileCleanup(WDFFILEOBJECT file_object)
    3.87 +static VOID
    3.88 +XenBus_EvtFileCleanup(WDFFILEOBJECT file_object)
    3.89  {
    3.90    PXENPCI_DEVICE_INTERFACE_DATA xpdid = GetXpdid(file_object);
    3.91    PXENPCI_DEVICE_DATA xpdd = GetXpdd(WdfFileObjectGetDevice(file_object));
    3.92 @@ -174,9 +146,9 @@ XenPci_EvtFileCleanup(WDFFILEOBJECT file
    3.93  
    3.94    KeAcquireSpinLock(&xpdid->lock, &old_irql);
    3.95  
    3.96 -  while (!IsListEmpty(&xpdid->watch_list_head))
    3.97 +  while (!IsListEmpty(&xpdid->xenbus.watch_list_head))
    3.98    {
    3.99 -    watch_context = (watch_context_t *)RemoveHeadList(&xpdid->watch_list_head);
   3.100 +    watch_context = (watch_context_t *)RemoveHeadList(&xpdid->xenbus.watch_list_head);
   3.101      KeReleaseSpinLock(&xpdid->lock, old_irql);
   3.102      msg = XenBus_RemWatch(xpdd, XBT_NIL, watch_context->path, XenPci_IoWatch, watch_context);
   3.103      if (msg != NULL)
   3.104 @@ -194,16 +166,16 @@ XenPci_EvtFileCleanup(WDFFILEOBJECT file
   3.105    FUNCTION_EXIT();
   3.106  }
   3.107  
   3.108 -VOID
   3.109 -XenPci_EvtFileClose(WDFFILEOBJECT file_object)
   3.110 +static VOID
   3.111 +XenBus_EvtFileClose(WDFFILEOBJECT file_object)
   3.112  {
   3.113    UNREFERENCED_PARAMETER(file_object);
   3.114    FUNCTION_ENTER();
   3.115    FUNCTION_EXIT();
   3.116  }
   3.117  
   3.118 -VOID
   3.119 -XenPci_EvtIoRead(WDFQUEUE queue, WDFREQUEST request, size_t length)
   3.120 +static VOID
   3.121 +XenBus_EvtIoRead(WDFQUEUE queue, WDFREQUEST request, size_t length)
   3.122  {
   3.123    NTSTATUS status;
   3.124    WDFFILEOBJECT file_object = WdfRequestGetFileObject(request);
   3.125 @@ -213,19 +185,19 @@ XenPci_EvtIoRead(WDFQUEUE queue, WDFREQU
   3.126    UNREFERENCED_PARAMETER(queue);
   3.127    
   3.128    FUNCTION_ENTER();
   3.129 -  status = WdfRequestForwardToIoQueue(request, xpdid->io_queue);
   3.130 +  status = WdfRequestForwardToIoQueue(request, xpdid->xenbus.io_queue);
   3.131    if (!NT_SUCCESS(status))
   3.132    {
   3.133      KdPrint((__DRIVER_NAME "     could not forward request (%08x)\n", status));
   3.134    }
   3.135    KeAcquireSpinLock(&xpdid->lock, &old_irql);
   3.136 -  if (!IsListEmpty(&xpdid->read_list_head))
   3.137 +  if (!IsListEmpty(&xpdid->xenbus.read_list_head))
   3.138    {
   3.139 -    status = WdfIoQueueRetrieveNextRequest(xpdid->io_queue, &request);
   3.140 +    status = WdfIoQueueRetrieveNextRequest(xpdid->xenbus.io_queue, &request);
   3.141      if (NT_SUCCESS(status))
   3.142      {
   3.143        KdPrint((__DRIVER_NAME "     found pending read\n"));
   3.144 -      XenPci_ProcessReadRequest(xpdid->io_queue, request, length);
   3.145 +      XenBus_ProcessReadRequest(xpdid->xenbus.io_queue, request, length);
   3.146        KeReleaseSpinLock(&xpdid->lock, old_irql);
   3.147        WdfRequestComplete(request, STATUS_SUCCESS);
   3.148      }
   3.149 @@ -245,8 +217,8 @@ XenPci_EvtIoRead(WDFQUEUE queue, WDFREQU
   3.150    return;
   3.151  }
   3.152  
   3.153 -VOID
   3.154 -XenPci_EvtIoWrite(WDFQUEUE queue, WDFREQUEST request, size_t length)
   3.155 +static VOID
   3.156 +XenBus_EvtIoWrite(WDFQUEUE queue, WDFREQUEST request, size_t length)
   3.157  {
   3.158    NTSTATUS status;
   3.159    PXENPCI_DEVICE_DATA xpdd = GetXpdd(WdfIoQueueGetDevice(queue));
   3.160 @@ -272,58 +244,58 @@ XenPci_EvtIoWrite(WDFQUEUE queue, WDFREQ
   3.161    
   3.162    src_ptr = (PUCHAR)buffer;
   3.163    src_len = (ULONG)length;
   3.164 -  dst_ptr = xpdid->u.buffer + xpdid->len;
   3.165 +  dst_ptr = xpdid->xenbus.u.buffer + xpdid->xenbus.len;
   3.166    while (src_len != 0)
   3.167    {
   3.168      KdPrint((__DRIVER_NAME "     %d bytes of write buffer remaining\n", src_len));
   3.169      /* get a complete msg header */
   3.170 -    if (xpdid->len < sizeof(xpdid->u.msg))
   3.171 +    if (xpdid->xenbus.len < sizeof(xpdid->xenbus.u.msg))
   3.172      {
   3.173 -      copy_len = min(sizeof(xpdid->u.msg) - xpdid->len, src_len);
   3.174 +      copy_len = min(sizeof(xpdid->xenbus.u.msg) - xpdid->xenbus.len, src_len);
   3.175        if (!copy_len)
   3.176          continue;
   3.177        memcpy(dst_ptr, src_ptr, copy_len);
   3.178        dst_ptr += copy_len;
   3.179        src_ptr += copy_len;
   3.180        src_len -= copy_len;
   3.181 -      xpdid->len += copy_len;
   3.182 +      xpdid->xenbus.len += copy_len;
   3.183      }
   3.184      /* exit if we can't get that */
   3.185 -    if (xpdid->len < sizeof(xpdid->u.msg))
   3.186 +    if (xpdid->xenbus.len < sizeof(xpdid->xenbus.u.msg))
   3.187        continue;
   3.188      /* get a complete msg body */
   3.189 -    if (xpdid->len < sizeof(xpdid->u.msg) + xpdid->u.msg.len)
   3.190 +    if (xpdid->xenbus.len < sizeof(xpdid->xenbus.u.msg) + xpdid->xenbus.u.msg.len)
   3.191      {
   3.192 -      copy_len = min(sizeof(xpdid->u.msg) + xpdid->u.msg.len - xpdid->len, src_len);
   3.193 +      copy_len = min(sizeof(xpdid->xenbus.u.msg) + xpdid->xenbus.u.msg.len - xpdid->xenbus.len, src_len);
   3.194        if (!copy_len)
   3.195          continue;
   3.196        memcpy(dst_ptr, src_ptr, copy_len);
   3.197        dst_ptr += copy_len;
   3.198        src_ptr += copy_len;
   3.199        src_len -= copy_len;
   3.200 -      xpdid->len += copy_len;
   3.201 +      xpdid->xenbus.len += copy_len;
   3.202      }
   3.203      /* exit if we can't get that */
   3.204 -    if (xpdid->len < sizeof(xpdid->u.msg) + xpdid->u.msg.len)
   3.205 +    if (xpdid->xenbus.len < sizeof(xpdid->xenbus.u.msg) + xpdid->xenbus.u.msg.len)
   3.206      {
   3.207        continue;
   3.208      }
   3.209      
   3.210 -    switch (xpdid->u.msg.type)
   3.211 +    switch (xpdid->xenbus.u.msg.type)
   3.212      {
   3.213      case XS_WATCH:
   3.214      case XS_UNWATCH:
   3.215        KeAcquireSpinLock(&xpdid->lock, &old_irql);
   3.216        watch_context = (watch_context_t *)ExAllocatePoolWithTag(NonPagedPool, sizeof(watch_context_t), XENPCI_POOL_TAG);
   3.217 -      watch_path = (PCHAR)(xpdid->u.buffer + sizeof(struct xsd_sockmsg));
   3.218 -      watch_token = (PCHAR)(xpdid->u.buffer + sizeof(struct xsd_sockmsg) + strlen(watch_path) + 1);
   3.219 +      watch_path = (PCHAR)(xpdid->xenbus.u.buffer + sizeof(struct xsd_sockmsg));
   3.220 +      watch_token = (PCHAR)(xpdid->xenbus.u.buffer + sizeof(struct xsd_sockmsg) + strlen(watch_path) + 1);
   3.221        RtlStringCbCopyA(watch_context->path, ARRAY_SIZE(watch_context->path), watch_path);
   3.222        RtlStringCbCopyA(watch_context->token, ARRAY_SIZE(watch_context->path), watch_token);
   3.223        watch_context->file_object = file_object;
   3.224 -      if (xpdid->u.msg.type == XS_WATCH)
   3.225 -        InsertTailList(&xpdid->watch_list_head, &watch_context->entry);
   3.226 +      if (xpdid->xenbus.u.msg.type == XS_WATCH)
   3.227 +        InsertTailList(&xpdid->xenbus.watch_list_head, &watch_context->entry);
   3.228        KeReleaseSpinLock(&xpdid->lock, old_irql);
   3.229 -      if (xpdid->u.msg.type == XS_WATCH)
   3.230 +      if (xpdid->xenbus.u.msg.type == XS_WATCH)
   3.231          msg = XenBus_AddWatch(xpdd, XBT_NIL, watch_path, XenPci_IoWatch, watch_context);
   3.232        else
   3.233          msg = XenBus_RemWatch(xpdd, XBT_NIL, watch_path, XenPci_IoWatch, watch_context);
   3.234 @@ -332,16 +304,16 @@ XenPci_EvtIoWrite(WDFQUEUE queue, WDFREQ
   3.235        {
   3.236          rep = ExAllocatePoolWithTag(NonPagedPool, sizeof(struct xsd_sockmsg) + strlen(msg) + 1, XENPCI_POOL_TAG);
   3.237          rep->type = XS_ERROR;
   3.238 -        rep->req_id = xpdid->u.msg.req_id;
   3.239 -        rep->tx_id = xpdid->u.msg.tx_id;
   3.240 +        rep->req_id = xpdid->xenbus.u.msg.req_id;
   3.241 +        rep->tx_id = xpdid->xenbus.u.msg.tx_id;
   3.242          rep->len = (ULONG)(strlen(msg) + 0);
   3.243          RtlStringCbCopyA((PCHAR)(rep + 1), strlen(msg) + 1, msg);
   3.244 -        if (xpdid->u.msg.type == XS_WATCH)
   3.245 +        if (xpdid->xenbus.u.msg.type == XS_WATCH)
   3.246            RemoveEntryList(&watch_context->entry);
   3.247        }
   3.248        else
   3.249        {
   3.250 -        if (xpdid->u.msg.type == XS_WATCH)
   3.251 +        if (xpdid->xenbus.u.msg.type == XS_WATCH)
   3.252          {
   3.253            WdfObjectReference(file_object);
   3.254          }
   3.255 @@ -351,29 +323,61 @@ XenPci_EvtIoWrite(WDFQUEUE queue, WDFREQ
   3.256            WdfObjectDereference(file_object);
   3.257          }
   3.258          rep = ExAllocatePoolWithTag(NonPagedPool, sizeof(struct xsd_sockmsg), XENPCI_POOL_TAG);
   3.259 -        rep->type = xpdid->u.msg.type;
   3.260 -        rep->req_id = xpdid->u.msg.req_id;
   3.261 -        rep->tx_id = xpdid->u.msg.tx_id;
   3.262 +        rep->type = xpdid->xenbus.u.msg.type;
   3.263 +        rep->req_id = xpdid->xenbus.u.msg.req_id;
   3.264 +        rep->tx_id = xpdid->xenbus.u.msg.tx_id;
   3.265          rep->len = 0;
   3.266        }
   3.267        KeReleaseSpinLock(&xpdid->lock, old_irql);
   3.268        break;
   3.269      default:
   3.270 -      rep = XenBus_Raw(xpdd, &xpdid->u.msg);
   3.271 +      rep = XenBus_Raw(xpdd, &xpdid->xenbus.u.msg);
   3.272        break;
   3.273      }
   3.274 -    xpdid->len = 0;
   3.275 +    xpdid->xenbus.len = 0;
   3.276      
   3.277      KeAcquireSpinLock(&xpdid->lock, &old_irql);
   3.278      list_entry = (xenbus_read_queue_item_t *)ExAllocatePoolWithTag(NonPagedPool, sizeof(xenbus_read_queue_item_t), XENPCI_POOL_TAG);
   3.279      list_entry->data = rep;
   3.280      list_entry->length = sizeof(*rep) + rep->len;
   3.281      list_entry->offset = 0;
   3.282 -    InsertTailList(&xpdid->read_list_head, (PLIST_ENTRY)list_entry);
   3.283 +    InsertTailList(&xpdid->xenbus.read_list_head, (PLIST_ENTRY)list_entry);
   3.284      KeReleaseSpinLock(&xpdid->lock, old_irql);
   3.285    }
   3.286    KdPrint((__DRIVER_NAME "     completing request with length %d\n", length));
   3.287    WdfRequestCompleteWithInformation(request, STATUS_SUCCESS, length);
   3.288  
   3.289    FUNCTION_EXIT();
   3.290 -}
   3.291 \ No newline at end of file
   3.292 +}
   3.293 +
   3.294 +NTSTATUS
   3.295 +XenBus_DeviceFileInit(WDFDEVICE device, PWDF_IO_QUEUE_CONFIG queue_config, WDFFILEOBJECT file_object)
   3.296 +{
   3.297 +  NTSTATUS status;
   3.298 +  PXENPCI_DEVICE_INTERFACE_DATA xpdid = GetXpdid(file_object);
   3.299 +  WDF_IO_QUEUE_CONFIG internal_queue_config;
   3.300 +  
   3.301 +  FUNCTION_ENTER();
   3.302 +
   3.303 +  xpdid->EvtFileCleanup = XenBus_EvtFileCleanup;  
   3.304 +  xpdid->EvtFileClose = XenBus_EvtFileClose;
   3.305 +  queue_config->EvtIoRead = XenBus_EvtIoRead;
   3.306 +  queue_config->EvtIoWrite = XenBus_EvtIoWrite;
   3.307 +  // queue_config->EvtIoDeviceControl = XenBus_EvtIoDeviceControl;
   3.308 +  
   3.309 +  InitializeListHead(&xpdid->xenbus.read_list_head);
   3.310 +  InitializeListHead(&xpdid->xenbus.watch_list_head);
   3.311 +  xpdid->xenbus.len = 0;
   3.312 +  WDF_IO_QUEUE_CONFIG_INIT(&internal_queue_config, WdfIoQueueDispatchManual);
   3.313 +  
   3.314 +  status = WdfIoQueueCreate(device, &internal_queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xpdid->xenbus.io_queue);
   3.315 +  if (!NT_SUCCESS(status)) {
   3.316 +    KdPrint(("Error creating queue 0x%x\n", status));
   3.317 +    FUNCTION_EXIT();
   3.318 +    return status;
   3.319 +  }
   3.320 +  
   3.321 +  FUNCTION_EXIT();
   3.322 +  
   3.323 +  return status;
   3.324 +}
     4.1 --- a/xenpci/xenpci.c	Wed Sep 23 17:06:30 2009 +1000
     4.2 +++ b/xenpci/xenpci.c	Fri Oct 02 13:53:13 2009 +1000
     4.3 @@ -170,8 +170,7 @@ XenPci_EvtDeviceAdd_XenPci(WDFDRIVER dri
     4.4    WdfDeviceSetSpecialFileSupport(device, WdfSpecialFileDump, TRUE);
     4.5  
     4.6    WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queue_config, WdfIoQueueDispatchParallel);
     4.7 -  queue_config.EvtIoRead = XenPci_EvtIoRead;
     4.8 -  queue_config.EvtIoWrite = XenPci_EvtIoWrite;
     4.9 +  queue_config.EvtIoDefault = XenPci_EvtIoDefault;
    4.10    status = WdfIoQueueCreate(device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xpdd->io_queue);
    4.11    if (!NT_SUCCESS(status)) {
    4.12        KdPrint(("Error creating queue 0x%x\n", status));
    4.13 @@ -196,6 +195,20 @@ XenPci_EvtDeviceAdd_XenPci(WDFDRIVER dri
    4.14        return status;
    4.15    }
    4.16  
    4.17 +  RtlInitUnicodeString(&reference, L"evtchn");
    4.18 +  status = WdfDeviceCreateDeviceInterface(device, &GUID_DEVINTERFACE_EVTCHN, &reference);
    4.19 +  if (!NT_SUCCESS(status)) {
    4.20 +      KdPrint(("Error registering device interface 0x%x\n", status));
    4.21 +      return status;
    4.22 +  }
    4.23 +
    4.24 +  RtlInitUnicodeString(&reference, L"gntdev");
    4.25 +  status = WdfDeviceCreateDeviceInterface(device, &GUID_DEVINTERFACE_GNTDEV, &reference);
    4.26 +  if (!NT_SUCCESS(status)) {
    4.27 +      KdPrint(("Error registering device interface 0x%x\n", status));
    4.28 +      return status;
    4.29 +  }
    4.30 +
    4.31    pbi.BusTypeGuid = GUID_BUS_TYPE_XEN;
    4.32    pbi.LegacyBusType = PNPBus;
    4.33    pbi.BusNumber = 0;
     5.1 --- a/xenpci/xenpci.h	Wed Sep 23 17:06:30 2009 +1000
     5.2 +++ b/xenpci/xenpci.h	Fri Oct 02 13:53:13 2009 +1000
     5.3 @@ -321,31 +321,52 @@ typedef struct {
     5.4  
     5.5  #define XEN_INTERFACE_VERSION 1
     5.6  
     5.7 -#define DEVICE_INTERFACE_TYPE_LEGACY 0
     5.8 +//#define DEVICE_INTERFACE_TYPE_LEGACY 0
     5.9  #define DEVICE_INTERFACE_TYPE_XENBUS 1
    5.10 +#define DEVICE_INTERFACE_TYPE_EVTCHN 2
    5.11 +#define DEVICE_INTERFACE_TYPE_GNTDEV 3
    5.12  
    5.13  typedef struct {
    5.14 -  ULONG type; /* must be the first member */
    5.15 -  KSPIN_LOCK lock;
    5.16    ULONG len;
    5.17 +  WDFQUEUE io_queue;
    5.18    union {
    5.19      struct xsd_sockmsg msg;
    5.20      UCHAR buffer[PAGE_SIZE];
    5.21    } u;
    5.22    LIST_ENTRY read_list_head;
    5.23    LIST_ENTRY watch_list_head;
    5.24 +} XENBUS_INTERFACE_DATA, *PXENBUS_INTERFACE_DATA;
    5.25 +
    5.26 +typedef struct {
    5.27 +  ULONG dummy; /* fill this in with whatever is required */
    5.28 +} EVTCHN_INTERFACE_DATA, *PEVTCHN_INTERFACE_DATA;
    5.29 +
    5.30 +typedef struct {
    5.31 +  ULONG dummy;  /* fill this in with whatever is required */
    5.32 +} GNTDEV_INTERFACE_DATA, *PGNTDEV_INTERFACE_DATA;
    5.33 +
    5.34 +typedef struct {
    5.35 +  ULONG type;
    5.36 +  KSPIN_LOCK lock;
    5.37    WDFQUEUE io_queue;
    5.38 -
    5.39 -  //PIRP pending_read_irp;
    5.40 +  EVT_WDF_FILE_CLEANUP *EvtFileCleanup;
    5.41 +  EVT_WDF_FILE_CLOSE *EvtFileClose;
    5.42 +  union {
    5.43 +    XENBUS_INTERFACE_DATA xenbus;
    5.44 +    EVTCHN_INTERFACE_DATA evtchn;
    5.45 +    GNTDEV_INTERFACE_DATA gntdev;
    5.46 +  };
    5.47  } XENPCI_DEVICE_INTERFACE_DATA, *PXENPCI_DEVICE_INTERFACE_DATA;
    5.48  
    5.49  WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENPCI_DEVICE_INTERFACE_DATA, GetXpdid)
    5.50  
    5.51 +NTSTATUS
    5.52 +XenBus_DeviceFileInit(WDFDEVICE device, PWDF_IO_QUEUE_CONFIG queue_config, WDFFILEOBJECT file_object);
    5.53 +
    5.54  EVT_WDF_DEVICE_FILE_CREATE XenPci_EvtDeviceFileCreate;
    5.55  EVT_WDF_FILE_CLOSE XenPci_EvtFileClose;
    5.56  EVT_WDF_FILE_CLEANUP XenPci_EvtFileCleanup;
    5.57 -EVT_WDF_IO_QUEUE_IO_READ XenPci_EvtIoRead;
    5.58 -EVT_WDF_IO_QUEUE_IO_WRITE XenPci_EvtIoWrite;
    5.59 +EVT_WDF_IO_QUEUE_IO_DEFAULT XenPci_EvtIoDefault;
    5.60  
    5.61  #include "hypercall.h"
    5.62  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/xenpci/xenpci_device_interface.c	Fri Oct 02 13:53:13 2009 +1000
     6.3 @@ -0,0 +1,82 @@
     6.4 +/*
     6.5 +PV Drivers for Windows Xen HVM Domains
     6.6 +Copyright (C) 2009 James Harper
     6.7 +
     6.8 +This program is free software; you can redistribute it and/or
     6.9 +modify it under the terms of the GNU General Public License
    6.10 +as published by the Free Software Foundation; either version 2
    6.11 +of the License, or (at your option) any later version.
    6.12 +
    6.13 +This program is distributed in the hope that it will be useful,
    6.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.16 +GNU General Public License for more details.
    6.17 +
    6.18 +You should have received a copy of the GNU General Public License
    6.19 +along with this program; if not, write to the Free Software
    6.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    6.21 +*/
    6.22 +
    6.23 +#include "xenpci.h"
    6.24 +
    6.25 +VOID
    6.26 +XenPci_EvtDeviceFileCreate(WDFDEVICE device, WDFREQUEST request, WDFFILEOBJECT file_object)
    6.27 +{
    6.28 +  NTSTATUS status;
    6.29 +  PXENPCI_DEVICE_INTERFACE_DATA xpdid = GetXpdid(file_object);
    6.30 +  WDF_IO_QUEUE_CONFIG queue_config;
    6.31 +  
    6.32 +  FUNCTION_ENTER();
    6.33 +  
    6.34 +  xpdid->type = DEVICE_INTERFACE_TYPE_XENBUS; //TODO: determine the actual type
    6.35 +  
    6.36 +  KeInitializeSpinLock(&xpdid->lock);
    6.37 +  WDF_IO_QUEUE_CONFIG_INIT(&queue_config, WdfIoQueueDispatchSequential);
    6.38 +  status = XenBus_DeviceFileInit(device, &queue_config, file_object); /* this completes the queue init */  
    6.39 +  if (!NT_SUCCESS(status)) {
    6.40 +      WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    6.41 +  }
    6.42 +  status = WdfIoQueueCreate(device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xpdid->io_queue);
    6.43 +  if (!NT_SUCCESS(status)) {
    6.44 +      KdPrint(("Error creating queue 0x%x\n", status));
    6.45 +      WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    6.46 +  }
    6.47 +
    6.48 +  WdfRequestComplete(request, STATUS_SUCCESS);
    6.49 +  
    6.50 +  FUNCTION_EXIT();
    6.51 +}
    6.52 +
    6.53 +VOID
    6.54 +XenPci_EvtFileCleanup(WDFFILEOBJECT file_object)
    6.55 +{
    6.56 +  PXENPCI_DEVICE_INTERFACE_DATA xpdid = GetXpdid(file_object);
    6.57 +
    6.58 +  FUNCTION_ENTER();
    6.59 +  xpdid->EvtFileCleanup(file_object);
    6.60 +  FUNCTION_EXIT();
    6.61 +}
    6.62 +
    6.63 +VOID
    6.64 +XenPci_EvtFileClose(WDFFILEOBJECT file_object)
    6.65 +{
    6.66 +  
    6.67 +  PXENPCI_DEVICE_INTERFACE_DATA xpdid = GetXpdid(file_object);
    6.68 +
    6.69 +  FUNCTION_ENTER();
    6.70 +  xpdid->EvtFileClose(file_object);
    6.71 +  FUNCTION_EXIT();
    6.72 +}
    6.73 +
    6.74 +VOID
    6.75 +XenPci_EvtIoDefault(WDFQUEUE queue, WDFREQUEST request)
    6.76 +{
    6.77 +  WDFFILEOBJECT file_object = WdfRequestGetFileObject(request);
    6.78 +  PXENPCI_DEVICE_INTERFACE_DATA xpdid = GetXpdid(file_object);
    6.79 +
    6.80 +  UNREFERENCED_PARAMETER(queue);
    6.81 +  
    6.82 +  FUNCTION_ENTER();
    6.83 +  WdfRequestForwardToIoQueue(request, xpdid->io_queue);
    6.84 +  FUNCTION_EXIT();
    6.85 +}