win-pvdrivers

changeset 432:68565fbe4425

Misc cleanups
Fix to the PSH code on Large Receive
Fix cert registration
author James Harper <james.harper@bendigoit.com.au>
date Wed Sep 17 23:28:47 2008 +1000 (2008-09-17)
parents 0514d961532d
children b1da81cc9868
files common.inc installer.nsi shutdownmon/shutdownmon.c xennet/xennet_rx.c xenpci/evtchn.c xenpci/xenpci.h xenpci/xenpci_fdo.c xenpci/xenpci_pdo.c xenvbd/xenvbd.c
line diff
     1.1 --- a/common.inc	Wed Sep 10 14:43:12 2008 +1000
     1.2 +++ b/common.inc	Wed Sep 17 23:28:47 2008 +1000
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.9.10.15
     1.5 +VERSION=0.9.10.17
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  MSC_WARNING_LEVEL=/W4
     1.8  INCLUDES = ..\common\include;..\common\include\public
     2.1 --- a/installer.nsi	Wed Sep 10 14:43:12 2008 +1000
     2.2 +++ b/installer.nsi	Wed Sep 17 23:28:47 2008 +1000
     2.3 @@ -6,7 +6,7 @@ Var ARCH_SPEC
     2.4  
     2.5  !define AppName "Xen PV Drivers"
     2.6  !define StartMenu "$SMPROGRAMS\${AppName}"
     2.7 -!define Version "0.9.11-pre15"
     2.8 +!define Version "0.9.11-pre18"
     2.9  #!define Version "$%VERSION%"
    2.10  Name "${AppName}"
    2.11  
    2.12 @@ -175,7 +175,9 @@ Section "Windows 2008 x64" win2k8x64
    2.13  SectionEnd
    2.14  
    2.15  Section /o "Install Cert" installcert
    2.16 -  ExecWait 'rundll32.exe cryptext.dll,CryptExtAddCER "$INSTDIR\ca.cer"'
    2.17 +  # For some reason this next line doesn't need any double quotes around
    2.18 +  # the filename, and in fact it breaks when they are included...
    2.19 +  ExecWait 'rundll32.exe cryptext.dll,CryptExtAddCER $INSTDIR\ca.cer'
    2.20  SectionEnd
    2.21  
    2.22  Section "Install Drivers" installdrivers
    2.23 @@ -219,6 +221,7 @@ Section "Install Drivers" installdrivers
    2.24  SectionEnd
    2.25  
    2.26  Section "Shutdown Monitor Service" shutdownmon
    2.27 +  ExecWait '"$INSTDIR\ShutdownMon.exe" -o'
    2.28    ExecWait '"$INSTDIR\ShutdownMon.exe" -u'
    2.29    ExecWait '"$INSTDIR\ShutdownMon.exe" -i'
    2.30    ExecWait 'NET START ShutdownMon'
     3.1 --- a/shutdownmon/shutdownmon.c	Wed Sep 10 14:43:12 2008 +1000
     3.2 +++ b/shutdownmon/shutdownmon.c	Wed Sep 17 23:28:47 2008 +1000
     3.3 @@ -12,6 +12,8 @@
     3.4  #define SERVICE_ID "ShutdownMon"
     3.5  #define SERVICE_NAME "Xen Shutdown Monitor"
     3.6  
     3.7 +#define OLD_SERVICE_ID "XenShutdownMon"
     3.8 +
     3.9  DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
    3.10  
    3.11  
    3.12 @@ -73,6 +75,43 @@ install_service()
    3.13  }
    3.14  
    3.15  static void
    3.16 +remove_old_service()
    3.17 +{
    3.18 +  SC_HANDLE manager_handle;
    3.19 +  SC_HANDLE service_handle;
    3.20 +
    3.21 +  manager_handle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    3.22 + 
    3.23 +  if (!manager_handle)
    3.24 +  {
    3.25 +    printf("OpenSCManager failed (%d)\n", GetLastError());
    3.26 +    return;
    3.27 +  }
    3.28 +
    3.29 +  service_handle = OpenService(manager_handle, OLD_SERVICE_ID, DELETE);
    3.30 + 
    3.31 +  if (!service_handle) 
    3.32 +  {
    3.33 +    printf("OpenService failed (%d)\n", GetLastError()); 
    3.34 +    CloseServiceHandle(manager_handle);
    3.35 +    return;
    3.36 +  }
    3.37 +
    3.38 +  if (!DeleteService(service_handle))
    3.39 +  {
    3.40 +    printf("DeleteService failed (%d)\n", GetLastError()); 
    3.41 +    CloseServiceHandle(service_handle); 
    3.42 +    CloseServiceHandle(manager_handle);
    3.43 +    return;
    3.44 +  }
    3.45 +
    3.46 +  printf("Old Service removed\n"); 
    3.47 +
    3.48 +  CloseServiceHandle(service_handle); 
    3.49 +  CloseServiceHandle(manager_handle);
    3.50 +}
    3.51 +
    3.52 +static void
    3.53  remove_service()
    3.54  {
    3.55    SC_HANDLE manager_handle;
    3.56 @@ -302,6 +341,7 @@ print_usage(char *name)
    3.57    printf(" -s run as service\n");
    3.58    printf(" -i install service\n");
    3.59    printf(" -u uninstall service\n");
    3.60 +  printf(" -o remove the old .NET service\n");
    3.61  }
    3.62  
    3.63  int __cdecl
    3.64 @@ -344,6 +384,9 @@ main(
    3.65    case 'u':
    3.66      remove_service();
    3.67      break;
    3.68 +  case 'o':
    3.69 +    remove_old_service();
    3.70 +    break;
    3.71    default:
    3.72      print_usage(argv[0]);
    3.73      return 1;
     4.1 --- a/xennet/xennet_rx.c	Wed Sep 10 14:43:12 2008 +1000
     4.2 +++ b/xennet/xennet_rx.c	Wed Sep 17 23:28:47 2008 +1000
     4.3 @@ -33,8 +33,6 @@ XenNet_RxBufferAlloc(struct xennet_info 
     4.4  
     4.5  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
     4.6  
     4.7 -  //ASSERT(!KeTestSpinLock(&xi->rx_lock));
     4.8 -
     4.9    batch_target = xi->rx_target - (req_prod - xi->rx.rsp_cons);
    4.10  
    4.11    if (batch_target < (xi->rx_target >> 2))
    4.12 @@ -363,7 +361,7 @@ XenNet_MakePackets(
    4.13      xi->rxpi.curr_mdl = 1;
    4.14  
    4.15    /* we can make certain assumptions here as the following code is only for tcp4 */
    4.16 -  psh = xi->rxpi.header[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 14] & 16;
    4.17 +  psh = xi->rxpi.header[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 13] & 8;
    4.18    while (xi->rxpi.tcp_remaining)
    4.19    {
    4.20      PUCHAR buffer;
    4.21 @@ -385,10 +383,14 @@ XenNet_MakePackets(
    4.22        NdisGetFirstBufferFromPacketSafe(packet, &mdl, &buffer, &buffer_length, &total_length, NormalPagePriority);
    4.23        if (xi->rxpi.tcp_remaining)
    4.24        {
    4.25 -        buffer[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 14] &= ~16;
    4.26 +        buffer[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 13] &= ~8;
    4.27 +        KdPrint((__DRIVER_NAME "     Seq %d cleared PSH\n", GET_NET_PULONG(&buffer[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 4])));
    4.28        }
    4.29        else
    4.30 -        buffer[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 14] |= 16;
    4.31 +      {
    4.32 +        buffer[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 13] |= 8;
    4.33 +        KdPrint((__DRIVER_NAME "     Seq %d set PSH\n", GET_NET_PULONG(&buffer[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 4])));
    4.34 +      }
    4.35      }
    4.36      XenNet_SumPacketData(&xi->rxpi, packet);
    4.37      entry = (PLIST_ENTRY)&packet->MiniportReservedEx[sizeof(PVOID)];
    4.38 @@ -422,6 +424,7 @@ XenNet_RxBufferCheck(struct xennet_info 
    4.39    struct netif_rx_response *rxrsp = NULL;
    4.40    struct netif_extra_info *ei;
    4.41    USHORT id;
    4.42 +  int more_to_do;
    4.43    
    4.44  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    4.45  
    4.46 @@ -500,12 +503,8 @@ XenNet_RxBufferCheck(struct xennet_info 
    4.47        }
    4.48      }
    4.49      xi->rx.rsp_cons = cons;
    4.50 -    if (!RING_HAS_UNCONSUMED_RESPONSES(&xi->rx))
    4.51 -    {
    4.52 -      xi->rx.sring->rsp_event = cons + 1;
    4.53 -      KeMemoryBarrier();
    4.54 -    }
    4.55 -  } while (RING_HAS_UNCONSUMED_RESPONSES(&xi->rx));
    4.56 +    RING_FINAL_CHECK_FOR_RESPONSES(&xi->rx, more_to_do);
    4.57 +  } while (more_to_do);
    4.58  
    4.59    if (xi->rxpi.more_frags || xi->rxpi.extra_info)
    4.60      KdPrint((__DRIVER_NAME "     Partial receive (more_frags = %d, extra_info = %d, total_length = %d, mdl_count = %d)\n", xi->rxpi.more_frags, xi->rxpi.extra_info, xi->rxpi.total_length, xi->rxpi.mdl_count));
     5.1 --- a/xenpci/evtchn.c	Wed Sep 10 14:43:12 2008 +1000
     5.2 +++ b/xenpci/evtchn.c	Wed Sep 17 23:28:47 2008 +1000
     5.3 @@ -23,17 +23,22 @@ Foundation, Inc., 51 Franklin Street, Fi
     5.4    #define xchg(p1, p2) InterlockedExchange((xen_long_t * volatile)p1, p2)
     5.5    /* rest implemented in mingw_extras.c */
     5.6  #elif defined(_X86_)
     5.7 -  #define xchg(p1, p2) _InterlockedExchange(p1, p2)
     5.8 -  #define synch_clear_bit(p1, p2) _interlockedbittestandreset(p2, p1)
     5.9 -  #define synch_set_bit(p1, p2) _interlockedbittestandset(p2, p1)
    5.10 +  #define xchg(p1, p2) InterlockedExchange(p1, p2)
    5.11 +//  #define synch_clear_bit(p1, p2) _interlockedbittestandreset(p2, p1)
    5.12 +//  #define synch_set_bit(p1, p2) _interlockedbittestandset(p2, p1)
    5.13 +  #define synch_clear_bit(p1, p2) InterlockedBitTestAndReset(p2, p1)
    5.14 +  #define synch_set_bit(p1, p2) InterlockedBitTestAndSet(p2, p1)
    5.15    #define bit_scan_forward(p1, p2) _BitScanForward(p1, p2)
    5.16  #else
    5.17 -  #define xchg(p1, p2) _InterlockedExchange64(p1, p2)
    5.18 +  #define xchg(p1, p2) InterlockedExchange64(p1, p2)
    5.19    #define synch_clear_bit(p1, p2) _interlockedbittestandreset64(p2, p1)
    5.20    #define synch_set_bit(p1, p2) _interlockedbittestandset64(p2, p1)
    5.21    #define bit_scan_forward(p1, p2) _BitScanForward64(p1, p2)
    5.22  #endif
    5.23  
    5.24 +#define BITS_PER_LONG (sizeof(xen_ulong_t) * 8)
    5.25 +#define BITS_PER_LONG_SHIFT (5 + (sizeof(xen_ulong_t) >> 3))
    5.26 +
    5.27  static DDKAPI VOID
    5.28  EvtChn_DpcBounce(PRKDPC Dpc, PVOID Context, PVOID SystemArgument1, PVOID SystemArgument2)
    5.29  {
    5.30 @@ -52,8 +57,6 @@ EvtChn_DpcBounce(PRKDPC Dpc, PVOID Conte
    5.31    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    5.32  }
    5.33  
    5.34 -BOOLEAN no_more_interrupts;
    5.35 -
    5.36  /* Called at DIRQL */
    5.37  BOOLEAN
    5.38  EvtChn_AckEvent(PVOID context, evtchn_port_t port)
    5.39 @@ -62,14 +65,25 @@ EvtChn_AckEvent(PVOID context, evtchn_po
    5.40    ULONG evt_word;
    5.41    ULONG evt_bit;
    5.42    xen_ulong_t val;
    5.43 +  
    5.44 +  shared_info_t *shared_info_area = xpdd->shared_info_area;
    5.45 +  int i;
    5.46  
    5.47 -  evt_bit = port & ((sizeof(xen_ulong_t) * 8) - 1);
    5.48 -  evt_word = port >> (5 + (sizeof(xen_ulong_t) >> 3));
    5.49 +  evt_bit = port & (BITS_PER_LONG - 1);
    5.50 +  evt_word = port >> BITS_PER_LONG_SHIFT;
    5.51  
    5.52    val = synch_clear_bit(evt_bit, (volatile xen_long_t *)&xpdd->evtchn_pending_pvt[evt_word]);
    5.53    
    5.54    //KdPrint((__DRIVER_NAME "     port %d = %d\n", port, !!val));
    5.55  
    5.56 +  for (i = 0; i < ARRAY_SIZE(shared_info_area->evtchn_pending); i++)
    5.57 +  {
    5.58 +    if (shared_info_area->evtchn_pending[i])
    5.59 +    {
    5.60 +      KdPrint((__DRIVER_NAME "     New event during IRQ processing - word = %d, val = %p\n", i, shared_info_area->evtchn_pending[i]));
    5.61 +    }
    5.62 +  }
    5.63 +
    5.64    return (BOOLEAN)!!val;
    5.65  }
    5.66  
    5.67 @@ -102,58 +116,59 @@ to CPU != 0, but we should always use vc
    5.68      return TRUE;
    5.69    }
    5.70      
    5.71 -  //ASSERT(!no_more_interrupts);
    5.72 -  
    5.73 -  /* we should check the evtchn_pending_pvt here and report if != 0 */
    5.74 -  
    5.75    UNREFERENCED_PARAMETER(Interrupt);
    5.76  
    5.77 +  for (i = 0; i < ARRAY_SIZE(xpdd->evtchn_pending_pvt); i++)
    5.78 +  {
    5.79 +    if (xpdd->evtchn_pending_pvt[i])
    5.80 +    {
    5.81 +      KdPrint((__DRIVER_NAME "     Unacknowledged event word = %d, val = %p\n", i, xpdd->evtchn_pending_pvt[i]));
    5.82 +      xpdd->evtchn_pending_pvt[i] = 0;
    5.83 +    }
    5.84 +  }
    5.85 +  
    5.86    vcpu_info = &shared_info_area->vcpu_info[cpu];
    5.87  
    5.88    vcpu_info->evtchn_upcall_pending = 0;
    5.89  
    5.90    evt_words = (xen_ulong_t)xchg((volatile xen_long_t *)&vcpu_info->evtchn_pending_sel, 0);
    5.91 -  
    5.92 +
    5.93    while (bit_scan_forward(&evt_word, evt_words))
    5.94    {
    5.95      evt_words &= ~(1 << evt_word);
    5.96      while (bit_scan_forward(&evt_bit, shared_info_area->evtchn_pending[evt_word] & ~shared_info_area->evtchn_mask[evt_word]))
    5.97      {
    5.98 +      synch_clear_bit(evt_bit, (volatile xen_long_t *)&shared_info_area->evtchn_pending[evt_word]);
    5.99        handled = TRUE;
   5.100 -      port = (evt_word << 5) + evt_bit;
   5.101 +      port = (evt_word << BITS_PER_LONG_SHIFT) + evt_bit;
   5.102        ev_action = &xpdd->ev_actions[port];
   5.103        ev_action->count++;
   5.104        switch (ev_action->type)
   5.105        {
   5.106        case EVT_ACTION_TYPE_NORMAL:
   5.107 -        synch_clear_bit(evt_bit, (volatile xen_long_t *)&shared_info_area->evtchn_pending[evt_word]);
   5.108          ev_action->ServiceRoutine(NULL, ev_action->ServiceContext);
   5.109          break;
   5.110        case EVT_ACTION_TYPE_IRQ:
   5.111 -        synch_clear_bit(evt_bit, (volatile xen_long_t *)&shared_info_area->evtchn_pending[evt_word]);
   5.112          synch_set_bit(evt_bit, (volatile xen_long_t *)&xpdd->evtchn_pending_pvt[evt_word]);
   5.113          deferred = TRUE;
   5.114          break;
   5.115        case EVT_ACTION_TYPE_DPC:
   5.116 -        synch_clear_bit(evt_bit, (volatile xen_long_t *)&shared_info_area->evtchn_pending[evt_word]);
   5.117          KeInsertQueueDpc(&ev_action->Dpc, NULL, NULL);
   5.118          break;
   5.119        case EVT_ACTION_TYPE_SUSPEND:
   5.120 -        synch_clear_bit(evt_bit, (volatile xen_long_t *)&shared_info_area->evtchn_pending[evt_word]);
   5.121          KdPrint((__DRIVER_NAME "     EVT_ACTION_TYPE_SUSPEND\n"));
   5.122          for (i = 0; i < ARRAY_SIZE(xpdd->evtchn_pending_pvt); i++)
   5.123          {
   5.124            if (xpdd->ev_actions[i].type == EVT_ACTION_TYPE_IRQ)
   5.125            {
   5.126 -            int suspend_bit = i & ((sizeof(xen_ulong_t) * 8) - 1);
   5.127 -            int suspend_word = i >> (5 + (sizeof(xen_ulong_t) >> 3));
   5.128 +            int suspend_bit = i & (BITS_PER_LONG - 1);
   5.129 +            int suspend_word = i >> BITS_PER_LONG_SHIFT;
   5.130              synch_set_bit(suspend_bit, (volatile xen_long_t *)&xpdd->evtchn_pending_pvt[suspend_word]);
   5.131            }
   5.132          }
   5.133          deferred = TRUE;
   5.134          break;
   5.135        default:
   5.136 -        synch_clear_bit(evt_bit, (volatile xen_long_t *)&shared_info_area->evtchn_pending[evt_word]);
   5.137          KdPrint((__DRIVER_NAME "     Unhandled Event!!!\n"));
   5.138          break;
   5.139        }
   5.140 @@ -234,7 +249,6 @@ EvtChn_BindIrq(PVOID Context, evtchn_por
   5.141      KdPrint((__DRIVER_NAME " Handler for port %d already registered, replacing\n", Port));
   5.142    }
   5.143  
   5.144 -  KeInitializeDpc(&xpdd->ev_actions[Port].Dpc, EvtChn_DpcBounce, &xpdd->ev_actions[Port]);
   5.145    xpdd->ev_actions[Port].vector = vector;
   5.146    xpdd->ev_actions[Port].xpdd = xpdd;
   5.147    KeMemoryBarrier();
   5.148 @@ -252,13 +266,16 @@ NTSTATUS
   5.149  EvtChn_Unbind(PVOID Context, evtchn_port_t Port)
   5.150  {
   5.151    PXENPCI_DEVICE_DATA xpdd = Context;
   5.152 +  int old_type;
   5.153    
   5.154    EvtChn_Mask(Context, Port);
   5.155 +  old_type = xpdd->ev_actions[Port].type;
   5.156 +  xpdd->ev_actions[Port].type = EVT_ACTION_TYPE_EMPTY;
   5.157 +  KeMemoryBarrier(); // make sure we don't call the old Service Routine with the new data...
   5.158    xpdd->ev_actions[Port].ServiceRoutine = NULL;
   5.159 -  KeMemoryBarrier();
   5.160    xpdd->ev_actions[Port].ServiceContext = NULL;
   5.161  
   5.162 -  if (xpdd->ev_actions[Port].type == EVT_ACTION_TYPE_DPC)
   5.163 +  if (old_type == EVT_ACTION_TYPE_DPC)
   5.164      KeRemoveQueueDpc(&xpdd->ev_actions[Port].Dpc);
   5.165    
   5.166    return STATUS_SUCCESS;
   5.167 @@ -269,8 +286,8 @@ EvtChn_Mask(PVOID Context, evtchn_port_t
   5.168  {
   5.169    PXENPCI_DEVICE_DATA xpdd = Context;
   5.170  
   5.171 -  synch_set_bit(port & 31,
   5.172 -    (volatile xen_long_t *)&xpdd->shared_info_area->evtchn_mask[port >> 5]);
   5.173 +  synch_set_bit(port & (BITS_PER_LONG - 1),
   5.174 +    (volatile xen_long_t *)&xpdd->shared_info_area->evtchn_mask[port >> BITS_PER_LONG_SHIFT]);
   5.175    return STATUS_SUCCESS;
   5.176  }
   5.177  
   5.178 @@ -279,8 +296,8 @@ EvtChn_Unmask(PVOID context, evtchn_port
   5.179  {
   5.180    PXENPCI_DEVICE_DATA xpdd = context;
   5.181  
   5.182 -  synch_clear_bit(port & 31,
   5.183 -    (volatile xen_long_t *)&xpdd->shared_info_area->evtchn_mask[port >> 5]);
   5.184 +  synch_clear_bit(port & (BITS_PER_LONG - 1),
   5.185 +    (volatile xen_long_t *)&xpdd->shared_info_area->evtchn_mask[port >> BITS_PER_LONG_SHIFT]);
   5.186    return STATUS_SUCCESS;
   5.187  }
   5.188  
   5.189 @@ -391,7 +408,7 @@ EvtChn_ConnectInterrupt(PXENPCI_DEVICE_D
   5.190    	xpdd->irq_vector,
   5.191    	xpdd->irq_level,
   5.192    	xpdd->irq_level,
   5.193 -  	LevelSensitive,
   5.194 +  	xpdd->irq_mode, //LevelSensitive,
   5.195    	TRUE,
   5.196    	xpdd->irq_affinity,
   5.197    	FALSE);
   5.198 @@ -416,29 +433,17 @@ EvtChn_Shutdown(PXENPCI_DEVICE_DATA xpdd
   5.199      xpdd->shared_info_area->vcpu_info[i].evtchn_upcall_mask = 1;
   5.200    KeMemoryBarrier();
   5.201    hvm_set_parameter(xpdd, HVM_PARAM_CALLBACK_IRQ, 0);
   5.202 -  //KeMemoryBarrier();
   5.203 -  //no_more_interrupts = TRUE;
   5.204 -  //KeMemoryBarrier();
   5.205  
   5.206 -#if (NTDDI_VERSION >= NTDDI_WINXP)
   5.207 -  KeFlushQueuedDpcs();
   5.208 -#else
   5.209    for (i = 0; i < NR_EVENTS; i++)
   5.210    {
   5.211 -    if (xpdd->ev_actions[i].type == EVT_ACTION_TYPE_DPC || xpdd->ev_actions[i].type == EVT_ACTION_TYPE_IRQ)
   5.212 +    if (xpdd->ev_actions[i].type == EVT_ACTION_TYPE_DPC)
   5.213      {
   5.214        KeRemoveQueueDpc(&xpdd->ev_actions[i].Dpc);
   5.215      }
   5.216    }
   5.217 +#if (NTDDI_VERSION >= NTDDI_WINXP)
   5.218 +  KeFlushQueuedDpcs();
   5.219  #endif
   5.220  
   5.221 -/*
   5.222 -KdPrint((__DRIVER_NAME "     Starting fake delay (IRQL = %d)\n", KeGetCurrentIrql()));
   5.223 -wait_time.QuadPart = 1000 * (-1 * 10 * 1000);
   5.224 -KeDelayExecutionThread(KernelMode, FALSE, &wait_time);
   5.225 -KdPrint((__DRIVER_NAME "     Done with fake delay\n"));
   5.226 -*/
   5.227 -  //IoDisconnectInterrupt(xpdd->interrupt);
   5.228 -
   5.229    return STATUS_SUCCESS;
   5.230  }
     6.1 --- a/xenpci/xenpci.h	Wed Sep 10 14:43:12 2008 +1000
     6.2 +++ b/xenpci/xenpci.h	Wed Sep 17 23:28:47 2008 +1000
     6.3 @@ -174,6 +174,7 @@ typedef struct {
     6.4    ULONG irq_number;
     6.5    ULONG irq_vector;
     6.6    KIRQL irq_level;
     6.7 +  KINTERRUPT_MODE irq_mode;
     6.8    KAFFINITY irq_affinity;
     6.9  
    6.10    PHYSICAL_ADDRESS shared_info_area_unmapped;
     7.1 --- a/xenpci/xenpci_fdo.c	Wed Sep 10 14:43:12 2008 +1000
     7.2 +++ b/xenpci/xenpci_fdo.c	Wed Sep 17 23:28:47 2008 +1000
     7.3 @@ -18,7 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fi
     7.4  */
     7.5  
     7.6  #include "xenpci.h"
     7.7 -//#include <wdmsec.h>
     7.8  #include <stdlib.h>
     7.9  
    7.10  #define SYSRQ_PATH "control/sysrq"
    7.11 @@ -576,50 +575,6 @@ XenPci_ShutdownHandler(char *path, PVOID
    7.12    FUNCTION_EXIT();
    7.13  }
    7.14  
    7.15 -static DDKAPI void
    7.16 -XenBus_DummyXenbusThreadProc(PVOID StartContext)
    7.17 -{
    7.18 -  PXENPCI_DEVICE_DATA xpdd = StartContext;
    7.19 -  char *value;
    7.20 -  char *err;
    7.21 -  int thread_id;
    7.22 -  
    7.23 -  thread_id = (int)PsGetCurrentThreadId();
    7.24 -  for(;;)
    7.25 -  {
    7.26 -    KdPrint((__DRIVER_NAME "     %08X: writing 666\n", thread_id));
    7.27 -    XenBus_Write(xpdd, XBT_NIL, "james", "666");
    7.28 -    err = XenBus_Read(xpdd, XBT_NIL, "james", &value);
    7.29 -    if (err)
    7.30 -    {
    7.31 -      KdPrint((__DRIVER_NAME "     %08X: error on read - %s\n", thread_id, err));
    7.32 -      XenPci_FreeMem(err);
    7.33 -    }
    7.34 -    else
    7.35 -    {
    7.36 -      KdPrint((__DRIVER_NAME "     %08X: read %s\n", thread_id, value));
    7.37 -      XenPci_FreeMem(value);
    7.38 -    }
    7.39 -    KdPrint((__DRIVER_NAME "     %08X: writing 362436\n", thread_id));
    7.40 -    XenBus_Write(xpdd, XBT_NIL, "james", "362436");
    7.41 -    err = XenBus_Read(xpdd, XBT_NIL, "james", &value);
    7.42 -    if (err)
    7.43 -    {
    7.44 -      KdPrint((__DRIVER_NAME "     %08X: error on read - %s\n", thread_id, err));
    7.45 -      XenPci_FreeMem(err);
    7.46 -    }
    7.47 -    else
    7.48 -    {
    7.49 -      KdPrint((__DRIVER_NAME "     %08X: read %s\n", thread_id, value));
    7.50 -      XenPci_FreeMem(value);
    7.51 -    }
    7.52 -/*
    7.53 -    wait_time.QuadPart = 1000 * (-1 * 10 * 1000);
    7.54 -    KeDelayExecutionThread(KernelMode, FALSE, &wait_time);
    7.55 -*/
    7.56 -  }
    7.57 -}
    7.58 -
    7.59  static VOID 
    7.60  XenPci_DumpPdoConfigs(PXENPCI_DEVICE_DATA xpdd)
    7.61  {
    7.62 @@ -635,9 +590,6 @@ static VOID
    7.63  XenPci_SysrqHandler(char *path, PVOID context)
    7.64  {
    7.65    PXENPCI_DEVICE_DATA xpdd = context;
    7.66 -  NTSTATUS status;
    7.67 -  HANDLE thread_handle;
    7.68 -  PIO_WORKITEM work_item;
    7.69    char *value;
    7.70    char letter;
    7.71    char *res;
    7.72 @@ -678,16 +630,12 @@ XenPci_SysrqHandler(char *path, PVOID co
    7.73    case 'B':
    7.74      KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000001, 0x00000000, 0x00000000, 0x00000000);
    7.75      break;
    7.76 +#if 0
    7.77    case 'X':
    7.78 -    status = PsCreateSystemThread(&thread_handle, THREAD_ALL_ACCESS, NULL, NULL, NULL, XenBus_DummyXenbusThreadProc, xpdd);
    7.79      break;
    7.80 -  case 'S':
    7.81 -    /* call shutdown from here for testing */
    7.82 -  	work_item = IoAllocateWorkItem(xpdd->common.fdo);
    7.83 -    IoQueueWorkItem(work_item, XenPci_BeginSuspend, DelayedWorkQueue, NULL);
    7.84 -    break;
    7.85 +#endif
    7.86    case 'C':
    7.87 -    /* call shutdown from here for testing */
    7.88 +    /* show some debugging info */
    7.89    	XenPci_DumpPdoConfigs(xpdd);
    7.90      break;
    7.91    default:
    7.92 @@ -837,6 +785,8 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
    7.93  	    xpdd->irq_level = (KIRQL)res_descriptor->u.Interrupt.Level;
    7.94    	  xpdd->irq_vector = res_descriptor->u.Interrupt.Vector;
    7.95  	    xpdd->irq_affinity = res_descriptor->u.Interrupt.Affinity;
    7.96 +      
    7.97 +      xpdd->irq_mode = (res_descriptor->Flags & CM_RESOURCE_INTERRUPT_LATCHED)?Latched:LevelSensitive;
    7.98        //memcpy(&InterruptTranslated, res_descriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
    7.99        break;
   7.100      case CmResourceTypeDevicePrivate:
   7.101 @@ -1088,58 +1038,28 @@ static DDKAPI VOID
   7.102  XenPci_Pnp_FilterResourceRequirementsCallback(PDEVICE_OBJECT device_object, PVOID context)
   7.103  {
   7.104    NTSTATUS status = STATUS_SUCCESS;
   7.105 -  //PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   7.106    PIRP irp = context;
   7.107 -#if 0
   7.108 -  PIO_RESOURCE_REQUIREMENTS_LIST old_irrl;
   7.109 -  PIO_RESOURCE_REQUIREMENTS_LIST new_irrl;
   7.110 -  //ULONG irl;
   7.111 -  //ULONG ird;
   7.112 +  PIO_RESOURCE_REQUIREMENTS_LIST irrl;
   7.113    PIO_RESOURCE_LIST irl;
   7.114    PIO_RESOURCE_DESCRIPTOR ird;
   7.115 -#endif
   7.116 +  ULONG i;
   7.117  
   7.118    UNREFERENCED_PARAMETER(device_object);
   7.119  
   7.120    FUNCTION_ENTER();
   7.121 -  FUNCTION_MSG(("IoStatus.status = %08X\n", irp->IoStatus.Status));
   7.122  
   7.123 -#if 0  
   7.124    /* this assumes that AlternativeLists == 1 */
   7.125 -  old_irrl = (PIO_RESOURCE_REQUIREMENTS_LIST)irp->IoStatus.Information;
   7.126 -  new_irrl = ExAllocatePoolWithTag(NonPagedPool, old_irrl->ListSize + sizeof(IO_RESOURCE_DESCRIPTOR) * 1, XENPCI_POOL_TAG);
   7.127 -  memcpy(new_irrl, old_irrl, old_irrl->ListSize);
   7.128 -  
   7.129 -  irl = &new_irrl->List[0];
   7.130 -  ird = &irl->Descriptors[irl->Count++];
   7.131 -  RtlZeroMemory(ird, sizeof(IO_RESOURCE_DESCRIPTOR));
   7.132 -  ird->Option = 0;
   7.133 -  ird->Type = CmResourceTypeInterrupt;
   7.134 -  ird->ShareDisposition = CmResourceShareDeviceExclusive;
   7.135 -  ird->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
   7.136 -  ird->u.Interrupt.MinimumVector = 16;
   7.137 -  ird->u.Interrupt.MaximumVector = 63;
   7.138 -/*
   7.139 -  ird->u.AffinityPolicy = IrqPolicyMachineDefault;
   7.140 -  ird->u.PriorityPolicy = IrqPriorityNormal;
   7.141 -  ird->u.TargetedProcessors = 0;
   7.142 -*/
   7.143 -
   7.144 -  irp->IoStatus.Information = (ULONG_PTR)new_irrl;
   7.145 -  // free old_irrl
   7.146 -#endif
   7.147 -/*
   7.148 -  for (irl = 0; irl < irrl->AlternativeLists; irl++)
   7.149 +  irrl = (PIO_RESOURCE_REQUIREMENTS_LIST)irp->IoStatus.Information;
   7.150 +  irl = &irrl->List[0];
   7.151 +  for (i = 0; i < irl->Count; i++)
   7.152    {
   7.153 -    for (ird = 0; ird < irrl->List[irl].Count; ird++)
   7.154 +    ird = &irl->Descriptors[i];
   7.155 +    if (ird->Type == CmResourceTypeInterrupt && ird->ShareDisposition != CmResourceShareShared)
   7.156      {
   7.157 -      if (irrl->List[irl].Descriptors[ird].Type == CmResourceTypeMemory)
   7.158 -      {
   7.159 -        irrl->List[irl].Descriptors[ird].ShareDisposition = CmResourceShareShared;
   7.160 -      }
   7.161 +      //ird->ShareDisposition = CmResourceShareShared;
   7.162 +      //KdPrint((__DRIVER_NAME "     Set interrupt to shared\n"));
   7.163      }
   7.164    }
   7.165 -*/
   7.166    irp->IoStatus.Status = status;
   7.167    IoCompleteRequest (irp, IO_NO_INCREMENT);
   7.168    
     8.1 --- a/xenpci/xenpci_pdo.c	Wed Sep 10 14:43:12 2008 +1000
     8.2 +++ b/xenpci/xenpci_pdo.c	Wed Sep 17 23:28:47 2008 +1000
     8.3 @@ -977,7 +977,7 @@ XenPci_QueryResourceRequirements(PDEVICE
     8.4    ird->Option = 0;
     8.5    ird->Type = CmResourceTypeInterrupt;
     8.6    ird->ShareDisposition = CmResourceShareShared;
     8.7 -  ird->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
     8.8 +  ird->Flags = (xpdd->irq_mode == Latched)?CM_RESOURCE_INTERRUPT_LATCHED:CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
     8.9    ird->u.Interrupt.MinimumVector = xpdd->irq_number;
    8.10    ird->u.Interrupt.MaximumVector = xpdd->irq_number;
    8.11    
     9.1 --- a/xenvbd/xenvbd.c	Wed Sep 10 14:43:12 2008 +1000
     9.2 +++ b/xenvbd/xenvbd.c	Wed Sep 17 23:28:47 2008 +1000
     9.3 @@ -907,7 +907,7 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
     9.4  
     9.5    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
     9.6  
     9.7 -  return FALSE; /* fall through to the next ISR... */
     9.8 +  return FALSE; /* always fall through to the next ISR... */
     9.9  }
    9.10  
    9.11  static BOOLEAN DDKAPI