win-pvdrivers

changeset 538:e75bb8d68370

Lots more changes...
author James Harper <james.harper@bendigoit.com.au>
date Tue Mar 03 09:51:24 2009 +1100 (2009-03-03)
parents 2a74ac2f43bb
children 9ed05604c105
files common.inc dirs installer.wxs makedist.bat xennet/makefile.inc xennet/xennet.c xennet/xennet_common.c xenpci/evtchn.c xenpci/makefile.inc xenpci/memory.c xenpci/xenbus.c xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci.inx xenpci/xenpci_fdo.c xenpci/xenpci_pdo.c xenscsi/makefile.inc xenvbd/makefile.inc xenvbd/xenvbd.c xenvbd/xenvbd.h
line diff
     1.1 --- a/common.inc	Wed Feb 18 22:18:23 2009 +1100
     1.2 +++ b/common.inc	Tue Mar 03 09:51:24 2009 +1100
     1.3 @@ -1,4 +1,6 @@
     1.4 -VERSION=0.9.11.16
     1.5 +!IFNDEF VERSION
     1.6 +GPLPV_VERSION=0.0.0.0
     1.7 +!ENDIF
     1.8  #TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.9  MSC_WARNING_LEVEL=/W4
    1.10  INCLUDES = ..\common\include;..\common\include\public
     2.1 --- a/dirs	Wed Feb 18 22:18:23 2009 +1100
     2.2 +++ b/dirs	Tue Mar 03 09:51:24 2009 +1100
     2.3 @@ -1,1 +1,1 @@
     2.4 -DIRS=xenpci xenhide xenvbd xennet xenscsi xenstub copyconfig shutdownmon
     2.5 \ No newline at end of file
     2.6 +DIRS=xenpci xenhide xenvbd xennet xenscsi copyconfig shutdownmon
     2.7 \ No newline at end of file
     3.1 --- a/installer.wxs	Wed Feb 18 22:18:23 2009 +1100
     3.2 +++ b/installer.wxs	Tue Mar 03 09:51:24 2009 +1100
     3.3 @@ -6,9 +6,9 @@
     3.4      <?define ARCHDIR = amd64 ?>
     3.5    <?endif ?>
     3.6  
     3.7 -  <Product Name='GPL PV Drivers for Windows' Id='915B4C12-093D-419d-8FEC-63DCFD8B820D'
     3.8 +  <Product Name='GPL PV Drivers for Windows' Id='*'
     3.9      UpgradeCode='4EDE5DEC-3208-4a1e-8E52-DAC44F7D7062'
    3.10 -    Language='1033' Codepage='1252' Version='1.0.0' Manufacturer='James Harper'>
    3.11 +    Language='1033' Codepage='1252' Version='$(env.GPLPV_VERSION)' Manufacturer='James Harper'>
    3.12  
    3.13      <Package Id='*' Keywords='Installer' Description="GPL PV Drivers for Windows"
    3.14        Comments='no comment' Manufacturer='James Harper'
    3.15 @@ -19,6 +19,9 @@
    3.16      
    3.17      <Media Id='1' Cabinet='gplpv.cab' EmbedCab='yes' />
    3.18  
    3.19 +    <CustomAction Id='InstallShutdownMonService' FileKey='shutdownmon.exe' ExeCommand='-i' Execute='deferred' Return='check'/>
    3.20 +    <CustomAction Id='UnInstallShutdownMonService' FileKey='shutdownmon.exe' ExeCommand='-u' Execute='deferred' Return='check'/>
    3.21 +
    3.22      <Directory Id='TARGETDIR' Name='SourceDir'>
    3.23        <Directory Id='ProgramFilesFolder' Name='PFiles'>
    3.24          <Directory Id='XenProgramFilesDir' Name='Xen PV Drivers'>
    3.25 @@ -38,36 +41,29 @@
    3.26                  <File Id='xenpci.inf' Name='xenpci.inf' DiskId='1' Source='xenpci\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenpci.inf' />
    3.27                  <File Id='xenpci.sys' Name='xenpci.sys' DiskId='1' Source='xenpci\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenpci.sys' />
    3.28                  <File Id='xenhide.sys' Name='xenhide.sys' DiskId='1' Source='xenhide\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenhide.sys' />
    3.29 -                <File Id='WdfCoInstaller01007.dll' Name='WdfCoInstaller01007.dll' DiskId='1' Source='$(env.BASEDIR)\redist\wdf\$(env.CPU)\WdfCoInstaller01007.dll' />
    3.30 -                <difx:Driver Sequence='99' Legacy='yes' />
    3.31 +                <File Id='WdfCoInstaller01007.dll' Name='WdfCoInstaller01007.dll' DiskId='1' Source='$(env.BASEDIR)\redist\wdf\$(env._BUILDARCH)\WdfCoInstaller01007.dll' />
    3.32 +                <difx:Driver Sequence='99' Legacy='yes' PlugAndPlayPrompt='no' ForceInstall='yes' />
    3.33                </Component>
    3.34              </Directory>
    3.35              <Directory Id='XenVbdDir' Name='xenvbd'>
    3.36                <Component Id='XenVbd' Guid='1F05DC54-974C-40f6-BF41-0EFDB3EBD1DC'>
    3.37                  <File Id='xenvbd.inf' Name='xenvbd.inf' DiskId='1' Source='xenvbd\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenvbd.inf' />
    3.38                  <File Id='xenvbd.sys' Name='xenvbd.sys' DiskId='1' Source='xenvbd\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenvbd.sys' />
    3.39 -                <difx:Driver Sequence='1' Legacy='yes' />
    3.40 +                <difx:Driver Sequence='1' Legacy='yes' PlugAndPlayPrompt='no' ForceInstall='yes'/>
    3.41                </Component>
    3.42              </Directory>
    3.43              <Directory Id='XenScsiDir' Name='xenscsi'>
    3.44                <Component Id='XenScsi' Guid='47C9AB48-3A7D-42b2-AE2C-7F9235C8B7B4'>
    3.45                  <File Id='xenscsi.inf' Name='xenscsi.inf' DiskId='1' Source='xenscsi\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenscsi.inf' />
    3.46                  <File Id='xenscsi.sys' Name='xenscsi.sys' DiskId='1' Source='xenscsi\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenscsi.sys' />
    3.47 -                <difx:Driver Sequence='1' Legacy='yes' />
    3.48 +                <difx:Driver Sequence='2' Legacy='yes' PlugAndPlayPrompt='no' ForceInstall='yes' />
    3.49                </Component>
    3.50              </Directory>
    3.51              <Directory Id='XenNetDir' Name='xennet'>
    3.52                <Component Id='XenNet' Guid='F16B1EC7-35B1-42c2-9017-22DC23D80BE7'>
    3.53                  <File Id='xennet.inf' Name='xennet.inf' DiskId='1' Source='xennet\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xennet.inf' />
    3.54                  <File Id='xennet.sys' Name='xennet.sys' DiskId='1' Source='xennet\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xennet.sys' />
    3.55 -                <difx:Driver Sequence='3' Legacy='yes' />
    3.56 -              </Component>
    3.57 -            </Directory>
    3.58 -            <Directory Id='XenStubDir' Name='xenstub'>
    3.59 -              <Component Id='XenStub' Guid='71794E97-D0CD-409b-BF7C-2FCEEEBD3D13'>
    3.60 -                <File Id='xenstub.inf' Name='xenstub.inf' DiskId='1' Source='xenstub\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenstub.inf' />
    3.61 -                <File Id='xenstub.sys' Name='xenstub.sys' DiskId='1' Source='xenstub\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenstub.sys' />
    3.62 -                <difx:Driver Sequence='4' Legacy='yes' />
    3.63 +                <difx:Driver Sequence='3' Legacy='yes' PlugAndPlayPrompt='no' ForceInstall='yes' />
    3.64                </Component>
    3.65              </Directory>
    3.66            </Directory>
    3.67 @@ -91,15 +87,12 @@
    3.68        <Feature Id='XenVbd' Title='XenVbd Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    3.69          <ComponentRef Id='XenVbd' />
    3.70        </Feature>
    3.71 -      <Feature Id='XenScsi' Title='XenVbd Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    3.72 +      <Feature Id='XenScsi' Title='XenScsi Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    3.73          <ComponentRef Id='XenScsi' />
    3.74        </Feature>
    3.75        <Feature Id='XenNet' Title='XenNet Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    3.76          <ComponentRef Id='XenNet' />
    3.77        </Feature>
    3.78 -      <Feature Id='XenStub' Title='XenNet Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    3.79 -        <ComponentRef Id='XenStub' />
    3.80 -      </Feature>
    3.81      </Feature>
    3.82      <Feature Id='ShutdownMon' Title='Shutdown Monitor' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    3.83        <ComponentRef Id='ShutdownMon' />
    3.84 @@ -110,7 +103,8 @@
    3.85  
    3.86      <InstallExecuteSequence>
    3.87        <ScheduleReboot After='InstallFinalize' />
    3.88 +      <Custom Action='UnInstallShutdownMonService' Before='StopServices'>$ShutdownMon=2</Custom> 
    3.89 +      <Custom Action='InstallShutdownMonService' After='StartServices'>$ShutdownMon>2</Custom> 
    3.90      </InstallExecuteSequence>
    3.91 -
    3.92    </Product>
    3.93  </Wix>
     4.1 --- a/makedist.bat	Wed Feb 18 22:18:23 2009 +1100
     4.2 +++ b/makedist.bat	Tue Mar 03 09:51:24 2009 +1100
     4.3 @@ -1,6 +1,17 @@
     4.4  @echo off
     4.5  IF NOT EXIST set_ddk_path.bat ECHO >set_ddk_path.bat SET DDK_PATH=C:\WinDDK\6001.18002
     4.6  
     4.7 +SET VERSION=0.10.0
     4.8 +SET BUILD_NUMBER=0
     4.9 +IF EXIST build_number.bat CALL build_number.bat
    4.10 +
    4.11 +SET GPLPV_VERSION=%VERSION%.%BUILD_NUMBER%
    4.12 +
    4.13 +SET /A BUILD_NUMBER=%BUILD_NUMBER%+1
    4.14 +ECHO >build_number.bat SET BUILD_NUMBER=%BUILD_NUMBER%
    4.15 +
    4.16 +ECHO BUILDING %GPLPV_VERSION%
    4.17 +
    4.18  CALL set_ddk_path.bat
    4.19  
    4.20  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre WXP && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.21 @@ -10,56 +21,38 @@ rem CALL sign_inf.bat winxp XP_X86
    4.22  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre WNET && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.23  rem CALL sign_sys.bat winnet i386 Server2003_X86
    4.24  rem CALL sign_inf.bat winnet Server2003_X64
    4.25 -rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.26 -rem "%WIX%\bin\light.exe" -o gplpv_%BUILD_ALT_DIR%.msi installer.wixobj "%WIX%\bin\difxapp_x86.wixlib" -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.27  
    4.28  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre x64 WNET && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.29  rem CALL sign_sys.bat winnet amd64 Server2003_X64
    4.30  rem CALL sign_inf.bat winnet Server2003_X64
    4.31 -rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.32 -rem "%WIX%\bin\light.exe" -o gplpv_%BUILD_ALT_DIR%.msi installer.wixobj "%WIX%\bin\difxapp_x86.wixlib" -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.33  
    4.34  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre WLH && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.35  rem CALL sign_sys.bat winlh i386 Server2008_X86
    4.36  rem CALL sign_inf.bat winlh Server2008_X64
    4.37 -rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.38 -rem "%WIX%\bin\light.exe" -o gplpv_%BUILD_ALT_DIR%.msi installer.wixobj "%WIX%\bin\difxapp_x86.wixlib" -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.39  
    4.40  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre x64 WLH && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.41  rem CALL sign_sys.bat winlh amd64 Server2008_X64
    4.42  rem CALL sign_inf.bat winlh Server2008_X64
    4.43 -rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.44 -rem "%WIX%\bin\light.exe" -o gplpv_%BUILD_ALT_DIR%.msi installer.wixobj "%WIX%\bin\difxapp_x86.wixlib" -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.45  
    4.46  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WXP && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.47  rem CALL sign_sys.bat winxp i386 XP_X86
    4.48  rem CALL sign_inf.bat winxp XP_X86
    4.49 -rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.50 -rem "%WIX%\bin\light.exe" -o gplpv_%BUILD_ALT_DIR%.msi installer.wixobj "%WIX%\bin\difxapp_x86.wixlib" -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.51  
    4.52  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WNET && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.53  rem CALL sign_sys.bat winnet i386 Server2003_X86
    4.54  rem CALL sign_inf.bat winnet Server2003_X64
    4.55 -rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.56 -rem "%WIX%\bin\light.exe" -o gplpv_%BUILD_ALT_DIR%.msi installer.wixobj "%WIX%\bin\difxapp_x86.wixlib" -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.57  
    4.58  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk x64 WNET && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.59  rem CALL sign_sys.bat winnet amd64 Server2003_X64
    4.60  rem CALL sign_inf.bat winnet Server2003_X64
    4.61 -rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.62 -rem "%WIX%\bin\light.exe" -o gplpv_%BUILD_ALT_DIR%.msi installer.wixobj "%WIX%\bin\difxapp_x86.wixlib" -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.63  
    4.64  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WLH && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.65  rem CALL sign_sys.bat winlh i386 Server2008_X86
    4.66  rem CALL sign_inf.bat winlh Server2008_X64
    4.67 -rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.68 -rem "%WIX%\bin\light.exe" -o gplpv_%BUILD_ALT_DIR%.msi installer.wixobj "%WIX%\bin\difxapp_x86.wixlib" -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.69  
    4.70  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk x64 WLH && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    4.71  rem CALL sign_sys.bat winlh amd64 Server2008_X64
    4.72  rem CALL sign_inf.bat winlh Server2008_X64
    4.73 -rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.74 -rem "%WIX%\bin\light.exe" -o gplpv_%BUILD_ALT_DIR%.msi installer.wixobj "%WIX%\bin\difxapp_x86.wixlib" -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    4.75  
    4.76  rem IF NOT EXIST SIGN_CONFIG.BAT GOTO DONT_SIGN
    4.77  rem CALL SIGN_CONFIG.BAT
     5.1 --- a/xennet/makefile.inc	Wed Feb 18 22:18:23 2009 +1100
     5.2 +++ b/xennet/makefile.inc	Tue Mar 03 09:51:24 2009 +1100
     5.3 @@ -1,5 +1,5 @@
     5.4  _LNG=$(LANGUAGE)
     5.5 -STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
     5.6 +STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(GPLPV_VERSION)
     5.7  
     5.8  $(OBJ_PATH)\$(O)\$(INF_NAME).inf: $(INF_NAME).inx sources ..\common.inc
     5.9      copy $(@B).inx $@
     6.1 --- a/xennet/xennet.c	Wed Feb 18 22:18:23 2009 +1100
     6.2 +++ b/xennet/xennet.c	Tue Mar 03 09:51:24 2009 +1100
     6.3 @@ -327,6 +327,8 @@ XenNet_Init(
     6.4  
     6.5    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
     6.6  
     6.7 +  length = NdisReadPciSlotInformation(MiniportAdapterHandle, 0, 0, &buf, 128);
     6.8 +  KdPrint((__DRIVER_NAME "     NdisReadPciSlotInformation = %d\n", length));
     6.9    /* deal with medium stuff */
    6.10    for (i = 0; i < MediumArraySize; i++)
    6.11    {
    6.12 @@ -638,21 +640,6 @@ XenNet_Init(
    6.13  
    6.14    KeMemoryBarrier(); // packets could be received anytime after we set Frontent to Connected
    6.15  
    6.16 -  #if 0
    6.17 -  status = NdisMRegisterInterrupt(&xi->interrupt, MiniportAdapterHandle, irq_vector, irq_level,
    6.18 -    TRUE, TRUE, irq_mode);
    6.19 -  if (!NT_SUCCESS(status))
    6.20 -  {
    6.21 -    KdPrint(("NdisMRegisterInterrupt failed with 0x%x\n", status));
    6.22 -    status = NDIS_STATUS_RESOURCES;
    6.23 -    xi->connected = FALSE;
    6.24 -    XenNet_TxShutdown(xi);
    6.25 -    XenNet_RxShutdown(xi);
    6.26 -    goto err;
    6.27 -  }
    6.28 -  #endif
    6.29 -  //xi->vectors.EvtChn_Bind(xi->vectors.context, xi->event_channel, XenNet_HandleEvent, xi);
    6.30 -
    6.31    FUNCTION_EXIT();
    6.32  
    6.33    return NDIS_STATUS_SUCCESS;
    6.34 @@ -688,10 +675,8 @@ XenNet_Shutdown(
    6.35  {
    6.36    UNREFERENCED_PARAMETER(MiniportAdapterContext);
    6.37  
    6.38 +  /* remember we are called at >= DIRQL here */
    6.39    FUNCTION_CALLED();
    6.40 -
    6.41 -  /* can't do this as shutdown might be called at DIRQL or higher */
    6.42 -  /* NdisMDeregisterInterrupt(&xi->interrupt); */
    6.43  }
    6.44  
    6.45  /* Opposite of XenNet_Init */
    6.46 @@ -705,18 +690,16 @@ XenNet_Halt(
    6.47    FUNCTION_ENTER();
    6.48    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    6.49  
    6.50 -  NdisMDeregisterInterrupt(&xi->interrupt);
    6.51 +  xi->connected = FALSE;
    6.52 +  KeMemoryBarrier(); /* make sure everyone sees that we are now shut down */
    6.53 +
    6.54 +  XenNet_TxShutdown(xi);
    6.55 +  XenNet_RxShutdown(xi);
    6.56  
    6.57    xi->vectors.XenPci_XenShutdownDevice(xi->vectors.context);
    6.58  
    6.59 -  xi->connected = FALSE;
    6.60 -  KeMemoryBarrier(); /* make sure everyone sees that we are now shut down */
    6.61 -
    6.62    // TODO: remove event channel xenbus entry (how?)
    6.63  
    6.64 -  XenNet_TxShutdown(xi);
    6.65 -  XenNet_RxShutdown(xi);
    6.66 -
    6.67    NdisFreeMemory(xi, 0, 0); // <= DISPATCH_LEVEL
    6.68  
    6.69    FUNCTION_EXIT();
     7.1 --- a/xennet/xennet_common.c	Wed Feb 18 22:18:23 2009 +1100
     7.2 +++ b/xennet/xennet_common.c	Tue Mar 03 09:51:24 2009 +1100
     7.3 @@ -147,7 +147,7 @@ XenNet_ParsePacketHeader(packet_info_t *
     7.4      {
     7.5        if (!XenNet_BuildHeader(pi, (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + 20)))
     7.6        {
     7.7 -        KdPrint((__DRIVER_NAME "     packet too small (IP Header + IP Options + TCP Header)\n"));
     7.8 +        //KdPrint((__DRIVER_NAME "     packet too small (IP Header + IP Options + TCP Header)\n"));
     7.9          return PARSE_TOO_SMALL;
    7.10        }
    7.11      }
     8.1 --- a/xenpci/evtchn.c	Wed Feb 18 22:18:23 2009 +1100
     8.2 +++ b/xenpci/evtchn.c	Tue Mar 03 09:51:24 2009 +1100
     8.3 @@ -101,6 +101,11 @@ to CPU != 0, but we should always use vc
     8.4      KdPrint((__DRIVER_NAME "     unhandled interrupt\n"));
     8.5    }
     8.6  
     8.7 +  if (xpdd->hibernated)
     8.8 +  {
     8.9 +    KdPrint((__DRIVER_NAME "     interrupt while hibernated\n"));
    8.10 +  }
    8.11 +
    8.12    for (i = 0; i < ARRAY_SIZE(xpdd->evtchn_pending_pvt); i++)
    8.13    {
    8.14      if (xpdd->evtchn_pending_pvt[i])
     9.1 --- a/xenpci/makefile.inc	Wed Feb 18 22:18:23 2009 +1100
     9.2 +++ b/xenpci/makefile.inc	Tue Mar 03 09:51:24 2009 +1100
     9.3 @@ -1,5 +1,5 @@
     9.4  _LNG=$(LANGUAGE)
     9.5 -STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION) -k $(KMDF_VERSION_MAJOR).$(KMDF_VERSION_MINOR)
     9.6 +STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(GPLPV_VERSION) -k $(KMDF_VERSION_MAJOR).$(KMDF_VERSION_MINOR)
     9.7  
     9.8  $(OBJ_PATH)\$(O)\$(TARGETNAME).inf: $(TARGETNAME).inx sources ..\common.inc
     9.9      copy $(@B).inx $@
    10.1 --- a/xenpci/memory.c	Wed Feb 18 22:18:23 2009 +1100
    10.2 +++ b/xenpci/memory.c	Tue Mar 03 09:51:24 2009 +1100
    10.3 @@ -5,20 +5,31 @@
    10.4  NTSTATUS
    10.5  hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd)
    10.6  {
    10.7 +  ULONG base;
    10.8    DWORD32 cpuid_output[4];
    10.9    char xensig[13];
   10.10    ULONG i;
   10.11    ULONG pages;
   10.12 -  ULONG msr;  
   10.13 +  ULONG msr;
   10.14  
   10.15 -  __cpuid(cpuid_output, 0x40000000);
   10.16 -  *(ULONG*)(xensig + 0) = cpuid_output[1];
   10.17 -  *(ULONG*)(xensig + 4) = cpuid_output[2];
   10.18 -  *(ULONG*)(xensig + 8) = cpuid_output[3];
   10.19 -  xensig[12] = '\0';
   10.20 -  KdPrint((__DRIVER_NAME "     Xen Signature = %s, EAX = 0x%08x\n", xensig, cpuid_output[0]));
   10.21 +  for (base = 0x40000000; base < 0x40001000; base += 0x100)
   10.22 +  {
   10.23 +    __cpuid(cpuid_output, 0x40000000);
   10.24 +    *(ULONG*)(xensig + 0) = cpuid_output[1];
   10.25 +    *(ULONG*)(xensig + 4) = cpuid_output[2];
   10.26 +    *(ULONG*)(xensig + 8) = cpuid_output[3];
   10.27 +    xensig[12] = '\0';
   10.28 +    KdPrint((__DRIVER_NAME "     base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]));
   10.29 +    if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2))
   10.30 +      break;
   10.31 +  }
   10.32 +  if (base >= 0x40001000)
   10.33 +  {
   10.34 +    KdPrint((__DRIVER_NAME "     Cannot find Xen signature\n"));
   10.35 +    return STATUS_UNSUCCESSFUL;
   10.36 +  }
   10.37  
   10.38 -  __cpuid(cpuid_output, 0x40000002);
   10.39 +  __cpuid(cpuid_output, base + 2);
   10.40    pages = cpuid_output[0];
   10.41    msr = cpuid_output[1];
   10.42  
    11.1 --- a/xenpci/xenbus.c	Wed Feb 18 22:18:23 2009 +1100
    11.2 +++ b/xenpci/xenbus.c	Tue Mar 03 09:51:24 2009 +1100
    11.3 @@ -731,25 +731,14 @@ XenBus_RemWatch(
    11.4  
    11.5    for (i = 0; i < MAX_WATCH_ENTRIES; i++)
    11.6    {
    11.7 -#if 0
    11.8 -    if (xpdd->XenBus_WatchEntries[i].Active)
    11.9 -    {
   11.10 -    KdPrint((__DRIVER_NAME "     (%d == 1) = %d\n", xpdd->XenBus_WatchEntries[i].Active, xpdd->XenBus_WatchEntries[i].Active == 1));
   11.11 -    KdPrint((__DRIVER_NAME "     strcmp(%s, %s) = %d\n", xpdd->XenBus_WatchEntries[i].Path, Path, strcmp(xpdd->XenBus_WatchEntries[i].Path, Path)));
   11.12 -    KdPrint((__DRIVER_NAME "     (%p == %p) = %d\n", xpdd->XenBus_WatchEntries[i].ServiceRoutine, ServiceRoutine, xpdd->XenBus_WatchEntries[i].ServiceRoutine == ServiceRoutine));
   11.13 -    KdPrint((__DRIVER_NAME "     (%p == %p) = %d\n", xpdd->XenBus_WatchEntries[i].ServiceContext, ServiceContext, xpdd->XenBus_WatchEntries[i].ServiceContext == ServiceContext));
   11.14 -#endif
   11.15 -    if (xpdd->XenBus_WatchEntries[i].Active == 1
   11.16 -      && strcmp(xpdd->XenBus_WatchEntries[i].Path, Path) == 0
   11.17 +    if (xpdd->XenBus_WatchEntries[i].Active
   11.18 +      && !strcmp(xpdd->XenBus_WatchEntries[i].Path, Path)
   11.19        && xpdd->XenBus_WatchEntries[i].ServiceRoutine == ServiceRoutine
   11.20        && xpdd->XenBus_WatchEntries[i].ServiceContext == ServiceContext)
   11.21      {
   11.22        KdPrint((__DRIVER_NAME "     Match\n"));
   11.23        break;
   11.24      }
   11.25 -#if 0
   11.26 -    }
   11.27 -#endif
   11.28    }
   11.29  
   11.30    if (i == MAX_WATCH_ENTRIES)
    12.1 --- a/xenpci/xenpci.c	Wed Feb 18 22:18:23 2009 +1100
    12.2 +++ b/xenpci/xenpci.c	Tue Mar 03 09:51:24 2009 +1100
    12.3 @@ -27,6 +27,32 @@ Foundation, Inc., 51 Franklin Street, Fi
    12.4  
    12.5  #pragma warning(disable : 4200) // zero-sized array
    12.6  
    12.7 +static VOID
    12.8 +XenPci_EvtDeviceUsageNotification(WDFDEVICE device, WDF_SPECIAL_FILE_TYPE notification_type, BOOLEAN is_in_notification_path)
    12.9 +{
   12.10 +  FUNCTION_ENTER();
   12.11 +  
   12.12 +  UNREFERENCED_PARAMETER(device);
   12.13 +
   12.14 +  switch (notification_type)
   12.15 +  {
   12.16 +  case WdfSpecialFilePaging:
   12.17 +    KdPrint((__DRIVER_NAME "     notification_type = Paging, flag = %d\n", is_in_notification_path));
   12.18 +    break;
   12.19 +  case WdfSpecialFileHibernation:
   12.20 +    KdPrint((__DRIVER_NAME "     notification_type = Hibernation, flag = %d\n", is_in_notification_path));
   12.21 +    break;
   12.22 +  case WdfSpecialFileDump:
   12.23 +    KdPrint((__DRIVER_NAME "     notification_type = Dump, flag = %d\n", is_in_notification_path));
   12.24 +    break;
   12.25 +  default:
   12.26 +    KdPrint((__DRIVER_NAME "     notification_type = %d, flag = %d\n", notification_type, is_in_notification_path));
   12.27 +    break;
   12.28 +  }
   12.29 +
   12.30 +  FUNCTION_EXIT();  
   12.31 +}
   12.32 +
   12.33  static NTSTATUS
   12.34  XenPci_EvtDeviceAdd(WDFDRIVER driver, PWDFDEVICE_INIT device_init)
   12.35  {
   12.36 @@ -46,6 +72,9 @@ XenPci_EvtDeviceAdd(WDFDRIVER driver, PW
   12.37    WDF_OBJECT_ATTRIBUTES file_attributes;
   12.38    WDF_FILEOBJECT_CONFIG file_config;
   12.39    WDF_IO_QUEUE_CONFIG queue_config;
   12.40 +  WDFKEY param_key;
   12.41 +  DECLARE_CONST_UNICODE_STRING(veto_devices_name, L"veto_devices");
   12.42 +  WDF_DEVICE_POWER_CAPABILITIES power_capabilities;
   12.43    
   12.44    UNREFERENCED_PARAMETER(driver);
   12.45  
   12.46 @@ -59,7 +88,8 @@ XenPci_EvtDeviceAdd(WDFDRIVER driver, PW
   12.47    pnp_power_callbacks.EvtDevicePrepareHardware = XenPci_EvtDevicePrepareHardware;
   12.48    pnp_power_callbacks.EvtDeviceReleaseHardware = XenPci_EvtDeviceReleaseHardware;
   12.49    pnp_power_callbacks.EvtDeviceQueryRemove = XenPci_EvtDeviceQueryRemove;
   12.50 -  
   12.51 +  pnp_power_callbacks.EvtDeviceUsageNotification = XenPci_EvtDeviceUsageNotification;
   12.52 +
   12.53    WdfDeviceInitSetPnpPowerEventCallbacks(device_init, &pnp_power_callbacks);
   12.54  
   12.55    WdfDeviceInitSetDeviceType(device_init, FILE_DEVICE_BUS_EXTENDER);
   12.56 @@ -74,16 +104,47 @@ XenPci_EvtDeviceAdd(WDFDRIVER driver, PW
   12.57    WdfDeviceInitSetFileObjectConfig(device_init, &file_config, &file_attributes);
   12.58    
   12.59    WdfDeviceInitSetIoType(device_init, WdfDeviceIoBuffered);
   12.60 +
   12.61 +  WdfDeviceInitSetPowerNotPageable(device_init);
   12.62    
   12.63    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&device_attributes, XENPCI_DEVICE_DATA);
   12.64    status = WdfDeviceCreate(&device_init, &device_attributes, &device);
   12.65 -  if (!NT_SUCCESS(status)) {
   12.66 -      KdPrint(("Error creating device 0x%x\n", status));
   12.67 -      return status;
   12.68 +  if (!NT_SUCCESS(status))
   12.69 +  {
   12.70 +    KdPrint(("Error creating device %08x\n", status));
   12.71 +    return status;
   12.72    }
   12.73  
   12.74    xpdd = GetXpdd(device);
   12.75  
   12.76 +  WdfCollectionCreate(WDF_NO_OBJECT_ATTRIBUTES, &xpdd->veto_devices);
   12.77 +  status = WdfDriverOpenParametersRegistryKey(driver, KEY_QUERY_VALUE, WDF_NO_OBJECT_ATTRIBUTES, &param_key);
   12.78 +  if (NT_SUCCESS(status))
   12.79 +  {
   12.80 +    status = WdfRegistryQueryMultiString(param_key, &veto_devices_name, WDF_NO_OBJECT_ATTRIBUTES, xpdd->veto_devices);
   12.81 +    if (!NT_SUCCESS(status))
   12.82 +    {
   12.83 +      KdPrint(("Error reading parameters/veto_devices value %08x\n", status));
   12.84 +    }
   12.85 +    WdfRegistryClose(param_key);
   12.86 +  }
   12.87 +  else
   12.88 +  {
   12.89 +    KdPrint(("Error opening parameters key %08x\n", status));
   12.90 +  }
   12.91 +  
   12.92 +  WDF_DEVICE_POWER_CAPABILITIES_INIT(&power_capabilities);
   12.93 +  power_capabilities.DeviceD1 = WdfTrue;
   12.94 +  power_capabilities.WakeFromD1 = WdfTrue;
   12.95 +  power_capabilities.DeviceWake = PowerDeviceD1;
   12.96 +  power_capabilities.DeviceState[PowerSystemWorking]   = PowerDeviceD1;
   12.97 +  power_capabilities.DeviceState[PowerSystemSleeping1] = PowerDeviceD1;
   12.98 +  power_capabilities.DeviceState[PowerSystemSleeping2] = PowerDeviceD2;
   12.99 +  power_capabilities.DeviceState[PowerSystemSleeping3] = PowerDeviceD2;
  12.100 +  power_capabilities.DeviceState[PowerSystemHibernate] = PowerDeviceD3;
  12.101 +  power_capabilities.DeviceState[PowerSystemShutdown]  = PowerDeviceD3;
  12.102 +  WdfDeviceSetPowerCapabilities(device, &power_capabilities);  
  12.103 +
  12.104    WdfDeviceSetSpecialFileSupport(device, WdfSpecialFilePaging, TRUE);
  12.105    WdfDeviceSetSpecialFileSupport(device, WdfSpecialFileHibernation, TRUE);
  12.106    WdfDeviceSetSpecialFileSupport(device, WdfSpecialFileDump, TRUE);
  12.107 @@ -179,11 +240,85 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  12.108    char Buf[300];// Sometimes bigger then 200 if system reboot from crash
  12.109    ULONG BufLen = 300;
  12.110    PKEY_VALUE_PARTIAL_INFORMATION KeyPartialValue;
  12.111 +  WDFCOLLECTION old_load_order, new_load_order;
  12.112 +  DECLARE_CONST_UNICODE_STRING(sgo_name, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder");
  12.113 +  DECLARE_CONST_UNICODE_STRING(list_name, L"List");
  12.114 +  WDFKEY sgo_key;
  12.115  
  12.116    UNREFERENCED_PARAMETER(RegistryPath);
  12.117  
  12.118    FUNCTION_ENTER();
  12.119  
  12.120 +  WdfCollectionCreate(WDF_NO_OBJECT_ATTRIBUTES, &old_load_order);
  12.121 +  WdfCollectionCreate(WDF_NO_OBJECT_ATTRIBUTES, &new_load_order);
  12.122 +  status = WdfRegistryOpenKey(NULL, &sgo_name, KEY_QUERY_VALUE, WDF_NO_OBJECT_ATTRIBUTES, &sgo_key);
  12.123 +  if (NT_SUCCESS(status))
  12.124 +  {
  12.125 +    status = WdfRegistryQueryMultiString(sgo_key, &list_name, WDF_NO_OBJECT_ATTRIBUTES, old_load_order);
  12.126 +    if (!NT_SUCCESS(status))
  12.127 +    {
  12.128 +      KdPrint((__DRIVER_NAME "     Error reading ServiceGroupOrder\\List value %08x\n", status));
  12.129 +    }
  12.130 +    else
  12.131 +    {
  12.132 +      ULONG i;
  12.133 +      LONG boot_bus_extender_index = -1;
  12.134 +      LONG wdf_load_group_index = -1;
  12.135 +      DECLARE_CONST_UNICODE_STRING(wdf_load_group_name, L"WdfLoadGroup");
  12.136 +      DECLARE_CONST_UNICODE_STRING(boot_bus_extender_name, L"Boot Bus Extender");
  12.137 +      KdPrint((__DRIVER_NAME "     Current Order:\n"));        
  12.138 +      for (i = 0; i < WdfCollectionGetCount(old_load_order); i++)
  12.139 +      {
  12.140 +        WDFOBJECT ws = WdfCollectionGetItem(old_load_order, i);
  12.141 +        UNICODE_STRING val;
  12.142 +        WdfStringGetUnicodeString(ws, &val);
  12.143 +        if (!RtlCompareUnicodeString(&val, &wdf_load_group_name, TRUE))
  12.144 +          wdf_load_group_index = (ULONG)i;
  12.145 +        if (!RtlCompareUnicodeString(&val, &boot_bus_extender_name, TRUE))
  12.146 +          boot_bus_extender_index = (ULONG)i;         
  12.147 +        KdPrint((__DRIVER_NAME "       %wZ\n", &val));        
  12.148 +      }
  12.149 +      KdPrint((__DRIVER_NAME "     wdf_load_group_index = %d\n", wdf_load_group_index));
  12.150 +      KdPrint((__DRIVER_NAME "     boot_bus_extender_index = %d\n", boot_bus_extender_index));
  12.151 +      if (boot_bus_extender_index >= 0 && wdf_load_group_index >= 0
  12.152 +          && boot_bus_extender_index < wdf_load_group_index)
  12.153 +      {
  12.154 +        for (i = 0; i < WdfCollectionGetCount(old_load_order); i++)
  12.155 +        {
  12.156 +          UNICODE_STRING val;
  12.157 +          WDFOBJECT ws;
  12.158 +          if (i == (ULONG)wdf_load_group_index)
  12.159 +            continue;
  12.160 +          ws = WdfCollectionGetItem(old_load_order, i);
  12.161 +          WdfStringGetUnicodeString(ws, &val);
  12.162 +          if (i == (ULONG)boot_bus_extender_index)
  12.163 +          {
  12.164 +            WDFSTRING wdf_load_group_val;
  12.165 +            WdfStringCreate(&wdf_load_group_name, WDF_NO_OBJECT_ATTRIBUTES, &wdf_load_group_val);
  12.166 +            WdfCollectionAdd(new_load_order, wdf_load_group_val);
  12.167 +          }
  12.168 +          WdfCollectionAdd(new_load_order, ws);
  12.169 +        }
  12.170 +        KdPrint((__DRIVER_NAME "     New Order:\n"));        
  12.171 +        for (i = 0; i < WdfCollectionGetCount(new_load_order); i++)
  12.172 +        {
  12.173 +          WDFOBJECT ws = WdfCollectionGetItem(new_load_order, i);
  12.174 +          UNICODE_STRING val;
  12.175 +          WdfStringGetUnicodeString(ws, &val);
  12.176 +          KdPrint((__DRIVER_NAME "       %wZ\n", &val));        
  12.177 +        }
  12.178 +        WdfRegistryAssignMultiString(sgo_key, &list_name, new_load_order);
  12.179 +      }
  12.180 +    }
  12.181 +    WdfRegistryClose(sgo_key);
  12.182 +  }
  12.183 +  else
  12.184 +  {
  12.185 +    KdPrint((__DRIVER_NAME "     Error opening ServiceGroupOrder key %08x\n", status));
  12.186 +  }
  12.187 +  WdfObjectDelete(new_load_order);
  12.188 +  WdfObjectDelete(old_load_order);
  12.189 +
  12.190    //TestStuff();  
  12.191    RtlInitUnicodeString(&RegKeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control");
  12.192    InitializeObjectAttributes(&RegObjectAttributes, &RegKeyName, OBJ_CASE_INSENSITIVE, NULL, NULL);
    13.1 --- a/xenpci/xenpci.h	Wed Feb 18 22:18:23 2009 +1100
    13.2 +++ b/xenpci/xenpci.h	Tue Mar 03 09:51:24 2009 +1100
    13.3 @@ -189,8 +189,11 @@ typedef struct {
    13.4  
    13.5    BOOLEAN removable;
    13.6    
    13.7 +  BOOLEAN hibernated;
    13.8 +  
    13.9    WDFQUEUE io_queue;
   13.10  
   13.11 +  WDFCOLLECTION veto_devices;
   13.12  #if 0
   13.13    KSPIN_LOCK mmio_freelist_lock;
   13.14    PPFN_NUMBER mmio_freelist_base;
   13.15 @@ -218,6 +221,7 @@ typedef struct {
   13.16    //PVOID xenbus_request;
   13.17    KEVENT backend_state_event;
   13.18    ULONG backend_state;
   13.19 +  ULONG frontend_state;
   13.20    PHYSICAL_ADDRESS config_page_phys;
   13.21    ULONG config_page_length;
   13.22    PUCHAR requested_resources_start;
   13.23 @@ -227,6 +231,8 @@ typedef struct {
   13.24    XENPCI_DEVICE_STATE device_state;
   13.25    BOOLEAN restart_on_resume;
   13.26    
   13.27 +  BOOLEAN hiber_usage_kludge;
   13.28 +  
   13.29  } XENPCI_PDO_DEVICE_DATA, *PXENPCI_PDO_DEVICE_DATA;
   13.30  
   13.31  WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENPCI_PDO_DEVICE_DATA, GetXppdd)
   13.32 @@ -238,22 +244,80 @@ typedef struct {
   13.33    ULONG index;
   13.34  } XENPCI_PDO_IDENTIFICATION_DESCRIPTION, *PXENPCI_PDO_IDENTIFICATION_DESCRIPTION;
   13.35  
   13.36 +#if 0
   13.37 +kd> dt _ADAPTER_OBJECT 81e96b08 -v
   13.38 +hal!_ADAPTER_OBJECT
   13.39 +struct _ADAPTER_OBJECT, 26 elements, 0x64 bytes
   13.40 +   +0x000 DmaHeader        : struct _DMA_ADAPTER, 3 elements, 0x8 bytes
   13.41 +   +0x008 MasterAdapter    : (null) 
   13.42 +   +0x00c MapRegistersPerChannel : 0x80001
   13.43 +   +0x010 AdapterBaseVa    : (null) 
   13.44 +   +0x014 MapRegisterBase  : (null) 
   13.45 +   +0x018 NumberOfMapRegisters : 0
   13.46 +   +0x01c CommittedMapRegisters : 0
   13.47 +   +0x020 CurrentWcb       : (null) 
   13.48 +   +0x024 ChannelWaitQueue : struct _KDEVICE_QUEUE, 5 elements, 0x14 bytes
   13.49 +   +0x038 RegisterWaitQueue : (null) 
   13.50 +   +0x03c AdapterQueue     : struct _LIST_ENTRY, 2 elements, 0x8 bytes
   13.51 + [ 0x0 - 0x0 ]
   13.52 +   +0x044 SpinLock         : 0
   13.53 +   +0x048 MapRegisters     : (null) 
   13.54 +   +0x04c PagePort         : (null) 
   13.55 +   +0x050 ChannelNumber    : 0xff ''
   13.56 +   +0x051 AdapterNumber    : 0 ''
   13.57 +   +0x052 DmaPortAddress   : 0
   13.58 +   +0x054 AdapterMode      : 0 ''
   13.59 +   +0x055 NeedsMapRegisters : 0 ''
   13.60 +   +0x056 MasterDevice     : 0x1 ''
   13.61 +   +0x057 Width16Bits      : 0 ''
   13.62 +   +0x058 ScatterGather    : 0x1 ''
   13.63 +   +0x059 IgnoreCount      : 0 ''
   13.64 +   +0x05a Dma32BitAddresses : 0x1 ''
   13.65 +   +0x05b Dma64BitAddresses : 0 ''
   13.66 +   +0x05c AdapterList      : struct _LIST_ENTRY, 2 elements, 0x8 bytes
   13.67 + [ 0x806e1250 - 0x81f1b474 ]
   13.68 +#endif
   13.69 +
   13.70 +/* need to confirm that this is the same for AMD64 too */
   13.71  typedef struct {
   13.72 -  DMA_ADAPTER dma_adapter;
   13.73 +  DMA_ADAPTER DmaHeader;
   13.74 +  PVOID MasterAdapter;
   13.75 +  ULONG MapRegistersPerChannel;
   13.76 +  PVOID AdapterBaseVa;
   13.77 +  PVOID MapRegisterBase;
   13.78 +  ULONG NumberOfMapRegisters;
   13.79 +  ULONG CommittedMapRegisters;
   13.80 +  PVOID CurrentWcb;
   13.81 +  KDEVICE_QUEUE ChannelWaitQueue;
   13.82 +  PKDEVICE_QUEUE RegisterWaitQueue;
   13.83 +  LIST_ENTRY AdapterQueue;
   13.84 +  KSPIN_LOCK SpinLock;
   13.85 +  PVOID MapRegisters;
   13.86 +  PVOID PagePort;
   13.87 +  UCHAR ChannelNumber;
   13.88 +  UCHAR AdapterNumber;
   13.89 +  USHORT DmaPortAddress;
   13.90 +  UCHAR AdapterMode;
   13.91 +  BOOLEAN NeedsMapRegisters;
   13.92 +  BOOLEAN MasterDevice;
   13.93 +  UCHAR Width16Bits;
   13.94 +  BOOLEAN ScatterGather;
   13.95 +  BOOLEAN IgnoreCount;
   13.96 +  BOOLEAN Dma32BitAddresses;
   13.97 +  BOOLEAN Dma64BitAddresses;
   13.98 +#if (NTDDI_VERSION >= NTDDI_WS03)
   13.99 +  BOOLEAN LegacyAdapter;
  13.100 +#endif
  13.101 +  LIST_ENTRY AdapterList;
  13.102 +} X_ADAPTER_OBJECT;
  13.103 +  
  13.104 +typedef struct {
  13.105 +  X_ADAPTER_OBJECT adapter_object;
  13.106    PXENPCI_PDO_DEVICE_DATA xppdd;
  13.107    dma_driver_extension_t *dma_extension;
  13.108    PDRIVER_OBJECT dma_extension_driver; /* to deference it */
  13.109  } xen_dma_adapter_t;
  13.110  
  13.111 -#if 0
  13.112 -typedef struct
  13.113 -{
  13.114 -  LIST_ENTRY entry;
  13.115 -  int state;
  13.116 -  PXENPCI_PDO_DEVICE_DATA context;
  13.117 -} XEN_CHILD, *PXEN_CHILD;
  13.118 -#endif
  13.119 -
  13.120  #define XEN_INTERFACE_VERSION 1
  13.121  
  13.122  #define DEVICE_INTERFACE_TYPE_LEGACY 0
    14.1 --- a/xenpci/xenpci.inx	Wed Feb 18 22:18:23 2009 +1100
    14.2 +++ b/xenpci/xenpci.inx	Tue Mar 03 09:51:24 2009 +1100
    14.3 @@ -47,6 +47,7 @@ StartType      = 0
    14.4  ErrorControl   = 1
    14.5  LoadOrderGroup = Boot Bus Extender
    14.6  ServiceBinary  = %12%\xenpci.sys
    14.7 +AddReg         = XenPci_Service_AddReg
    14.8  
    14.9  [XenHide_Service]
   14.10  DisplayName    = %XenHide.SVCDESC%
   14.11 @@ -57,6 +58,10 @@ LoadOrderGroup = System Bus Extender
   14.12  ServiceBinary  = %12%\xenhide.sys
   14.13  DelReg         = XenHide_Service_DelReg
   14.14  
   14.15 +[XenPci_Service_AddReg]
   14.16 +HKR,"Parameters", "veto_devices", 0x00010008, "console"
   14.17 +HKR,"Parameters", "veto_devices", 0x00010008, "vfb"
   14.18 +
   14.19  [XenHide_Service_DelReg]
   14.20  HKLM,SYSTEM\CurrentControlSet\Control\Class\{4D36E97D-E325-11CE-BFC1-08002BE10318},UpperFilters
   14.21  
    15.1 --- a/xenpci/xenpci_fdo.c	Wed Feb 18 22:18:23 2009 +1100
    15.2 +++ b/xenpci/xenpci_fdo.c	Tue Mar 03 09:51:24 2009 +1100
    15.3 @@ -363,7 +363,7 @@ XenPci_DeviceWatchHandler(char *path, PV
    15.4    char *value;
    15.5    PXENPCI_DEVICE_DATA xpdd = context;
    15.6  
    15.7 -  FUNCTION_ENTER();
    15.8 +  //FUNCTION_ENTER();
    15.9  
   15.10    bits = SplitString(path, '/', 4, &count);
   15.11    if (count == 3)
   15.12 @@ -384,7 +384,7 @@ XenPci_DeviceWatchHandler(char *path, PV
   15.13    }
   15.14    FreeSplitString(bits, count);
   15.15  
   15.16 -  FUNCTION_EXIT();
   15.17 +  //FUNCTION_EXIT();
   15.18  }
   15.19  
   15.20  NTSTATUS
   15.21 @@ -467,9 +467,34 @@ XenPci_EvtDeviceD0Entry(WDFDEVICE device
   15.22    NTSTATUS status = STATUS_SUCCESS;
   15.23    PXENPCI_DEVICE_DATA xpdd = GetXpdd(device);
   15.24  
   15.25 -  UNREFERENCED_PARAMETER(previous_state);
   15.26 +  FUNCTION_ENTER();
   15.27  
   15.28 -  FUNCTION_ENTER();
   15.29 +  xpdd->hibernated = FALSE;
   15.30 +
   15.31 +  switch (previous_state)
   15.32 +  {
   15.33 +  case WdfPowerDeviceD0:
   15.34 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   15.35 +    break;
   15.36 +  case WdfPowerDeviceD1:
   15.37 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   15.38 +    break;
   15.39 +  case WdfPowerDeviceD2:
   15.40 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
   15.41 +    break;
   15.42 +  case WdfPowerDeviceD3:
   15.43 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
   15.44 +    break;
   15.45 +  case WdfPowerDeviceD3Final:
   15.46 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
   15.47 +    break;
   15.48 +  case WdfPowerDevicePrepareForHibernation:
   15.49 +    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
   15.50 +    break;  
   15.51 +  default:
   15.52 +    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", previous_state));
   15.53 +    break;  
   15.54 +  }
   15.55    
   15.56    XenPci_Init(xpdd);
   15.57    if (tpr_patch_requested && !xpdd->tpr_patched)
   15.58 @@ -534,9 +559,34 @@ XenPci_EvtDeviceD0ExitPreInterruptsDisab
   15.59    NTSTATUS status = STATUS_SUCCESS;
   15.60    
   15.61    UNREFERENCED_PARAMETER(device);
   15.62 -  UNREFERENCED_PARAMETER(target_state);
   15.63    
   15.64    FUNCTION_ENTER();
   15.65 +  
   15.66 +  switch (target_state)
   15.67 +  {
   15.68 +  case WdfPowerDeviceD0:
   15.69 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   15.70 +    break;
   15.71 +  case WdfPowerDeviceD1:
   15.72 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   15.73 +    break;
   15.74 +  case WdfPowerDeviceD2:
   15.75 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
   15.76 +    break;
   15.77 +  case WdfPowerDeviceD3:
   15.78 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
   15.79 +    break;
   15.80 +  case WdfPowerDeviceD3Final:
   15.81 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
   15.82 +    break;
   15.83 +  case WdfPowerDevicePrepareForHibernation:
   15.84 +    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
   15.85 +    break;
   15.86 +  default:
   15.87 +    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", target_state));
   15.88 +    break;  
   15.89 +  }
   15.90 +  
   15.91    FUNCTION_EXIT();
   15.92    
   15.93    return status;
   15.94 @@ -546,11 +596,36 @@ NTSTATUS
   15.95  XenPci_EvtDeviceD0Exit(WDFDEVICE device, WDF_POWER_DEVICE_STATE target_state)
   15.96  {
   15.97    NTSTATUS status = STATUS_SUCCESS;
   15.98 -  
   15.99 -  UNREFERENCED_PARAMETER(device);
  15.100 -  UNREFERENCED_PARAMETER(target_state);
  15.101 +  PXENPCI_DEVICE_DATA xpdd = GetXpdd(device);
  15.102    
  15.103    FUNCTION_ENTER();
  15.104 +
  15.105 +  switch (target_state)
  15.106 +  {
  15.107 +  case WdfPowerDeviceD0:
  15.108 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
  15.109 +    break;
  15.110 +  case WdfPowerDeviceD1:
  15.111 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
  15.112 +    break;
  15.113 +  case WdfPowerDeviceD2:
  15.114 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
  15.115 +    break;
  15.116 +  case WdfPowerDeviceD3:
  15.117 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
  15.118 +    break;
  15.119 +  case WdfPowerDeviceD3Final:
  15.120 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
  15.121 +    break;
  15.122 +  case WdfPowerDevicePrepareForHibernation:
  15.123 +    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
  15.124 +    xpdd->hibernated = TRUE;
  15.125 +    break;  
  15.126 +  default:
  15.127 +    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", target_state));
  15.128 +    break;  
  15.129 +  }
  15.130 +
  15.131    FUNCTION_EXIT();
  15.132    
  15.133    return status;
  15.134 @@ -578,7 +653,7 @@ XenPci_EvtChildListScanForChildren(WDFCH
  15.135    char *msg;
  15.136    char **devices;
  15.137    char **instances;
  15.138 -  int i, j;
  15.139 +  ULONG i, j;
  15.140    CHAR path[128];
  15.141    XENPCI_PDO_IDENTIFICATION_DESCRIPTION child_description;
  15.142    
  15.143 @@ -592,6 +667,27 @@ XenPci_EvtChildListScanForChildren(WDFCH
  15.144      for (i = 0; devices[i]; i++)
  15.145      {
  15.146        RtlStringCbPrintfA(path, ARRAY_SIZE(path), "device/%s", devices[i]);
  15.147 +      
  15.148 +      for (j = 0; j < WdfCollectionGetCount(xpdd->veto_devices); j++)
  15.149 +      {
  15.150 +        WDFOBJECT ws = WdfCollectionGetItem(xpdd->veto_devices, j);
  15.151 +        UNICODE_STRING val;
  15.152 +        ANSI_STRING s;
  15.153 +        WdfStringGetUnicodeString(ws, &val);
  15.154 +        RtlUnicodeStringToAnsiString(&s, &val, TRUE);
  15.155 +        if (!strcmp(devices[i], s.Buffer))
  15.156 +        {
  15.157 +          RtlFreeAnsiString(&s);
  15.158 +          break;
  15.159 +        }
  15.160 +        RtlFreeAnsiString(&s);
  15.161 +      }
  15.162 +      if (j < WdfCollectionGetCount(xpdd->veto_devices))
  15.163 +      {
  15.164 +        XenPci_FreeMem(devices[i]);
  15.165 +        continue;
  15.166 +      }
  15.167 +    
  15.168        msg = XenBus_List(xpdd, XBT_NIL, path, &instances);
  15.169        if (!msg)
  15.170        {
    16.1 --- a/xenpci/xenpci_pdo.c	Wed Feb 18 22:18:23 2009 +1100
    16.2 +++ b/xenpci/xenpci_pdo.c	Tue Mar 03 09:51:24 2009 +1100
    16.3 @@ -77,7 +77,7 @@ XenPci_DOP_PutDmaAdapter(PDMA_ADAPTER dm
    16.4  
    16.5    if (xen_dma_adapter->dma_extension)
    16.6      ObDereferenceObject(xen_dma_adapter->dma_extension_driver);
    16.7 -  ExFreePoolWithTag(xen_dma_adapter->dma_adapter.DmaOperations, XENPCI_POOL_TAG);
    16.8 +  ExFreePoolWithTag(xen_dma_adapter->adapter_object.DmaHeader.DmaOperations, XENPCI_POOL_TAG);
    16.9    ExFreePoolWithTag(xen_dma_adapter, XENPCI_POOL_TAG);
   16.10    
   16.11    FUNCTION_EXIT();
   16.12 @@ -109,11 +109,12 @@ XenPci_DOP_AllocateCommonBuffer(
   16.13    //KdPrint((__DRIVER_NAME "     Length = %d\n", Length));
   16.14    
   16.15    buffer = ExAllocatePoolWithTag(NonPagedPool, Length, XENPCI_POOL_TAG);
   16.16 +  ASSERT(buffer); /* lazy */
   16.17  
   16.18    pfn = (PFN_NUMBER)(MmGetPhysicalAddress(buffer).QuadPart >> PAGE_SHIFT);
   16.19 -  ASSERT(pfn);
   16.20 +  ASSERT(pfn); /* lazy */
   16.21    gref = (grant_ref_t)GntTbl_GrantAccess(xpdd, 0, (ULONG)pfn, FALSE, INVALID_GRANT_REF);
   16.22 -  ASSERT(gref);
   16.23 +  ASSERT(gref); /* lazy */
   16.24    LogicalAddress->QuadPart = (gref << PAGE_SHIFT) | (PtrToUlong(buffer) & (PAGE_SIZE - 1));
   16.25    
   16.26    //FUNCTION_EXIT();
   16.27 @@ -170,7 +171,7 @@ XenPci_DOP_AllocateAdapterChannel(
   16.28    if (!map_register_base)
   16.29    {
   16.30      KdPrint((__DRIVER_NAME "     Cannot allocate memory for map_register_base\n"));
   16.31 -    FUNCTION_EXIT();
   16.32 +    //FUNCTION_EXIT();
   16.33      return STATUS_INSUFFICIENT_RESOURCES;
   16.34    }
   16.35    /* we should also allocate a single page of memory here for remap purposes as once we allocate the map registers there is no failure allowed */
   16.36 @@ -380,6 +381,7 @@ XenPci_DOP_MapTransfer(
   16.37      break;
   16.38    }
   16.39    
   16.40 +  //KdPrint((__DRIVER_NAME "     logical = %08x:%08x\n", map_register->logical.HighPart, map_register->logical.LowPart));
   16.41    //FUNCTION_EXIT();
   16.42    return map_register->logical;
   16.43  }
   16.44 @@ -554,6 +556,8 @@ XenPci_DOP_BuildScatterGatherList(
   16.45    grant_ref_t gref;
   16.46    //PUCHAR StartVa;
   16.47    
   16.48 +  //FUNCTION_ENTER();
   16.49 +  
   16.50    ASSERT(MmGetMdlVirtualAddress(Mdl) == CurrentVa);
   16.51  
   16.52    xen_dma_adapter = (xen_dma_adapter_t *)DmaAdapter;
   16.53 @@ -718,38 +722,93 @@ XenPci_BIS_GetDmaAdapter(PVOID context, 
   16.54    KdPrint((__DRIVER_NAME "      MaximumLength = %d\n", device_description->MaximumLength));
   16.55    KdPrint((__DRIVER_NAME "      DmaPort = %d\n", device_description->DmaPort));
   16.56    
   16.57 +  if (!device_description->Master)
   16.58 +    return NULL;
   16.59  /*
   16.60  we have to allocate PAGE_SIZE bytes here because Windows thinks this is
   16.61  actually an ADAPTER_OBJECT, and then the verifier crashes because
   16.62  Windows accessed beyond the end of the structure :(
   16.63  */
   16.64    xen_dma_adapter = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
   16.65 +  ASSERT(xen_dma_adapter);
   16.66    RtlZeroMemory(xen_dma_adapter, PAGE_SIZE);
   16.67 -  xen_dma_adapter->dma_adapter.Version = 2;
   16.68 -  xen_dma_adapter->dma_adapter.Size = sizeof(DMA_ADAPTER); //xen_dma_adapter_t);
   16.69 -  xen_dma_adapter->dma_adapter.DmaOperations = ExAllocatePoolWithTag(NonPagedPool, sizeof(DMA_OPERATIONS), XENPCI_POOL_TAG);
   16.70 -  xen_dma_adapter->dma_adapter.DmaOperations->Size = sizeof(DMA_OPERATIONS);
   16.71 -  xen_dma_adapter->dma_adapter.DmaOperations->PutDmaAdapter = XenPci_DOP_PutDmaAdapter;
   16.72 -  xen_dma_adapter->dma_adapter.DmaOperations->AllocateCommonBuffer = XenPci_DOP_AllocateCommonBuffer;
   16.73 -  xen_dma_adapter->dma_adapter.DmaOperations->FreeCommonBuffer = XenPci_DOP_FreeCommonBuffer;
   16.74 -  xen_dma_adapter->dma_adapter.DmaOperations->AllocateAdapterChannel = XenPci_DOP_AllocateAdapterChannel;
   16.75 -  xen_dma_adapter->dma_adapter.DmaOperations->FlushAdapterBuffers = XenPci_DOP_FlushAdapterBuffers;
   16.76 -  xen_dma_adapter->dma_adapter.DmaOperations->FreeAdapterChannel = XenPci_DOP_FreeAdapterChannel;
   16.77 -  xen_dma_adapter->dma_adapter.DmaOperations->FreeMapRegisters = XenPci_DOP_FreeMapRegisters;
   16.78 -  xen_dma_adapter->dma_adapter.DmaOperations->MapTransfer = XenPci_DOP_MapTransfer;
   16.79 -  xen_dma_adapter->dma_adapter.DmaOperations->GetDmaAlignment = XenPci_DOP_GetDmaAlignment;
   16.80 -  xen_dma_adapter->dma_adapter.DmaOperations->ReadDmaCounter = XenPci_DOP_ReadDmaCounter;
   16.81 -  xen_dma_adapter->dma_adapter.DmaOperations->GetScatterGatherList = XenPci_DOP_GetScatterGatherList;
   16.82 -  xen_dma_adapter->dma_adapter.DmaOperations->PutScatterGatherList = XenPci_DOP_PutScatterGatherList;
   16.83 -  xen_dma_adapter->dma_adapter.DmaOperations->CalculateScatterGatherList = XenPci_DOP_CalculateScatterGatherList;
   16.84 -  xen_dma_adapter->dma_adapter.DmaOperations->BuildScatterGatherList = XenPci_DOP_BuildScatterGatherList;
   16.85 -  xen_dma_adapter->dma_adapter.DmaOperations->BuildMdlFromScatterGatherList = XenPci_DOP_BuildMdlFromScatterGatherList;
   16.86 +  
   16.87 +  switch(device_description->Version)
   16.88 +  {
   16.89 +  case DEVICE_DESCRIPTION_VERSION1:
   16.90 +    xen_dma_adapter->adapter_object.DmaHeader.Version = 1;
   16.91 +    break;
   16.92 +  case DEVICE_DESCRIPTION_VERSION: /* ignore what the docs say here - DEVICE_DESCRIPTION_VERSION appears to mean the latest version */
   16.93 +  case DEVICE_DESCRIPTION_VERSION2:
   16.94 +    xen_dma_adapter->adapter_object.DmaHeader.Version = 2;
   16.95 +    break;
   16.96 +  default:
   16.97 +    KdPrint((__DRIVER_NAME "     Unsupported device description version %d\n", device_description->Version));
   16.98 +    ExFreePoolWithTag(xen_dma_adapter, XENPCI_POOL_TAG);
   16.99 +    return NULL;
  16.100 +  }
  16.101 +    
  16.102 +
  16.103 +  xen_dma_adapter->adapter_object.DmaHeader.Size = sizeof(X_ADAPTER_OBJECT); //xen_dma_adapter_t);
  16.104 +  xen_dma_adapter->adapter_object.MasterAdapter = NULL;
  16.105 +  xen_dma_adapter->adapter_object.MapRegistersPerChannel = 1024;
  16.106 +  xen_dma_adapter->adapter_object.AdapterBaseVa = NULL;
  16.107 +  xen_dma_adapter->adapter_object.MapRegisterBase = NULL;
  16.108 +  xen_dma_adapter->adapter_object.NumberOfMapRegisters = 0;
  16.109 +  xen_dma_adapter->adapter_object.CommittedMapRegisters = 0;
  16.110 +  xen_dma_adapter->adapter_object.CurrentWcb = NULL;
  16.111 +  KeInitializeDeviceQueue(&xen_dma_adapter->adapter_object.ChannelWaitQueue);
  16.112 +  xen_dma_adapter->adapter_object.RegisterWaitQueue = NULL;
  16.113 +  InitializeListHead(&xen_dma_adapter->adapter_object.AdapterQueue);
  16.114 +  KeInitializeSpinLock(&xen_dma_adapter->adapter_object.SpinLock);
  16.115 +  xen_dma_adapter->adapter_object.MapRegisters = NULL;
  16.116 +  xen_dma_adapter->adapter_object.PagePort = NULL;
  16.117 +  xen_dma_adapter->adapter_object.ChannelNumber = 0xff;
  16.118 +  xen_dma_adapter->adapter_object.AdapterNumber = 0;
  16.119 +  xen_dma_adapter->adapter_object.DmaPortAddress = 0;
  16.120 +  xen_dma_adapter->adapter_object.AdapterMode = 0;
  16.121 +  xen_dma_adapter->adapter_object.NeedsMapRegisters = FALSE; /* when true this causes a crash in the crash dump path */
  16.122 +  xen_dma_adapter->adapter_object.MasterDevice = 1;
  16.123 +  xen_dma_adapter->adapter_object.Width16Bits = 0;
  16.124 +  xen_dma_adapter->adapter_object.ScatterGather = device_description->ScatterGather;
  16.125 +  xen_dma_adapter->adapter_object.IgnoreCount = device_description->IgnoreCount;
  16.126 +  xen_dma_adapter->adapter_object.Dma32BitAddresses = device_description->Dma32BitAddresses;
  16.127 +  xen_dma_adapter->adapter_object.Dma64BitAddresses = device_description->Dma64BitAddresses;
  16.128 +  InitializeListHead(&xen_dma_adapter->adapter_object.AdapterList);  
  16.129 +  
  16.130 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations = ExAllocatePoolWithTag(NonPagedPool, sizeof(DMA_OPERATIONS), XENPCI_POOL_TAG);
  16.131 +  ASSERT(xen_dma_adapter->adapter_object.DmaHeader.DmaOperations);
  16.132 +  if (xen_dma_adapter->adapter_object.DmaHeader.Version == 1)
  16.133 +  {
  16.134 +    xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->Size = FIELD_OFFSET(DMA_OPERATIONS, CalculateScatterGatherList);
  16.135 +  }
  16.136 +  else
  16.137 +  {
  16.138 +    xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->Size = sizeof(DMA_OPERATIONS);
  16.139 +  }
  16.140 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->PutDmaAdapter = XenPci_DOP_PutDmaAdapter;
  16.141 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->AllocateCommonBuffer = XenPci_DOP_AllocateCommonBuffer;
  16.142 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->FreeCommonBuffer = XenPci_DOP_FreeCommonBuffer;
  16.143 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->AllocateAdapterChannel = XenPci_DOP_AllocateAdapterChannel;
  16.144 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->FlushAdapterBuffers = XenPci_DOP_FlushAdapterBuffers;
  16.145 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->FreeAdapterChannel = XenPci_DOP_FreeAdapterChannel;
  16.146 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->FreeMapRegisters = XenPci_DOP_FreeMapRegisters;
  16.147 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->MapTransfer = XenPci_DOP_MapTransfer;
  16.148 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->GetDmaAlignment = XenPci_DOP_GetDmaAlignment;
  16.149 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->ReadDmaCounter = XenPci_DOP_ReadDmaCounter;
  16.150 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->GetScatterGatherList = XenPci_DOP_GetScatterGatherList;
  16.151 +  xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->PutScatterGatherList = XenPci_DOP_PutScatterGatherList;
  16.152 +  if (xen_dma_adapter->adapter_object.DmaHeader.Version == 2)
  16.153 +  {
  16.154 +    xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->CalculateScatterGatherList = XenPci_DOP_CalculateScatterGatherList;
  16.155 +    xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->BuildScatterGatherList = XenPci_DOP_BuildScatterGatherList;
  16.156 +    xen_dma_adapter->adapter_object.DmaHeader.DmaOperations->BuildMdlFromScatterGatherList = XenPci_DOP_BuildMdlFromScatterGatherList;
  16.157 +  }
  16.158    xen_dma_adapter->xppdd = context;
  16.159    xen_dma_adapter->dma_extension = NULL;
  16.160  
  16.161    KdPrint((__DRIVER_NAME "     About to call IoGetAttachedDeviceReference\n"));
  16.162    curr = IoGetAttachedDeviceReference(WdfDeviceWdmGetDeviceObject(xen_dma_adapter->xppdd->wdf_device));
  16.163 -  //curr = WdfDeviceWdmGetAttachedDevice(xen_dma_adapter->xppdd->wdf_device);
  16.164    KdPrint((__DRIVER_NAME "     Before start of loop - curr = %p\n", curr));
  16.165    while (curr != NULL)
  16.166    {
  16.167 @@ -780,7 +839,7 @@ Windows accessed beyond the end of the s
  16.168  
  16.169    FUNCTION_EXIT();
  16.170  
  16.171 -  return &xen_dma_adapter->dma_adapter;
  16.172 +  return &xen_dma_adapter->adapter_object.DmaHeader;
  16.173  }
  16.174  
  16.175  static ULONG
  16.176 @@ -897,33 +956,11 @@ XenPci_BackEndStateHandler(char *path, P
  16.177      break;
  16.178  
  16.179    case XenbusStateClosing:
  16.180 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Closing (%s)\n", path));  
  16.181 -    if (xpdd->suspend_state == SUSPEND_STATE_NONE)
  16.182 +    KdPrint((__DRIVER_NAME "     Backend State Changed to Closing (%s)\n", path));
  16.183 +    if (xppdd->frontend_state == XenbusStateConnected)
  16.184      {
  16.185 +      KdPrint((__DRIVER_NAME "     Requesting eject\n"));
  16.186        WdfPdoRequestEject(device);
  16.187 -#if 0
  16.188 -      if (xppdd->common.device_usage_paging
  16.189 -        || xppdd->common.device_usage_dump
  16.190 -        || xppdd->common.device_usage_hibernation)
  16.191 -      {
  16.192 -        KdPrint((__DRIVER_NAME "     Not closing device because it is in use\n"));
  16.193 -        /* in use by page file, dump file, or hiber file - can't close */
  16.194 -        /* we should probably re-check if the device usage changes in the future */
  16.195 -      }
  16.196 -      else
  16.197 -      {
  16.198 -        
  16.199 -        if (xppdd->common.current_pnp_state == Started)
  16.200 -        {
  16.201 -          KdPrint((__DRIVER_NME "     Sending RequestDeviceEject\n"));
  16.202 -          WdfPdoRequestEject(device);
  16.203 -        }
  16.204 -        else
  16.205 -        {
  16.206 -          KdPrint((__DRIVER_NAME "     Not closing device because it is not started\n"));
  16.207 -        }
  16.208 -      }
  16.209 -#endif
  16.210      }
  16.211      break;
  16.212  
  16.213 @@ -1257,6 +1294,8 @@ XenPci_ChangeFrontendState(WDFDEVICE dev
  16.214    char path[128];
  16.215    
  16.216    //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  16.217 +  
  16.218 +  xppdd->frontend_state = frontend_state_set;
  16.219  
  16.220    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->path);
  16.221    XenBus_Printf(xpdd, XBT_NIL, path, "%d", frontend_state_set);
  16.222 @@ -1678,7 +1717,7 @@ XenPciPdo_EvtDeviceWdmIrpPreprocess_STAR
  16.223          if (!NT_SUCCESS(status))
  16.224          {
  16.225            RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  16.226 -          XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  16.227 +          XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, device);
  16.228            FUNCTION_ERROR_EXIT();
  16.229            return status;
  16.230          }
  16.231 @@ -1721,7 +1760,7 @@ XenPciPdo_EvtDeviceResourceRequirementsQ
  16.232    WDFIORESLIST res_list;
  16.233    IO_RESOURCE_DESCRIPTOR ird;
  16.234  
  16.235 -  FUNCTION_ENTER();
  16.236 +  //FUNCTION_ENTER();
  16.237    
  16.238    WdfIoResourceRequirementsListSetInterfaceType(requirements_list, PNPBus);
  16.239    
  16.240 @@ -1748,9 +1787,164 @@ XenPciPdo_EvtDeviceResourceRequirementsQ
  16.241    
  16.242    WdfIoResourceRequirementsListAppendIoResList(requirements_list, res_list);
  16.243  
  16.244 +  //FUNCTION_EXIT();
  16.245 +  
  16.246 +  return STATUS_SUCCESS;
  16.247 +}
  16.248 +
  16.249 +NTSTATUS
  16.250 +XenPciPdo_EvtDeviceD0Entry(WDFDEVICE device, WDF_POWER_DEVICE_STATE previous_state)
  16.251 +{
  16.252 +  NTSTATUS status = STATUS_SUCCESS;
  16.253 +  
  16.254 +  UNREFERENCED_PARAMETER(device);
  16.255 +  UNREFERENCED_PARAMETER(previous_state);
  16.256 +  
  16.257 +  FUNCTION_ENTER();
  16.258 +
  16.259 +  switch (previous_state)
  16.260 +  {
  16.261 +  case WdfPowerDeviceD0:
  16.262 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
  16.263 +    break;
  16.264 +  case WdfPowerDeviceD1:
  16.265 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
  16.266 +    break;
  16.267 +  case WdfPowerDeviceD2:
  16.268 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
  16.269 +    break;
  16.270 +  case WdfPowerDeviceD3:
  16.271 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
  16.272 +    break;
  16.273 +  case WdfPowerDeviceD3Final:
  16.274 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
  16.275 +    break;
  16.276 +  case WdfPowerDevicePrepareForHibernation:
  16.277 +    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
  16.278 +    break;  
  16.279 +  default:
  16.280 +    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", previous_state));
  16.281 +    break;  
  16.282 +  }
  16.283 +
  16.284    FUNCTION_EXIT();
  16.285    
  16.286 -  return STATUS_SUCCESS;
  16.287 +  return status;
  16.288 +}
  16.289 +
  16.290 +NTSTATUS
  16.291 +XenPciPdo_EvtDeviceD0Exit(WDFDEVICE device, WDF_POWER_DEVICE_STATE target_state)
  16.292 +{
  16.293 +  NTSTATUS status = STATUS_SUCCESS;
  16.294 +  PXENPCI_PDO_DEVICE_DATA xppdd = GetXppdd(device);
  16.295 +  PXENPCI_DEVICE_DATA xpdd = GetXpdd(xppdd->wdf_device_bus_fdo);
  16.296 +  char path[128];
  16.297 +  
  16.298 +  UNREFERENCED_PARAMETER(device);
  16.299 +  UNREFERENCED_PARAMETER(target_state);
  16.300 +  
  16.301 +  FUNCTION_ENTER();
  16.302 +
  16.303 +  KdPrint((__DRIVER_NAME "     path = %s\n", xppdd->path));
  16.304 +
  16.305 +  
  16.306 +  switch (target_state)
  16.307 +  {
  16.308 +  case WdfPowerDeviceD0:
  16.309 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
  16.310 +    break;
  16.311 +  case WdfPowerDeviceD1:
  16.312 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
  16.313 +    break;
  16.314 +  case WdfPowerDeviceD2:
  16.315 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD2\n"));
  16.316 +    break;
  16.317 +  case WdfPowerDeviceD3:
  16.318 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
  16.319 +    break;
  16.320 +  case WdfPowerDeviceD3Final:
  16.321 +    KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3Final\n"));
  16.322 +    break;
  16.323 +  case WdfPowerDevicePrepareForHibernation:
  16.324 +    KdPrint((__DRIVER_NAME "     WdfPowerDevicePrepareForHibernation\n"));
  16.325 +    break;  
  16.326 +  default:
  16.327 +    KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", target_state));
  16.328 +    break;  
  16.329 +  }
  16.330 +  
  16.331 +  if (target_state == WdfPowerDevicePrepareForHibernation
  16.332 +      || (target_state == WdfPowerDeviceD3 && xppdd->hiber_usage_kludge))
  16.333 +  {
  16.334 +    KdPrint((__DRIVER_NAME "     not powering down as we are hibernating\n"));
  16.335 +  }
  16.336 +  else
  16.337 +  {
  16.338 +    status = XenPci_XenShutdownDevice(device);
  16.339 +    /* Remove watch on backend state */
  16.340 +    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  16.341 +    XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, device);
  16.342 +  }
  16.343 +  FUNCTION_EXIT();
  16.344 +  
  16.345 +  return status;
  16.346 +}
  16.347 +
  16.348 +NTSTATUS
  16.349 +XenPciPdo_EvtDevicePrepareHardware (WDFDEVICE device, WDFCMRESLIST resources_raw, WDFCMRESLIST resources_translated)
  16.350 +{
  16.351 +  NTSTATUS status = STATUS_SUCCESS;
  16.352 +  
  16.353 +  UNREFERENCED_PARAMETER(device);
  16.354 +  UNREFERENCED_PARAMETER(resources_raw);
  16.355 +  UNREFERENCED_PARAMETER(resources_translated);
  16.356 +  
  16.357 +  FUNCTION_ENTER();
  16.358 +  FUNCTION_EXIT();
  16.359 +  
  16.360 +  return status;
  16.361 +}
  16.362 +
  16.363 +NTSTATUS
  16.364 +XenPciPdo_EvtDeviceReleaseHardware(WDFDEVICE device, WDFCMRESLIST resources_translated)
  16.365 +{
  16.366 +  NTSTATUS status = STATUS_SUCCESS;
  16.367 +  
  16.368 +  UNREFERENCED_PARAMETER(device);
  16.369 +  UNREFERENCED_PARAMETER(resources_translated);
  16.370 +  
  16.371 +  FUNCTION_ENTER();
  16.372 +  FUNCTION_EXIT();
  16.373 +  
  16.374 +  return status;
  16.375 +}
  16.376 +
  16.377 +static VOID
  16.378 +XenPciPdo_EvtDeviceUsageNotification(WDFDEVICE device, WDF_SPECIAL_FILE_TYPE notification_type, BOOLEAN is_in_notification_path)
  16.379 +{
  16.380 +  PXENPCI_PDO_DEVICE_DATA xppdd = GetXppdd(device);
  16.381 +
  16.382 +  FUNCTION_ENTER();
  16.383 +  
  16.384 +  KdPrint((__DRIVER_NAME "     path = %s\n", xppdd->path));
  16.385 +  switch (notification_type)
  16.386 +  {
  16.387 +  case WdfSpecialFilePaging:
  16.388 +    KdPrint((__DRIVER_NAME "     notification_type = Paging, flag = %d\n", is_in_notification_path));
  16.389 +    break;
  16.390 +  case WdfSpecialFileHibernation:
  16.391 +    xppdd->hiber_usage_kludge = is_in_notification_path;
  16.392 +    KdPrint((__DRIVER_NAME "     notification_type = Hibernation, flag = %d\n", is_in_notification_path));
  16.393 +    break;
  16.394 +  case WdfSpecialFileDump:
  16.395 +    KdPrint((__DRIVER_NAME "     notification_type = Dump, flag = %d\n", is_in_notification_path));
  16.396 +    break;
  16.397 +  default:
  16.398 +    KdPrint((__DRIVER_NAME "     notification_type = %d, flag = %d\n", notification_type, is_in_notification_path));
  16.399 +    break;
  16.400 +  }
  16.401 +
  16.402 +  FUNCTION_EXIT();  
  16.403  }
  16.404  
  16.405  NTSTATUS
  16.406 @@ -1770,22 +1964,24 @@ XenPci_EvtChildListCreateDevice(WDFCHILD
  16.407    WDF_QUERY_INTERFACE_CONFIG interface_config;
  16.408    BUS_INTERFACE_STANDARD bus_interface;
  16.409    WDF_PDO_EVENT_CALLBACKS pdo_callbacks;
  16.410 +  WDF_PNPPOWER_EVENT_CALLBACKS child_pnp_power_callbacks;
  16.411    UCHAR pnp_minor_functions[] = { IRP_MN_START_DEVICE };
  16.412 +  WDF_DEVICE_POWER_CAPABILITIES child_power_capabilities;
  16.413    
  16.414    FUNCTION_ENTER();
  16.415  
  16.416    WdfDeviceInitSetDeviceType(child_init, FILE_DEVICE_UNKNOWN);
  16.417    
  16.418 -/*
  16.419    WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&child_pnp_power_callbacks);
  16.420    child_pnp_power_callbacks.EvtDeviceD0Entry = XenPciPdo_EvtDeviceD0Entry;
  16.421 -  child_pnp_power_callbacks.EvtDeviceD0EntryPostInterruptsEnabled = XenPciPdo_EvtDeviceD0EntryPostInterruptsEnabled;
  16.422 +  //child_pnp_power_callbacks.EvtDeviceD0EntryPostInterruptsEnabled = XenPciPdo_EvtDeviceD0EntryPostInterruptsEnabled;
  16.423    child_pnp_power_callbacks.EvtDeviceD0Exit = XenPciPdo_EvtDeviceD0Exit;
  16.424 -  child_pnp_power_callbacks.EvtDeviceD0ExitPreInterruptsDisabled = XenPciPdo_EvtDeviceD0ExitPreInterruptsDisabled;
  16.425 +  //child_pnp_power_callbacks.EvtDeviceD0ExitPreInterruptsDisabled = XenPciPdo_EvtDeviceD0ExitPreInterruptsDisabled;
  16.426    child_pnp_power_callbacks.EvtDevicePrepareHardware = XenPciPdo_EvtDevicePrepareHardware;
  16.427    child_pnp_power_callbacks.EvtDeviceReleaseHardware = XenPciPdo_EvtDeviceReleaseHardware;
  16.428 +  child_pnp_power_callbacks.EvtDeviceUsageNotification = XenPciPdo_EvtDeviceUsageNotification;
  16.429    WdfDeviceInitSetPnpPowerEventCallbacks(child_init, &child_pnp_power_callbacks);
  16.430 -*/
  16.431 +
  16.432    KdPrint((__DRIVER_NAME "     device = '%s', index = '%d', path = '%s'\n",
  16.433      identification->device, identification->index, identification->path));
  16.434    
  16.435 @@ -1834,6 +2030,8 @@ XenPci_EvtChildListCreateDevice(WDFCHILD
  16.436      return status;
  16.437    }
  16.438    WdfPdoInitSetDefaultLocale(child_init, 0x0409);
  16.439 +
  16.440 +  WdfDeviceInitSetPowerNotPageable(child_init);
  16.441    
  16.442    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&child_attributes, XENPCI_PDO_DEVICE_DATA);
  16.443    status = WdfDeviceCreate(&child_init, &child_attributes, &child_device);
  16.444 @@ -1867,8 +2065,17 @@ XenPci_EvtChildListCreateDevice(WDFCHILD
  16.445    child_pnp_capabilities.HardwareDisabled = WdfFalse;
  16.446    WdfDeviceSetPnpCapabilities(child_device, &child_pnp_capabilities);
  16.447  
  16.448 -  //WDF_DEVICE_POWER_CAPABILITIES_INIT(&child_power_capabilities);
  16.449 -  //WdfDeviceSetPowerCapabilities(child_device, &child_power_capabilities);  
  16.450 +  WDF_DEVICE_POWER_CAPABILITIES_INIT(&child_power_capabilities);
  16.451 +  child_power_capabilities.DeviceD1 = WdfTrue;
  16.452 +  child_power_capabilities.WakeFromD1 = WdfTrue;
  16.453 +  child_power_capabilities.DeviceWake = PowerDeviceD1;
  16.454 +  child_power_capabilities.DeviceState[PowerSystemWorking]   = PowerDeviceD1;
  16.455 +  child_power_capabilities.DeviceState[PowerSystemSleeping1] = PowerDeviceD1;
  16.456 +  child_power_capabilities.DeviceState[PowerSystemSleeping2] = PowerDeviceD2;
  16.457 +  child_power_capabilities.DeviceState[PowerSystemSleeping3] = PowerDeviceD2;
  16.458 +  child_power_capabilities.DeviceState[PowerSystemHibernate] = PowerDeviceD3;
  16.459 +  child_power_capabilities.DeviceState[PowerSystemShutdown]  = PowerDeviceD3;
  16.460 +  WdfDeviceSetPowerCapabilities(child_device, &child_power_capabilities);  
  16.461  
  16.462    bus_interface.Size = sizeof(BUS_INTERFACE_STANDARD);
  16.463    bus_interface.Version = 1; //BUS_INTERFACE_STANDARD_VERSION;
  16.464 @@ -1891,6 +2098,7 @@ XenPci_EvtChildListCreateDevice(WDFCHILD
  16.465    xppdd->index = identification->index;
  16.466    KeInitializeEvent(&xppdd->backend_state_event, SynchronizationEvent, FALSE);
  16.467    xppdd->backend_state = XenbusStateUnknown;
  16.468 +  xppdd->frontend_state = XenbusStateUnknown;
  16.469    xppdd->backend_path[0] = '\0';
  16.470      
  16.471    FUNCTION_EXIT();
  16.472 @@ -4378,4 +4586,4 @@ XenPci_SystemControl_Pdo(PDEVICE_OBJECT 
  16.473  
  16.474    return status;
  16.475  }
  16.476 -#endif
  16.477 \ No newline at end of file
  16.478 +#endif
    17.1 --- a/xenscsi/makefile.inc	Wed Feb 18 22:18:23 2009 +1100
    17.2 +++ b/xenscsi/makefile.inc	Tue Mar 03 09:51:24 2009 +1100
    17.3 @@ -1,5 +1,5 @@
    17.4  _LNG=$(LANGUAGE)
    17.5 -STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
    17.6 +STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(GPLPV_VERSION)
    17.7  
    17.8  $(OBJ_PATH)\$(O)\$(TARGETNAME).inf: $(TARGETNAME).inx sources ..\common.inc
    17.9      copy $(@B).inx $@
    18.1 --- a/xenvbd/makefile.inc	Wed Feb 18 22:18:23 2009 +1100
    18.2 +++ b/xenvbd/makefile.inc	Tue Mar 03 09:51:24 2009 +1100
    18.3 @@ -1,5 +1,5 @@
    18.4  _LNG=$(LANGUAGE)
    18.5 -STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
    18.6 +STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(GPLPV_VERSION)
    18.7  
    18.8  $(OBJ_PATH)\$(O)\$(TARGETNAME).inf: $(TARGETNAME).inx sources ..\common.inc
    18.9      copy $(@B).inx $@
    19.1 --- a/xenvbd/xenvbd.c	Wed Feb 18 22:18:23 2009 +1100
    19.2 +++ b/xenvbd/xenvbd.c	Tue Mar 03 09:51:24 2009 +1100
    19.3 @@ -30,11 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fi
    19.4  
    19.5  #pragma warning(disable: 4127)
    19.6  
    19.7 -#ifdef ALLOC_PRAGMA
    19.8 -DRIVER_INITIALIZE DriverEntry;
    19.9 -#pragma alloc_text (INIT, DriverEntry)
   19.10 -#endif
   19.11 -
   19.12  #if defined(__x86_64__)
   19.13    #define LongLongToPtr(x) (PVOID)(x)
   19.14  #else
   19.15 @@ -224,7 +219,8 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
   19.16        qemu_protocol_version = PtrToUlong(value);
   19.17        break;
   19.18      case XEN_INIT_TYPE_GRANT_ENTRIES:
   19.19 -      xvdd->dump_grant_ref = *(grant_ref_t *)value;
   19.20 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - entries = %d\n", PtrToUlong(setting)));
   19.21 +      memcpy(xvdd->dump_grant_refs, value, PtrToUlong(setting) * sizeof(grant_ref_t));
   19.22        break;
   19.23      default:
   19.24        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   19.25 @@ -361,6 +357,8 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   19.26    ULONG block_count;
   19.27    blkif_shadow_t *shadow;
   19.28    ULONG remaining, offset, length;
   19.29 +  grant_ref_t gref;
   19.30 +  ULONG gref_index;
   19.31    PUCHAR ptr;
   19.32    int notify;
   19.33  
   19.34 @@ -388,67 +386,34 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   19.35    //KdPrint((__DRIVER_NAME "     sector_number = %d\n", (ULONG)shadow->req.sector_number));
   19.36    //KdPrint((__DRIVER_NAME "     handle = %d\n", shadow->req.handle));
   19.37    //KdPrint((__DRIVER_NAME "     operation = %d\n", shadow->req.operation));
   19.38 -  if (!dump_mode)
   19.39 -  {
   19.40 -    while (remaining > 0)
   19.41 -    {
   19.42 -      PHYSICAL_ADDRESS physical_address;
   19.43 -      physical_address = ScsiPortGetPhysicalAddress(xvdd, srb, ptr, &length);
   19.44 -      offset = physical_address.LowPart & (PAGE_SIZE - 1);
   19.45 -      if (offset & 511)
   19.46 -      {
   19.47 -        KdPrint((__DRIVER_NAME "     DataTransferLength = %d, remaining = %d, block_count = %d, offset = %d, ptr = %p, srb->DataBuffer = %p\n",
   19.48 -          srb->DataTransferLength, remaining, block_count, offset, ptr, srb->DataBuffer));
   19.49 -        ptr = srb->DataBuffer;
   19.50 -        block_count = decode_cdb_length(srb);;
   19.51 -        block_count *= xvdd->bytes_per_sector / 512;
   19.52 -        remaining = block_count * 512;
   19.53 -        while (remaining > 0)
   19.54 -        {
   19.55 -          physical_address = ScsiPortGetPhysicalAddress(xvdd, srb, ptr, &length);
   19.56 -          KdPrint((__DRIVER_NAME "     ptr = %p, physical_address = %08x:%08x, length = %d\n",
   19.57 -            ptr, physical_address.HighPart, physical_address.LowPart, length));
   19.58 -          remaining -= length;
   19.59 -          ptr += length;
   19.60 -          KdPrint((__DRIVER_NAME "     remaining = %d\n", remaining));
   19.61 -        }
   19.62 -      }
   19.63 -      
   19.64 -      ASSERT((offset & 511) == 0);
   19.65 -      ASSERT((length & 511) == 0);
   19.66 -      //length = min(PAGE_SIZE - offset, remaining);
   19.67 -      //KdPrint((__DRIVER_NAME "     length(a) = %d\n", length));
   19.68 -      shadow->req.seg[shadow->req.nr_segments].gref = (grant_ref_t)(physical_address.QuadPart >> PAGE_SHIFT);
   19.69 -      //KdPrint((__DRIVER_NAME "     length(b) = %d\n", length));
   19.70 -      shadow->req.seg[shadow->req.nr_segments].first_sect = (UCHAR)(offset >> 9);
   19.71 -      shadow->req.seg[shadow->req.nr_segments].last_sect = (UCHAR)(((offset + length) >> 9) - 1);
   19.72 -      remaining -= length;
   19.73 -      ptr += length;
   19.74 -      //KdPrint((__DRIVER_NAME "     seg[%d].gref = %d\n", shadow->req.nr_segments, shadow->req.seg[shadow->req.nr_segments].gref));
   19.75 -      //KdPrint((__DRIVER_NAME "     seg[%d].first_sect = %d\n", shadow->req.nr_segments, shadow->req.seg[shadow->req.nr_segments].first_sect));
   19.76 -      //KdPrint((__DRIVER_NAME "     seg[%d].last_sect = %d\n", shadow->req.nr_segments, shadow->req.seg[shadow->req.nr_segments].last_sect));
   19.77 -      shadow->req.nr_segments++;
   19.78 -    }
   19.79 -  }
   19.80 -  else
   19.81 +  gref_index = 0;
   19.82 +  while (remaining > 0)
   19.83    {
   19.84      PHYSICAL_ADDRESS physical_address;
   19.85 -    //KdPrint((__DRIVER_NAME "     remaining = %d\n", remaining));
   19.86 -    ASSERT(remaining <= PAGE_SIZE); /* one page at a time in dump mode */
   19.87      physical_address = ScsiPortGetPhysicalAddress(xvdd, srb, ptr, &length);
   19.88 +    if (!dump_mode)
   19.89 +    {
   19.90 +      gref = (grant_ref_t)(physical_address.QuadPart >> PAGE_SHIFT);
   19.91 +    }
   19.92 +    else
   19.93 +    {
   19.94 +      gref = (grant_ref_t)xvdd->vectors.GntTbl_GrantAccess(xvdd->vectors.context, 0,
   19.95 +              (ULONG)(physical_address.QuadPart >> PAGE_SHIFT), FALSE, xvdd->dump_grant_refs[gref_index++]);
   19.96 +    }
   19.97      offset = physical_address.LowPart & (PAGE_SIZE - 1);
   19.98 -    ASSERT(offset == 0);
   19.99 -    //ASSERT((offset & 511) == 0);
  19.100 -    shadow->req.seg[shadow->req.nr_segments].gref = 
  19.101 -      (grant_ref_t)xvdd->vectors.GntTbl_GrantAccess(xvdd->vectors.context, 0,
  19.102 -      (ULONG)(physical_address.QuadPart >> PAGE_SHIFT), FALSE, xvdd->dump_grant_ref);
  19.103 -    //KdPrint((__DRIVER_NAME "     gref = %d, dump_grant_ref = %d\n",
  19.104 -    //  shadow->req.seg[shadow->req.nr_segments].gref, xvdd->dump_grant_ref));
  19.105 +    length = min(PAGE_SIZE - offset, remaining);
  19.106 +    ASSERT((offset & 511) == 0);
  19.107 +    ASSERT((length & 511) == 0);
  19.108 +    //KdPrint((__DRIVER_NAME "     length(a) = %d\n", length));
  19.109 +    shadow->req.seg[shadow->req.nr_segments].gref = gref;
  19.110 +    //KdPrint((__DRIVER_NAME "     length(b) = %d\n", length));
  19.111      shadow->req.seg[shadow->req.nr_segments].first_sect = (UCHAR)(offset >> 9);
  19.112 -    shadow->req.seg[shadow->req.nr_segments].last_sect = (UCHAR)(((offset + remaining) >> 9) - 1);
  19.113 +    shadow->req.seg[shadow->req.nr_segments].last_sect = (UCHAR)(((offset + length) >> 9) - 1);
  19.114      remaining -= length;
  19.115 +    ptr += length;
  19.116      shadow->req.nr_segments++;
  19.117    }
  19.118 +
  19.119    //KdPrint((__DRIVER_NAME "     nr_segments = %d\n", shadow->req.nr_segments));
  19.120  
  19.121    XenVbd_PutRequest(xvdd, &shadow->req);
  19.122 @@ -548,7 +513,7 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
  19.123      return status;
  19.124    }
  19.125  
  19.126 -  if (dump_mode)
  19.127 +  if (!dump_mode)
  19.128    {
  19.129      ConfigInfo->MaximumTransferLength = BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE;
  19.130      ConfigInfo->NumberOfPhysicalBreaks = BLKIF_MAX_SEGMENTS_PER_REQUEST - 1;
  19.131 @@ -593,7 +558,7 @@ XenVbd_HwScsiInitialize(PVOID DeviceExte
  19.132    int i;
  19.133    int notify;
  19.134    
  19.135 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  19.136 +  FUNCTION_ENTER();
  19.137    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  19.138  
  19.139    if (!dump_mode)
  19.140 @@ -635,7 +600,7 @@ XenVbd_HwScsiInitialize(PVOID DeviceExte
  19.141      xvdd->ring_detect_state = 2;
  19.142    }
  19.143    
  19.144 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  19.145 +  FUNCTION_EXIT();
  19.146  
  19.147    return TRUE;
  19.148  }
  19.149 @@ -795,6 +760,7 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
  19.150    PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
  19.151    PSCSI_REQUEST_BLOCK srb;
  19.152    RING_IDX i, rp;
  19.153 +  ULONG j;
  19.154    blkif_response_t *rep;
  19.155    int block_count;
  19.156    int more_to_do = TRUE;
  19.157 @@ -904,12 +870,12 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
  19.158          put_shadow_on_freelist(xvdd, shadow);
  19.159          if (dump_mode)
  19.160          {
  19.161 -          ASSERT(shadow->req.nr_segments == 1);
  19.162 -          //KdPrint((__DRIVER_NAME "     gref = %d, dump_grant_ref = %d\n",
  19.163 -          //  shadow->req.seg[0].gref, xvdd->dump_grant_ref));
  19.164 -          ASSERT(shadow->req.seg[0].gref == xvdd->dump_grant_ref);
  19.165 -          xvdd->vectors.GntTbl_EndAccess(xvdd->vectors.context,
  19.166 -            shadow->req.seg[0].gref, TRUE);
  19.167 +          for (j = 0; j < shadow->req.nr_segments; j++)
  19.168 +          {
  19.169 +            ASSERT(shadow->req.seg[j].gref == xvdd->dump_grant_refs[j]);
  19.170 +            xvdd->vectors.GntTbl_EndAccess(xvdd->vectors.context,
  19.171 +              shadow->req.seg[j].gref, TRUE);
  19.172 +          }
  19.173          }
  19.174          ScsiPortNotification(RequestComplete, xvdd, srb);
  19.175          if (suspend_resume_state_pdo == SR_STATE_RUNNING)
  19.176 @@ -955,10 +921,9 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  19.177    PCDB cdb;
  19.178    PXENVBD_DEVICE_DATA xvdd = DeviceExtension;
  19.179  
  19.180 -  //KdPrint((__DRIVER_NAME " --> HwScsiStartIo PathId = %d, TargetId = %d, Lun = %d\n", Srb->PathId, Srb->TargetId, Srb->Lun));
  19.181 -
  19.182    if (xvdd->inactive)
  19.183    {
  19.184 +    KdPrint((__DRIVER_NAME "     Inactive Srb->Function = %08X\n", Srb->Function));
  19.185      Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
  19.186      ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  19.187      ScsiPortNotification(NextRequest, DeviceExtension);
  19.188 @@ -1246,18 +1211,15 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  19.189        }
  19.190        break;
  19.191      case SCSIOP_START_STOP_UNIT:
  19.192 -      if (dump_mode)
  19.193 -        KdPrint((__DRIVER_NAME "     Command = SCSIOP_START_STOP_UNIT\n"));
  19.194 +      KdPrint((__DRIVER_NAME "     Command = SCSIOP_START_STOP_UNIT\n"));
  19.195        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  19.196        break;
  19.197      case SCSIOP_RESERVE_UNIT:
  19.198 -      if (dump_mode)
  19.199 -        KdPrint((__DRIVER_NAME "     Command = SCSIOP_RESERVE_UNIT\n"));
  19.200 +      KdPrint((__DRIVER_NAME "     Command = SCSIOP_RESERVE_UNIT\n"));
  19.201        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  19.202        break;
  19.203      case SCSIOP_RELEASE_UNIT:
  19.204 -      if (dump_mode)
  19.205 -        KdPrint((__DRIVER_NAME "     Command = SCSIOP_RELEASE_UNIT\n"));
  19.206 +      KdPrint((__DRIVER_NAME "     Command = SCSIOP_RELEASE_UNIT\n"));
  19.207        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  19.208        break;
  19.209      default:
  19.210 @@ -1289,7 +1251,7 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  19.211      }
  19.212      break;
  19.213    case SRB_FUNCTION_IO_CONTROL:
  19.214 -    //KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
  19.215 +    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
  19.216      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
  19.217      ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  19.218      if (xvdd->device_state->suspend_resume_state_pdo == SR_STATE_RUNNING)
  19.219 @@ -1322,7 +1284,7 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  19.220    return TRUE;
  19.221  }
  19.222  
  19.223 -static BOOLEAN DDKAPI
  19.224 +static BOOLEAN
  19.225  XenVbd_HwScsiResetBus(PVOID DeviceExtension, ULONG PathId)
  19.226  {
  19.227    PXENVBD_DEVICE_DATA xvdd = DeviceExtension;
  19.228 @@ -1330,7 +1292,7 @@ XenVbd_HwScsiResetBus(PVOID DeviceExtens
  19.229    UNREFERENCED_PARAMETER(DeviceExtension);
  19.230    UNREFERENCED_PARAMETER(PathId);
  19.231  
  19.232 -  KdPrint((__DRIVER_NAME " --> HwScsiResetBus\n"));
  19.233 +  FUNCTION_ENTER();
  19.234  
  19.235    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  19.236    if (xvdd->ring_detect_state == 2 && xvdd->device_state->suspend_resume_state_pdo == SR_STATE_RUNNING)
  19.237 @@ -1338,23 +1300,23 @@ XenVbd_HwScsiResetBus(PVOID DeviceExtens
  19.238      ScsiPortNotification(NextRequest, DeviceExtension);
  19.239    }
  19.240  
  19.241 -  KdPrint((__DRIVER_NAME " <-- HwScsiResetBus\n"));
  19.242 +  FUNCTION_EXIT();
  19.243  
  19.244  
  19.245    return TRUE;
  19.246  }
  19.247  
  19.248 -static BOOLEAN DDKAPI
  19.249 +static BOOLEAN
  19.250  XenVbd_HwScsiAdapterState(PVOID DeviceExtension, PVOID Context, BOOLEAN SaveState)
  19.251  {
  19.252    UNREFERENCED_PARAMETER(DeviceExtension);
  19.253    UNREFERENCED_PARAMETER(Context);
  19.254    UNREFERENCED_PARAMETER(SaveState);
  19.255  
  19.256 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  19.257 +  FUNCTION_ENTER();
  19.258    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  19.259  
  19.260 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  19.261 +  FUNCTION_EXIT();
  19.262  
  19.263    return TRUE;
  19.264  }
  19.265 @@ -1382,6 +1344,7 @@ XenVbd_HwScsiAdapterControl(PVOID Device
  19.266      break;
  19.267    case ScsiStopAdapter:
  19.268      KdPrint((__DRIVER_NAME "     ScsiStopAdapter\n"));
  19.269 +    //KdBreakPoint();
  19.270      /* I don't think we actually have to do anything here... xenpci cleans up all the xenbus stuff for us */
  19.271      break;
  19.272    case ScsiRestartAdapter:
  19.273 @@ -1458,7 +1421,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  19.274  
  19.275    FUNCTION_ENTER();
  19.276    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  19.277 -  KdPrint((__DRIVER_NAME "     DriverObject = %p\n", DriverObject));
  19.278 +  KdPrint((__DRIVER_NAME "     DriverObject = %p, RegistryPath = %p\n", DriverObject, RegistryPath));
  19.279  
  19.280    /* RegistryPath == NULL when we are invoked as a crash dump driver */
  19.281    if (!RegistryPath)
  19.282 @@ -1477,7 +1440,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  19.283      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "mode", NULL, NULL);
  19.284      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sectors", NULL, NULL);
  19.285      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sector-size", NULL, NULL);
  19.286 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, NULL, ULongToPtr(1), NULL); /* 1 ref for use in crash dump */
  19.287 +    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, NULL, ULongToPtr(BLKIF_MAX_SEGMENTS_PER_REQUEST), NULL); /* for use in crash dump */
  19.288      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL, NULL);
  19.289  
  19.290      IoAllocateDriverObjectExtension(DriverObject, UlongToPtr(XEN_DMA_DRIVER_EXTENSION_MAGIC), sizeof(dma_driver_extension), &dma_driver_extension);  
  19.291 @@ -1493,14 +1456,9 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  19.292    HwInitializationData.SpecificLuExtensionSize = 0;
  19.293    HwInitializationData.SrbExtensionSize = 0;
  19.294    HwInitializationData.NumberOfAccessRanges = 1;
  19.295 -#if 0
  19.296 -  HwInitializationData.MapBuffers = TRUE;
  19.297 -  HwInitializationData.NeedPhysicalAddresses = FALSE;
  19.298 -#else
  19.299    HwInitializationData.MapBuffers = FALSE;
  19.300    HwInitializationData.NeedPhysicalAddresses = TRUE;
  19.301 -#endif
  19.302 -  HwInitializationData.TaggedQueuing = FALSE;
  19.303 +  HwInitializationData.TaggedQueuing = TRUE;
  19.304    HwInitializationData.AutoRequestSense = TRUE;
  19.305    HwInitializationData.MultipleRequestPerLu = TRUE;
  19.306    HwInitializationData.ReceiveEvent = FALSE;
  19.307 @@ -1515,14 +1473,9 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  19.308    HwInitializationData.HwFindAdapter = XenVbd_HwScsiFindAdapter;
  19.309    HwInitializationData.HwResetBus = XenVbd_HwScsiResetBus;
  19.310    HwInitializationData.HwDmaStarted = NULL;
  19.311 -  HwInitializationData.HwAdapterState = XenVbd_HwScsiAdapterState;
  19.312 +  HwInitializationData.HwAdapterState = NULL; //XenVbd_HwScsiAdapterState;
  19.313    HwInitializationData.HwAdapterControl = XenVbd_HwScsiAdapterControl;
  19.314  
  19.315 -#if 0
  19.316 -  if (dump_mode)
  19.317 -    KdBreakPoint();
  19.318 -#endif
  19.319 -
  19.320    status = ScsiPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
  19.321    
  19.322    if(!NT_SUCCESS(status))
  19.323 @@ -1533,5 +1486,4 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  19.324    FUNCTION_EXIT();
  19.325  
  19.326    return status;
  19.327 -}
  19.328 -
  19.329 +}
  19.330 \ No newline at end of file
    20.1 --- a/xenvbd/xenvbd.h	Wed Feb 18 22:18:23 2009 +1100
    20.2 +++ b/xenvbd/xenvbd.h	Tue Mar 03 09:51:24 2009 +1100
    20.3 @@ -133,7 +133,7 @@ struct
    20.4    XENPCI_VECTORS vectors;
    20.5    PXENPCI_DEVICE_STATE device_state;
    20.6    PSCSI_REQUEST_BLOCK pending_srb;
    20.7 -  grant_ref_t dump_grant_ref;
    20.8 +  grant_ref_t dump_grant_refs[BLKIF_MAX_SEGMENTS_PER_REQUEST - 1];
    20.9  /*  
   20.10    ULONGLONG interrupts;
   20.11    ULONGLONG aligned_requests;