ReactOS  0.4.14-dev-315-gbb6fece
mpsirql.c File Reference
#include <hal.h>
#include <debug.h>
Include dependency graph for mpsirql.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

KIRQL NTAPI KeGetCurrentIrql (VOID)
 
VOID KeSetCurrentIrql (KIRQL NewIrql)
 
VOID HalpLowerIrql (KIRQL NewIrql, BOOLEAN FromHalEndSystemInterrupt)
 
VOID FASTCALL KfLowerIrql (KIRQL NewIrql)
 
KIRQL FASTCALL KfRaiseIrql (KIRQL NewIrql)
 
KIRQL NTAPI KeRaiseIrqlToDpcLevel (VOID)
 
KIRQL NTAPI KeRaiseIrqlToSynchLevel (VOID)
 
BOOLEAN NTAPI HalBeginSystemInterrupt (KIRQL Irql, ULONG Vector, PKIRQL OldIrql)
 
VOID NTAPI HalEndSystemInterrupt (KIRQL Irql, IN PKTRAP_FRAME TrapFrame)
 
VOID NTAPI HalDisableSystemInterrupt (ULONG Vector, KIRQL Irql)
 
BOOLEAN NTAPI HalEnableSystemInterrupt (ULONG Vector, KIRQL Irql, KINTERRUPT_MODE InterruptMode)
 
VOID FASTCALL HalRequestSoftwareInterrupt (IN KIRQL Request)
 
VOID FASTCALL HalClearSoftwareInterrupt (IN KIRQL Request)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file mpsirql.c.

Function Documentation

◆ HalBeginSystemInterrupt()

BOOLEAN NTAPI HalBeginSystemInterrupt ( KIRQL  Irql,
ULONG  Vector,
PKIRQL  OldIrql 
)

Definition at line 244 of file mpsirql.c.

247 {
248  ULONG Flags;
249  DPRINT("Vector (0x%X) Irql (0x%X)\n", Vector, Irql);
250 
251  if (KeGetCurrentIrql () >= Irql)
252  {
253  DPRINT1("current irql %d, new irql %d\n", KeGetCurrentIrql(), Irql);
254  ASSERT(FALSE);
255  }
256 
257  Flags = __readeflags();
259  {
260  DPRINT1("HalBeginSystemInterrupt was called with interrupt's enabled\n");
261  ASSERT(FALSE);
262  }
266  return(TRUE);
267 }
#define TRUE
Definition: types.h:120
VOID KeSetCurrentIrql(KIRQL NewIrql)
Definition: mpsirql.c:51
__inline VOID APICWrite(ULONG Offset, ULONG Value)
_Out_ PKIRQL Irql
Definition: csq.h:179
#define APIC_TPR
Definition: apic.h:12
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
void DPRINT(...)
Definition: polytest.cpp:61
#define APIC_TPR_PRI
Definition: apic.h:42
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define IRQL2TPR(irql)
Definition: mps.h:9
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126
KIRQL NTAPI KeGetCurrentIrql(VOID)
Definition: mpsirql.c:24

◆ HalClearSoftwareInterrupt()

VOID FASTCALL HalClearSoftwareInterrupt ( IN KIRQL  Request)

Definition at line 354 of file mpsirql.c.

