Exemple #1
0
static void
usbd_task(device_object *dobj, void *arg)
{
	irp *ip;
	list_entry *l;
	struct ndis_softc *sc = arg;
	struct ndisusb_ep *ne;
	struct ndisusb_task *nt;
	union usbd_urb *urb;

	if (IsListEmpty(&sc->ndisusb_tasklist))
		return;

	KeAcquireSpinLockAtDpcLevel(&sc->ndisusb_tasklock);
	l = sc->ndisusb_tasklist.nle_flink;
	while (l != &sc->ndisusb_tasklist) {
		nt = CONTAINING_RECORD(l, struct ndisusb_task, nt_tasklist);

		ip = nt->nt_ctx;
		urb = usbd_geturb(ip);

		KeReleaseSpinLockFromDpcLevel(&sc->ndisusb_tasklock);
		NDISUSB_LOCK(sc);
		switch (nt->nt_type) {
		case NDISUSB_TASK_TSTART:
			ne = usbd_get_ndisep(ip, urb->uu_bulkintr.ubi_epdesc);
			if (ne == NULL)
				goto exit;
			usbd_transfer_start(ne->ne_xfer[0]);
			break;
		case NDISUSB_TASK_IRPCANCEL:
			ne = usbd_get_ndisep(ip,
			    (nt->nt_type == NDISUSB_TASK_IRPCANCEL) ?
			    urb->uu_bulkintr.ubi_epdesc :
			    urb->uu_pipe.upr_handle);
			if (ne == NULL)
				goto exit;
			
			usbd_transfer_stop(ne->ne_xfer[0]);
			usbd_transfer_start(ne->ne_xfer[0]);
			break;
		case NDISUSB_TASK_VENDOR:
			ne = (urb->uu_vcreq.uvc_trans_flags &
			    USBD_TRANSFER_DIRECTION_IN) ?
			    &sc->ndisusb_dread_ep : &sc->ndisusb_dwrite_ep;
			usbd_transfer_start(ne->ne_xfer[0]);
			break;
		default:
			break;
		}
exit:
		NDISUSB_UNLOCK(sc);
		KeAcquireSpinLockAtDpcLevel(&sc->ndisusb_tasklock);

		l = l->nle_flink;
		RemoveEntryList(&nt->nt_tasklist);
		free(nt, M_USBDEV);
	}
	KeReleaseSpinLockFromDpcLevel(&sc->ndisusb_tasklock);
}
Exemple #2
0
int
tdi_send(PIRP irp, PIO_STACK_LOCATION irps, struct completion *completion)
{
	TDI_REQUEST_KERNEL_SEND *param = (TDI_REQUEST_KERNEL_SEND *)(&irps->Parameters);
	struct ot_entry *ote_conn;
	KIRQL irql;

	KdPrint(("[tdi_fw] tdi_send: connobj: 0x%x; SendLength: %u; SendFlags: 0x%x\n",
		irps->FileObject, param->SendLength, param->SendFlags));

	ote_conn = ot_find_fileobj(irps->FileObject, &irql);
	if (ote_conn != NULL) {
		ULONG bytes = param->SendLength;

		ote_conn->bytes_out += bytes;

		// traffic stats
		KeAcquireSpinLockAtDpcLevel(&g_traffic_guard);
		
		g_traffic[TRAFFIC_TOTAL_OUT] += bytes;
		
		if (ote_conn->log_disconnect)
			g_traffic[TRAFFIC_COUNTED_OUT] += bytes;
		
		KeReleaseSpinLockFromDpcLevel(&g_traffic_guard);

		KeReleaseSpinLock(&g_ot_hash_guard, irql);
	}

	// TODO: process TDI_SEND_AND_DISCONNECT flag (used by IIS for example)

	return FILTER_ALLOW;
}
Exemple #3
0
VOID
NTAPI
ExpTimerDpcRoutine(IN PKDPC Dpc,
                   IN PVOID DeferredContext,
                   IN PVOID SystemArgument1,
                   IN PVOID SystemArgument2)
{
    PETIMER Timer = DeferredContext;
    BOOLEAN Inserted = FALSE;

    /* Reference the timer */
    if (!ObReferenceObjectSafe(Timer)) return;

    /* Lock the Timer */
    KeAcquireSpinLockAtDpcLevel(&Timer->Lock);

    /* Check if the timer is associated */
    if (Timer->ApcAssociated)
    {
        /* Queue the APC */
        Inserted = KeInsertQueueApc(&Timer->TimerApc,
                                    SystemArgument1,
                                    SystemArgument2,
                                    IO_NO_INCREMENT);
    }

    /* Release the Timer */
    KeReleaseSpinLockFromDpcLevel(&Timer->Lock);

    /* Dereference it if we couldn't queue the APC */
    if (!Inserted) ObDereferenceObject(Timer);
}
Exemple #4
0
/*
 * @implemented
 */
