win-pvdrivers

changeset 495:a6e3f76419c3

Too many changes to mention. Mostly revolving around updating the way the pci ide and network adapters are disabled.
Also removed windows 2000 support, as it didn't work anyway.
Also fixes to XenSCSI.
author James Harper <james.harper@bendigoit.com.au>
date Mon Dec 15 19:17:13 2008 +1100 (2008-12-15)
parents c431d22ff34b
children 785de85f3db7
files common.inc common/include/xen_public.h common/include/xen_windows.h installer.nsi makedist.bat xenhide/xenhide.c xenhide/xenhide.h xennet/xennet.c xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci.inx xenpci/xenpci_pdo.c xenscsi/xenscsi.c xenscsi/xenscsi.h xenvbd/xenvbd.c
line diff
     1.1 --- a/common.inc	Tue Dec 09 20:30:26 2008 +1100
     1.2 +++ b/common.inc	Mon Dec 15 19:17:13 2008 +1100
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.9.11.7
     1.5 +VERSION=0.9.11.8
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  MSC_WARNING_LEVEL=/W4
     1.8  INCLUDES = ..\common\include;..\common\include\public
     2.1 --- a/common/include/xen_public.h	Tue Dec 09 20:30:26 2008 +1100
     2.2 +++ b/common/include/xen_public.h	Mon Dec 15 19:17:13 2008 +1100
     2.3 @@ -177,6 +177,7 @@ typedef struct {
     2.4  //#define XEN_INIT_TYPE_COPY_PTR          9
     2.5  #define XEN_INIT_TYPE_RUN               10
     2.6  #define XEN_INIT_TYPE_STATE_PTR         11
     2.7 +#define XEN_INIT_TYPE_ACTIVE		12
     2.8  
     2.9  static __inline VOID
    2.10  __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
    2.11 @@ -278,6 +279,7 @@ ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type
    2.12    case XEN_INIT_TYPE_VECTORS:
    2.13    case XEN_INIT_TYPE_RUN:
    2.14    case XEN_INIT_TYPE_STATE_PTR:
    2.15 +  case XEN_INIT_TYPE_ACTIVE:
    2.16      break;
    2.17    case XEN_INIT_TYPE_WRITE_STRING:
    2.18      __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
    2.19 @@ -312,6 +314,7 @@ GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1,
    2.20    case XEN_INIT_TYPE_VECTORS:
    2.21    case XEN_INIT_TYPE_RUN:
    2.22    case XEN_INIT_TYPE_STATE_PTR:
    2.23 +  case XEN_INIT_TYPE_ACTIVE:
    2.24      *p1 = NULL;
    2.25      *p2 = NULL;
    2.26      break;
    2.27 @@ -347,6 +350,7 @@ ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type
    2.28    case XEN_INIT_TYPE_END:
    2.29    case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
    2.30    case XEN_INIT_TYPE_RUN:
    2.31 +  case XEN_INIT_TYPE_ACTIVE:
    2.32      break;
    2.33    case XEN_INIT_TYPE_RING:
    2.34      __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
    2.35 @@ -392,6 +396,7 @@ GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1,
    2.36    {
    2.37    case XEN_INIT_TYPE_END:
    2.38    case XEN_INIT_TYPE_RUN:
    2.39 +  case XEN_INIT_TYPE_ACTIVE:
    2.40      *p1 = NULL;
    2.41      *p2 = NULL;
    2.42      break;
     3.1 --- a/common/include/xen_windows.h	Tue Dec 09 20:30:26 2008 +1100
     3.2 +++ b/common/include/xen_windows.h	Mon Dec 15 19:17:13 2008 +1100
     3.3 @@ -192,7 +192,7 @@ FreePages(PMDL Mdl)
     3.4    ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
     3.5  }
     3.6  
     3.7 -//#define XEN_IOPORT_DEBUG_PORT_BASE 0x10
     3.8 +#define XEN_IOPORT_DEBUG_PORT_BASE 0x10
     3.9  
    3.10  static void XenDbgPrint(PCHAR format, ...)
    3.11  {
    3.12 @@ -215,7 +215,7 @@ static void XenDbgPrint(PCHAR format, ..
    3.13    {
    3.14      KeRaiseIrql(HIGH_LEVEL, &old_irql);
    3.15    }
    3.16 -  cpu = KeGetCurrentProcessorNumber() & 0x0F;
    3.17 +  cpu = KeGetCurrentProcessorNumber() & 0x07;
    3.18    for (i = 0; i < strlen(buf); i++)
    3.19    {
    3.20      WRITE_PORT_UCHAR((PUCHAR)XEN_IOPORT_DEBUG_PORT_BASE + cpu, buf[i]);
     4.1 --- a/installer.nsi	Tue Dec 09 20:30:26 2008 +1100
     4.2 +++ b/installer.nsi	Mon Dec 15 19:17:13 2008 +1100
     4.3 @@ -6,7 +6,7 @@ Var ARCH_SPEC
     4.4  
     4.5  !define AppName "Xen PV Drivers"
     4.6  !define StartMenu "$SMPROGRAMS\${AppName}"
     4.7 -!define Version "0.9.12-pre7"
     4.8 +!define Version "0.9.12-pre8"
     4.9  #!define Version "$%VERSION%"
    4.10  Name "${AppName}"
    4.11  
    4.12 @@ -55,25 +55,6 @@ amd64_done:
    4.13    CreateShortCut "${StartMenu}\Uninstall.lnk" "$INSTDIR\uninstall.exe"
    4.14  SectionEnd
    4.15  
    4.16 -Section "Windows 2000" win2k
    4.17 -  SetOutPath $INSTDIR
    4.18 -  File /nonfatal .\ca.cer
    4.19 -  SetOutPath $INSTDIR\drivers
    4.20 -  File .\target\win2k\xenpci.inf
    4.21 -  File .\target\win2k\xennet.inf
    4.22 -  File .\target\win2k\xenvbd.inf
    4.23 -  File .\target\win2k\xenscsi.inf
    4.24 -  File .\target\win2k\xenstub.inf
    4.25 -  File /nonfatal .\target\win2k\xengplpv.cat
    4.26 -  SetOutPath $INSTDIR\drivers\i386
    4.27 -  File .\target\win2k\i386\xenpci.sys
    4.28 -  File .\target\win2k\i386\xenhide.sys
    4.29 -  File .\target\win2k\i386\xennet.sys
    4.30 -  File .\target\win2k\i386\xenvbd.sys
    4.31 -  File .\target\win2k\i386\xenscsi.sys
    4.32 -  File .\target\win2k\i386\xenstub.sys
    4.33 -SectionEnd
    4.34 -
    4.35  Section "Windows XP" winxp
    4.36    SetOutPath $INSTDIR
    4.37    File /nonfatal .\ca.cer
    4.38 @@ -260,10 +241,6 @@ is_amd64:
    4.39  amd64_done:
    4.40    StrCpy $INSTDIR "$MYPROGRAMFILES\${AppName}"
    4.41    
    4.42 -  StrCmp $R0 "2000" 0 check_XP
    4.43 -  StrCpy $arch "win2k"
    4.44 -  Goto version_done
    4.45 -check_XP:
    4.46    StrCmp $R0 "XP" 0 check_2k3
    4.47    StrCpy $arch "winxp"
    4.48    Goto version_done
    4.49 @@ -305,11 +282,6 @@ Function .onSelChange
    4.50    Push $0
    4.51    
    4.52    StrCpy $newarch $arch
    4.53 -  StrCmp $arch "win2k" check_xp
    4.54 -  SectionGetFlags ${win2k} $0
    4.55 -  IntOp $0 $0 & ${SF_SELECTED}
    4.56 -  IntCmp $0 ${SF_SELECTED} 0 check_xp check_xp
    4.57 -  StrCpy $newarch "win2k"
    4.58  check_xp:
    4.59    StrCmp $arch "winxp" check_2k3x32
    4.60    SectionGetFlags ${winxp} $0
    4.61 @@ -350,15 +322,6 @@ FunctionEnd
    4.62  Function SelectSection
    4.63    Push $0
    4.64  
    4.65 -  StrCmp $arch "win2k" set_win2k
    4.66 -  SectionGetFlags ${win2k} $0
    4.67 -  IntOp $0 $0 & ${SECTION_OFF}
    4.68 -  SectionSetFlags ${win2k} $0
    4.69 -  goto check_xp
    4.70 -set_win2k:
    4.71 -  SectionGetFlags ${win2k} $0
    4.72 -  IntOp $0 $0 | ${SF_SELECTED}
    4.73 -  SectionSetFlags ${win2k} $0  
    4.74  check_xp:
    4.75    StrCmp $arch "winxp" set_winxp
    4.76    SectionGetFlags ${winxp} $0
     5.1 --- a/makedist.bat	Tue Dec 09 20:30:26 2008 +1100
     5.2 +++ b/makedist.bat	Mon Dec 15 19:17:13 2008 +1100
     5.3 @@ -1,11 +1,6 @@
     5.4  @echo off
     5.5  IF NOT EXIST set_ddk_path.bat ECHO >set_ddk_path.bat SET DDK_PATH=C:\WinDDK\6001.18001
     5.6  
     5.7 -CALL set_ddk_path.bat
     5.8 -cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk W2K && CD \Projects\win-pvdrivers.hg && build -cZg"
     5.9 -CALL sign_sys.bat win2k i386 2000
    5.10 -CALL sign_inf.bat win2k 2000
    5.11 -
    5.12  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WXP && CD \Projects\win-pvdrivers.hg && build -cZg"
    5.13  CALL sign_sys.bat winxp i386 XP_X86
    5.14  CALL sign_inf.bat winxp XP_X86
     6.1 --- a/xenhide/xenhide.c	Tue Dec 09 20:30:26 2008 +1100
     6.2 +++ b/xenhide/xenhide.c	Mon Dec 15 19:17:13 2008 +1100
     6.3 @@ -21,30 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fi
     6.4  #include <stdlib.h>
     6.5  
     6.6  extern PULONG InitSafeBootMode;
     6.7 -
     6.8 -DRIVER_INITIALIZE DriverEntry;
     6.9 -static NTSTATUS
    6.10 -XenHide_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject);
    6.11 -static NTSTATUS
    6.12 -XenHide_Pass(PDEVICE_OBJECT DeviceObject, PIRP Irp);
    6.13 -static NTSTATUS
    6.14 -XenHide_Pnp(PDEVICE_OBJECT DeviceObject, PIRP Irp);
    6.15 -static NTSTATUS
    6.16 -XenHide_AddDevice();
    6.17 -//static NTSTATUS
    6.18 -//XenHide_Unload();
    6.19 -
    6.20 -#ifdef ALLOC_PRAGMA
    6.21 -#pragma alloc_text (INIT, DriverEntry)
    6.22 -#pragma alloc_text (PAGE, XenHide_AddDevice)
    6.23 -#endif
    6.24 -
    6.25 -static BOOLEAN gplpv;
    6.26 -static BOOLEAN at_boot;
    6.27 -static BOOLEAN qemu_ide_device_filter_installed;
    6.28 -static BOOLEAN qemu_scsi_device_filter_installed;
    6.29 -static KEVENT add_device_event;
    6.30 -static XENHIDE_DRIVER_DATA xenhide_global_data;
    6.31 +static BOOLEAN need_gplpv_filter;
    6.32 +static BOOLEAN gplpv_interrogated;
    6.33  
    6.34  static NTSTATUS
    6.35  XenHide_Power(PDEVICE_OBJECT device_object, PIRP irp)
    6.36 @@ -58,134 +36,6 @@ XenHide_Power(PDEVICE_OBJECT device_obje
    6.37    return status;
    6.38  }
    6.39  
    6.40 -NTSTATUS
    6.41 -DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    6.42 -{
    6.43 -  NTSTATUS status;
    6.44 -  UNICODE_STRING RegKeyName;
    6.45 -  UNICODE_STRING RegValueName;
    6.46 -  HANDLE RegHandle;
    6.47 -  OBJECT_ATTRIBUTES RegObjectAttributes;
    6.48 -  char Buf[300];// Sometimes bigger then 200 if system reboot from crash
    6.49 -  ULONG BufLen = 300;
    6.50 -  PKEY_VALUE_PARTIAL_INFORMATION KeyPartialValue;
    6.51 -  int State = 0;
    6.52 -  size_t StartPos = 0;
    6.53 -  WCHAR *SystemStartOptions;
    6.54 -  size_t SystemStartOptionsLen;
    6.55 -  size_t i;
    6.56 -
    6.57 -  UNREFERENCED_PARAMETER(RegistryPath);
    6.58 -
    6.59 -  KdPrint((__DRIVER_NAME " --> DriverEntry\n"));
    6.60 -
    6.61 -  RtlInitUnicodeString(&RegKeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control");
    6.62 -  InitializeObjectAttributes(&RegObjectAttributes, &RegKeyName, OBJ_CASE_INSENSITIVE, NULL, NULL);
    6.63 -  status = ZwOpenKey(&RegHandle, KEY_READ, &RegObjectAttributes);
    6.64 -  if(!NT_SUCCESS(status))
    6.65 -  {
    6.66 -    KdPrint((__DRIVER_NAME "     ZwOpenKey returned %08x\n", status));
    6.67 -  }
    6.68 -
    6.69 -  RtlInitUnicodeString(&RegValueName, L"SystemStartOptions");
    6.70 -  status = ZwQueryValueKey(RegHandle, &RegValueName, KeyValuePartialInformation, Buf, BufLen, &BufLen);
    6.71 -  if(!NT_SUCCESS(status))
    6.72 -  {
    6.73 -    KdPrint((__DRIVER_NAME "     ZwQueryKeyValue returned %08x\n", status));
    6.74 -  }
    6.75 -  else
    6.76 -    ZwClose(RegHandle);
    6.77 -  KeyPartialValue = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
    6.78 -  SystemStartOptions = (WCHAR *)KeyPartialValue->Data;
    6.79 -
    6.80 -  qemu_ide_device_filter_installed = FALSE;
    6.81 -  qemu_scsi_device_filter_installed = FALSE;
    6.82 -  KeInitializeEvent(&add_device_event, SynchronizationEvent, FALSE);
    6.83 -
    6.84 -  gplpv = FALSE;
    6.85 -
    6.86 -  RtlStringCbLengthW(SystemStartOptions, KeyPartialValue->DataLength, &SystemStartOptionsLen);
    6.87 -
    6.88 -  for (i = 0; i <= SystemStartOptionsLen/2; i++)
    6.89 -  {
    6.90 -    //KdPrint((__DRIVER_NAME "     pos = %d, state = %d, char = '%wc' (%d)\n", i, State, SystemStartOptions[i], SystemStartOptions[i]));
    6.91 -    
    6.92 -    switch (State)
    6.93 -    {
    6.94 -    case 0:
    6.95 -      if (SystemStartOptions[i] == L'G')
    6.96 -      {
    6.97 -        StartPos = (int)i;
    6.98 -        State = 2;
    6.99 -      } else if (SystemStartOptions[i] != L' ')
   6.100 -      {
   6.101 -        State = 1;
   6.102 -      }
   6.103 -      break;
   6.104 -    case 1:
   6.105 -      if (SystemStartOptions[i] == L' ')
   6.106 -        State = 0;
   6.107 -      break;
   6.108 -    case 2:
   6.109 -      if (SystemStartOptions[i] == L'P')
   6.110 -        State = 3;
   6.111 -      else
   6.112 -        State = 0;
   6.113 -      break;
   6.114 -    case 3:
   6.115 -      if (SystemStartOptions[i] == L'L')
   6.116 -        State = 4;
   6.117 -      else
   6.118 -        State = 0;
   6.119 -      break;
   6.120 -    case 4:
   6.121 -      if (SystemStartOptions[i] == L'P')
   6.122 -        State = 5;
   6.123 -      else
   6.124 -        State = 0;
   6.125 -      break;
   6.126 -    case 5:
   6.127 -      if (SystemStartOptions[i] == L'V')
   6.128 -        State = 6;
   6.129 -      else
   6.130 -        State = 0;
   6.131 -      break;
   6.132 -    case 6:
   6.133 -      if (SystemStartOptions[i] == L' ' || SystemStartOptions[i] == 0)
   6.134 -        gplpv = TRUE;
   6.135 -      State = 0;
   6.136 -      break;
   6.137 -    }
   6.138 -  }
   6.139 -
   6.140 -  //
   6.141 -  // Check for Safe mode boot...
   6.142 -  //
   6.143 -  if (*InitSafeBootMode > 0)
   6.144 -  {
   6.145 -    KdPrint((__DRIVER_NAME "     Running in SAFE MODE...disabling PV drivers\n"));
   6.146 -    gplpv = FALSE;
   6.147 -  }
   6.148 -
   6.149 -  KdPrint((__DRIVER_NAME "     gplpv = %d\n", gplpv));
   6.150 -
   6.151 -  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
   6.152 -    DriverObject->MajorFunction[i] = XenHide_Pass;
   6.153 -  DriverObject->MajorFunction[IRP_MJ_PNP] = XenHide_Pnp;
   6.154 -  DriverObject->MajorFunction[IRP_MJ_POWER] = XenHide_Power;
   6.155 -  DriverObject->DriverExtension->AddDevice = XenHide_AddDevice;
   6.156 -
   6.157 -  RtlZeroMemory(&xenhide_global_data, sizeof(XENHIDE_DRIVER_DATA));
   6.158 -
   6.159 -  InitializeListHead(&xenhide_global_data.hide_list_head);
   6.160 -  KeInitializeSpinLock(&xenhide_global_data.hide_list_lock);
   6.161 -  KeInitializeEvent(&xenhide_global_data.hide_list_event, SynchronizationEvent, FALSE);
   6.162 -
   6.163 -  KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
   6.164 -
   6.165 -  return status;
   6.166 -}
   6.167 -
   6.168  static BOOLEAN
   6.169  XenHide_IdSuffixMatches(PDEVICE_OBJECT pdo, PWCHAR matching_id)
   6.170  {
   6.171 @@ -224,7 +74,7 @@ XenHide_IdSuffixMatches(PDEVICE_OBJECT p
   6.172  //      KdPrint((__DRIVER_NAME "     Comparing '%S' and '%S'\n", ptr, matching_id));
   6.173        if (wcscmp(ptr, matching_id) == 0)
   6.174        {
   6.175 -        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (Match)\n"));
   6.176 +        //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (Match)\n"));
   6.177          return TRUE;
   6.178        }
   6.179      }
   6.180 @@ -243,14 +93,24 @@ XenHide_AddDevice(
   6.181    PDEVICE_OBJECT deviceObject = NULL;
   6.182    PXENHIDE_DEVICE_DATA xhdd;
   6.183    ULONG length;
   6.184 -  GUID bus_type;
   6.185    WCHAR device_description[256];
   6.186 -  KIRQL old_irql;
   6.187    USHORT hide_type;
   6.188 -  PXENHIDE_HIDE_LIST_ENTRY list_entry;
   6.189 +  OBJECT_ATTRIBUTES oa;
   6.190 +  UNICODE_STRING dir_name;
   6.191 +  HANDLE handle;
   6.192  
   6.193 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   6.194 +  FUNCTION_ENTER();
   6.195  
   6.196 +  if (!gplpv_interrogated)
   6.197 +  {
   6.198 +    gplpv_interrogated = TRUE;
   6.199 +    RtlInitUnicodeString(&dir_name, L"\\NEED_GPLPV_FILTER");
   6.200 +    InitializeObjectAttributes(&oa, &dir_name, OBJ_KERNEL_HANDLE, NULL, NULL);
   6.201 +    status = ZwOpenDirectoryObject(&handle, DIRECTORY_QUERY, &oa);
   6.202 +    KdPrint((__DRIVER_NAME "     ZwOpenDirectoryObject = %08x\n", status));
   6.203 +    if (NT_SUCCESS(status))
   6.204 +      need_gplpv_filter = TRUE;
   6.205 +  }
   6.206    
   6.207    length = 512;
   6.208    status = IoGetDeviceProperty(PhysicalDeviceObject, DevicePropertyDeviceDescription, length, device_description, &length);
   6.209 @@ -261,69 +121,31 @@ XenHide_AddDevice(
   6.210  
   6.211    //KdPrint((__DRIVER_NAME "     Checking '%S'\n", device_description));
   6.212  
   6.213 -  length = sizeof(GUID);
   6.214 -  status = IoGetDeviceProperty(PhysicalDeviceObject, DevicePropertyBusTypeGuid, length, &bus_type, &length);
   6.215 -  if (!NT_SUCCESS(status))
   6.216 -  {
   6.217 -    RtlZeroMemory(&bus_type, sizeof(GUID));
   6.218 -  }
   6.219 -
   6.220    hide_type = XENHIDE_TYPE_NONE;
   6.221 -  if (gplpv)
   6.222 +  if (need_gplpv_filter)
   6.223    {
   6.224      /* hide only specific devices */
   6.225      if (XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_8086&DEV_7010")) // Qemu IDE
   6.226      {
   6.227        hide_type = XENHIDE_TYPE_DEVICE;
   6.228 -      qemu_ide_device_filter_installed = TRUE;
   6.229 -      KeSetEvent(&add_device_event, IO_NO_INCREMENT, FALSE);
   6.230      }
   6.231      else if (XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_1000&DEV_0012"))// Qemu SCSI
   6.232      {
   6.233        hide_type = XENHIDE_TYPE_DEVICE;
   6.234 -      qemu_scsi_device_filter_installed = TRUE;
   6.235 -      KeSetEvent(&add_device_event, IO_NO_INCREMENT, FALSE);
   6.236      }
   6.237      else if (XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_10EC&DEV_8139")) // Qemu Network
   6.238      {
   6.239        hide_type = XENHIDE_TYPE_DEVICE;
   6.240      }
   6.241 -    else if (XenHide_IdSuffixMatches(PhysicalDeviceObject, L"PNP0A03"))
   6.242 -    {
   6.243 -      hide_type = XENHIDE_TYPE_PCI_BUS;
   6.244 -    }
   6.245 -  }
   6.246 -  else
   6.247 -  {
   6.248 -    /* hide everything on the xen bus */
   6.249 -    if (memcmp(&bus_type, &GUID_BUS_TYPE_XEN, sizeof(GUID)) == 0)
   6.250 -      hide_type = XENHIDE_TYPE_DEVICE;
   6.251    }
   6.252  
   6.253    if (hide_type == XENHIDE_TYPE_NONE)
   6.254    {
   6.255 -    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (filter not required for %S)\n", device_description));
   6.256 +    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (filter not required for %S)\n", device_description));
   6.257      return STATUS_SUCCESS;
   6.258    }
   6.259  
   6.260 -  //KdPrint((__DRIVER_NAME "     Installing Filter for %S\n", device_description));
   6.261 -
   6.262 -  if (gplpv && hide_type == XENHIDE_TYPE_DEVICE)
   6.263 -  {
   6.264 -    KeAcquireSpinLock(&xenhide_global_data.hide_list_lock, &old_irql);
   6.265 -    list_entry = ExAllocatePoolWithTag(NonPagedPool, sizeof(XENHIDE_HIDE_LIST_ENTRY), XENHIDE_POOL_TAG);
   6.266 -    list_entry->pdo = PhysicalDeviceObject;
   6.267 -    InsertTailList(&xenhide_global_data.hide_list_head, (PLIST_ENTRY)list_entry);
   6.268 -    KeReleaseSpinLock(&xenhide_global_data.hide_list_lock, old_irql);
   6.269 -    KeSetEvent(&xenhide_global_data.hide_list_event, IO_NO_INCREMENT, FALSE);
   6.270 -    ASSERT(xenhide_global_data.pci_bus_pdo);
   6.271 -    IoInvalidateDeviceRelations(xenhide_global_data.pci_bus_pdo, BusRelations);
   6.272 -  }
   6.273 -  else if (hide_type == XENHIDE_TYPE_PCI_BUS)
   6.274 -  {
   6.275 -    ASSERT(!xenhide_global_data.pci_bus_pdo);
   6.276 -    xenhide_global_data.pci_bus_pdo = PhysicalDeviceObject;
   6.277 -  }
   6.278 +  KdPrint((__DRIVER_NAME "     Installing Filter for %S\n", device_description));
   6.279  
   6.280    status = IoCreateDevice (DriverObject,
   6.281      sizeof(XENHIDE_DEVICE_DATA),
   6.282 @@ -350,7 +172,7 @@ XenHide_AddDevice(
   6.283  
   6.284    deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
   6.285  
   6.286 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   6.287 +  FUNCTION_EXIT();
   6.288  
   6.289    return STATUS_SUCCESS;
   6.290  }
   6.291 @@ -391,6 +213,36 @@ XenHide_Pnp_IoCompletion(PDEVICE_OBJECT 
   6.292  }
   6.293  
   6.294  static NTSTATUS
   6.295 +XenHide_QueueWorkItem(PDEVICE_OBJECT device_object, PIO_WORKITEM_ROUTINE routine, PVOID context)
   6.296 +{
   6.297 +  PIO_WORKITEM work_item;
   6.298 +  NTSTATUS status = STATUS_SUCCESS;
   6.299 +
   6.300 +  work_item = IoAllocateWorkItem(device_object);
   6.301 +  IoQueueWorkItem(work_item, routine, DelayedWorkQueue, context);
   6.302 +
   6.303 +  return status;
   6.304 +}
   6.305 +
   6.306 +static VOID
   6.307 +XenHide_Pnp_StartDeviceCallback(PDEVICE_OBJECT device_object, PVOID context)
   6.308 +{
   6.309 +  NTSTATUS status = STATUS_SUCCESS;
   6.310 +  PIRP irp = context;
   6.311 +
   6.312 +  UNREFERENCED_PARAMETER(device_object);
   6.313 +
   6.314 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   6.315 +
   6.316 +  status = STATUS_UNSUCCESSFUL;
   6.317 +  irp->IoStatus.Status = status;
   6.318 +
   6.319 +  IoCompleteRequest(irp, IO_NO_INCREMENT);
   6.320 +
   6.321 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   6.322 +}
   6.323 +
   6.324 +static NTSTATUS
   6.325  XenHide_SendAndWaitForIrp(PDEVICE_OBJECT device_object, PIRP irp)
   6.326  {
   6.327    NTSTATUS status;
   6.328 @@ -419,93 +271,48 @@ XenHide_SendAndWaitForIrp(PDEVICE_OBJECT
   6.329    return status;
   6.330  }
   6.331  
   6.332 -static NTSTATUS
   6.333 -XenHide_QueueWorkItem(PDEVICE_OBJECT device_object, PIO_WORKITEM_ROUTINE routine, PVOID context)
   6.334 -{
   6.335 -  PIO_WORKITEM work_item;
   6.336 -  NTSTATUS status = STATUS_SUCCESS;
   6.337 -
   6.338 -  work_item = IoAllocateWorkItem(device_object);
   6.339 -  IoQueueWorkItem(work_item, routine, DelayedWorkQueue, context);
   6.340 -	
   6.341 -  return status;
   6.342 -}
   6.343 -
   6.344 -static VOID
   6.345 -XenHide_Pnp_StartDeviceCallback(PDEVICE_OBJECT device_object, PVOID context)
   6.346 -{
   6.347 -  NTSTATUS status = STATUS_SUCCESS;
   6.348 -  PIRP irp = context;
   6.349 -  
   6.350 -  UNREFERENCED_PARAMETER(device_object);
   6.351 -
   6.352 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   6.353 -  
   6.354 -  irp->IoStatus.Status = status;
   6.355 -  
   6.356 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
   6.357 -
   6.358 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   6.359 -}
   6.360 -
   6.361 -/*
   6.362 -The FDO will take the existance of a 0 CmResourceTypeMemory resource to mean that it should not do anything.
   6.363 -In the case of xenvbd this means it will not report any disks. In the case of xennet ???
   6.364 -*/
   6.365 -static NTSTATUS
   6.366 -XenHide_Pnp_StartDevice_AddHideFlag(PDEVICE_OBJECT device_object, PIRP irp)
   6.367 +XenHide_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
   6.368  {
   6.369    NTSTATUS status;
   6.370 +#if 0
   6.371    PIO_STACK_LOCATION stack;
   6.372 -  PCM_RESOURCE_LIST old_crl, new_crl;
   6.373 +  PCM_RESOURCE_LIST crl;
   6.374    PCM_PARTIAL_RESOURCE_LIST prl;
   6.375 -  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
   6.376 -  ULONG old_length, new_length;
   6.377 +#endif
   6.378  
   6.379    UNREFERENCED_PARAMETER(device_object);
   6.380  
   6.381 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   6.382 +  FUNCTION_ENTER();
   6.383  
   6.384 +#if 0
   6.385    stack = IoGetCurrentIrpStackLocation(irp);
   6.386  
   6.387 -  old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   6.388 -  old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
   6.389 -    FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
   6.390 -    FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
   6.391 -    sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
   6.392 -  new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
   6.393 -  new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENHIDE_POOL_TAG);
   6.394 -  memcpy(new_crl, old_crl, old_length);
   6.395 -  prl = &new_crl->List[0].PartialResourceList;
   6.396 -  prd = &prl->PartialDescriptors[prl->Count++];
   6.397 -  prd->Type = CmResourceTypeMemory;
   6.398 -  prd->ShareDisposition = CmResourceShareDeviceExclusive;
   6.399 -  prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
   6.400 -  prd->u.Memory.Start.QuadPart = 0;
   6.401 -  prd->u.Memory.Length = 0;
   6.402 -  stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
   6.403 -
   6.404 -  old_crl = stack->Parameters.StartDevice.AllocatedResources;
   6.405 -  new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENHIDE_POOL_TAG);
   6.406 -  memcpy(new_crl, old_crl, old_length);
   6.407 -  prl = &new_crl->List[0].PartialResourceList;
   6.408 -  prd = &prl->PartialDescriptors[prl->Count++];
   6.409 -  prd->Type = CmResourceTypeMemory;
   6.410 -  prd->ShareDisposition = CmResourceShareDeviceExclusive;
   6.411 -  prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
   6.412 -  prd->u.Memory.Start.QuadPart = (ULONGLONG)0;
   6.413 -  prd->u.Memory.Length = 0;
   6.414 -  stack->Parameters.StartDevice.AllocatedResources = new_crl;
   6.415 -
   6.416 -  // free the original resource lists???
   6.417 +  crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   6.418 +  prl = &crl->List[0].PartialResourceList;
   6.419 +  KdPrint((__DRIVER_NAME "     AllocatedResourcesTranslated count old value = %d\n", prl->Count));
   6.420 +  prl->Count = 0;
   6.421 +  crl = stack->Parameters.StartDevice.AllocatedResources;
   6.422 +  prl = &crl->List[0].PartialResourceList;
   6.423 +  KdPrint((__DRIVER_NAME "     AllocatedResources count old value = %d\n", prl->Count));
   6.424 +  prl->Count = 0;
   6.425 +#endif
   6.426  
   6.427    IoMarkIrpPending(irp);
   6.428    status = XenHide_SendAndWaitForIrp(device_object, irp);
   6.429  
   6.430 +#if 0
   6.431 +  crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   6.432 +  prl = &crl->List[0].PartialResourceList;
   6.433 +  KdPrint((__DRIVER_NAME "     AllocatedResourcesTranslated count value = %d\n", prl->Count));
   6.434 +  crl = stack->Parameters.StartDevice.AllocatedResources;
   6.435 +  prl = &crl->List[0].PartialResourceList;
   6.436 +  KdPrint((__DRIVER_NAME "     AllocatedResources count value = %d\n", prl->Count));
   6.437 +#endif
   6.438 +
   6.439    XenHide_QueueWorkItem(device_object, XenHide_Pnp_StartDeviceCallback, irp);
   6.440  
   6.441 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   6.442 -  
   6.443 +  FUNCTION_EXIT();
   6.444 +
   6.445    return STATUS_PENDING;
   6.446  }
   6.447  
   6.448 @@ -515,68 +322,14 @@ XenHide_Pnp(PDEVICE_OBJECT device_object
   6.449    NTSTATUS status = STATUS_SUCCESS;
   6.450    PIO_STACK_LOCATION stack;
   6.451    PXENHIDE_DEVICE_DATA xhdd = (PXENHIDE_DEVICE_DATA)device_object->DeviceExtension;
   6.452 -  PDEVICE_RELATIONS relations;
   6.453 -  PXENHIDE_HIDE_LIST_ENTRY list_entry;
   6.454 -  ULONG i, j;
   6.455 -  KIRQL old_irql;
   6.456  
   6.457 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ " (device_object = %p)\n", device_object));
   6.458 +  FUNCTION_ENTER();
   6.459  
   6.460    stack = IoGetCurrentIrpStackLocation(irp);
   6.461  
   6.462    switch (stack->MinorFunction) {
   6.463    case IRP_MN_START_DEVICE:
   6.464 -    //KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE\n"));
   6.465 -    if (xhdd->hide_type == XENHIDE_TYPE_DEVICE)
   6.466 -    {
   6.467 -      //KdPrint((__DRIVER_NAME "     hide_type == XENHIDE_TYPE_DEVICE\n"));
   6.468 -      //status = irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
   6.469 -      //IoCompleteRequest(irp, IO_NO_INCREMENT);
   6.470 -      status = XenHide_Pnp_StartDevice_AddHideFlag(device_object, irp);
   6.471 -    }
   6.472 -    else
   6.473 -    {
   6.474 -      //KdPrint((__DRIVER_NAME "     hide_type != XENHIDE_TYPE_DEVICE\n"));
   6.475 -      IoSkipCurrentIrpStackLocation(irp);
   6.476 -      status = IoCallDriver(xhdd->lower_do, irp);
   6.477 -    }
   6.478 -    break;
   6.479 -  case IRP_MN_QUERY_DEVICE_RELATIONS:
   6.480 -    if (xhdd->hide_type == XENHIDE_TYPE_PCI_BUS && stack->Parameters.QueryDeviceRelations.Type == BusRelations)
   6.481 -    {
   6.482 -      //KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS - BusRelations\n"));
   6.483 -      //IoMarkIrpPending(irp);
   6.484 -      status = XenHide_SendAndWaitForIrp(device_object, irp);
   6.485 -      relations = (PDEVICE_RELATIONS)irp->IoStatus.Information;
   6.486 -      for (i = 0, j = 0; i < relations->Count; i++)
   6.487 -      {
   6.488 -        if (i != j)
   6.489 -          relations->Objects[j] = relations->Objects[i];
   6.490 -        KeAcquireSpinLock(&xenhide_global_data.hide_list_lock, &old_irql);
   6.491 -        list_entry = (PXENHIDE_HIDE_LIST_ENTRY)xenhide_global_data.hide_list_head.Flink;
   6.492 -        while (list_entry != (PXENHIDE_HIDE_LIST_ENTRY)&xenhide_global_data.hide_list_head)
   6.493 -        {
   6.494 -          if (relations->Objects[i] == list_entry->pdo)
   6.495 -          {
   6.496 -            //KdPrint((__DRIVER_NAME "     Hiding %p\n", relations->Objects[i]));
   6.497 -            break;
   6.498 -          }
   6.499 -          list_entry = (PXENHIDE_HIDE_LIST_ENTRY)list_entry->entry.Flink;
   6.500 -        }
   6.501 -        if (list_entry == (PXENHIDE_HIDE_LIST_ENTRY)&xenhide_global_data.hide_list_head)
   6.502 -          j++;
   6.503 -        KeReleaseSpinLock(&xenhide_global_data.hide_list_lock, old_irql);
   6.504 -      }
   6.505 -      relations->Count = j;
   6.506 -      irp->IoStatus.Status = status;
   6.507 -      IoCompleteRequest (irp, IO_NO_INCREMENT);
   6.508 -    }
   6.509 -    else
   6.510 -    {
   6.511 -      //KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS - %d\n", stack->Parameters.QueryDeviceRelations.Type));
   6.512 -      IoSkipCurrentIrpStackLocation(irp);
   6.513 -      status = IoCallDriver(xhdd->lower_do, irp);
   6.514 -    }
   6.515 +    status = XenHide_Pnp_StartDevice(device_object, irp);
   6.516      break;
   6.517    case IRP_MN_REMOVE_DEVICE:
   6.518      //KdPrint((__DRIVER_NAME "     IRP_MN_REMOVE_DEVICE\n"));
   6.519 @@ -594,7 +347,31 @@ XenHide_Pnp(PDEVICE_OBJECT device_object
   6.520      break;
   6.521    }
   6.522  
   6.523 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", status));
   6.524 +  FUNCTION_EXIT();
   6.525  
   6.526    return status;
   6.527  }
   6.528 +
   6.529 +NTSTATUS
   6.530 +DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
   6.531 +{
   6.532 +  NTSTATUS status = STATUS_SUCCESS;
   6.533 +  int i;
   6.534 +  
   6.535 +  UNREFERENCED_PARAMETER(RegistryPath);
   6.536 +
   6.537 +  FUNCTION_ENTER();
   6.538 +
   6.539 +  need_gplpv_filter = FALSE;
   6.540 +  gplpv_interrogated = FALSE;
   6.541 +  
   6.542 +  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
   6.543 +    DriverObject->MajorFunction[i] = XenHide_Pass;
   6.544 +  DriverObject->MajorFunction[IRP_MJ_PNP] = XenHide_Pnp;
   6.545 +  DriverObject->MajorFunction[IRP_MJ_POWER] = XenHide_Power;
   6.546 +  DriverObject->DriverExtension->AddDevice = XenHide_AddDevice;
   6.547 +
   6.548 +  FUNCTION_EXIT();
   6.549 +
   6.550 +  return status;
   6.551 +}
     7.1 --- a/xenhide/xenhide.h	Tue Dec 09 20:30:26 2008 +1100
     7.2 +++ b/xenhide/xenhide.h	Mon Dec 15 19:17:13 2008 +1100
     7.3 @@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     7.4  #if !defined(_XENHIDE_H_)
     7.5  #define _XENHIDE_H_
     7.6  
     7.7 +#include <ntifs.h>
     7.8  #include <ntddk.h>
     7.9  #include <wdm.h>
    7.10  #include <initguid.h>
    7.11 @@ -30,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fi
    7.12  
    7.13  #define __DRIVER_NAME "XenHide"
    7.14  
    7.15 +#include <xen_windows.h>
    7.16  #include <xen_guids.h>
    7.17  
    7.18  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
    7.19 @@ -51,18 +53,4 @@ typedef struct {
    7.20    USHORT hide_type;
    7.21  } XENHIDE_DEVICE_DATA, *PXENHIDE_DEVICE_DATA;
    7.22  
    7.23 -typedef struct
    7.24 -{
    7.25 -  LIST_ENTRY entry;
    7.26 -  PDEVICE_OBJECT pdo;
    7.27 -} XENHIDE_HIDE_LIST_ENTRY,  *PXENHIDE_HIDE_LIST_ENTRY;
    7.28 -
    7.29 -typedef struct
    7.30 -{
    7.31 -  PDEVICE_OBJECT pci_bus_pdo;
    7.32 -  LIST_ENTRY hide_list_head;
    7.33 -  KSPIN_LOCK hide_list_lock;
    7.34 -  KEVENT hide_list_event;
    7.35 -} XENHIDE_DRIVER_DATA, *PXENHIDE_DRIVER_DATA;
    7.36 -
    7.37  #endif
     8.1 --- a/xennet/xennet.c	Tue Dec 09 20:30:26 2008 +1100
     8.2 +++ b/xennet/xennet.c	Mon Dec 15 19:17:13 2008 +1100
     8.3 @@ -392,9 +392,13 @@ XenNet_Init(
     8.4        irq_level = (KIRQL)prd->u.Interrupt.Level;
     8.5        KdPrint((__DRIVER_NAME "     irq_vector = %03x, irq_level = %03x\n", irq_vector, irq_level));
     8.6        break;
     8.7 -
     8.8      case CmResourceTypeMemory:
     8.9 -      if (prd->u.Memory.Start.QuadPart)
    8.10 +      if (xi->config_page)
    8.11 +      {
    8.12 +        KdPrint(("More than one memory range\n"));
    8.13 +        return NDIS_STATUS_RESOURCES;
    8.14 +      }
    8.15 +      else
    8.16        {
    8.17          status = NdisMMapIoSpace(&xi->config_page, MiniportAdapterHandle, prd->u.Memory.Start, prd->u.Memory.Length);
    8.18          if (!NT_SUCCESS(status))
    8.19 @@ -404,10 +408,6 @@ XenNet_Init(
    8.20            return NDIS_STATUS_RESOURCES;
    8.21          }
    8.22        }
    8.23 -      else
    8.24 -      {
    8.25 -        xi->inactive = TRUE;
    8.26 -      }
    8.27        break;
    8.28      }
    8.29    }
    8.30 @@ -739,24 +739,32 @@ DriverEntry(
    8.31    )
    8.32  {
    8.33    NTSTATUS status;
    8.34 -  NDIS_HANDLE ndis_wrapper_handle;
    8.35 +  NDIS_HANDLE ndis_wrapper_handle = NULL;
    8.36    NDIS_MINIPORT_CHARACTERISTICS mini_chars;
    8.37  
    8.38    FUNCTION_ENTER();
    8.39  
    8.40 +  KdPrint((__DRIVER_NAME "     DriverObject = %p, RegistryPath = %p\n", DriverObject, RegistryPath));
    8.41    RtlZeroMemory(&mini_chars, sizeof(mini_chars));
    8.42  
    8.43 +  KdPrint((__DRIVER_NAME "     NdisGetVersion = %x\n", NdisGetVersion()));
    8.44 +
    8.45 +  KdPrint((__DRIVER_NAME "     ndis_wrapper_handle = %p\n", ndis_wrapper_handle));
    8.46    NdisMInitializeWrapper(&ndis_wrapper_handle, DriverObject, RegistryPath, NULL);
    8.47 +  KdPrint((__DRIVER_NAME "     ndis_wrapper_handle = %p\n", ndis_wrapper_handle));
    8.48    if (!ndis_wrapper_handle)
    8.49    {
    8.50 -    KdPrint(("NdisMInitializeWrapper failed\n"));
    8.51 +    KdPrint((__DRIVER_NAME "     NdisMInitializeWrapper failed\n"));
    8.52      return NDIS_STATUS_FAILURE;
    8.53    }
    8.54 +  KdPrint((__DRIVER_NAME "     NdisMInitializeWrapper succeeded\n"));
    8.55  
    8.56    /* NDIS 5.1 driver */
    8.57    mini_chars.MajorNdisVersion = NDIS_MINIPORT_MAJOR_VERSION;
    8.58    mini_chars.MinorNdisVersion = NDIS_MINIPORT_MINOR_VERSION;
    8.59  
    8.60 +  KdPrint((__DRIVER_NAME "     MajorNdisVersion = %d,  MinorNdisVersion = %d\n", NDIS_MINIPORT_MAJOR_VERSION, NDIS_MINIPORT_MINOR_VERSION));
    8.61 +
    8.62    mini_chars.HaltHandler = XenNet_Halt;
    8.63    mini_chars.InitializeHandler = XenNet_Init;
    8.64    mini_chars.ISRHandler = XenNet_InterruptIsr;
    8.65 @@ -777,10 +785,12 @@ DriverEntry(
    8.66  #endif
    8.67  
    8.68    /* set up upper-edge interface */
    8.69 +  KdPrint((__DRIVER_NAME "     about to call NdisMRegisterMiniport\n"));
    8.70    status = NdisMRegisterMiniport(ndis_wrapper_handle, &mini_chars, sizeof(mini_chars));
    8.71 +  KdPrint((__DRIVER_NAME "     called NdisMRegisterMiniport\n"));
    8.72    if (!NT_SUCCESS(status))
    8.73    {
    8.74 -    KdPrint(("NdisMRegisterMiniport failed, status = 0x%x\n", status));
    8.75 +    KdPrint((__DRIVER_NAME "     NdisMRegisterMiniport failed, status = 0x%x\n", status));
    8.76      NdisTerminateWrapper(ndis_wrapper_handle, NULL);
    8.77      return status;
    8.78    }
     9.1 --- a/xenpci/xenpci.c	Tue Dec 09 20:30:26 2008 +1100
     9.2 +++ b/xenpci/xenpci.c	Mon Dec 15 19:17:13 2008 +1100
     9.3 @@ -223,23 +223,100 @@ XenPci_AddDevice(PDRIVER_OBJECT DriverOb
     9.4    FUNCTION_EXIT();
     9.5    return status;
     9.6  }
     9.7 +//DECLARE_UNICODE_STRING_SIZE(service_path, 512);
     9.8  
     9.9 -DECLARE_UNICODE_STRING_SIZE(service_path, 512);
    9.10 +#define XEN_GLOBAL_IOPORT_PORT_BASE 0x10
    9.11 +
    9.12 +ULONG need_gplpv_filter;
    9.13 +extern PULONG InitSafeBootMode;
    9.14  
    9.15  NTSTATUS DDKAPI
    9.16  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    9.17  {
    9.18    NTSTATUS status = STATUS_SUCCESS;
    9.19 +  PCONFIGURATION_INFORMATION conf_info;
    9.20 +  WCHAR *SystemStartOptions;
    9.21 +  UNICODE_STRING RegKeyName;
    9.22 +  UNICODE_STRING RegValueName;
    9.23 +  HANDLE RegHandle;
    9.24 +  OBJECT_ATTRIBUTES RegObjectAttributes;
    9.25 +  char Buf[300];// Sometimes bigger then 200 if system reboot from crash
    9.26 +  ULONG BufLen = 300;
    9.27 +  PKEY_VALUE_PARTIAL_INFORMATION KeyPartialValue;
    9.28  
    9.29    UNREFERENCED_PARAMETER(RegistryPath);
    9.30  
    9.31    FUNCTION_ENTER();
    9.32  
    9.33 -  //InitializeListHead(&ShutdownMsgList);
    9.34 -  //KeInitializeSpinLock(&ShutdownMsgLock);
    9.35 +  RtlInitUnicodeString(&RegKeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control");
    9.36 +  InitializeObjectAttributes(&RegObjectAttributes, &RegKeyName, OBJ_CASE_INSENSITIVE, NULL, NULL);
    9.37 +  status = ZwOpenKey(&RegHandle, KEY_READ, &RegObjectAttributes);
    9.38 +  if(!NT_SUCCESS(status))
    9.39 +  {
    9.40 +    KdPrint((__DRIVER_NAME "     ZwOpenKey returned %08x\n", status));
    9.41 +  }
    9.42 +
    9.43 +  RtlInitUnicodeString(&RegValueName, L"SystemStartOptions");
    9.44 +  status = ZwQueryValueKey(RegHandle, &RegValueName, KeyValuePartialInformation, Buf, BufLen, &BufLen);
    9.45 +  if(!NT_SUCCESS(status))
    9.46 +  {
    9.47 +    KdPrint((__DRIVER_NAME "     ZwQueryKeyValue returned %08x\n", status));
    9.48 +  }
    9.49 +  else
    9.50 +    ZwClose(RegHandle);
    9.51 +  KeyPartialValue = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
    9.52 +  SystemStartOptions = (WCHAR *)KeyPartialValue->Data;
    9.53 +
    9.54 +  KdPrint((__DRIVER_NAME "     SystemStartOptions = %s\n", SystemStartOptions));
    9.55 +  if (wcsstr(SystemStartOptions, L"NOGPLPV"))
    9.56 +    KdPrint((__DRIVER_NAME "     NOGPLPV found\n"));
    9.57 +  conf_info = IoGetConfigurationInformation();
    9.58 +  if ((conf_info == NULL || conf_info->DiskCount == 0)
    9.59 +      && !wcsstr(SystemStartOptions, L"NOGPLPV")
    9.60 +      && !*InitSafeBootMode)
    9.61 +  {
    9.62 +    /* see if the qemu method of disabling the PCI devices exists */
    9.63 +    if (READ_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 0)) == 'X'
    9.64 +        && READ_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 1)) == 'E'
    9.65 +        && READ_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 2)) == 'N')
    9.66 +    {
    9.67 +      UCHAR version = READ_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 3));
    9.68 +      switch(version)
    9.69 +      {
    9.70 +      case 1:
    9.71 +        need_gplpv_filter = TRUE;
    9.72 +        WRITE_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 8), 1);
    9.73 +        KdPrint((__DRIVER_NAME "     Disabled PCI devices\n"));
    9.74 +        break;
    9.75 +      default:
    9.76 +        KdPrint((__DRIVER_NAME "     Unknown version %d\n", (ULONG)version));
    9.77 +        break;
    9.78 +      }
    9.79 +    }
    9.80 +    else
    9.81 +    {
    9.82 +      KdPrint((__DRIVER_NAME "     Missing XEN signature\n"));
    9.83 +    }
    9.84 +    /* if not, tell the filter to deny the pci devices their resources */
    9.85 +    if (!need_gplpv_filter)
    9.86 +    {
    9.87 +      OBJECT_ATTRIBUTES oa;
    9.88 +      UNICODE_STRING dir_name;
    9.89 +      NTSTATUS status;
    9.90 +      HANDLE handle;
    9.91 +      
    9.92 +      RtlInitUnicodeString(&dir_name, L"\\NEED_GPLPV_FILTER");
    9.93 +      InitializeObjectAttributes(&oa, &dir_name, OBJ_KERNEL_HANDLE, NULL, NULL);
    9.94 +      status = ZwCreateDirectoryObject(&handle, DIRECTORY_CREATE_OBJECT, &oa);
    9.95 +      KdPrint((__DRIVER_NAME "     ZwCreateDirectoryObject = %08x\n", status));
    9.96 +      if (!NT_SUCCESS(status))
    9.97 +      {
    9.98 +        return status;
    9.99 +      }
   9.100 +      need_gplpv_filter = TRUE;
   9.101 +    }
   9.102 +  }
   9.103    
   9.104 -  RtlUnicodeStringCopy(&service_path, RegistryPath);
   9.105 -
   9.106    DriverObject->DriverExtension->AddDevice = XenPci_AddDevice;
   9.107    DriverObject->MajorFunction[IRP_MJ_PNP] = XenPci_Pnp;
   9.108    DriverObject->MajorFunction[IRP_MJ_POWER] = XenPci_Power;
    10.1 --- a/xenpci/xenpci.h	Tue Dec 09 20:30:26 2008 +1100
    10.2 +++ b/xenpci/xenpci.h	Mon Dec 15 19:17:13 2008 +1100
    10.3 @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fi
    10.4  #define __attribute__(arg) /* empty */
    10.5  #define EISCONN 127
    10.6  
    10.7 +#include <ntifs.h>
    10.8  #include <ntddk.h>
    10.9  
   10.10  #ifdef __MINGW32__
   10.11 @@ -68,7 +69,7 @@ DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC82
   10.12  #define EVT_ACTION_TYPE_IRQ     3
   10.13  #define EVT_ACTION_TYPE_SUSPEND 4
   10.14  
   10.15 -extern UNICODE_STRING service_path;
   10.16 +extern ULONG need_gplpv_filter;
   10.17  
   10.18  typedef struct _ev_action_t {
   10.19    PKSERVICE_ROUTINE ServiceRoutine;
    11.1 --- a/xenpci/xenpci.inx	Tue Dec 09 20:30:26 2008 +1100
    11.2 +++ b/xenpci/xenpci.inx	Mon Dec 15 19:17:13 2008 +1100
    11.3 @@ -46,7 +46,7 @@ 1 = %DISK_NAME%,,,.\amd64
    11.4  1 = %DISK_NAME%,,,.\i386
    11.5  
    11.6  [XenPCI_Inst.NT.Services]
    11.7 -AddService=XenPCI,2,XenPCI_Service
    11.8 +AddService=XenPCI,3,XenPCI_Service
    11.9  AddService=XenHide,0,XenHide_Service
   11.10  
   11.11  [XenPCI_Service]
   11.12 @@ -54,24 +54,16 @@ DisplayName    = %XenPCI.SVCDESC%
   11.13  ServiceType    = 1
   11.14  StartType      = 0
   11.15  ErrorControl   = 1
   11.16 -LoadOrderGroup = System Bus Extender
   11.17 +LoadOrderGroup = Boot Bus Extender
   11.18  ServiceBinary  = %12%\xenpci.sys
   11.19 -AddReg         = XenPCI_Service_AddReg
   11.20  
   11.21  [XenHide_Service]
   11.22  DisplayName    = %XenHide.SVCDESC%
   11.23  ServiceType    = 1
   11.24  StartType      = 0
   11.25  ErrorControl   = 1
   11.26 -LoadOrderGroup = Boot Bus Extender
   11.27 +LoadOrderGroup = System Bus Extender
   11.28  ServiceBinary  = %12%\xenhide.sys
   11.29 -AddReg         = XenHide_Service_AddReg
   11.30 -
   11.31 -[XenHide_Service_AddReg]
   11.32 -HKLM,SYSTEM\CurrentControlSet\Control\Class\{4D36E97D-E325-11CE-BFC1-08002BE10318},UpperFilters,0x00010008,XenHide
   11.33 -
   11.34 -[XenPCI_Service_AddReg]
   11.35 -HKR,,Security,,"D:P(A;;GA;;;SY)(A;;GA;;;BA)"   ; SDDL_DEVOBJ_SYS_ALL_ADM_ALL
   11.36  
   11.37  [Strings]
   11.38  XenGplPv = "Xen GPL PV Driver Developers"
    12.1 --- a/xenpci/xenpci_pdo.c	Tue Dec 09 20:30:26 2008 +1100
    12.2 +++ b/xenpci/xenpci_pdo.c	Mon Dec 15 19:17:13 2008 +1100
    12.3 @@ -595,7 +595,10 @@ XenPci_XenConfigDeviceSpecifyBuffers(PVO
    12.4    vectors.XenBus_List = XenPci_XenBus_List;
    12.5    vectors.XenBus_AddWatch = XenPci_XenBus_AddWatch;
    12.6    vectors.XenBus_RemWatch = XenPci_XenBus_RemWatch;
    12.7 - 
    12.8 +
    12.9 +  if (need_gplpv_filter)
   12.10 +    ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_ACTIVE, NULL, NULL);
   12.11 +  
   12.12    ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_VECTORS, NULL, &vectors);
   12.13    ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_STATE_PTR, NULL, &xppdd->device_state);
   12.14  
   12.15 @@ -950,220 +953,36 @@ XenPci_DumpPdoConfig(PDEVICE_OBJECT devi
   12.16  static PMDL
   12.17  XenConfig_MakeConfigPage(PDEVICE_OBJECT device_object)
   12.18  {
   12.19 -  NTSTATUS status;
   12.20 -
   12.21    //PXENCONFIG_DEVICE_DATA xcdd = (PXENCONFIG_DEVICE_DATA)device_object->DeviceExtension;
   12.22    //PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
   12.23    //PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   12.24 -
   12.25 -  HANDLE hwkey_handle, xenkey_handle, confkey_handle;
   12.26 -  ULONG length;
   12.27 -  PKEY_BASIC_INFORMATION key_info;
   12.28 -  PKEY_VALUE_PARTIAL_INFORMATION type_info;
   12.29 -  PKEY_VALUE_PARTIAL_INFORMATION value_info;
   12.30 -  UNICODE_STRING xenkey_name, confkey_name;
   12.31 -  UNICODE_STRING type_name, value_name;
   12.32 -  UNICODE_STRING tmp_unicode_string;
   12.33 -  //UNICODE_STRING typekey_value, valuekey_value;
   12.34 -  //UNICODE_STRING value_value;
   12.35 -  OBJECT_ATTRIBUTES oa;
   12.36 -  ULONG info_length = 1000;
   12.37    PMDL mdl;
   12.38 -  UCHAR type;
   12.39 -  ANSI_STRING setting;
   12.40 -  ANSI_STRING value;
   12.41    PUCHAR ptr;
   12.42 -  int i;
   12.43 -  DECLARE_UNICODE_STRING_SIZE(service_path_xenconfig, 512);
   12.44 +  PDEVICE_OBJECT curr;
   12.45    PDRIVER_OBJECT fdo_driver_object;
   12.46    PUCHAR fdo_driver_extension;
   12.47    
   12.48    mdl = AllocateUncachedPage();
   12.49    ptr = MmGetMdlVirtualAddress(mdl);
   12.50 -
   12.51 -  fdo_driver_object = IoGetAttachedDeviceReference(device_object)->DriverObject;
   12.52 -  KdPrint((__DRIVER_NAME "     fdo_driver_object = %p\n", fdo_driver_object));
   12.53 -  if (fdo_driver_object)
   12.54 -  {
   12.55 -    fdo_driver_extension = IoGetDriverObjectExtension(fdo_driver_object, UlongToPtr(XEN_INIT_DRIVER_EXTENSION_MAGIC));
   12.56 -    KdPrint((__DRIVER_NAME "     fdo_driver_extension = %p\n", fdo_driver_extension));
   12.57 -    if (fdo_driver_extension)
   12.58 -    {
   12.59 -      memcpy(ptr, fdo_driver_extension, PAGE_SIZE);
   12.60 -      return mdl;
   12.61 -    }
   12.62 -  }
   12.63 -
   12.64 -  status = IoOpenDeviceRegistryKey(device_object, PLUGPLAY_REGKEY_DEVICE, KEY_READ, &hwkey_handle);
   12.65 -
   12.66 -  if (!NT_SUCCESS(status))
   12.67 +  curr = IoGetAttachedDeviceReference(device_object);
   12.68 +  while (curr != NULL)
   12.69    {
   12.70 -    KdPrint((__DRIVER_NAME "     cannot get device key\n"));
   12.71 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
   12.72 -    return mdl;
   12.73 -  }
   12.74 -  RtlInitUnicodeString(&xenkey_name, L"XenConfig");
   12.75 -  InitializeObjectAttributes(&oa, &xenkey_name, 0, hwkey_handle, NULL);
   12.76 -  status = ZwOpenKey(&xenkey_handle, KEY_READ, &oa);
   12.77 -  if (!NT_SUCCESS(status))
   12.78 -  {
   12.79 -    KdPrint((__DRIVER_NAME "     cannot get XenConfig key for device\n"));
   12.80 -    fdo_driver_object = IoGetAttachedDeviceReference(device_object)->DriverObject;
   12.81 +    fdo_driver_object = curr->DriverObject;
   12.82      KdPrint((__DRIVER_NAME "     fdo_driver_object = %p\n", fdo_driver_object));
   12.83 -    fdo_driver_extension = IoGetDriverObjectExtension(fdo_driver_object, UlongToPtr(666));
   12.84 -    KdPrint((__DRIVER_NAME "     fdo_driver_extension = %p\n", fdo_driver_extension));
   12.85 -    KdPrint((__DRIVER_NAME "     fdo_driver_extension = %s\n", fdo_driver_extension));
   12.86 -#if 0
   12.87 -    RtlUnicodeStringPrintf(&service_path_xenconfig, L"%wZ\\XenConfig", &service_path);
   12.88 -    KdPrint((__DRIVER_NAME "     %wZ\n", &service_path_xenconfig));
   12.89 -    InitializeObjectAttributes(&oa, &service_path_xenconfig, 0, NULL, NULL);
   12.90 -#endif
   12.91 -    
   12.92 -    KdPrint((__DRIVER_NAME "     %wZ\n", &service_path));
   12.93 -    InitializeObjectAttributes(&oa, &service_path, 0, NULL, NULL);
   12.94 -    status = ZwOpenKey(&xenkey_handle, KEY_READ, &oa);
   12.95 -    if (!NT_SUCCESS(status))
   12.96 +    if (fdo_driver_object)
   12.97      {
   12.98 -      // close key_handle
   12.99 -      KdPrint((__DRIVER_NAME "    cannot get XenConfig for service (%08x)\n"));
  12.100 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
  12.101 -      return mdl;
  12.102 -    }
  12.103 -/*
  12.104 -    RtlInitUnicodeString(&xenkey_name, L"XenConfig");
  12.105 -    InitializeObjectAttributes(&oa, &xenkey_name, 0, service_handle, NULL);
  12.106 -    status = ZwOpenKey(&xenkey_handle, KEY_READ, &oa);
  12.107 -    if (!NT_SUCCESS(status))
  12.108 -    {    
  12.109 -      KdPrint((__DRIVER_NAME "    cannot get XenConfig key for driver\n"));
  12.110 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);          
  12.111 -      return mdl;
  12.112 -    }
  12.113 -*/
  12.114 -  }
  12.115 -  // XenConfig key exists, so we go ahead and make fake memory resources
  12.116 -  RtlInitUnicodeString(&type_name, L"type");
  12.117 -  RtlInitUnicodeString(&value_name, L"value");
  12.118 -  key_info = ExAllocatePoolWithTag(PagedPool, info_length, XENPCI_POOL_TAG);
  12.119 -  type_info = ExAllocatePoolWithTag(PagedPool, info_length, XENPCI_POOL_TAG);
  12.120 -  value_info = ExAllocatePoolWithTag(PagedPool, info_length, XENPCI_POOL_TAG);
  12.121 -  //value.Buffer = ExAllocatePoolWithTag(PagedPool, info_length, XENPCI_POOL_TAG);
  12.122 -  //value.MaximumLength = info_length;
  12.123 -  setting.Buffer = ExAllocatePoolWithTag(PagedPool, info_length, XENPCI_POOL_TAG);
  12.124 -  setting.MaximumLength = (USHORT)info_length;
  12.125 -  
  12.126 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RUN, NULL, NULL);
  12.127 -  for (i = 0; ZwEnumerateKey(xenkey_handle, i, KeyBasicInformation, key_info, info_length, &length) == STATUS_SUCCESS; i++)
  12.128 -  {
  12.129 -    confkey_name.Length = (USHORT)key_info->NameLength;
  12.130 -    confkey_name.MaximumLength = (USHORT)key_info->NameLength;
  12.131 -    confkey_name.Buffer = key_info->Name;
  12.132 -    RtlUnicodeStringToAnsiString(&setting, &confkey_name, FALSE);
  12.133 -    setting.Buffer[setting.Length] = 0;
  12.134 -    KdPrint((__DRIVER_NAME "     config key name = '%wZ'\n", &confkey_name));
  12.135 -    InitializeObjectAttributes(&oa, &confkey_name, 0, xenkey_handle, NULL);
  12.136 -    status = ZwOpenKey(&confkey_handle, KEY_READ, &oa);
  12.137 -    if (!NT_SUCCESS(status))
  12.138 -    {
  12.139 -      KdPrint((__DRIVER_NAME "    cannot get handle for XenConfig\\%wZ\n", &confkey_name));
  12.140 -      continue;
  12.141 -    }
  12.142 -    
  12.143 -    status = ZwQueryValueKey(confkey_handle, &type_name, KeyValuePartialInformation, type_info, info_length, &length);
  12.144 -    // make sure type is dword
  12.145 -    type = (UCHAR)*(ULONG *)type_info->Data;
  12.146 -    status = ZwQueryValueKey(confkey_handle, &value_name, KeyValuePartialInformation, value_info, info_length, &length);
  12.147 -    if (!NT_SUCCESS(status))
  12.148 -    {
  12.149 -      ADD_XEN_INIT_REQ(&ptr, type, setting.Buffer, NULL);
  12.150 -    }
  12.151 -    else
  12.152 -    {
  12.153 -      switch(value_info->Type)
  12.154 +      fdo_driver_extension = IoGetDriverObjectExtension(fdo_driver_object, UlongToPtr(XEN_INIT_DRIVER_EXTENSION_MAGIC));
  12.155 +      KdPrint((__DRIVER_NAME "     fdo_driver_extension = %p\n", fdo_driver_extension));
  12.156 +      if (fdo_driver_extension)
  12.157        {
  12.158 -      case REG_DWORD:
  12.159 -        ADD_XEN_INIT_REQ(&ptr, type, setting.Buffer, UlongToPtr(*(PULONG)value_info->Data));
  12.160 -        break;
  12.161 -        
  12.162 -      case REG_SZ:
  12.163 -        tmp_unicode_string.Length = (USHORT)value_info->DataLength;
  12.164 -        tmp_unicode_string.MaximumLength = (USHORT)value_info->DataLength;
  12.165 -        tmp_unicode_string.Buffer = (PWCHAR)value_info->Data;
  12.166 -        RtlUnicodeStringToAnsiString(&value, &tmp_unicode_string, FALSE);
  12.167 -        value.Buffer[value.Length] = 0;
  12.168 -        ADD_XEN_INIT_REQ(&ptr, type, setting.Buffer, value.Buffer);
  12.169 -        break;
  12.170 -      
  12.171 -      default:
  12.172 -        // report error here
  12.173 +        memcpy(ptr, fdo_driver_extension, PAGE_SIZE);
  12.174          break;
  12.175        }
  12.176      }
  12.177 +    curr = IoGetLowerDeviceObject(curr);
  12.178    }
  12.179 -  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);          
  12.180 -
  12.181 -  ExFreePoolWithTag(key_info, XENPCI_POOL_TAG);
  12.182 -
  12.183    return mdl;
  12.184  }
  12.185 -#if 0
  12.186 -static NTSTATUS
  12.187 -XenConfig_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
  12.188 -{
  12.189 -  PIO_STACK_LOCATION stack;
  12.190 -  PMDL mdl;
  12.191 -  PCM_RESOURCE_LIST old_crl, new_crl;
  12.192 -  PCM_PARTIAL_RESOURCE_LIST prl;
  12.193 -  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
  12.194 -  ULONG old_length, new_length;
  12.195 -
  12.196 -  UNREFERENCED_PARAMETER(device_object);
  12.197 -
  12.198 -  FUNCTION_ENTER();
  12.199 -
  12.200 -  stack = IoGetCurrentIrpStackLocation(irp);
  12.201 -
  12.202 -  if ((mdl = XenConfig_MakeConfigPage(device_object)) != NULL)
  12.203 -  {
  12.204 -    old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
  12.205 -    old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
  12.206 -      FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
  12.207 -      FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
  12.208 -      sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
  12.209 -    new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
  12.210 -    new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENPCI_POOL_TAG);
  12.211 -    memcpy(new_crl, old_crl, old_length);
  12.212 -    prl = &new_crl->List[0].PartialResourceList;
  12.213 -    prd = &prl->PartialDescriptors[prl->Count++];
  12.214 -    prd->Type = CmResourceTypeMemory;
  12.215 -    prd->ShareDisposition = CmResourceShareDeviceExclusive;
  12.216 -    prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
  12.217 -    KdPrint((__DRIVER_NAME "     PFN[0] = %p\n", MmGetMdlPfnArray(mdl)[0]));
  12.218 -    prd->u.Memory.Start.QuadPart = ((ULONGLONG)MmGetMdlPfnArray(mdl)[0]) << PAGE_SHIFT;
  12.219 -    prd->u.Memory.Length = PAGE_SIZE;
  12.220 -    KdPrint((__DRIVER_NAME "     Start = %08x:%08x, Length = %d\n", prd->u.Memory.Start.HighPart, prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
  12.221 -    stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
  12.222 -
  12.223 -    old_crl = stack->Parameters.StartDevice.AllocatedResources;
  12.224 -    new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENPCI_POOL_TAG);
  12.225 -    memcpy(new_crl, old_crl, old_length);
  12.226 -    prl = &new_crl->List[0].PartialResourceList;
  12.227 -    prd = &prl->PartialDescriptors[prl->Count++];
  12.228 -    prd->Type = CmResourceTypeMemory;
  12.229 -    prd->ShareDisposition = CmResourceShareDeviceExclusive;
  12.230 -    prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
  12.231 -    prd->u.Memory.Start.QuadPart = (ULONGLONG)MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
  12.232 -    prd->u.Memory.Length = PAGE_SIZE;
  12.233 -    stack->Parameters.StartDevice.AllocatedResources = new_crl;
  12.234 -
  12.235 -    // free the original resource lists???
  12.236 -  }
  12.237 -
  12.238 -  FUNCTION_EXIT();
  12.239 -  
  12.240 -  return STATUS_PENDING;
  12.241 -}
  12.242 -#endif
  12.243  
  12.244  static NTSTATUS
  12.245  XenPci_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
  12.246 @@ -1179,6 +998,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  12.247    PMDL mdl;
  12.248   
  12.249    FUNCTION_ENTER();
  12.250 +  KdPrint((__DRIVER_NAME "     %s\n", xppdd->path));
  12.251  
  12.252    DUMP_CURRENT_PNP_STATE(xppdd);
  12.253    
  12.254 @@ -1206,7 +1026,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  12.255        //xppdd->irq_level = (KIRQL)prd->u.Interrupt.Level;
  12.256        break;
  12.257      case CmResourceTypeMemory:
  12.258 -      if (prd->u.Memory.Length == 0)
  12.259 +      if (prd->u.Memory.Start.QuadPart == xpdd->platform_mmio_addr.QuadPart && prd->u.Memory.Length == 0)
  12.260        {
  12.261          prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
  12.262          prd->u.Memory.Length = MmGetMdlByteCount(mdl);
  12.263 @@ -1222,32 +1042,36 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  12.264      switch (prd->Type)
  12.265      {
  12.266      case CmResourceTypeInterrupt:
  12.267 -      KdPrint((__DRIVER_NAME "     CmResourceTypeInterrupt\n"));
  12.268 +      KdPrint((__DRIVER_NAME "     CmResourceTypeInterrupt (%d)\n", i));
  12.269        KdPrint((__DRIVER_NAME "     irq_vector = %02x\n", prd->u.Interrupt.Vector));
  12.270        KdPrint((__DRIVER_NAME "     irq_level = %d\n", prd->u.Interrupt.Level));
  12.271        xppdd->irq_vector = prd->u.Interrupt.Vector;
  12.272        xppdd->irq_level = (KIRQL)prd->u.Interrupt.Level;
  12.273        break;
  12.274      case CmResourceTypeMemory:
  12.275 -      if (prd->u.Memory.Length == 0)
  12.276 -      {
  12.277 -        prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
  12.278 -        prd->u.Memory.Length = MmGetMdlByteCount(mdl);
  12.279 -      }
  12.280 -      KdPrint((__DRIVER_NAME "     CmResourceTypeMemory\n"));
  12.281 +      KdPrint((__DRIVER_NAME "     CmResourceTypeMemory (%d)\n", i));
  12.282        KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
  12.283 -      xppdd->config_page_phys = prd->u.Memory.Start;
  12.284 -      xppdd->config_page_length = prd->u.Memory.Length;
  12.285 -      xppdd->requested_resources_start = xppdd->requested_resources_ptr = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
  12.286 -      xppdd->assigned_resources_start = xppdd->assigned_resources_ptr = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
  12.287 -      
  12.288 -      status = XenPci_XenConfigDevice(xppdd);
  12.289 -      if (!NT_SUCCESS(status))
  12.290 +      if (prd->u.Memory.Start.QuadPart == xpdd->platform_mmio_addr.QuadPart)
  12.291        {
  12.292 -        RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  12.293 -        XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  12.294 -        FUNCTION_ERROR_EXIT();
  12.295 -        return status;
  12.296 +        if (prd->u.Memory.Length == 0)
  12.297 +        {
  12.298 +          prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
  12.299 +          prd->u.Memory.Length = MmGetMdlByteCount(mdl);
  12.300 +          KdPrint((__DRIVER_NAME "     New Start = %08x, Length = %d\n", prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
  12.301 +        }
  12.302 +        xppdd->config_page_phys = prd->u.Memory.Start;
  12.303 +        xppdd->config_page_length = prd->u.Memory.Length;
  12.304 +        xppdd->requested_resources_start = xppdd->requested_resources_ptr = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
  12.305 +        xppdd->assigned_resources_start = xppdd->assigned_resources_ptr = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
  12.306 +        
  12.307 +        status = XenPci_XenConfigDevice(xppdd);
  12.308 +        if (!NT_SUCCESS(status))
  12.309 +        {
  12.310 +          RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  12.311 +          XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  12.312 +          FUNCTION_ERROR_EXIT();
  12.313 +          return status;
  12.314 +        }
  12.315        }
  12.316        break;
  12.317      }
    13.1 --- a/xenscsi/xenscsi.c	Tue Dec 09 20:30:26 2008 +1100
    13.2 +++ b/xenscsi/xenscsi.c	Mon Dec 15 19:17:13 2008 +1100
    13.3 @@ -28,7 +28,6 @@ DRIVER_INITIALIZE DriverEntry;
    13.4  #pragma warning(disable: 4127)
    13.5  
    13.6  static BOOLEAN dump_mode = FALSE;
    13.7 -static BOOLEAN global_inactive = FALSE;
    13.8  
    13.9  static vscsiif_shadow_t *
   13.10  get_shadow_from_freelist(PXENSCSI_DEVICE_DATA xsdd)
   13.11 @@ -80,8 +79,6 @@ XenScsi_HwScsiInterrupt(PVOID DeviceExte
   13.12    int more_to_do = TRUE;
   13.13    vscsiif_shadow_t *shadow;
   13.14  
   13.15 -  //FUNCTION_ENTER();
   13.16 -
   13.17    if (xsdd->pause_ack != xsdd->pause_req)
   13.18    {
   13.19      xsdd->pause_ack = xsdd->pause_req;
   13.20 @@ -92,7 +89,11 @@ XenScsi_HwScsiInterrupt(PVOID DeviceExte
   13.21      }
   13.22    }
   13.23    if (!dump_mode && !xsdd->vectors.EvtChn_AckEvent(xsdd->vectors.context, xsdd->event_channel))
   13.24 +  {
   13.25      return FALSE;
   13.26 +  }
   13.27 +
   13.28 +  //FUNCTION_ENTER();
   13.29    
   13.30    while (more_to_do)
   13.31    {
   13.32 @@ -104,10 +105,6 @@ XenScsi_HwScsiInterrupt(PVOID DeviceExte
   13.33        shadow = &xsdd->shadows[rep->rqid];
   13.34        Srb = shadow->Srb;
   13.35        Srb->ScsiStatus = (UCHAR)rep->rslt;
   13.36 -/*
   13.37 -      for (j = 0; j < Srb->SenseInfoBufferLength; j++)
   13.38 -        KdPrint((__DRIVER_NAME "     sense before %02x: %02x\n", j, (ULONG)((PUCHAR)Srb->SenseInfoBuffer)[j]));
   13.39 -*/
   13.40        memset(Srb->SenseInfoBuffer, 0, Srb->SenseInfoBufferLength);
   13.41        if (rep->sense_len > 0 && Srb->SenseInfoBuffer != NULL)
   13.42        {
   13.43 @@ -118,24 +115,42 @@ XenScsi_HwScsiInterrupt(PVOID DeviceExte
   13.44        case 0:
   13.45          //KdPrint((__DRIVER_NAME "     Xen Operation complete - result = 0x%08x, sense_len = %d, residual = %d\n", rep->rslt, rep->sense_len, rep->residual_len));
   13.46          Srb->SrbStatus = SRB_STATUS_SUCCESS;
   13.47 +        if (Srb->Cdb[0] == 0x03)
   13.48 +        {
   13.49 +          KdPrint((__DRIVER_NAME "     REQUEST_SENSE DataTransferLength = %d, residual = %d\n", Srb->DataTransferLength, rep->residual_len));
   13.50 +          //for (j = 0; j < Srb->DataTransferLength - rep->residual_len; j++)
   13.51 +          //  KdPrint((__DRIVER_NAME "     sense %02x: %02x\n", j, (ULONG)((PUCHAR)Srb->DataBuffer)[j]));
   13.52 +        }
   13.53          break;
   13.54        case 0x00010000: /* Device does not exist */
   13.55 -        KdPrint((__DRIVER_NAME "     Xen Operation error - result = 0x%08x, sense_len = %d, residual = %d\n", rep->rslt, rep->sense_len, rep->residual_len));
   13.56 +        KdPrint((__DRIVER_NAME "     Xen Operation error - cdb[0] = %02x, result = 0x%08x, sense_len = %d, residual = %d\n", (ULONG)Srb->Cdb[0], rep->rslt, rep->sense_len, rep->residual_len));
   13.57          Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
   13.58          break;
   13.59        default:
   13.60 -        KdPrint((__DRIVER_NAME "     Xen Operation error - result = 0x%08x, sense_len = %d, residual = %d\n", rep->rslt, rep->sense_len, rep->residual_len));
   13.61 +        KdPrint((__DRIVER_NAME "     Xen Operation error - cdb[0] = %02x, result = 0x%08x, sense_len = %d, residual = %d\n", (ULONG)Srb->Cdb[0], rep->rslt, rep->sense_len, rep->residual_len));
   13.62          Srb->SrbStatus = SRB_STATUS_ERROR;
   13.63 +
   13.64 +        //for (j = 0; j < Srb->SenseInfoBufferLength; j++)
   13.65 +        //  KdPrint((__DRIVER_NAME "     sense %02x: %02x\n", j, (ULONG)((PUCHAR)Srb->SenseInfoBuffer)[j]));
   13.66 +
   13.67          if (rep->sense_len > 0 && !(Srb->SrbFlags & SRB_FLAGS_DISABLE_AUTOSENSE) && Srb->SenseInfoBuffer != NULL)
   13.68          {
   13.69            KdPrint((__DRIVER_NAME "     Doing autosense\n"));
   13.70            Srb->SrbStatus |= SRB_STATUS_AUTOSENSE_VALID;
   13.71          }
   13.72 +        else if (Srb->SrbFlags & SRB_FLAGS_DISABLE_AUTOSENSE)
   13.73 +        {
   13.74 +          PXENSCSI_LU_DATA lud = ScsiPortGetLogicalUnit(DeviceExtension, Srb->PathId, Srb->TargetId, Srb->Lun);
   13.75 +          KdPrint((__DRIVER_NAME "     Autosense disabled\n"));
   13.76 +          if (lud != NULL)
   13.77 +          {
   13.78 +            KdPrint((__DRIVER_NAME "     Saving sense data\n"));
   13.79 +            lud->sense_len = rep->sense_len;
   13.80 +            memcpy(lud->sense_buffer, Srb->SenseInfoBuffer, lud->sense_len);
   13.81 +          }
   13.82 +        }
   13.83        }
   13.84 -/*
   13.85 -      for (j = 0; j < Srb->SenseInfoBufferLength; j++)
   13.86 -        KdPrint((__DRIVER_NAME "     sense after %02x: %02x\n", j, (ULONG)((PUCHAR)Srb->SenseInfoBuffer)[j]));
   13.87 -*/
   13.88 +
   13.89        /* work around a bug in scsiback that gives an incorrect result to REPORT_LUNS - fail it if the output is only 8 bytes */
   13.90        if (Srb->Cdb[0] == 0xa0 && Srb->SrbStatus == SRB_STATUS_SUCCESS &&
   13.91          Srb->DataTransferLength - rep->residual_len == 8)
   13.92 @@ -391,11 +406,10 @@ XenScsi_HwScsiFindAdapter(PVOID DeviceEx
   13.93      return SP_RETURN_BAD_CONFIG;
   13.94    }
   13.95  
   13.96 +  ptr = NULL;
   13.97    access_range = &((*(ConfigInfo->AccessRanges))[0]);
   13.98 -
   13.99    KdPrint((__DRIVER_NAME "     RangeStart = %08x, RangeLength = %08x\n",
  13.100      access_range->RangeStart.LowPart, access_range->RangeLength));
  13.101 -
  13.102    ptr = ScsiPortGetDeviceBase(
  13.103      DeviceExtension,
  13.104      ConfigInfo->AdapterInterfaceType,
  13.105 @@ -403,13 +417,12 @@ XenScsi_HwScsiFindAdapter(PVOID DeviceEx
  13.106      access_range->RangeStart,
  13.107      access_range->RangeLength,
  13.108      !access_range->RangeInMemory);
  13.109 -  if (ptr == NULL)
  13.110 +  if (!ptr)
  13.111    {
  13.112      KdPrint((__DRIVER_NAME "     Unable to map range\n"));
  13.113      KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
  13.114      return SP_RETURN_BAD_CONFIG;
  13.115    }
  13.116 -
  13.117    sring = NULL;
  13.118    xsdd->event_channel = 0;
  13.119    while((type = GET_XEN_INIT_RSP(&ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  13.120 @@ -471,8 +484,8 @@ XenScsi_HwScsiFindAdapter(PVOID DeviceEx
  13.121    }
  13.122  #endif
  13.123    
  13.124 -  ConfigInfo->ScatterGather = FALSE;
  13.125 -  ConfigInfo->NumberOfPhysicalBreaks = 0; //VSCSIIF_SG_TABLESIZE - 1;
  13.126 +  ConfigInfo->ScatterGather = TRUE;
  13.127 +  ConfigInfo->NumberOfPhysicalBreaks = VSCSIIF_SG_TABLESIZE - 1;
  13.128    ConfigInfo->MaximumTransferLength = VSCSIIF_SG_TABLESIZE * PAGE_SIZE;
  13.129    ConfigInfo->CachesData = FALSE;
  13.130    ConfigInfo->NumberOfBuses = 4; //SCSI_MAXIMUM_BUSES; //8
  13.131 @@ -574,13 +587,6 @@ XenScsi_PutSrbOnRing(PXENSCSI_DEVICE_DAT
  13.132      shadow->req.sc_data_direction = DMA_NONE;
  13.133    }
  13.134  
  13.135 -/*  
  13.136 -  for (i = 0; i < Srb->CdbLength; i++)
  13.137 -  {
  13.138 -    KdPrint((__DRIVER_NAME "     Cdb[%02x] = %02x\n", i, (ULONG)Srb->Cdb[i]));
  13.139 -  }
  13.140 -*/
  13.141 -
  13.142    remaining = Srb->DataTransferLength;
  13.143    shadow->req.seg[0].offset = 0;
  13.144    shadow->req.seg[0].length = 0;
  13.145 @@ -661,8 +667,42 @@ XenScsi_HwScsiStartIo(PVOID DeviceExtens
  13.146    switch (Srb->Function)
  13.147    {
  13.148    case SRB_FUNCTION_EXECUTE_SCSI:
  13.149 -    XenScsi_PutSrbOnRing(xsdd, Srb);
  13.150 -    Srb->SrbStatus = SRB_STATUS_PENDING;
  13.151 +    switch (Srb->Cdb[0])
  13.152 +    {
  13.153 +    case 0x03: { /* REQUEST_SENSE*/
  13.154 +      /* but what about when we allow multiple requests per lu? */
  13.155 +      PXENSCSI_LU_DATA lud = ScsiPortGetLogicalUnit(DeviceExtension, Srb->PathId, Srb->TargetId, Srb->Lun);
  13.156 +      if (lud != NULL && lud->sense_len)
  13.157 +      {
  13.158 +        KdPrint((__DRIVER_NAME "     Emulating REQUEST_SENSE (lu data = %p)\n", lud));
  13.159 +        memcpy(Srb->DataBuffer, lud->sense_buffer, min(lud->sense_len, Srb->DataTransferLength));
  13.160 +        if (lud->sense_len < Srb->DataTransferLength)
  13.161 +        {
  13.162 +          Srb->DataTransferLength = lud->sense_len;
  13.163 +          Srb->SrbStatus = SRB_STATUS_DATA_OVERRUN;
  13.164 +        }
  13.165 +        else
  13.166 +        {
  13.167 +          Srb->SrbStatus = SRB_STATUS_SUCCESS;
  13.168 +        }
  13.169 +        //for (i = 0; i < Srb->DataTransferLength; i++)
  13.170 +        //  KdPrint((__DRIVER_NAME "     sense %02x: %02x\n", i, (ULONG)((PUCHAR)Srb->DataBuffer)[i]));
  13.171 +        lud->sense_len = 0;
  13.172 +        ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  13.173 +        ScsiPortNotification(NextRequest, DeviceExtension);
  13.174 +        break;
  13.175 +      }
  13.176 +      else
  13.177 +      {
  13.178 +        KdPrint((__DRIVER_NAME "     Issuing REQUEST_SENSE (lud = %p)\n", lud));
  13.179 +      }
  13.180 +      // fall through
  13.181 +    }
  13.182 +    default:
  13.183 +      XenScsi_PutSrbOnRing(xsdd, Srb);
  13.184 +      Srb->SrbStatus = SRB_STATUS_PENDING;
  13.185 +      break;
  13.186 +    }
  13.187      break;
  13.188    case SRB_FUNCTION_IO_CONTROL:
  13.189      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
  13.190 @@ -776,11 +816,11 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  13.191    HwInitializationData.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA);
  13.192    HwInitializationData.AdapterInterfaceType = Internal;
  13.193    HwInitializationData.DeviceExtensionSize = sizeof(XENSCSI_DEVICE_DATA);
  13.194 -  HwInitializationData.SpecificLuExtensionSize = 0;
  13.195 +  HwInitializationData.SpecificLuExtensionSize = sizeof(XENSCSI_LU_DATA);
  13.196    HwInitializationData.SrbExtensionSize = 0;
  13.197    HwInitializationData.NumberOfAccessRanges = 1;
  13.198 -  HwInitializationData.MapBuffers = FALSE;
  13.199 -  HwInitializationData.NeedPhysicalAddresses = TRUE;
  13.200 +  HwInitializationData.MapBuffers = TRUE;
  13.201 +  HwInitializationData.NeedPhysicalAddresses = FALSE;
  13.202    HwInitializationData.TaggedQueuing = TRUE;
  13.203    HwInitializationData.AutoRequestSense = TRUE;
  13.204    HwInitializationData.MultipleRequestPerLu = TRUE;
    14.1 --- a/xenscsi/xenscsi.h	Tue Dec 09 20:30:26 2008 +1100
    14.2 +++ b/xenscsi/xenscsi.h	Mon Dec 15 19:17:13 2008 +1100
    14.3 @@ -92,6 +92,11 @@ struct
    14.4    BOOLEAN pause_ack;
    14.5  } typedef XENSCSI_DEVICE_DATA, *PXENSCSI_DEVICE_DATA;
    14.6  
    14.7 +struct {
    14.8 +  UCHAR sense_len;
    14.9 +  UCHAR sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
   14.10 +} typedef XENSCSI_LU_DATA, *PXENSCSI_LU_DATA;
   14.11 +
   14.12  enum dma_data_direction {
   14.13          DMA_BIDIRECTIONAL = 0,
   14.14          DMA_TO_DEVICE = 1,
    15.1 --- a/xenvbd/xenvbd.c	Tue Dec 09 20:30:26 2008 +1100
    15.2 +++ b/xenvbd/xenvbd.c	Mon Dec 15 19:17:13 2008 +1100
    15.3 @@ -42,7 +42,6 @@ DRIVER_INITIALIZE DriverEntry;
    15.4  #endif
    15.5  
    15.6  static BOOLEAN dump_mode = FALSE;
    15.7 -static BOOLEAN global_inactive = FALSE;
    15.8  
    15.9  static blkif_shadow_t *
   15.10  get_shadow_from_freelist(PXENVBD_DEVICE_DATA xvdd)
   15.11 @@ -139,7 +138,8 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
   15.12    xvdd->device_type = XENVBD_DEVICETYPE_UNKNOWN;
   15.13    xvdd->sring = NULL;
   15.14    xvdd->event_channel = 0;
   15.15 -  
   15.16 +
   15.17 +  xvdd->inactive = TRUE;  
   15.18    ptr = xvdd->device_base;
   15.19    while((type = GET_XEN_INIT_RSP(&ptr, (PVOID) &setting, (PVOID) &value)) != XEN_INIT_TYPE_END)
   15.20    {
   15.21 @@ -255,6 +255,9 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
   15.22        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
   15.23        xvdd->device_state = (PXENPCI_DEVICE_STATE)value;
   15.24        break;
   15.25 +    case XEN_INIT_TYPE_ACTIVE:
   15.26 +      xvdd->inactive = FALSE;
   15.27 +      break;
   15.28      default:
   15.29        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   15.30        break;
   15.31 @@ -270,6 +273,9 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
   15.32      KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   15.33      return SP_RETURN_BAD_CONFIG;
   15.34    }
   15.35 +  if (xvdd->inactive)
   15.36 +    KdPrint((__DRIVER_NAME "     Device is inactive\n"));
   15.37 +  
   15.38    if (xvdd->device_type == XENVBD_DEVICETYPE_CDROM)
   15.39    {
   15.40      /* CD/DVD drives must have bytes_per_sector = 2048. */
   15.41 @@ -412,7 +418,7 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   15.42    if (PtrToUlong(srb->DataBuffer) & 511) /* use SrbExtension intead of DataBuffer if DataBuffer is not aligned to sector size */
   15.43    {
   15.44      shadow->req.sector_number += srb_offset / 512; //xvdd->bytes_per_sector;
   15.45 -    //KdPrint((__DRIVER_NAME "     Using unaligned buffer - DataBuffer = %p, SrbExtension = %p, total length = %d, offset = %d, length = %d, sector = %d\n", srb->DataBuffer, srb->SrbExtension, block_count * 512, shadow->offset, shadow->length, shadow->req.sector_number));
   15.46 +    //KdPrint((__DRIVER_NAME "     Using unaligned buffer - DataBuffer = %p, SrbExtension = %p, total length = %d, offset = %d, length = %d, sector = %d\n", srb->DataBuffer, srb->SrbExtension, block_count * 512, shadow->offset, shadow->length, (ULONG)shadow->req.sector_number));
   15.47      if (srb->Cdb[0] == SCSIOP_WRITE)
   15.48      {
   15.49        memcpy(ptr, ((PUCHAR)srb->DataBuffer) + srb_offset, shadow->length);
   15.50 @@ -526,7 +532,6 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
   15.51    ULONG status;
   15.52  //  PXENPCI_XEN_DEVICE_DATA XenDeviceData;
   15.53    PACCESS_RANGE access_range;
   15.54 -  ULONG i;
   15.55  
   15.56    UNREFERENCED_PARAMETER(HwContext);
   15.57    UNREFERENCED_PARAMETER(BusInformation);
   15.58 @@ -540,42 +545,22 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
   15.59    KdPrint((__DRIVER_NAME "     BusInterruptLevel = %d\n", ConfigInfo->BusInterruptLevel));
   15.60    KdPrint((__DRIVER_NAME "     BusInterruptVector = %03x\n", ConfigInfo->BusInterruptVector));
   15.61  
   15.62 +  KdPrint((__DRIVER_NAME "     NumberOfAccessRanges = %d\n", ConfigInfo->NumberOfAccessRanges));    
   15.63    if (ConfigInfo->NumberOfAccessRanges != 1 && ConfigInfo->NumberOfAccessRanges != 2)
   15.64    {
   15.65 -    KdPrint((__DRIVER_NAME "     NumberOfAccessRanges = %d\n", ConfigInfo->NumberOfAccessRanges));    
   15.66      return SP_RETURN_BAD_CONFIG;
   15.67    }
   15.68  
   15.69 -  xvdd->inactive = global_inactive;
   15.70 -  
   15.71 -  for (i = 0; i < ConfigInfo->NumberOfAccessRanges; i++)
   15.72 -  {
   15.73 -    access_range = &((*(ConfigInfo->AccessRanges))[i]);
   15.74 -    if (access_range->RangeStart.QuadPart)
   15.75 -    {
   15.76 -      KdPrint((__DRIVER_NAME "     RangeStart = %08x, RangeLength = %08x\n",
   15.77 -        access_range->RangeStart.LowPart, access_range->RangeLength));
   15.78 -
   15.79 -      xvdd->device_base = ScsiPortGetDeviceBase(
   15.80 -        DeviceExtension,
   15.81 -        ConfigInfo->AdapterInterfaceType,
   15.82 -        ConfigInfo->SystemIoBusNumber,
   15.83 -        access_range->RangeStart,
   15.84 -        access_range->RangeLength,
   15.85 -        !access_range->RangeInMemory);
   15.86 -      if (xvdd->device_base == NULL)
   15.87 -      {
   15.88 -        KdPrint((__DRIVER_NAME "     Unable to map range\n"));
   15.89 -        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
   15.90 -        return SP_RETURN_BAD_CONFIG;
   15.91 -      }
   15.92 -    }
   15.93 -    else
   15.94 -    {
   15.95 -      xvdd->inactive = TRUE;
   15.96 -    }
   15.97 -  }
   15.98 -
   15.99 +  access_range = &((*(ConfigInfo->AccessRanges))[0]);
  15.100 +  KdPrint((__DRIVER_NAME "     RangeStart = %08x, RangeLength = %08x\n",
  15.101 +    access_range->RangeStart.LowPart, access_range->RangeLength));
  15.102 +  xvdd->device_base = ScsiPortGetDeviceBase(
  15.103 +    DeviceExtension,
  15.104 +    ConfigInfo->AdapterInterfaceType,
  15.105 +    ConfigInfo->SystemIoBusNumber,
  15.106 +    access_range->RangeStart,
  15.107 +    access_range->RangeLength,
  15.108 +    !access_range->RangeInMemory);
  15.109    if (!xvdd->device_base)
  15.110    {
  15.111      KdPrint((__DRIVER_NAME "     Invalid config\n"));
  15.112 @@ -891,8 +876,8 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
  15.113            if (srb->Cdb[0] == SCSIOP_READ)
  15.114              KdPrint((__DRIVER_NAME "     Operation = Read\n"));
  15.115            else
  15.116 -            KdPrint((__DRIVER_NAME "     Operation = Write\n"));     
  15.117 -          KdPrint((__DRIVER_NAME "     Sector = %08X, Count = %d\n", shadow->req.sector_number, block_count));
  15.118 +            KdPrint((__DRIVER_NAME "     Operation = Write\n"));
  15.119 +          KdPrint((__DRIVER_NAME "     Sector = %08X, Count = %d\n", (ULONG)shadow->req.sector_number, block_count));
  15.120            srb->SrbStatus = SRB_STATUS_ERROR;
  15.121            srb->ScsiStatus = 0x02;
  15.122            xvdd->last_sense_key = SCSI_SENSE_MEDIUM_ERROR;
  15.123 @@ -917,7 +902,7 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
  15.124              memcpy(((PUCHAR)srb->DataBuffer) + shadow->offset, GET_PAGE_ALIGNED(srb->SrbExtension), shadow->length);
  15.125            offset = shadow->offset + shadow->length;
  15.126            put_shadow_on_freelist(xvdd, shadow);
  15.127 -          if (offset == block_count * xvdd->bytes_per_sector)
  15.128 +          if (offset == block_count * 512)
  15.129            {
  15.130              ScsiPortNotification(RequestComplete, xvdd, srb);
  15.131              stat_outstanding_requests--;
  15.132 @@ -980,6 +965,8 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  15.133    if (xvdd->inactive)
  15.134    {
  15.135      Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
  15.136 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  15.137 +    ScsiPortNotification(NextRequest, DeviceExtension);
  15.138      return TRUE;
  15.139    }
  15.140    
  15.141 @@ -1367,12 +1354,12 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  15.142  {
  15.143    ULONG status;
  15.144    HW_INITIALIZATION_DATA HwInitializationData;
  15.145 -  PCONFIGURATION_INFORMATION conf_info;
  15.146    PVOID driver_extension;
  15.147    PUCHAR ptr;
  15.148  
  15.149    FUNCTION_ENTER();
  15.150    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  15.151 +  KdPrint((__DRIVER_NAME "     DriverObject = %p\n", DriverObject));
  15.152  
  15.153    IoAllocateDriverObjectExtension(DriverObject, UlongToPtr(XEN_INIT_DRIVER_EXTENSION_MAGIC), PAGE_SIZE, &driver_extension);
  15.154    ptr = driver_extension;
  15.155 @@ -1391,23 +1378,6 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  15.156    {
  15.157      dump_mode = TRUE;
  15.158    }
  15.159 -  else
  15.160 -  {
  15.161 -    conf_info = IoGetConfigurationInformation();
  15.162 -    if (conf_info == NULL)
  15.163 -    {
  15.164 -      KdPrint((__DRIVER_NAME "     conf_info == NULL\n"));
  15.165 -    }
  15.166 -    else
  15.167 -    {
  15.168 -      KdPrint((__DRIVER_NAME "     conf_info->DiskCount = %d\n", conf_info->DiskCount));
  15.169 -    }
  15.170 -    if (conf_info != NULL && conf_info->DiskCount && RegistryPath)
  15.171 -    {
  15.172 -      global_inactive = TRUE;
  15.173 -      KdPrint((__DRIVER_NAME "     Not loaded at boot time so setting inactive\n"));
  15.174 -    }
  15.175 -  }
  15.176    RtlZeroMemory(&HwInitializationData, sizeof(HW_INITIALIZATION_DATA));
  15.177  
  15.178    HwInitializationData.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA);