win-pvdrivers

changeset 1031:329b9b9d47ec

re-enable xenusb. compiles but untested.
author James Harper <james.harper@bendigoit.com.au>
date Thu Feb 21 20:37:38 2013 +1100 (2013-02-21)
parents 37c0c84a42e8
children 306c10cdcba1
files dirs xenusb/sources xenusb/xenusb.c xenusb/xenusb.h xenusb/xenusb_decode.c xenusb/xenusb_devurb.c xenusb/xenusb_fdo.c xenusb/xenusb_hub.c xenusb/xenusb_huburb.c
line diff
     1.1 --- a/dirs	Wed Feb 20 20:49:26 2013 +1100
     1.2 +++ b/dirs	Thu Feb 21 20:37:38 2013 +1100
     1.3 @@ -1,4 +1,2 @@
     1.4  
     1.5 -#DIRS=liblfds.6 xenpci xenvbd xennet xenscsi xenusb copyconfig shutdownmon waitnopendinginstallevents
     1.6 -
     1.7 -DIRS=liblfds.6 xenpci xenvbd_scsiport xenvbd_storport xenvbd_filter xennet copyconfig shutdownmon waitnopendinginstallevents
     1.8 +DIRS=liblfds.6 xenpci xenvbd_scsiport xenvbd_storport xenvbd_filter xennet xenusb copyconfig shutdownmon waitnopendinginstallevents
     2.1 --- a/xenusb/sources	Wed Feb 20 20:49:26 2013 +1100
     2.2 +++ b/xenusb/sources	Thu Feb 21 20:37:38 2013 +1100
     2.3 @@ -2,11 +2,18 @@
     2.4  TARGETNAME=xenusb
     2.5  TARGETTYPE=DRIVER
     2.6  KMDF_VERSION_MAJOR=1
     2.7 -NTTARGETFILES=$(NTTARGETFILES) $(OBJ_PATH)\$(O)\$(TARGETNAME).inf
     2.8 -TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\wdmsec.lib $(DDK_LIB_PATH)\Rtlver.lib $(DDK_LIB_PATH)\..\..\wlh\*\aux_klib.lib
     2.9 +NTTARGETFILE0=$(NTTARGETFILES) $(OBJ_PATH)\$(O)\$(TARGETNAME).inf
    2.10 +TARGETLIBS=$(TARGETLIBS) ..\xenpci\$(O)\xenpci.lib
    2.11 +TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\wdmsec.lib
    2.12 +TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\Rtlver.lib
    2.13 +TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\..\..\wlh\*\aux_klib.lib
    2.14  !IF $(386)
    2.15  TARGETLIBS=$(TARGETLIBS) $(LIBLFDS_DIR)\bin\i386\liblfds.lib
    2.16  !ELSE
    2.17  TARGETLIBS=$(TARGETLIBS) $(LIBLFDS_DIR)\bin\AMD64\liblfds.lib
    2.18  !ENDIF
    2.19 +
    2.20 +
    2.21 +
    2.22 +
    2.23  SOURCES=xenusb.rc xenusb.c xenusb_fdo.c xenusb_hub.c xenusb_huburb.c xenusb_devurb.c xenusb_decode.c
     3.1 --- a/xenusb/xenusb.c	Wed Feb 20 20:49:26 2013 +1100
     3.2 +++ b/xenusb/xenusb.c	Thu Feb 21 20:37:38 2013 +1100
     3.3 @@ -21,29 +21,21 @@ Foundation, Inc., 51 Franklin Street, Fi
     3.4  #include "xenusb.h"
     3.5  #include <stdlib.h>
     3.6  
     3.7 -/* Not really necessary but keeps PREfast happy */
     3.8  DRIVER_INITIALIZE DriverEntry;
     3.9  
    3.10  NTSTATUS
    3.11 -DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    3.12 -{
    3.13 +DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) {
    3.14    NTSTATUS status = STATUS_SUCCESS;
    3.15 -  PVOID driver_extension;
    3.16 -  PUCHAR ptr;
    3.17    WDF_DRIVER_CONFIG config;
    3.18    WDFDRIVER driver;
    3.19  
    3.20    FUNCTION_ENTER();
    3.21  
    3.22 -  IoAllocateDriverObjectExtension(DriverObject, UlongToPtr(XEN_INIT_DRIVER_EXTENSION_MAGIC), PAGE_SIZE, &driver_extension);
    3.23 -  ptr = driver_extension;
    3.24 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL, NULL);
    3.25 -    
    3.26    WDF_DRIVER_CONFIG_INIT(&config, XenUsb_EvtDriverDeviceAdd);
    3.27    status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, &driver);
    3.28  
    3.29    if (!NT_SUCCESS(status)) {
    3.30 -    KdPrint((__DRIVER_NAME "     WdfDriverCreate failed with status 0x%x\n", status));
    3.31 +    FUNCTION_MSG("WdfDriverCreate failed with status 0x%x\n", status);
    3.32    }
    3.33  
    3.34    FUNCTION_EXIT();
     4.1 --- a/xenusb/xenusb.h	Wed Feb 20 20:49:26 2013 +1100
     4.2 +++ b/xenusb/xenusb.h	Thu Feb 21 20:37:38 2013 +1100
     4.3 @@ -199,6 +199,12 @@ typedef struct
     4.4    ULONG reset_counter;
     4.5  } xenusb_port_t;
     4.6  
     4.7 +#define DEVICE_STATE_DISCONNECTED  0 /* -> INITIALISING */
     4.8 +#define DEVICE_STATE_INITIALISING  1 /* -> ACTIVE or INACTIVE */
     4.9 +#define DEVICE_STATE_INACTIVE      2
    4.10 +#define DEVICE_STATE_ACTIVE        3 /* -> DISCONNECTING */
    4.11 +#define DEVICE_STATE_DISCONNECTING 4 /* -> DISCONNECTED */
    4.12 +
    4.13  /*
    4.14  TODO: this driver crashes under checked build of windows (or probably just checked usbhub.sys)
    4.15  Needs a magic number of (ULONG)'HUBx' at the start of BusContext
    4.16 @@ -213,9 +219,16 @@ typedef struct {
    4.17    WDFQUEUE io_queue;
    4.18    WDFQUEUE pvurb_queue;
    4.19    WDFCHILDLIST child_list;
    4.20 +  PDEVICE_OBJECT pdo;
    4.21    
    4.22    WDFDEVICE root_hub_device;
    4.23  
    4.24 +  XN_HANDLE handle;
    4.25 +  ULONG device_state;
    4.26 +  ULONG backend_state;
    4.27 +  KEVENT backend_event;
    4.28 +  KDPC event_dpc;
    4.29 +
    4.30    struct stack_state *req_id_ss;
    4.31    partial_pvurb_t *partial_pvurbs[MAX_REQ_ID_COUNT];
    4.32  
    4.33 @@ -228,19 +241,18 @@ typedef struct {
    4.34    KSPIN_LOCK urb_ring_lock;
    4.35    usbif_urb_sring_t *urb_sring;
    4.36    usbif_urb_front_ring_t urb_ring;
    4.37 +  grant_ref_t urb_sring_gref;
    4.38 +
    4.39    LIST_ENTRY partial_pvurb_queue;
    4.40    LIST_ENTRY partial_pvurb_ring;
    4.41  
    4.42    KSPIN_LOCK conn_ring_lock;
    4.43    usbif_conn_sring_t *conn_sring;
    4.44    usbif_conn_front_ring_t conn_ring;
    4.45 +  grant_ref_t conn_sring_gref;
    4.46  
    4.47    domid_t backend_id;
    4.48    evtchn_port_t event_channel;
    4.49 -
    4.50 -  XENPCI_VECTORS vectors;
    4.51 -  PXENPCI_DEVICE_STATE device_state;
    4.52 -
    4.53  } XENUSB_DEVICE_DATA, *PXENUSB_DEVICE_DATA;
    4.54  
    4.55  WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENUSB_DEVICE_DATA, GetXudd)
    4.56 @@ -285,7 +297,7 @@ static uint16_t
    4.57  get_id_from_freelist(struct stack_state *ss) {
    4.58    ULONG_PTR _id;
    4.59    if (!stack_pop(ss, (VOID *)&_id)) {
    4.60 -    KdPrint((__DRIVER_NAME "     No more id's\n"));
    4.61 +    FUNCTION_MSG("No more id's\n");
    4.62      return (uint16_t)-1;
    4.63    }
    4.64    return (uint16_t)_id;
    4.65 @@ -298,11 +310,9 @@ put_id_on_freelist(struct stack_state *s
    4.66  }
    4.67  
    4.68  static
    4.69 -ULONGLONG parse_numeric_string(PCHAR string)
    4.70 -{
    4.71 +ULONGLONG parse_numeric_string(PCHAR string) {
    4.72    ULONGLONG val = 0;
    4.73 -  while (*string != 0)
    4.74 -  {
    4.75 +  while (*string != 0) {
    4.76      val = val * 10 + (*string - '0');
    4.77      string++;
    4.78    }
     5.1 --- a/xenusb/xenusb_decode.c	Wed Feb 20 20:49:26 2013 +1100
     5.2 +++ b/xenusb/xenusb_decode.c	Thu Feb 21 20:37:38 2013 +1100
     5.3 @@ -190,7 +190,7 @@ XenUsb_DecodeControlUrb(PURB urb, urb_de
     5.4    switch(urb->UrbHeader.Function)
     5.5    {
     5.6    case URB_FUNCTION_SELECT_CONFIGURATION:
     5.7 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_CONFIGURATION\n"));
     5.8 +    FUNCTION_MSG("URB_FUNCTION_SELECT_CONFIGURATION\n");
     5.9      decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
    5.10      decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Type = BMREQUEST_STANDARD;
    5.11      decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
    5.12 @@ -204,7 +204,7 @@ XenUsb_DecodeControlUrb(PURB urb, urb_de
    5.13      retval = URB_DECODE_INCOMPLETE;
    5.14      break;
    5.15    case URB_FUNCTION_SELECT_INTERFACE:
    5.16 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_INTERFACE\n"));
    5.17 +    FUNCTION_MSG("URB_FUNCTION_SELECT_INTERFACE\n");
    5.18      decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
    5.19      decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Type = BMREQUEST_STANDARD;
    5.20      decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
     6.1 --- a/xenusb/xenusb_devurb.c	Wed Feb 20 20:49:26 2013 +1100
     6.2 +++ b/xenusb/xenusb_devurb.c	Thu Feb 21 20:37:38 2013 +1100
     6.3 @@ -71,13 +71,13 @@ XenUsb_CompletionBulkInterrupt(
     6.4    WdfRequestGetParameters(request, &wrp);
     6.5    urb = (PURB)wrp.Parameters.Others.Arg1;
     6.6    ASSERT(urb);
     6.7 -  KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
     6.8 -  KdPrint((__DRIVER_NAME "     rsp id = %d\n", pvurb->rsp.id));
     6.9 -  KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", pvurb->rsp.start_frame));
    6.10 -  KdPrint((__DRIVER_NAME "     rsp status = %d\n", pvurb->rsp.status));
    6.11 -  KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", pvurb->rsp.actual_length));
    6.12 -  KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", pvurb->rsp.error_count));
    6.13 -  KdPrint((__DRIVER_NAME "     total_length = %d\n", pvurb->total_length));
    6.14 +  FUNCTION_MSG("URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n");
    6.15 +  FUNCTION_MSG("rsp id = %d\n", pvurb->rsp.id);
    6.16 +  FUNCTION_MSG("rsp start_frame = %d\n", pvurb->rsp.start_frame);
    6.17 +  FUNCTION_MSG("rsp status = %d\n", pvurb->rsp.status);
    6.18 +  FUNCTION_MSG("rsp actual_length = %d\n", pvurb->rsp.actual_length);
    6.19 +  FUNCTION_MSG("rsp error_count = %d\n", pvurb->rsp.error_count);
    6.20 +  FUNCTION_MSG("total_length = %d\n", pvurb->total_length);
    6.21    urb->UrbHeader.Status = XenUsb_GetUsbdStatusFromPvStatus(pvurb->rsp.status);
    6.22    urb->UrbBulkOrInterruptTransfer.TransferBufferLength = (ULONG)params->IoStatus.Information;
    6.23    if (urb->UrbHeader.Status == USBD_STATUS_SUCCESS)
    6.24 @@ -129,12 +129,12 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
    6.25    urb = (PURB)wrp.Parameters.Others.Arg1;
    6.26    ASSERT(urb);
    6.27  #if 0
    6.28 -  KdPrint((__DRIVER_NAME "     urb = %p\n", urb));
    6.29 -  KdPrint((__DRIVER_NAME "      Length = %d\n", urb->UrbHeader.Length));
    6.30 -  KdPrint((__DRIVER_NAME "      Function = %d\n", urb->UrbHeader.Function));
    6.31 -  KdPrint((__DRIVER_NAME "      Status = %d\n", urb->UrbHeader.Status));
    6.32 -  KdPrint((__DRIVER_NAME "      UsbdDeviceHandle = %p\n", urb->UrbHeader.UsbdDeviceHandle));
    6.33 -  KdPrint((__DRIVER_NAME "      UsbdFlags = %08x\n", urb->UrbHeader.UsbdFlags));
    6.34 +  FUNCTION_MSG("urb = %p\n", urb);
    6.35 +  FUNCTION_MSG(" Length = %d\n", urb->UrbHeader.Length);
    6.36 +  FUNCTION_MSG(" Function = %d\n", urb->UrbHeader.Function);
    6.37 +  FUNCTION_MSG(" Status = %d\n", urb->UrbHeader.Status);
    6.38 +  FUNCTION_MSG(" UsbdDeviceHandle = %p\n", urb->UrbHeader.UsbdDeviceHandle);
    6.39 +  FUNCTION_MSG(" UsbdFlags = %08x\n", urb->UrbHeader.UsbdFlags);
    6.40  #endif
    6.41    usb_device = urb->UrbHeader.UsbdDeviceHandle;
    6.42  
    6.43 @@ -170,18 +170,18 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
    6.44    switch(urb->UrbHeader.Function)
    6.45    {
    6.46    case URB_FUNCTION_SELECT_CONFIGURATION:
    6.47 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_CONFIGURATION\n"));
    6.48 -    KdPrint((__DRIVER_NAME "      ConfigurationDescriptor = %p\n", urb->UrbSelectConfiguration.ConfigurationDescriptor));
    6.49 +    FUNCTION_MSG("URB_FUNCTION_SELECT_CONFIGURATION\n");
    6.50 +    FUNCTION_MSG(" ConfigurationDescriptor = %p\n", urb->UrbSelectConfiguration.ConfigurationDescriptor);
    6.51      if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
    6.52      {
    6.53 -      KdPrint((__DRIVER_NAME "       bLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bLength));
    6.54 -      KdPrint((__DRIVER_NAME "       bDescriptorType = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bDescriptorType));
    6.55 -      KdPrint((__DRIVER_NAME "       wTotalLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->wTotalLength));
    6.56 -      KdPrint((__DRIVER_NAME "       bNumInterfaces = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces));
    6.57 -      KdPrint((__DRIVER_NAME "       bConfigurationValue = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue));
    6.58 -      KdPrint((__DRIVER_NAME "       iConfiguration = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->iConfiguration));
    6.59 -      KdPrint((__DRIVER_NAME "       bmAttributes = %04x\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bmAttributes));
    6.60 -      KdPrint((__DRIVER_NAME "       MaxPower = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower));
    6.61 +      FUNCTION_MSG("  bLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bLength);
    6.62 +      FUNCTION_MSG("  bDescriptorType = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bDescriptorType);
    6.63 +      FUNCTION_MSG("  wTotalLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->wTotalLength);
    6.64 +      FUNCTION_MSG("  bNumInterfaces = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces);
    6.65 +      FUNCTION_MSG("  bConfigurationValue = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue);
    6.66 +      FUNCTION_MSG("  iConfiguration = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->iConfiguration);
    6.67 +      FUNCTION_MSG("  bmAttributes = %04x\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bmAttributes);
    6.68 +      FUNCTION_MSG("  MaxPower = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower);
    6.69      }
    6.70      if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
    6.71      {
    6.72 @@ -204,26 +204,26 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
    6.73          interface_information->SubClass = usb_interface->interface_descriptor.bInterfaceSubClass;
    6.74          interface_information->Protocol = usb_interface->interface_descriptor.bInterfaceProtocol;
    6.75          interface_information->InterfaceHandle = usb_interface;
    6.76 -        KdPrint((__DRIVER_NAME "     InterfaceInformation[%d]\n", i));
    6.77 -        KdPrint((__DRIVER_NAME "      Length = %d\n", interface_information->Length));
    6.78 -        KdPrint((__DRIVER_NAME "      InterfaceNumber = %d\n", interface_information->InterfaceNumber));
    6.79 -        KdPrint((__DRIVER_NAME "      AlternateSetting = %d\n", interface_information->AlternateSetting));
    6.80 -        KdPrint((__DRIVER_NAME "      Class = %02x\n", (ULONG)interface_information->Class));
    6.81 -        KdPrint((__DRIVER_NAME "      SubClass = %02x\n", (ULONG)interface_information->SubClass));
    6.82 -        KdPrint((__DRIVER_NAME "      Protocol = %02x\n", (ULONG)interface_information->Protocol));
    6.83 -        KdPrint((__DRIVER_NAME "      InterfaceHandle = %p\n", interface_information->InterfaceHandle));
    6.84 -        KdPrint((__DRIVER_NAME "      NumberOfPipes = %d\n", interface_information->NumberOfPipes));
    6.85 +        FUNCTION_MSG("InterfaceInformation[%d]\n", i);
    6.86 +        FUNCTION_MSG(" Length = %d\n", interface_information->Length);
    6.87 +        FUNCTION_MSG(" InterfaceNumber = %d\n", interface_information->InterfaceNumber);
    6.88 +        FUNCTION_MSG(" AlternateSetting = %d\n", interface_information->AlternateSetting);
    6.89 +        FUNCTION_MSG(" Class = %02x\n", (ULONG)interface_information->Class);
    6.90 +        FUNCTION_MSG(" SubClass = %02x\n", (ULONG)interface_information->SubClass);
    6.91 +        FUNCTION_MSG(" Protocol = %02x\n", (ULONG)interface_information->Protocol);
    6.92 +        FUNCTION_MSG(" InterfaceHandle = %p\n", interface_information->InterfaceHandle);
    6.93 +        FUNCTION_MSG(" NumberOfPipes = %d\n", interface_information->NumberOfPipes);
    6.94          for (j = 0; j < interface_information->NumberOfPipes; j++)
    6.95          {
    6.96            xenusb_endpoint_t *usb_endpoint = usb_interface->endpoints[j];
    6.97 -          KdPrint((__DRIVER_NAME "      Pipe[%d] (before)\n", j));
    6.98 -          KdPrint((__DRIVER_NAME "       MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
    6.99 -          KdPrint((__DRIVER_NAME "       EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
   6.100 -          KdPrint((__DRIVER_NAME "       Interval = %d\n", interface_information->Pipes[j].Interval));
   6.101 -          KdPrint((__DRIVER_NAME "       PipeType = %d\n", interface_information->Pipes[j].PipeType));
   6.102 -          KdPrint((__DRIVER_NAME "       PipeHandle = %p\n", interface_information->Pipes[j].PipeHandle));
   6.103 -          KdPrint((__DRIVER_NAME "       MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
   6.104 -          KdPrint((__DRIVER_NAME "       PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
   6.105 +          FUNCTION_MSG(" Pipe[%d] (before)\n", j);
   6.106 +          FUNCTION_MSG("  MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize);
   6.107 +          FUNCTION_MSG("  EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress);
   6.108 +          FUNCTION_MSG("  Interval = %d\n", interface_information->Pipes[j].Interval);
   6.109 +          FUNCTION_MSG("  PipeType = %d\n", interface_information->Pipes[j].PipeType);
   6.110 +          FUNCTION_MSG("  PipeHandle = %p\n", interface_information->Pipes[j].PipeHandle);
   6.111 +          FUNCTION_MSG("  MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize);
   6.112 +          FUNCTION_MSG("  PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags);
   6.113            interface_information->Pipes[j].MaximumPacketSize = usb_endpoint->endpoint_descriptor.wMaxPacketSize;
   6.114            interface_information->Pipes[j].EndpointAddress = usb_endpoint->endpoint_descriptor.bEndpointAddress;
   6.115            interface_information->Pipes[j].Interval = usb_endpoint->endpoint_descriptor.bInterval;
   6.116 @@ -247,14 +247,14 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   6.117              break;
   6.118            }
   6.119            interface_information->Pipes[j].PipeHandle = usb_endpoint;
   6.120 -          KdPrint((__DRIVER_NAME "      Pipe[%d] (after)\n", j));
   6.121 -          KdPrint((__DRIVER_NAME "       MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
   6.122 -          KdPrint((__DRIVER_NAME "       EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
   6.123 -          KdPrint((__DRIVER_NAME "       Interval = %d\n", interface_information->Pipes[j].Interval));
   6.124 -          KdPrint((__DRIVER_NAME "       PipeType = %d\n", interface_information->Pipes[j].PipeType));
   6.125 -          KdPrint((__DRIVER_NAME "       PipeHandle = %p\n", interface_information->Pipes[j].PipeHandle));
   6.126 -          KdPrint((__DRIVER_NAME "       MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
   6.127 -          KdPrint((__DRIVER_NAME "       PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
   6.128 +          FUNCTION_MSG(" Pipe[%d] (after)\n", j);
   6.129 +          FUNCTION_MSG("  MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize);
   6.130 +          FUNCTION_MSG("  EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress);
   6.131 +          FUNCTION_MSG("  Interval = %d\n", interface_information->Pipes[j].Interval);
   6.132 +          FUNCTION_MSG("  PipeType = %d\n", interface_information->Pipes[j].PipeType);
   6.133 +          FUNCTION_MSG("  PipeHandle = %p\n", interface_information->Pipes[j].PipeHandle);
   6.134 +          FUNCTION_MSG("  MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize);
   6.135 +          FUNCTION_MSG("  PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags);
   6.136          }
   6.137          interface_information = (PUSBD_INTERFACE_INFORMATION)((PUCHAR)interface_information + interface_information->Length);
   6.138        }
   6.139 @@ -293,28 +293,28 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   6.140      }
   6.141      break;
   6.142    case URB_FUNCTION_SELECT_INTERFACE:
   6.143 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_INTERFACE\n"));
   6.144 +    FUNCTION_MSG("URB_FUNCTION_SELECT_INTERFACE\n");
   6.145      interface_information = &urb->UrbSelectInterface.Interface;
   6.146 -    KdPrint((__DRIVER_NAME "     InterfaceInformation\n"));
   6.147 -    KdPrint((__DRIVER_NAME "      Length = %d\n", interface_information->Length));
   6.148 -    KdPrint((__DRIVER_NAME "      InterfaceNumber = %d\n", interface_information->InterfaceNumber));
   6.149 -    KdPrint((__DRIVER_NAME "      AlternateSetting = %d\n", interface_information->AlternateSetting));
   6.150 -    KdPrint((__DRIVER_NAME "      Class = %02x\n", (ULONG)interface_information->Class));
   6.151 -    KdPrint((__DRIVER_NAME "      SubClass = %02x\n", (ULONG)interface_information->SubClass));
   6.152 -    KdPrint((__DRIVER_NAME "      Protocol = %02x\n", (ULONG)interface_information->Protocol));
   6.153 -    KdPrint((__DRIVER_NAME "      Reserved = %02x\n", (ULONG)interface_information->Reserved));
   6.154 -    KdPrint((__DRIVER_NAME "      InterfaceHandle = %p\n", interface_information->InterfaceHandle));
   6.155 -    KdPrint((__DRIVER_NAME "      NumberOfPipes = %d\n", interface_information->NumberOfPipes));
   6.156 +    FUNCTION_MSG("InterfaceInformation\n");
   6.157 +    FUNCTION_MSG(" Length = %d\n", interface_information->Length);
   6.158 +    FUNCTION_MSG(" InterfaceNumber = %d\n", interface_information->InterfaceNumber);
   6.159 +    FUNCTION_MSG(" AlternateSetting = %d\n", interface_information->AlternateSetting);
   6.160 +    FUNCTION_MSG(" Class = %02x\n", (ULONG)interface_information->Class);
   6.161 +    FUNCTION_MSG(" SubClass = %02x\n", (ULONG)interface_information->SubClass);
   6.162 +    FUNCTION_MSG(" Protocol = %02x\n", (ULONG)interface_information->Protocol);
   6.163 +    FUNCTION_MSG(" Reserved = %02x\n", (ULONG)interface_information->Reserved);
   6.164 +    FUNCTION_MSG(" InterfaceHandle = %p\n", interface_information->InterfaceHandle);
   6.165 +    FUNCTION_MSG(" NumberOfPipes = %d\n", interface_information->NumberOfPipes);
   6.166      for (i = 0; i < interface_information->NumberOfPipes; i++)
   6.167      {
   6.168 -      KdPrint((__DRIVER_NAME "      Pipe[%d]\n", i));
   6.169 -      KdPrint((__DRIVER_NAME "       MaximumPacketSize = %d\n", interface_information->Pipes[i].MaximumPacketSize));
   6.170 -      KdPrint((__DRIVER_NAME "       EndpointAddress = %d\n", interface_information->Pipes[i].EndpointAddress));
   6.171 -      KdPrint((__DRIVER_NAME "       Interval = %d\n", interface_information->Pipes[i].Interval));
   6.172 -      KdPrint((__DRIVER_NAME "       PipeType = %d\n", interface_information->Pipes[i].PipeType));
   6.173 -      KdPrint((__DRIVER_NAME "       PipeHandle = %p\n", interface_information->Pipes[i].PipeHandle));
   6.174 -      KdPrint((__DRIVER_NAME "       MaximumTransferSize = %d\n", interface_information->Pipes[i].MaximumTransferSize));
   6.175 -      KdPrint((__DRIVER_NAME "       PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags));
   6.176 +      FUNCTION_MSG(" Pipe[%d]\n", i);
   6.177 +      FUNCTION_MSG("  MaximumPacketSize = %d\n", interface_information->Pipes[i].MaximumPacketSize);
   6.178 +      FUNCTION_MSG("  EndpointAddress = %d\n", interface_information->Pipes[i].EndpointAddress);
   6.179 +      FUNCTION_MSG("  Interval = %d\n", interface_information->Pipes[i].Interval);
   6.180 +      FUNCTION_MSG("  PipeType = %d\n", interface_information->Pipes[i].PipeType);
   6.181 +      FUNCTION_MSG("  PipeHandle = %p\n", interface_information->Pipes[i].PipeHandle);
   6.182 +      FUNCTION_MSG("  MaximumTransferSize = %d\n", interface_information->Pipes[i].MaximumTransferSize);
   6.183 +      FUNCTION_MSG("  PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags);
   6.184      }
   6.185  
   6.186      pvurb = &local_pvurb; //ExAllocatePoolWithTag(NonPagedPool, sizeof(*pvurb), XENUSB_POOL_TAG);
   6.187 @@ -433,13 +433,13 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   6.188      switch(endpoint->endpoint_descriptor.bmAttributes & USB_ENDPOINT_TYPE_MASK)
   6.189      {
   6.190      case USB_ENDPOINT_TYPE_BULK:
   6.191 -      KdPrint((__DRIVER_NAME "      USB_ENDPOINT_TYPE_BULK\n"));
   6.192 +      FUNCTION_MSG(" USB_ENDPOINT_TYPE_BULK\n");
   6.193        break;
   6.194      case USB_ENDPOINT_TYPE_INTERRUPT:
   6.195 -      KdPrint((__DRIVER_NAME "      USB_ENDPOINT_TYPE_INTERRUPT\n"));
   6.196 +      FUNCTION_MSG(" USB_ENDPOINT_TYPE_INTERRUPT\n");
   6.197        break;
   6.198      default:
   6.199 -      KdPrint((__DRIVER_NAME "      USB_ENDPOINT_TYPE_%d\n", endpoint->endpoint_descriptor.bmAttributes));
   6.200 +      FUNCTION_MSG(" USB_ENDPOINT_TYPE_%d\n", endpoint->endpoint_descriptor.bmAttributes);
   6.201        break;
   6.202      }
   6.203      if (urb->UrbBulkOrInterruptTransfer.TransferBuffer) {
   6.204 @@ -464,8 +464,8 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   6.205      }
   6.206      break;
   6.207    case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
   6.208 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
   6.209 -    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
   6.210 +    FUNCTION_MSG("URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n");
   6.211 +    FUNCTION_MSG(" PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle);
   6.212      /* we only clear the stall here */
   6.213      endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
   6.214  
   6.215 @@ -499,14 +499,14 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   6.216      }
   6.217      break;
   6.218    case URB_FUNCTION_ABORT_PIPE:
   6.219 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_ABORT_PIPE\n"));
   6.220 -    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
   6.221 +    FUNCTION_MSG("URB_FUNCTION_ABORT_PIPE\n");
   6.222 +    FUNCTION_MSG(" PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle);
   6.223      /* just fake this.... i think we really need to flush any pending requests too */
   6.224      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   6.225      WdfRequestComplete(request, STATUS_SUCCESS);
   6.226      break;
   6.227    default:
   6.228 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_%04x\n", urb->UrbHeader.Function));
   6.229 +    FUNCTION_MSG("URB_FUNCTION_%04x\n", urb->UrbHeader.Function);
   6.230      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   6.231      WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   6.232      break;
     7.1 --- a/xenusb/xenusb_fdo.c	Wed Feb 20 20:49:26 2013 +1100
     7.2 +++ b/xenusb/xenusb_fdo.c	Thu Feb 21 20:37:38 2013 +1100
     7.3 @@ -23,12 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     7.4  
     7.5  /* Not really necessary but keeps PREfast happy */
     7.6  static EVT_WDF_DEVICE_D0_ENTRY XenUsb_EvtDeviceD0Entry;
     7.7 -static EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED XenUsb_EvtDeviceD0EntryPostInterruptsEnabled;
     7.8  static EVT_WDF_DEVICE_D0_EXIT XenUsb_EvtDeviceD0Exit;
     7.9 -static EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED XenUsb_EvtDeviceD0ExitPreInterruptsDisabled;
    7.10 -static EVT_WDF_DEVICE_PREPARE_HARDWARE XenUsb_EvtDevicePrepareHardware;
    7.11 -static EVT_WDF_DEVICE_RELEASE_HARDWARE XenUsb_EvtDeviceReleaseHardware;
    7.12 -static EVT_WDF_DEVICE_QUERY_REMOVE XenUsb_EvtDeviceQueryRemove;
    7.13  static EVT_WDFDEVICE_WDM_IRP_PREPROCESS XenUsb_EvtDeviceWdmIrpPreprocessQUERY_INTERFACE;
    7.14  static EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL XenUsb_EvtIoDeviceControl;
    7.15  static EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl;
    7.16 @@ -36,20 +31,8 @@ static EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVI
    7.17  static EVT_WDF_IO_QUEUE_IO_DEFAULT XenUsb_EvtIoDefault;
    7.18  static EVT_WDF_REQUEST_CANCEL XenUsb_EvtRequestCancelPvUrb;
    7.19  
    7.20 -//static EVT_WDF_PROGRAM_DMA XenUsb_ExecuteRequestCallback;
    7.21 -
    7.22 -NTSTATUS
    7.23 -XenUsb_EvtDeviceQueryRemove(WDFDEVICE device)
    7.24 -{
    7.25 -  //PXENUSB_DEVICE_DATA xudd = GetXudd(device);
    7.26 -  NTSTATUS status = STATUS_SUCCESS;
    7.27 -
    7.28 -  UNREFERENCED_PARAMETER(device);
    7.29 -  
    7.30 -  FUNCTION_ENTER();
    7.31 -  FUNCTION_EXIT();
    7.32 -  return status;
    7.33 -}
    7.34 +static NTSTATUS XenUsb_Connect(PVOID context, BOOLEAN suspend);
    7.35 +static NTSTATUS XenUsb_Disconnect(PVOID context, BOOLEAN suspend);
    7.36  
    7.37  static NTSTATUS
    7.38  XenUsb_EvtDeviceWdmIrpPreprocessQUERY_INTERFACE(WDFDEVICE device, PIRP irp)
    7.39 @@ -61,13 +44,13 @@ XenUsb_EvtDeviceWdmIrpPreprocessQUERY_IN
    7.40    stack = IoGetCurrentIrpStackLocation(irp);
    7.41  
    7.42    if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_GUID, sizeof(GUID)) == 0)
    7.43 -    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_HUB_GUID\n"));
    7.44 +    FUNCTION_MSG("USB_BUS_INTERFACE_HUB_GUID\n");
    7.45    else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_USBDI_GUID, sizeof(GUID)) == 0)
    7.46 -    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_USBDI_GUID\n"));
    7.47 +    FUNCTION_MSG("USB_BUS_INTERFACE_USBDI_GUID\n");
    7.48    else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &GUID_TRANSLATOR_INTERFACE_STANDARD, sizeof(GUID)) == 0)
    7.49 -    KdPrint((__DRIVER_NAME "     GUID_TRANSLATOR_INTERFACE_STANDARD\n"));
    7.50 +    FUNCTION_MSG("GUID_TRANSLATOR_INTERFACE_STANDARD\n");
    7.51    else
    7.52 -    KdPrint((__DRIVER_NAME "     GUID = %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n",
    7.53 +    FUNCTION_MSG("GUID = %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n",
    7.54        stack->Parameters.QueryInterface.InterfaceType->Data1,
    7.55        stack->Parameters.QueryInterface.InterfaceType->Data2,
    7.56        stack->Parameters.QueryInterface.InterfaceType->Data3,
    7.57 @@ -78,11 +61,11 @@ XenUsb_EvtDeviceWdmIrpPreprocessQUERY_IN
    7.58        stack->Parameters.QueryInterface.InterfaceType->Data4[4],
    7.59        stack->Parameters.QueryInterface.InterfaceType->Data4[5],
    7.60        stack->Parameters.QueryInterface.InterfaceType->Data4[6],
    7.61 -      stack->Parameters.QueryInterface.InterfaceType->Data4[7]));
    7.62 +      stack->Parameters.QueryInterface.InterfaceType->Data4[7]);
    7.63  
    7.64 -  KdPrint((__DRIVER_NAME "     Size = %d\n", stack->Parameters.QueryInterface.Size));
    7.65 -  KdPrint((__DRIVER_NAME "     Version = %d\n", stack->Parameters.QueryInterface.Version));
    7.66 -  KdPrint((__DRIVER_NAME "     Interface = %p\n", stack->Parameters.QueryInterface.Interface));
    7.67 +  FUNCTION_MSG("Size = %d\n", stack->Parameters.QueryInterface.Size);
    7.68 +  FUNCTION_MSG("Version = %d\n", stack->Parameters.QueryInterface.Version);
    7.69 +  FUNCTION_MSG("Interface = %p\n", stack->Parameters.QueryInterface.Interface);
    7.70  
    7.71  
    7.72    IoSkipCurrentIrpStackLocation(irp);
    7.73 @@ -120,16 +103,14 @@ PutRequestsOnRing(PXENUSB_DEVICE_DATA xu
    7.74    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xudd->urb_ring, notify);
    7.75    if (notify) {
    7.76      FUNCTION_MSG("Notifying\n");
    7.77 -    xudd->vectors.EvtChn_Notify(xudd->vectors.context, xudd->event_channel);
    7.78 +    XnNotify(xudd->handle, xudd->event_channel);
    7.79    }
    7.80    
    7.81    FUNCTION_EXIT();
    7.82  }
    7.83  
    7.84 -/* called at DISPATCH_LEVEL */
    7.85  static BOOLEAN
    7.86 -XenUsb_HandleEvent(PVOID context)
    7.87 -{
    7.88 +XenUsb_HandleEventDpc(PKDPC dpc, PVOID context, PVOID arg1, PVOID arg2) {
    7.89    NTSTATUS status;
    7.90    PXENUSB_DEVICE_DATA xudd = context;
    7.91    RING_IDX prod, cons;
    7.92 @@ -141,6 +122,10 @@ XenUsb_HandleEvent(PVOID context)
    7.93    partial_pvurb_t *partial_pvurb;
    7.94    BOOLEAN port_changed = FALSE;
    7.95  
    7.96 +  UNREFERENCED_PARAMETER(dpc);
    7.97 +  UNREFERENCED_PARAMETER(arg1);
    7.98 +  UNREFERENCED_PARAMETER(arg2);
    7.99 +
   7.100    FUNCTION_ENTER();
   7.101  
   7.102    more_to_do = TRUE;
   7.103 @@ -170,16 +155,15 @@ XenUsb_HandleEvent(PVOID context)
   7.104          if (partial_pvurb->mdl) {
   7.105            int i;
   7.106            for (i = 0; i < partial_pvurb->req.nr_buffer_segs; i++) {
   7.107 -            xudd->vectors.GntTbl_EndAccess(xudd->vectors.context,
   7.108 -              partial_pvurb->req.seg[i].gref, FALSE, (ULONG)'XUSB');
   7.109 +            XnEndAccess(xudd->handle, partial_pvurb->req.seg[i].gref, FALSE, (ULONG)'XUSB');
   7.110            }
   7.111          }
   7.112  
   7.113 -        KdPrint((__DRIVER_NAME "     urb_ring rsp id = %d\n", partial_pvurb->rsp.id));
   7.114 -        KdPrint((__DRIVER_NAME "     urb_ring rsp start_frame = %d\n", partial_pvurb->rsp.start_frame));
   7.115 -        KdPrint((__DRIVER_NAME "     urb_ring rsp status = %d\n", partial_pvurb->rsp.status));
   7.116 -        KdPrint((__DRIVER_NAME "     urb_ring rsp actual_length = %d\n", partial_pvurb->rsp.actual_length));
   7.117 -        KdPrint((__DRIVER_NAME "     urb_ring rsp error_count = %d\n", partial_pvurb->rsp.error_count));
   7.118 +        FUNCTION_MSG("urb_ring rsp id = %d\n", partial_pvurb->rsp.id);
   7.119 +        FUNCTION_MSG("urb_ring rsp start_frame = %d\n", partial_pvurb->rsp.start_frame);
   7.120 +        FUNCTION_MSG("urb_ring rsp status = %d\n", partial_pvurb->rsp.status);
   7.121 +        FUNCTION_MSG("urb_ring rsp actual_length = %d\n", partial_pvurb->rsp.actual_length);
   7.122 +        FUNCTION_MSG("urb_ring rsp error_count = %d\n", partial_pvurb->rsp.error_count);
   7.123        }
   7.124        if (partial_pvurb->other_partial_pvurb) {
   7.125          if (!partial_pvurb->other_partial_pvurb->on_ring) {
   7.126 @@ -244,8 +228,8 @@ XenUsb_HandleEvent(PVOID context)
   7.127      {
   7.128        USHORT old_port_status;
   7.129        conn_rsp = RING_GET_RESPONSE(&xudd->conn_ring, cons);
   7.130 -      KdPrint((__DRIVER_NAME "     conn_rsp->portnum = %d\n", conn_rsp->portnum));
   7.131 -      KdPrint((__DRIVER_NAME "     conn_rsp->speed = %d\n", conn_rsp->speed));
   7.132 +      FUNCTION_MSG("conn_rsp->portnum = %d\n", conn_rsp->portnum);
   7.133 +      FUNCTION_MSG("conn_rsp->speed = %d\n", conn_rsp->speed);
   7.134        
   7.135        old_port_status = xudd->ports[conn_rsp->portnum - 1].port_status;
   7.136        xudd->ports[conn_rsp->portnum - 1].port_type = conn_rsp->speed;
   7.137 @@ -296,6 +280,19 @@ XenUsb_HandleEvent(PVOID context)
   7.138    return TRUE;
   7.139  }
   7.140  
   7.141 +static BOOLEAN
   7.142 +XenUsb_HandleEvent_DIRQL(PVOID context) {
   7.143 +  PXENUSB_DEVICE_DATA xudd = context;
   7.144 +  
   7.145 +  //FUNCTION_ENTER();
   7.146 +  if (xudd->device_state == DEVICE_STATE_ACTIVE || xudd->device_state == DEVICE_STATE_DISCONNECTING) {
   7.147 +    KeInsertQueueDpc(&xudd->event_dpc, NULL, NULL);
   7.148 +  }
   7.149 +  //FUNCTION_EXIT();
   7.150 +  return TRUE;
   7.151 +}
   7.152 +
   7.153 +#if 0
   7.154  static NTSTATUS
   7.155  XenUsb_StartXenbusInit(PXENUSB_DEVICE_DATA xudd)
   7.156  {
   7.157 @@ -310,82 +307,76 @@ XenUsb_StartXenbusInit(PXENUSB_DEVICE_DA
   7.158    while((type = GET_XEN_INIT_RSP(&ptr, (PVOID)&setting, (PVOID)&value, (PVOID)&value2)) != XEN_INIT_TYPE_END) {
   7.159      switch(type) {
   7.160      case XEN_INIT_TYPE_READ_STRING_BACK:
   7.161 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING_BACK - %s = %s\n", setting, value));
   7.162 +      FUNCTION_MSG("XEN_INIT_TYPE_READ_STRING_BACK - %s = %s\n", setting, value);
   7.163        break;
   7.164      case XEN_INIT_TYPE_READ_STRING_FRONT:
   7.165 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING_FRONT - %s = %s\n", setting, value));
   7.166 +      FUNCTION_MSG("XEN_INIT_TYPE_READ_STRING_FRONT - %s = %s\n", setting, value);
   7.167        break;
   7.168      case XEN_INIT_TYPE_VECTORS:
   7.169 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
   7.170 +      FUNCTION_MSG("XEN_INIT_TYPE_VECTORS\n");
   7.171        if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
   7.172          ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC) {
   7.173 -        KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
   7.174 -          ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
   7.175 -        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   7.176 +        FUNCTION_MSG("vectors mismatch (magic = %08x, length = %d)\n",
   7.177 +          ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length);
   7.178 +        FUNCTION_EXIT();
   7.179          return STATUS_BAD_INITIAL_PC;
   7.180        }
   7.181        else
   7.182          memcpy(&xudd->vectors, value, sizeof(XENPCI_VECTORS));
   7.183        break;
   7.184      case XEN_INIT_TYPE_STATE_PTR:
   7.185 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
   7.186 +      FUNCTION_MSG("XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value));
   7.187        xudd->device_state = (PXENPCI_DEVICE_STATE)value;
   7.188        break;
   7.189      default:
   7.190 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   7.191 +      FUNCTION_MSG("XEN_INIT_TYPE_%d\n", type);
   7.192        break;
   7.193      }
   7.194    }
   7.195 -
   7.196    return STATUS_SUCCESS;
   7.197  }
   7.198 +#endif
   7.199  
   7.200 +#if 0
   7.201  static NTSTATUS
   7.202 -XenUsb_CompleteXenbusInit(PXENUSB_DEVICE_DATA xudd)
   7.203 -{
   7.204 +XenUsb_CompleteXenbusInit(PXENUSB_DEVICE_DATA xudd) {
   7.205    PUCHAR ptr;
   7.206    USHORT type;
   7.207    PCHAR setting, value, value2;
   7.208    ULONG i;
   7.209  
   7.210    ptr = xudd->config_page;
   7.211 -  while((type = GET_XEN_INIT_RSP(&ptr, (PVOID)&setting, (PVOID)&value, (PVOID)&value2)) != XEN_INIT_TYPE_END)
   7.212 -  {
   7.213 -    switch(type)
   7.214 -    {
   7.215 +  while((type = GET_XEN_INIT_RSP(&ptr, (PVOID)&setting, (PVOID)&value, (PVOID)&value2)) != XEN_INIT_TYPE_END) {
   7.216 +    switch(type) {
   7.217      case XEN_INIT_TYPE_RING: /* frontend ring */
   7.218 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
   7.219 -      if (strcmp(setting, "urb-ring-ref") == 0)
   7.220 -      {
   7.221 +      FUNCTION_MSG("XEN_INIT_TYPE_RING - %s = %p\n", setting, value);
   7.222 +      if (strcmp(setting, "urb-ring-ref") == 0) {
   7.223          xudd->urb_sring = (usbif_urb_sring_t *)value;
   7.224          FRONT_RING_INIT(&xudd->urb_ring, xudd->urb_sring, PAGE_SIZE);
   7.225        }
   7.226 -      if (strcmp(setting, "conn-ring-ref") == 0)
   7.227 -      {
   7.228 +      if (strcmp(setting, "conn-ring-ref") == 0) {
   7.229          xudd->conn_sring = (usbif_conn_sring_t *)value;
   7.230          FRONT_RING_INIT(&xudd->conn_ring, xudd->conn_sring, PAGE_SIZE);
   7.231        }
   7.232        break;
   7.233      case XEN_INIT_TYPE_EVENT_CHANNEL_DPC: /* frontend event channel */
   7.234 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL_DPC - %s = %d\n", setting, PtrToUlong(value) & 0x3FFFFFFF));
   7.235 -      if (strcmp(setting, "event-channel") == 0)
   7.236 -      {
   7.237 +      FUNCTION_MSG("XEN_INIT_TYPE_EVENT_CHANNEL_DPC - %s = %d\n", setting, PtrToUlong(value) & 0x3FFFFFFF);
   7.238 +      if (strcmp(setting, "event-channel") == 0) {
   7.239          xudd->event_channel = PtrToUlong(value);
   7.240        }
   7.241        break;
   7.242      case XEN_INIT_TYPE_READ_STRING_BACK:
   7.243      case XEN_INIT_TYPE_READ_STRING_FRONT:
   7.244 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
   7.245 +      FUNCTION_MSG("XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value);
   7.246        break;
   7.247      default:
   7.248 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   7.249 +      FUNCTION_MSG("XEN_INIT_TYPE_%d\n", type);
   7.250        break;
   7.251      }
   7.252    }
   7.253 -  if (xudd->urb_sring == NULL || xudd->conn_sring == NULL || xudd->event_channel == 0)
   7.254 -  {
   7.255 -    KdPrint((__DRIVER_NAME "     Missing settings\n"));
   7.256 -    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   7.257 +  if (xudd->urb_sring == NULL || xudd->conn_sring == NULL || xudd->event_channel == 0) {
   7.258 +    FUNCTION_MSG("Missing settings\n");
   7.259 +    FUNCTION_EXIT();
   7.260      return STATUS_BAD_INITIAL_PC;
   7.261    }
   7.262    
   7.263 @@ -396,259 +387,245 @@ XenUsb_CompleteXenbusInit(PXENUSB_DEVICE
   7.264    
   7.265    return STATUS_SUCCESS;
   7.266  }
   7.267 +#endif
   7.268 +
   7.269 +VOID
   7.270 +XenUsb_DeviceCallback(PVOID context, ULONG callback_type, PVOID value) {
   7.271 +  PXENUSB_DEVICE_DATA xudd = (PXENUSB_DEVICE_DATA)context;
   7.272 +  ULONG state;
   7.273 +  
   7.274 +  FUNCTION_ENTER();
   7.275 +  switch (callback_type) {
   7.276 +  case XN_DEVICE_CALLBACK_BACKEND_STATE:
   7.277 +    state = (ULONG)(ULONG_PTR)value;
   7.278 +    if (state == xudd->backend_state) {
   7.279 +      FUNCTION_MSG("same state %d\n", state);
   7.280 +      FUNCTION_EXIT();
   7.281 +    }
   7.282 +    FUNCTION_MSG("XenBusState = %d -> %d\n", xudd->backend_state, state);
   7.283 +    xudd->backend_state = state;
   7.284 +    KeSetEvent(&xudd->backend_event, 0, FALSE);
   7.285 +    break;
   7.286 +  case XN_DEVICE_CALLBACK_SUSPEND:
   7.287 +    FUNCTION_MSG("XN_DEVICE_CALLBACK_SUSPEND");
   7.288 +    XenUsb_Disconnect(xudd, TRUE);
   7.289 +    break;
   7.290 +  case XN_DEVICE_CALLBACK_RESUME:
   7.291 +    FUNCTION_MSG("XN_DEVICE_CALLBACK_RESUME");
   7.292 +    xudd->device_state = DEVICE_STATE_INITIALISING;
   7.293 +    XenUsb_Connect(xudd, TRUE);
   7.294 +    // some sort of notify to kick things off?
   7.295 +    break;
   7.296 +  }
   7.297 +  FUNCTION_EXIT();
   7.298 +}
   7.299  
   7.300  NTSTATUS
   7.301 -XenUsb_EvtDevicePrepareHardware(WDFDEVICE device, WDFCMRESLIST resources_raw, WDFCMRESLIST resources_translated)
   7.302 -{
   7.303 +XenUsb_Connect(PVOID context, BOOLEAN suspend) {
   7.304 +  NTSTATUS status;
   7.305 +  PXENUSB_DEVICE_DATA xudd = context;
   7.306 +  PFN_NUMBER pfn;
   7.307 +  int i;
   7.308 +
   7.309 +  if (!suspend) {
   7.310 +    xudd->handle = XnOpenDevice(xudd->pdo, XenUsb_DeviceCallback, xudd);
   7.311 +  }
   7.312 +  if (!xudd->handle) {
   7.313 +    FUNCTION_MSG("Cannot open Xen device\n");
   7.314 +    return STATUS_UNSUCCESSFUL;
   7.315 +  }
   7.316 +
   7.317 +  if (xudd->device_state != DEVICE_STATE_INACTIVE) {
   7.318 +    for (i = 0; i <= 5 && xudd->backend_state != XenbusStateInitialising && xudd->backend_state != XenbusStateInitWait && xudd->backend_state != XenbusStateInitialised; i++) {
   7.319 +      FUNCTION_MSG("Waiting for XenbusStateInitXxx\n");
   7.320 +      if (xudd->backend_state == XenbusStateClosed) {
   7.321 +        status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "state", XenbusStateInitialising);
   7.322 +      }
   7.323 +      KeWaitForSingleObject(&xudd->backend_event, Executive, KernelMode, FALSE, NULL);
   7.324 +    }
   7.325 +    if (xudd->backend_state != XenbusStateInitialising && xudd->backend_state != XenbusStateInitWait && xudd->backend_state != XenbusStateInitialised) {
   7.326 +      FUNCTION_MSG("Backend state timeout\n");
   7.327 +      return STATUS_UNSUCCESSFUL;
   7.328 +    }
   7.329 +    if (!NT_SUCCESS(status = XnBindEvent(xudd->handle, &xudd->event_channel, XenUsb_HandleEvent_DIRQL, xudd))) {
   7.330 +      FUNCTION_MSG("Cannot allocate event channel\n");
   7.331 +      return STATUS_UNSUCCESSFUL;
   7.332 +    }
   7.333 +    FUNCTION_MSG("event_channel = %d\n", xudd->event_channel);
   7.334 +    status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "event-channel", xudd->event_channel);
   7.335 +    xudd->urb_sring = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENUSB_POOL_TAG);
   7.336 +    if (!xudd->urb_sring) {
   7.337 +      FUNCTION_MSG("Cannot allocate urb_sring\n");
   7.338 +      return STATUS_UNSUCCESSFUL;
   7.339 +    }
   7.340 +    SHARED_RING_INIT(xudd->urb_sring);
   7.341 +    FRONT_RING_INIT(&xudd->urb_ring, xudd->urb_sring, PAGE_SIZE);
   7.342 +    pfn = (PFN_NUMBER)(MmGetPhysicalAddress(xudd->urb_sring).QuadPart >> PAGE_SHIFT);
   7.343 +    FUNCTION_MSG("usb sring pfn = %d\n", (ULONG)pfn);
   7.344 +    xudd->urb_sring_gref = XnGrantAccess(xudd->handle, (ULONG)pfn, FALSE, INVALID_GRANT_REF, XENUSB_POOL_TAG);
   7.345 +    FUNCTION_MSG("usb sring_gref = %d\n", xudd->urb_sring_gref);
   7.346 +    status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "urb-ring-ref", xudd->urb_sring_gref);  
   7.347 +    xudd->conn_sring = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENUSB_POOL_TAG);
   7.348 +    if (!xudd->conn_sring) {
   7.349 +      FUNCTION_MSG("Cannot allocate conn_sring\n");
   7.350 +      return STATUS_UNSUCCESSFUL;
   7.351 +    }
   7.352 +    SHARED_RING_INIT(xudd->conn_sring);
   7.353 +    FRONT_RING_INIT(&xudd->conn_ring, xudd->conn_sring, PAGE_SIZE);
   7.354 +    pfn = (PFN_NUMBER)(MmGetPhysicalAddress(xudd->conn_sring).QuadPart >> PAGE_SHIFT);
   7.355 +    FUNCTION_MSG("conn sring pfn = %d\n", (ULONG)pfn);
   7.356 +    xudd->conn_sring_gref = XnGrantAccess(xudd->handle, (ULONG)pfn, FALSE, INVALID_GRANT_REF, XENUSB_POOL_TAG);
   7.357 +    FUNCTION_MSG("conn sring_gref = %d\n", xudd->conn_sring_gref);
   7.358 +    status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "conn-ring-ref", xudd->conn_sring_gref);  
   7.359 +
   7.360 +    /* fill conn ring with requests */
   7.361 +    for (i = 0; i < USB_CONN_RING_SIZE; i++) {
   7.362 +      usbif_conn_request_t *req = RING_GET_REQUEST(&xudd->conn_ring, i);
   7.363 +      req->id = (uint16_t)i;
   7.364 +    }
   7.365 +    xudd->conn_ring.req_prod_pvt = i;
   7.366 +
   7.367 +    status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "state", XenbusStateConnected);
   7.368 +    for (i = 0; i <= 5 && xudd->backend_state != XenbusStateConnected; i++) {
   7.369 +      FUNCTION_MSG("Waiting for XenbusStateConnected\n");
   7.370 +      KeWaitForSingleObject(&xudd->backend_event, Executive, KernelMode, FALSE, NULL);
   7.371 +    }
   7.372 +    if (xudd->backend_state != XenbusStateConnected) {
   7.373 +      FUNCTION_MSG("Backend state timeout\n");
   7.374 +      return STATUS_UNSUCCESSFUL;
   7.375 +    }
   7.376 +    xudd->device_state = DEVICE_STATE_ACTIVE;
   7.377 +  }
   7.378 +
   7.379 +  return STATUS_SUCCESS;
   7.380 +}
   7.381 +
   7.382 +NTSTATUS
   7.383 +XenUsb_Disconnect(PVOID context, BOOLEAN suspend) {
   7.384 +  PXENUSB_DEVICE_DATA xudd = (PXENUSB_DEVICE_DATA)context;
   7.385 +  //PFN_NUMBER pfn;
   7.386 +  NTSTATUS status;
   7.387 +
   7.388 +  if (xudd->device_state != DEVICE_STATE_ACTIVE && xudd->device_state != DEVICE_STATE_INACTIVE) {
   7.389 +    FUNCTION_MSG("state not DEVICE_STATE_(IN)ACTIVE, is %d instead\n", xudd->device_state);
   7.390 +    FUNCTION_EXIT();
   7.391 +    return STATUS_SUCCESS;
   7.392 +  }
   7.393 +  if (xudd->device_state != DEVICE_STATE_INACTIVE) {
   7.394 +    xudd->device_state = DEVICE_STATE_DISCONNECTING;
   7.395 +    status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "state", XenbusStateClosing);
   7.396 +    while (xudd->backend_state != XenbusStateClosing && xudd->backend_state != XenbusStateClosed) {
   7.397 +      FUNCTION_MSG("Waiting for XenbusStateClosing/Closed\n");
   7.398 +      KeWaitForSingleObject(&xudd->backend_event, Executive, KernelMode, FALSE, NULL);
   7.399 +    }
   7.400 +    status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "state", XenbusStateClosed);
   7.401 +    while (xudd->backend_state != XenbusStateClosed) {
   7.402 +      FUNCTION_MSG("Waiting for XenbusStateClosed\n");
   7.403 +      KeWaitForSingleObject(&xudd->backend_event, Executive, KernelMode, FALSE, NULL);
   7.404 +    }
   7.405 +    XnUnbindEvent(xudd->handle, xudd->event_channel);
   7.406 +    
   7.407 +  #if NTDDI_VERSION < WINXP
   7.408 +    KeFlushQueuedDpcs();
   7.409 +  #endif
   7.410 +    XnEndAccess(xudd->handle, xudd->conn_sring_gref, FALSE, XENUSB_POOL_TAG);
   7.411 +    ExFreePoolWithTag(xudd->conn_sring, XENUSB_POOL_TAG);
   7.412 +    XnEndAccess(xudd->handle, xudd->urb_sring_gref, FALSE, XENUSB_POOL_TAG);
   7.413 +    ExFreePoolWithTag(xudd->urb_sring, XENUSB_POOL_TAG);
   7.414 +  }
   7.415 +  if (!suspend) {
   7.416 +    XnCloseDevice(xudd->handle);
   7.417 +  }
   7.418 +  xudd->device_state = DEVICE_STATE_DISCONNECTED;
   7.419 +  return STATUS_SUCCESS;
   7.420 +}
   7.421 +
   7.422 +NTSTATUS
   7.423 +XenUsb_EvtDeviceD0Entry(WDFDEVICE device, WDF_POWER_DEVICE_STATE previous_state) {
   7.424    NTSTATUS status = STATUS_SUCCESS;
   7.425    PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   7.426 -  PCM_PARTIAL_RESOURCE_DESCRIPTOR raw_descriptor, translated_descriptor;
   7.427 -  ULONG i;
   7.428 -  PUCHAR ptr;
   7.429 +
   7.430 +  UNREFERENCED_PARAMETER(device);
   7.431  
   7.432    FUNCTION_ENTER();
   7.433 -  
   7.434 -  ASSERT(WdfCmResourceListGetCount(resources_raw) == WdfCmResourceListGetCount(resources_translated));
   7.435 -  
   7.436 -  for (i = 0; i < WdfCmResourceListGetCount(resources_raw); i++)
   7.437 -  {
   7.438 -    raw_descriptor = WdfCmResourceListGetDescriptor(resources_raw, i);
   7.439 -    translated_descriptor = WdfCmResourceListGetDescriptor(resources_translated, i);
   7.440 -    switch (raw_descriptor->Type) {
   7.441 -    case CmResourceTypePort:
   7.442 -      KdPrint((__DRIVER_NAME "     IoPort Address(%x) Length: %d\n", translated_descriptor->u.Port.Start.LowPart, translated_descriptor->u.Port.Length));
   7.443 -      break;
   7.444 -    case CmResourceTypeMemory:
   7.445 -      KdPrint((__DRIVER_NAME "     Memory (%x:%x) Length:(%d)\n", translated_descriptor->u.Memory.Start.LowPart, translated_descriptor->u.Memory.Start.HighPart, translated_descriptor->u.Memory.Length));
   7.446 -      KdPrint((__DRIVER_NAME "     Memory flags = %04X\n", translated_descriptor->Flags));
   7.447 -      xudd->config_page = MmMapIoSpace(translated_descriptor->u.Memory.Start, translated_descriptor->u.Memory.Length, MmNonCached);
   7.448 -      KdPrint((__DRIVER_NAME "     Memory mapped to %p\n", xudd->config_page));
   7.449 -      break;
   7.450 -    case CmResourceTypeInterrupt:
   7.451 -      KdPrint((__DRIVER_NAME "     irq_number = %03x\n", raw_descriptor->u.Interrupt.Vector));
   7.452 -      KdPrint((__DRIVER_NAME "     irq_vector = %03x\n", translated_descriptor->u.Interrupt.Vector));
   7.453 -      KdPrint((__DRIVER_NAME "     irq_level = %03x\n", translated_descriptor->u.Interrupt.Level));
   7.454 -      break;
   7.455 -    case CmResourceTypeDevicePrivate:
   7.456 -      KdPrint((__DRIVER_NAME "     Private Data: 0x%02x 0x%02x 0x%02x\n", translated_descriptor->u.DevicePrivate.Data[0], translated_descriptor->u.DevicePrivate.Data[1], translated_descriptor->u.DevicePrivate.Data[2]));
   7.457 -      break;
   7.458 -    default:
   7.459 -      KdPrint((__DRIVER_NAME "     Unhandled resource type (0x%x)\n", translated_descriptor->Type));
   7.460 -      break;
   7.461 -    }
   7.462 -  }
   7.463  
   7.464 -  status = XenUsb_StartXenbusInit(xudd);
   7.465 +  switch (previous_state) {
   7.466 +  case WdfPowerDeviceD0:
   7.467 +    FUNCTION_MSG("WdfPowerDeviceD1\n");
   7.468 +    break;
   7.469 +  case WdfPowerDeviceD1:
   7.470 +    FUNCTION_MSG("WdfPowerDeviceD1\n");
   7.471 +    break;
   7.472 +  case WdfPowerDeviceD2:
   7.473 +    FUNCTION_MSG("WdfPowerDeviceD2\n");
   7.474 +    break;
   7.475 +  case WdfPowerDeviceD3:
   7.476 +    FUNCTION_MSG("WdfPowerDeviceD3\n");
   7.477 +    break;
   7.478 +  case WdfPowerDeviceD3Final:
   7.479 +    FUNCTION_MSG("WdfPowerDeviceD3Final\n");
   7.480 +    break;
   7.481 +  case WdfPowerDevicePrepareForHibernation:
   7.482 +    FUNCTION_MSG("WdfPowerDevicePrepareForHibernation\n");
   7.483 +    break;  
   7.484 +  default:
   7.485 +    FUNCTION_MSG("Unknown WdfPowerDevice state %d\n", previous_state);
   7.486 +    break;  
   7.487 +  }
   7.488 +  
   7.489 +  XenUsb_Connect(xudd, FALSE);
   7.490  
   7.491 -  ptr = xudd->config_page;
   7.492 -  //ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RUN, NULL, NULL, NULL);
   7.493 -  //ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RUN, NULL, NULL, NULL);
   7.494 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "urb-ring-ref", NULL, NULL);
   7.495 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "conn-ring-ref", NULL, NULL);
   7.496 -  #pragma warning(suppress:4054)
   7.497 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_DPC, "event-channel", (PVOID)XenUsb_HandleEvent, xudd);
   7.498 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_XB_STATE_MAP_PRE_CONNECT, NULL, NULL, NULL);
   7.499 -  __ADD_XEN_INIT_UCHAR(&ptr, 0); /* no pre-connect required */
   7.500 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_XB_STATE_MAP_POST_CONNECT, NULL, NULL, NULL);
   7.501 -  __ADD_XEN_INIT_UCHAR(&ptr, XenbusStateConnected);
   7.502 -  __ADD_XEN_INIT_UCHAR(&ptr, XenbusStateConnected);
   7.503 -  __ADD_XEN_INIT_UCHAR(&ptr, 20);
   7.504 -  __ADD_XEN_INIT_UCHAR(&ptr, 0);
   7.505 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_XB_STATE_MAP_SHUTDOWN, NULL, NULL, NULL);
   7.506 -  __ADD_XEN_INIT_UCHAR(&ptr, XenbusStateClosing);
   7.507 -  __ADD_XEN_INIT_UCHAR(&ptr, XenbusStateClosing);
   7.508 -  __ADD_XEN_INIT_UCHAR(&ptr, 50);
   7.509 -  __ADD_XEN_INIT_UCHAR(&ptr, XenbusStateClosed);
   7.510 -  __ADD_XEN_INIT_UCHAR(&ptr, XenbusStateClosed);
   7.511 -  __ADD_XEN_INIT_UCHAR(&ptr, 50);
   7.512 -  __ADD_XEN_INIT_UCHAR(&ptr, XenbusStateInitialising);
   7.513 -  __ADD_XEN_INIT_UCHAR(&ptr, XenbusStateInitWait);
   7.514 -  __ADD_XEN_INIT_UCHAR(&ptr, 50);
   7.515 -  __ADD_XEN_INIT_UCHAR(&ptr, 0);
   7.516 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL, NULL);
   7.517 -  status = xudd->vectors.XenPci_XenConfigDevice(xudd->vectors.context);
   7.518 -
   7.519 -  status = XenUsb_CompleteXenbusInit(xudd);
   7.520 -  
   7.521    FUNCTION_EXIT();
   7.522  
   7.523    return status;
   7.524  }
   7.525  
   7.526  NTSTATUS
   7.527 -XenUsb_EvtDeviceD0Entry(WDFDEVICE device, WDF_POWER_DEVICE_STATE previous_state)
   7.528 -{
   7.529 +XenUsb_EvtDeviceD0Exit(WDFDEVICE device, WDF_POWER_DEVICE_STATE target_state) {
   7.530    NTSTATUS status = STATUS_SUCCESS;
   7.531    PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   7.532 -  ULONG i;
   7.533 -  int notify;
   7.534 -  //PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   7.535 +  
   7.536 +  FUNCTION_ENTER();
   7.537  
   7.538    UNREFERENCED_PARAMETER(device);
   7.539  
   7.540 -  FUNCTION_ENTER();
   7.541 -
   7.542 -  switch (previous_state)
   7.543 -  {
   7.544 +  switch (target_state) {
   7.545    case WdfPowerDeviceD0:
   7.546 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   7.547 +    FUNCTION_MSG("WdfPowerDeviceD1\n");
   7.548      break;
   7.549    case WdfPowerDeviceD1:
   7.550 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   7.551 +    FUNCTION_MSG("WdfPowerDeviceD1\n");
   7.552      break;
   7.553    case WdfPowerDeviceD2:
   7.554 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
   7.555 +    FUNCTION_MSG("WdfPowerDeviceD2\n");
   7.556      break;
   7.557    case WdfPowerDeviceD3:
   7.558 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
   7.559 +    FUNCTION_MSG("WdfPowerDeviceD3\n");
   7.560      break;
   7.561    case WdfPowerDeviceD3Final:
   7.562 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
   7.563 +    FUNCTION_MSG("WdfPowerDeviceD3Final\n");
   7.564      break;
   7.565    case WdfPowerDevicePrepareForHibernation:
   7.566 -    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
   7.567 +    FUNCTION_MSG("WdfPowerDevicePrepareForHibernation\n");
   7.568      break;  
   7.569    default:
   7.570 -    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", previous_state));
   7.571 +    FUNCTION_MSG("Unknown WdfPowerDevice state %d\n", target_state);
   7.572      break;  
   7.573    }
   7.574  
   7.575 -  /* fill conn ring with requests */
   7.576 -  for (i = 0; i < USB_CONN_RING_SIZE; i++)
   7.577 -  {
   7.578 -    usbif_conn_request_t *req = RING_GET_REQUEST(&xudd->conn_ring, i);
   7.579 -    req->id = (uint16_t)i;
   7.580 -  }
   7.581 -  xudd->conn_ring.req_prod_pvt = i;
   7.582 -
   7.583 -  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xudd->urb_ring, notify);
   7.584 -  if (notify)
   7.585 -  {
   7.586 -    xudd->vectors.EvtChn_Notify(xudd->vectors.context, xudd->event_channel);
   7.587 -  }
   7.588 -  
   7.589 -  FUNCTION_EXIT();
   7.590 -
   7.591 -  return status;
   7.592 -}
   7.593 -
   7.594 -NTSTATUS
   7.595 -XenUsb_EvtDeviceD0EntryPostInterruptsEnabled(WDFDEVICE device, WDF_POWER_DEVICE_STATE previous_state)
   7.596 -{
   7.597 -  NTSTATUS status = STATUS_SUCCESS;
   7.598 -  //PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   7.599 -
   7.600 -  UNREFERENCED_PARAMETER(device);
   7.601 -  UNREFERENCED_PARAMETER(previous_state);
   7.602 -
   7.603 -  FUNCTION_ENTER();
   7.604 +  XenUsb_Disconnect(xudd, FALSE);
   7.605    
   7.606    FUNCTION_EXIT();
   7.607    
   7.608    return status;
   7.609  }
   7.610  
   7.611 -NTSTATUS
   7.612 -XenUsb_EvtDeviceD0ExitPreInterruptsDisabled(WDFDEVICE device, WDF_POWER_DEVICE_STATE target_state)
   7.613 -{
   7.614 -  NTSTATUS status = STATUS_SUCCESS;
   7.615 -  
   7.616 -  UNREFERENCED_PARAMETER(device);
   7.617 -  
   7.618 -  FUNCTION_ENTER();
   7.619 -  
   7.620 -  switch (target_state)
   7.621 -  {
   7.622 -  case WdfPowerDeviceD0:
   7.623 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   7.624 -    break;
   7.625 -  case WdfPowerDeviceD1:
   7.626 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   7.627 -    break;
   7.628 -  case WdfPowerDeviceD2:
   7.629 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
   7.630 -    break;
   7.631 -  case WdfPowerDeviceD3:
   7.632 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
   7.633 -    break;
   7.634 -  case WdfPowerDeviceD3Final:
   7.635 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
   7.636 -    break;
   7.637 -  case WdfPowerDevicePrepareForHibernation:
   7.638 -    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
   7.639 -    break;
   7.640 -  default:
   7.641 -    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", target_state));
   7.642 -    break;  
   7.643 -  }
   7.644 -  
   7.645 -  FUNCTION_EXIT();
   7.646 -  
   7.647 -  return status;
   7.648 -}
   7.649 -
   7.650 -NTSTATUS
   7.651 -XenUsb_EvtDeviceD0Exit(WDFDEVICE device, WDF_POWER_DEVICE_STATE target_state)
   7.652 -{
   7.653 -  NTSTATUS status = STATUS_SUCCESS;
   7.654 -  //PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   7.655 -  
   7.656 -  FUNCTION_ENTER();
   7.657 -
   7.658 -  UNREFERENCED_PARAMETER(device);
   7.659 -
   7.660 -  switch (target_state)
   7.661 -  {
   7.662 -  case WdfPowerDeviceD0:
   7.663 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   7.664 -    break;
   7.665 -  case WdfPowerDeviceD1:
   7.666 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   7.667 -    break;
   7.668 -  case WdfPowerDeviceD2:
   7.669 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
   7.670 -    break;
   7.671 -  case WdfPowerDeviceD3:
   7.672 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
   7.673 -    break;
   7.674 -  case WdfPowerDeviceD3Final:
   7.675 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
   7.676 -    break;
   7.677 -  case WdfPowerDevicePrepareForHibernation:
   7.678 -    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
   7.679 -    break;  
   7.680 -  default:
   7.681 -    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", target_state));
   7.682 -    break;  
   7.683 -  }
   7.684 -  
   7.685 -  FUNCTION_EXIT();
   7.686 -  
   7.687 -  return status;
   7.688 -}
   7.689 -
   7.690 -NTSTATUS
   7.691 -XenUsb_EvtDeviceReleaseHardware(WDFDEVICE device, WDFCMRESLIST resources_translated)
   7.692 -{
   7.693 -  NTSTATUS status = STATUS_SUCCESS;
   7.694 -  
   7.695 -  UNREFERENCED_PARAMETER(device);
   7.696 -  UNREFERENCED_PARAMETER(resources_translated);
   7.697 -  
   7.698 -  FUNCTION_ENTER();
   7.699 -  FUNCTION_EXIT();
   7.700 -  
   7.701 -  return status;
   7.702 -}
   7.703 -
   7.704  VOID
   7.705 -XenUsb_EvtChildListScanForChildren(WDFCHILDLIST child_list)
   7.706 -{
   7.707 +XenUsb_EvtChildListScanForChildren(WDFCHILDLIST child_list) {
   7.708    NTSTATUS status;
   7.709    PXENUSB_DEVICE_DATA xudd = GetXudd(WdfChildListGetDevice(child_list));
   7.710    XENUSB_PDO_IDENTIFICATION_DESCRIPTION child_description;
   7.711    CHAR path[128];
   7.712 -  PCHAR err;
   7.713    PCHAR value;
   7.714    ULONG i;
   7.715  
   7.716 @@ -658,21 +635,18 @@ XenUsb_EvtChildListScanForChildren(WDFCH
   7.717  
   7.718    // hold the queue on each device and set each device to a pending state
   7.719    // read backend/num_ports
   7.720 -  RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/num-ports", xudd->vectors.backend_path);
   7.721 -  err = xudd->vectors.XenBus_Read(xudd->vectors.context, XBT_NIL, path, &value);
   7.722 -  if (err)
   7.723 -  {
   7.724 -    XenPci_FreeMem(err);
   7.725 +  //RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/num-ports", xudd->vectors.backend_path);
   7.726 +  status = XnReadString(xudd->handle, XBT_NIL, path, &value);
   7.727 +  if (status != STATUS_SUCCESS) {
   7.728      WdfChildListEndScan(child_list);
   7.729 -    KdPrint((__DRIVER_NAME "     Failed to read num-ports\n"));
   7.730 +    FUNCTION_MSG("Failed to read num-ports\n");
   7.731      return;
   7.732    }
   7.733    xudd->num_ports = (ULONG)parse_numeric_string(value);  
   7.734 -  XenPci_FreeMem(value);
   7.735 -  KdPrint((__DRIVER_NAME "     num-ports = %d\n", xudd->num_ports));
   7.736 +  XnFreeMem(xudd->handle, value);
   7.737 +  FUNCTION_MSG("num-ports = %d\n", xudd->num_ports);
   7.738  
   7.739 -  for (i = 0; i < 8; i++)
   7.740 -  {
   7.741 +  for (i = 0; i < 8; i++) {
   7.742      xudd->ports[i].port_number = i + 1;
   7.743      xudd->ports[i].port_type = USB_PORT_TYPE_NOT_CONNECTED;
   7.744      xudd->ports[i].port_status = 0; //1 << PORT_ENABLE;
   7.745 @@ -685,9 +659,8 @@ XenUsb_EvtChildListScanForChildren(WDFCH
   7.746    child_description.device_number = 0; //TODO: get the proper index from parent
   7.747  
   7.748    status = WdfChildListAddOrUpdateChildDescriptionAsPresent(child_list, &child_description.header, NULL);
   7.749 -  if (!NT_SUCCESS(status))
   7.750 -  {
   7.751 -    KdPrint((__DRIVER_NAME "     WdfChildListAddOrUpdateChildDescriptionAsPresent failed with status 0x%08x\n", status));
   7.752 +  if (!NT_SUCCESS(status)) {
   7.753 +    FUNCTION_MSG("WdfChildListAddOrUpdateChildDescriptionAsPresent failed with status 0x%08x\n", status);
   7.754    }
   7.755  
   7.756    WdfChildListEndScan(child_list);
   7.757 @@ -719,34 +692,34 @@ XenUsb_EvtIoDeviceControl(
   7.758    switch(io_control_code)
   7.759    {
   7.760    case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION:
   7.761 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_INFORMATION\n"));
   7.762 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_INFORMATION\n");
   7.763      break;
   7.764    case IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION:
   7.765 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION\n"));
   7.766 +    FUNCTION_MSG("IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION\n");
   7.767      break;
   7.768    case IOCTL_USB_GET_NODE_CONNECTION_NAME:
   7.769 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_NAME\n"));
   7.770 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_NAME\n");
   7.771      break;
   7.772    case IOCTL_USB_DIAG_IGNORE_HUBS_ON:
   7.773 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_DIAG_IGNORE_HUBS_ON\n"));
   7.774 +    FUNCTION_MSG("IOCTL_USB_DIAG_IGNORE_HUBS_ON\n");
   7.775      break;
   7.776    case IOCTL_USB_DIAG_IGNORE_HUBS_OFF:
   7.777 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_DIAG_IGNORE_HUBS_OFF\n"));
   7.778 +    FUNCTION_MSG("IOCTL_USB_DIAG_IGNORE_HUBS_OFF\n");
   7.779      break;
   7.780    case IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME:
   7.781 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME\n"));
   7.782 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME\n");
   7.783      break;
   7.784    case IOCTL_USB_GET_HUB_CAPABILITIES:
   7.785 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_HUB_CAPABILITIES\n"));
   7.786 +    FUNCTION_MSG("IOCTL_USB_GET_HUB_CAPABILITIES\n");
   7.787      break;
   7.788    case IOCTL_USB_HUB_CYCLE_PORT:
   7.789 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_HUB_CYCLE_PORT\n"));
   7.790 +    FUNCTION_MSG("IOCTL_USB_HUB_CYCLE_PORT\n");
   7.791      break;
   7.792    case IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES:
   7.793 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES\n"));
   7.794 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES\n");
   7.795      break;
   7.796    case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX:
   7.797 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX\n"));
   7.798 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX\n");
   7.799      break;
   7.800    case IOCTL_USB_GET_ROOT_HUB_NAME:
   7.801    {
   7.802 @@ -754,8 +727,8 @@ XenUsb_EvtIoDeviceControl(
   7.803      size_t length;
   7.804      ULONG required_length = sizeof(USB_HCD_DRIVERKEY_NAME);
   7.805      
   7.806 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_ROOT_HUB_NAME\n"));
   7.807 -    KdPrint((__DRIVER_NAME "      output_buffer_length = %d\n", output_buffer_length));
   7.808 +    FUNCTION_MSG("IOCTL_USB_GET_ROOT_HUB_NAME\n");
   7.809 +    FUNCTION_MSG(" output_buffer_length = %d\n", output_buffer_length);
   7.810        
   7.811      if (output_buffer_length < sizeof(USB_HCD_DRIVERKEY_NAME)) {
   7.812        status = STATUS_BUFFER_TOO_SMALL;
   7.813 @@ -789,21 +762,17 @@ XenUsb_EvtIoDeviceControl(
   7.814                WdfRequestSetInformation(request, output_buffer_length);
   7.815              }
   7.816            } else {
   7.817 -            KdPrint((__DRIVER_NAME "     WdfStringCreate = %08x\n", status));
   7.818 +            FUNCTION_MSG("WdfStringCreate = %08x\n", status);
   7.819            }
   7.820 -        }
   7.821 -        else
   7.822 -        {
   7.823 -          KdPrint((__DRIVER_NAME "     WdfDeviceRetrieveDeviceInterfaceString = %08x\n", status));
   7.824 +        } else {
   7.825 +          FUNCTION_MSG("WdfDeviceRetrieveDeviceInterfaceString = %08x\n", status);
   7.826            status = STATUS_INVALID_PARAMETER;
   7.827          }
   7.828 +      } else {
   7.829 +        FUNCTION_MSG("WdfRequestRetrieveOutputBuffer = %08x\n", status);
   7.830        }
   7.831 -      else
   7.832 -      {
   7.833 -        KdPrint((__DRIVER_NAME "     WdfRequestRetrieveOutputBuffer = %08x\n", status));
   7.834 -      }
   7.835 -      KdPrint((__DRIVER_NAME "      uhdn->ActualLength = %d\n", uhdn->ActualLength));
   7.836 -      KdPrint((__DRIVER_NAME "      uhdn->DriverKeyName = %S\n", uhdn->DriverKeyName));
   7.837 +      FUNCTION_MSG(" uhdn->ActualLength = %d\n", uhdn->ActualLength);
   7.838 +      FUNCTION_MSG(" uhdn->DriverKeyName = %S\n", uhdn->DriverKeyName);
   7.839      }
   7.840      break;
   7.841    }
   7.842 @@ -814,8 +783,8 @@ XenUsb_EvtIoDeviceControl(
   7.843      ULONG required_length = sizeof(USB_HCD_DRIVERKEY_NAME);
   7.844      ULONG key_length;
   7.845      
   7.846 -    KdPrint((__DRIVER_NAME "     IOCTL_GET_HCD_DRIVERKEY_NAME\n"));
   7.847 -    KdPrint((__DRIVER_NAME "      output_buffer_length = %d\n", output_buffer_length));
   7.848 +    FUNCTION_MSG("IOCTL_GET_HCD_DRIVERKEY_NAME\n");
   7.849 +    FUNCTION_MSG(" output_buffer_length = %d\n", output_buffer_length);
   7.850        
   7.851      if (output_buffer_length < sizeof(USB_HCD_DRIVERKEY_NAME)) {
   7.852        FUNCTION_MSG("Buffer too small (%d < %d)\n", output_buffer_length, sizeof(USB_HCD_DRIVERKEY_NAME));
   7.853 @@ -824,15 +793,15 @@ XenUsb_EvtIoDeviceControl(
   7.854      }
   7.855      status = WdfRequestRetrieveOutputBuffer(request, output_buffer_length, (PVOID *)&uhdn, &length);
   7.856      if (!NT_SUCCESS(status)) {
   7.857 -      KdPrint((__DRIVER_NAME "     WdfRequestRetrieveOutputBuffer = %08x\n", status));
   7.858 +      FUNCTION_MSG("WdfRequestRetrieveOutputBuffer = %08x\n", status);
   7.859        break;
   7.860      }
   7.861      status = WdfDeviceQueryProperty(device, DevicePropertyDriverKeyName, 0, NULL, &key_length);
   7.862      if (!NT_SUCCESS(status)) {
   7.863 -      KdPrint((__DRIVER_NAME "     WdfDeviceQueryProperty = %08x\n", status));
   7.864 +      FUNCTION_MSG("WdfDeviceQueryProperty = %08x\n", status);
   7.865        break;
   7.866      }    
   7.867 -    KdPrint((__DRIVER_NAME "      key_length = %d\n", key_length));
   7.868 +    FUNCTION_MSG(" key_length = %d\n", key_length);
   7.869      required_length = FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + key_length + 2;
   7.870      uhdn->ActualLength = required_length;
   7.871      FUNCTION_MSG("output_buffer_length = %d\n", output_buffer_length);
   7.872 @@ -856,14 +825,14 @@ XenUsb_EvtIoDeviceControl(
   7.873    }
   7.874  #if 0
   7.875    case IOCTL_USB_RESET_HUB:
   7.876 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_RESET_HUB\n"));
   7.877 +    FUNCTION_MSG("IOCTL_USB_RESET_HUB\n");
   7.878      break;
   7.879  #endif
   7.880    default:
   7.881 -    KdPrint((__DRIVER_NAME "     Unknown IOCTL %08x\n", io_control_code));
   7.882 +    FUNCTION_MSG("Unknown IOCTL %08x\n", io_control_code);
   7.883      break;
   7.884    }
   7.885 -  KdPrint((__DRIVER_NAME "     Calling WdfRequestComplete with status = %08x\n", status));
   7.886 +  FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n", status);
   7.887    WdfRequestComplete(request, status);
   7.888  
   7.889    FUNCTION_EXIT();
   7.890 @@ -993,19 +962,18 @@ XenUsb_EvtIoInternalDeviceControl_PVURB(
   7.891      partial_pvurb->req.buffer_length = (USHORT)MmGetMdlByteCount(partial_pvurb->mdl);
   7.892      partial_pvurb->req.nr_buffer_segs = (USHORT)ADDRESS_AND_SIZE_TO_SPAN_PAGES(MmGetMdlVirtualAddress(partial_pvurb->mdl), MmGetMdlByteCount(partial_pvurb->mdl));
   7.893      for (i = 0; i < partial_pvurb->req.nr_buffer_segs; i++) {
   7.894 -      partial_pvurb->req.seg[i].gref = xudd->vectors.GntTbl_GrantAccess(xudd->vectors.context,
   7.895 -           (ULONG)MmGetMdlPfnArray(partial_pvurb->mdl)[i], FALSE, INVALID_GRANT_REF, (ULONG)'XUSB');
   7.896 +      partial_pvurb->req.seg[i].gref = XnGrantAccess(xudd->handle, (ULONG)MmGetMdlPfnArray(partial_pvurb->mdl)[i], FALSE, INVALID_GRANT_REF, (ULONG)'XUSB');
   7.897        partial_pvurb->req.seg[i].offset = (USHORT)offset;
   7.898        partial_pvurb->req.seg[i].length = (USHORT)min((USHORT)remaining, (USHORT)PAGE_SIZE - offset);
   7.899        offset = 0;
   7.900        remaining -= partial_pvurb->req.seg[i].length;
   7.901 -      KdPrint((__DRIVER_NAME "     seg = %d\n", i));
   7.902 -      KdPrint((__DRIVER_NAME "      gref = %d\n", partial_pvurb->req.seg[i].gref));
   7.903 -      KdPrint((__DRIVER_NAME "      offset = %d\n", partial_pvurb->req.seg[i].offset));
   7.904 -      KdPrint((__DRIVER_NAME "      length = %d\n", partial_pvurb->req.seg[i].length));
   7.905 +      FUNCTION_MSG("seg = %d\n", i);
   7.906 +      FUNCTION_MSG(" gref = %d\n", partial_pvurb->req.seg[i].gref);
   7.907 +      FUNCTION_MSG(" offset = %d\n", partial_pvurb->req.seg[i].offset);
   7.908 +      FUNCTION_MSG(" length = %d\n", partial_pvurb->req.seg[i].length);
   7.909      }
   7.910 -    KdPrint((__DRIVER_NAME "     buffer_length = %d\n", partial_pvurb->req.buffer_length));
   7.911 -    KdPrint((__DRIVER_NAME "     nr_buffer_segs = %d\n", partial_pvurb->req.nr_buffer_segs));
   7.912 +    FUNCTION_MSG("buffer_length = %d\n", partial_pvurb->req.buffer_length);
   7.913 +    FUNCTION_MSG("nr_buffer_segs = %d\n", partial_pvurb->req.nr_buffer_segs);
   7.914    }
   7.915    InsertTailList(&xudd->partial_pvurb_queue, &partial_pvurb->entry);
   7.916    PutRequestsOnRing(xudd);
   7.917 @@ -1044,7 +1012,7 @@ XenUsb_EvtIoInternalDeviceControl(
   7.918      WdfRequestForwardToIoQueue(request, xudd->pvurb_queue);
   7.919      break;
   7.920    default:
   7.921 -    KdPrint((__DRIVER_NAME "     Unknown IOCTL %08x\n", io_control_code));
   7.922 +    FUNCTION_MSG("Unknown IOCTL %08x\n", io_control_code);
   7.923      WdfRequestComplete(request, WdfRequestGetStatus(request));
   7.924      break;
   7.925    }
   7.926 @@ -1071,25 +1039,25 @@ XenUsb_EvtIoDefault(
   7.927    switch (parameters.Type)
   7.928    {
   7.929    case WdfRequestTypeCreate:
   7.930 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeCreate\n"));
   7.931 +    FUNCTION_MSG("WdfRequestTypeCreate\n");
   7.932      break;
   7.933    case WdfRequestTypeClose:
   7.934 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeClose\n"));
   7.935 +    FUNCTION_MSG("WdfRequestTypeClose\n");
   7.936      break;
   7.937    case WdfRequestTypeRead:
   7.938 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeRead\n"));
   7.939 +    FUNCTION_MSG("WdfRequestTypeRead\n");
   7.940      break;
   7.941    case WdfRequestTypeWrite:
   7.942 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeWrite\n"));
   7.943 +    FUNCTION_MSG("WdfRequestTypeWrite\n");
   7.944      break;
   7.945    case WdfRequestTypeDeviceControl:
   7.946 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeDeviceControl\n"));
   7.947 +    FUNCTION_MSG("WdfRequestTypeDeviceControl\n");
   7.948      break;
   7.949    case WdfRequestTypeDeviceControlInternal:
   7.950 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeDeviceControlInternal\n"));
   7.951 +    FUNCTION_MSG("WdfRequestTypeDeviceControlInternal\n");
   7.952      break;
   7.953    default:
   7.954 -    KdPrint((__DRIVER_NAME "     Unknown type %x\n", parameters.Type));
   7.955 +    FUNCTION_MSG("Unknown type %x\n", parameters.Type);
   7.956      break;
   7.957    }
   7.958    WdfRequestComplete(request, status);  
   7.959 @@ -1122,13 +1090,7 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
   7.960  
   7.961    WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnp_power_callbacks);
   7.962    pnp_power_callbacks.EvtDeviceD0Entry = XenUsb_EvtDeviceD0Entry;
   7.963 -  pnp_power_callbacks.EvtDeviceD0EntryPostInterruptsEnabled = XenUsb_EvtDeviceD0EntryPostInterruptsEnabled;
   7.964    pnp_power_callbacks.EvtDeviceD0Exit = XenUsb_EvtDeviceD0Exit;
   7.965 -  pnp_power_callbacks.EvtDeviceD0ExitPreInterruptsDisabled = XenUsb_EvtDeviceD0ExitPreInterruptsDisabled;
   7.966 -  pnp_power_callbacks.EvtDevicePrepareHardware = XenUsb_EvtDevicePrepareHardware;
   7.967 -  pnp_power_callbacks.EvtDeviceReleaseHardware = XenUsb_EvtDeviceReleaseHardware;
   7.968 -  pnp_power_callbacks.EvtDeviceQueryRemove = XenUsb_EvtDeviceQueryRemove;
   7.969 -  //pnp_power_callbacks.EvtDeviceUsageNotification = XenUsb_EvtDeviceUsageNotification;
   7.970  
   7.971    WdfDeviceInitSetPnpPowerEventCallbacks(device_init, &pnp_power_callbacks);
   7.972  
   7.973 @@ -1154,14 +1116,17 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
   7.974    status = WdfDeviceCreate(&device_init, &device_attributes, &device);
   7.975    if (!NT_SUCCESS(status))
   7.976    {
   7.977 -    KdPrint(("Error creating device %08x\n", status));
   7.978 +    FUNCTION_MSG("Error creating device %08x\n", status);
   7.979      return status;
   7.980    }
   7.981  
   7.982    xudd = GetXudd(device);
   7.983 +  xudd->pdo = WdfDeviceWdmGetPhysicalDevice(device);
   7.984    xudd->child_list = WdfFdoGetDefaultChildList(device);
   7.985 +  KeInitializeEvent(&xudd->backend_event, SynchronizationEvent, FALSE);
   7.986    InitializeListHead(&xudd->partial_pvurb_queue);
   7.987    InitializeListHead(&xudd->partial_pvurb_ring);
   7.988 +  KeInitializeDpc(&xudd->event_dpc, XenUsb_HandleEventDpc, xudd);
   7.989  
   7.990    KeInitializeSpinLock(&xudd->urb_ring_lock);
   7.991    
   7.992 @@ -1172,7 +1137,7 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
   7.993    queue_config.EvtIoDefault = XenUsb_EvtIoDefault;
   7.994    status = WdfIoQueueCreate(device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xudd->io_queue);
   7.995    if (!NT_SUCCESS(status)) {
   7.996 -      KdPrint((__DRIVER_NAME "     Error creating io_queue 0x%x\n", status));
   7.997 +      FUNCTION_MSG("Error creating io_queue 0x%x\n", status);
   7.998        return status;
   7.999    }
  7.1000  
  7.1001 @@ -1184,7 +1149,7 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
  7.1002    queue_config.Settings.Parallel.NumberOfPresentedRequests = USB_URB_RING_SIZE; /* the queue controls if the ring is full */
  7.1003    status = WdfIoQueueCreate(device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xudd->pvurb_queue);
  7.1004    if (!NT_SUCCESS(status)) {
  7.1005 -      KdPrint((__DRIVER_NAME "     Error creating urb_queue 0x%x\n", status));
  7.1006 +      FUNCTION_MSG("Error creating urb_queue 0x%x\n", status);
  7.1007        return status;
  7.1008    }
  7.1009  
     8.1 --- a/xenusb/xenusb_hub.c	Wed Feb 20 20:49:26 2013 +1100
     8.2 +++ b/xenusb/xenusb_hub.c	Thu Feb 21 20:37:38 2013 +1100
     8.3 @@ -103,26 +103,26 @@ XenUsbHub_EvtIoDefault(
     8.4    switch (parameters.Type)
     8.5    {
     8.6    case WdfRequestTypeCreate:
     8.7 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeCreate\n"));
     8.8 +    FUNCTION_MSG("WdfRequestTypeCreate\n");
     8.9      break;
    8.10    case WdfRequestTypeClose:
    8.11 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeClose\n"));
    8.12 +    FUNCTION_MSG("WdfRequestTypeClose\n");
    8.13      break;
    8.14    case WdfRequestTypeRead:
    8.15 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeRead\n"));
    8.16 +    FUNCTION_MSG("WdfRequestTypeRead\n");
    8.17      break;
    8.18    case WdfRequestTypeWrite:
    8.19 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeWrite\n"));
    8.20 +    FUNCTION_MSG("WdfRequestTypeWrite\n");
    8.21      break;
    8.22    case WdfRequestTypeDeviceControl:
    8.23 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeDeviceControl\n"));
    8.24 +    FUNCTION_MSG("WdfRequestTypeDeviceControl\n");
    8.25      
    8.26      break;
    8.27    case WdfRequestTypeDeviceControlInternal:
    8.28 -    KdPrint((__DRIVER_NAME "     WdfRequestTypeDeviceControlInternal\n"));
    8.29 +    FUNCTION_MSG("WdfRequestTypeDeviceControlInternal\n");
    8.30      break;
    8.31    default:
    8.32 -    KdPrint((__DRIVER_NAME "     Unknown type %x\n", parameters.Type));
    8.33 +    FUNCTION_MSG("Unknown type %x\n", parameters.Type);
    8.34      break;
    8.35    }
    8.36    FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n");
    8.37 @@ -182,43 +182,43 @@ XenUsbHub_EvtIoDeviceControl(
    8.38    switch(io_control_code)
    8.39    {
    8.40    case IOCTL_USB_GET_NODE_INFORMATION:
    8.41 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_INFORMATION\n"));
    8.42 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_INFORMATION\n");
    8.43      break;
    8.44    case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION:
    8.45 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_INFORMATION\n"));
    8.46 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_INFORMATION\n");
    8.47      break;
    8.48    case IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION:
    8.49 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION\n"));
    8.50 +    FUNCTION_MSG("IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION\n");
    8.51      break;
    8.52    case IOCTL_USB_GET_NODE_CONNECTION_NAME:
    8.53 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_NAME\n"));
    8.54 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_NAME\n");
    8.55      break;
    8.56    case IOCTL_USB_DIAG_IGNORE_HUBS_ON:
    8.57 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_DIAG_IGNORE_HUBS_ON\n"));
    8.58 +    FUNCTION_MSG("IOCTL_USB_DIAG_IGNORE_HUBS_ON\n");
    8.59      break;
    8.60    case IOCTL_USB_DIAG_IGNORE_HUBS_OFF:
    8.61 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_DIAG_IGNORE_HUBS_OFF\n"));
    8.62 +    FUNCTION_MSG("IOCTL_USB_DIAG_IGNORE_HUBS_OFF\n");
    8.63      break;
    8.64    case IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME:
    8.65 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME\n"));
    8.66 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME\n");
    8.67      break;
    8.68    case IOCTL_USB_GET_HUB_CAPABILITIES:
    8.69 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_HUB_CAPABILITIES\n"));
    8.70 +    FUNCTION_MSG("IOCTL_USB_GET_HUB_CAPABILITIES\n");
    8.71      break;
    8.72    case IOCTL_USB_HUB_CYCLE_PORT:
    8.73 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_HUB_CYCLE_PORT\n"));
    8.74 +    FUNCTION_MSG("IOCTL_USB_HUB_CYCLE_PORT\n");
    8.75      break;
    8.76    case IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES:
    8.77 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES\n"));
    8.78 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES\n");
    8.79      break;
    8.80    case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX:
    8.81 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX\n"));
    8.82 +    FUNCTION_MSG("IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX\n");
    8.83      break;
    8.84    case IOCTL_GET_HCD_DRIVERKEY_NAME:
    8.85 -    KdPrint((__DRIVER_NAME "     IOCTL_GET_HCD_DRIVERKEY_NAME (***)\n"));
    8.86 +    FUNCTION_MSG("IOCTL_GET_HCD_DRIVERKEY_NAME (***)\n");
    8.87      break;
    8.88    default:
    8.89 -    KdPrint((__DRIVER_NAME "     Unknown IOCTL %08x\n", io_control_code));
    8.90 +    FUNCTION_MSG("Unknown IOCTL %08x\n", io_control_code);
    8.91      break;
    8.92    }
    8.93    FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n");
    8.94 @@ -263,26 +263,26 @@ XenUsbHub_EvtIoInternalDeviceControl(
    8.95    switch(io_control_code)
    8.96    {
    8.97    case IOCTL_INTERNAL_USB_CYCLE_PORT:
    8.98 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_CYCLE_PORT\n"));
    8.99 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_CYCLE_PORT\n");
   8.100      break;
   8.101    case IOCTL_INTERNAL_USB_ENABLE_PORT:
   8.102 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_ENABLE_PORT\n"));
   8.103 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_ENABLE_PORT\n");
   8.104      break;
   8.105    case IOCTL_INTERNAL_USB_GET_BUS_INFO:
   8.106 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_GET_BUS_INFO\n"));
   8.107 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_BUS_INFO\n");
   8.108      break;
   8.109    case IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME:
   8.110 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME\n"));
   8.111 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME\n");
   8.112      break;
   8.113    case IOCTL_INTERNAL_USB_GET_HUB_COUNT:
   8.114 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_GET_HUB_COUNT\n"));
   8.115 -    KdPrint((__DRIVER_NAME "     Count before increment = %p\n", *(PULONG)wrp.Parameters.Others.Arg1));
   8.116 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_HUB_COUNT\n");
   8.117 +    FUNCTION_MSG("Count before increment = %p\n", *(PULONG)wrp.Parameters.Others.Arg1);
   8.118      (*(PULONG)wrp.Parameters.Others.Arg1)++;
   8.119      status = STATUS_SUCCESS;
   8.120      break;
   8.121  #if (NTDDI_VERSION >= NTDDI_VISTA)
   8.122    case IOCTL_INTERNAL_USB_GET_HUB_NAME:
   8.123 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_GET_HUB_NAME (hub)\n"));
   8.124 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_HUB_NAME (hub)\n");
   8.125      status = WdfRequestRetrieveOutputBuffer(request, FIELD_OFFSET(USB_HUB_NAME, HubName) + 18, (PVOID *)&uhn, &length);
   8.126      if (NT_SUCCESS(status))
   8.127      {
   8.128 @@ -299,22 +299,22 @@ XenUsbHub_EvtIoInternalDeviceControl(
   8.129      status = STATUS_SUCCESS;
   8.130      break;
   8.131    case IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO:
   8.132 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO\n"));
   8.133 -    KdPrint((__DRIVER_NAME "     WdfDeviceWdmGetPhysicalDevice(device) = %p\n", WdfDeviceWdmGetPhysicalDevice(device)));
   8.134 -    //KdPrint((__DRIVER_NAME "     IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(device)) = %p\n", IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(device))));
   8.135 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO\n");
   8.136 +    FUNCTION_MSG("WdfDeviceWdmGetPhysicalDevice(device) = %p\n", WdfDeviceWdmGetPhysicalDevice(device));
   8.137 +    //FUNCTION_MSG("IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(device)) = %p\n", IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(device));
   8.138      *(PVOID *)wrp.Parameters.Others.Arg1 = WdfDeviceWdmGetPhysicalDevice(device);
   8.139      //*(PVOID *)wrp.Parameters.Others.Arg2 = IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(device));
   8.140      *(PVOID *)wrp.Parameters.Others.Arg2 = IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(xupdd->wdf_device_bus_fdo));
   8.141      status = STATUS_SUCCESS;
   8.142      break;
   8.143    case IOCTL_INTERNAL_USB_RESET_PORT:
   8.144 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_RESET_PORT\n"));
   8.145 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_RESET_PORT\n");
   8.146      break;
   8.147    case IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION:
   8.148 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION\n"));
   8.149 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION\n");
   8.150      break;
   8.151    case IOCTL_INTERNAL_USB_SUBMIT_URB:
   8.152 -    //KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_SUBMIT_URB\n"));
   8.153 +    //FUNCTION_MSG("IOCTL_INTERNAL_USB_SUBMIT_URB\n");
   8.154      urb = (PURB)wrp.Parameters.Others.Arg1;
   8.155      ASSERT(urb);
   8.156      usb_device = urb->UrbHeader.UsbdDeviceHandle;
   8.157 @@ -403,25 +403,25 @@ XenUsbHub_EvtDeviceD0Entry(WDFDEVICE dev
   8.158    switch (previous_state)
   8.159    {
   8.160    case WdfPowerDeviceD0:
   8.161 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   8.162 +    FUNCTION_MSG("WdfPowerDeviceD1\n");
   8.163      break;
   8.164    case WdfPowerDeviceD1:
   8.165 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   8.166 +    FUNCTION_MSG("WdfPowerDeviceD1\n");
   8.167      break;
   8.168    case WdfPowerDeviceD2:
   8.169 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
   8.170 +    FUNCTION_MSG("WdfPowerDeviceD2\n");
   8.171      break;
   8.172    case WdfPowerDeviceD3:
   8.173 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
   8.174 +    FUNCTION_MSG("WdfPowerDeviceD3\n");
   8.175      break;
   8.176    case WdfPowerDeviceD3Final:
   8.177 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
   8.178 +    FUNCTION_MSG("WdfPowerDeviceD3Final\n");
   8.179      break;
   8.180    case WdfPowerDevicePrepareForHibernation:
   8.181 -    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
   8.182 +    FUNCTION_MSG("WdfPowerDevicePrepareForHibernation\n");
   8.183      break;  
   8.184    default:
   8.185 -    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", previous_state));
   8.186 +    FUNCTION_MSG("Unknown WdfPowerDevice state %d\n", previous_state);
   8.187      break;  
   8.188    }
   8.189  
   8.190 @@ -468,25 +468,25 @@ XenUsbHub_EvtDeviceD0Exit(WDFDEVICE devi
   8.191    switch (target_state)
   8.192    {
   8.193    case WdfPowerDeviceD0:
   8.194 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   8.195 +    FUNCTION_MSG("WdfPowerDeviceD1\n");
   8.196      break;
   8.197    case WdfPowerDeviceD1:
   8.198 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   8.199 +    FUNCTION_MSG("WdfPowerDeviceD1\n");
   8.200      break;
   8.201    case WdfPowerDeviceD2:
   8.202 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
   8.203 +    FUNCTION_MSG("WdfPowerDeviceD2\n");
   8.204      break;
   8.205    case WdfPowerDeviceD3:
   8.206 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
   8.207 +    FUNCTION_MSG("WdfPowerDeviceD3\n");
   8.208      break;
   8.209    case WdfPowerDeviceD3Final:
   8.210 -    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
   8.211 +    FUNCTION_MSG("WdfPowerDeviceD3Final\n");
   8.212      break;
   8.213    case WdfPowerDevicePrepareForHibernation:
   8.214 -    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
   8.215 +    FUNCTION_MSG("WdfPowerDevicePrepareForHibernation\n");
   8.216      break;  
   8.217    default:
   8.218 -    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", target_state));
   8.219 +    FUNCTION_MSG("Unknown WdfPowerDevice state %d\n", target_state);
   8.220      break;  
   8.221    }
   8.222    
   8.223 @@ -537,16 +537,16 @@ XenUsbHub_EvtDeviceUsageNotification(WDF
   8.224    switch (notification_type)
   8.225    {
   8.226    case WdfSpecialFilePaging:
   8.227 -    KdPrint((__DRIVER_NAME "     notification_type = Paging, flag = %d\n", is_in_notification_path));
   8.228 +    FUNCTION_MSG("notification_type = Paging, flag = %d\n", is_in_notification_path);
   8.229      break;
   8.230    case WdfSpecialFileHibernation:
   8.231 -    KdPrint((__DRIVER_NAME "     notification_type = Hibernation, flag = %d\n", is_in_notification_path));
   8.232 +    FUNCTION_MSG("notification_type = Hibernation, flag = %d\n", is_in_notification_path);
   8.233      break;
   8.234    case WdfSpecialFileDump:
   8.235 -    KdPrint((__DRIVER_NAME "     notification_type = Dump, flag = %d\n", is_in_notification_path));
   8.236 +    FUNCTION_MSG("notification_type = Dump, flag = %d\n", is_in_notification_path);
   8.237      break;
   8.238    default:
   8.239 -    KdPrint((__DRIVER_NAME "     notification_type = %d, flag = %d\n", notification_type, is_in_notification_path));
   8.240 +    FUNCTION_MSG("notification_type = %d, flag = %d\n", notification_type, is_in_notification_path);
   8.241      break;
   8.242    }
   8.243  
   8.244 @@ -634,8 +634,8 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   8.245    
   8.246    FUNCTION_ENTER();
   8.247  
   8.248 -  KdPrint((__DRIVER_NAME "     device = %p\n", device));
   8.249 -  KdPrint((__DRIVER_NAME "     usb_device = %p\n", usb_device));
   8.250 +  FUNCTION_MSG("device = %p\n", device);
   8.251 +  FUNCTION_MSG("usb_device = %p\n", usb_device);
   8.252    usb_device->pdo_device = BusContext;
   8.253    
   8.254    // TODO: get address from freelist and assign it to the device...
   8.255 @@ -703,30 +703,30 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   8.256      FUNCTION_MSG("WdfIoTargetSendInternalIoctlOthersSynchronously(USB_REQUEST_GET_DESCRIPTOR, USB_DEVICE_DESCRIPTOR_TYPE) = %08x\n", status);
   8.257      return status;
   8.258    }
   8.259 -  KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", pvurb.rsp.start_frame));
   8.260 -  KdPrint((__DRIVER_NAME "     rsp status = %d\n", pvurb.rsp.status));
   8.261 -  KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", pvurb.rsp.actual_length));
   8.262 -  KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", pvurb.rsp.error_count));
   8.263 +  FUNCTION_MSG("rsp start_frame = %d\n", pvurb.rsp.start_frame);
   8.264 +  FUNCTION_MSG("rsp status = %d\n", pvurb.rsp.status);
   8.265 +  FUNCTION_MSG("rsp actual_length = %d\n", pvurb.rsp.actual_length);
   8.266 +  FUNCTION_MSG("rsp error_count = %d\n", pvurb.rsp.error_count);
   8.267    ptr = buf;
   8.268    device_descriptor = (PUSB_DEVICE_DESCRIPTOR)ptr;
   8.269 -  KdPrint((__DRIVER_NAME "     bLength = %d\n", device_descriptor->bLength));
   8.270 -  KdPrint((__DRIVER_NAME "     bNumConfigurations = %d\n", device_descriptor->bNumConfigurations));
   8.271 +  FUNCTION_MSG("bLength = %d\n", device_descriptor->bLength);
   8.272 +  FUNCTION_MSG("bNumConfigurations = %d\n", device_descriptor->bNumConfigurations);
   8.273    memcpy(&usb_device->device_descriptor, device_descriptor, device_descriptor->bLength);
   8.274    usb_device->configs = ExAllocatePoolWithTag(NonPagedPool, sizeof(PVOID) * device_descriptor->bNumConfigurations, XENUSB_POOL_TAG);
   8.275    if (!usb_device->configs) {
   8.276      FUNCTION_MSG("ExAllocatePoolWithTag(usb_device->configs) failed\n");
   8.277      return STATUS_INSUFFICIENT_RESOURCES;
   8.278    }
   8.279 -  KdPrint((__DRIVER_NAME "     bLength = %d\n", device_descriptor->bLength));
   8.280 -  KdPrint((__DRIVER_NAME "     bDescriptorType = %d\n", device_descriptor->bDescriptorType));
   8.281 -  KdPrint((__DRIVER_NAME "     bcdUSB = %04x\n", device_descriptor->bcdUSB));
   8.282 -  KdPrint((__DRIVER_NAME "     bDeviceClass = %02x\n", device_descriptor->bDeviceClass));
   8.283 -  KdPrint((__DRIVER_NAME "     bDeviceSubClass = %02x\n", device_descriptor->bDeviceSubClass));
   8.284 -  KdPrint((__DRIVER_NAME "     bDeviceProtocol = %02x\n", device_descriptor->bDeviceProtocol));
   8.285 -  KdPrint((__DRIVER_NAME "     idVendor = %04x\n", device_descriptor->idVendor));
   8.286 -  KdPrint((__DRIVER_NAME "     idProduct = %04x\n", device_descriptor->idProduct));
   8.287 -  KdPrint((__DRIVER_NAME "     bcdDevice = %04x\n", device_descriptor->bcdDevice));
   8.288 -  KdPrint((__DRIVER_NAME "     bNumConfigurations = %04x\n", device_descriptor->bNumConfigurations));
   8.289 +  FUNCTION_MSG("bLength = %d\n", device_descriptor->bLength);
   8.290 +  FUNCTION_MSG("bDescriptorType = %d\n", device_descriptor->bDescriptorType);
   8.291 +  FUNCTION_MSG("bcdUSB = %04x\n", device_descriptor->bcdUSB);
   8.292 +  FUNCTION_MSG("bDeviceClass = %02x\n", device_descriptor->bDeviceClass);
   8.293 +  FUNCTION_MSG("bDeviceSubClass = %02x\n", device_descriptor->bDeviceSubClass);
   8.294 +  FUNCTION_MSG("bDeviceProtocol = %02x\n", device_descriptor->bDeviceProtocol);
   8.295 +  FUNCTION_MSG("idVendor = %04x\n", device_descriptor->idVendor);
   8.296 +  FUNCTION_MSG("idProduct = %04x\n", device_descriptor->idProduct);
   8.297 +  FUNCTION_MSG("bcdDevice = %04x\n", device_descriptor->bcdDevice);
   8.298 +  FUNCTION_MSG("bNumConfigurations = %04x\n", device_descriptor->bNumConfigurations);
   8.299  
   8.300    /* get the config descriptor */
   8.301    for (i = 0; i < device_descriptor->bNumConfigurations; i++)
   8.302 @@ -749,21 +749,21 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   8.303        FUNCTION_MSG("WdfIoTargetSendInternalIoctlOthersSynchronously(USB_REQUEST_GET_DESCRIPTOR, USB_CONFIGURATION_DESCRIPTOR_TYPE) = %08x\n", status);
   8.304        return status;
   8.305      }
   8.306 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", pvurb.rsp.start_frame));
   8.307 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", pvurb.rsp.status));
   8.308 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", pvurb.rsp.actual_length));
   8.309 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", pvurb.rsp.error_count));
   8.310 +    FUNCTION_MSG("rsp start_frame = %d\n", pvurb.rsp.start_frame);
   8.311 +    FUNCTION_MSG("rsp status = %d\n", pvurb.rsp.status);
   8.312 +    FUNCTION_MSG("rsp actual_length = %d\n", pvurb.rsp.actual_length);
   8.313 +    FUNCTION_MSG("rsp error_count = %d\n", pvurb.rsp.error_count);
   8.314      ptr = buf;
   8.315      config_descriptor = (PUSB_CONFIGURATION_DESCRIPTOR)ptr;
   8.316 -    KdPrint((__DRIVER_NAME "     Config %d\n", i));
   8.317 -    KdPrint((__DRIVER_NAME "      bLength = %d\n", config_descriptor->bLength));
   8.318 -    KdPrint((__DRIVER_NAME "      bDescriptorType = %d\n", config_descriptor->bDescriptorType));
   8.319 -    KdPrint((__DRIVER_NAME "      wTotalLength = %d\n", config_descriptor->wTotalLength));
   8.320 -    KdPrint((__DRIVER_NAME "      bNumInterfaces = %d\n", config_descriptor->bNumInterfaces));
   8.321 -    KdPrint((__DRIVER_NAME "      iConfiguration = %d\n", config_descriptor->iConfiguration));
   8.322 -    KdPrint((__DRIVER_NAME "      bConfigurationValue = %d\n", config_descriptor->bConfigurationValue));
   8.323 -    KdPrint((__DRIVER_NAME "      bmAttributes = %02x\n", config_descriptor->bmAttributes));
   8.324 -    KdPrint((__DRIVER_NAME "      MaxPower = %d\n", config_descriptor->MaxPower));
   8.325 +    FUNCTION_MSG("Config %d\n", i);
   8.326 +    FUNCTION_MSG(" bLength = %d\n", config_descriptor->bLength);
   8.327 +    FUNCTION_MSG(" bDescriptorType = %d\n", config_descriptor->bDescriptorType);
   8.328 +    FUNCTION_MSG(" wTotalLength = %d\n", config_descriptor->wTotalLength);
   8.329 +    FUNCTION_MSG(" bNumInterfaces = %d\n", config_descriptor->bNumInterfaces);
   8.330 +    FUNCTION_MSG(" iConfiguration = %d\n", config_descriptor->iConfiguration);
   8.331 +    FUNCTION_MSG(" bConfigurationValue = %d\n", config_descriptor->bConfigurationValue);
   8.332 +    FUNCTION_MSG(" bmAttributes = %02x\n", config_descriptor->bmAttributes);
   8.333 +    FUNCTION_MSG(" MaxPower = %d\n", config_descriptor->MaxPower);
   8.334      usb_device->configs[i] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_config_t) + sizeof(PVOID) * config_descriptor->bNumInterfaces, XENUSB_POOL_TAG);
   8.335      if (!usb_device->configs) {
   8.336        FUNCTION_MSG("ExAllocatePoolWithTag(usb_device->configs[i]) failed\n");
   8.337 @@ -778,16 +778,16 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   8.338      while (j < config_descriptor->bNumInterfaces)
   8.339      {
   8.340        interface_descriptor = (PUSB_INTERFACE_DESCRIPTOR)ptr;
   8.341 -      KdPrint((__DRIVER_NAME "       Interface %d\n", j));
   8.342 -      KdPrint((__DRIVER_NAME "        bLength = %d\n", interface_descriptor->bLength));
   8.343 -      KdPrint((__DRIVER_NAME "        bDescriptorType = %d\n", interface_descriptor->bDescriptorType));
   8.344 -      KdPrint((__DRIVER_NAME "        bInterfaceNumber = %d\n", interface_descriptor->bInterfaceNumber));
   8.345 -      KdPrint((__DRIVER_NAME "        bAlternateSetting = %d\n", interface_descriptor->bAlternateSetting));
   8.346 -      KdPrint((__DRIVER_NAME "        bNumEndpoints = %d\n", interface_descriptor->bNumEndpoints));
   8.347 -      KdPrint((__DRIVER_NAME "        bInterfaceClass = %d\n", interface_descriptor->bInterfaceClass));
   8.348 -      KdPrint((__DRIVER_NAME "        bInterfaceSubClass = %d\n", interface_descriptor->bInterfaceSubClass));
   8.349 -      KdPrint((__DRIVER_NAME "        bInterfaceProtocol = %d\n", interface_descriptor->bInterfaceProtocol));
   8.350 -      KdPrint((__DRIVER_NAME "        iInterface = %d\n", interface_descriptor->iInterface));
   8.351 +      FUNCTION_MSG("  Interface %d\n", j);
   8.352 +      FUNCTION_MSG("   bLength = %d\n", interface_descriptor->bLength);
   8.353 +      FUNCTION_MSG("   bDescriptorType = %d\n", interface_descriptor->bDescriptorType);
   8.354 +      FUNCTION_MSG("   bInterfaceNumber = %d\n", interface_descriptor->bInterfaceNumber);
   8.355 +      FUNCTION_MSG("   bAlternateSetting = %d\n", interface_descriptor->bAlternateSetting);
   8.356 +      FUNCTION_MSG("   bNumEndpoints = %d\n", interface_descriptor->bNumEndpoints);
   8.357 +      FUNCTION_MSG("   bInterfaceClass = %d\n", interface_descriptor->bInterfaceClass);
   8.358 +      FUNCTION_MSG("   bInterfaceSubClass = %d\n", interface_descriptor->bInterfaceSubClass);
   8.359 +      FUNCTION_MSG("   bInterfaceProtocol = %d\n", interface_descriptor->bInterfaceProtocol);
   8.360 +      FUNCTION_MSG("   iInterface = %d\n", interface_descriptor->iInterface);
   8.361        ptr += interface_descriptor->bLength;
   8.362        usb_device->configs[i]->interfaces[j] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_interface_t) + sizeof(PVOID) * interface_descriptor->bNumEndpoints, XENUSB_POOL_TAG);
   8.363        usb_device->configs[i]->interfaces[j]->config = usb_device->configs[i];
   8.364 @@ -798,18 +798,18 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   8.365          endpoint_descriptor = (PUSB_ENDPOINT_DESCRIPTOR)ptr;
   8.366          if (endpoint_descriptor->bDescriptorType != 5)
   8.367          {
   8.368 -          KdPrint((__DRIVER_NAME "        Unknown bDescriptorType %d found length = %d\n", endpoint_descriptor->bDescriptorType, endpoint_descriptor->bLength));
   8.369 +          FUNCTION_MSG("   Unknown bDescriptorType %d found length = %d\n", endpoint_descriptor->bDescriptorType, endpoint_descriptor->bLength);
   8.370            ptr += endpoint_descriptor->bLength;
   8.371            continue;
   8.372          }
   8.373  
   8.374 -        KdPrint((__DRIVER_NAME "        Endpoint %d\n", k));
   8.375 -        KdPrint((__DRIVER_NAME "         bLength = %d\n", endpoint_descriptor->bLength));
   8.376 -        KdPrint((__DRIVER_NAME "         bDescriptorType = %d\n", endpoint_descriptor->bDescriptorType));
   8.377 -        KdPrint((__DRIVER_NAME "         bEndpointAddress = %02x\n", endpoint_descriptor->bEndpointAddress));
   8.378 -        KdPrint((__DRIVER_NAME "         bmAttributes = %02x\n", endpoint_descriptor->bmAttributes));
   8.379 -        KdPrint((__DRIVER_NAME "         wMaxPacketSize = %d\n", endpoint_descriptor->wMaxPacketSize));
   8.380 -        KdPrint((__DRIVER_NAME "         bInterval = %d\n", endpoint_descriptor->bInterval));
   8.381 +        FUNCTION_MSG("   Endpoint %d\n", k);
   8.382 +        FUNCTION_MSG("    bLength = %d\n", endpoint_descriptor->bLength);
   8.383 +        FUNCTION_MSG("    bDescriptorType = %d\n", endpoint_descriptor->bDescriptorType);
   8.384 +        FUNCTION_MSG("    bEndpointAddress = %02x\n", endpoint_descriptor->bEndpointAddress);
   8.385 +        FUNCTION_MSG("    bmAttributes = %02x\n", endpoint_descriptor->bmAttributes);
   8.386 +        FUNCTION_MSG("    wMaxPacketSize = %d\n", endpoint_descriptor->wMaxPacketSize);
   8.387 +        FUNCTION_MSG("    bInterval = %d\n", endpoint_descriptor->bInterval);
   8.388          ptr += endpoint_descriptor->bLength;
   8.389          usb_device->configs[i]->interfaces[j]->endpoints[k] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_endpoint_t), XENUSB_POOL_TAG);
   8.390          usb_device->configs[i]->interfaces[j]->endpoints[k]->interface = usb_device->configs[i]->interfaces[j];
   8.391 @@ -848,7 +848,7 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   8.392    queue_config.PowerManaged = TRUE; /* power managed queue for SUBMIT_URB */
   8.393    status = WdfIoQueueCreate(device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &usb_device->urb_queue);
   8.394    if (!NT_SUCCESS(status)) {
   8.395 -      KdPrint((__DRIVER_NAME "     Error creating urb_queue 0x%x\n", status));
   8.396 +      FUNCTION_MSG("Error creating urb_queue 0x%x\n", status);
   8.397        return status;
   8.398    }
   8.399    FUNCTION_EXIT();
   8.400 @@ -874,12 +874,12 @@ XenUsbHub_UBIH_GetUsbDescriptors(
   8.401  
   8.402    FUNCTION_ENTER();
   8.403  
   8.404 -  KdPrint((__DRIVER_NAME "     BusContext = %p\n", BusContext));
   8.405 -  KdPrint((__DRIVER_NAME "     DeviceHandle = %p\n", DeviceHandle));
   8.406 -  KdPrint((__DRIVER_NAME "     DeviceDescriptorBuffer = %p\n", DeviceDescriptorBuffer));
   8.407 -  KdPrint((__DRIVER_NAME "     DeviceDescriptorBufferLength = %d\n", *DeviceDescriptorBufferLength));
   8.408 -  KdPrint((__DRIVER_NAME "     ConfigDescriptorBuffer = %p\n", ConfigDescriptorBuffer));
   8.409 -  KdPrint((__DRIVER_NAME "     ConfigDescriptorBufferLength = %d\n", *ConfigDescriptorBufferLength));
   8.410 +  FUNCTION_MSG("BusContext = %p\n", BusContext);
   8.411 +  FUNCTION_MSG("DeviceHandle = %p\n", DeviceHandle);
   8.412 +  FUNCTION_MSG("DeviceDescriptorBuffer = %p\n", DeviceDescriptorBuffer);
   8.413 +  FUNCTION_MSG("DeviceDescriptorBufferLength = %d\n", *DeviceDescriptorBufferLength);
   8.414 +  FUNCTION_MSG("ConfigDescriptorBuffer = %p\n", ConfigDescriptorBuffer);
   8.415 +  FUNCTION_MSG("ConfigDescriptorBufferLength = %d\n", *ConfigDescriptorBufferLength);
   8.416    
   8.417    memcpy(DeviceDescriptorBuffer, &usb_device->device_descriptor, usb_device->device_descriptor.bLength);
   8.418    *DeviceDescriptorBufferLength = usb_device->device_descriptor.bLength;
   8.419 @@ -927,10 +927,10 @@ XenUsbHub_UBIH_RemoveUsbDevice (
   8.420    FUNCTION_ENTER();
   8.421    
   8.422    if (Flags & USBD_KEEP_DEVICE_DATA)
   8.423 -    KdPrint((__DRIVER_NAME "     USBD_KEEP_DEVICE_DATA\n"));
   8.424 +    FUNCTION_MSG("USBD_KEEP_DEVICE_DATA\n");
   8.425      
   8.426    if (Flags & USBD_MARK_DEVICE_BUSY)
   8.427 -    KdPrint((__DRIVER_NAME "     USBD_MARK_DEVICE_BUSY\n"));
   8.428 +    FUNCTION_MSG("USBD_MARK_DEVICE_BUSY\n");
   8.429  
   8.430    put_id_on_freelist(xupdd->dev_id_ss, (uint16_t)usb_device->address);
   8.431    // check if there are no pending requests
   8.432 @@ -1001,24 +1001,24 @@ XenUsbHub_UBIH_QueryDeviceInformation(
   8.433  
   8.434    FUNCTION_ENTER();
   8.435  
   8.436 -  KdPrint((__DRIVER_NAME "     BusContext = %p\n", BusContext));
   8.437 -  KdPrint((__DRIVER_NAME "     DeviceHandle = %p\n", DeviceHandle));
   8.438 -  KdPrint((__DRIVER_NAME "     DeviceInformationBuffer = %p\n", DeviceInformationBuffer));
   8.439 -  KdPrint((__DRIVER_NAME "     DeviceInformationBufferLength = %d\n", DeviceInformationBufferLength));
   8.440 -  KdPrint((__DRIVER_NAME "     ->InformationLevel = %d\n", udi->InformationLevel));
   8.441 +  FUNCTION_MSG("BusContext = %p\n", BusContext);
   8.442 +  FUNCTION_MSG("DeviceHandle = %p\n", DeviceHandle);
   8.443 +  FUNCTION_MSG("DeviceInformationBuffer = %p\n", DeviceInformationBuffer);
   8.444 +  FUNCTION_MSG("DeviceInformationBufferLength = %d\n", DeviceInformationBufferLength);
   8.445 +  FUNCTION_MSG("->InformationLevel = %d\n", udi->InformationLevel);
   8.446    required_size = (ULONG)FIELD_OFFSET(USB_DEVICE_INFORMATION_0, PipeList[usb_device->active_interface->interface_descriptor.bNumEndpoints]);
   8.447 -  KdPrint((__DRIVER_NAME "     required_size = %d\n", required_size));
   8.448 +  FUNCTION_MSG("required_size = %d\n", required_size);
   8.449    *LengthOfDataReturned = required_size;
   8.450    udi->ActualLength = required_size;
   8.451    if (DeviceInformationBufferLength < required_size)
   8.452    {
   8.453 -    KdPrint((__DRIVER_NAME "     STATUS_BUFFER_TOO_SMALL\n"));
   8.454 +    FUNCTION_MSG("STATUS_BUFFER_TOO_SMALL\n");
   8.455      FUNCTION_EXIT();
   8.456      return STATUS_BUFFER_TOO_SMALL;
   8.457    }
   8.458    if (udi->InformationLevel != 0)
   8.459    {
   8.460 -    KdPrint((__DRIVER_NAME "     STATUS_NOT_SUPPORTED\n"));
   8.461 +    FUNCTION_MSG("STATUS_NOT_SUPPORTED\n");
   8.462      FUNCTION_EXIT();
   8.463      return STATUS_NOT_SUPPORTED;
   8.464    }
   8.465 @@ -1055,19 +1055,17 @@ XenUsbHub_UBIH_GetControllerInformation 
   8.466  
   8.467    FUNCTION_ENTER();
   8.468  
   8.469 -  KdPrint((__DRIVER_NAME "     BusContext = %p\n", BusContext));
   8.470 -  KdPrint((__DRIVER_NAME "     ControllerInformationBuffer = %p\n", ControllerInformationBuffer));
   8.471 -  KdPrint((__DRIVER_NAME "     ControllerInformationBufferLength = %d\n", ControllerInformationBufferLength));
   8.472 -  KdPrint((__DRIVER_NAME "     ->InformationLevel = %d\n", uci->InformationLevel));
   8.473 -  if (ControllerInformationBufferLength < sizeof(USB_CONTROLLER_INFORMATION_0))
   8.474 -  {
   8.475 -    KdPrint((__DRIVER_NAME "     STATUS_BUFFER_TOO_SMALL\n"));
   8.476 +  FUNCTION_MSG("BusContext = %p\n", BusContext);
   8.477 +  FUNCTION_MSG("ControllerInformationBuffer = %p\n", ControllerInformationBuffer);
   8.478 +  FUNCTION_MSG("ControllerInformationBufferLength = %d\n", ControllerInformationBufferLength);
   8.479 +  FUNCTION_MSG("->InformationLevel = %d\n", uci->InformationLevel);
   8.480 +  if (ControllerInformationBufferLength < sizeof(USB_CONTROLLER_INFORMATION_0)) {
   8.481 +    FUNCTION_MSG("STATUS_BUFFER_TOO_SMALL\n");
   8.482      FUNCTION_EXIT();
   8.483      return STATUS_BUFFER_TOO_SMALL;
   8.484    }
   8.485 -  if (uci->InformationLevel != 0)
   8.486 -  {
   8.487 -    KdPrint((__DRIVER_NAME "     STATUS_NOT_SUPPORTED\n"));
   8.488 +  if (uci->InformationLevel != 0) {
   8.489 +    FUNCTION_MSG("STATUS_NOT_SUPPORTED\n");
   8.490      FUNCTION_EXIT();
   8.491      return STATUS_NOT_SUPPORTED;
   8.492    }
   8.493 @@ -1113,21 +1111,21 @@ XenUsbHub_UBIH_GetExtendedHubInformation
   8.494    
   8.495    FUNCTION_ENTER();
   8.496  
   8.497 -  KdPrint((__DRIVER_NAME "     BusContext = %p\n", BusContext));
   8.498 -  KdPrint((__DRIVER_NAME "     HubPhysicalDeviceObject = %p\n", HubPhysicalDeviceObject));
   8.499 -  KdPrint((__DRIVER_NAME "     HubInformationBuffer = %p\n", HubInformationBuffer));
   8.500 -  KdPrint((__DRIVER_NAME "     HubInformationBufferLength = %d\n", HubInformationBufferLength));
   8.501 -  KdPrint((__DRIVER_NAME "     ->InformationLevel = %d\n", hib->InformationLevel));
   8.502 +  FUNCTION_MSG("BusContext = %p\n", BusContext);
   8.503 +  FUNCTION_MSG("HubPhysicalDeviceObject = %p\n", HubPhysicalDeviceObject);
   8.504 +  FUNCTION_MSG("HubInformationBuffer = %p\n", HubInformationBuffer);
   8.505 +  FUNCTION_MSG("HubInformationBufferLength = %d\n", HubInformationBufferLength);
   8.506 +  FUNCTION_MSG("->InformationLevel = %d\n", hib->InformationLevel);
   8.507    if (HubInformationBufferLength < (ULONG)FIELD_OFFSET(USB_EXTHUB_INFORMATION_0, Port[8]))
   8.508    {
   8.509 -    KdPrint((__DRIVER_NAME "     STATUS_BUFFER_TOO_SMALL\n"));
   8.510 +    FUNCTION_MSG("STATUS_BUFFER_TOO_SMALL\n");
   8.511      FUNCTION_EXIT();
   8.512      return STATUS_BUFFER_TOO_SMALL;
   8.513    }
   8.514  #if 0
   8.515    if (hib->InformationLevel != 0)
   8.516    {
   8.517 -    KdPrint((__DRIVER_NAME "     STATUS_NOT_SUPPORTED\n"));
   8.518 +    FUNCTION_MSG("STATUS_NOT_SUPPORTED\n");
   8.519      FUNCTION_EXIT();
   8.520      return STATUS_NOT_SUPPORTED;
   8.521    }
   8.522 @@ -1159,9 +1157,9 @@ XenUsbHub_UBIH_GetRootHubSymbolicName(
   8.523  
   8.524    UNREFERENCED_PARAMETER(BusContext);
   8.525    
   8.526 -  KdPrint((__DRIVER_NAME "     BusContext = %p\n", BusContext));
   8.527 -  KdPrint((__DRIVER_NAME "     HubInformationBuffer = %p\n", HubInformationBuffer));
   8.528 -  KdPrint((__DRIVER_NAME "     HubInformationBufferLength = %d\n", HubInformationBufferLength));
   8.529 +  FUNCTION_MSG("BusContext = %p\n", BusContext);
   8.530 +  FUNCTION_MSG("HubInformationBuffer = %p\n", HubInformationBuffer);
   8.531 +  FUNCTION_MSG("HubInformationBufferLength = %d\n", HubInformationBufferLength);
   8.532    RtlStringCbCopyW(HubInformationBuffer, HubInformationBufferLength, L"ROOT_HUB");
   8.533    *HubNameActualLength = 16;
   8.534  
   8.535 @@ -1196,9 +1194,9 @@ XenUsbHub_UBIH_Initialize20Hub (
   8.536    UNREFERENCED_PARAMETER(TtCount);
   8.537    
   8.538    FUNCTION_ENTER();
   8.539 -  KdPrint((__DRIVER_NAME "     BusContext = %p\n", BusContext));
   8.540 -  KdPrint((__DRIVER_NAME "     HubDeviceHandle = %p\n", HubDeviceHandle));
   8.541 -  KdPrint((__DRIVER_NAME "     TtCount = %d\n", TtCount));
   8.542 +  FUNCTION_MSG("BusContext = %p\n", BusContext);
   8.543 +  FUNCTION_MSG("HubDeviceHandle = %p\n", HubDeviceHandle);
   8.544 +  FUNCTION_MSG("TtCount = %d\n", TtCount);
   8.545    FUNCTION_EXIT();
   8.546    return status;
   8.547  }
   8.548 @@ -1271,8 +1269,8 @@ XenUsbHub_UBIH_CreateUsbDeviceEx(
   8.549  
   8.550    status = XenUsbHub_UBIH_CreateUsbDevice(BusContext, DeviceHandle, HubDeviceHandle, PortStatus, PortNumber);
   8.551    
   8.552 -  KdPrint((__DRIVER_NAME "     CdErrorInfo = %p\n", CdErrorInfo));
   8.553 -  KdPrint((__DRIVER_NAME "     TtPortNumber = %d\n", TtPortNumber));
   8.554 +  FUNCTION_MSG("CdErrorInfo = %p\n", CdErrorInfo);
   8.555 +  FUNCTION_MSG("TtPortNumber = %d\n", TtPortNumber);
   8.556    
   8.557    FUNCTION_EXIT();
   8.558    return status;
   8.559 @@ -1297,11 +1295,11 @@ XenUsbHub_UBIH_CreateUsbDeviceV7(
   8.560    UNREFERENCED_PARAMETER(PhysicalDeviceObjectName);
   8.561    
   8.562    FUNCTION_ENTER();
   8.563 -  KdPrint((__DRIVER_NAME "     PortPath->PortPathDepth = %d\n", PortPath->PortPathDepth));
   8.564 -  KdPrint((__DRIVER_NAME "     PortPath->PortPath[%d] = %d\n", PortPath->PortPathDepth - 1));
   8.565 +  FUNCTION_MSG("PortPath->PortPathDepth = %d\n", PortPath->PortPathDepth);
   8.566 +  FUNCTION_MSG("PortPath->PortPath[%d] = %d\n", PortPath->PortPathDepth - 1);
   8.567    status = XenUsbHub_UBIH_CreateUsbDeviceEx(BusContext, NewDeviceHandle, &HsHubDeviceHandle, PortStatus, (USHORT)PortPath->PortPath[PortPath->PortPathDepth-1], CdErrorInfo, TtPortNumber);
   8.568 -  KdPrint((__DRIVER_NAME "     PdoDeviceObject = %p\n", PdoDeviceObject));
   8.569 -  KdPrint((__DRIVER_NAME "     PhysicalDeviceObjectName = %S\n", PhysicalDeviceObjectName->Buffer));
   8.570 +  FUNCTION_MSG("PdoDeviceObject = %p\n", PdoDeviceObject);
   8.571 +  FUNCTION_MSG("PhysicalDeviceObjectName = %S\n", PhysicalDeviceObjectName->Buffer);
   8.572    FUNCTION_EXIT();
   8.573    return status;
   8.574  }
   8.575 @@ -1672,10 +1670,10 @@ XenUsbHub_UBIU_EnumLogEntry(
   8.576    UNREFERENCED_PARAMETER(P1);
   8.577    UNREFERENCED_PARAMETER(P2);
   8.578    
   8.579 -  KdPrint((__DRIVER_NAME "     DriverTag = %08x\n", DriverTag));
   8.580 -  KdPrint((__DRIVER_NAME "     EnumTag = %08x\n", EnumTag));
   8.581 -  KdPrint((__DRIVER_NAME "     P1 = %08x\n", P1));
   8.582 -  KdPrint((__DRIVER_NAME "     P2 = %08x\n", P2));
   8.583 +  FUNCTION_MSG("DriverTag = %08x\n", DriverTag);
   8.584 +  FUNCTION_MSG("EnumTag = %08x\n", EnumTag);
   8.585 +  FUNCTION_MSG("P1 = %08x\n", P1);
   8.586 +  FUNCTION_MSG("P2 = %08x\n", P2);
   8.587  
   8.588    FUNCTION_EXIT();
   8.589    return status;
   8.590 @@ -1756,14 +1754,14 @@ XenUsbHub_ProcessHubInterruptEvent(xenus
   8.591    if (status == STATUS_NO_MORE_ENTRIES)
   8.592    {
   8.593      WdfSpinLockRelease(endpoint->lock);
   8.594 -    KdPrint((__DRIVER_NAME "      No More Entries\n", status));
   8.595 +    FUNCTION_MSG(" No More Entries\n", status);
   8.596      FUNCTION_EXIT();
   8.597      return;
   8.598    }
   8.599    if (!NT_SUCCESS(status))
   8.600    {
   8.601      WdfSpinLockRelease(endpoint->lock);
   8.602 -    KdPrint((__DRIVER_NAME "      Failed to get request from queue %08x\n", status));
   8.603 +    FUNCTION_MSG(" Failed to get request from queue %08x\n", status);
   8.604      FUNCTION_EXIT();
   8.605      return;
   8.606    }
   8.607 @@ -1829,7 +1827,7 @@ XenUsbHub_EvtDeviceWdmIrpPreprocessQUERY
   8.608  
   8.609    if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_GUID, sizeof(GUID)) == 0)
   8.610    {
   8.611 -    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_HUB_GUID\n"));
   8.612 +    FUNCTION_MSG("USB_BUS_INTERFACE_HUB_GUID\n");
   8.613      if ((stack->Parameters.QueryInterface.Version == USB_BUSIF_HUB_VERSION_5 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_HUB_V5))
   8.614  #if (NTDDI_VERSION >= NTDDI_VISTA)  
   8.615        || (stack->Parameters.QueryInterface.Version == USB_BUSIF_HUB_VERSION_6 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_HUB_V6))
   8.616 @@ -1895,12 +1893,12 @@ XenUsbHub_EvtDeviceWdmIrpPreprocessQUERY
   8.617      }
   8.618      else
   8.619      {
   8.620 -      KdPrint((__DRIVER_NAME "     size/version mismatch\n"));
   8.621 +      FUNCTION_MSG("size/version mismatch\n");
   8.622      }
   8.623    }
   8.624    else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_USBDI_GUID, sizeof(GUID)) == 0)
   8.625    {
   8.626 -    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_USBDI_GUID\n"));
   8.627 +    FUNCTION_MSG("USB_BUS_INTERFACE_USBDI_GUID\n");
   8.628      if ((stack->Parameters.QueryInterface.Version == USB_BUSIF_USBDI_VERSION_0 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_USBDI_V0))
   8.629        || (stack->Parameters.QueryInterface.Version == USB_BUSIF_USBDI_VERSION_1 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_USBDI_V1))
   8.630        || (stack->Parameters.QueryInterface.Version == USB_BUSIF_USBDI_VERSION_2 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_USBDI_V2))
   8.631 @@ -1940,21 +1938,21 @@ XenUsbHub_EvtDeviceWdmIrpPreprocessQUERY
   8.632      }
   8.633      else
   8.634      {
   8.635 -      KdPrint((__DRIVER_NAME "     size/version mismatch\n"));
   8.636 +      FUNCTION_MSG("size/version mismatch\n");
   8.637      }
   8.638    }
   8.639    else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &GUID_TRANSLATOR_INTERFACE_STANDARD, sizeof(GUID)) == 0)
   8.640 -    KdPrint((__DRIVER_NAME "     GUID_TRANSLATOR_INTERFACE_STANDARD\n"));
   8.641 +    FUNCTION_MSG("GUID_TRANSLATOR_INTERFACE_STANDARD\n");
   8.642  #if (NTDDI_VERSION >= NTDDI_VISTA)
   8.643    else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &GUID_PNP_LOCATION_INTERFACE, sizeof(GUID)) == 0)
   8.644 -    KdPrint((__DRIVER_NAME "     GUID_PNP_LOCATION_INTERFACE\n"));
   8.645 +    FUNCTION_MSG("GUID_PNP_LOCATION_INTERFACE\n");
   8.646  #endif
   8.647    else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_MINIDUMP_GUID, sizeof(GUID)) == 0)
   8.648 -    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_HUB_MINIDUMP_GUID\n"));
   8.649 +    FUNCTION_MSG("USB_BUS_INTERFACE_HUB_MINIDUMP_GUID\n");
   8.650    else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_SS_GUID, sizeof(GUID)) == 0)
   8.651 -    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_HUB_SS_GUID\n"));
   8.652 +    FUNCTION_MSG("USB_BUS_INTERFACE_HUB_SS_GUID\n");
   8.653    else
   8.654 -    KdPrint((__DRIVER_NAME "     GUID = %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n",
   8.655 +    FUNCTION_MSG("GUID = %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n",
   8.656        stack->Parameters.QueryInterface.InterfaceType->Data1,
   8.657        stack->Parameters.QueryInterface.InterfaceType->Data2,
   8.658        stack->Parameters.QueryInterface.InterfaceType->Data3,
   8.659 @@ -1965,11 +1963,11 @@ XenUsbHub_EvtDeviceWdmIrpPreprocessQUERY
   8.660        stack->Parameters.QueryInterface.InterfaceType->Data4[4],
   8.661        stack->Parameters.QueryInterface.InterfaceType->Data4[5],
   8.662        stack->Parameters.QueryInterface.InterfaceType->Data4[6],
   8.663 -      stack->Parameters.QueryInterface.InterfaceType->Data4[7]));
   8.664 +      stack->Parameters.QueryInterface.InterfaceType->Data4[7]);
   8.665  
   8.666 -  KdPrint((__DRIVER_NAME "     Size = %d\n", stack->Parameters.QueryInterface.Size));
   8.667 -  KdPrint((__DRIVER_NAME "     Version = %d\n", stack->Parameters.QueryInterface.Version));
   8.668 -  KdPrint((__DRIVER_NAME "     Interface = %p\n", stack->Parameters.QueryInterface.Interface));
   8.669 +  FUNCTION_MSG("Size = %d\n", stack->Parameters.QueryInterface.Size);
   8.670 +  FUNCTION_MSG("Version = %d\n", stack->Parameters.QueryInterface.Version);
   8.671 +  FUNCTION_MSG("Interface = %p\n", stack->Parameters.QueryInterface.Interface);
   8.672  
   8.673    IoSkipCurrentIrpStackLocation(irp);
   8.674    
   8.675 @@ -2019,7 +2017,7 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   8.676  
   8.677    FUNCTION_ENTER();
   8.678  
   8.679 -  //KdPrint((__DRIVER_NAME "     device = %d, port = %d, vendor_id = %04x, product_id = %04x\n",
   8.680 +  //FUNCTION_MSG("device = %d, port = %d, vendor_id = %04x, product_id = %04x\n",
   8.681  
   8.682    WdfDeviceInitSetDeviceType(child_init, FILE_DEVICE_UNKNOWN);
   8.683  
   8.684 @@ -2149,7 +2147,7 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   8.685    queue_config.PowerManaged = TRUE; /* power managed queue for SUBMIT_URB */
   8.686    status = WdfIoQueueCreate(child_device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xupdd->usb_device->urb_queue);
   8.687    if (!NT_SUCCESS(status)) {
   8.688 -      KdPrint((__DRIVER_NAME "     Error creating urb_queue 0x%x\n", status));
   8.689 +      FUNCTION_MSG("Error creating urb_queue 0x%x\n", status);
   8.690        return status;
   8.691    }
   8.692    
   8.693 @@ -2160,7 +2158,7 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   8.694    status = WdfIoQueueCreate(child_device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES,
   8.695      &xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->queue);
   8.696    if (!NT_SUCCESS(status)) {
   8.697 -      KdPrint((__DRIVER_NAME "     Error creating timer io_queue 0x%x\n", status));
   8.698 +      FUNCTION_MSG("Error creating timer io_queue 0x%x\n", status);
   8.699        return status;
   8.700    }
   8.701    //*GetEndpoint(xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->queue) = xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0];
   8.702 @@ -2173,7 +2171,7 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   8.703    queue_config.PowerManaged = FALSE;
   8.704    status = WdfIoQueueCreate(child_device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xupdd->io_queue);
   8.705    if (!NT_SUCCESS(status)) {
   8.706 -      KdPrint((__DRIVER_NAME "     Error creating io_queue 0x%x\n", status));
   8.707 +      FUNCTION_MSG("Error creating io_queue 0x%x\n", status);
   8.708        return status;
   8.709    }
   8.710  
     9.1 --- a/xenusb/xenusb_huburb.c	Wed Feb 20 20:49:26 2013 +1100
     9.2 +++ b/xenusb/xenusb_huburb.c	Thu Feb 21 20:37:38 2013 +1100
     9.3 @@ -53,12 +53,12 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
     9.4    urb = (PURB)wrp.Parameters.Others.Arg1;
     9.5    ASSERT(urb);
     9.6  #if 0
     9.7 -  KdPrint((__DRIVER_NAME "     urb = %p\n", urb));
     9.8 -  KdPrint((__DRIVER_NAME "      Length = %d\n", urb->UrbHeader.Length));
     9.9 -  KdPrint((__DRIVER_NAME "      Function = %d\n", urb->UrbHeader.Function));
    9.10 -  KdPrint((__DRIVER_NAME "      Status = %d\n", urb->UrbHeader.Status));
    9.11 -  KdPrint((__DRIVER_NAME "      UsbdDeviceHandle = %p\n", urb->UrbHeader.UsbdDeviceHandle));
    9.12 -  KdPrint((__DRIVER_NAME "      UsbdFlags = %08x\n", urb->UrbHeader.UsbdFlags));
    9.13 +  FUNCTION_MSG("urb = %p\n", urb);
    9.14 +  FUNCTION_MSG(" Length = %d\n", urb->UrbHeader.Length);
    9.15 +  FUNCTION_MSG(" Function = %d\n", urb->UrbHeader.Function);
    9.16 +  FUNCTION_MSG(" Status = %d\n", urb->UrbHeader.Status);
    9.17 +  FUNCTION_MSG(" UsbdDeviceHandle = %p\n", urb->UrbHeader.UsbdDeviceHandle);
    9.18 +  FUNCTION_MSG(" UsbdFlags = %08x\n", urb->UrbHeader.UsbdFlags);
    9.19  #endif
    9.20    usb_device = urb->UrbHeader.UsbdDeviceHandle;
    9.21  
    9.22 @@ -68,7 +68,7 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
    9.23    decode_retval = XenUsb_DecodeControlUrb(urb, &decode_data);
    9.24    if (decode_retval == URB_DECODE_UNKNOWN)
    9.25    {
    9.26 -    FUNCTION_MSG("Unknown URB - Calling WdfRequestCompletestatus with status = %08x\n", STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL));
    9.27 +    FUNCTION_MSG("Unknown URB - Calling WdfRequestCompletestatus with status = %08x\n", STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL);
    9.28      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
    9.29      WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    9.30      return;
    9.31 @@ -95,50 +95,50 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
    9.32    switch(urb->UrbHeader.Function)
    9.33    {
    9.34    case URB_FUNCTION_SELECT_CONFIGURATION:
    9.35 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_CONFIGURATION\n"));
    9.36 -    KdPrint((__DRIVER_NAME "      ConfigurationDescriptor = %p\n", urb->UrbSelectConfiguration.ConfigurationDescriptor));
    9.37 +    FUNCTION_MSG("URB_FUNCTION_SELECT_CONFIGURATION\n");
    9.38 +    FUNCTION_MSG(" ConfigurationDescriptor = %p\n", urb->UrbSelectConfiguration.ConfigurationDescriptor);
    9.39      if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
    9.40      {
    9.41 -      KdPrint((__DRIVER_NAME "       bLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bLength));
    9.42 -      KdPrint((__DRIVER_NAME "       bDescriptorType = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bDescriptorType));
    9.43 -      KdPrint((__DRIVER_NAME "       wTotalLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->wTotalLength));
    9.44 -      KdPrint((__DRIVER_NAME "       bNumInterfaces = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces));
    9.45 -      KdPrint((__DRIVER_NAME "       bConfigurationValue = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue));
    9.46 -      KdPrint((__DRIVER_NAME "       iConfiguration = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->iConfiguration));
    9.47 -      KdPrint((__DRIVER_NAME "       bmAttributes = %04x\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bmAttributes));
    9.48 -      KdPrint((__DRIVER_NAME "       MaxPower = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower));
    9.49 +      FUNCTION_MSG("  bLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bLength);
    9.50 +      FUNCTION_MSG("  bDescriptorType = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bDescriptorType);
    9.51 +      FUNCTION_MSG("  wTotalLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->wTotalLength);
    9.52 +      FUNCTION_MSG("  bNumInterfaces = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces);
    9.53 +      FUNCTION_MSG("  bConfigurationValue = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue);
    9.54 +      FUNCTION_MSG("  iConfiguration = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->iConfiguration);
    9.55 +      FUNCTION_MSG("  bmAttributes = %04x\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bmAttributes);
    9.56 +      FUNCTION_MSG("  MaxPower = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower);
    9.57      }
    9.58 -    KdPrint((__DRIVER_NAME "      ConfigurationHandle = %p\n", urb->UrbSelectConfiguration.ConfigurationHandle));
    9.59 +    FUNCTION_MSG(" ConfigurationHandle = %p\n", urb->UrbSelectConfiguration.ConfigurationHandle);
    9.60      if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
    9.61      {
    9.62        urb->UrbSelectConfiguration.ConfigurationHandle = xupdd->usb_device->configs[0];
    9.63        interface_information = &urb->UrbSelectConfiguration.Interface;
    9.64        for (i = 0; i < urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces; i++)
    9.65        {
    9.66 -        KdPrint((__DRIVER_NAME "     InterfaceInformation[%d]\n", i));
    9.67 -        KdPrint((__DRIVER_NAME "      Length = %d\n", interface_information->Length));
    9.68 -        KdPrint((__DRIVER_NAME "      InterfaceNumber = %d\n", interface_information->InterfaceNumber));
    9.69 -        KdPrint((__DRIVER_NAME "      AlternateSetting = %d\n", interface_information->AlternateSetting));
    9.70 -        KdPrint((__DRIVER_NAME "      Class = %02x\n", (ULONG)interface_information->Class));
    9.71 -        KdPrint((__DRIVER_NAME "      SubClass = %02x\n", (ULONG)interface_information->SubClass));
    9.72 -        KdPrint((__DRIVER_NAME "      Protocol = %02x\n", (ULONG)interface_information->Protocol));
    9.73 -        KdPrint((__DRIVER_NAME "      Reserved = %02x\n", (ULONG)interface_information->Reserved));
    9.74 -        KdPrint((__DRIVER_NAME "      InterfaceHandle = %p\n", interface_information->InterfaceHandle));
    9.75 -        KdPrint((__DRIVER_NAME "      NumberOfPipes = %d\n", interface_information->NumberOfPipes));
    9.76 +        FUNCTION_MSG("InterfaceInformation[%d]\n", i);
    9.77 +        FUNCTION_MSG(" Length = %d\n", interface_information->Length);
    9.78 +        FUNCTION_MSG(" InterfaceNumber = %d\n", interface_information->InterfaceNumber);
    9.79 +        FUNCTION_MSG(" AlternateSetting = %d\n", interface_information->AlternateSetting);
    9.80 +        FUNCTION_MSG(" Class = %02x\n", (ULONG)interface_information->Class);
    9.81 +        FUNCTION_MSG(" SubClass = %02x\n", (ULONG)interface_information->SubClass);
    9.82 +        FUNCTION_MSG(" Protocol = %02x\n", (ULONG)interface_information->Protocol);
    9.83 +        FUNCTION_MSG(" Reserved = %02x\n", (ULONG)interface_information->Reserved);
    9.84 +        FUNCTION_MSG(" InterfaceHandle = %p\n", interface_information->InterfaceHandle);
    9.85 +        FUNCTION_MSG(" NumberOfPipes = %d\n", interface_information->NumberOfPipes);
    9.86          interface_information->InterfaceHandle = xupdd->usb_device->configs[0]->interfaces[0];
    9.87          interface_information->Class = 0x09;
    9.88          interface_information->SubClass = 0x00;
    9.89          interface_information->SubClass = 0x00;
    9.90          for (j = 0; j < interface_information->NumberOfPipes; j++)
    9.91          {
    9.92 -          KdPrint((__DRIVER_NAME "      Pipe[%d]\n", i));
    9.93 -          KdPrint((__DRIVER_NAME "       MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
    9.94 -          KdPrint((__DRIVER_NAME "       EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
    9.95 -          KdPrint((__DRIVER_NAME "       Interval = %d\n", interface_information->Pipes[j].Interval));
    9.96 -          KdPrint((__DRIVER_NAME "       PipeType = %d\n", interface_information->Pipes[j].PipeType));
    9.97 -          KdPrint((__DRIVER_NAME "       PipeHandle = %d\n", interface_information->Pipes[j].PipeHandle));
    9.98 -          KdPrint((__DRIVER_NAME "       MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
    9.99 -          KdPrint((__DRIVER_NAME "       PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
   9.100 +          FUNCTION_MSG(" Pipe[%d]\n", i);
   9.101 +          FUNCTION_MSG("  MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize);
   9.102 +          FUNCTION_MSG("  EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress);
   9.103 +          FUNCTION_MSG("  Interval = %d\n", interface_information->Pipes[j].Interval);
   9.104 +          FUNCTION_MSG("  PipeType = %d\n", interface_information->Pipes[j].PipeType);
   9.105 +          FUNCTION_MSG("  PipeHandle = %d\n", interface_information->Pipes[j].PipeHandle);
   9.106 +          FUNCTION_MSG("  MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize);
   9.107 +          FUNCTION_MSG("  PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags);
   9.108            interface_information->Pipes[j].MaximumPacketSize = 2;
   9.109            interface_information->Pipes[j].EndpointAddress = 0x81;
   9.110            interface_information->Pipes[j].Interval = 12;
   9.111 @@ -153,28 +153,28 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   9.112      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.113      break;
   9.114    case URB_FUNCTION_SELECT_INTERFACE:
   9.115 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_INTERFACE\n"));
   9.116 +    FUNCTION_MSG("URB_FUNCTION_SELECT_INTERFACE\n");
   9.117      interface_information = &urb->UrbSelectInterface.Interface;
   9.118 -    KdPrint((__DRIVER_NAME "     InterfaceInformation\n"));
   9.119 -    KdPrint((__DRIVER_NAME "      Length = %d\n", interface_information->Length));
   9.120 -    KdPrint((__DRIVER_NAME "      InterfaceNumber = %d\n", interface_information->InterfaceNumber));
   9.121 -    KdPrint((__DRIVER_NAME "      AlternateSetting = %d\n", interface_information->AlternateSetting));
   9.122 -    KdPrint((__DRIVER_NAME "      Class = %02x\n", (ULONG)interface_information->Class));
   9.123 -    KdPrint((__DRIVER_NAME "      SubClass = %02x\n", (ULONG)interface_information->SubClass));
   9.124 -    KdPrint((__DRIVER_NAME "      Protocol = %02x\n", (ULONG)interface_information->Protocol));
   9.125 -    KdPrint((__DRIVER_NAME "      Reserved = %02x\n", (ULONG)interface_information->Reserved));
   9.126 -    KdPrint((__DRIVER_NAME "      InterfaceHandle = %p\n", interface_information->InterfaceHandle));
   9.127 -    KdPrint((__DRIVER_NAME "      NumberOfPipes = %d\n", interface_information->NumberOfPipes));
   9.128 +    FUNCTION_MSG("InterfaceInformation\n");
   9.129 +    FUNCTION_MSG(" Length = %d\n", interface_information->Length);
   9.130 +    FUNCTION_MSG(" InterfaceNumber = %d\n", interface_information->InterfaceNumber);
   9.131 +    FUNCTION_MSG(" AlternateSetting = %d\n", interface_information->AlternateSetting);
   9.132 +    FUNCTION_MSG(" Class = %02x\n", (ULONG)interface_information->Class);
   9.133 +    FUNCTION_MSG(" SubClass = %02x\n", (ULONG)interface_information->SubClass);
   9.134 +    FUNCTION_MSG(" Protocol = %02x\n", (ULONG)interface_information->Protocol);
   9.135 +    FUNCTION_MSG(" Reserved = %02x\n", (ULONG)interface_information->Reserved);
   9.136 +    FUNCTION_MSG(" InterfaceHandle = %p\n", interface_information->InterfaceHandle);
   9.137 +    FUNCTION_MSG(" NumberOfPipes = %d\n", interface_information->NumberOfPipes);
   9.138      for (i = 0; i < interface_information->NumberOfPipes; i++)
   9.139      {
   9.140 -      KdPrint((__DRIVER_NAME "      Pipe[%d]\n", i));
   9.141 -      KdPrint((__DRIVER_NAME "       MaximumPacketSize = %d\n", interface_information->Pipes[i].MaximumPacketSize));
   9.142 -      KdPrint((__DRIVER_NAME "       EndpointAddress = %d\n", interface_information->Pipes[i].EndpointAddress));
   9.143 -      KdPrint((__DRIVER_NAME "       Interval = %d\n", interface_information->Pipes[i].Interval));
   9.144 -      KdPrint((__DRIVER_NAME "       PipeType = %d\n", interface_information->Pipes[i].PipeType));
   9.145 -      KdPrint((__DRIVER_NAME "       PipeHandle = %d\n", interface_information->Pipes[i].PipeHandle));
   9.146 -      KdPrint((__DRIVER_NAME "       MaximumTransferSize = %d\n", interface_information->Pipes[i].MaximumTransferSize));
   9.147 -      KdPrint((__DRIVER_NAME "       PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags));
   9.148 +      FUNCTION_MSG(" Pipe[%d]\n", i);
   9.149 +      FUNCTION_MSG("  MaximumPacketSize = %d\n", interface_information->Pipes[i].MaximumPacketSize);
   9.150 +      FUNCTION_MSG("  EndpointAddress = %d\n", interface_information->Pipes[i].EndpointAddress);
   9.151 +      FUNCTION_MSG("  Interval = %d\n", interface_information->Pipes[i].Interval);
   9.152 +      FUNCTION_MSG("  PipeType = %d\n", interface_information->Pipes[i].PipeType);
   9.153 +      FUNCTION_MSG("  PipeHandle = %d\n", interface_information->Pipes[i].PipeHandle);
   9.154 +      FUNCTION_MSG("  MaximumTransferSize = %d\n", interface_information->Pipes[i].MaximumTransferSize);
   9.155 +      FUNCTION_MSG("  PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags);
   9.156      }
   9.157      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   9.158      break;
   9.159 @@ -200,7 +200,7 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   9.160          switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
   9.161          {
   9.162          case BMREQUEST_TO_DEVICE:
   9.163 -          KdPrint((__DRIVER_NAME "       Recipient=Device\n"));
   9.164 +          FUNCTION_MSG("  Recipient=Device\n");
   9.165            ((PUSHORT)decode_data.buffer)[0] = 0x0001; /* self powered */
   9.166            urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.167            break;
   9.168 @@ -220,7 +220,7 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   9.169          case BMREQUEST_TO_OTHER:
   9.170            FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
   9.171            FUNCTION_MSG(" Type=Class\n");
   9.172 -          KdPrint((__DRIVER_NAME "       Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte));
   9.173 +          FUNCTION_MSG("  Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
   9.174            ((PUSHORT)decode_data.buffer)[0] = xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status;
   9.175            ((PUSHORT)decode_data.buffer)[1] = xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change;
   9.176            urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.177 @@ -335,15 +335,15 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   9.178        switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
   9.179        {
   9.180        case BMREQUEST_STANDARD: /* Standard */
   9.181 -        KdPrint((__DRIVER_NAME "       Type=Standard\n"));
   9.182 +        FUNCTION_MSG("  Type=Standard\n");
   9.183          switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
   9.184          {
   9.185          case BMREQUEST_TO_DEVICE:
   9.186 -          KdPrint((__DRIVER_NAME "       Recipient=Device\n"));
   9.187 +          FUNCTION_MSG("  Recipient=Device\n");
   9.188            switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
   9.189            {
   9.190            case 1: /* DEVICE_REMOTE_WAKEUP */
   9.191 -            KdPrint((__DRIVER_NAME "       Feature=DEVICE_REMOTE_WAKEUP\n"));
   9.192 +            FUNCTION_MSG("  Feature=DEVICE_REMOTE_WAKEUP\n");
   9.193              /* fake this */
   9.194              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.195              break;
   9.196 @@ -359,45 +359,45 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   9.197          break;
   9.198          break;
   9.199        case BMREQUEST_CLASS: /* Class */
   9.200 -        KdPrint((__DRIVER_NAME "       Type=Class\n"));
   9.201 +        FUNCTION_MSG("  Type=Class\n");
   9.202          switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
   9.203          {
   9.204          case BMREQUEST_TO_OTHER:
   9.205 -          KdPrint((__DRIVER_NAME "       Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte));
   9.206 +          FUNCTION_MSG("  Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
   9.207            switch (urb->UrbControlVendorClassRequest.Value)
   9.208            {
   9.209            case PORT_ENABLE:
   9.210 -            KdPrint((__DRIVER_NAME "        PORT_ENABLE\n"));
   9.211 +            FUNCTION_MSG("   PORT_ENABLE\n");
   9.212              xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status &= ~(1 << PORT_ENABLE);
   9.213              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.214              break;
   9.215            case PORT_SUSPEND:
   9.216 -            KdPrint((__DRIVER_NAME "        PORT_SUSPEND (NOOP)\n"));
   9.217 +            FUNCTION_MSG("   PORT_SUSPEND (NOOP)\n");
   9.218              /* do something here */
   9.219              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.220              break;
   9.221            case C_PORT_CONNECTION:
   9.222 -            KdPrint((__DRIVER_NAME "        C_PORT_CONNECTION\n"));
   9.223 +            FUNCTION_MSG("   C_PORT_CONNECTION\n");
   9.224              xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change &= ~(1 << PORT_CONNECTION);
   9.225              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.226              break;
   9.227            case C_PORT_ENABLE:
   9.228 -            KdPrint((__DRIVER_NAME "        C_PORT_ENABLE\n"));
   9.229 +            FUNCTION_MSG("   C_PORT_ENABLE\n");
   9.230              xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change &= ~(1 << PORT_ENABLE);
   9.231              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.232              break;
   9.233            case C_PORT_RESET:
   9.234 -            KdPrint((__DRIVER_NAME "        C_PORT_RESET\n"));
   9.235 +            FUNCTION_MSG("   C_PORT_RESET\n");
   9.236              xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change &= ~(1 << PORT_RESET);
   9.237              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.238              break;
   9.239            default:
   9.240 -            KdPrint((__DRIVER_NAME "        Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
   9.241 +            FUNCTION_MSG("   Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value);
   9.242              break;
   9.243            }
   9.244 -          KdPrint((__DRIVER_NAME "        status = %04x, change = %04x\n",
   9.245 +          FUNCTION_MSG("   status = %04x, change = %04x\n",
   9.246              xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status,
   9.247 -            xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change));
   9.248 +            xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change);
   9.249            break;
   9.250          default:
   9.251            FUNCTION_MSG(" Recipient=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
   9.252 @@ -405,25 +405,25 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   9.253          }
   9.254          break;
   9.255        default:
   9.256 -        KdPrint((__DRIVER_NAME "       Type=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type));
   9.257 +        FUNCTION_MSG("  Type=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
   9.258          break;
   9.259        }
   9.260        break;
   9.261      case USB_REQUEST_SET_FEATURE:
   9.262 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_SET_FEATURE\n"));
   9.263 -      KdPrint((__DRIVER_NAME "       SetPortFeature\n"));
   9.264 +      FUNCTION_MSG(" USB_REQUEST_SET_FEATURE\n");
   9.265 +      FUNCTION_MSG("  SetPortFeature\n");
   9.266        switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
   9.267        {
   9.268        case 0: /* Standard */
   9.269 -        KdPrint((__DRIVER_NAME "       Type=Standard\n"));
   9.270 +        FUNCTION_MSG("  Type=Standard\n");
   9.271          switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
   9.272          {
   9.273          case BMREQUEST_TO_DEVICE:
   9.274 -          KdPrint((__DRIVER_NAME "       Recipient=Device\n"));
   9.275 +          FUNCTION_MSG("  Recipient=Device\n");
   9.276            switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
   9.277            {
   9.278            case 1: /* DEVICE_REMOTE_WAKEUP */
   9.279 -            KdPrint((__DRIVER_NAME "       Feature=DEVICE_REMOTE_WAKEUP\n"));
   9.280 +            FUNCTION_MSG("  Feature=DEVICE_REMOTE_WAKEUP\n");
   9.281              /* fake this */
   9.282              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.283              break;
   9.284 @@ -438,25 +438,25 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   9.285          }
   9.286          break;
   9.287        case 1: /* Class */
   9.288 -        KdPrint((__DRIVER_NAME "       Type=Class\n"));
   9.289 +        FUNCTION_MSG("  Type=Class\n");
   9.290          switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
   9.291          {
   9.292          case BMREQUEST_TO_OTHER:
   9.293 -          KdPrint((__DRIVER_NAME "       Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte));
   9.294 +          FUNCTION_MSG("  Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
   9.295            switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
   9.296            {
   9.297            case PORT_ENABLE:
   9.298 -            KdPrint((__DRIVER_NAME "        PORT_ENABLE (NOOP)\n"));
   9.299 +            FUNCTION_MSG("   PORT_ENABLE (NOOP)\n");
   9.300              /* do something here */
   9.301              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.302              break;
   9.303            case PORT_SUSPEND:
   9.304 -            KdPrint((__DRIVER_NAME "        PORT_SUSPEND (NOOP)\n"));
   9.305 +            FUNCTION_MSG("   PORT_SUSPEND (NOOP)\n");
   9.306              /* do something here */
   9.307              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.308              break;
   9.309            case PORT_RESET:
   9.310 -            KdPrint((__DRIVER_NAME "        PORT_RESET\n"));
   9.311 +            FUNCTION_MSG("   PORT_RESET\n");
   9.312              /* just fake the reset by setting the status bit to indicate that the reset is complete*/
   9.313              //xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status |= (1 << PORT_RESET);
   9.314              //xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].reset_counter = 10;
   9.315 @@ -469,17 +469,17 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   9.316              XenUsbHub_ProcessHubInterruptEvent(endpoint);
   9.317              break;
   9.318            case PORT_POWER:
   9.319 -            KdPrint((__DRIVER_NAME "        PORT_POWER\n"));
   9.320 +            FUNCTION_MSG("   PORT_POWER\n");
   9.321              xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status |= (1 << PORT_POWER);
   9.322              urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.323              break;
   9.324            default:
   9.325 -            KdPrint((__DRIVER_NAME "        PORT_%04X\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W));
   9.326 +            FUNCTION_MSG("   PORT_%04X\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
   9.327              break;
   9.328            }
   9.329 -          KdPrint((__DRIVER_NAME "        status = %04x, change = %04x\n",
   9.330 +          FUNCTION_MSG("   status = %04x, change = %04x\n",
   9.331              xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
   9.332 -            xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
   9.333 +            xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change);
   9.334            break;
   9.335          default:
   9.336            FUNCTION_MSG(__DRIVER_NAME "       Recipient=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
   9.337 @@ -490,28 +490,28 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   9.338        break;
   9.339      default:
   9.340        FUNCTION_MSG(" USB_REQUEST_%02x\n", (ULONG)decode_data.setup_packet.default_pipe_setup_packet.bRequest);
   9.341 -      KdPrint((__DRIVER_NAME "      TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
   9.342 +      FUNCTION_MSG(" TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength);
   9.343        break;
   9.344      }
   9.345      break;
   9.346    case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
   9.347 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
   9.348 -    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
   9.349 +    FUNCTION_MSG("URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n");
   9.350 +    FUNCTION_MSG(" PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle);
   9.351      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.352      break;
   9.353    case URB_FUNCTION_ABORT_PIPE:
   9.354 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_ABORT_PIPE\n"));
   9.355 -    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
   9.356 +    FUNCTION_MSG("URB_FUNCTION_ABORT_PIPE\n");
   9.357 +    FUNCTION_MSG(" PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle);
   9.358      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   9.359      break;
   9.360    case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
   9.361  #if 0
   9.362 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
   9.363 -    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbBulkOrInterruptTransfer.PipeHandle));
   9.364 -    KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags));
   9.365 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbBulkOrInterruptTransfer.TransferBufferLength));
   9.366 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBuffer));
   9.367 -    KdPrint((__DRIVER_NAME "      TransferBufferMdl = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBufferMDL));
   9.368 +    FUNCTION_MSG("URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n");
   9.369 +    FUNCTION_MSG(" PipeHandle = %p\n", urb->UrbBulkOrInterruptTransfer.PipeHandle);
   9.370 +    FUNCTION_MSG(" TransferFlags = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags);
   9.371 +    FUNCTION_MSG(" TransferBufferLength = %d\n", urb->UrbBulkOrInterruptTransfer.TransferBufferLength);
   9.372 +    FUNCTION_MSG(" TransferBuffer = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBuffer);
   9.373 +    FUNCTION_MSG(" TransferBufferMdl = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBufferMDL);
   9.374  #endif
   9.375      endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
   9.376      //WdfSpinLockAcquire(endpoint->lock);