ReactOS 0.4.15-dev-7931-gfd331f1
apicsmp.c File Reference
#include <hal.h>
#include "apicp.h"
#include <smp.h>
#include <debug.h>
Include dependency graph for apicsmp.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

FORCEINLINE VOID ApicRequestGlobalInterrupt (_In_ UCHAR DestinationProcessor, _In_ UCHAR Vector, _In_ APIC_MT MessageType, _In_ APIC_TGM TriggerMode, _In_ APIC_DSH DestinationShortHand)
 
VOID ApicStartApplicationProcessor (_In_ ULONG NTProcessorNumber, _In_ PHYSICAL_ADDRESS StartupLoc)
 
VOID NTAPI HalpBroadcastIpiSpecifyVector (_In_ UCHAR Vector, _In_ BOOLEAN IncludeSelf)
 Broadcasts an IPI with a specified vector to all processors.
 
VOID NTAPI HalRequestIpiSpecifyVector (_In_ KAFFINITY TargetSet, _In_ UCHAR Vector)
 Requests an IPI with a specified vector on the specified processors.
 
VOID NTAPI HalpRequestIpi (_In_ KAFFINITY TargetSet)
 Requests an IPI interrupt on the specified processors.
 

Variables

PPROCESSOR_IDENTITY HalpProcessorIdentity
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file apicsmp.c.

Function Documentation

◆ ApicRequestGlobalInterrupt()

FORCEINLINE VOID ApicRequestGlobalInterrupt ( _In_ UCHAR  DestinationProcessor,
_In_ UCHAR  Vector,
_In_ APIC_MT  MessageType,
_In_ APIC_TGM  TriggerMode,
_In_ APIC_DSH  DestinationShortHand 
)
Parameters
Vector- Specifies the interrupt vector to be delivered.
MessageType- Specifies the message type sent to the CPU core interrupt handler. This can be one of the following values: APIC_MT_Fixed - Delivers an interrupt to the target local APIC specified in Destination field. APIC_MT_LowestPriority - Delivers an interrupt to the local APIC executing at the lowest priority of all local APICs. APIC_MT_SMI - Delivers an SMI interrupt to target local APIC(s). APIC_MT_RemoteRead - Delivers a read request to read an APIC register in the target local APIC specified in Destination field. APIC_MT_NMI - Delivers a non-maskable interrupt to the target local APIC specified in the Destination field. Vector is ignored. APIC_MT_INIT - Delivers an INIT request to the target local APIC(s) specified in the Destination field. TriggerMode must be APIC_TGM_Edge, Vector must be 0. APIC_MT_Startup - Delivers a start-up request (SIPI) to the target local APIC(s) specified in Destination field. Vector specifies the startup address. APIC_MT_ExtInt - Delivers an external interrupt to the target local APIC specified in Destination field.
TriggerMode- The trigger mode of the interrupt. Can be: APIC_TGM_Edge - The interrupt is edge triggered. APIC_TGM_Level - The interrupt is level triggered.
DestinationShortHand- Specifies where to send the interrupt. APIC_DSH_Destination APIC_DSH_Self APIC_DSH_AllIncludingSelf APIC_DSH_AllExcludingSelf
See also
"AMD64 Architecture Programmer's Manual Volume 2 System Programming" Chapter 16 "Advanced Programmable Interrupt Controller (APIC)" 16.5 "Interprocessor Interrupts (IPI)"

Definition at line 63 of file apicsmp.c.

69{
72
73 /* Disable interrupts so that we can change IRR without being interrupted */
75 _disable();
76
77 /* Wait for the APIC to be idle */
78 do
79 {
81 } while (Icr.DeliveryStatus);
82
83 /* Setup the command register */
84 Icr.LongLong = 0;
85 Icr.Vector = Vector;
86 Icr.MessageType = MessageType;
88 Icr.DeliveryStatus = 0;
89 Icr.Level = 0;
90 Icr.TriggerMode = TriggerMode;
91 Icr.RemoteReadStatus = 0;
92 Icr.DestinationShortHand = DestinationShortHand;
93 Icr.Destination = DestinationProcessor;
94
95 /* Write the low dword last to send the interrupt */
98
99 /* Finally, restore the original interrupt state */
101 {
102 _enable();
103 }
104}
#define EFLAGS_INTERRUPT_MASK
Definition: SystemCall.c:11
@ APIC_DM_Physical
Definition: apicp.h:145
FORCEINLINE ULONG ApicRead(APIC_REGISTER Register)
Definition: apicp.h:316
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:323
@ APIC_ICR0
Definition: apicp.h:94
@ APIC_ICR1
Definition: apicp.h:95
void __cdecl _disable(void)
Definition: intrin_arm.h:365
void __cdecl _enable(void)
Definition: intrin_arm.h:373
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by ApicStartApplicationProcessor(), HalpBroadcastIpiSpecifyVector(), and HalRequestIpiSpecifyVector().

◆ ApicStartApplicationProcessor()

VOID ApicStartApplicationProcessor ( _In_ ULONG  NTProcessorNumber,
_In_ PHYSICAL_ADDRESS  StartupLoc 
)

Definition at line 110 of file apicsmp.c.

