Sync to trunk head (r47736)
[reactos.git] / hal / halx86 / mp / processor_mp.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: hal/halx86/mp/processor_mp.c
6 * PURPOSE: Intel MultiProcessor specification support
7 * PROGRAMMER: David Welch (welch@cwcom.net)
8 * Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * NOTES: Parts adapted from linux SMP code
10 * UPDATE HISTORY:
11 * 22/05/1998 DW Created
12 * 12/04/2001 CSH Added MultiProcessor specification support
13 */
14
15 /* INCLUDES *****************************************************************/
16
17 #include <hal.h>
18 #define NDEBUG
19 #include <debug.h>
20
21 KAFFINITY HalpActiveProcessors, HalpDefaultInterruptAffinity;
22
23 /* PRIVATE FUNCTIONS *********************************************************/
24
25 VOID
26 NTAPI
27 HaliHaltSystem(VOID)
28 {
29 /* Disable interrupts and halt the CPU */
30 _disable();
31 __halt();
32 }
33
34 /* FUNCTIONS *****************************************************************/
35
36 VOID NTAPI
37 HalInitializeProcessor(ULONG ProcessorNumber,
38 PLOADER_PARAMETER_BLOCK LoaderBlock)
39 {
40 ULONG CPU;
41
42 DPRINT("HalInitializeProcessor(%x %x)\n", ProcessorNumber, LoaderBlock);
43
44 CPU = ThisCPU();
45 if (OnlineCPUs & (1 << CPU))
46 {
47 ASSERT(FALSE);
48 }
49
50 if (ProcessorNumber == 0)
51 {
52 HaliInitBSP();
53 }
54 else
55 {
56 APICSetup();
57
58 DPRINT("CPU %d says it is now booted.\n", CPU);
59
60 APICCalibrateTimer(CPU);
61 }
62
63 /* This processor is now booted */
64 CPUMap[CPU].Flags |= CPU_ENABLED;
65 OnlineCPUs |= (1 << CPU);
66
67 /* Setup busy waiting */
68 //HalpCalibrateStallExecution();
69 }
70
71 BOOLEAN NTAPI
72 HalAllProcessorsStarted (VOID)
73 {
74 ULONG CPUs = 0, i;
75
76 DPRINT("HalAllProcessorsStarted()\n");
77 for (i = 0; i < 32; i++)
78 {
79 if (OnlineCPUs & (1 << i))
80 {
81 CPUs++;
82 }
83 }
84 if (CPUs > CPUCount)
85 {
86 ASSERT(FALSE);
87 }
88 else if (CPUs == CPUCount)
89 {
90
91 IOAPICEnable();
92 IOAPICSetupIds();
93 if (CPUCount > 1)
94 {
95 APICSyncArbIDs();
96 }
97 IOAPICSetupIrqs();
98
99 return TRUE;
100 }
101 return FALSE;
102 }
103
104 BOOLEAN
105 NTAPI
106 HalStartNextProcessor(
107 IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
108 IN PKPROCESSOR_STATE ProcessorState)
109 {
110 ULONG CPU;
111
112 DPRINT("HalStartNextProcessor(%x %x)\n", LoaderBlock, ProcessorState);
113
114 for (CPU = 0; CPU < CPUCount; CPU++)
115 {
116 if (!(OnlineCPUs & (1<<CPU)))
117 {
118 break;
119 }
120 }
121
122 if (CPU >= CPUCount)
123 {
124 ASSERT(FALSE);
125 }
126
127 DPRINT1("Attempting to boot CPU %d\n", CPU);
128
129 HaliStartApplicationProcessor(CPU, (ULONG)ProcessorState);
130
131 return TRUE;
132 }
133
134 VOID
135 NTAPI
136 HalProcessorIdle(VOID)
137 {
138 UNIMPLEMENTED;
139 }
140
141 /* EOF */