win-pvdrivers

changeset 314:a55d72ac422f

updates to the whole xenconfig thing to allow xennet to dynamically config. Almost there.
Created some bat files to do the signing.
author James Harper <james.harper@bendigoit.com.au>
date Tue Jun 17 10:35:26 2008 +1000 (2008-06-17)
parents ec53700c0df4
children a37206f28587
files common.inc common/include/xen_public.h common/include/xen_windows.h installer.nsi makedist.bat sign_config.bat.template sign_inf.bat sign_sys.bat xenconfig/xenconfig.c xennet/xennet.c xennet/xennet.h xennet/xennet.inx xenpci/xenpci.h xenpci/xenpci_pdo.c xenscsi/scsiport.c xenscsi/xenscsi.c xenscsi/xenscsi.h xenscsi/xenscsi.inx xenvbd/xenvbd.h xenvbd/xenvbd.inx
line diff
     1.1 --- a/common.inc	Sat Jun 14 23:16:49 2008 +1000
     1.2 +++ b/common.inc	Tue Jun 17 10:35:26 2008 +1000
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.9.9.0
     1.5 +VERSION=0.9.9.2
     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	Sat Jun 14 23:16:49 2008 +1000
     2.2 +++ b/common/include/xen_public.h	Tue Jun 17 10:35:26 2008 +1000
     2.3 @@ -91,47 +91,10 @@ typedef char *
     2.4  (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
     2.5  
     2.6  typedef NTSTATUS
     2.7 -(*PXEN_XENPCI_SHUTDOWN_DEVICE)(PVOID Context);
     2.8 -
     2.9 -#if 0
    2.10 -typedef struct _XEN_IFACE {
    2.11 -  INTERFACE InterfaceHeader;
    2.12 -
    2.13 -  PXEN_ALLOCMMIO AllocMMIO;
    2.14 -  PXEN_FREEMEM FreeMem;
    2.15 -
    2.16 -  PXEN_EVTCHN_BIND EvtChn_Bind;
    2.17 -  PXEN_EVTCHN_UNBIND EvtChn_Unbind;
    2.18 -  PXEN_EVTCHN_MASK EvtChn_Mask;
    2.19 -  PXEN_EVTCHN_UNMASK EvtChn_Unmask;
    2.20 -  PXEN_EVTCHN_NOTIFY EvtChn_Notify;
    2.21 -  PXEN_EVTCHN_ALLOCUNBOUND EvtChn_AllocUnbound;
    2.22 -  PXEN_EVTCHN_BIND EvtChn_BindDpc;
    2.23 +(*PXEN_XENPCI_XEN_CONFIG_DEVICE)(PVOID Context);
    2.24  
    2.25 -  PXEN_GNTTBL_GETREF GntTbl_GetRef;
    2.26 -  PXEN_GNTTBL_PUTREF GntTbl_PutRef;
    2.27 -  PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
    2.28 -  PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
    2.29 -
    2.30 -  PXEN_XENBUS_READ XenBus_Read;
    2.31 -  PXEN_XENBUS_WRITE XenBus_Write;
    2.32 -  PXEN_XENBUS_PRINTF XenBus_Printf;
    2.33 -  PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
    2.34 -  PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
    2.35 -  PXEN_XENBUS_LIST XenBus_List;
    2.36 -  PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
    2.37 -  PXEN_XENBUS_REMWATCH XenBus_RemWatch;
    2.38 -} XEN_IFACE, *PXEN_IFACE;
    2.39 -
    2.40 -typedef struct _XENPCI_IDENTIFICATION_DESCRIPTION
    2.41 -{
    2.42 -  WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER Header;
    2.43 -  char DeviceType[128]; //UNICODE_STRING DeviceType;
    2.44 -  char Path[128];
    2.45 -  ULONG DeviceIndex;
    2.46 -} XENPCI_IDENTIFICATION_DESCRIPTION, *PXENPCI_IDENTIFICATION_DESCRIPTION;
    2.47 -#endif
    2.48 -
    2.49 +typedef NTSTATUS
    2.50 +(*PXEN_XENPCI_XEN_SHUTDOWN_DEVICE)(PVOID Context);
    2.51  
    2.52  #define XEN_DATA_MAGIC 0x12345678
    2.53  
    2.54 @@ -150,7 +113,8 @@ typedef struct {
    2.55    PXEN_GNTTBL_PUTREF GntTbl_PutRef;
    2.56    PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
    2.57    PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
    2.58 -  PXEN_XENPCI_SHUTDOWN_DEVICE XenPci_ShutdownDevice;
    2.59 +  PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
    2.60 +  PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
    2.61  } XENPCI_VECTORS, *PXENPCI_VECTORS;
    2.62  
    2.63  
    2.64 @@ -163,7 +127,8 @@ typedef struct {
    2.65  #define XEN_INIT_TYPE_READ_STRING_BACK  6
    2.66  #define XEN_INIT_TYPE_VECTORS           7
    2.67  #define XEN_INIT_TYPE_GRANT_ENTRIES     8
    2.68 -#define XEN_INIT_TYPE_COPY_PTR          9
    2.69 +//#define XEN_INIT_TYPE_COPY_PTR          9
    2.70 +#define XEN_INIT_TYPE_RUN               10
    2.71  
    2.72  static __inline VOID
    2.73  __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
    2.74 @@ -201,9 +166,7 @@ static __inline VOID
    2.75  __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
    2.76  {
    2.77    KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
    2.78 -  //RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
    2.79 -  // using strcpy instead of above needed for mingw32
    2.80 -  strcpy((char *)*ptr, val);
    2.81 +  RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
    2.82    *ptr += strlen(val) + 1;
    2.83  }
    2.84  
    2.85 @@ -265,6 +228,7 @@ ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type
    2.86    {
    2.87    case XEN_INIT_TYPE_END:
    2.88    case XEN_INIT_TYPE_VECTORS:
    2.89 +  case XEN_INIT_TYPE_RUN:
    2.90      break;
    2.91    case XEN_INIT_TYPE_WRITE_STRING:
    2.92      __ADD_XEN_INIT_STRING(ptr, p1);
    2.93 @@ -280,9 +244,9 @@ ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type
    2.94    case XEN_INIT_TYPE_GRANT_ENTRIES:
    2.95      __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
    2.96      break;
    2.97 -  case XEN_INIT_TYPE_COPY_PTR:
    2.98 -    __ADD_XEN_INIT_STRING(ptr, p1);
    2.99 -    __ADD_XEN_INIT_PTR(ptr, p2);
   2.100 +//  case XEN_INIT_TYPE_COPY_PTR:
   2.101 +//    __ADD_XEN_INIT_STRING(ptr, p1);
   2.102 +//    __ADD_XEN_INIT_PTR(ptr, p2);
   2.103    }
   2.104  }
   2.105  
   2.106 @@ -296,6 +260,7 @@ GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1,
   2.107    {
   2.108    case XEN_INIT_TYPE_END:
   2.109    case XEN_INIT_TYPE_VECTORS:
   2.110 +  case XEN_INIT_TYPE_RUN:
   2.111      *p1 = NULL;
   2.112      *p2 = NULL;
   2.113      break;
   2.114 @@ -314,9 +279,9 @@ GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1,
   2.115    case XEN_INIT_TYPE_GRANT_ENTRIES:
   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 -    *p2 = __GET_XEN_INIT_PTR(ptr);
   2.121 +//  case XEN_INIT_TYPE_COPY_PTR:
   2.122 +//    *p1 = __GET_XEN_INIT_STRING(ptr);
   2.123 +//    *p2 = __GET_XEN_INIT_PTR(ptr);
   2.124    }
   2.125    return retval;
   2.126  }
   2.127 @@ -329,6 +294,7 @@ ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type
   2.128    {
   2.129    case XEN_INIT_TYPE_END:
   2.130    case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
   2.131 +  case XEN_INIT_TYPE_RUN:
   2.132      break;
   2.133    case XEN_INIT_TYPE_RING:
   2.134      __ADD_XEN_INIT_STRING(ptr, p1);
   2.135 @@ -354,10 +320,10 @@ ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type
   2.136      memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
   2.137      *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
   2.138      break;
   2.139 -  case XEN_INIT_TYPE_COPY_PTR:
   2.140 -    __ADD_XEN_INIT_STRING(ptr, p1);
   2.141 -    __ADD_XEN_INIT_PTR(ptr, p2);
   2.142 -    break;
   2.143 +//  case XEN_INIT_TYPE_COPY_PTR:
   2.144 +//    __ADD_XEN_INIT_STRING(ptr, p1);
   2.145 +//    __ADD_XEN_INIT_PTR(ptr, p2);
   2.146 +//    break;
   2.147    }
   2.148  }
   2.149  
   2.150 @@ -370,6 +336,7 @@ GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1,
   2.151    switch (retval)
   2.152    {
   2.153    case XEN_INIT_TYPE_END:
   2.154 +  case XEN_INIT_TYPE_RUN:
   2.155      *p1 = NULL;
   2.156      *p2 = NULL;
   2.157      break;
   2.158 @@ -403,9 +370,9 @@ GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1,
   2.159      *p2 = *ptr;
   2.160      *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
   2.161      break;
   2.162 -  case XEN_INIT_TYPE_COPY_PTR:
   2.163 -    *p1 = __GET_XEN_INIT_STRING(ptr);
   2.164 -    *p2 = __GET_XEN_INIT_PTR(ptr);
   2.165 +//  case XEN_INIT_TYPE_COPY_PTR:
   2.166 +//    *p1 = __GET_XEN_INIT_STRING(ptr);
   2.167 +//    *p2 = __GET_XEN_INIT_PTR(ptr);
   2.168    }
   2.169    return retval;
   2.170  }
     3.1 --- a/common/include/xen_windows.h	Sat Jun 14 23:16:49 2008 +1000
     3.2 +++ b/common/include/xen_windows.h	Tue Jun 17 10:35:26 2008 +1000
     3.3 @@ -35,6 +35,9 @@ typedef UINT32 uint32_t;
     3.4  typedef UINT64 uint64_t;
     3.5  #endif
     3.6  
     3.7 +#ifdef __MINGW32__
     3.8 +#define RtlStringCbCopyA(dst, dst_len, src) strncpy(dst, src, dst_len)
     3.9 +#endif
    3.10  #include <xen.h>
    3.11  
    3.12  #define _PAGE_PRESENT  0x001UL
     4.1 --- a/installer.nsi	Sat Jun 14 23:16:49 2008 +1000
     4.2 +++ b/installer.nsi	Tue Jun 17 10:35:26 2008 +1000
     4.3 @@ -3,7 +3,7 @@
     4.4  
     4.5  !define AppName "Xen PV Drivers"
     4.6  !define StartMenu "$SMPROGRAMS\${AppName}"
     4.7 -!define Version "0.9.9"
     4.8 +!define Version "0.9.10-pre1"
     4.9  #!define Version "$%VERSION%"
    4.10  Name "${AppName}"
    4.11  InstallDir "$PROGRAMFILES\${AppName}"
    4.12 @@ -75,6 +75,7 @@ Section "Windows XP" winxp
    4.13    File .\target\winxp\xenvbd.inf
    4.14    File .\target\winxp\xenscsi.inf
    4.15    File .\target\winxp\xenstub.inf
    4.16 +  File .\target\winxp\xengplpv.cat
    4.17    SetOutPath $INSTDIR\drivers\i386
    4.18    File .\target\winxp\i386\xenpci.sys
    4.19    File .\target\winxp\i386\xenhide.sys
    4.20 @@ -92,6 +93,7 @@ Section "Windows 2003 x32" win2k3x32
    4.21    File .\target\winnet\xenvbd.inf
    4.22    File .\target\winnet\xenscsi.inf
    4.23    File .\target\winnet\xenstub.inf
    4.24 +  File .\target\winnet\xengplpv.cat
    4.25    SetOutPath $INSTDIR\drivers\i386
    4.26    File .\target\winnet\i386\xenpci.sys
    4.27    File .\target\winnet\i386\xenhide.sys
    4.28 @@ -109,6 +111,7 @@ Section "Windows 2003 x64" win2k3x64
    4.29    File .\target\winnet\xenvbd.inf
    4.30    File .\target\winnet\xenscsi.inf
    4.31    File .\target\winnet\xenstub.inf
    4.32 +  File .\target\winnet\xengplpv.cat
    4.33    SetOutPath $INSTDIR\drivers\amd64
    4.34    File .\target\winnet\amd64\xenpci.sys
    4.35    File .\target\winnet\amd64\xenhide.sys
    4.36 @@ -126,6 +129,7 @@ Section "Windows 2008 x32" win2k8x32
    4.37    File .\target\winlh\xenvbd.inf
    4.38    File .\target\winlh\xenscsi.inf
    4.39    File .\target\winlh\xenstub.inf
    4.40 +  File .\target\winlh\xengplpv.cat
    4.41    SetOutPath $INSTDIR\drivers\i386
    4.42    File .\target\winlh\i386\xenpci.sys
    4.43    File .\target\winlh\i386\xenhide.sys
    4.44 @@ -143,6 +147,7 @@ Section "Windows 2008 x64" win2k8x64
    4.45    File .\target\winlh\xenvbd.inf
    4.46    File .\target\winlh\xenscsi.inf
    4.47    File .\target\winlh\xenstub.inf
    4.48 +  File .\target\winlh\xengplpv.cat
    4.49    SetOutPath $INSTDIR\drivers\amd64
    4.50    File .\target\winlh\amd64\xenpci.sys
    4.51    File .\target\winlh\amd64\xenhide.sys
     5.1 --- a/makedist.bat	Sat Jun 14 23:16:49 2008 +1000
     5.2 +++ b/makedist.bat	Tue Jun 17 10:35:26 2008 +1000
     5.3 @@ -1,12 +1,25 @@
     5.4  @echo off
     5.5 -IF NOT EXIST set_ddk_path.bat ECHO >set_ddk_path.bat SET DDK_PATH=C:\WinDDK\6001.17121
     5.6 +IF NOT EXIST set_ddk_path.bat ECHO >set_ddk_path.bat SET DDK_PATH=C:\WinDDK\6001.18001
     5.7 +
     5.8  CALL set_ddk_path.bat
     5.9  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk W2K && CD \Projects\win-pvdrivers.hg && build -cZg"
    5.10 +CALL sign_sys.bat win2k i386 2000
    5.11 +CALL sign_inf.bat win2k 2000
    5.12 +
    5.13  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WXP && CD \Projects\win-pvdrivers.hg && build -cZg"
    5.14 +CALL sign_sys.bat winxp i386 XP_X86
    5.15 +CALL sign_inf.bat winxp XP_X86
    5.16 +
    5.17  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WNET && CD \Projects\win-pvdrivers.hg && build -cZg"
    5.18 +CALL sign_sys.bat winnet i386 Server2003_X86
    5.19  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk x64 WNET && CD \Projects\win-pvdrivers.hg && build -cZg"
    5.20 +CALL sign_sys.bat winnet amd64 Server2003_X64
    5.21 +CALL sign_inf.bat winnet Server2003_X64
    5.22 +
    5.23  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk WLH && CD \Projects\win-pvdrivers.hg && build -cZg"
    5.24 +CALL sign_sys.bat winnet i386 Server2008_X86
    5.25  cmd /C "%DDK_PATH%\bin\setenv.bat %DDK_PATH%\ chk x64 WLH && CD \Projects\win-pvdrivers.hg && build -cZg"
    5.26 -rem xcopy target\* dist /E /EXCLUDE:exclude.txt /I /D /Y
    5.27 -rem copy doc\*.txt dist
    5.28 -"%ProgramFiles%\NSIS\makensis.exe" installer.nsi
    5.29 \ No newline at end of file
    5.30 +CALL sign_sys.bat winnet amd64 Server2008_X64
    5.31 +CALL sign_inf.bat winnet Server2008_X64
    5.32 +
    5.33 +"%ProgramFiles%\NSIS\makensis.exe" installer.nsi
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/sign_config.bat.template	Tue Jun 17 10:35:26 2008 +1000
     6.3 @@ -0,0 +1,2 @@
     6.4 +SET CERT_NAME=friendly name of your certificate
     6.5 +SET CA_CERT_NAME=name of your CA cert
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/sign_inf.bat	Tue Jun 17 10:35:26 2008 +1000
     7.3 @@ -0,0 +1,6 @@
     7.4 +@ECHO OFF
     7.5 +IF NOT EXIST SIGN_CONFIG.BAT GOTO DONT_SIGN
     7.6 +CALL SIGN_CONFIG.BAT
     7.7 +%DDK_PATH%\bin\selfsign\inf2cat /driver:target/%1 /os:%2
     7.8 +%DDK_PATH%\bin\selfsign\signtool sign /v /n %CERT_NAME% /t http://timestamp.verisign.com/scripts/timestamp.dll target\%1\xengplpv.cat
     7.9 +:DONT_SIGN
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/sign_sys.bat	Tue Jun 17 10:35:26 2008 +1000
     8.3 @@ -0,0 +1,5 @@
     8.4 +@ECHO OFF
     8.5 +IF NOT EXIST SIGN_CONFIG.BAT GOTO DONT_SIGN
     8.6 +CALL SIGN_CONFIG.BAT
     8.7 +%DDK_PATH%\bin\selfsign\signtool sign /v /n %CERT_NAME% /t http://timestamp.verisign.com/scripts/timestamp.dll target\%1\%2\xenhide.sys target\%1\%2\xennet.sys target\%1\%2\xenpci.sys target\%1\%2\xenvbd.sys target\%1\%2\xenstub.sys target\%1\%2\xenconfig.sys target\%1\%2\xenscsi.sys
     8.8 +:DONT_SIGN
     9.1 --- a/xenconfig/xenconfig.c	Sat Jun 14 23:16:49 2008 +1000
     9.2 +++ b/xenconfig/xenconfig.c	Tue Jun 17 10:35:26 2008 +1000
     9.3 @@ -178,8 +178,10 @@ static VOID
     9.4  XenConfig_Pnp_StartDeviceCallback(PDEVICE_OBJECT device_object, PVOID context)
     9.5  {
     9.6    NTSTATUS status = STATUS_SUCCESS;
     9.7 -  PXENCONFIG_DEVICE_DATA xcdd = device_object->DeviceExtension;
     9.8 +  //PXENCONFIG_DEVICE_DATA xcdd = device_object->DeviceExtension;
     9.9    PIRP irp = context;
    9.10 +  
    9.11 +  UNREFERENCED_PARAMETER(device_object);
    9.12  
    9.13    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    9.14    
    9.15 @@ -214,12 +216,16 @@ XenConfig_MakeConfigPage(PDEVICE_OBJECT 
    9.16    PUCHAR ptr;
    9.17    int i;
    9.18  
    9.19 +  mdl = AllocateUncachedPage();
    9.20 +  ptr = MmGetMdlVirtualAddress(mdl);
    9.21 +
    9.22    status = IoOpenDeviceRegistryKey(xcdd->pdo, PLUGPLAY_REGKEY_DEVICE, KEY_READ, &hwkey_handle);
    9.23  
    9.24    if (!NT_SUCCESS(status))
    9.25    {
    9.26      KdPrint((__DRIVER_NAME "    cannot get hardware key\n"));
    9.27 -    return NULL;
    9.28 +    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);          
    9.29 +    return mdl;
    9.30    }
    9.31    RtlInitUnicodeString(&xenkey_name, L"XenConfig");
    9.32    InitializeObjectAttributes(&oa, &xenkey_name, 0, hwkey_handle, NULL);
    9.33 @@ -228,11 +234,10 @@ XenConfig_MakeConfigPage(PDEVICE_OBJECT 
    9.34    {
    9.35      // close key_handle
    9.36      KdPrint((__DRIVER_NAME "    cannot get XenConfig key\n"));
    9.37 -    return NULL;
    9.38 +    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);          
    9.39 +    return mdl;
    9.40    }
    9.41    // XenConfig key exists, so we go ahead and make fake memory resources
    9.42 -  mdl = AllocateUncachedPage();
    9.43 -  ptr = MmGetMdlVirtualAddress(mdl);
    9.44    RtlInitUnicodeString(&type_name, L"type");
    9.45    RtlInitUnicodeString(&value_name, L"value");
    9.46    key_info = ExAllocatePoolWithTag(PagedPool, info_length, XENCONFIG_POOL_TAG);
    9.47 @@ -243,6 +248,7 @@ XenConfig_MakeConfigPage(PDEVICE_OBJECT 
    9.48    setting.Buffer = ExAllocatePoolWithTag(PagedPool, info_length, XENCONFIG_POOL_TAG);
    9.49    setting.MaximumLength = (USHORT)info_length;
    9.50    
    9.51 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RUN, NULL, NULL);
    9.52    for (i = 0; ZwEnumerateKey(xenkey_handle, i, KeyBasicInformation, key_info, info_length, &length) == STATUS_SUCCESS; i++)
    9.53    {
    9.54      confkey_name.Length = (USHORT)key_info->NameLength;
    9.55 @@ -313,7 +319,7 @@ static NTSTATUS
    9.56  XenConfig_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
    9.57  {
    9.58    NTSTATUS status;
    9.59 -  PXENCONFIG_DEVICE_DATA xcdd = (PXENCONFIG_DEVICE_DATA)device_object->DeviceExtension;
    9.60 +  //PXENCONFIG_DEVICE_DATA xcdd = (PXENCONFIG_DEVICE_DATA)device_object->DeviceExtension;
    9.61    PIO_STACK_LOCATION stack;
    9.62    PMDL mdl;
    9.63    PCM_RESOURCE_LIST old_crl, new_crl;
    10.1 --- a/xennet/xennet.c	Sat Jun 14 23:16:49 2008 +1000
    10.2 +++ b/xennet/xennet.c	Tue Jun 17 10:35:26 2008 +1000
    10.3 @@ -135,6 +135,9 @@ XenNet_Init(
    10.4    PUCHAR ptr;
    10.5    PCHAR setting, value;
    10.6    ULONG length;
    10.7 +  NDIS_HANDLE config_handle;
    10.8 +  NDIS_STRING config_param_name;
    10.9 +  PNDIS_CONFIGURATION_PARAMETER config_param;
   10.10    
   10.11    UNREFERENCED_PARAMETER(OpenErrorStatus);
   10.12  
   10.13 @@ -195,7 +198,8 @@ XenNet_Init(
   10.14    xi->config_csum = 1;
   10.15    xi->config_sg = 1;
   10.16    xi->config_gso = 61440;
   10.17 -
   10.18 +  xi->config_page = NULL;
   10.19 +  
   10.20    for (i = 0; i < nrl->Count; i++)
   10.21    {
   10.22      prd = &nrl->PartialDescriptors[i];
   10.23 @@ -209,83 +213,22 @@ XenNet_Init(
   10.24        break;
   10.25  
   10.26      case CmResourceTypeMemory:
   10.27 -      //ptr = MmMapIoSpace(prd->u.Memory.Start, prd->u.Memory.Length, MmCached);
   10.28 -      NdisMMapIoSpace(&ptr, MiniportAdapterHandle, prd->u.Memory.Start, PAGE_SIZE);
   10.29 -      ASSERT(ptr);
   10.30 -      while((type = GET_XEN_INIT_RSP(&ptr, &setting, &value)) != XEN_INIT_TYPE_END)
   10.31 +      status = NdisMMapIoSpace(&xi->config_page, MiniportAdapterHandle, prd->u.Memory.Start, prd->u.Memory.Length);
   10.32 +      if (!NT_SUCCESS(status))
   10.33        {
   10.34 -        switch(type)
   10.35 -        {
   10.36 -        case XEN_INIT_TYPE_RING: /* frontend ring */
   10.37 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
   10.38 -          if (strcmp(setting, "tx-ring-ref") == 0)
   10.39 -          {
   10.40 -            FRONT_RING_INIT(&xi->tx, (netif_tx_sring_t *)value, PAGE_SIZE);
   10.41 -          } else if (strcmp(setting, "rx-ring-ref") == 0)
   10.42 -          {
   10.43 -            FRONT_RING_INIT(&xi->rx, (netif_rx_sring_t *)value, PAGE_SIZE);
   10.44 -          }
   10.45 -          break;
   10.46 -        case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel */
   10.47 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, PtrToUlong(value)));
   10.48 -          if (strcmp(setting, "event-channel") == 0)
   10.49 -          {
   10.50 -            xi->event_channel = PtrToUlong(value);
   10.51 -          }
   10.52 -          break;
   10.53 -        case XEN_INIT_TYPE_READ_STRING_BACK:
   10.54 -        case XEN_INIT_TYPE_READ_STRING_FRONT:
   10.55 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
   10.56 -          if (strcmp(setting, "mac") == 0)
   10.57 -          {
   10.58 -            char *s, *e;
   10.59 -            s = value;
   10.60 -            for (j = 0; j < ETH_ALEN; j++) {
   10.61 -              xi->perm_mac_addr[j] = (UINT8)simple_strtoul(s, &e, 16);
   10.62 -              if ((s == e) || (*e != ((j == ETH_ALEN-1) ? '\0' : ':'))) {
   10.63 -                KdPrint((__DRIVER_NAME "Error parsing MAC address\n"));
   10.64 -              }
   10.65 -              s = e + 1;
   10.66 -            }
   10.67 -            memcpy(xi->curr_mac_addr, xi->perm_mac_addr, ETH_ALEN);
   10.68 -          }
   10.69 -          break;
   10.70 -        case XEN_INIT_TYPE_VECTORS:
   10.71 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
   10.72 -          if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
   10.73 -            ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC)
   10.74 -          {
   10.75 -            KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
   10.76 -              ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
   10.77 -            KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   10.78 -            return NDIS_ERROR_CODE_ADAPTER_NOT_FOUND;
   10.79 -          }
   10.80 -          else
   10.81 -            memcpy(&xi->vectors, value, sizeof(XENPCI_VECTORS));
   10.82 -          break;
   10.83 -        case XEN_INIT_TYPE_COPY_PTR:
   10.84 -          if (strcmp(setting, "new_crl_translated") == 0)
   10.85 -          {
   10.86 -            xi->new_crl_translated = (PCM_RESOURCE_LIST)value;
   10.87 -          }
   10.88 -          else if (strcmp(setting, "new_crl_raw") == 0)
   10.89 -          {
   10.90 -            xi->new_crl_raw = (PCM_RESOURCE_LIST)value;
   10.91 -          }
   10.92 -          else if (strcmp(setting, "uncached_config_page") == 0)
   10.93 -          {
   10.94 -            xi->uncached_config_page = (PMDL)value;
   10.95 -          }
   10.96 -        default:
   10.97 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   10.98 -          break;
   10.99 -        }
  10.100 +        KdPrint(("NdisMMapIoSpace failed with 0x%x\n", status));
  10.101 +        NdisFreeMemory(nrl, nrl_length, 0);
  10.102 +        return NDIS_STATUS_RESOURCES;
  10.103        }
  10.104        break;
  10.105      }
  10.106    }
  10.107 -
  10.108    NdisFreeMemory(nrl, nrl_length, 0);
  10.109 +  if (!xi->config_page)
  10.110 +  {
  10.111 +    KdPrint(("No config page given\n"));
  10.112 +    return NDIS_STATUS_RESOURCES;
  10.113 +  }
  10.114  
  10.115    KeInitializeSpinLock(&xi->rx_lock);
  10.116  
  10.117 @@ -322,6 +265,174 @@ XenNet_Init(
  10.118      goto err;
  10.119    }
  10.120  
  10.121 +  ptr = xi->config_page;
  10.122 +  while((type = GET_XEN_INIT_RSP(&ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  10.123 +  {
  10.124 +    switch(type)
  10.125 +    {
  10.126 +    case XEN_INIT_TYPE_VECTORS:
  10.127 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
  10.128 +      if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
  10.129 +        ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC)
  10.130 +      {
  10.131 +        KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
  10.132 +          ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
  10.133 +        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  10.134 +        return NDIS_ERROR_CODE_ADAPTER_NOT_FOUND;
  10.135 +      }
  10.136 +      else
  10.137 +        memcpy(&xi->vectors, value, sizeof(XENPCI_VECTORS));
  10.138 +      break;
  10.139 +    default:
  10.140 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
  10.141 +      break;
  10.142 +    }
  10.143 +  }
  10.144 +
  10.145 +  // now build config page
  10.146 +  
  10.147 +  NdisOpenConfiguration(&status, &config_handle, WrapperConfigurationContext);
  10.148 +  if (!NT_SUCCESS(status))
  10.149 +  {
  10.150 +    KdPrint(("Could not open config in registry (%08x)\n", status));
  10.151 +    goto err;
  10.152 +  }
  10.153 +
  10.154 +  NdisInitUnicodeString(&config_param_name, L"ScatterGather");
  10.155 +  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  10.156 +  if (!NT_SUCCESS(status))
  10.157 +  {
  10.158 +    KdPrint(("Could not read ScatterGather value (%08x)\n", status));
  10.159 +    xi->config_sg = 1;
  10.160 +  }
  10.161 +  else
  10.162 +  {
  10.163 +    KdPrint(("ScatterGather = %d\n", config_param->ParameterData.IntegerData));
  10.164 +    xi->config_sg = config_param->ParameterData.IntegerData;
  10.165 +  }
  10.166 +  
  10.167 +  NdisInitUnicodeString(&config_param_name, L"LargeSendOffload");
  10.168 +  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  10.169 +  if (!NT_SUCCESS(status))
  10.170 +  {
  10.171 +    KdPrint(("Could not read LargeSendOffload value (%08x)\n", status));
  10.172 +    xi->config_gso = 0;
  10.173 +  }
  10.174 +  else
  10.175 +  {
  10.176 +    KdPrint(("LargeSendOffload = %d\n", config_param->ParameterData.IntegerData));
  10.177 +    xi->config_gso = config_param->ParameterData.IntegerData;
  10.178 +    if (xi->config_gso > 61440)
  10.179 +    {
  10.180 +      xi->config_gso = 61440;
  10.181 +      KdPrint(("(clipped to %d)\n", xi->config_gso));
  10.182 +    }
  10.183 +  }
  10.184 +
  10.185 +  NdisInitUnicodeString(&config_param_name, L"ChecksumOffload");
  10.186 +  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  10.187 +  if (!NT_SUCCESS(status))
  10.188 +  {
  10.189 +    KdPrint(("Could not read ChecksumOffload value (%08x)\n", status));
  10.190 +    xi->config_csum = 1;
  10.191 +  }
  10.192 +  else
  10.193 +  {
  10.194 +    KdPrint(("ChecksumOffload = %d\n", config_param->ParameterData.IntegerData));
  10.195 +    xi->config_csum = config_param->ParameterData.IntegerData;
  10.196 +  }
  10.197 +
  10.198 +  NdisInitUnicodeString(&config_param_name, L"MTU");
  10.199 +  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);  
  10.200 +  if (!NT_SUCCESS(status))
  10.201 +  {
  10.202 +    KdPrint(("Could not read MTU value (%08x)\n", status));
  10.203 +    xi->config_mtu = 1500;
  10.204 +  }
  10.205 +  else
  10.206 +  {
  10.207 +    KdPrint(("MTU = %d\n", config_param->ParameterData.IntegerData));
  10.208 +    xi->config_mtu = config_param->ParameterData.IntegerData;
  10.209 +  }
  10.210 +
  10.211 +  xi->config_max_pkt_size = max(xi->config_mtu + XN_HDR_SIZE, xi->config_gso + XN_HDR_SIZE);
  10.212 +  
  10.213 +  NdisCloseConfiguration(config_handle);
  10.214 +
  10.215 +  ptr = xi->config_page;
  10.216 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RUN, NULL, NULL);
  10.217 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "tx-ring-ref", NULL);
  10.218 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "rx-ring-ref", NULL);
  10.219 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL);
  10.220 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "mac", NULL);
  10.221 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-no-csum-offload", "0");
  10.222 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-sg", "1");
  10.223 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-gso-tcpv4", "1");
  10.224 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "request-rx-copy", "1");
  10.225 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-rx-notify", "1");
  10.226 +  ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
  10.227 +  
  10.228 +  status = xi->vectors.XenPci_XenConfigDevice(xi->vectors.context);
  10.229 +  // check return value
  10.230 +
  10.231 +  ptr = xi->config_page;
  10.232 +  while((type = GET_XEN_INIT_RSP(&ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  10.233 +  {
  10.234 +    switch(type)
  10.235 +    {
  10.236 +    case XEN_INIT_TYPE_RING: /* frontend ring */
  10.237 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
  10.238 +      if (strcmp(setting, "tx-ring-ref") == 0)
  10.239 +      {
  10.240 +        FRONT_RING_INIT(&xi->tx, (netif_tx_sring_t *)value, PAGE_SIZE);
  10.241 +      } else if (strcmp(setting, "rx-ring-ref") == 0)
  10.242 +      {
  10.243 +        FRONT_RING_INIT(&xi->rx, (netif_rx_sring_t *)value, PAGE_SIZE);
  10.244 +      }
  10.245 +      break;
  10.246 +    case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel */
  10.247 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, PtrToUlong(value)));
  10.248 +      if (strcmp(setting, "event-channel") == 0)
  10.249 +      {
  10.250 +        xi->event_channel = PtrToUlong(value);
  10.251 +      }
  10.252 +      break;
  10.253 +    case XEN_INIT_TYPE_READ_STRING_BACK:
  10.254 +    case XEN_INIT_TYPE_READ_STRING_FRONT:
  10.255 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
  10.256 +      if (strcmp(setting, "mac") == 0)
  10.257 +      {
  10.258 +        char *s, *e;
  10.259 +        s = value;
  10.260 +        for (j = 0; j < ETH_ALEN; j++) {
  10.261 +          xi->perm_mac_addr[j] = (UINT8)simple_strtoul(s, &e, 16);
  10.262 +          if ((s == e) || (*e != ((j == ETH_ALEN-1) ? '\0' : ':'))) {
  10.263 +            KdPrint((__DRIVER_NAME "Error parsing MAC address\n"));
  10.264 +          }
  10.265 +          s = e + 1;
  10.266 +        }
  10.267 +        memcpy(xi->curr_mac_addr, xi->perm_mac_addr, ETH_ALEN);
  10.268 +      }
  10.269 +      break;
  10.270 +    case XEN_INIT_TYPE_VECTORS:
  10.271 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
  10.272 +      if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
  10.273 +        ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC)
  10.274 +      {
  10.275 +        KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
  10.276 +          ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
  10.277 +        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  10.278 +        return NDIS_ERROR_CODE_ADAPTER_NOT_FOUND;
  10.279 +      }
  10.280 +      else
  10.281 +        memcpy(&xi->vectors, value, sizeof(XENPCI_VECTORS));
  10.282 +      break;
  10.283 +    default:
  10.284 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
  10.285 +      break;
  10.286 +    }
  10.287 +  }
  10.288 +  
  10.289    KeInitializeEvent(&xi->shutdown_event, SynchronizationEvent, FALSE);  
  10.290  
  10.291    XenNet_TxInit(xi);
  10.292 @@ -394,55 +505,10 @@ XenNet_Halt(
  10.293    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  10.294    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  10.295  
  10.296 -#if 0
  10.297 -  // set frontend state to 'closing'
  10.298 -  xi->state = XenbusStateClosing;
  10.299 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
  10.300 -  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
  10.301 -
  10.302 -  // wait for backend to set 'Closing' state
  10.303 -
  10.304 -  while (xi->backend_state != XenbusStateClosing)
  10.305 -  {
  10.306 -    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
  10.307 -    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
  10.308 -      KdPrint((__DRIVER_NAME "     Still Waiting for Closing...\n"));
  10.309 -  }
  10.310 -
  10.311 -  // set frontend state to 'closed'
  10.312 -  xi->state = XenbusStateClosed;
  10.313 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
  10.314 -  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
  10.315 -
  10.316 -  // wait for backend to set 'Closed' state
  10.317 -  while (xi->backend_state != XenbusStateClosed)
  10.318 -  {
  10.319 -    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
  10.320 -    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
  10.321 -      KdPrint((__DRIVER_NAME "     Still Waiting for Closed...\n"));
  10.322 -  }
  10.323 -
  10.324 -  // set frontend state to 'Initialising'
  10.325 -  xi->state = XenbusStateInitialising;
  10.326 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
  10.327 -  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
  10.328 -
  10.329 -  // wait for backend to set 'InitWait' state
  10.330 -  while (xi->backend_state != XenbusStateInitWait)
  10.331 -  {
  10.332 -    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
  10.333 -    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
  10.334 -      KdPrint((__DRIVER_NAME "     Still Waiting for InitWait...\n"));
  10.335 -  }
  10.336 -#endif
  10.337    // Disables the interrupt
  10.338    XenNet_Shutdown(xi);
  10.339  
  10.340 -  xi->vectors.XenPci_ShutdownDevice(xi->vectors.context);
  10.341 -
  10.342 -  ExFreePoolWithTag(xi->new_crl_raw, XENNET_POOL_TAG);
  10.343 -  ExFreePoolWithTag(xi->new_crl_translated, XENNET_POOL_TAG);
  10.344 -  FreeUncachedPage(xi->uncached_config_page);
  10.345 +  xi->vectors.XenPci_XenShutdownDevice(xi->vectors.context);
  10.346  
  10.347    xi->connected = FALSE;
  10.348    KeMemoryBarrier(); /* make sure everyone sees that we are now shut down */
  10.349 @@ -452,15 +518,6 @@ XenNet_Halt(
  10.350    XenNet_TxShutdown(xi);
  10.351    XenNet_RxShutdown(xi);
  10.352  
  10.353 -#if 0
  10.354 -
  10.355 -  /* Remove watch on backend state */
  10.356 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->backend_path);
  10.357 -  xi->XenInterface.XenBus_RemWatch(if_cxt, XBT_NIL, TmpPath,
  10.358 -    XenNet_BackEndStateHandler, xi);
  10.359 -
  10.360 -#endif
  10.361 -
  10.362    NdisFreeBufferPool(xi->buffer_pool);
  10.363    NdisFreePacketPool(xi->packet_pool);
  10.364  
  10.365 @@ -469,180 +526,6 @@ XenNet_Halt(
  10.366    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  10.367  }
  10.368  
  10.369 -static PDRIVER_DISPATCH XenNet_Pnp_Original;
  10.370 -
  10.371 -static NTSTATUS
  10.372 -XenNet_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
  10.373 -{
  10.374 -  PIO_STACK_LOCATION stack;
  10.375 -  NTSTATUS status;
  10.376 -  PCM_RESOURCE_LIST old_crl;
  10.377 -  PCM_RESOURCE_LIST new_crl_translated;
  10.378 -  PCM_RESOURCE_LIST new_crl_raw;
  10.379 -  PCM_PARTIAL_RESOURCE_LIST prl;
  10.380 -  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
  10.381 -  ULONG old_length, new_length;
  10.382 -  PMDL mdl;
  10.383 -  PUCHAR start, ptr;
  10.384 -  //NDIS_STRING config_param_name;
  10.385 -  //PNDIS_CONFIGURATION_PARAMETER config_param;
  10.386 -
  10.387 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  10.388 -
  10.389 -  stack = IoGetCurrentIrpStackLocation(irp);
  10.390 -
  10.391 -  // check if the Irp is meant for us... maybe the stack->DeviceObject field?
  10.392 -  
  10.393 -  switch (stack->MinorFunction)
  10.394 -  {
  10.395 -  case IRP_MN_START_DEVICE:
  10.396 -  
  10.397 -#if 0
  10.398 -  NdisOpenConfiguration(&status, &config_handle, WrapperConfigurationContext);
  10.399 -  if (!NT_SUCCESS(status))
  10.400 -  {
  10.401 -    KdPrint(("Could not open config in registry (%08x)\n", status));
  10.402 -    goto err;
  10.403 -  }
  10.404 -
  10.405 -  NdisInitUnicodeString(&config_param_name, L"ScatterGather");
  10.406 -  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  10.407 -  if (!NT_SUCCESS(status))
  10.408 -  {
  10.409 -    KdPrint(("Could not read ScatterGather value (%08x)\n", status));
  10.410 -    xi->config_sg = 1;
  10.411 -  }
  10.412 -  else
  10.413 -  {
  10.414 -    KdPrint(("ScatterGather = %d\n", config_param->ParameterData.IntegerData));
  10.415 -    xi->config_sg = config_param->ParameterData.IntegerData;
  10.416 -  }
  10.417 -  
  10.418 -  NdisInitUnicodeString(&config_param_name, L"LargeSendOffload");
  10.419 -  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  10.420 -  if (!NT_SUCCESS(status))
  10.421 -  {
  10.422 -    KdPrint(("Could not read LargeSendOffload value (%08x)\n", status));
  10.423 -    xi->config_gso = 0;
  10.424 -  }
  10.425 -  else
  10.426 -  {
  10.427 -    KdPrint(("LargeSendOffload = %d\n", config_param->ParameterData.IntegerData));
  10.428 -    xi->config_gso = config_param->ParameterData.IntegerData;
  10.429 -    if (xi->config_gso > 61440)
  10.430 -    {
  10.431 -      xi->config_gso = 61440;
  10.432 -      KdPrint(("(clipped to %d)\n", xi->config_gso));
  10.433 -    }
  10.434 -  }
  10.435 -
  10.436 -  NdisInitUnicodeString(&config_param_name, L"ChecksumOffload");
  10.437 -  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  10.438 -  if (!NT_SUCCESS(status))
  10.439 -  {
  10.440 -    KdPrint(("Could not read ChecksumOffload value (%08x)\n", status));
  10.441 -    xi->config_csum = 1;
  10.442 -  }
  10.443 -  else
  10.444 -  {
  10.445 -    KdPrint(("ChecksumOffload = %d\n", config_param->ParameterData.IntegerData));
  10.446 -    xi->config_csum = config_param->ParameterData.IntegerData;
  10.447 -  }
  10.448 -
  10.449 -  NdisInitUnicodeString(&config_param_name, L"MTU");
  10.450 -  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);  
  10.451 -  if (!NT_SUCCESS(status))
  10.452 -  {
  10.453 -    KdPrint(("Could not read MTU value (%08x)\n", status));
  10.454 -    xi->config_mtu = 1500;
  10.455 -  }
  10.456 -  else
  10.457 -  {
  10.458 -    KdPrint(("MTU = %d\n", config_param->ParameterData.IntegerData));
  10.459 -    xi->config_mtu = config_param->ParameterData.IntegerData;
  10.460 -  }
  10.461 -
  10.462 -  xi->config_max_pkt_size = max(xi->config_mtu + XN_HDR_SIZE, xi->config_gso + XN_HDR_SIZE);
  10.463 -  
  10.464 -  NdisCloseConfiguration(config_handle);
  10.465 -#endif
  10.466 -
  10.467 -    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
  10.468 -    old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
  10.469 -    if (old_crl != NULL)
  10.470 -    {
  10.471 -      mdl = AllocateUncachedPage();
  10.472 -      old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
  10.473 -        FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
  10.474 -        FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
  10.475 -        sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
  10.476 -      new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
  10.477 -      new_crl_translated = ExAllocatePoolWithTag(PagedPool, new_length, XENNET_POOL_TAG);
  10.478 -      new_crl_raw = ExAllocatePoolWithTag(PagedPool, new_length, XENNET_POOL_TAG);
  10.479 -      memcpy(new_crl_translated, old_crl, old_length);
  10.480 -      prl = &new_crl_translated->List[0].PartialResourceList;
  10.481 -      prd = &prl->PartialDescriptors[prl->Count++];
  10.482 -      prd->Type = CmResourceTypeMemory;
  10.483 -      prd->ShareDisposition = CmResourceShareDeviceExclusive;
  10.484 -      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
  10.485 -      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
  10.486 -      prd->u.Memory.Length = PAGE_SIZE;
  10.487 -      KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
  10.488 -      ptr = start = MmGetMdlVirtualAddress(mdl);
  10.489 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "tx-ring-ref", NULL);
  10.490 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "rx-ring-ref", NULL);
  10.491 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL);
  10.492 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "mac", NULL);
  10.493 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-no-csum-offload", "0");
  10.494 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-sg", "1");
  10.495 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-gso-tcpv4", "1");
  10.496 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "request-rx-copy", "1");
  10.497 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-rx-notify", "1");
  10.498 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_VECTORS, NULL, NULL);
  10.499 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_COPY_PTR, "new_crl_translated", new_crl_translated);
  10.500 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_COPY_PTR, "new_crl_raw", new_crl_raw);
  10.501 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_COPY_PTR, "uncached_config_page", mdl);
  10.502 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
  10.503 -      
  10.504 -      stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl_translated;
  10.505 -
  10.506 -      old_crl = stack->Parameters.StartDevice.AllocatedResources;
  10.507 -      memcpy(new_crl_raw, old_crl, old_length);
  10.508 -      prl = &new_crl_raw->List[0].PartialResourceList;
  10.509 -      prd = &prl->PartialDescriptors[prl->Count++];
  10.510 -      prd->Type = CmResourceTypeMemory;
  10.511 -      prd->ShareDisposition = CmResourceShareDeviceExclusive;
  10.512 -      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
  10.513 -      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
  10.514 -      prd->u.Memory.Length = PAGE_SIZE;
  10.515 -      stack->Parameters.StartDevice.AllocatedResources = new_crl_raw;
  10.516 -      IoCopyCurrentIrpStackLocationToNext(irp);
  10.517 -    }
  10.518 -    else
  10.519 -    {
  10.520 -      KdPrint((__DRIVER_NAME "     AllocatedResource == NULL\n"));
  10.521 -    }
  10.522 -    status = XenNet_Pnp_Original(device_object, irp);
  10.523 -    break;
  10.524 -  case IRP_MN_STOP_DEVICE:
  10.525 -    KdPrint((__DRIVER_NAME "     IRP_MN_STOP_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
  10.526 -    status = XenNet_Pnp_Original(device_object, irp);
  10.527 -    break;
  10.528 -  case IRP_MN_REMOVE_DEVICE:
  10.529 -    KdPrint((__DRIVER_NAME "     IRP_MN_REMOVE_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
  10.530 -    status = XenNet_Pnp_Original(device_object, irp);
  10.531 -    break;
  10.532 -  default:
  10.533 -    KdPrint((__DRIVER_NAME "     Unknown Minor %d\n", stack->MinorFunction));
  10.534 -    status = XenNet_Pnp_Original(device_object, irp);
  10.535 -    break;
  10.536 -  }
  10.537 -
  10.538 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  10.539 -
  10.540 -  return status;
  10.541 -}
  10.542 -
  10.543  NTSTATUS
  10.544  DriverEntry(
  10.545    PDRIVER_OBJECT DriverObject,
  10.546 @@ -720,9 +603,5 @@ DriverEntry(
  10.547      return status;
  10.548    }
  10.549  
  10.550 -  /* this is a bit naughty... */
  10.551 -  XenNet_Pnp_Original = DriverObject->MajorFunction[IRP_MJ_PNP];
  10.552 -  DriverObject->MajorFunction[IRP_MJ_PNP] = XenNet_Pnp;
  10.553 -
  10.554    return status;
  10.555  }
    11.1 --- a/xennet/xennet.h	Sat Jun 14 23:16:49 2008 +1000
    11.2 +++ b/xennet/xennet.h	Tue Jun 17 10:35:26 2008 +1000
    11.3 @@ -156,9 +156,6 @@ struct xennet_info
    11.4    PDEVICE_OBJECT lower_do;
    11.5    //WDFDEVICE wdf_device;
    11.6    WCHAR dev_desc[NAME_SIZE];
    11.7 -  PMDL uncached_config_page;
    11.8 -  PCM_RESOURCE_LIST new_crl_raw;
    11.9 -  PCM_RESOURCE_LIST new_crl_translated;
   11.10  
   11.11    /* NDIS-related vars */
   11.12    NDIS_HANDLE adapter_handle;
   11.13 @@ -179,6 +176,7 @@ struct xennet_info
   11.14    KEVENT shutdown_event;
   11.15    char backend_path[MAX_XENBUS_STR_LEN];
   11.16    ULONG backend_state;
   11.17 +  PVOID config_page;
   11.18  
   11.19    /* Xen ring-related vars */
   11.20    KSPIN_LOCK rx_lock;
    12.1 --- a/xennet/xennet.inx	Sat Jun 14 23:16:49 2008 +1000
    12.2 +++ b/xennet/xennet.inx	Tue Jun 17 10:35:26 2008 +1000
    12.3 @@ -63,9 +63,11 @@ HKR, Ndi\Params\ScatterGather\enum, 1, ,
    12.4  
    12.5  [XenNet.CopyFiles]
    12.6  xennet.sys
    12.7 +xenconfig.sys
    12.8  
    12.9  [SourceDisksFiles]
   12.10  xennet.sys=1
   12.11 +xenconfig.sys=1
   12.12  
   12.13  [SourceDisksNames.x86]
   12.14  1 = %DISK_NAME%,,,\i386
   12.15 @@ -75,6 +77,7 @@ 1 = %DISK_NAME%,,,\amd64
   12.16  
   12.17  [XenNet_Inst.Services]
   12.18  AddService=XenNet,2,XenNet_Service 
   12.19 +AddService=XenConfig,0,XenConfig_Service
   12.20  
   12.21  [XenNet_Inst.NT.Services]
   12.22  AddService=XenNet,2,XenNet_Service 
   12.23 @@ -93,9 +96,27 @@ AddReg = XenNet_Service_AddReg
   12.24  HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
   12.25  HKLM,SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318},UpperFilters,0x00010008,XenHide
   12.26  
   12.27 +[XenNet_Inst.NT.HW]
   12.28 +AddReg = XenNet_UpperFilter_AddReg
   12.29 +
   12.30 +[XenNet_UpperFilter_AddReg]
   12.31 +HKR,,UpperFilters,0x10000,XenConfig
   12.32 +
   12.33 +[XenConfig_Service]
   12.34 +DisplayName    = %XenConfig.SVCDESC%                            
   12.35 +ServiceType    = 1
   12.36 +StartType      = 0
   12.37 +ErrorControl   = 1
   12.38 +LoadOrderGroup = System Bus Extender
   12.39 +ServiceBinary  = %12%\xenconfig.sys                            
   12.40 +AddReg = XenConfig_Service_AddReg
   12.41 +
   12.42 +[XenConfig_Service_AddReg]
   12.43 +HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
   12.44 +
   12.45  [Strings]
   12.46  XenGplPv = "Xen GPL PV Driver Developers"
   12.47 -ClassName = "Network Adapters"
   12.48  XenNet.SVCDESC = "Xen Net Device Driver"
   12.49  XenNet.DRVDESC = "Xen Net Device Driver"
   12.50 +XenConfig.SVCDESC = "Xen Config Resource Generator"
   12.51  DISK_NAME = "Xen Net Device Driver Install Disk"
    13.1 --- a/xenpci/xenpci.h	Sat Jun 14 23:16:49 2008 +1000
    13.2 +++ b/xenpci/xenpci.h	Tue Jun 17 10:35:26 2008 +1000
    13.3 @@ -219,9 +219,6 @@ typedef struct {
    13.4    PIRP shutdown_irp;
    13.5  } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
    13.6  
    13.7 -/* The total number of event channels or rings allowed per device... probably never more than 2 */
    13.8 -#define MAX_RESOURCES 4
    13.9 -
   13.10  typedef struct {  
   13.11    XENPCI_COMMON common;
   13.12    PDEVICE_OBJECT bus_pdo;
   13.13 @@ -234,12 +231,13 @@ typedef struct {
   13.14    ULONG irq_vector;
   13.15    KIRQL irq_level;
   13.16    char backend_path[128];
   13.17 -  PVOID xenbus_request;
   13.18 +  //PVOID xenbus_request;
   13.19    KEVENT backend_state_event;
   13.20    ULONG backend_state;
   13.21 -  grant_ref_t grant_refs[MAX_RESOURCES];
   13.22 -  PMDL mdls[MAX_RESOURCES];
   13.23 -  evtchn_port_t event_channels[MAX_RESOURCES];
   13.24 +  PHYSICAL_ADDRESS config_page_phys;
   13.25 +  ULONG config_page_length;
   13.26 +  PUCHAR assigned_resources_start;
   13.27 +  PUCHAR assigned_resources_ptr;
   13.28  } XENPCI_PDO_DEVICE_DATA, *PXENPCI_PDO_DEVICE_DATA;
   13.29  
   13.30  typedef struct
    14.1 --- a/xenpci/xenpci_pdo.c	Sat Jun 14 23:16:49 2008 +1000
    14.2 +++ b/xenpci/xenpci_pdo.c	Tue Jun 17 10:35:26 2008 +1000
    14.3 @@ -352,9 +352,15 @@ XenPci_GntTbl_GetRef(PVOID Context)
    14.4  }
    14.5  
    14.6  static NTSTATUS
    14.7 -XenPci_ShutdownDevice(PVOID Context)
    14.8 +XenPci_XenShutdownDevice(PVOID Context)
    14.9  {
   14.10    PXENPCI_PDO_DEVICE_DATA xppdd = Context;
   14.11 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   14.12 +  PUCHAR in_ptr;
   14.13 +  ULONG i;
   14.14 +  UCHAR type;
   14.15 +  PVOID setting;
   14.16 +  PVOID value;
   14.17  
   14.18    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   14.19  
   14.20 @@ -371,38 +377,215 @@ XenPci_ShutdownDevice(PVOID Context)
   14.21      if (xppdd->backend_state == XenbusStateClosing)
   14.22        XenPci_ChangeFrontendState(xppdd, XenbusStateClosed, XenbusStateClosed, 30000);
   14.23    }
   14.24 +
   14.25 +  if (xppdd->assigned_resources_start != NULL)
   14.26 +  {
   14.27 +    ADD_XEN_INIT_RSP(&xppdd->assigned_resources_ptr, XEN_INIT_TYPE_END, NULL, NULL);
   14.28 +    in_ptr = xppdd->assigned_resources_start;
   14.29 +    while((type = GET_XEN_INIT_RSP(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
   14.30 +    {
   14.31 +      switch (type)
   14.32 +      {
   14.33 +      case XEN_INIT_TYPE_RING: /* frontend ring */
   14.34 +        FreePages(value);
   14.35 +        break;
   14.36 +      case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
   14.37 +        // don't know how to do this yet...
   14.38 +        break;
   14.39 +      case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel bound to irq */
   14.40 +        EvtChn_Unbind(xpdd, PtrToUlong(value));
   14.41 +        break;
   14.42 +      case XEN_INIT_TYPE_GRANT_ENTRIES:
   14.43 +        for (i = 0; i < PtrToUlong(setting); i++)
   14.44 +          GntTbl_EndAccess(xpdd, ((grant_ref_t *)value)[i], FALSE);
   14.45 +        break;
   14.46 +      }
   14.47 +    }
   14.48 +    ExFreePoolWithTag(xppdd->assigned_resources_start, XENPCI_POOL_TAG);
   14.49 +    xppdd->assigned_resources_start = NULL;
   14.50 +  }
   14.51 +
   14.52    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   14.53  
   14.54    return STATUS_SUCCESS;
   14.55  }
   14.56  
   14.57 -// this may work in future versions of xen...
   14.58 -#if 0
   14.59  static NTSTATUS
   14.60 -XenPci_Remap_Page(PXENPCI_DEVICE_DATA xpdd, PFN_NUMBER src, PFN_NUMBER dst)
   14.61 +XenPci_XenConfigDevice(PVOID context)
   14.62  {
   14.63 -  xen_memory_exchange_t xme;
   14.64 -  //xen_pfn_t *pfns;
   14.65 -  int ret;
   14.66 -  
   14.67 -  xme.in.domid = DOMID_SELF;
   14.68 -  set_xen_guest_handle(xme.in.extent_start, src);
   14.69 -  xme.in.nr_extents = 1;
   14.70 -  xme.in.extent_order = 0;
   14.71 -  xme.in.address_bits = 64;
   14.72 +  PXENPCI_PDO_DEVICE_DATA xppdd = context;
   14.73 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
   14.74 +  NTSTATUS status = STATUS_SUCCESS;
   14.75 +  ULONG i;
   14.76 +  char path[128];
   14.77 +  PCHAR setting, value;
   14.78 +  PCHAR res;
   14.79 +  PVOID address;
   14.80 +  UCHAR type;
   14.81 +  PUCHAR in_ptr, in_start;
   14.82 +  PUCHAR out_ptr, out_start;
   14.83 +  XENPCI_VECTORS vectors;
   14.84 +  ULONG event_channel;
   14.85 +  BOOLEAN run = FALSE;
   14.86 +  PMDL ring;
   14.87 +  grant_ref_t gref;
   14.88 + 
   14.89 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   14.90  
   14.91 -  xme.out.domid = DOMID_SELF;
   14.92 -  set_xen_guest_handle(xme.out.extent_start, dst);
   14.93 -  xme.out.nr_extents = 1;
   14.94 -  xme.out.extent_order = 0;
   14.95 -  xme.out.address_bits = 64;
   14.96 -  
   14.97 -  xme.nr_exchanged = 0;
   14.98 -  
   14.99 -  ret = HYPERVISOR_memory_op(xpdd, XENMEM_exchange, &xme);
  14.100 -  KdPrint((__DRIVER_NAME " hypervisor memory op ret = %d\n", ret));  
  14.101 +  out_ptr = out_start = MmMapIoSpace(xppdd->config_page_phys, xppdd->config_page_length, MmNonCached);
  14.102 +  in_ptr = in_start = ExAllocatePoolWithTag(PagedPool, xppdd->config_page_length, XENPCI_POOL_TAG);
  14.103 +  memcpy(in_ptr, out_ptr, xppdd->config_page_length);
  14.104 +
  14.105 +  // always add vectors
  14.106 +  vectors.magic = XEN_DATA_MAGIC;
  14.107 +  vectors.length = sizeof(XENPCI_VECTORS);
  14.108 +  vectors.context = xppdd;
  14.109 +  vectors.EvtChn_Bind = XenPci_EvtChn_Bind;
  14.110 +  vectors.EvtChn_BindDpc = XenPci_EvtChn_BindDpc;
  14.111 +  vectors.EvtChn_Unbind = XenPci_EvtChn_Unbind;
  14.112 +  vectors.EvtChn_Mask = XenPci_EvtChn_Mask;
  14.113 +  vectors.EvtChn_Unmask = XenPci_EvtChn_Unmask;
  14.114 +  vectors.EvtChn_Notify = XenPci_EvtChn_Notify;
  14.115 +  vectors.GntTbl_GetRef = XenPci_GntTbl_GetRef;
  14.116 +  vectors.GntTbl_PutRef = XenPci_GntTbl_PutRef;
  14.117 +  vectors.GntTbl_GrantAccess = XenPci_GntTbl_GrantAccess;
  14.118 +  vectors.GntTbl_EndAccess = XenPci_GntTbl_EndAccess;
  14.119 +  vectors.XenPci_XenConfigDevice = XenPci_XenConfigDevice;
  14.120 +  vectors.XenPci_XenShutdownDevice = XenPci_XenShutdownDevice;
  14.121 +  ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_VECTORS, NULL, &vectors);
  14.122 +
  14.123 +  // first pass, possibly before state == Connected
  14.124 +  while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  14.125 +  {
  14.126 +    switch (type)
  14.127 +    {
  14.128 +    case XEN_INIT_TYPE_RUN:
  14.129 +      run = TRUE;
  14.130 +    case XEN_INIT_TYPE_WRITE_STRING: /* frontend setting = value */
  14.131 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_WRITE_STRING - %s = %s\n", setting, value));
  14.132 +      RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  14.133 +      XenBus_Printf(xpdd, XBT_NIL, path, "%s", value);
  14.134 +      break;
  14.135 +    case XEN_INIT_TYPE_RING: /* frontend ring */
  14.136 +      /* we only allocate and do the SHARED_RING_INIT here */
  14.137 +      if ((ring = AllocatePage()) != 0)
  14.138 +      {
  14.139 +        address = MmGetMdlVirtualAddress(ring);
  14.140 +        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, address));
  14.141 +        SHARED_RING_INIT((struct dummy_sring *)address);
  14.142 +        if ((gref = GntTbl_GrantAccess(
  14.143 +          xpdd, 0, (ULONG)*MmGetMdlPfnArray(ring), FALSE, 0)) != 0)
  14.144 +        {
  14.145 +          RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  14.146 +          XenBus_Printf(xpdd, XBT_NIL, path, "%d", gref);
  14.147 +          ADD_XEN_INIT_RSP(&out_ptr, type, setting, address);
  14.148 +          ADD_XEN_INIT_RSP(&xppdd->assigned_resources_ptr, type, setting, ring);
  14.149 +          // add the grant entry too so it gets freed automatically
  14.150 +          __ADD_XEN_INIT_UCHAR(&xppdd->assigned_resources_ptr, XEN_INIT_TYPE_GRANT_ENTRIES);
  14.151 +          __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, PtrToUlong(1));
  14.152 +          __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, gref);
  14.153 +        }
  14.154 +        else
  14.155 +        {
  14.156 +          FreePages(ring);
  14.157 +          status = STATUS_UNSUCCESSFUL;
  14.158 +          goto error;
  14.159 +        }
  14.160 +      }
  14.161 +      else
  14.162 +      {
  14.163 +        status = STATUS_UNSUCCESSFUL;
  14.164 +        goto error;
  14.165 +      }
  14.166 +      break;
  14.167 +    case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
  14.168 +    case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel bound to irq */
  14.169 +      if ((event_channel = EvtChn_AllocUnbound(xpdd, 0)) != 0)
  14.170 +      {
  14.171 +        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, event_channel));
  14.172 +        RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  14.173 +        XenBus_Printf(xpdd, XBT_NIL, path, "%d", event_channel);
  14.174 +        ADD_XEN_INIT_RSP(&out_ptr, type, setting, UlongToPtr(event_channel));
  14.175 +        ADD_XEN_INIT_RSP(&xppdd->assigned_resources_ptr, type, setting, UlongToPtr(event_channel));
  14.176 +        if (type == XEN_INIT_TYPE_EVENT_CHANNEL_IRQ)
  14.177 +          EvtChn_BindIrq(xpdd, event_channel, xppdd->irq_vector);
  14.178 +      }
  14.179 +      else
  14.180 +      {
  14.181 +        status = STATUS_UNSUCCESSFUL;
  14.182 +        goto error;
  14.183 +      }
  14.184 +      break;
  14.185 +#if 0     
  14.186 +    case XEN_INIT_TYPE_COPY_PTR:
  14.187 +      ADD_XEN_INIT_RSP(&out_ptr, type, setting, value);
  14.188 +      break;
  14.189 +#endif      
  14.190 +    }
  14.191 +  }
  14.192 +  if (!NT_SUCCESS(status))
  14.193 +  {
  14.194 +    goto error;
  14.195 +  }
  14.196 +  if (run && XenPci_ChangeFrontendState(xppdd, XenbusStateConnected, XenbusStateConnected, 30000) != STATUS_SUCCESS)
  14.197 +  {
  14.198 +    status = STATUS_UNSUCCESSFUL;
  14.199 +    goto error;
  14.200 +  }
  14.201 +
  14.202 +  // second pass, possibly after state == Connected
  14.203 +  in_ptr = in_start;
  14.204 +  while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  14.205 +  {
  14.206 +    switch(type)
  14.207 +    {
  14.208 +    case XEN_INIT_TYPE_READ_STRING_BACK:
  14.209 +    case XEN_INIT_TYPE_READ_STRING_FRONT:
  14.210 +      if (type == XEN_INIT_TYPE_READ_STRING_FRONT)
  14.211 +        RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  14.212 +      else
  14.213 +        RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->backend_path, setting);
  14.214 +      res = XenBus_Read(xpdd, XBT_NIL, path, &value);
  14.215 +      if (res)
  14.216 +      {
  14.217 +        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = <failed>\n", setting));
  14.218 +        XenPci_FreeMem(res);
  14.219 +        ADD_XEN_INIT_RSP(&out_ptr, type, setting, NULL);
  14.220 +      }
  14.221 +      else
  14.222 +      {
  14.223 +        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
  14.224 +        ADD_XEN_INIT_RSP(&out_ptr, type, setting, value);
  14.225 +        XenPci_FreeMem(value);
  14.226 +      }
  14.227 +      break;
  14.228 +    case XEN_INIT_TYPE_VECTORS:
  14.229 +      // this is always done so ignore the request
  14.230 +      break;
  14.231 +    case XEN_INIT_TYPE_GRANT_ENTRIES:
  14.232 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(value)));
  14.233 +      __ADD_XEN_INIT_UCHAR(&out_ptr, type);
  14.234 +      __ADD_XEN_INIT_UCHAR(&xppdd->assigned_resources_ptr, type);
  14.235 +      __ADD_XEN_INIT_ULONG(&out_ptr, PtrToUlong(value));
  14.236 +      __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, PtrToUlong(value));
  14.237 +      for (i = 0; i < PtrToUlong(value); i++)
  14.238 +      {
  14.239 +        __ADD_XEN_INIT_ULONG(&out_ptr, GntTbl_GetRef(xpdd));
  14.240 +        __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, GntTbl_GetRef(xpdd));
  14.241 +      }
  14.242 +      break;
  14.243 +    }
  14.244 +  }
  14.245 +
  14.246 +error:
  14.247 +  ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_END, NULL, NULL);
  14.248 +  MmUnmapIoSpace(out_start, xppdd->config_page_length);
  14.249 +  ExFreePoolWithTag(in_start, XENPCI_POOL_TAG);
  14.250 +
  14.251 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (%08x\n", status));
  14.252 +
  14.253 +  return status;
  14.254  }
  14.255 -#endif
  14.256  
  14.257  static NTSTATUS
  14.258  XenPci_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
  14.259 @@ -411,32 +594,17 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  14.260    PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
  14.261    PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  14.262    PIO_STACK_LOCATION stack;
  14.263 -  PCM_PARTIAL_RESOURCE_LIST res_list;
  14.264 -  PCM_PARTIAL_RESOURCE_DESCRIPTOR res_descriptor;
  14.265 +  PCM_PARTIAL_RESOURCE_LIST prl;
  14.266 +  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
  14.267    ULONG i;
  14.268    char path[128];
  14.269 -  PCHAR setting, value;
  14.270 +  PCHAR value;
  14.271    PCHAR res;
  14.272 -  PVOID address;
  14.273 -  UCHAR type;
  14.274 -  PUCHAR in_ptr = NULL;
  14.275 -  PUCHAR out_ptr, out_start = NULL;
  14.276 -  XENPCI_VECTORS vectors;
  14.277 -  ULONG rings = 0;
  14.278 -  ULONG event_channels = 0;
  14.279 -  BOOLEAN has_config_page = FALSE;
  14.280 -  PMDL mdl;
  14.281 -  PCM_RESOURCE_LIST old_crl, new_crl;
  14.282 -  PCM_PARTIAL_RESOURCE_LIST prl;
  14.283 -  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
  14.284 -  ULONG old_length, new_length;
  14.285   
  14.286    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  14.287  
  14.288    DUMP_CURRENT_PNP_STATE(xppdd);
  14.289    
  14.290 -  xppdd->xenbus_request = NULL;
  14.291 -  
  14.292    stack = IoGetCurrentIrpStackLocation(irp);
  14.293  
  14.294    /* Get backend path */
  14.295 @@ -456,200 +624,45 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
  14.296    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  14.297    XenBus_AddWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  14.298  
  14.299 -#if 0
  14.300 -  has_config_page = FALSE;
  14.301 -  res_list = &stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
  14.302 -  for (i = 0; i < res_list->Count; i++)
  14.303 +  if (XenPci_ChangeFrontendState(xppdd, XenbusStateInitialising, XenbusStateInitWait, 30000) != STATUS_SUCCESS)
  14.304    {
  14.305 -    res_descriptor = &res_list->PartialDescriptors[i];
  14.306 -    if (res_descriptor->Type == CmResourceTypeMemory)
  14.307 -    {
  14.308 -      has_config_page = TRUE;
  14.309 -      break;
  14.310 -    }
  14.311 -  }
  14.312 -#endif
  14.313 -
  14.314 -  res_list = &stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList;
  14.315 -  for (i = 0; i < res_list->Count; i++)
  14.316 -  {
  14.317 -    res_descriptor = &res_list->PartialDescriptors[i];
  14.318 -    switch (res_descriptor->Type)
  14.319 -    {
  14.320 -    case CmResourceTypeInterrupt:
  14.321 -      KdPrint((__DRIVER_NAME "     irq_number = %d\n", res_descriptor->u.Interrupt.Vector));
  14.322 -      KdPrint((__DRIVER_NAME "     irq_level = %03x\n", res_descriptor->u.Interrupt.Level));
  14.323 -      break;
  14.324 -    }
  14.325 +    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  14.326 +    XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  14.327 +    return STATUS_UNSUCCESSFUL;
  14.328    }
  14.329  
  14.330 -  res_list = &stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
  14.331 -  for (i = 0; i < res_list->Count; i++)
  14.332 +  prl = &stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
  14.333 +  for (i = 0; i < prl->Count; i++)
  14.334    {
  14.335 -    res_descriptor = &res_list->PartialDescriptors[i];
  14.336 -    switch (res_descriptor->Type)
  14.337 +    prd = & prl->PartialDescriptors[i];
  14.338 +    switch (prd->Type)
  14.339      {
  14.340      case CmResourceTypeInterrupt:
  14.341        KdPrint((__DRIVER_NAME "     CmResourceTypeInterrupt\n"));
  14.342 -      KdPrint((__DRIVER_NAME "     irq_vector = %03x\n", res_descriptor->u.Interrupt.Vector));
  14.343 -      KdPrint((__DRIVER_NAME "     irq_level = %d\n", res_descriptor->u.Interrupt.Level));
  14.344 -      xppdd->irq_vector = res_descriptor->u.Interrupt.Vector;
  14.345 -      xppdd->irq_level = (KIRQL)res_descriptor->u.Interrupt.Level;
  14.346 +      KdPrint((__DRIVER_NAME "     irq_vector = %03x\n", prd->u.Interrupt.Vector));
  14.347 +      KdPrint((__DRIVER_NAME "     irq_level = %d\n", prd->u.Interrupt.Level));
  14.348 +      xppdd->irq_vector = prd->u.Interrupt.Vector;
  14.349 +      xppdd->irq_level = (KIRQL)prd->u.Interrupt.Level;
  14.350        break;
  14.351      case CmResourceTypeMemory:
  14.352        KdPrint((__DRIVER_NAME "     CmResourceTypeMemory\n"));
  14.353 -      KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", res_descriptor->u.Memory.Start.LowPart, res_descriptor->u.Memory.Length));
  14.354 -      if (XenPci_ChangeFrontendState(xppdd, XenbusStateInitialising, XenbusStateInitWait, 30000) != STATUS_SUCCESS)
  14.355 -      {
  14.356 -        RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  14.357 -        XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  14.358 -        return STATUS_UNSUCCESSFUL;
  14.359 -      }
  14.360 -      out_ptr = out_start = MmMapIoSpace(res_descriptor->u.Memory.Start, res_descriptor->u.Memory.Length, MmNonCached);
  14.361 -      in_ptr = xppdd->xenbus_request = ExAllocatePoolWithTag(PagedPool, res_descriptor->u.Memory.Length, XENPCI_POOL_TAG);
  14.362 -      KdPrint((__DRIVER_NAME "     out_ptr = %p, in_ptr = %p\n", out_ptr, in_ptr));
  14.363 -      memcpy(in_ptr, out_ptr, res_descriptor->u.Memory.Length);
  14.364 -      
  14.365 -      while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  14.366 -      {
  14.367 -        switch (type)
  14.368 -        {
  14.369 -        case XEN_INIT_TYPE_WRITE_STRING: /* frontend setting = value */
  14.370 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_WRITE_STRING - %s = %s\n", setting, value));
  14.371 -          RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  14.372 -          XenBus_Printf(xpdd, XBT_NIL, path, "%s", value);
  14.373 -          break;
  14.374 -        case XEN_INIT_TYPE_RING: /* frontend ring */
  14.375 -          /* we only allocate and do the SHARED_RING_INIT here */
  14.376 -          if ((xppdd->mdls[rings] = AllocatePage()) != 0)
  14.377 -          {
  14.378 -            address = MmGetMdlVirtualAddress(xppdd->mdls[rings]);
  14.379 -            KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, address));
  14.380 -            SHARED_RING_INIT((struct dummy_sring *)address);
  14.381 -            if ((xppdd->grant_refs[rings] = GntTbl_GrantAccess(
  14.382 -              xpdd, 0, (ULONG)*MmGetMdlPfnArray(xppdd->mdls[rings]), FALSE, 0)) != 0)
  14.383 -            {
  14.384 -              RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  14.385 -              XenBus_Printf(xpdd, XBT_NIL, path, "%d", xppdd->grant_refs[rings]);
  14.386 -              ADD_XEN_INIT_RSP(&out_ptr, type, setting, address);
  14.387 -            }
  14.388 -            else
  14.389 -            {
  14.390 -              status = STATUS_UNSUCCESSFUL;
  14.391 -            }
  14.392 -          }
  14.393 -          else
  14.394 -          {
  14.395 -            xppdd->grant_refs[rings] = 0;
  14.396 -            status = STATUS_UNSUCCESSFUL;
  14.397 -          }
  14.398 -          rings++;
  14.399 -          break;
  14.400 -        case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
  14.401 -        case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel bound to irq */
  14.402 -          if ((xppdd->event_channels[event_channels] = EvtChn_AllocUnbound(xpdd, 0)) != 0)
  14.403 -          {
  14.404 -            KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, xppdd->event_channels[event_channels]));
  14.405 -            RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  14.406 -            XenBus_Printf(xpdd, XBT_NIL, path, "%d", xppdd->event_channels[event_channels]);
  14.407 -            ADD_XEN_INIT_RSP(&out_ptr, type, setting, UlongToPtr(xppdd->event_channels[event_channels]));
  14.408 -            if (type == XEN_INIT_TYPE_EVENT_CHANNEL_IRQ)
  14.409 -              EvtChn_BindIrq(xpdd, xppdd->event_channels[event_channels], xppdd->irq_vector);
  14.410 -          }
  14.411 -          else
  14.412 -          {
  14.413 -            status = STATUS_UNSUCCESSFUL;
  14.414 -          }
  14.415 -          event_channels++;
  14.416 -          break;
  14.417 -        case XEN_INIT_TYPE_COPY_PTR:
  14.418 -          ADD_XEN_INIT_RSP(&out_ptr, type, setting, value);
  14.419 -          break;
  14.420 -        }
  14.421 -      }
  14.422 +      KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
  14.423 +      xppdd->config_page_phys = prd->u.Memory.Start;
  14.424 +      xppdd->config_page_length = prd->u.Memory.Length;
  14.425 +      xppdd->assigned_resources_start = xppdd->assigned_resources_ptr = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
  14.426 +      status = XenPci_XenConfigDevice(xppdd);
  14.427        if (!NT_SUCCESS(status))
  14.428        {
  14.429          RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  14.430          XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  14.431          return status;
  14.432        }
  14.433 -      if (XenPci_ChangeFrontendState(xppdd, XenbusStateConnected, XenbusStateConnected, 30000) != STATUS_SUCCESS)
  14.434 -      {
  14.435 -        RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  14.436 -        XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
  14.437 -        return STATUS_UNSUCCESSFUL;
  14.438 -      }
  14.439      }
  14.440    }
  14.441 -
  14.442 -  res_list = &stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
  14.443 -  for (i = 0; i < res_list->Count; i++)
  14.444 -  {
  14.445 -    res_descriptor = &res_list->PartialDescriptors[i];
  14.446 -    switch (res_descriptor->Type) {
  14.447 -    case CmResourceTypeMemory:
  14.448 -      in_ptr = xppdd->xenbus_request;
  14.449 -      while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  14.450 -      {
  14.451 -        switch(type)
  14.452 -        {
  14.453 -        case XEN_INIT_TYPE_READ_STRING_BACK:
  14.454 -        case XEN_INIT_TYPE_READ_STRING_FRONT:
  14.455 -          if (type == XEN_INIT_TYPE_READ_STRING_FRONT)
  14.456 -            RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
  14.457 -          else
  14.458 -            RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->backend_path, setting);
  14.459 -          res = XenBus_Read(xpdd, XBT_NIL, path, &value);
  14.460 -          if (res)
  14.461 -          {
  14.462 -            KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = <failed>\n", setting));
  14.463 -            XenPci_FreeMem(res);
  14.464 -            ADD_XEN_INIT_RSP(&out_ptr, type, setting, NULL);
  14.465 -          }
  14.466 -          else
  14.467 -          {
  14.468 -            KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
  14.469 -            ADD_XEN_INIT_RSP(&out_ptr, type, setting, value);
  14.470 -            XenPci_FreeMem(value);
  14.471 -          }
  14.472 -          break;
  14.473 -        case XEN_INIT_TYPE_VECTORS:
  14.474 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
  14.475 -          vectors.magic = XEN_DATA_MAGIC;
  14.476 -          vectors.length = sizeof(XENPCI_VECTORS);
  14.477 -          vectors.context = xppdd;
  14.478 -          vectors.EvtChn_Bind = XenPci_EvtChn_Bind;
  14.479 -          vectors.EvtChn_BindDpc = XenPci_EvtChn_BindDpc;
  14.480 -          vectors.EvtChn_Unbind = XenPci_EvtChn_Unbind;
  14.481 -          vectors.EvtChn_Mask = XenPci_EvtChn_Mask;
  14.482 -          vectors.EvtChn_Unmask = XenPci_EvtChn_Unmask;
  14.483 -          vectors.EvtChn_Notify = XenPci_EvtChn_Notify;
  14.484 -          vectors.GntTbl_GetRef = XenPci_GntTbl_GetRef;
  14.485 -          vectors.GntTbl_PutRef = XenPci_GntTbl_PutRef;
  14.486 -          vectors.GntTbl_GrantAccess = XenPci_GntTbl_GrantAccess;
  14.487 -          vectors.GntTbl_EndAccess = XenPci_GntTbl_EndAccess;
  14.488 -          vectors.XenPci_ShutdownDevice = XenPci_ShutdownDevice;
  14.489 -          ADD_XEN_INIT_RSP(&out_ptr, type, NULL, &vectors);
  14.490 -          break;
  14.491 -        case XEN_INIT_TYPE_GRANT_ENTRIES:
  14.492 -          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(value)));
  14.493 -          __ADD_XEN_INIT_UCHAR(&out_ptr, type);
  14.494 -          __ADD_XEN_INIT_ULONG(&out_ptr, PtrToUlong(value));
  14.495 -          for (i = 0; i < PtrToUlong(value); i++)
  14.496 -            __ADD_XEN_INIT_ULONG(&out_ptr, GntTbl_GetRef(xpdd));
  14.497 -          break;
  14.498 -        }
  14.499 -      }
  14.500 -      ADD_XEN_INIT_RSP(&out_ptr, XEN_INIT_TYPE_END, NULL, NULL);
  14.501 -      MmUnmapIoSpace(out_start, res_descriptor->u.Memory.Length);
  14.502 -      //ExFreePoolWithTag(in_start, XENPCI_POOL_TAG);
  14.503 -    }
  14.504 -  }
  14.505 -
  14.506 +  SET_PNP_STATE(&xppdd->common, Started);
  14.507 +  
  14.508    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  14.509  
  14.510 -  SET_PNP_STATE(&xppdd->common, Started);
  14.511 -  
  14.512    return STATUS_SUCCESS;
  14.513  }
  14.514  
  14.515 @@ -660,11 +673,6 @@ XenPci_Pnp_RemoveDevice(PDEVICE_OBJECT d
  14.516    PXENPCI_PDO_DEVICE_DATA xppdd = device_object->DeviceExtension;
  14.517    PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
  14.518    char path[128];
  14.519 -  PCHAR setting, value;
  14.520 -  UCHAR type;
  14.521 -  PUCHAR in_ptr = NULL;
  14.522 -  ULONG rings = 0;
  14.523 -  ULONG event_channels = 0;
  14.524  
  14.525    UNREFERENCED_PARAMETER(irp);
  14.526  
  14.527 @@ -674,30 +682,7 @@ XenPci_Pnp_RemoveDevice(PDEVICE_OBJECT d
  14.528  
  14.529    if (xppdd->common.current_pnp_state != Removed)
  14.530    {
  14.531 -    status = XenPci_ShutdownDevice(xppdd);
  14.532 -
  14.533 -    if (xppdd->xenbus_request != NULL)
  14.534 -    {
  14.535 -      in_ptr = xppdd->xenbus_request;
  14.536 -      while((type = GET_XEN_INIT_REQ(&in_ptr, &setting, &value)) != XEN_INIT_TYPE_END)
  14.537 -      {
  14.538 -        switch (type)
  14.539 -        {
  14.540 -        case XEN_INIT_TYPE_RING: /* frontend ring */
  14.541 -          GntTbl_EndAccess(xpdd, xppdd->grant_refs[rings], FALSE);
  14.542 -          FreePages(xppdd->mdls[rings]);
  14.543 -          xppdd->mdls[rings] = NULL;
  14.544 -          rings++;
  14.545 -          break;
  14.546 -        case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
  14.547 -        case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel bound to irq */
  14.548 -          EvtChn_Unbind(xpdd, xppdd->event_channels[event_channels++]);
  14.549 -          break;
  14.550 -        }
  14.551 -      }
  14.552 -      ExFreePoolWithTag(xppdd->xenbus_request, XENPCI_POOL_TAG);
  14.553 -      xppdd->xenbus_request = NULL;
  14.554 -    }
  14.555 +    status = XenPci_XenShutdownDevice(xppdd);
  14.556      /* Remove watch on backend state */
  14.557      RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
  14.558      XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackEndStateHandler, xppdd);
    15.1 --- a/xenscsi/scsiport.c	Sat Jun 14 23:16:49 2008 +1000
    15.2 +++ b/xenscsi/scsiport.c	Tue Jun 17 10:35:26 2008 +1000
    15.3 @@ -262,17 +262,9 @@ XenScsi_HwScsiFindAdapter(PVOID DeviceEx
    15.4        break;
    15.5      case XEN_INIT_TYPE_GRANT_ENTRIES:
    15.6        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
    15.7 -      if (PtrToUlong(setting) != GRANT_ENTRIES)
    15.8 -      {
    15.9 -        KdPrint((__DRIVER_NAME "     grant entries mismatch\n"));
   15.10 -        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   15.11 -        return SP_RETURN_BAD_CONFIG;
   15.12 -      }
   15.13 -      else
   15.14 -      {
   15.15 -        memcpy(&xsdd->grant_free_list, value, sizeof(ULONG) * PtrToUlong(setting));
   15.16 -        xsdd->grant_free = GRANT_ENTRIES;
   15.17 -      }
   15.18 +      xsdd->grant_entries = (USHORT)PtrToUlong(setting);
   15.19 +      memcpy(&xsdd->grant_free_list, value, sizeof(grant_ref_t) * xsdd->grant_entries);
   15.20 +      xsdd->grant_free = xsdd->grant_entries;
   15.21        break;
   15.22      default:
   15.23        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
    16.1 --- a/xenscsi/xenscsi.c	Sat Jun 14 23:16:49 2008 +1000
    16.2 +++ b/xenscsi/xenscsi.c	Tue Jun 17 10:35:26 2008 +1000
    16.3 @@ -50,127 +50,6 @@ XenScsi_HwScsiAdapterControl(PVOID Devic
    16.4  #pragma alloc_text (INIT, DriverEntry)
    16.5  #endif
    16.6  
    16.7 -static PDRIVER_DISPATCH XenScsi_Pnp_Original;
    16.8 -
    16.9 -static NTSTATUS
   16.10 -XenScsi_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
   16.11 -{
   16.12 -  PIO_STACK_LOCATION stack;
   16.13 -  NTSTATUS status;
   16.14 -  PCM_RESOURCE_LIST old_crl, new_crl;
   16.15 -  PCM_PARTIAL_RESOURCE_LIST prl;
   16.16 -  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
   16.17 -  ULONG old_length, new_length;
   16.18 -  PMDL mdl;
   16.19 -  PUCHAR start, ptr;
   16.20 -
   16.21 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   16.22 -
   16.23 -  stack = IoGetCurrentIrpStackLocation(irp);
   16.24 -
   16.25 -  // check if the Irp is meant for us... maybe the stack->DeviceObject field?
   16.26 -  
   16.27 -  switch (stack->MinorFunction)
   16.28 -  {
   16.29 -  case IRP_MN_START_DEVICE:
   16.30 -    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
   16.31 -    old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   16.32 -    if (old_crl != NULL)
   16.33 -    {
   16.34 -      mdl = AllocateUncachedPage();
   16.35 -      old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
   16.36 -        FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
   16.37 -        FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
   16.38 -        sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
   16.39 -      new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
   16.40 -      new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENSCSI_POOL_TAG);
   16.41 -      memcpy(new_crl, old_crl, old_length);
   16.42 -      prl = &new_crl->List[0].PartialResourceList;
   16.43 -      prd = &prl->PartialDescriptors[prl->Count++];
   16.44 -      prd->Type = CmResourceTypeMemory;
   16.45 -      prd->ShareDisposition = CmResourceShareDeviceExclusive;
   16.46 -      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
   16.47 -      KdPrint((__DRIVER_NAME "     PFN[0] = %p\n", MmGetMdlPfnArray(mdl)[0]));
   16.48 -      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
   16.49 -      prd->u.Memory.Length = PAGE_SIZE;
   16.50 -      KdPrint((__DRIVER_NAME "     Start = %08x:%08x, Length = %d\n", prd->u.Memory.Start.HighPart, prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
   16.51 -      ptr = start = MmGetMdlVirtualAddress(mdl);
   16.52 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "ring-ref", NULL);
   16.53 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL);
   16.54 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_FRONT, "b-dev", NULL);
   16.55 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_VECTORS, NULL, NULL);
   16.56 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, UlongToPtr(GRANT_ENTRIES), NULL);
   16.57 -      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
   16.58 -      
   16.59 -      stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
   16.60 -
   16.61 -      old_crl = stack->Parameters.StartDevice.AllocatedResources;
   16.62 -      new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENSCSI_POOL_TAG);
   16.63 -      memcpy(new_crl, old_crl, old_length);
   16.64 -      prl = &new_crl->List[0].PartialResourceList;
   16.65 -      prd = &prl->PartialDescriptors[prl->Count++];
   16.66 -      prd->Type = CmResourceTypeMemory;
   16.67 -      prd->ShareDisposition = CmResourceShareDeviceExclusive;
   16.68 -      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
   16.69 -      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
   16.70 -      prd->u.Memory.Length = PAGE_SIZE;
   16.71 -      stack->Parameters.StartDevice.AllocatedResources = new_crl;
   16.72 -      IoCopyCurrentIrpStackLocationToNext(irp);
   16.73 -    }
   16.74 -    else
   16.75 -    {
   16.76 -      KdPrint((__DRIVER_NAME "     AllocatedResource == NULL\n"));
   16.77 -    }
   16.78 -    status = XenScsi_Pnp_Original(device_object, irp);
   16.79 -
   16.80 -    break;
   16.81 -
   16.82 -  case IRP_MN_QUERY_STOP_DEVICE:
   16.83 -    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_STOP_DEVICE\n"));
   16.84 -    status = XenScsi_Pnp_Original(device_object, irp);
   16.85 -    break;
   16.86 -
   16.87 -  case IRP_MN_STOP_DEVICE:
   16.88 -    KdPrint((__DRIVER_NAME "     IRP_MN_STOP_DEVICE\n"));
   16.89 -    status = XenScsi_Pnp_Original(device_object, irp);
   16.90 -    break;
   16.91 -
   16.92 -  case IRP_MN_CANCEL_STOP_DEVICE:
   16.93 -    KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_STOP_DEVICE\n"));
   16.94 -    status = XenScsi_Pnp_Original(device_object, irp);
   16.95 -    break;
   16.96 -
   16.97 -  case IRP_MN_QUERY_REMOVE_DEVICE:
   16.98 -    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_REMOVE_DEVICE\n"));
   16.99 -    status = XenScsi_Pnp_Original(device_object, irp);
  16.100 -    break;
  16.101 -
  16.102 -  case IRP_MN_REMOVE_DEVICE:
  16.103 -    KdPrint((__DRIVER_NAME "     IRP_MN_REMOVE_DEVICE\n"));
  16.104 -    status = XenScsi_Pnp_Original(device_object, irp);
  16.105 -    break;
  16.106 -
  16.107 -  case IRP_MN_CANCEL_REMOVE_DEVICE:
  16.108 -    KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_REMOVE_DEVICE\n"));
  16.109 -    status = XenScsi_Pnp_Original(device_object, irp);
  16.110 -    break;
  16.111 -
  16.112 -  case IRP_MN_SURPRISE_REMOVAL:
  16.113 -    KdPrint((__DRIVER_NAME "     IRP_MN_SURPRISE_REMOVAL\n"));
  16.114 -    status = XenScsi_Pnp_Original(device_object, irp);
  16.115 -    break;
  16.116 -
  16.117 -  default:
  16.118 -    KdPrint((__DRIVER_NAME "     Unknown Minor = %d\n", stack->MinorFunction));
  16.119 -    status = XenScsi_Pnp_Original(device_object, irp);
  16.120 -    break;
  16.121 -  }
  16.122 -
  16.123 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  16.124 -
  16.125 -  return status;
  16.126 -}
  16.127 -
  16.128  NTSTATUS
  16.129  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
  16.130  {
  16.131 @@ -204,10 +83,6 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
  16.132  
  16.133    Status = ScsiPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
  16.134    
  16.135 -  /* this is a bit naughty... */
  16.136 -  XenScsi_Pnp_Original = DriverObject->MajorFunction[IRP_MJ_PNP];
  16.137 -  DriverObject->MajorFunction[IRP_MJ_PNP] = XenScsi_Pnp;
  16.138 -
  16.139    if(!NT_SUCCESS(Status))
  16.140    {
  16.141      KdPrint((__DRIVER_NAME " ScsiPortInitialize failed with status 0x%08x\n", Status));
    17.1 --- a/xenscsi/xenscsi.h	Sat Jun 14 23:16:49 2008 +1000
    17.2 +++ b/xenscsi/xenscsi.h	Tue Jun 17 10:35:26 2008 +1000
    17.3 @@ -37,7 +37,7 @@ typedef struct {
    17.4  } vscsiif_shadow_t;
    17.5  
    17.6  #define SHADOW_ENTRIES 32
    17.7 -#define GRANT_ENTRIES 128
    17.8 +#define MAX_GRANT_ENTRIES 512
    17.9  
   17.10  struct
   17.11  {
   17.12 @@ -45,8 +45,9 @@ struct
   17.13    USHORT shadow_free_list[SHADOW_ENTRIES];
   17.14    USHORT shadow_free;
   17.15  
   17.16 -  grant_ref_t grant_free_list[GRANT_ENTRIES];
   17.17 +  grant_ref_t grant_free_list[MAX_GRANT_ENTRIES];
   17.18    USHORT grant_free;
   17.19 +  USHORT grant_entries;
   17.20  
   17.21    evtchn_port_t event_channel;
   17.22  
    18.1 --- a/xenscsi/xenscsi.inx	Sat Jun 14 23:16:49 2008 +1000
    18.2 +++ b/xenscsi/xenscsi.inx	Tue Jun 17 10:35:26 2008 +1000
    18.3 @@ -26,9 +26,11 @@ CopyFiles=XenScsi.CopyFiles
    18.4  
    18.5  [XenScsi.CopyFiles]
    18.6  xenscsi.sys
    18.7 +xenconfig.sys
    18.8  
    18.9  [XenScsi_Inst.NT.Services]
   18.10  AddService=XenScsi,2,XenScsi_Service, XenScsi_EventLog
   18.11 +AddService=XenConfig,0,XenConfig_Service
   18.12  
   18.13  [XenScsi_Service]
   18.14  DisplayName    = %XenScsi.SVCDESC%                            
   18.15 @@ -37,7 +39,7 @@ StartType      = 0
   18.16  ErrorControl   = 1
   18.17  LoadOrderGroup = System Bus Extender
   18.18  ServiceBinary  = %12%\xenscsi.sys                            
   18.19 -AddReg = XenScsi_Service_AddReg
   18.20 +AddReg = XenScsi_Service_AddReg,XenScsi_XenConfig_AddReg
   18.21  
   18.22  [XenScsi_Service_AddReg]
   18.23  HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
   18.24 @@ -50,10 +52,33 @@ HKR,,EventMessageFile,0x00020000,"%Syste
   18.25  HKR,,TypesSupported,0x00010001,7
   18.26  
   18.27  [XenScsi_Inst.NT.HW]
   18.28 -AddReg = XenScsi_Inst_HW_AddReg
   18.29 +AddReg = XenScsi_XenConfig_AddReg, XenScsi_UpperFilter_AddReg
   18.30 +
   18.31 +[XenScsi_XenConfig_AddReg]
   18.32 +HKR,"XenConfig\ring-ref", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_RING%
   18.33 +HKR,"XenConfig\event-channel", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_EVENT_CHANNEL_IRQ%
   18.34 +HKR,"XenConfig\b-dev", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_FRONT%
   18.35 +HKR,"XenConfig\grants", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_GRANT_ENTRIES%
   18.36 +HKR,"XenConfig\grants", "value", %FLG_ADDREG_TYPE_DWORD%, 144
   18.37 +
   18.38 +[XenScsi_UpperFilter_AddReg]
   18.39 +HKR,,UpperFilters,0x10000,XenConfig
   18.40 +
   18.41 +[XenConfig_Service]
   18.42 +DisplayName    = %XenConfig.SVCDESC%                            
   18.43 +ServiceType    = 1
   18.44 +StartType      = 0
   18.45 +ErrorControl   = 1
   18.46 +LoadOrderGroup = System Bus Extender
   18.47 +ServiceBinary  = %12%\xenconfig.sys                            
   18.48 +AddReg = XenConfig_Service_AddReg
   18.49 +
   18.50 +[XenConfig_Service_AddReg]
   18.51 +HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
   18.52  
   18.53  [SourceDisksFiles]
   18.54  xenscsi.sys=1
   18.55 +xenconfig.sys=1
   18.56  
   18.57  [SourceDisksNames.x86]
   18.58  1 = %DISK_NAME%,,,.\i386
   18.59 @@ -65,4 +90,16 @@ 1 = %DISK_NAME%,,,.\amd64
   18.60  XenGplPv = "Xen GPL PV Driver Developers"
   18.61  XenScsi.SVCDESC = "Xen SCSI Driver"
   18.62  XenScsi.DRVDESC = "Xen SCSI Driver"
   18.63 +XenConfig.SVCDESC = "Xen Config Resource Generator"
   18.64  DISK_NAME = "Xen SCSI Device Driver Install Disk"
   18.65 +FLG_ADDREG_TYPE_DWORD = 0x00010001
   18.66 +XEN_INIT_TYPE_END = 0
   18.67 +XEN_INIT_TYPE_WRITE_STRING = 1
   18.68 +XEN_INIT_TYPE_RING = 2
   18.69 +XEN_INIT_TYPE_EVENT_CHANNEL = 3
   18.70 +XEN_INIT_TYPE_EVENT_CHANNEL_IRQ = 4
   18.71 +XEN_INIT_TYPE_READ_STRING_FRONT = 5
   18.72 +XEN_INIT_TYPE_READ_STRING_BACK = 6
   18.73 +XEN_INIT_TYPE_VECTORS = 7
   18.74 +XEN_INIT_TYPE_GRANT_ENTRIES = 8
   18.75 +XEN_INIT_TYPE_COPY_PTR = 9
    19.1 --- a/xenvbd/xenvbd.h	Sat Jun 14 23:16:49 2008 +1000
    19.2 +++ b/xenvbd/xenvbd.h	Tue Jun 17 10:35:26 2008 +1000
    19.3 @@ -81,7 +81,6 @@ typedef struct {
    19.4  } blkif_shadow_t;
    19.5  
    19.6  #define SHADOW_ENTRIES 16
    19.7 -//#define GRANT_ENTRIES ((SHADOW_ENTRIES * BLKIF_MAX_SEGMENTS_PER_REQUEST) / 2)
    19.8  #define MAX_GRANT_ENTRIES 512
    19.9  
   19.10  typedef enum {
    20.1 --- a/xenvbd/xenvbd.inx	Sat Jun 14 23:16:49 2008 +1000
    20.2 +++ b/xenvbd/xenvbd.inx	Tue Jun 17 10:35:26 2008 +1000
    20.3 @@ -39,7 +39,7 @@ StartType      = 0
    20.4  ErrorControl   = 1
    20.5  LoadOrderGroup = System Bus Extender
    20.6  ServiceBinary  = %12%\xenvbd.sys                            
    20.7 -AddReg = XenVbd_Service_AddReg,XenVbd_XenConfig_AddReg
    20.8 +AddReg = XenVbd_Service_AddReg
    20.9  
   20.10  [XenVbd_Service_AddReg]
   20.11  HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001