ReactOS  0.4.15-dev-4874-g57c84dd
apic.c File Reference
#include <hal.h>
#include "apicp.h"
#include <debug.h>
Include dependency graph for apic.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define APIC_LAZY_IRQL
 
#define ApicRaiseIrql   ApicSetIrql
 

Functions

FORCEINLINE ULONG IOApicRead (UCHAR Register)
 
FORCEINLINE VOID IOApicWrite (UCHAR Register, ULONG Value)
 
FORCEINLINE VOID ApicWriteIORedirectionEntry (UCHAR Index, IOAPIC_REDIRECTION_REGISTER ReDirReg)
 
FORCEINLINE IOAPIC_REDIRECTION_REGISTER ApicReadIORedirectionEntry (UCHAR Index)
 
FORCEINLINE VOID ApicRequestSelfInterrupt (IN UCHAR Vector, UCHAR TriggerMode)
 
FORCEINLINE VOID ApicSendEOI (void)
 
FORCEINLINE KIRQL ApicGetProcessorIrql (VOID)
 
FORCEINLINE KIRQL ApicGetCurrentIrql (VOID)
 
FORCEINLINE VOID ApicSetIrql (KIRQL Irql)
 
FORCEINLINE VOID ApicLowerIrql (KIRQL Irql)
 
UCHAR FASTCALL HalpIrqToVector (UCHAR Irq)
 
KIRQL FASTCALL HalpVectorToIrql (UCHAR Vector)
 
UCHAR FASTCALL HalpVectorToIrq (UCHAR Vector)
 
VOID NTAPI HalpSendEOI (VOID)
 
VOID NTAPI ApicInitializeLocalApic (ULONG Cpu)
 
UCHAR NTAPI HalpAllocateSystemInterrupt (_In_ UCHAR Irq, _In_ UCHAR Vector)
 
ULONG NTAPI HalpGetRootInterruptVector (_In_ ULONG BusInterruptLevel, _In_ ULONG BusInterruptVector, _Out_ PKIRQL OutIrql, _Out_ PKAFFINITY OutAffinity)
 
VOID NTAPI ApicInitializeIOApic (VOID)
 
VOID NTAPI HalpInitializePICs (IN BOOLEAN EnableInterrupts)
 
VOID DECLSPEC_NORETURN FASTCALL HalpApcInterruptHandler (IN PKTRAP_FRAME TrapFrame)
 
VOID DECLSPEC_NORETURN FASTCALL HalpDispatchInterruptHandler (IN PKTRAP_FRAME TrapFrame)
 
VOID FASTCALL HalRequestSoftwareInterrupt (IN KIRQL Irql)
 
VOID FASTCALL HalClearSoftwareInterrupt (IN KIRQL Irql)
 
BOOLEAN NTAPI HalEnableSystemInterrupt (IN ULONG Vector, IN KIRQL Irql, IN KINTERRUPT_MODE InterruptMode)
 
VOID NTAPI HalDisableSystemInterrupt (IN ULONG Vector, IN KIRQL Irql)
 
BOOLEAN NTAPI HalBeginSystemInterrupt (IN KIRQL Irql, IN ULONG Vector, OUT PKIRQL OldIrql)
 
VOID NTAPI HalEndSystemInterrupt (IN KIRQL OldIrql, IN PKTRAP_FRAME TrapFrame)
 
KIRQL NTAPI KeGetCurrentIrql (VOID)
 
VOID FASTCALL KfLowerIrql (IN KIRQL OldIrql)
 
KIRQL FASTCALL KfRaiseIrql (IN KIRQL NewIrql)
 
KIRQL NTAPI KeRaiseIrqlToDpcLevel (VOID)
 
KIRQL NTAPI KeRaiseIrqlToSynchLevel (VOID)
 

Variables

ULONG ApicVersion
 
UCHAR HalpVectorToIndex [256]
 
const UCHAR HalpIRQLtoTPR [32]
 
const KIRQL HalVectorToIRQL [16]
 

Macro Definition Documentation

◆ APIC_LAZY_IRQL

#define APIC_LAZY_IRQL

Definition at line 22 of file apic.c.

◆ ApicRaiseIrql

#define ApicRaiseIrql   ApicSetIrql

Definition at line 232 of file apic.c.

◆ NDEBUG

#define NDEBUG

Definition at line 18 of file apic.c.

Function Documentation

◆ ApicGetCurrentIrql()

FORCEINLINE KIRQL ApicGetCurrentIrql ( VOID  )

Definition at line 206 of file apic.c.

207 {
208 #ifdef _M_AMD64
209  return (KIRQL)__readcr8();
210 #elif defined(APIC_LAZY_IRQL)
211  /* Return the field in the PCR */
213 #else
214  /* Read the TPR and convert it to an IRQL */
215  return TprToIrql(ApicRead(APIC_TPR));
216 #endif
217 }
FORCEINLINE ULONG ApicRead(APIC_REGISTER Register)
Definition: apicp.h:315
Definition: ke.h:289
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR KIRQL
Definition: env_spec_w32.h:591
PPC_QUAL unsigned char __readfsbyte(const unsigned long Offset)
Definition: intrin_ppc.h:360
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
Definition: apicp.h:81
#define TprToIrql(Tpr)
Definition: apicp.h:55

Referenced by HalBeginSystemInterrupt(), HalpApcInterruptHandler(), HalpDispatchInterruptHandler(), KeGetCurrentIrql(), KfLowerIrql(), and KfRaiseIrql().

◆ ApicGetProcessorIrql()

FORCEINLINE KIRQL ApicGetProcessorIrql ( VOID  )

Definition at line 198 of file apic.c.

199 {
200  /* Read the TPR and convert it to an IRQL */
201  return TprToIrql(ApicRead(APIC_PPR));
202 }
FORCEINLINE ULONG ApicRead(APIC_REGISTER Register)
Definition: apicp.h:315
Definition: apicp.h:83
#define TprToIrql(Tpr)
Definition: apicp.h:55