BOOLEAN
NTAPI
KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt,
                       IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
                       IN PVOID SynchronizeContext OPTIONAL)
{
    BOOLEAN Success;
    KIRQL OldIrql;
    
    /* Raise IRQL */
    OldIrql = KfRaiseIrql(Interrupt->SynchronizeIrql);
    
    /* Acquire interrupt spinlock */
    KeAcquireSpinLockAtDpcLevel(Interrupt->ActualLock);
    
    /* Call the routine */
    Success = SynchronizeRoutine(SynchronizeContext);
    
    /* Release lock */
    KeReleaseSpinLockFromDpcLevel(Interrupt->ActualLock);
    
    /* Lower IRQL */
    KfLowerIrql(OldIrql);
    
    /* Return status */
    return Success;
}
Exemple #5
0
void TimerDpcInterrupt(IN PKDPC Dpc, IN PEventHandlerData EventBlock,IN PVOID SystemArg1,IN PVOID SystemArg2)
{

    UNREFERENCED_PARAMETER(Dpc); 
    UNREFERENCED_PARAMETER(SystemArg1); 
    UNREFERENCED_PARAMETER(SystemArg2); 
    if (!EventBlock) return;

	if (!EventBlock->bStopScan) {
		//      CEncoderDevice* EncDevice = EventBlock->pDevice;
		//
		// Reschedule the timer for the next interrupt time.
		//
		if(EventBlock->CurrentFrequency <= EventBlock->ScanData.EndFrequency)
		{
			KeSetEvent(&(EventBlock->InitEvent), 0,FALSE);
		}
		else
		{
			KeAcquireSpinLockAtDpcLevel(&(EventHandler->LockAccess));
			EventBlock->bStopScan = TRUE;
			EventBlock->CurrentFrequency = EventBlock->ScanData.EndFrequency;
			KeReleaseSpinLockFromDpcLevel(&(EventHandler->LockAccess));
			KeSetEvent(&(EventBlock->ThreadEvent), 0,FALSE);            
		}

	} else {
		//
		// If someone is waiting on the hardware to stop, raise the stop
		// event and clear the flag.
		//
		KeSetEvent(&(EventBlock->ThreadEvent), 0,FALSE);
	}
}
Exemple #6
0
NTSTATUS
tdi_receive_complete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
{
	PIO_STACK_LOCATION irps = IoGetCurrentIrpStackLocation(Irp);
	struct ot_entry *ote_conn;
	KIRQL irql;

	KdPrint(("[tdi_fw] tdi_receive_complete: connobj: 0x%x; status: 0x%x; received: %u\n",
		irps->FileObject, Irp->IoStatus.Status, Irp->IoStatus.Information));

	ote_conn = ot_find_fileobj(irps->FileObject, &irql);
	if (ote_conn != NULL) {
		ULONG bytes =  Irp->IoStatus.Information;

		ote_conn->bytes_in += bytes;

		// traffic stats
		KeAcquireSpinLockAtDpcLevel(&g_traffic_guard);
		
		g_traffic[TRAFFIC_TOTAL_IN] += bytes;
		
		if (ote_conn->log_disconnect)
			g_traffic[TRAFFIC_COUNTED_IN] += bytes;
		
		KeReleaseSpinLockFromDpcLevel(&g_traffic_guard);

		KeReleaseSpinLock(&g_ot_hash_guard, irql);
	}

	return tdi_generic_complete(DeviceObject, Irp, Context);
}
Exemple #7
0
VOID
NotifierDisconnect(
    IN  PXENVIF_NOTIFIER    Notifier
    )
{
    KeAcquireSpinLockAtDpcLevel(&Notifier->Lock);

    ASSERT(Notifier->Connected);
    Notifier->Connected = FALSE;

    STORE(Release, Notifier->StoreInterface);
    Notifier->StoreInterface = NULL;

    DEBUG(Deregister,
          Notifier->DebugInterface,
          Notifier->DebugCallback);
    Notifier->DebugCallback = NULL;

    DEBUG(Release, Notifier->DebugInterface);
    Notifier->DebugInterface = NULL;

    EVTCHN(Close,
           Notifier->EvtchnInterface,
           Notifier->Evtchn);
    Notifier->Evtchn = NULL;

    Notifier->Events = 0;

    EVTCHN(Release, Notifier->EvtchnInterface);
    Notifier->EvtchnInterface = NULL;

    KeReleaseSpinLockFromDpcLevel(&Notifier->Lock);
}
Exemple #8
0
VOID WriteToBuffer(
		//PRING_BUFFER 	pRb,
		const PCHAR 	pMsg,
		ULONG			size
		)
{
	PKSPIN_LOCK		spinLock;
	KIRQL			currentIrql, oldIrql;
	
	
	
	//in init KeInitializeSpinLock(&spinLock);
	
	KeRaiseIrql(HIGH_LEVEL, &oldIrql);
	
	//currentIrql = KeGetCurrentIrql();
		
	KeAcquireSpinLockAtDpcLevel(spinLock, &currentIrql);
	
	bNeedFlush = WriteToBufferHelper(
			pRb,
			pMsg,
			size);
	
	KeReleaseSpinLockFromDpcLevel(spinLock, currentIrql);
	
	KeLowerIrql(&oldIrql);
	
	if (bNeedFlush)
		if (KeGetCurrentIrql()<2) {
			KeSetEvent
		} else {
			KeInsertQueuedDpc
		}
}
Exemple #9
0
VOID
NdisDprReleaseSpinLock(
    IN PNDIS_SPIN_LOCK SpinLock
    )
{
    KeReleaseSpinLockFromDpcLevel(&SpinLock->SpinLock);
}
Exemple #10
0
static VOID CfixkrsReleaseLockFilamentRegistry( 
	__in PCFIXKRP_FILAMENT_REGISTRY Registry,
	__in KIRQL OldIrql
	)
{
	KeReleaseSpinLockFromDpcLevel( &Registry->Lock );
	KeLowerIrql( OldIrql );
}
Exemple #11
0
VOID NTAPI
VideoPortReleaseSpinLockFromDpcLevel(
   IN PVOID HwDeviceExtension,
   IN PSPIN_LOCK SpinLock)
{
   TRACE_(VIDEOPRT, "VideoPortReleaseSpinLockFromDpcLevel\n");
   KeReleaseSpinLockFromDpcLevel((PKSPIN_LOCK)SpinLock);
}
Exemple #12
0
static struct ndisusb_xfer *
usbd_aq_getfirst(struct ndis_softc *sc, struct ndisusb_ep *ne)
{
	struct ndisusb_xfer *nx;

	KeAcquireSpinLockAtDpcLevel(&ne->ne_lock);
	if (IsListEmpty(&ne->ne_active)) {
		device_printf(sc->ndis_dev,
		    "%s: the active queue can't be empty.\n", __func__);
		KeReleaseSpinLockFromDpcLevel(&ne->ne_lock);
		return (NULL);
	}
	nx = CONTAINING_RECORD(ne->ne_active.nle_flink, struct ndisusb_xfer,
	    nx_next);
	RemoveEntryList(&nx->nx_next);
	KeReleaseSpinLockFromDpcLevel(&ne->ne_lock);

	return (nx);
}
Exemple #13
0
VOID
NTAPI
USBSTOR_Cancel(
    IN  PDEVICE_OBJECT DeviceObject,
    IN  PIRP Irp)
{
    PFDO_DEVICE_EXTENSION FDODeviceExtension;

    //
    // get FDO device extension
    //
    FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

    //
    // sanity check
    //
    ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
    ASSERT(FDODeviceExtension->Common.IsFDO);

    //
    // acquire irp list lock
    //
    KeAcquireSpinLockAtDpcLevel(&FDODeviceExtension->IrpListLock);

    //
    // remove the irp from the list
    //
    RemoveEntryList(&Irp->Tail.Overlay.ListEntry);

    //
    // release irp list lock
    //
    KeReleaseSpinLockFromDpcLevel(&FDODeviceExtension->IrpListLock);    

    //
    // now release the cancel lock
    //
    IoReleaseCancelSpinLock(Irp->CancelIrql);

    //
    // set cancel status
    //
    Irp->IoStatus.Status = STATUS_CANCELLED;

    //
    // now cancel the irp
    //
    USBSTOR_QueueTerminateRequest(DeviceObject, Irp);
    IoCompleteRequest(Irp, IO_NO_INCREMENT);

    //
    // start the next one
    //
    USBSTOR_QueueNextRequest(DeviceObject);
}
Exemple #14
0
/*++
Routine Description:

	handle TXDone interrupt routine..

Arguments:

	FdoData 	Pointer to our FdoData

Return Value:

	 None

--*/
VOID
BthHandleTxRingDmaDoneInterrupt(
	IN  PRTBTH_ADAPTER  	 pAd,
	IN  INT_SOURCE_CSR_STRUC TxRingBitmap)
{
	PRT_TX_RING 	pTxRing;
	PTXD_STRUC  	pTxD;
	UCHAR   		RingIdx;
	UCHAR   		Count;
	UINT8		TxRingSize;

	for (RingIdx = 0; RingIdx < NUM_OF_TX_RING; RingIdx++)
	{
		Count = 0;
		pTxRing = &pAd->TxRing[RingIdx];

		KeAcquireSpinLockAtDpcLevel(&pAd->SendLock);

		RT_IO_READ32(pAd, TX_DTX_IDX0 + RingIdx * RINGREG_DIFF, &pTxRing->TxDmaIdx);
		while ((pTxRing->TxDmaIdx != 0xffffffff) && (pTxRing->TxSwFreeIdx != pTxRing->TxDmaIdx))
		{
#if  0
			if (pTxRing->TxDmaIdx >= TX_RING_SIZE)
			{
				DebugPrint(ERROR, DBG_MISC, "BthHandleTxRingDmaDoneInterrupt: Invalid pTxRing->TxDmaIdx = 0x%08x\n", pTxRing->TxDmaIdx);

				//
				// Invalid value, try to read it again.
				// It should be fine after read again.
				//
				RT_IO_READ32(pAd, TX_DTX_IDX0 + RingIdx * RINGREG_DIFF, &pTxRing->TxDmaIdx);
				Count++;
				if (Count > 10)
					break;
				continue;
			}
#endif
			pTxD = (PTXD_STRUC) (pTxRing->Cell[pTxRing->TxSwFreeIdx].AllocVa);
			if(pTxD->DmaDone == 0)
			{
				break;
			}
			//pTxD->DmaDone = 0;

//DebugPrint(TRACE, DBG_MISC, "-->%s(TxRing-%d):pTxRing->TxDmaIdx=0x%x, pTxRing->TxSwFreeIdx=0x%x!\n", __FUNCTION__, RingIdx, pTxRing->TxDmaIdx, pTxRing->TxSwFreeIdx);
			TxRingSize = BthGetTxRingSize(pAd, RingIdx);
			//INC_RING_INDEX(pTxRing->TxSwFreeIdx, TX_RING_SIZE);
			INC_RING_INDEX(pTxRing->TxSwFreeIdx, TxRingSize);
			KeSetEvent(&pAd->CoreEventTriggered, 1, FALSE);
		}

		KeReleaseSpinLockFromDpcLevel(&pAd->SendLock);
	}
}
Exemple #15
0
static int32_t
usbd_func_vendorclass(irp *ip)
{
	device_t dev = IRP_NDIS_DEV(ip);
	int32_t error;
	struct ndis_softc *sc = device_get_softc(dev);
	struct ndisusb_ep *ne;
	struct ndisusb_xfer *nx;
	struct usbd_urb_vendor_or_class_request *vcreq;
	union usbd_urb *urb;

	if (!(sc->ndisusb_status & NDISUSB_STATUS_SETUP_EP)) {
		/*
		 * XXX In some cases the interface number isn't 0.  However
		 * some driver (eg. RTL8187L NDIS driver) calls this function
		 * before calling URB_FUNCTION_SELECT_CONFIGURATION.
		 */
		error = usbd_setup_endpoint_default(ip, 0);
		if (error != USB_ERR_NORMAL_COMPLETION)
			return usbd_usb2urb(error);
		sc->ndisusb_status |= NDISUSB_STATUS_SETUP_EP;
	}

	urb = usbd_geturb(ip);
	vcreq = &urb->uu_vcreq;
	ne = (vcreq->uvc_trans_flags & USBD_TRANSFER_DIRECTION_IN) ?
	    &sc->ndisusb_dread_ep : &sc->ndisusb_dwrite_ep;
	IRP_NDISUSB_EP(ip) = ne;
	ip->irp_cancelfunc = (cancel_func)usbd_irpcancel_wrap;

	nx = malloc(sizeof(struct ndisusb_xfer), M_USBDEV, M_NOWAIT | M_ZERO);
	if (nx == NULL) {
		device_printf(IRP_NDIS_DEV(ip), "out of memory\n");
		return (USBD_STATUS_NO_MEMORY);
	}
	nx->nx_ep = ne;
	nx->nx_priv = ip;
	KeAcquireSpinLockAtDpcLevel(&ne->ne_lock);
	InsertTailList((&ne->ne_pending), (&nx->nx_next));
	KeReleaseSpinLockFromDpcLevel(&ne->ne_lock);

	/* we've done to setup xfer.  Let's transfer it.  */
	ip->irp_iostat.isb_status = STATUS_PENDING;
	ip->irp_iostat.isb_info = 0;
	USBD_URB_STATUS(urb) = USBD_STATUS_PENDING;
	IoMarkIrpPending(ip);

	error = usbd_taskadd(ip, NDISUSB_TASK_VENDOR);
	if (error != USBD_STATUS_SUCCESS)
		return (error);

	return (USBD_STATUS_PENDING);
}
Exemple #16
0
__inline VOID
MP_FREE_SEND_PACKET(
    __in  PFDO_DATA   FdoData,
    __in  PMP_TCB     pMpTcb,
    __in  NTSTATUS    Status
    )
