win-pvdrivers

changeset 310:60372bd2582d wdm

First cut of putting xenbus config details in the .inf file - xenvbd may yet pass WHQL
author James Harper <james.harper@bendigoit.com.au>
date Fri Jun 13 14:16:50 2008 +1000 (2008-06-13)
parents 41c06d83082d
children c25d8b936290
files common.inc common/include/xen_public.h dirs installer.nsi xenconfig/makefile.inc xenconfig/sources xenconfig/xenconfig.c xenconfig/xenconfig.h xenpci/xenpci_fdo.c xenpci/xenpci_pdo.c xenvbd/scsiport.c xenvbd/xenvbd.c xenvbd/xenvbd.h xenvbd/xenvbd.inx
line diff
     1.1 --- a/common.inc	Wed Jun 11 21:24:57 2008 +1000
     1.2 +++ b/common.inc	Fri Jun 13 14:16:50 2008 +1000
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.9.8.5
     1.5 +VERSION=0.9.8.7
     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	Wed Jun 11 21:24:57 2008 +1000
     2.2 +++ b/common/include/xen_public.h	Fri Jun 13 14:16:50 2008 +1000
     2.3 @@ -20,6 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  #if !defined(_XEN_PUBLIC_H_)
     2.5  #define _XEN_PUBLIC_H_
     2.6  
     2.7 +#include <grant_table.h>
     2.8 +#include <event_channel.h>
     2.9  #include <xen_guids.h>
    2.10  //{5C568AC5-9DDF-4FA5-A94A-39D67077819C}
    2.11  DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
    2.12 @@ -166,7 +168,7 @@ typedef struct {
    2.13  static __inline VOID
    2.14  __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
    2.15  {
    2.16 -//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
    2.17 +  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
    2.18    *(PUCHAR)(*ptr) = val;
    2.19    *ptr += sizeof(UCHAR);
    2.20  }
    2.21 @@ -174,7 +176,7 @@ static __inline VOID
    2.22  static __inline VOID
    2.23  __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
    2.24  {
    2.25 -//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
    2.26 +  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
    2.27    *(PUSHORT)(*ptr) = val;
    2.28    *ptr += sizeof(USHORT);
    2.29  }
    2.30 @@ -182,7 +184,7 @@ static __inline VOID
    2.31  static __inline VOID
    2.32  __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
    2.33  {
    2.34 -//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
    2.35 +  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
    2.36    *(PULONG)(*ptr) = val;
    2.37    *ptr += sizeof(ULONG);
    2.38  }
    2.39 @@ -190,7 +192,7 @@ static __inline VOID
    2.40  static __inline VOID
    2.41  __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
    2.42  {
    2.43 -//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
    2.44 +  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
    2.45    *(PVOID *)(*ptr) = val;
    2.46    *ptr += sizeof(PVOID);
    2.47  }
    2.48 @@ -198,7 +200,7 @@ static __inline VOID
    2.49  static __inline VOID
    2.50  __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
    2.51  {
    2.52 -//  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
    2.53 +  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
    2.54    //RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
    2.55    // using strcpy instead of above needed for mingw32
    2.56    strcpy((char *)*ptr, val);
    2.57 @@ -210,7 +212,7 @@ static __inline UCHAR
    2.58  {
    2.59    UCHAR retval;
    2.60    retval = **ptr;
    2.61 -//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
    2.62 +  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
    2.63    *ptr += sizeof(UCHAR);
    2.64    return retval;
    2.65  }
    2.66 @@ -220,7 +222,7 @@ static __inline USHORT
    2.67  {
    2.68    USHORT retval;
    2.69    retval = *(PUSHORT)*ptr;
    2.70 -//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
    2.71 +  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
    2.72    *ptr += sizeof(USHORT);
    2.73    return retval;
    2.74  }
    2.75 @@ -230,7 +232,7 @@ static __inline ULONG
    2.76  {
    2.77    ULONG retval;
    2.78    retval = *(PLONG)*ptr;
    2.79 -//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
    2.80 +  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
    2.81    *ptr += sizeof(ULONG);
    2.82    return retval;
    2.83  }
    2.84 @@ -240,7 +242,7 @@ static __inline PCHAR
    2.85  {
    2.86    PCHAR retval;
    2.87    retval = (PCHAR)*ptr;
    2.88 -//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
    2.89 +  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
    2.90    *ptr += strlen((PCHAR)*ptr) + 1;
    2.91    return retval;
    2.92  }
    2.93 @@ -250,7 +252,7 @@ static __inline PVOID
    2.94  {
    2.95    PVOID retval;
    2.96    retval = *(PVOID *)(*ptr);
    2.97 -//  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
    2.98 +  KdPrint((__DRIVER_NAME "     GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
    2.99    *ptr += sizeof(PVOID);
   2.100    return retval;
   2.101  }
   2.102 @@ -276,7 +278,7 @@ ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type
   2.103      __ADD_XEN_INIT_STRING(ptr, p1);
   2.104      break;
   2.105    case XEN_INIT_TYPE_GRANT_ENTRIES:
   2.106 -    __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
   2.107 +    __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
   2.108      break;
   2.109    case XEN_INIT_TYPE_COPY_PTR:
   2.110      __ADD_XEN_INIT_STRING(ptr, p1);
   2.111 @@ -310,7 +312,7 @@ GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1,
   2.112      *p2 = NULL;
   2.113      break;
   2.114    case XEN_INIT_TYPE_GRANT_ENTRIES:
   2.115 -    *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
   2.116 +    *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
   2.117      break;
   2.118    case XEN_INIT_TYPE_COPY_PTR:
   2.119      *p1 = __GET_XEN_INIT_STRING(ptr);
   2.120 @@ -355,6 +357,7 @@ ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type
   2.121    case XEN_INIT_TYPE_COPY_PTR:
   2.122      __ADD_XEN_INIT_STRING(ptr, p1);
   2.123      __ADD_XEN_INIT_PTR(ptr, p2);
   2.124 +    break;
   2.125    }
   2.126  }
   2.127  
   2.128 @@ -398,7 +401,7 @@ GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1,
   2.129    case XEN_INIT_TYPE_GRANT_ENTRIES:
   2.130      *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
   2.131      *p2 = *ptr;
   2.132 -    *ptr += PtrToUlong(*p1) * sizeof(grant_entry_t);
   2.133 +    *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
   2.134      break;
   2.135    case XEN_INIT_TYPE_COPY_PTR:
   2.136      *p1 = __GET_XEN_INIT_STRING(ptr);
     3.1 --- a/dirs	Wed Jun 11 21:24:57 2008 +1000
     3.2 +++ b/dirs	Fri Jun 13 14:16:50 2008 +1000
     3.3 @@ -1,1 +1,1 @@
     3.4 -DIRS=xenpci xenhide xenvbd xennet xenscsi xenstub
     3.5 \ No newline at end of file
     3.6 +DIRS=xenpci xenhide xenvbd xennet xenscsi xenstub xenconfig
     3.7 \ No newline at end of file
     4.1 --- a/installer.nsi	Wed Jun 11 21:24:57 2008 +1000
     4.2 +++ b/installer.nsi	Fri Jun 13 14:16:50 2008 +1000
     4.3 @@ -143,6 +143,7 @@ Section "Windows 2008 x64" win2k8x64
     4.4    File .\target\winlh\amd64\xenvbd.sys
     4.5    File .\target\winlh\amd64\xenscsi.sys
     4.6    File .\target\winlh\amd64\xenstub.sys
     4.7 +  File .\target\winlh\amd64\xenconfig.sys
     4.8  SectionEnd
     4.9  
    4.10  Section "Install Drivers" installdrivers
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/xenconfig/sources	Fri Jun 13 14:16:50 2008 +1000
     6.3 @@ -0,0 +1,5 @@
     6.4 +!INCLUDE ..\common.inc
     6.5 +TARGETNAME=xenconfig
     6.6 +TARGETTYPE=DRIVER
     6.7 +INF_NAME=$(TARGETNAME)
     6.8 +SOURCES=xenconfig.c
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/xenconfig/xenconfig.c	Fri Jun 13 14:16:50 2008 +1000
     7.3 @@ -0,0 +1,394 @@
     7.4 +/*
     7.5 +PV Drivers for Windows Xen HVM Domains
     7.6 +Copyright (C) 2007 James Harper
     7.7 +
     7.8 +This program is free software; you can redistribute it and/or
     7.9 +modify it under the terms of the GNU General Public License
    7.10 +as published by the Free Software Foundation; either version 2
    7.11 +of the License, or (at your option) any later version.
    7.12 +
    7.13 +This program is distributed in the hope that it will be useful,
    7.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.16 +GNU General Public License for more details.
    7.17 +
    7.18 +You should have received a copy of the GNU General Public License
    7.19 +along with this program; if not, write to the Free Software
    7.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    7.21 +*/
    7.22 +
    7.23 +#include "xenconfig.h"
    7.24 +#include <stdlib.h>
    7.25 +
    7.26 +DRIVER_INITIALIZE DriverEntry;
    7.27 +static NTSTATUS
    7.28 +XenConfig_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject);
    7.29 +static NTSTATUS
    7.30 +XenConfig_Pass(PDEVICE_OBJECT DeviceObject, PIRP Irp);
    7.31 +static NTSTATUS
    7.32 +XenConfig_Pnp(PDEVICE_OBJECT DeviceObject, PIRP Irp);
    7.33 +static NTSTATUS
    7.34 +XenConfig_AddDevice();
    7.35 +//static NTSTATUS
    7.36 +//XenConfig_Unload();
    7.37 +
    7.38 +#ifdef ALLOC_PRAGMA
    7.39 +#pragma alloc_text (INIT, DriverEntry)
    7.40 +#pragma alloc_text (PAGE, XenConfig_AddDevice)
    7.41 +#endif
    7.42 +
    7.43 +static BOOLEAN gplpv;
    7.44 +
    7.45 +NTSTATUS
    7.46 +DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    7.47 +{
    7.48 +  NTSTATUS status = STATUS_SUCCESS;
    7.49 +  int i;
    7.50 +
    7.51 +  UNREFERENCED_PARAMETER(RegistryPath);
    7.52 +
    7.53 +  KdPrint((__DRIVER_NAME " --> DriverEntry\n"));
    7.54 +
    7.55 +  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
    7.56 +    DriverObject->MajorFunction[i] = XenConfig_Pass;
    7.57 +  DriverObject->MajorFunction[IRP_MJ_PNP] = XenConfig_Pnp;
    7.58 +  DriverObject->DriverExtension->AddDevice = XenConfig_AddDevice;
    7.59 +
    7.60 +  KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
    7.61 +
    7.62 +  return status;
    7.63 +}
    7.64 +
    7.65 +static NTSTATUS
    7.66 +XenConfig_AddDevice(
    7.67 +  PDRIVER_OBJECT DriverObject,
    7.68 +  PDEVICE_OBJECT PhysicalDeviceObject
    7.69 +  )
    7.70 +{
    7.71 +  NTSTATUS status;
    7.72 +  PDEVICE_OBJECT device_object = NULL;
    7.73 +  PXENCONFIG_DEVICE_DATA xcdd;
    7.74 +
    7.75 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    7.76 +
    7.77 +  status = IoCreateDevice (DriverObject,
    7.78 +    sizeof(XENCONFIG_DEVICE_DATA),
    7.79 +    NULL,
    7.80 +    FILE_DEVICE_UNKNOWN,
    7.81 +    FILE_DEVICE_SECURE_OPEN,
    7.82 +    FALSE,
    7.83 +    &device_object);
    7.84 +
    7.85 +  xcdd = (PXENCONFIG_DEVICE_DATA)device_object->DeviceExtension;
    7.86 +
    7.87 +  xcdd->pdo = PhysicalDeviceObject;
    7.88 +  xcdd->lower_do = IoAttachDeviceToDeviceStack(
    7.89 +    device_object, PhysicalDeviceObject);
    7.90 +  device_object->Flags |= xcdd->lower_do->Flags;
    7.91 +
    7.92 +  device_object->DeviceType = xcdd->lower_do->DeviceType;
    7.93 +
    7.94 +  device_object->Characteristics = 
    7.95 +    xcdd->lower_do->Characteristics;
    7.96 +
    7.97 +  xcdd->filter_do = device_object;
    7.98 +
    7.99 +  device_object->Flags &= ~DO_DEVICE_INITIALIZING;
   7.100 +
   7.101 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   7.102 +
   7.103 +  return STATUS_SUCCESS;
   7.104 +}
   7.105 +
   7.106 +static NTSTATUS
   7.107 +XenConfig_Pass(PDEVICE_OBJECT DeviceObject, PIRP Irp)
   7.108 +{
   7.109 +  PXENCONFIG_DEVICE_DATA xcdd = (PXENCONFIG_DEVICE_DATA)DeviceObject->DeviceExtension;
   7.110 +  NTSTATUS status;
   7.111 +    
   7.112 +  IoSkipCurrentIrpStackLocation(Irp);
   7.113 +  status = IoCallDriver(xcdd->lower_do, Irp);
   7.114 +  return status;
   7.115 +}
   7.116 +
   7.117 +static NTSTATUS
   7.118 +XenConfig_Pnp_IoCompletion(PDEVICE_OBJECT device_object, PIRP irp, PVOID context)
   7.119 +{
   7.120 +  PKEVENT event = (PKEVENT)context;
   7.121 +
   7.122 +  UNREFERENCED_PARAMETER(device_object);
   7.123 +
   7.124 +//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.125 +
   7.126 +  if (irp->PendingReturned)
   7.127 +  {
   7.128 +    KeSetEvent(event, IO_NO_INCREMENT, FALSE);
   7.129 +  }
   7.130 +
   7.131 +//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   7.132 +
   7.133 +  return STATUS_MORE_PROCESSING_REQUIRED;
   7.134 +}
   7.135 +
   7.136 +static NTSTATUS
   7.137 +XenConfig_SendAndWaitForIrp(PDEVICE_OBJECT device_object, PIRP irp)
   7.138 +{
   7.139 +  NTSTATUS status;
   7.140 +  PXENCONFIG_DEVICE_DATA xcdd = (PXENCONFIG_DEVICE_DATA)device_object->DeviceExtension;
   7.141 +  KEVENT event;
   7.142 +
   7.143 +  UNREFERENCED_PARAMETER(device_object);
   7.144 +
   7.145 +//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.146 +
   7.147 +  KeInitializeEvent(&event, NotificationEvent, FALSE);
   7.148 +
   7.149 +  IoCopyCurrentIrpStackLocationToNext(irp);
   7.150 +  IoSetCompletionRoutine(irp, XenConfig_Pnp_IoCompletion, &event, TRUE, TRUE, TRUE);
   7.151 +
   7.152 +  status = IoCallDriver(xcdd->lower_do, irp);
   7.153 +
   7.154 +  if (status == STATUS_PENDING)
   7.155 +  {
   7.156 +//    KdPrint((__DRIVER_NAME "     waiting ...\n"));
   7.157 +    KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
   7.158 +//    KdPrint((__DRIVER_NAME "     ... done\n"));
   7.159 +    status = irp->IoStatus.Status;
   7.160 +  }
   7.161 +
   7.162 +//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   7.163 +
   7.164 +  return status;
   7.165 +}
   7.166 +
   7.167 +static VOID
   7.168 +XenConfig_Pnp_StartDeviceCallback(PDEVICE_OBJECT device_object, PVOID context)
   7.169 +{
   7.170 +  NTSTATUS status = STATUS_SUCCESS;
   7.171 +  PXENCONFIG_DEVICE_DATA xcdd = device_object->DeviceExtension;
   7.172 +  PIRP irp = context;
   7.173 +
   7.174 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.175 +  
   7.176 +  irp->IoStatus.Status = status;
   7.177 +  
   7.178 +  IoCompleteRequest(irp, IO_NO_INCREMENT);
   7.179 +
   7.180 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   7.181 +}
   7.182 +
   7.183 +static PMDL
   7.184 +XenConfig_MakeConfigPage(PDEVICE_OBJECT device_object)
   7.185 +{
   7.186 +  NTSTATUS status;
   7.187 +  PXENCONFIG_DEVICE_DATA xcdd = (PXENCONFIG_DEVICE_DATA)device_object->DeviceExtension;
   7.188 +  HANDLE hwkey_handle, xenkey_handle, confkey_handle;
   7.189 +  ULONG length;
   7.190 +  PKEY_BASIC_INFORMATION key_info;
   7.191 +  PKEY_VALUE_PARTIAL_INFORMATION type_info;
   7.192 +  PKEY_VALUE_PARTIAL_INFORMATION value_info;
   7.193 +  UNICODE_STRING xenkey_name, confkey_name;
   7.194 +  UNICODE_STRING type_name, value_name;
   7.195 +  UNICODE_STRING tmp_unicode_string;
   7.196 +  //UNICODE_STRING typekey_value, valuekey_value;
   7.197 +  //UNICODE_STRING value_value;
   7.198 +  OBJECT_ATTRIBUTES oa;
   7.199 +  ULONG info_length = 1000;
   7.200 +  PMDL mdl;
   7.201 +  UCHAR type;
   7.202 +  ANSI_STRING setting;
   7.203 +  ANSI_STRING value;
   7.204 +  PUCHAR ptr;
   7.205 +  int i;
   7.206 +
   7.207 +  status = IoOpenDeviceRegistryKey(xcdd->pdo, PLUGPLAY_REGKEY_DEVICE, KEY_READ, &hwkey_handle);
   7.208 +
   7.209 +  if (!NT_SUCCESS(status))
   7.210 +  {
   7.211 +    KdPrint((__DRIVER_NAME "    cannot get hardware key\n"));
   7.212 +    return NULL;
   7.213 +  }
   7.214 +  RtlInitUnicodeString(&xenkey_name, L"XenConfig");
   7.215 +  InitializeObjectAttributes(&oa, &xenkey_name, 0, hwkey_handle, NULL);
   7.216 +  status = ZwOpenKey(&xenkey_handle, KEY_READ, &oa);
   7.217 +  if (!NT_SUCCESS(status))
   7.218 +  {
   7.219 +    // close key_handle
   7.220 +    KdPrint((__DRIVER_NAME "    cannot get XenConfig key\n"));
   7.221 +    return NULL;
   7.222 +  }
   7.223 +  // XenConfig key exists, so we go ahead and make fake memory resources
   7.224 +  mdl = AllocateUncachedPage();
   7.225 +  ptr = MmGetMdlVirtualAddress(mdl);
   7.226 +  RtlInitUnicodeString(&type_name, L"type");
   7.227 +  RtlInitUnicodeString(&value_name, L"value");
   7.228 +  key_info = ExAllocatePoolWithTag(PagedPool, info_length, XENCONFIG_POOL_TAG);
   7.229 +  type_info = ExAllocatePoolWithTag(PagedPool, info_length, XENCONFIG_POOL_TAG);
   7.230 +  value_info = ExAllocatePoolWithTag(PagedPool, info_length, XENCONFIG_POOL_TAG);
   7.231 +  //value.Buffer = ExAllocatePoolWithTag(PagedPool, info_length, XENCONFIG_POOL_TAG);
   7.232 +  //value.MaximumLength = info_length;
   7.233 +  setting.Buffer = ExAllocatePoolWithTag(PagedPool, info_length, XENCONFIG_POOL_TAG);
   7.234 +  setting.MaximumLength = (USHORT)info_length;
   7.235 +  
   7.236 +  for (i = 0; ZwEnumerateKey(xenkey_handle, i, KeyBasicInformation, key_info, info_length, &length) == STATUS_SUCCESS; i++)
   7.237 +  {
   7.238 +    confkey_name.Length = (USHORT)key_info->NameLength;
   7.239 +    confkey_name.MaximumLength = (USHORT)key_info->NameLength;
   7.240 +    confkey_name.Buffer = key_info->Name;
   7.241 +    RtlUnicodeStringToAnsiString(&setting, &confkey_name, FALSE);
   7.242 +    setting.Buffer[setting.Length] = 0;
   7.243 +    KdPrint((__DRIVER_NAME "     config key name = '%wZ'\n", &confkey_name));
   7.244 +    InitializeObjectAttributes(&oa, &confkey_name, 0, xenkey_handle, NULL);
   7.245 +    status = ZwOpenKey(&confkey_handle, KEY_READ, &oa);
   7.246 +    if (!NT_SUCCESS(status))
   7.247 +    {
   7.248 +      KdPrint((__DRIVER_NAME "    cannot get handle for XenConfig\\%wZ\n", &confkey_name));
   7.249 +      continue;
   7.250 +    }
   7.251 +    
   7.252 +    status = ZwQueryValueKey(confkey_handle, &type_name, KeyValuePartialInformation, type_info, info_length, &length);
   7.253 +    // make sure type is dword
   7.254 +    type = (UCHAR)*(ULONG *)type_info->Data;
   7.255 +    status = ZwQueryValueKey(confkey_handle, &value_name, KeyValuePartialInformation, value_info, info_length, &length);
   7.256 +    if (!NT_SUCCESS(status))
   7.257 +    {
   7.258 +      ADD_XEN_INIT_REQ(&ptr, type, setting.Buffer, NULL);
   7.259 +    }
   7.260 +    else
   7.261 +    {
   7.262 +      switch(value_info->Type)
   7.263 +      {
   7.264 +      case REG_DWORD:
   7.265 +        ADD_XEN_INIT_REQ(&ptr, type, setting.Buffer, UlongToPtr(*(PULONG)value_info->Data));
   7.266 +        break;
   7.267 +        
   7.268 +      case REG_SZ:
   7.269 +        tmp_unicode_string.Length = (USHORT)value_info->DataLength;
   7.270 +        tmp_unicode_string.MaximumLength = (USHORT)value_info->DataLength;
   7.271 +        tmp_unicode_string.Buffer = (PWCHAR)value_info->Data;
   7.272 +        RtlUnicodeStringToAnsiString(&value, &tmp_unicode_string, FALSE);
   7.273 +        value.Buffer[value.Length] = 0;
   7.274 +        ADD_XEN_INIT_REQ(&ptr, type, setting.Buffer, value.Buffer);
   7.275 +        break;
   7.276 +      
   7.277 +      default:
   7.278 +        // report error here
   7.279 +        break;
   7.280 +      }
   7.281 +    }
   7.282 +  }
   7.283 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);          
   7.284 +
   7.285 +  ExFreePoolWithTag(key_info, XENCONFIG_POOL_TAG);
   7.286 +
   7.287 +  return mdl;
   7.288 +}
   7.289 +
   7.290 +static NTSTATUS
   7.291 +XenConfig_QueueWorkItem(PDEVICE_OBJECT device_object, PIO_WORKITEM_ROUTINE routine, PVOID context)
   7.292 +{
   7.293 +  PIO_WORKITEM work_item;
   7.294 +  NTSTATUS status = STATUS_SUCCESS;
   7.295 +
   7.296 +	work_item = IoAllocateWorkItem(device_object);
   7.297 +	IoQueueWorkItem(work_item, routine, DelayedWorkQueue, context);
   7.298 +	
   7.299 +  return status;
   7.300 +}
   7.301 +
   7.302 +static NTSTATUS
   7.303 +XenConfig_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
   7.304 +{
   7.305 +  NTSTATUS status;
   7.306 +  PXENCONFIG_DEVICE_DATA xcdd = (PXENCONFIG_DEVICE_DATA)device_object->DeviceExtension;
   7.307 +  PIO_STACK_LOCATION stack;
   7.308 +  PMDL mdl;
   7.309 +  PCM_RESOURCE_LIST old_crl, new_crl;
   7.310 +  PCM_PARTIAL_RESOURCE_LIST prl;
   7.311 +  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
   7.312 +  ULONG old_length, new_length;
   7.313 +
   7.314 +  UNREFERENCED_PARAMETER(device_object);
   7.315 +
   7.316 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.317 +
   7.318 +  stack = IoGetCurrentIrpStackLocation(irp);
   7.319 +
   7.320 +  if ((mdl = XenConfig_MakeConfigPage(device_object)) != NULL)
   7.321 +  {
   7.322 +    old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   7.323 +    old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
   7.324 +      FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
   7.325 +      FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
   7.326 +      sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
   7.327 +    new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
   7.328 +    new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENCONFIG_POOL_TAG);
   7.329 +    memcpy(new_crl, old_crl, old_length);
   7.330 +    prl = &new_crl->List[0].PartialResourceList;
   7.331 +    prd = &prl->PartialDescriptors[prl->Count++];
   7.332 +    prd->Type = CmResourceTypeMemory;
   7.333 +    prd->ShareDisposition = CmResourceShareDeviceExclusive;
   7.334 +    prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
   7.335 +    KdPrint((__DRIVER_NAME "     PFN[0] = %p\n", MmGetMdlPfnArray(mdl)[0]));
   7.336 +    prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
   7.337 +    prd->u.Memory.Length = PAGE_SIZE;
   7.338 +    KdPrint((__DRIVER_NAME "     Start = %08x:%08x, Length = %d\n", prd->u.Memory.Start.HighPart, prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
   7.339 +    stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
   7.340 +
   7.341 +    old_crl = stack->Parameters.StartDevice.AllocatedResources;
   7.342 +    new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENCONFIG_POOL_TAG);
   7.343 +    memcpy(new_crl, old_crl, old_length);
   7.344 +    prl = &new_crl->List[0].PartialResourceList;
   7.345 +    prd = &prl->PartialDescriptors[prl->Count++];
   7.346 +    prd->Type = CmResourceTypeMemory;
   7.347 +    prd->ShareDisposition = CmResourceShareDeviceExclusive;
   7.348 +    prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
   7.349 +    prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
   7.350 +    prd->u.Memory.Length = PAGE_SIZE;
   7.351 +    stack->Parameters.StartDevice.AllocatedResources = new_crl;
   7.352 +
   7.353 +    // free the original resource lists???
   7.354 +  }
   7.355 +
   7.356 +  IoMarkIrpPending(irp);
   7.357 +  status = XenConfig_SendAndWaitForIrp(device_object, irp);
   7.358 +
   7.359 +  XenConfig_QueueWorkItem(device_object, XenConfig_Pnp_StartDeviceCallback, irp);
   7.360 +
   7.361 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   7.362 +  
   7.363 +  return STATUS_PENDING;
   7.364 +}
   7.365 +
   7.366 +static NTSTATUS
   7.367 +XenConfig_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
   7.368 +{
   7.369 +  NTSTATUS status = STATUS_SUCCESS;
   7.370 +  PIO_STACK_LOCATION stack;
   7.371 +  PXENCONFIG_DEVICE_DATA xcdd = (PXENCONFIG_DEVICE_DATA)device_object->DeviceExtension;
   7.372 +
   7.373 +//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   7.374 +
   7.375 +  stack = IoGetCurrentIrpStackLocation(irp);
   7.376 +
   7.377 +  switch (stack->MinorFunction) {
   7.378 +  case IRP_MN_START_DEVICE:
   7.379 +    return XenConfig_Pnp_StartDevice(device_object, irp);
   7.380 +  case IRP_MN_QUERY_CAPABILITIES:
   7.381 +//    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_CAPABILITIES\n"));
   7.382 +    stack->Parameters.DeviceCapabilities.Capabilities->NoDisplayInUI = 1;
   7.383 +    status = XenConfig_SendAndWaitForIrp(device_object, irp);
   7.384 +    status = irp->IoStatus.Status = STATUS_SUCCESS;
   7.385 +    IoCompleteRequest(irp, IO_NO_INCREMENT);
   7.386 +//    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   7.387 +    return status;
   7.388 +  default:
   7.389 +    IoSkipCurrentIrpStackLocation(irp);
   7.390 +    status = IoCallDriver(xcdd->lower_do, irp);
   7.391 +    break;
   7.392 +  }
   7.393 +
   7.394 +//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", status));
   7.395 +
   7.396 +  return status;
   7.397 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/xenconfig/xenconfig.h	Fri Jun 13 14:16:50 2008 +1000
     8.3 @@ -0,0 +1,45 @@
     8.4 +/*
     8.5 +PV Drivers for Windows Xen HVM Domains
     8.6 +Copyright (C) 2007 James Harper
     8.7 +
     8.8 +This program is free software; you can redistribute it and/or
     8.9 +modify it under the terms of the GNU General Public License
    8.10 +as published by the Free Software Foundation; either version 2
    8.11 +of the License, or (at your option) any later version.
    8.12 +
    8.13 +This program is distributed in the hope that it will be useful,
    8.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.16 +GNU General Public License for more details.
    8.17 +
    8.18 +You should have received a copy of the GNU General Public License
    8.19 +along with this program; if not, write to the Free Software
    8.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    8.21 +*/
    8.22 +
    8.23 +#if !defined(_XENCONFIG_H_)
    8.24 +#define _XENCONFIG_H_
    8.25 +
    8.26 +#include <ntddk.h>
    8.27 +#include <wdm.h>
    8.28 +#include <initguid.h>
    8.29 +#include <wdmguid.h>
    8.30 +#include <errno.h>
    8.31 +#define NTSTRSAFE_LIB
    8.32 +#include <ntstrsafe.h>
    8.33 +#define __DRIVER_NAME "XenConfig"
    8.34 +#include <xen_windows.h>
    8.35 +#include <xen_public.h>
    8.36 +
    8.37 +#define XENCONFIG_POOL_TAG (ULONG) 'XenC'
    8.38 +
    8.39 +typedef struct
    8.40 +{
    8.41 +  PDEVICE_OBJECT filter_do;
    8.42 +  PDEVICE_OBJECT pdo;
    8.43 +  PDEVICE_OBJECT lower_do;
    8.44 +
    8.45 +  PMDL config_mdl;
    8.46 +} XENCONFIG_DEVICE_DATA, *PXENCONFIG_DEVICE_DATA;
    8.47 +
    8.48 +#endif
     9.1 --- a/xenpci/xenpci_fdo.c	Wed Jun 11 21:24:57 2008 +1000
     9.2 +++ b/xenpci/xenpci_fdo.c	Fri Jun 13 14:16:50 2008 +1000
     9.3 @@ -180,13 +180,13 @@ XenPci_Pnp_IoCompletion(PDEVICE_OBJECT d
     9.4  static NTSTATUS
     9.5  XenPci_QueueWorkItem(PDEVICE_OBJECT device_object, PIO_WORKITEM_ROUTINE routine, PVOID context)
     9.6  {
     9.7 -    PIO_WORKITEM work_item;
     9.8 -    NTSTATUS status = STATUS_SUCCESS;
     9.9 +  PIO_WORKITEM work_item;
    9.10 +  NTSTATUS status = STATUS_SUCCESS;
    9.11  
    9.12  	work_item = IoAllocateWorkItem(device_object);
    9.13  	IoQueueWorkItem(work_item, routine, DelayedWorkQueue, context);
    9.14  	
    9.15 -    return status;
    9.16 +  return status;
    9.17  }
    9.18  
    9.19  static NTSTATUS
    10.1 --- a/xenpci/xenpci_pdo.c	Wed Jun 11 21:24:57 2008 +1000
    10.2 +++ b/xenpci/xenpci_pdo.c	Fri Jun 13 14:16:50 2008 +1000
    10.3 @@ -403,82 +403,6 @@ XenPci_Remap_Page(PXENPCI_DEVICE_DATA xp
    10.4  }
    10.5  #endif
    10.6  
    10.7 -    
    10.8 -static PMDL
    10.9 -XenPci_MakeConfigPage(PDEVICE_OBJECT device_object)
   10.10 -{
   10.11 -#if 0
   10.12 -  NTSTATUS status;
   10.13 -  PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
   10.14 -  HANDLE hwkey_handle, xenkey_handle, confkey_handle;
   10.15 -  ULONG length;
   10.16 -  PKEY_BASIC_INFORMATION key_info;
   10.17 -  PKEY_VALUE_FULL_INFORMATION value_info;
   10.18 -  UNICODE_STRING xenkey_name, confkey_name;
   10.19 -  UNICODE_STRING value_name;
   10.20 -  PWCHAR value_value;
   10.21 -  //UNICODE_STRING typekey_value, valuekey_value;
   10.22 -  //UNICODE_STRING value_value;
   10.23 -  OBJECT_ATTRIBUTES oa;
   10.24 -  ULONG info_length = 1000;
   10.25 -  PMDL mdl;
   10.26 -  UCHAR type;
   10.27 -  int i, j;
   10.28 -
   10.29 -  status = IoOpenDeviceRegistryKey(device_object, PLUGPLAY_REGKEY_DEVICE, KEY_READ, &hwkey_handle);
   10.30 -
   10.31 -  if (!NT_SUCCESS(status))
   10.32 -  {
   10.33 -    KdPrint((__DRIVER_NAME "    cannot get hardware key\n"));
   10.34 -    return NULL;
   10.35 -  }
   10.36 -  RtlInitUnicodeString(&xenkey_name, L"XenConfig");
   10.37 -  InitializeObjectAttributes(&oa, &xenkey_name, 0, hwkey_handle, NULL);
   10.38 -  status = ZwOpenKey(&xenkey_handle, KEY_READ, &oa);
   10.39 -  if (!NT_SUCCESS(status))
   10.40 -  {
   10.41 -    // close key_handle
   10.42 -    KdPrint((__DRIVER_NAME "    cannot get XenConfig key\n"));
   10.43 -    return NULL;
   10.44 -  }
   10.45 -  // XenConfig key exists, so we go ahead and make fake memory resources
   10.46 -  mdl = AllocateUncachedPage();
   10.47 -  //RtlInitUnicodeString(&typekey_name, "type");
   10.48 -  //RtlInitUnicodeString(&valuekey_name, "value");
   10.49 -  key_info = value_info = ExAllocatePoolWithTag(PagedPool, info_length, XENPCI_POOL_TAG);
   10.50 -  for (i = 0; ZwEnumerateKey(xenkey_handle, i, KeyBasicInformation, key_info, info_length, &length) == STATUS_SUCCESS; i++)
   10.51 -  {
   10.52 -    confkey_name.Length = (USHORT)key_info->NameLength;
   10.53 -    confkey_name.MaximumLength = (USHORT)key_info->NameLength;
   10.54 -    confkey_name.Buffer = key_info->Name;
   10.55 -    KdPrint((__DRIVER_NAME "     config key name = '%wZ'\n", &confkey_name));
   10.56 -    InitializeObjectAttributes(&oa, &confkey_name, 0, xenkey_handle, NULL);
   10.57 -    status = ZwOpenKey(&confkey_handle, KEY_READ, &oa);
   10.58 -    if (!NT_SUCCESS(status))
   10.59 -    {
   10.60 -      KdPrint((__DRIVER_NAME "    cannot get handle for XenConfig\\%wZ\n", &confkey_name));
   10.61 -      continue;
   10.62 -    }
   10.63 -    for (j = 0; ZwEnumerateValueKey(confkey_handle, j, KeyValueFullInformation, value_info, info_length, &length) == STATUS_SUCCESS; j++)
   10.64 -    {
   10.65 -      value_name.Length = confkey_name.MaximumLength = (USHORT)value_info->NameLength;
   10.66 -      value_name.Buffer = value_info->Name;
   10.67 -      KdPrint((__DRIVER_NAME "      name = '%wZ'\n", &value_name));
   10.68 -      if (value_info->Type != REG_SZ)
   10.69 -      {
   10.70 -        KdPrint((__DRIVER_NAME "      type is not REG_SZ (is %d)\n", value_info->Type));
   10.71 -        continue;
   10.72 -      }
   10.73 -      value_value = (PWCHAR)(((PUCHAR)value_info) + value_info->DataOffset);
   10.74 -      KdPrint((__DRIVER_NAME "      value = '%ws'\n", value_value));
   10.75 -    }
   10.76 -  }
   10.77 -  ExFreePoolWithTag(key_info, XENPCI_POOL_TAG);
   10.78 -#endif
   10.79 -
   10.80 -  return NULL;
   10.81 -}
   10.82 -
   10.83  static NTSTATUS
   10.84  XenPci_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
   10.85  {
   10.86 @@ -531,6 +455,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
   10.87    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
   10.88    XenBus_AddWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
   10.89  
   10.90 +#if 0
   10.91    has_config_page = FALSE;
   10.92    res_list = &stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
   10.93    for (i = 0; i < res_list->Count; i++)
   10.94 @@ -542,42 +467,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
   10.95        break;
   10.96      }
   10.97    }
   10.98 -
   10.99 -  if (!has_config_page && (mdl = XenPci_MakeConfigPage(device_object)) != NULL)
  10.100 -  {
  10.101 -    old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
  10.102 -    old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
  10.103 -      FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
  10.104 -      FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
  10.105 -      sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
  10.106 -    new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
  10.107 -    new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENPCI_POOL_TAG);
  10.108 -    memcpy(new_crl, old_crl, old_length);
  10.109 -    prl = &new_crl->List[0].PartialResourceList;
  10.110 -    prd = &prl->PartialDescriptors[prl->Count++];
  10.111 -    prd->Type = CmResourceTypeMemory;
  10.112 -    prd->ShareDisposition = CmResourceShareDeviceExclusive;
  10.113 -    prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
  10.114 -    KdPrint((__DRIVER_NAME "     PFN[0] = %p\n", MmGetMdlPfnArray(mdl)[0]));
  10.115 -    prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
  10.116 -    prd->u.Memory.Length = PAGE_SIZE;
  10.117 -    KdPrint((__DRIVER_NAME "     Start = %08x:%08x, Length = %d\n", prd->u.Memory.Start.HighPart, prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
  10.118 -    stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
  10.119 -
  10.120 -    old_crl = stack->Parameters.StartDevice.AllocatedResources;
  10.121 -    new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENPCI_POOL_TAG);
  10.122 -    memcpy(new_crl, old_crl, old_length);
  10.123 -    prl = &new_crl->List[0].PartialResourceList;
  10.124 -    prd = &prl->PartialDescriptors[prl->Count++];
  10.125 -    prd->Type = CmResourceTypeMemory;
  10.126 -    prd->ShareDisposition = CmResourceShareDeviceExclusive;
  10.127 -    prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
  10.128 -    prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
  10.129 -    prd->u.Memory.Length = PAGE_SIZE;
  10.130 -    stack->Parameters.StartDevice.AllocatedResources = new_crl;
  10.131 -    
  10.132 -    // free the original resource lists???
  10.133 -  }
  10.134 +#endif
  10.135  
  10.136    res_list = &stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList;
  10.137    for (i = 0; i < res_list->Count; i++)
  10.138 @@ -741,10 +631,10 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  10.139            ADD_XEN_INIT_RSP(&out_ptr, type, NULL, &vectors);
  10.140            break;
  10.141          case XEN_INIT_TYPE_GRANT_ENTRIES:
  10.142 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
  10.143 +          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(value)));
  10.144            __ADD_XEN_INIT_UCHAR(&out_ptr, type);
  10.145 -          __ADD_XEN_INIT_ULONG(&out_ptr, PtrToUlong(setting));
  10.146 -          for (i = 0; i < PtrToUlong(setting); i++)
  10.147 +          __ADD_XEN_INIT_ULONG(&out_ptr, PtrToUlong(value));
  10.148 +          for (i = 0; i < PtrToUlong(value); i++)
  10.149              __ADD_XEN_INIT_ULONG(&out_ptr, GntTbl_GetRef(xpdd));
  10.150            break;
  10.151          }
  10.152 @@ -826,7 +716,7 @@ XenPci_Pnp_RemoveDevice(PDEVICE_OBJECT d
  10.153  static NTSTATUS
  10.154  XenPci_QueryResourceRequirements(PDEVICE_OBJECT device_object, PIRP irp)
  10.155  {
  10.156 -  PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
  10.157 +  //PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
  10.158    //PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  10.159    PIO_RESOURCE_REQUIREMENTS_LIST irrl;
  10.160    PIO_RESOURCE_DESCRIPTOR ird;
    11.1 --- a/xenvbd/scsiport.c	Wed Jun 11 21:24:57 2008 +1000
    11.2 +++ b/xenvbd/scsiport.c	Fri Jun 13 14:16:50 2008 +1000
    11.3 @@ -221,17 +221,9 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
    11.4        break;
    11.5      case XEN_INIT_TYPE_GRANT_ENTRIES:
    11.6        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
    11.7 -      if (PtrToUlong(setting) != GRANT_ENTRIES)
    11.8 -      {
    11.9 -        KdPrint((__DRIVER_NAME "     grant entries mismatch\n"));
   11.10 -        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   11.11 -        return SP_RETURN_BAD_CONFIG;
   11.12 -      }
   11.13 -      else
   11.14 -      {
   11.15 -        memcpy(&xvdd->grant_free_list, value, sizeof(ULONG) * PtrToUlong(setting));
   11.16 -        xvdd->grant_free = GRANT_ENTRIES;
   11.17 -      }
   11.18 +      xvdd->grant_entries = (USHORT)PtrToUlong(setting);
   11.19 +      memcpy(&xvdd->grant_free_list, value, sizeof(grant_ref_t) * xvdd->grant_entries);
   11.20 +      xvdd->grant_free = xvdd->grant_entries;
   11.21        break;
   11.22      default:
   11.23        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
    12.1 --- a/xenvbd/xenvbd.c	Wed Jun 11 21:24:57 2008 +1000
    12.2 +++ b/xenvbd/xenvbd.c	Fri Jun 13 14:16:50 2008 +1000
    12.3 @@ -35,6 +35,7 @@ DRIVER_INITIALIZE DriverEntry;
    12.4  #pragma alloc_text (INIT, DriverEntry)
    12.5  #endif
    12.6  
    12.7 +#if 0
    12.8  static PDRIVER_DISPATCH XenVbd_Pnp_Original;
    12.9  
   12.10  static NTSTATUS
   12.11 @@ -60,26 +61,6 @@ XenVbd_Pnp(PDEVICE_OBJECT device_object,
   12.12    {
   12.13    case IRP_MN_START_DEVICE:
   12.14      KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
   12.15 -#if 0
   12.16 -    crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   12.17 -    prl = &crl->List[0].PartialResourceList;
   12.18 -    for (i = 0; i < prl->Count; i++)
   12.19 -    {
   12.20 -      prd = &prl->PartialDescriptors[i];
   12.21 -      if (prd->Type == CmResourceTypeMemory)
   12.22 -      {
   12.23 -        ptr = MmMapIoSpace(prd->u.Memory.Start, prd->u.Memory.Length, MmNonCached);
   12.24 -        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "ring-ref", NULL);
   12.25 -        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL);
   12.26 -        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_FRONT, "device-type", NULL);
   12.27 -        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sectors", NULL);
   12.28 -        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sector-size", NULL);
   12.29 -        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_VECTORS, NULL, NULL);
   12.30 -        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, UlongToPtr(GRANT_ENTRIES), NULL);
   12.31 -        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);        
   12.32 -      }
   12.33 -    }
   12.34 -#endif
   12.35      old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   12.36      if (old_crl != NULL)
   12.37      {
   12.38 @@ -107,7 +88,7 @@ XenVbd_Pnp(PDEVICE_OBJECT device_object,
   12.39        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sectors", NULL);
   12.40        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sector-size", NULL);
   12.41        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_VECTORS, NULL, NULL);
   12.42 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, UlongToPtr(GRANT_ENTRIES), NULL);
   12.43 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, NULL, UlongToPtr(GRANT_ENTRIES));
   12.44        ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
   12.45        
   12.46        stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
   12.47 @@ -175,6 +156,7 @@ XenVbd_Pnp(PDEVICE_OBJECT device_object,
   12.48  
   12.49    return status;
   12.50  }
   12.51 +#endif
   12.52  
   12.53  NTSTATUS
   12.54  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
   12.55 @@ -209,6 +191,8 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   12.56  
   12.57    status = ScsiPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
   12.58    
   12.59 +
   12.60 +#if 0
   12.61    /* DriverObject will be NULL if we are being called in dump mode */
   12.62    if (DriverObject != NULL)
   12.63    {
   12.64 @@ -218,6 +202,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   12.65    }
   12.66    else
   12.67      XenVbd_Pnp_Original = NULL;
   12.68 +#endif
   12.69  
   12.70    if(!NT_SUCCESS(status))
   12.71    {
    13.1 --- a/xenvbd/xenvbd.h	Wed Jun 11 21:24:57 2008 +1000
    13.2 +++ b/xenvbd/xenvbd.h	Fri Jun 13 14:16:50 2008 +1000
    13.3 @@ -81,7 +81,8 @@ typedef struct {
    13.4  } blkif_shadow_t;
    13.5  
    13.6  #define SHADOW_ENTRIES 16
    13.7 -#define GRANT_ENTRIES ((SHADOW_ENTRIES * BLKIF_MAX_SEGMENTS_PER_REQUEST) / 2)
    13.8 +//#define GRANT_ENTRIES ((SHADOW_ENTRIES * BLKIF_MAX_SEGMENTS_PER_REQUEST) / 2)
    13.9 +#define MAX_GRANT_ENTRIES 512
   13.10  
   13.11  typedef enum {
   13.12    XENVBD_DEVICETYPE_UNKNOWN,
   13.13 @@ -97,8 +98,9 @@ struct
   13.14    USHORT shadow_free;
   13.15    USHORT shadow_min_free;
   13.16  
   13.17 -  grant_ref_t grant_free_list[GRANT_ENTRIES];
   13.18 +  grant_ref_t grant_free_list[MAX_GRANT_ENTRIES];
   13.19    USHORT grant_free;
   13.20 +  USHORT grant_entries;
   13.21  
   13.22    evtchn_port_t event_channel;
   13.23    union {
    14.1 --- a/xenvbd/xenvbd.inx	Wed Jun 11 21:24:57 2008 +1000
    14.2 +++ b/xenvbd/xenvbd.inx	Fri Jun 13 14:16:50 2008 +1000
    14.3 @@ -54,20 +54,45 @@ HKR,,EventMessageFile,0x00020000,"%Syste
    14.4  HKR,,TypesSupported,0x00010001,7
    14.5  
    14.6  [XenVbd_Inst.NT.HW]
    14.7 -AddReg = XenVbd_XenConfig_AddReg
    14.8 +AddReg = XenVbd_XenConfig_AddReg, XenVbd_UpperFilter_AddReg
    14.9  
   14.10  [XenVbd_XenConfig_AddReg]
   14.11 -HKR,"XenConfig\ring-ref", "type", , RING
   14.12 -HKR,"XenConfig\event-channel", "type", , EVENT_CHANNEL_IRQ
   14.13 -HKR,"XenConfig\device-type", "type", , READ_STRING_FRONT
   14.14 -HKR,"XenConfig\sectors", "type", , READ_STRING_FRONT
   14.15 -HKR,"XenConfig\sector-size", "type", , READ_STRING_BACK
   14.16 -HKR,"XenConfig\vectors", "type", , VECTORS
   14.17 -HKR,"XenConfig\vectors", "type", , GRANT_ENTRIES
   14.18 -HKR,"XenConfig\vectors", "value", , 144
   14.19 +HKR,"XenConfig\ring-ref", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_RING%
   14.20 +HKR,"XenConfig\event-channel", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_EVENT_CHANNEL_IRQ%
   14.21 +HKR,"XenConfig\device-type", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_FRONT%
   14.22 +HKR,"XenConfig\sectors", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_BACK%
   14.23 +HKR,"XenConfig\sector-size", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_BACK%
   14.24 +HKR,"XenConfig\vectors", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_VECTORS%
   14.25 +HKR,"XenConfig\grants", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_GRANT_ENTRIES%
   14.26 +HKR,"XenConfig\grants", "value", %FLG_ADDREG_TYPE_DWORD%, 144
   14.27 +
   14.28 +[XenVbd_UpperFilter_AddReg]
   14.29 +HKR,,UpperFilters,0x10000,XenConfig
   14.30 +
   14.31 +[XenConfig_Inst.NT.HW]
   14.32 +CopyFiles=XenConfig.CopyFiles
   14.33 +
   14.34 +[XenConfig.CopyFiles]
   14.35 +xenconfig.sys
   14.36 +
   14.37 +[XenConfig_Inst.NT.Services]
   14.38 +AddService=XenConfig,0,XenConfig_Service
   14.39 +
   14.40 +[XenConfig_Service]
   14.41 +DisplayName    = %XenConfig.SVCDESC%                            
   14.42 +ServiceType    = 1
   14.43 +StartType      = 0
   14.44 +ErrorControl   = 1
   14.45 +LoadOrderGroup = System Bus Extender
   14.46 +ServiceBinary  = %12%\xenconfig.sys                            
   14.47 +AddReg = XenConfig_Service_AddReg
   14.48 +
   14.49 +[XenConfig_Service_AddReg]
   14.50 +HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
   14.51  
   14.52  [SourceDisksFiles]
   14.53  xenvbd.sys=1
   14.54 +xenconfig.sys=1
   14.55  
   14.56  [SourceDisksNames.x86]
   14.57  1 = %DISK_NAME%,,,.\i386
   14.58 @@ -79,4 +104,16 @@ 1 = %DISK_NAME%,,,.\amd64
   14.59  XenGplPv = "Xen GPL PV Driver Developers"
   14.60  XenVbd.SVCDESC = "Xen Block Device Driver"
   14.61  XenVbd.DRVDESC = "Xen Block Device Driver"
   14.62 +XenConfig.DRVDESC = "Xen Config Resource Generator"
   14.63  DISK_NAME = "Xen Block Device Driver Install Disk"
   14.64 +FLG_ADDREG_TYPE_DWORD = 0x00010001
   14.65 +XEN_INIT_TYPE_END = 0
   14.66 +XEN_INIT_TYPE_WRITE_STRING = 1
   14.67 +XEN_INIT_TYPE_RING = 2
   14.68 +XEN_INIT_TYPE_EVENT_CHANNEL = 3
   14.69 +XEN_INIT_TYPE_EVENT_CHANNEL_IRQ = 4
   14.70 +XEN_INIT_TYPE_READ_STRING_FRONT = 5
   14.71 +XEN_INIT_TYPE_READ_STRING_BACK = 6
   14.72 +XEN_INIT_TYPE_VECTORS = 7
   14.73 +XEN_INIT_TYPE_GRANT_ENTRIES = 8
   14.74 +XEN_INIT_TYPE_COPY_PTR = 9