win-pvdrivers

changeset 77:b9b4b731f890

Tidyups and work on getting xennet at least as functional as it was before I started messing with it :)
author James Harper <james.harper@bendigoit.com.au>
date Fri Dec 28 23:21:49 2007 +1100 (2007-12-28)
parents dfa772949c6e
children 63da9239cfe2
files common/include/xen_public.h xenenum/sources xenenum/xenenum.c xennet/sources xennet/xennet.c xenpci/sources xenpci/xenpci.c xenvbd/sources xenvbd/xenvbd.inx
line diff
     1.1 --- a/common/include/xen_public.h	Thu Dec 27 22:23:33 2007 +1100
     1.2 +++ b/common/include/xen_public.h	Fri Dec 28 23:21:49 2007 +1100
     1.3 @@ -30,6 +30,9 @@ DEFINE_GUID( GUID_XEN_IFACE, 0x5C568AC5,
     1.4  typedef PHYSICAL_ADDRESS
     1.5  (*PXEN_ALLOCMMIO)(ULONG Length);
     1.6  
     1.7 +typedef PHYSICAL_ADDRESS
     1.8 +(*PXEN_FREEMEM)(PVOID Ptr);
     1.9 +
    1.10  typedef NTSTATUS
    1.11  (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
    1.12  
    1.13 @@ -84,6 +87,7 @@ typedef struct _XEN_IFACE {
    1.14    INTERFACE InterfaceHeader;
    1.15  
    1.16    PXEN_ALLOCMMIO AllocMMIO;
    1.17 +  PXEN_FREEMEM FreeMem;
    1.18  
    1.19    PXEN_EVTCHN_BIND EvtChn_Bind;
    1.20    PXEN_EVTCHN_UNBIND EvtChn_Unbind;
     2.1 --- a/xenenum/sources	Thu Dec 27 22:23:33 2007 +1100
     2.2 +++ b/xenenum/sources	Fri Dec 28 23:21:49 2007 +1100
     2.3 @@ -1,7 +1,7 @@
     2.4  TARGETNAME=xenenum
     2.5  TARGETTYPE=DRIVER
     2.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     2.7 -VERSION=0.5.0.12
     2.8 +VERSION=0.5.0.11
     2.9  KMDF_VERSION=1
    2.10  MSC_WARNING_LEVEL=/W4
    2.11  INF_NAME=xenenum
     3.1 --- a/xenenum/xenenum.c	Thu Dec 27 22:23:33 2007 +1100
     3.2 +++ b/xenenum/xenenum.c	Fri Dec 28 23:21:49 2007 +1100
     3.3 @@ -433,7 +433,10 @@ XenEnum_WatchHandler(char *Path, PVOID D
     3.4      RtlInitAnsiString(&AnsiBuf, Bits[1]);
     3.5      RtlAnsiStringToUnicodeString(&IdentificationDescription.DeviceType, &AnsiBuf, TRUE);
     3.6      IdentificationDescription.DeviceIndex = atoi(Bits[2]);
     3.7 -    Status = WdfChildListAddOrUpdateChildDescriptionAsPresent(ChildList, &IdentificationDescription.Header, NULL);
     3.8 +    if (IdentificationDescription.DeviceIndex > 0)
     3.9 +    {
    3.10 +      Status = WdfChildListAddOrUpdateChildDescriptionAsPresent(ChildList, &IdentificationDescription.Header, NULL);
    3.11 +    }
    3.12    }
    3.13    else if (Count > 3)
    3.14    {
    3.15 @@ -534,6 +537,7 @@ XenEnum_ChildListCreateDevice(WDFCHILDLI
    3.16    ChildDeviceData->XenInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
    3.17  
    3.18    ChildDeviceData->XenInterface.AllocMMIO = XenInterface.AllocMMIO;
    3.19 +  ChildDeviceData->XenInterface.FreeMem = XenInterface.FreeMem;
    3.20  
    3.21    ChildDeviceData->XenInterface.EvtChn_Bind = XenInterface.EvtChn_Bind;
    3.22    ChildDeviceData->XenInterface.EvtChn_Unbind = XenInterface.EvtChn_Unbind;
     4.1 --- a/xennet/sources	Thu Dec 27 22:23:33 2007 +1100
     4.2 +++ b/xennet/sources	Fri Dec 28 23:21:49 2007 +1100
     4.3 @@ -1,7 +1,7 @@
     4.4  TARGETNAME=XENNET
     4.5  TARGETTYPE=DRIVER
     4.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     4.7 -VERSION=0.5.0.0
     4.8 +VERSION=0.5.0.8
     4.9  KMDF_VERSION=1
    4.10  MSC_WARNING_LEVEL=/W4
    4.11  INF_NAME=xennet
     5.1 --- a/xennet/xennet.c	Thu Dec 27 22:23:33 2007 +1100
     5.2 +++ b/xennet/xennet.c	Fri Dec 28 23:21:49 2007 +1100
     5.3 @@ -58,7 +58,7 @@ struct xennet_info
     5.4    UINT8 perm_mac_addr[ETH_ALEN];
     5.5    UINT8 curr_mac_addr[ETH_ALEN];
     5.6  
     5.7 -  char Path[128];
     5.8 +//  char Path[128];
     5.9    char BackendPath[128];
    5.10    XEN_IFACE XenInterface;
    5.11  
    5.12 @@ -107,6 +107,8 @@ struct xennet_info
    5.13    ULONG64 stat_tx_error;
    5.14    ULONG64 stat_rx_error;
    5.15    ULONG64 stat_rx_no_buffer;
    5.16 +
    5.17 +  KEVENT backend_ready_event;
    5.18  };
    5.19  
    5.20  /* This function copied from linux's lib/vsprintf.c, see it for attribution */
    5.21 @@ -403,7 +405,7 @@ XenNet_BackEndStateHandler(char *Path, P
    5.22    xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
    5.23      XBT_NIL, Path, &Value);
    5.24    be_state = atoi(Value);
    5.25 -  ExFreePool(Value);
    5.26 +  xi->XenInterface.FreeMem(Value);
    5.27  
    5.28    switch (be_state)
    5.29    {
    5.30 @@ -452,7 +454,7 @@ XenNet_BackEndStateHandler(char *Path, P
    5.31      for (i = 0; params[i].name; i++)
    5.32      {
    5.33        RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/%s",
    5.34 -        xi->Path, params[i].name);
    5.35 +        xi->pdoData->Path, params[i].name);
    5.36        err = xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
    5.37          XBT_NIL, TmpPath, "%d", params[i].value);
    5.38        if (err)
    5.39 @@ -469,7 +471,7 @@ XenNet_BackEndStateHandler(char *Path, P
    5.40      XenNet_AllocRXBuffers(xi);
    5.41  
    5.42      KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
    5.43 -    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->Path);
    5.44 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdoData->Path);
    5.45      xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
    5.46        XBT_NIL, TmpPath, "%d", XenbusStateConnected);
    5.47  
    5.48 @@ -485,6 +487,7 @@ XenNet_BackEndStateHandler(char *Path, P
    5.49  
    5.50    case XenbusStateConnected:
    5.51      KdPrint((__DRIVER_NAME "     Backend State Changed to Connected\n"));  
    5.52 +    KeSetEvent(&xi->backend_ready_event, 1, FALSE);
    5.53      break;
    5.54  
    5.55    case XenbusStateClosing:
    5.56 @@ -535,7 +538,6 @@ XenNet_Init(
    5.57    WDF_OBJECT_ATTRIBUTES wdf_attrs;
    5.58    char *msg;
    5.59    char *Value;
    5.60 -  char **vif_devs;
    5.61    char TmpPath[128];
    5.62  
    5.63    UNREFERENCED_PARAMETER(OpenErrorStatus);
    5.64 @@ -640,85 +642,59 @@ XenNet_Init(
    5.65      goto err;
    5.66    }
    5.67  
    5.68 -
    5.69    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath),
    5.70 -      "%s/%d/state", xi->pdoData->Path, xi->pdoData->DeviceIndex);
    5.71 -
    5.72 -  msg = xi->XenInterface.XenBus_List(xi->XenInterface.InterfaceHeader.Context,
    5.73 -    XBT_NIL, "device/vif", &vif_devs);
    5.74 -  if (msg)
    5.75 +      "%s/backend", xi->pdoData->Path);
    5.76 +  KdPrint(("About to read %s to get backend path\n", TmpPath));
    5.77 +  xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
    5.78 +      XBT_NIL, TmpPath, &Value);
    5.79 +  if (!Value)
    5.80    {
    5.81 -    KdPrint((__DRIVER_NAME ": " __FUNCTION__ ": List retval is nonzero!\n"));
    5.82 +    KdPrint((__DRIVER_NAME "    Failed to read backend path\n"));
    5.83      status = NDIS_STATUS_FAILURE;
    5.84      goto err;
    5.85    }
    5.86 -
    5.87 -  for (i = 0; vif_devs[i]; i++)
    5.88 -  {
    5.89 -    if (i > 0)
    5.90 -    {
    5.91 -      KdPrint((__DRIVER_NAME "Can only handle 1 vif so far, ignoring vif %s\n", vif_devs[i]));
    5.92 -      continue;
    5.93 -    }
    5.94 -    RtlStringCbPrintfA(xi->Path, ARRAY_SIZE(xi->Path), "device/vif/%s", vif_devs[i]);
    5.95 -
    5.96 -    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath),
    5.97 -      "device/vif/%s/state", vif_devs[i]);
    5.98 -    KdPrint(("%s\n", TmpPath));
    5.99 +  // Check for Value == NULL here
   5.100 +  RtlStringCbCopyA(xi->BackendPath, ARRAY_SIZE(xi->BackendPath), Value);
   5.101 +  KdPrint((__DRIVER_NAME "backend path = %s\n", xi->BackendPath));
   5.102  
   5.103 -    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/backend", xi->Path);
   5.104 -    xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
   5.105 -      XBT_NIL, TmpPath, &Value);
   5.106 -    if (!Value)
   5.107 -    {
   5.108 -      KdPrint((__DRIVER_NAME "    backend Read Failed\n"));
   5.109 -    }
   5.110 -    else
   5.111 -    {
   5.112 -      RtlStringCbCopyA(xi->BackendPath, ARRAY_SIZE(xi->BackendPath), Value);
   5.113 -      KdPrint((__DRIVER_NAME "backend path = %s\n", xi->BackendPath));
   5.114 -    }
   5.115 -    ExFreePool(Value);
   5.116 +  KeInitializeEvent(&xi->backend_ready_event, SynchronizationEvent, FALSE);  
   5.117  
   5.118 -    /* Add watch on backend state */
   5.119 -    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->BackendPath);
   5.120 -    xi->XenInterface.XenBus_AddWatch(xi->XenInterface.InterfaceHeader.Context,
   5.121 +  /* Add watch on backend state */
   5.122 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->BackendPath);
   5.123 +  xi->XenInterface.XenBus_AddWatch(xi->XenInterface.InterfaceHeader.Context,
   5.124        XBT_NIL, TmpPath, XenNet_BackEndStateHandler, xi);
   5.125  
   5.126 -    /* get mac address */
   5.127 -    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/mac", xi->Path);
   5.128 -    xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
   5.129 -      XBT_NIL, TmpPath, &Value);
   5.130 -    if (!Value)
   5.131 -    {
   5.132 -      KdPrint((__DRIVER_NAME "    mac Read Failed\n"));
   5.133 -    }
   5.134 -    else
   5.135 -    {
   5.136 -      char *s, *e;
   5.137 -      int i;
   5.138 -
   5.139 -      s = Value;
   5.140 +  // wait here for signal that we are all set up
   5.141 +  KeWaitForSingleObject(&xi->backend_ready_event, Executive, KernelMode, FALSE, NULL);
   5.142  
   5.143 -      for (i = 0; i < ETH_ALEN; i++) {
   5.144 -        xi->perm_mac_addr[i] = (UINT8)simple_strtoul(s, &e, 16);
   5.145 -        if ((s == e) || (*e != ((i == ETH_ALEN-1) ? '\0' : ':'))) {
   5.146 -          KdPrint((__DRIVER_NAME "Error parsing MAC address\n"));
   5.147 -          ExFreePool(Value);
   5.148 -          ExFreePool(vif_devs);
   5.149 -          status = NDIS_STATUS_FAILURE;
   5.150 -          goto err;
   5.151 -        }
   5.152 -        s = e + 1;
   5.153 +  /* get mac address */
   5.154 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/mac", xi->BackendPath);
   5.155 +  xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
   5.156 +      XBT_NIL, TmpPath, &Value);
   5.157 +  if (!Value)
   5.158 +  {
   5.159 +    KdPrint((__DRIVER_NAME "    mac Read Failed\n"));
   5.160 +    status = NDIS_STATUS_FAILURE;
   5.161 +    goto err;
   5.162 +  }
   5.163 +  else
   5.164 +  {
   5.165 +    char *s, *e;
   5.166 +    int i;
   5.167 +    s = Value;
   5.168 +    for (i = 0; i < ETH_ALEN; i++) {
   5.169 +      xi->perm_mac_addr[i] = (UINT8)simple_strtoul(s, &e, 16);
   5.170 +      if ((s == e) || (*e != ((i == ETH_ALEN-1) ? '\0' : ':'))) {
   5.171 +        KdPrint((__DRIVER_NAME "Error parsing MAC address\n"));
   5.172 +        xi->XenInterface.FreeMem(Value);
   5.173 +        status = NDIS_STATUS_FAILURE;
   5.174 +        goto err;
   5.175        }
   5.176 -      memcpy(xi->curr_mac_addr, xi->perm_mac_addr, ETH_ALEN);
   5.177 +      s = e + 1;
   5.178      }
   5.179 -    ExFreePool(Value);
   5.180 -
   5.181 -    //XenVbd_HotPlugHandler(buffer, NULL);
   5.182 -    //ExFreePoolWithTag(bdDevices[i], XENPCI_POOL_TAG);
   5.183 +    memcpy(xi->curr_mac_addr, xi->perm_mac_addr, ETH_ALEN);
   5.184 +    xi->XenInterface.FreeMem(Value);
   5.185    }
   5.186 -  ExFreePool(vif_devs);
   5.187  
   5.188    return NDIS_STATUS_SUCCESS;
   5.189  
     6.1 --- a/xenpci/sources	Thu Dec 27 22:23:33 2007 +1100
     6.2 +++ b/xenpci/sources	Fri Dec 28 23:21:49 2007 +1100
     6.3 @@ -1,7 +1,7 @@
     6.4  TARGETNAME=XENPCI
     6.5  TARGETTYPE=DRIVER
     6.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     6.7 -VERSION=0.5.0.5
     6.8 +VERSION=0.5.0.6
     6.9  KMDF_VERSION=1
    6.10  MSC_WARNING_LEVEL=/W4
    6.11  INF_NAME=xenpci
     7.1 --- a/xenpci/xenpci.c	Thu Dec 27 22:23:33 2007 +1100
     7.2 +++ b/xenpci/xenpci.c	Fri Dec 28 23:21:49 2007 +1100
     7.3 @@ -203,6 +203,11 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
     7.4    return status;
     7.5  }
     7.6  
     7.7 +static XenPCI_FreeMem(PVOID Ptr)
     7.8 +{
     7.9 +  ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
    7.10 +}
    7.11 +
    7.12  static NTSTATUS
    7.13  get_hypercall_stubs(WDFDEVICE Device)
    7.14  {
    7.15 @@ -803,6 +808,7 @@ XenPCI_ChildListCreateDevice(
    7.16    ChildDeviceData->XenInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
    7.17  
    7.18    ChildDeviceData->XenInterface.AllocMMIO = XenPCI_AllocMMIO;
    7.19 +  ChildDeviceData->XenInterface.FreeMem = XenPCI_FreeMem;
    7.20  
    7.21    ChildDeviceData->XenInterface.EvtChn_Bind = EvtChn_Bind;
    7.22    ChildDeviceData->XenInterface.EvtChn_Unbind = EvtChn_Unbind;
     8.1 --- a/xenvbd/sources	Thu Dec 27 22:23:33 2007 +1100
     8.2 +++ b/xenvbd/sources	Fri Dec 28 23:21:49 2007 +1100
     8.3 @@ -1,7 +1,7 @@
     8.4  TARGETNAME=XENVBD
     8.5  TARGETTYPE=DRIVER
     8.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     8.7 -VERSION=0.5.0.5
     8.8 +VERSION=0.5.0.6
     8.9  KMDF_VERSION=1
    8.10  MSC_WARNING_LEVEL=/W4
    8.11  INF_NAME=xenvbd
     9.1 --- a/xenvbd/xenvbd.inx	Thu Dec 27 22:23:33 2007 +1100
     9.2 +++ b/xenvbd/xenvbd.inx	Fri Dec 28 23:21:49 2007 +1100
     9.3 @@ -42,8 +42,6 @@ AddReg = XenVbd_Service_AddReg
     9.4  
     9.5  [XenVbd_Service_AddReg]
     9.6  HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
     9.7 -;HKR,,"LowerFilters",0x00010000,"XenAddResource"
     9.8 -HKR,"w00t"", "XXX", 0x00010001, 0x00000001
     9.9  
    9.10  [XenVbd_Inst.NT.CoInstallers]
    9.11  AddReg=CoInstaller_AddReg