Referenced by HalpApcInterruptHandler(), and HalpDispatchInterruptHandler().

◆ ApicInitializeIOApic()

VOID NTAPI ApicInitializeIOApic ( VOID  )

Definition at line 459 of file apic.c.

460 {
461  PHARDWARE_PTE Pte;
463  UCHAR Index;
464  ULONG Vector;
465 
466  /* Map the I/O Apic page */
469  Pte->Valid = 1;
470  Pte->Write = 1;
471  Pte->Owner = 1;
472  Pte->CacheDisable = 1;
473  Pte->Global = 1;
475 
476  /* Setup a redirection entry */
477  ReDirReg.Vector = APIC_FREE_VECTOR;
478  ReDirReg.DeliveryMode = APIC_MT_Fixed;
480  ReDirReg.DeliveryStatus = 0;
481  ReDirReg.Polarity = 0;
482  ReDirReg.RemoteIRR = 0;
483  ReDirReg.TriggerMode = APIC_TGM_Edge;
484  ReDirReg.Mask = 1;
485  ReDirReg.Reserved = 0;
486  ReDirReg.Destination = 0;
487 
488  /* Loop all table entries */
489  for (Index = 0; Index < APIC_MAX_IRQ; Index++)
490  {
491  /* Initialize entry */
493  }
494 
495  /* Init the vactor to index table */
496  for (Vector = 0; Vector <= 255; Vector++)
497  {
499  }
500 
501  /* Enable the timer interrupt (but keep it masked) */
502  ReDirReg.Vector = APIC_CLOCK_VECTOR;
503  ReDirReg.DeliveryMode = APIC_MT_Fixed;
505  ReDirReg.TriggerMode = APIC_TGM_Edge;
506  ReDirReg.Mask = 1;
507  ReDirReg.Destination = ApicRead(APIC_ID);
509 }
ULONG64 Valid
Definition: mmtypes.h:66
#define _ReadWriteBarrier()
Definition: intrin_arm.h:36
ULONG64 Global
Definition: mmtypes.h:74
ULONG64 Owner
Definition: mmtypes.h:68
FORCEINLINE ULONG ApicRead(APIC_REGISTER Register)
Definition: apicp.h:315
ULONG64 CacheDisable
Definition: mmtypes.h:70
#define HalAddressToPte(x)
Definition: halp.h:163
FORCEINLINE VOID ApicWriteIORedirectionEntry(UCHAR Index, IOAPIC_REDIRECTION_REGISTER ReDirReg)
Definition: apic.c:114
Definition: apicp.h:79
#define APIC_CLOCK_VECTOR
Definition: apicp.h:44
UCHAR HalpVectorToIndex[256]
Definition: apic.c:28
#define APIC_FREE_VECTOR
Definition: apicp.h:59
_In_ WDFCOLLECTION _In_ ULONG Index
#define IOAPIC_PHYS_BASE
Definition: apicp.h:114
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG64 PageFrameNumber
Definition: mmtypes.h:78
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:800
ULONG64 Write
Definition: mmtypes.h:67
unsigned int ULONG
Definition: retypes.h:1
#define APIC_CLOCK_INDEX
Definition: apicp.h:115
#define IOAPIC_BASE
Definition: apicp.h:37
#define APIC_MAX_IRQ
Definition: apicp.h:58

Referenced by HalpInitializePICs().

◆ ApicInitializeLocalApic()

VOID NTAPI ApicInitializeLocalApic ( ULONG  Cpu)

Definition at line 291 of file apic.c.

