win-pvdrivers

changeset 269:6128d5c1e7a8 wdm

vbd is now working. w00t.
author James Harper <james.harper@bendigoit.com.au>
date Wed May 14 11:45:39 2008 +1000 (2008-05-14)
parents f28ce60f3fa7
children 1c1ae7c8a41f
files common.inc common/include/xen_public.h xenhide/xenhide.c xenhide/xenhide.h xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci_fdo.c xenpci/xenpci_pdo.c xenvbd/xenvbd.c
line diff
     1.1 --- a/common.inc	Tue May 13 00:02:24 2008 +1000
     1.2 +++ b/common.inc	Wed May 14 11:45:39 2008 +1000
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.8.9.42
     1.5 +VERSION=0.8.9.45
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  KMDF_VERSION=1
     1.8  !IF $(_NT_TOOLS_VERSION) > 0x700
     2.1 --- a/common/include/xen_public.h	Tue May 13 00:02:24 2008 +1000
     2.2 +++ b/common/include/xen_public.h	Wed May 14 11:45:39 2008 +1000
     2.3 @@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  #if !defined(_XEN_PUBLIC_H_)
     2.5  #define _XEN_PUBLIC_H_
     2.6  
     2.7 +#include <xen_guids.h>
     2.8  //{5C568AC5-9DDF-4FA5-A94A-39D67077819C}
     2.9  DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
    2.10  
     3.1 --- a/xenhide/xenhide.c	Tue May 13 00:02:24 2008 +1000
     3.2 +++ b/xenhide/xenhide.c	Wed May 14 11:45:39 2008 +1000
     3.3 @@ -37,7 +37,7 @@ XenHide_AddDevice();
     3.4  #pragma alloc_text (PAGE, XenHide_AddDevice)
     3.5  #endif
     3.6  
     3.7 -static BOOLEAN AutoEnumerate;
     3.8 +static BOOLEAN gplpv;
     3.9  
    3.10  NTSTATUS
    3.11  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    3.12 @@ -80,7 +80,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    3.13    KeyPartialValue = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
    3.14    SystemStartOptions = (WCHAR *)KeyPartialValue->Data;
    3.15  
    3.16 -  AutoEnumerate = FALSE;
    3.17 +  gplpv = FALSE;
    3.18  
    3.19    RtlStringCbLengthW(SystemStartOptions, KeyPartialValue->DataLength, &SystemStartOptionsLen);
    3.20  
    3.21 @@ -130,18 +130,17 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    3.22        break;
    3.23      case 6:
    3.24        if (SystemStartOptions[i] == L' ' || SystemStartOptions[i] == 0)
    3.25 -        AutoEnumerate = TRUE;
    3.26 +        gplpv = TRUE;
    3.27        State = 0;
    3.28        break;
    3.29      }
    3.30    }
    3.31  
    3.32 -  KdPrint((__DRIVER_NAME "     AutoEnumerate = %d\n", AutoEnumerate));
    3.33 +  KdPrint((__DRIVER_NAME "     gplpv = %d\n", gplpv));
    3.34  
    3.35    for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
    3.36      DriverObject->MajorFunction[i] = XenHide_Pass;
    3.37 -  if (AutoEnumerate)
    3.38 -    DriverObject->MajorFunction[IRP_MJ_PNP] = XenHide_Pnp;
    3.39 +  DriverObject->MajorFunction[IRP_MJ_PNP] = XenHide_Pnp;
    3.40    DriverObject->DriverExtension->AddDevice = XenHide_AddDevice;
    3.41  
    3.42    KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
    3.43 @@ -157,37 +156,54 @@ XenHide_AddDevice(
    3.44  {
    3.45    NTSTATUS status;
    3.46    PDEVICE_OBJECT deviceObject = NULL;
    3.47 -  PDEVICE_EXTENSION DeviceExtension;
    3.48 -  ULONG Length;
    3.49 -  WCHAR Buffer[256];
    3.50 -  size_t StrLen;
    3.51 -  int Match;
    3.52 -  PWCHAR Ptr;
    3.53 -  INTERFACE_TYPE it;
    3.54 +  PXENHIDE_DEVICE_DATA DeviceExtension;
    3.55 +  ULONG length;
    3.56 +  WCHAR buffer[256];
    3.57 +//  size_t StrLen;
    3.58 +//  int Match;
    3.59 +//  PWCHAR Ptr;
    3.60 +  GUID bus_type;
    3.61  
    3.62 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    3.63 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    3.64 +
    3.65 +  length = 256;
    3.66 +  status = IoGetDeviceProperty(PhysicalDeviceObject, DevicePropertyDeviceDescription, length, buffer, &length);
    3.67 +  if (!NT_SUCCESS(status))
    3.68 +    KdPrint((__DRIVER_NAME "     (failed to get DevicePropertyDeviceDescription %08x)\n", status));
    3.69 +  else
    3.70 +    KdPrint((__DRIVER_NAME "     Description = %S\n", buffer));
    3.71  
    3.72 -// get DevicePropertyLegacyBusType. If it's not PCI then return
    3.73 -
    3.74 -  Length = sizeof(it);
    3.75 -  status = IoGetDeviceProperty(PhysicalDeviceObject, DevicePropertyLegacyBusType, Length, &it, &Length);
    3.76 +  length = sizeof(GUID);
    3.77 +  status = IoGetDeviceProperty(PhysicalDeviceObject, DevicePropertyBusTypeGuid, length, &bus_type, &length);
    3.78    if (!NT_SUCCESS(status))
    3.79 +  {
    3.80 +    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (failed to get DevicePropertyBusTypeGuid %08x)\n", status));
    3.81      return STATUS_SUCCESS;
    3.82 +  }
    3.83  
    3.84 -  if (it != PCIBus)
    3.85 +  if (!gplpv && memcmp(&bus_type, &GUID_BUS_TYPE_XEN, sizeof(GUID)) != 0)
    3.86 +  {
    3.87 +    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (gplpv == FALSE && bus_type != GUID_BUS_TYPE_XEN)\n"));
    3.88      return STATUS_SUCCESS;
    3.89 +  }
    3.90 +  
    3.91 +  if (gplpv && memcmp(&bus_type, &GUID_BUS_TYPE_PCI, sizeof(GUID)) != 0)
    3.92 +  {
    3.93 +    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (gplpv == TRUE && bus_type != GUID_BUS_TYPE_PCI)\n"));
    3.94 +    return STATUS_SUCCESS;
    3.95 +  }
    3.96  
    3.97 -  KdPrint((__DRIVER_NAME " Found\n")); 
    3.98 +  KdPrint((__DRIVER_NAME "     Installing Filter\n"));
    3.99  
   3.100    status = IoCreateDevice (DriverObject,
   3.101 -    sizeof(DEVICE_EXTENSION),
   3.102 +    sizeof(XENHIDE_DEVICE_DATA),
   3.103      NULL,
   3.104      FILE_DEVICE_UNKNOWN,
   3.105      FILE_DEVICE_SECURE_OPEN,
   3.106      FALSE,
   3.107      &deviceObject);
   3.108  
   3.109 -  DeviceExtension = (PDEVICE_EXTENSION)deviceObject->DeviceExtension;
   3.110 +  DeviceExtension = (PXENHIDE_DEVICE_DATA)deviceObject->DeviceExtension;
   3.111  
   3.112    DeviceExtension->NextLowerDevice = IoAttachDeviceToDeviceStack(
   3.113      deviceObject,
   3.114 @@ -203,6 +219,7 @@ XenHide_AddDevice(
   3.115  
   3.116    //INITIALIZE_PNP_STATE(DeviceExtension);
   3.117  
   3.118 +#if 0
   3.119    if (AutoEnumerate)
   3.120    {
   3.121      status = IoRegisterDeviceInterface(PhysicalDeviceObject, (LPGUID)&GUID_XENHIDE_IFACE, NULL, &DeviceExtension->InterfaceName);
   3.122 @@ -223,10 +240,11 @@ XenHide_AddDevice(
   3.123    {
   3.124  //    KdPrint((__DRIVER_NAME "     Not registering Interface\n"));
   3.125    }
   3.126 +#endif
   3.127  
   3.128    deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
   3.129  
   3.130 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   3.131 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   3.132  
   3.133    return STATUS_SUCCESS;
   3.134  }
   3.135 @@ -243,7 +261,7 @@ XenHide_IoCompletion(PDEVICE_OBJECT Devi
   3.136    int Match;
   3.137    int Offset = 0;
   3.138    int FoundIde = 0;
   3.139 -  PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)Context;
   3.140 +  PXENHIDE_DEVICE_DATA DeviceExtension = (PXENHIDE_DEVICE_DATA)Context;
   3.141  
   3.142    UNREFERENCED_PARAMETER(DeviceObject);
   3.143    UNREFERENCED_PARAMETER(Context);
   3.144 @@ -263,7 +281,6 @@ XenHide_IoCompletion(PDEVICE_OBJECT Devi
   3.145      break;
   3.146    case 1:
   3.147      DeviceExtension->InternalState = 2;
   3.148 -#if 0
   3.149      if (Relations != NULL)
   3.150      {
   3.151        for (i = 0; i < Relations->Count; i++)
   3.152 @@ -283,16 +300,18 @@ XenHide_IoCompletion(PDEVICE_OBJECT Devi
   3.153            for (Ptr = Buffer; *Ptr != 0; Ptr += StrLen + 1)
   3.154            {
   3.155              // Qemu IDE
   3.156 -            if (XenHide_StringMatches(Ptr, L"PCI\\VEN_8086&DEV_7010")) {
   3.157 +            if (wcscmp(Ptr, L"PCI\\VEN_8086&DEV_7010") == 0) {
   3.158                Match = 1;
   3.159                FoundIde = 1;
   3.160                break;
   3.161              }
   3.162 +#if 0
   3.163              // Qemu Network
   3.164              if (XenHide_StringMatches(Ptr, L"PCI\\VEN_10EC&DEV_8139")) {
   3.165                Match = 1;
   3.166                break;
   3.167              }
   3.168 +#endif
   3.169              RtlStringCchLengthW(Ptr, Length, &StrLen);
   3.170            }
   3.171          }
   3.172 @@ -313,7 +332,6 @@ XenHide_IoCompletion(PDEVICE_OBJECT Devi
   3.173        }
   3.174        Relations->Count -= Offset;
   3.175      }
   3.176 -#endif
   3.177      break;
   3.178    default:
   3.179      break;
   3.180 @@ -326,7 +344,7 @@ XenHide_IoCompletion(PDEVICE_OBJECT Devi
   3.181  static NTSTATUS
   3.182  XenHide_Pass(PDEVICE_OBJECT DeviceObject, PIRP Irp)
   3.183  {
   3.184 -  PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
   3.185 +  PXENHIDE_DEVICE_DATA DeviceExtension = (PXENHIDE_DEVICE_DATA)DeviceObject->DeviceExtension;
   3.186    NTSTATUS status;
   3.187      
   3.188    IoSkipCurrentIrpStackLocation(Irp);
   3.189 @@ -335,18 +353,23 @@ XenHide_Pass(PDEVICE_OBJECT DeviceObject
   3.190  }
   3.191  
   3.192  static NTSTATUS
   3.193 -XenHide_Pnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
   3.194 +XenHide_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
   3.195  {
   3.196 -  NTSTATUS Status = STATUS_SUCCESS;
   3.197 -  PIO_STACK_LOCATION Stack;
   3.198 -  PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
   3.199 +  NTSTATUS status = STATUS_SUCCESS;
   3.200 +  PIO_STACK_LOCATION stack;
   3.201 +  PXENHIDE_DEVICE_DATA xhdd = (PXENHIDE_DEVICE_DATA)device_object->DeviceExtension;
   3.202  
   3.203    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   3.204    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   3.205  
   3.206 -  Stack = IoGetCurrentIrpStackLocation(Irp);
   3.207 +  stack = IoGetCurrentIrpStackLocation(irp);
   3.208  
   3.209 -  switch (Stack->MinorFunction) {
   3.210 +  switch (stack->MinorFunction) {
   3.211 +  case IRP_MN_START_DEVICE:
   3.212 +    status = irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
   3.213 +    IoCompleteRequest(irp, IO_NO_INCREMENT);
   3.214 +    break;
   3.215 +#if 0
   3.216    case IRP_MN_QUERY_DEVICE_RELATIONS:
   3.217  //    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS\n"));
   3.218      switch (Stack->Parameters.QueryDeviceRelations.Type)
   3.219 @@ -361,14 +384,14 @@ XenHide_Pnp(PDEVICE_OBJECT DeviceObject,
   3.220        break;  
   3.221      }
   3.222      break;
   3.223 +#endif
   3.224    default:
   3.225 -    IoSkipCurrentIrpStackLocation(Irp);
   3.226 +    IoSkipCurrentIrpStackLocation(irp);
   3.227 +    status = IoCallDriver(xhdd->NextLowerDevice, irp);
   3.228      break;
   3.229    }
   3.230  
   3.231 -  Status = IoCallDriver(DeviceExtension->NextLowerDevice, Irp);
   3.232 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", status));
   3.233  
   3.234 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", Status));
   3.235 -
   3.236 -  return Status;
   3.237 +  return status;
   3.238  }
     4.1 --- a/xenhide/xenhide.h	Tue May 13 00:02:24 2008 +1000
     4.2 +++ b/xenhide/xenhide.h	Wed May 14 11:45:39 2008 +1000
     4.3 @@ -30,15 +30,17 @@ Foundation, Inc., 51 Franklin Street, Fi
     4.4  
     4.5  #define __DRIVER_NAME "XenHide"
     4.6  
     4.7 +#include <xen_guids.h>
     4.8 +
     4.9  #define XENHIDE_POOL_TAG (ULONG) 'XHID'
    4.10  
    4.11  //{CD433FE7-954F-4D51-BE29-D8A38DFA1108}
    4.12 -DEFINE_GUID(GUID_XENHIDE_IFACE, 0xCD433FE7, 0x954F, 0x4D51, 0xBE, 0x29, 0xD8, 0xA3, 0x8D, 0xFA, 0x11, 0x08);
    4.13 +//DEFINE_GUID(GUID_XENHIDE_IFACE, 0xCD433FE7, 0x954F, 0x4D51, 0xBE, 0x29, 0xD8, 0xA3, 0x8D, 0xFA, 0x11, 0x08);
    4.14  
    4.15  #define XENHIDE_TYPE_PCI 1
    4.16  #define XENHIDE_TYPE_HIDE 2
    4.17  
    4.18 -struct _DEVICE_EXTENSION {
    4.19 +struct {
    4.20    PDEVICE_OBJECT Self;
    4.21    PDEVICE_OBJECT PhysicalDeviceObject;
    4.22    PDRIVER_OBJECT DriverObject;
    4.23 @@ -46,6 +48,6 @@ struct _DEVICE_EXTENSION {
    4.24    IO_REMOVE_LOCK RemoveLock;
    4.25    UNICODE_STRING InterfaceName;
    4.26    ULONG InternalState;
    4.27 -} typedef DEVICE_EXTENSION, *PDEVICE_EXTENSION;
    4.28 +} typedef XENHIDE_DEVICE_DATA, *PXENHIDE_DEVICE_DATA;
    4.29  
    4.30  #endif
     5.1 --- a/xenpci/xenpci.c	Tue May 13 00:02:24 2008 +1000
     5.2 +++ b/xenpci/xenpci.c	Wed May 14 11:45:39 2008 +1000
     5.3 @@ -30,9 +30,6 @@ DRIVER_INITIALIZE DriverEntry;
     5.4  #pragma alloc_text (INIT, DriverEntry)
     5.5  #endif
     5.6  
     5.7 -/* Global (driver-wide) variables */
     5.8 -static BOOLEAN AutoEnumerate;
     5.9 -
    5.10  #pragma warning(disable : 4200) // zero-sized array
    5.11  
    5.12  static NTSTATUS
     6.1 --- a/xenpci/xenpci.h	Tue May 13 00:02:24 2008 +1000
     6.2 +++ b/xenpci/xenpci.h	Wed May 14 11:45:39 2008 +1000
     6.3 @@ -194,7 +194,7 @@ typedef struct
     6.4  static __inline VOID
     6.5  sw_interrupt(UCHAR intno)
     6.6  {
     6.7 -  KdPrint((__DRIVER_NAME "     Calling interrupt %02X\n", intno));
     6.8 +  //KdPrint((__DRIVER_NAME "     Calling interrupt %02X\n", intno));
     6.9    switch (intno)
    6.10    {
    6.11    SWINT(0x10) SWINT(0x11) SWINT(0x12) SWINT(0x13) SWINT(0x14) SWINT(0x15) SWINT(0x16) SWINT(0x17)
     7.1 --- a/xenpci/xenpci_fdo.c	Tue May 13 00:02:24 2008 +1000
     7.2 +++ b/xenpci/xenpci_fdo.c	Wed May 14 11:45:39 2008 +1000
     7.3 @@ -38,7 +38,6 @@ XenPCI_XenBusWatchHandler(char *Path, PV
     7.4  */
     7.5  
     7.6  /* Global (driver-wide) variables */
     7.7 -static BOOLEAN AutoEnumerate;
     7.8  static LIST_ENTRY ShutdownMsgList;
     7.9  
    7.10  #pragma warning(disable : 4200) // zero-sized array
    7.11 @@ -710,7 +709,7 @@ XenPci_Pnp_Fdo(PDEVICE_OBJECT device_obj
    7.12      IoSkipCurrentIrpStackLocation(irp);
    7.13      irp->IoStatus.Status = STATUS_SUCCESS;
    7.14      break;
    7.15 -
    7.16 +//#if 0
    7.17    case IRP_MN_QUERY_DEVICE_RELATIONS:
    7.18      KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS\n"));
    7.19      switch (stack->Parameters.QueryDeviceRelations.Type)
    7.20 @@ -724,7 +723,7 @@ XenPci_Pnp_Fdo(PDEVICE_OBJECT device_obj
    7.21        break;  
    7.22      }
    7.23      break;
    7.24 -    
    7.25 +//#endif    
    7.26    case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
    7.27      KdPrint((__DRIVER_NAME "     IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n"));
    7.28      return XenPci_Pnp_FilterResourceRequirements(device_object, irp);
     8.1 --- a/xenpci/xenpci_pdo.c	Tue May 13 00:02:24 2008 +1000
     8.2 +++ b/xenpci/xenpci_pdo.c	Wed May 14 11:45:39 2008 +1000
     8.3 @@ -575,7 +575,7 @@ XenPci_Pnp_Pdo(PDEVICE_OBJECT device_obj
     8.4    case IRP_MN_QUERY_BUS_INFORMATION:
     8.5      KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_BUS_INFORMATION (status = %08x)\n", irp->IoStatus.Status));
     8.6      pbi = (PPNP_BUS_INFORMATION)ExAllocatePoolWithTag(PagedPool, sizeof(PNP_BUS_INFORMATION), XENPCI_POOL_TAG);
     8.7 -    pbi->BusTypeGuid = GUID_XENPCI_DEVCLASS;
     8.8 +    pbi->BusTypeGuid = GUID_BUS_TYPE_XEN;
     8.9      pbi->LegacyBusType = Internal;
    8.10      pbi->BusNumber = 0;
    8.11      irp->IoStatus.Information = (ULONG_PTR)pbi;
     9.1 --- a/xenvbd/xenvbd.c	Tue May 13 00:02:24 2008 +1000
     9.2 +++ b/xenvbd/xenvbd.c	Wed May 14 11:45:39 2008 +1000
     9.3 @@ -116,7 +116,6 @@ XenVbd_Pnp(PDEVICE_OBJECT device_object,
     9.4        prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
     9.5        prd->u.Memory.Length = PAGE_SIZE;
     9.6        stack->Parameters.StartDevice.AllocatedResources = new_crl;
     9.7 -
     9.8        IoCopyCurrentIrpStackLocationToNext(irp);
     9.9      }
    9.10      else
    9.11 @@ -189,7 +188,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    9.12    HwInitializationData.HwDmaStarted = NULL;
    9.13    HwInitializationData.DeviceExtensionSize = sizeof(XENVBD_DEVICE_DATA);
    9.14    HwInitializationData.SpecificLuExtensionSize = 0;
    9.15 -  HwInitializationData.SrbExtensionSize = 0;
    9.16 +  HwInitializationData.SrbExtensionSize = PAGE_SIZE;
    9.17    HwInitializationData.NumberOfAccessRanges = 1;
    9.18    HwInitializationData.MapBuffers = TRUE;
    9.19    HwInitializationData.NeedPhysicalAddresses = FALSE;