win-pvdrivers

changeset 274:874c3640830e wdm

Lots more updates. Added pvscsi support and started working on the stub drivers. Also working on unload support.
author James Harper <james.harper@bendigoit.com.au>
date Thu May 22 13:46:15 2008 +1000 (2008-05-22)
parents 63920d09b07d
children 0401d8062ede
files ShutdownMon/Program.cs Xen.sln common.inc common/include/public/io/vscsiif.h common/include/xen_public.h common/include/xen_windows.h dirs doc/INSTALLING.txt doc/README.txt xennet/makefile.inc xennet/xennet.c xennet/xennet.h xennet/xennet.inx xennet/xennet_rx.c xennet/xennet_tx.c xenpci/amd64/swint.asm xenpci/evtchn.c xenpci/hypercall_amd64.h xenpci/sources xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci.inx xenpci/xenpci_fdo.c xenpci/xenpci_pdo.c xenscsi/sources xenscsi/xenscsi.c xenscsi/xenscsi.h xenscsi/xenscsi.inx xenstub/makefile.inc xenstub/xenstub.c xenstub/xenstub.h xenvbd/xenvbd.c xenvbd/xenvbd.h xenvbd/xenvbd.inx
line diff
     1.1 --- a/ShutdownMon/Program.cs	Sat May 17 00:06:05 2008 +1000
     1.2 +++ b/ShutdownMon/Program.cs	Thu May 22 13:46:15 2008 +1000
     1.3 @@ -112,7 +112,7 @@ namespace ShutdownMon
     1.4          internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
     1.5          internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
     1.6  
     1.7 -        [StructLayout(LayoutKind.Sequential)]
     1.8 +        [StructLayout(LayoutKind.Sequential, Pack = 1)]
     1.9          protected struct SP_DEVICE_INTERFACE_DATA
    1.10          {
    1.11              public UInt32 cbSize;
    1.12 @@ -120,9 +120,21 @@ namespace ShutdownMon
    1.13              public UInt32 Flags;
    1.14              public IntPtr Reserved;
    1.15          };
    1.16 -
    1.17 +        /*
    1.18 +        [StructLayout(LayoutKind.Sequential, Pack = 1)]
    1.19 +        public struct SP_DEVICE_INTERFACE_DETAIL_DATA
    1.20 +        {
    1.21 +            public int Size;
    1.22 +            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
    1.23 +            public string DevicePath;
    1.24 +        }
    1.25 +        */
    1.26          [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
    1.27 -        private static extern IntPtr SetupDiGetClassDevsA(ref Guid ClassGuid, UInt32 Enumerator, IntPtr hwndParent, UInt32 Flags);
    1.28 +        private static extern IntPtr SetupDiGetClassDevsA(
    1.29 +            ref Guid ClassGuid,
    1.30 +            UInt32 Enumerator,
    1.31 +            IntPtr hwndParent,
    1.32 +            UInt32 Flags);
    1.33  
    1.34          [DllImport("setupapi.dll", SetLastError = true)]
    1.35          private static extern Boolean SetupDiEnumDeviceInterfaces(
    1.36 @@ -156,13 +168,17 @@ namespace ShutdownMon
    1.37              sdid.Reserved = IntPtr.Zero;
    1.38  
    1.39              if (!SetupDiEnumDeviceInterfaces(handle, IntPtr.Zero, ref XenInterface, 0, out sdid))
    1.40 -                return null;
    1.41 +                throw new Win32Exception(Marshal.GetLastWin32Error());
    1.42 +            Console.WriteLine("Got interface");
    1.43              UInt32 buflen = 1024;
    1.44              IntPtr buf = Marshal.AllocHGlobal((int)buflen);
    1.45 -            Marshal.WriteInt32(buf, 4 + Marshal.SystemDefaultCharSize);
    1.46 -            bool success = SetupDiGetDeviceInterfaceDetail(handle, ref sdid, buf, buflen, ref buflen, IntPtr.Zero);
    1.47 -            if (!success)
    1.48 -                return null;
    1.49 +            if (Marshal.SizeOf(buf) == 4)
    1.50 +                Marshal.WriteInt32(buf, 6); // 32 bit systems align it this way...
    1.51 +            else
    1.52 +                Marshal.WriteInt32(buf, 8); // and 64 bit systems align it that...
    1.53 +            if (!SetupDiGetDeviceInterfaceDetail(handle, ref sdid, buf, buflen, ref buflen, IntPtr.Zero))
    1.54 +                throw new Win32Exception(Marshal.GetLastWin32Error());
    1.55 +            Console.WriteLine("Got detail");
    1.56              string filename = Marshal.PtrToStringUni(new IntPtr(buf.ToInt64() + 4));
    1.57              Console.WriteLine("interface path = " + filename);
    1.58              // free stuff here
     2.1 --- a/Xen.sln	Sat May 17 00:06:05 2008 +1000
     2.2 +++ b/Xen.sln	Thu May 22 13:46:15 2008 +1000
     2.3 @@ -5,8 +5,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F
     2.4  EndProject
     2.5  Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "XenPvInstaller", "XenPvInstaller\XenPvInstaller.vdproj", "{086AB089-7132-4D35-8BBE-D5211FBBD915}"
     2.6  EndProject
     2.7 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.csproj", "{BA4FE7E7-BB00-4EAA-81C4-DA8F7A94A583}"
     2.8 -EndProject
     2.9  Global
    2.10  	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    2.11  		Debug|Any CPU = Debug|Any CPU
    2.12 @@ -19,10 +17,6 @@ Global
    2.13  		{26FF5B06-2383-454E-821F-306186171677}.Release|Any CPU.Build.0 = Release|Any CPU
    2.14  		{086AB089-7132-4D35-8BBE-D5211FBBD915}.Debug|Any CPU.ActiveCfg = Debug
    2.15  		{086AB089-7132-4D35-8BBE-D5211FBBD915}.Release|Any CPU.ActiveCfg = Release
    2.16 -		{BA4FE7E7-BB00-4EAA-81C4-DA8F7A94A583}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    2.17 -		{BA4FE7E7-BB00-4EAA-81C4-DA8F7A94A583}.Debug|Any CPU.Build.0 = Debug|Any CPU
    2.18 -		{BA4FE7E7-BB00-4EAA-81C4-DA8F7A94A583}.Release|Any CPU.ActiveCfg = Release|Any CPU
    2.19 -		{BA4FE7E7-BB00-4EAA-81C4-DA8F7A94A583}.Release|Any CPU.Build.0 = Release|Any CPU
    2.20  	EndGlobalSection
    2.21  	GlobalSection(SolutionProperties) = preSolution
    2.22  		HideSolutionNode = FALSE
     3.1 --- a/common.inc	Sat May 17 00:06:05 2008 +1000
     3.2 +++ b/common.inc	Thu May 22 13:46:15 2008 +1000
     3.3 @@ -1,12 +1,5 @@
     3.4 -VERSION=0.8.9.47
     3.5 +VERSION=0.9.0.12
     3.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     3.7 -KMDF_VERSION=1
     3.8 -!IF $(_NT_TOOLS_VERSION) > 0x700
     3.9 -KMDF_MAJOR_VERSION=1
    3.10 -!ELSE
    3.11 -KMDF_VERSION_MAJOR=1
    3.12 -KMDF_VERSION_MINOR=5
    3.13 -!ENDIF
    3.14  MSC_WARNING_LEVEL=/W4
    3.15  INCLUDES = ..\common\include;..\common\include\public
    3.16  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\ntstrsafe.lib
     4.1 --- a/common/include/public/io/vscsiif.h	Sat May 17 00:06:05 2008 +1000
     4.2 +++ b/common/include/public/io/vscsiif.h	Thu May 22 13:46:15 2008 +1000
     4.3 @@ -1,73 +1,73 @@
     4.4 -/******************************************************************************
     4.5 - * scsiif.h
     4.6 - * 
     4.7 - * Based on the blkif.h code.
     4.8 - * 
     4.9 - * Permission is hereby granted, free of charge, to any person obtaining a copy
    4.10 - * of this software and associated documentation files (the "Software"), to
    4.11 - * deal in the Software without restriction, including without limitation the
    4.12 - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    4.13 - * sell copies of the Software, and to permit persons to whom the Software is
    4.14 - * furnished to do so, subject to the following conditions:
    4.15 - *
    4.16 - * The above copyright notice and this permission notice shall be included in
    4.17 - * all copies or substantial portions of the Software.
    4.18 - *
    4.19 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    4.20 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    4.21 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    4.22 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    4.23 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    4.24 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    4.25 - * DEALINGS IN THE SOFTWARE.
    4.26 - *
    4.27 - * Copyright(c) FUJITSU Limited 2008.
    4.28 - */
    4.29 -
    4.30 -#ifndef __XEN__PUBLIC_IO_SCSI_H__
    4.31 -#define __XEN__PUBLIC_IO_SCSI_H__
    4.32 -
    4.33 -#include "ring.h"
    4.34 -#include "../grant_table.h"
    4.35 -
    4.36 -#define VSCSIIF_CMND_SCSI			1	/* scsi */
    4.37 -#define VSCSIIF_CMND_SCSI_RESET			2	/* scsi */
    4.38 -
    4.39 -/* ----------------------------------------------------------------------
    4.40 -	Definition of Ring Structures
    4.41 -   ---------------------------------------------------------------------- */
    4.42 -
    4.43 -#define VSCSIIF_DEFAULT_CAN_QUEUE	256
    4.44 -#define VSCSIIF_MAX_COMMAND_SIZE	16
    4.45 -#define VSCSIIF_SG_TABLESIZE		27
    4.46 -
    4.47 -struct vscsiif_request {
    4.48 -	uint16_t rqid;
    4.49 -	uint8_t cmd;
    4.50 -	/* SCSI */
    4.51 -	uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE];
    4.52 -	uint8_t cmd_len;
    4.53 -	uint16_t id, lun, channel;
    4.54 -	uint8_t sc_data_direction;
    4.55 -	uint8_t use_sg;
    4.56 -	uint32_t request_bufflen;
    4.57 -	/*int32_t timeout_per_command;*/
    4.58 -	struct scsiif_request_segment {
    4.59 -		grant_ref_t gref;
    4.60 -		uint16_t offset;
    4.61 -		uint16_t length;
    4.62 -	} seg[VSCSIIF_SG_TABLESIZE];
    4.63 -};
    4.64 -
    4.65 -#define VSCSIIF_SENSE_BUFFERSIZE 	96
    4.66 -
    4.67 -struct vscsiif_response {
    4.68 -	uint16_t rqid;
    4.69 -	int32_t  rslt;
    4.70 -	uint8_t sense_len;
    4.71 -	uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
    4.72 -};
    4.73 -
    4.74 -DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response);
    4.75 -
    4.76 -#endif
    4.77 +/******************************************************************************
    4.78 + * scsiif.h
    4.79 + * 
    4.80 + * Based on the blkif.h code.
    4.81 + * 
    4.82 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    4.83 + * of this software and associated documentation files (the "Software"), to
    4.84 + * deal in the Software without restriction, including without limitation the
    4.85 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    4.86 + * sell copies of the Software, and to permit persons to whom the Software is
    4.87 + * furnished to do so, subject to the following conditions:
    4.88 + *
    4.89 + * The above copyright notice and this permission notice shall be included in
    4.90 + * all copies or substantial portions of the Software.
    4.91 + *
    4.92 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    4.93 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    4.94 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    4.95 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    4.96 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    4.97 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    4.98 + * DEALINGS IN THE SOFTWARE.
    4.99 + *
   4.100 + * Copyright(c) FUJITSU Limited 2008.
   4.101 + */
   4.102 +
   4.103 +#ifndef __XEN__PUBLIC_IO_SCSI_H__
   4.104 +#define __XEN__PUBLIC_IO_SCSI_H__
   4.105 +
   4.106 +#include "ring.h"
   4.107 +#include "../grant_table.h"
   4.108 +
   4.109 +#define VSCSIIF_CMND_SCSI			1	/* scsi */
   4.110 +#define VSCSIIF_CMND_SCSI_RESET			2	/* scsi */
   4.111 +
   4.112 +/* ----------------------------------------------------------------------
   4.113 +	Definition of Ring Structures
   4.114 +   ---------------------------------------------------------------------- */
   4.115 +
   4.116 +#define VSCSIIF_DEFAULT_CAN_QUEUE	256
   4.117 +#define VSCSIIF_MAX_COMMAND_SIZE	16
   4.118 +#define VSCSIIF_SG_TABLESIZE		27
   4.119 +
   4.120 +struct vscsiif_request {
   4.121 +	uint16_t rqid;
   4.122 +	uint8_t cmd;
   4.123 +	/* SCSI */
   4.124 +	uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE];
   4.125 +	uint8_t cmd_len;
   4.126 +	uint16_t id, lun, channel;
   4.127 +	uint8_t sc_data_direction;
   4.128 +	uint8_t use_sg;
   4.129 +	uint32_t request_bufflen;
   4.130 +	/*int32_t timeout_per_command;*/
   4.131 +	struct scsiif_request_segment {
   4.132 +		grant_ref_t gref;
   4.133 +		uint16_t offset;
   4.134 +		uint16_t length;
   4.135 +	} seg[VSCSIIF_SG_TABLESIZE];
   4.136 +};
   4.137 +
   4.138 +#define VSCSIIF_SENSE_BUFFERSIZE 	96
   4.139 +
   4.140 +struct vscsiif_response {
   4.141 +	uint16_t rqid;
   4.142 +	int32_t  rslt;
   4.143 +	uint8_t sense_len;
   4.144 +	uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
   4.145 +};
   4.146 +
   4.147 +DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response);
   4.148 +
   4.149 +#endif
   4.150 \ No newline at end of file
     5.1 --- a/common/include/xen_public.h	Sat May 17 00:06:05 2008 +1000
     5.2 +++ b/common/include/xen_public.h	Thu May 22 13:46:15 2008 +1000
     5.3 @@ -88,6 +88,9 @@ typedef char *
     5.4  typedef char *
     5.5  (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
     5.6  
     5.7 +typedef NTSTATUS
     5.8 +(*PXEN_XENPCI_SHUTDOWN_DEVICE)(PVOID Context);
     5.9 +
    5.10  #if 0
    5.11  typedef struct _XEN_IFACE {
    5.12    INTERFACE InterfaceHeader;
    5.13 @@ -145,6 +148,7 @@ typedef struct {
    5.14    PXEN_GNTTBL_PUTREF GntTbl_PutRef;
    5.15    PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
    5.16    PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
    5.17 +  PXEN_XENPCI_SHUTDOWN_DEVICE XenPci_ShutdownDevice;
    5.18  } XENPCI_VECTORS, *PXENPCI_VECTORS;
    5.19  
    5.20  
     6.1 --- a/common/include/xen_windows.h	Sat May 17 00:06:05 2008 +1000
     6.2 +++ b/common/include/xen_windows.h	Thu May 22 13:46:15 2008 +1000
     6.3 @@ -14,6 +14,7 @@
     6.4  #else
     6.5    #error Unknown architecture
     6.6  #endif
     6.7 +
     6.8  typedef INT8 int8_t;
     6.9  typedef UINT8 uint8_t;
    6.10  typedef INT16 int16_t;
    6.11 @@ -136,6 +137,28 @@ AllocatePage()
    6.12    return AllocatePagesExtra(1, 0);
    6.13  }
    6.14  
    6.15 +static PMDL
    6.16 +AllocateUncachedPage()
    6.17 +{
    6.18 +  PMDL mdl;
    6.19 +  PVOID buf;
    6.20 +
    6.21 +  buf = MmAllocateNonCachedMemory(PAGE_SIZE);
    6.22 +  mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
    6.23 +  MmBuildMdlForNonPagedPool(mdl);
    6.24 +
    6.25 +  return mdl;
    6.26 +}  
    6.27 +
    6.28 +static VOID
    6.29 +FreeUncachedPage(PMDL mdl)
    6.30 +{
    6.31 +  PVOID buf = MmGetMdlVirtualAddress(mdl);
    6.32 +
    6.33 +  IoFreeMdl(mdl);
    6.34 +  MmFreeNonCachedMemory(buf, PAGE_SIZE);
    6.35 +}
    6.36 +
    6.37  static VOID
    6.38  FreePages(PMDL Mdl)
    6.39  {
     7.1 --- a/dirs	Sat May 17 00:06:05 2008 +1000
     7.2 +++ b/dirs	Thu May 22 13:46:15 2008 +1000
     7.3 @@ -1,1 +1,1 @@
     7.4 -DIRS=xenpci xenhide xenvbd xennet
     7.5 \ No newline at end of file
     7.6 +DIRS=xenpci xenhide xenvbd xennet xenscsi xenstub
     7.7 \ No newline at end of file
     8.1 --- a/doc/INSTALLING.txt	Sat May 17 00:06:05 2008 +1000
     8.2 +++ b/doc/INSTALLING.txt	Thu May 22 13:46:15 2008 +1000
     8.3 @@ -1,1 +1,1 @@
     8.4 -see http://www.meadowcourt.org/james/xen/gplpv.htm for details
     8.5 \ No newline at end of file
     8.6 +see http://wiki.xensource.com/xenwiki/XenWindowsGplPv/Installing for details
     8.7 \ No newline at end of file
     9.1 --- a/doc/README.txt	Sat May 17 00:06:05 2008 +1000
     9.2 +++ b/doc/README.txt	Thu May 22 13:46:15 2008 +1000
     9.3 @@ -1,1 +1,1 @@
     9.4 -see http://www.meadowcourt.org/james/xen/gplpv.htm for details
     9.5 \ No newline at end of file
     9.6 +see http://wiki.xensource.com/xenwiki/XenWindowsGplPv for details
     9.7 \ No newline at end of file
    10.1 --- a/xennet/makefile.inc	Sat May 17 00:06:05 2008 +1000
    10.2 +++ b/xennet/makefile.inc	Thu May 22 13:46:15 2008 +1000
    10.3 @@ -1,5 +1,5 @@
    10.4  _LNG=$(LANGUAGE)
    10.5 -STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -k $(KMDF_VERSION_MAJOR).$(KMDF_VERSION_MINOR) -v $(VERSION)
    10.6 +STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
    10.7  
    10.8  ..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf: $(INF_NAME).inx sources ..\common.inc
    10.9      copy $(@B).inx $@
    11.1 --- a/xennet/xennet.c	Sat May 17 00:06:05 2008 +1000
    11.2 +++ b/xennet/xennet.c	Thu May 22 13:46:15 2008 +1000
    11.3 @@ -173,20 +173,27 @@ XenNet_Init(
    11.4      0, NDIS_ATTRIBUTE_DESERIALIZE, // | NDIS_ATTRIBUTE_BUS_MASTER),
    11.5      NdisInterfaceInternal);
    11.6  
    11.7 +  length = 0;
    11.8    NdisMQueryAdapterResources(&status, WrapperConfigurationContext,
    11.9      NULL, (PUINT)&length);
   11.10 -  NdisAllocateMemoryWithTag(&nrl, length, XENNET_POOL_TAG);
   11.11 +  KdPrint((__DRIVER_NAME "     length = %d\n", length));
   11.12 +  status = NdisAllocateMemoryWithTag(&nrl, length, XENNET_POOL_TAG);
   11.13 +  if (status != NDIS_STATUS_SUCCESS)
   11.14 +  {
   11.15 +    KdPrint((__DRIVER_NAME "     Could not get allocate memory for Adapter Resources 0x%x\n", status));
   11.16 +    return NDIS_ERROR_CODE_ADAPTER_NOT_FOUND;
   11.17 +  }
   11.18    NdisMQueryAdapterResources(&status, WrapperConfigurationContext,
   11.19      nrl, (PUINT)&length);
   11.20    if (status != NDIS_STATUS_SUCCESS)
   11.21    {
   11.22 -    KdPrint(("Could not get Adapter Resources 0x%x\n", status));
   11.23 +    KdPrint((__DRIVER_NAME "     Could not get Adapter Resources 0x%x\n", status));
   11.24      return NDIS_ERROR_CODE_ADAPTER_NOT_FOUND;
   11.25    }
   11.26    xi->event_channel = 0;
   11.27    xi->config_csum = 1;
   11.28    xi->config_sg = 1;
   11.29 -  xi->config_gso = 1;
   11.30 +  xi->config_gso = 61440;
   11.31  
   11.32    for (i = 0; i < nrl->Count; i++)
   11.33    {
   11.34 @@ -201,7 +208,9 @@ XenNet_Init(
   11.35        break;
   11.36  
   11.37      case CmResourceTypeMemory:
   11.38 +      //ptr = MmMapIoSpace(prd->u.Memory.Start, prd->u.Memory.Length, MmCached);
   11.39        NdisMMapIoSpace(&ptr, MiniportAdapterHandle, prd->u.Memory.Start, PAGE_SIZE);
   11.40 +      ASSERT(ptr);
   11.41        while((type = GET_XEN_INIT_RSP(&ptr, &setting, &value)) != XEN_INIT_TYPE_END)
   11.42        {
   11.43          switch(type)
   11.44 @@ -348,9 +357,11 @@ XenNet_Shutdown(
   11.45    IN NDIS_HANDLE MiniportAdapterContext
   11.46    )
   11.47  {
   11.48 -  UNREFERENCED_PARAMETER(MiniportAdapterContext);
   11.49 +  struct xennet_info *xi = MiniportAdapterContext;
   11.50  
   11.51    KdPrint((__FUNCTION__ " called\n"));
   11.52 +
   11.53 +  NdisMDeregisterInterrupt(&xi->interrupt);
   11.54  }
   11.55  
   11.56  /* Opposite of XenNet_Init */
   11.57 @@ -411,6 +422,8 @@ XenNet_Halt(
   11.58    // Disables the interrupt
   11.59    XenNet_Shutdown(xi);
   11.60  
   11.61 +  xi->vectors.XenPci_ShutdownDevice(xi->vectors.context);
   11.62 +
   11.63    xi->connected = FALSE;
   11.64    KeMemoryBarrier(); /* make sure everyone sees that we are now shut down */
   11.65  
   11.66 @@ -452,7 +465,7 @@ XenNet_Pnp(PDEVICE_OBJECT device_object,
   11.67    //NDIS_STRING config_param_name;
   11.68    //PNDIS_CONFIGURATION_PARAMETER config_param;
   11.69  
   11.70 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   11.71 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   11.72  
   11.73    stack = IoGetCurrentIrpStackLocation(irp);
   11.74  
   11.75 @@ -536,7 +549,7 @@ XenNet_Pnp(PDEVICE_OBJECT device_object,
   11.76      old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   11.77      if (old_crl != NULL)
   11.78      {
   11.79 -      mdl = AllocatePage();
   11.80 +      mdl = AllocateUncachedPage();
   11.81        old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
   11.82          FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
   11.83          FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
   11.84 @@ -586,12 +599,21 @@ XenNet_Pnp(PDEVICE_OBJECT device_object,
   11.85      }
   11.86      status = XenNet_Pnp_Original(device_object, irp);
   11.87      break;
   11.88 +  case IRP_MN_STOP_DEVICE:
   11.89 +    KdPrint((__DRIVER_NAME "     IRP_MN_STOP_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
   11.90 +    status = XenNet_Pnp_Original(device_object, irp);
   11.91 +    break;
   11.92 +  case IRP_MN_REMOVE_DEVICE:
   11.93 +    KdPrint((__DRIVER_NAME "     IRP_MN_REMOVE_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
   11.94 +    status = XenNet_Pnp_Original(device_object, irp);
   11.95 +    break;
   11.96    default:
   11.97 +    KdPrint((__DRIVER_NAME "     Unknown Minor %d\n", stack->MinorFunction));
   11.98      status = XenNet_Pnp_Original(device_object, irp);
   11.99      break;
  11.100    }
  11.101  
  11.102 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  11.103 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  11.104  
  11.105    return status;
  11.106  }
    12.1 --- a/xennet/xennet.h	Sat May 17 00:06:05 2008 +1000
    12.2 +++ b/xennet/xennet.h	Thu May 22 13:46:15 2008 +1000
    12.3 @@ -21,10 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fi
    12.4  #pragma warning(disable: 4201)
    12.5  #pragma warning(disable: 4214)
    12.6  
    12.7 +#include <ntddk.h>
    12.8  #include <wdm.h>
    12.9 -//#include <wdf.h>
   12.10 -//#include <wdfminiport.h>
   12.11 -#include <initguid.h>
   12.12 +
   12.13  #define NDIS_MINIPORT_DRIVER
   12.14  #if NTDDI_VERSION < NTDDI_WINXP
   12.15  # define NDIS50_MINIPORT 1
   12.16 @@ -36,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fi
   12.17  #define NTSTRSAFE_LIB
   12.18  #include <ntstrsafe.h>
   12.19  
   12.20 +
   12.21  #define __DRIVER_NAME "XenNet"
   12.22  
   12.23  #include <xen_windows.h>
   12.24 @@ -51,6 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fi
   12.25  #include <stdlib.h>
   12.26  #define XENNET_POOL_TAG (ULONG) 'XenN'
   12.27  
   12.28 +
   12.29  /* Xen macros use these, so they need to be redefined to Win equivs */
   12.30  #define wmb() KeMemoryBarrier()
   12.31  #define mb() KeMemoryBarrier()
   12.32 @@ -135,10 +136,11 @@ typedef struct {
   12.33    BOOLEAN more_frags;
   12.34  } packet_info_t;
   12.35  
   12.36 +#define PAGE_LIST_SIZE (max(NET_RX_RING_SIZE, NET_TX_RING_SIZE) * 4)
   12.37  typedef struct
   12.38  {
   12.39    struct xennet_info *xi;
   12.40 -  PMDL page_list[NET_RX_RING_SIZE];
   12.41 +  PMDL page_list[PAGE_LIST_SIZE];
   12.42    ULONG page_free;
   12.43    ULONG page_free_lowest;
   12.44    ULONG page_free_target;
    13.1 --- a/xennet/xennet.inx	Sat May 17 00:06:05 2008 +1000
    13.2 +++ b/xennet/xennet.inx	Thu May 22 13:46:15 2008 +1000
    13.3 @@ -3,6 +3,7 @@ Signature="$WINDOWS NT$"
    13.4  Class=Net
    13.5  ClassGuid={4D36E972-E325-11CE-BFC1-08002BE10318}
    13.6  Provider=%XenGplPv%
    13.7 +CatalogFile="XenGPLPV.cat"
    13.8  
    13.9  [DestinationDirs]
   13.10  DefaultDestDir = 12
    14.1 --- a/xennet/xennet_rx.c	Sat May 17 00:06:05 2008 +1000
    14.2 +++ b/xennet/xennet_rx.c	Thu May 22 13:46:15 2008 +1000
    14.3 @@ -547,11 +547,13 @@ XenNet_RxBufferFree(struct xennet_info *
    14.4  
    14.5    for (i = 0; i < NET_RX_RING_SIZE; i++)
    14.6    {
    14.7 +    KdPrint((__DRIVER_NAME "     Ring slot %d = %p\n", i, xi->rx_buffers[i]));
    14.8      if (!xi->rx_buffers[i])
    14.9        continue;
   14.10  
   14.11      mdl = xi->rx_buffers[i];
   14.12      NdisAdjustBufferLength(mdl, PAGE_SIZE);
   14.13 +    KdPrint((__DRIVER_NAME "     Calling PutPage - page_free = %d\n", xi->rx_freelist.page_free));
   14.14      XenFreelist_PutPage(&xi->rx_freelist, mdl);
   14.15    }
   14.16  }
    15.1 --- a/xennet/xennet_tx.c	Sat May 17 00:06:05 2008 +1000
    15.2 +++ b/xennet/xennet_tx.c	Thu May 22 13:46:15 2008 +1000
    15.3 @@ -486,6 +486,7 @@ XenNet_TxShutdown(xennet_info_t *xi)
    15.4    ASSERT(!xi->connected);
    15.5  
    15.6    KeAcquireSpinLock(&xi->tx_lock, &OldIrql);
    15.7 +
    15.8    /* Free packets in tx queue */
    15.9    entry = RemoveHeadList(&xi->tx_waiting_pkt_list);
   15.10    while (entry != &xi->tx_waiting_pkt_list)
   15.11 @@ -508,7 +509,6 @@ XenNet_TxShutdown(xennet_info_t *xi)
   15.12  
   15.13    XenFreelist_Dispose(&xi->tx_freelist);
   15.14  
   15.15 -  /* free TX resources */
   15.16    KeReleaseSpinLock(&xi->tx_lock, OldIrql);
   15.17  
   15.18    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/xenpci/amd64/swint.asm	Thu May 22 13:46:15 2008 +1000
    16.3 @@ -0,0 +1,1037 @@
    16.4 +.code
    16.5 +_sw_interrupt proc
    16.6 +  shl rcx, 3
    16.7 +  mov rax, jump_table
    16.8 +  add rax, rcx
    16.9 +  jmp qword ptr [rax]
   16.10 +
   16.11 +I0:
   16.12 +  int 0
   16.13 +  ret
   16.14 +I1:
   16.15 +  int 1
   16.16 +  ret
   16.17 +I2:
   16.18 +  int 2
   16.19 +  ret
   16.20 +I3:
   16.21 +  int 3
   16.22 +  ret
   16.23 +I4:
   16.24 +  int 4
   16.25 +  ret
   16.26 +I5:
   16.27 +  int 5
   16.28 +  ret
   16.29 +I6:
   16.30 +  int 6
   16.31 +  ret
   16.32 +I7:
   16.33 +  int 7
   16.34 +  ret
   16.35 +I8:
   16.36 +  int 8
   16.37 +  ret
   16.38 +I9:
   16.39 +  int 9
   16.40 +  ret
   16.41 +I10:
   16.42 +  int 10
   16.43 +  ret
   16.44 +I11:
   16.45 +  int 11
   16.46 +  ret
   16.47 +I12:
   16.48 +  int 12
   16.49 +  ret
   16.50 +I13:
   16.51 +  int 13
   16.52 +  ret
   16.53 +I14:
   16.54 +  int 14
   16.55 +  ret
   16.56 +I15:
   16.57 +  int 15
   16.58 +  ret
   16.59 +I16:
   16.60 +  int 16
   16.61 +  ret
   16.62 +I17:
   16.63 +  int 17
   16.64 +  ret
   16.65 +I18:
   16.66 +  int 18
   16.67 +  ret
   16.68 +I19:
   16.69 +  int 19
   16.70 +  ret
   16.71 +I20:
   16.72 +  int 20
   16.73 +  ret
   16.74 +I21:
   16.75 +  int 21
   16.76 +  ret
   16.77 +I22:
   16.78 +  int 22
   16.79 +  ret
   16.80 +I23:
   16.81 +  int 23
   16.82 +  ret
   16.83 +I24:
   16.84 +  int 24
   16.85 +  ret
   16.86 +I25:
   16.87 +  int 25
   16.88 +  ret
   16.89 +I26:
   16.90 +  int 26
   16.91 +  ret
   16.92 +I27:
   16.93 +  int 27
   16.94 +  ret
   16.95 +I28:
   16.96 +  int 28
   16.97 +  ret
   16.98 +I29:
   16.99 +  int 29
  16.100 +  ret
  16.101 +I30:
  16.102 +  int 30
  16.103 +  ret
  16.104 +I31:
  16.105 +  int 31
  16.106 +  ret
  16.107 +I32:
  16.108 +  int 32
  16.109 +  ret
  16.110 +I33:
  16.111 +  int 33
  16.112 +  ret
  16.113 +I34:
  16.114 +  int 34
  16.115 +  ret
  16.116 +I35:
  16.117 +  int 35
  16.118 +  ret
  16.119 +I36:
  16.120 +  int 36
  16.121 +  ret
  16.122 +I37:
  16.123 +  int 37
  16.124 +  ret
  16.125 +I38:
  16.126 +  int 38
  16.127 +  ret
  16.128 +I39:
  16.129 +  int 39
  16.130 +  ret
  16.131 +I40:
  16.132 +  int 40
  16.133 +  ret
  16.134 +I41:
  16.135 +  int 41
  16.136 +  ret
  16.137 +I42:
  16.138 +  int 42
  16.139 +  ret
  16.140 +I43:
  16.141 +  int 43
  16.142 +  ret
  16.143 +I44:
  16.144 +  int 44
  16.145 +  ret
  16.146 +I45:
  16.147 +  int 45
  16.148 +  ret
  16.149 +I46:
  16.150 +  int 46
  16.151 +  ret
  16.152 +I47:
  16.153 +  int 47
  16.154 +  ret
  16.155 +I48:
  16.156 +  int 48
  16.157 +  ret
  16.158 +I49:
  16.159 +  int 49
  16.160 +  ret
  16.161 +I50:
  16.162 +  int 50
  16.163 +  ret
  16.164 +I51:
  16.165 +  int 51
  16.166 +  ret
  16.167 +I52:
  16.168 +  int 52
  16.169 +  ret
  16.170 +I53:
  16.171 +  int 53
  16.172 +  ret
  16.173 +I54:
  16.174 +  int 54
  16.175 +  ret
  16.176 +I55:
  16.177 +  int 55
  16.178 +  ret
  16.179 +I56:
  16.180 +  int 56
  16.181 +  ret
  16.182 +I57:
  16.183 +  int 57
  16.184 +  ret
  16.185 +I58:
  16.186 +  int 58
  16.187 +  ret
  16.188 +I59:
  16.189 +  int 59
  16.190 +  ret
  16.191 +I60:
  16.192 +  int 60
  16.193 +  ret
  16.194 +I61:
  16.195 +  int 61
  16.196 +  ret
  16.197 +I62:
  16.198 +  int 62
  16.199 +  ret
  16.200 +I63:
  16.201 +  int 63
  16.202 +  ret
  16.203 +I64:
  16.204 +  int 64
  16.205 +  ret
  16.206 +I65:
  16.207 +  int 65
  16.208 +  ret
  16.209 +I66:
  16.210 +  int 66
  16.211 +  ret
  16.212 +I67:
  16.213 +  int 67
  16.214 +  ret
  16.215 +I68:
  16.216 +  int 68
  16.217 +  ret
  16.218 +I69:
  16.219 +  int 69
  16.220 +  ret
  16.221 +I70:
  16.222 +  int 70
  16.223 +  ret
  16.224 +I71:
  16.225 +  int 71
  16.226 +  ret
  16.227 +I72:
  16.228 +  int 72
  16.229 +  ret
  16.230 +I73:
  16.231 +  int 73
  16.232 +  ret
  16.233 +I74:
  16.234 +  int 74
  16.235 +  ret
  16.236 +I75:
  16.237 +  int 75
  16.238 +  ret
  16.239 +I76:
  16.240 +  int 76
  16.241 +  ret
  16.242 +I77:
  16.243 +  int 77
  16.244 +  ret
  16.245 +I78:
  16.246 +  int 78
  16.247 +  ret
  16.248 +I79:
  16.249 +  int 79
  16.250 +  ret
  16.251 +I80:
  16.252 +  int 80
  16.253 +  ret
  16.254 +I81:
  16.255 +  int 81
  16.256 +  ret
  16.257 +I82:
  16.258 +  int 82
  16.259 +  ret
  16.260 +I83:
  16.261 +  int 83
  16.262 +  ret
  16.263 +I84:
  16.264 +  int 84
  16.265 +  ret
  16.266 +I85:
  16.267 +  int 85
  16.268 +  ret
  16.269 +I86:
  16.270 +  int 86
  16.271 +  ret
  16.272 +I87:
  16.273 +  int 87
  16.274 +  ret
  16.275 +I88:
  16.276 +  int 88
  16.277 +  ret
  16.278 +I89:
  16.279 +  int 89
  16.280 +  ret
  16.281 +I90:
  16.282 +  int 90
  16.283 +  ret
  16.284 +I91:
  16.285 +  int 91
  16.286 +  ret
  16.287 +I92:
  16.288 +  int 92
  16.289 +  ret
  16.290 +I93:
  16.291 +  int 93
  16.292 +  ret
  16.293 +I94:
  16.294 +  int 94
  16.295 +  ret
  16.296 +I95:
  16.297 +  int 95
  16.298 +  ret
  16.299 +I96:
  16.300 +  int 96
  16.301 +  ret
  16.302 +I97:
  16.303 +  int 97
  16.304 +  ret
  16.305 +I98:
  16.306 +  int 98
  16.307 +  ret
  16.308 +I99:
  16.309 +  int 99
  16.310 +  ret
  16.311 +I100:
  16.312 +  int 100
  16.313 +  ret
  16.314 +I101:
  16.315 +  int 101
  16.316 +  ret
  16.317 +I102:
  16.318 +  int 102
  16.319 +  ret
  16.320 +I103:
  16.321 +  int 103
  16.322 +  ret
  16.323 +I104:
  16.324 +  int 104
  16.325 +  ret
  16.326 +I105:
  16.327 +  int 105
  16.328 +  ret
  16.329 +I106:
  16.330 +  int 106
  16.331 +  ret
  16.332 +I107:
  16.333 +  int 107
  16.334 +  ret
  16.335 +I108:
  16.336 +  int 108
  16.337 +  ret
  16.338 +I109:
  16.339 +  int 109
  16.340 +  ret
  16.341 +I110:
  16.342 +  int 110
  16.343 +  ret
  16.344 +I111:
  16.345 +  int 111
  16.346 +  ret
  16.347 +I112:
  16.348 +  int 112
  16.349 +  ret
  16.350 +I113:
  16.351 +  int 113
  16.352 +  ret
  16.353 +I114:
  16.354 +  int 114
  16.355 +  ret
  16.356 +I115:
  16.357 +  int 115
  16.358 +  ret
  16.359 +I116:
  16.360 +  int 116
  16.361 +  ret
  16.362 +I117:
  16.363 +  int 117
  16.364 +  ret
  16.365 +I118:
  16.366 +  int 118
  16.367 +  ret
  16.368 +I119:
  16.369 +  int 119
  16.370 +  ret
  16.371 +I120:
  16.372 +  int 120
  16.373 +  ret
  16.374 +I121:
  16.375 +  int 121
  16.376 +  ret
  16.377 +I122:
  16.378 +  int 122
  16.379 +  ret
  16.380 +I123:
  16.381 +  int 123
  16.382 +  ret
  16.383 +I124:
  16.384 +  int 124
  16.385 +  ret
  16.386 +I125:
  16.387 +  int 125
  16.388 +  ret
  16.389 +I126:
  16.390 +  int 126
  16.391 +  ret
  16.392 +I127:
  16.393 +  int 127
  16.394 +  ret
  16.395 +I128:
  16.396 +  int 128
  16.397 +  ret
  16.398 +I129:
  16.399 +  int 129
  16.400 +  ret
  16.401 +I130:
  16.402 +  int 130
  16.403 +  ret
  16.404 +I131:
  16.405 +  int 131
  16.406 +  ret
  16.407 +I132:
  16.408 +  int 132
  16.409 +  ret
  16.410 +I133:
  16.411 +  int 133
  16.412 +  ret
  16.413 +I134:
  16.414 +  int 134
  16.415 +  ret
  16.416 +I135:
  16.417 +  int 135
  16.418 +  ret
  16.419 +I136:
  16.420 +  int 136
  16.421 +  ret
  16.422 +I137:
  16.423 +  int 137
  16.424 +  ret
  16.425 +I138:
  16.426 +  int 138
  16.427 +  ret
  16.428 +I139:
  16.429 +  int 139
  16.430 +  ret
  16.431 +I140:
  16.432 +  int 140
  16.433 +  ret
  16.434 +I141:
  16.435 +  int 141
  16.436 +  ret
  16.437 +I142:
  16.438 +  int 142
  16.439 +  ret
  16.440 +I143:
  16.441 +  int 143
  16.442 +  ret
  16.443 +I144:
  16.444 +  int 144
  16.445 +  ret
  16.446 +I145:
  16.447 +  int 145
  16.448 +  ret
  16.449 +I146:
  16.450 +  int 146
  16.451 +  ret
  16.452 +I147:
  16.453 +  int 147
  16.454 +  ret
  16.455 +I148:
  16.456 +  int 148
  16.457 +  ret
  16.458 +I149:
  16.459 +  int 149
  16.460 +  ret
  16.461 +I150:
  16.462 +  int 150
  16.463 +  ret
  16.464 +I151:
  16.465 +  int 151
  16.466 +  ret
  16.467 +I152:
  16.468 +  int 152
  16.469 +  ret
  16.470 +I153:
  16.471 +  int 153
  16.472 +  ret
  16.473 +I154:
  16.474 +  int 154
  16.475 +  ret
  16.476 +I155:
  16.477 +  int 155
  16.478 +  ret
  16.479 +I156:
  16.480 +  int 156
  16.481 +  ret
  16.482 +I157:
  16.483 +  int 157
  16.484 +  ret
  16.485 +I158:
  16.486 +  int 158
  16.487 +  ret
  16.488 +I159:
  16.489 +  int 159
  16.490 +  ret
  16.491 +I160:
  16.492 +  int 160
  16.493 +  ret
  16.494 +I161:
  16.495 +  int 161
  16.496 +  ret
  16.497 +I162:
  16.498 +  int 162
  16.499 +  ret
  16.500 +I163:
  16.501 +  int 163
  16.502 +  ret
  16.503 +I164:
  16.504 +  int 164
  16.505 +  ret
  16.506 +I165:
  16.507 +  int 165
  16.508 +  ret
  16.509 +I166:
  16.510 +  int 166
  16.511 +  ret
  16.512 +I167:
  16.513 +  int 167
  16.514 +  ret
  16.515 +I168:
  16.516 +  int 168
  16.517 +  ret
  16.518 +I169:
  16.519 +  int 169
  16.520 +  ret
  16.521 +I170:
  16.522 +  int 170
  16.523 +  ret
  16.524 +I171:
  16.525 +  int 171
  16.526 +  ret
  16.527 +I172:
  16.528 +  int 172
  16.529 +  ret
  16.530 +I173:
  16.531 +  int 173
  16.532 +  ret
  16.533 +I174:
  16.534 +  int 174
  16.535 +  ret
  16.536 +I175:
  16.537 +  int 175
  16.538 +  ret
  16.539 +I176:
  16.540 +  int 176
  16.541 +  ret
  16.542 +I177:
  16.543 +  int 177
  16.544 +  ret
  16.545 +I178:
  16.546 +  int 178
  16.547 +  ret
  16.548 +I179:
  16.549 +  int 179
  16.550 +  ret
  16.551 +I180:
  16.552 +  int 180
  16.553 +  ret
  16.554 +I181:
  16.555 +  int 181
  16.556 +  ret
  16.557 +I182:
  16.558 +  int 182
  16.559 +  ret
  16.560 +I183:
  16.561 +  int 183
  16.562 +  ret
  16.563 +I184:
  16.564 +  int 184
  16.565 +  ret
  16.566 +I185:
  16.567 +  int 185
  16.568 +  ret
  16.569 +I186:
  16.570 +  int 186
  16.571 +  ret
  16.572 +I187:
  16.573 +  int 187
  16.574 +  ret
  16.575 +I188:
  16.576 +  int 188
  16.577 +  ret
  16.578 +I189:
  16.579 +  int 189
  16.580 +  ret
  16.581 +I190:
  16.582 +  int 190
  16.583 +  ret
  16.584 +I191:
  16.585 +  int 191
  16.586 +  ret
  16.587 +I192:
  16.588 +  int 192
  16.589 +  ret
  16.590 +I193:
  16.591 +  int 193
  16.592 +  ret
  16.593 +I194:
  16.594 +  int 194
  16.595 +  ret
  16.596 +I195:
  16.597 +  int 195
  16.598 +  ret
  16.599 +I196:
  16.600 +  int 196
  16.601 +  ret
  16.602 +I197:
  16.603 +  int 197
  16.604 +  ret
  16.605 +I198:
  16.606 +  int 198
  16.607 +  ret
  16.608 +I199:
  16.609 +  int 199
  16.610 +  ret
  16.611 +I200:
  16.612 +  int 200
  16.613 +  ret
  16.614 +I201:
  16.615 +  int 201
  16.616 +  ret
  16.617 +I202:
  16.618 +  int 202
  16.619 +  ret
  16.620 +I203:
  16.621 +  int 203
  16.622 +  ret
  16.623 +I204:
  16.624 +  int 204
  16.625 +  ret
  16.626 +I205:
  16.627 +  int 205
  16.628 +  ret
  16.629 +I206:
  16.630 +  int 206
  16.631 +  ret
  16.632 +I207:
  16.633 +  int 207
  16.634 +  ret
  16.635 +I208:
  16.636 +  int 208
  16.637 +  ret
  16.638 +I209:
  16.639 +  int 209
  16.640 +  ret
  16.641 +I210:
  16.642 +  int 210
  16.643 +  ret
  16.644 +I211:
  16.645 +  int 211
  16.646 +  ret
  16.647 +I212:
  16.648 +  int 212
  16.649 +  ret
  16.650 +I213:
  16.651 +  int 213
  16.652 +  ret
  16.653 +I214:
  16.654 +  int 214
  16.655 +  ret
  16.656 +I215:
  16.657 +  int 215
  16.658 +  ret
  16.659 +I216:
  16.660 +  int 216
  16.661 +  ret
  16.662 +I217:
  16.663 +  int 217
  16.664 +  ret
  16.665 +I218:
  16.666 +  int 218
  16.667 +  ret
  16.668 +I219:
  16.669 +  int 219
  16.670 +  ret
  16.671 +I220:
  16.672 +  int 220
  16.673 +  ret
  16.674 +I221:
  16.675 +  int 221
  16.676 +  ret
  16.677 +I222:
  16.678 +  int 222
  16.679 +  ret
  16.680 +I223:
  16.681 +  int 223
  16.682 +  ret
  16.683 +I224:
  16.684 +  int 224
  16.685 +  ret
  16.686 +I225:
  16.687 +  int 225
  16.688 +  ret
  16.689 +I226:
  16.690 +  int 226
  16.691 +  ret
  16.692 +I227:
  16.693 +  int 227
  16.694 +  ret
  16.695 +I228:
  16.696 +  int 228
  16.697 +  ret
  16.698 +I229:
  16.699 +  int 229
  16.700 +  ret
  16.701 +I230:
  16.702 +  int 230
  16.703 +  ret
  16.704 +I231:
  16.705 +  int 231
  16.706 +  ret
  16.707 +I232:
  16.708 +  int 232
  16.709 +  ret
  16.710 +I233:
  16.711 +  int 233
  16.712 +  ret
  16.713 +I234:
  16.714 +  int 234
  16.715 +  ret
  16.716 +I235:
  16.717 +  int 235
  16.718 +  ret
  16.719 +I236:
  16.720 +  int 236
  16.721 +  ret
  16.722 +I237:
  16.723 +  int 237
  16.724 +  ret
  16.725 +I238:
  16.726 +  int 238
  16.727 +  ret
  16.728 +I239:
  16.729 +  int 239
  16.730 +  ret
  16.731 +I240:
  16.732 +  int 240
  16.733 +  ret
  16.734 +I241:
  16.735 +  int 241
  16.736 +  ret
  16.737 +I242:
  16.738 +  int 242
  16.739 +  ret
  16.740 +I243:
  16.741 +  int 243
  16.742 +  ret
  16.743 +I244:
  16.744 +  int 244
  16.745 +  ret
  16.746 +I245:
  16.747 +  int 245
  16.748 +  ret
  16.749 +I246:
  16.750 +  int 246
  16.751 +  ret
  16.752 +I247:
  16.753 +  int 247
  16.754 +  ret
  16.755 +I248:
  16.756 +  int 248
  16.757 +  ret
  16.758 +I249:
  16.759 +  int 249
  16.760 +  ret
  16.761 +I250:
  16.762 +  int 250
  16.763 +  ret
  16.764 +I251:
  16.765 +  int 251
  16.766 +  ret
  16.767 +I252:
  16.768 +  int 252
  16.769 +  ret
  16.770 +I253:
  16.771 +  int 253
  16.772 +  ret
  16.773 +I254:
  16.774 +  int 254
  16.775 +  ret
  16.776 +I255:
  16.777 +  int 255
  16.778 +  ret
  16.779 +
  16.780 +.data
  16.781 +jump_table:
  16.782 +  dq I0
  16.783 +  dq I1
  16.784 +  dq I2
  16.785 +  dq I3
  16.786 +  dq I4
  16.787 +  dq I5
  16.788 +  dq I6
  16.789 +  dq I7
  16.790 +  dq I8
  16.791 +  dq I9
  16.792 +  dq I10
  16.793 +  dq I11
  16.794 +  dq I12
  16.795 +  dq I13
  16.796 +  dq I14
  16.797 +  dq I15
  16.798 +  dq I16
  16.799 +  dq I17
  16.800 +  dq I18
  16.801 +  dq I19
  16.802 +  dq I20
  16.803 +  dq I21
  16.804 +  dq I22
  16.805 +  dq I23
  16.806 +  dq I24
  16.807 +  dq I25
  16.808 +  dq I26
  16.809 +  dq I27
  16.810 +  dq I28
  16.811 +  dq I29
  16.812 +  dq I30
  16.813 +  dq I31
  16.814 +  dq I32
  16.815 +  dq I33
  16.816 +  dq I34
  16.817 +  dq I35
  16.818 +  dq I36
  16.819 +  dq I37
  16.820 +  dq I38
  16.821 +  dq I39
  16.822 +  dq I40
  16.823 +  dq I41
  16.824 +  dq I42
  16.825 +  dq I43
  16.826 +  dq I44
  16.827 +  dq I45
  16.828 +  dq I46
  16.829 +  dq I47
  16.830 +  dq I48
  16.831 +  dq I49
  16.832 +  dq I50
  16.833 +  dq I51
  16.834 +  dq I52
  16.835 +  dq I53
  16.836 +  dq I54
  16.837 +  dq I55
  16.838 +  dq I56
  16.839 +  dq I57
  16.840 +  dq I58
  16.841 +  dq I59
  16.842 +  dq I60
  16.843 +  dq I61
  16.844 +  dq I62
  16.845 +  dq I63
  16.846 +  dq I64
  16.847 +  dq I65
  16.848 +  dq I66
  16.849 +  dq I67
  16.850 +  dq I68
  16.851 +  dq I69
  16.852 +  dq I70
  16.853 +  dq I71
  16.854 +  dq I72
  16.855 +  dq I73
  16.856 +  dq I74
  16.857 +  dq I75
  16.858 +  dq I76
  16.859 +  dq I77
  16.860 +  dq I78
  16.861 +  dq I79
  16.862 +  dq I80
  16.863 +  dq I81
  16.864 +  dq I82
  16.865 +  dq I83
  16.866 +  dq I84
  16.867 +  dq I85
  16.868 +  dq I86
  16.869 +  dq I87
  16.870 +  dq I88
  16.871 +  dq I89
  16.872 +  dq I90
  16.873 +  dq I91
  16.874 +  dq I92
  16.875 +  dq I93
  16.876 +  dq I94
  16.877 +  dq I95
  16.878 +  dq I96
  16.879 +  dq I97
  16.880 +  dq I98
  16.881 +  dq I99
  16.882 +  dq I100
  16.883 +  dq I101
  16.884 +  dq I102
  16.885 +  dq I103
  16.886 +  dq I104
  16.887 +  dq I105
  16.888 +  dq I106
  16.889 +  dq I107
  16.890 +  dq I108
  16.891 +  dq I109
  16.892 +  dq I110
  16.893 +  dq I111
  16.894 +  dq I112
  16.895 +  dq I113
  16.896 +  dq I114
  16.897 +  dq I115
  16.898 +  dq I116
  16.899 +  dq I117
  16.900 +  dq I118
  16.901 +  dq I119
  16.902 +  dq I120
  16.903 +  dq I121
  16.904 +  dq I122
  16.905 +  dq I123
  16.906 +  dq I124
  16.907 +  dq I125
  16.908 +  dq I126
  16.909 +  dq I127
  16.910 +  dq I128
  16.911 +  dq I129
  16.912 +  dq I130
  16.913 +  dq I131
  16.914 +  dq I132
  16.915 +  dq I133
  16.916 +  dq I134
  16.917 +  dq I135
  16.918 +  dq I136
  16.919 +  dq I137
  16.920 +  dq I138
  16.921 +  dq I139
  16.922 +  dq I140
  16.923 +  dq I141
  16.924 +  dq I142
  16.925 +  dq I143
  16.926 +  dq I144
  16.927 +  dq I145
  16.928 +  dq I146
  16.929 +  dq I147
  16.930 +  dq I148
  16.931 +  dq I149
  16.932 +  dq I150
  16.933 +  dq I151
  16.934 +  dq I152
  16.935 +  dq I153
  16.936 +  dq I154
  16.937 +  dq I155
  16.938 +  dq I156
  16.939 +  dq I157
  16.940 +  dq I158
  16.941 +  dq I159
  16.942 +  dq I160
  16.943 +  dq I161
  16.944 +  dq I162
  16.945 +  dq I163
  16.946 +  dq I164
  16.947 +  dq I165
  16.948 +  dq I166
  16.949 +  dq I167
  16.950 +  dq I168
  16.951 +  dq I169
  16.952 +  dq I170
  16.953 +  dq I171
  16.954 +  dq I172
  16.955 +  dq I173
  16.956 +  dq I174
  16.957 +  dq I175
  16.958 +  dq I176
  16.959 +  dq I177
  16.960 +  dq I178
  16.961 +  dq I179
  16.962 +  dq I180
  16.963 +  dq I181
  16.964 +  dq I182
  16.965 +  dq I183
  16.966 +  dq I184
  16.967 +  dq I185
  16.968 +  dq I186
  16.969 +  dq I187
  16.970 +  dq I188
  16.971 +  dq I189
  16.972 +  dq I190
  16.973 +  dq I191
  16.974 +  dq I192
  16.975 +  dq I193
  16.976 +  dq I194
  16.977 +  dq I195
  16.978 +  dq I196
  16.979 +  dq I197
  16.980 +  dq I198
  16.981 +  dq I199
  16.982 +  dq I200
  16.983 +  dq I201
  16.984 +  dq I202
  16.985 +  dq I203
  16.986 +  dq I204
  16.987 +  dq I205
  16.988 +  dq I206
  16.989 +  dq I207
  16.990 +  dq I208
  16.991 +  dq I209
  16.992 +  dq I210
  16.993 +  dq I211
  16.994 +  dq I212
  16.995 +  dq I213
  16.996 +  dq I214
  16.997 +  dq I215
  16.998 +  dq I216
  16.999 +  dq I217
 16.1000 +  dq I218
 16.1001 +  dq I219
 16.1002 +  dq I220
 16.1003 +  dq I221
 16.1004 +  dq I222
 16.1005 +  dq I223
 16.1006 +  dq I224
 16.1007 +  dq I225
 16.1008 +  dq I226
 16.1009 +  dq I227
 16.1010 +  dq I228
 16.1011 +  dq I229
 16.1012 +  dq I230
 16.1013 +  dq I231
 16.1014 +  dq I232
 16.1015 +  dq I233
 16.1016 +  dq I234
 16.1017 +  dq I235
 16.1018 +  dq I236
 16.1019 +  dq I237
 16.1020 +  dq I238
 16.1021 +  dq I239
 16.1022 +  dq I240
 16.1023 +  dq I241
 16.1024 +  dq I242
 16.1025 +  dq I243
 16.1026 +  dq I244
 16.1027 +  dq I245
 16.1028 +  dq I246
 16.1029 +  dq I247
 16.1030 +  dq I248
 16.1031 +  dq I249
 16.1032 +  dq I250
 16.1033 +  dq I251
 16.1034 +  dq I252
 16.1035 +  dq I253
 16.1036 +  dq I254
 16.1037 +  dq I255
 16.1038 +.code
 16.1039 +_sw_interrupt endp
 16.1040 +END
    17.1 --- a/xenpci/evtchn.c	Sat May 17 00:06:05 2008 +1000
    17.2 +++ b/xenpci/evtchn.c	Thu May 22 13:46:15 2008 +1000
    17.3 @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fi
    17.4  
    17.5  #include "xenpci.h"
    17.6  
    17.7 -#if defined(_WIN32)
    17.8 +#if defined(_X86_)
    17.9    #define xchg(p1, p2) _InterlockedExchange(p1, p2)
   17.10    #define synch_clear_bit(p1, p2) _interlockedbittestandreset(p2, p1)
   17.11    #define synch_set_bit(p1, p2) _interlockedbittestandset(p2, p1)
    18.1 --- a/xenpci/hypercall_amd64.h	Sat May 17 00:06:05 2008 +1000
    18.2 +++ b/xenpci/hypercall_amd64.h	Thu May 22 13:46:15 2008 +1000
    18.3 @@ -20,28 +20,28 @@ Foundation, Inc., 51 Franklin Street, Fi
    18.4  extern int _hypercall2(VOID *address, int cmd, void *arg);
    18.5  
    18.6  static __inline int
    18.7 -HYPERVISOR_memory_op(WDFDEVICE Device, int cmd, void *arg)
    18.8 +HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
    18.9  {
   18.10 -  PCHAR memory_op_func = GetDeviceData(Device)->hypercall_stubs;
   18.11 +  PCHAR memory_op_func = xpdd->hypercall_stubs;
   18.12    memory_op_func += __HYPERVISOR_memory_op * 32;
   18.13    return _hypercall2(memory_op_func, cmd, arg);
   18.14  }
   18.15  
   18.16  static __inline int
   18.17 -HYPERVISOR_xen_version(WDFDEVICE Device, int cmd, void *arg)
   18.18 +HYPERVISOR_xen_version(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   18.19  {
   18.20 -  PCHAR xen_version_func = GetDeviceData(Device)->hypercall_stubs;
   18.21 +  PCHAR xen_version_func = xpdd->hypercall_stubs;
   18.22    xen_version_func += __HYPERVISOR_xen_version * 32;
   18.23    return _hypercall2(xen_version_func, cmd, arg);
   18.24  }
   18.25  
   18.26  #if 0
   18.27  static __inline int
   18.28 -HYPERVISOR_grant_table_op(WDFDEVICE Device, int cmd, void *uop, unsigned int count)
   18.29 +HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
   18.30  {
   18.31    ASSERTMSG("grant_table_op not yet supported under AMD64", FALSE);
   18.32  /*
   18.33 -  char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
   18.34 +  char *hypercall_stubs = xpdd->hypercall_stubs;
   18.35    long __res;
   18.36    __asm {
   18.37      mov ebx, cmd
   18.38 @@ -58,11 +58,11 @@ HYPERVISOR_grant_table_op(WDFDEVICE Devi
   18.39  }
   18.40  
   18.41  static __inline int
   18.42 -HYPERVISOR_mmu_update(WDFDEVICE Device, mmu_update_t *req, int count, int *success_count, domid_t domid)
   18.43 +HYPERVISOR_mmu_update(PXENPCI_DEVICE_DATA xpdd, mmu_update_t *req, int count, int *success_count, domid_t domid)
   18.44  {
   18.45    ASSERTMSG("mmu_update not yet supported under AMD64", FALSE);
   18.46  /*
   18.47 -  char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
   18.48 +  char *hypercall_stubs = xpdd->hypercall_stubs;
   18.49    long __res;
   18.50    long _domid = (long)domid;
   18.51    __asm {
   18.52 @@ -81,11 +81,11 @@ HYPERVISOR_mmu_update(WDFDEVICE Device, 
   18.53  }
   18.54  
   18.55  static __inline int
   18.56 -HYPERVISOR_console_io(WDFDEVICE Device, int cmd, int count, char *string)
   18.57 +HYPERVISOR_console_io(PXENPCI_DEVICE_DATA xpdd, int cmd, int count, char *string)
   18.58  {
   18.59    ASSERTMSG("console_io not yet supported under AMD64", FALSE);
   18.60  /*
   18.61 -  char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
   18.62 +  char *hypercall_stubs = xpdd->hypercall_stubs;
   18.63    long __res;
   18.64    __asm {
   18.65      mov ebx, cmd
   18.66 @@ -103,31 +103,31 @@ HYPERVISOR_console_io(WDFDEVICE Device, 
   18.67  #endif
   18.68  
   18.69  static __inline int
   18.70 -HYPERVISOR_hvm_op(WDFDEVICE Device, int op, struct xen_hvm_param *arg)
   18.71 +HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
   18.72  {
   18.73 -  PCHAR hvm_op_func = GetDeviceData(Device)->hypercall_stubs;
   18.74 +  PCHAR hvm_op_func = xpdd->hypercall_stubs;
   18.75    hvm_op_func += __HYPERVISOR_hvm_op * 32;
   18.76    return _hypercall2(hvm_op_func, op, arg);
   18.77  }
   18.78  
   18.79  static __inline int
   18.80 -HYPERVISOR_event_channel_op(WDFDEVICE Device, int cmd, void *op)
   18.81 +HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *op)
   18.82  {
   18.83 -  PCHAR event_channel_op_func = GetDeviceData(Device)->hypercall_stubs;
   18.84 +  PCHAR event_channel_op_func = xpdd->hypercall_stubs;
   18.85    event_channel_op_func += __HYPERVISOR_event_channel_op * 32;
   18.86    return _hypercall2(event_channel_op_func, cmd, op);
   18.87  }
   18.88  
   18.89  static __inline int
   18.90 -HYPERVISOR_sched_op(WDFDEVICE Device, int cmd, void *arg)
   18.91 +HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   18.92  {
   18.93 -  PCHAR sched_op_func = GetDeviceData(Device)->hypercall_stubs;
   18.94 +  PCHAR sched_op_func = xpdd->hypercall_stubs;
   18.95    sched_op_func += __HYPERVISOR_sched_op * 32;
   18.96    return _hypercall2(sched_op_func, cmd, arg);
   18.97  }
   18.98  
   18.99  static __inline int
  18.100 -HYPERVISOR_shutdown(WDFDEVICE Device, unsigned int reason)
  18.101 +HYPERVISOR_shutdown(PXENPCI_DEVICE_DATA xpdd, unsigned int reason)
  18.102  {
  18.103    struct sched_shutdown ss;
  18.104    int retval;
  18.105 @@ -138,15 +138,16 @@ HYPERVISOR_shutdown(WDFDEVICE Device, un
  18.106  
  18.107    KdPrint((__DRIVER_NAME "     A\n"));
  18.108  
  18.109 -  retval = HYPERVISOR_sched_op(Device, SCHEDOP_shutdown, &ss);
  18.110 +  retval = HYPERVISOR_sched_op(xpdd, SCHEDOP_shutdown, &ss);
  18.111  
  18.112    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  18.113  
  18.114    return retval;
  18.115  }
  18.116  
  18.117 +#if 0
  18.118  static __inline ULONGLONG
  18.119 -hvm_get_parameter(WDFDEVICE Device, int hvm_param)
  18.120 +hvm_get_parameter(PXENPCI_DEVICE_DATA xpdd, int hvm_param)
  18.121  {
  18.122    struct xen_hvm_param a;
  18.123    int retval;
  18.124 @@ -154,9 +155,10 @@ hvm_get_parameter(WDFDEVICE Device, int 
  18.125    KdPrint((__DRIVER_NAME " --> hvm_get_parameter\n"));
  18.126    a.domid = DOMID_SELF;
  18.127    a.index = hvm_param;
  18.128 -  retval = HYPERVISOR_hvm_op(Device, HVMOP_get_param, &a);
  18.129 +  retval = HYPERVISOR_hvm_op(xpdd, HVMOP_get_param, &a);
  18.130    KdPrint((__DRIVER_NAME " hvm_get_parameter retval = %d\n", retval));
  18.131    KdPrint((__DRIVER_NAME " hvm_get_parameter value = %ld\n", a.value));
  18.132    KdPrint((__DRIVER_NAME " <-- hvm_get_parameter\n"));
  18.133    return a.value;
  18.134  }
  18.135 +#endif
  18.136 \ No newline at end of file
    19.1 --- a/xenpci/sources	Sat May 17 00:06:05 2008 +1000
    19.2 +++ b/xenpci/sources	Thu May 22 13:46:15 2008 +1000
    19.3 @@ -6,5 +6,5 @@ TARGETTYPE=DRIVER
    19.4  INF_NAME=$(TARGETNAME)
    19.5  MISCFILES=..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf
    19.6  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\wdmsec.lib
    19.7 -AMD64_SOURCES=hypercall.asm
    19.8 +AMD64_SOURCES=hypercall.asm swint.asm
    19.9  SOURCES=xenpci.c xenpci_fdo.c xenpci_pdo.c evtchn.c gnttbl.c xenbus.c
   19.10 \ No newline at end of file
    20.1 --- a/xenpci/xenpci.c	Sat May 17 00:06:05 2008 +1000
    20.2 +++ b/xenpci/xenpci.c	Thu May 22 13:46:15 2008 +1000
    20.3 @@ -185,9 +185,6 @@ XenPci_AddDevice(PDRIVER_OBJECT DriverOb
    20.4    WdfDeviceSetSpecialFileSupport(Device, WdfSpecialFileHibernation, TRUE);
    20.5    WdfDeviceSetSpecialFileSupport(Device, WdfSpecialFileDump, TRUE);
    20.6  
    20.7 -#if (NTDDI_VERSION >= NTDDI_WS03SP1)
    20.8 -  KeInitializeGuardedMutex(&xpdd->WatchHandlerMutex);
    20.9 -#endif
   20.10    busInfo.BusTypeGuid = GUID_XENPCI_DEVCLASS;
   20.11    busInfo.LegacyBusType = Internal;
   20.12    busInfo.BusNumber = 0;
    21.1 --- a/xenpci/xenpci.h	Sat May 17 00:06:05 2008 +1000
    21.2 +++ b/xenpci/xenpci.h	Thu May 22 13:46:15 2008 +1000
    21.3 @@ -106,11 +106,26 @@ typedef struct _XENBUS_WATCH_ENTRY {
    21.4  
    21.5  // TODO: tidy up & organize this struct
    21.6  
    21.7 +typedef enum {
    21.8 +    Unknown = 0,
    21.9 +    NotStarted,
   21.10 +    Started,
   21.11 +    StopPending,
   21.12 +    Stopped,
   21.13 +    RemovePending,
   21.14 +    SurpriseRemovePending,
   21.15 +    Removed
   21.16 +} DEVICE_PNP_STATE;
   21.17 +
   21.18  typedef struct
   21.19  {
   21.20    PDEVICE_OBJECT fdo;
   21.21    PDEVICE_OBJECT pdo;
   21.22    PDEVICE_OBJECT lower_do;
   21.23 +  
   21.24 +  DEVICE_PNP_STATE device_pnp_state;
   21.25 +  DEVICE_POWER_STATE device_power_state;
   21.26 +  SYSTEM_POWER_STATE system_power_state; 
   21.27  } XENPCI_COMMON, *PXENPCI_COMMON;
   21.28  
   21.29  #define SHUTDOWN_RING_SIZE 128
   21.30 @@ -180,18 +195,24 @@ typedef struct {
   21.31    PIRP shutdown_irp;
   21.32  } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
   21.33  
   21.34 +/* The total number of event channels or rings allowed per device... probably never more than 2 */
   21.35 +#define MAX_RESOURCES 4
   21.36 +
   21.37  typedef struct {  
   21.38    XENPCI_COMMON common;
   21.39    PDEVICE_OBJECT bus_fdo;
   21.40    char path[128];
   21.41    char device[128];
   21.42    ULONG index;
   21.43 -  //PHYSICAL_ADDRESS mmio_phys;
   21.44    ULONG irq_vector;
   21.45    KIRQL irq_level;
   21.46    char backend_path[128];
   21.47 +  PVOID xenbus_request;
   21.48    KEVENT backend_state_event;
   21.49    ULONG backend_state;
   21.50 +  grant_ref_t grant_refs[MAX_RESOURCES];
   21.51 +  PMDL mdls[MAX_RESOURCES];
   21.52 +  evtchn_port_t event_channels[MAX_RESOURCES];
   21.53  } XENPCI_PDO_DEVICE_DATA, *PXENPCI_PDO_DEVICE_DATA;
   21.54  
   21.55  typedef struct
   21.56 @@ -203,6 +224,7 @@ typedef struct
   21.57  
   21.58  #define SWINT(x) case x: __asm { int x } break;
   21.59  
   21.60 +#if defined(_X86_)
   21.61  static __inline VOID
   21.62  sw_interrupt(UCHAR intno)
   21.63  {
   21.64 @@ -230,6 +252,16 @@ sw_interrupt(UCHAR intno)
   21.65      break;
   21.66    }
   21.67  }    
   21.68 +#else
   21.69 +VOID _sw_interrupt(UCHAR);
   21.70 +
   21.71 +static __inline VOID
   21.72 +sw_interrupt(UCHAR intno)
   21.73 +{
   21.74 +  _sw_interrupt(intno);
   21.75 +}
   21.76 +#endif
   21.77 +
   21.78    
   21.79  #include "hypercall.h"
   21.80  
    22.1 --- a/xenpci/xenpci.inx	Sat May 17 00:06:05 2008 +1000
    22.2 +++ b/xenpci/xenpci.inx	Thu May 22 13:46:15 2008 +1000
    22.3 @@ -3,6 +3,7 @@ Signature="$WINDOWS NT$"
    22.4  Class=System
    22.5  ClassGuid={4D36E97D-E325-11CE-BFC1-08002BE10318}
    22.6  Provider=%XenGplPv%
    22.7 +CatalogFile="XenGPLPV.cat"
    22.8  
    22.9  [DestinationDirs]
   22.10  DefaultDestDir = 12
    23.1 --- a/xenpci/xenpci_fdo.c	Sat May 17 00:06:05 2008 +1000
    23.2 +++ b/xenpci/xenpci_fdo.c	Thu May 22 13:46:15 2008 +1000
    23.3 @@ -47,7 +47,7 @@ XenPci_Power_Fdo(PDEVICE_OBJECT device_o
    23.4    PIO_STACK_LOCATION stack;
    23.5    POWER_STATE_TYPE power_type;
    23.6    POWER_STATE power_state;
    23.7 -  PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
    23.8 +  PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
    23.9    //PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   23.10  
   23.11    UNREFERENCED_PARAMETER(device_object);
   23.12 @@ -84,7 +84,7 @@ XenPci_Power_Fdo(PDEVICE_OBJECT device_o
   23.13    }
   23.14    PoStartNextPowerIrp(irp);
   23.15    IoSkipCurrentIrpStackLocation(irp);
   23.16 -  status =  PoCallDriver (xppdd->common.lower_do, irp);
   23.17 +  status =  PoCallDriver (xpdd->common.lower_do, irp);
   23.18    
   23.19    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   23.20  
   23.21 @@ -300,6 +300,7 @@ XenBus_ShutdownIoCancel(PDEVICE_OBJECT d
   23.22    irp->IoStatus.Information = 0;
   23.23    KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
   23.24    IoCompleteRequest(irp, IO_NO_INCREMENT);
   23.25 +
   23.26    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   23.27  }
   23.28  
   23.29 @@ -324,7 +325,6 @@ XenBus_ShutdownHandler(char *path, PVOID
   23.30    }
   23.31  
   23.32    KdPrint((__DRIVER_NAME "     Shutdown value = %s\n", value));
   23.33 -  KdPrint((__DRIVER_NAME "     strlen(...) = %d\n", strlen(value)));
   23.34  
   23.35    if (strlen(value) != 0)
   23.36    {
   23.37 @@ -335,19 +335,16 @@ XenBus_ShutdownHandler(char *path, PVOID
   23.38      }
   23.39      else
   23.40      {
   23.41 -      KdPrint((__DRIVER_NAME "     Before - shutdown_start = %d, shutdown_prod = %d, shutdown_cons = %d\n",xpdd->shutdown_start, xpdd->shutdown_prod, xpdd->shutdown_cons));
   23.42        KeAcquireSpinLock(&xpdd->shutdown_ring_lock, &old_irql);
   23.43        if (xpdd->shutdown_start >= xpdd->shutdown_cons)
   23.44          xpdd->shutdown_prod = xpdd->shutdown_start;
   23.45        else
   23.46          xpdd->shutdown_start = xpdd->shutdown_prod;
   23.47 -      KdPrint((__DRIVER_NAME "     Middle - shutdown_start = %d, shutdown_prod = %d, shutdown_cons = %d\n",xpdd->shutdown_start, xpdd->shutdown_prod, xpdd->shutdown_cons));
   23.48        memcpy(&xpdd->shutdown_ring[xpdd->shutdown_prod], value, strlen(value));
   23.49 -      xpdd->shutdown_prod += strlen(value);
   23.50 +      xpdd->shutdown_prod += (ULONG)strlen(value);
   23.51        xpdd->shutdown_ring[xpdd->shutdown_prod++] = '\r';
   23.52        xpdd->shutdown_ring[xpdd->shutdown_prod++] = '\n';
   23.53        KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
   23.54 -      KdPrint((__DRIVER_NAME "     After - shutdown_start = %d, shutdown_prod = %d, shutdown_cons = %d\n",xpdd->shutdown_start, xpdd->shutdown_prod, xpdd->shutdown_cons));
   23.55        XenPci_ProcessShutdownIrp(xpdd);
   23.56      }
   23.57    }
   23.58 @@ -358,6 +355,30 @@ XenBus_ShutdownHandler(char *path, PVOID
   23.59  }
   23.60  
   23.61  static VOID
   23.62 +XenPci_DeviceWatchHandler(char *path, PVOID context)
   23.63 +{
   23.64 +  char **bits;
   23.65 +  int count;
   23.66 +  PXENPCI_DEVICE_DATA xpdd = context;
   23.67 +
   23.68 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   23.69 +
   23.70 +  KdPrint((__DRIVER_NAME "     path = %s\n", path));
   23.71 +  bits = SplitString(path, '/', 4, &count);
   23.72 +  KdPrint((__DRIVER_NAME "     count = %d\n", count));
   23.73 +
   23.74 +  if (count == 3)
   23.75 +  {
   23.76 +    /* we probably have to be a bit smarter here and do nothing if xenpci isn't running yet */
   23.77 +    KdPrint((__DRIVER_NAME "     Invalidating Device Relations\n"));
   23.78 +    IoInvalidateDeviceRelations(xpdd->common.pdo, BusRelations);
   23.79 +  }
   23.80 +  FreeSplitString(bits, count);
   23.81 +
   23.82 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   23.83 +}
   23.84 +
   23.85 +static VOID
   23.86  XenPci_Pnp_StartDeviceCallback(PDEVICE_OBJECT device_object, PVOID context)
   23.87  {
   23.88    NTSTATUS status = STATUS_SUCCESS;
   23.89 @@ -381,6 +402,9 @@ XenPci_Pnp_StartDeviceCallback(PDEVICE_O
   23.90    response = XenBus_AddWatch(xpdd, XBT_NIL, SHUTDOWN_PATH, XenBus_ShutdownHandler, xpdd);
   23.91    KdPrint((__DRIVER_NAME "     shutdown watch response = '%s'\n", response)); 
   23.92  
   23.93 +  response = XenBus_AddWatch(xpdd, XBT_NIL, "device", XenPci_DeviceWatchHandler, xpdd);
   23.94 +  KdPrint((__DRIVER_NAME "     device watch response = '%s'\n", response)); 
   23.95 +
   23.96    status = IoSetDeviceInterfaceState(&xpdd->interface_name, TRUE);
   23.97    if (!NT_SUCCESS(status))
   23.98    {
   23.99 @@ -692,10 +716,12 @@ XenPci_Pnp_QueryBusRelationsCallback(PDE
  23.100                &pdo);
  23.101              if (!NT_SUCCESS(status))
  23.102                KdPrint((__DRIVER_NAME "     IoCreateDevice status = %08X\n", status));
  23.103 +            RtlZeroMemory(pdo->DeviceExtension, sizeof(XENPCI_PDO_DEVICE_DATA));
  23.104              child->context = (PXENPCI_PDO_DEVICE_DATA)pdo->DeviceExtension;
  23.105              child->context->common.fdo = NULL;
  23.106              child->context->common.pdo = pdo;
  23.107              child->context->common.lower_do = NULL;
  23.108 +            child->context->common.device_pnp_state = NotStarted;
  23.109              child->context->bus_fdo = device_object;
  23.110              RtlStringCbCopyA(child->context->path, ARRAY_SIZE(child->context->path), path);
  23.111              RtlStringCbCopyA(child->context->device, ARRAY_SIZE(child->context->device), devices[i]);
    24.1 --- a/xenpci/xenpci_pdo.c	Sat May 17 00:06:05 2008 +1000
    24.2 +++ b/xenpci/xenpci_pdo.c	Thu May 22 13:46:15 2008 +1000
    24.3 @@ -36,7 +36,7 @@ XenPci_Power_Pdo(PDEVICE_OBJECT device_o
    24.4  
    24.5    UNREFERENCED_PARAMETER(device_object);
    24.6    
    24.7 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    24.8 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    24.9  
   24.10    stack = IoGetCurrentIrpStackLocation(irp);
   24.11    power_type = stack->Parameters.Power.Type;
   24.12 @@ -84,7 +84,7 @@ XenPci_Power_Pdo(PDEVICE_OBJECT device_o
   24.13    status = irp->IoStatus.Status;
   24.14    IoCompleteRequest(irp, IO_NO_INCREMENT);
   24.15    
   24.16 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   24.17 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   24.18  
   24.19    return status;
   24.20  }
   24.21 @@ -171,8 +171,185 @@ struct dummy_sring {
   24.22  };
   24.23  
   24.24  static NTSTATUS
   24.25 +XenPci_ChangeFrontendState(PXENPCI_PDO_DEVICE_DATA xppdd, ULONG frontend_state_set, ULONG backend_state_response, ULONG maximum_wait_ms)
   24.26 +{
   24.27 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   24.28 +  LARGE_INTEGER timeout;
   24.29 +  ULONG remaining;
   24.30 +  ULONG thiswait;
   24.31 +  char path[128];
   24.32 +  
   24.33 +  /* Tell backend we're going down */
   24.34 +  RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->path);
   24.35 +  XenBus_Printf(xpdd, XBT_NIL, path, "%d", frontend_state_set);
   24.36 +
   24.37 +  remaining = maximum_wait_ms;
   24.38 +  while (xppdd->backend_state != backend_state_response)
   24.39 +  {
   24.40 +    thiswait = min((LONG)remaining, 1000); // 1 second or remaining time, whichever is less
   24.41 +    timeout.QuadPart = (LONGLONG)-1 * thiswait * 1000 * 10;
   24.42 +    if (KeWaitForSingleObject(&xppdd->backend_state_event, Executive, KernelMode, FALSE, &timeout) == STATUS_TIMEOUT)
   24.43 +    {
   24.44 +      remaining -= thiswait;
   24.45 +      if (remaining == 0)
   24.46 +      {
   24.47 +        KdPrint((__DRIVER_NAME "     Timed out waiting for %d!\n", backend_state_response));
   24.48 +        return STATUS_UNSUCCESSFUL;
   24.49 +      }
   24.50 +      KdPrint((__DRIVER_NAME "     Still waiting for %d (currently %d)...\n", backend_state_response, xppdd->backend_state));
   24.51 +    }
   24.52 +  }
   24.53 +  return STATUS_SUCCESS;
   24.54 +}
   24.55 +
   24.56 +static VOID
   24.57 +DUMP_CURRENT_PNP_STATE(PXENPCI_PDO_DEVICE_DATA xppdd)
   24.58 +{
   24.59 +  switch (xppdd->common.device_pnp_state)
   24.60 +  {
   24.61 +  case Unknown:
   24.62 +    KdPrint((__DRIVER_NAME "     pnp_state = Unknown\n"));
   24.63 +    break;
   24.64 +  case NotStarted:
   24.65 +    KdPrint((__DRIVER_NAME "     pnp_state = NotStarted\n"));
   24.66 +    break;
   24.67 +  case Started:
   24.68 +    KdPrint((__DRIVER_NAME "     pnp_state = Started\n"));
   24.69 +    break;
   24.70 +  case StopPending:
   24.71 +    KdPrint((__DRIVER_NAME "     pnp_state = StopPending\n"));
   24.72 +    break;
   24.73 +  case Stopped:
   24.74 +    KdPrint((__DRIVER_NAME "     pnp_state = Stopped\n"));
   24.75 +    break;
   24.76 +  case RemovePending:
   24.77 +    KdPrint((__DRIVER_NAME "     pnp_state = RemovePending\n"));
   24.78 +    break;
   24.79 +  case SurpriseRemovePending:
   24.80 +    KdPrint((__DRIVER_NAME "     pnp_state = SurpriseRemovePending\n"));
   24.81 +    break;
   24.82 +  case Removed:
   24.83 +    KdPrint((__DRIVER_NAME "     pnp_state = Removed\n"));
   24.84 +    break;
   24.85 +  default:
   24.86 +    KdPrint((__DRIVER_NAME "     pnp_state = ???\n"));
   24.87 +    break;
   24.88 +  }
   24.89 +}
   24.90 +
   24.91 +static NTSTATUS
   24.92 +XenPci_EvtChn_Bind(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext)
   24.93 +{
   24.94 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
   24.95 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   24.96 +  
   24.97 +  return EvtChn_Bind(xpdd, Port, ServiceRoutine, ServiceContext);
   24.98 +}
   24.99 +
  24.100 +static NTSTATUS
  24.101 +XenPci_EvtChn_BindDpc(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext)
  24.102 +{
  24.103 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.104 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.105 +  
  24.106 +  return EvtChn_BindDpc(xpdd, Port, ServiceRoutine, ServiceContext);
  24.107 +}
  24.108 +
  24.109 +static NTSTATUS
  24.110 +XenPci_EvtChn_Unbind(PVOID Context, evtchn_port_t Port)
  24.111 +{
  24.112 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.113 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.114 +  
  24.115 +  return EvtChn_Unbind(xpdd, Port);
  24.116 +}
  24.117 +
  24.118 +static NTSTATUS
  24.119 +XenPci_EvtChn_Mask(PVOID Context, evtchn_port_t Port)
  24.120 +{
  24.121 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.122 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.123 +  
  24.124 +  return EvtChn_Mask(xpdd, Port);
  24.125 +}
  24.126 +
  24.127 +static NTSTATUS
  24.128 +XenPci_EvtChn_Unmask(PVOID Context, evtchn_port_t Port)
  24.129 +{
  24.130 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.131 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.132 +  
  24.133 +  return EvtChn_Unmask(xpdd, Port);
  24.134 +}
  24.135 +
  24.136 +static NTSTATUS
  24.137 +XenPci_EvtChn_Notify(PVOID Context, evtchn_port_t Port)
  24.138 +{
  24.139 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.140 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.141 +  
  24.142 +  return EvtChn_Notify(xpdd, Port);
  24.143 +}
  24.144 +
  24.145 +static grant_ref_t
  24.146 +XenPci_GntTbl_GrantAccess(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref)
  24.147 +{
  24.148 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.149 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.150 +  
  24.151 +  return GntTbl_GrantAccess(xpdd, domid, frame, readonly, ref);
  24.152 +}
  24.153 +
  24.154 +static BOOLEAN
  24.155 +XenPci_GntTbl_EndAccess(PVOID Context, grant_ref_t ref, BOOLEAN keepref)
  24.156 +{
  24.157 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.158 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.159 +  
  24.160 +  return GntTbl_EndAccess(xpdd, ref, keepref);
  24.161 +}
  24.162 +
  24.163 +static VOID
  24.164 +XenPci_GntTbl_PutRef(PVOID Context, grant_ref_t ref)
  24.165 +{
  24.166 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.167 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.168 +  
  24.169 +  GntTbl_PutRef(xpdd, ref);
  24.170 +}
  24.171 +
  24.172 +static grant_ref_t
  24.173 +XenPci_GntTbl_GetRef(PVOID Context)
  24.174 +{
  24.175 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.176 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.177 +  
  24.178 +  return GntTbl_GetRef(xpdd);
  24.179 +}
  24.180 +
  24.181 +static NTSTATUS
  24.182 +XenPci_ShutdownDevice(PVOID Context)
  24.183 +{
  24.184 +  PXENPCI_PDO_DEVICE_DATA xppdd = Context;
  24.185 +
  24.186 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  24.187 +
  24.188 +  if (xppdd->backend_state == XenbusStateConnected)
  24.189 +    XenPci_ChangeFrontendState(xppdd, XenbusStateClosing, XenbusStateClosing, 30000);
  24.190 +  if (xppdd->backend_state == XenbusStateClosing)
  24.191 +    XenPci_ChangeFrontendState(xppdd, XenbusStateClosed, XenbusStateClosed, 30000);
  24.192 +  if (xppdd->backend_state == XenbusStateClosed)
  24.193 +    XenPci_ChangeFrontendState(xppdd, XenbusStateInitialising, XenbusStateInitWait, 30000);
  24.194 +    
  24.195 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  24.196 +
  24.197 +  return STATUS_SUCCESS;
  24.198 +}
  24.199 +
  24.200 +static NTSTATUS
  24.201  XenPci_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
  24.202  {
  24.203 +  NTSTATUS status = STATUS_SUCCESS;
  24.204    PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
  24.205    PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.206    PIO_STACK_LOCATION stack;
  24.207 @@ -182,20 +359,20 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  24.208    char path[128];
  24.209    PCHAR setting, value;
  24.210    PCHAR res;
  24.211 -  PMDL mdl;
  24.212    PVOID address;
  24.213 -  grant_ref_t gref;
  24.214 -  evtchn_port_t event_channel;
  24.215    UCHAR type;
  24.216 -  PUCHAR in_ptr = NULL, in_start = NULL;
  24.217 +  PUCHAR in_ptr = NULL;
  24.218    PUCHAR out_ptr, out_start = NULL;
  24.219    XENPCI_VECTORS vectors;
  24.220 -  LARGE_INTEGER timeout;
  24.221 -
  24.222 -  UNREFERENCED_PARAMETER(device_object);
  24.223 +  ULONG rings = 0;
  24.224 +  ULONG event_channels = 0;
  24.225  
  24.226    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  24.227  
  24.228 +  DUMP_CURRENT_PNP_STATE(xppdd);
  24.229 +  
  24.230 +  xppdd->xenbus_request = NULL;
  24.231 +  
  24.232    stack = IoGetCurrentIrpStackLocation(irp);
  24.233  
  24.234    /* Get backend path */
  24.235 @@ -206,6 +383,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  24.236    {
  24.237      KdPrint((__DRIVER_NAME "    Failed to read backend path\n"));
  24.238      XenPci_FreeMem(res);
  24.239 +    return STATUS_UNSUCCESSFUL;
  24.240    }
  24.241    RtlStringCbCopyA(xppdd->backend_path, ARRAY_SIZE(xppdd->backend_path), value);
  24.242    XenPci_FreeMem(value);
  24.243 @@ -214,16 +392,11 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  24.244    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  24.245    XenBus_AddWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  24.246  
  24.247 -  /* Tell backend we're coming up */
  24.248 -  RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->path);
  24.249 -  XenBus_Printf(xpdd, XBT_NIL, path, "%d", XenbusStateInitialising);
  24.250 -
  24.251 -  // wait here for signal that we are all set up - we should probably add a timeout to make sure we don't hang forever
  24.252 -  while (xppdd->backend_state != XenbusStateInitWait)
  24.253 +  if (XenPci_ChangeFrontendState(xppdd, XenbusStateInitialising, XenbusStateInitWait, 30000) != STATUS_SUCCESS)
  24.254    {
  24.255 -    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
  24.256 -    if (KeWaitForSingleObject(&xppdd->backend_state_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
  24.257 -      KdPrint((__DRIVER_NAME "     Still Waiting for InitWait...\n"));
  24.258 +    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  24.259 +    XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  24.260 +    return STATUS_UNSUCCESSFUL;
  24.261    }
  24.262  
  24.263    res_list = &stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList;
  24.264 @@ -255,7 +428,8 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  24.265        KdPrint((__DRIVER_NAME "     CmResourceTypeMemory\n"));
  24.266        KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", res_descriptor->u.Memory.Start.LowPart, res_descriptor->u.Memory.Length));
  24.267        out_ptr = out_start = MmMapIoSpace(res_descriptor->u.Memory.Start, res_descriptor->u.Memory.Length, MmNonCached);
  24.268 -      in_ptr = in_start = ExAllocatePoolWithTag(PagedPool, res_descriptor->u.Memory.Length, XENPCI_POOL_TAG);
  24.269 +      in_ptr = xppdd->xenbus_request = ExAllocatePoolWithTag(PagedPool, res_descriptor->u.Memory.Length, XENPCI_POOL_TAG);
  24.270 +      KdPrint((__DRIVER_NAME "     out_ptr = %p, in_ptr = %p\n", out_ptr, in_ptr));
  24.271        memcpy(in_ptr, out_ptr, res_descriptor->u.Memory.Length);
  24.272        
  24.273        while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  24.274 @@ -269,40 +443,63 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  24.275            break;
  24.276          case XEN_INIT_TYPE_RING: /* frontend ring */
  24.277            /* we only allocate and do the SHARED_RING_INIT here */
  24.278 -          mdl = AllocatePage();
  24.279 -          address = MmGetMdlVirtualAddress(mdl);
  24.280 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, address));
  24.281 -          SHARED_RING_INIT((struct dummy_sring *)address);
  24.282 -          gref = GntTbl_GrantAccess(xpdd, 0, *MmGetMdlPfnArray(mdl), FALSE, 0);
  24.283 -          RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  24.284 -          XenBus_Printf(xpdd, XBT_NIL, path, "%d", gref);
  24.285 -          ADD_XEN_INIT_RSP(&out_ptr, type, setting, address);
  24.286 +          if ((xppdd->mdls[rings] = AllocatePage()) != 0)
  24.287 +          {
  24.288 +            address = MmGetMdlVirtualAddress(xppdd->mdls[rings]);
  24.289 +            KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, address));
  24.290 +            SHARED_RING_INIT((struct dummy_sring *)address);
  24.291 +            if ((xppdd->grant_refs[rings] = GntTbl_GrantAccess(
  24.292 +              xpdd, 0, (ULONG)*MmGetMdlPfnArray(xppdd->mdls[rings]), FALSE, 0)) != 0)
  24.293 +            {
  24.294 +              RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  24.295 +              XenBus_Printf(xpdd, XBT_NIL, path, "%d", xppdd->grant_refs[rings]);
  24.296 +              ADD_XEN_INIT_RSP(&out_ptr, type, setting, address);
  24.297 +            }
  24.298 +            else
  24.299 +            {
  24.300 +              status = STATUS_UNSUCCESSFUL;
  24.301 +            }
  24.302 +          }
  24.303 +          else
  24.304 +          {
  24.305 +            xppdd->grant_refs[rings] = 0;
  24.306 +            status = STATUS_UNSUCCESSFUL;
  24.307 +          }
  24.308 +          rings++;
  24.309            break;
  24.310          case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
  24.311          case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel bound to irq */
  24.312 -          event_channel = EvtChn_AllocUnbound(xpdd, 0);
  24.313 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, event_channel));
  24.314 -          RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  24.315 -          XenBus_Printf(xpdd, XBT_NIL, path, "%d", event_channel);
  24.316 -          ADD_XEN_INIT_RSP(&out_ptr, type, setting, UlongToPtr(event_channel));
  24.317 -          if (type == XEN_INIT_TYPE_EVENT_CHANNEL_IRQ)
  24.318 -            EvtChn_BindIrq(xpdd, event_channel, xppdd->irq_vector);
  24.319 +          if ((xppdd->event_channels[event_channels] = EvtChn_AllocUnbound(xpdd, 0)) != 0)
  24.320 +          {
  24.321 +            KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, xppdd->event_channels[event_channels]));
  24.322 +            RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  24.323 +            XenBus_Printf(xpdd, XBT_NIL, path, "%d", xppdd->event_channels[event_channels]);
  24.324 +            ADD_XEN_INIT_RSP(&out_ptr, type, setting, UlongToPtr(xppdd->event_channels[event_channels]));
  24.325 +            if (type == XEN_INIT_TYPE_EVENT_CHANNEL_IRQ)
  24.326 +              EvtChn_BindIrq(xpdd, xppdd->event_channels[event_channels], xppdd->irq_vector);
  24.327 +          }
  24.328 +          else
  24.329 +          {
  24.330 +            status = STATUS_UNSUCCESSFUL;
  24.331 +          }
  24.332 +          event_channels++;
  24.333            break;
  24.334          }
  24.335        }
  24.336      }
  24.337    }
  24.338  
  24.339 -  /* We are all ready to go */
  24.340 -  RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->path);
  24.341 -  XenBus_Printf(xpdd, XBT_NIL, path, "%d", XenbusStateConnected);
  24.342 -
  24.343 -  // wait here for signal that we are all set up - we should probably add a timeout to make sure we don't hang forever
  24.344 -  while (xppdd->backend_state != XenbusStateConnected)
  24.345 +  if (!NT_SUCCESS(status))
  24.346    {
  24.347 -    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
  24.348 -    if (KeWaitForSingleObject(&xppdd->backend_state_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
  24.349 -      KdPrint((__DRIVER_NAME "     Still Waiting for Connected...\n"));
  24.350 +    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  24.351 +    XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  24.352 +    return status;
  24.353 +  }
  24.354 +  if (XenPci_ChangeFrontendState(xppdd, XenbusStateConnected, XenbusStateConnected, 30000) != STATUS_SUCCESS)
  24.355 +  {
  24.356 +    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  24.357 +    XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  24.358 +    return STATUS_UNSUCCESSFUL;
  24.359    }
  24.360  
  24.361    res_list = &stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
  24.362 @@ -311,7 +508,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  24.363      res_descriptor = &res_list->PartialDescriptors[i];
  24.364      switch (res_descriptor->Type) {
  24.365      case CmResourceTypeMemory:
  24.366 -      in_ptr = in_start;
  24.367 +      in_ptr = xppdd->xenbus_request;
  24.368        while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  24.369        {
  24.370          switch(type)
  24.371 @@ -340,17 +537,18 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  24.372            KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
  24.373            vectors.magic = XEN_DATA_MAGIC;
  24.374            vectors.length = sizeof(XENPCI_VECTORS);
  24.375 -          vectors.context = xpdd;
  24.376 -          vectors.EvtChn_Bind = EvtChn_Bind;
  24.377 -          vectors.EvtChn_BindDpc = EvtChn_BindDpc;
  24.378 -          vectors.EvtChn_Unbind = EvtChn_Unbind;
  24.379 -          vectors.EvtChn_Mask = EvtChn_Mask;
  24.380 -          vectors.EvtChn_Unmask = EvtChn_Unmask;
  24.381 -          vectors.EvtChn_Notify = EvtChn_Notify;
  24.382 -          vectors.GntTbl_GetRef = GntTbl_GetRef;
  24.383 -          vectors.GntTbl_PutRef = GntTbl_PutRef;
  24.384 -          vectors.GntTbl_GrantAccess = GntTbl_GrantAccess;
  24.385 -          vectors.GntTbl_EndAccess = GntTbl_EndAccess;
  24.386 +          vectors.context = xppdd;
  24.387 +          vectors.EvtChn_Bind = XenPci_EvtChn_Bind;
  24.388 +          vectors.EvtChn_BindDpc = XenPci_EvtChn_BindDpc;
  24.389 +          vectors.EvtChn_Unbind = XenPci_EvtChn_Unbind;
  24.390 +          vectors.EvtChn_Mask = XenPci_EvtChn_Mask;
  24.391 +          vectors.EvtChn_Unmask = XenPci_EvtChn_Unmask;
  24.392 +          vectors.EvtChn_Notify = XenPci_EvtChn_Notify;
  24.393 +          vectors.GntTbl_GetRef = XenPci_GntTbl_GetRef;
  24.394 +          vectors.GntTbl_PutRef = XenPci_GntTbl_PutRef;
  24.395 +          vectors.GntTbl_GrantAccess = XenPci_GntTbl_GrantAccess;
  24.396 +          vectors.GntTbl_EndAccess = XenPci_GntTbl_EndAccess;
  24.397 +          vectors.XenPci_ShutdownDevice = XenPci_ShutdownDevice;
  24.398            ADD_XEN_INIT_RSP(&out_ptr, type, NULL, &vectors);
  24.399            break;
  24.400          case XEN_INIT_TYPE_GRANT_ENTRIES:
  24.401 @@ -364,13 +562,64 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  24.402        }
  24.403        ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_END, NULL, NULL);
  24.404        MmUnmapIoSpace(out_start, res_descriptor->u.Memory.Length);
  24.405 -      ExFreePoolWithTag(in_start, XENPCI_POOL_TAG);
  24.406 +      //ExFreePoolWithTag(in_start, XENPCI_POOL_TAG);
  24.407      }
  24.408    }
  24.409 +
  24.410 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  24.411 +
  24.412 +  xpdd->common.device_pnp_state = Started;
  24.413 +  
  24.414 +  return STATUS_SUCCESS;
  24.415 +}
  24.416 +
  24.417 +static NTSTATUS
  24.418 +XenPci_Pnp_RemoveDevice(PDEVICE_OBJECT device_object, PIRP irp)
  24.419 +{
  24.420 +  NTSTATUS status;
  24.421 +  PXENPCI_PDO_DEVICE_DATA xppdd = device_object->DeviceExtension;
  24.422 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  24.423 +  char path[128];
  24.424 +  PCHAR setting, value;
  24.425 +  UCHAR type;
  24.426 +  PUCHAR in_ptr = NULL;
  24.427 +  ULONG rings = 0;
  24.428 +  ULONG event_channels = 0;
  24.429 +
  24.430 +  UNREFERENCED_PARAMETER(irp);
  24.431 +
  24.432 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  24.433 +
  24.434 +  DUMP_CURRENT_PNP_STATE(xppdd);
  24.435 +
  24.436 +  status = XenPci_ShutdownDevice(xppdd);
  24.437 +
  24.438 +  if (xppdd->xenbus_request != NULL)
  24.439 +  {
  24.440 +    in_ptr = xppdd->xenbus_request;
  24.441 +    while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  24.442 +    {
  24.443 +      switch (type)
  24.444 +      {
  24.445 +      case XEN_INIT_TYPE_RING: /* frontend ring */
  24.446 +        GntTbl_EndAccess(xpdd, xppdd->grant_refs[rings], FALSE);
  24.447 +        FreePages(xppdd->mdls[rings]);
  24.448 +        rings++;
  24.449 +        break;
  24.450 +      case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
  24.451 +      case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel bound to irq */
  24.452 +        EvtChn_Unbind(xpdd, xppdd->event_channels[event_channels++]);
  24.453 +        break;
  24.454 +      }
  24.455 +    }
  24.456 +  }
  24.457 +  /* Remove watch on backend state */
  24.458 +  RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  24.459 +  XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  24.460    
  24.461    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  24.462  
  24.463 -  return STATUS_SUCCESS;
  24.464 +  return status;
  24.465  }
  24.466  
  24.467  static NTSTATUS
  24.468 @@ -493,41 +742,60 @@ XenPci_Pnp_Pdo(PDEVICE_OBJECT device_obj
  24.469      
  24.470    case IRP_MN_QUERY_STOP_DEVICE:
  24.471      KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_STOP_DEVICE (status = %08x)\n", irp->IoStatus.Status));
  24.472 +    xppdd->common.device_pnp_state = StopPending;
  24.473      status = STATUS_SUCCESS;
  24.474      break;
  24.475  
  24.476    case IRP_MN_STOP_DEVICE:
  24.477      KdPrint((__DRIVER_NAME "     IRP_MN_STOP_DEVICE (status = %08x)\n", irp->IoStatus.Status));
  24.478 +    xppdd->common.device_pnp_state = Stopped;
  24.479      status = STATUS_SUCCESS;
  24.480      break;
  24.481  
  24.482    case IRP_MN_CANCEL_STOP_DEVICE:
  24.483      KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_STOP_DEVICE (status = %08x)\n", irp->IoStatus.Status));
  24.484 +    xppdd->common.device_pnp_state = Started; /* obviously this isn't really correct :) */
  24.485      status = STATUS_SUCCESS;
  24.486      break;
  24.487  
  24.488    case IRP_MN_QUERY_REMOVE_DEVICE:
  24.489      KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_REMOVE_DEVICE (status = %08x)\n", irp->IoStatus.Status));
  24.490 +    xppdd->common.device_pnp_state = RemovePending;
  24.491      status = STATUS_SUCCESS;
  24.492      break;
  24.493  
  24.494    case IRP_MN_REMOVE_DEVICE:
  24.495      KdPrint((__DRIVER_NAME "     IRP_MN_REMOVE_DEVICE (status = %08x)\n", irp->IoStatus.Status));
  24.496 -    status = STATUS_SUCCESS;
  24.497 +    status = XenPci_Pnp_RemoveDevice(device_object, irp);
  24.498      break;
  24.499  
  24.500    case IRP_MN_CANCEL_REMOVE_DEVICE:
  24.501      KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_REMOVE_DEVICE (status = %08x)\n", irp->IoStatus.Status));
  24.502 +    xppdd->common.device_pnp_state = Started; /* obviously this isn't really correct :) */
  24.503      status = STATUS_SUCCESS;
  24.504      break;
  24.505  
  24.506    case IRP_MN_SURPRISE_REMOVAL:
  24.507      KdPrint((__DRIVER_NAME "     IRP_MN_SURPRISE_REMOVAL (status = %08x)\n", irp->IoStatus.Status));
  24.508 +    xppdd->common.device_pnp_state = SurpriseRemovePending;
  24.509      status = STATUS_SUCCESS;
  24.510      break;
  24.511  
  24.512    case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  24.513      KdPrint((__DRIVER_NAME "     IRP_MN_DEVICE_USAGE_NOTIFICATION (status = %08x)\n", irp->IoStatus.Status));
  24.514 +    switch (stack->Parameters.UsageNotification.Type)
  24.515 +    {
  24.516 +    case DeviceUsageTypePaging:
  24.517 +      KdPrint((__DRIVER_NAME "     type = DeviceUsageTypePaging\n"));
  24.518 +      break;
  24.519 +    case DeviceUsageTypeDumpFile:
  24.520 +      KdPrint((__DRIVER_NAME "     type = DeviceUsageTypeDumpFile\n"));
  24.521 +      break;
  24.522 +    case DeviceUsageTypeHibernation:
  24.523 +      KdPrint((__DRIVER_NAME "     type = DeviceUsageTypeHibernation\n"));
  24.524 +      break;
  24.525 +    }
  24.526 +    KdPrint((__DRIVER_NAME "     inpath = %d\n", stack->Parameters.UsageNotification.InPath));
  24.527      status = STATUS_SUCCESS;
  24.528      break;
  24.529  
    25.1 --- a/xenscsi/sources	Sat May 17 00:06:05 2008 +1000
    25.2 +++ b/xenscsi/sources	Thu May 22 13:46:15 2008 +1000
    25.3 @@ -4,4 +4,4 @@ TARGETTYPE=DRIVER
    25.4  INF_NAME=$(TARGETNAME)
    25.5  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\scsiport.lib
    25.6  MISCFILES=..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf
    25.7 -SOURCES=xenscsi.c
    25.8 +SOURCES=xenscsi.c scsiport.c
    26.1 --- a/xenscsi/xenscsi.c	Sat May 17 00:06:05 2008 +1000
    26.2 +++ b/xenscsi/xenscsi.c	Thu May 22 13:46:15 2008 +1000
    26.3 @@ -1,4 +1,24 @@
    26.4 +/*
    26.5 +PV Drivers for Windows Xen HVM Domains
    26.6 +Copyright (C) 2007 James Harper
    26.7 +
    26.8 +This program is free software; you can redistribute it and/or
    26.9 +modify it under the terms of the GNU General Public License
   26.10 +as published by the Free Software Foundation; either version 2
   26.11 +of the License, or (at your option) any later version.
   26.12 +
   26.13 +This program is distributed in the hope that it will be useful,
   26.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   26.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   26.16 +GNU General Public License for more details.
   26.17 +
   26.18 +You should have received a copy of the GNU General Public License
   26.19 +along with this program; if not, write to the Free Software
   26.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   26.21 +*/
   26.22 +
   26.23  #include "xenscsi.h"
   26.24 +#include <io/blkif.h>
   26.25  #include <scsi.h>
   26.26  #include <ntddscsi.h>
   26.27  #include <ntdddisk.h>
   26.28 @@ -9,9 +29,6 @@
   26.29  
   26.30  #pragma warning(disable: 4127)
   26.31  
   26.32 -#define wmb() KeMemoryBarrier()
   26.33 -#define mb() KeMemoryBarrier()
   26.34 -
   26.35  DRIVER_INITIALIZE DriverEntry;
   26.36  
   26.37  static ULONG
   26.38 @@ -33,6 +50,127 @@ XenScsi_HwScsiAdapterControl(PVOID Devic
   26.39  #pragma alloc_text (INIT, DriverEntry)
   26.40  #endif
   26.41  
   26.42 +static PDRIVER_DISPATCH XenScsi_Pnp_Original;
   26.43 +
   26.44 +static NTSTATUS
   26.45 +XenScsi_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
   26.46 +{
   26.47 +  PIO_STACK_LOCATION stack;
   26.48 +  NTSTATUS status;
   26.49 +  PCM_RESOURCE_LIST old_crl, new_crl;
   26.50 +  PCM_PARTIAL_RESOURCE_LIST prl;
   26.51 +  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
   26.52 +  ULONG old_length, new_length;
   26.53 +  PMDL mdl;
   26.54 +  PUCHAR start, ptr;
   26.55 +
   26.56 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   26.57 +
   26.58 +  stack = IoGetCurrentIrpStackLocation(irp);
   26.59 +
   26.60 +  // check if the Irp is meant for us... maybe the stack->DeviceObject field?
   26.61 +  
   26.62 +  switch (stack->MinorFunction)
   26.63 +  {
   26.64 +  case IRP_MN_START_DEVICE:
   26.65 +    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
   26.66 +    old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   26.67 +    if (old_crl != NULL)
   26.68 +    {
   26.69 +      mdl = AllocateUncachedPage();
   26.70 +      old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
   26.71 +        FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
   26.72 +        FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
   26.73 +        sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
   26.74 +      new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
   26.75 +      new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENSCSI_POOL_TAG);
   26.76 +      memcpy(new_crl, old_crl, old_length);
   26.77 +      prl = &new_crl->List[0].PartialResourceList;
   26.78 +      prd = &prl->PartialDescriptors[prl->Count++];
   26.79 +      prd->Type = CmResourceTypeMemory;
   26.80 +      prd->ShareDisposition = CmResourceShareDeviceExclusive;
   26.81 +      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
   26.82 +      KdPrint((__DRIVER_NAME "     PFN[0] = %p\n", MmGetMdlPfnArray(mdl)[0]));
   26.83 +      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
   26.84 +      prd->u.Memory.Length = PAGE_SIZE;
   26.85 +      KdPrint((__DRIVER_NAME "     Start = %08x:%08x, Length = %d\n", prd->u.Memory.Start.HighPart, prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
   26.86 +      ptr = start = MmGetMdlVirtualAddress(mdl);
   26.87 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "ring-ref", NULL);
   26.88 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL);
   26.89 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_FRONT, "b-dev", NULL);
   26.90 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_VECTORS, NULL, NULL);
   26.91 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, UlongToPtr(GRANT_ENTRIES), NULL);
   26.92 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
   26.93 +      
   26.94 +      stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
   26.95 +
   26.96 +      old_crl = stack->Parameters.StartDevice.AllocatedResources;
   26.97 +      new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENSCSI_POOL_TAG);
   26.98 +      memcpy(new_crl, old_crl, old_length);
   26.99 +      prl = &new_crl->List[0].PartialResourceList;
  26.100 +      prd = &prl->PartialDescriptors[prl->Count++];
  26.101 +      prd->Type = CmResourceTypeMemory;
  26.102 +      prd->ShareDisposition = CmResourceShareDeviceExclusive;
  26.103 +      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
  26.104 +      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
  26.105 +      prd->u.Memory.Length = PAGE_SIZE;
  26.106 +      stack->Parameters.StartDevice.AllocatedResources = new_crl;
  26.107 +      IoCopyCurrentIrpStackLocationToNext(irp);
  26.108 +    }
  26.109 +    else
  26.110 +    {
  26.111 +      KdPrint((__DRIVER_NAME "     AllocatedResource == NULL\n"));
  26.112 +    }
  26.113 +    status = XenScsi_Pnp_Original(device_object, irp);
  26.114 +
  26.115 +    break;
  26.116 +
  26.117 +  case IRP_MN_QUERY_STOP_DEVICE:
  26.118 +    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_STOP_DEVICE\n"));
  26.119 +    status = XenScsi_Pnp_Original(device_object, irp);
  26.120 +    break;
  26.121 +
  26.122 +  case IRP_MN_STOP_DEVICE:
  26.123 +    KdPrint((__DRIVER_NAME "     IRP_MN_STOP_DEVICE\n"));
  26.124 +    status = XenScsi_Pnp_Original(device_object, irp);
  26.125 +    break;
  26.126 +
  26.127 +  case IRP_MN_CANCEL_STOP_DEVICE:
  26.128 +    KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_STOP_DEVICE\n"));
  26.129 +    status = XenScsi_Pnp_Original(device_object, irp);
  26.130 +    break;
  26.131 +
  26.132 +  case IRP_MN_QUERY_REMOVE_DEVICE:
  26.133 +    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_REMOVE_DEVICE\n"));
  26.134 +    status = XenScsi_Pnp_Original(device_object, irp);
  26.135 +    break;
  26.136 +
  26.137 +  case IRP_MN_REMOVE_DEVICE:
  26.138 +    KdPrint((__DRIVER_NAME "     IRP_MN_REMOVE_DEVICE\n"));
  26.139 +    status = XenScsi_Pnp_Original(device_object, irp);
  26.140 +    break;
  26.141 +
  26.142 +  case IRP_MN_CANCEL_REMOVE_DEVICE:
  26.143 +    KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_REMOVE_DEVICE\n"));
  26.144 +    status = XenScsi_Pnp_Original(device_object, irp);
  26.145 +    break;
  26.146 +
  26.147 +  case IRP_MN_SURPRISE_REMOVAL:
  26.148 +    KdPrint((__DRIVER_NAME "     IRP_MN_SURPRISE_REMOVAL\n"));
  26.149 +    status = XenScsi_Pnp_Original(device_object, irp);
  26.150 +    break;
  26.151 +
  26.152 +  default:
  26.153 +    KdPrint((__DRIVER_NAME "     Unknown Minor = %d\n", stack->MinorFunction));
  26.154 +    status = XenScsi_Pnp_Original(device_object, irp);
  26.155 +    break;
  26.156 +  }
  26.157 +
  26.158 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  26.159 +
  26.160 +  return status;
  26.161 +}
  26.162 +
  26.163  NTSTATUS
  26.164  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
  26.165  {
  26.166 @@ -45,14 +183,8 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  26.167    RtlZeroMemory(&HwInitializationData, sizeof(HW_INITIALIZATION_DATA));
  26.168  
  26.169    HwInitializationData.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA);
  26.170 -  HwInitializationData.AdapterInterfaceType = Internal; //PNPBus;
  26.171 -  HwInitializationData.HwInitialize = XenScsi_HwScsiInitialize;
  26.172 -  HwInitializationData.HwStartIo = XenScsi_HwScsiStartIo;
  26.173 -  HwInitializationData.HwInterrupt = XenScsi_HwScsiInterrupt;
  26.174 -  HwInitializationData.HwFindAdapter = XenScsi_HwScsiFindAdapter;
  26.175 -  HwInitializationData.HwResetBus = XenScsi_HwScsiResetBus;
  26.176 +  HwInitializationData.AdapterInterfaceType = Internal;
  26.177    HwInitializationData.HwDmaStarted = NULL;
  26.178 -  HwInitializationData.HwAdapterState = XenScsi_HwScsiAdapterState;
  26.179    HwInitializationData.DeviceExtensionSize = sizeof(XENSCSI_DEVICE_DATA);
  26.180    HwInitializationData.SpecificLuExtensionSize = 0;
  26.181    HwInitializationData.SrbExtensionSize = 0;
  26.182 @@ -60,16 +192,21 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  26.183    HwInitializationData.MapBuffers = TRUE;
  26.184    HwInitializationData.NeedPhysicalAddresses = FALSE;
  26.185    HwInitializationData.TaggedQueuing = TRUE;
  26.186 -  HwInitializationData.AutoRequestSense = TRUE;
  26.187 -  HwInitializationData.MultipleRequestPerLu = FALSE;
  26.188 +  HwInitializationData.AutoRequestSense = FALSE;
  26.189 +  HwInitializationData.MultipleRequestPerLu = TRUE;
  26.190    HwInitializationData.ReceiveEvent = FALSE;
  26.191    HwInitializationData.VendorIdLength = 0;
  26.192    HwInitializationData.VendorId = NULL;
  26.193    HwInitializationData.DeviceIdLength = 0;
  26.194    HwInitializationData.DeviceId = NULL;
  26.195 -  HwInitializationData.HwAdapterControl = XenScsi_HwScsiAdapterControl;
  26.196 +
  26.197 +  XenScsi_FillInitCallbacks(&HwInitializationData);
  26.198  
  26.199    Status = ScsiPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
  26.200 +  
  26.201 +  /* this is a bit naughty... */
  26.202 +  XenScsi_Pnp_Original = DriverObject->MajorFunction[IRP_MJ_PNP];
  26.203 +  DriverObject->MajorFunction[IRP_MJ_PNP] = XenScsi_Pnp;
  26.204  
  26.205    if(!NT_SUCCESS(Status))
  26.206    {
  26.207 @@ -80,805 +217,3 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  26.208  
  26.209    return Status;
  26.210  }
  26.211 -
  26.212 -static __inline uint16_t
  26.213 -GET_ID_FROM_FREELIST(PXENSCSI_TARGET_DATA TargetData)
  26.214 -{
  26.215 -  uint16_t free;
  26.216 -  free = TargetData->shadow_free;
  26.217 -  TargetData->shadow_free = TargetData->shadow[free].req.rqid;
  26.218 -  TargetData->shadow[free].req.rqid = 0x0fff; /* debug */
  26.219 -  return free;
  26.220 -}
  26.221 -
  26.222 -static __inline VOID
  26.223 -ADD_ID_TO_FREELIST(PXENSCSI_TARGET_DATA TargetData, uint16_t Id)
  26.224 -{
  26.225 -  TargetData->shadow[Id].req.rqid  = TargetData->shadow_free;
  26.226 -  TargetData->shadow[Id].Srb = NULL;
  26.227 -  TargetData->shadow_free = Id;
  26.228 -}
  26.229 -
  26.230 -static BOOLEAN
  26.231 -XenScsi_Interrupt(PKINTERRUPT Interrupt, PVOID DeviceExtension)
  26.232 -{
  26.233 -  PXENSCSI_TARGET_DATA TargetData = (PXENSCSI_TARGET_DATA)DeviceExtension;
  26.234 -
  26.235 -  UNREFERENCED_PARAMETER(Interrupt);
  26.236 -
  26.237 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  26.238 -
  26.239 -  TargetData->PendingInterrupt = TRUE;
  26.240 -
  26.241 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  26.242 -
  26.243 -  return TRUE;
  26.244 -}
  26.245 -
  26.246 -static VOID
  26.247 -XenScsi_HwScsiInterruptTarget(PVOID DeviceExtension)
  26.248 -{
  26.249 -  PXENSCSI_TARGET_DATA TargetData = (PXENSCSI_TARGET_DATA)DeviceExtension;
  26.250 -  PSCSI_REQUEST_BLOCK Srb;
  26.251 -  RING_IDX i, rp;
  26.252 -  vscsiif_response_t *rep;
  26.253 -  PXENSCSI_DEVICE_DATA DeviceData = (PXENSCSI_DEVICE_DATA)TargetData->DeviceData;
  26.254 -  int more_to_do = TRUE;
  26.255 -
  26.256 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  26.257 -
  26.258 -  while (more_to_do)
  26.259 -  {
  26.260 -    rp = TargetData->Ring.sring->rsp_prod;
  26.261 -    KeMemoryBarrier();
  26.262 -    for (i = TargetData->Ring.rsp_cons; i != rp; i++)
  26.263 -    {
  26.264 -      rep = RING_GET_RESPONSE(&TargetData->Ring, i);
  26.265 -      Srb = TargetData->shadow[rep->rqid].Srb;
  26.266 -      Srb->ScsiStatus = (UCHAR)rep->rslt;
  26.267 -      if (!rep->rslt)
  26.268 -        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  26.269 -      else
  26.270 -      {
  26.271 -        KdPrint((__DRIVER_NAME "     Xen Operation returned error (result = 0x%08x)\n", rep->rslt));
  26.272 -        Srb->SrbStatus = SRB_STATUS_ERROR;
  26.273 -        if (rep->sense_len > 0 && rep->sense_len <= Srb->SenseInfoBufferLength && !(Srb->SrbFlags & SRB_FLAGS_DISABLE_AUTOSENSE) && Srb->SenseInfoBuffer != NULL)
  26.274 -        {
  26.275 -          Srb->SrbStatus |= SRB_STATUS_AUTOSENSE_VALID;
  26.276 -          memcpy(Srb->SenseInfoBuffer, rep->sense_buffer, rep->sense_len);
  26.277 -        }
  26.278 -      }
  26.279 -      if (Srb->SrbFlags & SRB_FLAGS_DATA_IN)
  26.280 -        memcpy(Srb->DataBuffer, TargetData->shadow[rep->rqid].Buf, Srb->DataTransferLength);
  26.281 -
  26.282 -      ScsiPortNotification(RequestComplete, DeviceData, Srb);
  26.283 -      ScsiPortNotification(NextLuRequest, DeviceData, Srb->PathId, Srb->TargetId, Srb->Lun);
  26.284 -//      ScsiPortNotification(NextRequest, DeviceData);
  26.285 -
  26.286 -      ADD_ID_TO_FREELIST(TargetData, rep->rqid);
  26.287 -    }
  26.288 -
  26.289 -    TargetData->Ring.rsp_cons = i;
  26.290 -    if (i != TargetData->Ring.req_prod_pvt)
  26.291 -    {
  26.292 -      RING_FINAL_CHECK_FOR_RESPONSES(&TargetData->Ring, more_to_do);
  26.293 -    }
  26.294 -    else
  26.295 -    {
  26.296 -      TargetData->Ring.sring->rsp_event = i + 1;
  26.297 -      more_to_do = FALSE;
  26.298 -    }
  26.299 -  }
  26.300 -
  26.301 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  26.302 -}
  26.303 -
  26.304 -static BOOLEAN
  26.305 -XenScsi_HwScsiInterrupt(PVOID DeviceExtension)
  26.306 -{
  26.307 -  PXENSCSI_DEVICE_DATA DeviceData;
  26.308 -  PXENSCSI_TARGET_DATA TargetData;
  26.309 -  int i, j;
  26.310 -
  26.311 -  //KdPrint((__DRIVER_NAME " --> HwScsiInterrupt\n"));
  26.312 -
  26.313 -  DeviceData = (PXENSCSI_DEVICE_DATA)DeviceExtension;
  26.314 -
  26.315 -  KeMemoryBarrier();
  26.316 -  for (i = 0; i < SCSI_BUSES; i++)
  26.317 -  {
  26.318 -    for (j = 0; j < SCSI_TARGETS_PER_BUS; j++)
  26.319 -    {
  26.320 -      TargetData = &DeviceData->BusData[i].TargetData[j];
  26.321 -      if (TargetData->PendingInterrupt)
  26.322 -        XenScsi_HwScsiInterruptTarget(TargetData);
  26.323 -      TargetData->PendingInterrupt = FALSE;
  26.324 -    }
  26.325 -  }
  26.326 -  //KdPrint((__DRIVER_NAME " <-- HwScsiInterrupt\n"));
  26.327 -
  26.328 -  return FALSE;
  26.329 -}
  26.330 -
  26.331 -static VOID
  26.332 -XenScsi_BackEndStateHandler(char *Path, PVOID Data)
  26.333 -{
  26.334 -  PXENSCSI_TARGET_DATA TargetData;
  26.335 -  PXENSCSI_DEVICE_DATA DeviceData;
  26.336 -  char TmpPath[128];
  26.337 -  char *Value;
  26.338 -  int NewState;
  26.339 -  int scanning;
  26.340 -  PMDL Mdl;
  26.341 -  grant_ref_t ref;
  26.342 -  vscsiif_sring_t *SharedRing;
  26.343 -  ULONG PFN;
  26.344 -  ULONG i, j;
  26.345 -
  26.346 -  KdPrint((__DRIVER_NAME " --> BackEndStateHandler\n"));
  26.347 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  26.348 -
  26.349 -  TargetData = (PXENSCSI_TARGET_DATA)Data;
  26.350 -  DeviceData = (PXENSCSI_DEVICE_DATA)TargetData->DeviceData;
  26.351 -
  26.352 -  DeviceData->XenDeviceData->XenInterface.XenBus_Read(
  26.353 -    DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.354 -    XBT_NIL, Path, &Value);
  26.355 -
  26.356 -  NewState = atoi(Value);
  26.357 -  switch (NewState)
  26.358 -  {
  26.359 -  case XenbusStateUnknown:
  26.360 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Unknown\n"));  
  26.361 -    break;
  26.362 -
  26.363 -  case XenbusStateInitialising:
  26.364 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Initialising\n"));  
  26.365 -    break;
  26.366 -
  26.367 -  case XenbusStateInitWait:
  26.368 -    KdPrint((__DRIVER_NAME "     Backend State Changed to InitWait\n"));  
  26.369 -
  26.370 -    TargetData->EventChannel = DeviceData->XenDeviceData->XenInterface.EvtChn_AllocUnbound(
  26.371 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, 0);
  26.372 -    DeviceData->XenDeviceData->XenInterface.EvtChn_Bind(
  26.373 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.374 -      TargetData->EventChannel, XenScsi_Interrupt, TargetData);
  26.375 -    Mdl = AllocatePage();
  26.376 -    PFN = (ULONG)*MmGetMdlPfnArray(Mdl);
  26.377 -    SharedRing = (vscsiif_sring_t *)MmGetMdlVirtualAddress(Mdl);
  26.378 -    RtlZeroMemory(SharedRing, PAGE_SIZE);
  26.379 -    SHARED_RING_INIT(SharedRing);
  26.380 -    FRONT_RING_INIT(&TargetData->Ring, SharedRing, PAGE_SIZE);
  26.381 -    ref = DeviceData->XenDeviceData->XenInterface.GntTbl_GrantAccess(
  26.382 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.383 -      0, PFN, FALSE, 0);
  26.384 -    ASSERT((signed short)ref >= 0);
  26.385 -    TargetData->ring_detect_state = 0;
  26.386 -    TargetData->shadow = ExAllocatePoolWithTag(NonPagedPool, sizeof(vscsiif_shadow_t) * VSCSIIF_RING_SIZE, XENSCSI_POOL_TAG);
  26.387 -
  26.388 -    memset(TargetData->shadow, 0, sizeof(vscsiif_shadow_t) * VSCSIIF_RING_SIZE);
  26.389 -    for (i = 0; i < VSCSIIF_RING_SIZE; i++)
  26.390 -    {
  26.391 -      TargetData->shadow[i].req.rqid = (uint16_t)i + 1;
  26.392 -      TargetData->shadow[i].Mdl = AllocatePages(VSCSIIF_SG_TABLESIZE); // stupid that we have to do this!
  26.393 -      TargetData->shadow[i].Buf = MmGetMdlVirtualAddress(TargetData->shadow[i].Mdl);
  26.394 -      for (j = 0; j < VSCSIIF_SG_TABLESIZE; j++)
  26.395 -      {
  26.396 -        TargetData->shadow[i].req.seg[j].gref = DeviceData->XenDeviceData->XenInterface.GntTbl_GrantAccess(
  26.397 -          DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.398 -          0, (ULONG)MmGetMdlPfnArray(TargetData->shadow[i].Mdl)[j], FALSE, 0);
  26.399 -        ASSERT((signed short)TargetData->shadow[i].req.seg[j].gref >= 0);
  26.400 -      }
  26.401 -    }
  26.402 -    TargetData->shadow_free = 0;
  26.403 -
  26.404 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  26.405 -    RtlStringCbCatA(TmpPath, 128, "/ring-ref");
  26.406 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(
  26.407 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.408 -      XBT_NIL, TmpPath, "%d", ref);
  26.409 -
  26.410 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  26.411 -    RtlStringCbCatA(TmpPath, 128, "/event-channel");
  26.412 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(
  26.413 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.414 -      XBT_NIL, TmpPath, "%d", TargetData->EventChannel);
  26.415 -
  26.416 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  26.417 -    RtlStringCbCatA(TmpPath, 128, "/state");
  26.418 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(
  26.419 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, 
  26.420 -      XBT_NIL, TmpPath, "%d", XenbusStateInitialised);
  26.421 -
  26.422 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  26.423 -    RtlStringCbCatA(TmpPath, 128, "/b-dev");
  26.424 -    DeviceData->XenDeviceData->XenInterface.XenBus_Read(
  26.425 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.426 -      XBT_NIL, TmpPath, &Value);
  26.427 -
  26.428 -    KdPrint((__DRIVER_NAME "     dev string = %s\n", Value));  
  26.429 -    
  26.430 -    i = 0;
  26.431 -    j = 0;
  26.432 -    scanning = TRUE;
  26.433 -    while (scanning)
  26.434 -    {
  26.435 -      if (Value[i] == 0)
  26.436 -        scanning = FALSE;
  26.437 -      if (Value[i] == ':' || Value[i] == 0)
  26.438 -      {
  26.439 -         Value[i] = 0;
  26.440 -         TargetData->host = TargetData->channel;
  26.441 -         TargetData->channel = TargetData->id;
  26.442 -         TargetData->id = TargetData->lun;
  26.443 -         TargetData->lun = atoi(&Value[j]);
  26.444 -         j = i + 1;
  26.445 -      }
  26.446 -      i++;
  26.447 -    }
  26.448 -    KdPrint((__DRIVER_NAME "     host = %d, channel = %d, id = %d, lun = %d\n",
  26.449 -      TargetData->host, TargetData->channel, TargetData->id, TargetData->lun));  
  26.450 -
  26.451 -/*
  26.452 -    KdPrint((__DRIVER_NAME "     sizeof(vscsiif_request) = %d\n", sizeof(struct vscsiif_request)));
  26.453 -    KdPrint((__DRIVER_NAME "     sizeof(vscsiif_request_segment) = %d\n", sizeof(struct vscsiif_request_segment)));
  26.454 -    KdPrint((__DRIVER_NAME "     sizeof(vscsiif_response) = %d\n", sizeof(struct vscsiif_response)));
  26.455 -    KdPrint((__DRIVER_NAME "     operation = %d\n", (int)((char *)(&req.operation) - (char *)(&req))));
  26.456 -    KdPrint((__DRIVER_NAME "     nr_segments = %d\n", (int)((char *)(&req.nr_segments) - (char *)(&req))));
  26.457 -    KdPrint((__DRIVER_NAME "     handle = %d\n", (int)((char *)(&req.handle) - (char *)(&req))));
  26.458 -    KdPrint((__DRIVER_NAME "     id = %d\n", (int)((char *)(&req.rqid) - (char *)(&req))));
  26.459 -    KdPrint((__DRIVER_NAME "     sector_number = %d\n", (int)((char *)(&req.sector_number) - (char *)(&req))));
  26.460 -    KdPrint((__DRIVER_NAME "     seg = %d\n", (int)((char *)(&req.seg) - (char *)(&req))));
  26.461 -
  26.462 -    KdPrint((__DRIVER_NAME "     id = %d\n", (int)((char *)(&rep.id) - (char *)(&rep))));
  26.463 -    KdPrint((__DRIVER_NAME "     operation = %d\n", (int)((char *)(&rep.operation) - (char *)(&rep))));
  26.464 -    KdPrint((__DRIVER_NAME "     status = %d\n", (int)((char *)(&rep.status) - (char *)(&rep))));
  26.465 -
  26.466 -    KdPrint((__DRIVER_NAME "     sizeof(union vscsiif_sring_entry) = %d\n", sizeof(union vscsiif_sring_entry)));
  26.467 -    KdPrint((__DRIVER_NAME "     %d\n", (int)((char *)(&entries[1]) - (char *)(&entries[0]))));
  26.468 -*/
  26.469 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Initialised\n"));
  26.470 -    break;
  26.471 -
  26.472 -  case XenbusStateInitialised:
  26.473 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Initialised\n"));
  26.474 -    break;
  26.475 -
  26.476 -  case XenbusStateConnected:
  26.477 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Connected\n"));  
  26.478 -
  26.479 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  26.480 -    RtlStringCbCatA(TmpPath, 128, "/state");
  26.481 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, XBT_NIL, TmpPath, "%d", XenbusStateConnected);
  26.482 -
  26.483 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
  26.484 -    InterlockedIncrement(&DeviceData->EnumeratedDevices);
  26.485 -    KdPrint((__DRIVER_NAME "     Added a device\n"));  
  26.486 -
  26.487 -// now ask windows to rescan the scsi bus...
  26.488 -    DeviceData->BusChangePending = 1;
  26.489 -    break;
  26.490 -
  26.491 -  case XenbusStateClosing:
  26.492 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Closing\n"));  
  26.493 -    // this behaviour is only to properly close down to then restart in the case of a dump
  26.494 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  26.495 -    RtlStringCbCatA(TmpPath, 128, "/state");
  26.496 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, XBT_NIL, TmpPath, "%d", XenbusStateClosed);
  26.497 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Closed\n"));
  26.498 -    break;
  26.499 -
  26.500 -  case XenbusStateClosed:
  26.501 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Closed\n"));  
  26.502 -    // this behaviour is only to properly close down to then restart in the case of a dump
  26.503 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  26.504 -    RtlStringCbCatA(TmpPath, 128, "/state");
  26.505 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, XBT_NIL, TmpPath, "%d", XenbusStateInitialising);
  26.506 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Initialising\n"));
  26.507 -    break;
  26.508 -
  26.509 -  default:
  26.510 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Undefined = %d\n", NewState));
  26.511 -    break;
  26.512 -  }
  26.513 -
  26.514 -  KdPrint((__DRIVER_NAME " <-- BackEndStateHandler\n"));
  26.515 -}
  26.516 -
  26.517 -static VOID
  26.518 -XenScsi_WatchHandler(char *Path, PVOID DeviceExtension)
  26.519 -{
  26.520 -  PXENSCSI_DEVICE_DATA DeviceData = (PXENSCSI_DEVICE_DATA)DeviceExtension;
  26.521 -  char **Bits;
  26.522 -  int Count;
  26.523 -  char TmpPath[128];
  26.524 -  char *Value;
  26.525 -  int CurrentBus, CurrentTarget;
  26.526 -  PXENSCSI_TARGET_DATA TargetData, VacantTarget;
  26.527 -  KIRQL OldIrql;
  26.528 -  int i;
  26.529 -
  26.530 -  KdPrint((__DRIVER_NAME " --> WatchHandler (DeviceData = %p)\n", DeviceData));
  26.531 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  26.532 -
  26.533 -  KdPrint((__DRIVER_NAME "     Path = %s\n", Path));
  26.534 -
  26.535 -  Bits = SplitString(Path, '/', 4, &Count);
  26.536 -  switch (Count)
  26.537 -  {
  26.538 -  case 0:
  26.539 -  case 1:
  26.540 -  case 2:
  26.541 -    break; // should never happen
  26.542 -  case 3:
  26.543 -    break;
  26.544 -  case 4:
  26.545 -    if (strcmp(Bits[3], "state") != 0) // we only care when the state appears
  26.546 -      break;
  26.547 -
  26.548 -    KeAcquireSpinLock(&DeviceData->Lock, &OldIrql);
  26.549 -
  26.550 -    for (VacantTarget = NULL,i = 0; i < SCSI_BUSES * SCSI_TARGETS_PER_BUS; i++)
  26.551 -    {
  26.552 -      CurrentBus = i / SCSI_TARGETS_PER_BUS;
  26.553 -      CurrentTarget = i % SCSI_TARGETS_PER_BUS;
  26.554 -      if (CurrentTarget == 7) // don't use 7 - it would be for the controller
  26.555 -        continue;
  26.556 -      TargetData = &DeviceData->BusData[CurrentBus].TargetData[CurrentTarget];
  26.557 -      if (TargetData->Present && strncmp(TargetData->Path, Path, strlen(TargetData->Path)) == 0 && Path[strlen(TargetData->Path)] == '/')
  26.558 -        break; // already exists
  26.559 -      else if (!TargetData->Present && VacantTarget == NULL)
  26.560 -        VacantTarget = TargetData;
  26.561 -    }
  26.562 -    if (i == SCSI_BUSES * SCSI_TARGETS_PER_BUS && VacantTarget != NULL)
  26.563 -    {
  26.564 -      VacantTarget->Present = 1;
  26.565 -      KeReleaseSpinLock(&DeviceData->Lock, OldIrql);
  26.566 -
  26.567 -      DeviceData->XenDeviceData->XenInterface.XenBus_Read(
  26.568 -        DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.569 -        XBT_NIL, Path, &Value);
  26.570 -
  26.571 -      if (Value == NULL)
  26.572 -      {
  26.573 -        KdPrint((__DRIVER_NAME "     blank state?\n"));
  26.574 -        break;
  26.575 -      }
  26.576 -      if (atoi(Value) != XenbusStateInitialising)
  26.577 -        DeviceData->XenDeviceData->XenInterface.XenBus_Printf(
  26.578 -          DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.579 -          XBT_NIL, Path, "%d", XenbusStateClosing);
  26.580 -
  26.581 -      RtlStringCbCopyA(VacantTarget->Path, 128, Bits[0]);
  26.582 -      RtlStringCbCatA(VacantTarget->Path, 128, "/");
  26.583 -      RtlStringCbCatA(VacantTarget->Path, 128, Bits[1]);
  26.584 -      RtlStringCbCatA(VacantTarget->Path, 128, "/");
  26.585 -      RtlStringCbCatA(VacantTarget->Path, 128, Bits[2]);
  26.586 -
  26.587 -      VacantTarget->DeviceIndex = atoi(Bits[2]);
  26.588 -
  26.589 -      RtlStringCbCopyA(TmpPath, 128, VacantTarget->Path);
  26.590 -      RtlStringCbCatA(TmpPath, 128, "/backend");
  26.591 -      DeviceData->XenDeviceData->XenInterface.XenBus_Read(
  26.592 -        DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.593 -        XBT_NIL, TmpPath, &Value);
  26.594 -      if (Value == NULL)
  26.595 -        KdPrint((__DRIVER_NAME "     Read Failed\n"));
  26.596 -      else
  26.597 -        RtlStringCbCopyA(VacantTarget->BackendPath, 128, Value);
  26.598 -      RtlStringCbCopyA(TmpPath, 128, VacantTarget->BackendPath);
  26.599 -      RtlStringCbCatA(TmpPath, 128, "/state");
  26.600 -
  26.601 -      DeviceData->XenDeviceData->XenInterface.XenBus_AddWatch(
  26.602 -        DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.603 -        XBT_NIL, TmpPath, XenScsi_BackEndStateHandler, VacantTarget);
  26.604 -    }
  26.605 -    else
  26.606 -      KeReleaseSpinLock(&DeviceData->Lock, OldIrql);
  26.607 -    break;
  26.608 -  }
  26.609 -  
  26.610 -  FreeSplitString(Bits, Count);
  26.611 -
  26.612 -  KdPrint((__DRIVER_NAME " <-- WatchHandler\n"));  
  26.613 -
  26.614 -  return;
  26.615 -}
  26.616 -
  26.617 -static ULONG
  26.618 -XenScsi_HwScsiFindAdapter(PVOID DeviceExtension, PVOID HwContext, PVOID BusInformation, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PBOOLEAN Again)
  26.619 -{
  26.620 -  ULONG i, j;
  26.621 -  PACCESS_RANGE AccessRange;
  26.622 -  PXENSCSI_DEVICE_DATA DeviceData = (PXENSCSI_DEVICE_DATA)DeviceExtension;
  26.623 -  char **ScsiDevices;
  26.624 -  char *msg;
  26.625 -  char buffer[128];
  26.626 -
  26.627 -  UNREFERENCED_PARAMETER(HwContext);
  26.628 -  UNREFERENCED_PARAMETER(BusInformation);
  26.629 -  UNREFERENCED_PARAMETER(ArgumentString);
  26.630 -  KeInitializeSpinLock(&DeviceData->Lock);
  26.631 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));  
  26.632 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  26.633 -
  26.634 -  // testing this for dump mode
  26.635 -//  if (KeGetCurrentIrql() > ConfigInfo->BusInterruptLevel)
  26.636 -//    ConfigInfo->BusInterruptLevel = KeGetCurrentIrql();
  26.637 -
  26.638 -  KdPrint((__DRIVER_NAME "     BusInterruptLevel = %d\n", ConfigInfo->BusInterruptLevel));
  26.639 -  KdPrint((__DRIVER_NAME "     BusInterruptVector = %d\n", ConfigInfo->BusInterruptVector));
  26.640 -
  26.641 -  KdPrint((__DRIVER_NAME "     AccessRanges = %d\n", ConfigInfo->NumberOfAccessRanges));
  26.642 -
  26.643 -  for (i = 0; i < ConfigInfo->NumberOfAccessRanges; i++)
  26.644 -  {
  26.645 -    AccessRange = &(*(ConfigInfo->AccessRanges))[i];
  26.646 -    KdPrint((__DRIVER_NAME "     AccessRange %2d: RangeStart = %p, RangeLength = %x, RangeInMemory = %d\n", i, AccessRange->RangeStart.QuadPart, AccessRange->RangeLength, AccessRange->RangeInMemory));
  26.647 -    switch (i)
  26.648 -    {
  26.649 -    case 0:
  26.650 -      DeviceData->XenDeviceData = (PVOID)(xen_ulong_t)AccessRange->RangeStart.QuadPart;
  26.651 -      KdPrint((__DRIVER_NAME "     Mapped to virtual address %p\n", DeviceData->XenDeviceData));
  26.652 -      KdPrint((__DRIVER_NAME "     Magic = %08x\n", DeviceData->XenDeviceData->Magic));
  26.653 -      if (DeviceData->XenDeviceData->Magic != XEN_DATA_MAGIC)
  26.654 -      {
  26.655 -        KdPrint((__DRIVER_NAME "     Invalid Magic Number\n"));
  26.656 -        return SP_RETURN_NOT_FOUND;
  26.657 -      }
  26.658 -      break;
  26.659 -    default:
  26.660 -      break;
  26.661 -    }
  26.662 -  }
  26.663 -#if defined(__x86_64__)
  26.664 -  ConfigInfo->Master = TRUE; // Won't work under x64 without this...
  26.665 -#endif
  26.666 -  ConfigInfo->MaximumTransferLength = VSCSIIF_SG_TABLESIZE * PAGE_SIZE;
  26.667 -  ConfigInfo->NumberOfPhysicalBreaks = VSCSIIF_SG_TABLESIZE - 1;
  26.668 -  ConfigInfo->ScatterGather = TRUE;
  26.669 -  ConfigInfo->AlignmentMask = 0;
  26.670 -  ConfigInfo->NumberOfBuses = SCSI_BUSES;
  26.671 -  for (i = 0; i < ConfigInfo->NumberOfBuses; i++)
  26.672 -  {
  26.673 -    ConfigInfo->InitiatorBusId[i] = 7;
  26.674 -  }
  26.675 -  ConfigInfo->MaximumNumberOfLogicalUnits = 1;
  26.676 -  ConfigInfo->MaximumNumberOfTargets = SCSI_TARGETS_PER_BUS;
  26.677 -//  ConfigInfo->TaggedQueueing = TRUE;
  26.678 -  if (ConfigInfo->Dma64BitAddresses == SCSI_DMA64_SYSTEM_SUPPORTED)
  26.679 -    ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_SUPPORTED;
  26.680 -  // This all has to be initialized here as the real Initialize routine
  26.681 -  // is called at DIRQL, and the XenBus stuff has to be called at
  26.682 -  // <= DISPATCH_LEVEL
  26.683 -
  26.684 -  for (i = 0; i < SCSI_BUSES; i++)
  26.685 -  {
  26.686 -    for (j = 0; j < SCSI_TARGETS_PER_BUS; j++)
  26.687 -    {
  26.688 -      DeviceData->BusData[i].TargetData[j].Present = 0;
  26.689 -      DeviceData->BusData[i].TargetData[j].DeviceData = DeviceData;
  26.690 -    }
  26.691 -  }
  26.692 -
  26.693 -  DeviceData->XenDeviceData->WatchContext = DeviceExtension;
  26.694 -  KeMemoryBarrier();
  26.695 -  DeviceData->XenDeviceData->WatchHandler = XenScsi_WatchHandler;
  26.696 -
  26.697 -//  KeInitializeEvent(&DeviceData->WaitDevicesEvent, SynchronizationEvent, FALSE);  
  26.698 -  DeviceData->EnumeratedDevices = 0;
  26.699 -  DeviceData->TotalInitialDevices = 0;
  26.700 -
  26.701 -//  if (DeviceData->XenDeviceData->AutoEnumerate)
  26.702 -//  {
  26.703 -    msg = DeviceData->XenDeviceData->XenInterface.XenBus_List(
  26.704 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.705 -      XBT_NIL, "device/vscsi", &ScsiDevices);
  26.706 -    if (!msg)
  26.707 -    {
  26.708 -      for (i = 0; ScsiDevices[i]; i++)
  26.709 -      {
  26.710 -        KdPrint((__DRIVER_NAME "     found existing scsi device %s\n", ScsiDevices[i]));
  26.711 -        RtlStringCbPrintfA(buffer, ARRAY_SIZE(buffer), "device/vscsi/%s/state", ScsiDevices[i]);
  26.712 -        XenScsi_WatchHandler(buffer, DeviceData);
  26.713 -        DeviceData->TotalInitialDevices++;
  26.714 -      }  
  26.715 -    }
  26.716 -//  }
  26.717 -
  26.718 -  *Again = FALSE;
  26.719 -
  26.720 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
  26.721 -
  26.722 -  return SP_RETURN_FOUND;
  26.723 -}
  26.724 -
  26.725 -static VOID 
  26.726 -XenScsi_CheckBusChangedTimer(PVOID DeviceExtension);
  26.727 -
  26.728 -static VOID 
  26.729 -XenScsi_CheckBusEnumeratedTimer(PVOID DeviceExtension)
  26.730 -{
  26.731 -  PXENSCSI_DEVICE_DATA DeviceData = (PXENSCSI_DEVICE_DATA)DeviceExtension;
  26.732 -
  26.733 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  26.734 -//  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  26.735 -
  26.736 -  if (DeviceData->BusChangePending && DeviceData->EnumeratedDevices >= DeviceData->TotalInitialDevices)
  26.737 -  {
  26.738 -    DeviceData->BusChangePending = 0;
  26.739 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
  26.740 -    ScsiPortNotification(RequestTimerCall, DeviceExtension, XenScsi_CheckBusChangedTimer, 1000000);
  26.741 -  }
  26.742 -  else
  26.743 -  {
  26.744 -    ScsiPortNotification(RequestTimerCall, DeviceExtension, XenScsi_CheckBusEnumeratedTimer, 100000);
  26.745 -  }
  26.746 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  26.747 -}
  26.748 -
  26.749 -static VOID 
  26.750 -XenScsi_CheckBusChangedTimer(PVOID DeviceExtension)
  26.751 -{
  26.752 -  PXENSCSI_DEVICE_DATA DeviceData = (PXENSCSI_DEVICE_DATA)DeviceExtension;
  26.753 -
  26.754 -  if (DeviceData->BusChangePending)
  26.755 -  {
  26.756 -    ScsiPortNotification(BusChangeDetected, DeviceData, 0);
  26.757 -    DeviceData->BusChangePending = 0;
  26.758 -  }
  26.759 -  ScsiPortNotification(RequestTimerCall, DeviceExtension, XenScsi_CheckBusChangedTimer, 1000000);
  26.760 -}
  26.761 -
  26.762 -static BOOLEAN
  26.763 -XenScsi_HwScsiInitialize(PVOID DeviceExtension)
  26.764 -{
  26.765 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  26.766 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  26.767 -
  26.768 -  ScsiPortNotification(RequestTimerCall, DeviceExtension, XenScsi_CheckBusEnumeratedTimer, 100000);
  26.769 -
  26.770 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  26.771 -
  26.772 -  return TRUE;
  26.773 -}
  26.774 -
  26.775 -// Call with device lock held
  26.776 -static VOID
  26.777 -XenScsi_PutSrbOnRing(PXENSCSI_TARGET_DATA TargetData, PSCSI_REQUEST_BLOCK Srb)
  26.778 -{
  26.779 -  //PUCHAR DataBuffer;
  26.780 -  int i;
  26.781 -  vscsiif_shadow_t *shadow;
  26.782 -  uint16_t id;
  26.783 -  int remaining;
  26.784 -
  26.785 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  26.786 -
  26.787 -  if (RING_FULL(&TargetData->Ring))
  26.788 -  {
  26.789 -    KdPrint((__DRIVER_NAME "     RING IS FULL - EXPECT BADNESS\n"));
  26.790 -    // TODO: Fail badly here
  26.791 -  }
  26.792 -
  26.793 -  id = GET_ID_FROM_FREELIST(TargetData);
  26.794 -  if (id == 0x0fff)
  26.795 -  {
  26.796 -    KdPrint((__DRIVER_NAME "     Something is horribly wrong in PutSrbOnRing\n"));
  26.797 -  }
  26.798 -
  26.799 -  shadow = &TargetData->shadow[id];
  26.800 -  shadow->Srb = Srb;
  26.801 -  shadow->req.rqid = id;
  26.802 -  shadow->req.cmd = VSCSIIF_CMND_SCSI;
  26.803 -  memset(shadow->req.cmnd, 0, VSCSIIF_MAX_COMMAND_SIZE);
  26.804 -  memcpy(shadow->req.cmnd, Srb->Cdb, 16);
  26.805 -  shadow->req.cmd_len = Srb->CdbLength;
  26.806 -  shadow->req.id = (USHORT)TargetData->id;
  26.807 -  shadow->req.lun = (USHORT)TargetData->lun;
  26.808 -  shadow->req.channel = (USHORT)TargetData->channel;
  26.809 -  if (Srb->DataTransferLength && (Srb->SrbFlags & SRB_FLAGS_DATA_IN) && (Srb->SrbFlags & SRB_FLAGS_DATA_OUT))
  26.810 -    shadow->req.sc_data_direction = DMA_BIDIRECTIONAL;
  26.811 -  else if (Srb->DataTransferLength && (Srb->SrbFlags & SRB_FLAGS_DATA_IN))
  26.812 -    shadow->req.sc_data_direction = DMA_FROM_DEVICE;
  26.813 -  else if (Srb->DataTransferLength && (Srb->SrbFlags & SRB_FLAGS_DATA_OUT))
  26.814 -    shadow->req.sc_data_direction = DMA_TO_DEVICE;
  26.815 -  else
  26.816 -    shadow->req.sc_data_direction = DMA_NONE;
  26.817 -  shadow->req.use_sg = (UINT8)((Srb->DataTransferLength + PAGE_SIZE - 1) >> PAGE_SHIFT);
  26.818 -  shadow->req.request_bufflen = Srb->DataTransferLength;
  26.819 -
  26.820 -//  KdPrint((__DRIVER_NAME "     pages = %d\n", shadow->req.use_sg));
  26.821 -  remaining = Srb->DataTransferLength;
  26.822 -  shadow->req.seg[0].offset = 0;
  26.823 -  shadow->req.seg[0].length = 0;
  26.824 -  for (i = 0; remaining != 0; i++)
  26.825 -  {
  26.826 -    shadow->req.seg[i].offset = 0; // this is the offset into the page
  26.827 -    if (remaining >= PAGE_SIZE)
  26.828 -    {
  26.829 -      shadow->req.seg[i].length = PAGE_SIZE;
  26.830 -      remaining -= PAGE_SIZE;
  26.831 -    }
  26.832 -    else
  26.833 -    {
  26.834 -      shadow->req.seg[i].length = (USHORT)remaining;
  26.835 -      remaining = 0;
  26.836 -    }
  26.837 -//    KdPrint((__DRIVER_NAME "     sg %d: offset = %d, size = %d\n", i, shadow->req.seg[i].offset, shadow->req.seg[i].length));
  26.838 -  }
  26.839 -  if (Srb->SrbFlags & SRB_FLAGS_DATA_OUT)
  26.840 -    memcpy(TargetData->shadow[shadow->req.rqid].Buf, Srb->DataBuffer, Srb->DataTransferLength);
  26.841 -
  26.842 -  *RING_GET_REQUEST(&TargetData->Ring, TargetData->Ring.req_prod_pvt) = shadow->req;
  26.843 -  TargetData->Ring.req_prod_pvt++;
  26.844 -
  26.845 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  26.846 -}
  26.847 -
  26.848 -static BOOLEAN
  26.849 -XenScsi_HwScsiStartIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK Srb)
  26.850 -{
  26.851 -  PXENSCSI_DEVICE_DATA DeviceData = (PXENSCSI_DEVICE_DATA)DeviceExtension;
  26.852 -  PXENSCSI_TARGET_DATA TargetData;
  26.853 -  int notify;
  26.854 -
  26.855 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ " PathId = %d, TargetId = %d, Lun = %d\n", Srb->PathId, Srb->TargetId, Srb->Lun));
  26.856 -
  26.857 -  // If we haven't enumerated all the devices yet then just defer the request
  26.858 -  // A timer will issue a NextRequest to get things started again...
  26.859 -  if (DeviceData->EnumeratedDevices < DeviceData->TotalInitialDevices)
  26.860 -  {
  26.861 -    Srb->SrbStatus = SRB_STATUS_BUSY;
  26.862 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  26.863 -    KdPrint((__DRIVER_NAME " --- HwScsiStartIo (Bus not enumerated yet)\n"));
  26.864 -    return TRUE;
  26.865 -  }
  26.866 -
  26.867 -  if (Srb->PathId >= SCSI_BUSES || Srb->TargetId >= SCSI_TARGETS_PER_BUS)
  26.868 -  {
  26.869 -    Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
  26.870 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  26.871 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
  26.872 -    KdPrint((__DRIVER_NAME " --- HwScsiStartIo (Out of bounds)\n"));
  26.873 -    return TRUE;
  26.874 -  }
  26.875 -
  26.876 -  TargetData = &DeviceData->BusData[Srb->PathId].TargetData[Srb->TargetId];
  26.877 -
  26.878 -  if (!TargetData->Present)
  26.879 -  {
  26.880 -    Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
  26.881 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  26.882 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
  26.883 -    KdPrint((__DRIVER_NAME " --- HwScsiStartIo (Not Present)\n"));
  26.884 -    return TRUE;
  26.885 -  }
  26.886 -
  26.887 -  switch (Srb->Function)
  26.888 -  {
  26.889 -  case SRB_FUNCTION_EXECUTE_SCSI:
  26.890 -#if 0
  26.891 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_EXECUTE_SCSI\n"));
  26.892 -    KdPrint((__DRIVER_NAME "      CdbLength = %d\n", Srb->CdbLength));
  26.893 -    for (i = 0; i < Srb->CdbLength; i++)
  26.894 -      KdPrint((__DRIVER_NAME "      %02x: %02x\n", i, Srb->Cdb[i]));
  26.895 -    KdPrint((__DRIVER_NAME "      SrbFlags = 0x%02x\n", Srb->SrbFlags));
  26.896 -    KdPrint((__DRIVER_NAME "      DataTransferLength = %d\n", Srb->DataTransferLength));
  26.897 -#endif
  26.898 -    XenScsi_PutSrbOnRing(TargetData, Srb);
  26.899 -    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&TargetData->Ring, notify);
  26.900 -    if (notify)
  26.901 -      DeviceData->XenDeviceData->XenInterface.EvtChn_Notify(
  26.902 -        DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  26.903 -        TargetData->EventChannel);
  26.904 -    if (!RING_FULL(&TargetData->Ring))
  26.905 -      ScsiPortNotification(NextLuRequest, DeviceExtension, Srb->PathId, Srb->TargetId, Srb->Lun);
  26.906 -    else
  26.907 -      ScsiPortNotification(NextRequest, DeviceExtension);
  26.908 -    break;
  26.909 -  case SRB_FUNCTION_CLAIM_DEVICE:
  26.910 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_CLAIM_DEVICE\n"));
  26.911 -//    ObReferenceObject(WdfDeviceWdmGetDeviceObject(Device));
  26.912 -//    Srb->DataBuffer = WdfDeviceWdmGetDeviceObject(Device);
  26.913 -    Srb->SrbStatus = SRB_STATUS_SUCCESS;
  26.914 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  26.915 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
  26.916 -    break;
  26.917 -  case SRB_FUNCTION_IO_CONTROL:
  26.918 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
  26.919 -    Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
  26.920 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  26.921 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
  26.922 -    break;
  26.923 -  case SRB_FUNCTION_FLUSH:
  26.924 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
  26.925 -    Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
  26.926 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  26.927 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
  26.928 -    break;
  26.929 -  default:
  26.930 -    KdPrint((__DRIVER_NAME "     Unhandled Srb->Function = %08X\n", Srb->Function));
  26.931 -    Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
  26.932 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  26.933 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
  26.934 -    break;
  26.935 -  }
  26.936 -
  26.937 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  26.938 -
  26.939 -  return TRUE;
  26.940 -}
  26.941 -
  26.942 -static BOOLEAN
  26.943 -XenScsi_HwScsiResetBus(PVOID DeviceExtension, ULONG PathId)
  26.944 -{
  26.945 -  UNREFERENCED_PARAMETER(DeviceExtension);
  26.946 -  UNREFERENCED_PARAMETER(PathId);
  26.947 -
  26.948 -
  26.949 -  KdPrint((__DRIVER_NAME " --> HwScsiResetBus\n"));
  26.950 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  26.951 -
  26.952 -  KdPrint((__DRIVER_NAME " <-- HwScsiResetBus\n"));
  26.953 -
  26.954 -  return TRUE;
  26.955 -}
  26.956 -
  26.957 -
  26.958 -static BOOLEAN
  26.959 -XenScsi_HwScsiAdapterState(PVOID DeviceExtension, PVOID Context, BOOLEAN SaveState)
  26.960 -{
  26.961 -  UNREFERENCED_PARAMETER(DeviceExtension);
  26.962 -  UNREFERENCED_PARAMETER(Context);
  26.963 -  UNREFERENCED_PARAMETER(SaveState);
  26.964 -
  26.965 -  KdPrint((__DRIVER_NAME " --> HwScsiAdapterState\n"));
  26.966 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  26.967 -
  26.968 -  KdPrint((__DRIVER_NAME " <-- HwScsiAdapterState\n"));
  26.969 -
  26.970 -  return TRUE;
  26.971 -}
  26.972 -
  26.973 -static SCSI_ADAPTER_CONTROL_STATUS
  26.974 -XenScsi_HwScsiAdapterControl(PVOID DeviceExtension, SCSI_ADAPTER_CONTROL_TYPE ControlType, PVOID Parameters)
  26.975 -{
  26.976 -  SCSI_ADAPTER_CONTROL_STATUS Status = ScsiAdapterControlSuccess;
  26.977 -  PSCSI_SUPPORTED_CONTROL_TYPE_LIST SupportedControlTypeList;
  26.978 -
  26.979 -  UNREFERENCED_PARAMETER(DeviceExtension);
  26.980 -
  26.981 -  KdPrint((__DRIVER_NAME " --> HwScsiAdapterControl\n"));
  26.982 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  26.983 -
  26.984 -  switch (ControlType)
  26.985 -  {
  26.986 -  case ScsiQuerySupportedControlTypes:
  26.987 -    SupportedControlTypeList = (PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters;
  26.988 -    KdPrint((__DRIVER_NAME "     ScsiQuerySupportedControlTypes (Max = %d)\n", SupportedControlTypeList->MaxControlType));
  26.989 -    SupportedControlTypeList->SupportedTypeList[ScsiQuerySupportedControlTypes] = TRUE;
  26.990 -    SupportedControlTypeList->SupportedTypeList[ScsiStopAdapter] = TRUE;
  26.991 -    break;
  26.992 -  case ScsiStopAdapter:
  26.993 -    KdPrint((__DRIVER_NAME "     ScsiStopAdapter\n"));
  26.994 -    break;
  26.995 -  case ScsiRestartAdapter:
  26.996 -    KdPrint((__DRIVER_NAME "     ScsiRestartAdapter\n"));
  26.997 -    break;
  26.998 -  case ScsiSetBootConfig:
  26.999 -    KdPrint((__DRIVER_NAME "     ScsiSetBootConfig\n"));
 26.1000 -    break;
 26.1001 -  case ScsiSetRunningConfig:
 26.1002 -    KdPrint((__DRIVER_NAME "     ScsiSetRunningConfig\n"));
 26.1003 -    break;
 26.1004 -  default:
 26.1005 -    KdPrint((__DRIVER_NAME "     UNKNOWN\n"));
 26.1006 -    break;
 26.1007 -  }
 26.1008 -
 26.1009 -  KdPrint((__DRIVER_NAME " <-- HwScsiAdapterControl\n"));
 26.1010 -
 26.1011 -  return Status;
 26.1012 -}
    27.1 --- a/xenscsi/xenscsi.h	Sat May 17 00:06:05 2008 +1000
    27.2 +++ b/xenscsi/xenscsi.h	Thu May 22 13:46:15 2008 +1000
    27.3 @@ -35,53 +35,30 @@ typedef struct vscsiif_response vscsiif_
    27.4  typedef struct {
    27.5    vscsiif_request_t req;
    27.6    PSCSI_REQUEST_BLOCK Srb;
    27.7 -  PMDL Mdl;
    27.8 -  VOID *Buf;
    27.9  } vscsiif_shadow_t;
   27.10  
   27.11 -//#include "scsidata.h"
   27.12 -
   27.13 -#define SCSI_BUSES 4
   27.14 -#define SCSI_TARGETS_PER_BUS 16
   27.15 +#define SHADOW_ENTRIES 32
   27.16 +#define GRANT_ENTRIES 128
   27.17  
   27.18  struct
   27.19  {
   27.20 -  int Present;
   27.21 -  BOOLEAN PendingInterrupt;
   27.22 -  PVOID DeviceData; // how can we create a forward definition for this???
   27.23 -  evtchn_port_t EventChannel;
   27.24 -  vscsiif_shadow_t *shadow;
   27.25 -  uint16_t shadow_free;
   27.26 -  ULONG RingBufPFN;
   27.27 -  int BackendState;
   27.28 -  int FrontendState;
   27.29 -  char Path[128];
   27.30 -  int DeviceIndex;
   27.31 -  char BackendPath[128];
   27.32 -  vscsiif_front_ring_t Ring;
   27.33 -  int ring_detect_state;
   27.34 +  vscsiif_shadow_t shadows[SHADOW_ENTRIES];
   27.35 +  USHORT shadow_free_list[SHADOW_ENTRIES];
   27.36 +  USHORT shadow_free;
   27.37 +
   27.38 +  grant_ref_t grant_free_list[GRANT_ENTRIES];
   27.39 +  USHORT grant_free;
   27.40 +
   27.41 +  evtchn_port_t event_channel;
   27.42 +
   27.43 +  vscsiif_front_ring_t ring;
   27.44 +
   27.45    int host;
   27.46    int channel;
   27.47    int id;
   27.48    int lun;
   27.49 -} typedef XENSCSI_TARGET_DATA, *PXENSCSI_TARGET_DATA;
   27.50  
   27.51 -struct
   27.52 -{
   27.53 -  XENSCSI_TARGET_DATA TargetData[SCSI_TARGETS_PER_BUS];
   27.54 -} typedef XENSCSI_BUS_DATA, *PXENSCSI_BUS_DATA;
   27.55 -
   27.56 -struct
   27.57 -{
   27.58 -  PXENPCI_XEN_DEVICE_DATA XenDeviceData;
   27.59 -  XENSCSI_BUS_DATA BusData[SCSI_BUSES];
   27.60 -
   27.61 -  KSPIN_LOCK Lock;
   27.62 -
   27.63 -  int BusChangePending;
   27.64 -
   27.65 -  LONG EnumeratedDevices;
   27.66 -  int TotalInitialDevices;
   27.67 +  XENPCI_VECTORS vectors;
   27.68  } typedef XENSCSI_DEVICE_DATA, *PXENSCSI_DEVICE_DATA;
   27.69  
   27.70  enum dma_data_direction {
   27.71 @@ -91,4 +68,7 @@ enum dma_data_direction {
   27.72          DMA_NONE = 3,
   27.73  };
   27.74  
   27.75 +VOID
   27.76 +XenScsi_FillInitCallbacks(PHW_INITIALIZATION_DATA HwInitializationData);
   27.77 +
   27.78  #endif
    28.1 --- a/xenscsi/xenscsi.inx	Sat May 17 00:06:05 2008 +1000
    28.2 +++ b/xenscsi/xenscsi.inx	Thu May 22 13:46:15 2008 +1000
    28.3 @@ -3,6 +3,7 @@ Signature="$WINDOWS NT$"
    28.4  Class=SCSIAdapter
    28.5  ClassGuid={4D36E97B-E325-11CE-BFC1-08002BE10318}
    28.6  Provider=%XenGplPv%
    28.7 +CatalogFile="XenGPLPV.cat"
    28.8  
    28.9  [DestinationDirs]
   28.10  DefaultDestDir = 12
   28.11 @@ -27,11 +28,9 @@ CopyFiles=XenScsi.CopyFiles
   28.12  
   28.13  [XenScsi.CopyFiles]
   28.14  xenscsi.sys
   28.15 -xenaddresource.sys
   28.16  
   28.17  [XenScsi_Inst.NT.Services]
   28.18  AddService=XenScsi,2,XenScsi_Service, XenScsi_EventLog
   28.19 -AddService=XenAddResource,,XenAddResource_Service
   28.20  
   28.21  [XenScsi_Service]
   28.22  DisplayName    = %XenScsi.SVCDESC%                            
   28.23 @@ -52,66 +51,11 @@ AddReg = XenScsi_EventLog_AddReg
   28.24  HKR,,EventMessageFile,0x00020000,"%SystemRoot%\System32\IoLogMsg.dll;%SystemRoot%\System32\drivers\XenScsi.sys"
   28.25  HKR,,TypesSupported,0x00010001,7
   28.26  
   28.27 -[XenScsi_Inst.NT.CoInstallers]
   28.28 -AddReg=CoInstaller_AddReg
   28.29 -CopyFiles=CoInstaller_CopyFiles
   28.30 -
   28.31 -[XenScsi_Inst.NT.Wdf]
   28.32 -KmdfService = xenscsi, xenscsi_wdfsect
   28.33 -
   28.34  [XenScsi_Inst.NT.HW]
   28.35  AddReg = XenScsi_Inst_HW_AddReg
   28.36  
   28.37 -[XenScsi_Inst_HW_AddReg]
   28.38 -HKR,,"UpperFilters",0x00010000,"xenaddresource"
   28.39 -
   28.40 -[XenAddResource_Inst.NT]
   28.41 -CopyFiles=XenAddResource.CopyFiles
   28.42 -
   28.43 -[XenAddResource_Inst.NT.Services]
   28.44 -AddService=XenAddResource,,XenAddResource_Service 
   28.45 -
   28.46 -[XenAddResource_Inst.NT.HW]
   28.47 -AddReg = XenAddResource_Inst_HW_AddReg
   28.48 -
   28.49 -[XenAddResource_Inst_HW_AddReg]
   28.50 -HKR,,"LowerFilters",0x00010000,"xenaddresource"
   28.51 -
   28.52 -[XenAddResource.CopyFiles]
   28.53 -xenaddresource.sys
   28.54 -
   28.55 -[XenAddResource_Service]
   28.56 -DisplayName    = "Xen Resource Adder"
   28.57 -ServiceType    = 1
   28.58 -StartType      = 0
   28.59 -ErrorControl   = 1
   28.60 -LoadOrderGroup = System Bus Extender
   28.61 -ServiceBinary  = %12%\xenaddresource.sys
   28.62 -AddReg = XenAddResource_Service_AddReg
   28.63 -
   28.64 -[XenAddResource.CopyFiles]
   28.65 -xenaddresource.sys
   28.66 -
   28.67 -[XenAddResource_Service_AddReg]
   28.68 -HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
   28.69 -
   28.70 -[XenAddResource_Inst.NT.CoInstallers]
   28.71 -AddReg=CoInstaller_AddReg
   28.72 -CopyFiles=CoInstaller_CopyFiles
   28.73 -
   28.74 -[XenAddResource_Inst.NT.Wdf]
   28.75 -KmdfService = xenaddresource, xenaddresource_wdfsect
   28.76 -
   28.77 -[xenscsi_wdfsect]
   28.78 -KmdfLibraryVersion = $KMDFVERSION$
   28.79 -
   28.80 -[xenaddresource_wdfsect]
   28.81 -KmdfLibraryVersion = $KMDFVERSION$
   28.82 -
   28.83  [SourceDisksFiles]
   28.84  xenscsi.sys=1
   28.85 -xenaddresource.sys=1
   28.86 -WdfCoinstaller$KMDFCOINSTALLERVERSION$.dll=1,,
   28.87  
   28.88  [SourceDisksNames.x86]
   28.89  1 = %DISK_NAME%,,,\i386
   28.90 @@ -119,15 +63,8 @@ 1 = %DISK_NAME%,,,\i386
   28.91  [SourceDisksNames.amd64]
   28.92  1 = %DISK_NAME%,,,\amd64
   28.93  
   28.94 -[CoInstaller_CopyFiles]
   28.95 -WdfCoinstaller$KMDFCOINSTALLERVERSION$.dll,,,2
   28.96 -
   28.97 -[CoInstaller_AddReg]
   28.98 -HKR,,CoInstallers32,0x00010000, "WdfCoinstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller"
   28.99 -
  28.100  [Strings]
  28.101  XenGplPv = "Xen GPL PV Driver Developers"
  28.102  XenScsi.SVCDESC = "Xen SCSI Driver"
  28.103  XenScsi.DRVDESC = "Xen SCSI Driver"
  28.104 -XenAddResource.DRVDESC = "Xen Resource Adder"
  28.105  DISK_NAME = "Xen SCSI Device Driver Install Disk"
    29.1 --- a/xenstub/makefile.inc	Sat May 17 00:06:05 2008 +1000
    29.2 +++ b/xenstub/makefile.inc	Thu May 22 13:46:15 2008 +1000
    29.3 @@ -1,5 +1,5 @@
    29.4  _LNG=$(LANGUAGE)
    29.5 -STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -k $(KMDF_VERSION_MAJOR).$(KMDF_VERSION_MINOR) -v $(VERSION)
    29.6 +STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
    29.7  
    29.8  ..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf: $(INF_NAME).inx sources ..\common.inc
    29.9      copy $(@B).inx $@
    30.1 --- a/xenstub/xenstub.c	Sat May 17 00:06:05 2008 +1000
    30.2 +++ b/xenstub/xenstub.c	Thu May 22 13:46:15 2008 +1000
    30.3 @@ -17,143 +17,187 @@ along with this program; if not, write t
    30.4  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    30.5  */
    30.6  
    30.7 -#include "XenStub.h"
    30.8 +#include "xenstub.h"
    30.9  #include <stdlib.h>
   30.10  
   30.11  DRIVER_INITIALIZE DriverEntry;
   30.12 -static NTSTATUS
   30.13 -XenStub_AddDevice(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit);
   30.14 -static NTSTATUS
   30.15 -XenStub_PrepareHardware(WDFDEVICE hDevice, WDFCMRESLIST Resources, WDFCMRESLIST ResourcesTranslated);
   30.16 -static NTSTATUS
   30.17 -XenStub_ReleaseHardware(WDFDEVICE Device, WDFCMRESLIST ResourcesTranslated);
   30.18 -static NTSTATUS
   30.19 -XenStub_D0Entry(WDFDEVICE Device, WDF_POWER_DEVICE_STATE PreviousState);
   30.20 -static NTSTATUS
   30.21 -XenStub_D0Exit(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState);
   30.22 -
   30.23 -#ifdef ALLOC_PRAGMA
   30.24 -#pragma alloc_text (INIT, DriverEntry)
   30.25 -#pragma alloc_text (PAGE, XenStub_AddDevice)
   30.26 -#endif
   30.27 -
   30.28 -#pragma warning(disable : 4200) // zero-sized array
   30.29  
   30.30  NTSTATUS
   30.31 -DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
   30.32 +XenStub_Irp_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
   30.33  {
   30.34 -  WDF_DRIVER_CONFIG config;
   30.35 +  PIO_STACK_LOCATION stack;
   30.36    NTSTATUS status;
   30.37 +  PXENSTUB_DEVICE_DATA xsdd;
   30.38  
   30.39 -  KdPrint((__DRIVER_NAME " --> DriverEntry\n"));
   30.40 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   30.41 +
   30.42 +  xsdd = (PXENSTUB_DEVICE_DATA)device_object->DeviceExtension;
   30.43 +
   30.44 +  stack = IoGetCurrentIrpStackLocation(irp);
   30.45 +
   30.46 +  switch (stack->MinorFunction)
   30.47 +  {
   30.48 +  case IRP_MN_START_DEVICE:
   30.49 +    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE\n"));
   30.50 +    IoSkipCurrentIrpStackLocation(irp);
   30.51 +    //irp->IoStatus.Status = STATUS_SUCCESS;
   30.52 +    break;
   30.53 +    
   30.54 +  case IRP_MN_QUERY_STOP_DEVICE:
   30.55 +    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_STOP_DEVICE\n"));
   30.56 +    IoSkipCurrentIrpStackLocation(irp);
   30.57 +    //irp->IoStatus.Status = STATUS_SUCCESS;
   30.58 +    break;
   30.59 +
   30.60 +  case IRP_MN_STOP_DEVICE:
   30.61 +    KdPrint((__DRIVER_NAME "     IRP_MN_STOP_DEVICE\n"));
   30.62 +    IoSkipCurrentIrpStackLocation(irp);
   30.63 +    //irp->IoStatus.Status = STATUS_SUCCESS;
   30.64 +    break;
   30.65 +
   30.66 +  case IRP_MN_CANCEL_STOP_DEVICE:
   30.67 +    KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_STOP_DEVICE\n"));
   30.68 +    IoSkipCurrentIrpStackLocation(irp);
   30.69 +    //irp->IoStatus.Status = STATUS_SUCCESS;
   30.70 +    break;
   30.71  
   30.72 -  WDF_DRIVER_CONFIG_INIT(&config, XenStub_AddDevice);
   30.73 -  status = WdfDriverCreate(
   30.74 -    DriverObject,
   30.75 -    RegistryPath,
   30.76 -    WDF_NO_OBJECT_ATTRIBUTES,
   30.77 -    &config,
   30.78 -    WDF_NO_HANDLE);
   30.79 -  if(!NT_SUCCESS(status))
   30.80 -  {
   30.81 -    KdPrint((__DRIVER_NAME " WdfDriverCreate failed with status 0x%08x\n", status));
   30.82 +  case IRP_MN_QUERY_REMOVE_DEVICE:
   30.83 +    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_REMOVE_DEVICE\n"));
   30.84 +    IoSkipCurrentIrpStackLocation(irp);
   30.85 +    //irp->IoStatus.Status = STATUS_SUCCESS;
   30.86 +    break;
   30.87 +    
   30.88 +  case IRP_MN_REMOVE_DEVICE:
   30.89 +    KdPrint((__DRIVER_NAME "     IRP_MN_REMOVE_DEVICE\n"));
   30.90 +    IoSkipCurrentIrpStackLocation(irp);
   30.91 +    //irp->IoStatus.Status = STATUS_SUCCESS;
   30.92 +    break;
   30.93 +
   30.94 +  case IRP_MN_CANCEL_REMOVE_DEVICE:
   30.95 +    KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_REMOVE_DEVICE\n"));
   30.96 +    IoSkipCurrentIrpStackLocation(irp);
   30.97 +    //irp->IoStatus.Status = STATUS_SUCCESS;
   30.98 +    break;
   30.99 +
  30.100 +  case IRP_MN_SURPRISE_REMOVAL:
  30.101 +    KdPrint((__DRIVER_NAME "     IRP_MN_SURPRISE_REMOVAL\n"));
  30.102 +    IoSkipCurrentIrpStackLocation(irp);
  30.103 +    //irp->IoStatus.Status = STATUS_SUCCESS;
  30.104 +    break;
  30.105 +
  30.106 +  case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  30.107 +    KdPrint((__DRIVER_NAME "     IRP_MN_DEVICE_USAGE_NOTIFICATION\n"));
  30.108 +    IoSkipCurrentIrpStackLocation(irp);
  30.109 +    //irp->IoStatus.Status = STATUS_SUCCESS;
  30.110 +    break;
  30.111 +
  30.112 +  case IRP_MN_QUERY_DEVICE_RELATIONS:
  30.113 +    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS\n"));
  30.114 +    IoSkipCurrentIrpStackLocation(irp);
  30.115 +    //irp->IoStatus.Status = STATUS_SUCCESS;
  30.116 +    break;
  30.117 +
  30.118 +  case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
  30.119 +    KdPrint((__DRIVER_NAME "     IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n"));
  30.120 +    IoSkipCurrentIrpStackLocation(irp);
  30.121 +    //irp->IoStatus.Status = STATUS_SUCCESS;
  30.122 +    break;
  30.123 +
  30.124 +  default:
  30.125 +    //KdPrint((__DRIVER_NAME "     Unhandled Minor = %d\n", stack->MinorFunction));
  30.126 +    IoSkipCurrentIrpStackLocation(irp);
  30.127 +    break;
  30.128    }
  30.129  
  30.130 -  KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
  30.131 +  status = IoCallDriver(xsdd->lower_do, irp);
  30.132 +
  30.133 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  30.134 +
  30.135 +  return status;
  30.136 +}
  30.137 +
  30.138 +NTSTATUS
  30.139 +XenStub_Irp_Power(PDEVICE_OBJECT device_object, PIRP irp)
  30.140 +{
  30.141 +  NTSTATUS status;
  30.142 +  PXENSTUB_DEVICE_DATA xsdd = device_object->DeviceExtension;
  30.143 +
  30.144 +  UNREFERENCED_PARAMETER(device_object);
  30.145 +  
  30.146 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  30.147 +
  30.148 +  PoStartNextPowerIrp(irp);
  30.149 +  IoSkipCurrentIrpStackLocation(irp);
  30.150 +
  30.151 +  status =  PoCallDriver (xsdd->lower_do, irp);
  30.152 +  
  30.153 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  30.154  
  30.155    return status;
  30.156  }
  30.157  
  30.158  static NTSTATUS
  30.159 -XenStub_AddDevice(
  30.160 -    IN WDFDRIVER Driver,
  30.161 -    IN PWDFDEVICE_INIT DeviceInit
  30.162 -    )
  30.163 +XenStub_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
  30.164  {
  30.165 -  NTSTATUS Status;
  30.166 -  WDF_OBJECT_ATTRIBUTES attributes;
  30.167 -  WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
  30.168 -  WDFDEVICE Device;
  30.169 -
  30.170 -  UNREFERENCED_PARAMETER(Driver);
  30.171 -
  30.172 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  30.173 -
  30.174 -  WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
  30.175 -  pnpPowerCallbacks.EvtDevicePrepareHardware = XenStub_PrepareHardware;
  30.176 -  pnpPowerCallbacks.EvtDeviceReleaseHardware = XenStub_ReleaseHardware;
  30.177 -  pnpPowerCallbacks.EvtDeviceD0Entry = XenStub_D0Entry;
  30.178 -  pnpPowerCallbacks.EvtDeviceD0Exit = XenStub_D0Exit;
  30.179 -  WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);
  30.180 -
  30.181 -  WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
  30.182 -
  30.183 -  Status = WdfDeviceCreate(&DeviceInit, &attributes, &Device);  
  30.184 -  if(!NT_SUCCESS(Status))
  30.185 -  {
  30.186 -    KdPrint((__DRIVER_NAME "     WdfDeviceCreate failed with Status 0x%08x\n", Status));
  30.187 -    return Status;
  30.188 -  }
  30.189 -
  30.190 -  KdPrint((__DRIVER_NAME " <-- DeviceAdd\n"));
  30.191 -  return Status;
  30.192 -}
  30.193 -
  30.194 -static NTSTATUS
  30.195 -XenStub_PrepareHardware(
  30.196 -  WDFDEVICE Device,
  30.197 -  WDFCMRESLIST ResourceList,
  30.198 -  WDFCMRESLIST ResourceListTranslated)
  30.199 -{
  30.200 -  UNREFERENCED_PARAMETER(Device);
  30.201 -  UNREFERENCED_PARAMETER(ResourceList);
  30.202 -  UNREFERENCED_PARAMETER(ResourceListTranslated);
  30.203 +  NTSTATUS status;
  30.204 +  PDEVICE_OBJECT fdo = NULL;
  30.205 +  PXENSTUB_DEVICE_DATA xsdd;
  30.206  
  30.207    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  30.208  
  30.209 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  30.210 +  status = IoCreateDevice(DriverObject,
  30.211 +    sizeof(XENSTUB_DEVICE_DATA),
  30.212 +    NULL,
  30.213 +    FILE_DEVICE_NULL,
  30.214 +    FILE_DEVICE_SECURE_OPEN,
  30.215 +    FALSE,
  30.216 +    &fdo);
  30.217 +
  30.218 +  if (!NT_SUCCESS(status))
  30.219 +  {
  30.220 +    KdPrint((__DRIVER_NAME "     IoCreateDevice failed 0x%08x\n", status));
  30.221 +    return status;
  30.222 +  }
  30.223  
  30.224 -  return STATUS_SUCCESS;
  30.225 +  xsdd = (PXENSTUB_DEVICE_DATA)fdo->DeviceExtension;
  30.226 +
  30.227 +  RtlZeroMemory(xsdd, sizeof(XENSTUB_DEVICE_DATA));
  30.228 +
  30.229 +  xsdd->fdo = fdo;
  30.230 +  xsdd->pdo = PhysicalDeviceObject;
  30.231 +  xsdd->lower_do = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
  30.232 +  if(xsdd->lower_do == NULL) {
  30.233 +    IoDeleteDevice(fdo);
  30.234 +    return STATUS_NO_SUCH_DEVICE;
  30.235 +  }
  30.236 +  
  30.237 +  fdo->Flags &= ~DO_DEVICE_INITIALIZING;
  30.238 +
  30.239 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  30.240 +  return status;
  30.241  }
  30.242  
  30.243 -static NTSTATUS
  30.244 -XenStub_ReleaseHardware(WDFDEVICE Device, WDFCMRESLIST ResourcesTranslated)
  30.245 +NTSTATUS
  30.246 +DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
  30.247  {
  30.248 -  UNREFERENCED_PARAMETER(Device);
  30.249 -  UNREFERENCED_PARAMETER(ResourcesTranslated);
  30.250 +  NTSTATUS status = STATUS_SUCCESS;
  30.251 +
  30.252 +  UNREFERENCED_PARAMETER(RegistryPath);
  30.253  
  30.254    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  30.255  
  30.256 +  DriverObject->DriverExtension->AddDevice = XenStub_AddDevice;
  30.257 +  DriverObject->MajorFunction[IRP_MJ_PNP] = XenStub_Irp_Pnp;
  30.258 +  DriverObject->MajorFunction[IRP_MJ_POWER] = XenStub_Irp_Power;
  30.259 +  DriverObject->MajorFunction[IRP_MJ_CREATE] = NULL;
  30.260 +  DriverObject->MajorFunction[IRP_MJ_CLOSE] = NULL;
  30.261 +  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = NULL;
  30.262 +  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NULL;
  30.263 +  DriverObject->MajorFunction[IRP_MJ_READ] = NULL;
  30.264 +  DriverObject->MajorFunction[IRP_MJ_WRITE] = NULL;
  30.265 +  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = NULL;
  30.266 +
  30.267    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  30.268  
  30.269 -  return STATUS_SUCCESS;
  30.270 -}
  30.271 -
  30.272 -static NTSTATUS
  30.273 -XenStub_D0Entry(
  30.274 -  WDFDEVICE Device,
  30.275 -  WDF_POWER_DEVICE_STATE PreviousState
  30.276 -  )
  30.277 -{
  30.278 -  UNREFERENCED_PARAMETER(Device);
  30.279 -  UNREFERENCED_PARAMETER(PreviousState);
  30.280 -
  30.281 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  30.282 -
  30.283 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  30.284 -
  30.285 -  return STATUS_SUCCESS;
  30.286 -}
  30.287 -
  30.288 -static NTSTATUS
  30.289 -XenStub_D0Exit(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState)
  30.290 -{
  30.291 -  UNREFERENCED_PARAMETER(Device);
  30.292 -  UNREFERENCED_PARAMETER(TargetState);
  30.293 -
  30.294 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  30.295 -
  30.296 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  30.297 -
  30.298 -  return STATUS_SUCCESS;
  30.299 -}
  30.300 +  return status;
  30.301 +}
  30.302 \ No newline at end of file
    31.1 --- a/xenstub/xenstub.h	Sat May 17 00:06:05 2008 +1000
    31.2 +++ b/xenstub/xenstub.h	Thu May 22 13:46:15 2008 +1000
    31.3 @@ -22,7 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fi
    31.4  
    31.5  #include <ntddk.h>
    31.6  #include <wdm.h>
    31.7 -#include <wdf.h>
    31.8  #include <initguid.h>
    31.9  #include <wdmguid.h>
   31.10  #include <errno.h>
   31.11 @@ -30,6 +29,12 @@ Foundation, Inc., 51 Franklin Street, Fi
   31.12  #include <ntstrsafe.h>
   31.13  #define __DRIVER_NAME "XenStub"
   31.14  #include <xen_windows.h>
   31.15 -//#include <xen_public.h>
   31.16 +
   31.17 +typedef struct
   31.18 +{
   31.19 +  PDEVICE_OBJECT fdo;
   31.20 +  PDEVICE_OBJECT pdo;
   31.21 +  PDEVICE_OBJECT lower_do;
   31.22 +} XENSTUB_DEVICE_DATA, *PXENSTUB_DEVICE_DATA;
   31.23  
   31.24  #endif
    32.1 --- a/xenvbd/xenvbd.c	Sat May 17 00:06:05 2008 +1000
    32.2 +++ b/xenvbd/xenvbd.c	Thu May 22 13:46:15 2008 +1000
    32.3 @@ -77,7 +77,7 @@ XenVbd_Pnp(PDEVICE_OBJECT device_object,
    32.4      old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
    32.5      if (old_crl != NULL)
    32.6      {
    32.7 -      mdl = AllocatePage();
    32.8 +      mdl = AllocateUncachedPage();
    32.9        old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
   32.10          FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
   32.11          FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
   32.12 @@ -90,9 +90,10 @@ XenVbd_Pnp(PDEVICE_OBJECT device_object,
   32.13        prd->Type = CmResourceTypeMemory;
   32.14        prd->ShareDisposition = CmResourceShareDeviceExclusive;
   32.15        prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
   32.16 +      KdPrint((__DRIVER_NAME "     PFN[0] = %p\n", MmGetMdlPfnArray(mdl)[0]));
   32.17        prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
   32.18        prd->u.Memory.Length = PAGE_SIZE;
   32.19 -      KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
   32.20 +      KdPrint((__DRIVER_NAME "     Start = %08x:%08x, Length = %d\n", prd->u.Memory.Start.HighPart, prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
   32.21        ptr = start = MmGetMdlVirtualAddress(mdl);
   32.22        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "ring-ref", NULL);
   32.23        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL);
   32.24 @@ -175,7 +176,7 @@ XenVbd_Pnp(PDEVICE_OBJECT device_object,
   32.25  NTSTATUS
   32.26  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
   32.27  {
   32.28 -  ULONG Status;
   32.29 +  ULONG status;
   32.30    HW_INITIALIZATION_DATA HwInitializationData;
   32.31  
   32.32    KdPrint((__DRIVER_NAME " --> "__FUNCTION__ "\n"));
   32.33 @@ -188,7 +189,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   32.34    HwInitializationData.HwDmaStarted = NULL;
   32.35    HwInitializationData.DeviceExtensionSize = sizeof(XENVBD_DEVICE_DATA);
   32.36    HwInitializationData.SpecificLuExtensionSize = 0;
   32.37 -  HwInitializationData.SrbExtensionSize = PAGE_SIZE;
   32.38 +  HwInitializationData.SrbExtensionSize = UNALIGNED_DOUBLE_BUFFER_SIZE;
   32.39    HwInitializationData.NumberOfAccessRanges = 1;
   32.40    HwInitializationData.MapBuffers = TRUE;
   32.41    HwInitializationData.NeedPhysicalAddresses = FALSE;
   32.42 @@ -203,291 +204,18 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   32.43  
   32.44    XenVbd_FillInitCallbacks(&HwInitializationData);
   32.45  
   32.46 -  Status = ScsiPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
   32.47 +  status = ScsiPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
   32.48    
   32.49    /* this is a bit naughty... */
   32.50    XenVbd_Pnp_Original = DriverObject->MajorFunction[IRP_MJ_PNP];
   32.51    DriverObject->MajorFunction[IRP_MJ_PNP] = XenVbd_Pnp;
   32.52  
   32.53 -  if(!NT_SUCCESS(Status))
   32.54 +  if(!NT_SUCCESS(status))
   32.55    {
   32.56 -    KdPrint((__DRIVER_NAME " ScsiPortInitialize failed with status 0x%08x\n", Status));
   32.57 +    KdPrint((__DRIVER_NAME " ScsiPortInitialize failed with status 0x%08x\n", status));
   32.58    }
   32.59  
   32.60    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   32.61  
   32.62 -  return Status;
   32.63 -}
   32.64 -#if 0
   32.65 -static __inline uint64_t
   32.66 -GET_ID_FROM_FREELIST(PXENVBD_DEVICE_DATA device_data)
   32.67 -{
   32.68 -  uint64_t free;
   32.69 -  free = device_data->shadow_free;
   32.70 -  device_data->shadow_free = device_data->shadow[free].req.id;
   32.71 -  device_data->shadow[free].req.id = 0x0fffffee; /* debug */
   32.72 -  return free;
   32.73 +  return status;
   32.74  }
   32.75 -#endif
   32.76 -
   32.77 -#if 0
   32.78 -static VOID
   32.79 -XenVbd_BackEndStateHandler(char *Path, PVOID Data)
   32.80 -{
   32.81 -  PXENVBD_DEVICE_DATA device_data;
   32.82 -  char TmpPath[128];
   32.83 -  char *Value;
   32.84 -  int NewState;
   32.85 -  PMDL Mdl;
   32.86 -  grant_ref_t ref;
   32.87 -  blkif_sring_t *SharedRing;
   32.88 -  ULONG PFN;
   32.89 -  ULONG i, j;
   32.90 -  blkif_request_t *req;
   32.91 -  int notify;
   32.92 -
   32.93 -  KdPrint((__DRIVER_NAME " --> BackEndStateHandler\n"));
   32.94 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   32.95 -
   32.96 -  device_data = (PXENVBD_TARGET_DATA)Data;
   32.97 -
   32.98 -  DeviceData->XenDeviceData->XenInterface.XenBus_Read(
   32.99 -    DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.100 -    XBT_NIL, Path, &Value);
  32.101 -
  32.102 -  NewState = atoi(Value);
  32.103 -  switch (NewState)
  32.104 -  {
  32.105 -  case XenbusStateUnknown:
  32.106 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Unknown\n"));  
  32.107 -    break;
  32.108 -
  32.109 -  case XenbusStateInitialising:
  32.110 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Initialising\n"));  
  32.111 -    break;
  32.112 -
  32.113 -  case XenbusStateInitWait:
  32.114 -    KdPrint((__DRIVER_NAME "     Backend State Changed to InitWait\n"));  
  32.115 -
  32.116 -    TargetData->EventChannel = DeviceData->XenDeviceData->XenInterface.EvtChn_AllocUnbound(
  32.117 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, 0);
  32.118 -    DeviceData->XenDeviceData->XenInterface.EvtChn_Bind(
  32.119 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.120 -      TargetData->EventChannel, XenVbd_Interrupt, TargetData);
  32.121 -    Mdl = AllocatePage();
  32.122 -    PFN = (ULONG)*MmGetMdlPfnArray(Mdl);
  32.123 -    SharedRing = (blkif_sring_t *)MmGetMdlVirtualAddress(Mdl);
  32.124 -    RtlZeroMemory(SharedRing, PAGE_SIZE);
  32.125 -    SHARED_RING_INIT(SharedRing);
  32.126 -    FRONT_RING_INIT(&TargetData->Ring, SharedRing, PAGE_SIZE);
  32.127 -    ref = DeviceData->XenDeviceData->XenInterface.GntTbl_GrantAccess(
  32.128 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.129 -      0, PFN, FALSE, 0);
  32.130 -    ASSERT((signed short)ref >= 0);
  32.131 -    TargetData->ring_detect_state = 0;
  32.132 -    TargetData->shadow = ExAllocatePoolWithTag(NonPagedPool, sizeof(blkif_shadow_t) * max(BLK_RING_SIZE, BLK_OTHER_RING_SIZE), XENVBD_POOL_TAG);
  32.133 -
  32.134 -    memset(TargetData->shadow, 0, sizeof(blkif_shadow_t) * max(BLK_RING_SIZE, BLK_OTHER_RING_SIZE));
  32.135 -    for (i = 0; i < max(BLK_RING_SIZE, BLK_OTHER_RING_SIZE); i++)
  32.136 -    {
  32.137 -      TargetData->shadow[i].req.id = i + 1;
  32.138 -      TargetData->shadow[i].Mdl = AllocatePages(BLKIF_MAX_SEGMENTS_PER_REQUEST); // stupid that we have to do this!
  32.139 -      TargetData->shadow[i].Buf = MmGetMdlVirtualAddress(TargetData->shadow[i].Mdl);
  32.140 -      for (j = 0; j < BLKIF_MAX_SEGMENTS_PER_REQUEST; j++)
  32.141 -      {
  32.142 -        TargetData->shadow[i].req.seg[j].gref = DeviceData->XenDeviceData->XenInterface.GntTbl_GrantAccess(
  32.143 -          DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.144 -          0, (ULONG)MmGetMdlPfnArray(TargetData->shadow[i].Mdl)[j], FALSE, 0);
  32.145 -        ASSERT((signed short)TargetData->shadow[i].req.seg[j].gref >= 0);
  32.146 -      }
  32.147 -    }
  32.148 -    TargetData->shadow_free = 0;
  32.149 -
  32.150 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  32.151 -    RtlStringCbCatA(TmpPath, 128, "/protocol");
  32.152 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(
  32.153 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.154 -      XBT_NIL, TmpPath, "%s", XEN_IO_PROTO_ABI_NATIVE);
  32.155 -
  32.156 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  32.157 -    RtlStringCbCatA(TmpPath, 128, "/ring-ref");
  32.158 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(
  32.159 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.160 -      XBT_NIL, TmpPath, "%d", ref);
  32.161 -
  32.162 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  32.163 -    RtlStringCbCatA(TmpPath, 128, "/event-channel");
  32.164 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(
  32.165 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.166 -      XBT_NIL, TmpPath, "%d", TargetData->EventChannel);
  32.167 -
  32.168 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  32.169 -    RtlStringCbCatA(TmpPath, 128, "/state");
  32.170 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(
  32.171 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, 
  32.172 -      XBT_NIL, TmpPath, "%d", XenbusStateInitialised);
  32.173 -
  32.174 -/*
  32.175 -    KdPrint((__DRIVER_NAME "     sizeof(blkif_request) = %d\n", sizeof(struct blkif_request)));
  32.176 -    KdPrint((__DRIVER_NAME "     sizeof(blkif_request_segment) = %d\n", sizeof(struct blkif_request_segment)));
  32.177 -    KdPrint((__DRIVER_NAME "     sizeof(blkif_response) = %d\n", sizeof(struct blkif_response)));
  32.178 -    KdPrint((__DRIVER_NAME "     operation = %d\n", (int)((char *)(&req.operation) - (char *)(&req))));
  32.179 -    KdPrint((__DRIVER_NAME "     nr_segments = %d\n", (int)((char *)(&req.nr_segments) - (char *)(&req))));
  32.180 -    KdPrint((__DRIVER_NAME "     handle = %d\n", (int)((char *)(&req.handle) - (char *)(&req))));
  32.181 -    KdPrint((__DRIVER_NAME "     id = %d\n", (int)((char *)(&req.id) - (char *)(&req))));
  32.182 -    KdPrint((__DRIVER_NAME "     sector_number = %d\n", (int)((char *)(&req.sector_number) - (char *)(&req))));
  32.183 -    KdPrint((__DRIVER_NAME "     seg = %d\n", (int)((char *)(&req.seg) - (char *)(&req))));
  32.184 -
  32.185 -    KdPrint((__DRIVER_NAME "     id = %d\n", (int)((char *)(&rep.id) - (char *)(&rep))));
  32.186 -    KdPrint((__DRIVER_NAME "     operation = %d\n", (int)((char *)(&rep.operation) - (char *)(&rep))));
  32.187 -    KdPrint((__DRIVER_NAME "     status = %d\n", (int)((char *)(&rep.status) - (char *)(&rep))));
  32.188 -
  32.189 -    KdPrint((__DRIVER_NAME "     sizeof(union blkif_sring_entry) = %d\n", sizeof(union blkif_sring_entry)));
  32.190 -    KdPrint((__DRIVER_NAME "     %d\n", (int)((char *)(&entries[1]) - (char *)(&entries[0]))));
  32.191 -*/
  32.192 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Initialised\n"));
  32.193 -    break;
  32.194 -
  32.195 -  case XenbusStateInitialised:
  32.196 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Initialised\n"));
  32.197 -    break;
  32.198 -
  32.199 -  case XenbusStateConnected:
  32.200 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Connected\n"));  
  32.201 -
  32.202 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  32.203 -    RtlStringCbCatA(TmpPath, 128, "/device-type");
  32.204 -    DeviceData->XenDeviceData->XenInterface.XenBus_Read(
  32.205 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.206 -      XBT_NIL, TmpPath, &Value);
  32.207 -    if (strcmp(Value, "disk") == 0)
  32.208 -    {
  32.209 -      KdPrint((__DRIVER_NAME "     DeviceType = Disk\n"));    
  32.210 -      TargetData->DeviceType = XENVBD_DEVICETYPE_DISK;
  32.211 -    }
  32.212 -    else if (strcmp(Value, "cdrom") == 0)
  32.213 -    {
  32.214 -      KdPrint((__DRIVER_NAME "     DeviceType = CDROM\n"));    
  32.215 -      TargetData->DeviceType = XENVBD_DEVICETYPE_CDROM;
  32.216 -    }
  32.217 -    else
  32.218 -    {
  32.219 -      KdPrint((__DRIVER_NAME "     DeviceType = %s (This probably won't work!)\n", Value));
  32.220 -      TargetData->DeviceType = XENVBD_DEVICETYPE_UNKNOWN;
  32.221 -    }
  32.222 -
  32.223 -    RtlStringCbCopyA(TmpPath, 128, TargetData->BackendPath);
  32.224 -    RtlStringCbCatA(TmpPath, 128, "/type"); // should probably check that this is 'phy' or 'file' or at least not ''
  32.225 -    DeviceData->XenDeviceData->XenInterface.XenBus_Read(
  32.226 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.227 -      XBT_NIL, TmpPath, &Value);
  32.228 -    KdPrint((__DRIVER_NAME "     Backend Type = %s\n", Value));
  32.229 -    ExFreePool(Value);
  32.230 -
  32.231 -    RtlStringCbCopyA(TmpPath, 128, TargetData->BackendPath);
  32.232 -    RtlStringCbCatA(TmpPath, 128, "/mode"); // should store this...
  32.233 -    DeviceData->XenDeviceData->XenInterface.XenBus_Read(
  32.234 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.235 -      XBT_NIL, TmpPath, &Value);
  32.236 -    KdPrint((__DRIVER_NAME "     Backend Mode = %s\n", Value));
  32.237 -    ExFreePool(Value);
  32.238 -
  32.239 -    RtlStringCbCopyA(TmpPath, 128, TargetData->BackendPath);
  32.240 -    RtlStringCbCatA(TmpPath, 128, "/sector-size");
  32.241 -    DeviceData->XenDeviceData->XenInterface.XenBus_Read(
  32.242 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.243 -      XBT_NIL, TmpPath, &Value);
  32.244 -    // should complain if Value == NULL
  32.245 -    TargetData->BytesPerSector = atoi(Value);
  32.246 -
  32.247 -    KdPrint((__DRIVER_NAME "     BytesPerSector = %d\n", TargetData->BytesPerSector));    
  32.248 -
  32.249 -    RtlStringCbCopyA(TmpPath, 128, TargetData->BackendPath);
  32.250 -    RtlStringCbCatA(TmpPath, 128, "/sectors");
  32.251 -    DeviceData->XenDeviceData->XenInterface.XenBus_Read(
  32.252 -      DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.253 -      XBT_NIL, TmpPath, &Value);
  32.254 -    // should complain if Value == NULL
  32.255 -    TargetData->TotalSectors = (ULONGLONG)atol(Value);
  32.256 -
  32.257 -    KdPrint((__DRIVER_NAME "     TotalSectors = %d\n", TargetData->TotalSectors));    
  32.258 -
  32.259 -    // should probably use the partition table (if one exists) here for the sectorspertrack and trackspercylinder values
  32.260 -    TargetData->Geometry.MediaType = FixedMedia;
  32.261 -    TargetData->Geometry.BytesPerSector = TargetData->BytesPerSector;
  32.262 -    TargetData->Geometry.SectorsPerTrack = 63;
  32.263 -    TargetData->Geometry.TracksPerCylinder = 255;
  32.264 -    TargetData->Geometry.Cylinders.QuadPart = TargetData->TotalSectors / TargetData->Geometry.SectorsPerTrack / TargetData->Geometry.TracksPerCylinder;
  32.265 -    KdPrint((__DRIVER_NAME "     Geometry C/H/S = %d/%d/%d\n", TargetData->Geometry.Cylinders.LowPart, TargetData->Geometry.TracksPerCylinder, TargetData->Geometry.SectorsPerTrack));
  32.266 -
  32.267 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  32.268 -    RtlStringCbCatA(TmpPath, 128, "/state");
  32.269 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, XBT_NIL, TmpPath, "%d", XenbusStateConnected);
  32.270 -
  32.271 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
  32.272 -
  32.273 -    TargetData->Running = 1;
  32.274 -    KeMemoryBarrier();
  32.275 -    
  32.276 -    req = RING_GET_REQUEST(&TargetData->Ring, TargetData->Ring.req_prod_pvt);
  32.277 -    req->operation = 0xff;
  32.278 -    req->nr_segments = 0;
  32.279 -    for (i = 0; i < req->nr_segments; i++)
  32.280 -    {
  32.281 -      req->seg[i].gref = 0xffffffff;
  32.282 -      req->seg[i].first_sect = 0xff;
  32.283 -      req->seg[i].last_sect = 0xff;
  32.284 -    }
  32.285 -    TargetData->Ring.req_prod_pvt++;
  32.286 -
  32.287 -    req = RING_GET_REQUEST(&TargetData->Ring, TargetData->Ring.req_prod_pvt);
  32.288 -    req->operation = 0xff;
  32.289 -    req->nr_segments = 0;
  32.290 -    for (i = 0; i < req->nr_segments; i++)
  32.291 -    {
  32.292 -      req->seg[i].gref = 0xffffffff;
  32.293 -      req->seg[i].first_sect = 0xff;
  32.294 -      req->seg[i].last_sect = 0xff;
  32.295 -    }
  32.296 -    TargetData->Ring.req_prod_pvt++;
  32.297 -
  32.298 -    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&TargetData->Ring, notify);
  32.299 -    if (notify)
  32.300 -      DeviceData->XenDeviceData->XenInterface.EvtChn_Notify(
  32.301 -        DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
  32.302 -        TargetData->EventChannel);
  32.303 -
  32.304 -    InterlockedIncrement(&DeviceData->EnumeratedDevices);
  32.305 -    KdPrint((__DRIVER_NAME "     Added a device\n"));  
  32.306 -
  32.307 -// now ask windows to rescan the scsi bus...
  32.308 -//    DeviceData->BusChangePending = 1;
  32.309 -    break;
  32.310 -
  32.311 -  case XenbusStateClosing:
  32.312 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Closing\n"));  
  32.313 -    // this behaviour is only to properly close down to then restart in the case of a dump
  32.314 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  32.315 -    RtlStringCbCatA(TmpPath, 128, "/state");
  32.316 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, XBT_NIL, TmpPath, "%d", XenbusStateClosed);
  32.317 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Closed\n"));
  32.318 -    break;
  32.319 -
  32.320 -  case XenbusStateClosed:
  32.321 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Closed\n"));  
  32.322 -    // this behaviour is only to properly close down to then restart in the case of a dump
  32.323 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
  32.324 -    RtlStringCbCatA(TmpPath, 128, "/state");
  32.325 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, XBT_NIL, TmpPath, "%d", XenbusStateInitialising);
  32.326 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Initialising\n"));
  32.327 -    break;
  32.328 -
  32.329 -  default:
  32.330 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Undefined = %d\n", NewState));
  32.331 -    break;
  32.332 -  }
  32.333 -
  32.334 -  KdPrint((__DRIVER_NAME " <-- BackEndStateHandler\n"));
  32.335 -}
  32.336 -
  32.337 -#endif
    33.1 --- a/xenvbd/xenvbd.h	Sat May 17 00:06:05 2008 +1000
    33.2 +++ b/xenvbd/xenvbd.h	Thu May 22 13:46:15 2008 +1000
    33.3 @@ -44,6 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fi
    33.4  
    33.5  #define XENVBD_POOL_TAG (ULONG) 'XVBD'
    33.6  
    33.7 +#define UNALIGNED_DOUBLE_BUFFER_SIZE (PAGE_SIZE * 2)
    33.8  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
    33.9  #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
   33.10  #define BLK_OTHER_RING_SIZE __RING_SIZE((blkif_other_sring_t *)0, PAGE_SIZE)
   33.11 @@ -75,10 +76,6 @@ DEFINE_RING_TYPES(blkif_other, struct bl
   33.12  typedef struct {
   33.13    blkif_request_t req;
   33.14    PSCSI_REQUEST_BLOCK Srb;
   33.15 -/*
   33.16 -  PMDL Mdl;
   33.17 -  VOID *Buf;
   33.18 -*/
   33.19  } blkif_shadow_t;
   33.20  
   33.21  #define SHADOW_ENTRIES 32
    34.1 --- a/xenvbd/xenvbd.inx	Sat May 17 00:06:05 2008 +1000
    34.2 +++ b/xenvbd/xenvbd.inx	Thu May 22 13:46:15 2008 +1000
    34.3 @@ -3,6 +3,7 @@ Signature="$WINDOWS NT$"
    34.4  Class=SCSIAdapter
    34.5  ClassGuid={4D36E97B-E325-11CE-BFC1-08002BE10318}
    34.6  Provider=%XenGplPv%
    34.7 +CatalogFile="XenGPLPV.cat"
    34.8  
    34.9  [DestinationDirs]
   34.10  DefaultDestDir = 12
   34.11 @@ -25,11 +26,9 @@ CopyFiles=XenVbd.CopyFiles
   34.12  
   34.13  [XenVbd.CopyFiles]
   34.14  xenvbd.sys
   34.15 -;xenaddresource.sys
   34.16  
   34.17  [XenVbd_Inst.NT.Services]
   34.18  AddService=XenVbd,2,XenVbd_Service, XenVbd_EventLog
   34.19 -;AddService=XenAddResource,,XenAddResource_Service
   34.20  
   34.21  [XenVbd_Service]
   34.22  DisplayName    = %XenVbd.SVCDESC%                            
   34.23 @@ -42,7 +41,9 @@ AddReg = XenVbd_Service_AddReg
   34.24  
   34.25  [XenVbd_Service_AddReg]
   34.26  HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
   34.27 +; Add XenHide as a filter to IDE Controllers
   34.28  HKLM,SYSTEM\CurrentControlSet\Control\Class\{4D36E96A-E325-11CE-BFC1-08002BE10318},UpperFilters,0x00010008,XenHide
   34.29 +; Add XenHide as a filter to SCSI Controllers
   34.30  HKLM,SYSTEM\CurrentControlSet\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318},UpperFilters,0x00010008,XenHide
   34.31  
   34.32  [XenVbd_EventLog]
   34.33 @@ -55,52 +56,17 @@ HKR,,TypesSupported,0x00010001,7
   34.34  [XenVbd_Inst.NT.HW]
   34.35  AddReg = XenVbd_Inst_HW_AddReg
   34.36  
   34.37 -[XenVbd_Inst_HW_AddReg]
   34.38 -;HKR,,"UpperFilters",0x00010000,"xenaddresource"
   34.39 -
   34.40 -;[XenAddResource_Inst.NT]
   34.41 -;CopyFiles=XenAddResource.CopyFiles
   34.42 -
   34.43 -;[XenAddResource_Inst.NT.Services]
   34.44 -;AddService=XenAddResource,,XenAddResource_Service 
   34.45 -
   34.46 -;[XenAddResource_Inst.NT.HW]
   34.47 -;AddReg = XenAddResource_Inst_HW_AddReg
   34.48 -
   34.49 -;[XenAddResource_Inst_HW_AddReg]
   34.50 -;HKR,,"LowerFilters",0x00010000,"xenaddresource"
   34.51 -
   34.52 -;[XenAddResource.CopyFiles]
   34.53 -;xenaddresource.sys
   34.54 -
   34.55 -;[XenAddResource_Service]
   34.56 -;DisplayName    = "Xen Resource Adder"
   34.57 -;ServiceType    = 1
   34.58 -;StartType      = 0
   34.59 -;ErrorControl   = 1
   34.60 -;LoadOrderGroup = System Bus Extender
   34.61 -;ServiceBinary  = %12%\xenaddresource.sys
   34.62 -;AddReg = XenAddResource_Service_AddReg
   34.63 -
   34.64 -;[XenAddResource.CopyFiles]
   34.65 -;xenaddresource.sys
   34.66 -
   34.67 -;[XenAddResource_Service_AddReg]
   34.68 -;HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
   34.69 -
   34.70  [SourceDisksFiles]
   34.71  xenvbd.sys=1
   34.72 -;xenaddresource.sys=1
   34.73  
   34.74  [SourceDisksNames.x86]
   34.75 -1 = %DISK_NAME%,,,\i386
   34.76 +1 = %DISK_NAME%,,,.\i386
   34.77  
   34.78  [SourceDisksNames.amd64]
   34.79 -1 = %DISK_NAME%,,,\amd64
   34.80 +1 = %DISK_NAME%,,,.\amd64
   34.81  
   34.82  [Strings]
   34.83  XenGplPv = "Xen GPL PV Driver Developers"
   34.84  XenVbd.SVCDESC = "Xen Block Device Driver"
   34.85  XenVbd.DRVDESC = "Xen Block Device Driver"
   34.86 -;XenAddResource.DRVDESC = "Xen Resource Adder"
   34.87  DISK_NAME = "Xen Block Device Driver Install Disk"