292 {
293  APIC_BASE_ADRESS_REGISTER BaseRegister;
294  APIC_SPURIOUS_INERRUPT_REGISTER SpIntRegister;
295  LVT_REGISTER LvtEntry;
296 
297  /* Enable the APIC if it wasn't yet */
298  BaseRegister.LongLong = __readmsr(MSR_APIC_BASE);
299  BaseRegister.Enable = 1;
300  BaseRegister.BootStrapCPUCore = (Cpu == 0);
301  __writemsr(MSR_APIC_BASE, BaseRegister.LongLong);
302 
303  /* Set spurious vector and SoftwareEnable to 1 */
304  SpIntRegister.Long = ApicRead(APIC_SIVR);
305  SpIntRegister.Vector = APIC_SPURIOUS_VECTOR;
306  SpIntRegister.SoftwareEnable = 1;
307  SpIntRegister.FocusCPUCoreChecking = 0;
308  ApicWrite(APIC_SIVR, SpIntRegister.Long);
309 
310  /* Read the version and save it globally */
311  if (Cpu == 0) ApicVersion = ApicRead(APIC_VER);
312 
313  /* Set the mode to flat (max 8 CPUs supported!) */
315 
316  /* Set logical apic ID */
317  ApicWrite(APIC_LDR, ApicLogicalId(Cpu) << 24);
318 
319  /* Set the spurious ISR */
321 
322  /* Create a template LVT */
323  LvtEntry.Long = 0;
324  LvtEntry.Vector = APIC_FREE_VECTOR;
325  LvtEntry.MessageType = APIC_MT_Fixed;
326  LvtEntry.DeliveryStatus = 0;
327  LvtEntry.RemoteIRR = 0;
328  LvtEntry.TriggerMode = APIC_TGM_Edge;
329  LvtEntry.Mask = 1;
330  LvtEntry.TimerMode = 0;
331 
332  /* Initialize and mask LVTs */
333  ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
334  ApicWrite(APIC_THRMLVTR, LvtEntry.Long);
335  ApicWrite(APIC_PCLVTR, LvtEntry.Long);
336  ApicWrite(APIC_EXT0LVTR, LvtEntry.Long);
337  ApicWrite(APIC_EXT1LVTR, LvtEntry.Long);
338  ApicWrite(APIC_EXT2LVTR, LvtEntry.Long);
339  ApicWrite(APIC_EXT3LVTR, LvtEntry.Long);
340 
341  /* LINT0 */
342  LvtEntry.Vector = APIC_SPURIOUS_VECTOR;
343  LvtEntry.MessageType = APIC_MT_ExtInt;
344  ApicWrite(APIC_LINT0, LvtEntry.Long);
345 
346  /* Enable LINT1 (NMI) */
347  LvtEntry.Mask = 0;
348  LvtEntry.Vector = APIC_NMI_VECTOR;
349  LvtEntry.MessageType = APIC_MT_NMI;
350  LvtEntry.TriggerMode = APIC_TGM_Level;
351  ApicWrite(APIC_LINT1, LvtEntry.Long);
352 
353  /* Enable error LVTR */
354  LvtEntry.Vector = APIC_ERROR_VECTOR;
355  LvtEntry.MessageType = APIC_MT_Fixed;
356  ApicWrite(APIC_ERRLVTR, LvtEntry.Long);
357 
358  /* Set the IRQL from the PCR */
360 #ifdef APIC_LAZY_IRQL
361  /* Save the new hard IRQL in the IRR field */
362  KeGetPcr()->IRR = KeGetPcr()->Irql;
363 #endif
364 }
Definition: apicp.h:80
Definition: apicp.h:87
FORCEINLINE ULONG ApicRead(APIC_REGISTER Register)
Definition: apicp.h:315
UINT32 Vector
Definition: apicp.h:266
UINT32 DeliveryStatus
Definition: apicp.h:269
#define APIC_NMI_VECTOR
Definition: apicp.h:51
ULONG ApicVersion
Definition: apic.c:27
_Out_ PKIRQL Irql
Definition: csq.h:179
#define APIC_SPURIOUS_VECTOR
Definition: apicp.h:40
#define KeGetPcr()
Definition: ke.h:26
#define ApicLogicalId(Cpu)
Definition: apicp.h:116
UINT32 Long
Definition: apicp.h:263
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:322
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
UINT32 TimerMode
Definition: apicp.h:274
UINT32 Mask
Definition: apicp.h:273
#define MSR_APIC_BASE
Definition: apicp.h:113
UINT32 RemoteIRR
Definition: apicp.h:271
#define APIC_FREE_VECTOR
Definition: apicp.h:59
UINT32 MessageType
Definition: apicp.h:267
#define APIC_ERROR_VECTOR
Definition: apicp.h:47
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:297
Definition: apicp.h:86
FORCEINLINE VOID ApicSetIrql(KIRQL Irql)
Definition: apic.c:221
VOID __cdecl ApicSpuriousService(VOID)
UINT32 TriggerMode
Definition: apicp.h:272

Referenced by HalpInitProcessor().

◆ ApicLowerIrql()

FORCEINLINE VOID ApicLowerIrql ( KIRQL  Irql)

Definition at line 237 of file apic.c.

238 {
240 
241  /* Is the new Irql lower than set in the TPR? */
242  if (Irql < KeGetPcr()->IRR)
243  {
244  /* Save the new hard IRQL in the IRR field */
245  KeGetPcr()->IRR = Irql;
246 
247  /* Need to lower it back */
249  }
250 }
Definition: ke.h:289
_Out_ PKIRQL Irql
Definition: csq.h:179
#define KeGetPcr()
Definition: ke.h:26
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:322
PPC_QUAL void __writefsbyte(const unsigned long Offset, const unsigned char Data)
Definition: intrin_ppc.h:342
#define IrqlToTpr(Irql)
Definition: apicp.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
Definition: apicp.h:81

Referenced by HalEndSystemInterrupt(), HalpApcInterruptHandler(), HalpDispatchInterruptHandler(), and KfLowerIrql().

◆ ApicReadIORedirectionEntry()

FORCEINLINE IOAPIC_REDIRECTION_REGISTER ApicReadIORedirectionEntry ( UCHAR  Index)

Definition at line 125 of file apic.c.

127 {
129 
131  ReDirReg.Long0 = IOApicRead(IOAPIC_REDTBL + 2 * Index);
132  ReDirReg.Long1 = IOApicRead(IOAPIC_REDTBL + 2 * Index + 1);
133 
134  return ReDirReg;
135 }
#define IOAPIC_REDTBL
Definition: apicp.h:287
#define ASSERT(a)
Definition: mode.c:44
_In_ WDFCOLLECTION _In_ ULONG Index
FORCEINLINE ULONG IOApicRead(UCHAR Register)
Definition: apic.c:94
#define APIC_MAX_IRQ
Definition: apicp.h:58

Referenced by HalBeginSystemInterrupt(), and HalEnableSystemInterrupt().

◆ ApicRequestSelfInterrupt()

FORCEINLINE VOID ApicRequestSelfInterrupt ( IN UCHAR  Vector,
UCHAR  TriggerMode 
)

Definition at line 139 of file apic.c.

