win-pvdrivers

changeset 342:eabe51317e3a

Suspend works for xenvbd, not for xennet though (eg after a resume you won't have a working network
author James Harper <james.harper@bendigoit.com.au>
date Thu Jun 26 16:55:43 2008 +1000 (2008-06-26)
parents 744c19115142
children 6cfd70daada3
files common/include/xen_public.h xenhide/xenhide.c xenpci/evtchn.c xenpci/xenbus.c xenpci/xenpci.h xenpci/xenpci_fdo.c xenpci/xenpci_pdo.c xenvbd/scsiport.c xenvbd/xenvbd.h
line diff
     1.1 --- a/common/include/xen_public.h	Wed Jun 25 10:26:51 2008 +1000
     1.2 +++ b/common/include/xen_public.h	Thu Jun 26 16:55:43 2008 +1000
     1.3 @@ -115,8 +115,19 @@ typedef struct {
     1.4    PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
     1.5    PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
     1.6    PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
     1.7 +
     1.8  } XENPCI_VECTORS, *PXENPCI_VECTORS;
     1.9  
    1.10 +#define RESUME_STATE_RUNNING            0
    1.11 +#define RESUME_STATE_BACKEND_RESUME     1
    1.12 +#define RESUME_STATE_FRONTEND_RESUME    2
    1.13 +
    1.14 +typedef struct {
    1.15 +  ULONG magic;
    1.16 +  USHORT length;
    1.17 +
    1.18 +  ULONG resume_state;
    1.19 +} XENPCI_DEVICE_STATE, *PXENPCI_DEVICE_STATE;
    1.20  
    1.21  #define XEN_INIT_TYPE_END               0
    1.22  #define XEN_INIT_TYPE_WRITE_STRING      1
    1.23 @@ -129,11 +140,12 @@ typedef struct {
    1.24  #define XEN_INIT_TYPE_GRANT_ENTRIES     8
    1.25  //#define XEN_INIT_TYPE_COPY_PTR          9
    1.26  #define XEN_INIT_TYPE_RUN               10
    1.27 +#define XEN_INIT_TYPE_STATE_PTR         11
    1.28  
    1.29  static __inline VOID
    1.30  __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
    1.31  {
    1.32 -  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
    1.33 +//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
    1.34    *(PUCHAR)(*ptr) = val;
    1.35    *ptr += sizeof(UCHAR);
    1.36  }
    1.37 @@ -141,7 +153,7 @@ static __inline VOID
    1.38  static __inline VOID
    1.39  __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
    1.40  {
    1.41 -  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
    1.42 +//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
    1.43    *(PUSHORT)(*ptr) = val;
    1.44    *ptr += sizeof(USHORT);
    1.45  }
    1.46 @@ -149,7 +161,7 @@ static __inline VOID
    1.47  static __inline VOID
    1.48  __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
    1.49  {
    1.50 -  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
    1.51 +//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
    1.52    *(PULONG)(*ptr) = val;
    1.53    *ptr += sizeof(ULONG);
    1.54  }
    1.55 @@ -157,7 +169,7 @@ static __inline VOID
    1.56  static __inline VOID
    1.57  __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
    1.58  {
    1.59 -  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
    1.60 +//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
    1.61    *(PVOID *)(*ptr) = val;
    1.62    *ptr += sizeof(PVOID);
    1.63  }
    1.64 @@ -165,7 +177,7 @@ static __inline VOID
    1.65  static __inline VOID
    1.66  __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
    1.67  {
    1.68 -  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
    1.69 +//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
    1.70    RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
    1.71    *ptr += strlen(val) + 1;
    1.72  }
    1.73 @@ -175,7 +187,7 @@ static __inline UCHAR
    1.74  {
    1.75    UCHAR retval;
    1.76    retval = **ptr;
    1.77 -  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
    1.78 +//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
    1.79    *ptr += sizeof(UCHAR);
    1.80    return retval;
    1.81  }
    1.82 @@ -185,7 +197,7 @@ static __inline USHORT
    1.83  {
    1.84    USHORT retval;
    1.85    retval = *(PUSHORT)*ptr;
    1.86 -  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
    1.87 +//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
    1.88    *ptr += sizeof(USHORT);
    1.89    return retval;
    1.90  }
    1.91 @@ -195,7 +207,7 @@ static __inline ULONG
    1.92  {
    1.93    ULONG retval;
    1.94    retval = *(PLONG)*ptr;
    1.95 -  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
    1.96 +//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
    1.97    *ptr += sizeof(ULONG);
    1.98    return retval;
    1.99  }
   1.100 @@ -205,7 +217,7 @@ static __inline PCHAR
   1.101  {
   1.102    PCHAR retval;
   1.103    retval = (PCHAR)*ptr;
   1.104 -  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
   1.105 +//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
   1.106    *ptr += strlen((PCHAR)*ptr) + 1;
   1.107    return retval;
   1.108  }
   1.109 @@ -215,7 +227,7 @@ static __inline PVOID
   1.110  {
   1.111    PVOID retval;
   1.112    retval = *(PVOID *)(*ptr);
   1.113 -  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
   1.114 +//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
   1.115    *ptr += sizeof(PVOID);
   1.116    return retval;
   1.117  }
   1.118 @@ -229,6 +241,7 @@ ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type
   1.119    case XEN_INIT_TYPE_END:
   1.120    case XEN_INIT_TYPE_VECTORS:
   1.121    case XEN_INIT_TYPE_RUN:
   1.122 +  case XEN_INIT_TYPE_STATE_PTR:
   1.123      break;
   1.124    case XEN_INIT_TYPE_WRITE_STRING:
   1.125      __ADD_XEN_INIT_STRING(ptr, p1);
   1.126 @@ -261,6 +274,7 @@ GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1,
   1.127    case XEN_INIT_TYPE_END:
   1.128    case XEN_INIT_TYPE_VECTORS:
   1.129    case XEN_INIT_TYPE_RUN:
   1.130 +  case XEN_INIT_TYPE_STATE_PTR:
   1.131      *p1 = NULL;
   1.132      *p2 = NULL;
   1.133      break;
   1.134 @@ -320,6 +334,9 @@ ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type
   1.135      memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
   1.136      *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
   1.137      break;
   1.138 +  case XEN_INIT_TYPE_STATE_PTR:
   1.139 +    __ADD_XEN_INIT_PTR(ptr, p2);
   1.140 +    break;
   1.141  //  case XEN_INIT_TYPE_COPY_PTR:
   1.142  //    __ADD_XEN_INIT_STRING(ptr, p1);
   1.143  //    __ADD_XEN_INIT_PTR(ptr, p2);
   1.144 @@ -370,6 +387,9 @@ GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1,
   1.145      *p2 = *ptr;
   1.146      *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
   1.147      break;
   1.148 +  case XEN_INIT_TYPE_STATE_PTR:
   1.149 +    *p2 = __GET_XEN_INIT_PTR(ptr);
   1.150 +    break;
   1.151  //  case XEN_INIT_TYPE_COPY_PTR:
   1.152  //    *p1 = __GET_XEN_INIT_STRING(ptr);
   1.153  //    *p2 = __GET_XEN_INIT_PTR(ptr);
     2.1 --- a/xenhide/xenhide.c	Wed Jun 25 10:26:51 2008 +1000
     2.2 +++ b/xenhide/xenhide.c	Thu Jun 26 16:55:43 2008 +1000
     2.3 @@ -187,7 +187,7 @@ XenHide_IdSuffixMatches(PDEVICE_OBJECT p
     2.4        
     2.5      if (!NT_SUCCESS(status))
     2.6      {
     2.7 -      KdPrint((__DRIVER_NAME "     i = %d, status = %x, ids_length = %d\n", i, status, ids_length));
     2.8 +      //KdPrint((__DRIVER_NAME "     i = %d, status = %x, ids_length = %d\n", i, status, ids_length));
     2.9        continue;
    2.10      }
    2.11      
    2.12 @@ -201,12 +201,12 @@ XenHide_IdSuffixMatches(PDEVICE_OBJECT p
    2.13          ptr += string_length - wcslen(matching_id);
    2.14          string_length -= wcslen(matching_id);
    2.15        }
    2.16 -      KdPrint((__DRIVER_NAME "     Comparing '%S' and '%S'\n", ptr, matching_id));
    2.17 +      //KdPrint((__DRIVER_NAME "     Comparing '%S' and '%S'\n", ptr, matching_id));
    2.18        if (wcscmp(ptr, matching_id) == 0)
    2.19         return TRUE;
    2.20      }
    2.21    }
    2.22 -  KdPrint((__DRIVER_NAME "     No match\n"));  
    2.23 +  //KdPrint((__DRIVER_NAME "     No match\n"));  
    2.24    return FALSE;
    2.25  }
    2.26  
    2.27 @@ -236,7 +236,7 @@ XenHide_AddDevice(
    2.28      device_description[0] = 0;
    2.29    }
    2.30  
    2.31 -  KdPrint((__DRIVER_NAME "     Checking '%S'\n", device_description));
    2.32 +  //KdPrint((__DRIVER_NAME "     Checking '%S'\n", device_description));
    2.33  
    2.34    length = sizeof(GUID);
    2.35    status = IoGetDeviceProperty(PhysicalDeviceObject, DevicePropertyBusTypeGuid, length, &bus_type, &length);
    2.36 @@ -391,7 +391,7 @@ XenHide_Pnp(PDEVICE_OBJECT device_object
    2.37    ULONG i, j;
    2.38    KIRQL old_irql;
    2.39  
    2.40 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.41 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.42  
    2.43    stack = IoGetCurrentIrpStackLocation(irp);
    2.44  
    2.45 @@ -453,7 +453,7 @@ XenHide_Pnp(PDEVICE_OBJECT device_object
    2.46      break;
    2.47    }
    2.48  
    2.49 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", status));
    2.50 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", status));
    2.51  
    2.52    return status;
    2.53  }
     3.1 --- a/xenpci/evtchn.c	Wed Jun 25 10:26:51 2008 +1000
     3.2 +++ b/xenpci/evtchn.c	Thu Jun 26 16:55:43 2008 +1000
     3.3 @@ -98,15 +98,13 @@ EvtChn_DpcBounce(PRKDPC Dpc, PVOID Conte
     3.4    UNREFERENCED_PARAMETER(SystemArgument1);
     3.5    UNREFERENCED_PARAMETER(SystemArgument2);
     3.6  
     3.7 -if (((PXENPCI_DEVICE_DATA)action->xpdd)->suspending)
     3.8 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
     3.9 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    3.10  
    3.11    if (action->type == EVT_ACTION_TYPE_IRQ)
    3.12      sw_interrupt((UCHAR)action->vector);
    3.13    else
    3.14      action->ServiceRoutine(NULL, action->ServiceContext);
    3.15 -if (((PXENPCI_DEVICE_DATA)action->xpdd)->suspending)
    3.16 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    3.17 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    3.18  }
    3.19  
    3.20  static DDKAPI BOOLEAN
    3.21 @@ -303,10 +301,9 @@ EvtChn_AllocUnbound(PVOID Context, domid
    3.22    return op.port;
    3.23  }
    3.24  
    3.25 -NTSTATUS
    3.26 -EvtChn_Init(PXENPCI_DEVICE_DATA xpdd)
    3.27 +static VOID
    3.28 +EvtChn_Connect(PXENPCI_DEVICE_DATA xpdd)
    3.29  {
    3.30 -  NTSTATUS status;
    3.31    int i;
    3.32  
    3.33    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    3.34 @@ -330,25 +327,6 @@ EvtChn_Init(PXENPCI_DEVICE_DATA xpdd)
    3.35      xpdd->shared_info_area->vcpu_info[i].evtchn_upcall_mask = 1;
    3.36    }
    3.37  
    3.38 -  status = IoConnectInterrupt(
    3.39 -    &xpdd->interrupt,
    3.40 -	EvtChn_Interrupt,
    3.41 -	xpdd,
    3.42 -	NULL,
    3.43 -	xpdd->irq_vector,
    3.44 -	xpdd->irq_level,
    3.45 -	xpdd->irq_level,
    3.46 -	LevelSensitive,
    3.47 -	TRUE, /* this is a bit of a hack to make xenvbd work */
    3.48 -	xpdd->irq_affinity,
    3.49 -	FALSE);
    3.50 -  
    3.51 -  if (!NT_SUCCESS(status))
    3.52 -  {
    3.53 -    KdPrint((__DRIVER_NAME "     IoConnectInterrupt failed 0x%08x\n", status));
    3.54 -    return status;
    3.55 -  }
    3.56 -
    3.57    hvm_set_parameter(xpdd, HVM_PARAM_CALLBACK_IRQ, xpdd->irq_number);
    3.58  
    3.59    for (i = 0; i < MAX_VIRT_CPUS; i++)
    3.60 @@ -356,11 +334,43 @@ EvtChn_Init(PXENPCI_DEVICE_DATA xpdd)
    3.61      xpdd->shared_info_area->vcpu_info[i].evtchn_upcall_mask = 0;
    3.62    }
    3.63    
    3.64 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    3.65 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    3.66 +}
    3.67  
    3.68 +NTSTATUS
    3.69 +EvtChn_Init(PXENPCI_DEVICE_DATA xpdd)
    3.70 +{
    3.71 +  NTSTATUS status;
    3.72 +  
    3.73 +  EvtChn_Connect(xpdd);
    3.74 +  
    3.75 +  status = IoConnectInterrupt(
    3.76 +    &xpdd->interrupt,
    3.77 +  	EvtChn_Interrupt,
    3.78 +  	xpdd,
    3.79 +  	NULL,
    3.80 +  	xpdd->irq_vector,
    3.81 +  	xpdd->irq_level,
    3.82 +  	xpdd->irq_level,
    3.83 +  	LevelSensitive,
    3.84 +  	TRUE,
    3.85 +  	xpdd->irq_affinity,
    3.86 +  	FALSE);
    3.87 +  
    3.88 +  if (!NT_SUCCESS(status))
    3.89 +  {
    3.90 +    KdPrint((__DRIVER_NAME "     IoConnectInterrupt failed 0x%08x\n", status));
    3.91 +    return status;
    3.92 +  }
    3.93    return status;
    3.94  }
    3.95  
    3.96 +VOID
    3.97 +EvtChn_Resume(PXENPCI_DEVICE_DATA xpdd)
    3.98 +{
    3.99 +  EvtChn_Connect(xpdd);
   3.100 +}
   3.101 +
   3.102  NTSTATUS
   3.103  EvtChn_Shutdown(PXENPCI_DEVICE_DATA xpdd)
   3.104  {
     4.1 --- a/xenpci/xenbus.c	Wed Jun 25 10:26:51 2008 +1000
     4.2 +++ b/xenpci/xenbus.c	Thu Jun 26 16:55:43 2008 +1000
     4.3 @@ -41,8 +41,7 @@ static int allocate_xenbus_id(PXENPCI_DE
     4.4    static int probe;
     4.5    int o_probe;
     4.6  
     4.7 -if (xpdd->suspending)
     4.8 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
     4.9 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.10  
    4.11    for (;;)
    4.12    {
    4.13 @@ -69,8 +68,7 @@ if (xpdd->suspending)
    4.14    //init_waitqueue_head(&req_info[o_probe].waitq);
    4.15    KeInitializeEvent(&xpdd->req_info[o_probe].WaitEvent, SynchronizationEvent, FALSE);
    4.16  
    4.17 -if (xpdd->suspending)
    4.18 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.19 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.20  
    4.21    return o_probe;
    4.22  }
    4.23 @@ -138,8 +136,7 @@ static void xb_write(
    4.24    struct xsd_sockmsg m = {type, req_id, trans_id };
    4.25    struct write_req header_req = { &m, sizeof(m) };
    4.26  
    4.27 -if (xpdd->suspending)
    4.28 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.29 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.30  
    4.31    for (r = 0; r < nr_reqs; r++)
    4.32      len += (size_t)req[r].len;
    4.33 @@ -204,8 +201,7 @@ if (xpdd->suspending)
    4.34    /* Send evtchn to notify remote */
    4.35    EvtChn_Notify(xpdd, xpdd->xen_store_evtchn);
    4.36  
    4.37 -if (xpdd->suspending)
    4.38 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.39 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.40  }
    4.41  
    4.42  static struct xsd_sockmsg *
    4.43 @@ -218,8 +214,7 @@ xenbus_msg_reply(
    4.44  {
    4.45    int id;
    4.46  
    4.47 -if (xpdd->suspending)
    4.48 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.49 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.50  
    4.51    id = allocate_xenbus_id(xpdd);
    4.52  
    4.53 @@ -229,8 +224,7 @@ if (xpdd->suspending)
    4.54  
    4.55    release_xenbus_id(xpdd, id);
    4.56  
    4.57 -if (xpdd->suspending)
    4.58 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.59 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.60  
    4.61    return xpdd->req_info[id].Reply;
    4.62  }
    4.63 @@ -248,8 +242,7 @@ XenBus_Read(
    4.64    char *res;
    4.65    char *msg;
    4.66  
    4.67 -if (xpdd->suspending)
    4.68 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.69 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.70  
    4.71    ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
    4.72  
    4.73 @@ -265,8 +258,7 @@ if (xpdd->suspending)
    4.74    ExFreePoolWithTag(rep, XENPCI_POOL_TAG);
    4.75    *value = res;
    4.76  
    4.77 -if (xpdd->suspending)
    4.78 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.79 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.80  
    4.81    return NULL;
    4.82  }
    4.83 @@ -288,8 +280,7 @@ XenBus_Write(
    4.84    struct xsd_sockmsg *rep;
    4.85    char *msg;
    4.86  
    4.87 -if (xpdd->suspending)
    4.88 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.89 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.90  
    4.91    ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
    4.92  
    4.93 @@ -299,17 +290,28 @@ if (xpdd->suspending)
    4.94      return msg;
    4.95    ExFreePoolWithTag(rep, XENPCI_POOL_TAG);
    4.96  
    4.97 -if (xpdd->suspending)
    4.98 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.99 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   4.100  
   4.101    return NULL;
   4.102  }
   4.103  
   4.104 +static VOID
   4.105 +XenBus_Connect(PXENPCI_DEVICE_DATA xpdd)
   4.106 +{
   4.107 +  PHYSICAL_ADDRESS pa_xen_store_interface;
   4.108 +  xen_ulong_t xen_store_mfn;
   4.109 +
   4.110 +  xpdd->xen_store_evtchn = (evtchn_port_t)hvm_get_parameter(xpdd, HVM_PARAM_STORE_EVTCHN);
   4.111 +  xen_store_mfn = (xen_ulong_t)hvm_get_parameter(xpdd, HVM_PARAM_STORE_PFN);
   4.112 +  pa_xen_store_interface.QuadPart = (ULONGLONG)xen_store_mfn << PAGE_SHIFT;
   4.113 +  xpdd->xen_store_interface = MmMapIoSpace(pa_xen_store_interface, PAGE_SIZE, MmNonCached);
   4.114 +
   4.115 +  EvtChn_BindDpc(xpdd, xpdd->xen_store_evtchn, XenBus_Interrupt, xpdd);
   4.116 +}
   4.117 +
   4.118  NTSTATUS
   4.119  XenBus_Init(PXENPCI_DEVICE_DATA xpdd)
   4.120  {
   4.121 -  PHYSICAL_ADDRESS pa_xen_store_interface;
   4.122 -  xen_ulong_t xen_store_mfn;
   4.123    NTSTATUS Status;
   4.124    int i;
   4.125      
   4.126 @@ -319,12 +321,6 @@ XenBus_Init(PXENPCI_DEVICE_DATA xpdd)
   4.127  
   4.128    KeInitializeSpinLock(&xpdd->WatchLock);
   4.129  
   4.130 -  xpdd->xen_store_evtchn = (evtchn_port_t)hvm_get_parameter(xpdd, HVM_PARAM_STORE_EVTCHN);
   4.131 -
   4.132 -  xen_store_mfn = (xen_ulong_t)hvm_get_parameter(xpdd, HVM_PARAM_STORE_PFN);
   4.133 -  pa_xen_store_interface.QuadPart = (ULONGLONG)xen_store_mfn << PAGE_SHIFT;
   4.134 -  xpdd->xen_store_interface = MmMapIoSpace(pa_xen_store_interface, PAGE_SIZE, MmNonCached);
   4.135 -
   4.136    for (i = 0; i < MAX_WATCH_ENTRIES; i++)
   4.137    {
   4.138      xpdd->XenBus_WatchEntries[i].Active = 0;
   4.139 @@ -350,8 +346,8 @@ XenBus_Init(PXENPCI_DEVICE_DATA xpdd)
   4.140      return STATUS_UNSUCCESSFUL;
   4.141    }
   4.142  
   4.143 -  EvtChn_BindDpc(xpdd, xpdd->xen_store_evtchn, XenBus_Interrupt, xpdd);
   4.144 -
   4.145 +  XenBus_Connect(xpdd);
   4.146 +  
   4.147  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   4.148  
   4.149    return STATUS_SUCCESS;
   4.150 @@ -602,14 +598,15 @@ XenBus_SendAddWatch(
   4.151    return msg;
   4.152  }
   4.153  
   4.154 +/* called at PASSIVE_LEVEL */
   4.155  VOID
   4.156  XenBus_Resume(PXENPCI_DEVICE_DATA xpdd)
   4.157  {
   4.158    int i;
   4.159  
   4.160    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   4.161 -  
   4.162 -  hvm_set_parameter(xpdd, HVM_PARAM_CALLBACK_IRQ, xpdd->irq_number);
   4.163 +
   4.164 +  XenBus_Connect(xpdd);
   4.165    
   4.166    for (i = 0; i < MAX_WATCH_ENTRIES; i++)
   4.167    {
     5.1 --- a/xenpci/xenpci.h	Wed Jun 25 10:26:51 2008 +1000
     5.2 +++ b/xenpci/xenpci.h	Thu Jun 26 16:55:43 2008 +1000
     5.3 @@ -245,8 +245,11 @@ typedef struct {
     5.4    ULONG backend_state;
     5.5    PHYSICAL_ADDRESS config_page_phys;
     5.6    ULONG config_page_length;
     5.7 +  PUCHAR requested_resources_start;
     5.8 +  PUCHAR requested_resources_ptr;
     5.9    PUCHAR assigned_resources_start;
    5.10    PUCHAR assigned_resources_ptr;
    5.11 +  XENPCI_DEVICE_STATE device_state;
    5.12  } XENPCI_PDO_DEVICE_DATA, *PXENPCI_PDO_DEVICE_DATA;
    5.13  
    5.14  typedef struct
    5.15 @@ -358,7 +361,8 @@ XenPci_Irp_Read_Pdo(PDEVICE_OBJECT devic
    5.16  NTSTATUS
    5.17  XenPci_Irp_Cleanup_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
    5.18  
    5.19 -
    5.20 +NTSTATUS
    5.21 +XenPci_Resume(PDEVICE_OBJECT device_object);
    5.22  
    5.23  char *
    5.24  XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
    5.25 @@ -394,6 +398,8 @@ XenPci_AllocMMIO(PXENPCI_DEVICE_DATA xpd
    5.26  
    5.27  NTSTATUS
    5.28  EvtChn_Init(PXENPCI_DEVICE_DATA xpdd);
    5.29 +VOID
    5.30 +EvtChn_Resume(PXENPCI_DEVICE_DATA xpdd);
    5.31  NTSTATUS
    5.32  EvtChn_Shutdown(PXENPCI_DEVICE_DATA xpdd);
    5.33  
     6.1 --- a/xenpci/xenpci_fdo.c	Wed Jun 25 10:26:51 2008 +1000
     6.2 +++ b/xenpci/xenpci_fdo.c	Thu Jun 26 16:55:43 2008 +1000
     6.3 @@ -305,6 +305,7 @@ static VOID
     6.4  XenPci_CompleteResume(PDEVICE_OBJECT device_object, PVOID context)
     6.5  {
     6.6    PXENPCI_DEVICE_DATA xpdd;
     6.7 +  PXEN_CHILD child;
     6.8  
     6.9    UNREFERENCED_PARAMETER(context);
    6.10    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    6.11 @@ -313,6 +314,13 @@ XenPci_CompleteResume(PDEVICE_OBJECT dev
    6.12  
    6.13    XenBus_Resume(xpdd);
    6.14  
    6.15 +  for (child = (PXEN_CHILD)xpdd->child_list.Flink; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
    6.16 +  {
    6.17 +    XenPci_Resume(child->context->common.pdo);
    6.18 +    child->context->device_state.resume_state = RESUME_STATE_FRONTEND_RESUME;
    6.19 +    // how can we signal children that they are ready to restart again?
    6.20 +  }
    6.21 +
    6.22    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    6.23  }
    6.24  
    6.25 @@ -335,6 +343,8 @@ XenPci_Suspend(
    6.26    int cancelled;
    6.27    int i;
    6.28    PIO_WORKITEM work_item;
    6.29 +  PXEN_CHILD child;
    6.30 +  //PUCHAR gnttbl_backup[PAGE_SIZE * NR_GRANT_FRAMES];
    6.31  
    6.32    UNREFERENCED_PARAMETER(Dpc);
    6.33    UNREFERENCED_PARAMETER(SystemArgument2);
    6.34 @@ -369,13 +379,25 @@ XenPci_Suspend(
    6.35    }
    6.36    KdPrint((__DRIVER_NAME "     all other processors are spinning\n"));
    6.37  
    6.38 +  // make a backup of the grant table - we are going to keep it instead of throwing it away
    6.39 +  //memcpy(gnttbl_backup, xpdd->gnttab_table, PAGE_SIZE * NR_GRANT_FRAMES);
    6.40 +
    6.41    KdPrint((__DRIVER_NAME "     calling suspend\n"));
    6.42    cancelled = hvm_shutdown(Context, SHUTDOWN_suspend);
    6.43    KdPrint((__DRIVER_NAME "     back from suspend, cancelled = %d\n", cancelled));
    6.44  
    6.45    XenPci_Init(xpdd);
    6.46 +  
    6.47 +  GntTbl_Map(Context, 0, NR_GRANT_FRAMES - 1);
    6.48 +  
    6.49 +  EvtChn_Resume(xpdd);
    6.50  
    6.51 -  GntTbl_Map(Context, 0, NR_GRANT_FRAMES - 1);
    6.52 +  //memcpy(xpdd->gnttab_table, gnttbl_backup, PAGE_SIZE * NR_GRANT_FRAMES);
    6.53 +
    6.54 +  for (child = (PXEN_CHILD)xpdd->child_list.Flink; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
    6.55 +  {
    6.56 +    child->context->device_state.resume_state = RESUME_STATE_BACKEND_RESUME;
    6.57 +  }
    6.58  
    6.59    KeLowerIrql(old_irql);
    6.60    
    6.61 @@ -426,6 +448,7 @@ XenPci_BeginSuspend(PXENPCI_DEVICE_DATA 
    6.62      {
    6.63        xpdd->shared_info_area->vcpu_info[i].evtchn_upcall_mask = 1;
    6.64      }
    6.65 +    KeMemoryBarrier();
    6.66      KeFlushQueuedDpcs();
    6.67  
    6.68      //ActiveProcessorCount = KeQueryActiveProcessorCount(&ActiveProcessorMask); // this is for Vista+
     7.1 --- a/xenpci/xenpci_pdo.c	Wed Jun 25 10:26:51 2008 +1000
     7.2 +++ b/xenpci/xenpci_pdo.c	Thu Jun 26 16:55:43 2008 +1000
     7.3 @@ -411,7 +411,10 @@ XenPci_XenShutdownDevice(PVOID Context)
     7.4  }
     7.5  
     7.6  static NTSTATUS
     7.7 -XenPci_XenConfigDevice(PVOID context)
     7.8 +XenPci_XenConfigDevice(PVOID context);
     7.9 +
    7.10 +static NTSTATUS
    7.11 +XenPci_XenConfigDeviceSpecifyBuffers(PVOID context, PUCHAR src, PUCHAR dst)
    7.12  {
    7.13    PXENPCI_PDO_DEVICE_DATA xppdd = context;
    7.14    PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
    7.15 @@ -422,20 +425,20 @@ XenPci_XenConfigDevice(PVOID context)
    7.16    PCHAR res;
    7.17    PVOID address;
    7.18    UCHAR type;
    7.19 -  PUCHAR in_ptr, in_start;
    7.20 -  PUCHAR out_ptr, out_start;
    7.21 +  PUCHAR in_ptr; //, in_start;
    7.22 +  PUCHAR out_ptr; //, out_start;
    7.23    XENPCI_VECTORS vectors;
    7.24    ULONG event_channel;
    7.25    BOOLEAN run = FALSE;
    7.26    PMDL ring;
    7.27    grant_ref_t gref;
    7.28 +  BOOLEAN done_xenbus_init = FALSE;
    7.29   
    7.30    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    7.31  
    7.32 -  out_ptr = out_start = MmMapIoSpace(xppdd->config_page_phys, xppdd->config_page_length, MmNonCached);
    7.33 -  in_ptr = in_start = ExAllocatePoolWithTag(PagedPool, xppdd->config_page_length, XENPCI_POOL_TAG);
    7.34 -  memcpy(in_ptr, out_ptr, xppdd->config_page_length);
    7.35 -
    7.36 +  in_ptr = src;
    7.37 +  out_ptr = dst;
    7.38 +  
    7.39    // always add vectors
    7.40    vectors.magic = XEN_DATA_MAGIC;
    7.41    vectors.length = sizeof(XENPCI_VECTORS);
    7.42 @@ -453,10 +456,23 @@ XenPci_XenConfigDevice(PVOID context)
    7.43    vectors.XenPci_XenConfigDevice = XenPci_XenConfigDevice;
    7.44    vectors.XenPci_XenShutdownDevice = XenPci_XenShutdownDevice;
    7.45    ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_VECTORS, NULL, &vectors);
    7.46 +  ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_STATE_PTR, NULL, &xppdd->device_state);
    7.47  
    7.48    // first pass, possibly before state == Connected
    7.49    while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
    7.50    {
    7.51 +    if (!done_xenbus_init)
    7.52 +    {
    7.53 +      if (XenPci_ChangeFrontendState(xppdd, XenbusStateInitialising, XenbusStateInitWait, 30000) != STATUS_SUCCESS)
    7.54 +      {
    7.55 +        status = STATUS_UNSUCCESSFUL;
    7.56 +        goto error;
    7.57 +      }
    7.58 +      done_xenbus_init = TRUE;
    7.59 +    }
    7.60 +    
    7.61 +    ADD_XEN_INIT_REQ(&xppdd->requested_resources_ptr, type, setting, value);
    7.62 +
    7.63      switch (type)
    7.64      {
    7.65      case XEN_INIT_TYPE_RUN:
    7.66 @@ -527,14 +543,17 @@ XenPci_XenConfigDevice(PVOID context)
    7.67    {
    7.68      goto error;
    7.69    }
    7.70 -  if (run && XenPci_ChangeFrontendState(xppdd, XenbusStateConnected, XenbusStateConnected, 30000) != STATUS_SUCCESS)
    7.71 +  if (run)
    7.72    {
    7.73 -    status = STATUS_UNSUCCESSFUL;
    7.74 -    goto error;
    7.75 +    if (XenPci_ChangeFrontendState(xppdd, XenbusStateConnected, XenbusStateConnected, 30000) != STATUS_SUCCESS)
    7.76 +    {
    7.77 +      status = STATUS_UNSUCCESSFUL;
    7.78 +      goto error;
    7.79 +    }
    7.80    }
    7.81  
    7.82    // second pass, possibly after state == Connected
    7.83 -  in_ptr = in_start;
    7.84 +  in_ptr = src;
    7.85    while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
    7.86    {
    7.87      switch(type)
    7.88 @@ -578,35 +597,47 @@ XenPci_XenConfigDevice(PVOID context)
    7.89    }
    7.90  
    7.91  error:
    7.92 -  ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_END, NULL, NULL);
    7.93 -  MmUnmapIoSpace(out_start, xppdd->config_page_length);
    7.94 -  ExFreePoolWithTag(in_start, XENPCI_POOL_TAG);
    7.95 -
    7.96    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (%08x\n", status));
    7.97  
    7.98    return status;
    7.99  }
   7.100  
   7.101  static NTSTATUS
   7.102 -XenPci_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
   7.103 +XenPci_XenConfigDevice(PVOID context)
   7.104  {
   7.105 -  NTSTATUS status = STATUS_SUCCESS;
   7.106 +  NTSTATUS status;
   7.107 +  PUCHAR src, dst;
   7.108 +  PXENPCI_PDO_DEVICE_DATA xppdd = context;  
   7.109 +
   7.110 +  src = ExAllocatePoolWithTag(PagedPool, xppdd->config_page_length, XENPCI_POOL_TAG);
   7.111 +  dst = MmMapIoSpace(xppdd->config_page_phys, xppdd->config_page_length, MmNonCached);
   7.112 +  memcpy(src, dst, xppdd->config_page_length);
   7.113 +  
   7.114 +  status = XenPci_XenConfigDeviceSpecifyBuffers(xppdd, src, dst);
   7.115 +
   7.116 +  MmUnmapIoSpace(dst, xppdd->config_page_length);
   7.117 +  ExFreePoolWithTag(src, XENPCI_POOL_TAG);
   7.118 +  
   7.119 +  return status;
   7.120 +}
   7.121 +
   7.122 +static NTSTATUS
   7.123 +XenPci_GetBackendAndAddWatch(PDEVICE_OBJECT device_object)
   7.124 +{
   7.125    PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
   7.126    PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   7.127 -  PIO_STACK_LOCATION stack;
   7.128 -  PCM_PARTIAL_RESOURCE_LIST prl;
   7.129 -  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
   7.130 -  ULONG i;
   7.131    char path[128];
   7.132 -  PCHAR value;
   7.133    PCHAR res;
   7.134 - 
   7.135 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.136 +  PCHAR value;
   7.137  
   7.138 -  DUMP_CURRENT_PNP_STATE(xppdd);
   7.139 +  if (strlen(xppdd->backend_path) != 0)
   7.140 +  {
   7.141 +    // this must be the restore path - remove the existing watch
   7.142 +    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
   7.143 +    KdPrint((__DRIVER_NAME "    Removing old watch on %s\n", path));
   7.144 +    XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
   7.145 +  }
   7.146    
   7.147 -  stack = IoGetCurrentIrpStackLocation(irp);
   7.148 -
   7.149    /* Get backend path */
   7.150    RtlStringCbPrintfA(path, ARRAY_SIZE(path),
   7.151      "%s/backend", xppdd->path);
   7.152 @@ -624,12 +655,84 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
   7.153    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
   7.154    XenBus_AddWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
   7.155  
   7.156 -  if (XenPci_ChangeFrontendState(xppdd, XenbusStateInitialising, XenbusStateInitWait, 30000) != STATUS_SUCCESS)
   7.157 +  return STATUS_SUCCESS;
   7.158 +}
   7.159 +
   7.160 +NTSTATUS
   7.161 +XenPci_Resume(PDEVICE_OBJECT device_object)
   7.162 +{
   7.163 +  NTSTATUS status;
   7.164 +  PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
   7.165 +  //PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   7.166 +  //PUCHAR in_ptr;
   7.167 +  //UCHAR type;
   7.168 +  //PVOID setting;
   7.169 +  //PVOID value;
   7.170 +  //CHAR path[256];
   7.171 +  //PVOID address;
   7.172 +  ULONG old_backend_state;
   7.173 +  PUCHAR src, dst;
   7.174 +
   7.175 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.176 +
   7.177 +  old_backend_state = xppdd->backend_state;
   7.178 +  status = XenPci_GetBackendAndAddWatch(device_object);
   7.179 +  if (!NT_SUCCESS(status))
   7.180 +    return status;
   7.181 +  
   7.182 +  if (xppdd->common.current_pnp_state == Started && old_backend_state == XenbusStateConnected)
   7.183    {
   7.184 -    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
   7.185 -    XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
   7.186 -    return STATUS_UNSUCCESSFUL;
   7.187 +  
   7.188 +    if (XenPci_ChangeFrontendState(xppdd, XenbusStateInitialising, XenbusStateInitWait, 30000) != STATUS_SUCCESS)
   7.189 +    {
   7.190 +      // this is probably an unrecoverable situation...
   7.191 +      return STATUS_UNSUCCESSFUL;
   7.192 +    }
   7.193 +    if (xppdd->assigned_resources_ptr)
   7.194 +    {
   7.195 +      // reset things - feed the 'requested resources' back in
   7.196 +      ADD_XEN_INIT_RSP(&xppdd->requested_resources_ptr, XEN_INIT_TYPE_END, NULL, NULL);
   7.197 +      src = xppdd->requested_resources_start;
   7.198 +      xppdd->requested_resources_ptr = xppdd->requested_resources_start = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, XENPCI_POOL_TAG);;
   7.199 +      xppdd->assigned_resources_ptr = xppdd->assigned_resources_start;
   7.200 +      
   7.201 +      dst = MmMapIoSpace(xppdd->config_page_phys, xppdd->config_page_length, MmNonCached);
   7.202 +      
   7.203 +      status = XenPci_XenConfigDeviceSpecifyBuffers(xppdd, src, dst);
   7.204 +
   7.205 +      MmUnmapIoSpace(dst, xppdd->config_page_length);
   7.206 +      ExFreePoolWithTag(src, XENPCI_POOL_TAG);
   7.207 +    }
   7.208 +    if (XenPci_ChangeFrontendState(xppdd, XenbusStateConnected, XenbusStateConnected, 30000) != STATUS_SUCCESS)
   7.209 +    {
   7.210 +      // this is definitely an unrecoverable situation...
   7.211 +      return STATUS_UNSUCCESSFUL;
   7.212 +    }
   7.213    }
   7.214 +  return STATUS_SUCCESS;
   7.215 +} 
   7.216 +
   7.217 +static NTSTATUS
   7.218 +XenPci_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
   7.219 +{
   7.220 +  NTSTATUS status = STATUS_SUCCESS;
   7.221 +  PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
   7.222 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   7.223 +  PIO_STACK_LOCATION stack;
   7.224 +  PCM_PARTIAL_RESOURCE_LIST prl;
   7.225 +  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
   7.226 +  ULONG i;
   7.227 +  char path[128];
   7.228 + 
   7.229 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.230 +
   7.231 +  DUMP_CURRENT_PNP_STATE(xppdd);
   7.232 +  
   7.233 +  stack = IoGetCurrentIrpStackLocation(irp);
   7.234 +
   7.235 +  status = XenPci_GetBackendAndAddWatch(device_object);
   7.236 +  if (!NT_SUCCESS(status))
   7.237 +    return status;
   7.238  
   7.239    prl = &stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
   7.240    for (i = 0; i < prl->Count; i++)
   7.241 @@ -649,8 +752,11 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
   7.242        KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
   7.243        xppdd->config_page_phys = prd->u.Memory.Start;
   7.244        xppdd->config_page_length = prd->u.Memory.Length;
   7.245 +      xppdd->requested_resources_start = xppdd->requested_resources_ptr = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
   7.246        xppdd->assigned_resources_start = xppdd->assigned_resources_ptr = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
   7.247 +      
   7.248        status = XenPci_XenConfigDevice(xppdd);
   7.249 +
   7.250        if (!NT_SUCCESS(status))
   7.251        {
   7.252          RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
   7.253 @@ -819,7 +925,7 @@ XenPci_Pnp_Pdo(PDEVICE_OBJECT device_obj
   7.254    PPNP_BUS_INFORMATION pbi;
   7.255    ULONG *usage_type;
   7.256  
   7.257 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.258 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.259  
   7.260    stack = IoGetCurrentIrpStackLocation(irp);
   7.261  
   7.262 @@ -1060,7 +1166,7 @@ XenPci_Pnp_Pdo(PDEVICE_OBJECT device_obj
   7.263      break;
   7.264        
   7.265    default:
   7.266 -    KdPrint((__DRIVER_NAME "     Unhandled Minor = %d, Status = %08x\n", stack->MinorFunction, irp->IoStatus.Status));
   7.267 +    //KdPrint((__DRIVER_NAME "     Unhandled Minor = %d, Status = %08x\n", stack->MinorFunction, irp->IoStatus.Status));
   7.268      status = irp->IoStatus.Status;
   7.269      break;
   7.270    }
   7.271 @@ -1068,7 +1174,7 @@ XenPci_Pnp_Pdo(PDEVICE_OBJECT device_obj
   7.272    irp->IoStatus.Status = status;
   7.273    IoCompleteRequest(irp, IO_NO_INCREMENT);
   7.274  
   7.275 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   7.276 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   7.277  
   7.278    return status;
   7.279  }
     8.1 --- a/xenvbd/scsiport.c	Wed Jun 25 10:26:51 2008 +1000
     8.2 +++ b/xenvbd/scsiport.c	Thu Jun 26 16:55:43 2008 +1000
     8.3 @@ -90,72 +90,40 @@ XenVbd_GetResponse(PXENVBD_DEVICE_DATA x
     8.4  }
     8.5  
     8.6  static VOID
     8.7 -XenVbd_HwScsiTimer(PVOID DeviceExtension)
     8.8 +XenVbd_PutRequest(PXENVBD_DEVICE_DATA xvdd, blkif_request_t *req)
     8.9  {
    8.10 -  PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
    8.11 +  blkif_other_request_t *other_req;
    8.12  
    8.13 -  KdPrint((__DRIVER_NAME "     aligned requests   = %I64d, aligned bytes   = %I64d\n", xvdd->aligned_requests, xvdd->aligned_bytes));
    8.14 -  KdPrint((__DRIVER_NAME "     unaligned requests = %I64d, unaligned bytes = %I64d\n", xvdd->unaligned_requests, xvdd->unaligned_bytes));
    8.15 -  KdPrint((__DRIVER_NAME "     interrupts = %I64d\n", xvdd->interrupts));
    8.16 -  KdPrint((__DRIVER_NAME "     no_free_grant_requests = %I64d\n", xvdd->no_free_grant_requests));
    8.17 -  xvdd->shadow_min_free = xvdd->shadow_free;
    8.18 -  ScsiPortNotification(RequestTimerCall, DeviceExtension, XenVbd_HwScsiTimer, 60 * 1000 * 1000);
    8.19 +  if (!xvdd->use_other)
    8.20 +  {
    8.21 +    *RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt) = *req;
    8.22 +  }
    8.23 +  else
    8.24 +  {  
    8.25 +    other_req = RING_GET_REQUEST(&xvdd->other_ring, xvdd->ring.req_prod_pvt);
    8.26 +    other_req->operation = req->operation;
    8.27 +    other_req->nr_segments = req->nr_segments;
    8.28 +    other_req->handle = req->handle;
    8.29 +    other_req->id = req->id;
    8.30 +    other_req->sector_number = req->sector_number;
    8.31 +    memcpy(other_req->seg, req->seg, sizeof(struct blkif_request_segment) * req->nr_segments);
    8.32 +  }
    8.33 +  xvdd->ring.req_prod_pvt++;
    8.34  }
    8.35  
    8.36  static ULONG
    8.37 -XenVbd_HwScsiFindAdapter(PVOID DeviceExtension, PVOID HwContext, PVOID BusInformation, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PBOOLEAN Again)
    8.38 +XenVbd_InitFromConfig(PXENVBD_DEVICE_DATA xvdd)
    8.39  {
    8.40    ULONG i;
    8.41 -//  PACCESS_RANGE AccessRange;
    8.42 -  PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
    8.43 -//  ULONG status;
    8.44 -//  PXENPCI_XEN_DEVICE_DATA XenDeviceData;
    8.45 -  PACCESS_RANGE access_range;
    8.46    PUCHAR ptr;
    8.47    USHORT type;
    8.48    PCHAR setting, value;
    8.49 -  blkif_sring_t *sring;
    8.50 -
    8.51 -  UNREFERENCED_PARAMETER(HwContext);
    8.52 -  UNREFERENCED_PARAMETER(BusInformation);
    8.53 -  UNREFERENCED_PARAMETER(ArgumentString);
    8.54 -
    8.55 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));  
    8.56 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    8.57 -
    8.58 -  *Again = FALSE;
    8.59 -
    8.60 -  KdPrint((__DRIVER_NAME "     BusInterruptLevel = %d\n", ConfigInfo->BusInterruptLevel));
    8.61 -  KdPrint((__DRIVER_NAME "     BusInterruptVector = %03x\n", ConfigInfo->BusInterruptVector));
    8.62 -
    8.63 -  if (ConfigInfo->NumberOfAccessRanges != 1)
    8.64 -  {
    8.65 -    KdPrint((__DRIVER_NAME "     NumberOfAccessRanges = %d\n", ConfigInfo->NumberOfAccessRanges));    
    8.66 -    return SP_RETURN_BAD_CONFIG;
    8.67 -  }
    8.68 -
    8.69 -  access_range = &((*(ConfigInfo->AccessRanges))[0]);
    8.70 -
    8.71 -  KdPrint((__DRIVER_NAME "     RangeStart = %08x, RangeLength = %08x\n",
    8.72 -    access_range->RangeStart.LowPart, access_range->RangeLength));
    8.73 -
    8.74 -  ptr = ScsiPortGetDeviceBase(
    8.75 -    DeviceExtension,
    8.76 -    ConfigInfo->AdapterInterfaceType,
    8.77 -    ConfigInfo->SystemIoBusNumber,
    8.78 -    access_range->RangeStart,
    8.79 -    access_range->RangeLength,
    8.80 -    !access_range->RangeInMemory);
    8.81 -  if (ptr == NULL)
    8.82 -  {
    8.83 -    KdPrint((__DRIVER_NAME "     Unable to map range\n"));
    8.84 -    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
    8.85 -    return SP_RETURN_BAD_CONFIG;
    8.86 -  }
    8.87  
    8.88    xvdd->device_type = XENVBD_DEVICETYPE_UNKNOWN;
    8.89 -  sring = NULL;
    8.90 +  xvdd->sring = NULL;
    8.91    xvdd->event_channel = 0;
    8.92 +  
    8.93 +  ptr = xvdd->device_base;
    8.94    while((type = GET_XEN_INIT_RSP(&ptr, &setting, &value)) != XEN_INIT_TYPE_END)
    8.95    {
    8.96      switch(type)
    8.97 @@ -164,11 +132,11 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
    8.98        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
    8.99        if (strcmp(setting, "ring-ref") == 0)
   8.100        {
   8.101 -        sring = (blkif_sring_t *)value;
   8.102 -        FRONT_RING_INIT(&xvdd->ring, sring, PAGE_SIZE);
   8.103 +        xvdd->sring = (blkif_sring_t *)value;
   8.104 +        FRONT_RING_INIT(&xvdd->ring, xvdd->sring, PAGE_SIZE);
   8.105          /* this bit is for when we have to take over an existing ring on a bug check */
   8.106 -        xvdd->ring.req_prod_pvt = sring->req_prod;
   8.107 -        xvdd->ring.rsp_cons = sring->rsp_prod;
   8.108 +        xvdd->ring.req_prod_pvt = xvdd->sring->req_prod;
   8.109 +        xvdd->ring.rsp_cons = xvdd->sring->rsp_prod;
   8.110        }
   8.111        break;
   8.112      case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
   8.113 @@ -224,13 +192,17 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
   8.114        memcpy(&xvdd->grant_free_list, value, sizeof(grant_ref_t) * xvdd->grant_entries);
   8.115        xvdd->grant_free = xvdd->grant_entries;
   8.116        break;
   8.117 +    case XEN_INIT_TYPE_STATE_PTR:
   8.118 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
   8.119 +      xvdd->device_state = (PXENPCI_DEVICE_STATE)value;
   8.120 +      break;
   8.121      default:
   8.122        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   8.123        break;
   8.124      }
   8.125    }
   8.126    if (xvdd->device_type == XENVBD_DEVICETYPE_UNKNOWN
   8.127 -    || sring == NULL
   8.128 +    || xvdd->sring == NULL
   8.129      || xvdd->event_channel == 0
   8.130      || xvdd->total_sectors == 0
   8.131      || xvdd->bytes_per_sector == 0)
   8.132 @@ -239,32 +211,9 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
   8.133      KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   8.134      return SP_RETURN_BAD_CONFIG;
   8.135    }
   8.136 -  
   8.137 +
   8.138    /* for some reason total_sectors is measured in 512 byte sectors always, so correct this to be in bytes_per_sectors */
   8.139    xvdd->total_sectors /= xvdd->bytes_per_sector / 512;
   8.140 -  
   8.141 -  ConfigInfo->MaximumTransferLength = BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE;
   8.142 -  ConfigInfo->NumberOfPhysicalBreaks = 0; //BLKIF_MAX_SEGMENTS_PER_REQUEST - 1;
   8.143 -  ConfigInfo->ScatterGather = TRUE;
   8.144 -  ConfigInfo->AlignmentMask = 0;
   8.145 -  ConfigInfo->NumberOfBuses = 1;
   8.146 -  ConfigInfo->InitiatorBusId[0] = 1;
   8.147 -  ConfigInfo->MaximumNumberOfLogicalUnits = 1;
   8.148 -  ConfigInfo->MaximumNumberOfTargets = 2;
   8.149 -  ConfigInfo->BufferAccessScsiPortControlled = TRUE;
   8.150 -  if (ConfigInfo->Dma64BitAddresses == SCSI_DMA64_SYSTEM_SUPPORTED)
   8.151 -  {
   8.152 -    ConfigInfo->Master = TRUE;
   8.153 -    ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_SUPPORTED;
   8.154 -    KdPrint((__DRIVER_NAME "     Dma64BitAddresses supported\n"));
   8.155 -  }
   8.156 -  else
   8.157 -  {
   8.158 -    ConfigInfo->Master = FALSE;
   8.159 -    KdPrint((__DRIVER_NAME "     Dma64BitAddresses not supported\n"));
   8.160 -  }
   8.161 -
   8.162 -  xvdd->ring_detect_state = 0;
   8.163  
   8.164    xvdd->shadow_free = 0;
   8.165    memset(xvdd->shadows, 0, sizeof(blkif_shadow_t) * SHADOW_ENTRIES);
   8.166 @@ -273,76 +222,8 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
   8.167      xvdd->shadows[i].req.id = i;
   8.168      put_shadow_on_freelist(xvdd, &xvdd->shadows[i]);
   8.169    }
   8.170 -
   8.171 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
   8.172 -
   8.173 -  return SP_RETURN_FOUND;
   8.174 -}
   8.175 -
   8.176 -static BOOLEAN
   8.177 -XenVbd_HwScsiInitialize(PVOID DeviceExtension)
   8.178 -{
   8.179 -  PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
   8.180 -  blkif_request_t *req;
   8.181 -  int i;
   8.182 -  int notify;
   8.183    
   8.184 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   8.185 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   8.186 -
   8.187 -  req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
   8.188 -  req->operation = 0xff;
   8.189 -  req->nr_segments = 0;
   8.190 -  for (i = 0; i < req->nr_segments; i++)
   8.191 -  {
   8.192 -    req->seg[i].gref = 0xffffffff;
   8.193 -    req->seg[i].first_sect = 0xff;
   8.194 -    req->seg[i].last_sect = 0xff;
   8.195 -  }
   8.196 -  xvdd->ring.req_prod_pvt++;
   8.197 -
   8.198 -  req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
   8.199 -  req->operation = 0xff;
   8.200 -  req->nr_segments = 0;
   8.201 -  for (i = 0; i < req->nr_segments; i++)
   8.202 -  {
   8.203 -    req->seg[i].gref = 0xffffffff;
   8.204 -    req->seg[i].first_sect = 0xff;
   8.205 -    req->seg[i].last_sect = 0xff;
   8.206 -  }
   8.207 -  xvdd->ring.req_prod_pvt++;
   8.208 -
   8.209 -  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xvdd->ring, notify);
   8.210 -  if (notify)
   8.211 -    xvdd->vectors.EvtChn_Notify(xvdd->vectors.context, xvdd->event_channel);
   8.212 -
   8.213 -  ScsiPortNotification(RequestTimerCall, DeviceExtension, XenVbd_HwScsiTimer, 60 * 1000 * 1000);
   8.214 -
   8.215 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   8.216 -
   8.217 -  return TRUE;
   8.218 -}
   8.219 -
   8.220 -static VOID
   8.221 -XenVbd_PutRequest(PXENVBD_DEVICE_DATA xvdd, blkif_request_t *req)
   8.222 -{
   8.223 -  blkif_other_request_t *other_req;
   8.224 -
   8.225 -  if (!xvdd->use_other)
   8.226 -  {
   8.227 -    *RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt) = *req;
   8.228 -  }
   8.229 -  else
   8.230 -  {  
   8.231 -    other_req = RING_GET_REQUEST(&xvdd->other_ring, xvdd->ring.req_prod_pvt);
   8.232 -    other_req->operation = req->operation;
   8.233 -    other_req->nr_segments = req->nr_segments;
   8.234 -    other_req->handle = req->handle;
   8.235 -    other_req->id = req->id;
   8.236 -    other_req->sector_number = req->sector_number;
   8.237 -    memcpy(other_req->seg, req->seg, sizeof(struct blkif_request_segment) * req->nr_segments);
   8.238 -  }
   8.239 -  xvdd->ring.req_prod_pvt++;
   8.240 +  return SP_RETURN_FOUND;
   8.241  }
   8.242  
   8.243  static VOID
   8.244 @@ -447,6 +328,178 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   8.245    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   8.246  }
   8.247  
   8.248 +#define RESUME_CHECK_TIMER_INTERVAL (100 * 1000)
   8.249 +
   8.250 +static VOID
   8.251 +XenVbd_HwScsiTimer(PVOID DeviceExtension)
   8.252 +{
   8.253 +  PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
   8.254 +  ULONG i;
   8.255 +  blkif_shadow_t shadows[SHADOW_ENTRIES];
   8.256 +  ULONG shadow_entries;
   8.257 +  blkif_shadow_t *shadow;  
   8.258 +
   8.259 +/*
   8.260 +  KdPrint((__DRIVER_NAME "     aligned requests   = %I64d, aligned bytes   = %I64d\n", xvdd->aligned_requests, xvdd->aligned_bytes));
   8.261 +  KdPrint((__DRIVER_NAME "     unaligned requests = %I64d, unaligned bytes = %I64d\n", xvdd->unaligned_requests, xvdd->unaligned_bytes));
   8.262 +  KdPrint((__DRIVER_NAME "     interrupts = %I64d\n", xvdd->interrupts));
   8.263 +  KdPrint((__DRIVER_NAME "     no_free_grant_requests = %I64d\n", xvdd->no_free_grant_requests));
   8.264 +  xvdd->shadow_min_free = xvdd->shadow_free;
   8.265 +*/
   8.266 +
   8.267 +  if (xvdd->device_state->resume_state == RESUME_STATE_FRONTEND_RESUME)
   8.268 +  {
   8.269 +    KdPrint((__DRIVER_NAME "     found device in resume state\n"));
   8.270 +    FRONT_RING_INIT(&xvdd->ring, xvdd->sring, PAGE_SIZE);
   8.271 +    // re-submit srb's
   8.272 +    
   8.273 +    shadow_entries = 0;
   8.274 +    for (i = 0; i < SHADOW_ENTRIES; i++)
   8.275 +    {
   8.276 +      shadow = &xvdd->shadows[i];
   8.277 +      if (shadow->srb)
   8.278 +      {
   8.279 +        shadows[shadow_entries++] = xvdd->shadows[i];
   8.280 +        shadow->srb = NULL;
   8.281 +      }
   8.282 +    }
   8.283 +
   8.284 +    XenVbd_InitFromConfig(xvdd);
   8.285 +    
   8.286 +    for (i = 0; i < shadow_entries; i++)
   8.287 +    {
   8.288 +      shadow = &shadows[i];
   8.289 +      XenVbd_PutSrbOnRing(xvdd, shadow->srb, shadow->offset);
   8.290 +    }
   8.291 +    
   8.292 +    xvdd->device_state->resume_state = RESUME_STATE_RUNNING;
   8.293 +  }
   8.294 +  
   8.295 +  ScsiPortNotification(RequestTimerCall, DeviceExtension, XenVbd_HwScsiTimer, RESUME_CHECK_TIMER_INTERVAL);
   8.296 +}
   8.297 +
   8.298 +static ULONG
   8.299 +XenVbd_HwScsiFindAdapter(PVOID DeviceExtension, PVOID HwContext, PVOID BusInformation, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PBOOLEAN Again)
   8.300 +{
   8.301 +//  PACCESS_RANGE AccessRange;
   8.302 +  PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
   8.303 +  ULONG status;
   8.304 +//  PXENPCI_XEN_DEVICE_DATA XenDeviceData;
   8.305 +  PACCESS_RANGE access_range;
   8.306 +
   8.307 +  UNREFERENCED_PARAMETER(HwContext);
   8.308 +  UNREFERENCED_PARAMETER(BusInformation);
   8.309 +  UNREFERENCED_PARAMETER(ArgumentString);
   8.310 +
   8.311 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));  
   8.312 +  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   8.313 +
   8.314 +  *Again = FALSE;
   8.315 +
   8.316 +  KdPrint((__DRIVER_NAME "     BusInterruptLevel = %d\n", ConfigInfo->BusInterruptLevel));
   8.317 +  KdPrint((__DRIVER_NAME "     BusInterruptVector = %03x\n", ConfigInfo->BusInterruptVector));
   8.318 +
   8.319 +  if (ConfigInfo->NumberOfAccessRanges != 1)
   8.320 +  {
   8.321 +    KdPrint((__DRIVER_NAME "     NumberOfAccessRanges = %d\n", ConfigInfo->NumberOfAccessRanges));    
   8.322 +    return SP_RETURN_BAD_CONFIG;
   8.323 +  }
   8.324 +
   8.325 +  access_range = &((*(ConfigInfo->AccessRanges))[0]);
   8.326 +
   8.327 +  KdPrint((__DRIVER_NAME "     RangeStart = %08x, RangeLength = %08x\n",
   8.328 +    access_range->RangeStart.LowPart, access_range->RangeLength));
   8.329 +
   8.330 +  xvdd->device_base = ScsiPortGetDeviceBase(
   8.331 +    DeviceExtension,
   8.332 +    ConfigInfo->AdapterInterfaceType,
   8.333 +    ConfigInfo->SystemIoBusNumber,
   8.334 +    access_range->RangeStart,
   8.335 +    access_range->RangeLength,
   8.336 +    !access_range->RangeInMemory);
   8.337 +  if (xvdd->device_base == NULL)
   8.338 +  {
   8.339 +    KdPrint((__DRIVER_NAME "     Unable to map range\n"));
   8.340 +    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
   8.341 +    return SP_RETURN_BAD_CONFIG;
   8.342 +  }
   8.343 +
   8.344 +  status = XenVbd_InitFromConfig(xvdd);
   8.345 +  if (status != SP_RETURN_FOUND)
   8.346 +    return status;
   8.347 +  
   8.348 +  ConfigInfo->MaximumTransferLength = BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE;
   8.349 +  ConfigInfo->NumberOfPhysicalBreaks = 0; //BLKIF_MAX_SEGMENTS_PER_REQUEST - 1;
   8.350 +  ConfigInfo->ScatterGather = TRUE;
   8.351 +  ConfigInfo->AlignmentMask = 0;
   8.352 +  ConfigInfo->NumberOfBuses = 1;
   8.353 +  ConfigInfo->InitiatorBusId[0] = 1;
   8.354 +  ConfigInfo->MaximumNumberOfLogicalUnits = 1;
   8.355 +  ConfigInfo->MaximumNumberOfTargets = 2;
   8.356 +  ConfigInfo->BufferAccessScsiPortControlled = TRUE;
   8.357 +  if (ConfigInfo->Dma64BitAddresses == SCSI_DMA64_SYSTEM_SUPPORTED)
   8.358 +  {
   8.359 +    ConfigInfo->Master = TRUE;
   8.360 +    ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_SUPPORTED;
   8.361 +    KdPrint((__DRIVER_NAME "     Dma64BitAddresses supported\n"));
   8.362 +  }
   8.363 +  else
   8.364 +  {
   8.365 +    ConfigInfo->Master = FALSE;
   8.366 +    KdPrint((__DRIVER_NAME "     Dma64BitAddresses not supported\n"));
   8.367 +  }
   8.368 +
   8.369 +  xvdd->ring_detect_state = 0;
   8.370 +
   8.371 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
   8.372 +
   8.373 +  return SP_RETURN_FOUND;
   8.374 +}
   8.375 +
   8.376 +static BOOLEAN
   8.377 +XenVbd_HwScsiInitialize(PVOID DeviceExtension)
   8.378 +{
   8.379 +  PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
   8.380 +  blkif_request_t *req;
   8.381 +  int i;
   8.382 +  int notify;
   8.383 +  
   8.384 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   8.385 +  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   8.386 +
   8.387 +  req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
   8.388 +  req->operation = 0xff;
   8.389 +  req->nr_segments = 0;
   8.390 +  for (i = 0; i < req->nr_segments; i++)
   8.391 +  {
   8.392 +    req->seg[i].gref = 0xffffffff;
   8.393 +    req->seg[i].first_sect = 0xff;
   8.394 +    req->seg[i].last_sect = 0xff;
   8.395 +  }
   8.396 +  xvdd->ring.req_prod_pvt++;
   8.397 +
   8.398 +  req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
   8.399 +  req->operation = 0xff;
   8.400 +  req->nr_segments = 0;
   8.401 +  for (i = 0; i < req->nr_segments; i++)
   8.402 +  {
   8.403 +    req->seg[i].gref = 0xffffffff;
   8.404 +    req->seg[i].first_sect = 0xff;
   8.405 +    req->seg[i].last_sect = 0xff;
   8.406 +  }
   8.407 +  xvdd->ring.req_prod_pvt++;
   8.408 +
   8.409 +  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xvdd->ring, notify);
   8.410 +  if (notify)
   8.411 +    xvdd->vectors.EvtChn_Notify(xvdd->vectors.context, xvdd->event_channel);
   8.412 +
   8.413 +  ScsiPortNotification(RequestTimerCall, DeviceExtension, XenVbd_HwScsiTimer, RESUME_CHECK_TIMER_INTERVAL);
   8.414 +
   8.415 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   8.416 +
   8.417 +  return TRUE;
   8.418 +}
   8.419 +
   8.420  static ULONG
   8.421  XenVbd_FillModePage(PXENVBD_DEVICE_DATA xvdd, PSCSI_REQUEST_BLOCK srb)
   8.422  {
   8.423 @@ -461,7 +514,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   8.424  
   8.425    UNREFERENCED_PARAMETER(xvdd);
   8.426  
   8.427 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   8.428 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   8.429    
   8.430    cdb = (PCDB)srb->Cdb;
   8.431    page_code = cdb->MODE_SENSE.PageCode;
   8.432 @@ -530,7 +583,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   8.433    srb->ScsiStatus = 0;
   8.434    memcpy(srb->DataBuffer, buffer, srb->DataTransferLength);
   8.435    
   8.436 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   8.437 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   8.438  
   8.439    return TRUE;
   8.440  }
   8.441 @@ -834,7 +887,7 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   8.442        }
   8.443        break;
   8.444      case SCSIOP_READ_CAPACITY:
   8.445 -      KdPrint((__DRIVER_NAME "     Command = READ_CAPACITY\n"));
   8.446 +      //KdPrint((__DRIVER_NAME "     Command = READ_CAPACITY\n"));
   8.447        //KdPrint((__DRIVER_NAME "       LUN = %d, RelAdr = %d\n", Srb->Cdb[1] >> 4, Srb->Cdb[1] & 1));
   8.448        //KdPrint((__DRIVER_NAME "       LBA = %02x%02x%02x%02x\n", Srb->Cdb[2], Srb->Cdb[3], Srb->Cdb[4], Srb->Cdb[5]));
   8.449        //KdPrint((__DRIVER_NAME "       PMI = %d\n", Srb->Cdb[8] & 1));
     9.1 --- a/xenvbd/xenvbd.h	Wed Jun 25 10:26:51 2008 +1000
     9.2 +++ b/xenvbd/xenvbd.h	Thu Jun 26 16:55:43 2008 +1000
     9.3 @@ -100,7 +100,10 @@ struct
     9.4    grant_ref_t grant_free_list[MAX_GRANT_ENTRIES];
     9.5    USHORT grant_free;
     9.6    USHORT grant_entries;
     9.7 +  
     9.8 +  PUCHAR device_base;
     9.9  
    9.10 +  blkif_sring_t *sring;
    9.11    evtchn_port_t event_channel;
    9.12    union {
    9.13      blkif_front_ring_t ring;
    9.14 @@ -116,6 +119,7 @@ struct
    9.15    ULONG bytes_per_sector;
    9.16    ULONGLONG total_sectors;
    9.17    XENPCI_VECTORS vectors;
    9.18 +  PXENPCI_DEVICE_STATE device_state;
    9.19    PSCSI_REQUEST_BLOCK pending_srb;
    9.20    
    9.21    ULONGLONG interrupts;