]> git.proxmox.com Git - mirror_edk2.git/blame - QuarkPlatformPkg/Platform/Pei/PlatformInit/PlatformEarlyInit.c
QuarkPlatformPkg/ForceRecovery: Add UEFI application to force recovery
[mirror_edk2.git] / QuarkPlatformPkg / Platform / Pei / PlatformInit / PlatformEarlyInit.c
CommitLineData
b303605e
MK
1/** @file\r
2This PEIM initialize platform for MRC, following action is performed,\r
31. Initizluize GMCH\r
42. Detect boot mode\r
53. Detect video adapter to determine whether we need pre allocated memory\r
64. Calls MRC to initialize memory and install a PPI notify to do post memory initialization.\r
7This file contains the main entrypoint of the PEIM.\r
8\r
406d8575 9Copyright (c) 2013 - 2016 Intel Corporation.\r
b303605e
MK
10\r
11This program and the accompanying materials\r
12are licensed and made available under the terms and conditions of the BSD License\r
13which accompanies this distribution. The full text of the license may be found at\r
14http://opensource.org/licenses/bsd-license.php\r
15\r
16THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
17WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
18\r
19**/\r
20\r
21\r
22#include "CommonHeader.h"\r
23#include "PlatformEarlyInit.h"\r
24#include "PeiFvSecurity.h"\r
25\r
26EFI_STATUS\r
27EFIAPI\r
28EndOfPeiSignalPpiNotifyCallback (\r
29 IN EFI_PEI_SERVICES **PeiServices,\r
30 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
31 IN VOID *Ppi\r
32 );\r
33\r
34//\r
35// Function prototypes to routines implemented in other source modules\r
36// within this component.\r
37//\r
38\r
39EFI_STATUS\r
40EFIAPI\r
41PlatformErratasPostMrc (\r
42 VOID\r
43 );\r
44\r
45//\r
46// The global indicator, the FvFileLoader callback will modify it to TRUE after loading PEIM into memory\r
47//\r
48BOOLEAN ImageInMemory = FALSE;\r
49\r
50BOARD_LEGACY_GPIO_CONFIG mBoardLegacyGpioConfigTable[] = { PLATFORM_LEGACY_GPIO_TABLE_DEFINITION };\r
51UINTN mBoardLegacyGpioConfigTableLen = (sizeof(mBoardLegacyGpioConfigTable) / sizeof(BOARD_LEGACY_GPIO_CONFIG));\r
52BOARD_GPIO_CONTROLLER_CONFIG mBoardGpioControllerConfigTable[] = { PLATFORM_GPIO_CONTROLLER_CONFIG_DEFINITION };\r
53UINTN mBoardGpioControllerConfigTableLen = (sizeof(mBoardGpioControllerConfigTable) / sizeof(BOARD_GPIO_CONTROLLER_CONFIG));\r
54UINT8 ChipsetDefaultMac [6] = {0xff,0xff,0xff,0xff,0xff,0xff};\r
55\r
56EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[1] = {\r
57 {\r
58 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
59 &gEfiPeiMasterBootModePpiGuid,\r
60 NULL\r
61 }\r
62};\r
63\r
64EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList[1] = {\r
65 {\r
66 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
67 &gEfiPeiMemoryDiscoveredPpiGuid,\r
68 MemoryDiscoveredPpiNotifyCallback\r
69 }\r
70};\r
71\r
72EFI_PEI_NOTIFY_DESCRIPTOR mEndOfPeiSignalPpiNotifyList[1] = {\r
73 {\r
74 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
75 &gEfiEndOfPeiSignalPpiGuid,\r
76 EndOfPeiSignalPpiNotifyCallback\r
77 }\r
78};\r
79\r
80EFI_PEI_STALL_PPI mStallPpi = {\r
81 PEI_STALL_RESOLUTION,\r
82 Stall\r
83};\r
84\r
85EFI_PEI_PPI_DESCRIPTOR mPpiStall[1] = {\r
86 {\r
87 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
88 &gEfiPeiStallPpiGuid,\r
89 &mStallPpi\r
90 }\r
91};\r
92\r
93/**\r
94 Set Mac address on chipset ethernet device.\r
95\r
96 @param Bus PCI Bus number of chipset ethernet device.\r
97 @param Device Device number of chipset ethernet device.\r
98 @param Func PCI Function number of chipset ethernet device.\r
99 @param MacAddr MAC Address to set.\r
100\r
101**/\r
102VOID\r
103EFIAPI\r
104SetLanControllerMacAddr (\r
105 IN CONST UINT8 Bus,\r
106 IN CONST UINT8 Device,\r
107 IN CONST UINT8 Func,\r
108 IN CONST UINT8 *MacAddr,\r
109 IN CONST UINT32 Bar0\r
110 )\r
111{\r
112 UINT32 Data32;\r
113 UINT16 PciVid;\r
114 UINT16 PciDid;\r
115 UINT32 Addr;\r
116 UINT32 MacVer;\r
117 volatile UINT8 *Wrote;\r
118 UINT32 DevPcieAddr;\r
119 UINT16 SaveCmdReg;\r
120 UINT32 SaveBarReg;\r
121\r
122 DevPcieAddr = PCI_LIB_ADDRESS (\r
123 Bus,\r
124 Device,\r
125 Func,\r
126 0\r
127 );\r
128\r
129 //\r
130 // Do nothing if not a supported device.\r
131 //\r
132 PciVid = PciRead16 (DevPcieAddr + PCI_VENDOR_ID_OFFSET);\r
133 PciDid = PciRead16 (DevPcieAddr + PCI_DEVICE_ID_OFFSET);\r
134 if((PciVid != V_IOH_MAC_VENDOR_ID) || (PciDid != V_IOH_MAC_DEVICE_ID)) {\r
135 return;\r
136 }\r
137\r
138 //\r
139 // Save current settings for PCI CMD/BAR registers\r
140 //\r
141 SaveCmdReg = PciRead16 (DevPcieAddr + PCI_COMMAND_OFFSET);\r
142 SaveBarReg = PciRead32 (DevPcieAddr + R_IOH_MAC_MEMBAR);\r
143\r
144 //\r
145 // Use predefined tempory memory resource\r
146 //\r
147 PciWrite32 ( DevPcieAddr + R_IOH_MAC_MEMBAR, Bar0);\r
148 PciWrite8 ( DevPcieAddr + PCI_COMMAND_OFFSET, EFI_PCI_COMMAND_MEMORY_SPACE);\r
149\r
150 Addr = Bar0 + R_IOH_MAC_GMAC_REG_8;\r
151 MacVer = *((volatile UINT32 *) (UINTN)(Addr));\r
152\r
153 DEBUG ((EFI_D_INFO, "Ioh MAC [B:%d, D:%d, F:%d] VER:%04x ADDR:",\r
154 (UINTN) Bus,\r
155 (UINTN) Device,\r
156 (UINTN) Func,\r
157 (UINTN) MacVer\r
158 ));\r
159\r
160 //\r
161 // Set MAC Address0 Low Register (GMAC_REG_17) ADDRLO bits.\r
162 //\r
163 Addr = Bar0 + R_IOH_MAC_GMAC_REG_17;\r
164 Data32 = *((UINT32 *) (UINTN)(&MacAddr[0]));\r
165 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
166 Wrote = (volatile UINT8 *) (UINTN)(Addr);\r
167 DEBUG ((EFI_D_INFO, "%02x-%02x-%02x-%02x-",\r
168 (UINTN) Wrote[0],\r
169 (UINTN) Wrote[1],\r
170 (UINTN) Wrote[2],\r
171 (UINTN) Wrote[3]\r
172 ));\r
173\r
174 //\r
175 // Set MAC Address0 High Register (GMAC_REG_16) ADDRHI bits\r
176 // and Address Enable (AE) bit.\r
177 //\r
178 Addr = Bar0 + R_IOH_MAC_GMAC_REG_16;\r
179 Data32 =\r
180 ((UINT32) MacAddr[4]) |\r
181 (((UINT32)MacAddr[5]) << 8) |\r
182 B_IOH_MAC_AE;\r
183 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
184 Wrote = (volatile UINT8 *) (UINTN)(Addr);\r
185\r
186 DEBUG ((EFI_D_INFO, "%02x-%02x\n", (UINTN) Wrote[0], (UINTN) Wrote[1]));\r
187\r
188 //\r
189 // Restore settings for PCI CMD/BAR registers\r
190 //\r
191 PciWrite32 ((DevPcieAddr + R_IOH_MAC_MEMBAR), SaveBarReg);\r
192 PciWrite16 (DevPcieAddr + PCI_COMMAND_OFFSET, SaveCmdReg);\r
193}\r
194\r
406d8575
MK
195/**\r
196 Initialize state of I2C GPIO expanders.\r
197\r
198 @param PlatformType Platform type for GPIO expander init.\r
199\r
200**/\r
201EFI_STATUS\r
202EarlyPlatformConfigGpioExpanders (\r
203 IN CONST EFI_PLATFORM_TYPE PlatformType\r
204 )\r
205{\r
206 EFI_STATUS Status;\r
207 EFI_I2C_DEVICE_ADDRESS I2CSlaveAddress;\r
208 UINTN Length;\r
209 UINTN ReadLength;\r
210 UINT8 Buffer[2];\r
211\r
212 //\r
213 // Configure GPIO expanders for Galileo Gen 2\r
214 // Route I2C pins to Arduino header\r
215 // Set all GPIO expander pins connected to the Reset Button as inputs\r
216 //\r
217 if (PlatformType == GalileoGen2) {\r
218 //\r
219 // Configure AMUX1_IN (EXP2.P1_4) as an output\r
220 //\r
221 PlatformPcal9555GpioSetDir (\r
222 GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR, // IO Expander 2.\r
223 12, // P1-4.\r
224 FALSE // Configure as output\r
225 );\r
226\r
227 //\r
228 // Set AMUX1_IN(EXP2.P1_4) low to route I2C to Arduino Shield connector\r
229 //\r
230 PlatformPcal9555GpioSetLevel (\r
231 GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR, // IO Expander 2.\r
232 12, // P1-4. \r
233 FALSE // Set pin low\r
234 );\r
235\r
236 //\r
237 // Configure Reset Button(EXP1.P1_7) as an input\r
238 //\r
239 PlatformPcal9555GpioSetDir (\r
240 GALILEO_GEN2_IOEXP1_7BIT_SLAVE_ADDR, // IO Expander 1.\r
241 15, // P1-7.\r
242 TRUE\r
243 );\r
244\r
245 //\r
246 // Disable pullup on Reset Button(EXP1.P1_7)\r
247 //\r
248 PlatformPcal9555GpioDisablePull (\r
249 GALILEO_GEN2_IOEXP1_7BIT_SLAVE_ADDR, // IO Expander 1.\r
250 15 // P1-7.\r
251 );\r
252\r
253 //\r
254 // Configure Reset Button(EXP2.P1_7) as an input\r
255 //\r
256 PlatformPcal9555GpioSetDir (\r
257 GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR, // IO Expander 2.\r
258 15, // P1-7.\r
259 TRUE\r
260 );\r
261\r
262 //\r
263 // Disable pullup on Reset Button(EXP2.P1_7)\r
264 //\r
265 PlatformPcal9555GpioDisablePull (\r
266 GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR, // IO Expander 2.\r
267 15 // P1-7.\r
268 );\r
269 }\r
270\r
271 //\r
272 // Configure GPIO expanders for Galileo Gen 2\r
273 // Set all GPIO expander pins connected to the Reset Button as inputs\r
274 // Route I2C pins to Arduino header\r
275 //\r
276 if (PlatformType == Galileo) {\r
277 //\r
278 // Detect the I2C Slave Address of the GPIO Expander\r
279 //\r
280 if (PlatformLegacyGpioGetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, GALILEO_DETERMINE_IOEXP_SLA_RESUMEWELL_GPIO)) {\r
281 I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2HI_7BIT_SLAVE_ADDR;\r
282 } else {\r
283 I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2LO_7BIT_SLAVE_ADDR;\r
284 }\r
285 DEBUG ((EFI_D_INFO, "Galileo GPIO Expender Slave Address = %02x\n", I2CSlaveAddress.I2CDeviceAddress));\r
286\r
287 //\r
288 // Set I2C_MUX (GPORT1_BIT5) low to route I2C to Arduino Shield connector\r
289 //\r
290\r
291 //\r
292 // Select GPIO Expander GPORT1\r
293 //\r
294 Length = 2;\r
295 Buffer[0] = 0x18; //sub-address\r
296 Buffer[1] = 0x01; //data\r
297 Status = I2cWriteMultipleByte (\r
298 I2CSlaveAddress,\r
299 EfiI2CSevenBitAddrMode,\r
300 &Length,\r
301 &Buffer\r
302 );\r
303 ASSERT_EFI_ERROR (Status);\r
304\r
305 //\r
306 // Read "Pin Direction" of GPIO Expander GPORT1\r
307 //\r
308 Length = 1;\r
309 ReadLength = 1;\r
310 Buffer[1] = 0x1C;\r
311 Status = I2cReadMultipleByte (\r
312 I2CSlaveAddress,\r
313 EfiI2CSevenBitAddrMode,\r
314 &Length,\r
315 &ReadLength,\r
316 &Buffer[1]\r
317 );\r
318 ASSERT_EFI_ERROR (Status);\r
319\r
320 //\r
321 // Configure GPIO Expander GPORT1_BIT5 as an output\r
322 //\r
323 Length = 2;\r
324 Buffer[0] = 0x1C; //sub-address\r
325 Buffer[1] = (UINT8)(Buffer[1] & (~BIT5)); //data\r
326\r
327 Status = I2cWriteMultipleByte (\r
328 I2CSlaveAddress,\r
329 EfiI2CSevenBitAddrMode,\r
330 &Length,\r
331 &Buffer\r
332 );\r
333 ASSERT_EFI_ERROR (Status);\r
334\r
335 //\r
336 // Set GPIO Expander GPORT1_BIT5 low\r
337 //\r
338 Length = 2;\r
339 Buffer[0] = 0x09; //sub-address\r
340 Buffer[1] = (UINT8)(~BIT5); //data\r
341\r
342 Status = I2cWriteMultipleByte (\r
343 I2CSlaveAddress,\r
344 EfiI2CSevenBitAddrMode,\r
345 &Length,\r
346 &Buffer\r
347 );\r
348 ASSERT_EFI_ERROR (Status);\r
349\r
350 //\r
351 // Configure RESET_N_SHLD (GPORT5_BIT0) and SW_RESET_N_SHLD (GPORT5_BIT1) as inputs\r
352 //\r
353\r
354 //\r
355 // Select GPIO Expander GPORT5\r
356 //\r
357 Length = 2;\r
358 Buffer[0] = 0x18;\r
359 Buffer[1] = 0x05;\r
360 Status = I2cWriteMultipleByte (\r
361 I2CSlaveAddress,\r
362 EfiI2CSevenBitAddrMode,\r
363 &Length,\r
364 &Buffer\r
365 );\r
366 ASSERT_EFI_ERROR (Status);\r
367\r
368 //\r
369 // Read "Pin Direction" of GPIO Expander GPORT5\r
370 //\r
371 Length = 1;\r
372 ReadLength = 1;\r
373 Buffer[1] = 0x1C;\r
374 Status = I2cReadMultipleByte (\r
375 I2CSlaveAddress,\r
376 EfiI2CSevenBitAddrMode,\r
377 &Length,\r
378 &ReadLength,\r
379 &Buffer[1]\r
380 );\r
381 ASSERT_EFI_ERROR (Status);\r
382\r
383 //\r
384 // Configure GPIO Expander GPORT5_BIT0 and GPORT5_BIT1 as inputs\r
385 //\r
386 Length = 2;\r
387 Buffer[0] = 0x1C;\r
388 Buffer[1] = Buffer[1] | BIT0 | BIT1;\r
389 Status = I2cWriteMultipleByte (\r
390 I2CSlaveAddress,\r
391 EfiI2CSevenBitAddrMode,\r
392 &Length,\r
393 &Buffer\r
394 );\r
395 ASSERT_EFI_ERROR (Status);\r
396 }\r
397\r
398 return EFI_SUCCESS;\r
399}\r
400\r
b303605e
MK
401/**\r
402 This is the entrypoint of PEIM\r
403\r
404 @param FileHandle Handle of the file being invoked.\r
405 @param PeiServices Describes the list of possible PEI Services.\r
406\r
407 @retval EFI_SUCCESS if it completed successfully.\r
408**/\r
409EFI_STATUS\r
410EFIAPI\r
411PeiInitPlatform (\r
412 IN EFI_PEI_FILE_HANDLE FileHandle,\r
413 IN CONST EFI_PEI_SERVICES **PeiServices\r
414 )\r
415{\r
416 EFI_STATUS Status;\r
417 EFI_BOOT_MODE BootMode;\r
418 EFI_PEI_STALL_PPI *StallPpi;\r
419 EFI_PEI_PPI_DESCRIPTOR *StallPeiPpiDescriptor;\r
420 EFI_FV_FILE_INFO FileInfo;\r
421 EFI_PLATFORM_TYPE PlatformType;\r
422\r
423 PlatformType = (EFI_PLATFORM_TYPE)PcdGet16 (PcdPlatformType);\r
424\r
425 //\r
426 // Initialize Firmware Volume security.\r
427 // This must be done before any firmware volume accesses (excl. BFV)\r
428 //\r
429 Status = PeiInitializeFvSecurity();\r
430 ASSERT_EFI_ERROR (Status);\r
431\r
432 //\r
433 // Do any early platform specific initialization.\r
434 //\r
435 EarlyPlatformInit ();\r
436\r
437 //\r
438 // This is a second path on entry, in recovery boot path the Stall PPI need to be memory-based\r
439 // to improve recovery performance.\r
440 //\r
441 Status = PeiServicesFfsGetFileInfo (FileHandle, &FileInfo);\r
442 ASSERT_EFI_ERROR (Status);\r
443 //\r
444 // The follow conditional check only works for memory-mapped FFS,\r
445 // so we ASSERT that the file is really a MM FFS.\r
446 //\r
447 ASSERT (FileInfo.Buffer != NULL);\r
448 if (!(((UINTN) FileInfo.Buffer <= (UINTN) PeiInitPlatform) &&\r
449 ((UINTN) PeiInitPlatform <= (UINTN) FileInfo.Buffer + FileInfo.BufferSize))) {\r
450 //\r
451 // Now that module in memory, update the\r
452 // PPI that describes the Stall to other modules\r
453 //\r
454 Status = PeiServicesLocatePpi (\r
455 &gEfiPeiStallPpiGuid,\r
456 0,\r
457 &StallPeiPpiDescriptor,\r
458 (VOID **) &StallPpi\r
459 );\r
460\r
461 if (!EFI_ERROR (Status)) {\r
462\r
463 Status = PeiServicesReInstallPpi (\r
464 StallPeiPpiDescriptor,\r
465 &mPpiStall[0]\r
466 );\r
467 } else {\r
468\r
469 Status = PeiServicesInstallPpi (&mPpiStall[0]);\r
470 }\r
471 return Status;\r
472 }\r
473\r
474 //\r
475 // Initialize System Phys\r
476 //\r
477\r
478 // Program USB Phy\r
479 InitializeUSBPhy();\r
480\r
481 //\r
482 // Do platform specific logic to create a boot mode\r
483 //\r
484 Status = UpdateBootMode ((EFI_PEI_SERVICES**)PeiServices, &BootMode);\r
485 ASSERT_EFI_ERROR (Status);\r
486\r
487 //\r
488 // Signal possible dependent modules that there has been a\r
489 // final boot mode determination\r
490 //\r
491 if (!EFI_ERROR(Status)) {\r
492 Status = PeiServicesInstallPpi (&mPpiBootMode[0]);\r
493 ASSERT_EFI_ERROR (Status);\r
494 }\r
495\r
496 if (BootMode != BOOT_ON_S3_RESUME) {\r
497 QNCClearSmiAndWake ();\r
498 }\r
499\r
500 DEBUG ((EFI_D_INFO, "MRC Entry\n"));\r
501 MemoryInit ((EFI_PEI_SERVICES**)PeiServices);\r
502\r
503 //\r
504 // Do Early PCIe init.\r
505 //\r
506 DEBUG ((EFI_D_INFO, "Early PCIe controller initialization\n"));\r
507 PlatformPciExpressEarlyInit (PlatformType);\r
508\r
509\r
510 DEBUG ((EFI_D_INFO, "Platform Erratas After MRC\n"));\r
511 PlatformErratasPostMrc ();\r
512\r
406d8575
MK
513 //\r
514 //\r
515 //\r
516 DEBUG ((EFI_D_INFO, "EarlyPlatformConfigGpioExpanders ()\n"));\r
517 EarlyPlatformConfigGpioExpanders (PlatformType);\r
518\r
b303605e
MK
519 //\r
520 // Now that all of the pre-permanent memory activities have\r
521 // been taken care of, post a call-back for the permanent-memory\r
522 // resident services, such as HOB construction.\r
523 // PEI Core will switch stack after this PEIM exit. After that the MTRR\r
524 // can be set.\r
525 //\r
526 Status = PeiServicesNotifyPpi (&mMemoryDiscoveredNotifyList[0]);\r
527 ASSERT_EFI_ERROR (Status);\r
528/*\r
529\r
530 if (BootMode != BOOT_ON_S3_RESUME) {\r
531 Status = PeiServicesNotifyPpi (mEndOfPeiSignalPpiNotifyList);\r
532 ASSERT_EFI_ERROR (Status);\r
533 }\r
534*/\r
535 if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
536 PeiServicesRegisterForShadow (FileHandle);\r
537 }\r
538\r
539 return Status;\r
540}\r
541\r
542EFI_STATUS\r
543EFIAPI\r
544EndOfPeiSignalPpiNotifyCallback (\r
545 IN EFI_PEI_SERVICES **PeiServices,\r
546 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
547 IN VOID *Ppi\r
548 )\r
549{\r
550 EFI_STATUS Status;\r
551\r
552 DEBUG ((EFI_D_INFO, "End of PEI Signal Callback\n"));\r
553\r
554 //\r
555 // Restore the flash region to be UC\r
556 // for both normal boot as we build a Resource Hob to\r
557 // describe this region as UC to DXE core.\r
558 //\r
559 WriteBackInvalidateDataCacheRange (\r
560 (VOID *) (UINTN) PcdGet32 (PcdFlashAreaBaseAddress),\r
561 PcdGet32 (PcdFlashAreaSize)\r
562 );\r
563\r
564 Status = MtrrSetMemoryAttribute (PcdGet32 (PcdFlashAreaBaseAddress), PcdGet32 (PcdFlashAreaSize), CacheUncacheable);\r
565 ASSERT_EFI_ERROR (Status);\r
566\r
567 return EFI_SUCCESS;\r
568}\r
569\r
570/**\r
571 This function will initialize USB Phy registers associated with QuarkSouthCluster.\r
572\r
573 @param VOID No Argument\r
574\r
575 @retval EFI_SUCCESS All registers have been initialized\r
576**/\r
577VOID\r
578EFIAPI\r
579InitializeUSBPhy (\r
580 VOID\r
581 )\r
582{\r
583 UINT32 RegData32;\r
584\r
585 /** In order to configure the PHY to use clk120 (ickusbcoreclk) as PLL reference clock\r
586 * and Port2 as a USB device port, the following sequence must be followed\r
587 *\r
588 **/\r
589\r
590 // Sideband register write to USB AFE (Phy)\r
591 RegData32 = QNCAltPortRead (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_GLOBAL_PORT);\r
592 RegData32 &= ~(BIT1);\r
593 //\r
594 // Sighting #4930631 PDNRESCFG [8:7] of USB2_GLOBAL_PORT = 11b.\r
595 // For port 0 & 1 as host and port 2 as device.\r
596 //\r
597 RegData32 |= (BIT8 | BIT7);\r
598 QNCAltPortWrite (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_GLOBAL_PORT, RegData32);\r
599\r
600 //\r
601 // Sighting #4930653 Required BIOS change on Disconnect vref to change to 600mV.\r
602 //\r
603 RegData32 = QNCAltPortRead (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_COMPBG);\r
604 RegData32 &= ~(BIT10 | BIT9 | BIT8 | BIT7);\r
605 RegData32 |= (BIT10 | BIT7);\r
606 QNCAltPortWrite (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_COMPBG, RegData32);\r
607\r
608 // Sideband register write to USB AFE (Phy)\r
609 // (pllbypass) to bypass/Disable PLL before switch\r
610 RegData32 = QNCAltPortRead (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL2);\r
611 RegData32 |= BIT29;\r
612 QNCAltPortWrite (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL2, RegData32);\r
613\r
614 // Sideband register write to USB AFE (Phy)\r
615 // (coreclksel) to select 120MHz (ickusbcoreclk) clk source.\r
616 // (Default 0 to select 96MHz (ickusbclk96_npad/ppad))\r
617 RegData32 = QNCAltPortRead (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL1);\r
618 RegData32 |= BIT1;\r
619 QNCAltPortWrite (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL1, RegData32);\r
620\r
621 // Sideband register write to USB AFE (Phy)\r
622 // (divide by 8) to achieve internal 480MHz clock\r
623 // for 120MHz input refclk. (Default: 4'b1000 (divide by 10) for 96MHz)\r
624 RegData32 = QNCAltPortRead (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL1);\r
625 RegData32 &= ~(BIT5 | BIT4 | BIT3);\r
626 RegData32 |= BIT6;\r
627 QNCAltPortWrite (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL1, RegData32);\r
628\r
629 // Sideband register write to USB AFE (Phy)\r
630 // Clear (pllbypass)\r
631 RegData32 = QNCAltPortRead (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL2);\r
632 RegData32 &= ~BIT29;\r
633 QNCAltPortWrite (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL2, RegData32);\r
634\r
635 // Sideband register write to USB AFE (Phy)\r
636 // Set (startlock) to force the PLL FSM to restart the lock\r
637 // sequence due to input clock/freq switch.\r
638 RegData32 = QNCAltPortRead (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL2);\r
639 RegData32 |= BIT24;\r
640 QNCAltPortWrite (QUARK_SC_USB_AFE_SB_PORT_ID, USB2_PLL2, RegData32);\r
641\r
642 // At this point the PLL FSM and COMP FSM will complete\r
643\r
644}\r
645\r
646/**\r
647 This function provides early platform Thermal sensor initialisation.\r
648**/\r
649VOID\r
650EFIAPI\r
651EarlyPlatformThermalSensorInit (\r
652 VOID\r
653 )\r
654{\r
655 DEBUG ((EFI_D_INFO, "Early Platform Thermal Sensor Init\n"));\r
656\r
657 //\r
658 // Set Thermal sensor mode.\r
659 //\r
660 QNCThermalSensorSetRatiometricMode ();\r
661\r
662 //\r
663 // Enable RMU Thermal sensor with a Catastrophic Trip point.\r
664 //\r
665 QNCThermalSensorEnableWithCatastrophicTrip (PLATFORM_CATASTROPHIC_TRIP_CELSIUS);\r
666\r
667 //\r
668 // Lock all RMU Thermal sensor control & trip point registers.\r
669 //\r
670 QNCThermalSensorLockAllRegisters ();\r
671}\r
672\r
673/**\r
674 Print early platform info messages includeing the Stage1 module that's\r
675 running, MFH item list and platform data item list.\r
676**/\r
677VOID\r
678EFIAPI\r
679EarlyPlatformInfoMessages (\r
680 VOID\r
681 )\r
682{\r
683 DEBUG_CODE_BEGIN ();\r
684 QUARK_EDKII_STAGE1_HEADER *Edk2ImageHeader;\r
685\r
686 //\r
687 // Find which 'Stage1' image we are running and print the details\r
688 //\r
689 Edk2ImageHeader = (QUARK_EDKII_STAGE1_HEADER *) PcdGet32 (PcdEsramStage1Base);\r
690 DEBUG ((EFI_D_INFO, "\n************************************************************\n"));\r
691\r
692 switch ((UINT8)Edk2ImageHeader->ImageIndex & QUARK_STAGE1_IMAGE_TYPE_MASK) {\r
693 case QUARK_STAGE1_BOOT_IMAGE_TYPE:\r
694 DEBUG ((EFI_D_INFO, "**** Quark EDKII Stage 1 Boot Image %d ****\n", ((UINT8)Edk2ImageHeader->ImageIndex & ~(QUARK_STAGE1_IMAGE_TYPE_MASK))));\r
695 break;\r
696\r
697 case QUARK_STAGE1_RECOVERY_IMAGE_TYPE:\r
698 DEBUG ((EFI_D_INFO, "**** Quark EDKII Stage 1 Recovery Image %d ****\n", ((UINT8)Edk2ImageHeader->ImageIndex & ~(QUARK_STAGE1_IMAGE_TYPE_MASK))));\r
699 break;\r
700\r
701 default:\r
702 DEBUG ((EFI_D_INFO, "**** Quark EDKII Unknown Stage 1 Image !!!! ****\n"));\r
703 break;\r
704 }\r
705 DEBUG (\r
706 (EFI_D_INFO,\r
707 "**** Quark EDKII Stage 2 Image 0x%08X:0x%08X ****\n" ,\r
708 (UINTN) PcdGet32 (PcdFlashFvMainBase),\r
709 (UINTN) PcdGet32 (PcdFlashFvMainSize)\r
710 ));\r
711\r
712 DEBUG (\r
713 (EFI_D_INFO,\r
714 "**** Quark EDKII Payload Image 0x%08X:0x%08X ****\n" ,\r
715 (UINTN) PcdGet32 (PcdFlashFvPayloadBase),\r
716 (UINTN) PcdGet32 (PcdFlashFvPayloadSize)\r
717 ));\r
718\r
719 DEBUG ((EFI_D_INFO, "************************************************************\n\n"));\r
720\r
721 DEBUG_CODE_END ();\r
722}\r
723\r
724/**\r
725 Check if system reset due to error condition.\r
726\r
727 @param ClearErrorBits If TRUE clear error flags and value bits.\r
728\r
729 @retval TRUE if system reset due to error condition.\r
730 @retval FALSE if NO reset error conditions.\r
731**/\r
732BOOLEAN\r
733CheckForResetDueToErrors (\r
734 IN BOOLEAN ClearErrorBits\r
735 )\r
736{\r
737 UINT32 RegValue;\r
738 BOOLEAN ResetDueToError;\r
739\r
740 ResetDueToError = FALSE;\r
741\r
742 //\r
743 // Check if RMU reset system due to access violations.\r
744 // RMU updates a SOC Unit register before reseting the system.\r
745 //\r
746 RegValue = QNCAltPortRead (QUARK_SCSS_SOC_UNIT_SB_PORT_ID, QUARK_SCSS_SOC_UNIT_CFG_STICKY_RW);\r
747 if ((RegValue & B_CFG_STICKY_RW_VIOLATION) != 0) {\r
748 ResetDueToError = TRUE;\r
749\r
750 DEBUG (\r
751 (EFI_D_ERROR,\r
752 "\nReset due to access violation: %s %s %s %s\n",\r
753 ((RegValue & B_CFG_STICKY_RW_IMR_VIOLATION) != 0) ? L"'IMR'" : L".",\r
754 ((RegValue & B_CFG_STICKY_RW_DECC_VIOLATION) != 0) ? L"'DECC'" : L".",\r
755 ((RegValue & B_CFG_STICKY_RW_SMM_VIOLATION) != 0) ? L"'SMM'" : L".",\r
756 ((RegValue & B_CFG_STICKY_RW_HMB_VIOLATION) != 0) ? L"'HMB'" : L"."\r
757 ));\r
758\r
759 //\r
760 // Clear error bits.\r
761 //\r
762 if (ClearErrorBits) {\r
763 RegValue &= ~(B_CFG_STICKY_RW_VIOLATION);\r
764 QNCAltPortWrite (QUARK_SCSS_SOC_UNIT_SB_PORT_ID, QUARK_SCSS_SOC_UNIT_CFG_STICKY_RW, RegValue);\r
765 }\r
766 }\r
767\r
768 return ResetDueToError;\r
769}\r
770\r
771/**\r
772 This function provides early platform initialization.\r
773\r
774 @param PlatformInfo Pointer to platform Info structure.\r
775\r
776**/\r
777VOID\r
778EFIAPI\r
779EarlyPlatformInit (\r
780 VOID\r
781 )\r
782{\r
783 EFI_PLATFORM_TYPE PlatformType;\r
784\r
785 PlatformType = (EFI_PLATFORM_TYPE) PcdGet16 (PcdPlatformType);\r
786\r
787 DEBUG ((EFI_D_INFO, "EarlyPlatformInit for PlatType=0x%02x\n", (UINTN) PlatformType));\r
788\r
789 //\r
790 // Check if system reset due to error condition.\r
791 //\r
792 if (CheckForResetDueToErrors (TRUE)) {\r
793 if(FeaturePcdGet (WaitIfResetDueToError)) {\r
794 DEBUG ((EFI_D_ERROR, "Press any key to continue.\n"));\r
795 PlatformDebugPortGetChar8 ();\r
796 }\r
797 }\r
798\r
799 //\r
800 // Display platform info messages.\r
801 //\r
802 EarlyPlatformInfoMessages ();\r
803\r
804 //\r
805 // Early Legacy Gpio Init.\r
806 //\r
807 EarlyPlatformLegacyGpioInit (PlatformType);\r
808\r
809 //\r
810 // Early platform Legacy GPIO manipulation depending on GPIOs\r
811 // setup by EarlyPlatformLegacyGpioInit.\r
812 //\r
813 EarlyPlatformLegacyGpioManipulation (PlatformType);\r
814\r
815 //\r
816 // Early platform specific GPIO Controller init & manipulation.\r
817 // Combined for sharing of temp. memory bar.\r
818 //\r
819 EarlyPlatformGpioCtrlerInitAndManipulation (PlatformType);\r
820\r
821 //\r
822 // Early Thermal Sensor Init.\r
823 //\r
824 EarlyPlatformThermalSensorInit ();\r
825\r
826 //\r
827 // Early Lan Ethernet Mac Init.\r
828 //\r
829 EarlyPlatformMacInit (\r
830 PcdGetPtr (PcdIohEthernetMac0),\r
831 PcdGetPtr (PcdIohEthernetMac1)\r
832 );\r
833}\r
834\r
835/**\r
836 This function provides early platform Legacy GPIO initialisation.\r
837\r
838 @param PlatformType Platform type for GPIO init.\r
839\r
840**/\r
841VOID\r
842EFIAPI\r
843EarlyPlatformLegacyGpioInit (\r
844 IN CONST EFI_PLATFORM_TYPE PlatformType\r
845 )\r
846{\r
847 BOARD_LEGACY_GPIO_CONFIG *LegacyGpioConfig;\r
848 UINT32 NewValue;\r
849 UINT32 GpioBaseAddress;\r
850\r
851 //\r
852 // Assert if platform type outside table range.\r
853 //\r
854 ASSERT ((UINTN) PlatformType < mBoardLegacyGpioConfigTableLen);\r
855 LegacyGpioConfig = &mBoardLegacyGpioConfigTable[(UINTN) PlatformType];\r
856\r
857 GpioBaseAddress = (UINT32)PcdGet16 (PcdGbaIoBaseAddress);\r
858\r
859 NewValue = 0x0;\r
860 //\r
861 // Program QNC GPIO Registers.\r
862 //\r
863 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_CGEN_CORE_WELL) & 0xFFFFFFFC) | LegacyGpioConfig->CoreWellEnable;\r
864 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_CGEN_CORE_WELL, NewValue );\r
865 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_CGIO_CORE_WELL) & 0xFFFFFFFC) | LegacyGpioConfig->CoreWellIoSelect;\r
866 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_CGIO_CORE_WELL, NewValue);\r
867 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_CGLVL_CORE_WELL) & 0xFFFFFFFC) | LegacyGpioConfig->CoreWellLvlForInputOrOutput;\r
868 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_CGLVL_CORE_WELL, NewValue);\r
869 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_CGTPE_CORE_WELL) & 0xFFFFFFFC) | LegacyGpioConfig->CoreWellTriggerPositiveEdge;\r
870 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_CGTPE_CORE_WELL, NewValue );\r
871 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_CGTNE_CORE_WELL) & 0xFFFFFFFC) | LegacyGpioConfig->CoreWellTriggerNegativeEdge;\r
872 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_CGTNE_CORE_WELL, NewValue);\r
873 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_CGGPE_CORE_WELL) & 0xFFFFFFFC) | LegacyGpioConfig->CoreWellGPEEnable;\r
874 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_CGGPE_CORE_WELL, NewValue);\r
875 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_CGSMI_CORE_WELL) & 0xFFFFFFFC) | LegacyGpioConfig->CoreWellSMIEnable;\r
876 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_CGSMI_CORE_WELL, NewValue );\r
877 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_CGTS_CORE_WELL) & 0xFFFFFFFC) | LegacyGpioConfig->CoreWellTriggerStatus;\r
878 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_CGTS_CORE_WELL, NewValue);\r
879 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_CNMIEN_CORE_WELL) & 0xFFFFFFFC) | LegacyGpioConfig->CoreWellNMIEnable;\r
880 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_CNMIEN_CORE_WELL, NewValue);\r
881\r
882 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_RGEN_RESUME_WELL) & 0xFFFFFFC0) | LegacyGpioConfig->ResumeWellEnable;\r
883 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RGEN_RESUME_WELL, NewValue );\r
884 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_RGIO_RESUME_WELL) & 0xFFFFFFC0) | LegacyGpioConfig->ResumeWellIoSelect;\r
885 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RGIO_RESUME_WELL, NewValue) ;\r
886 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_RGLVL_RESUME_WELL) & 0xFFFFFFC0) | LegacyGpioConfig->ResumeWellLvlForInputOrOutput;\r
887 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RGLVL_RESUME_WELL, NewValue);\r
888 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_RGTPE_RESUME_WELL) & 0xFFFFFFC0) | LegacyGpioConfig->ResumeWellTriggerPositiveEdge;\r
889 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RGTPE_RESUME_WELL, NewValue );\r
890 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_RGTNE_RESUME_WELL) & 0xFFFFFFC0) | LegacyGpioConfig->ResumeWellTriggerNegativeEdge;\r
891 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RGTNE_RESUME_WELL, NewValue) ;\r
892 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_RGGPE_RESUME_WELL) & 0xFFFFFFC0) | LegacyGpioConfig->ResumeWellGPEEnable;\r
893 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RGGPE_RESUME_WELL, NewValue);\r
894 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_RGSMI_RESUME_WELL) & 0xFFFFFFC0) | LegacyGpioConfig->ResumeWellSMIEnable;\r
895 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RGSMI_RESUME_WELL, NewValue );\r
896 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_RGTS_RESUME_WELL) & 0xFFFFFFC0) | LegacyGpioConfig->ResumeWellTriggerStatus;\r
897 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RGTS_RESUME_WELL, NewValue) ;\r
898 NewValue = (IoRead32 (GpioBaseAddress + R_QNC_GPIO_RNMIEN_RESUME_WELL) & 0xFFFFFFC0) | LegacyGpioConfig->ResumeWellNMIEnable;\r
899 IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RNMIEN_RESUME_WELL, NewValue);\r
900}\r
901\r
902/**\r
903 Performs any early platform specific Legacy GPIO manipulation.\r
904\r
905 @param PlatformType Platform type GPIO manipulation.\r
906\r
907**/\r
908VOID\r
909EFIAPI\r
910EarlyPlatformLegacyGpioManipulation (\r
911 IN CONST EFI_PLATFORM_TYPE PlatformType\r
912 )\r
913{\r
914 if (PlatformType == CrossHill) {\r
915\r
916 //\r
917 // Pull TPM reset low for 80us (equivalent to cold reset, Table 39\r
918 // Infineon SLB9645 Databook), then pull TPM reset high and wait for\r
919 // 150ms to give time for TPM to stabilise (Section 4.7.1 Infineon\r
920 // SLB9645 Databook states TPM is ready to receive command after 30ms\r
921 // but section 4.7 states some TPM commands may take longer to execute\r
922 // upto 150ms after test).\r
923 //\r
924\r
925 PlatformLegacyGpioSetLevel (\r
926 R_QNC_GPIO_RGLVL_RESUME_WELL,\r
927 PLATFORM_RESUMEWELL_TPM_RST_GPIO,\r
928 FALSE\r
929 );\r
930 MicroSecondDelay (80);\r
931\r
932 PlatformLegacyGpioSetLevel (\r
933 R_QNC_GPIO_RGLVL_RESUME_WELL,\r
934 PLATFORM_RESUMEWELL_TPM_RST_GPIO,\r
935 TRUE\r
936 );\r
937 MicroSecondDelay (150000);\r
938 }\r
939\r
940}\r
941\r
942/**\r
943 Performs any early platform specific GPIO Controller init & manipulation.\r
944\r
945 @param PlatformType Platform type for GPIO init & manipulation.\r
946\r
947**/\r
948VOID\r
949EFIAPI\r
950EarlyPlatformGpioCtrlerInitAndManipulation (\r
951 IN CONST EFI_PLATFORM_TYPE PlatformType\r
952 )\r
953{\r
954 UINT32 IohGpioBase;\r
955 UINT32 Data32;\r
956 UINT32 Addr;\r
957 BOARD_GPIO_CONTROLLER_CONFIG *GpioConfig;\r
958 UINT32 DevPcieAddr;\r
959 UINT16 SaveCmdReg;\r
960 UINT32 SaveBarReg;\r
961 UINT16 PciVid;\r
962 UINT16 PciDid;\r
963\r
964 ASSERT ((UINTN) PlatformType < mBoardGpioControllerConfigTableLen);\r
965 GpioConfig = &mBoardGpioControllerConfigTable[(UINTN) PlatformType];\r
966\r
967 IohGpioBase = (UINT32) PcdGet64 (PcdIohGpioMmioBase);\r
968\r
969 DevPcieAddr = PCI_LIB_ADDRESS (\r
970 PcdGet8 (PcdIohGpioBusNumber),\r
971 PcdGet8 (PcdIohGpioDevNumber),\r
972 PcdGet8 (PcdIohGpioFunctionNumber),\r
973 0\r
974 );\r
975\r
976 //\r
977 // Do nothing if not a supported device.\r
978 //\r
979 PciVid = PciRead16 (DevPcieAddr + PCI_VENDOR_ID_OFFSET);\r
980 PciDid = PciRead16 (DevPcieAddr + PCI_DEVICE_ID_OFFSET);\r
981 if((PciVid != V_IOH_I2C_GPIO_VENDOR_ID) || (PciDid != V_IOH_I2C_GPIO_DEVICE_ID)) {\r
982 return;\r
983 }\r
984\r
985 //\r
986 // Save current settings for PCI CMD/BAR registers.\r
987 //\r
988 SaveCmdReg = PciRead16 (DevPcieAddr + PCI_COMMAND_OFFSET);\r
989 SaveBarReg = PciRead32 (DevPcieAddr + PcdGet8 (PcdIohGpioBarRegister));\r
990\r
991 //\r
992 // Use predefined tempory memory resource.\r
993 //\r
994 PciWrite32 ( DevPcieAddr + PcdGet8 (PcdIohGpioBarRegister), IohGpioBase);\r
995 PciWrite8 ( DevPcieAddr + PCI_COMMAND_OFFSET, EFI_PCI_COMMAND_MEMORY_SPACE);\r
996\r
997 //\r
998 // Gpio Controller Init Tasks.\r
999 //\r
1000\r
1001 //\r
1002 // IEN- Interrupt Enable Register\r
1003 //\r
1004 Addr = IohGpioBase + GPIO_INTEN;\r
1005 Data32 = *((volatile UINT32 *) (UINTN)(Addr)) & 0xFFFFFF00; // Keep reserved bits [31:8]\r
1006 Data32 |= (GpioConfig->IntEn & 0x000FFFFF);\r
1007 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1008\r
1009 //\r
1010 // ISTATUS- Interrupt Status Register\r
1011 //\r
1012 Addr = IohGpioBase + GPIO_INTSTATUS;\r
1013 Data32 = *((volatile UINT32 *) (UINTN)(Addr)) & 0xFFFFFF00; // Keep reserved bits [31:8]\r
1014 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1015\r
1016 //\r
1017 // GPIO SWPORTA Direction Register - GPIO_SWPORTA_DR\r
1018 //\r
1019 Addr = IohGpioBase + GPIO_SWPORTA_DR;\r
1020 Data32 = *((volatile UINT32 *) (UINTN)(Addr)) & 0xFFFFFF00; // Keep reserved bits [31:8]\r
1021 Data32 |= (GpioConfig->PortADR & 0x000FFFFF);\r
1022 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1023\r
1024 //\r
1025 // GPIO SWPORTA Data Direction Register - GPIO_SWPORTA_DDR - default input\r
1026 //\r
1027 Addr = IohGpioBase + GPIO_SWPORTA_DDR;\r
1028 Data32 = *((volatile UINT32 *) (UINTN)(Addr)) & 0xFFFFFF00; // Keep reserved bits [31:8]\r
1029 Data32 |= (GpioConfig->PortADir & 0x000FFFFF);\r
1030 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1031\r
1032 //\r
1033 // Interrupt Mask Register - GPIO_INTMASK - default interrupts unmasked\r
1034 //\r
1035 Addr = IohGpioBase + GPIO_INTMASK;\r
1036 Data32 = *((volatile UINT32 *) (UINTN)(Addr)) & 0xFFFFFF00; // Keep reserved bits [31:8]\r
1037 Data32 |= (GpioConfig->IntMask & 0x000FFFFF);\r
1038 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1039\r
1040 //\r
1041 // Interrupt Level Type Register - GPIO_INTTYPE_LEVEL - default is level sensitive\r
1042 //\r
1043 Addr = IohGpioBase + GPIO_INTTYPE_LEVEL;\r
1044 Data32 = *((volatile UINT32 *) (UINTN)(Addr)) & 0xFFFFFF00; // Keep reserved bits [31:8]\r
1045 Data32 |= (GpioConfig->IntType & 0x000FFFFF);\r
1046 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1047\r
1048 //\r
1049 // Interrupt Polarity Type Register - GPIO_INT_POLARITY - default is active low\r
1050 //\r
1051 Addr = IohGpioBase + GPIO_INT_POLARITY;\r
1052 Data32 = *((volatile UINT32 *) (UINTN)(Addr)) & 0xFFFFFF00; // Keep reserved bits [31:8]\r
1053 Data32 |= (GpioConfig->IntPolarity & 0x000FFFFF);\r
1054 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1055\r
1056 //\r
1057 // Interrupt Debounce Type Register - GPIO_DEBOUNCE - default no debounce\r
1058 //\r
1059 Addr = IohGpioBase + GPIO_DEBOUNCE;\r
1060 Data32 = *((volatile UINT32 *) (UINTN)(Addr)) & 0xFFFFFF00; // Keep reserved bits [31:8]\r
1061 Data32 |= (GpioConfig->Debounce & 0x000FFFFF);\r
1062 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1063\r
1064 //\r
1065 // Interrupt Clock Synchronisation Register - GPIO_LS_SYNC - default no sync with pclk_intr(APB bus clk)\r
1066 //\r
1067 Addr = IohGpioBase + GPIO_LS_SYNC;\r
1068 Data32 = *((volatile UINT32 *) (UINTN)(Addr)) & 0xFFFFFF00; // Keep reserved bits [31:8]\r
1069 Data32 |= (GpioConfig->LsSync & 0x000FFFFF);\r
1070 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1071\r
1072 //\r
1073 // Gpio Controller Manipulation Tasks.\r
1074 //\r
1075\r
1076 if (PlatformType == (EFI_PLATFORM_TYPE) Galileo) {\r
1077 //\r
1078 // Reset Cypress Expander on Galileo Platform\r
1079 //\r
1080 Addr = IohGpioBase + GPIO_SWPORTA_DR;\r
1081 Data32 = *((volatile UINT32 *) (UINTN)(Addr));\r
1082 Data32 |= BIT4; // Cypress Reset line controlled by GPIO<4>\r
1083 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1084\r
1085 Data32 = *((volatile UINT32 *) (UINTN)(Addr));\r
1086 Data32 &= ~BIT4; // Cypress Reset line controlled by GPIO<4>\r
1087 *((volatile UINT32 *) (UINTN)(Addr)) = Data32;\r
1088\r
1089 }\r
1090\r
1091 //\r
1092 // Restore settings for PCI CMD/BAR registers\r
1093 //\r
1094 PciWrite32 ((DevPcieAddr + PcdGet8 (PcdIohGpioBarRegister)), SaveBarReg);\r
1095 PciWrite16 (DevPcieAddr + PCI_COMMAND_OFFSET, SaveCmdReg);\r
1096}\r
1097\r
1098/**\r
1099 Performs any early platform init of SoC Ethernet Mac devices.\r
1100\r
1101 @param IohMac0Address Mac address to program into Mac0 device.\r
1102 @param IohMac1Address Mac address to program into Mac1 device.\r
1103\r
1104**/\r
1105VOID\r
1106EFIAPI\r
1107EarlyPlatformMacInit (\r
1108 IN CONST UINT8 *IohMac0Address,\r
1109 IN CONST UINT8 *IohMac1Address\r
1110 )\r
1111{\r
1112 BOOLEAN SetMacAddr;\r
1113\r
1114 //\r
1115 // Set chipset MAC0 address if configured.\r
1116 //\r
1117 SetMacAddr =\r
1118 (CompareMem (ChipsetDefaultMac, IohMac0Address, sizeof (ChipsetDefaultMac))) != 0;\r
1119 if (SetMacAddr) {\r
1120 if ((*(IohMac0Address) & BIT0) != 0) {\r
1121 DEBUG ((EFI_D_ERROR, "HALT: Multicast Mac Address configured for Ioh MAC [B:%d, D:%d, F:%d]\n",\r
1122 (UINTN) IOH_MAC0_BUS_NUMBER,\r
1123 (UINTN) IOH_MAC0_DEVICE_NUMBER,\r
1124 (UINTN) IOH_MAC0_FUNCTION_NUMBER\r
1125 ));\r
1126 ASSERT (FALSE);\r
1127 } else {\r
1128 SetLanControllerMacAddr (\r
1129 IOH_MAC0_BUS_NUMBER,\r
1130 IOH_MAC0_DEVICE_NUMBER,\r
1131 IOH_MAC0_FUNCTION_NUMBER,\r
1132 IohMac0Address,\r
1133 (UINT32) PcdGet64(PcdIohMac0MmioBase)\r
1134 );\r
1135 }\r
1136 } else {\r
1137 DEBUG ((EFI_D_WARN, "WARNING: Ioh MAC [B:%d, D:%d, F:%d] NO HW ADDR CONFIGURED!!!\n",\r
1138 (UINTN) IOH_MAC0_BUS_NUMBER,\r
1139 (UINTN) IOH_MAC0_DEVICE_NUMBER,\r
1140 (UINTN) IOH_MAC0_FUNCTION_NUMBER\r
1141 ));\r
1142 }\r
1143\r
1144 //\r
1145 // Set chipset MAC1 address if configured.\r
1146 //\r
1147 SetMacAddr =\r
1148 (CompareMem (ChipsetDefaultMac, IohMac1Address, sizeof (ChipsetDefaultMac))) != 0;\r
1149 if (SetMacAddr) {\r
1150 if ((*(IohMac1Address) & BIT0) != 0) {\r
1151 DEBUG ((EFI_D_ERROR, "HALT: Multicast Mac Address configured for Ioh MAC [B:%d, D:%d, F:%d]\n",\r
1152 (UINTN) IOH_MAC1_BUS_NUMBER,\r
1153 (UINTN) IOH_MAC1_DEVICE_NUMBER,\r
1154 (UINTN) IOH_MAC1_FUNCTION_NUMBER\r
1155 ));\r
1156 ASSERT (FALSE);\r
1157 } else {\r
1158 SetLanControllerMacAddr (\r
1159 IOH_MAC1_BUS_NUMBER,\r
1160 IOH_MAC1_DEVICE_NUMBER,\r
1161 IOH_MAC1_FUNCTION_NUMBER,\r
1162 IohMac1Address,\r
1163 (UINT32) PcdGet64(PcdIohMac1MmioBase)\r
1164 );\r
1165 }\r
1166 } else {\r
1167 DEBUG ((EFI_D_WARN, "WARNING: Ioh MAC [B:%d, D:%d, F:%d] NO HW ADDR CONFIGURED!!!\n",\r
1168 (UINTN) IOH_MAC1_BUS_NUMBER,\r
1169 (UINTN) IOH_MAC1_DEVICE_NUMBER,\r
1170 (UINTN) IOH_MAC1_FUNCTION_NUMBER\r
1171 ));\r
1172 }\r
1173}\r
1174\r