win-pvdrivers

changeset 137:76b6a278e97d

Attempted to use the AllocMMIO function so that it isn't such a problem when the memory can't be freed properly in xennet unload. It didn't work though.
author James Harper <james.harper@bendigoit.com.au>
date Sat Jan 19 17:42:05 2008 +1100 (2008-01-19)
parents 351dfc4aa660
children 7ff0dd6ba883
files xennet/sources xennet/xennet.c xenpci/gnttbl.c xenpci/sources xenpci/xenpci.c
line diff
     1.1 --- a/xennet/sources	Sat Jan 19 14:51:33 2008 +1100
     1.2 +++ b/xennet/sources	Sat Jan 19 17:42:05 2008 +1100
     1.3 @@ -1,7 +1,7 @@
     1.4  TARGETNAME=XENNET
     1.5  TARGETTYPE=DRIVER
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7 -VERSION=0.5.0.97
     1.8 +VERSION=0.5.0.102
     1.9  KMDF_VERSION=1
    1.10  MSC_WARNING_LEVEL=/W4
    1.11  INF_NAME=xennet
     2.1 --- a/xennet/xennet.c	Sat Jan 19 14:51:33 2008 +1100
     2.2 +++ b/xennet/xennet.c	Sat Jan 19 17:42:05 2008 +1100
     2.3 @@ -32,6 +32,8 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  
     2.5  #define GRANT_INVALID_REF 0
     2.6  
     2.7 +#define XEN_DOESNT_UNGRANT_RINGS 1
     2.8 +
     2.9  /* couldn't get regular xen ring macros to work...*/
    2.10  #define __NET_RING_SIZE(type, _sz) \
    2.11      (__RD32( \
    2.12 @@ -87,9 +89,14 @@ struct xennet_info
    2.13    struct netif_tx_sring *tx_pgs;
    2.14    struct netif_rx_sring *rx_pgs;
    2.15  
    2.16 +#if !defined(XEN_DOESNT_UNGRANT_RINGS)
    2.17    /* MDLs for the above */
    2.18    PMDL tx_mdl;
    2.19    PMDL rx_mdl;
    2.20 +#else
    2.21 +  PHYSICAL_ADDRESS tx_phys;
    2.22 +  PHYSICAL_ADDRESS rx_phys;
    2.23 +#endif
    2.24  
    2.25    /* Packets given to netback. The first entry in tx_pkts
    2.26     * is an index into a chain of free entries. */
    2.27 @@ -627,8 +634,7 @@ XenNet_BackEndStateHandler(char *Path, P
    2.28      xi->XenInterface.EvtChn_BindDpc(xi->XenInterface.InterfaceHeader.Context,
    2.29        xi->event_channel, XenNet_Interrupt, xi);
    2.30  
    2.31 -    /* TODO: must free pages in MDL as well as MDL using MmFreePagesFromMdl and ExFreePool */
    2.32 -    // or, allocate mem and then get mdl, then free mdl
    2.33 +#if !defined(XEN_DOESNT_UNGRANT_RINGS)
    2.34      xi->tx_mdl = AllocatePage();
    2.35  PageAlloc++;
    2.36      xi->tx_pgs = MmGetMdlVirtualAddress(xi->tx_mdl);
    2.37 @@ -646,6 +652,34 @@ PageAlloc++;
    2.38      xi->rx_ring_ref = xi->XenInterface.GntTbl_GrantAccess(
    2.39        xi->XenInterface.InterfaceHeader.Context, 0,
    2.40        *MmGetMdlPfnArray(xi->rx_mdl), FALSE);
    2.41 +#else
    2.42 +    xi->tx_phys = xi->XenInterface.AllocMMIO(
    2.43 +      xi->XenInterface.InterfaceHeader.Context, PAGE_SIZE);
    2.44 +KdPrint(("tx_phys = %08x\n", xi->tx_phys.LowPart));
    2.45 +    xi->tx_pgs = MmMapIoSpace(xi->tx_phys,
    2.46 +      PAGE_SIZE, MmNonCached);
    2.47 +KdPrint(("tx_pgs = %08p\n", xi->tx_pgs));
    2.48 +    SHARED_RING_INIT(xi->tx_pgs);
    2.49 +    FRONT_RING_INIT(&xi->tx, xi->tx_pgs, PAGE_SIZE);
    2.50 +KdPrint(("tx_pfn = %08x\n", xi->tx_phys.QuadPart >> PAGE_SHIFT));
    2.51 +    xi->tx_ring_ref = xi->XenInterface.GntTbl_GrantAccess(
    2.52 +      xi->XenInterface.InterfaceHeader.Context, 0,
    2.53 +      (ULONG)(xi->tx_phys.QuadPart >> PAGE_SHIFT), FALSE);
    2.54 +KdPrint(("tx_ring_ref = %08x\n", xi->tx_ring_ref));
    2.55 +
    2.56 +    xi->rx_phys = xi->XenInterface.AllocMMIO(
    2.57 +      xi->XenInterface.InterfaceHeader.Context, PAGE_SIZE);
    2.58 +KdPrint(("rx_phys = %08x\n", xi->rx_phys.LowPart));
    2.59 +    xi->rx_pgs = MmMapIoSpace(xi->rx_phys,
    2.60 +      PAGE_SIZE, MmNonCached);
    2.61 +KdPrint(("rx_pgs = %08x\n", xi->rx_pgs));
    2.62 +    SHARED_RING_INIT(xi->rx_pgs);
    2.63 +    FRONT_RING_INIT(&xi->rx, xi->rx_pgs, PAGE_SIZE);
    2.64 +    xi->rx_ring_ref = xi->XenInterface.GntTbl_GrantAccess(
    2.65 +      xi->XenInterface.InterfaceHeader.Context, 0,
    2.66 +      (ULONG)(xi->rx_phys.QuadPart >> PAGE_SHIFT), FALSE);
    2.67 +KdPrint(("rx_ring_ref = %08x\n", xi->rx_ring_ref));
    2.68 +#endif
    2.69  
    2.70      /* fixup array for dynamic values */
    2.71      params[0].value = xi->tx_ring_ref;
    2.72 @@ -1630,6 +1664,7 @@ XenNet_Shutdown(
    2.73  }
    2.74  
    2.75  /* Opposite of XenNet_Init */
    2.76 +VOID
    2.77  XenNet_Halt(
    2.78    IN NDIS_HANDLE MiniportAdapterContext
    2.79    )
    2.80 @@ -1687,6 +1722,7 @@ KdPrint((__DRIVER_NAME "     PageAlloc =
    2.81  KdPrint((__DRIVER_NAME "     PacketPoolAlloc = %d\n", PacketPoolAlloc));
    2.82  KdPrint((__DRIVER_NAME "     BufferPoolAlloc = %d\n", BufferPoolAlloc));
    2.83  
    2.84 +#if !defined(XEN_DOESNT_UNGRANT_RINGS)
    2.85    /* free TX resources */
    2.86    if (xi->XenInterface.GntTbl_EndAccess(if_cxt, xi->tx_ring_ref))
    2.87    {
    2.88 @@ -1697,18 +1733,6 @@ PageAlloc--;
    2.89    /* if EndAccess fails then tx/rx ring pages LEAKED -- it's not safe to reuse
    2.90       pages Dom0 still has access to */
    2.91    xi->tx_pgs = NULL;
    2.92 -  XenNet_TxBufferFree(xi);
    2.93 -
    2.94 -KdPrint((__DRIVER_NAME "     NdisAlloc = %d\n", NdisAlloc));
    2.95 -KdPrint((__DRIVER_NAME "     MdlAlloc = %d\n", MdlAlloc));
    2.96 -KdPrint((__DRIVER_NAME "     BufferAlloc = %d\n", BufferAlloc));
    2.97 -KdPrint((__DRIVER_NAME "     PacketAlloc = %d\n", PacketAlloc));
    2.98 -KdPrint((__DRIVER_NAME "     PageAlloc = %d\n", PageAlloc));
    2.99 -KdPrint((__DRIVER_NAME "     PacketPoolAlloc = %d\n", PacketPoolAlloc));
   2.100 -KdPrint((__DRIVER_NAME "     BufferPoolAlloc = %d\n", BufferPoolAlloc));
   2.101 -
   2.102 -  KdPrint((__DRIVER_NAME "     tx_outstanding = %d\n", xi->tx_outstanding));
   2.103 -  KdPrint((__DRIVER_NAME "     rx_outstanding = %d\n", xi->rx_outstanding));
   2.104  
   2.105    /* free RX resources */
   2.106    if (xi->XenInterface.GntTbl_EndAccess(if_cxt, xi->rx_ring_ref))
   2.107 @@ -1718,6 +1742,9 @@ KdPrint((__DRIVER_NAME "     BufferPoolA
   2.108  PageAlloc--;
   2.109    }
   2.110    xi->rx_pgs = NULL;
   2.111 +#endif
   2.112 +
   2.113 +  XenNet_TxBufferFree(xi);
   2.114    XenNet_RxBufferFree(MiniportAdapterContext);
   2.115  
   2.116    /* Remove watch on backend state */
   2.117 @@ -1748,6 +1775,14 @@ KdPrint((__DRIVER_NAME "     BufferPoolA
   2.118    NdisFreeMemory(xi, 0, 0); // <= DISPATCH_LEVEL
   2.119  NdisAlloc--;
   2.120  
   2.121 +KdPrint((__DRIVER_NAME "     NdisAlloc = %d\n", NdisAlloc));
   2.122 +KdPrint((__DRIVER_NAME "     MdlAlloc = %d\n", MdlAlloc));
   2.123 +KdPrint((__DRIVER_NAME "     BufferAlloc = %d\n", BufferAlloc));
   2.124 +KdPrint((__DRIVER_NAME "     PacketAlloc = %d\n", PacketAlloc));
   2.125 +KdPrint((__DRIVER_NAME "     PageAlloc = %d\n", PageAlloc));
   2.126 +KdPrint((__DRIVER_NAME "     PacketPoolAlloc = %d\n", PacketPoolAlloc));
   2.127 +KdPrint((__DRIVER_NAME "     BufferPoolAlloc = %d\n", BufferPoolAlloc));
   2.128 +
   2.129    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.130  }
   2.131  
     3.1 --- a/xenpci/gnttbl.c	Sat Jan 19 14:51:33 2008 +1100
     3.2 +++ b/xenpci/gnttbl.c	Sat Jan 19 17:42:05 2008 +1100
     3.3 @@ -109,6 +109,8 @@ GntTbl_GrantAccess(
     3.4  
     3.5    //KdPrint((__DRIVER_NAME " --> GntTbl_GrantAccess\n"));
     3.6  
     3.7 +  KdPrint((__DRIVER_NAME "     Granting access to frame %08x\n", frame));
     3.8 +
     3.9    /* TODO: locking? */
    3.10    ref = get_free_entry(Device);
    3.11    xpdd->gnttab_table[ref].frame = frame;
     4.1 --- a/xenpci/sources	Sat Jan 19 14:51:33 2008 +1100
     4.2 +++ b/xenpci/sources	Sat Jan 19 17:42:05 2008 +1100
     4.3 @@ -1,7 +1,7 @@
     4.4  TARGETNAME=XENPCI
     4.5  TARGETTYPE=DRIVER
     4.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     4.7 -VERSION=0.5.0.33
     4.8 +VERSION=0.5.0.37
     4.9  KMDF_VERSION=1
    4.10  MSC_WARNING_LEVEL=/W4
    4.11  INF_NAME=xenpci
     5.1 --- a/xenpci/xenpci.c	Sat Jan 19 14:51:33 2008 +1100
     5.2 +++ b/xenpci/xenpci.c	Sat Jan 19 17:42:05 2008 +1100
     5.3 @@ -274,6 +274,8 @@ XenPCI_AllocMMIO(WDFDEVICE Device, ULONG
     5.4  
     5.5    PHYSICAL_ADDRESS addr;
     5.6  
     5.7 +  len = (len + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
     5.8 +
     5.9    addr = xpdd->platform_mmio_addr;
    5.10    addr.QuadPart += xpdd->platform_mmio_alloc;
    5.11    xpdd->platform_mmio_alloc += len;