MdeModulePkg: Update library class name of PlatformHookLibSerialPortPpi.inf
[mirror_edk2.git] / IntelFspPkg / Library / BaseFspPlatformLib / FspPlatformNotify.c
CommitLineData
c8ec22a2
JY
1/** @file\r
2\r
3 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php.\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include <PiPei.h>\r
15#include <Library/PeiServicesLib.h>\r
16#include <Library/PeiServicesTablePointerLib.h>\r
17#include <Library/BaseLib.h>\r
18#include <Library/BaseMemoryLib.h>\r
19#include <Library/PcdLib.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/HobLib.h>\r
22#include <Library/FspSwitchStackLib.h>\r
23#include <Library/FspCommonLib.h>\r
24#include <Guid/EventGroup.h>\r
25#include <FspApi.h>\r
26#include <Protocol/PciEnumerationComplete.h>\r
27\r
28EFI_PEI_PPI_DESCRIPTOR mPeiPostPciEnumerationPpi = {\r
29 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
30 &gEfiPciEnumerationCompleteProtocolGuid,\r
31 NULL\r
32};\r
33\r
34EFI_PEI_PPI_DESCRIPTOR mPeiReadyToBootPpi = {\r
35 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
36 &gEfiEventReadyToBootGuid,\r
37 NULL\r
38};\r
39\r
40\r
8e89d9ce 41UINT32 mFspNotifySequence[] = {\r
c8ec22a2
JY
42 EnumInitPhaseAfterPciEnumeration,\r
43 EnumInitPhaseReadyToBoot\r
44};\r
45\r
46/**\r
47 Install FSP notification.\r
48\r
8e89d9ce 49 @param[in] NotificationCode FSP notification code\r
c8ec22a2
JY
50\r
51 @retval EFI_SUCCESS Notify FSP successfully\r
8e89d9ce 52 @retval EFI_INVALID_PARAMETER NotificationCode is invalid\r
c8ec22a2
JY
53\r
54**/\r
55EFI_STATUS\r
56EFIAPI\r
57FspNotificationHandler (\r
8e89d9ce 58 IN UINT32 NotificationCode\r
c8ec22a2
JY
59 )\r
60{\r
61 EFI_STATUS Status;\r
62\r
63 Status = EFI_SUCCESS;\r
64\r
8e89d9ce 65 switch (NotificationCode) {\r
c8ec22a2
JY
66 case EnumInitPhaseAfterPciEnumeration:\r
67 //\r
68 // Do POST PCI initialization if needed\r
69 //\r
70 DEBUG ((DEBUG_INFO | DEBUG_INIT, "FSP Post PCI Enumeration ...\n"));\r
71 PeiServicesInstallPpi (&mPeiPostPciEnumerationPpi);\r
72 break;\r
73\r
74 case EnumInitPhaseReadyToBoot:\r
75 //\r
76 // Ready To Boot\r
77 //\r
78 DEBUG ((DEBUG_INFO| DEBUG_INIT, "FSP Ready To Boot ...\n"));\r
79 PeiServicesInstallPpi (&mPeiReadyToBootPpi);\r
80 break;\r
81\r
82 default:\r
83 Status = EFI_INVALID_PARAMETER;\r
84 break;\r
85 }\r
86\r
87 return Status;\r
88}\r
89\r
90/**\r
91 This function transfer control to the ContinuationFunc passed in by the\r
92 bootloader.\r
93\r
94**/\r
95VOID\r
96EFIAPI\r
97FspInitDone (\r
98 VOID\r
99 )\r
100{\r
101 FSP_INIT_PARAMS *FspInitParams;\r
102\r
103 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
104\r
105 //\r
106 // Modify the parameters for ContinuationFunc\r
107 //\r
108 SetFspContinuationFuncParameter(EFI_SUCCESS, 0);\r
109 SetFspContinuationFuncParameter((UINT32)GetHobList(), 1);\r
110\r
111 //\r
112 // Modify the return address to ContinuationFunc\r
113 //\r
114 SetFspApiReturnAddress((UINT32)FspInitParams->ContinuationFunc);\r
115\r
116 //\r
117 // Give control back to the boot loader framework caller after FspInit is done\r
118 // It is done throught the continuation function\r
119 //\r
120 SetFspMeasurePoint (FSP_PERF_ID_API_FSPINIT_EXIT);\r
121 Pei2LoaderSwitchStack();\r
122}\r
123\r
124/**\r
125 This function handle NotifyPhase API call from the bootloader.\r
126 It gives control back to the bootloader after it is handled. If the\r
127 Notification code is a ReadyToBoot event, this function will return\r
128 and FSP continues the remaining execution until it reaches the DxeIpl.\r
129\r
130**/\r
131VOID\r
132FspWaitForNotify (\r
133 VOID\r
134 )\r
135{\r
136 EFI_STATUS Status;\r
8e89d9ce
JY
137 UINT32 NotificationValue;\r
138 UINT32 NotificationCount;\r
c8ec22a2
JY
139 UINT8 Count;\r
140\r
8e89d9ce
JY
141 NotificationCount = 0;\r
142 while (NotificationCount < sizeof(mFspNotifySequence) / sizeof(UINT32)) {\r
c8ec22a2 143\r
8e89d9ce 144 Count = (UINT8)((NotificationCount << 1) & 0x07);\r
c8ec22a2
JY
145 SetFspMeasurePoint (FSP_PERF_ID_API_NOTIFY_POSTPCI_ENTRY + Count);\r
146\r
8e89d9ce
JY
147 NotificationValue = ((NOTIFY_PHASE_PARAMS *)(UINTN)GetFspApiParameter ())->Phase;\r
148 DEBUG ((DEBUG_INFO, "FSP Got Notification. Notification Value : 0x%08X\n", NotificationValue));\r
c8ec22a2 149\r
8e89d9ce 150 if (mFspNotifySequence[NotificationCount] != NotificationValue) {\r
c8ec22a2
JY
151 //\r
152 // Notify code does not follow the predefined order\r
153 //\r
154 SetFspApiReturnStatus(EFI_UNSUPPORTED);\r
155 } else {\r
156 //\r
157 // Process Notification and Give control back to the boot loader framework caller\r
158 //\r
8e89d9ce 159 Status = FspNotificationHandler (NotificationValue);\r
c8ec22a2
JY
160 SetFspApiReturnStatus(Status);\r
161 if (!EFI_ERROR(Status)) {\r
8e89d9ce 162 NotificationCount++;\r
c8ec22a2 163 SetFspApiReturnStatus(EFI_SUCCESS);\r
8e89d9ce 164 if (NotificationValue == EnumInitPhaseReadyToBoot) {\r
c8ec22a2
JY
165 break;\r
166 }\r
167 }\r
168 }\r
169 SetFspMeasurePoint (FSP_PERF_ID_API_NOTIFY_POSTPCI_EXIT + Count);\r
170 Pei2LoaderSwitchStack();\r
171 }\r
172\r
173 //\r
174 // Control goes back to the PEI Core and it dispatches further PEIMs.\r
175 // DXEIPL is the final one to transfer control back to the boot loader.\r
176 //\r
177}\r
178\r