ReactOS 0.4.15-dev-7093-g01a8288
apicsmp.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS HAL
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: SMP specific APIC code
5 * COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
6 * Copyright 2023 Justin Miller <justin.miller@reactos.org>
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <hal.h>
12#include "apicp.h"
13#include <smp.h>
14
15#define NDEBUG
16#include <debug.h>
17
18
20
21/* INTERNAL FUNCTIONS *********************************************************/
22
62VOID
64 _In_ UCHAR DestinationProcessor,
66 _In_ APIC_MT MessageType,
67 _In_ APIC_TGM TriggerMode,
68 _In_ APIC_DSH DestinationShortHand)
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}
105
106
107/* SMP SUPPORT FUNCTIONS ******************************************************/
108
109VOID
110NTAPI
112{
114 __debugbreak();
115}
116
117VOID
119 _In_ ULONG NTProcessorNumber,
120 _In_ PHYSICAL_ADDRESS StartupLoc)
121{
122 ASSERT(StartupLoc.HighPart == 0);
123 ASSERT((StartupLoc.QuadPart & 0xFFF) == 0);
124 ASSERT((StartupLoc.QuadPart & 0xFFF00FFF) == 0);
125
126 /* Init IPI */
127 ApicRequestGlobalInterrupt(HalpProcessorIdentity[NTProcessorNumber].LapicId, 0,
129
130 /* De-Assert Init IPI */
131 ApicRequestGlobalInterrupt(HalpProcessorIdentity[NTProcessorNumber].LapicId, 0,
133
134 /* Stall execution for a bit to give APIC time: MPS Spec - B.4 */
136
137 /* Startup IPI */
138 ApicRequestGlobalInterrupt(HalpProcessorIdentity[NTProcessorNumber].LapicId, (StartupLoc.LowPart) >> 12,
140}
@ APIC_DM_Physical
Definition: apicp.h:144
@ APIC_DSH_Destination
Definition: apicp.h:151
@ APIC_MT_INIT
Definition: apicp.h:129
@ APIC_MT_Startup
Definition: apicp.h:130
enum _APIC_MT APIC_MT
FORCEINLINE ULONG ApicRead(APIC_REGISTER Register)
Definition: apicp.h:315
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:322
enum _APIC_TGM APIC_TGM
@ APIC_ICR0
Definition: apicp.h:93
@ APIC_ICR1
Definition: apicp.h:94
enum _APIC_DSH APIC_DSH
@ APIC_TGM_Level
Definition: apicp.h:138
@ APIC_TGM_Edge
Definition: apicp.h:137
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
VOID ApicStartApplicationProcessor(_In_ ULONG NTProcessorNumber, _In_ PHYSICAL_ADDRESS StartupLoc)
Definition: apicsmp.c:118
VOID NTAPI HalpRequestIpi(_In_ KAFFINITY TargetProcessors)
Definition: apicsmp.c:111
PPROCESSOR_IDENTITY HalpProcessorIdentity
Definition: madt.c:21
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:81
#define UNIMPLEMENTED
Definition: debug.h:115
ULONG_PTR KAFFINITY
Definition: compat.h:85
void __cdecl _disable(void)
Definition: intrin_arm.h:365
void __cdecl _enable(void)
Definition: intrin_arm.h:373
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
#define ASSERT(a)
Definition: mode.c:44
#define _In_
Definition: ms_sal.h:308
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:187
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
#define FORCEINLINE
Definition: wdftypes.h:67
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
unsigned char UCHAR
Definition: xmlstorage.h:181