/*++
Routine Description:

    Recycle a MP_TCB and complete the packet if necessary
    Assumption: Send spinlock has been acquired

Arguments:

    FdoData     Pointer to our FdoData
    pMpTcb      Pointer to MP_TCB
    Status      Irp completion status

Return Value:

    None

--*/
{

    PIRP  Irp;

    ASSERT(MP_TEST_FLAG(pMpTcb, fMP_TCB_IN_USE));

    Irp = pMpTcb->Irp;
    pMpTcb->Irp = NULL;
    pMpTcb->Count = 0;

    MP_CLEAR_FLAGS(pMpTcb);

    FdoData->CurrSendHead = FdoData->CurrSendHead->Next;
    FdoData->nBusySend--;
    ASSERT(FdoData->nBusySend >= 0);

    if (Irp)
    {
        KeReleaseSpinLockFromDpcLevel(&FdoData->SendLock);
        NICCompleteSendRequest(FdoData,
                            Irp,
                            Status,
                            pMpTcb->PacketLength,
                            TRUE // Yes, we are calling at DISPATCH_LEVEL
                            );

        KeAcquireSpinLockAtDpcLevel(&FdoData->SendLock);
    }
}
Exemple #17
0
NTSTATUS
tdi_event_chained_receive(
    IN PVOID TdiEventContext,
    IN CONNECTION_CONTEXT ConnectionContext,
    IN ULONG ReceiveFlags,
    IN ULONG ReceiveLength,
    IN ULONG StartingOffset,
    IN PMDL  Tsdu,
    IN PVOID TsduDescriptor)
{
	TDI_EVENT_CONTEXT *ctx = (TDI_EVENT_CONTEXT *)TdiEventContext;
	PFILE_OBJECT connobj = ot_find_conn_ctx(ctx->fileobj, ConnectionContext);
	NTSTATUS status;

	KdPrint(("[tdi_fw] tdi_event_chained_receive: addrobj 0x%x; connobj: 0x%x; %u; flags: 0x%x\n",
		ctx->fileobj, connobj, ReceiveLength, ReceiveFlags));

	status = ((PTDI_IND_CHAINED_RECEIVE)(ctx->old_handler))
		(ctx->old_context, ConnectionContext, ReceiveFlags,ReceiveLength ,
		StartingOffset, Tsdu, TsduDescriptor);

	KdPrint(("[tdi_fw] tdi_event_chained_receive: status 0x%x\n", status));

	if (status == STATUS_SUCCESS || status == STATUS_PENDING) {
		struct ot_entry *ote_conn;
		KIRQL irql;

		ote_conn = ot_find_fileobj(connobj, &irql);
		if (ote_conn != NULL) {
			ULONG bytes = ReceiveLength;

			ote_conn->bytes_in += bytes;

			// traffic stats
			KeAcquireSpinLockAtDpcLevel(&g_traffic_guard);
			
			g_traffic[TRAFFIC_TOTAL_IN] += bytes;
			
			if (ote_conn->log_disconnect)
				g_traffic[TRAFFIC_COUNTED_IN] += bytes;
			
			KeReleaseSpinLockFromDpcLevel(&g_traffic_guard);

			KeReleaseSpinLock(&g_ot_hash_guard, irql);
		}
	}

	return status;
}
Exemple #18
0
VOID
NTAPI
ExpTimerApcKernelRoutine(IN PKAPC Apc,
                         IN OUT PKNORMAL_ROUTINE* NormalRoutine,
                         IN OUT PVOID* NormalContext,
                         IN OUT PVOID* SystemArgument1,
                         IN OUT PVOID* SystemArguemnt2)
{
    PETIMER Timer;
    KIRQL OldIrql;
    ULONG DerefsToDo = 1;
    PETHREAD Thread = PsGetCurrentThread();

    /* We need to find out which Timer we are */
    Timer = CONTAINING_RECORD(Apc, ETIMER, TimerApc);

    /* Lock the Timer */
    KeAcquireSpinLock(&Timer->Lock, &OldIrql);

    /* Lock the Thread's Active Timer List*/
    KeAcquireSpinLockAtDpcLevel(&Thread->ActiveTimerListLock);

    /* Make sure that the Timer is valid, and that it belongs to this thread */
    if ((Timer->ApcAssociated) && (&Thread->Tcb == Timer->TimerApc.Thread))
    {
        /* Check if it's not periodic */
        if (!Timer->Period)
        {
            /* Remove it from the Active Timers List */
            RemoveEntryList(&Timer->ActiveTimerListEntry);

            /* Disable it */
            Timer->ApcAssociated = FALSE;
            DerefsToDo++;
        }
    }
    else
    {
        /* Clear the normal routine */
        *NormalRoutine = NULL;
    }

    /* Release locks */
    KeReleaseSpinLockFromDpcLevel(&Thread->ActiveTimerListLock);
    KeReleaseSpinLock(&Timer->Lock, OldIrql);

    /* Dereference as needed */
    ObDereferenceObjectEx(Timer, DerefsToDo);
}
Exemple #19
0
BOOLEAN
compdev_post_event_select_driver(PUSB_DEV_MANAGER dev_mgr, DEV_HANDLE dev_handle)
{
    PUSB_EVENT pevent;
    BOOLEAN bret;
    PUSB_DEV pdev;
    USE_BASIC_NON_PENDING_IRQL;

    if (dev_mgr == NULL || dev_handle == 0)
        return FALSE;

    if (usb_query_and_lock_dev(dev_mgr, dev_handle, &pdev) != STATUS_SUCCESS)
        return FALSE;

    KeAcquireSpinLockAtDpcLevel(&dev_mgr->event_list_lock);
    lock_dev(pdev, TRUE);

    if (dev_state(pdev) == USB_DEV_STATE_ZOMB)
    {
        bret = FALSE;
        goto LBL_OUT;
    }

    pevent = alloc_event(&dev_mgr->event_pool, 1);
    if (pevent == NULL)
    {
        bret = FALSE;
        goto LBL_OUT;
    }
    pevent->flags = USB_EVENT_FLAG_ACTIVE;
    pevent->event = USB_EVENT_DEFAULT;
    pevent->pdev = pdev;
    pevent->context = 0;
    pevent->param = 0;
    pevent->pnext = 0;          //vertical queue for serialized operation
    pevent->process_event = compdev_event_select_if_driver;
    pevent->process_queue = event_list_default_process_queue;

    InsertTailList(&dev_mgr->event_list, &pevent->event_link);
    KeSetEvent(&dev_mgr->wake_up_event, 0, FALSE);      // wake up the dev_mgr_thread
    bret = TRUE;

  LBL_OUT:

    unlock_dev(pdev, TRUE);
    KeReleaseSpinLockFromDpcLevel(&dev_mgr->event_list_lock);
    usb_unlock_dev(pdev);
    return bret;
}
Exemple #20
0
NTSTATUS
MacEnable(
    IN  PXENVIF_MAC     Mac
    )
{
    PXENVIF_FRONTEND    Frontend;
    NTSTATUS            status;

    Frontend = Mac->Frontend;

    ASSERT3U(KeGetCurrentIrql(), ==, DISPATCH_LEVEL);
    KeAcquireSpinLockAtDpcLevel(&Mac->Lock);

    status = STORE(Watch,
                   Mac->StoreInterface,
                   FrontendGetPath(Frontend),
                   "disconnect",
                   &Mac->Event,
                   &Mac->Watch);
    if (!NT_SUCCESS(status))
        goto fail1;

    ASSERT(!Mac->Enabled);
    Mac->Enabled = TRUE;

    KeReleaseSpinLockFromDpcLevel(&Mac->Lock);

    return STATUS_SUCCESS;

fail1:
    Error("fail1 (%08x)\n");

    KeReleaseSpinLockFromDpcLevel(&Mac->Lock);

    return status;
}
Exemple #21
0
void
AcpiOsReleaseLock(
    ACPI_SPINLOCK Handle,
    ACPI_CPU_FLAGS Flags)
{
    KIRQL OldIrql = (KIRQL)Flags;

    if (OldIrql >= DISPATCH_LEVEL)
    {
        KeReleaseSpinLockFromDpcLevel((PKSPIN_LOCK)Handle);
    }
    else
    {
        KeReleaseSpinLock((PKSPIN_LOCK)Handle, OldIrql);
    }
}
Exemple #22
0
static int32_t
usbd_func_bulkintr(irp *ip)
{
	int32_t error;
	struct ndisusb_ep *ne;
	struct ndisusb_xfer *nx;
	struct usbd_urb_bulk_or_intr_transfer *ubi;
	union usbd_urb *urb;
	usb_endpoint_descriptor_t *ep;

	urb = usbd_geturb(ip);
	ubi = &urb->uu_bulkintr;
	ep = ubi->ubi_epdesc;
	if (ep == NULL)
		return (USBD_STATUS_INVALID_PIPE_HANDLE);

	ne = usbd_get_ndisep(ip, ep);
	if (ne == NULL) {
		device_printf(IRP_NDIS_DEV(ip), "get NULL endpoint info.\n");
		return (USBD_STATUS_INVALID_PIPE_HANDLE);
	}

	nx = malloc(sizeof(struct ndisusb_xfer), M_USBDEV, M_NOWAIT | M_ZERO);
	if (nx == NULL) {
		device_printf(IRP_NDIS_DEV(ip), "out of memory\n");
		return (USBD_STATUS_NO_MEMORY);
	}
	nx->nx_ep = ne;
	nx->nx_priv = ip;
	KeAcquireSpinLockAtDpcLevel(&ne->ne_lock);
	InsertTailList((&ne->ne_pending), (&nx->nx_next));
	KeReleaseSpinLockFromDpcLevel(&ne->ne_lock);

	/* we've done to setup xfer.  Let's transfer it.  */
	ip->irp_iostat.isb_status = STATUS_PENDING;
	ip->irp_iostat.isb_info = 0;
	USBD_URB_STATUS(urb) = USBD_STATUS_PENDING;
	IoMarkIrpPending(ip);

	error = usbd_taskadd(ip, NDISUSB_TASK_TSTART);
	if (error != USBD_STATUS_SUCCESS)
		return (error);

	return (USBD_STATUS_PENDING);
}
Exemple #23
0
VOID
NICFreeQueuedSendPackets(
    __in  PFDO_DATA  FdoData
    )
