ReactOS  0.4.14-dev-115-g4576127
interrupt.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for interrupt.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

void KiInterruptDispatch (void)
 
VOID 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)
 
BOOLEAN NTAPI KeConnectInterrupt (IN PKINTERRUPT Interrupt)
 
BOOLEAN NTAPI KeDisconnectInterrupt (IN PKINTERRUPT Interrupt)
 
BOOLEAN NTAPI KeSynchronizeExecution (IN OUT PKINTERRUPT Interrupt, IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine, IN PVOID SynchronizeContext OPTIONAL)
 

Variables

UCHAR KiInterruptDispatchTemplate [16]
 
UCHAR KiUnexpectedRange []
 
UCHAR KiUnexpectedRangeEnd []
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file interrupt.c.

Function Documentation

◆ KeConnectInterrupt()

BOOLEAN NTAPI KeConnectInterrupt ( IN PKINTERRUPT  Interrupt)

Definition at line 81 of file interrupt.c.

82 {
83  PVOID CurrentHandler;
84 
85  ASSERT(Interrupt->Vector <= MAXIMUM_IDTVECTOR);
86  ASSERT(Interrupt->Number < KeNumberProcessors);
87  ASSERT(Interrupt->Irql <= HIGH_LEVEL);
88 
89  /* Check if its already connected */
90  if (Interrupt->Connected) return TRUE;
91 
92  /* Query the current handler */
93  CurrentHandler = KeQueryInterruptHandler(Interrupt->Vector);
94 
95  /* Check if the vector is already unused */
96  if ((CurrentHandler >= (PVOID)KiUnexpectedRange) &&
97  (CurrentHandler <= (PVOID)KiUnexpectedRangeEnd))
98  {
99  /* Initialize the list for chained interrupts */
100  InitializeListHead(&Interrupt->InterruptListEntry);
101 
102  /* Set normal dispatch address */
103  Interrupt->DispatchAddress = KiInterruptDispatch;
104 
105  /* Set the new handler */
106  KeRegisterInterruptHandler(Interrupt->Vector,
107  Interrupt->DispatchCode);
108 
109  if (!HalEnableSystemInterrupt(Interrupt->Vector,
110  Interrupt->Irql,
111  Interrupt->Mode))
112  {
113  /* Didn't work, restore old handler */
114  DPRINT1("HalEnableSystemInterrupt failed\n");
115  KeRegisterInterruptHandler(Interrupt->Vector, CurrentHandler);
116  return FALSE;
117  }
118 
119  /* Mark as connected */
120  Interrupt->Connected = TRUE;
121  }
122  else
123  {
124  // later
125  __debugbreak();
126  }
127 
128  return TRUE;
129 }
BOOLEAN NTAPI HalEnableSystemInterrupt(IN ULONG Vector, IN KIRQL Irql, IN KINTERRUPT_MODE InterruptMode)
Definition: pic.c:295
#define TRUE
Definition: types.h:120
UCHAR KiUnexpectedRange[]
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
FORCEINLINE PVOID KeQueryInterruptHandler(IN ULONG Vector)
Definition: ke.h:268
#define MAXIMUM_IDTVECTOR
Definition: asm.h:277
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:242
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
UCHAR KiUnexpectedRangeEnd[]
#define DPRINT1
Definition: precomp.h:8
void KiInterruptDispatch(void)

Referenced by IoConnectInterrupt().

◆ KeDisconnectInterrupt()

BOOLEAN NTAPI KeDisconnectInterrupt ( IN PKINTERRUPT  Interrupt)

Definition at line 133 of file interrupt.c.

134 {
136  __debugbreak();
137  return FALSE;
138 }
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by IoDisconnectInterrupt().

◆ KeInitializeInterrupt()

VOID 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 
)

Definition at line 29 of file interrupt.c.