140 {
141  ULONG Flags;
144 
145  /*
146  * The IRR registers are spaced 16 bytes apart and hold 32 status bits each.
147  * Pre-compute the register and bit that match our vector.
148  */
149  ULONG VectorHigh = Vector / 32;
150  ULONG VectorLow = Vector % 32;
151  ULONG Irr = APIC_IRR + 0x10 * VectorHigh;
152  ULONG IrrBit = 1UL << VectorLow;
153 
154  /* Setup the command register */
155  Icr.Long0 = 0;
156  Icr.Vector = Vector;
158  Icr.TriggerMode = TriggerMode;
160 
161  /* Disable interrupts so that we can change IRR without being interrupted */
162  Flags = __readeflags();
163  _disable();
164 
165  /* Wait for the APIC to be idle */
166  do
167  {
168  IcrStatus.Long0 = ApicRead(APIC_ICR0);
169  } while (IcrStatus.DeliveryStatus);
170 
171  /* Write the low dword to send the interrupt */
172  ApicWrite(APIC_ICR0, Icr.Long0);
173 
174  /* Wait until we see the interrupt request.
175  * It will stay in requested state until we re-enable interrupts.
176  */
177  while (!(ApicRead(Irr) & IrrBit))
178  {
179  NOTHING;
180  }
181 
182  /* Finally, restore the original interrupt state */
184  {
185  _enable();
186  }
187 }
FORCEINLINE ULONG ApicRead(APIC_REGISTER Register)
Definition: apicp.h:315
void __cdecl _enable(void)
Definition: intrin_arm.h:373
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1666
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:322
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define NOTHING
Definition: env_spec_w32.h:461
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:800
Definition: apicp.h:91
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
#define UL
Definition: tui.h:148
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126

Referenced by HalBeginSystemInterrupt(), and HalRequestSoftwareInterrupt().

◆ ApicSendEOI()

FORCEINLINE VOID ApicSendEOI ( void  )

Definition at line 191 of file apic.c.

192 {
193  ApicWrite(APIC_EOI, 0);
194 }
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:322
Definition: apicp.h:84

Referenced by HalBeginSystemInterrupt(), HalEndSystemInterrupt(), HalpApcInterruptHandler(), HalpDispatchInterruptHandler(), and HalpSendEOI().

◆ ApicSetIrql()

FORCEINLINE VOID ApicSetIrql ( KIRQL  Irql)

Definition at line 221 of file apic.c.

222 {
223 #ifdef _M_AMD64
224  __writecr8(Irql);
225 #elif defined(APIC_LAZY_IRQL)
227 #else
228  /* Convert IRQL and write the TPR */
230 #endif
231 }
Definition: ke.h:289
_Out_ PKIRQL Irql
Definition: csq.h:179
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:322
PPC_QUAL void __writefsbyte(const unsigned long Offset, const unsigned char Data)
Definition: intrin_ppc.h:342
#define IrqlToTpr(Irql)
Definition: apicp.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
Definition: apicp.h:81

Referenced by ApicInitializeLocalApic().

◆ ApicWriteIORedirectionEntry()

FORCEINLINE VOID ApicWriteIORedirectionEntry ( UCHAR  Index,
IOAPIC_REDIRECTION_REGISTER  ReDirReg 
)

Definition at line 114 of file apic.c.

117 {
119  IOApicWrite(IOAPIC_REDTBL + 2 * Index, ReDirReg.Long0);
120  IOApicWrite(IOAPIC_REDTBL + 2 * Index + 1, ReDirReg.Long1);
121 }
#define IOAPIC_REDTBL
Definition: apicp.h:287
FORCEINLINE VOID IOApicWrite(UCHAR Register, ULONG Value)
Definition: apic.c:104
#define ASSERT(a)
Definition: mode.c:44
_In_ WDFCOLLECTION _In_ ULONG Index
#define APIC_MAX_IRQ
Definition: apicp.h:58

Referenced by ApicInitializeIOApic(), HalEnableSystemInterrupt(), and HalpAllocateSystemInterrupt().

◆ HalBeginSystemInterrupt()

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

Definition at line 747 of file apic.c.

751 {
752  KIRQL CurrentIrql;
753 
754  /* Get the current IRQL */
755  CurrentIrql = ApicGetCurrentIrql();
756 
757 #ifdef APIC_LAZY_IRQL
758  /* Check if this interrupt is allowed */
759  if (CurrentIrql >= Irql)
760  {
762  UCHAR Index;
763 
764  /* It is not, set the real Irql in the TPR! */
765  ApicWrite(APIC_TPR, IrqlToTpr(CurrentIrql));
766 
767  /* Save the new hard IRQL in the IRR field */
768  KeGetPcr()->IRR = CurrentIrql;
769 
770  /* End this interrupt */
771  ApicSendEOI();
772 
773  /* Get the irq for this vector */
775 
776  /* Check if it's valid */
777  if (Index < APIC_MAX_IRQ)
778  {
779  /* Read the I/O redirection entry */
780  RedirReg = ApicReadIORedirectionEntry(Index);
781 
782  /* Re-request the interrupt to be handled later */
784  }
785  else
786  {
787  /* This should be a reserved vector! */
789 
790  /* Re-request the interrupt to be handled later */
792  }
793 
794  /* Pretend it was a spurious interrupt */
795  return FALSE;
796  }
797 #endif
798  /* Save the current IRQL */
799  *OldIrql = CurrentIrql;
800 
801  /* Set the new IRQL */
803 
804  /* Turn on interrupts */
805  _enable();
806 
807  /* Success */
808  return TRUE;
809 }
FORCEINLINE VOID ApicRequestSelfInterrupt(IN UCHAR Vector, UCHAR TriggerMode)
Definition: apic.c:139
#define TRUE
Definition: types.h:120
void __cdecl _enable(void)
Definition: intrin_arm.h:373
FORCEINLINE IOAPIC_REDIRECTION_REGISTER ApicReadIORedirectionEntry(UCHAR Index)
Definition: apic.c:125
_Out_ PKIRQL Irql
Definition: csq.h:179
#define KeGetPcr()
Definition: ke.h:26
FORCEINLINE KIRQL ApicGetCurrentIrql(VOID)
Definition: apic.c:206
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:322
#define ApicRaiseIrql
Definition: apic.c:232
UCHAR HalpVectorToIndex[256]
Definition: apic.c:28
#define ASSERT(a)
Definition: mode.c:44
#define APIC_RESERVED_VECTOR
Definition: apicp.h:60
_In_ WDFCOLLECTION _In_ ULONG Index
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IrqlToTpr(Irql)
Definition: apicp.h:53
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:800
FORCEINLINE VOID ApicSendEOI(void)
Definition: apic.c:191
#define APIC_MAX_IRQ
Definition: apicp.h:58
Definition: apicp.h:81