113{
114 ASSERT(StartupLoc.HighPart == 0);
115 ASSERT((StartupLoc.QuadPart & 0xFFF) == 0);
116 ASSERT((StartupLoc.QuadPart & 0xFFF00FFF) == 0);
117
118 /* Init IPI */
119 ApicRequestGlobalInterrupt(HalpProcessorIdentity[NTProcessorNumber].LapicId, 0,
121
122 /* De-Assert Init IPI */
123 ApicRequestGlobalInterrupt(HalpProcessorIdentity[NTProcessorNumber].LapicId, 0,
125
126 /* Stall execution for a bit to give APIC time: MPS Spec - B.4 */
128
129 /* Startup IPI */
130 ApicRequestGlobalInterrupt(HalpProcessorIdentity[NTProcessorNumber].LapicId, (StartupLoc.LowPart) >> 12,
132}
@ APIC_DSH_Destination
Definition: apicp.h:152
@ APIC_MT_INIT
Definition: apicp.h:130
@ APIC_MT_Startup
Definition: apicp.h:131
@ APIC_TGM_Level
Definition: apicp.h:139
@ APIC_TGM_Edge
Definition: apicp.h:138
FORCEINLINE VOID ApicRequestGlobalInterrupt(_In_ UCHAR DestinationProcessor, _In_ UCHAR Vector, _In_ APIC_MT MessageType, _In_ APIC_TGM TriggerMode, _In_ APIC_DSH DestinationShortHand)
Definition: apicsmp.c:63
PPROCESSOR_IDENTITY HalpProcessorIdentity
Definition: madt.c:21
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:81
#define ASSERT(a)
Definition: mode.c:44

Referenced by HalStartNextProcessor().

◆ HalpBroadcastIpiSpecifyVector()

VOID NTAPI HalpBroadcastIpiSpecifyVector ( _In_ UCHAR  Vector,
_In_ BOOLEAN  IncludeSelf 
)

Broadcasts an IPI with a specified vector to all processors.

Parameters
Vector- Specifies the interrupt vector to be delivered.
IncludeSelf- Specifies whether to include the current processor.

Definition at line 144 of file apicsmp.c.

147{
148 APIC_DSH DestinationShortHand = IncludeSelf ?
150
151 /* Request the interrupt targeted at all processors */
152 ApicRequestGlobalInterrupt(0, // Ignored
153 Vector,
156 DestinationShortHand);
157}
@ APIC_DSH_AllIncludingSelf
Definition: apicp.h:154
@ APIC_DSH_AllExcludingSelf
Definition: apicp.h:155
@ APIC_MT_Fixed
Definition: apicp.h:125
enum _APIC_DSH APIC_DSH

Referenced by HalpBroadcastClockIpi(), and HalRequestIpiSpecifyVector().

◆ HalpRequestIpi()

VOID NTAPI HalpRequestIpi ( _In_ KAFFINITY  TargetSet)

Requests an IPI interrupt on the specified processors.

Parameters
TargetSet- Specifies the set of processors to send the IPI to.

Definition at line 223 of file apicsmp.c.

225{
226 /* Request the IPI vector */
228}
#define APIC_IPI_VECTOR
Definition: apicp.h:47
VOID NTAPI HalRequestIpiSpecifyVector(_In_ KAFFINITY TargetSet, _In_ UCHAR Vector)
Requests an IPI with a specified vector on the specified processors.
Definition: apicsmp.c:169

Referenced by HalRequestIpi().

◆ HalRequestIpiSpecifyVector()

VOID NTAPI HalRequestIpiSpecifyVector ( _In_ KAFFINITY  TargetSet,
_In_ UCHAR  Vector 
)

Requests an IPI with a specified vector on the specified processors.

Parameters
TargetSet- Specifies the set of processors to send the IPI to.
Vector- Specifies the interrupt vector to be delivered.
Remarks
This function is exported on Windows 10.

Definition at line 169 of file apicsmp.c.

172{
173 KAFFINITY ActiveProcessors = HalpActiveProcessors;
174 KAFFINITY RemainingSet, SetMember;
175 ULONG ProcessorIndex;
176 ULONG LApicId;
177
178 /* Sanitize the target set */
179 TargetSet &= ActiveProcessors;
180
181 /* Check if all processors are requested */
182 if (TargetSet == ActiveProcessors)
183 {
184 /* Send an IPI to all processors, including this processor */
186 return;
187 }
188
189 /* Check if all processors except the current one are requested */
190 if (TargetSet == (ActiveProcessors & ~KeGetCurrentPrcb()->SetMember))
191 {
192 /* Send an IPI to all processors, excluding this processor */
194 return;
195 }
196
197 /* Loop while we have more processors */
198 RemainingSet = TargetSet;
199 while (RemainingSet != 0)
200 {
201 NT_VERIFY(BitScanForwardAffinity(&ProcessorIndex, RemainingSet) != 0);
202 ASSERT(ProcessorIndex < KeNumberProcessors);
203 SetMember = AFFINITY_MASK(ProcessorIndex);
204 RemainingSet &= ~SetMember;
205
206 /* Send the interrupt to the target processor */
207 LApicId = HalpProcessorIdentity[ProcessorIndex].LapicId;
209 Vector,
213 }
214}
VOID NTAPI HalpBroadcastIpiSpecifyVector(_In_ UCHAR Vector, _In_ BOOLEAN IncludeSelf)
Broadcasts an IPI with a specified vector to all processors.
Definition: apicsmp.c:144
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
ULONG_PTR KAFFINITY
Definition: compat.h:85
KAFFINITY HalpActiveProcessors
Definition: processor.c:17
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1146
FORCEINLINE KAFFINITY AFFINITY_MASK(ULONG Index)
Definition: kefuncs.h:39
FORCEINLINE BOOLEAN BitScanForwardAffinity(PULONG Index, KAFFINITY Mask)
Definition: kefuncs.h:45
UCHAR LapicId
Definition: smp.h:14
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3287

Referenced by HalpRequestIpi().

Variable Documentation

◆ HalpProcessorIdentity

PPROCESSOR_IDENTITY HalpProcessorIdentity
extern

Definition at line 21 of file madt.c.

Referenced by ApicStartApplicationProcessor(), and HalRequestIpiSpecifyVector().