1998-08-25 04:27:26 +00:00
|
|
|
/*
|
2006-08-24 23:25:37 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: ntoskrnl/ke/i386/irq.c
|
|
|
|
* PURPOSE: Manages the Kernel's IRQ support for external drivers,
|
2009-11-02 18:08:49 +00:00
|
|
|
* for the purposes of connecting, disconnecting and setting
|
2006-08-24 23:25:37 +00:00
|
|
|
* up ISRs for drivers. The backend behind the Io* Interrupt
|
|
|
|
* routines.
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
1998-08-25 04:27:26 +00:00
|
|
|
*/
|
|
|
|
|
2007-03-19 03:29:29 +00:00
|
|
|
/* INCLUDES *****************************************************************/
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2002-09-08 10:23:54 +00:00
|
|
|
#define NDEBUG
|
2006-08-24 23:25:37 +00:00
|
|
|
#include <debug.h>
|
2001-04-13 16:12:26 +00:00
|
|
|
|
2007-03-19 03:29:29 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
ULONG KiISRTimeout = 55;
|
|
|
|
USHORT KiISROverflow = 30000;
|
2008-08-10 05:47:20 +00:00
|
|
|
extern ULONG NTAPI KiChainedDispatch2ndLvl(VOID);
|
2007-03-19 03:29:29 +00:00
|
|
|
|
2006-08-24 05:36:50 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KiGetVectorDispatch(IN ULONG Vector,
|
|
|
|
IN PDISPATCH_INFO Dispatch)
|
|
|
|
{
|
|
|
|
PKINTERRUPT_ROUTINE Handler;
|
2010-01-01 15:09:14 +00:00
|
|
|
PVOID Current;
|
2009-10-29 19:58:41 +00:00
|
|
|
UCHAR Type;
|
|
|
|
UCHAR Entry;
|
|
|
|
|
|
|
|
/* Check if this is a primary or 2nd-level dispatch */
|
|
|
|
Type = HalSystemVectorDispatchEntry(Vector,
|
|
|
|
&Dispatch->FlatDispatch,
|
|
|
|
&Dispatch->NoDispatch);
|
|
|
|
ASSERT(Type == 0);
|
|
|
|
|
|
|
|
/* Get the IDT entry for this vector */
|
|
|
|
Entry = HalVectorToIDTEntry(Vector);
|
2006-08-24 02:53:40 +00:00
|
|
|
|
|
|
|
/* Setup the unhandled dispatch */
|
|
|
|
Dispatch->NoDispatch = (PVOID)(((ULONG_PTR)&KiStartUnexpectedRange) +
|
2009-10-29 19:58:41 +00:00
|
|
|
(Entry - PRIMARY_VECTOR_BASE) *
|
2006-08-24 02:53:40 +00:00
|
|
|
KiUnexpectedEntrySize);
|
|
|
|
|
|
|
|
/* Setup the handlers */
|
2010-01-11 17:44:09 +00:00
|
|
|
Dispatch->InterruptDispatch = (PVOID)KiInterruptDispatch;
|
2006-08-24 02:53:40 +00:00
|
|
|
Dispatch->FloatingDispatch = NULL; // Floating Interrupts are not supported
|
2010-01-11 17:44:09 +00:00
|
|
|
Dispatch->ChainedDispatch = (PVOID)KiChainedDispatch;
|
2006-08-24 02:53:40 +00:00
|
|
|
Dispatch->FlatDispatch = NULL;
|
|
|
|
|
|
|
|
/* Get the current handler */
|
2010-01-01 15:09:14 +00:00
|
|
|
Current = KeQueryInterruptHandler(Vector);
|
2006-08-24 02:53:40 +00:00
|
|
|
|
|
|
|
/* Set the interrupt */
|
|
|
|
Dispatch->Interrupt = CONTAINING_RECORD(Current,
|
|
|
|
KINTERRUPT,
|
|
|
|
DispatchCode);
|
|
|
|
|
|
|
|
/* Check what this interrupt is connected to */
|
|
|
|
if ((PKINTERRUPT_ROUTINE)Current == Dispatch->NoDispatch)
|
|
|
|
{
|
|
|
|
/* Not connected */
|
|
|
|
Dispatch->Type = NoConnect;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the handler */
|
|
|
|
Handler = Dispatch->Interrupt->DispatchAddress;
|
|
|
|
if (Handler == Dispatch->ChainedDispatch)
|
|
|
|
{
|
|
|
|
/* It's a chained interrupt */
|
|
|
|
Dispatch->Type = ChainConnect;
|
|
|
|
}
|
|
|
|
else if ((Handler == Dispatch->InterruptDispatch) ||
|
|
|
|
(Handler == Dispatch->FloatingDispatch))
|
|
|
|
{
|
|
|
|
/* It's unchained */
|
|
|
|
Dispatch->Type = NormalConnect;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Unknown */
|
|
|
|
Dispatch->Type = UnknownConnect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KiConnectVectorToInterrupt(IN PKINTERRUPT Interrupt,
|
|
|
|
IN CONNECT_TYPE Type)
|
|
|
|
{
|
|
|
|
DISPATCH_INFO Dispatch;
|
|
|
|
PKINTERRUPT_ROUTINE Handler;
|
|
|
|
|
|
|
|
/* Get vector data */
|
|
|
|
KiGetVectorDispatch(Interrupt->Vector, &Dispatch);
|
|
|
|
|
|
|
|
/* Check if we're only disconnecting */
|
|
|
|
if (Type == NoConnect)
|
|
|
|
{
|
|
|
|
/* Set the handler to NoDispatch */
|
|
|
|
Handler = Dispatch.NoDispatch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the right handler */
|
|
|
|
Handler = (Type == NormalConnect) ?
|
|
|
|
Dispatch.InterruptDispatch:
|
|
|
|
Dispatch.ChainedDispatch;
|
|
|
|
ASSERT(Interrupt->FloatingSave == FALSE);
|
|
|
|
|
|
|
|
/* Set the handler */
|
|
|
|
Interrupt->DispatchAddress = Handler;
|
|
|
|
|
2010-01-11 17:44:09 +00:00
|
|
|
/* Read note in trap.s -- patching not needed since JMP is static */
|
2006-08-24 02:53:40 +00:00
|
|
|
|
|
|
|
/* Now set the final handler address */
|
|
|
|
ASSERT(Dispatch.FlatDispatch == NULL);
|
|
|
|
Handler = (PVOID)&Interrupt->DispatchCode;
|
|
|
|
}
|
|
|
|
|
2010-01-01 15:09:14 +00:00
|
|
|
/* Register the interrupt */
|
|
|
|
KeRegisterInterruptHandler(Interrupt->Vector, Handler);
|
2006-08-24 02:53:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 23:18:53 +00:00
|
|
|
VOID
|
|
|
|
FORCEINLINE
|
|
|
|
DECLSPEC_NORETURN
|
|
|
|
KiExitInterrupt(IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN KIRQL OldIrql,
|
|
|
|
IN BOOLEAN Spurious)
|
|
|
|
{
|
|
|
|
/* Check if this was a real interrupt */
|
|
|
|
if (!Spurious)
|
|
|
|
{
|
|
|
|
/* It was, disable interrupts and restore the IRQL */
|
|
|
|
_disable();
|
[HAL]: Rewrite IRQL handling. Alex's original code (lately translated to C) was a copy of the MicroChannel (MCA), Checked-Build HAL, an unexplained choice considering MCA is not supported or even available anymore. Windows, on machines with a PIC, uses a mechanism called Lazy IRQL, in which the PIC is only programmed "lazily", meaning that lowering and raising the IRQL does not actually change the interrupt mask. Therefore, lower priority interrupts will still come in at high IRQL. At this point, the HAL will detect this, only now mask the PICs, and lie that the lower interrupt was "spurious", while setting a pending bit. When the IRQL is lowered, the bit is detected, and a software/delayed "INT" is done with the correct IRQ vector number. More details are available in the typical resources.
[HAL]: Implement support for Level interrupts, which are used by certain EISA cards, and more particularly, all PCI hardware. Level interrupts were not previously handled correctly, being treated as edge/latched interrupts instead.
[NTOS/HAL]: Remove VDM Alert KPCR hack (which was buggy). Now the PKTRAP_FRAME is passed as a parameter to HalpEndSoftwareInterrupt/HalEndSystemInterrupt. This also removes the HalpNestedTrap ASM hack, since the call can now be done in C.
[PERF]: On real machines, writing the PIC mask is a relatively expensive I/O operation, and IRQL lower/raise can happen hundreds of times a second. Lazy IRQL provides an important optimization.
[PERF]: Correctly handling level interrupts as level interrupts allows for faster, and more efficient, IRQ handling.
svn path=/trunk/; revision=45320
2010-01-29 21:10:33 +00:00
|
|
|
HalEndSystemInterrupt(OldIrql, TrapFrame);
|
2010-01-28 23:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now exit the trap */
|
|
|
|
KiEoiHelper(TrapFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
KiUnexpectedInterrupt(VOID)
|
|
|
|
{
|
|
|
|
/* Crash the machine */
|
|
|
|
KeBugCheck(TRAP_CAUSE_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
KiUnexpectedInterruptTailHandler(IN PKTRAP_FRAME TrapFrame)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
|
|
/* Enter trap */
|
|
|
|
KiEnterInterruptTrap(TrapFrame);
|
|
|
|
|
|
|
|
/* Increase interrupt count */
|
|
|
|
KeGetCurrentPrcb()->InterruptCount++;
|
|
|
|
|
|
|
|
/* Start the interrupt */
|
2010-02-13 02:01:33 +00:00
|
|
|
if (HalBeginSystemInterrupt(HIGH_LEVEL, TrapFrame->ErrCode, &OldIrql))
|
2010-01-28 23:18:53 +00:00
|
|
|
{
|
|
|
|
/* Warn user */
|
|
|
|
DPRINT1("\n\x7\x7!!! Unexpected Interrupt %02lx !!!\n");
|
|
|
|
|
|
|
|
/* Now call the epilogue code */
|
|
|
|
KiExitInterrupt(TrapFrame, OldIrql, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Now call the epilogue code */
|
|
|
|
KiExitInterrupt(TrapFrame, OldIrql, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef
|
|
|
|
FASTCALL
|
|
|
|
VOID
|
|
|
|
(PKI_INTERRUPT_DISPATCH)(
|
|
|
|
IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN PKINTERRUPT Interrupt
|
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
KiInterruptDispatch(IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN PKINTERRUPT Interrupt)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
|
|
/* Increase interrupt count */
|
|
|
|
KeGetCurrentPrcb()->InterruptCount++;
|
|
|
|
|
|
|
|
/* Begin the interrupt, making sure it's not spurious */
|
|
|
|
if (HalBeginSystemInterrupt(Interrupt->SynchronizeIrql,
|
|
|
|
Interrupt->Vector,
|
|
|
|
&OldIrql))
|
|
|
|
{
|
|
|
|
/* Acquire interrupt lock */
|
|
|
|
KxAcquireSpinLock(Interrupt->ActualLock);
|
|
|
|
|
|
|
|
/* Call the ISR */
|
|
|
|
Interrupt->ServiceRoutine(Interrupt, Interrupt->ServiceContext);
|
|
|
|
|
|
|
|
/* Release interrupt lock */
|
|
|
|
KxReleaseSpinLock(Interrupt->ActualLock);
|
|
|
|
|
|
|
|
/* Now call the epilogue code */
|
|
|
|
KiExitInterrupt(TrapFrame, OldIrql, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Now call the epilogue code */
|
|
|
|
KiExitInterrupt(TrapFrame, OldIrql, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
KiChainedDispatch(IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN PKINTERRUPT Interrupt)
|
|
|
|
{
|
2010-01-29 01:37:25 +00:00
|
|
|
KIRQL OldIrql;
|
|
|
|
BOOLEAN Handled;
|
|
|
|
PLIST_ENTRY NextEntry, ListHead;
|
2010-02-10 23:24:59 +00:00
|
|
|
|
2010-01-28 23:18:53 +00:00
|
|
|
/* Increase interrupt count */
|
|
|
|
KeGetCurrentPrcb()->InterruptCount++;
|
2010-01-29 01:37:25 +00:00
|
|
|
|
|
|
|
/* Begin the interrupt, making sure it's not spurious */
|
|
|
|
if (HalBeginSystemInterrupt(Interrupt->Irql,
|
|
|
|
Interrupt->Vector,
|
|
|
|
&OldIrql))
|
|
|
|
{
|
|
|
|
/* Get list pointers */
|
|
|
|
ListHead = &Interrupt->InterruptListEntry;
|
|
|
|
NextEntry = ListHead; /* The head is an entry! */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Check if this interrupt's IRQL is higher than the current one */
|
|
|
|
if (Interrupt->SynchronizeIrql > Interrupt->Irql)
|
|
|
|
{
|
|
|
|
/* Raise to higher IRQL */
|
|
|
|
OldIrql = KfRaiseIrql(Interrupt->Irql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Acquire interrupt lock */
|
|
|
|
KxAcquireSpinLock(Interrupt->ActualLock);
|
|
|
|
|
|
|
|
/* Call the ISR */
|
|
|
|
Handled = Interrupt->ServiceRoutine(Interrupt,
|
|
|
|
Interrupt->ServiceContext);
|
|
|
|
|
|
|
|
/* Release interrupt lock */
|
|
|
|
KxReleaseSpinLock(Interrupt->ActualLock);
|
|
|
|
|
|
|
|
/* Check if this interrupt's IRQL is higher than the current one */
|
|
|
|
if (Interrupt->SynchronizeIrql > Interrupt->Irql)
|
|
|
|
{
|
|
|
|
/* Lower the IRQL back */
|
|
|
|
KfLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
2010-01-29 02:25:30 +00:00
|
|
|
/* Check if the interrupt got handled and it's level */
|
|
|
|
if ((Handled) && (Interrupt->Mode == LevelSensitive)) break;
|
|
|
|
|
|
|
|
/* What's next? */
|
|
|
|
NextEntry = NextEntry->Flink;
|
2010-01-29 01:37:25 +00:00
|
|
|
|
2010-01-29 02:25:30 +00:00
|
|
|
/* Is this the last one? */
|
|
|
|
if (NextEntry == ListHead)
|
|
|
|
{
|
|
|
|
/* Level should not have gotten here */
|
|
|
|
if (Interrupt->Mode == LevelSensitive) break;
|
2010-01-29 01:37:25 +00:00
|
|
|
|
2010-01-29 02:25:30 +00:00
|
|
|
/* As for edge, we can only exit once nobody can handle the interrupt */
|
|
|
|
if (!Handled) break;
|
2010-01-29 01:37:25 +00:00
|
|
|
}
|
2010-01-29 02:25:30 +00:00
|
|
|
|
|
|
|
/* Get the interrupt object for the next pass */
|
|
|
|
Interrupt = CONTAINING_RECORD(NextEntry, KINTERRUPT, InterruptListEntry);
|
2010-01-29 01:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now call the epilogue code */
|
|
|
|
KiExitInterrupt(TrapFrame, OldIrql, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Now call the epilogue code */
|
|
|
|
KiExitInterrupt(TrapFrame, OldIrql, TRUE);
|
|
|
|
}
|
2010-02-10 23:24:59 +00:00
|
|
|
}
|
2010-01-28 23:18:53 +00:00
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
2010-01-29 01:12:08 +00:00
|
|
|
KiInterruptTemplateHandler(IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN PKINTERRUPT Interrupt)
|
2010-01-28 23:18:53 +00:00
|
|
|
{
|
|
|
|
/* Enter interrupt frame */
|
|
|
|
KiEnterInterruptTrap(TrapFrame);
|
|
|
|
|
|
|
|
/* Call the correct dispatcher */
|
|
|
|
((PKI_INTERRUPT_DISPATCH*)Interrupt->DispatchAddress)(TrapFrame, Interrupt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-24 05:36:50 +00:00
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
2003-07-11 01:23:16 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2006-08-24 02:53:40 +00:00
|
|
|
VOID
|
2006-08-24 23:25:37 +00:00
|
|
|
NTAPI
|
|
|
|
KeInitializeInterrupt(IN PKINTERRUPT Interrupt,
|
|
|
|
IN PKSERVICE_ROUTINE ServiceRoutine,
|
|
|
|
IN PVOID ServiceContext,
|
|
|
|
IN PKSPIN_LOCK SpinLock,
|
|
|
|
IN ULONG Vector,
|
|
|
|
IN KIRQL Irql,
|
|
|
|
IN KIRQL SynchronizeIrql,
|
|
|
|
IN KINTERRUPT_MODE InterruptMode,
|
|
|
|
IN BOOLEAN ShareVector,
|
|
|
|
IN CHAR ProcessorNumber,
|
|
|
|
IN BOOLEAN FloatingSave)
|
2000-07-10 21:55:49 +00:00
|
|
|
{
|
2006-08-24 02:53:40 +00:00
|
|
|
ULONG i;
|
|
|
|
PULONG DispatchCode = &Interrupt->DispatchCode[0], Patch = DispatchCode;
|
|
|
|
|
|
|
|
/* Set the Interrupt Header */
|
|
|
|
Interrupt->Type = InterruptObject;
|
|
|
|
Interrupt->Size = sizeof(KINTERRUPT);
|
|
|
|
|
|
|
|
/* Check if we got a spinlock */
|
|
|
|
if (SpinLock)
|
|
|
|
{
|
|
|
|
Interrupt->ActualLock = SpinLock;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This means we'll be usin the built-in one */
|
|
|
|
KeInitializeSpinLock(&Interrupt->SpinLock);
|
|
|
|
Interrupt->ActualLock = &Interrupt->SpinLock;
|
|
|
|
}
|
2000-07-10 21:55:49 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Set the other settings */
|
|
|
|
Interrupt->ServiceRoutine = ServiceRoutine;
|
|
|
|
Interrupt->ServiceContext = ServiceContext;
|
|
|
|
Interrupt->Vector = Vector;
|
|
|
|
Interrupt->Irql = Irql;
|
|
|
|
Interrupt->SynchronizeIrql = SynchronizeIrql;
|
|
|
|
Interrupt->Mode = InterruptMode;
|
|
|
|
Interrupt->ShareVector = ShareVector;
|
|
|
|
Interrupt->Number = ProcessorNumber;
|
|
|
|
Interrupt->FloatingSave = FloatingSave;
|
2009-09-27 20:07:43 +00:00
|
|
|
Interrupt->TickCount = MAXULONG;
|
|
|
|
Interrupt->DispatchCount = MAXULONG;
|
2006-08-24 02:53:40 +00:00
|
|
|
|
|
|
|
/* Loop the template in memory */
|
|
|
|
for (i = 0; i < KINTERRUPT_DISPATCH_CODES; i++)
|
|
|
|
{
|
|
|
|
/* Copy the dispatch code */
|
2010-01-29 01:12:08 +00:00
|
|
|
*DispatchCode++ = ((PULONG)KiInterruptTemplate)[i];
|
2006-08-24 02:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Jump to the last 4 bytes */
|
|
|
|
Patch = (PULONG)((ULONG_PTR)Patch +
|
|
|
|
((ULONG_PTR)&KiInterruptTemplateObject -
|
|
|
|
(ULONG_PTR)KiInterruptTemplate) - 4);
|
2000-07-10 21:55:49 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Apply the patch */
|
|
|
|
*Patch = PtrToUlong(Interrupt);
|
2000-07-10 21:55:49 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Disconnect it at first */
|
|
|
|
Interrupt->Connected = FALSE;
|
|
|
|
}
|
2004-11-07 22:55:38 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KeConnectInterrupt(IN PKINTERRUPT Interrupt)
|
|
|
|
{
|
|
|
|
BOOLEAN Connected, Error, Status;
|
|
|
|
KIRQL Irql, OldIrql;
|
|
|
|
UCHAR Number;
|
|
|
|
ULONG Vector;
|
|
|
|
DISPATCH_INFO Dispatch;
|
|
|
|
|
|
|
|
/* Get data from interrupt */
|
|
|
|
Number = Interrupt->Number;
|
|
|
|
Vector = Interrupt->Vector;
|
|
|
|
Irql = Interrupt->Irql;
|
|
|
|
|
|
|
|
/* Validate the settings */
|
|
|
|
if ((Irql > HIGH_LEVEL) ||
|
|
|
|
(Number >= KeNumberProcessors) ||
|
|
|
|
(Interrupt->SynchronizeIrql < Irql) ||
|
|
|
|
(Interrupt->FloatingSave))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-11-01 14:37:19 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Set defaults */
|
|
|
|
Connected = FALSE;
|
|
|
|
Error = FALSE;
|
2005-01-01 11:28:46 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Set the system affinity and acquire the dispatcher lock */
|
|
|
|
KeSetSystemAffinityThread(1 << Number);
|
2006-11-28 08:11:14 +00:00
|
|
|
OldIrql = KiAcquireDispatcherLock();
|
2005-01-01 11:28:46 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Check if it's already been connected */
|
|
|
|
if (!Interrupt->Connected)
|
|
|
|
{
|
|
|
|
/* Get vector dispatching information */
|
|
|
|
KiGetVectorDispatch(Vector, &Dispatch);
|
2005-01-01 11:28:46 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Check if the vector is already connected */
|
|
|
|
if (Dispatch.Type == NoConnect)
|
|
|
|
{
|
|
|
|
/* Do the connection */
|
|
|
|
Interrupt->Connected = Connected = TRUE;
|
2005-01-01 11:28:46 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Initialize the list */
|
|
|
|
InitializeListHead(&Interrupt->InterruptListEntry);
|
2005-01-01 11:28:46 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Connect and enable the interrupt */
|
|
|
|
KiConnectVectorToInterrupt(Interrupt, NormalConnect);
|
|
|
|
Status = HalEnableSystemInterrupt(Vector, Irql, Interrupt->Mode);
|
|
|
|
if (!Status) Error = TRUE;
|
|
|
|
}
|
|
|
|
else if ((Dispatch.Type != UnknownConnect) &&
|
|
|
|
(Interrupt->ShareVector) &&
|
|
|
|
(Dispatch.Interrupt->ShareVector) &&
|
|
|
|
(Dispatch.Interrupt->Mode == Interrupt->Mode))
|
|
|
|
{
|
|
|
|
/* The vector is shared and the interrupts are compatible */
|
|
|
|
Interrupt->Connected = Connected = TRUE;
|
2009-02-23 13:16:43 +00:00
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
// ASSERT(Irql <= SYNCH_LEVEL);
|
2006-08-24 02:53:40 +00:00
|
|
|
|
|
|
|
/* Check if this is the first chain */
|
|
|
|
if (Dispatch.Type != ChainConnect)
|
|
|
|
{
|
2009-02-23 13:16:43 +00:00
|
|
|
/* This is not supported */
|
|
|
|
ASSERT(Dispatch.Interrupt->Mode != Latched);
|
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Setup the chainned handler */
|
|
|
|
KiConnectVectorToInterrupt(Dispatch.Interrupt, ChainConnect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert into the interrupt list */
|
|
|
|
InsertTailList(&Dispatch.Interrupt->InterruptListEntry,
|
|
|
|
&Interrupt->InterruptListEntry);
|
|
|
|
}
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Unlock the dispatcher and revert affinity */
|
2006-11-28 08:11:14 +00:00
|
|
|
KiReleaseDispatcherLock(OldIrql);
|
2006-08-24 02:53:40 +00:00
|
|
|
KeRevertToUserAffinityThread();
|
2005-01-01 11:28:46 +00:00
|
|
|
|
2007-03-19 03:29:29 +00:00
|
|
|
/* Check if we failed while trying to connect */
|
|
|
|
if ((Connected) && (Error))
|
|
|
|
{
|
|
|
|
DPRINT1("HalEnableSystemInterrupt failed\n");
|
|
|
|
KeDisconnectInterrupt(Interrupt);
|
|
|
|
Connected = FALSE;
|
|
|
|
}
|
|
|
|
|
2006-08-24 02:53:40 +00:00
|
|
|
/* Return to caller */
|
|
|
|
return Connected;
|
2000-07-10 21:55:49 +00:00
|
|
|
}
|
|
|
|
|
2003-07-11 01:23:16 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
2000-07-10 21:55:49 +00:00
|
|
|
*/
|
2006-08-24 05:36:50 +00:00
|
|
|
BOOLEAN
|
2006-08-24 23:25:37 +00:00
|
|
|
NTAPI
|
|
|
|
KeDisconnectInterrupt(IN PKINTERRUPT Interrupt)
|
2000-07-10 21:55:49 +00:00
|
|
|
{
|
2006-08-24 05:36:50 +00:00
|
|
|
KIRQL OldIrql, Irql;
|
|
|
|
ULONG Vector;
|
|
|
|
DISPATCH_INFO Dispatch;
|
|
|
|
PKINTERRUPT NextInterrupt;
|
2005-06-22 23:10:15 +00:00
|
|
|
BOOLEAN State;
|
2005-01-01 11:28:46 +00:00
|
|
|
|
2005-06-22 23:10:15 +00:00
|
|
|
/* Set the affinity */
|
2006-08-24 05:36:50 +00:00
|
|
|
KeSetSystemAffinityThread(1 << Interrupt->Number);
|
2005-01-01 11:28:46 +00:00
|
|
|
|
2006-08-24 05:36:50 +00:00
|
|
|
/* Lock the dispatcher */
|
2006-11-28 08:11:14 +00:00
|
|
|
OldIrql = KiAcquireDispatcherLock();
|
2005-01-01 11:28:46 +00:00
|
|
|
|
2005-06-22 23:10:15 +00:00
|
|
|
/* Check if it's actually connected */
|
2006-08-24 05:36:50 +00:00
|
|
|
State = Interrupt->Connected;
|
|
|
|
if (State)
|
2005-06-22 23:10:15 +00:00
|
|
|
{
|
2006-08-24 05:36:50 +00:00
|
|
|
/* Get the vector and IRQL */
|
|
|
|
Irql = Interrupt->Irql;
|
|
|
|
Vector = Interrupt->Vector;
|
|
|
|
|
|
|
|
/* Get vector dispatch data */
|
|
|
|
KiGetVectorDispatch(Vector, &Dispatch);
|
|
|
|
|
|
|
|
/* Check if it was chained */
|
|
|
|
if (Dispatch.Type == ChainConnect)
|
|
|
|
{
|
|
|
|
/* Check if the top-level interrupt is being removed */
|
|
|
|
ASSERT(Irql <= SYNCH_LEVEL);
|
|
|
|
if (Interrupt == Dispatch.Interrupt)
|
|
|
|
{
|
|
|
|
/* Get the next one */
|
|
|
|
Dispatch.Interrupt = CONTAINING_RECORD(Dispatch.Interrupt->
|
|
|
|
InterruptListEntry.Flink,
|
|
|
|
KINTERRUPT,
|
|
|
|
InterruptListEntry);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-08-24 05:36:50 +00:00
|
|
|
/* Reconnect it */
|
|
|
|
KiConnectVectorToInterrupt(Dispatch.Interrupt, ChainConnect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove it */
|
|
|
|
RemoveEntryList(&Interrupt->InterruptListEntry);
|
|
|
|
|
|
|
|
/* Get the next one */
|
|
|
|
NextInterrupt = CONTAINING_RECORD(Dispatch.Interrupt->
|
|
|
|
InterruptListEntry.Flink,
|
|
|
|
KINTERRUPT,
|
|
|
|
InterruptListEntry);
|
|
|
|
|
|
|
|
/* Check if this is the only one left */
|
|
|
|
if (Dispatch.Interrupt == NextInterrupt)
|
|
|
|
{
|
|
|
|
/* Connect it in non-chained mode */
|
|
|
|
KiConnectVectorToInterrupt(Dispatch.Interrupt, NormalConnect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2005-06-22 23:10:15 +00:00
|
|
|
{
|
2006-08-24 05:36:50 +00:00
|
|
|
/* Only one left, disable and remove it */
|
|
|
|
HalDisableSystemInterrupt(Interrupt->Vector, Irql);
|
|
|
|
KiConnectVectorToInterrupt(Interrupt, NoConnect);
|
2005-06-22 23:10:15 +00:00
|
|
|
}
|
2006-08-24 05:36:50 +00:00
|
|
|
|
2005-06-22 23:10:15 +00:00
|
|
|
/* Disconnect it */
|
2006-08-24 05:36:50 +00:00
|
|
|
Interrupt->Connected = FALSE;
|
2005-06-22 23:10:15 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 05:36:50 +00:00
|
|
|
/* Unlock the dispatcher and revert affinity */
|
2006-11-28 08:11:14 +00:00
|
|
|
KiReleaseDispatcherLock(OldIrql);
|
2005-06-22 23:10:15 +00:00
|
|
|
KeRevertToUserAffinityThread();
|
2006-08-24 05:36:50 +00:00
|
|
|
|
|
|
|
/* Return to caller */
|
2005-06-22 23:10:15 +00:00
|
|
|
return State;
|
2005-01-01 11:28:46 +00:00
|
|
|
}
|
2000-07-10 21:55:49 +00:00
|
|
|
|
2010-01-11 17:44:09 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt,
|
|
|
|
IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
|
|
|
|
IN PVOID SynchronizeContext OPTIONAL)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
|
|
/* Raise IRQL */
|
|
|
|
OldIrql = KfRaiseIrql(Interrupt->SynchronizeIrql);
|
|
|
|
|
|
|
|
/* Acquire interrupt spinlock */
|
|
|
|
KeAcquireSpinLockAtDpcLevel(Interrupt->ActualLock);
|
|
|
|
|
|
|
|
/* Call the routine */
|
|
|
|
Status = SynchronizeRoutine(SynchronizeContext);
|
|
|
|
|
|
|
|
/* Release lock */
|
|
|
|
KeReleaseSpinLockFromDpcLevel(Interrupt->ActualLock);
|
|
|
|
|
|
|
|
/* Lower IRQL */
|
|
|
|
KfLowerIrql(OldIrql);
|
|
|
|
|
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2000-03-19 13:35:38 +00:00
|
|
|
/* EOF */
|