win-pvdrivers

changeset 272:909b775a891f wdm

Fixed a few bugs in shutdown handler. Drivers appear to be working now. Shutdown not so much yet...
author James Harper <james.harper@bendigoit.com.au>
date Fri May 16 23:56:57 2008 +1000 (2008-05-16)
parents da9b1e17fbc0
children 63920d09b07d
files ShutdownMon/Program.cs Xen.sln common.inc common/include/xen_public.h doc/INSTALLING.txt doc/README.txt target/install.bat xenhide/xenhide.c xennet/xennet.c xennet/xennet_oid.c xenpci/xenbus.c xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci_fdo.c xenpci/xenpci_pdo.c xenvbd/xenvbd.inx
line diff
     1.1 --- a/ShutdownMon/Program.cs	Thu May 15 00:25:25 2008 +1000
     1.2 +++ b/ShutdownMon/Program.cs	Fri May 16 23:56:57 2008 +1000
     1.3 @@ -112,6 +112,62 @@ 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 +        protected struct SP_DEVICE_INTERFACE_DATA
     1.9 +        {
    1.10 +            public UInt32 cbSize;
    1.11 +            public Guid InterfaceClassGuid;
    1.12 +            public UInt32 Flags;
    1.13 +            public IntPtr Reserved;
    1.14 +        };
    1.15 +
    1.16 +        [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
    1.17 +        private static extern IntPtr SetupDiGetClassDevsA(ref Guid ClassGuid, UInt32 Enumerator, IntPtr hwndParent, UInt32 Flags);
    1.18 +
    1.19 +        [DllImport("setupapi.dll", SetLastError = true)]
    1.20 +        private static extern Boolean SetupDiEnumDeviceInterfaces(
    1.21 +            IntPtr DeviceInfoSet,
    1.22 +            IntPtr DeviceInfoData,
    1.23 +            ref Guid InterfaceClassGuid,
    1.24 +            int MemberIndex,
    1.25 +            out SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);
    1.26 +
    1.27 +        [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
    1.28 +        private static extern Boolean SetupDiGetDeviceInterfaceDetail(
    1.29 +            IntPtr DeviceInfoSet,
    1.30 +            ref SP_DEVICE_INTERFACE_DATA DeviceIntefaceData,
    1.31 +            IntPtr DeviceInterfaceDetailData,
    1.32 +            UInt32 DeviceInterfacedetailDatasize,
    1.33 +            ref UInt32 DeviceInterfacedetaildataSize,
    1.34 +            IntPtr DeviceInfoData);
    1.35 +
    1.36 +        const int DIGCF_PRESENT = 0x00000002;
    1.37 +        const int DIGCF_DEVICEINTERFACE = 0x00000010;
    1.38 +
    1.39 +        private string GetXenInterfacePath()
    1.40 +        {
    1.41 +            Guid XenInterface = new Guid("{5c568ac5-9ddf-4fa5-a94a-39d67077819c}");
    1.42 +            IntPtr handle = SetupDiGetClassDevsA(ref XenInterface, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
    1.43 +            SP_DEVICE_INTERFACE_DATA sdid = new SP_DEVICE_INTERFACE_DATA();
    1.44 +
    1.45 +            sdid.cbSize = (UInt32)Marshal.SizeOf(sdid);
    1.46 +            sdid.InterfaceClassGuid = System.Guid.Empty;
    1.47 +            sdid.Flags = 0;
    1.48 +            sdid.Reserved = IntPtr.Zero;
    1.49 +
    1.50 +            if (!SetupDiEnumDeviceInterfaces(handle, IntPtr.Zero, ref XenInterface, 0, out sdid))
    1.51 +                return null;
    1.52 +            UInt32 buflen = 1024;
    1.53 +            IntPtr buf = Marshal.AllocHGlobal((int)buflen);
    1.54 +            Marshal.WriteInt32(buf, 4 + Marshal.SystemDefaultCharSize);
    1.55 +            bool success = SetupDiGetDeviceInterfaceDetail(handle, ref sdid, buf, buflen, ref buflen, IntPtr.Zero);
    1.56 +            if (!success)
    1.57 +                return null;
    1.58 +            string filename = Marshal.PtrToStringUni(new IntPtr(buf.ToInt64() + 4));
    1.59 +            Console.WriteLine("interface path = " + filename);
    1.60 +            // free stuff here
    1.61 +            return filename;
    1.62 +        }
    1.63  
    1.64          private static void DoExitWin(bool bForceAppsClosed, bool bRebootAfterShutdown)
    1.65          {
    1.66 @@ -269,7 +325,7 @@ namespace ShutdownMon
    1.67              SafeFileHandle handle;
    1.68              byte[] buf = new byte[128];
    1.69  
    1.70 -            handle = CreateFile(@"\\.\XenShutdown", FILE_GENERIC_READ, 0, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero);
    1.71 +            handle = CreateFile(GetXenInterfacePath(), FILE_GENERIC_READ, 0, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero);
    1.72              FileStream fs = new FileStream(handle, FileAccess.Read);
    1.73              StreamReader sr = new StreamReader(fs);
    1.74  
     2.1 --- a/Xen.sln	Thu May 15 00:25:25 2008 +1000
     2.2 +++ b/Xen.sln	Fri May 16 23:56:57 2008 +1000
     2.3 @@ -5,6 +5,8 @@ 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 @@ -17,6 +19,10 @@ 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	Thu May 15 00:25:25 2008 +1000
     3.2 +++ b/common.inc	Fri May 16 23:56:57 2008 +1000
     3.3 @@ -1,4 +1,4 @@
     3.4 -VERSION=0.8.9.45
     3.5 +VERSION=0.8.9.47
     3.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     3.7  KMDF_VERSION=1
     3.8  !IF $(_NT_TOOLS_VERSION) > 0x700
     4.1 --- a/common/include/xen_public.h	Thu May 15 00:25:25 2008 +1000
     4.2 +++ b/common/include/xen_public.h	Fri May 16 23:56:57 2008 +1000
     4.3 @@ -24,9 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fi
     4.4  //{5C568AC5-9DDF-4FA5-A94A-39D67077819C}
     4.5  DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
     4.6  
     4.7 -//{CD433FE7-954F-4D51-BE29-D8A38DFA1108}
     4.8 -DEFINE_GUID(GUID_XENHIDE_IFACE, 0xCD433FE7, 0x954F, 0x4D51, 0xBE, 0x29, 0xD8, 0xA3, 0x8D, 0xFA, 0x11, 0x08);
     4.9 -
    4.10  typedef PHYSICAL_ADDRESS
    4.11  (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
    4.12  
     5.1 --- a/doc/INSTALLING.txt	Thu May 15 00:25:25 2008 +1000
     5.2 +++ b/doc/INSTALLING.txt	Fri May 16 23:56:57 2008 +1000
     5.3 @@ -1,86 +1,1 @@
     5.4 -Please follow the steps here exactly. If you don't, you may be left with 
     5.5 -an unbootable machine (although 'Last known good configuration' should 
     5.6 -make it bootable again). 
     5.7 -
     5.8 -0a. If you are installing over a previous version where you installed the xenhide
     5.9 -driver over the top of the windows PCI driver, make sure you install the system
    5.10 -PCI driver back again. doing an Update Driver on xenhide and just clicking next
    5.11 -should do this. It's probably a good idea to also uninstall all the xen drivers
    5.12 -too before upgrading... ymmv.
    5.13 -
    5.14 -0b. If you are upgrading from a more recent version than the above, do the
    5.15 -following (until I get upgrading definitely working properly):
    5.16 -    i. Boot into non-GPLPV mode
    5.17 -    ii. Remove C:\windows\system32\drivers\xen*.sys (*** EXCEPT xenhide.sys ***)
    5.18 -    iii. Reboot, back into non-GPLPV mode again
    5.19 -
    5.20 -1. Copy the driver files that you built by following the BUILDING.txt 
    5.21 -steps (or that you got from a binary dist), so that on your testing 
    5.22 -machine the tree looks like this: 
    5.23 -
    5.24 -Xen\install.bat
    5.25 -Xen\ShutdownMon.exe
    5.26 -Xen\<os>\xenenum.inf
    5.27 -Xen\<os>\xennet.inf
    5.28 -Xen\<os>\xenpci.inf
    5.29 -Xen\<os>\xenscsi.inf
    5.30 -Xen\<os>\xenstub.inf
    5.31 -Xen\<os>\xenvbd.inf
    5.32 -Xen\<os>\DPInst.exe
    5.33 -Xen\<os>\<arch>\xenaddresource.sys
    5.34 -Xen\<os>\<arch>\xenenum.sys 
    5.35 -Xen\<os>\<arch>\xenhide.sys 
    5.36 -Xen\<os>\<arch>\xennet.sys
    5.37 -Xen\<os>\<arch>\xenpci.sys
    5.38 -Xen\<os>\<arch>\xenscsi.sys
    5.39 -Xen\<os>\<arch>\xenstub.sys
    5.40 -Xen\<os>\<arch>\xenvbd.sys 
    5.41 -Xen\<os>\<arch>\WdfCoInstaller01005.dll
    5.42 -(If you have compiled yourself, you'll need to copy
    5.43 -WdfCoInstaller01007.dll and DPInst.exe from the redist folder in the DDK) (<os> is
    5.44 -winxp for XP, or winnet for 2K3. <arch> is i386 or amd64)
    5.45 -
    5.46 -2. run 'install.bat' in the Xen directory
    5.47 -
    5.48 -3. Click Next and Ok when prompted. The drivers are unsigned so be prepared to do
    5.49 -this more than once.
    5.50 -
    5.51 -4. Reboot when prompted to ensure that your computer still boots without any
    5.52 -issues. You'll now have two ethernet interfaces, which may or may not cause
    5.53 -problems.
    5.54 -
    5.55 -5. edit your boot.ini to look something like this: 
    5.56 -
    5.57 -"
    5.58 -[boot loader]
    5.59 -timeout=30 
    5.60 -default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
    5.61 -
    5.62 -[operating systems] 
    5.63 -multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows Server 2003, Enterprise" /noexecute=optout /fastdetect 
    5.64 -multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows Server 2003, Enterprise, GPLPV" /noexecute=optout /fastdetect /gplpv
    5.65 -" 
    5.66 -
    5.67 -17. The main thing in the above step is that you have a line with /gplpv 
    5.68 -on the end. This tells the PV device (vbd, vif) drivers to activate,
    5.69 -otherwise they will pretty much sit silent. At the moment, vif always
    5.70 -activates.
    5.71 -
    5.72 -18. Reboot and select the /gplpv entry. If it doesn't work then email me 
    5.73 -(james.harper@bendigoit.com.au) with some details and i'll see what I can
    5.74 -do. 
    5.75 -
    5.76 -Without the /gplpv option specified, the xenvbd driver will only pick up 
    5.77 -on devices you have added since boot, so you can still test it without 
    5.78 -specifying /gplpv and doing something like the following in Dom0: 
    5.79 -
    5.80 -"
    5.81 -xm block-attach mywindowsdomain phy:/dev/someblockdevice /dev/hdc w
    5.82 -" 
    5.83 -
    5.84 -For physical devices only, you need to specify the 'phy:' in your xen
    5.85 -config file and in the block-attach line otherwise the backend doesn't
    5.86 -seem to publish the block and sector sizes correctly.
    5.87 -
    5.88 -If you do the block-attach, then your block device should show up under 
    5.89 -windows, and you can partition it etc. 
    5.90 +see http://www.meadowcourt.org/james/xen/gplpv.htm for details
    5.91 \ No newline at end of file
     6.1 --- a/doc/README.txt	Thu May 15 00:25:25 2008 +1000
     6.2 +++ b/doc/README.txt	Fri May 16 23:56:57 2008 +1000
     6.3 @@ -1,25 +1,1 @@
     6.4 -This is my GPL'd Xen HVM PV drivers for Windows. You can contact me at 
     6.5 -james.harper@bendigoit.com.au, or on the xen-devel mailing list. 
     6.6 -
     6.7 -Block and Network drivers are supported, and a service is supplied which
     6.8 -will respond to 'xm shutdown' and 'xm reboot' commands.
     6.9 -
    6.10 -My test environment is Xen 3.1.1 (64 bit Hypervisor) and Windows 2003 
    6.11 -sp2 (32, 32p, 64). YMMV.
    6.12 -
    6.13 -You can get the source using Mercurial at 
    6.14 -http://xenbits.xensource.com/ext/win-pvdrivers.hg. 
    6.15 -
    6.16 -Please do not in any way consider it ready for production use. 
    6.17 -Definitely do not use them on a production DomU. While I have never seen 
    6.18 -them cause a problem with the hypervisor or Dom0, I would also be very 
    6.19 -wary of using them on a production physical machine too.
    6.20 -
    6.21 -It now seems fairly sane, I'm using it on a few low-risk production
    6.22 -machines without any problems.
    6.23 -
    6.24 -See BUILDING.txt for instructions on building the drivers. 
    6.25 -
    6.26 -See INSTALLING.txt for instructions on installing the drivers. 
    6.27 -
    6.28 -See TODO.txt for known problems and future plans. 
    6.29 +see http://www.meadowcourt.org/james/xen/gplpv.htm for details
    6.30 \ No newline at end of file
     7.1 --- a/target/install.bat	Thu May 15 00:25:25 2008 +1000
     7.2 +++ b/target/install.bat	Fri May 16 23:56:57 2008 +1000
     7.3 @@ -19,7 +19,6 @@ goto exit
     7.4  echo Windows XP Detected... Installing...
     7.5  shutdownmon -i
     7.6  cd winxp
     7.7 -copy /y ..\common\i386\wdfcoinstaller* i386 >nul
     7.8  copy /y ..\common\i386\dpinst.exe . >nul
     7.9  dpinst.exe /LM /SA
    7.10  cd ..
    7.11 @@ -30,7 +29,6 @@ goto exit
    7.12  echo Windows 2000 Detected... Installing...
    7.13  shutdownmon -i
    7.14  cd win2k
    7.15 -copy /y ..\common\i386\wdfcoinstaller* i386 >nul
    7.16  copy /y ..\common\i386\dpinst.exe . >nul
    7.17  dpinst.exe /LM /SA
    7.18  cd ..
    7.19 @@ -43,7 +41,6 @@ if %PROCESSOR_ARCHITECTURE% == AMD64 got
    7.20  echo Windows 2003 (i386) Detected... Installing...
    7.21  shutdownmon -i
    7.22  cd winnet
    7.23 -copy /y ..\common\i386\wdfcoinstaller* i386 >nul
    7.24  copy /y ..\common\i386\dpinst.exe . >nul
    7.25  dpinst.exe /LM /SA
    7.26  cd ..
    7.27 @@ -54,7 +51,6 @@ goto exit
    7.28  echo Windows 2003 (amd64) Detected... Installing...
    7.29  shutdownmon -i
    7.30  cd winnet
    7.31 -copy /y ..\common\amd64\wdfcoinstaller* amd64 >nul
    7.32  copy /y ..\common\amd64\dpinst.exe . >nul
    7.33  dpinst.exe /LM /SA
    7.34  cd ..
    7.35 @@ -66,7 +62,6 @@ if %PROCESSOR_ARCHITECTURE% == AMD64 got
    7.36  echo Windows Vista/2008 (i386) Detected... Installing...
    7.37  shutdownmon -i
    7.38  cd winlh
    7.39 -copy /y ..\common\i386\wdfcoinstaller* i386 >nul
    7.40  copy /y ..\common\i386\dpinst.exe . >nul
    7.41  dpinst.exe /LM /SA
    7.42  cd ..
    7.43 @@ -77,7 +72,6 @@ goto exit
    7.44  echo Windows Vista/2008 (amd64) Detected... Installing...
    7.45  shutdownmon -i
    7.46  cd winlh
    7.47 -copy /y ..\common\amd64\wdfcoinstaller* amd64 >nul
    7.48  copy /y ..\common\amd64\dpinst.exe . >nul
    7.49  dpinst.exe /LM /SA
    7.50  cd ..
    7.51 @@ -85,4 +79,4 @@ echo Done
    7.52  goto exit
    7.53  
    7.54  pause
    7.55 -:exit
    7.56 \ No newline at end of file
    7.57 +:exit
     8.1 --- a/xenhide/xenhide.c	Thu May 15 00:25:25 2008 +1000
     8.2 +++ b/xenhide/xenhide.c	Fri May 16 23:56:57 2008 +1000
     8.3 @@ -219,29 +219,6 @@ XenHide_AddDevice(
     8.4  
     8.5    //INITIALIZE_PNP_STATE(DeviceExtension);
     8.6  
     8.7 -#if 0
     8.8 -  if (AutoEnumerate)
     8.9 -  {
    8.10 -    status = IoRegisterDeviceInterface(PhysicalDeviceObject, (LPGUID)&GUID_XENHIDE_IFACE, NULL, &DeviceExtension->InterfaceName);
    8.11 -    if (!NT_SUCCESS(status))
    8.12 -    {
    8.13 -      KdPrint((__DRIVER_NAME "     IoRegisterDeviceInterface failed 0x%08x\n", status));
    8.14 -      return status;
    8.15 -    }
    8.16 -//    KdPrint((__DRIVER_NAME "     IoRegisterDeviceInterface complete, SymbolicLinkName = %wZ\n", &DeviceExtension->InterfaceName));
    8.17 -    status = IoSetDeviceInterfaceState(&DeviceExtension->InterfaceName, TRUE);
    8.18 -    if (!NT_SUCCESS(status))
    8.19 -    {
    8.20 -      KdPrint((__DRIVER_NAME "     IoSetDeviceInterfaceState failed 0x%08x\n", status));
    8.21 -      return status;
    8.22 -    }
    8.23 -  }
    8.24 -  else
    8.25 -  {
    8.26 -//    KdPrint((__DRIVER_NAME "     Not registering Interface\n"));
    8.27 -  }
    8.28 -#endif
    8.29 -
    8.30    deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
    8.31  
    8.32    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    8.33 @@ -250,98 +227,6 @@ XenHide_AddDevice(
    8.34  }
    8.35  
    8.36  static NTSTATUS
    8.37 -XenHide_IoCompletion(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
    8.38 -{
    8.39 -  ULONG i, j;
    8.40 -  PDEVICE_RELATIONS Relations;
    8.41 -  WCHAR Buffer[256];
    8.42 -  PWCHAR Ptr;
    8.43 -  ULONG Length;
    8.44 -  size_t StrLen;
    8.45 -  int Match;
    8.46 -  int Offset = 0;
    8.47 -  int FoundIde = 0;
    8.48 -  PXENHIDE_DEVICE_DATA DeviceExtension = (PXENHIDE_DEVICE_DATA)Context;
    8.49 -
    8.50 -  UNREFERENCED_PARAMETER(DeviceObject);
    8.51 -  UNREFERENCED_PARAMETER(Context);
    8.52 -
    8.53 -//  KdPrint((__DRIVER_NAME " --> IoCompletion\n"));
    8.54 -
    8.55 -  Relations = (PDEVICE_RELATIONS)Irp->IoStatus.Information;
    8.56 -
    8.57 -  switch (DeviceExtension->InternalState)
    8.58 -  {
    8.59 -  case 0:
    8.60 -    DeviceExtension->InternalState = 1;
    8.61 -    for (i = 0; i < Relations->Count; i++)
    8.62 -    {
    8.63 -      KdPrint((__DRIVER_NAME "     i = %d, DeviceType = 0x%08x\n", i, Relations->Objects[i]->DeviceType));
    8.64 -    }
    8.65 -    break;
    8.66 -  case 1:
    8.67 -    DeviceExtension->InternalState = 2;
    8.68 -    if (Relations != NULL)
    8.69 -    {
    8.70 -      for (i = 0; i < Relations->Count; i++)
    8.71 -      {
    8.72 -        if (Offset != 0)
    8.73 -          Relations->Objects[i - Offset] = Relations->Objects[i];
    8.74 -    
    8.75 -        Match = 0;
    8.76 -        for (j = 0; j < 2 && !Match; j++)
    8.77 -        {
    8.78 -          Length = sizeof(Buffer);
    8.79 -          if (j == 0)
    8.80 -            IoGetDeviceProperty(Relations->Objects[i - Offset], DevicePropertyCompatibleIDs, Length, Buffer, &Length);
    8.81 -          else
    8.82 -            IoGetDeviceProperty(Relations->Objects[i - Offset], DevicePropertyHardwareID, Length, Buffer, &Length);
    8.83 -           StrLen = 0;
    8.84 -          for (Ptr = Buffer; *Ptr != 0; Ptr += StrLen + 1)
    8.85 -          {
    8.86 -            // Qemu IDE
    8.87 -            if (wcscmp(Ptr, L"PCI\\VEN_8086&DEV_7010") == 0) {
    8.88 -              Match = 1;
    8.89 -              FoundIde = 1;
    8.90 -              break;
    8.91 -            }
    8.92 -#if 0
    8.93 -            // Qemu Network
    8.94 -            if (XenHide_StringMatches(Ptr, L"PCI\\VEN_10EC&DEV_8139")) {
    8.95 -              Match = 1;
    8.96 -              break;
    8.97 -            }
    8.98 -#endif
    8.99 -            RtlStringCchLengthW(Ptr, Length, &StrLen);
   8.100 -          }
   8.101 -        }
   8.102 -        if (Match)
   8.103 -        {
   8.104 -          KdPrint((__DRIVER_NAME "     Match at i = %d\n", i));
   8.105 -          Offset++;
   8.106 -        }
   8.107 -      }
   8.108 -      if (!FoundIde)
   8.109 -      {
   8.110 -        /*
   8.111 -        We _must_ not let windows continue if the PV drivers have been
   8.112 -        activated and we haven't managed to find and hide the IDE device.
   8.113 -        Throwing a BSoD is the only option at this point.
   8.114 -        */
   8.115 -        KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000002, 0x00000000, 0x00000000, 0x00000000);
   8.116 -      }
   8.117 -      Relations->Count -= Offset;
   8.118 -    }
   8.119 -    break;
   8.120 -  default:
   8.121 -    break;
   8.122 -  }
   8.123 -//  KdPrint((__DRIVER_NAME " <-- IoCompletion\n"));
   8.124 -
   8.125 -  return Irp->IoStatus.Status;
   8.126 -}
   8.127 -
   8.128 -static NTSTATUS
   8.129  XenHide_Pass(PDEVICE_OBJECT DeviceObject, PIRP Irp)
   8.130  {
   8.131    PXENHIDE_DEVICE_DATA DeviceExtension = (PXENHIDE_DEVICE_DATA)DeviceObject->DeviceExtension;
   8.132 @@ -369,22 +254,6 @@ XenHide_Pnp(PDEVICE_OBJECT device_object
   8.133      status = irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
   8.134      IoCompleteRequest(irp, IO_NO_INCREMENT);
   8.135      break;
   8.136 -#if 0
   8.137 -  case IRP_MN_QUERY_DEVICE_RELATIONS:
   8.138 -//    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS\n"));
   8.139 -    switch (Stack->Parameters.QueryDeviceRelations.Type)
   8.140 -    {
   8.141 -    case BusRelations:
   8.142 -//      KdPrint((__DRIVER_NAME "       BusRelations\n"));
   8.143 -      IoCopyCurrentIrpStackLocationToNext(Irp);
   8.144 -      IoSetCompletionRoutine(Irp, XenHide_IoCompletion, DeviceExtension, TRUE, TRUE, TRUE);
   8.145 -      break;
   8.146 -    default:
   8.147 -      IoSkipCurrentIrpStackLocation(Irp);
   8.148 -      break;  
   8.149 -    }
   8.150 -    break;
   8.151 -#endif
   8.152    default:
   8.153      IoSkipCurrentIrpStackLocation(irp);
   8.154      status = IoCallDriver(xhdd->NextLowerDevice, irp);
     9.1 --- a/xennet/xennet.c	Thu May 15 00:25:25 2008 +1000
     9.2 +++ b/xennet/xennet.c	Fri May 16 23:56:57 2008 +1000
     9.3 @@ -129,8 +129,8 @@ XenNet_Init(
     9.4    ULONG length;
     9.5    PNDIS_RESOURCE_LIST nrl;
     9.6    PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
     9.7 -  KIRQL irq_level;
     9.8 -  ULONG irq_vector;
     9.9 +  KIRQL irq_level = 0;
    9.10 +  ULONG irq_vector = 0;
    9.11    UCHAR type;
    9.12    PUCHAR ptr;
    9.13    PCHAR setting, value;
    9.14 @@ -452,7 +452,7 @@ XenNet_Pnp(PDEVICE_OBJECT device_object,
    9.15    //NDIS_STRING config_param_name;
    9.16    //PNDIS_CONFIGURATION_PARAMETER config_param;
    9.17  
    9.18 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    9.19 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    9.20  
    9.21    stack = IoGetCurrentIrpStackLocation(irp);
    9.22  
    9.23 @@ -591,7 +591,7 @@ XenNet_Pnp(PDEVICE_OBJECT device_object,
    9.24      break;
    9.25    }
    9.26  
    9.27 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
    9.28 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
    9.29  
    9.30    return status;
    9.31  }
    10.1 --- a/xennet/xennet_oid.c	Thu May 15 00:25:25 2008 +1000
    10.2 +++ b/xennet/xennet_oid.c	Fri May 16 23:56:57 2008 +1000
    10.3 @@ -396,7 +396,7 @@ XenNet_SetInformation(
    10.4    PNDIS_TASK_TCP_LARGE_SEND nttls;
    10.5    int offset;
    10.6  
    10.7 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    10.8 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    10.9  
   10.10    UNREFERENCED_PARAMETER(MiniportAdapterContext);
   10.11    UNREFERENCED_PARAMETER(InformationBufferLength);
   10.12 @@ -587,6 +587,6 @@ XenNet_SetInformation(
   10.13        status = NDIS_STATUS_NOT_SUPPORTED;
   10.14        break;
   10.15    }
   10.16 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   10.17 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   10.18    return status;
   10.19  }
    11.1 --- a/xenpci/xenbus.c	Thu May 15 00:25:25 2008 +1000
    11.2 +++ b/xenpci/xenbus.c	Fri May 16 23:56:57 2008 +1000
    11.3 @@ -244,6 +244,8 @@ XenBus_Read(
    11.4  
    11.5  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    11.6  
    11.7 +  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
    11.8 +
    11.9    rep = xenbus_msg_reply(xpdd, XS_READ, xbt, req, ARRAY_SIZE(req));
   11.10    msg = errmsg(rep);
   11.11    if (msg) {
   11.12 @@ -280,6 +282,8 @@ XenBus_Write(
   11.13  
   11.14  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   11.15  
   11.16 +  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
   11.17 +
   11.18    rep = xenbus_msg_reply(xpdd, XS_WRITE, xbt, req, ARRAY_SIZE(req));
   11.19    msg = errmsg(rep);
   11.20    if (msg)
   11.21 @@ -301,6 +305,8 @@ XenBus_Init(PXENPCI_DEVICE_DATA xpdd)
   11.22      
   11.23  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   11.24  
   11.25 +  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
   11.26 +
   11.27    KeInitializeSpinLock(&xpdd->WatchLock);
   11.28  
   11.29    xpdd->xen_store_evtchn = (evtchn_port_t)hvm_get_parameter(xpdd, HVM_PARAM_STORE_EVTCHN);
   11.30 @@ -369,6 +375,8 @@ XenBus_Close(PXENPCI_DEVICE_DATA xpdd)
   11.31    //KWAIT_BLOCK WaitBlockArray[2];
   11.32    PVOID WaitArray[2];
   11.33  
   11.34 +  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
   11.35 +
   11.36    xpdd->XenBus_ShuttingDown = TRUE;
   11.37  
   11.38    KeSetEvent(&xpdd->XenBus_ReadThreadEvent, 1, FALSE);
   11.39 @@ -403,6 +411,8 @@ XenBus_List(
   11.40  
   11.41  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   11.42  
   11.43 +  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
   11.44 +
   11.45    repmsg = xenbus_msg_reply(xpdd, XS_DIRECTORY, xbt, req, ARRAY_SIZE(req));
   11.46    msg = errmsg(repmsg);
   11.47    if (msg)
   11.48 @@ -574,6 +584,8 @@ XenBus_AddWatch(
   11.49  
   11.50  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   11.51  
   11.52 +  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
   11.53 +
   11.54    ASSERT(strlen(Path) < ARRAY_SIZE(w_entry->Path));
   11.55  
   11.56    KeAcquireSpinLock(&xpdd->WatchLock, &OldIrql);
   11.57 @@ -640,6 +652,7 @@ XenBus_RemWatch(
   11.58    KIRQL OldIrql;
   11.59  
   11.60  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   11.61 +  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
   11.62  
   11.63    KeAcquireSpinLock(&xpdd->WatchLock, &OldIrql);
   11.64  
   11.65 @@ -713,6 +726,7 @@ XenBus_StartTransaction(PVOID Context, x
   11.66    char *err;
   11.67  
   11.68  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   11.69 +  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
   11.70  
   11.71    rep = xenbus_msg_reply(xpdd, XS_TRANSACTION_START, 0, &req, 1);
   11.72    err = errmsg(rep);
   11.73 @@ -793,6 +807,7 @@ XenBus_Printf(
   11.74    char *retval;
   11.75  
   11.76  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   11.77 +  ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
   11.78  
   11.79    va_start(ap, fmt);
   11.80    RtlStringCbVPrintfA(buf, ARRAY_SIZE(buf), fmt, ap);
    12.1 --- a/xenpci/xenpci.c	Thu May 15 00:25:25 2008 +1000
    12.2 +++ b/xenpci/xenpci.c	Fri May 16 23:56:57 2008 +1000
    12.3 @@ -61,6 +61,62 @@ XenPci_Power(PDEVICE_OBJECT device_objec
    12.4  }
    12.5  
    12.6  static NTSTATUS
    12.7 +XenPci_Irp_Create(PDEVICE_OBJECT device_object, PIRP irp)
    12.8 +{
    12.9 +  NTSTATUS status;
   12.10 +  PXENPCI_COMMON common = device_object->DeviceExtension;
   12.11 +  
   12.12 +  if (common->lower_do)
   12.13 +    status = XenPci_Irp_Create_Fdo(device_object, irp);
   12.14 +  else
   12.15 +    status = XenPci_Irp_Create_Pdo(device_object, irp);  
   12.16 +
   12.17 +  return status;
   12.18 +}
   12.19 +
   12.20 +static NTSTATUS
   12.21 +XenPci_Irp_Close(PDEVICE_OBJECT device_object, PIRP irp)
   12.22 +{
   12.23 +  NTSTATUS status;
   12.24 +  PXENPCI_COMMON common = device_object->DeviceExtension;
   12.25 +  
   12.26 +  if (common->lower_do)
   12.27 +    status = XenPci_Irp_Close_Fdo(device_object, irp);
   12.28 +  else
   12.29 +    status = XenPci_Irp_Close_Pdo(device_object, irp);  
   12.30 +
   12.31 +  return status;
   12.32 +}
   12.33 +
   12.34 +static NTSTATUS
   12.35 +XenPci_Irp_Read(PDEVICE_OBJECT device_object, PIRP irp)
   12.36 +{
   12.37 +  NTSTATUS status;
   12.38 +  PXENPCI_COMMON common = device_object->DeviceExtension;
   12.39 +  
   12.40 +  if (common->lower_do)
   12.41 +    status = XenPci_Irp_Read_Fdo(device_object, irp);
   12.42 +  else
   12.43 +    status = XenPci_Irp_Read_Pdo(device_object, irp);  
   12.44 +
   12.45 +  return status;
   12.46 +}
   12.47 +
   12.48 +static NTSTATUS
   12.49 +XenPci_Irp_Cleanup(PDEVICE_OBJECT device_object, PIRP irp)
   12.50 +{
   12.51 +  NTSTATUS status;
   12.52 +  PXENPCI_COMMON common = device_object->DeviceExtension;
   12.53 +  
   12.54 +  if (common->lower_do)
   12.55 +    status = XenPci_Irp_Cleanup_Fdo(device_object, irp);
   12.56 +  else
   12.57 +    status = XenPci_Irp_Cleanup_Pdo(device_object, irp);  
   12.58 +
   12.59 +  return status;
   12.60 +}
   12.61 +
   12.62 +static NTSTATUS
   12.63  XenPci_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
   12.64  {
   12.65    NTSTATUS status;
   12.66 @@ -88,10 +144,16 @@ XenPci_AddDevice(PDRIVER_OBJECT DriverOb
   12.67      return status;
   12.68    }
   12.69  
   12.70 +  fdo->Flags |= DO_BUFFERED_IO;
   12.71 +  
   12.72    xpdd = (PXENPCI_DEVICE_DATA)fdo->DeviceExtension;
   12.73  
   12.74    RtlZeroMemory(xpdd, sizeof(XENPCI_DEVICE_DATA));
   12.75  
   12.76 +  xpdd->shutdown_prod = 0;
   12.77 +  xpdd->shutdown_cons = 0;
   12.78 +  KeInitializeSpinLock(&xpdd->shutdown_ring_lock);
   12.79 +
   12.80    xpdd->common.fdo = fdo;
   12.81    xpdd->common.pdo = PhysicalDeviceObject;
   12.82    xpdd->common.lower_do = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
   12.83 @@ -116,117 +178,19 @@ XenPci_AddDevice(PDRIVER_OBJECT DriverOb
   12.84      KdPrint((__DRIVER_NAME "     IoRegisterDeviceInterface succeeded - %wZ\n", &xpdd->interface_name));
   12.85    }
   12.86    
   12.87 -
   12.88    fdo->Flags &= ~DO_DEVICE_INITIALIZING;
   12.89  
   12.90  #if 0
   12.91 -  WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_BUS_EXTENDER);
   12.92 -  WDF_CHILD_LIST_CONFIG_INIT(&config, sizeof(XENPCI_IDENTIFICATION_DESCRIPTION), XenPCI_ChildListCreateDevice);
   12.93 -  WdfFdoInitSetDefaultChildListConfig(DeviceInit, &config, WDF_NO_OBJECT_ATTRIBUTES);
   12.94 -
   12.95 -  WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
   12.96 -  pnpPowerCallbacks.EvtDevicePrepareHardware = XenPCI_PrepareHardware;
   12.97 -  pnpPowerCallbacks.EvtDeviceReleaseHardware = XenPCI_ReleaseHardware;
   12.98 -  pnpPowerCallbacks.EvtDeviceD0Entry = XenPCI_D0Entry;
   12.99 -  pnpPowerCallbacks.EvtDeviceD0EntryPostInterruptsEnabled
  12.100 -    = XenPCI_D0EntryPostInterruptsEnabled;
  12.101 -  pnpPowerCallbacks.EvtDeviceD0ExitPreInterruptsDisabled
  12.102 -    = XenPCI_D0ExitPreInterruptsDisabled;
  12.103 -  pnpPowerCallbacks.EvtDeviceD0Exit = XenPCI_D0Exit;
  12.104 -  WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);
  12.105 -
  12.106 -  WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoBuffered);
  12.107 -
  12.108 -  Status = WdfDeviceInitAssignName(DeviceInit, &DeviceName);
  12.109 -  if (!NT_SUCCESS(Status))
  12.110 -  {
  12.111 -    KdPrint((__DRIVER_NAME "     WdfDeviceInitAssignName failed 0x%08x\n", Status));
  12.112 -    return Status;
  12.113 -  }
  12.114 -
  12.115 -  /*initialize storage for the device context*/
  12.116 -  WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, XENPCI_DEVICE_DATA);
  12.117 -
  12.118 -  /*create a device instance.*/
  12.119 -  Status = WdfDeviceCreate(&DeviceInit, &attributes, &Device);  
  12.120 -  if(!NT_SUCCESS(Status))
  12.121 -  {
  12.122 -    KdPrint((__DRIVER_NAME "     WdfDeviceCreate failed with Status 0x%08x\n", Status));
  12.123 -    return Status;
  12.124 -  }
  12.125 -  xpdd = GetDeviceData(Device);
  12.126 -  xpdd->Device = Device;
  12.127 -
  12.128    WdfDeviceSetSpecialFileSupport(Device, WdfSpecialFilePaging, TRUE);
  12.129    WdfDeviceSetSpecialFileSupport(Device, WdfSpecialFileHibernation, TRUE);
  12.130    WdfDeviceSetSpecialFileSupport(Device, WdfSpecialFileDump, TRUE);
  12.131  
  12.132 -  Status = IoGetDeviceInterfaces(&GUID_XENHIDE_IFACE, NULL, 0, &InterfaceList);
  12.133 -  if (!NT_SUCCESS(Status) || InterfaceList == NULL || *InterfaceList == 0)
  12.134 -  {
  12.135 -    AutoEnumerate = FALSE;
  12.136 -    KdPrint((__DRIVER_NAME "     XenHide not loaded or GPLPV not specified\n", Status));
  12.137 -  }
  12.138 -  else
  12.139 -  {
  12.140 -    AutoEnumerate = TRUE;
  12.141 -    KdPrint((__DRIVER_NAME "     XenHide loaded and GPLPV specified\n", Status));
  12.142 -  }
  12.143 -
  12.144  #if (NTDDI_VERSION >= NTDDI_WS03SP1)
  12.145    KeInitializeGuardedMutex(&xpdd->WatchHandlerMutex);
  12.146  #endif
  12.147    busInfo.BusTypeGuid = GUID_XENPCI_DEVCLASS;
  12.148    busInfo.LegacyBusType = Internal;
  12.149    busInfo.BusNumber = 0;
  12.150 -
  12.151 -  WdfDeviceSetBusInformationForChildren(Device, &busInfo);
  12.152 -
  12.153 -  WDF_INTERRUPT_CONFIG_INIT(&InterruptConfig, EvtChn_Interrupt, NULL);
  12.154 -  InterruptConfig.EvtInterruptEnable = XenPCI_InterruptEnable;
  12.155 -  InterruptConfig.EvtInterruptDisable = XenPCI_InterruptDisable;
  12.156 -  Status = WdfInterruptCreate(Device, &InterruptConfig, WDF_NO_OBJECT_ATTRIBUTES, &xpdd->XenInterrupt);
  12.157 -  if (!NT_SUCCESS (Status))
  12.158 -  {
  12.159 -    KdPrint((__DRIVER_NAME "     WdfInterruptCreate failed 0x%08x\n", Status));
  12.160 -    return Status;
  12.161 -  }
  12.162 -
  12.163 -  Status = WdfDeviceCreateDeviceInterface(Device, (LPGUID)&GUID_XEN_IFACE, NULL);
  12.164 -  if (!NT_SUCCESS(Status))
  12.165 -  {
  12.166 -    KdPrint((__DRIVER_NAME "     WdfDeviceCreateDeviceInterface failed 0x%08x\n", Status));
  12.167 -    return Status;
  12.168 -  }
  12.169 -  WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&IoQConfig, WdfIoQueueDispatchSequential);
  12.170 -  IoQConfig.EvtIoDefault = XenPCI_IoDefault;
  12.171 -
  12.172 -  Status = WdfIoQueueCreate(Device, &IoQConfig, WDF_NO_OBJECT_ATTRIBUTES, NULL);
  12.173 -  if (!NT_SUCCESS(Status))
  12.174 -  {
  12.175 -    KdPrint((__DRIVER_NAME "     WdfIoQueueCreate failed 0x%08x\n", Status));
  12.176 -    return Status;
  12.177 -  }
  12.178 -
  12.179 -  WDF_IO_QUEUE_CONFIG_INIT(&IoQConfig, WdfIoQueueDispatchSequential);
  12.180 -  IoQConfig.EvtIoRead = XenPCI_IoRead;
  12.181 -
  12.182 -  Status = WdfIoQueueCreate(Device, &IoQConfig, WDF_NO_OBJECT_ATTRIBUTES, &ReadQueue);
  12.183 -  if (!NT_SUCCESS(Status))
  12.184 -  {
  12.185 -    KdPrint((__DRIVER_NAME "     WdfIoQueueCreate (ReadQueue) failed 0x%08x\n", Status));
  12.186 -    return Status;
  12.187 -  }
  12.188 -
  12.189 -  WdfIoQueueStopSynchronously(ReadQueue);
  12.190 -  WdfDeviceConfigureRequestDispatching(Device, ReadQueue, WdfRequestTypeRead);
  12.191 -
  12.192 -  Status = WdfDeviceCreateSymbolicLink(Device, &SymbolicName);
  12.193 -  if (!NT_SUCCESS(Status))
  12.194 -  {
  12.195 -    KdPrint((__DRIVER_NAME "     WdfDeviceCreateSymbolicLink failed 0x%08x\n", Status));
  12.196 -    return Status;
  12.197 -  }
  12.198  #endif
  12.199  
  12.200    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  12.201 @@ -248,11 +212,11 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  12.202    DriverObject->DriverExtension->AddDevice = XenPci_AddDevice;
  12.203    DriverObject->MajorFunction[IRP_MJ_PNP] = XenPci_Pnp;
  12.204    DriverObject->MajorFunction[IRP_MJ_POWER] = XenPci_Power;
  12.205 -  DriverObject->MajorFunction[IRP_MJ_CREATE] = NULL; //XenPci_Dummy;
  12.206 -  DriverObject->MajorFunction[IRP_MJ_CLOSE] = NULL; //XenPci_Dummy;
  12.207 -  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = NULL; //XenPci_Dummy;
  12.208 +  DriverObject->MajorFunction[IRP_MJ_CREATE] = XenPci_Irp_Create;
  12.209 +  DriverObject->MajorFunction[IRP_MJ_CLOSE] = XenPci_Irp_Close;
  12.210 +  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = XenPci_Irp_Cleanup;
  12.211    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NULL; //XenPci_Dummy;
  12.212 -  DriverObject->MajorFunction[IRP_MJ_READ] = NULL; //XenPci_Dummy;
  12.213 +  DriverObject->MajorFunction[IRP_MJ_READ] = XenPci_Irp_Read;
  12.214    DriverObject->MajorFunction[IRP_MJ_WRITE] = NULL; //XenPci_Dummy;
  12.215    DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = NULL; //XenPci_Dummy;
  12.216  
    13.1 --- a/xenpci/xenpci.h	Thu May 15 00:25:25 2008 +1000
    13.2 +++ b/xenpci/xenpci.h	Fri May 16 23:56:57 2008 +1000
    13.3 @@ -113,6 +113,8 @@ typedef struct
    13.4    PDEVICE_OBJECT lower_do;
    13.5  } XENPCI_COMMON, *PXENPCI_COMMON;
    13.6  
    13.7 +#define SHUTDOWN_RING_SIZE 128
    13.8 +
    13.9  typedef struct {  
   13.10    XENPCI_COMMON common;
   13.11    
   13.12 @@ -168,6 +170,14 @@ typedef struct {
   13.13    int suspending;
   13.14    
   13.15    UNICODE_STRING interface_name;
   13.16 +  BOOLEAN interface_open;
   13.17 +  
   13.18 +  KSPIN_LOCK shutdown_ring_lock;
   13.19 +  CHAR shutdown_ring[SHUTDOWN_RING_SIZE];
   13.20 +  ULONG shutdown_prod;
   13.21 +  ULONG shutdown_cons;
   13.22 +  ULONG shutdown_start; /* the start of the most recent message on the ring */
   13.23 +  PIRP shutdown_irp;
   13.24  } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
   13.25  
   13.26  typedef struct {  
   13.27 @@ -240,13 +250,29 @@ NTSTATUS
   13.28  XenPci_Dummy_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.29  NTSTATUS
   13.30  XenPci_Pnp_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.31 +NTSTATUS
   13.32 +XenPci_Irp_Create_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.33 +NTSTATUS
   13.34 +XenPci_Irp_Close_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.35 +NTSTATUS
   13.36 +XenPci_Irp_Read_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.37 +NTSTATUS
   13.38 +XenPci_Irp_Cleanup_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.39  
   13.40  NTSTATUS
   13.41  XenPci_Power_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.42 -NTSTATUS
   13.43 -XenPci_Dummy_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.44 +//NTSTATUS
   13.45 +//XenPci_Dummy_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.46  NTSTATUS
   13.47  XenPci_Pnp_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.48 +NTSTATUS
   13.49 +XenPci_Irp_Create_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.50 +NTSTATUS
   13.51 +XenPci_Irp_Close_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.52 +NTSTATUS
   13.53 +XenPci_Irp_Read_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.54 +NTSTATUS
   13.55 +XenPci_Irp_Cleanup_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
   13.56  
   13.57  
   13.58  
    14.1 --- a/xenpci/xenpci_fdo.c	Thu May 15 00:25:25 2008 +1000
    14.2 +++ b/xenpci/xenpci_fdo.c	Fri May 16 23:56:57 2008 +1000
    14.3 @@ -28,8 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fi
    14.4  static VOID
    14.5  XenBus_SysrqHandler(char *Path, PVOID Data);
    14.6  static VOID
    14.7 -XenBus_ShutdownHandler(char *Path, PVOID Data);
    14.8 -static VOID
    14.9  XenBus_BalloonHandler(char *Path, PVOID Data);
   14.10  
   14.11  /*
   14.12 @@ -37,37 +35,57 @@ static VOID
   14.13  XenPCI_XenBusWatchHandler(char *Path, PVOID Data);
   14.14  */
   14.15  
   14.16 -/* Global (driver-wide) variables */
   14.17 -static LIST_ENTRY ShutdownMsgList;
   14.18 -
   14.19  #pragma warning(disable : 4200) // zero-sized array
   14.20  
   14.21 -typedef struct {
   14.22 -  LIST_ENTRY ListEntry;
   14.23 -  ULONG Ptr;
   14.24 -//  ULONG Len;
   14.25 -  CHAR Buf[0];
   14.26 -} SHUTDOWN_MSG_ENTRY, *PSHUTDOWN_MSG_ENTRY;
   14.27 -
   14.28 -static KSPIN_LOCK ShutdownMsgLock;
   14.29 -
   14.30 -CM_PARTIAL_RESOURCE_DESCRIPTOR InterruptRaw;
   14.31 -CM_PARTIAL_RESOURCE_DESCRIPTOR InterruptTranslated;
   14.32 +//CM_PARTIAL_RESOURCE_DESCRIPTOR InterruptRaw;
   14.33 +//CM_PARTIAL_RESOURCE_DESCRIPTOR InterruptTranslated;
   14.34  
   14.35  NTSTATUS
   14.36  XenPci_Power_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
   14.37  {
   14.38    NTSTATUS status;
   14.39    PIO_STACK_LOCATION stack;
   14.40 -  PXENPCI_DEVICE_DATA xpdd;
   14.41 +  POWER_STATE_TYPE power_type;
   14.42 +  POWER_STATE power_state;
   14.43 +  PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
   14.44 +  //PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   14.45  
   14.46 +  UNREFERENCED_PARAMETER(device_object);
   14.47 +  
   14.48    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   14.49  
   14.50 -  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   14.51    stack = IoGetCurrentIrpStackLocation(irp);
   14.52 +  power_type = stack->Parameters.Power.Type;
   14.53 +  power_state = stack->Parameters.Power.State;
   14.54 +
   14.55 +  switch (stack->MinorFunction)
   14.56 +  {
   14.57 +  case IRP_MN_POWER_SEQUENCE:
   14.58 +    KdPrint((__DRIVER_NAME "     IRP_MN_POWER_SEQUENCE\n"));
   14.59 +    break;
   14.60 +  case IRP_MN_QUERY_POWER:
   14.61 +    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_POWER\n"));
   14.62 +    break;
   14.63 +  case IRP_MN_SET_POWER:
   14.64 +    KdPrint((__DRIVER_NAME "     IRP_MN_SET_POWER\n"));
   14.65 +    switch (power_type) {
   14.66 +    case DevicePowerState:
   14.67 +      KdPrint((__DRIVER_NAME "     DevicePowerState\n"));
   14.68 +      break;
   14.69 +    case SystemPowerState:
   14.70 +      KdPrint((__DRIVER_NAME "     SystemPowerState\n"));
   14.71 +      break;
   14.72 +    default:
   14.73 +      break;
   14.74 +    }    
   14.75 +    break;
   14.76 +  case IRP_MN_WAIT_WAKE:
   14.77 +    break;
   14.78 +  }
   14.79 +  PoStartNextPowerIrp(irp);
   14.80    IoSkipCurrentIrpStackLocation(irp);
   14.81 -  status = PoCallDriver(xpdd->common.lower_do, irp);
   14.82 -
   14.83 +  status =  PoCallDriver (xppdd->common.lower_do, irp);
   14.84 +  
   14.85    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   14.86  
   14.87    return status;
   14.88 @@ -204,14 +222,150 @@ XenPci_SendAndWaitForIrp(PDEVICE_OBJECT 
   14.89    return status;
   14.90  }
   14.91  
   14.92 +static NTSTATUS
   14.93 +XenPci_ProcessShutdownIrp(PXENPCI_DEVICE_DATA xpdd)
   14.94 +{
   14.95 +  PIO_STACK_LOCATION stack;
   14.96 +  NTSTATUS status;
   14.97 +  PIRP irp;
   14.98 +  KIRQL old_irql;
   14.99 +  ULONG length;
  14.100 +
  14.101 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.102 +
  14.103 +  KeAcquireSpinLock(&xpdd->shutdown_ring_lock, &old_irql);
  14.104 +  if (xpdd->shutdown_irp)
  14.105 +  {
  14.106 +    irp = xpdd->shutdown_irp;
  14.107 +    stack = IoGetCurrentIrpStackLocation(irp);
  14.108 +    KdPrint((__DRIVER_NAME "     stack = %p\n", stack));
  14.109 +    KdPrint((__DRIVER_NAME "     length = %d, buffer = %p\n", stack->Parameters.Read.Length, irp->AssociatedIrp.SystemBuffer));
  14.110 +    length = min(xpdd->shutdown_prod - xpdd->shutdown_cons, stack->Parameters.Read.Length);
  14.111 +    KdPrint((__DRIVER_NAME "     length = %d\n", length));
  14.112 +    if (length > 0)
  14.113 +    {
  14.114 +      memcpy(irp->AssociatedIrp.SystemBuffer, &xpdd->shutdown_ring[xpdd->shutdown_prod & (SHUTDOWN_RING_SIZE - 1)], length);
  14.115 +      xpdd->shutdown_cons += length;
  14.116 +      if (xpdd->shutdown_cons > SHUTDOWN_RING_SIZE)
  14.117 +      {
  14.118 +        xpdd->shutdown_cons -= SHUTDOWN_RING_SIZE;
  14.119 +        xpdd->shutdown_prod -= SHUTDOWN_RING_SIZE;
  14.120 +        xpdd->shutdown_start -= SHUTDOWN_RING_SIZE;
  14.121 +      }
  14.122 +      xpdd->shutdown_irp = NULL;
  14.123 +      KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
  14.124 +      status = STATUS_SUCCESS;    
  14.125 +      irp->IoStatus.Status = status;
  14.126 +      irp->IoStatus.Information = length;
  14.127 +      IoSetCancelRoutine(irp, NULL);
  14.128 +      IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.129 +    }
  14.130 +    else
  14.131 +    {
  14.132 +      KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
  14.133 +      KdPrint((__DRIVER_NAME "     nothing to read... pending\n"));
  14.134 +      IoMarkIrpPending(irp);
  14.135 +      status = STATUS_PENDING;
  14.136 +    }
  14.137 +  }
  14.138 +  else
  14.139 +  {
  14.140 +    KdPrint((__DRIVER_NAME "     no pending irp\n"));
  14.141 +    KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
  14.142 +    status = STATUS_SUCCESS;
  14.143 +  }  
  14.144 +
  14.145 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  14.146 +
  14.147 +  return status;
  14.148 +}
  14.149 +
  14.150 +static VOID
  14.151 +XenBus_ShutdownIoCancel(PDEVICE_OBJECT device_object, PIRP irp)
  14.152 +{
  14.153 +  PXENPCI_DEVICE_DATA xpdd;
  14.154 +  KIRQL old_irql;
  14.155 +
  14.156 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.157 +
  14.158 +  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  14.159 +  IoReleaseCancelSpinLock(irp->CancelIrql);
  14.160 +  KeAcquireSpinLock(&xpdd->shutdown_ring_lock, &old_irql);
  14.161 +  if (irp == xpdd->shutdown_irp)
  14.162 +  {
  14.163 +    KdPrint((__DRIVER_NAME "     Not the current irp???\n"));
  14.164 +    xpdd->shutdown_irp = NULL;
  14.165 +  }
  14.166 +  irp->IoStatus.Status = STATUS_CANCELLED;
  14.167 +  irp->IoStatus.Information = 0;
  14.168 +  KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
  14.169 +  IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.170 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  14.171 +}
  14.172 +
  14.173 +static void
  14.174 +XenBus_ShutdownHandler(char *path, PVOID context)
  14.175 +{
  14.176 +  PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)context;
  14.177 +  char *res;
  14.178 +  char *value;
  14.179 +  KIRQL old_irql;
  14.180 +
  14.181 +  UNREFERENCED_PARAMETER(path);
  14.182 +
  14.183 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.184 +
  14.185 +  res = XenBus_Read(xpdd, XBT_NIL, SHUTDOWN_PATH, &value);
  14.186 +  if (res)
  14.187 +  {
  14.188 +    KdPrint(("Error reading shutdown path - %s\n", res));
  14.189 +    XenPci_FreeMem(res);
  14.190 +    return;
  14.191 +  }
  14.192 +
  14.193 +  KdPrint((__DRIVER_NAME "     Shutdown value = %s\n", value));
  14.194 +  KdPrint((__DRIVER_NAME "     strlen(...) = %d\n", strlen(value)));
  14.195 +
  14.196 +  if (strlen(value) != 0)
  14.197 +  {
  14.198 +    if (strcmp(value, "suspend") == 0)
  14.199 +    {
  14.200 +      KdPrint((__DRIVER_NAME "     Suspend detected\n"));
  14.201 +      //XenPci_BeginSuspend(Device);
  14.202 +    }
  14.203 +    else
  14.204 +    {
  14.205 +      KdPrint((__DRIVER_NAME "     Before - shutdown_start = %d, shutdown_prod = %d, shutdown_cons = %d\n",xpdd->shutdown_start, xpdd->shutdown_prod, xpdd->shutdown_cons));
  14.206 +      KeAcquireSpinLock(&xpdd->shutdown_ring_lock, &old_irql);
  14.207 +      if (xpdd->shutdown_start >= xpdd->shutdown_cons)
  14.208 +        xpdd->shutdown_prod = xpdd->shutdown_start;
  14.209 +      else
  14.210 +        xpdd->shutdown_start = xpdd->shutdown_prod;
  14.211 +      KdPrint((__DRIVER_NAME "     Middle - shutdown_start = %d, shutdown_prod = %d, shutdown_cons = %d\n",xpdd->shutdown_start, xpdd->shutdown_prod, xpdd->shutdown_cons));
  14.212 +      memcpy(&xpdd->shutdown_ring[xpdd->shutdown_prod], value, strlen(value));
  14.213 +      xpdd->shutdown_prod += strlen(value);
  14.214 +      xpdd->shutdown_ring[xpdd->shutdown_prod++] = '\r';
  14.215 +      xpdd->shutdown_ring[xpdd->shutdown_prod++] = '\n';
  14.216 +      KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
  14.217 +      KdPrint((__DRIVER_NAME "     After - shutdown_start = %d, shutdown_prod = %d, shutdown_cons = %d\n",xpdd->shutdown_start, xpdd->shutdown_prod, xpdd->shutdown_cons));
  14.218 +      XenPci_ProcessShutdownIrp(xpdd);
  14.219 +    }
  14.220 +  }
  14.221 +
  14.222 +  //XenPci_FreeMem(value);
  14.223 +
  14.224 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  14.225 +}
  14.226 +
  14.227  static VOID
  14.228  XenPci_Pnp_StartDeviceCallback(PDEVICE_OBJECT device_object, PVOID context)
  14.229  {
  14.230    NTSTATUS status = STATUS_SUCCESS;
  14.231    PXENPCI_DEVICE_DATA xpdd = device_object->DeviceExtension;
  14.232    PIRP irp = context;
  14.233 +  char *response;
  14.234  
  14.235 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.236 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.237    
  14.238    XenPci_Init(xpdd);
  14.239  
  14.240 @@ -221,6 +375,12 @@ XenPci_Pnp_StartDeviceCallback(PDEVICE_O
  14.241  
  14.242    XenBus_Init(xpdd);
  14.243  
  14.244 +  //response = XenBus_AddWatch(xpdd, XBT_NIL, SYSRQ_PATH, XenBus_SysrqHandler, xpdd);
  14.245 +  //KdPrint((__DRIVER_NAME "     sysrqwatch response = '%s'\n", response)); 
  14.246 +  
  14.247 +  response = XenBus_AddWatch(xpdd, XBT_NIL, SHUTDOWN_PATH, XenBus_ShutdownHandler, xpdd);
  14.248 +  KdPrint((__DRIVER_NAME "     shutdown watch response = '%s'\n", response)); 
  14.249 +
  14.250    status = IoSetDeviceInterfaceState(&xpdd->interface_name, TRUE);
  14.251    if (!NT_SUCCESS(status))
  14.252    {
  14.253 @@ -231,7 +391,7 @@ XenPci_Pnp_StartDeviceCallback(PDEVICE_O
  14.254    
  14.255    IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.256  
  14.257 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  14.258 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  14.259  }
  14.260  
  14.261  static NTSTATUS
  14.262 @@ -264,7 +424,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  14.263      case CmResourceTypeInterrupt:
  14.264        KdPrint((__DRIVER_NAME "     irq_number = %03x\n", res_descriptor->u.Interrupt.Vector));
  14.265        xpdd->irq_number = res_descriptor->u.Interrupt.Vector;
  14.266 -      memcpy(&InterruptRaw, res_descriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
  14.267 +      //memcpy(&InterruptRaw, res_descriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
  14.268        break;
  14.269      }
  14.270    }
  14.271 @@ -291,7 +451,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  14.272  	    xpdd->irq_level = (KIRQL)res_descriptor->u.Interrupt.Level;
  14.273    	  xpdd->irq_vector = res_descriptor->u.Interrupt.Vector;
  14.274  	    xpdd->irq_affinity = res_descriptor->u.Interrupt.Affinity;
  14.275 -      memcpy(&InterruptTranslated, res_descriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
  14.276 +      //memcpy(&InterruptTranslated, res_descriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
  14.277        break;
  14.278      case CmResourceTypeDevicePrivate:
  14.279        KdPrint((__DRIVER_NAME "     Private Data: 0x%02x 0x%02x 0x%02x\n", res_descriptor->u.DevicePrivate.Data[0], res_descriptor->u.DevicePrivate.Data[1], res_descriptor->u.DevicePrivate.Data[2] ));
  14.280 @@ -508,7 +668,7 @@ XenPci_Pnp_QueryBusRelationsCallback(PDE
  14.281              if (strcmp(child->context->path, path) == 0)
  14.282              {
  14.283                KdPrint((__DRIVER_NAME "     Existing device %s\n", path));
  14.284 -              ASSERT(child->state != CHILD_STATE_DELETED);
  14.285 +              ASSERT(child->state == CHILD_STATE_DELETED);
  14.286                child->state = CHILD_STATE_ADDED;
  14.287                device_count++;
  14.288                break;
  14.289 @@ -659,7 +819,7 @@ XenPci_Pnp_Fdo(PDEVICE_OBJECT device_obj
  14.290    NTSTATUS status;
  14.291    PXENPCI_DEVICE_DATA xpdd;
  14.292  
  14.293 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.294 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.295  
  14.296    xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  14.297  
  14.298 @@ -715,7 +875,7 @@ XenPci_Pnp_Fdo(PDEVICE_OBJECT device_obj
  14.299      IoSkipCurrentIrpStackLocation(irp);
  14.300      irp->IoStatus.Status = STATUS_SUCCESS;
  14.301      break;
  14.302 -//#if 0
  14.303 +
  14.304    case IRP_MN_QUERY_DEVICE_RELATIONS:
  14.305      KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS\n"));
  14.306      switch (stack->Parameters.QueryDeviceRelations.Type)
  14.307 @@ -729,26 +889,116 @@ XenPci_Pnp_Fdo(PDEVICE_OBJECT device_obj
  14.308        break;  
  14.309      }
  14.310      break;
  14.311 -//#endif    
  14.312 +
  14.313    case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
  14.314      KdPrint((__DRIVER_NAME "     IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n"));
  14.315      return XenPci_Pnp_FilterResourceRequirements(device_object, irp);
  14.316  
  14.317    default:
  14.318 -    KdPrint((__DRIVER_NAME "     Unhandled Minor = %d\n", stack->MinorFunction));
  14.319 +    //KdPrint((__DRIVER_NAME "     Unhandled Minor = %d\n", stack->MinorFunction));
  14.320      IoSkipCurrentIrpStackLocation(irp);
  14.321      break;
  14.322    }
  14.323  
  14.324    status = IoCallDriver(xpdd->common.lower_do, irp);
  14.325  
  14.326 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  14.327 +
  14.328 +  return status;
  14.329 +}
  14.330 +
  14.331 +NTSTATUS
  14.332 +XenPci_Irp_Create_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  14.333 +{
  14.334 +  PXENPCI_DEVICE_DATA xpdd;
  14.335 +  NTSTATUS status;
  14.336 +
  14.337 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.338 +
  14.339 +  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  14.340 +  status = STATUS_SUCCESS;    
  14.341 +  irp->IoStatus.Status = status;
  14.342 +  IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.343 +
  14.344 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  14.345 +
  14.346 +  return status;
  14.347 +}
  14.348 +
  14.349 +NTSTATUS
  14.350 +XenPci_Irp_Close_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  14.351 +{
  14.352 +  PXENPCI_DEVICE_DATA xpdd;
  14.353 +  NTSTATUS status;
  14.354 +
  14.355 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.356 +
  14.357 +  // wait until pending irp's 
  14.358 +  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  14.359 +  status = STATUS_SUCCESS;    
  14.360 +  irp->IoStatus.Status = status;
  14.361 +  IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.362 +
  14.363 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  14.364 +
  14.365 +  return status;
  14.366 +}
  14.367 +
  14.368 +NTSTATUS
  14.369 +XenPci_Irp_Read_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  14.370 +{
  14.371 +  PXENPCI_DEVICE_DATA xpdd;
  14.372 +  NTSTATUS status;
  14.373 +  PIO_STACK_LOCATION stack;
  14.374 +  KIRQL old_irql;
  14.375 +
  14.376 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.377 +
  14.378 +  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  14.379 +  stack = IoGetCurrentIrpStackLocation(irp);
  14.380 +  if (stack->Parameters.Read.Length == 0)
  14.381 +  {
  14.382 +    irp->IoStatus.Information = 0;
  14.383 +    status = STATUS_SUCCESS;    
  14.384 +    irp->IoStatus.Status = status;
  14.385 +    IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.386 +  }
  14.387 +  else 
  14.388 +  {
  14.389 +    KdPrint((__DRIVER_NAME "     stack = %p\n", stack));
  14.390 +    KdPrint((__DRIVER_NAME "     length = %d, buffer = %p\n", stack->Parameters.Read.Length, irp->AssociatedIrp.SystemBuffer));
  14.391 +    
  14.392 +    KeAcquireSpinLock(&xpdd->shutdown_ring_lock, &old_irql);
  14.393 +    xpdd->shutdown_irp = irp;
  14.394 +    IoSetCancelRoutine(irp, XenBus_ShutdownIoCancel);
  14.395 +    KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
  14.396 +    status = XenPci_ProcessShutdownIrp(xpdd);
  14.397 +  }
  14.398 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  14.399 +
  14.400 +  return status;
  14.401 +}
  14.402 +
  14.403 +
  14.404 +NTSTATUS
  14.405 +XenPci_Irp_Cleanup_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  14.406 +{
  14.407 +  NTSTATUS status;
  14.408 +
  14.409 +  UNREFERENCED_PARAMETER(device_object);
  14.410 +
  14.411 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.412 +  
  14.413 +  status = STATUS_SUCCESS;
  14.414 +  irp->IoStatus.Status = status;
  14.415 +  IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.416 +  
  14.417    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  14.418  
  14.419    return status;
  14.420  }
  14.421  
  14.422  #if 0
  14.423 -
  14.424  static NTSTATUS
  14.425  XenPCI_D0Entry(
  14.426      IN WDFDEVICE  Device,
  14.427 @@ -792,7 +1042,7 @@ XenPCI_D0EntryPostInterruptsEnabled(WDFD
  14.428    KdPrint((__DRIVER_NAME "     shutdown watch response = '%s'\n", response)); 
  14.429  
  14.430    response = XenBus_AddWatch(Device, XBT_NIL, BALLOON_PATH, XenBus_BalloonHandler, Device);
  14.431 -  KdPrint((__DRIVER_NAME "     shutdown watch response = '%s'\n", response)); 
  14.432 +  KdPrint((__DRIVER_NAME "     balloon watch response = '%s'\n", response)); 
  14.433  
  14.434    response = XenBus_AddWatch(Device, XBT_NIL, "device", XenPCI_XenBusWatchHandler, Device);
  14.435    KdPrint((__DRIVER_NAME "     device watch response = '%s'\n", response)); 
  14.436 @@ -1168,91 +1418,10 @@ XenPci_BeginSuspend(WDFDEVICE Device)
  14.437    }
  14.438    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  14.439  }
  14.440 -
  14.441 -static void
  14.442 -XenBus_ShutdownHandler(char *Path, PVOID Data)
  14.443 -{
  14.444 -  WDFDEVICE Device = Data;  
  14.445 -  char *res;
  14.446 -  char *Value;
  14.447 -  xenbus_transaction_t xbt;
  14.448 -  int retry;
  14.449 -  PSHUTDOWN_MSG_ENTRY Entry;
  14.450 -
  14.451 -  UNREFERENCED_PARAMETER(Path);
  14.452 -
  14.453 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.454 -  KdPrint((__DRIVER_NAME "     Device = %p\n", Device));
  14.455 -
  14.456 -  res = XenBus_StartTransaction(Device, &xbt);
  14.457 -  if (res)
  14.458 -  {
  14.459 -    KdPrint(("Error starting transaction\n"));
  14.460 -    XenPci_FreeMem(res);
  14.461 -    return;
  14.462 -  }
  14.463 -
  14.464 -  res = XenBus_Read(Device, XBT_NIL, SHUTDOWN_PATH, &Value);
  14.465 -  if (res)
  14.466 -  {
  14.467 -    KdPrint(("Error reading shutdown path\n"));
  14.468 -    XenPci_FreeMem(res);
  14.469 -    XenBus_EndTransaction(Device, xbt, 1, &retry);
  14.470 -    return;
  14.471 -  }
  14.472 +#endif
  14.473  
  14.474 -  if (Value != NULL && strlen(Value) != 0)
  14.475 -  {
  14.476 -    res = XenBus_Write(Device, XBT_NIL, SHUTDOWN_PATH, "");
  14.477 -    if (res)
  14.478 -    {
  14.479 -      KdPrint(("Error writing shutdown path\n"));
  14.480 -      XenPci_FreeMem(res);
  14.481 -      // end trans?
  14.482 -      return;
  14.483 -    }
  14.484 -  } 
  14.485 -
  14.486 -  if (Value != NULL)
  14.487 -  {
  14.488 -    KdPrint((__DRIVER_NAME "     Shutdown Value = %s\n", Value));
  14.489 -    KdPrint((__DRIVER_NAME "     strlen(...) = %d\n", strlen(Value)));
  14.490 -  }
  14.491 -  else
  14.492 -  {
  14.493 -    KdPrint((__DRIVER_NAME "     Shutdown Value = <null>\n"));
  14.494 -  }
  14.495  
  14.496 -  res = XenBus_EndTransaction(Device, xbt, 0, &retry);
  14.497 -  if (res)
  14.498 -  {
  14.499 -    KdPrint(("Error ending transaction\n"));
  14.500 -    XenPci_FreeMem(res);
  14.501 -    return;
  14.502 -  }
  14.503 -
  14.504 -  if (Value != NULL && strlen(Value) != 0)
  14.505 -  {
  14.506 -    if (strcmp(Value, "suspend") == 0)
  14.507 -    {
  14.508 -      KdPrint((__DRIVER_NAME "     Suspend detected\n"));
  14.509 -      XenPci_BeginSuspend(Device);
  14.510 -    }
  14.511 -    else
  14.512 -    {
  14.513 -      Entry = (PSHUTDOWN_MSG_ENTRY)ExAllocatePoolWithTag(NonPagedPool, sizeof(SHUTDOWN_MSG_ENTRY) + strlen(Value) + 1 + 1, XENPCI_POOL_TAG);
  14.514 -      Entry->Ptr = 0;
  14.515 -      RtlStringCbPrintfA(Entry->Buf, sizeof(SHUTDOWN_MSG_ENTRY) + strlen(Value) + 1 + 1, "%s\n", Value);
  14.516 -      InsertTailList(&ShutdownMsgList, &Entry->ListEntry);
  14.517 -      WdfIoQueueStart(ReadQueue);
  14.518 -    }
  14.519 -  }
  14.520 -
  14.521 -  XenPci_FreeMem(Value);
  14.522 -
  14.523 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  14.524 -}
  14.525 -
  14.526 +#if 0
  14.527  static VOID
  14.528  XenBus_BalloonHandler(char *Path, PVOID Data)
  14.529  {
    15.1 --- a/xenpci/xenpci_pdo.c	Thu May 15 00:25:25 2008 +1000
    15.2 +++ b/xenpci/xenpci_pdo.c	Fri May 16 23:56:57 2008 +1000
    15.3 @@ -27,16 +27,66 @@ Foundation, Inc., 51 Franklin Street, Fi
    15.4  NTSTATUS
    15.5  XenPci_Power_Pdo(PDEVICE_OBJECT device_object, PIRP irp)
    15.6  {
    15.7 +  NTSTATUS status;
    15.8 +  PIO_STACK_LOCATION stack;
    15.9 +  POWER_STATE_TYPE power_type;
   15.10 +  POWER_STATE power_state;
   15.11 +  //PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
   15.12 +  //PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   15.13 +
   15.14    UNREFERENCED_PARAMETER(device_object);
   15.15    
   15.16 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   15.17 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   15.18  
   15.19 -  irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
   15.20 +  stack = IoGetCurrentIrpStackLocation(irp);
   15.21 +  power_type = stack->Parameters.Power.Type;
   15.22 +  power_state = stack->Parameters.Power.State;
   15.23 +  
   15.24 +  switch (stack->MinorFunction)
   15.25 +  {
   15.26 +  case IRP_MN_POWER_SEQUENCE:
   15.27 +    KdPrint((__DRIVER_NAME "     IRP_MN_POWER_SEQUENCE\n"));
   15.28 +    status = STATUS_NOT_SUPPORTED;
   15.29 +    break;
   15.30 +  case IRP_MN_QUERY_POWER:
   15.31 +    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_POWER\n"));
   15.32 +    status = STATUS_SUCCESS;
   15.33 +    break;
   15.34 +  case IRP_MN_SET_POWER:
   15.35 +    KdPrint((__DRIVER_NAME "     IRP_MN_SET_POWER\n"));
   15.36 +    switch (power_type) {
   15.37 +    case DevicePowerState:
   15.38 +      PoSetPowerState(device_object, power_type, power_state);
   15.39 +      status = STATUS_SUCCESS;
   15.40 +      break;
   15.41 +    case SystemPowerState:
   15.42 +      status = STATUS_SUCCESS;
   15.43 +      break;
   15.44 +    default:
   15.45 +      status = STATUS_NOT_SUPPORTED;
   15.46 +      break;
   15.47 +    }    
   15.48 +    break;
   15.49 +  case IRP_MN_WAIT_WAKE:
   15.50 +    KdPrint((__DRIVER_NAME "     IRP_MN_WAIT_WAKE\n"));
   15.51 +    status = STATUS_NOT_SUPPORTED;
   15.52 +    break;
   15.53 +  default:
   15.54 +    //KdPrint((__DRIVER_NAME "     Unknown IRP_MN_%d\n", stack->MinorFunction));
   15.55 +    status = STATUS_NOT_SUPPORTED;
   15.56 +    break;
   15.57 +  }
   15.58 +  if (status != STATUS_NOT_SUPPORTED) {
   15.59 +    irp->IoStatus.Status = status;
   15.60 +  }
   15.61 +
   15.62 +  PoStartNextPowerIrp(irp);
   15.63 +  status = irp->IoStatus.Status;
   15.64    IoCompleteRequest(irp, IO_NO_INCREMENT);
   15.65    
   15.66 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   15.67 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   15.68  
   15.69 -  return irp->IoStatus.Status;
   15.70 +  return status;
   15.71  }
   15.72  
   15.73  static VOID
   15.74 @@ -640,3 +690,69 @@ XenPci_Pnp_Pdo(PDEVICE_OBJECT device_obj
   15.75  
   15.76    return status;
   15.77  }
   15.78 +
   15.79 +NTSTATUS
   15.80 +XenPci_Irp_Create_Pdo(PDEVICE_OBJECT device_object, PIRP irp)
   15.81 +{
   15.82 +  PXENPCI_DEVICE_DATA xpdd;
   15.83 +  NTSTATUS status;
   15.84 +
   15.85 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   15.86 +
   15.87 +  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   15.88 +  status = IoCallDriver(xpdd->common.lower_do, irp);
   15.89 +
   15.90 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   15.91 +
   15.92 +  return status;
   15.93 +}
   15.94 +
   15.95 +NTSTATUS
   15.96 +XenPci_Irp_Close_Pdo(PDEVICE_OBJECT device_object, PIRP irp)
   15.97 +{
   15.98 +  PXENPCI_DEVICE_DATA xpdd;
   15.99 +  NTSTATUS status;
  15.100 +
  15.101 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  15.102 +
  15.103 +  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  15.104 +  status = IoCallDriver(xpdd->common.lower_do, irp);
  15.105 +
  15.106 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  15.107 +
  15.108 +  return status;
  15.109 +}
  15.110 +
  15.111 +NTSTATUS
  15.112 +XenPci_Irp_Read_Pdo(PDEVICE_OBJECT device_object, PIRP irp)
  15.113 +{
  15.114 +  PXENPCI_DEVICE_DATA xpdd;
  15.115 +  NTSTATUS status;
  15.116 +
  15.117 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  15.118 +
  15.119 +  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  15.120 +  status = IoCallDriver(xpdd->common.lower_do, irp);
  15.121 +
  15.122 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  15.123 +
  15.124 +  return status;
  15.125 +}
  15.126 +
  15.127 +NTSTATUS
  15.128 +XenPci_Irp_Cleanup_Pdo(PDEVICE_OBJECT device_object, PIRP irp)
  15.129 +{
  15.130 +  NTSTATUS status;
  15.131 +
  15.132 +  UNREFERENCED_PARAMETER(device_object);
  15.133 +
  15.134 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  15.135 +  
  15.136 +  status = STATUS_SUCCESS;
  15.137 +  irp->IoStatus.Status = status;
  15.138 +  IoCompleteRequest(irp, IO_NO_INCREMENT);
  15.139 +  
  15.140 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  15.141 +
  15.142 +  return status;
  15.143 +}
    16.1 --- a/xenvbd/xenvbd.inx	Thu May 15 00:25:25 2008 +1000
    16.2 +++ b/xenvbd/xenvbd.inx	Fri May 16 23:56:57 2008 +1000
    16.3 @@ -34,7 +34,7 @@ AddService=XenVbd,2,XenVbd_Service, XenV
    16.4  [XenVbd_Service]
    16.5  DisplayName    = %XenVbd.SVCDESC%                            
    16.6  ServiceType    = 1
    16.7 -StartType      = 3
    16.8 +StartType      = 0
    16.9  ErrorControl   = 1
   16.10  LoadOrderGroup = System Bus Extender
   16.11  ServiceBinary  = %12%\xenvbd.sys