]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/CpuDxe/CpuDxe.c
MdeModulePkg DXE Core: Add Idle event during BootServices WaitForEvent
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuDxe.c
CommitLineData
a47463f2 1/** @file\r
2 CPU DXE Module.\r
3\r
f877f300 4 Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>\r
01a1c0fc 5 This program and the accompanying materials\r
a47463f2 6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "CpuDxe.h"\r
16\r
17//\r
18// Global Variables\r
19//\r
20IA32_IDT_GATE_DESCRIPTOR gIdtTable[INTERRUPT_VECTOR_NUMBER] = { 0 };\r
21\r
22EFI_CPU_INTERRUPT_HANDLER ExternalVectorTable[0x100];\r
23BOOLEAN InterruptState = FALSE;\r
24EFI_HANDLE mCpuHandle = NULL;\r
25BOOLEAN mIsFlushingGCD;\r
26UINT8 mDefaultMemoryType = MTRR_CACHE_WRITE_BACK;\r
27UINT64 mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;\r
28UINT64 mValidMtrrBitsMask = MTRR_LIB_MSR_VALID_MASK;\r
29\r
30FIXED_MTRR mFixedMtrrTable[] = {\r
31 {\r
32 MTRR_LIB_IA32_MTRR_FIX64K_00000,\r
33 0,\r
34 0x10000\r
35 },\r
36 {\r
37 MTRR_LIB_IA32_MTRR_FIX16K_80000,\r
38 0x80000,\r
39 0x4000\r
40 },\r
41 {\r
42 MTRR_LIB_IA32_MTRR_FIX16K_A0000,\r
43 0xA0000,\r
44 0x4000\r
45 },\r
46 {\r
47 MTRR_LIB_IA32_MTRR_FIX4K_C0000,\r
48 0xC0000,\r
49 0x1000\r
50 },\r
51 {\r
52 MTRR_LIB_IA32_MTRR_FIX4K_C8000,\r
53 0xC8000,\r
54 0x1000\r
55 },\r
56 {\r
57 MTRR_LIB_IA32_MTRR_FIX4K_D0000,\r
58 0xD0000,\r
59 0x1000\r
60 },\r
61 {\r
62 MTRR_LIB_IA32_MTRR_FIX4K_D8000,\r
63 0xD8000,\r
64 0x1000\r
65 },\r
66 {\r
67 MTRR_LIB_IA32_MTRR_FIX4K_E0000,\r
68 0xE0000,\r
69 0x1000\r
70 },\r
71 {\r
72 MTRR_LIB_IA32_MTRR_FIX4K_E8000,\r
73 0xE8000,\r
74 0x1000\r
75 },\r
76 {\r
77 MTRR_LIB_IA32_MTRR_FIX4K_F0000,\r
78 0xF0000,\r
79 0x1000\r
80 },\r
81 {\r
82 MTRR_LIB_IA32_MTRR_FIX4K_F8000,\r
83 0xF8000,\r
84 0x1000\r
85 },\r
86};\r
87\r
88\r
89EFI_CPU_ARCH_PROTOCOL gCpu = {\r
90 CpuFlushCpuDataCache,\r
91 CpuEnableInterrupt,\r
92 CpuDisableInterrupt,\r
93 CpuGetInterruptState,\r
94 CpuInit,\r
95 CpuRegisterInterruptHandler,\r
96 CpuGetTimerValue,\r
97 CpuSetMemoryAttributes,\r
98 1, // NumberOfTimers\r
99 4 // DmaBufferAlignment\r
100};\r
101\r
102//\r
103// Error code flag indicating whether or not an error code will be\r
104// pushed on the stack if an exception occurs.\r
105//\r
106// 1 means an error code will be pushed, otherwise 0\r
107//\r
108// bit 0 - exception 0\r
109// bit 1 - exception 1\r
110// etc.\r
111//\r
112UINT32 mErrorCodeFlag = 0x00027d00;\r
113\r
557b970a 114//\r
115// Local function prototypes\r
116//\r
1e51d595
ED
117\r
118/**\r
119 Set Interrupt Descriptor Table Handler Address.\r
120\r
121 @param Index The Index of the interrupt descriptor table handle.\r
122 @param Handler Handler address.\r
123\r
124**/\r
557b970a 125VOID\r
126SetInterruptDescriptorTableHandlerAddress (\r
127 IN UINTN Index,\r
128 IN VOID *Handler OPTIONAL\r
129 );\r
130\r
a47463f2 131//\r
132// CPU Arch Protocol Functions\r
133//\r
134\r
135\r
136/**\r
137 Common exception handler.\r
138\r
139 @param InterruptType Exception type\r
140 @param SystemContext EFI_SYSTEM_CONTEXT\r
141\r
142**/\r
143VOID\r
144EFIAPI\r
145CommonExceptionHandler (\r
146 IN EFI_EXCEPTION_TYPE InterruptType,\r
147 IN EFI_SYSTEM_CONTEXT SystemContext\r
148 )\r
149{\r
150#if defined (MDE_CPU_IA32)\r
151 DEBUG ((\r
152 EFI_D_ERROR,\r
153 "!!!! IA32 Exception Type - %08x !!!!\n",\r
154 InterruptType\r
155 ));\r
430fbbe0 156 if ((mErrorCodeFlag & (1 << InterruptType)) != 0) {\r
a47463f2 157 DEBUG ((\r
158 EFI_D_ERROR,\r
159 "ExceptionData - %08x\n",\r
160 SystemContext.SystemContextIa32->ExceptionData\r
161 ));\r
162 }\r
163 DEBUG ((\r
164 EFI_D_ERROR,\r
165 "CS - %04x, EIP - %08x, EFL - %08x, SS - %04x\n",\r
166 SystemContext.SystemContextIa32->Cs,\r
167 SystemContext.SystemContextIa32->Eip,\r
168 SystemContext.SystemContextIa32->Eflags,\r
169 SystemContext.SystemContextIa32->Ss\r
170 ));\r
171 DEBUG ((\r
172 EFI_D_ERROR,\r
173 "DS - %04x, ES - %04x, FS - %04x, GS - %04x\n",\r
174 SystemContext.SystemContextIa32->Ds,\r
175 SystemContext.SystemContextIa32->Es,\r
176 SystemContext.SystemContextIa32->Fs,\r
177 SystemContext.SystemContextIa32->Gs\r
178 ));\r
179 DEBUG ((\r
180 EFI_D_ERROR,\r
181 "EAX - %08x, EBX - %08x, ECX - %08x, EDX - %08x\n",\r
182 SystemContext.SystemContextIa32->Eax,\r
183 SystemContext.SystemContextIa32->Ebx,\r
184 SystemContext.SystemContextIa32->Ecx,\r
185 SystemContext.SystemContextIa32->Edx\r
186 ));\r
187 DEBUG ((\r
188 EFI_D_ERROR,\r
189 "ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x\n",\r
190 SystemContext.SystemContextIa32->Esp,\r
191 SystemContext.SystemContextIa32->Ebp,\r
192 SystemContext.SystemContextIa32->Esi,\r
193 SystemContext.SystemContextIa32->Edi\r
194 ));\r
195 DEBUG ((\r
196 EFI_D_ERROR,\r
197 "GDT - %08x LIM - %04x, IDT - %08x LIM - %04x\n",\r
198 SystemContext.SystemContextIa32->Gdtr[0],\r
199 SystemContext.SystemContextIa32->Gdtr[1],\r
200 SystemContext.SystemContextIa32->Idtr[0],\r
201 SystemContext.SystemContextIa32->Idtr[1]\r
202 ));\r
203 DEBUG ((\r
204 EFI_D_ERROR,\r
205 "LDT - %08x, TR - %08x\n",\r
206 SystemContext.SystemContextIa32->Ldtr,\r
207 SystemContext.SystemContextIa32->Tr\r
208 ));\r
209 DEBUG ((\r
210 EFI_D_ERROR,\r
211 "CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x\n",\r
212 SystemContext.SystemContextIa32->Cr0,\r
213 SystemContext.SystemContextIa32->Cr2,\r
214 SystemContext.SystemContextIa32->Cr3,\r
215 SystemContext.SystemContextIa32->Cr4\r
216 ));\r
217 DEBUG ((\r
218 EFI_D_ERROR,\r
219 "DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x\n",\r
220 SystemContext.SystemContextIa32->Dr0,\r
221 SystemContext.SystemContextIa32->Dr1,\r
222 SystemContext.SystemContextIa32->Dr2,\r
223 SystemContext.SystemContextIa32->Dr3\r
224 ));\r
225 DEBUG ((\r
226 EFI_D_ERROR,\r
227 "DR6 - %08x, DR7 - %08x\n",\r
228 SystemContext.SystemContextIa32->Dr6,\r
229 SystemContext.SystemContextIa32->Dr7\r
230 ));\r
231#elif defined (MDE_CPU_X64)\r
232 DEBUG ((\r
233 EFI_D_ERROR,\r
234 "!!!! X64 Exception Type - %016lx !!!!\n",\r
235 (UINT64)InterruptType\r
236 ));\r
430fbbe0 237 if ((mErrorCodeFlag & (1 << InterruptType)) != 0) {\r
a47463f2 238 DEBUG ((\r
239 EFI_D_ERROR,\r
240 "ExceptionData - %016lx\n",\r
241 SystemContext.SystemContextX64->ExceptionData\r
242 ));\r
243 }\r
244 DEBUG ((\r
245 EFI_D_ERROR,\r
246 "RIP - %016lx, RFL - %016lx\n",\r
247 SystemContext.SystemContextX64->Rip,\r
248 SystemContext.SystemContextX64->Rflags\r
249 ));\r
250 DEBUG ((\r
251 EFI_D_ERROR,\r
252 "RAX - %016lx, RCX - %016lx, RDX - %016lx\n",\r
253 SystemContext.SystemContextX64->Rax,\r
254 SystemContext.SystemContextX64->Rcx,\r
255 SystemContext.SystemContextX64->Rdx\r
256 ));\r
257 DEBUG ((\r
258 EFI_D_ERROR,\r
259 "RBX - %016lx, RSP - %016lx, RBP - %016lx\n",\r
260 SystemContext.SystemContextX64->Rbx,\r
261 SystemContext.SystemContextX64->Rsp,\r
262 SystemContext.SystemContextX64->Rbp\r
263 ));\r
264 DEBUG ((\r
265 EFI_D_ERROR,\r
266 "RSI - %016lx, RDI - %016lx\n",\r
267 SystemContext.SystemContextX64->Rsi,\r
268 SystemContext.SystemContextX64->Rdi\r
269 ));\r
270 DEBUG ((\r
271 EFI_D_ERROR,\r
272 "R8 - %016lx, R9 - %016lx, R10 - %016lx\n",\r
273 SystemContext.SystemContextX64->R8,\r
274 SystemContext.SystemContextX64->R9,\r
275 SystemContext.SystemContextX64->R10\r
276 ));\r
277 DEBUG ((\r
278 EFI_D_ERROR,\r
279 "R11 - %016lx, R12 - %016lx, R13 - %016lx\n",\r
280 SystemContext.SystemContextX64->R11,\r
281 SystemContext.SystemContextX64->R12,\r
282 SystemContext.SystemContextX64->R13\r
283 ));\r
284 DEBUG ((\r
285 EFI_D_ERROR,\r
286 "R14 - %016lx, R15 - %016lx\n",\r
287 SystemContext.SystemContextX64->R14,\r
288 SystemContext.SystemContextX64->R15\r
289 ));\r
290 DEBUG ((\r
291 EFI_D_ERROR,\r
292 "CS - %04lx, DS - %04lx, ES - %04lx, FS - %04lx, GS - %04lx, SS - %04lx\n",\r
293 SystemContext.SystemContextX64->Cs,\r
294 SystemContext.SystemContextX64->Ds,\r
295 SystemContext.SystemContextX64->Es,\r
296 SystemContext.SystemContextX64->Fs,\r
297 SystemContext.SystemContextX64->Gs,\r
298 SystemContext.SystemContextX64->Ss\r
299 ));\r
300 DEBUG ((\r
301 EFI_D_ERROR,\r
302 "GDT - %016lx; %04lx, IDT - %016lx; %04lx\n",\r
303 SystemContext.SystemContextX64->Gdtr[0],\r
304 SystemContext.SystemContextX64->Gdtr[1],\r
305 SystemContext.SystemContextX64->Idtr[0],\r
306 SystemContext.SystemContextX64->Idtr[1]\r
307 ));\r
308 DEBUG ((\r
309 EFI_D_ERROR,\r
310 "LDT - %016lx, TR - %016lx\n",\r
311 SystemContext.SystemContextX64->Ldtr,\r
312 SystemContext.SystemContextX64->Tr\r
313 ));\r
314 DEBUG ((\r
315 EFI_D_ERROR,\r
316 "CR0 - %016lx, CR2 - %016lx, CR3 - %016lx\n",\r
317 SystemContext.SystemContextX64->Cr0,\r
318 SystemContext.SystemContextX64->Cr2,\r
319 SystemContext.SystemContextX64->Cr3\r
320 ));\r
321 DEBUG ((\r
322 EFI_D_ERROR,\r
323 "CR4 - %016lx, CR8 - %016lx\n",\r
324 SystemContext.SystemContextX64->Cr4,\r
325 SystemContext.SystemContextX64->Cr8\r
326 ));\r
327 DEBUG ((\r
328 EFI_D_ERROR,\r
329 "DR0 - %016lx, DR1 - %016lx, DR2 - %016lx\n",\r
330 SystemContext.SystemContextX64->Dr0,\r
331 SystemContext.SystemContextX64->Dr1,\r
332 SystemContext.SystemContextX64->Dr2\r
333 ));\r
334 DEBUG ((\r
335 EFI_D_ERROR,\r
336 "DR3 - %016lx, DR6 - %016lx, DR7 - %016lx\n",\r
337 SystemContext.SystemContextX64->Dr3,\r
338 SystemContext.SystemContextX64->Dr6,\r
339 SystemContext.SystemContextX64->Dr7\r
340 ));\r
341#else\r
342#error CPU type not supported for exception information dump!\r
343#endif\r
344\r
345 //\r
346 // Hang the system with CpuSleep so the processor will enter a lower power\r
347 // state.\r
348 //\r
349 while (TRUE) {\r
350 CpuSleep ();\r
351 };\r
352}\r
353\r
354\r
355/**\r
356 Flush CPU data cache. If the instruction cache is fully coherent\r
357 with all DMA operations then function can just return EFI_SUCCESS.\r
358\r
359 @param This Protocol instance structure\r
360 @param Start Physical address to start flushing from.\r
361 @param Length Number of bytes to flush. Round up to chipset\r
362 granularity.\r
363 @param FlushType Specifies the type of flush operation to perform.\r
364\r
365 @retval EFI_SUCCESS If cache was flushed\r
366 @retval EFI_UNSUPPORTED If flush type is not supported.\r
367 @retval EFI_DEVICE_ERROR If requested range could not be flushed.\r
368\r
369**/\r
370EFI_STATUS\r
371EFIAPI\r
372CpuFlushCpuDataCache (\r
373 IN EFI_CPU_ARCH_PROTOCOL *This,\r
374 IN EFI_PHYSICAL_ADDRESS Start,\r
375 IN UINT64 Length,\r
376 IN EFI_CPU_FLUSH_TYPE FlushType\r
377 )\r
378{\r
379 if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {\r
380 AsmWbinvd ();\r
381 return EFI_SUCCESS;\r
382 } else if (FlushType == EfiCpuFlushTypeInvalidate) {\r
383 AsmInvd ();\r
384 return EFI_SUCCESS;\r
385 } else {\r
386 return EFI_UNSUPPORTED;\r
387 }\r
388}\r
389\r
390\r
391/**\r
392 Enables CPU interrupts.\r
393\r
394 @param This Protocol instance structure\r
395\r
396 @retval EFI_SUCCESS If interrupts were enabled in the CPU\r
397 @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU.\r
398\r
399**/\r
400EFI_STATUS\r
401EFIAPI\r
402CpuEnableInterrupt (\r
403 IN EFI_CPU_ARCH_PROTOCOL *This\r
404 )\r
405{\r
406 EnableInterrupts ();\r
407\r
408 InterruptState = TRUE;\r
409 return EFI_SUCCESS;\r
410}\r
411\r
412\r
413/**\r
414 Disables CPU interrupts.\r
415\r
416 @param This Protocol instance structure\r
417\r
418 @retval EFI_SUCCESS If interrupts were disabled in the CPU.\r
419 @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU.\r
420\r
421**/\r
422EFI_STATUS\r
423EFIAPI\r
424CpuDisableInterrupt (\r
425 IN EFI_CPU_ARCH_PROTOCOL *This\r
426 )\r
427{\r
428 DisableInterrupts ();\r
429\r
430 InterruptState = FALSE;\r
431 return EFI_SUCCESS;\r
432}\r
433\r
434\r
435/**\r
436 Return the state of interrupts.\r
437\r
438 @param This Protocol instance structure\r
439 @param State Pointer to the CPU's current interrupt state\r
440\r
441 @retval EFI_SUCCESS If interrupts were disabled in the CPU.\r
442 @retval EFI_INVALID_PARAMETER State is NULL.\r
443\r
444**/\r
445EFI_STATUS\r
446EFIAPI\r
447CpuGetInterruptState (\r
448 IN EFI_CPU_ARCH_PROTOCOL *This,\r
449 OUT BOOLEAN *State\r
450 )\r
451{\r
452 if (State == NULL) {\r
453 return EFI_INVALID_PARAMETER;\r
454 }\r
455\r
456 *State = InterruptState;\r
457 return EFI_SUCCESS;\r
458}\r
459\r
460\r
461/**\r
462 Generates an INIT to the CPU.\r
463\r
464 @param This Protocol instance structure\r
465 @param InitType Type of CPU INIT to perform\r
466\r
467 @retval EFI_SUCCESS If CPU INIT occurred. This value should never be\r
468 seen.\r
469 @retval EFI_DEVICE_ERROR If CPU INIT failed.\r
470 @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported.\r
471\r
472**/\r
473EFI_STATUS\r
474EFIAPI\r
475CpuInit (\r
476 IN EFI_CPU_ARCH_PROTOCOL *This,\r
477 IN EFI_CPU_INIT_TYPE InitType\r
478 )\r
479{\r
480 return EFI_UNSUPPORTED;\r
481}\r
482\r
483\r
484/**\r
485 Registers a function to be called from the CPU interrupt handler.\r
486\r
487 @param This Protocol instance structure\r
488 @param InterruptType Defines which interrupt to hook. IA-32\r
489 valid range is 0x00 through 0xFF\r
490 @param InterruptHandler A pointer to a function of type\r
491 EFI_CPU_INTERRUPT_HANDLER that is called\r
492 when a processor interrupt occurs. A null\r
493 pointer is an error condition.\r
494\r
495 @retval EFI_SUCCESS If handler installed or uninstalled.\r
496 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler\r
497 for InterruptType was previously installed.\r
498 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for\r
499 InterruptType was not previously installed.\r
500 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType\r
501 is not supported.\r
502\r
503**/\r
504EFI_STATUS\r
505EFIAPI\r
506CpuRegisterInterruptHandler (\r
507 IN EFI_CPU_ARCH_PROTOCOL *This,\r
508 IN EFI_EXCEPTION_TYPE InterruptType,\r
509 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
510 )\r
511{\r
512 if (InterruptType < 0 || InterruptType > 0xff) {\r
513 return EFI_UNSUPPORTED;\r
514 }\r
515\r
516 if (InterruptHandler == NULL && ExternalVectorTable[InterruptType] == NULL) {\r
517 return EFI_INVALID_PARAMETER;\r
518 }\r
519\r
520 if (InterruptHandler != NULL && ExternalVectorTable[InterruptType] != NULL) {\r
521 return EFI_ALREADY_STARTED;\r
522 }\r
523\r
c52acd89 524 SetInterruptDescriptorTableHandlerAddress ((UINTN)InterruptType, NULL);\r
a47463f2 525 ExternalVectorTable[InterruptType] = InterruptHandler;\r
526 return EFI_SUCCESS;\r
527}\r
528\r
529\r
530/**\r
531 Returns a timer value from one of the CPU's internal timers. There is no\r
532 inherent time interval between ticks but is a function of the CPU frequency.\r
533\r
534 @param This - Protocol instance structure.\r
535 @param TimerIndex - Specifies which CPU timer is requested.\r
536 @param TimerValue - Pointer to the returned timer value.\r
537 @param TimerPeriod - A pointer to the amount of time that passes\r
538 in femtoseconds (10-15) for each increment\r
539 of TimerValue. If TimerValue does not\r
540 increment at a predictable rate, then 0 is\r
541 returned. The amount of time that has\r
542 passed between two calls to GetTimerValue()\r
543 can be calculated with the formula\r
544 (TimerValue2 - TimerValue1) * TimerPeriod.\r
545 This parameter is optional and may be NULL.\r
546\r
547 @retval EFI_SUCCESS - If the CPU timer count was returned.\r
548 @retval EFI_UNSUPPORTED - If the CPU does not have any readable timers.\r
549 @retval EFI_DEVICE_ERROR - If an error occurred while reading the timer.\r
550 @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is NULL.\r
551\r
552**/\r
553EFI_STATUS\r
554EFIAPI\r
555CpuGetTimerValue (\r
556 IN EFI_CPU_ARCH_PROTOCOL *This,\r
557 IN UINT32 TimerIndex,\r
558 OUT UINT64 *TimerValue,\r
559 OUT UINT64 *TimerPeriod OPTIONAL\r
560 )\r
561{\r
562 if (TimerValue == NULL) {\r
563 return EFI_INVALID_PARAMETER;\r
564 }\r
565\r
566 if (TimerIndex != 0) {\r
567 return EFI_INVALID_PARAMETER;\r
568 }\r
569\r
570 *TimerValue = AsmReadTsc ();\r
571\r
572 if (TimerPeriod != NULL) {\r
573 //\r
574 // BugBug: Hard coded. Don't know how to do this generically\r
575 //\r
576 *TimerPeriod = 1000000000;\r
577 }\r
578\r
579 return EFI_SUCCESS;\r
580}\r
581\r
582\r
583/**\r
4ec21e8b 584 Implementation of SetMemoryAttributes() service of CPU Architecture Protocol.\r
585\r
586 This function modifies the attributes for the memory region specified by BaseAddress and\r
587 Length from their current attributes to the attributes specified by Attributes.\r
588\r
589 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
590 @param BaseAddress The physical address that is the start address of a memory region.\r
591 @param Length The size in bytes of the memory region.\r
592 @param Attributes The bit mask of attributes to set for the memory region.\r
593\r
594 @retval EFI_SUCCESS The attributes were set for the memory region.\r
595 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r
596 BaseAddress and Length cannot be modified.\r
597 @retval EFI_INVALID_PARAMETER Length is zero.\r
598 Attributes specified an illegal combination of attributes that\r
599 cannot be set together.\r
600 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
601 the memory resource range.\r
602 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r
603 resource range specified by BaseAddress and Length.\r
604 The bit mask of attributes is not support for the memory resource\r
605 range specified by BaseAddress and Length.\r
a47463f2 606\r
607**/\r
608EFI_STATUS\r
609EFIAPI\r
610CpuSetMemoryAttributes (\r
611 IN EFI_CPU_ARCH_PROTOCOL *This,\r
612 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
613 IN UINT64 Length,\r
614 IN UINT64 Attributes\r
615 )\r
616{\r
617 RETURN_STATUS Status;\r
618 MTRR_MEMORY_CACHE_TYPE CacheType;\r
619\r
947a573a 620 if (!IsMtrrSupported ()) {\r
621 return EFI_UNSUPPORTED;\r
622 }\r
623\r
a47463f2 624 //\r
625 // If this function is called because GCD SetMemorySpaceAttributes () is called\r
626 // by RefreshGcdMemoryAttributes (), then we are just synchronzing GCD memory\r
627 // map with MTRR values. So there is no need to modify MTRRs, just return immediately\r
628 // to avoid unnecessary computing.\r
629 //\r
630 if (mIsFlushingGCD) {\r
631 DEBUG((EFI_D_ERROR, " Flushing GCD\n"));\r
632 return EFI_SUCCESS;\r
633 }\r
634\r
635 switch (Attributes) {\r
636 case EFI_MEMORY_UC:\r
637 CacheType = CacheUncacheable;\r
638 break;\r
639\r
640 case EFI_MEMORY_WC:\r
641 CacheType = CacheWriteCombining;\r
642 break;\r
643\r
644 case EFI_MEMORY_WT:\r
645 CacheType = CacheWriteThrough;\r
646 break;\r
647\r
648 case EFI_MEMORY_WP:\r
649 CacheType = CacheWriteProtected;\r
650 break;\r
651\r
652 case EFI_MEMORY_WB:\r
653 CacheType = CacheWriteBack;\r
654 break;\r
655\r
4ec21e8b 656 case EFI_MEMORY_UCE:\r
657 case EFI_MEMORY_RP:\r
658 case EFI_MEMORY_XP:\r
659 case EFI_MEMORY_RUNTIME:\r
a47463f2 660 return EFI_UNSUPPORTED;\r
4ec21e8b 661\r
662 default:\r
663 return EFI_INVALID_PARAMETER;\r
a47463f2 664 }\r
665 //\r
666 // call MTRR libary function\r
667 //\r
f877f300 668 Status = MtrrSetMemoryAttribute (\r
a47463f2 669 BaseAddress,\r
670 Length,\r
671 CacheType\r
672 );\r
673\r
a47463f2 674 return (EFI_STATUS) Status;\r
675}\r
676\r
677/**\r
678 Initializes the valid bits mask and valid address mask for MTRRs.\r
679\r
680 This function initializes the valid bits mask and valid address mask for MTRRs.\r
681\r
682**/\r
683VOID\r
684InitializeMtrrMask (\r
685 VOID\r
686 )\r
687{\r
688 UINT32 RegEax;\r
689 UINT8 PhysicalAddressBits;\r
690\r
691 AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
692\r
693 if (RegEax >= 0x80000008) {\r
694 AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);\r
695\r
696 PhysicalAddressBits = (UINT8) RegEax;\r
697\r
698 mValidMtrrBitsMask = LShiftU64 (1, PhysicalAddressBits) - 1;\r
699 mValidMtrrAddressMask = mValidMtrrBitsMask & 0xfffffffffffff000ULL;\r
700 } else {\r
701 mValidMtrrBitsMask = MTRR_LIB_MSR_VALID_MASK;\r
702 mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;\r
703 }\r
704}\r
705\r
706/**\r
430fbbe0 707 Gets GCD Mem Space type from MTRR Type.\r
a47463f2 708\r
430fbbe0 709 This function gets GCD Mem Space type from MTRR Type.\r
a47463f2 710\r
430fbbe0 711 @param MtrrAttributes MTRR memory type\r
a47463f2 712\r
713 @return GCD Mem Space type\r
714\r
715**/\r
716UINT64\r
717GetMemorySpaceAttributeFromMtrrType (\r
718 IN UINT8 MtrrAttributes\r
719 )\r
720{\r
721 switch (MtrrAttributes) {\r
722 case MTRR_CACHE_UNCACHEABLE:\r
723 return EFI_MEMORY_UC;\r
724 case MTRR_CACHE_WRITE_COMBINING:\r
725 return EFI_MEMORY_WC;\r
726 case MTRR_CACHE_WRITE_THROUGH:\r
727 return EFI_MEMORY_WT;\r
728 case MTRR_CACHE_WRITE_PROTECTED:\r
729 return EFI_MEMORY_WP;\r
730 case MTRR_CACHE_WRITE_BACK:\r
731 return EFI_MEMORY_WB;\r
732 default:\r
733 return 0;\r
734 }\r
735}\r
736\r
737/**\r
738 Searches memory descriptors covered by given memory range.\r
739\r
740 This function searches into the Gcd Memory Space for descriptors\r
741 (from StartIndex to EndIndex) that contains the memory range\r
742 specified by BaseAddress and Length.\r
743\r
744 @param MemorySpaceMap Gcd Memory Space Map as array.\r
745 @param NumberOfDescriptors Number of descriptors in map.\r
746 @param BaseAddress BaseAddress for the requested range.\r
747 @param Length Length for the requested range.\r
748 @param StartIndex Start index into the Gcd Memory Space Map.\r
749 @param EndIndex End index into the Gcd Memory Space Map.\r
750\r
751 @retval EFI_SUCCESS Search successfully.\r
752 @retval EFI_NOT_FOUND The requested descriptors does not exist.\r
753\r
754**/\r
755EFI_STATUS\r
756SearchGcdMemorySpaces (\r
757 IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap,\r
758 IN UINTN NumberOfDescriptors,\r
759 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
760 IN UINT64 Length,\r
761 OUT UINTN *StartIndex,\r
762 OUT UINTN *EndIndex\r
763 )\r
764{\r
765 UINTN Index;\r
766\r
767 *StartIndex = 0;\r
768 *EndIndex = 0;\r
769 for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
770 if (BaseAddress >= MemorySpaceMap[Index].BaseAddress &&\r
771 BaseAddress < MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) {\r
772 *StartIndex = Index;\r
773 }\r
774 if (BaseAddress + Length - 1 >= MemorySpaceMap[Index].BaseAddress &&\r
775 BaseAddress + Length - 1 < MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) {\r
776 *EndIndex = Index;\r
777 return EFI_SUCCESS;\r
778 }\r
779 }\r
780 return EFI_NOT_FOUND;\r
781}\r
782\r
783/**\r
784 Sets the attributes for a specified range in Gcd Memory Space Map.\r
785\r
786 This function sets the attributes for a specified range in\r
787 Gcd Memory Space Map.\r
788\r
789 @param MemorySpaceMap Gcd Memory Space Map as array\r
790 @param NumberOfDescriptors Number of descriptors in map\r
791 @param BaseAddress BaseAddress for the range\r
792 @param Length Length for the range\r
793 @param Attributes Attributes to set\r
794\r
795 @retval EFI_SUCCESS Memory attributes set successfully\r
796 @retval EFI_NOT_FOUND The specified range does not exist in Gcd Memory Space\r
797\r
798**/\r
799EFI_STATUS\r
800SetGcdMemorySpaceAttributes (\r
801 IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap,\r
802 IN UINTN NumberOfDescriptors,\r
803 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
804 IN UINT64 Length,\r
805 IN UINT64 Attributes\r
806 )\r
807{\r
808 EFI_STATUS Status;\r
809 UINTN Index;\r
810 UINTN StartIndex;\r
811 UINTN EndIndex;\r
812 EFI_PHYSICAL_ADDRESS RegionStart;\r
813 UINT64 RegionLength;\r
814\r
815 //\r
816 // Get all memory descriptors covered by the memory range\r
817 //\r
818 Status = SearchGcdMemorySpaces (\r
819 MemorySpaceMap,\r
820 NumberOfDescriptors,\r
821 BaseAddress,\r
822 Length,\r
823 &StartIndex,\r
824 &EndIndex\r
825 );\r
826 if (EFI_ERROR (Status)) {\r
827 return Status;\r
828 }\r
829\r
830 //\r
831 // Go through all related descriptors and set attributes accordingly\r
832 //\r
833 for (Index = StartIndex; Index <= EndIndex; Index++) {\r
834 if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeNonExistent) {\r
835 continue;\r
836 }\r
837 //\r
838 // Calculate the start and end address of the overlapping range\r
839 //\r
840 if (BaseAddress >= MemorySpaceMap[Index].BaseAddress) {\r
841 RegionStart = BaseAddress;\r
842 } else {\r
843 RegionStart = MemorySpaceMap[Index].BaseAddress;\r
844 }\r
845 if (BaseAddress + Length - 1 < MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) {\r
846 RegionLength = BaseAddress + Length - RegionStart;\r
847 } else {\r
848 RegionLength = MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - RegionStart;\r
849 }\r
850 //\r
851 // Set memory attributes according to MTRR attribute and the original attribute of descriptor\r
852 //\r
853 gDS->SetMemorySpaceAttributes (\r
854 RegionStart,\r
855 RegionLength,\r
856 (MemorySpaceMap[Index].Attributes & ~EFI_MEMORY_CACHETYPE_MASK) | (MemorySpaceMap[Index].Capabilities & Attributes)\r
857 );\r
858 }\r
859\r
860 return EFI_SUCCESS;\r
861}\r
862\r
863\r
864/**\r
865 Refreshes the GCD Memory Space attributes according to MTRRs.\r
866\r
867 This function refreshes the GCD Memory Space attributes according to MTRRs.\r
868\r
869**/\r
870VOID\r
871RefreshGcdMemoryAttributes (\r
872 VOID\r
873 )\r
874{\r
875 EFI_STATUS Status;\r
876 UINTN Index;\r
877 UINTN SubIndex;\r
878 UINT64 RegValue;\r
879 EFI_PHYSICAL_ADDRESS BaseAddress;\r
880 UINT64 Length;\r
881 UINT64 Attributes;\r
882 UINT64 CurrentAttributes;\r
883 UINT8 MtrrType;\r
884 UINTN NumberOfDescriptors;\r
885 EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r
886 UINT64 DefaultAttributes;\r
6640eb36 887 VARIABLE_MTRR VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
a47463f2 888 MTRR_FIXED_SETTINGS MtrrFixedSettings;\r
3b9be416 889 UINT32 FirmwareVariableMtrrCount;\r
3b9be416 890\r
947a573a 891 if (!IsMtrrSupported ()) {\r
892 return;\r
893 }\r
894\r
3b9be416 895 FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
5bdfa4e5 896 ASSERT (FirmwareVariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);\r
a47463f2 897\r
898// mIsFlushingGCD = TRUE;\r
899 mIsFlushingGCD = FALSE;\r
900 MemorySpaceMap = NULL;\r
901\r
902 //\r
903 // Initialize the valid bits mask and valid address mask for MTRRs\r
904 //\r
905 InitializeMtrrMask ();\r
906\r
907 //\r
908 // Get the memory attribute of variable MTRRs\r
909 //\r
910 MtrrGetMemoryAttributeInVariableMtrr (\r
911 mValidMtrrBitsMask,\r
912 mValidMtrrAddressMask,\r
913 VariableMtrr\r
914 );\r
915\r
916 //\r
917 // Get the memory space map from GCD\r
918 //\r
919 Status = gDS->GetMemorySpaceMap (\r
920 &NumberOfDescriptors,\r
921 &MemorySpaceMap\r
922 );\r
923 ASSERT_EFI_ERROR (Status);\r
924\r
925 DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (mDefaultMemoryType);\r
926\r
927 //\r
928 // Set default attributes to all spaces.\r
929 //\r
930 for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
931 if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeNonExistent) {\r
932 continue;\r
933 }\r
934 gDS->SetMemorySpaceAttributes (\r
935 MemorySpaceMap[Index].BaseAddress,\r
936 MemorySpaceMap[Index].Length,\r
937 (MemorySpaceMap[Index].Attributes & ~EFI_MEMORY_CACHETYPE_MASK) |\r
938 (MemorySpaceMap[Index].Capabilities & DefaultAttributes)\r
939 );\r
940 }\r
941\r
942 //\r
943 // Go for variable MTRRs with WB attribute\r
944 //\r
3b9be416 945 for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
a47463f2 946 if (VariableMtrr[Index].Valid &&\r
947 VariableMtrr[Index].Type == MTRR_CACHE_WRITE_BACK) {\r
948 SetGcdMemorySpaceAttributes (\r
949 MemorySpaceMap,\r
950 NumberOfDescriptors,\r
951 VariableMtrr[Index].BaseAddress,\r
952 VariableMtrr[Index].Length,\r
953 EFI_MEMORY_WB\r
954 );\r
955 }\r
956 }\r
957 //\r
958 // Go for variable MTRRs with Non-WB attribute\r
959 //\r
3b9be416 960 for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
a47463f2 961 if (VariableMtrr[Index].Valid &&\r
962 VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK) {\r
963 Attributes = GetMemorySpaceAttributeFromMtrrType ((UINT8) VariableMtrr[Index].Type);\r
964 SetGcdMemorySpaceAttributes (\r
965 MemorySpaceMap,\r
966 NumberOfDescriptors,\r
967 VariableMtrr[Index].BaseAddress,\r
968 VariableMtrr[Index].Length,\r
969 Attributes\r
970 );\r
971 }\r
972 }\r
973\r
974 //\r
975 // Go for fixed MTRRs\r
976 //\r
977 Attributes = 0;\r
978 BaseAddress = 0;\r
979 Length = 0;\r
980 MtrrGetFixedMtrr (&MtrrFixedSettings);\r
981 for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) {\r
982 RegValue = MtrrFixedSettings.Mtrr[Index];\r
983 //\r
984 // Check for continuous fixed MTRR sections\r
985 //\r
986 for (SubIndex = 0; SubIndex < 8; SubIndex++) {\r
987 MtrrType = (UINT8) RShiftU64 (RegValue, SubIndex * 8);\r
988 CurrentAttributes = GetMemorySpaceAttributeFromMtrrType (MtrrType);\r
989 if (Length == 0) {\r
990 //\r
991 // A new MTRR attribute begins\r
992 //\r
993 Attributes = CurrentAttributes;\r
994 } else {\r
995 //\r
996 // If fixed MTRR attribute changed, then set memory attribute for previous atrribute\r
997 //\r
998 if (CurrentAttributes != Attributes) {\r
999 SetGcdMemorySpaceAttributes (\r
1000 MemorySpaceMap,\r
1001 NumberOfDescriptors,\r
1002 BaseAddress,\r
1003 Length,\r
1004 Attributes\r
1005 );\r
1006 BaseAddress = mFixedMtrrTable[Index].BaseAddress + mFixedMtrrTable[Index].Length * SubIndex;\r
1007 Length = 0;\r
1008 Attributes = CurrentAttributes;\r
1009 }\r
1010 }\r
1011 Length += mFixedMtrrTable[Index].Length;\r
1012 }\r
1013 }\r
1014 //\r
1015 // Handle the last fixed MTRR region\r
1016 //\r
1017 SetGcdMemorySpaceAttributes (\r
1018 MemorySpaceMap,\r
1019 NumberOfDescriptors,\r
1020 BaseAddress,\r
1021 Length,\r
1022 Attributes\r
1023 );\r
1024\r
1025 //\r
1026 // Free memory space map allocated by GCD service GetMemorySpaceMap ()\r
1027 //\r
1028 if (MemorySpaceMap != NULL) {\r
1029 FreePool (MemorySpaceMap);\r
1030 }\r
1031\r
1032 mIsFlushingGCD = FALSE;\r
1033}\r
1034\r
1e51d595
ED
1035/**\r
1036 Set Interrupt Descriptor Table Handler Address.\r
1037\r
1038 @param Index The Index of the interrupt descriptor table handle.\r
1039 @param Handler Handler address.\r
a47463f2 1040\r
1e51d595 1041**/\r
557b970a 1042VOID\r
1043SetInterruptDescriptorTableHandlerAddress (\r
1044 IN UINTN Index,\r
1045 IN VOID *Handler OPTIONAL\r
1046 )\r
1047{\r
1048 UINTN UintnHandler;\r
1049\r
1050 if (Handler != NULL) {\r
1051 UintnHandler = (UINTN) Handler;\r
1052 } else {\r
1053 UintnHandler = ((UINTN) AsmIdtVector00) + (8 * Index);\r
1054 }\r
1055\r
1056 gIdtTable[Index].Bits.OffsetLow = (UINT16)UintnHandler;\r
1057 gIdtTable[Index].Bits.Reserved_0 = 0;\r
1058 gIdtTable[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
1059 gIdtTable[Index].Bits.OffsetHigh = (UINT16)(UintnHandler >> 16);\r
1060#if defined (MDE_CPU_X64)\r
1061 gIdtTable[Index].Bits.OffsetUpper = (UINT32)(UintnHandler >> 32);\r
1062 gIdtTable[Index].Bits.Reserved_1 = 0;\r
1063#endif\r
1064}\r
1065\r
1066\r
a47463f2 1067/**\r
1068 Initialize Interrupt Descriptor Table for interrupt handling.\r
1069\r
1070**/\r
a47463f2 1071VOID\r
1072InitInterruptDescriptorTable (\r
1073 VOID\r
1074 )\r
1075{\r
557b970a 1076 EFI_STATUS Status;\r
1077 IA32_DESCRIPTOR OldIdtPtr;\r
1078 IA32_IDT_GATE_DESCRIPTOR *OldIdt;\r
1079 UINTN OldIdtSize;\r
1080 VOID *IdtPtrAlignmentBuffer;\r
1081 IA32_DESCRIPTOR *IdtPtr;\r
1082 UINTN Index;\r
1083 UINT16 CurrentCs;\r
1084 VOID *IntHandler;\r
a47463f2 1085\r
1086 SetMem (ExternalVectorTable, sizeof(ExternalVectorTable), 0);\r
1087\r
1088 //\r
557b970a 1089 // Get original IDT address and size.\r
a47463f2 1090 //\r
557b970a 1091 AsmReadIdtr ((IA32_DESCRIPTOR *) &OldIdtPtr);\r
1092\r
1093 if ((OldIdtPtr.Base != 0) && ((OldIdtPtr.Limit & 7) == 7)) {\r
1094 OldIdt = (IA32_IDT_GATE_DESCRIPTOR*) OldIdtPtr.Base;\r
304a39b7 1095 OldIdtSize = (OldIdtPtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR);\r
557b970a 1096 } else {\r
1097 OldIdt = NULL;\r
1098 OldIdtSize = 0;\r
a47463f2 1099 }\r
1100\r
0564ae5e 1101 //\r
557b970a 1102 // Intialize IDT\r
0564ae5e 1103 //\r
557b970a 1104 CurrentCs = AsmReadCs();\r
1105 for (Index = 0; Index < INTERRUPT_VECTOR_NUMBER; Index ++) {\r
1106 //\r
1107 // If the old IDT had a handler for this interrupt, then\r
1108 // preserve it.\r
1109 //\r
1110 if (Index < OldIdtSize) {\r
1111 IntHandler = \r
1112 (VOID*) (\r
1113 OldIdt[Index].Bits.OffsetLow +\r
1114 (OldIdt[Index].Bits.OffsetHigh << 16)\r
1115#if defined (MDE_CPU_X64)\r
1116 + (((UINTN) OldIdt[Index].Bits.OffsetUpper) << 32)\r
1117#endif\r
1118 );\r
1119 } else {\r
1120 IntHandler = NULL;\r
1121 }\r
0564ae5e 1122\r
557b970a 1123 gIdtTable[Index].Bits.Selector = CurrentCs;\r
1124 gIdtTable[Index].Bits.Reserved_0 = 0;\r
1125 gIdtTable[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
1126 SetInterruptDescriptorTableHandlerAddress (Index, IntHandler);\r
0564ae5e 1127 }\r
557b970a 1128\r
a47463f2 1129 //\r
1130 // Load IDT Pointer\r
1131 //\r
1132 IdtPtrAlignmentBuffer = AllocatePool (sizeof (*IdtPtr) + 16);\r
1133 IdtPtr = ALIGN_POINTER (IdtPtrAlignmentBuffer, 16);\r
1134 IdtPtr->Base = (UINT32)(((UINTN)(VOID*) gIdtTable) & (BASE_4GB-1));\r
5b7e61a0 1135 IdtPtr->Limit = (UINT16) (sizeof (gIdtTable) - 1);\r
ea99e00d 1136\r
a47463f2 1137 AsmWriteIdtr (IdtPtr);\r
ea99e00d 1138\r
a47463f2 1139 FreePool (IdtPtrAlignmentBuffer);\r
1140\r
1141 //\r
1142 // Initialize Exception Handlers\r
1143 //\r
62ba7e17 1144 for (Index = OldIdtSize; Index < 32; Index++) {\r
a47463f2 1145 Status = CpuRegisterInterruptHandler (&gCpu, Index, CommonExceptionHandler);\r
1146 ASSERT_EFI_ERROR (Status);\r
1147 }\r
1148\r
1149 //\r
1150 // Set the pointer to the array of C based exception handling routines.\r
1151 //\r
1152 InitializeExternalVectorTablePtr (ExternalVectorTable);\r
1153\r
1154}\r
1155\r
1156\r
1157/**\r
1158 Initialize the state information for the CPU Architectural Protocol.\r
1159\r
1160 @param ImageHandle Image handle this driver.\r
1161 @param SystemTable Pointer to the System Table.\r
1162\r
1163 @retval EFI_SUCCESS Thread can be successfully created\r
1164 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure\r
1165 @retval EFI_DEVICE_ERROR Cannot create the thread\r
1166\r
1167**/\r
1168EFI_STATUS\r
1169EFIAPI\r
1170InitializeCpu (\r
1171 IN EFI_HANDLE ImageHandle,\r
1172 IN EFI_SYSTEM_TABLE *SystemTable\r
1173 )\r
1174{\r
1175 EFI_STATUS Status;\r
1176\r
1177 //\r
1178 // Make sure interrupts are disabled\r
1179 //\r
1180 DisableInterrupts ();\r
1181\r
1182 //\r
1183 // Init GDT for DXE\r
1184 //\r
1185 InitGlobalDescriptorTable ();\r
1186\r
1187 //\r
1188 // Setup IDT pointer, IDT and interrupt entry points\r
1189 //\r
1190 InitInterruptDescriptorTable ();\r
1191\r
1192 //\r
1193 // Install CPU Architectural Protocol\r
1194 //\r
1195 Status = gBS->InstallMultipleProtocolInterfaces (\r
1196 &mCpuHandle,\r
1197 &gEfiCpuArchProtocolGuid, &gCpu,\r
1198 NULL\r
1199 );\r
1200 ASSERT_EFI_ERROR (Status);\r
1201\r
1202 //\r
1203 // Refresh GCD memory space map according to MTRR value.\r
1204 //\r
1205 RefreshGcdMemoryAttributes ();\r
1206\r
1207 return Status;\r
1208}\r
1209\r