]>
Commit | Line | Data |
---|---|---|
65e79f93 JF |
1 | /** @file |
2 | CPU PEI Module installs CPU Multiple Processor PPI. | |
3 | ||
4 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> | |
5 | This program and the accompanying materials | |
6 | are licensed and made available under the terms and conditions of the BSD License | |
7 | which accompanies this distribution. The full text of the license may be found at | |
8 | http://opensource.org/licenses/bsd-license.php | |
9 | ||
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
12 | ||
13 | **/ | |
14 | ||
15 | #include "CpuMpPei.h" | |
16 | ||
f9d30595 JF |
17 | // |
18 | // Global Descriptor Table (GDT) | |
19 | // | |
20 | GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT mGdtEntries[] = { | |
21 | /* selector { Global Segment Descriptor } */ | |
22 | /* 0x00 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //null descriptor | |
23 | /* 0x08 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear data segment descriptor | |
24 | /* 0x10 */ {{0xffff, 0, 0, 0xf, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear code segment descriptor | |
25 | /* 0x18 */ {{0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor | |
26 | /* 0x20 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system code segment descriptor | |
27 | /* 0x28 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor | |
28 | /* 0x30 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor | |
29 | /* 0x38 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 1, 0, 1, 0}}, //system code segment descriptor | |
30 | /* 0x40 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor | |
31 | }; | |
32 | ||
33 | // | |
34 | // IA32 Gdt register | |
35 | // | |
36 | GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR mGdt = { | |
37 | sizeof (mGdtEntries) - 1, | |
38 | (UINTN) mGdtEntries | |
39 | }; | |
40 | ||
05e107f8 JF |
41 | /** |
42 | Get available system memory below 1MB by specified size. | |
43 | ||
44 | @param WakeupBufferSize Wakeup buffer size required | |
45 | ||
46 | @retval other Return wakeup buffer address below 1MB. | |
47 | @retval -1 Cannot find free memory below 1MB. | |
48 | **/ | |
49 | UINTN | |
50 | GetWakeupBuffer ( | |
51 | IN UINTN WakeupBufferSize | |
52 | ) | |
53 | { | |
54 | EFI_PEI_HOB_POINTERS Hob; | |
55 | UINTN WakeupBufferStart; | |
56 | UINTN WakeupBufferEnd; | |
57 | ||
58 | // | |
59 | // Get the HOB list for processing | |
60 | // | |
61 | Hob.Raw = GetHobList (); | |
62 | ||
63 | // | |
64 | // Collect memory ranges | |
65 | // | |
66 | while (!END_OF_HOB_LIST (Hob)) { | |
67 | if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { | |
68 | if ((Hob.ResourceDescriptor->PhysicalStart < BASE_1MB) && | |
69 | (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && | |
70 | ((Hob.ResourceDescriptor->ResourceAttribute & | |
71 | (EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | | |
72 | EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED | | |
73 | EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED | |
74 | )) == 0) | |
75 | ) { | |
76 | // | |
77 | // Need memory under 1MB to be collected here | |
78 | // | |
79 | WakeupBufferEnd = (UINTN) (Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength); | |
80 | if (WakeupBufferEnd > BASE_1MB) { | |
81 | // | |
82 | // Wakeup buffer should be under 1MB | |
83 | // | |
84 | WakeupBufferEnd = BASE_1MB; | |
85 | } | |
86 | // | |
87 | // Wakeup buffer should be aligned on 4KB | |
88 | // | |
89 | WakeupBufferStart = (WakeupBufferEnd - WakeupBufferSize) & ~(SIZE_4KB - 1); | |
90 | if (WakeupBufferStart < Hob.ResourceDescriptor->PhysicalStart) { | |
91 | continue; | |
92 | } | |
93 | // | |
94 | // Create a memory allocation HOB. | |
95 | // | |
96 | BuildMemoryAllocationHob ( | |
97 | WakeupBufferStart, | |
98 | WakeupBufferSize, | |
99 | EfiBootServicesData | |
100 | ); | |
101 | return WakeupBufferStart; | |
102 | } | |
103 | } | |
104 | // | |
105 | // Find the next HOB | |
106 | // | |
107 | Hob.Raw = GET_NEXT_HOB (Hob); | |
108 | } | |
109 | ||
110 | return (UINTN) -1; | |
111 | } | |
65e79f93 JF |
112 | |
113 | /** | |
114 | The Entry point of the MP CPU PEIM. | |
115 | ||
116 | This function will wakeup APs and collect CPU AP count and install the | |
117 | Mp Service Ppi. | |
118 | ||
119 | @param FileHandle Handle of the file being invoked. | |
120 | @param PeiServices Describes the list of possible PEI Services. | |
121 | ||
122 | @retval EFI_SUCCESS MpServicePpi is installed successfully. | |
123 | ||
124 | **/ | |
125 | EFI_STATUS | |
126 | EFIAPI | |
127 | CpuMpPeimInit ( | |
128 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
129 | IN CONST EFI_PEI_SERVICES **PeiServices | |
130 | ) | |
131 | { | |
132 | ||
133 | ||
f9d30595 JF |
134 | // |
135 | // Load new GDT table on BSP | |
136 | // | |
137 | AsmInitializeGdt (&mGdt); | |
65e79f93 JF |
138 | |
139 | return EFI_SUCCESS; | |
140 | } |