win-pvdrivers

changeset 537:2a74ac2f43bb

more big updates
dma now working under xp
author James Harper <james.harper@bendigoit.com.au>
date Wed Feb 18 22:18:23 2009 +1100 (2009-02-18)
parents 1d39de3ab8d6
children e75bb8d68370
files common.inc installer.wxs makedist.bat shutdownmon/shutdownmon.c xennet/makefile.inc xennet/sources xennet/xennet.c xennet/xennet.h xennet/xennet.inx xennet/xennet_rx.c xennet/xennet_tx.c xenpci/makefile.inc xenpci/sources xenpci/xenbus_device_interface.c xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci.inx xenpci/xenpci_fdo.c xenpci/xenpci_highsync.c xenpci/xenpci_patch_kernel.c xenpci/xenpci_pdo.c xenscsi/makefile.inc xenscsi/sources xenscsi/xenscsi.c xenstub/makefile.inc xenstub/sources xenstub/xenstub.inx xenvbd/makefile.inc xenvbd/sources xenvbd/xenvbd.c xenvbd/xenvbd.inx
line diff
     1.1 --- a/common.inc	Sat Feb 14 13:35:48 2009 +1100
     1.2 +++ b/common.inc	Wed Feb 18 22:18:23 2009 +1100
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.9.11.15
     1.5 +VERSION=0.9.11.16
     1.6  #TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  MSC_WARNING_LEVEL=/W4
     1.8  INCLUDES = ..\common\include;..\common\include\public
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/installer.wxs	Wed Feb 18 22:18:23 2009 +1100
     2.3 @@ -0,0 +1,116 @@
     2.4 +<?xml version='1.0' encoding='windows-1252'?>
     2.5 +<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:difx='http://schemas.microsoft.com/wix/DifxAppExtension' xmlns:iis='http://schemas.microsoft.com/wix/IIsExtension'>
     2.6 +  <?if $(env._BUILDARCH) = x86 ?>
     2.7 +    <?define ARCHDIR = i386 ?>
     2.8 +  <?elseif $(env._BUILDARCH) = AMD64 ?>
     2.9 +    <?define ARCHDIR = amd64 ?>
    2.10 +  <?endif ?>
    2.11 +
    2.12 +  <Product Name='GPL PV Drivers for Windows' Id='915B4C12-093D-419d-8FEC-63DCFD8B820D'
    2.13 +    UpgradeCode='4EDE5DEC-3208-4a1e-8E52-DAC44F7D7062'
    2.14 +    Language='1033' Codepage='1252' Version='1.0.0' Manufacturer='James Harper'>
    2.15 +
    2.16 +    <Package Id='*' Keywords='Installer' Description="GPL PV Drivers for Windows"
    2.17 +      Comments='no comment' Manufacturer='James Harper'
    2.18 +      InstallerVersion='100' Languages='1033' Compressed='yes' SummaryCodepage='1252' />
    2.19 +
    2.20 +    <UIRef Id="WixUI_Mondo" />
    2.21 +    <UIRef Id="WixUI_ErrorProgressText" />
    2.22 +    
    2.23 +    <Media Id='1' Cabinet='gplpv.cab' EmbedCab='yes' />
    2.24 +
    2.25 +    <Directory Id='TARGETDIR' Name='SourceDir'>
    2.26 +      <Directory Id='ProgramFilesFolder' Name='PFiles'>
    2.27 +        <Directory Id='XenProgramFilesDir' Name='Xen PV Drivers'>
    2.28 +          <Directory Id='BinDir' Name='bin'>
    2.29 +            <Component Id='ShutdownMon' Guid='BF8DC887-4B46-4e77-ACD3-125E8A2BAB8E'>
    2.30 +              <File Id='shutdownmon.exe' Name='shutdownmon.exe' DiskId='1' Source='shutdownmon\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\shutdownmon.exe' />
    2.31 +            </Component>
    2.32 +            <Component Id='CopyConfig' Guid='C01F8A97-1410-41ce-A16E-76E6072FDFF8'>
    2.33 +              <File Id='copyconfig.exe' Name='copyconfig.exe' DiskId='1' Source='copyconfig\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\copyconfig.exe' />
    2.34 +            </Component>
    2.35 +          </Directory>  
    2.36 +          <Directory Id='DocDir' Name='doc'>
    2.37 +          </Directory>
    2.38 +          <Directory Id='DriversDir' Name='drivers'>
    2.39 +            <Directory Id='XenPciDir' Name='xenpci'>
    2.40 +              <Component Id='XenPci' Guid='D6BB9B5F-61F9-4b6e-8FAD-289706F5EBEB'>
    2.41 +                <File Id='xenpci.inf' Name='xenpci.inf' DiskId='1' Source='xenpci\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenpci.inf' />
    2.42 +                <File Id='xenpci.sys' Name='xenpci.sys' DiskId='1' Source='xenpci\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenpci.sys' />
    2.43 +                <File Id='xenhide.sys' Name='xenhide.sys' DiskId='1' Source='xenhide\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenhide.sys' />
    2.44 +                <File Id='WdfCoInstaller01007.dll' Name='WdfCoInstaller01007.dll' DiskId='1' Source='$(env.BASEDIR)\redist\wdf\$(env.CPU)\WdfCoInstaller01007.dll' />
    2.45 +                <difx:Driver Sequence='99' Legacy='yes' />
    2.46 +              </Component>
    2.47 +            </Directory>
    2.48 +            <Directory Id='XenVbdDir' Name='xenvbd'>
    2.49 +              <Component Id='XenVbd' Guid='1F05DC54-974C-40f6-BF41-0EFDB3EBD1DC'>
    2.50 +                <File Id='xenvbd.inf' Name='xenvbd.inf' DiskId='1' Source='xenvbd\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenvbd.inf' />
    2.51 +                <File Id='xenvbd.sys' Name='xenvbd.sys' DiskId='1' Source='xenvbd\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenvbd.sys' />
    2.52 +                <difx:Driver Sequence='1' Legacy='yes' />
    2.53 +              </Component>
    2.54 +            </Directory>
    2.55 +            <Directory Id='XenScsiDir' Name='xenscsi'>
    2.56 +              <Component Id='XenScsi' Guid='47C9AB48-3A7D-42b2-AE2C-7F9235C8B7B4'>
    2.57 +                <File Id='xenscsi.inf' Name='xenscsi.inf' DiskId='1' Source='xenscsi\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenscsi.inf' />
    2.58 +                <File Id='xenscsi.sys' Name='xenscsi.sys' DiskId='1' Source='xenscsi\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenscsi.sys' />
    2.59 +                <difx:Driver Sequence='1' Legacy='yes' />
    2.60 +              </Component>
    2.61 +            </Directory>
    2.62 +            <Directory Id='XenNetDir' Name='xennet'>
    2.63 +              <Component Id='XenNet' Guid='F16B1EC7-35B1-42c2-9017-22DC23D80BE7'>
    2.64 +                <File Id='xennet.inf' Name='xennet.inf' DiskId='1' Source='xennet\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xennet.inf' />
    2.65 +                <File Id='xennet.sys' Name='xennet.sys' DiskId='1' Source='xennet\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xennet.sys' />
    2.66 +                <difx:Driver Sequence='3' Legacy='yes' />
    2.67 +              </Component>
    2.68 +            </Directory>
    2.69 +            <Directory Id='XenStubDir' Name='xenstub'>
    2.70 +              <Component Id='XenStub' Guid='71794E97-D0CD-409b-BF7C-2FCEEEBD3D13'>
    2.71 +                <File Id='xenstub.inf' Name='xenstub.inf' DiskId='1' Source='xenstub\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenstub.inf' />
    2.72 +                <File Id='xenstub.sys' Name='xenstub.sys' DiskId='1' Source='xenstub\obj$(env.BUILD_ALT_DIR)\$(var.ARCHDIR)\xenstub.sys' />
    2.73 +                <difx:Driver Sequence='4' Legacy='yes' />
    2.74 +              </Component>
    2.75 +            </Directory>
    2.76 +          </Directory>
    2.77 +        </Directory>
    2.78 +        <Component Id='Cert' Guid='11112EC8-8635-45fb-9AE8-C22310F1E82D'>
    2.79 +          <File Id='ca.cer' Name='ca.cer' DiskId='1' Source='ca.cer' />
    2.80 +          <iis:Certificate Id='ca.cer' Name='ca.cer' Request='no' BinaryKey='ca.cer' StoreLocation='localMachine' StoreName='root' Overwrite='no' />
    2.81 +        </Component>
    2.82 +      </Directory>
    2.83 +    </Directory>
    2.84 +
    2.85 +    <Binary Id='ca.cer' SourceFile='ca.cer' />    
    2.86 +
    2.87 +    <Feature Id='Cert' Title='Install Certificate' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    2.88 +      <ComponentRef Id='Cert' />
    2.89 +    </Feature>
    2.90 +    <Feature Id='Drivers' Title='Drivers' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    2.91 +      <Feature Id='XenPci' Title='XenPci Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='disallow'>
    2.92 +        <ComponentRef Id='XenPci' />
    2.93 +      </Feature>
    2.94 +      <Feature Id='XenVbd' Title='XenVbd Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    2.95 +        <ComponentRef Id='XenVbd' />
    2.96 +      </Feature>
    2.97 +      <Feature Id='XenScsi' Title='XenVbd Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
    2.98 +        <ComponentRef Id='XenScsi' />
    2.99 +      </Feature>
   2.100 +      <Feature Id='XenNet' Title='XenNet Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
   2.101 +        <ComponentRef Id='XenNet' />
   2.102 +      </Feature>
   2.103 +      <Feature Id='XenStub' Title='XenNet Driver' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
   2.104 +        <ComponentRef Id='XenStub' />
   2.105 +      </Feature>
   2.106 +    </Feature>
   2.107 +    <Feature Id='ShutdownMon' Title='Shutdown Monitor' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
   2.108 +      <ComponentRef Id='ShutdownMon' />
   2.109 +    </Feature>
   2.110 +    <Feature Id='CopyConfig' Title='Copy Network Config' Level='1' AllowAdvertise='no' InstallDefault='local' Absent='allow'>
   2.111 +      <ComponentRef Id='CopyConfig' />
   2.112 +    </Feature>
   2.113 +
   2.114 +    <InstallExecuteSequence>
   2.115 +      <ScheduleReboot After='InstallFinalize' />
   2.116 +    </InstallExecuteSequence>
   2.117 +
   2.118 +  </Product>
   2.119 +</Wix>
     3.1 --- a/makedist.bat	Sat Feb 14 13:35:48 2009 +1100
     3.2 +++ b/makedist.bat	Wed Feb 18 22:18:23 2009 +1100
     3.3 @@ -1,27 +1,67 @@
     3.4  @echo off
     3.5 -IF NOT EXIST set_ddk_path.bat ECHO >set_ddk_path.bat SET DDK_PATH=C:\WinDDK\6001.18001
     3.6 +IF NOT EXIST set_ddk_path.bat ECHO >set_ddk_path.bat SET DDK_PATH=C:\WinDDK\6001.18002
     3.7  
     3.8  CALL set_ddk_path.bat
     3.9  
    3.10 -cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WXP && CD \Projects\win-pvdrivers.hg && build -cZg"
    3.11 -CALL sign_sys.bat winxp i386 XP_X86
    3.12 -CALL sign_inf.bat winxp XP_X86
    3.13 -
    3.14 -cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WNET && CD \Projects\win-pvdrivers.hg && build -cZg"
    3.15 -CALL sign_sys.bat winnet i386 Server2003_X86
    3.16 -cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk x64 WNET && CD \Projects\win-pvdrivers.hg && build -cZg"
    3.17 -CALL sign_sys.bat winnet amd64 Server2003_X64
    3.18 -CALL sign_inf.bat winnet Server2003_X64
    3.19 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre WXP && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.20 +rem CALL sign_sys.bat winxp i386 XP_X86
    3.21 +rem CALL sign_inf.bat winxp XP_X86
    3.22  
    3.23 -cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WLH && CD \Projects\win-pvdrivers.hg && build -cZg"
    3.24 -CALL sign_sys.bat winlh i386 Server2008_X86
    3.25 -cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk x64 WLH && CD \Projects\win-pvdrivers.hg && build -cZg"
    3.26 -CALL sign_sys.bat winlh amd64 Server2008_X64
    3.27 -CALL sign_inf.bat winlh Server2008_X64
    3.28 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre WNET && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.29 +rem CALL sign_sys.bat winnet i386 Server2003_X86
    3.30 +rem CALL sign_inf.bat winnet Server2003_X64
    3.31 +rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    3.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"
    3.33  
    3.34 -IF NOT EXIST SIGN_CONFIG.BAT GOTO DONT_SIGN
    3.35 -CALL SIGN_CONFIG.BAT
    3.36 -%DDK_PATH%\bin\selfsign\certmgr -put -r %CA_CERT_LOCATION% -c -s %CA_CERT_STORE% -n %CA_CERT_NAME% ca.cer
    3.37 -:DONT_SIGN
    3.38 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre x64 WNET && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.39 +rem CALL sign_sys.bat winnet amd64 Server2003_X64
    3.40 +rem CALL sign_inf.bat winnet Server2003_X64
    3.41 +rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    3.42 +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"
    3.43  
    3.44 -"%ProgramFiles%\NSIS\makensis.exe" installer.nsi
    3.45 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre WLH && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.46 +rem CALL sign_sys.bat winlh i386 Server2008_X86
    3.47 +rem CALL sign_inf.bat winlh Server2008_X64
    3.48 +rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    3.49 +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"
    3.50 +
    3.51 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ fre x64 WLH && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.52 +rem CALL sign_sys.bat winlh amd64 Server2008_X64
    3.53 +rem CALL sign_inf.bat winlh Server2008_X64
    3.54 +rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    3.55 +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"
    3.56 +
    3.57 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WXP && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.58 +rem CALL sign_sys.bat winxp i386 XP_X86
    3.59 +rem CALL sign_inf.bat winxp XP_X86
    3.60 +rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    3.61 +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"
    3.62 +
    3.63 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WNET && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.64 +rem CALL sign_sys.bat winnet i386 Server2003_X86
    3.65 +rem CALL sign_inf.bat winnet Server2003_X64
    3.66 +rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    3.67 +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"
    3.68 +
    3.69 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk x64 WNET && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.70 +rem CALL sign_sys.bat winnet amd64 Server2003_X64
    3.71 +rem CALL sign_inf.bat winnet Server2003_X64
    3.72 +rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    3.73 +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"
    3.74 +
    3.75 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WLH && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.76 +rem CALL sign_sys.bat winlh i386 Server2008_X86
    3.77 +rem CALL sign_inf.bat winlh Server2008_X64
    3.78 +rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    3.79 +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"
    3.80 +
    3.81 +cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk x64 WLH && CD \Projects\win-pvdrivers.hg && build -cZg && call wix.bat"
    3.82 +rem CALL sign_sys.bat winlh amd64 Server2008_X64
    3.83 +rem CALL sign_inf.bat winlh Server2008_X64
    3.84 +rem "%WIX%\bin\candle" installer.wxs -ext "%WIX%\bin\WixUIExtension.dll" -ext "%WIX%\bin\WixDifxAppExtension.dll" -ext "%WIX%\bin\WixIIsExtension.dll"
    3.85 +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"
    3.86 +
    3.87 +rem IF NOT EXIST SIGN_CONFIG.BAT GOTO DONT_SIGN
    3.88 +rem CALL SIGN_CONFIG.BAT
    3.89 +rem %DDK_PATH%\bin\selfsign\certmgr -put -r %CA_CERT_LOCATION% -c -s %CA_CERT_STORE% -n %CA_CERT_NAME% ca.cer
    3.90 +rem :DONT_SIGN
     4.1 --- a/shutdownmon/shutdownmon.c	Sat Feb 14 13:35:48 2009 +1100
     4.2 +++ b/shutdownmon/shutdownmon.c	Wed Feb 18 22:18:23 2009 +1100
     4.3 @@ -262,7 +262,7 @@ xb_add_watch(HANDLE handle, char *path)
     4.4    msg->type = XS_WATCH;
     4.5    msg->req_id = 0;
     4.6    msg->tx_id = 0;
     4.7 -  msg->len = strlen(path) + 1 + strlen(token) + 1;
     4.8 +  msg->len = (ULONG)(strlen(path) + 1 + strlen(token) + 1);
     4.9    strcpy(buf + sizeof(*msg), path);
    4.10    strcpy(buf + sizeof(*msg) + strlen(path) + 1, token);
    4.11  
    4.12 @@ -319,7 +319,7 @@ printf("read start\n");
    4.13    msg->type = XS_READ;
    4.14    msg->req_id = 0;
    4.15    msg->tx_id = 0;
    4.16 -  msg->len = strlen(path) + 1;
    4.17 +  msg->len = (ULONG)(strlen(path) + 1);
    4.18    strcpy(buf + sizeof(*msg), path);
    4.19    if (!WriteFile(handle, buf, sizeof(*msg) + msg->len, &bytes_written, NULL))
    4.20    {
     5.1 --- a/xennet/makefile.inc	Sat Feb 14 13:35:48 2009 +1100
     5.2 +++ b/xennet/makefile.inc	Wed Feb 18 22:18:23 2009 +1100
     5.3 @@ -1,6 +1,6 @@
     5.4  _LNG=$(LANGUAGE)
     5.5  STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
     5.6  
     5.7 -$(INF_NAME).inf: $(INF_NAME).inx sources ..\common.inc
     5.8 +$(OBJ_PATH)\$(O)\$(INF_NAME).inf: $(INF_NAME).inx sources ..\common.inc
     5.9      copy $(@B).inx $@
    5.10      $(STAMP)
     6.1 --- a/xennet/sources	Sat Feb 14 13:35:48 2009 +1100
     6.2 +++ b/xennet/sources	Wed Feb 18 22:18:23 2009 +1100
     6.3 @@ -3,5 +3,5 @@ TARGETNAME=xennet
     6.4  TARGETTYPE=DRIVER
     6.5  INF_NAME=$(TARGETNAME)
     6.6  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\ndis.lib
     6.7 -MISCFILES=$(INF_NAME).inf
     6.8 +NTTARGETFILES=$(NTTARGETFILES) $(OBJ_PATH)\$(O)\$(INF_NAME).inf
     6.9  SOURCES=xennet.c xennet_tx.c xennet_rx.c xennet_oid.c xennet_common.c
     7.1 --- a/xennet/xennet.c	Sat Feb 14 13:35:48 2009 +1100
     7.2 +++ b/xennet/xennet.c	Wed Feb 18 22:18:23 2009 +1100
     7.3 @@ -315,7 +315,7 @@ XenNet_Init(
     7.4    ULONG i;
     7.5    PUCHAR ptr;
     7.6    UCHAR type;
     7.7 -  PCHAR setting, value, value2;
     7.8 +  PCHAR setting, value;
     7.9    ULONG length;
    7.10    CHAR buf[128];
    7.11    PVOID network_address;
    7.12 @@ -596,7 +596,8 @@ XenNet_Init(
    7.13    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RUN, NULL, NULL, NULL);
    7.14    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "tx-ring-ref", NULL, NULL);
    7.15    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "rx-ring-ref", NULL, NULL);
    7.16 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL, "event-channel", XenNet_HandleEvent, xi);
    7.17 +  #pragma warning(suppress:4054)
    7.18 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL, "event-channel", (PVOID)XenNet_HandleEvent, xi);
    7.19    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "mac", NULL, NULL);
    7.20    RtlStringCbPrintfA(buf, ARRAY_SIZE(buf), "%d", !xi->config_csum);
    7.21    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "request-rx-copy", "1", NULL);
     8.1 --- a/xennet/xennet.h	Sat Feb 14 13:35:48 2009 +1100
     8.2 +++ b/xennet/xennet.h	Wed Feb 18 22:18:23 2009 +1100
     8.3 @@ -270,6 +270,9 @@ struct xennet_info
     8.4  #define TX_HEADER_BUFFER_SIZE 512
     8.5  //#define TX_HEADER_BUFFERS (NET_TX_RING_SIZE >> 2)
     8.6  #define TX_HEADER_BUFFERS (NET_TX_RING_SIZE)
     8.7 +  BOOLEAN tx_shutting_down;
     8.8 +  KEVENT tx_idle_event;
     8.9 +  ULONG tx_outstanding;
    8.10    ULONG tx_id_free;
    8.11    USHORT tx_id_list[NET_TX_RING_SIZE];
    8.12    ULONG tx_hb_free;
    8.13 @@ -305,7 +308,7 @@ struct xennet_info
    8.14    ULONG rx_min_target;
    8.15  
    8.16    /* how many packets are in the net stack atm */
    8.17 -  LONG rx_outstanding;
    8.18 +  ULONG rx_outstanding;
    8.19  
    8.20    /* config vars from registry */
    8.21    ULONG config_sg;
     9.1 --- a/xennet/xennet.inx	Sat Feb 14 13:35:48 2009 +1100
     9.2 +++ b/xennet/xennet.inx	Wed Feb 18 22:18:23 2009 +1100
     9.3 @@ -12,13 +12,9 @@ DefaultDestDir = 12
     9.4  ExcludeFromSelect=*
     9.5  
     9.6  [Manufacturer]
     9.7 -%XenGplPv%=XenGplPv,NTx86
     9.8 -%XenGplPv%=XenGplPv,NTamd64
     9.9 +%XenGplPv%=XenGplPv,NT$ARCH$
    9.10  
    9.11 -[XenGplPv.NTx86]
    9.12 -%XenNet.DRVDESC%=XenNet_Inst, XEN\VIF
    9.13 -
    9.14 -[XenGplPv.NTamd64]
    9.15 +[XenGplPv.NT$ARCH$]
    9.16  %XenNet.DRVDESC%=XenNet_Inst, XEN\VIF
    9.17  
    9.18  [XenNet_Inst.NT]
    9.19 @@ -86,11 +82,8 @@ xennet.sys
    9.20  [SourceDisksFiles]
    9.21  xennet.sys=1
    9.22  
    9.23 -[SourceDisksNames.x86]
    9.24 -1 = %DISK_NAME%,,,\i386
    9.25 -
    9.26 -[SourceDisksNames.amd64]
    9.27 -1 = %DISK_NAME%,,,\amd64
    9.28 +[SourceDisksNames]
    9.29 +1 = %DISK_NAME%
    9.30  
    9.31  [XenNet_Inst.Services]
    9.32  AddService=XenNet,2,XenNet_Service 
    10.1 --- a/xennet/xennet_rx.c	Sat Feb 14 13:35:48 2009 +1100
    10.2 +++ b/xennet/xennet_rx.c	Wed Feb 18 22:18:23 2009 +1100
    10.3 @@ -61,8 +61,6 @@ put_pb_on_freelist(struct xennet_info *x
    10.4    }
    10.5  }
    10.6  
    10.7 -BOOLEAN ___restored = FALSE;
    10.8 -
    10.9  // Called at DISPATCH_LEVEL with rx lock held
   10.10  static NDIS_STATUS
   10.11  XenNet_FillRing(struct xennet_info *xi)
   10.12 @@ -102,8 +100,6 @@ XenNet_FillRing(struct xennet_info *xi)
   10.13      req->id = id;
   10.14      req->gref = (grant_ref_t)(page_buf->logical.QuadPart >> PAGE_SHIFT);
   10.15      ASSERT(req->gref != INVALID_GRANT_REF);
   10.16 -    //if (___restored)
   10.17 -    //  KdPrint((__DRIVER_NAME "     putting page_buf %p with id %d and gref %d and physical %p on ring at id %d\n", page_buf, page_buf->id, req->gref, page_buf->logical.LowPart, id));
   10.18    }
   10.19    KeMemoryBarrier();
   10.20    xi->rx.req_prod_pvt = req_prod + i;
   10.21 @@ -910,7 +906,6 @@ XenNet_RxResumeStart(xennet_info_t *xi)
   10.22  
   10.23    FUNCTION_ENTER();
   10.24  
   10.25 -  ___restored = TRUE;  
   10.26    KeAcquireSpinLock(&xi->rx_lock, &old_irql);
   10.27    XenNet_PurgeRing(xi);
   10.28    KeReleaseSpinLock(&xi->rx_lock, old_irql);
   10.29 @@ -1027,6 +1022,8 @@ XenNet_RxShutdown(xennet_info_t *xi)
   10.30  
   10.31    NdisFreePacketPool(xi->rx_packet_pool);
   10.32  
   10.33 +  NdisDeleteNPagedLookasideList(&xi->rx_lookaside_list);
   10.34 +
   10.35    KeReleaseSpinLock(&xi->rx_lock, OldIrql);
   10.36  
   10.37    FUNCTION_EXIT();
    11.1 --- a/xennet/xennet_tx.c	Sat Feb 14 13:35:48 2009 +1100
    11.2 +++ b/xennet/xennet_tx.c	Wed Feb 18 22:18:23 2009 +1100
    11.3 @@ -306,6 +306,7 @@ XenNet_HWSendPacket(struct xennet_info *
    11.4  
    11.5    //NDIS_SET_PACKET_STATUS(packet, NDIS_STATUS_SUCCESS);
    11.6    //FUNCTION_EXIT();
    11.7 +  xi->tx_outstanding++;
    11.8    return TRUE;
    11.9  }
   11.10  
   11.11 @@ -410,11 +411,12 @@ XenNet_TxBufferGC(PKDPC dpc, PVOID conte
   11.12    while (head)
   11.13    {
   11.14      packet = (PNDIS_PACKET)head;
   11.15 -//KdPrint(("-packet = %p\n", packet));
   11.16      head = *(PNDIS_PACKET *)&packet->MiniportReservedEx[0];
   11.17      NdisMSendComplete(xi->adapter_handle, packet, NDIS_STATUS_SUCCESS);
   11.18 +    xi->tx_outstanding--;
   11.19 +    if (!xi->tx_outstanding && xi->tx_shutting_down)
   11.20 +      KeSetEvent(&xi->tx_idle_event, IO_NO_INCREMENT, FALSE);
   11.21    }
   11.22 -//KdPrint((__DRIVER_NAME "     packets_outstanding = %d\n", packets_outstanding));
   11.23  
   11.24    if (xi->device_state->suspend_resume_state_pdo == SR_STATE_SUSPENDING
   11.25      && xi->device_state->suspend_resume_state_fdo != SR_STATE_SUSPENDING
   11.26 @@ -502,7 +504,6 @@ XenNet_TxResumeEnd(xennet_info_t *xi)
   11.27  BOOLEAN
   11.28  XenNet_TxInit(xennet_info_t *xi)
   11.29  {
   11.30 -  NDIS_STATUS status;
   11.31    USHORT i, j;
   11.32  
   11.33    KeInitializeSpinLock(&xi->tx_lock);
   11.34 @@ -512,13 +513,9 @@ XenNet_TxInit(xennet_info_t *xi)
   11.35    //KeSetImportanceDpc(&xi->tx_dpc, HighImportance);
   11.36    InitializeListHead(&xi->tx_waiting_pkt_list);
   11.37  
   11.38 -  NdisAllocateBufferPool(&status, &xi->tx_buffer_pool, TX_HEADER_BUFFERS);
   11.39 -  if (status != NDIS_STATUS_SUCCESS)
   11.40 -  {
   11.41 -    KdPrint(("NdisAllocateBufferPool failed with 0x%x\n", status));
   11.42 -    return FALSE;
   11.43 -  }
   11.44 -
   11.45 +  KeInitializeEvent(&xi->tx_idle_event, SynchronizationEvent, FALSE);
   11.46 +  xi->tx_shutting_down = FALSE;
   11.47 +  xi->tx_outstanding = 0;
   11.48    xi->tx_ring_free = NET_TX_RING_SIZE;
   11.49  
   11.50    for (i = 0; i < TX_HEADER_BUFFERS / (PAGE_SIZE / TX_HEADER_BUFFER_SIZE); i++)
   11.51 @@ -526,6 +523,8 @@ XenNet_TxInit(xennet_info_t *xi)
   11.52      PVOID virtual;
   11.53      NDIS_PHYSICAL_ADDRESS logical;
   11.54      NdisMAllocateSharedMemory(xi->adapter_handle, PAGE_SIZE, TRUE, &virtual, &logical);
   11.55 +    if (virtual == NULL)
   11.56 +      continue;
   11.57      //KdPrint((__DRIVER_NAME "     Allocated SharedMemory at %p\n", virtual));
   11.58      for (j = 0; j < PAGE_SIZE / TX_HEADER_BUFFER_SIZE; j++)
   11.59      {
   11.60 @@ -536,6 +535,8 @@ XenNet_TxInit(xennet_info_t *xi)
   11.61        put_hb_on_freelist(xi, &xi->tx_hbs[index]);
   11.62      }
   11.63    }
   11.64 +  if (i == 0)
   11.65 +    KdPrint((__DRIVER_NAME "     Unable to allocate any SharedMemory buffers\n"));
   11.66  
   11.67    xi->tx_id_free = 0;
   11.68    for (i = 0; i < NET_TX_RING_SIZE; i++)
   11.69 @@ -559,6 +560,7 @@ XenNet_TxShutdown(xennet_info_t *xi)
   11.70    //PMDL mdl;
   11.71    //ULONG i;
   11.72    KIRQL OldIrql;
   11.73 +  shared_buffer_t *hb;
   11.74  
   11.75    FUNCTION_ENTER();
   11.76  
   11.77 @@ -566,6 +568,8 @@ XenNet_TxShutdown(xennet_info_t *xi)
   11.78  
   11.79    KeAcquireSpinLock(&xi->tx_lock, &OldIrql);
   11.80  
   11.81 +  xi->tx_shutting_down = TRUE;
   11.82 +
   11.83    /* Free packets in tx queue */
   11.84    entry = RemoveHeadList(&xi->tx_waiting_pkt_list);
   11.85    while (entry != &xi->tx_waiting_pkt_list)
   11.86 @@ -575,19 +579,22 @@ XenNet_TxShutdown(xennet_info_t *xi)
   11.87      entry = RemoveHeadList(&xi->tx_waiting_pkt_list);
   11.88    }
   11.89    
   11.90 -#if 0
   11.91 -  /* free sent-but-not-completed packets */
   11.92 -  for (i = 0; i < NET_TX_RING_SIZE; i++)
   11.93 +  KeReleaseSpinLock(&xi->tx_lock, OldIrql);
   11.94 +
   11.95 +  while (xi->tx_outstanding)
   11.96    {
   11.97 -    mdl = xi->tx_mdls[i];
   11.98 -    if (mdl)
   11.99 -    {
  11.100 -      NdisAdjustBufferLength(xi->tx_mdls[i], PAGE_SIZE);
  11.101 -      //XenFreelist_PutPage(&xi->tx_freelist, xi->tx_mdls[i]);
  11.102 -    }
  11.103 +    KdPrint((__DRIVER_NAME "     Waiting for all packets to be sent\n"));
  11.104 +    KeWaitForSingleObject(&xi->tx_idle_event, Executive, KernelMode, FALSE, NULL);
  11.105    }
  11.106 -#endif
  11.107 -  NdisFreeBufferPool(xi->tx_buffer_pool);
  11.108 +
  11.109 +  KeAcquireSpinLock(&xi->tx_lock, &OldIrql);
  11.110 +
  11.111 +  while((hb = get_hb_from_freelist(xi)) != NULL)
  11.112 +  {
  11.113 +    /* only free the actual buffers which were aligned on a page boundary */
  11.114 +    if ((PtrToUlong(hb->virtual) & (PAGE_SIZE - 1)) == 0)
  11.115 +      NdisMFreeSharedMemory(xi->adapter_handle, PAGE_SIZE, TRUE, hb->virtual, hb->logical);
  11.116 +  }
  11.117  
  11.118    KeReleaseSpinLock(&xi->tx_lock, OldIrql);
  11.119  
    12.1 --- a/xenpci/makefile.inc	Sat Feb 14 13:35:48 2009 +1100
    12.2 +++ b/xenpci/makefile.inc	Wed Feb 18 22:18:23 2009 +1100
    12.3 @@ -1,6 +1,6 @@
    12.4  _LNG=$(LANGUAGE)
    12.5  STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION) -k $(KMDF_VERSION_MAJOR).$(KMDF_VERSION_MINOR)
    12.6  
    12.7 -$(INF_NAME).inf: $(INF_NAME).inx sources ..\common.inc
    12.8 +$(OBJ_PATH)\$(O)\$(TARGETNAME).inf: $(TARGETNAME).inx sources ..\common.inc
    12.9      copy $(@B).inx $@
   12.10      $(STAMP)
    13.1 --- a/xenpci/sources	Sat Feb 14 13:35:48 2009 +1100
    13.2 +++ b/xenpci/sources	Wed Feb 18 22:18:23 2009 +1100
    13.3 @@ -2,8 +2,7 @@
    13.4  TARGETNAME=xenpci
    13.5  TARGETTYPE=DRIVER
    13.6  KMDF_VERSION_MAJOR=1
    13.7 -INF_NAME=$(TARGETNAME)
    13.8 -MISCFILES=$(INF_NAME).inf
    13.9 +NTTARGETFILES=$(NTTARGETFILES) $(OBJ_PATH)\$(O)\$(TARGETNAME).inf
   13.10  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\wdmsec.lib $(DDK_LIB_PATH)\Rtlver.lib $(DDK_LIB_PATH)\aux_klib.lib
   13.11  AMD64_SOURCES=hypercall.asm
   13.12  I386_SOURCES=tpr_emulate.asm
    14.1 --- a/xenpci/xenbus_device_interface.c	Sat Feb 14 13:35:48 2009 +1100
    14.2 +++ b/xenpci/xenbus_device_interface.c	Wed Feb 18 22:18:23 2009 +1100
    14.3 @@ -19,7 +19,6 @@ Foundation, Inc., 51 Franklin Street, Fi
    14.4  
    14.5  #include "xenpci.h"
    14.6  
    14.7 -
    14.8  typedef struct {
    14.9    LIST_ENTRY entry;
   14.10    PVOID data;
   14.11 @@ -69,7 +68,7 @@ XenPci_ProcessReadRequest(WDFQUEUE queue
   14.12    NTSTATUS status;
   14.13    WDFFILEOBJECT file_object = WdfRequestGetFileObject(request);
   14.14    PXENPCI_DEVICE_INTERFACE_DATA xpdid = GetXpdid(file_object);
   14.15 -  ULONG dst_length = length;
   14.16 +  ULONG dst_length = (ULONG)length;
   14.17    ULONG dst_offset = 0;
   14.18    ULONG copy_length;
   14.19    xenbus_read_queue_item_t *list_entry;
   14.20 @@ -94,8 +93,8 @@ XenPci_ProcessReadRequest(WDFQUEUE queue
   14.21      dst_offset += copy_length;
   14.22      if (list_entry->offset == list_entry->length)
   14.23      {
   14.24 -      // free the list entry
   14.25 -      // free the data
   14.26 +      ExFreePoolWithTag(list_entry->data, XENPCI_POOL_TAG);
   14.27 +      ExFreePoolWithTag(list_entry, XENPCI_POOL_TAG);
   14.28      }
   14.29      else
   14.30      {
   14.31 @@ -117,19 +116,23 @@ XenPci_IoWatch(char *path, PVOID context
   14.32    KIRQL old_irql;
   14.33    struct xsd_sockmsg *rep;
   14.34    xenbus_read_queue_item_t *list_entry;
   14.35 +  size_t remaining;
   14.36    WDFREQUEST request;
   14.37  
   14.38    FUNCTION_ENTER();
   14.39    
   14.40    KeAcquireSpinLock(&xpdid->lock, &old_irql);
   14.41    
   14.42 +  remaining = sizeof(struct xsd_sockmsg) + strlen(path) + 1 + strlen(watch_context->token) + 1;
   14.43    rep = ExAllocatePoolWithTag(NonPagedPool, sizeof(struct xsd_sockmsg) + strlen(path) + 1 + strlen(watch_context->token) + 1, XENPCI_POOL_TAG);
   14.44    rep->type = XS_WATCH_EVENT;
   14.45    rep->req_id = 0;
   14.46    rep->tx_id = 0;
   14.47 -  rep->len = strlen(path) + 1 + strlen(watch_context->token) + 1;
   14.48 -  strcpy((PCHAR)(rep + 1), path);
   14.49 -  strcpy((PCHAR)(rep + 1) + strlen(path) + 1, watch_context->token);
   14.50 +  rep->len = (ULONG)(strlen(path) + 1 + strlen(watch_context->token) + 1);
   14.51 +  remaining -= sizeof(struct xsd_sockmsg);
   14.52 +  RtlStringCbCopyA((PCHAR)(rep + 1), remaining, path);
   14.53 +  remaining -= strlen(path) + 1;
   14.54 +  RtlStringCbCopyA((PCHAR)(rep + 1) + strlen(path) + 1, remaining, watch_context->token);
   14.55    
   14.56    list_entry = (xenbus_read_queue_item_t *)ExAllocatePoolWithTag(NonPagedPool, sizeof(xenbus_read_queue_item_t), XENPCI_POOL_TAG);
   14.57    list_entry->data = rep;
   14.58 @@ -207,6 +210,8 @@ XenPci_EvtIoRead(WDFQUEUE queue, WDFREQU
   14.59    PXENPCI_DEVICE_INTERFACE_DATA xpdid = GetXpdid(file_object);
   14.60    KIRQL old_irql;
   14.61  
   14.62 +  UNREFERENCED_PARAMETER(queue);
   14.63 +  
   14.64    FUNCTION_ENTER();
   14.65    status = WdfRequestForwardToIoQueue(request, xpdid->io_queue);
   14.66    if (!NT_SUCCESS(status))
   14.67 @@ -266,7 +271,7 @@ XenPci_EvtIoWrite(WDFQUEUE queue, WDFREQ
   14.68    ASSERT(NT_SUCCESS(status));
   14.69    
   14.70    src_ptr = (PUCHAR)buffer;
   14.71 -  src_len = length;
   14.72 +  src_len = (ULONG)length;
   14.73    dst_ptr = xpdid->u.buffer + xpdid->len;
   14.74    while (src_len != 0)
   14.75    {
   14.76 @@ -310,10 +315,10 @@ XenPci_EvtIoWrite(WDFQUEUE queue, WDFREQ
   14.77      case XS_UNWATCH:
   14.78        KeAcquireSpinLock(&xpdid->lock, &old_irql);
   14.79        watch_context = (watch_context_t *)ExAllocatePoolWithTag(NonPagedPool, sizeof(watch_context_t), XENPCI_POOL_TAG);
   14.80 -      watch_path = xpdid->u.buffer + sizeof(struct xsd_sockmsg);
   14.81 -      watch_token = xpdid->u.buffer + sizeof(struct xsd_sockmsg) + strlen(watch_path) + 1;
   14.82 -      strcpy(watch_context->path, watch_path);
   14.83 -      strcpy(watch_context->token, watch_token);
   14.84 +      watch_path = (PCHAR)(xpdid->u.buffer + sizeof(struct xsd_sockmsg));
   14.85 +      watch_token = (PCHAR)(xpdid->u.buffer + sizeof(struct xsd_sockmsg) + strlen(watch_path) + 1);
   14.86 +      RtlStringCbCopyA(watch_context->path, ARRAY_SIZE(watch_context->path), watch_path);
   14.87 +      RtlStringCbCopyA(watch_context->token, ARRAY_SIZE(watch_context->path), watch_token);
   14.88        watch_context->file_object = file_object;
   14.89        if (xpdid->u.msg.type == XS_WATCH)
   14.90          InsertTailList(&xpdid->watch_list_head, &watch_context->entry);
   14.91 @@ -329,8 +334,8 @@ XenPci_EvtIoWrite(WDFQUEUE queue, WDFREQ
   14.92          rep->type = XS_ERROR;
   14.93          rep->req_id = xpdid->u.msg.req_id;
   14.94          rep->tx_id = xpdid->u.msg.tx_id;
   14.95 -        rep->len = strlen(msg) + 0;
   14.96 -        strcpy((PCHAR)(rep + 1), msg);
   14.97 +        rep->len = (ULONG)(strlen(msg) + 0);
   14.98 +        RtlStringCbCopyA((PCHAR)(rep + 1), strlen(msg) + 1, msg);
   14.99          if (xpdid->u.msg.type == XS_WATCH)
  14.100            RemoveEntryList(&watch_context->entry);
  14.101        }
  14.102 @@ -371,290 +376,4 @@ XenPci_EvtIoWrite(WDFQUEUE queue, WDFREQ
  14.103    WdfRequestCompleteWithInformation(request, STATUS_SUCCESS, length);
  14.104  
  14.105    FUNCTION_EXIT();
  14.106 -}
  14.107 -
  14.108 -#if 0
  14.109 -NTSTATUS
  14.110 -XenPci_Irp_Create_XenBus(PDEVICE_OBJECT device_object, PIRP irp)
  14.111 -{
  14.112 -  NTSTATUS status;
  14.113 -  PIO_STACK_LOCATION stack;
  14.114 -  PFILE_OBJECT file;
  14.115 -  device_interface_xenbus_context_t *dixc;
  14.116 -  
  14.117 -  FUNCTION_ENTER();
  14.118 -  
  14.119 -  UNREFERENCED_PARAMETER(device_object);
  14.120 -  stack = IoGetCurrentIrpStackLocation(irp);
  14.121 -  file = stack->FileObject;
  14.122 -  dixc = (device_interface_xenbus_context_t *)ExAllocatePoolWithTag(NonPagedPool, sizeof(device_interface_xenbus_context_t), XENPCI_POOL_TAG);
  14.123 -  dixc->type = DEVICE_INTERFACE_TYPE_XENBUS;
  14.124 -  KeInitializeSpinLock(&dixc->lock);
  14.125 -  InitializeListHead(&dixc->read_list_head);
  14.126 -  dixc->len = 0;
  14.127 -  file->FsContext = dixc;
  14.128 -  status = STATUS_SUCCESS;    
  14.129 -  dixc->pending_read_irp = NULL;
  14.130 -  irp->IoStatus.Status = status;
  14.131 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.132 -  
  14.133 -  FUNCTION_EXIT();
  14.134 -  
  14.135 -  return status;
  14.136 -}
  14.137 -
  14.138 -NTSTATUS
  14.139 -XenPci_Irp_Close_XenBus(PDEVICE_OBJECT device_object, PIRP irp)
  14.140 -{
  14.141 -  PXENPCI_DEVICE_DATA xpdd;
  14.142 -  NTSTATUS status;
  14.143 -
  14.144 -  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  14.145 -  status = STATUS_SUCCESS;    
  14.146 -  irp->IoStatus.Status = status;
  14.147 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.148 -  // cleanup dixc here
  14.149 -  
  14.150 -  return status;
  14.151 -}
  14.152 -
  14.153 -static NTSTATUS
  14.154 -XenPci_Irp_Read_XenBus_Complete(device_interface_xenbus_context_t *dixc, PIRP irp)
  14.155 -{
  14.156 -  KIRQL old_irql;
  14.157 -  ULONG dst_length;
  14.158 -  ULONG dst_offset;
  14.159 -  ULONG copy_length;
  14.160 -  xenbus_read_queue_item_t *list_entry;
  14.161 -  PIO_STACK_LOCATION stack;
  14.162 -  NTSTATUS status;
  14.163 -
  14.164 -  FUNCTION_ENTER();
  14.165 -  
  14.166 -KdPrint((__DRIVER_NAME "     A - dixc = %p, irp = %p\n", dixc, irp));
  14.167 -  stack = IoGetCurrentIrpStackLocation(irp);
  14.168 -KdPrint((__DRIVER_NAME "     Aa\n"));
  14.169 -  dst_length = stack->Parameters.Read.Length;
  14.170 -KdPrint((__DRIVER_NAME "     B - dst_length = %d\n", dst_length));
  14.171 -  dst_offset = 0;
  14.172 -KdPrint((__DRIVER_NAME "     C\n"));
  14.173 -  KeAcquireSpinLock(&dixc->lock, &old_irql);
  14.174 -KdPrint((__DRIVER_NAME "     D"));
  14.175 -  while(dst_offset < dst_length && (list_entry = (xenbus_read_queue_item_t *)RemoveHeadList(&dixc->read_list_head)) != (xenbus_read_queue_item_t *)&dixc->read_list_head)
  14.176 -  {
  14.177 -KdPrint((__DRIVER_NAME "     E\n"));
  14.178 -    copy_length = min(list_entry->length - list_entry->offset, dst_length - dst_offset);
  14.179 -    KdPrint((__DRIVER_NAME "     copying %d bytes\n", copy_length));
  14.180 -    memcpy((PUCHAR)irp->AssociatedIrp.SystemBuffer + dst_offset, (PUCHAR)list_entry->data + list_entry->offset, copy_length);
  14.181 -    list_entry->offset += copy_length;
  14.182 -    dst_offset += copy_length;
  14.183 -    if (list_entry->offset == list_entry->length)
  14.184 -    {
  14.185 -      // free the list entry
  14.186 -      // free the data
  14.187 -    }
  14.188 -    else
  14.189 -    {
  14.190 -      InsertHeadList(&dixc->read_list_head, (PLIST_ENTRY)list_entry);
  14.191 -    }      
  14.192 -  }
  14.193 -  KeReleaseSpinLock(&dixc->lock, old_irql);
  14.194 -KdPrint((__DRIVER_NAME "     F\n"));
  14.195 -  
  14.196 -  if (dst_offset > 0)
  14.197 -  {
  14.198 -    KdPrint((__DRIVER_NAME "     completing request\n"));
  14.199 -    status = STATUS_SUCCESS;
  14.200 -    irp->IoStatus.Status = status;
  14.201 -    irp->IoStatus.Information = dst_offset;
  14.202 -    IoSetCancelRoutine(irp, NULL);
  14.203 -    IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.204 -  }
  14.205 -  else
  14.206 -  {
  14.207 -    KdPrint((__DRIVER_NAME "     pending request\n"));
  14.208 -    status = STATUS_PENDING;
  14.209 -  }
  14.210 -
  14.211 -  FUNCTION_EXIT();
  14.212 -
  14.213 -  return status;
  14.214 -}
  14.215 -
  14.216 -static VOID
  14.217 -XenPci_Irp_Read_Cancel(PDEVICE_OBJECT device_object, PIRP irp)
  14.218 -{
  14.219 -  PIO_STACK_LOCATION stack;
  14.220 -  PFILE_OBJECT file;
  14.221 -  device_interface_xenbus_context_t *dixc;
  14.222 -  KIRQL old_irql;
  14.223 -
  14.224 -  FUNCTION_ENTER();
  14.225 -
  14.226 -  UNREFERENCED_PARAMETER(device_object);
  14.227 -
  14.228 -  stack = IoGetCurrentIrpStackLocation(irp);
  14.229 -  file = stack->FileObject;
  14.230 -  dixc = file->FsContext;
  14.231 -  IoReleaseCancelSpinLock(irp->CancelIrql);
  14.232 -  KeAcquireSpinLock(&dixc->lock, &old_irql);
  14.233 -  if (irp != dixc->pending_read_irp)
  14.234 -  {
  14.235 -    KdPrint((__DRIVER_NAME "     Not the current irp???\n"));
  14.236 -  }
  14.237 -  dixc->pending_read_irp = NULL;
  14.238 -  irp->IoStatus.Status = STATUS_CANCELLED;
  14.239 -  irp->IoStatus.Information = 0;
  14.240 -  KeReleaseSpinLock(&dixc->lock, old_irql);
  14.241 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.242 -
  14.243 -  FUNCTION_EXIT();
  14.244 -}
  14.245 -
  14.246 -NTSTATUS
  14.247 -XenPci_Irp_Read_XenBus(PDEVICE_OBJECT device_object, PIRP irp)
  14.248 -{
  14.249 -  NTSTATUS status;
  14.250 -  PIO_STACK_LOCATION stack;
  14.251 -  PFILE_OBJECT file;
  14.252 -  device_interface_xenbus_context_t *dixc;
  14.253 -  KIRQL old_irql;
  14.254 -
  14.255 -  UNREFERENCED_PARAMETER(device_object);
  14.256 -
  14.257 -  stack = IoGetCurrentIrpStackLocation(irp);
  14.258 -  file = stack->FileObject;
  14.259 -  dixc = file->FsContext;
  14.260 -
  14.261 -  ASSERT(!dixc->pending_read_irp);
  14.262 -  
  14.263 -  if (stack->Parameters.Read.Length == 0)
  14.264 -  {
  14.265 -    status = STATUS_SUCCESS;    
  14.266 -    irp->IoStatus.Status = status;
  14.267 -    irp->IoStatus.Information = 0;
  14.268 -    IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.269 -  }
  14.270 -  else 
  14.271 -  {
  14.272 -    status = XenPci_Irp_Read_XenBus_Complete(dixc, irp);
  14.273 -    if (status == STATUS_PENDING)
  14.274 -    {
  14.275 -      IoMarkIrpPending(irp);
  14.276 -      KeAcquireSpinLock(&dixc->lock, &old_irql);
  14.277 -      dixc->pending_read_irp = irp;
  14.278 -      KeReleaseSpinLock(&dixc->lock, old_irql);
  14.279 -      IoSetCancelRoutine(irp, XenPci_Irp_Read_Cancel);
  14.280 -    }
  14.281 -  }
  14.282 -  return status;
  14.283 -}
  14.284 -
  14.285 -NTSTATUS
  14.286 -XenPci_Irp_Write_XenBus(PDEVICE_OBJECT device_object, PIRP irp)
  14.287 -{
  14.288 -  NTSTATUS status;
  14.289 -  PIO_STACK_LOCATION stack;
  14.290 -  PFILE_OBJECT file;
  14.291 -  device_interface_xenbus_context_t *dixc;
  14.292 -  PUCHAR src_ptr;
  14.293 -  ULONG src_len;
  14.294 -  PUCHAR dst_ptr;
  14.295 -  ULONG copy_len;
  14.296 -  struct xsd_sockmsg *rep;
  14.297 -  PXENPCI_DEVICE_DATA xpdd;
  14.298 -  KIRQL old_irql;
  14.299 -  xenbus_read_queue_item_t *list_entry;
  14.300 -  PIRP read_irp;
  14.301 -  NTSTATUS read_status;
  14.302 -  
  14.303 -  FUNCTION_ENTER();
  14.304 -  
  14.305 -  xpdd = device_object->DeviceExtension;
  14.306 -  stack = IoGetCurrentIrpStackLocation(irp);
  14.307 -  file = stack->FileObject;
  14.308 -  dixc = file->FsContext;
  14.309 -  
  14.310 -  KdPrint((__DRIVER_NAME "     write length = %d\n", stack->Parameters.Write.Length));
  14.311 -  
  14.312 -  src_ptr = (PUCHAR)irp->AssociatedIrp.SystemBuffer;
  14.313 -  src_len = stack->Parameters.Write.Length;
  14.314 -  dst_ptr = dixc->u.buffer + dixc->len;
  14.315 -  while (src_len != 0)
  14.316 -  {
  14.317 -    /* get a complete msg header */
  14.318 -    if (dixc->len < sizeof(dixc->u.msg))
  14.319 -    {
  14.320 -      copy_len = min(sizeof(dixc->u.msg) - dixc->len, src_len);
  14.321 -      if (!copy_len)
  14.322 -        continue;
  14.323 -      memcpy(dst_ptr, src_ptr, copy_len);
  14.324 -      dst_ptr += copy_len;
  14.325 -      src_ptr += copy_len;
  14.326 -      src_len -= copy_len;
  14.327 -      dixc->len += copy_len;
  14.328 -    }
  14.329 -    /* exit if we can't get that */
  14.330 -    if (dixc->len < sizeof(dixc->u.msg))
  14.331 -      continue;
  14.332 -    /* get a complete msg body */
  14.333 -    if (dixc->len < sizeof(dixc->u.msg) + dixc->u.msg.len)
  14.334 -    {
  14.335 -      copy_len = min(sizeof(dixc->u.msg) + dixc->u.msg.len - dixc->len, src_len);
  14.336 -      if (!copy_len)
  14.337 -        continue;
  14.338 -      memcpy(dst_ptr, src_ptr, copy_len);
  14.339 -      dst_ptr += copy_len;
  14.340 -      src_ptr += copy_len;
  14.341 -      src_len -= copy_len;
  14.342 -      dixc->len += copy_len;
  14.343 -    }
  14.344 -    /* exit if we can't get that */
  14.345 -    if (dixc->len < sizeof(dixc->u.msg) + dixc->u.msg.len)
  14.346 -    {
  14.347 -      continue;
  14.348 -    }
  14.349 -    
  14.350 -    rep = XenBus_Raw(xpdd, &dixc->u.msg);
  14.351 -    KeAcquireSpinLock(&dixc->lock, &old_irql);
  14.352 -    list_entry = (xenbus_read_queue_item_t *)ExAllocatePoolWithTag(NonPagedPool, sizeof(xenbus_read_queue_item_t), XENPCI_POOL_TAG);
  14.353 -    list_entry->data = rep;
  14.354 -    list_entry->length = sizeof(*rep) + rep->len;
  14.355 -    list_entry->offset = 0;
  14.356 -    InsertTailList(&dixc->read_list_head, (PLIST_ENTRY)list_entry);
  14.357 -    read_irp = dixc->pending_read_irp;
  14.358 -    dixc->pending_read_irp = NULL;
  14.359 -    KeReleaseSpinLock(&dixc->lock, old_irql);
  14.360 -    if (read_irp)
  14.361 -    {
  14.362 -      read_status = XenPci_Irp_Read_XenBus_Complete(dixc, read_irp);
  14.363 -      ASSERT(read_status == STATUS_SUCCESS);
  14.364 -    }
  14.365 -  }
  14.366 -  status = STATUS_SUCCESS;    
  14.367 -  irp->IoStatus.Status = status;
  14.368 -  irp->IoStatus.Information = stack->Parameters.Write.Length;
  14.369 -
  14.370 -  KdPrint((__DRIVER_NAME "     Information = %d\n", irp->IoStatus.Information));
  14.371 -
  14.372 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.373 -
  14.374 -  FUNCTION_EXIT();
  14.375 -
  14.376 -  return status;
  14.377 -}
  14.378 -
  14.379 -NTSTATUS
  14.380 -XenPci_Irp_Cleanup_XenBus(PDEVICE_OBJECT device_object, PIRP irp)
  14.381 -{
  14.382 -  PXENPCI_DEVICE_DATA xpdd;
  14.383 -  NTSTATUS status;
  14.384 -
  14.385 -  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  14.386 -  status = STATUS_SUCCESS;    
  14.387 -  irp->IoStatus.Status = status;
  14.388 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
  14.389 -
  14.390 -  return status;
  14.391 -}
  14.392 -#endif
  14.393 \ No newline at end of file
  14.394 +}
  14.395 \ No newline at end of file
    15.1 --- a/xenpci/xenpci.c	Sat Feb 14 13:35:48 2009 +1100
    15.2 +++ b/xenpci/xenpci.c	Wed Feb 18 22:18:23 2009 +1100
    15.3 @@ -25,148 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fi
    15.4  #define SHUTDOWN_PATH "control/shutdown"
    15.5  #define BALLOON_PATH "memory/target"
    15.6  
    15.7 -#if 0
    15.8 -#ifdef ALLOC_PRAGMA
    15.9 -DRIVER_INITIALIZE DriverEntry;
   15.10 -#pragma alloc_text (INIT, DriverEntry)
   15.11 -#endif
   15.12 -
   15.13  #pragma warning(disable : 4200) // zero-sized array
   15.14  
   15.15 -static DDKAPI NTSTATUS
   15.16 -XenPci_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
   15.17 -{
   15.18 -  NTSTATUS status;
   15.19 -  PXENPCI_COMMON common = device_object->DeviceExtension;
   15.20 -  
   15.21 -  if (common->lower_do)
   15.22 -    status = XenPci_Pnp_Fdo(device_object, irp);
   15.23 -  else
   15.24 -    status = XenPci_Pnp_Pdo(device_object, irp);  
   15.25 -
   15.26 -  return status;
   15.27 -}
   15.28 -
   15.29 -static DDKAPI NTSTATUS
   15.30 -XenPci_Power(PDEVICE_OBJECT device_object, PIRP irp)
   15.31 -{
   15.32 -  NTSTATUS status;
   15.33 -  PXENPCI_COMMON common = device_object->DeviceExtension;
   15.34 -  
   15.35 -  if (common->lower_do)
   15.36 -    status = XenPci_Power_Fdo(device_object, irp);
   15.37 -  else
   15.38 -    status = XenPci_Power_Pdo(device_object, irp);  
   15.39 -
   15.40 -  return status;
   15.41 -}
   15.42 -
   15.43 -static DDKAPI NTSTATUS
   15.44 -XenPci_Irp_Create(PDEVICE_OBJECT device_object, PIRP irp)
   15.45 -{
   15.46 -  NTSTATUS status;
   15.47 -  PXENPCI_COMMON common = device_object->DeviceExtension;
   15.48 -  
   15.49 -  if (common->lower_do)
   15.50 -    status = XenPci_Irp_Create_Fdo(device_object, irp);
   15.51 -  else
   15.52 -    status = XenPci_Irp_Create_Pdo(device_object, irp);  
   15.53 -
   15.54 -  return status;
   15.55 -}
   15.56 -
   15.57 -static DDKAPI NTSTATUS
   15.58 -XenPci_Irp_Close(PDEVICE_OBJECT device_object, PIRP irp)
   15.59 -{
   15.60 -  NTSTATUS status;
   15.61 -  PXENPCI_COMMON common = device_object->DeviceExtension;
   15.62 -  
   15.63 -  if (common->lower_do)
   15.64 -    status = XenPci_Irp_Close_Fdo(device_object, irp);
   15.65 -  else
   15.66 -    status = XenPci_Irp_Close_Pdo(device_object, irp);  
   15.67 -
   15.68 -  return status;
   15.69 -}
   15.70 -
   15.71 -static DDKAPI NTSTATUS
   15.72 -XenPci_Irp_Read(PDEVICE_OBJECT device_object, PIRP irp)
   15.73 -{
   15.74 -  NTSTATUS status;
   15.75 -  PXENPCI_COMMON common = device_object->DeviceExtension;
   15.76 -  
   15.77 -  if (common->lower_do)
   15.78 -    status = XenPci_Irp_Read_Fdo(device_object, irp);
   15.79 -  else
   15.80 -    status = XenPci_Irp_Read_Pdo(device_object, irp);  
   15.81 -
   15.82 -  return status;
   15.83 -}
   15.84 -
   15.85 -static DDKAPI NTSTATUS
   15.86 -XenPci_Irp_Write(PDEVICE_OBJECT device_object, PIRP irp)
   15.87 -{
   15.88 -  NTSTATUS status;
   15.89 -  PXENPCI_COMMON common = device_object->DeviceExtension;
   15.90 -  
   15.91 -  if (common->lower_do)
   15.92 -    status = XenPci_Irp_Write_Fdo(device_object, irp);
   15.93 -  else
   15.94 -    status = XenPci_Irp_Write_Pdo(device_object, irp);  
   15.95 -
   15.96 -  return status;
   15.97 -}
   15.98 -
   15.99 -static DDKAPI NTSTATUS
  15.100 -XenPci_Irp_Cleanup(PDEVICE_OBJECT device_object, PIRP irp)
  15.101 -{
  15.102 -  NTSTATUS status;
  15.103 -  PXENPCI_COMMON common = device_object->DeviceExtension;
  15.104 -  
  15.105 -  if (common->lower_do)
  15.106 -    status = XenPci_Irp_Cleanup_Fdo(device_object, irp);
  15.107 -  else
  15.108 -    status = XenPci_Irp_Cleanup_Pdo(device_object, irp);  
  15.109 -
  15.110 -  return status;
  15.111 -}
  15.112 -
  15.113 -static DDKAPI NTSTATUS
  15.114 -XenPci_SystemControl(PDEVICE_OBJECT device_object, PIRP irp)
  15.115 -{
  15.116 -  NTSTATUS status;
  15.117 -  PXENPCI_COMMON common = device_object->DeviceExtension;
  15.118 -  
  15.119 -  if (common->lower_do)
  15.120 -    status = XenPci_SystemControl_Fdo(device_object, irp);
  15.121 -  else
  15.122 -    status = XenPci_SystemControl_Pdo(device_object, irp);  
  15.123 -
  15.124 -  return status;
  15.125 -}
  15.126 -
  15.127 -static DDKAPI NTSTATUS
  15.128 -XenPci_Dummy(PDEVICE_OBJECT device_object, PIRP irp)
  15.129 -{
  15.130 -  NTSTATUS status;
  15.131 -  PIO_STACK_LOCATION stack;
  15.132 -  PXENPCI_COMMON common = device_object->DeviceExtension;
  15.133 -  
  15.134 -  FUNCTION_ENTER();
  15.135 -
  15.136 -  UNREFERENCED_PARAMETER(device_object);
  15.137 -
  15.138 -  stack = IoGetCurrentIrpStackLocation(irp);
  15.139 -  KdPrint((__DRIVER_NAME "     Major = %d, Minor = %d\n", stack->MajorFunction, stack->MinorFunction));
  15.140 -  IoSkipCurrentIrpStackLocation(irp);
  15.141 -  status = IoCallDriver(common->lower_do, irp);
  15.142 -
  15.143 -  FUNCTION_EXIT();
  15.144 -  
  15.145 -  return status;
  15.146 -}
  15.147 -#endif
  15.148 -
  15.149  static NTSTATUS
  15.150  XenPci_EvtDeviceAdd(WDFDRIVER driver, PWDFDEVICE_INIT device_init)
  15.151  {
  15.152 @@ -198,6 +58,8 @@ XenPci_EvtDeviceAdd(WDFDRIVER driver, PW
  15.153    pnp_power_callbacks.EvtDeviceD0ExitPreInterruptsDisabled = XenPci_EvtDeviceD0ExitPreInterruptsDisabled;
  15.154    pnp_power_callbacks.EvtDevicePrepareHardware = XenPci_EvtDevicePrepareHardware;
  15.155    pnp_power_callbacks.EvtDeviceReleaseHardware = XenPci_EvtDeviceReleaseHardware;
  15.156 +  pnp_power_callbacks.EvtDeviceQueryRemove = XenPci_EvtDeviceQueryRemove;
  15.157 +  
  15.158    WdfDeviceInitSetPnpPowerEventCallbacks(device_init, &pnp_power_callbacks);
  15.159  
  15.160    WdfDeviceInitSetDeviceType(device_init, FILE_DEVICE_BUS_EXTENDER);
  15.161 @@ -258,91 +120,10 @@ XenPci_EvtDeviceAdd(WDFDRIVER driver, PW
  15.162    pbi.BusNumber = 0;
  15.163    WdfDeviceSetBusInformationForChildren(device, &pbi);
  15.164  
  15.165 -#if 0
  15.166 -  xpdd->shutdown_prod = 0;
  15.167 -  xpdd->shutdown_cons = 0;
  15.168 -  KeInitializeSpinLock(&xpdd->shutdown_ring_lock);
  15.169 -#endif
  15.170 +  xpdd->removable = TRUE;
  15.171  
  15.172    FUNCTION_EXIT();
  15.173    return status;
  15.174 -  
  15.175 -#if 0                                
  15.176 -  status = IoCreateDevice(DriverObject,
  15.177 -    sizeof(XENPCI_DEVICE_DATA),
  15.178 -    NULL,
  15.179 -    FILE_DEVICE_BUS_EXTENDER,
  15.180 -    FILE_DEVICE_SECURE_OPEN,
  15.181 -    FALSE,
  15.182 -    &fdo);
  15.183 -
  15.184 -  if (!NT_SUCCESS(status))
  15.185 -  {
  15.186 -    KdPrint((__DRIVER_NAME "     IoCreateDevice failed 0x%08x\n", status));
  15.187 -    return status;
  15.188 -  }
  15.189 -
  15.190 -  fdo->Flags |= DO_BUFFERED_IO;
  15.191 -  
  15.192 -  xpdd = (PXENPCI_DEVICE_DATA)fdo->DeviceExtension;
  15.193 -
  15.194 -  RtlZeroMemory(xpdd, sizeof(XENPCI_DEVICE_DATA));
  15.195 -
  15.196 -  xpdd->shutdown_prod = 0;
  15.197 -  xpdd->shutdown_cons = 0;
  15.198 -  KeInitializeSpinLock(&xpdd->shutdown_ring_lock);
  15.199 -
  15.200 -  xpdd->common.fdo = fdo;
  15.201 -  xpdd->common.pdo = PhysicalDeviceObject;
  15.202 -  xpdd->common.lower_do = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
  15.203 -  if(xpdd->common.lower_do == NULL) {
  15.204 -    IoDeleteDevice(fdo);
  15.205 -    return STATUS_NO_SUCH_DEVICE;
  15.206 -  }
  15.207 -  INIT_PNP_STATE(&xpdd->common);
  15.208 -  xpdd->common.device_usage_paging = 0;
  15.209 -  xpdd->common.device_usage_dump = 0;
  15.210 -  xpdd->common.device_usage_hibernation = 0;
  15.211 -
  15.212 -  InitializeListHead(&xpdd->child_list);
  15.213 -
  15.214 -  RtlInitUnicodeString(&reference, L"legacy");
  15.215 -  status = IoRegisterDeviceInterface(
  15.216 -    PhysicalDeviceObject,
  15.217 -    &GUID_XEN_IFACE,
  15.218 -    &reference,
  15.219 -    &xpdd->legacy_interface_name);
  15.220 -
  15.221 -  if (!NT_SUCCESS(status))
  15.222 -  {
  15.223 -    KdPrint((__DRIVER_NAME "     IoRegisterDeviceInterface(GUID_XEN_IFACE) failed with status 0x%08x\n", status));
  15.224 -  }
  15.225 -  else
  15.226 -  {
  15.227 -    KdPrint((__DRIVER_NAME "     IoRegisterDeviceInterface(GUID_XEN_IFACE) succeeded - %wZ\n", &xpdd->legacy_interface_name));
  15.228 -  }
  15.229 -
  15.230 -  RtlInitUnicodeString(&reference, L"xenbus");
  15.231 -  status = IoRegisterDeviceInterface(
  15.232 -    PhysicalDeviceObject,
  15.233 -    &GUID_XENBUS_IFACE,
  15.234 -    &reference,
  15.235 -    &xpdd->interface_name);
  15.236 -
  15.237 -  if (!NT_SUCCESS(status))
  15.238 -  {
  15.239 -    KdPrint((__DRIVER_NAME "     IoRegisterDeviceInterface(GUID_XENBUS_IFACE) failed with status 0x%08x\n", status));
  15.240 -  }
  15.241 -  else
  15.242 -  {
  15.243 -    KdPrint((__DRIVER_NAME "     IoRegisterDeviceInterface(GUID_XENBUS_IFACE) succeeded - %wZ\n", &xpdd->interface_name));
  15.244 -  }
  15.245 -
  15.246 -  fdo->Flags &= ~DO_DEVICE_INITIALIZING;
  15.247 -
  15.248 -  FUNCTION_EXIT();
  15.249 -  return status;
  15.250 -#endif
  15.251  }
  15.252  
  15.253  ULONG qemu_filtered;
  15.254 @@ -460,7 +241,12 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  15.255        qemu_filtered = TRUE;
  15.256      }
  15.257    }
  15.258 -
  15.259 +  
  15.260 +  if (qemu_filtered)
  15.261 +    KdPrint((__DRIVER_NAME "     PV Devices Active\n"));
  15.262 +  else
  15.263 +    KdPrint((__DRIVER_NAME "     PV Devices InActive\n"));
  15.264 +  
  15.265    WDF_DRIVER_CONFIG_INIT(&config, XenPci_EvtDeviceAdd);
  15.266    status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, &driver);
  15.267  
  15.268 @@ -468,19 +254,6 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  15.269      KdPrint( ("WdfDriverCreate failed with status 0x%x\n", status));
  15.270    }
  15.271  
  15.272 -#if 0
  15.273 -  DriverObject->DriverExtension->AddDevice = XenPci_AddDevice;
  15.274 -  DriverObject->MajorFunction[IRP_MJ_PNP] = XenPci_Pnp;
  15.275 -  DriverObject->MajorFunction[IRP_MJ_POWER] = XenPci_Power;
  15.276 -  DriverObject->MajorFunction[IRP_MJ_CREATE] = XenPci_Irp_Create;
  15.277 -  DriverObject->MajorFunction[IRP_MJ_CLOSE] = XenPci_Irp_Close;
  15.278 -  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = XenPci_Irp_Cleanup;
  15.279 -  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = XenPci_Dummy;
  15.280 -  DriverObject->MajorFunction[IRP_MJ_READ] = XenPci_Irp_Read;
  15.281 -  DriverObject->MajorFunction[IRP_MJ_WRITE] = XenPci_Irp_Write;
  15.282 -  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = XenPci_SystemControl;
  15.283 -#endif
  15.284 -
  15.285    FUNCTION_EXIT();
  15.286  
  15.287    return status;
    16.1 --- a/xenpci/xenpci.h	Sat Feb 14 13:35:48 2009 +1100
    16.2 +++ b/xenpci/xenpci.h	Wed Feb 18 22:18:23 2009 +1100
    16.3 @@ -109,58 +109,6 @@ typedef struct _XENBUS_WATCH_ENTRY {
    16.4  #define CHILD_STATE_DELETED 1
    16.5  #define CHILD_STATE_ADDED 2
    16.6  
    16.7 -#if 0
    16.8 -// TODO: tidy up & organize this struct
    16.9 -
   16.10 -typedef enum {
   16.11 -    Unknown = 0,
   16.12 -    NotStarted,
   16.13 -    Started,
   16.14 -    StopPending,
   16.15 -    Stopped,
   16.16 -    RemovePending,
   16.17 -    SurpriseRemovePending,
   16.18 -    Removed
   16.19 -} DEVICE_PNP_STATE;
   16.20 -
   16.21 -#if 0
   16.22 -typedef struct
   16.23 -{
   16.24 -  PDEVICE_OBJECT fdo;
   16.25 -  PDEVICE_OBJECT pdo;
   16.26 -  PDEVICE_OBJECT lower_do;
   16.27 -  
   16.28 -  DEVICE_PNP_STATE current_pnp_state;
   16.29 -  DEVICE_PNP_STATE previous_pnp_state;
   16.30 -  DEVICE_POWER_STATE device_power_state;
   16.31 -  SYSTEM_POWER_STATE system_power_state;
   16.32 -  
   16.33 -  ULONG device_usage_paging;
   16.34 -  ULONG device_usage_dump;
   16.35 -  ULONG device_usage_hibernation;
   16.36 -} XENPCI_COMMON, *PXENPCI_COMMON;
   16.37 -#endif
   16.38 -
   16.39 -static __inline void INIT_PNP_STATE(PXENPCI_COMMON common)
   16.40 -{
   16.41 -  common->current_pnp_state = NotStarted;
   16.42 -  common->previous_pnp_state = NotStarted;
   16.43 -}
   16.44 -
   16.45 -static __inline void SET_PNP_STATE(PXENPCI_COMMON common, DEVICE_PNP_STATE state)
   16.46 -{
   16.47 -  common->previous_pnp_state = common->current_pnp_state;
   16.48 -  common->current_pnp_state = state;
   16.49 -}
   16.50 -
   16.51 -static __inline void REVERT_PNP_STATE(PXENPCI_COMMON common)
   16.52 -{
   16.53 -  common->current_pnp_state = common->previous_pnp_state;
   16.54 -}
   16.55 -#endif
   16.56 -
   16.57 -#define SHUTDOWN_RING_SIZE 128
   16.58 -
   16.59  #define SUSPEND_STATE_NONE      0 /* no suspend in progress */
   16.60  #define SUSPEND_STATE_SCHEDULED 1 /* suspend scheduled */
   16.61  #define SUSPEND_STATE_HIGH_IRQL 2 /* all processors are at high IRQL and spinning */
   16.62 @@ -239,15 +187,9 @@ typedef struct {
   16.63    UNICODE_STRING interface_name;
   16.64    BOOLEAN interface_open;
   16.65  
   16.66 +  BOOLEAN removable;
   16.67 +  
   16.68    WDFQUEUE io_queue;
   16.69 -#if 0
   16.70 -  KSPIN_LOCK shutdown_ring_lock;
   16.71 -  CHAR shutdown_ring[SHUTDOWN_RING_SIZE];
   16.72 -  ULONG shutdown_prod;
   16.73 -  ULONG shutdown_cons;
   16.74 -  ULONG shutdown_start; /* the start of the most recent message on the ring */
   16.75 -  PIRP shutdown_irp;
   16.76 -#endif
   16.77  
   16.78  #if 0
   16.79    KSPIN_LOCK mmio_freelist_lock;
   16.80 @@ -298,11 +240,9 @@ typedef struct {
   16.81  
   16.82  typedef struct {
   16.83    DMA_ADAPTER dma_adapter;
   16.84 -  //DMA_OPERATIONS dma_operations;
   16.85    PXENPCI_PDO_DEVICE_DATA xppdd;
   16.86    dma_driver_extension_t *dma_extension;
   16.87 -  //ULONG map_register_count;
   16.88 -  //map_register_t *map_registers;
   16.89 +  PDRIVER_OBJECT dma_extension_driver; /* to deference it */
   16.90  } xen_dma_adapter_t;
   16.91  
   16.92  #if 0
   16.93 @@ -357,6 +297,8 @@ EVT_WDF_DEVICE_D0_ENTRY XenPci_EvtDevice
   16.94  EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED XenPci_EvtDeviceD0EntryPostInterruptsEnabled;
   16.95  EVT_WDF_DEVICE_D0_EXIT XenPci_EvtDeviceD0Exit;
   16.96  EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED XenPci_EvtDeviceD0ExitPreInterruptsDisabled;
   16.97 +EVT_WDF_DEVICE_QUERY_REMOVE XenPci_EvtDeviceQueryRemove;
   16.98 +
   16.99  NTSTATUS
  16.100  XenPci_EvtChildListCreateDevice(WDFCHILDLIST child_list, PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER description_header, PWDFDEVICE_INIT child_init);
  16.101  VOID
    17.1 --- a/xenpci/xenpci.inx	Sat Feb 14 13:35:48 2009 +1100
    17.2 +++ b/xenpci/xenpci.inx	Wed Feb 18 22:18:23 2009 +1100
    17.3 @@ -4,6 +4,8 @@ Class=System
    17.4  ClassGuid={4D36E97D-E325-11CE-BFC1-08002BE10318}
    17.5  Provider=%XenGplPv%
    17.6  CatalogFile="XenGPLPV.cat"
    17.7 +DriverPackageType=PlugAndPlay
    17.8 +DriverPackageDisplayName=%XenPCI.DRVDESC%
    17.9  
   17.10  [DestinationDirs]
   17.11  DefaultDestDir = 12
   17.12 @@ -12,14 +14,9 @@ DefaultDestDir = 12
   17.13  ExcludeFromSelect=*
   17.14  
   17.15  [Manufacturer]
   17.16 -%XenGplPv%=XenPCI,NTx86
   17.17 -%XenGplPv%=XenPCI,NTamd64
   17.18 -%XenGplPv%=XenPCI
   17.19 +%XenGplPv%=XenPCI,NT$ARCH$
   17.20  
   17.21 -[XenPCI.NTx86]
   17.22 -%XenPCI.DRVDESC%=XenPCI_Device, PCI\VEN_5853&DEV_0001
   17.23 -
   17.24 -[XenPCI.NTAMD64]
   17.25 +[XenPCI.NT$ARCH$]
   17.26  %XenPCI.DRVDESC%=XenPCI_Device, PCI\VEN_5853&DEV_0001
   17.27  
   17.28  [XenPCI]
   17.29 @@ -36,14 +33,8 @@ xenhide.sys
   17.30  xenpci.sys=1
   17.31  xenhide.sys=1
   17.32  
   17.33 -[SourceDisksNames.x86]
   17.34 -1 = %DISK_NAME%,,,.\i386
   17.35 -
   17.36 -[SourceDisksNames.amd64]
   17.37 -1 = %DISK_NAME%,,,.\amd64
   17.38 -
   17.39  [SourceDisksNames]
   17.40 -1 = %DISK_NAME%,,,.\i386
   17.41 +1 = %DISK_NAME%,,,.
   17.42  
   17.43  [XenPCI_Device.NT.Services]
   17.44  AddService=XenPCI,3,XenPCI_Service
    18.1 --- a/xenpci/xenpci_fdo.c	Sat Feb 14 13:35:48 2009 +1100
    18.2 +++ b/xenpci/xenpci_fdo.c	Wed Feb 18 22:18:23 2009 +1100
    18.3 @@ -93,6 +93,21 @@ XenPci_AllocMMIO(PXENPCI_DEVICE_DATA xpd
    18.4  
    18.5  extern ULONG tpr_patch_requested;
    18.6  
    18.7 +NTSTATUS
    18.8 +XenPci_EvtDeviceQueryRemove(WDFDEVICE device)
    18.9 +{
   18.10 +  PXENPCI_DEVICE_DATA xpdd = GetXpdd(device);
   18.11 +  NTSTATUS status;
   18.12 +  
   18.13 +  FUNCTION_ENTER();
   18.14 +  if (xpdd->removable)
   18.15 +    status = STATUS_SUCCESS;
   18.16 +  else
   18.17 +    status = STATUS_UNSUCCESSFUL;
   18.18 +  FUNCTION_EXIT();
   18.19 +  return status;
   18.20 +}
   18.21 +
   18.22  static NTSTATUS
   18.23  XenPci_Init(PXENPCI_DEVICE_DATA xpdd)
   18.24  {
    19.1 --- a/xenpci/xenpci_highsync.c	Sat Feb 14 13:35:48 2009 +1100
    19.2 +++ b/xenpci/xenpci_highsync.c	Wed Feb 18 22:18:23 2009 +1100
    19.3 @@ -19,6 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fi
    19.4  
    19.5  #include "xenpci.h"
    19.6  
    19.7 +/*
    19.8 +we need these intrinsics as even going to HIGH_LEVEL doesn't ensure that interrupts are completely disabled
    19.9 +*/
   19.10 +#pragma intrinsic(_disable)
   19.11 +#pragma intrinsic(_enable)
   19.12 +
   19.13  struct {
   19.14    volatile ULONG        do_spin;
   19.15    volatile LONG         nr_spinning;
   19.16 @@ -47,7 +53,7 @@ XenPci_HighSyncCallFunction0(
   19.17  
   19.18    FUNCTION_ENTER();
   19.19    ActiveProcessorCount = (ULONG)KeNumberProcessors;
   19.20 -  __asm cli;  
   19.21 +  _disable(); //__asm cli;  
   19.22    KeRaiseIrql(highsync_info->sync_level, &old_irql);
   19.23    while (highsync_info->nr_spinning < (LONG)ActiveProcessorCount - 1)
   19.24    {
   19.25 @@ -56,7 +62,7 @@ XenPci_HighSyncCallFunction0(
   19.26    }
   19.27    highsync_info->function0(highsync_info->context);
   19.28    KeLowerIrql(old_irql);
   19.29 -  __asm sti;
   19.30 +  _enable(); //__asm sti;
   19.31    highsync_info->do_spin = FALSE;
   19.32    KeMemoryBarrier();  
   19.33    
    20.1 --- a/xenpci/xenpci_patch_kernel.c	Sat Feb 14 13:35:48 2009 +1100
    20.2 +++ b/xenpci/xenpci_patch_kernel.c	Wed Feb 18 22:18:23 2009 +1100
    20.3 @@ -397,6 +397,8 @@ XenPci_PatchKernel(PXENPCI_DEVICE_DATA x
    20.4      
    20.5    XenPci_HighSync(XenPci_DoPatchKernel0, XenPci_DoPatchKernelN, &patch_info);
    20.6    
    20.7 +  xpdd->removable = FALSE;
    20.8 +  
    20.9    FUNCTION_EXIT();
   20.10  }
   20.11  
    21.1 --- a/xenpci/xenpci_pdo.c	Sat Feb 14 13:35:48 2009 +1100
    21.2 +++ b/xenpci/xenpci_pdo.c	Wed Feb 18 22:18:23 2009 +1100
    21.3 @@ -24,21 +24,31 @@ Foundation, Inc., 51 Franklin Street, Fi
    21.4  #pragma warning(disable : 4200) // zero-sized array
    21.5  #pragma warning(disable: 4127) // conditional expression is constant
    21.6  
    21.7 -static VOID
    21.8 -XenPci_IS_InterfaceReference(PVOID context)
    21.9 -{
   21.10 -  UNREFERENCED_PARAMETER(context);
   21.11 -  FUNCTION_ENTER();
   21.12 -  FUNCTION_EXIT();
   21.13 -}
   21.14 -
   21.15 -static VOID
   21.16 -XenPci_IS_InterfaceDereference(PVOID context)
   21.17 -{
   21.18 -  UNREFERENCED_PARAMETER(context);
   21.19 -  FUNCTION_ENTER();
   21.20 -  FUNCTION_EXIT();
   21.21 -}
   21.22 +#define MAP_TYPE_VIRTUAL  1
   21.23 +#define MAP_TYPE_MDL      2
   21.24 +#define MAP_TYPE_REMAPPED 3
   21.25 +
   21.26 +typedef struct {
   21.27 +  ULONG map_type;
   21.28 +  PVOID aligned_buffer;
   21.29 +  PVOID unaligned_buffer;
   21.30 +  ULONG copy_length;
   21.31 +} sg_extra_t;
   21.32 +
   21.33 +typedef struct {
   21.34 +  ULONG map_type;
   21.35 +  PVOID aligned_buffer;
   21.36 +  PVOID unaligned_buffer;
   21.37 +  ULONG copy_length;
   21.38 +  PHYSICAL_ADDRESS logical;
   21.39 +} map_register_t;
   21.40 +
   21.41 +typedef struct {
   21.42 +  PDEVICE_OBJECT device_object;
   21.43 +  ULONG total_map_registers;
   21.44 +  ULONG count;
   21.45 +  map_register_t regs[1];
   21.46 +} map_register_base_t;  
   21.47  
   21.48  static BOOLEAN
   21.49  XenPci_BIS_TranslateBusAddress(PVOID context, PHYSICAL_ADDRESS bus_address, ULONG length, PULONG address_space, PPHYSICAL_ADDRESS translated_address)
   21.50 @@ -61,10 +71,15 @@ XenPci_BIS_TranslateBusAddress(PVOID con
   21.51  static VOID
   21.52  XenPci_DOP_PutDmaAdapter(PDMA_ADAPTER dma_adapter)
   21.53  {
   21.54 -  UNREFERENCED_PARAMETER(dma_adapter);
   21.55 +  xen_dma_adapter_t *xen_dma_adapter = (xen_dma_adapter_t *)dma_adapter;
   21.56    
   21.57    FUNCTION_ENTER();
   21.58 -  // decrement ref count
   21.59 +
   21.60 +  if (xen_dma_adapter->dma_extension)
   21.61 +    ObDereferenceObject(xen_dma_adapter->dma_extension_driver);
   21.62 +  ExFreePoolWithTag(xen_dma_adapter->dma_adapter.DmaOperations, XENPCI_POOL_TAG);
   21.63 +  ExFreePoolWithTag(xen_dma_adapter, XENPCI_POOL_TAG);
   21.64 +  
   21.65    FUNCTION_EXIT();
   21.66  
   21.67    return;
   21.68 @@ -78,7 +93,7 @@ XenPci_DOP_AllocateCommonBuffer(
   21.69    BOOLEAN CacheEnabled
   21.70  )
   21.71  {
   21.72 -  xen_dma_adapter_t *xen_dma_adapter;
   21.73 +  xen_dma_adapter_t *xen_dma_adapter = (xen_dma_adapter_t *)DmaAdapter;
   21.74    PXENPCI_DEVICE_DATA xpdd;
   21.75    PVOID buffer;
   21.76    PFN_NUMBER pfn;
   21.77 @@ -89,7 +104,6 @@ XenPci_DOP_AllocateCommonBuffer(
   21.78    
   21.79    //FUNCTION_ENTER();
   21.80  
   21.81 -  xen_dma_adapter = (xen_dma_adapter_t *)DmaAdapter;
   21.82    xpdd = GetXpdd(xen_dma_adapter->xppdd->wdf_device_bus_fdo);
   21.83  
   21.84    //KdPrint((__DRIVER_NAME "     Length = %d\n", Length));
   21.85 @@ -98,7 +112,7 @@ XenPci_DOP_AllocateCommonBuffer(
   21.86  
   21.87    pfn = (PFN_NUMBER)(MmGetPhysicalAddress(buffer).QuadPart >> PAGE_SHIFT);
   21.88    ASSERT(pfn);
   21.89 -  gref = (grant_ref_t)GntTbl_GrantAccess(xpdd, 0, pfn, FALSE, INVALID_GRANT_REF);
   21.90 +  gref = (grant_ref_t)GntTbl_GrantAccess(xpdd, 0, (ULONG)pfn, FALSE, INVALID_GRANT_REF);
   21.91    ASSERT(gref);
   21.92    LogicalAddress->QuadPart = (gref << PAGE_SHIFT) | (PtrToUlong(buffer) & (PAGE_SIZE - 1));
   21.93    
   21.94 @@ -121,75 +135,103 @@ XenPci_DOP_FreeCommonBuffer(
   21.95  
   21.96    UNREFERENCED_PARAMETER(dma_adapter);
   21.97    UNREFERENCED_PARAMETER(length);
   21.98 -  UNREFERENCED_PARAMETER(logical_address);
   21.99    UNREFERENCED_PARAMETER(cache_enabled);
  21.100  
  21.101 -  FUNCTION_ENTER();
  21.102 +//  FUNCTION_ENTER();
  21.103  
  21.104    xpdd = GetXpdd(xen_dma_adapter->xppdd->wdf_device_bus_fdo);
  21.105 -
  21.106    gref = (grant_ref_t)(logical_address.QuadPart >> PAGE_SHIFT);
  21.107    GntTbl_EndAccess(xpdd, gref, FALSE);
  21.108 -  
  21.109    ExFreePoolWithTag(virtual_address, XENPCI_POOL_TAG);
  21.110  
  21.111 -  FUNCTION_EXIT();
  21.112 +//  FUNCTION_EXIT();
  21.113  }
  21.114  
  21.115  static NTSTATUS
  21.116  XenPci_DOP_AllocateAdapterChannel(
  21.117 -    IN PDMA_ADAPTER  DmaAdapter,
  21.118 -    IN PDEVICE_OBJECT  DeviceObject,
  21.119 -    IN ULONG  NumberOfMapRegisters,
  21.120 -    IN PDRIVER_CONTROL  ExecutionRoutine,
  21.121 -    IN PVOID  Context
  21.122 +    IN PDMA_ADAPTER dma_adapter,
  21.123 +    IN PDEVICE_OBJECT device_object,
  21.124 +    IN ULONG NumberOfMapRegisters,
  21.125 +    IN PDRIVER_CONTROL ExecutionRoutine,
  21.126 +    IN PVOID Context
  21.127      )
  21.128  {
  21.129 +  //xen_dma_adapter_t *xen_dma_adapter = (xen_dma_adapter_t *)dma_adapter;
  21.130 +  //PXENPCI_DEVICE_DATA xpdd = GetXpdd(xen_dma_adapter->xppdd->wdf_device_bus_fdo);
  21.131    IO_ALLOCATION_ACTION action;
  21.132 +  map_register_base_t *map_register_base;
  21.133    
  21.134 -  UNREFERENCED_PARAMETER(DmaAdapter);
  21.135 -  UNREFERENCED_PARAMETER(NumberOfMapRegisters);
  21.136 +  UNREFERENCED_PARAMETER(dma_adapter);
  21.137    
  21.138 -  FUNCTION_ENTER();
  21.139 -  action = ExecutionRoutine(DeviceObject, DeviceObject->CurrentIrp, UlongToPtr(64), Context);
  21.140 +  //FUNCTION_ENTER();
  21.141 +
  21.142 +  map_register_base = ExAllocatePoolWithTag(NonPagedPool, 
  21.143 +    FIELD_OFFSET(map_register_base_t, regs) + NumberOfMapRegisters * sizeof(map_register_t), XENPCI_POOL_TAG);
  21.144 +  if (!map_register_base)
  21.145 +  {
  21.146 +    KdPrint((__DRIVER_NAME "     Cannot allocate memory for map_register_base\n"));
  21.147 +    FUNCTION_EXIT();
  21.148 +    return STATUS_INSUFFICIENT_RESOURCES;
  21.149 +  }
  21.150 +  /* 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 */
  21.151 +  map_register_base->device_object = device_object;
  21.152 +  map_register_base->total_map_registers = NumberOfMapRegisters;
  21.153 +  map_register_base->count = 0;
  21.154 +  
  21.155 +  action = ExecutionRoutine(device_object, device_object->CurrentIrp, map_register_base, Context);
  21.156    
  21.157    switch (action)
  21.158    {
  21.159    case KeepObject:
  21.160      KdPrint((__DRIVER_NAME "     KeepObject\n"));
  21.161 +    ASSERT(FALSE);
  21.162      break;
  21.163    case DeallocateObject:
  21.164      KdPrint((__DRIVER_NAME "     DeallocateObject\n"));
  21.165 +    ASSERT(FALSE);
  21.166      break;
  21.167    case DeallocateObjectKeepRegisters:
  21.168 -    KdPrint((__DRIVER_NAME "     DeallocateObjectKeepRegisters\n"));
  21.169 +    //KdPrint((__DRIVER_NAME "     DeallocateObjectKeepRegisters\n"));
  21.170      break;
  21.171    default:
  21.172      KdPrint((__DRIVER_NAME "     Unknown action %d\n", action));
  21.173 +    ASSERT(FALSE);
  21.174      break;
  21.175    }
  21.176 -  FUNCTION_EXIT();
  21.177 +  //FUNCTION_EXIT();
  21.178    return STATUS_SUCCESS;
  21.179  }
  21.180  
  21.181  static BOOLEAN
  21.182  XenPci_DOP_FlushAdapterBuffers(
  21.183 -  PDMA_ADAPTER DmaAdapter,
  21.184 -  PMDL Mdl,
  21.185 +  PDMA_ADAPTER dma_adapter,
  21.186 +  PMDL mdl,
  21.187    PVOID MapRegisterBase,
  21.188    PVOID CurrentVa,
  21.189    ULONG Length,
  21.190 -  BOOLEAN WriteToDevice)
  21.191 +  BOOLEAN write_to_device)
  21.192  {
  21.193 -  UNREFERENCED_PARAMETER(DmaAdapter);
  21.194 -  UNREFERENCED_PARAMETER(Mdl);
  21.195 -  UNREFERENCED_PARAMETER(MapRegisterBase);
  21.196 +  //xen_dma_adapter_t *xen_dma_adapter = (xen_dma_adapter_t *)dma_adapter;
  21.197 +  //PXENPCI_DEVICE_DATA xpdd = GetXpdd(xen_dma_adapter->xppdd->wdf_device_bus_fdo);
  21.198 +  map_register_base_t *map_register_base = MapRegisterBase;
  21.199 +  map_register_t *map_register;
  21.200 +  ULONG i;
  21.201 +  
  21.202 +  UNREFERENCED_PARAMETER(dma_adapter);
  21.203 +  UNREFERENCED_PARAMETER(mdl);
  21.204    UNREFERENCED_PARAMETER(CurrentVa);
  21.205    UNREFERENCED_PARAMETER(Length);
  21.206 -  UNREFERENCED_PARAMETER(WriteToDevice);
  21.207 -
  21.208 -  FUNCTION_ENTER();
  21.209 -  FUNCTION_EXIT();
  21.210 +
  21.211 +  //FUNCTION_ENTER();
  21.212 +  
  21.213 +  for (i = 0; i < map_register_base->count; i++)
  21.214 +  {
  21.215 +    map_register = &map_register_base->regs[i];
  21.216 +    if (map_register->map_type == MAP_TYPE_REMAPPED && !write_to_device)
  21.217 +      memcpy(map_register->unaligned_buffer, map_register->aligned_buffer, map_register->copy_length);
  21.218 +  }
  21.219 +  //FUNCTION_EXIT();
  21.220 +  
  21.221    return TRUE;
  21.222  }
  21.223  
  21.224 @@ -206,42 +248,140 @@ XenPci_DOP_FreeAdapterChannel(
  21.225  
  21.226  static VOID
  21.227  XenPci_DOP_FreeMapRegisters(
  21.228 -  PDMA_ADAPTER DmaAdapter,
  21.229 +  PDMA_ADAPTER dma_adapter,
  21.230    PVOID MapRegisterBase,
  21.231    ULONG NumberOfMapRegisters)
  21.232  {
  21.233 -  UNREFERENCED_PARAMETER(DmaAdapter);
  21.234 -  UNREFERENCED_PARAMETER(MapRegisterBase);
  21.235 -  UNREFERENCED_PARAMETER(NumberOfMapRegisters);
  21.236 -
  21.237 -  FUNCTION_ENTER();
  21.238 -  FUNCTION_EXIT();
  21.239 +  xen_dma_adapter_t *xen_dma_adapter = (xen_dma_adapter_t *)dma_adapter;
  21.240 +  PXENPCI_DEVICE_DATA xpdd = GetXpdd(xen_dma_adapter->xppdd->wdf_device_bus_fdo);
  21.241 +  map_register_base_t *map_register_base = MapRegisterBase;
  21.242 +  map_register_t *map_register;
  21.243 +  ULONG i;
  21.244 +  grant_ref_t gref;
  21.245 +
  21.246 +  //FUNCTION_ENTER();
  21.247 +  ASSERT(map_register_base->total_map_registers == NumberOfMapRegisters);
  21.248 +
  21.249 +  for (i = 0; i < map_register_base->count; i++)
  21.250 +  {
  21.251 +    map_register = &map_register_base->regs[i];
  21.252 +    switch (map_register->map_type)
  21.253 +    {
  21.254 +    case MAP_TYPE_REMAPPED:
  21.255 +      gref = (grant_ref_t)(map_register->logical.QuadPart >> PAGE_SHIFT);
  21.256 +      GntTbl_EndAccess(xpdd, gref, FALSE);
  21.257 +      ExFreePoolWithTag(map_register->aligned_buffer, XENPCI_POOL_TAG);
  21.258 +      break;
  21.259 +    case MAP_TYPE_MDL:
  21.260 +      gref = (grant_ref_t)(map_register->logical.QuadPart >> PAGE_SHIFT);
  21.261 +      GntTbl_EndAccess(xpdd, gref, FALSE);
  21.262 +      break;
  21.263 +    case MAP_TYPE_VIRTUAL:
  21.264 +      break;
  21.265 +    }
  21.266 +  }
  21.267 +  ExFreePoolWithTag(map_register_base, XENPCI_POOL_TAG);
  21.268 +
  21.269 +  //FUNCTION_EXIT();
  21.270  }
  21.271  
  21.272  static PHYSICAL_ADDRESS
  21.273  XenPci_DOP_MapTransfer(
  21.274 -    PDMA_ADAPTER DmaAdapter,
  21.275 -    PMDL Mdl,
  21.276 +    PDMA_ADAPTER dma_adapter,
  21.277 +    PMDL mdl,
  21.278      PVOID MapRegisterBase,
  21.279      PVOID CurrentVa,
  21.280      PULONG Length,
  21.281      BOOLEAN WriteToDevice)
  21.282  {
  21.283 -  PHYSICAL_ADDRESS physical;
  21.284 +  xen_dma_adapter_t *xen_dma_adapter = (xen_dma_adapter_t *)dma_adapter;
  21.285 +  PXENPCI_DEVICE_DATA xpdd = GetXpdd(xen_dma_adapter->xppdd->wdf_device_bus_fdo);
  21.286 +  map_register_base_t *map_register_base = MapRegisterBase;
  21.287 +  map_register_t *map_register = &map_register_base->regs[map_register_base->count];
  21.288 +  PDEVICE_OBJECT device_object = map_register_base->device_object;
  21.289 +  ULONG page_offset;
  21.290 +  PFN_NUMBER pfn;
  21.291 +  grant_ref_t gref;
  21.292 +  PUCHAR ptr;
  21.293 +  ULONG mdl_offset;
  21.294 +  ULONG pfn_index;
  21.295 +
  21.296 +  //FUNCTION_ENTER();
  21.297 +
  21.298 +  //KdPrint((__DRIVER_NAME "     Mdl = %p, MapRegisterBase = %p, MdlVa = %p, CurrentVa = %p, Length = %d\n",
  21.299 +  //  mdl, MapRegisterBase, MmGetMdlVirtualAddress(mdl), CurrentVa, *Length));
  21.300 +
  21.301 +  ASSERT(mdl);
  21.302 +  ASSERT(map_register_base->count < map_register_base->total_map_registers);
  21.303    
  21.304 -  UNREFERENCED_PARAMETER(DmaAdapter);
  21.305 -  UNREFERENCED_PARAMETER(Mdl);
  21.306 -  UNREFERENCED_PARAMETER(MapRegisterBase);
  21.307 -  UNREFERENCED_PARAMETER(CurrentVa);
  21.308 -  UNREFERENCED_PARAMETER(Length);
  21.309 -  UNREFERENCED_PARAMETER(WriteToDevice);
  21.310 -
  21.311 -  FUNCTION_ENTER();
  21.312 +  if (xen_dma_adapter->dma_extension)
  21.313 +  {
  21.314 +    if (xen_dma_adapter->dma_extension->need_virtual_address(device_object->CurrentIrp))
  21.315 +    {
  21.316 +      map_register->map_type = MAP_TYPE_VIRTUAL;
  21.317 +    }
  21.318 +    else
  21.319 +    {
  21.320 +      ULONG alignment = xen_dma_adapter->dma_extension->get_alignment(device_object->CurrentIrp);
  21.321 +      if ((MmGetMdlByteOffset(mdl) & (alignment - 1)) || (MmGetMdlByteCount(mdl) & (alignment - 1)))
  21.322 +      {
  21.323 +        map_register->map_type = MAP_TYPE_REMAPPED;
  21.324 +      }
  21.325 +      else
  21.326 +      {
  21.327 +        map_register->map_type = MAP_TYPE_MDL;
  21.328 +      }
  21.329 +    }
  21.330 +  }
  21.331 +  else
  21.332 +  {
  21.333 +    map_register->map_type = MAP_TYPE_MDL;
  21.334 +  }
  21.335 +
  21.336 +  switch (map_register->map_type)
  21.337 +  {
  21.338 +  case MAP_TYPE_MDL:
  21.339 +    //KdPrint((__DRIVER_NAME "     MAP_TYPE_MDL\n"));
  21.340 +    mdl_offset = (ULONG)((ULONGLONG)CurrentVa - (ULONGLONG)MmGetMdlVirtualAddress(mdl));
  21.341 +    page_offset = PtrToUlong(CurrentVa) & (PAGE_SIZE - 1);
  21.342 +    *Length = min(*Length, PAGE_SIZE - page_offset);
  21.343 +    pfn_index = (ULONG)(((ULONGLONG)CurrentVa >> PAGE_SHIFT) - ((ULONGLONG)MmGetMdlVirtualAddress(mdl) >> PAGE_SHIFT));
  21.344 +    //KdPrint((__DRIVER_NAME "     mdl_offset = %d, page_offset = %d, length = %d, pfn_index = %d\n",
  21.345 +    //  mdl_offset, page_offset, *Length, pfn_index));
  21.346 +    pfn = MmGetMdlPfnArray(mdl)[pfn_index];
  21.347 +    gref = (grant_ref_t)GntTbl_GrantAccess(xpdd, 0, (ULONG)pfn, FALSE, INVALID_GRANT_REF);
  21.348 +    map_register->logical.QuadPart = (LONGLONG)(gref << PAGE_SHIFT) | page_offset;
  21.349 +    map_register_base->count++;
  21.350 +    break;
  21.351 +  case MAP_TYPE_REMAPPED:
  21.352 +    //KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED\n"));
  21.353 +    *Length = min(*Length, PAGE_SIZE);
  21.354 +    map_register->aligned_buffer = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
  21.355 +    ASSERT(map_register->aligned_buffer);
  21.356 +    map_register->unaligned_buffer = MmGetSystemAddressForMdlSafe(mdl, NormalPagePriority);
  21.357 +    ASSERT(map_register->unaligned_buffer); /* lazy */
  21.358 +    map_register->copy_length = *Length;
  21.359 +    if (WriteToDevice)
  21.360 +      memcpy(map_register->aligned_buffer, map_register->unaligned_buffer, map_register->copy_length);
  21.361 +    pfn = (PFN_NUMBER)(MmGetPhysicalAddress(map_register->aligned_buffer).QuadPart >> PAGE_SHIFT);
  21.362 +    gref = (grant_ref_t)GntTbl_GrantAccess(xpdd, 0, (ULONG)pfn, FALSE, INVALID_GRANT_REF);
  21.363 +    map_register->logical.QuadPart = (LONGLONG)(gref << PAGE_SHIFT);
  21.364 +    map_register_base->count++;
  21.365 +    break;
  21.366 +  case MAP_TYPE_VIRTUAL:
  21.367 +    //KdPrint((__DRIVER_NAME "     MAP_TYPE_VIRTUAL\n"));
  21.368 +    ptr = MmGetSystemAddressForMdlSafe(mdl, NormalPagePriority);
  21.369 +    ASSERT(ptr); /* lazy */
  21.370 +    map_register->logical.QuadPart = (ULONGLONG)ptr;
  21.371 +    map_register_base->count++;
  21.372 +    break;
  21.373 +  default:
  21.374 +    ASSERT(FALSE);
  21.375 +    break;
  21.376 +  }
  21.377    
  21.378 -  physical.QuadPart = 0;
  21.379 -  
  21.380 -  FUNCTION_EXIT();
  21.381 -  return physical;
  21.382 +  //FUNCTION_EXIT();
  21.383 +  return map_register->logical;
  21.384  }
  21.385  
  21.386  static ULONG
  21.387 @@ -291,17 +431,6 @@ XenPci_DOP_GetScatterGatherList(
  21.388    return STATUS_SUCCESS;
  21.389  }
  21.390  
  21.391 -#define MAP_TYPE_VIRTUAL  1
  21.392 -#define MAP_TYPE_MDL      2
  21.393 -#define MAP_TYPE_REMAPPED 3
  21.394 -
  21.395 -typedef struct {
  21.396 -  ULONG map_type;
  21.397 -  PVOID aligned_buffer;
  21.398 -  PVOID unaligned_buffer;
  21.399 -  ULONG copy_length;
  21.400 -} sg_extra_t;
  21.401 -
  21.402  static VOID
  21.403  XenPci_DOP_PutScatterGatherList(
  21.404      IN PDMA_ADAPTER DmaAdapter,
  21.405 @@ -423,15 +552,15 @@ XenPci_DOP_BuildScatterGatherList(
  21.406    ULONG offset;
  21.407    PFN_NUMBER pfn;
  21.408    grant_ref_t gref;
  21.409 +  //PUCHAR StartVa;
  21.410    
  21.411 -  UNREFERENCED_PARAMETER(WriteToDevice);
  21.412 -
  21.413 -  //FUNCTION_ENTER();
  21.414 +  ASSERT(MmGetMdlVirtualAddress(Mdl) == CurrentVa);
  21.415  
  21.416    xen_dma_adapter = (xen_dma_adapter_t *)DmaAdapter;
  21.417    xpdd = GetXpdd(xen_dma_adapter->xppdd->wdf_device_bus_fdo);
  21.418  
  21.419    ASSERT(Mdl);
  21.420 +  
  21.421    if (xen_dma_adapter->dma_extension)
  21.422    {
  21.423      if (xen_dma_adapter->dma_extension->need_virtual_address(DeviceObject->CurrentIrp))
  21.424 @@ -443,9 +572,9 @@ XenPci_DOP_BuildScatterGatherList(
  21.425      else
  21.426      {
  21.427        ULONG alignment = xen_dma_adapter->dma_extension->get_alignment(DeviceObject->CurrentIrp);
  21.428 -      if (PtrToUlong(CurrentVa) & (alignment - 1))
  21.429 +      if ((MmGetMdlByteOffset(Mdl) & (alignment - 1)) || (MmGetMdlByteCount(Mdl) & (alignment - 1)))
  21.430        {
  21.431 -        ASSERT(!Mdl->Next); /* can only remap a single buffer */
  21.432 +        ASSERT(!Mdl->Next); /* can only remap a single buffer for now - will need to check all Mdl's in the future */
  21.433          map_type = MAP_TYPE_REMAPPED;
  21.434          sglist->NumberOfElements = ADDRESS_AND_SIZE_TO_SPAN_PAGES(NULL, Length);
  21.435        }
  21.436 @@ -478,22 +607,19 @@ XenPci_DOP_BuildScatterGatherList(
  21.437    switch (map_type)
  21.438    {
  21.439    case MAP_TYPE_MDL:
  21.440 -    //KdPrint((__DRIVER_NAME "     MAP_TYPE_MDL\n"));
  21.441 +    //KdPrint((__DRIVER_NAME "     MAP_TYPE_MDL - %p\n", MmGetMdlVirtualAddress(Mdl)));
  21.442      total_remaining = Length;
  21.443      for (sg_element = 0, curr_mdl = Mdl; curr_mdl; curr_mdl = curr_mdl->Next)
  21.444      {
  21.445        remaining = MmGetMdlByteCount(curr_mdl);
  21.446 -      if (!MmGetMdlByteOffset(Mdl) && (PtrToUlong(CurrentVa) & (PAGE_SIZE - 1)))
  21.447 -        offset = (PtrToUlong(CurrentVa) & (PAGE_SIZE - 1));
  21.448 -      else
  21.449 -        offset = MmGetMdlByteOffset(curr_mdl);
  21.450 +      offset = MmGetMdlByteOffset(curr_mdl);
  21.451        for (i = 0; i < ADDRESS_AND_SIZE_TO_SPAN_PAGES(MmGetMdlVirtualAddress(curr_mdl), MmGetMdlByteCount(curr_mdl)); i++)
  21.452        {
  21.453  //KdPrint((__DRIVER_NAME "     element = %d\n", sg_element));
  21.454  //KdPrint((__DRIVER_NAME "     remaining = %d\n", remaining));
  21.455          pfn = MmGetMdlPfnArray(curr_mdl)[i];
  21.456          ASSERT(pfn);
  21.457 -        gref = (grant_ref_t)GntTbl_GrantAccess(xpdd, 0, pfn, FALSE, INVALID_GRANT_REF);
  21.458 +        gref = (grant_ref_t)GntTbl_GrantAccess(xpdd, 0, (ULONG)pfn, FALSE, INVALID_GRANT_REF);
  21.459          ASSERT(gref != INVALID_GRANT_REF);
  21.460          sglist->Elements[sg_element].Address.QuadPart = (LONGLONG)(gref << PAGE_SHIFT) | offset;
  21.461          sglist->Elements[sg_element].Length = min(min(PAGE_SIZE - offset, remaining), total_remaining);
  21.462 @@ -505,17 +631,15 @@ XenPci_DOP_BuildScatterGatherList(
  21.463      }
  21.464      break;
  21.465    case MAP_TYPE_REMAPPED:
  21.466 -    //KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED\n"));
  21.467      sg_extra->aligned_buffer = ExAllocatePoolWithTag(NonPagedPool, max(Length, PAGE_SIZE), XENPCI_POOL_TAG);
  21.468      if (!sg_extra->aligned_buffer)
  21.469      {
  21.470 -      //KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED buffer allocation failed - requested va = %p, length = %d\n", CurrentVa, Length));
  21.471 +      //KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED buffer allocation failed - requested va = %p, length = %d\n", MmGetMdlVirtualAddress(Mdl), Length));
  21.472        return STATUS_INSUFFICIENT_RESOURCES;
  21.473      }
  21.474 +    //KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED - %p -> %p\n", MmGetMdlVirtualAddress(Mdl), sg_extra->aligned_buffer));
  21.475      sg_extra->unaligned_buffer = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
  21.476      ASSERT(sg_extra->unaligned_buffer); /* lazy */
  21.477 -    if (!MmGetMdlByteOffset(Mdl) && (PtrToUlong(CurrentVa) & (PAGE_SIZE - 1)))
  21.478 -      sg_extra->unaligned_buffer = (PUCHAR)sg_extra->unaligned_buffer + (PtrToUlong(CurrentVa) & (PAGE_SIZE - 1));
  21.479      sg_extra->copy_length = Length;
  21.480      if (WriteToDevice)
  21.481        memcpy(sg_extra->aligned_buffer, sg_extra->unaligned_buffer, sg_extra->copy_length);
  21.482 @@ -524,7 +648,7 @@ XenPci_DOP_BuildScatterGatherList(
  21.483      {
  21.484        pfn = (PFN_NUMBER)(MmGetPhysicalAddress((PUCHAR)sg_extra->aligned_buffer + (sg_element << PAGE_SHIFT)).QuadPart >> PAGE_SHIFT);
  21.485        ASSERT(pfn);
  21.486 -      gref = (grant_ref_t)GntTbl_GrantAccess(xpdd, 0, pfn, FALSE, INVALID_GRANT_REF);
  21.487 +      gref = (grant_ref_t)GntTbl_GrantAccess(xpdd, 0, (ULONG)pfn, FALSE, INVALID_GRANT_REF);
  21.488        ASSERT(gref);
  21.489        sglist->Elements[sg_element].Address.QuadPart = (ULONGLONG)gref << PAGE_SHIFT;
  21.490        sglist->Elements[sg_element].Length = min(PAGE_SIZE, remaining);
  21.491 @@ -532,24 +656,14 @@ XenPci_DOP_BuildScatterGatherList(
  21.492      }
  21.493      break;
  21.494    case MAP_TYPE_VIRTUAL:
  21.495 -    //KdPrint((__DRIVER_NAME "     MAP_TYPE_VIRTUAL\n"));
  21.496      ptr = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
  21.497      ASSERT(ptr); /* lazy */
  21.498 -    if (!MmGetMdlByteOffset(Mdl) && (PtrToUlong(CurrentVa) & (PAGE_SIZE - 1)))
  21.499 -      ptr += (PtrToUlong(CurrentVa) & (PAGE_SIZE - 1));
  21.500      sglist->Elements[0].Address.QuadPart = (ULONGLONG)ptr;
  21.501      sglist->Elements[0].Length = Length;
  21.502 +    //KdPrint((__DRIVER_NAME "     MAP_TYPE_VIRTUAL - %08x\n", sglist->Elements[0].Address.LowPart));
  21.503      break;
  21.504    }
  21.505 -#if 0
  21.506 -  KdPrint((__DRIVER_NAME "     Mdl = %p, CurrentVa = %p, Mdl->Va = %p, Offset = %d, Length = %d\n", 
  21.507 -    Mdl, CurrentVa, MmGetMdlVirtualAddress(Mdl), MmGetMdlByteOffset(Mdl), Length));
  21.508 -  for (i = 0; i < sglist->NumberOfElements; i++)
  21.509 -  {
  21.510 -    KdPrint((__DRIVER_NAME "     sge[%d]->Address = %08x%08x, Length = %d\n", i, sglist->Elements[i].Address.HighPart,
  21.511 -      sglist->Elements[i].Address.LowPart, sglist->Elements[i].Length));
  21.512 -  }
  21.513 -#endif
  21.514 +
  21.515    ExecutionRoutine(DeviceObject, DeviceObject->CurrentIrp, ScatterGatherBuffer, Context);
  21.516  
  21.517    //FUNCTION_EXIT();
  21.518 @@ -614,7 +728,6 @@ Windows accessed beyond the end of the s
  21.519    xen_dma_adapter->dma_adapter.Version = 2;
  21.520    xen_dma_adapter->dma_adapter.Size = sizeof(DMA_ADAPTER); //xen_dma_adapter_t);
  21.521    xen_dma_adapter->dma_adapter.DmaOperations = ExAllocatePoolWithTag(NonPagedPool, sizeof(DMA_OPERATIONS), XENPCI_POOL_TAG);
  21.522 -  //xen_dma_adapter->dma_adapter.DmaOperations = &xen_dma_adapter->dma_operations;
  21.523    xen_dma_adapter->dma_adapter.DmaOperations->Size = sizeof(DMA_OPERATIONS);
  21.524    xen_dma_adapter->dma_adapter.DmaOperations->PutDmaAdapter = XenPci_DOP_PutDmaAdapter;
  21.525    xen_dma_adapter->dma_adapter.DmaOperations->AllocateCommonBuffer = XenPci_DOP_AllocateCommonBuffer;
  21.526 @@ -641,16 +754,21 @@ Windows accessed beyond the end of the s
  21.527    while (curr != NULL)
  21.528    {
  21.529      fdo_driver_object = curr->DriverObject;
  21.530 -    KdPrint((__DRIVER_NAME "     fdo_driver_object = %p\n", fdo_driver_object));
  21.531      if (fdo_driver_object)
  21.532      {
  21.533 +      ObReferenceObject(fdo_driver_object);
  21.534        fdo_driver_extension = IoGetDriverObjectExtension(fdo_driver_object, UlongToPtr(XEN_DMA_DRIVER_EXTENSION_MAGIC));
  21.535        if (fdo_driver_extension)
  21.536        {
  21.537 +        xen_dma_adapter->dma_extension_driver = fdo_driver_object; /* so we can dereference it on putdmaadapter */
  21.538          xen_dma_adapter->dma_extension = (dma_driver_extension_t *)fdo_driver_extension;
  21.539          ObDereferenceObject(curr);
  21.540          break;
  21.541        }
  21.542 +      else
  21.543 +      {
  21.544 +        ObDereferenceObject(fdo_driver_object);
  21.545 +      }
  21.546      }
  21.547      prev = curr;
  21.548      curr = IoGetLowerDeviceObject(curr);
  21.549 @@ -658,7 +776,7 @@ Windows accessed beyond the end of the s
  21.550    }
  21.551    KdPrint((__DRIVER_NAME "     End of loop\n"));
  21.552  
  21.553 -  *number_of_map_registers = 1024; //1024; /* why not... */
  21.554 +  *number_of_map_registers = 1024; /* why not... */
  21.555  
  21.556    FUNCTION_EXIT();
  21.557  
  21.558 @@ -1371,6 +1489,7 @@ XenPci_XenConfigDeviceSpecifyBuffers(WDF
  21.559          }
  21.560          else
  21.561          {
  21.562 +          #pragma warning(suppress:4055)
  21.563            EvtChn_Bind(xpdd, event_channel, (PXEN_EVTCHN_SERVICE_ROUTINE)value, value2);
  21.564          }
  21.565        }
  21.566 @@ -1754,8 +1873,8 @@ XenPci_EvtChildListCreateDevice(WDFCHILD
  21.567    bus_interface.Size = sizeof(BUS_INTERFACE_STANDARD);
  21.568    bus_interface.Version = 1; //BUS_INTERFACE_STANDARD_VERSION;
  21.569    bus_interface.Context = xppdd;
  21.570 -  bus_interface.InterfaceReference = XenPci_IS_InterfaceReference;
  21.571 -  bus_interface.InterfaceDereference = XenPci_IS_InterfaceReference;
  21.572 +  bus_interface.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
  21.573 +  bus_interface.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
  21.574    bus_interface.TranslateBusAddress = XenPci_BIS_TranslateBusAddress;
  21.575    bus_interface.GetDmaAdapter = XenPci_BIS_GetDmaAdapter;
  21.576    bus_interface.SetBusData = XenPci_BIS_SetBusData;
  21.577 @@ -3607,7 +3726,7 @@ XenPci_DOP_BuildScatterGatherList(
  21.578    switch (map_type)
  21.579    {
  21.580    case MAP_TYPE_MDL:
  21.581 -    //KdPrint((__DRIVER_NAME "     MAP_TYPE_MDL\n"));
  21.582 +    KdPrint((__DRIVER_NAME "     MAP_TYPE_MDL - %p\n", CurrentVa));
  21.583      total_remaining = Length;
  21.584      for (sg_element = 0, curr_mdl = Mdl; curr_mdl; curr_mdl = curr_mdl->Next)
  21.585      {
  21.586 @@ -3634,9 +3753,9 @@ XenPci_DOP_BuildScatterGatherList(
  21.587      }
  21.588      break;
  21.589    case MAP_TYPE_REMAPPED:
  21.590 -    //KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED\n"));
  21.591      sg_extra->aligned_buffer = ExAllocatePoolWithTag(NonPagedPool, max(Length, PAGE_SIZE), XENPCI_POOL_TAG);
  21.592      ASSERT(sg_extra->aligned_buffer); /* lazy */
  21.593 +    KdPrint((__DRIVER_NAME "     MAP_TYPE_REMAPPED - %p -> %p\n", CurrentVa, sg_extra->aligned_buffer));
  21.594      sg_extra->unaligned_buffer = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
  21.595      ASSERT(sg_extra->unaligned_buffer); /* lazy */
  21.596      if (!MmGetMdlByteOffset(Mdl) && (PtrToUlong(CurrentVa) & (PAGE_SIZE - 1)))
  21.597 @@ -3657,7 +3776,7 @@ XenPci_DOP_BuildScatterGatherList(
  21.598      }
  21.599      break;
  21.600    case MAP_TYPE_VIRTUAL:
  21.601 -    //KdPrint((__DRIVER_NAME "     MAP_TYPE_VIRTUAL\n"));
  21.602 +    KdPrint((__DRIVER_NAME "     MAP_TYPE_VIRTUAL\n"));
  21.603      ptr = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
  21.604      ASSERT(ptr); /* lazy */
  21.605      if (!MmGetMdlByteOffset(Mdl) && (PtrToUlong(CurrentVa) & (PAGE_SIZE - 1)))
    22.1 --- a/xenscsi/makefile.inc	Sat Feb 14 13:35:48 2009 +1100
    22.2 +++ b/xenscsi/makefile.inc	Wed Feb 18 22:18:23 2009 +1100
    22.3 @@ -1,6 +1,6 @@
    22.4  _LNG=$(LANGUAGE)
    22.5  STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
    22.6  
    22.7 -..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf: $(INF_NAME).inx sources ..\common.inc
    22.8 +$(OBJ_PATH)\$(O)\$(TARGETNAME).inf: $(TARGETNAME).inx sources ..\common.inc
    22.9      copy $(@B).inx $@
   22.10      $(STAMP)
    23.1 --- a/xenscsi/sources	Sat Feb 14 13:35:48 2009 +1100
    23.2 +++ b/xenscsi/sources	Wed Feb 18 22:18:23 2009 +1100
    23.3 @@ -1,7 +1,8 @@
    23.4  !include "..\common.inc"
    23.5 +!UNDEF KMDF_VERSION
    23.6 +!UNDEF KMDF_VERSION_MAJOR
    23.7  TARGETNAME=xenscsi
    23.8  TARGETTYPE=DRIVER
    23.9 -INF_NAME=$(TARGETNAME)
   23.10  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\scsiport.lib
   23.11 -MISCFILES=..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf
   23.12 +NTTARGETFILES=$(NTTARGETFILES) $(OBJ_PATH)\$(O)\$(TARGETNAME).inf
   23.13  SOURCES=xenscsi.c
    24.1 --- a/xenscsi/xenscsi.c	Sat Feb 14 13:35:48 2009 +1100
    24.2 +++ b/xenscsi/xenscsi.c	Wed Feb 18 22:18:23 2009 +1100
    24.3 @@ -228,9 +228,10 @@ XenScsi_ParseBackendDevice(scsi_dev_t *d
    24.4  static VOID
    24.5  XenScsi_WaitPause(PVOID DeviceExtension)
    24.6  {
    24.7 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
    24.8 -  LARGE_INTEGER wait_time;
    24.9 +  //PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   24.10 +  //LARGE_INTEGER wait_time;
   24.11  
   24.12 +  UNREFERENCED_PARAMETER(DeviceExtension);
   24.13    FUNCTION_ENTER();
   24.14  #if 0
   24.15    xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->device_state->pdo_event_channel);
    25.1 --- a/xenstub/makefile.inc	Sat Feb 14 13:35:48 2009 +1100
    25.2 +++ b/xenstub/makefile.inc	Wed Feb 18 22:18:23 2009 +1100
    25.3 @@ -1,6 +1,6 @@
    25.4  _LNG=$(LANGUAGE)
    25.5  STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
    25.6  
    25.7 -$(INF_NAME).inf: $(INF_NAME).inx sources ..\common.inc
    25.8 +$(OBJ_PATH)\$(O)\$(TARGETNAME).inf: $(TARGETNAME).inx sources ..\common.inc
    25.9      copy $(@B).inx $@
   25.10      $(STAMP)
    26.1 --- a/xenstub/sources	Sat Feb 14 13:35:48 2009 +1100
    26.2 +++ b/xenstub/sources	Wed Feb 18 22:18:23 2009 +1100
    26.3 @@ -1,6 +1,5 @@
    26.4  !INCLUDE ..\common.inc
    26.5  TARGETNAME=xenstub
    26.6  TARGETTYPE=DRIVER
    26.7 -INF_NAME=$(TARGETNAME)
    26.8 -MISCFILES=$(INF_NAME).inf
    26.9 +NTTARGETFILES=$(NTTARGETFILES) $(OBJ_PATH)\$(O)\$(TARGETNAME).inf
   26.10  SOURCES=xenstub.c
    27.1 --- a/xenstub/xenstub.inx	Sat Feb 14 13:35:48 2009 +1100
    27.2 +++ b/xenstub/xenstub.inx	Wed Feb 18 22:18:23 2009 +1100
    27.3 @@ -12,15 +12,10 @@ DefaultDestDir = 12
    27.4  ExcludeFromSelect=*
    27.5  
    27.6  [Manufacturer]
    27.7 -%XenGplPv%=XenGplPv,NTx86
    27.8 -%XenGplPv%=XenGplPv,NTamd64
    27.9 +%XenGplPv%=XenGplPv,NT$ARCH$
   27.10 +%XenGplPv%=XenGplPv,NT$ARCH$
   27.11  
   27.12 -[XenGplPv.NTx86]
   27.13 -%XenStub.DRVDESC.CONSOLE%=XenStub_Inst, XEN\CONSOLE
   27.14 -%XenStub.DRVDESC.VFB%=XenStub_Inst, XEN\VFB
   27.15 -%XenStub.DRVDESC.VKBD%=XenStub_Inst, XEN\VKBD
   27.16 -
   27.17 -[XenGplPv.NTamd64]
   27.18 +[XenGplPv.NT$ARCH$]
   27.19  %XenStub.DRVDESC.CONSOLE%=XenStub_Inst, XEN\CONSOLE
   27.20  %XenStub.DRVDESC.VFB%=XenStub_Inst, XEN\VFB
   27.21  %XenStub.DRVDESC.VKBD%=XenStub_Inst, XEN\VKBD
   27.22 @@ -34,11 +29,8 @@ xenstub.sys
   27.23  [SourceDisksFiles]
   27.24  xenstub.sys=1
   27.25  
   27.26 -[SourceDisksNames.x86]
   27.27 -1 = %DISK_NAME%,,,.\i386
   27.28 -
   27.29 -[SourceDisksNames.amd64]
   27.30 -1 = %DISK_NAME%,,,.\amd64
   27.31 +[SourceDisksNames]
   27.32 +1 = %DISK_NAME%
   27.33  
   27.34  [XenStub_Inst.Services]
   27.35  AddService=XenStub,2,XenStub_Service 
    28.1 --- a/xenvbd/makefile.inc	Sat Feb 14 13:35:48 2009 +1100
    28.2 +++ b/xenvbd/makefile.inc	Wed Feb 18 22:18:23 2009 +1100
    28.3 @@ -1,6 +1,6 @@
    28.4  _LNG=$(LANGUAGE)
    28.5  STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
    28.6  
    28.7 -$(INF_NAME).inf: $(INF_NAME).inx sources ..\common.inc
    28.8 +$(OBJ_PATH)\$(O)\$(TARGETNAME).inf: $(TARGETNAME).inx sources ..\common.inc
    28.9      copy $(@B).inx $@
   28.10      $(STAMP)
    29.1 --- a/xenvbd/sources	Sat Feb 14 13:35:48 2009 +1100
    29.2 +++ b/xenvbd/sources	Wed Feb 18 22:18:23 2009 +1100
    29.3 @@ -3,7 +3,6 @@
    29.4  !UNDEF KMDF_VERSION_MAJOR
    29.5  TARGETNAME=xenvbd
    29.6  TARGETTYPE=DRIVER
    29.7 -INF_NAME=$(TARGETNAME)
    29.8 -MISCFILES=$(INF_NAME).inf
    29.9  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\scsiport.lib
   29.10 +NTTARGETFILES=$(NTTARGETFILES) $(OBJ_PATH)\$(O)\$(TARGETNAME).inf
   29.11  SOURCES=xenvbd.c
    30.1 --- a/xenvbd/xenvbd.c	Sat Feb 14 13:35:48 2009 +1100
    30.2 +++ b/xenvbd/xenvbd.c	Wed Feb 18 22:18:23 2009 +1100
    30.3 @@ -36,13 +36,11 @@ DRIVER_INITIALIZE DriverEntry;
    30.4  #endif
    30.5  
    30.6  #if defined(__x86_64__)
    30.7 -  #define GET_PAGE_ALIGNED(ptr) ((PVOID)(((ULONGLONG)ptr + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)))
    30.8 +  #define LongLongToPtr(x) (PVOID)(x)
    30.9  #else
   30.10 -  #define GET_PAGE_ALIGNED(ptr) UlongToPtr((PtrToUlong(ptr) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
   30.11 +  #define LongLongToPtr(x) UlongToPtr(x)
   30.12  #endif
   30.13  
   30.14 -#define LongLongToPtr(x) ((PVOID)(ULONG)(x))
   30.15 -
   30.16  static BOOLEAN dump_mode = FALSE;
   30.17  
   30.18  ULONGLONG parse_numeric_string(PCHAR string)
   30.19 @@ -96,13 +94,6 @@ XenVbd_PutRequest(PXENVBD_DEVICE_DATA xv
   30.20  {
   30.21    blkif_other_request_t *other_req;
   30.22  
   30.23 -  if (dump_mode)
   30.24 -  {
   30.25 -    KdPrint((__DRIVER_NAME "     ring.sring->rsp_prod = %d\n", xvdd->ring.sring->rsp_prod));
   30.26 -    KdPrint((__DRIVER_NAME "     ring.sring->rsp_event = %d\n", xvdd->ring.sring->rsp_event));
   30.27 -    KdPrint((__DRIVER_NAME "     ring.rsp_cons = %d\n", xvdd->ring.rsp_cons));
   30.28 -    KdPrint((__DRIVER_NAME "     ring.req_prod_pvt = %d\n", xvdd->ring.req_prod_pvt));
   30.29 -  }
   30.30    if (!xvdd->use_other)
   30.31    {
   30.32      *RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt) = *req;
   30.33 @@ -118,10 +109,6 @@ XenVbd_PutRequest(PXENVBD_DEVICE_DATA xv
   30.34      memcpy(other_req->seg, req->seg, sizeof(struct blkif_request_segment) * req->nr_segments);
   30.35    }
   30.36    xvdd->ring.req_prod_pvt++;
   30.37 -  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_prod = %d\n", xvdd->ring.sring->rsp_prod));
   30.38 -  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_event = %d\n", xvdd->ring.sring->rsp_event));
   30.39 -  //KdPrint((__DRIVER_NAME "     ring.rsp_cons = %d\n", xvdd->ring.rsp_cons));
   30.40 -  //KdPrint((__DRIVER_NAME "     ring.req_prod_pvt = %d\n", xvdd->ring.req_prod_pvt));
   30.41  }
   30.42  
   30.43  static ULONG
   30.44 @@ -408,7 +395,27 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   30.45        PHYSICAL_ADDRESS physical_address;
   30.46        physical_address = ScsiPortGetPhysicalAddress(xvdd, srb, ptr, &length);
   30.47        offset = physical_address.LowPart & (PAGE_SIZE - 1);
   30.48 +      if (offset & 511)
   30.49 +      {
   30.50 +        KdPrint((__DRIVER_NAME "     DataTransferLength = %d, remaining = %d, block_count = %d, offset = %d, ptr = %p, srb->DataBuffer = %p\n",
   30.51 +          srb->DataTransferLength, remaining, block_count, offset, ptr, srb->DataBuffer));
   30.52 +        ptr = srb->DataBuffer;
   30.53 +        block_count = decode_cdb_length(srb);;
   30.54 +        block_count *= xvdd->bytes_per_sector / 512;
   30.55 +        remaining = block_count * 512;
   30.56 +        while (remaining > 0)
   30.57 +        {
   30.58 +          physical_address = ScsiPortGetPhysicalAddress(xvdd, srb, ptr, &length);
   30.59 +          KdPrint((__DRIVER_NAME "     ptr = %p, physical_address = %08x:%08x, length = %d\n",
   30.60 +            ptr, physical_address.HighPart, physical_address.LowPart, length));
   30.61 +          remaining -= length;
   30.62 +          ptr += length;
   30.63 +          KdPrint((__DRIVER_NAME "     remaining = %d\n", remaining));
   30.64 +        }
   30.65 +      }
   30.66 +      
   30.67        ASSERT((offset & 511) == 0);
   30.68 +      ASSERT((length & 511) == 0);
   30.69        //length = min(PAGE_SIZE - offset, remaining);
   30.70        //KdPrint((__DRIVER_NAME "     length(a) = %d\n", length));
   30.71        shadow->req.seg[shadow->req.nr_segments].gref = (grant_ref_t)(physical_address.QuadPart >> PAGE_SHIFT);
   30.72 @@ -873,8 +880,6 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
   30.73          ScsiPortNotification(NextRequest, DeviceExtension);
   30.74          break;
   30.75        case 2:
   30.76 -        if (dump_mode)
   30.77 -          KdPrint((__DRIVER_NAME "     rep->id = %d\n", rep->id));
   30.78          shadow = &xvdd->shadows[rep->id];
   30.79          srb = shadow->srb;
   30.80          ASSERT(srb != NULL);
   30.81 @@ -938,10 +943,6 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
   30.82      }
   30.83      FUNCTION_EXIT();
   30.84    }
   30.85 -  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_prod = %d\n", xvdd->ring.sring->rsp_prod));
   30.86 -  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_event = %d\n", xvdd->ring.sring->rsp_event));
   30.87 -  //KdPrint((__DRIVER_NAME "     ring.rsp_cons = %d\n", xvdd->ring.rsp_cons));
   30.88 -  //KdPrint((__DRIVER_NAME "     ring.req_prod_pvt = %d\n", xvdd->ring.req_prod_pvt));
   30.89  
   30.90    return FALSE; /* always fall through to the next ISR... */
   30.91  }
   30.92 @@ -1317,8 +1318,7 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   30.93      break;
   30.94    }
   30.95  
   30.96 -  if (dump_mode)
   30.97 -    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   30.98 +  //FUNCTION_EXIT();
   30.99    return TRUE;
  30.100  }
  30.101  
    31.1 --- a/xenvbd/xenvbd.inx	Sat Feb 14 13:35:48 2009 +1100
    31.2 +++ b/xenvbd/xenvbd.inx	Wed Feb 18 22:18:23 2009 +1100
    31.3 @@ -12,13 +12,9 @@ DefaultDestDir = 12
    31.4  ExcludeFromSelect=*
    31.5  
    31.6  [Manufacturer]
    31.7 -%XenGplPv%=XenGplPv,NTx86
    31.8 -%XenGplPv%=XenGplPv,NTamd64
    31.9 +%XenGplPv%=XenGplPv,NT$ARCH$
   31.10  
   31.11 -[XenGplPv.NTx86]
   31.12 -%XenVbd.DRVDESC%=XenVbd_Inst, XEN\VBD
   31.13 -
   31.14 -[XenGplPv.NTamd64]
   31.15 +[XenGplPv.NT$ARCH$]
   31.16  %XenVbd.DRVDESC%=XenVbd_Inst, XEN\VBD
   31.17  
   31.18  [XenVbd_Inst.NT]
   31.19 @@ -56,11 +52,8 @@ HKR,,TypesSupported,0x00010001,7
   31.20  [SourceDisksFiles]
   31.21  xenvbd.sys=1
   31.22  
   31.23 -[SourceDisksNames.x86]
   31.24 -1 = %DISK_NAME%,,,.\i386
   31.25 -
   31.26 -[SourceDisksNames.amd64]
   31.27 -1 = %DISK_NAME%,,,.\amd64
   31.28 +[SourceDisksNames]
   31.29 +1 = %DISK_NAME%
   31.30  
   31.31  [Strings]
   31.32  XenGplPv = "Xen GPL PV Driver Developers"