/*++
Routine Description:

    Free and complete the pended sends on SendQueueHead
    Assumption: spinlock has been acquired

Arguments:

    FdoData     Pointer to our FdoData

Return Value:

     None

--*/
{
    PLIST_ENTRY     pEntry;
    PIRP            irp;
    NTSTATUS        status = MP_GET_STATUS_FROM_FLAGS(FdoData);

    DebugPrint(TRACE, DBG_WRITE, "--> NICFreeQueuedSendPackets\n");

    while (!IsListEmpty(&FdoData->SendQueueHead))
    {
        pEntry = RemoveHeadList(&FdoData->SendQueueHead);
        FdoData->nWaitSend--;
        KeReleaseSpinLockFromDpcLevel(&FdoData->SendLock);

        ASSERT(pEntry);
        irp = CONTAINING_RECORD(pEntry, IRP, Tail.Overlay.ListEntry);

        NICCompleteSendRequest(FdoData, irp, status, 0, TRUE);


        KeAcquireSpinLockAtDpcLevel(&FdoData->SendLock);
    }

    DebugPrint(TRACE, DBG_WRITE, "<-- NICFreeQueuedSendPackets\n");

}
Exemple #24
0
static FORCEINLINE BOOLEAN
__NotifierUnmask(
    IN  PXENVIF_NOTIFIER    Notifier
    )
{
    BOOLEAN                 Pending;

    KeAcquireSpinLockAtDpcLevel(&Notifier->Lock);

    Pending = (Notifier->Connected) ?
              EVTCHN(Unmask,
                     Notifier->EvtchnInterface,
                     Notifier->Evtchn,
                     FALSE) :
              FALSE;

    KeReleaseSpinLockFromDpcLevel(&Notifier->Lock);

    return Pending;
}
Exemple #25
0
/*
 * @implemented
 */
