]> git.proxmox.com Git - mirror_edk2.git/blame - QuarkPlatformPkg/Platform/Pei/PlatformInit/MemoryCallback.c
QuarkPlatformPkg: Add new package for Galileo boards
[mirror_edk2.git] / QuarkPlatformPkg / Platform / Pei / PlatformInit / MemoryCallback.c
CommitLineData
b303605e
MK
1/** @file\r
2This file includes a memory call back function notified when MRC is done,\r
3following action is performed in this file,\r
4 1. ICH initialization after MRC.\r
5 2. SIO initialization.\r
6 3. Install ResetSystem and FinvFv PPI.\r
7 4. Set MTRR for PEI\r
8 5. Create FV HOB and Flash HOB\r
9\r
10Copyright (c) 2013 Intel Corporation.\r
11\r
12This program and the accompanying materials\r
13are licensed and made available under the terms and conditions of the BSD License\r
14which accompanies this distribution. The full text of the license may be found at\r
15http://opensource.org/licenses/bsd-license.php\r
16\r
17THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
19\r
20**/\r
21\r
22\r
23#include "CommonHeader.h"\r
24\r
25#include "PlatformEarlyInit.h"\r
26\r
27extern EFI_PEI_PPI_DESCRIPTOR mPpiStall[];\r
28\r
29EFI_PEI_RESET_PPI mResetPpi = { ResetSystem };\r
30\r
31EFI_PEI_PPI_DESCRIPTOR mPpiList[1] = {\r
32 {\r
33 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
34 &gEfiPeiResetPpiGuid,\r
35 &mResetPpi\r
36 }\r
37};\r
38\r
39/**\r
40 This function reset the entire platform, including all processor and devices, and\r
41 reboots the system.\r
42\r
43 @param PeiServices General purpose services available to every PEIM.\r
44\r
45 @retval EFI_SUCCESS if it completed successfully.\r
46**/\r
47EFI_STATUS\r
48EFIAPI\r
49ResetSystem (\r
50 IN CONST EFI_PEI_SERVICES **PeiServices\r
51 )\r
52{\r
53 ResetCold();\r
54 return EFI_SUCCESS;\r
55}\r
56\r
57/**\r
58 This function provides a blocking stall for reset at least the given number of microseconds\r
59 stipulated in the final argument.\r
60\r
61 @param PeiServices General purpose services available to every PEIM.\r
62\r
63 @param this Pointer to the local data for the interface.\r
64\r
65 @param Microseconds number of microseconds for which to stall.\r
66\r
67 @retval EFI_SUCCESS the function provided at least the required stall.\r
68**/\r
69EFI_STATUS\r
70EFIAPI\r
71Stall (\r
72 IN CONST EFI_PEI_SERVICES **PeiServices,\r
73 IN CONST EFI_PEI_STALL_PPI *This,\r
74 IN UINTN Microseconds\r
75 )\r
76{\r
77 MicroSecondDelay (Microseconds);\r
78 return EFI_SUCCESS;\r
79}\r
80\r
81\r
82/**\r
83 This function will be called when MRC is done.\r
84\r
85 @param PeiServices General purpose services available to every PEIM.\r
86\r
87 @param NotifyDescriptor Information about the notify event..\r
88\r
89 @param Ppi The notify context.\r
90\r
91 @retval EFI_SUCCESS If the function completed successfully.\r
92**/\r
93EFI_STATUS\r
94EFIAPI\r
95MemoryDiscoveredPpiNotifyCallback (\r
96 IN EFI_PEI_SERVICES **PeiServices,\r
97 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
98 IN VOID *Ppi\r
99 )\r
100{\r
101 EFI_STATUS Status;\r
102 EFI_BOOT_MODE BootMode;\r
103 UINT64 MemoryLength;\r
104 EFI_SMRAM_DESCRIPTOR *SmramDescriptor;\r
105 UINTN NumSmramRegions;\r
106 UINT32 RmuMainBaseAddress;\r
107 UINT32 RegData32;\r
108 UINT8 CpuAddressWidth;\r
109 UINT32 RegEax;\r
110 MTRR_SETTINGS MtrrSettings;\r
111\r
112 DEBUG ((EFI_D_INFO, "Platform PEIM Memory Callback\n"));\r
113\r
114 NumSmramRegions = 0;\r
115 SmramDescriptor = NULL;\r
116 RmuMainBaseAddress = 0;\r
117\r
118 PERF_START (NULL, "SetCache", NULL, 0);\r
119\r
120 InfoPostInstallMemory (&RmuMainBaseAddress, &SmramDescriptor, &NumSmramRegions);\r
121 ASSERT (SmramDescriptor != NULL);\r
122 ASSERT (RmuMainBaseAddress != 0);\r
123\r
124 MemoryLength = ((UINT64) RmuMainBaseAddress) + 0x10000;\r
125\r
126 Status = PeiServicesGetBootMode (&BootMode);\r
127 ASSERT_EFI_ERROR (Status);\r
128\r
129 //\r
130 // Get current MTRR settings\r
131 //\r
132 MtrrGetAllMtrrs (&MtrrSettings);\r
133\r
134 //\r
135 // Set all DRAM cachability to CacheWriteBack\r
136 //\r
137 Status = MtrrSetMemoryAttributeInMtrrSettings (&MtrrSettings, 0, MemoryLength, CacheWriteBack);\r
138 ASSERT_EFI_ERROR (Status);\r
139\r
140 //\r
141 // RTC:28208 - System hang/crash when entering probe mode(ITP) when relocating SMBASE\r
142 // Workaround to make default SMRAM UnCachable\r
143 //\r
144 Status = MtrrSetMemoryAttributeInMtrrSettings (&MtrrSettings, 0x30000, SIZE_64KB, CacheUncacheable);\r
145 ASSERT_EFI_ERROR (Status);\r
146\r
147 //\r
148 // Set new MTRR settings\r
149 //\r
150 MtrrSetAllMtrrs (&MtrrSettings);\r
151\r
152 PERF_END (NULL, "SetCache", NULL, 0);\r
153\r
154 //\r
155 // Install PeiReset for PeiResetSystem service\r
156 //\r
157 Status = PeiServicesInstallPpi (&mPpiList[0]);\r
158 ASSERT_EFI_ERROR (Status);\r
159\r
160 //\r
161 // Do QNC initialization after MRC\r
162 //\r
163 PeiQNCPostMemInit ();\r
164\r
165 Status = PeiServicesInstallPpi (&mPpiStall[0]);\r
166 ASSERT_EFI_ERROR (Status);\r
167\r
168 //\r
169 // Set E000/F000 Routing\r
170 //\r
171 RegData32 = QNCPortRead (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC);\r
172 RegData32 |= (BIT2|BIT1);\r
173 QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC, RegData32);\r
174\r
175 if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
176 Status = PeimInitializeRecovery (PeiServices);\r
177 ASSERT_EFI_ERROR (Status);\r
178 } else if (BootMode == BOOT_ON_S3_RESUME) {\r
179 return EFI_SUCCESS;\r
180 } else {\r
181 PeiServicesInstallFvInfoPpi (\r
182 NULL,\r
183 (VOID *) (UINTN) PcdGet32 (PcdFlashFvMainBase),\r
184 PcdGet32 (PcdFlashFvMainSize),\r
185 NULL,\r
186 NULL\r
187 );\r
188\r
189 //\r
190 // Publish the FVMAIN FV so the DXE Phase can dispatch drivers from this FV\r
191 // and produce Load File Protocols for UEFI Applications in this FV.\r
192 //\r
193 BuildFvHob (\r
194 PcdGet32 (PcdFlashFvMainBase),\r
195 PcdGet32 (PcdFlashFvMainSize)\r
196 );\r
197\r
198 //\r
199 // Publish the Payload FV so the DXE Phase can dispatch drivers from this FV\r
200 // and produce Load File Protocols for UEFI Applications in this FV.\r
201 //\r
202 BuildFvHob (\r
203 PcdGet32 (PcdFlashFvPayloadBase),\r
204 PcdGet32 (PcdFlashFvPayloadSize)\r
205 );\r
206 }\r
207\r
208 //\r
209 // Build flash HOB, it's going to be used by GCD and E820 building\r
210 // Map full SPI flash decode range (regardless of smaller SPI flash parts installed)\r
211 //\r
212 BuildResourceDescriptorHob (\r
213 EFI_RESOURCE_FIRMWARE_DEVICE,\r
214 (EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
215 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
216 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),\r
217 (SIZE_4GB - SIZE_8MB),\r
218 SIZE_8MB\r
219 );\r
220\r
221 //\r
222 // Create a CPU hand-off information\r
223 //\r
224 CpuAddressWidth = 32;\r
225 AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL);\r
226 if (RegEax >= CPUID_VIR_PHY_ADDRESS_SIZE) {\r
227 AsmCpuid (CPUID_VIR_PHY_ADDRESS_SIZE, &RegEax, NULL, NULL, NULL);\r
228 CpuAddressWidth = (UINT8) (RegEax & 0xFF);\r
229 }\r
230 DEBUG ((EFI_D_INFO, "CpuAddressWidth: %d\n", CpuAddressWidth));\r
231\r
232 BuildCpuHob (CpuAddressWidth, 16);\r
233\r
234 ASSERT_EFI_ERROR (Status);\r
235\r
236 return Status;\r
237}\r