win-pvdrivers

changeset 497:312a41f82b8f

Updated to support the proposed patches to qemu from Steven Smith on ~20081216
author James Harper <james.harper@bendigoit.com.au>
date Fri Dec 19 22:08:17 2008 +1100 (2008-12-19)
parents 785de85f3db7
children e1663de619d3
files common/include/xen_public.h common/include/xen_windows.h xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci.inx xenpci/xenpci_pdo.c xenvbd/xenvbd.c
line diff
     1.1 --- a/common/include/xen_public.h	Wed Dec 17 20:09:32 2008 +1100
     1.2 +++ b/common/include/xen_public.h	Fri Dec 19 22:08:17 2008 +1100
     1.3 @@ -165,19 +165,20 @@ typedef struct {
     1.4  
     1.5  #define XEN_INIT_DRIVER_EXTENSION_MAGIC ((ULONG)'XCFG')
     1.6  
     1.7 -#define XEN_INIT_TYPE_END               0
     1.8 -#define XEN_INIT_TYPE_WRITE_STRING      1
     1.9 -#define XEN_INIT_TYPE_RING              2
    1.10 -#define XEN_INIT_TYPE_EVENT_CHANNEL     3
    1.11 -#define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
    1.12 -#define XEN_INIT_TYPE_READ_STRING_FRONT 5
    1.13 -#define XEN_INIT_TYPE_READ_STRING_BACK  6
    1.14 -#define XEN_INIT_TYPE_VECTORS           7
    1.15 -#define XEN_INIT_TYPE_GRANT_ENTRIES     8
    1.16 -//#define XEN_INIT_TYPE_COPY_PTR          9
    1.17 -#define XEN_INIT_TYPE_RUN               10
    1.18 -#define XEN_INIT_TYPE_STATE_PTR         11
    1.19 -#define XEN_INIT_TYPE_ACTIVE		12
    1.20 +#define XEN_INIT_TYPE_END                       0
    1.21 +#define XEN_INIT_TYPE_WRITE_STRING              1
    1.22 +#define XEN_INIT_TYPE_RING                      2
    1.23 +#define XEN_INIT_TYPE_EVENT_CHANNEL             3
    1.24 +#define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ         4
    1.25 +#define XEN_INIT_TYPE_READ_STRING_FRONT         5
    1.26 +#define XEN_INIT_TYPE_READ_STRING_BACK          6
    1.27 +#define XEN_INIT_TYPE_VECTORS                   7
    1.28 +#define XEN_INIT_TYPE_GRANT_ENTRIES             8
    1.29 +//#define XEN_INIT_TYPE_COPY_PTR                  9
    1.30 +#define XEN_INIT_TYPE_RUN                       10
    1.31 +#define XEN_INIT_TYPE_STATE_PTR                 11
    1.32 +#define XEN_INIT_TYPE_ACTIVE                    12
    1.33 +#define XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION     13
    1.34  
    1.35  static __inline VOID
    1.36  __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
    1.37 @@ -280,6 +281,7 @@ ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type
    1.38    case XEN_INIT_TYPE_RUN:
    1.39    case XEN_INIT_TYPE_STATE_PTR:
    1.40    case XEN_INIT_TYPE_ACTIVE:
    1.41 +  case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
    1.42      break;
    1.43    case XEN_INIT_TYPE_WRITE_STRING:
    1.44      __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
    1.45 @@ -315,6 +317,7 @@ GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1,
    1.46    case XEN_INIT_TYPE_RUN:
    1.47    case XEN_INIT_TYPE_STATE_PTR:
    1.48    case XEN_INIT_TYPE_ACTIVE:
    1.49 +  case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
    1.50      *p1 = NULL;
    1.51      *p2 = NULL;
    1.52      break;
    1.53 @@ -379,6 +382,9 @@ ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type
    1.54    case XEN_INIT_TYPE_STATE_PTR:
    1.55      __ADD_XEN_INIT_PTR(ptr, p2);
    1.56      break;
    1.57 +  case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
    1.58 +    __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
    1.59 +    break;
    1.60  //  case XEN_INIT_TYPE_COPY_PTR:
    1.61  //    __ADD_XEN_INIT_STRING(ptr, p1);
    1.62  //    __ADD_XEN_INIT_PTR(ptr, p2);
    1.63 @@ -433,6 +439,9 @@ GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1,
    1.64    case XEN_INIT_TYPE_STATE_PTR:
    1.65      *p2 = __GET_XEN_INIT_PTR(ptr);
    1.66      break;
    1.67 +  case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
    1.68 +    *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
    1.69 +    break;
    1.70  //  case XEN_INIT_TYPE_COPY_PTR:
    1.71  //    *p1 = __GET_XEN_INIT_STRING(ptr);
    1.72  //    *p2 = __GET_XEN_INIT_PTR(ptr);
     2.1 --- a/common/include/xen_windows.h	Wed Dec 17 20:09:32 2008 +1100
     2.2 +++ b/common/include/xen_windows.h	Fri Dec 19 22:08:17 2008 +1100
     2.3 @@ -192,39 +192,63 @@ FreePages(PMDL Mdl)
     2.4    ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
     2.5  }
     2.6  
     2.7 -#define XEN_IOPORT_DEBUG_PORT_BASE 0x10
     2.8 +#define XEN_IOPORT_BASE 0x10
     2.9 +
    2.10 +/*
    2.11 +define these as pointers so that the READ_PORT* functions complain if
    2.12 +the wrong width is used with the wrong defined port
    2.13 +*/
    2.14 +
    2.15 +#define XEN_IOPORT_MAGIC        ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
    2.16 +#define XEN_IOPORT_LOG          ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
    2.17 +#define XEN_IOPORT_VERSION      ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
    2.18 +#define XEN_IOPORT_PRODUCT      ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 2))
    2.19 +#define XEN_IOPORT_BUILD        ((PULONG)UlongToPtr(XEN_IOPORT_BASE + 0))
    2.20 +#define XEN_IOPORT_DEVICE_MASK  ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
    2.21 +
    2.22 +#define QEMU_UNPLUG_ALL_IDE_DISKS 1
    2.23 +#define QEMU_UNPLUG_ALL_NICS 2
    2.24 +#define QEMU_UNPLUG_AUX_IDE_DISKS 4
    2.25 +
    2.26 +static BOOLEAN debug_port_probed = FALSE;
    2.27 +static BOOLEAN debug_port_enabled;
    2.28  
    2.29  static void XenDbgPrint(PCHAR format, ...)
    2.30  {
    2.31    CHAR buf[512];
    2.32    va_list ap;
    2.33 -#ifdef XEN_IOPORT_DEBUG_PORT_BASE
    2.34    ULONG i;
    2.35 -  BOOLEAN flag;
    2.36 -  int cpu;
    2.37 +  //int cpu;
    2.38    KIRQL old_irql = 0;
    2.39 -#endif
    2.40 -  
    2.41 +
    2.42 +  if (!debug_port_probed)
    2.43 +  {
    2.44 +    if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2
    2.45 +        || READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0xd249)
    2.46 +    {
    2.47 +      debug_port_enabled = TRUE;
    2.48 +    }
    2.49 +    else
    2.50 +    {
    2.51 +      debug_port_enabled = FALSE;
    2.52 +    }
    2.53 +    debug_port_probed = TRUE;
    2.54 +  }
    2.55    va_start(ap, format);
    2.56    RtlStringCbVPrintfA(buf, ARRAY_SIZE(buf), format, ap);
    2.57    va_end(ap);
    2.58    DbgPrint(buf);
    2.59 -#ifdef XEN_IOPORT_DEBUG_PORT_BASE
    2.60 -  flag = (KeGetCurrentIrql() < HIGH_LEVEL);
    2.61 -  if (flag)
    2.62 +
    2.63 +  if (debug_port_enabled)
    2.64    {
    2.65      KeRaiseIrql(HIGH_LEVEL, &old_irql);
    2.66 -  }
    2.67 -  cpu = KeGetCurrentProcessorNumber() & 0x07;
    2.68 -  for (i = 0; i < strlen(buf); i++)
    2.69 -  {
    2.70 -    WRITE_PORT_UCHAR((PUCHAR)XEN_IOPORT_DEBUG_PORT_BASE + cpu, buf[i]);
    2.71 -  }
    2.72 -  if (flag)
    2.73 -  {
    2.74 +    //cpu = KeGetCurrentProcessorNumber() & 0x07;
    2.75 +    for (i = 0; i < strlen(buf); i++)
    2.76 +    {
    2.77 +      WRITE_PORT_UCHAR(XEN_IOPORT_LOG, buf[i]);
    2.78 +    }
    2.79      KeLowerIrql(old_irql);
    2.80    }
    2.81 -#endif
    2.82  }
    2.83  
    2.84  #ifdef KdPrint
     3.1 --- a/xenpci/xenpci.c	Wed Dec 17 20:09:32 2008 +1100
     3.2 +++ b/xenpci/xenpci.c	Fri Dec 19 22:08:17 2008 +1100
     3.3 @@ -223,11 +223,9 @@ XenPci_AddDevice(PDRIVER_OBJECT DriverOb
     3.4    FUNCTION_EXIT();
     3.5    return status;
     3.6  }
     3.7 -//DECLARE_UNICODE_STRING_SIZE(service_path, 512);
     3.8  
     3.9 -#define XEN_GLOBAL_IOPORT_PORT_BASE 0x10
    3.10 -
    3.11 -ULONG need_gplpv_filter;
    3.12 +ULONG qemu_filtered;
    3.13 +ULONG qemu_protocol_version;
    3.14  extern PULONG InitSafeBootMode;
    3.15  
    3.16  NTSTATUS DDKAPI
    3.17 @@ -276,20 +274,28 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    3.18        && !*InitSafeBootMode)
    3.19    {
    3.20      /* see if the qemu method of disabling the PCI devices exists */
    3.21 -    if (READ_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 0)) == 'X'
    3.22 -        && READ_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 1)) == 'E'
    3.23 -        && READ_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 2)) == 'N')
    3.24 +    if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2)
    3.25      {
    3.26 -      UCHAR version = READ_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 3));
    3.27 -      switch(version)
    3.28 +      qemu_protocol_version = READ_PORT_UCHAR(XEN_IOPORT_VERSION);
    3.29 +      KdPrint((__DRIVER_NAME "     Version = %d\n", qemu_protocol_version));
    3.30 +      switch(qemu_protocol_version)
    3.31        {
    3.32        case 1:
    3.33 -        need_gplpv_filter = TRUE;
    3.34 -        WRITE_PORT_UCHAR((PUCHAR)UlongToPtr(XEN_GLOBAL_IOPORT_PORT_BASE + 8), 1);
    3.35 -        KdPrint((__DRIVER_NAME "     Disabled PCI devices\n"));
    3.36 +        WRITE_PORT_USHORT(XEN_IOPORT_PRODUCT, XEN_PV_PRODUCT_NUMBER);
    3.37 +        WRITE_PORT_ULONG(XEN_IOPORT_BUILD, XEN_PV_PRODUCT_BUILD);
    3.38 +        if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) != 0x49d2)
    3.39 +        {
    3.40 +          KdPrint((__DRIVER_NAME "     Blacklisted\n"));
    3.41 +          break;
    3.42 +        }
    3.43 +        /* fall through */
    3.44 +      case 0:
    3.45 +        qemu_filtered = TRUE;
    3.46 +        WRITE_PORT_USHORT(XEN_IOPORT_DEVICE_MASK, QEMU_UNPLUG_ALL_IDE_DISKS|QEMU_UNPLUG_ALL_NICS);
    3.47 +        KdPrint((__DRIVER_NAME "     Disabled qemu devices\n"));
    3.48          break;
    3.49        default:
    3.50 -        KdPrint((__DRIVER_NAME "     Unknown version %d\n", (ULONG)version));
    3.51 +        KdPrint((__DRIVER_NAME "     Unknown qemu version %d\n", qemu_protocol_version));
    3.52          break;
    3.53        }
    3.54      }
    3.55 @@ -298,13 +304,14 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    3.56        KdPrint((__DRIVER_NAME "     Missing XEN signature\n"));
    3.57      }
    3.58      /* if not, tell the filter to deny the pci devices their resources */
    3.59 -    if (!need_gplpv_filter)
    3.60 +    if (!qemu_filtered)
    3.61      {
    3.62        OBJECT_ATTRIBUTES oa;
    3.63        UNICODE_STRING dir_name;
    3.64        NTSTATUS status;
    3.65        HANDLE handle;
    3.66        
    3.67 +      KdPrint((__DRIVER_NAME "     Adding DirectoryObject\n"));
    3.68        RtlInitUnicodeString(&dir_name, L"\\NEED_GPLPV_FILTER");
    3.69        InitializeObjectAttributes(&oa, &dir_name, OBJ_KERNEL_HANDLE, NULL, NULL);
    3.70        status = ZwCreateDirectoryObject(&handle, DIRECTORY_CREATE_OBJECT, &oa);
    3.71 @@ -313,10 +320,10 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    3.72        {
    3.73          return status;
    3.74        }
    3.75 -      need_gplpv_filter = TRUE;
    3.76 +      qemu_filtered = TRUE;
    3.77      }
    3.78    }
    3.79 -  
    3.80 +
    3.81    DriverObject->DriverExtension->AddDevice = XenPci_AddDevice;
    3.82    DriverObject->MajorFunction[IRP_MJ_PNP] = XenPci_Pnp;
    3.83    DriverObject->MajorFunction[IRP_MJ_POWER] = XenPci_Power;
     4.1 --- a/xenpci/xenpci.h	Wed Dec 17 20:09:32 2008 +1100
     4.2 +++ b/xenpci/xenpci.h	Fri Dec 19 22:08:17 2008 +1100
     4.3 @@ -69,7 +69,11 @@ DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC82
     4.4  #define EVT_ACTION_TYPE_IRQ     3
     4.5  #define EVT_ACTION_TYPE_SUSPEND 4
     4.6  
     4.7 -extern ULONG need_gplpv_filter;
     4.8 +#define XEN_PV_PRODUCT_NUMBER   0x0002
     4.9 +#define XEN_PV_PRODUCT_BUILD    0x00000001
    4.10 +
    4.11 +extern ULONG qemu_filtered;
    4.12 +extern ULONG qemu_protocol_version;
    4.13  
    4.14  typedef struct _ev_action_t {
    4.15    PKSERVICE_ROUTINE ServiceRoutine;
     5.1 --- a/xenpci/xenpci.inx	Wed Dec 17 20:09:32 2008 +1100
     5.2 +++ b/xenpci/xenpci.inx	Fri Dec 19 22:08:17 2008 +1100
     5.3 @@ -60,10 +60,14 @@ ServiceBinary  = %12%\xenpci.sys
     5.4  [XenHide_Service]
     5.5  DisplayName    = %XenHide.SVCDESC%
     5.6  ServiceType    = 1
     5.7 -StartType      = 0
     5.8 +StartType      = 3
     5.9  ErrorControl   = 1
    5.10  LoadOrderGroup = System Bus Extender
    5.11  ServiceBinary  = %12%\xenhide.sys
    5.12 +DelReg         = XenHide_Service_DelReg
    5.13 +
    5.14 +[XenHide_Service_DelReg]
    5.15 +HKLM,SYSTEM\CurrentControlSet\Control\Class\{4D36E97D-E325-11CE-BFC1-08002BE10318},UpperFilters
    5.16  
    5.17  [Strings]
    5.18  XenGplPv = "Xen GPL PV Driver Developers"
    5.19 @@ -71,4 +75,3 @@ XenPCI.SVCDESC = "Xen PCI Device Driver"
    5.20  XenPCI.DRVDESC = "Xen PCI Device Driver"
    5.21  XenHide.SVCDESC = "Xen PCI Device Hider Driver"
    5.22  DISK_NAME = "Xen PCI Device Driver Install Disk"
    5.23 -
     6.1 --- a/xenpci/xenpci_pdo.c	Wed Dec 17 20:09:32 2008 +1100
     6.2 +++ b/xenpci/xenpci_pdo.c	Fri Dec 19 22:08:17 2008 +1100
     6.3 @@ -596,8 +596,10 @@ XenPci_XenConfigDeviceSpecifyBuffers(PVO
     6.4    vectors.XenBus_AddWatch = XenPci_XenBus_AddWatch;
     6.5    vectors.XenBus_RemWatch = XenPci_XenBus_RemWatch;
     6.6  
     6.7 -  if (need_gplpv_filter)
     6.8 +  if (qemu_filtered)
     6.9      ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_ACTIVE, NULL, NULL);
    6.10 +
    6.11 +  ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION, NULL, UlongToPtr(qemu_protocol_version));
    6.12    
    6.13    ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_VECTORS, NULL, &vectors);
    6.14    ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_STATE_PTR, NULL, &xppdd->device_state);
     7.1 --- a/xenvbd/xenvbd.c	Wed Dec 17 20:09:32 2008 +1100
     7.2 +++ b/xenvbd/xenvbd.c	Fri Dec 19 22:08:17 2008 +1100
     7.3 @@ -145,6 +145,7 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
     7.4    PUCHAR ptr;
     7.5    USHORT type;
     7.6    PCHAR setting, value;
     7.7 +  ULONG qemu_protocol_version = 0;
     7.8  
     7.9    xvdd->device_type = XENVBD_DEVICETYPE_UNKNOWN;
    7.10    xvdd->sring = NULL;
    7.11 @@ -269,6 +270,8 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
    7.12      case XEN_INIT_TYPE_ACTIVE:
    7.13        xvdd->inactive = FALSE;
    7.14        break;
    7.15 +    case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
    7.16 +      qemu_protocol_version = PtrToUlong(value);
    7.17      default:
    7.18        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
    7.19        break;
    7.20 @@ -284,6 +287,9 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
    7.21      KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    7.22      return SP_RETURN_BAD_CONFIG;
    7.23    }
    7.24 +  if (!xvdd->inactive && xvdd->device_type == XENVBD_DEVICETYPE_CDROM && qemu_protocol_version > 0)
    7.25 +    xvdd->inactive = TRUE;
    7.26 +
    7.27    if (xvdd->inactive)
    7.28      KdPrint((__DRIVER_NAME "     Device is inactive\n"));
    7.29