126bccbcbf6e6be7f52caffbeecf63784be038b8
[reactos.git] / reactos / 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 /* PRIVATE FUNCTIONS *********************************************************/
22
23 VOID
24 NTAPI
25 HaliHaltSystem(VOID)
26 {
27 /* Disable interrupts and halt the CPU */
28 _disable();
29 __halt();
30 }
31
32 /* FUNCTIONS *****************************************************************/
33
34 VOID NTAPI
35 HalInitializeProcessor(ULONG ProcessorNumber,
36 PLOADER_PARAMETER_BLOCK LoaderBlock)
37 {
38 ULONG CPU;
39
40 DPRINT("HalInitializeProcessor(%x %x)\n", ProcessorNumber, LoaderBlock);
41
42 CPU = ThisCPU();
43 if (OnlineCPUs & (1 << CPU))
44 {
45 ASSERT(FALSE);
46 }
47
48 if (ProcessorNumber == 0)
49 {
50 HaliInitBSP();
51 }
52 else
53 {
54 APICSetup();
55
56 DPRINT("CPU %d says it is now booted.\n", CPU);
57
58 APICCalibrateTimer(CPU);
59 }
60
61 /* This processor is now booted */
62 CPUMap[CPU].Flags |= CPU_ENABLED;
63 OnlineCPUs |= (1 << CPU);
64
65 /* Setup busy waiting */
66 //HalpCalibrateStallExecution();
67 }
68
69 BOOLEAN NTAPI
70 HalAllProcessorsStarted (VOID)
71 {
72 ULONG CPUs = 0, i;
73
74 DPRINT("HalAllProcessorsStarted()\n");
75 for (i = 0; i < 32; i++)
76 {
77 if (OnlineCPUs & (1 << i))
78 {
79 CPUs++;
80 }
81 }
82 if (CPUs > CPUCount)
83 {
84 ASSERT(FALSE);
85 }
86 else if (CPUs == CPUCount)
87 {
88
89 IOAPICEnable();
90 IOAPICSetupIds();
91 if (CPUCount > 1)
92 {
93 APICSyncArbIDs();
94 }
95 IOAPICSetupIrqs();
96
97 return TRUE;
98 }
99 return FALSE;
100 }
101
102 BOOLEAN
103 NTAPI
104 HalStartNextProcessor(
105 IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
106 IN PKPROCESSOR_STATE ProcessorState)
107 {
108 ULONG CPU;
109
110 DPRINT("HalStartNextProcessor(%x %x)\n", LoaderBlock, ProcessorState);
111
112 for (CPU = 0; CPU < CPUCount; CPU++)
113 {
114 if (!(OnlineCPUs & (1<<CPU)))
115 {
116 break;
117 }
118 }
119
120 if (CPU >= CPUCount)
121 {
122 ASSERT(FALSE);
123 }
124
125 DPRINT1("Attempting to boot CPU %d\n", CPU);
126
127 HaliStartApplicationProcessor(CPU, (ULONG)ProcessorState);
128
129 return TRUE;
130 }
131
132 VOID
133 NTAPI
134 HalProcessorIdle(VOID)
135 {
136 UNIMPLEMENTED;
137 }
138
139 /* EOF */