41 {
42 
43  /* Initialize the header */
44  Interrupt->Type = InterruptObject;
45  Interrupt->Size = sizeof(KINTERRUPT);
46 
47  /* If no Spinlock is given, use the internal */
48  if (!SpinLock) SpinLock = &Interrupt->SpinLock;
49  KeInitializeSpinLock(&Interrupt->SpinLock);
50 
51  /* Set the given parameters */
52  Interrupt->ServiceRoutine = ServiceRoutine;
53  Interrupt->ServiceContext = ServiceContext;
54  Interrupt->ActualLock = SpinLock;
55  Interrupt->Vector = Vector;
56  Interrupt->Irql = Irql;
57  Interrupt->SynchronizeIrql = SynchronizeIrql;
58  Interrupt->Mode = InterruptMode;
59  Interrupt->ShareVector = ShareVector;
60  Interrupt->Number = ProcessorNumber;
61  Interrupt->FloatingSave = FloatingSave;
62 
63  /* Set initial values */
64  Interrupt->TickCount = 0;
65  Interrupt->Connected = FALSE;
66  Interrupt->ServiceCount = 0;
67  Interrupt->DispatchCount = 0;
68  Interrupt->TrapFrame = NULL;
69  Interrupt->Reserved = 0;
70 
71  /* Copy the dispatch code (its location independent, no need to patch it) */
72  RtlCopyMemory(Interrupt->DispatchCode,
74  sizeof(Interrupt->DispatchCode));
75 
76  Interrupt->DispatchAddress = 0;
77 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG _In_ KIRQL _In_ KIRQL _In_ KINTERRUPT_MODE InterruptMode
Definition: iofuncs.h:798
UCHAR KiInterruptDispatchTemplate[16]
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG _In_ KIRQL _In_ KIRQL _In_ KINTERRUPT_MODE _In_ BOOLEAN ShareVector
Definition: iofuncs.h:798
_Out_ PKIRQL Irql
Definition: csq.h:179
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
smooth NULL
Definition: ftsmooth.c:416
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG _In_ KIRQL _In_ KIRQL SynchronizeIrql
Definition: iofuncs.h:798
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID ServiceContext
Definition: iofuncs.h:798
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG _In_ KIRQL _In_ KIRQL _In_ KINTERRUPT_MODE _In_ BOOLEAN _In_ KAFFINITY _In_ BOOLEAN FloatingSave
Definition: iofuncs.h:798
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:798
struct _KINTERRUPT KINTERRUPT
_In_ PKSERVICE_ROUTINE ServiceRoutine
Definition: iofuncs.h:798

Referenced by IoConnectInterrupt().

◆ KeSynchronizeExecution()

BOOLEAN NTAPI KeSynchronizeExecution ( IN OUT PKINTERRUPT  Interrupt,
IN PKSYNCHRONIZE_ROUTINE  SynchronizeRoutine,
IN PVOID SynchronizeContext  OPTIONAL 
)

Definition at line 142 of file interrupt.c.

145 {
147  KIRQL OldIrql;
148 
149  /* Raise IRQL */
150  OldIrql = KfRaiseIrql(Interrupt->SynchronizeIrql);
151 
152  /* Acquire interrupt spinlock */
153  KeAcquireSpinLockAtDpcLevel(Interrupt->ActualLock);
154 
155  /* Call the routine */
157 
158  /* Release lock */
159  KeReleaseSpinLockFromDpcLevel(Interrupt->ActualLock);
160 
161  /* Lower IRQL */
163 
164  /* Return status */
165  return Success;
166 }
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
_In_ PKSYNCHRONIZE_ROUTINE SynchronizeRoutine
Definition: kefuncs.h:549
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
_In_ PKSYNCHRONIZE_ROUTINE _In_opt_ __drv_aliasesMem PVOID SynchronizeContext
Definition: kefuncs.h:549

Referenced by KspSynchronizedEventRoutine(), NdisMSynchronizeWithInterrupt(), ScsiPortAllocateAdapterChannel(), ScsiPortDpcForIsr(), ScsiPortInitialize(), ScsiPortIoTimer(), ScsiPortStartIo(), SerialDeviceControl(), SpiAdapterControl(), StreamClassStartDevice(), TestSynchronizeExecution(), and VideoPortSynchronizeExecution().

◆ KiInterruptDispatch()

void KiInterruptDispatch ( void  )

Referenced by KeConnectInterrupt().

Variable Documentation

◆ KiInterruptDispatchTemplate

UCHAR KiInterruptDispatchTemplate[16]

Referenced by KeInitializeInterrupt().

◆ KiUnexpectedRange

UCHAR KiUnexpectedRange[]

Referenced by KeConnectInterrupt().

◆ KiUnexpectedRangeEnd

UCHAR KiUnexpectedRangeEnd[]

Referenced by KeConnectInterrupt().