win-pvdrivers

diff xenpci/gnttbl.c @ 766:6300617040e0

Big changes - not ready for production use.
Removed all the custom DMA handling code as it was completely incompatible with the Windows verifier.
Added liblfds (using the lock free stack) from liblfds.org so that grant's can be obtained at DIRQL.
Fixed xennet and xenvbd to support the changes.
xenusb and xenscsi almost certainly will not yet work after the changes.
author James Harper <james.harper@bendigoit.com.au>
date Sun Jan 31 21:28:42 2010 +1100 (2010-01-31)
parents a88fe72e3597
children 5e3af133e8a6
line diff
     1.1 --- a/xenpci/gnttbl.c	Sun Jan 17 15:16:50 2010 +1100
     1.2 +++ b/xenpci/gnttbl.c	Sun Jan 31 21:28:42 2010 +1100
     1.3 @@ -23,19 +23,8 @@ VOID
     1.4  GntTbl_PutRef(PVOID Context, grant_ref_t ref)
     1.5  {
     1.6    PXENPCI_DEVICE_DATA xpdd = Context;
     1.7 -  KIRQL old_irql = 0; /* prevents compiler warnings due to Acquire done in if statement */
     1.8  
     1.9 -  if (xpdd->suspend_state != SUSPEND_STATE_HIGH_IRQL)
    1.10 -  {
    1.11 -    ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
    1.12 -    KeAcquireSpinLock(&xpdd->grant_lock, &old_irql);
    1.13 -  }
    1.14 -  xpdd->gnttab_list[xpdd->gnttab_list_free] = ref;
    1.15 -  xpdd->gnttab_list_free++;
    1.16 -  if (xpdd->suspend_state != SUSPEND_STATE_HIGH_IRQL)
    1.17 -  {
    1.18 -    KeReleaseSpinLock(&xpdd->grant_lock, old_irql);
    1.19 -  }
    1.20 +  stack_push(xpdd->gnttab_ss, (PVOID)ref);
    1.21  }
    1.22  
    1.23  grant_ref_t
    1.24 @@ -43,25 +32,14 @@ GntTbl_GetRef(PVOID Context)
    1.25  {
    1.26    PXENPCI_DEVICE_DATA xpdd = Context;
    1.27    unsigned int ref;
    1.28 -  KIRQL old_irql = 0; /* prevents compiler warnings due to Acquire done in if statement */
    1.29 -  int suspend_state = xpdd->suspend_state;
    1.30 -  
    1.31 -  if (suspend_state != SUSPEND_STATE_HIGH_IRQL)
    1.32 +  PVOID ptr_ref;
    1.33 +
    1.34 +  if (!stack_pop(xpdd->gnttab_ss, &ptr_ref))
    1.35    {
    1.36 -    ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
    1.37 -    KeAcquireSpinLock(&xpdd->grant_lock, &old_irql);
    1.38 -  }
    1.39 -  if (!xpdd->gnttab_list_free)
    1.40 -  {
    1.41 -    if (suspend_state != SUSPEND_STATE_HIGH_IRQL)
    1.42 -      KeReleaseSpinLock(&xpdd->grant_lock, old_irql);
    1.43 -    KdPrint((__DRIVER_NAME "     No free grant refs\n"));    
    1.44 +    KdPrint((__DRIVER_NAME "     No free grant refs\n"));
    1.45      return INVALID_GRANT_REF;
    1.46    }
    1.47 -  xpdd->gnttab_list_free--;
    1.48 -  ref = xpdd->gnttab_list[xpdd->gnttab_list_free];
    1.49 -  if (suspend_state != SUSPEND_STATE_HIGH_IRQL)
    1.50 -    KeReleaseSpinLock(&xpdd->grant_lock, old_irql);
    1.51 +  ref = (grant_ref_t)ptr_ref;
    1.52  
    1.53    return ref;
    1.54  }
    1.55 @@ -177,8 +155,6 @@ GntTbl_Init(PXENPCI_DEVICE_DATA xpdd)
    1.56    
    1.57    FUNCTION_ENTER();
    1.58    
    1.59 -  KeInitializeSpinLock(&xpdd->grant_lock);
    1.60 -
    1.61    xpdd->grant_frames = GntTbl_QueryMaxFrames(xpdd);
    1.62    KdPrint((__DRIVER_NAME "     grant_frames = %d\n", xpdd->grant_frames));
    1.63    grant_entries = min(NR_GRANT_ENTRIES, (xpdd->grant_frames * PAGE_SIZE / sizeof(grant_entry_t)));
    1.64 @@ -187,8 +163,6 @@ GntTbl_Init(PXENPCI_DEVICE_DATA xpdd)
    1.65    ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
    1.66    xpdd->gnttab_table_copy = ExAllocatePoolWithTag(NonPagedPool, xpdd->grant_frames * PAGE_SIZE, XENPCI_POOL_TAG);
    1.67    ASSERT(xpdd->gnttab_table_copy); // lazy
    1.68 -  xpdd->gnttab_list = ExAllocatePoolWithTag(NonPagedPool, sizeof(grant_ref_t) * grant_entries, XENPCI_POOL_TAG);
    1.69 -  ASSERT(xpdd->gnttab_list); // lazy
    1.70    xpdd->gnttab_table_physical = XenPci_AllocMMIO(xpdd, PAGE_SIZE * xpdd->grant_frames);
    1.71    xpdd->gnttab_table = MmMapIoSpace(xpdd->gnttab_table_physical, PAGE_SIZE * xpdd->grant_frames, MmNonCached);
    1.72    if (!xpdd->gnttab_table)
    1.73 @@ -197,11 +171,11 @@ GntTbl_Init(PXENPCI_DEVICE_DATA xpdd)
    1.74      // this should be a show stopper...
    1.75      return;
    1.76    }
    1.77 +
    1.78 +  stack_new(&xpdd->gnttab_ss, grant_entries);
    1.79    
    1.80 -  RtlZeroMemory(xpdd->gnttab_list, sizeof(grant_ref_t) * grant_entries);
    1.81 -  xpdd->gnttab_list_free = 0;
    1.82    for (i = NR_RESERVED_ENTRIES; i < grant_entries; i++)
    1.83 -    GntTbl_PutRef(xpdd, i);
    1.84 +    stack_push(xpdd->gnttab_ss, (PVOID)i);
    1.85    
    1.86    GntTbl_Map(xpdd, 0, xpdd->grant_frames - 1);
    1.87