Referenced by HalpApcInterruptHandler(), HalpDispatchInterruptHandler(), and MpsTimerHandler().

◆ HalClearSoftwareInterrupt()

VOID FASTCALL HalClearSoftwareInterrupt ( IN KIRQL  Irql)

Definition at line 658 of file apic.c.

660 {
661  /* Nothing to do */
662 }

◆ HalDisableSystemInterrupt()

VOID NTAPI HalDisableSystemInterrupt ( IN ULONG  Vector,
IN KIRQL  Irql 
)

Definition at line 723 of file apic.c.

726 {
728  UCHAR Index;
729  ASSERT(Irql <= HIGH_LEVEL);
731 
733 
734  /* Read lower dword of redirection entry */
735  ReDirReg.Long0 = IOApicRead(IOAPIC_REDTBL + 2 * Index);
736 
737  /* Mask it */
738  ReDirReg.Mask = 1;
739 
740  /* Write back lower dword */
741  IOApicWrite(IOAPIC_REDTBL + 2 * Index, ReDirReg.Long0);
742 }
_Out_ PKIRQL Irql
Definition: csq.h:179
#define IOAPIC_REDTBL
Definition: apicp.h:287
FORCEINLINE VOID IOApicWrite(UCHAR Register, ULONG Value)
Definition: apic.c:104
UCHAR HalpVectorToIndex[256]
Definition: apic.c:28
#define ASSERT(a)
Definition: mode.c:44
_In_ WDFCOLLECTION _In_ ULONG Index
unsigned char UCHAR
Definition: xmlstorage.h:181
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:800
FORCEINLINE ULONG IOApicRead(UCHAR Register)
Definition: apic.c:94

◆ HalEnableSystemInterrupt()

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

Definition at line 669 of file apic.c.

673 {
675  PKPRCB Prcb = KeGetCurrentPrcb();
676  UCHAR Index;
677  ASSERT(Irql <= HIGH_LEVEL);
678  ASSERT((IrqlToTpr(Irql) & 0xF0) == (Vector & 0xF0));
679 
680  /* Get the irq for this vector */
682 
683  /* Check if its valid */
684  if (Index == APIC_FREE_VECTOR)
685  {
686  /* Interrupt is not in use */
687  return FALSE;
688  }
689 
690  /* Read the redirection entry */
691  ReDirReg = ApicReadIORedirectionEntry(Index);
692 
693  /* Check if the interrupt was unused */
694  if (ReDirReg.Vector != Vector)
695  {
696  ReDirReg.Vector = Vector;
698  ReDirReg.DestinationMode = APIC_DM_Logical;
699  ReDirReg.Destination = 0;
700  }
701 
702  /* Check if the destination is logical */
703  if (ReDirReg.DestinationMode == APIC_DM_Logical)
704  {
705  /* Set the bit for this cpu */
706  ReDirReg.Destination |= ApicLogicalId(Prcb->Number);
707  }
708 
709  /* Set the trigger mode */
710  ReDirReg.TriggerMode = 1 - InterruptMode;
711 
712  /* Now unmask it */
713  ReDirReg.Mask = FALSE;
714 
715  /* Write back the entry */
717 
718  return TRUE;
719 }
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG _In_ KIRQL _In_ KIRQL _In_ KINTERRUPT_MODE InterruptMode
Definition: iofuncs.h:800
#define TRUE
Definition: types.h:120
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1080
FORCEINLINE IOAPIC_REDIRECTION_REGISTER ApicReadIORedirectionEntry(UCHAR Index)
Definition: apic.c:125
_Out_ PKIRQL Irql
Definition: csq.h:179
#define ApicLogicalId(Cpu)
Definition: apicp.h:116
FORCEINLINE VOID ApicWriteIORedirectionEntry(UCHAR Index, IOAPIC_REDIRECTION_REGISTER ReDirReg)
Definition: apic.c:114
#define FALSE
Definition: types.h:117
UCHAR HalpVectorToIndex[256]
Definition: apic.c:28
#define ASSERT(a)
Definition: mode.c:44
#define APIC_FREE_VECTOR
Definition: apicp.h:59
_In_ WDFCOLLECTION _In_ ULONG Index
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IrqlToTpr(Irql)
Definition: apicp.h:53
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:800
USHORT Number
Definition: ketypes.h:564

◆ HalEndSystemInterrupt()

