2 Essential platform configuration.
4 Copyright (c) 2013 Intel Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "PlatformInitDxe.h"
14 // The protocols, PPI and GUID defintions for this module
18 // The Library classes this module consumes
22 // RTC:28208 - System hang/crash when entering probe mode(ITP) when relocating SMBASE
23 // Workaround to make default SMRAM UnCachable
25 #define SMM_DEFAULT_SMBASE 0x30000 // Default SMBASE address
26 #define SMM_DEFAULT_SMBASE_SIZE_BYTES 0x10000 // Size in bytes of default SMRAM
28 BOOLEAN mMemCfgDone
= FALSE
;
29 UINT8 ChipsetDefaultMac
[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
33 PlatformInitializeUart0MuxGalileo (
41 This is the routine to initialize UART0 for DBG2 support. The hardware used in this process is a
42 Legacy Bridge (Legacy GPIO), I2C controller, a bi-directional MUX and a Cypress CY8C9540A chip.
55 EFI_I2C_DEVICE_ADDRESS I2CSlaveAddress
;
59 if (PlatformLegacyGpioGetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL
, GALILEO_DETERMINE_IOEXP_SLA_RESUMEWELL_GPIO
)) {
60 I2CSlaveAddress
.I2CDeviceAddress
= GALILEO_IOEXP_J2HI_7BIT_SLAVE_ADDR
;
62 I2CSlaveAddress
.I2CDeviceAddress
= GALILEO_IOEXP_J2LO_7BIT_SLAVE_ADDR
;
66 // Set GPIO_SUS<2> as an output, raise voltage to Vdd.
68 PlatformLegacyGpioSetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL
, 2, TRUE
);
74 Buffer
[0] = 0x18; //sub-address
75 Buffer
[1] = 0x03; //data
77 Status
= I2cWriteMultipleByte (
79 EfiI2CSevenBitAddrMode
,
83 ASSERT_EFI_ERROR (Status
);
86 // Set "Pin Direction" bit4 and bit5 as outputs
89 Buffer
[0] = 0x1C; //sub-address
90 Buffer
[1] = 0xCF; //data
92 Status
= I2cWriteMultipleByte (
94 EfiI2CSevenBitAddrMode
,
98 ASSERT_EFI_ERROR (Status
);
101 // Lower GPORT3 bit4 and bit5 to Vss
104 Buffer
[0] = 0x0B; //sub-address
105 Buffer
[1] = 0xCF; //data
107 Status
= I2cWriteMultipleByte (
109 EfiI2CSevenBitAddrMode
,
113 ASSERT_EFI_ERROR (Status
);
118 PlatformInitializeUart0MuxGalileoGen2 (
126 This is the routine to initialize UART0 on GalileoGen2. The hardware used in this process is
127 I2C controller and the configuring the following IO Expander signal.
129 EXP1.P1_5 should be configured as an output & driven high.
130 EXP1.P0_0 should be configured as an output & driven high.
131 EXP0.P1_4 should be configured as an output, driven low.
132 EXP1.P0_1 pullup should be disabled.
133 EXP0.P1_5 Pullup should be disabled.
147 // EXP1.P1_5 should be configured as an output & driven high.
149 PlatformPcal9555GpioSetDir (
150 GALILEO_GEN2_IOEXP1_7BIT_SLAVE_ADDR
, // IO Expander 1.
154 PlatformPcal9555GpioSetLevel (
155 GALILEO_GEN2_IOEXP1_7BIT_SLAVE_ADDR
, // IO Expander 1.
161 // EXP1.P0_0 should be configured as an output & driven high.
163 PlatformPcal9555GpioSetDir (
164 GALILEO_GEN2_IOEXP0_7BIT_SLAVE_ADDR
, // IO Expander 0.
168 PlatformPcal9555GpioSetLevel (
169 GALILEO_GEN2_IOEXP0_7BIT_SLAVE_ADDR
, // IO Expander 0.
175 // EXP0.P1_4 should be configured as an output, driven low.
177 PlatformPcal9555GpioSetDir (
178 GALILEO_GEN2_IOEXP0_7BIT_SLAVE_ADDR
, // IO Expander 0.
182 PlatformPcal9555GpioSetLevel ( // IO Expander 0.
183 GALILEO_GEN2_IOEXP0_7BIT_SLAVE_ADDR
, // P1-4
189 // EXP1.P0_1 pullup should be disabled.
191 PlatformPcal9555GpioDisablePull (
192 GALILEO_GEN2_IOEXP1_7BIT_SLAVE_ADDR
, // IO Expander 1.
197 // EXP0.P1_5 Pullup should be disabled.
199 PlatformPcal9555GpioDisablePull (
200 GALILEO_GEN2_IOEXP0_7BIT_SLAVE_ADDR
, // IO Expander 0.
207 PlatformConfigOnSmmConfigurationProtocol (
215 Function runs in PI-DXE to perform platform specific config when
216 SmmConfigurationProtocol is installed.
219 Event - The event that occured.
220 Context - For EFI compatiblity. Not used.
233 Status
= gBS
->LocateProtocol (&gEfiSmmConfigurationProtocolGuid
, NULL
, &SmmCfgProt
);
234 if (Status
!= EFI_SUCCESS
){
235 DEBUG ((DEBUG_INFO
, "gEfiSmmConfigurationProtocolGuid triggered but not valid.\n"));
239 DEBUG ((DEBUG_INFO
, "Platform DXE Mem config already done.\n"));
244 // Disable eSram block (this will also clear/zero eSRAM)
245 // We only use eSRAM in the PEI phase. Disable now that we are in the DXE phase
247 NewValue
= QNCPortRead (QUARK_NC_MEMORY_MANAGER_SB_PORT_ID
, QUARK_NC_MEMORY_MANAGER_ESRAMPGCTRL_BLOCK
);
248 NewValue
|= BLOCK_DISABLE_PG
;
249 QNCPortWrite (QUARK_NC_MEMORY_MANAGER_SB_PORT_ID
, QUARK_NC_MEMORY_MANAGER_ESRAMPGCTRL_BLOCK
, NewValue
);
252 // Update HMBOUND to top of DDR3 memory and LOCK
253 // We disabled eSRAM so now we move HMBOUND down to top of DDR3
255 QNCGetTSEGMemoryRange (&BaseAddress
, &SmramLength
);
256 NewValue
= (UINT32
)(BaseAddress
+ SmramLength
);
257 DEBUG ((EFI_D_INFO
,"Locking HMBOUND at: = 0x%8x\n",NewValue
));
258 QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID
, QUARK_NC_HOST_BRIDGE_HMBOUND_REG
, (NewValue
| HMBOUND_LOCK
));
261 // Lock IMR5 now that HMBOUND is locked (legacy S3 region)
263 NewValue
= QNCPortRead (QUARK_NC_MEMORY_MANAGER_SB_PORT_ID
, QUARK_NC_MEMORY_MANAGER_IMR5
+QUARK_NC_MEMORY_MANAGER_IMRXL
);
264 NewValue
|= IMR_LOCK
;
265 QNCPortWrite (QUARK_NC_MEMORY_MANAGER_SB_PORT_ID
, QUARK_NC_MEMORY_MANAGER_IMR5
+QUARK_NC_MEMORY_MANAGER_IMRXL
, NewValue
);
268 // Lock IMR6 now that HMBOUND is locked (ACPI Reclaim/ACPI/Runtime services/Reserved)
270 NewValue
= QNCPortRead (QUARK_NC_MEMORY_MANAGER_SB_PORT_ID
, QUARK_NC_MEMORY_MANAGER_IMR6
+QUARK_NC_MEMORY_MANAGER_IMRXL
);
271 NewValue
|= IMR_LOCK
;
272 QNCPortWrite (QUARK_NC_MEMORY_MANAGER_SB_PORT_ID
, QUARK_NC_MEMORY_MANAGER_IMR6
+QUARK_NC_MEMORY_MANAGER_IMRXL
, NewValue
);
275 // Disable IMR2 memory protection (RMU Main Binary)
278 QUARK_NC_MEMORY_MANAGER_IMR2
,
279 (UINT32
)(IMRL_RESET
& ~IMR_EN
),
281 (UINT32
)IMRX_ALL_ACCESS
,
282 (UINT32
)IMRX_ALL_ACCESS
286 // Disable IMR3 memory protection (Default SMRAM)
289 QUARK_NC_MEMORY_MANAGER_IMR3
,
290 (UINT32
)(IMRL_RESET
& ~IMR_EN
),
292 (UINT32
)IMRX_ALL_ACCESS
,
293 (UINT32
)IMRX_ALL_ACCESS
297 // Disable IMR4 memory protection (eSRAM).
300 QUARK_NC_MEMORY_MANAGER_IMR4
,
301 (UINT32
)(IMRL_RESET
& ~IMR_EN
),
303 (UINT32
)IMRX_ALL_ACCESS
,
304 (UINT32
)IMRX_ALL_ACCESS
308 // RTC:28208 - System hang/crash when entering probe mode(ITP) when relocating SMBASE
309 // Workaround to make default SMRAM UnCachable
311 Status
= gDS
->SetMemorySpaceAttributes (
312 (EFI_PHYSICAL_ADDRESS
) SMM_DEFAULT_SMBASE
,
313 SMM_DEFAULT_SMBASE_SIZE_BYTES
,
316 ASSERT_EFI_ERROR (Status
);
323 PlatformConfigOnSpiReady (
331 Function runs in PI-DXE to perform platform specific config when SPI
335 Event - The event that occured.
336 Context - For EFI compatiblity. Not used.
344 VOID
*SpiReadyProt
= NULL
;
345 EFI_PLATFORM_TYPE Type
;
346 EFI_BOOT_MODE BootMode
;
348 BootMode
= GetBootModeHob ();
350 Status
= gBS
->LocateProtocol (&gEfiSmmSpiReadyProtocolGuid
, NULL
, &SpiReadyProt
);
351 if (Status
!= EFI_SUCCESS
){
352 DEBUG ((DEBUG_INFO
, "gEfiSmmSpiReadyProtocolGuid triggered but not valid.\n"));
357 // Lock regions SPI flash.
359 PlatformFlashLockPolicy (FALSE
);
362 // Configurations and checks to be done when DXE tracing available.
366 // Platform specific Signal routing.
370 // Skip any signal not needed for recovery and flash update.
372 if (BootMode
!= BOOT_ON_FLASH_UPDATE
&& BootMode
!= BOOT_IN_RECOVERY_MODE
) {
375 // Galileo Platform UART0 support.
377 Type
= (EFI_PLATFORM_TYPE
)PcdGet16 (PcdPlatformType
);
378 if (Type
== Galileo
) {
380 // Use MUX to connect out UART0 pins.
382 PlatformInitializeUart0MuxGalileo ();
386 // GalileoGen2 Platform UART0 support.
388 if (Type
== GalileoGen2
) {
390 // Use route out UART0 pins.
392 PlatformInitializeUart0MuxGalileoGen2 ();
414 EFI_EVENT EventSmmCfg
;
415 EFI_EVENT EventSpiReady
;
416 VOID
*RegistrationSmmCfg
;
417 VOID
*RegistrationSpiReady
;
420 // Schedule callback for when SmmConfigurationProtocol installed.
422 EventSmmCfg
= EfiCreateProtocolNotifyEvent (
423 &gEfiSmmConfigurationProtocolGuid
,
425 PlatformConfigOnSmmConfigurationProtocol
,
429 ASSERT (EventSmmCfg
!= NULL
);
432 // Schedule callback to setup SPI Flash Policy when SPI interface ready.
434 EventSpiReady
= EfiCreateProtocolNotifyEvent (
435 &gEfiSmmSpiReadyProtocolGuid
,
437 PlatformConfigOnSpiReady
,
439 &RegistrationSpiReady
441 ASSERT (EventSpiReady
!= NULL
);