VOID
EXPORT
EthFilterDprIndicateReceiveComplete(
    IN  PETH_FILTER Filter)
/*
 * FUNCTION: Receive indication complete function for Ethernet devices
 * ARGUMENTS:
 *     Filter = Pointer to Ethernet filter
 */
{
  PLIST_ENTRY CurrentEntry;
  PLOGICAL_ADAPTER Adapter;
  PADAPTER_BINDING AdapterBinding;

  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));

  if( !Filter ) {
      NDIS_DbgPrint(MIN_TRACE, ("Filter is NULL\n"));
      return;
  }

  Adapter = (PLOGICAL_ADAPTER)((PETHI_FILTER)Filter)->Miniport;

  NDIS_DbgPrint(MAX_TRACE, ("acquiring miniport block lock\n"));
  KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
    {
      CurrentEntry = Adapter->ProtocolListHead.Flink;

      while (CurrentEntry != &Adapter->ProtocolListHead)
        {
          AdapterBinding = CONTAINING_RECORD(CurrentEntry, ADAPTER_BINDING, AdapterListEntry);

          (*AdapterBinding->ProtocolBinding->Chars.ReceiveCompleteHandler)(
              AdapterBinding->NdisOpenBlock.ProtocolBindingContext);

          CurrentEntry = CurrentEntry->Flink;
        }
    }
  KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
}
Exemple #26
0
VOID Log(char *format, ...)
{
    KIRQL CurrentIrql;

    unsigned short size;
    va_list args;
    UCHAR buffer[1024] = {0};

    va_start(args, format);

    CurrentIrql = KeGetCurrentIrql();
    if (CurrentIrql < DISPATCH_LEVEL)
    {
        KeRaiseIrqlToDpcLevel();
    }
    
    KeAcquireSpinLockAtDpcLevel(g_LogLock);

/*    RtlZeroMemory(&buffer, sizeof(buffer));*/
/*    vsnprintf((PUCHAR)&buffer, sizeof(buffer), "%d:", g_LogIndex);*/
/*    buffer[1023] = '\0';*/
/*    size = strlen(buffer);*/

/*    InsertLogEntry(buffer, size);*/
/*    */

    RtlZeroMemory(&buffer, sizeof(buffer));
    vsnprintf((PUCHAR)&buffer, sizeof(buffer), (PUCHAR)format, args);
    buffer[1023] = '\0';
    size = strlen(buffer);

    InsertLogEntry(buffer, size);
    
    KeReleaseSpinLockFromDpcLevel(g_LogLock);

    if (CurrentIrql < DISPATCH_LEVEL)
    {
        KeLowerIrql(CurrentIrql);
    }
}
Exemple #27
0
/*
 * this function is for mainly deferring a task to the another thread because
 * we don't want to be in the scope of HAL lock.
 */
