3 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php.
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Library/PeiServicesLib.h>
16 #include <Library/PeiServicesTablePointerLib.h>
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/PcdLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/HobLib.h>
22 #include <Library/FspSwitchStackLib.h>
23 #include <Library/FspCommonLib.h>
24 #include <Guid/EventGroup.h>
26 #include <Protocol/PciEnumerationComplete.h>
28 EFI_PEI_PPI_DESCRIPTOR mPeiPostPciEnumerationPpi
= {
29 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
30 &gEfiPciEnumerationCompleteProtocolGuid
,
34 EFI_PEI_PPI_DESCRIPTOR mPeiReadyToBootPpi
= {
35 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
36 &gEfiEventReadyToBootGuid
,
41 UINT32 mFspNotfifySequence
[] = {
42 EnumInitPhaseAfterPciEnumeration
,
43 EnumInitPhaseReadyToBoot
47 Install FSP notification.
49 @param[in] NotificatonCode FSP notification code
51 @retval EFI_SUCCESS Notify FSP successfully
52 @retval EFI_INVALID_PARAMETER NotificatonCode is invalid
57 FspNotificationHandler (
58 IN UINT32 NotificatonCode
65 switch (NotificatonCode
) {
66 case EnumInitPhaseAfterPciEnumeration
:
68 // Do POST PCI initialization if needed
70 DEBUG ((DEBUG_INFO
| DEBUG_INIT
, "FSP Post PCI Enumeration ...\n"));
71 PeiServicesInstallPpi (&mPeiPostPciEnumerationPpi
);
74 case EnumInitPhaseReadyToBoot
:
78 DEBUG ((DEBUG_INFO
| DEBUG_INIT
, "FSP Ready To Boot ...\n"));
79 PeiServicesInstallPpi (&mPeiReadyToBootPpi
);
83 Status
= EFI_INVALID_PARAMETER
;
91 This function transfer control to the ContinuationFunc passed in by the
101 FSP_INIT_PARAMS
*FspInitParams
;
103 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
106 // Modify the parameters for ContinuationFunc
108 SetFspContinuationFuncParameter(EFI_SUCCESS
, 0);
109 SetFspContinuationFuncParameter((UINT32
)GetHobList(), 1);
112 // Modify the return address to ContinuationFunc
114 SetFspApiReturnAddress((UINT32
)FspInitParams
->ContinuationFunc
);
117 // Give control back to the boot loader framework caller after FspInit is done
118 // It is done throught the continuation function
120 SetFspMeasurePoint (FSP_PERF_ID_API_FSPINIT_EXIT
);
121 Pei2LoaderSwitchStack();
125 This function handle NotifyPhase API call from the bootloader.
126 It gives control back to the bootloader after it is handled. If the
127 Notification code is a ReadyToBoot event, this function will return
128 and FSP continues the remaining execution until it reaches the DxeIpl.
137 UINT32 NotificatonValue
;
138 UINT32 NotificatonCount
;
141 NotificatonCount
= 0;
142 while (NotificatonCount
< sizeof(mFspNotfifySequence
) / sizeof(UINT32
)) {
144 Count
= (UINT8
)((NotificatonCount
<< 1) & 0x07);
145 SetFspMeasurePoint (FSP_PERF_ID_API_NOTIFY_POSTPCI_ENTRY
+ Count
);
147 NotificatonValue
= ((NOTIFY_PHASE_PARAMS
*)(UINTN
)GetFspApiParameter ())->Phase
;
148 DEBUG ((DEBUG_INFO
, "FSP Got Notification. Notification Value : 0x%08X\n", NotificatonValue
));
150 if (mFspNotfifySequence
[NotificatonCount
] != NotificatonValue
) {
152 // Notify code does not follow the predefined order
154 SetFspApiReturnStatus(EFI_UNSUPPORTED
);
157 // Process Notification and Give control back to the boot loader framework caller
159 Status
= FspNotificationHandler (NotificatonValue
);
160 SetFspApiReturnStatus(Status
);
161 if (!EFI_ERROR(Status
)) {
163 SetFspApiReturnStatus(EFI_SUCCESS
);
164 if (NotificatonValue
== EnumInitPhaseReadyToBoot
) {
169 SetFspMeasurePoint (FSP_PERF_ID_API_NOTIFY_POSTPCI_EXIT
+ Count
);
170 Pei2LoaderSwitchStack();
174 // Control goes back to the PEI Core and it dispatches further PEIMs.
175 // DXEIPL is the final one to transfer control back to the boot loader.