VOID NTAPI HalEndSystemInterrupt ( IN KIRQL  OldIrql,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 813 of file apic.c.

816 {
817  /* Send an EOI */
818  ApicSendEOI();
819 
820  /* Restore the old IRQL */
822 }
FORCEINLINE VOID ApicLowerIrql(KIRQL Irql)
Definition: apic.c:237
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
FORCEINLINE VOID ApicSendEOI(void)
Definition: apic.c:191

Referenced by MpsTimerHandler().

◆ HalpAllocateSystemInterrupt()

UCHAR NTAPI HalpAllocateSystemInterrupt ( _In_ UCHAR  Irq,
_In_ UCHAR  Vector 
)

Definition at line 368 of file apic.c.

371 {
373 
374  ASSERT(Irq < APIC_MAX_IRQ);
376 
377  /* Setup a redirection entry */
378  ReDirReg.Vector = Vector;
380  ReDirReg.DestinationMode = APIC_DM_Logical;
381  ReDirReg.DeliveryStatus = 0;
382  ReDirReg.Polarity = 0;
383  ReDirReg.RemoteIRR = 0;
384  ReDirReg.TriggerMode = APIC_TGM_Edge;
385  ReDirReg.Mask = 1;
386  ReDirReg.Reserved = 0;
387  ReDirReg.Destination = 0;
388 
389  /* Initialize entry */
390  ApicWriteIORedirectionEntry(Irq, ReDirReg);
391 
392  /* Save irq in the table */
393  HalpVectorToIndex[Vector] = Irq;
394 
395  return Vector;
396 }
FORCEINLINE VOID ApicWriteIORedirectionEntry(UCHAR Index, IOAPIC_REDIRECTION_REGISTER ReDirReg)
Definition: apic.c:114
UCHAR HalpVectorToIndex[256]
Definition: apic.c:28
#define ASSERT(a)
Definition: mode.c:44
#define APIC_FREE_VECTOR
Definition: apicp.h:59
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:800
#define APIC_MAX_IRQ
Definition: apicp.h:58

Referenced by HalpGetRootInterruptVector().

◆ HalpApcInterruptHandler()

VOID DECLSPEC_NORETURN FASTCALL HalpApcInterruptHandler ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 556 of file apic.c.

557 {
558  KPROCESSOR_MODE ProcessorMode;
559  KIRQL OldIrql;
561 
562  /* Enter trap */
563  KiEnterInterruptTrap(TrapFrame);
564 
565 #ifdef APIC_LAZY_IRQL
567  {
568  /* "Spurious" interrupt, exit the interrupt */
569  KiEoiHelper(TrapFrame);
570  }
571 #else
572  /* Save the old IRQL */
575 #endif
576 
577  /* Raise to APC_LEVEL */
579 
580  /* End the interrupt */
581  ApicSendEOI();
582 
583  /* Kernel or user APC? */
584  if (KiUserTrap(TrapFrame)) ProcessorMode = UserMode;
585  else if (TrapFrame->EFlags & EFLAGS_V86_MASK) ProcessorMode = UserMode;
586  else ProcessorMode = KernelMode;
587 
588  /* Enable interrupts and call the kernel's APC interrupt handler */
589  _enable();
590  KiDeliverApc(ProcessorMode, NULL, TrapFrame);
591 
592  /* Disable interrupts */
593  _disable();
594 
595  /* Restore the old IRQL */
597 
598  /* Exit the interrupt */
599  KiEoiHelper(TrapFrame);
600 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
FORCEINLINE KIRQL ApicGetProcessorIrql(VOID)
Definition: apic.c:198
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
#define EFLAGS_V86_MASK
Definition: ketypes.h:132
FORCEINLINE KIRQL ApicGetCurrentIrql(VOID)
Definition: apic.c:206
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define ApicRaiseIrql
Definition: apic.c:232
#define APC_VECTOR
Definition: apicp.h:41
#define ASSERT(a)
Definition: mode.c:44
FORCEINLINE VOID ApicLowerIrql(KIRQL Irql)
Definition: apic.c:237
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:360
FORCEINLINE VOID KiEnterInterruptTrap(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:368
#define NULL
Definition: types.h:112
void __cdecl _disable(void)
Definition: intrin_arm.h:365
FORCEINLINE VOID ApicSendEOI(void)
Definition: apic.c:191
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
BOOLEAN NTAPI HalBeginSystemInterrupt(IN KIRQL Irql, IN ULONG Vector, OUT PKIRQL OldIrql)
Definition: apic.c:747

◆ HalpDispatchInterruptHandler()

VOID DECLSPEC_NORETURN FASTCALL HalpDispatchInterruptHandler ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 605 of file apic.c.

606 {
607  KIRQL OldIrql;
609 
610  /* Enter trap */
611  KiEnterInterruptTrap(TrapFrame);
612 
613 #ifdef APIC_LAZY_IRQL
615  {
616  /* "Spurious" interrupt, exit the interrupt */
617  KiEoiHelper(TrapFrame);
618  }
619 #else
620  /* Get the current IRQL */
623 #endif
624 
625  /* Raise to DISPATCH_LEVEL */
627 
628  /* End the interrupt */
629  ApicSendEOI();
630 
631  /* Enable interrupts and call the kernel's DPC interrupt handler */
632  _enable();
634  _disable();
635 
636  /* Restore the old IRQL */
638 
639  /* Exit the interrupt */
640  KiEoiHelper(TrapFrame);
641 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
FORCEINLINE KIRQL ApicGetProcessorIrql(VOID)
Definition: apic.c:198
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
FORCEINLINE KIRQL ApicGetCurrentIrql(VOID)
Definition: apic.c:206
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define ApicRaiseIrql
Definition: apic.c:232
#define ASSERT(a)
Definition: mode.c:44
FORCEINLINE VOID ApicLowerIrql(KIRQL Irql)
Definition: apic.c:237
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
VOID NTAPI KiDispatchInterrupt(VOID)
Definition: thrdini.c:295
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE VOID KiEnterInterruptTrap(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:368
void __cdecl _disable(void)
Definition: intrin_arm.h:365
FORCEINLINE VOID ApicSendEOI(void)
Definition: apic.c:191
#define DISPATCH_VECTOR
Definition: apicp.h:42
BOOLEAN NTAPI HalBeginSystemInterrupt(IN KIRQL Irql, IN ULONG Vector, OUT PKIRQL OldIrql)
Definition: apic.c:747

◆ HalpGetRootInterruptVector()

ULONG NTAPI HalpGetRootInterruptVector ( _In_ ULONG  BusInterruptLevel,
_In_ ULONG  BusInterruptVector,
_Out_ PKIRQL  OutIrql,
_Out_ PKAFFINITY  OutAffinity 
)

Definition at line 400 of file apic.c.

405 {
406  UCHAR Vector;
407  KIRQL Irql;
408 
409  /* Get the vector currently registered */
411 
412  /* Check if it's used */
413  if (Vector != APIC_FREE_VECTOR)
414  {
415  /* Calculate IRQL */
417  *OutIrql = HalpVectorToIrql(Vector);
418  }
419  else
420  {
421  ULONG Offset;
422 
423  /* Outer loop to find alternative slots, when all IRQLs are in use */
424  for (Offset = 0; Offset < 15; Offset++)
425  {
426  /* Loop allowed IRQL range */
427  for (Irql = CLOCK_LEVEL - 1; Irql >= CMCI_LEVEL; Irql--)
428  {
429  /* Calculate the vactor */
431 
432  /* Check if the vector is free */
434  {
435  /* Found one, allocate the interrupt */
437  *OutIrql = Irql;
438  goto Exit;
439  }
440  }
441  }
442 
443  DPRINT1("Failed to get an interrupt vector for IRQ %lu\n", BusInterruptLevel);
444  *OutAffinity = 0;
445  *OutIrql = 0;
446  return 0;
447  }
448 
449 Exit:
450 
451  *OutAffinity = HalpDefaultInterruptAffinity;
453 
454  return Vector;
455 }
UCHAR FASTCALL HalpVectorToIrq(UCHAR Vector)
Definition: apic.c:277
_In_ ULONG _In_ ULONG BusInterruptLevel
Definition: halfuncs.h:170
KAFFINITY HalpDefaultInterruptAffinity
Definition: processor.c:18
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR KIRQL
Definition: env_spec_w32.h:591
UCHAR FASTCALL HalpIrqToVector(UCHAR Irq)
Definition: apic.c:257
KIRQL FASTCALL HalpVectorToIrql(UCHAR Vector)
Definition: apic.c:270
UCHAR NTAPI HalpAllocateSystemInterrupt(_In_ UCHAR Irq, _In_ UCHAR Vector)
Definition: apic.c:368
UCHAR HalpVectorToIndex[256]
Definition: apic.c:28
#define ASSERT(a)
Definition: mode.c:44
#define APIC_FREE_VECTOR
Definition: apicp.h:59
static void Exit(void)
Definition: sock.c:1331
#define CLOCK_LEVEL
Definition: ketypes.h:16
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IrqlToTpr(Irql)
Definition: apicp.h:53
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define CMCI_LEVEL
Definition: ketypes.h:15
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:800
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by HalGetInterruptVector(), and HalpGetSystemInterruptVector().

◆ HalpInitializePICs()

VOID NTAPI HalpInitializePICs ( IN BOOLEAN  EnableInterrupts)

Definition at line 513 of file apic.c.

514 {
515  ULONG_PTR EFlags;
516 
517  /* Save EFlags and disable interrupts */
518  EFlags = __readeflags();
519  _disable();
520 
521  /* Initialize and mask the PIC */
523 
524  /* Initialize the I/O APIC */
526 
527  /* Manually reserve some vectors */
532 
533  /* Set interrupt handlers in the IDT */
535 #ifndef _M_AMD64
538 #endif
539 
540  /* Register the vectors for APC and dispatch interrupts */
543 
544  /* Restore interrupt state */
546  __writeeflags(EFlags);
547 }
static NTSTATUS EnableInterrupts(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR FlagsToDisable, IN UCHAR FlagsToEnable)
Definition: pnp.c:380
VOID NTAPI HalpRegisterVector(IN UCHAR Flags, IN ULONG BusVector, IN ULONG SystemVector, IN KIRQL Irql)
Definition: usage.c:34
#define APIC_SPURIOUS_VECTOR
Definition: apicp.h:40
uint32_t ULONG_PTR
Definition: typedefs.h:65
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1666
VOID __cdecl HalpDispatchInterrupt(VOID)
VOID NTAPI ApicInitializeIOApic(VOID)
Definition: apic.c:459
#define APIC_CLOCK_VECTOR
Definition: apicp.h:44
UCHAR HalpVectorToIndex[256]
Definition: apic.c:28
#define APC_VECTOR
Definition: apicp.h:41
#define APIC_RESERVED_VECTOR
Definition: apicp.h:60
#define IDT_INTERNAL
Definition: halp.h:21
VOID __cdecl HalpApcInterrupt(VOID)
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1661
VOID HalpClockInterrupt(VOID)
Definition: timer.c:30
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:297
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
void __cdecl _disable(void)
Definition: intrin_arm.h:365
#define DISPATCH_VECTOR
Definition: apicp.h:42
#define APC_LEVEL
Definition: env_spec_w32.h:695
VOID NTAPI HalpInitializeLegacyPICs(VOID)
Definition: pic.c:18
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126

◆ HalpIrqToVector()

UCHAR FASTCALL HalpIrqToVector ( UCHAR  Irq)

Definition at line 257 of file apic.c.

258 {
260 
261  /* Read low dword of the redirection entry */
262  ReDirReg.Long0 = IOApicRead(IOAPIC_REDTBL + 2 * Irq);
263 
264  /* Return the vector */
265  return (UCHAR)ReDirReg.Vector;
266 }
#define IOAPIC_REDTBL
Definition: apicp.h:287
unsigned char UCHAR
Definition: xmlstorage.h:181
FORCEINLINE ULONG IOApicRead(UCHAR Register)
Definition: apic.c:94

Referenced by HalpGetRootInterruptVector().

◆ HalpSendEOI()

VOID NTAPI HalpSendEOI ( VOID  )

Definition at line 284 of file apic.c.

285 {
286  ApicSendEOI();
287 }
FORCEINLINE VOID ApicSendEOI(void)
Definition: apic.c:191

◆ HalpVectorToIrq()

UCHAR FASTCALL HalpVectorToIrq ( UCHAR  Vector)

Definition at line 277 of file apic.c.

278 {
279  return HalpVectorToIndex[Vector];
280 }
UCHAR HalpVectorToIndex[256]
Definition: apic.c:28
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:800

Referenced by HalpGetRootInterruptVector().

◆ HalpVectorToIrql()

KIRQL FASTCALL HalpVectorToIrql ( UCHAR  Vector)

Definition at line 270 of file apic.c.

271 {
272  return TprToIrql(Vector);
273 }
#define TprToIrql(Tpr)
Definition: apicp.h:55

Referenced by HalpGetRootInterruptVector().

◆ HalRequestSoftwareInterrupt()

VOID FASTCALL HalRequestSoftwareInterrupt ( IN KIRQL  Irql)

Definition at line 650 of file apic.c.

651 {
652  /* Convert irql to vector and request an interrupt */
654 }
FORCEINLINE VOID ApicRequestSelfInterrupt(IN UCHAR Vector, UCHAR TriggerMode)
Definition: apic.c:139
_Out_ PKIRQL Irql
Definition: csq.h:179
#define IrqlToSoftVector(Irql)
Definition: apicp.h:54

◆ IOApicRead()

FORCEINLINE ULONG IOApicRead ( UCHAR  Register)

Definition at line 94 of file apic.c.

95 {
96  /* Select the register, then do the read */
97  ASSERT(Register <= 0x3F);
100 }
NTKERNELAPI VOID NTAPI WRITE_REGISTER_ULONG(IN PULONG Register, IN ULONG Value)
#define IOAPIC_IOWIN
Definition: apicp.h:281
NTKERNELAPI ULONG NTAPI READ_REGISTER_ULONG(IN PULONG Register)
#define IOAPIC_IOREGSEL
Definition: apicp.h:280
#define ASSERT(a)
Definition: mode.c:44
unsigned int * PULONG
Definition: retypes.h:1
#define IOAPIC_BASE
Definition: apicp.h:37

Referenced by ApicReadIORedirectionEntry(), HalDisableSystemInterrupt(), and HalpIrqToVector().

◆ IOApicWrite()

FORCEINLINE VOID IOApicWrite ( UCHAR  Register,
ULONG  Value 
)

Definition at line 104 of file apic.c.

105 {
106  /* Select the register, then do the write */
107  ASSERT(Register <= 0x3F);
110 }
NTKERNELAPI VOID NTAPI WRITE_REGISTER_ULONG(IN PULONG Register, IN ULONG Value)
#define IOAPIC_IOWIN
Definition: apicp.h:281
#define IOAPIC_IOREGSEL
Definition: apicp.h:280
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
#define ASSERT(a)
Definition: mode.c:44
unsigned int * PULONG
Definition: retypes.h:1
#define IOAPIC_BASE
Definition: apicp.h:37

Referenced by ApicWriteIORedirectionEntry(), and HalDisableSystemInterrupt().

◆ KeGetCurrentIrql()

KIRQL NTAPI KeGetCurrentIrql ( VOID  )

Definition at line 829 of file apic.c.

830 {
831  /* Read the current TPR and convert it to an IRQL */
832  return ApicGetCurrentIrql();
833 }
FORCEINLINE KIRQL ApicGetCurrentIrql(VOID)
Definition: apic.c:206

◆ KeRaiseIrqlToDpcLevel()

KIRQL NTAPI KeRaiseIrqlToDpcLevel ( VOID  )

Definition at line 878 of file apic.c.

879 {
880  return KfRaiseIrql(DISPATCH_LEVEL);
881 }
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: apic.c:854

◆ KeRaiseIrqlToSynchLevel()

KIRQL NTAPI KeRaiseIrqlToSynchLevel ( VOID  )

Definition at line 885 of file apic.c.

886 {
887  return KfRaiseIrql(SYNCH_LEVEL);
888 }
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: apic.c:854

◆ KfLowerIrql()

VOID FASTCALL KfLowerIrql ( IN KIRQL  OldIrql)

Definition at line 837 of file apic.c.

839 {
840 #if DBG
841  /* Validate correct lower */
842  if (OldIrql > ApicGetCurrentIrql())
843  {
844  /* Crash system */
845  KeBugCheck(IRQL_NOT_LESS_OR_EQUAL);
846  }
847 #endif
848  /* Set the new IRQL */
850 }
FORCEINLINE KIRQL ApicGetCurrentIrql(VOID)
Definition: apic.c:206
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
FORCEINLINE VOID ApicLowerIrql(KIRQL Irql)
Definition: apic.c:237
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792

◆ KfRaiseIrql()

KIRQL FASTCALL KfRaiseIrql ( IN KIRQL  NewIrql)

Definition at line 854 of file apic.c.

856 {
857  KIRQL OldIrql;
858 
859  /* Read the current IRQL */
861 #if DBG
862  /* Validate correct raise */
863  if (OldIrql > NewIrql)
864  {
865  /* Crash system */
866  KeBugCheck(IRQL_NOT_GREATER_OR_EQUAL);
867  }
868 #endif
869  /* Convert the new IRQL to a TPR value and write the register */
871 
872  /* Return old IRQL */
873  return OldIrql;
874 }
FORCEINLINE KIRQL ApicGetCurrentIrql(VOID)
Definition: apic.c:206
UCHAR KIRQL
Definition: env_spec_w32.h:591
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
#define ApicRaiseIrql
Definition: apic.c:232
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114

Referenced by KeRaiseIrqlToDpcLevel(), and KeRaiseIrqlToSynchLevel().

Variable Documentation

◆ ApicVersion

ULONG ApicVersion

Definition at line 27 of file apic.c.

Referenced by ApicInitializeLocalApic().

◆ HalpIRQLtoTPR

const UCHAR HalpIRQLtoTPR[32]

Definition at line 32 of file apic.c.

◆ HalpVectorToIndex

◆ HalVectorToIRQL

const KIRQL HalVectorToIRQL[16]
Initial value:
=
{
0,
0xff,
0xff,
1,
2,
4,
5,
6,
7,
8,
9,
10,
27,
28,
29,
31,
}

Definition at line 69 of file apic.c.