static int32_t
usbd_taskadd(irp *ip, unsigned type)
{
	device_t dev = IRP_NDIS_DEV(ip);
	struct ndis_softc *sc = device_get_softc(dev);
	struct ndisusb_task *nt;

	nt = malloc(sizeof(struct ndisusb_task), M_USBDEV, M_NOWAIT | M_ZERO);
	if (nt == NULL)
		return (USBD_STATUS_NO_MEMORY);
	nt->nt_type = type;
	nt->nt_ctx = ip;

	KeAcquireSpinLockAtDpcLevel(&sc->ndisusb_tasklock);
	InsertTailList((&sc->ndisusb_tasklist), (&nt->nt_tasklist));
	KeReleaseSpinLockFromDpcLevel(&sc->ndisusb_tasklock);

	IoQueueWorkItem(sc->ndisusb_taskitem,
	    (io_workitem_func)usbd_task_wrap, WORKQUEUE_CRITICAL, sc);

	return (USBD_STATUS_SUCCESS);
}
/**
 * DPC handler.
 *
 * @param   pDPC        DPC descriptor.
 * @param   pDevObj     Device object.
 * @param   pIrp        Interrupt request packet.
 * @param   pContext    Context specific pointer.
 */
void vboxguestwinDpcHandler(PKDPC pDPC, PDEVICE_OBJECT pDevObj,
                            PIRP pIrp, PVOID pContext)
{
    PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
    Log(("VBoxGuest::vboxguestwinGuestDpcHandler: pDevExt=0x%p\n", pDevExt));

    /* test & reset the counter */
    if (ASMAtomicXchgU32(&pDevExt->u32MousePosChangedSeq, 0))
    {
        Assert(KeGetCurrentIrql() == DISPATCH_LEVEL);
        /* we need a lock here to avoid concurrency with the set event ioctl handler thread,
         * i.e. to prevent the event from destroyed while we're using it */
        KeAcquireSpinLockAtDpcLevel(&pDevExt->win.s.MouseEventAccessLock);
        if (pDevExt->win.s.pfnMouseNotify)
        {
            pDevExt->win.s.pfnMouseNotify(pDevExt->win.s.pvMouseNotify);
        }
        KeReleaseSpinLockFromDpcLevel(&pDevExt->win.s.MouseEventAccessLock);
    }

    /* Process the wake-up list we were asked by the scheduling a DPC
     *  in vboxguestwinIsrHandler(). */
    VBoxGuestWaitDoWakeUps(pDevExt);
}
Exemple #29
0
VOID
KeReleaseInterruptSpinLock (
    __inout PKINTERRUPT Interrupt,
    __in KIRQL OldIrql
    )

/*++

Routine Description:

    This function releases the actual spin lock associated with an interrupt
    object and lowers the IRQL to its previous value.

Arguments:

    Interrupt - Supplies a pointer to a control object of type interrupt.

    OldIrql - Supplies the previous IRQL value.

Return Value:

    None.

--*/

{

    //
    // Release the actual spin lock associated with the interrupt object
    // and lower IRQL to its previous value.
    //

    KeReleaseSpinLockFromDpcLevel(Interrupt->ActualLock);
    KeLowerIrql(OldIrql);
    return;
}
Exemple #30
0
VOID TcpipReleaseSpinLockFromDpcLevel( PKSPIN_LOCK SpinLock ) {
    KeReleaseSpinLockFromDpcLevel( SpinLock );
}