356 {
358 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ HalDisableSystemInterrupt()

VOID NTAPI HalDisableSystemInterrupt ( ULONG  Vector,
KIRQL  Irql 
)

Definition at line 291 of file mpsirql.c.

293 {
294  ULONG irq;
295 
296  DPRINT ("Vector (0x%X)\n", Vector);
297 
298  if (Vector < FIRST_DEVICE_VECTOR ||
299  Vector >= FIRST_DEVICE_VECTOR + NUMBER_DEVICE_VECTORS)
300  {
301  DPRINT1("Not a device interrupt, vector=%x\n", Vector);
302  ASSERT(FALSE);
303  return;
304  }
305 
306  irq = VECTOR2IRQ (Vector);
307  IOAPICMaskIrq (irq);
308 
309  return;
310 }
VOID IOAPICMaskIrq(ULONG Irq)
Definition: ioapic.c:497
unsigned char irq
Definition: dsp.h:13
#define NUMBER_DEVICE_VECTORS
Definition: mps.h:37
#define VECTOR2IRQ(vector)
Definition: halirq.h:25
void DPRINT(...)
Definition: polytest.cpp:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1

◆ HalEnableSystemInterrupt()

BOOLEAN NTAPI HalEnableSystemInterrupt ( ULONG  Vector,
KIRQL  Irql,
KINTERRUPT_MODE  InterruptMode 
)

Definition at line 314 of file mpsirql.c.

317 {
318  ULONG irq;
319 
320  if (Vector < FIRST_DEVICE_VECTOR ||
321  Vector >= FIRST_DEVICE_VECTOR + NUMBER_DEVICE_VECTORS)
322  {
323  DPRINT("Not a device interrupt\n");
324  return FALSE;
325  }
326 
327  /* FIXME: We must check if the requested and the assigned interrupt mode is the same */
328 
329  irq = VECTOR2IRQ (Vector);
331 
332  return TRUE;
333 }
#define TRUE
Definition: types.h:120
unsigned char irq
Definition: dsp.h:13
#define NUMBER_DEVICE_VECTORS
Definition: mps.h:37
#define VECTOR2IRQ(vector)
Definition: halirq.h:25
void DPRINT(...)
Definition: polytest.cpp:61
VOID IOAPICUnmaskIrq(ULONG Irq)
Definition: ioapic.c:514
unsigned int ULONG
Definition: retypes.h:1

◆ HalEndSystemInterrupt()

VOID NTAPI HalEndSystemInterrupt ( KIRQL  Irql,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 271 of file mpsirql.c.

276 {
277  ULONG Flags;
278  Flags = __readeflags();
279 
281  {
282  DPRINT1("HalEndSystemInterrupt was called with interrupt's enabled\n");
283  ASSERT(FALSE);
284  }
285  APICSendEOI();
287 }
VOID HalpLowerIrql(KIRQL NewIrql, BOOLEAN FromHalEndSystemInterrupt)
Definition: mpsirql.c:72
__inline VOID APICSendEOI(VOID)
#define TRUE
Definition: types.h:120
_Out_ PKIRQL Irql
Definition: csq.h:179
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126

◆ HalpLowerIrql()

VOID HalpLowerIrql ( KIRQL  NewIrql,
BOOLEAN  FromHalEndSystemInterrupt 
)

Definition at line 72 of file mpsirql.c.

73 {
74  ULONG Flags;
75  UCHAR DpcRequested;
76  if (NewIrql >= DISPATCH_LEVEL)
77  {
80  return;
81  }
82  Flags = __readeflags();
84  {
87  DpcRequested = __readfsbyte(FIELD_OFFSET(KIPCR, HalReserved[HAL_DPC_REQUEST]));
88  if (FromHalEndSystemInterrupt || DpcRequested)
89  {
91  _enable();
94  {
95  _disable();
96  }
97  }
99  }
100  if (NewIrql == APC_LEVEL)
101  {
102  return;
103  }
104  if (KeGetCurrentThread () != NULL &&
105  KeGetCurrentThread ()->ApcState.KernelApcPending)
106  {
107  _enable();
109  if (!(Flags & EFLAGS_INTERRUPT_MASK))
110  {
111  _disable();
112  }
113  }
115 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
VOID KeSetCurrentIrql(KIRQL NewIrql)
Definition: mpsirql.c:51
__inline VOID APICWrite(ULONG Offset, ULONG Value)
#define APIC_TPR
Definition: apic.h:12
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
smooth NULL
Definition: ftsmooth.c:416
#define APIC_TPR_PRI
Definition: apic.h:42
PPC_QUAL unsigned char __readfsbyte(const unsigned long Offset)
Definition: intrin_ppc.h:360
PPC_QUAL void __writefsbyte(const unsigned long Offset, const unsigned char Data)
Definition: intrin_ppc.h:342
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID NTAPI KiDispatchInterrupt(VOID)
Definition: thrdini.c:295
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define IRQL2TPR(irql)
Definition: mps.h:9
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define HAL_DPC_REQUEST
Definition: halp.h:11
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1492
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
#define KeGetCurrentThread
Definition: hal.h:44
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
#define APC_LEVEL
Definition: env_spec_w32.h:695
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126
KIRQL NTAPI KeGetCurrentIrql(VOID)
Definition: mpsirql.c:24

Referenced by HalEndSystemInterrupt(), and KfLowerIrql().

◆ HalRequestSoftwareInterrupt()

VOID FASTCALL HalRequestSoftwareInterrupt ( IN KIRQL  Request)

Definition at line 336 of file mpsirql.c.

337 {
338  switch (Request)
339  {
340  case APC_LEVEL:
341  __writefsbyte(FIELD_OFFSET(KIPCR, HalReserved[HAL_APC_REQUEST]), 1);
342  break;
343 
344  case DISPATCH_LEVEL:
345  __writefsbyte(FIELD_OFFSET(KIPCR, HalReserved[HAL_DPC_REQUEST]), 1);
346  break;
347 
348  default:
349  ASSERT(FALSE);
350  }
351 }
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
#define HAL_APC_REQUEST
Definition: halp.h:10
PPC_QUAL void __writefsbyte(const unsigned long Offset, const unsigned char Data)
Definition: intrin_ppc.h:342
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define HAL_DPC_REQUEST
Definition: halp.h:11
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define APC_LEVEL
Definition: env_spec_w32.h:695

◆ KeGetCurrentIrql()

KIRQL NTAPI KeGetCurrentIrql ( VOID  )

Definition at line 24 of file mpsirql.c.

29 {
30  KIRQL irql;
31  ULONG Flags;
32 
33  Flags = __readeflags();
34  _disable();
35 
37  if (irql > HIGH_LEVEL)
38  {
39  DPRINT1 ("CurrentIrql %x\n", irql);
40  ASSERT(FALSE);
41  }
43  {
44  _enable();
45  }
46  return irql;
47 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
Definition: ke.h:280
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
PPC_QUAL unsigned char __readfsbyte(const unsigned long Offset)
Definition: intrin_ppc.h:360
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define DPRINT1
Definition: precomp.h:8
KIRQL irql
Definition: wave.h:1
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126

Referenced by HalBeginSystemInterrupt(), HalpLowerIrql(), KfLowerIrql(), and KfRaiseIrql().

◆ KeRaiseIrqlToDpcLevel()

KIRQL NTAPI KeRaiseIrqlToDpcLevel ( VOID  )

Definition at line 213 of file mpsirql.c.

214 {
215  return KfRaiseIrql (DISPATCH_LEVEL);
216 }
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
KIRQL FASTCALL KfRaiseIrql(KIRQL NewIrql)
Definition: mpsirql.c:165

◆ KeRaiseIrqlToSynchLevel()

KIRQL NTAPI KeRaiseIrqlToSynchLevel ( VOID  )

Definition at line 237 of file mpsirql.c.

238 {
239  return KfRaiseIrql (CLOCK2_LEVEL);
240 }
#define CLOCK2_LEVEL
Definition: env_spec_w32.h:700
KIRQL FASTCALL KfRaiseIrql(KIRQL NewIrql)
Definition: mpsirql.c:165

◆ KeSetCurrentIrql()

VOID KeSetCurrentIrql ( KIRQL  NewIrql)

Definition at line 51 of file mpsirql.c.

55 {
56  ULONG Flags;
57  if (NewIrql > HIGH_LEVEL)
58  {
59  DPRINT1 ("NewIrql %x\n", NewIrql);
60  ASSERT(FALSE);
61  }
62  Flags = __readeflags();
63  _disable();
66  {
67  _enable();
68  }
69 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
Definition: ke.h:280
_Out_ PKIRQL Irql
Definition: csq.h:179
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
PPC_QUAL void __writefsbyte(const unsigned long Offset, const unsigned char Data)
Definition: intrin_ppc.h:342
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define DPRINT1
Definition: precomp.h:8
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126

Referenced by HalBeginSystemInterrupt(), HalpLowerIrql(), KfRaiseIrql(), and KiInitializePcr().

◆ KfLowerIrql()

VOID FASTCALL KfLowerIrql ( KIRQL  NewIrql)

Definition at line 135 of file mpsirql.c.

136 {
137  KIRQL oldIrql = KeGetCurrentIrql();
138  if (NewIrql > oldIrql)
139  {
140  DPRINT1 ("NewIrql %x CurrentIrql %x\n", NewIrql, oldIrql);
141  ASSERT(FALSE);
142  }
144 }
VOID HalpLowerIrql(KIRQL NewIrql, BOOLEAN FromHalEndSystemInterrupt)
Definition: mpsirql.c:72
UCHAR KIRQL
Definition: env_spec_w32.h:591
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DPRINT1
Definition: precomp.h:8
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114
KIRQL NTAPI KeGetCurrentIrql(VOID)
Definition: mpsirql.c:24

Referenced by KeLowerIrql(), KeReleaseInStackQueuedSpinLock(), KeReleaseQueuedSpinLock(), and KfReleaseSpinLock().

◆ KfRaiseIrql()

KIRQL FASTCALL KfRaiseIrql ( KIRQL  NewIrql)

Definition at line 165 of file mpsirql.c.

166 {
167  KIRQL OldIrql;
168  ULONG Flags;
169 
170  Flags = __readeflags();
171  _disable();
172 
174 
175  if (NewIrql < OldIrql)
176  {
177  DPRINT1 ("CurrentIrql %x NewIrql %x\n", KeGetCurrentIrql (), NewIrql);
178  ASSERT(FALSE);
179  }
180 
181 
182  if (NewIrql > DISPATCH_LEVEL)
183  {
185  }
188  {
189  _enable();
190  }
191 
192  return OldIrql;
193 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
VOID KeSetCurrentIrql(KIRQL NewIrql)
Definition: mpsirql.c:51
__inline VOID APICWrite(ULONG Offset, ULONG Value)
#define APIC_TPR
Definition: apic.h:12
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
#define APIC_TPR_PRI
Definition: apic.h:42
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define IRQL2TPR(irql)
Definition: mps.h:9
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define DPRINT1
Definition: precomp.h:8
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126
KIRQL NTAPI KeGetCurrentIrql(VOID)
Definition: mpsirql.c:24

Referenced by KeAcquireInStackQueuedSpinLock(), KeAcquireInStackQueuedSpinLockRaiseToSynch(), KeAcquireQueuedSpinLock(), KeAcquireQueuedSpinLockRaiseToSynch(), KeAcquireSpinLockRaiseToSynch(), KeRaiseIrql(), KeRaiseIrqlToDpcLevel(), KeRaiseIrqlToSynchLevel(), KeTryToAcquireQueuedSpinLock(), KeTryToAcquireQueuedSpinLockRaiseToSynch(), and KfAcquireSpinLock().