BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / IntelFspPkg / Library / BaseFspPlatformLib / FspPlatformNotify.c
CommitLineData
c8ec22a2
JY
1/** @file\r
2\r
d5fb1edf 3 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
c8ec22a2
JY
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
9da59186 92 BootLoader.\r
c8ec22a2
JY
93\r
94**/\r
95VOID\r
96EFIAPI\r
97FspInitDone (\r
98 VOID\r
99 )\r
100{\r
d5fb1edf
JY
101 FSP_INIT_PARAMS *FspInitParams;\r
102\r
103 if (GetFspApiCallingMode() == 0) {\r
9da59186
JY
104 //\r
105 // FspInit API is used, so jump into the ContinuationFunc\r
106 //\r
d5fb1edf
JY
107 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
108 \r
109 //\r
110 // Modify the parameters for ContinuationFunc\r
111 //\r
112 SetFspContinuationFuncParameter(EFI_SUCCESS, 0);\r
113 SetFspContinuationFuncParameter((UINT32)GetHobList(), 1);\r
114 \r
115 //\r
116 // Modify the return address to ContinuationFunc\r
117 //\r
118 SetFspApiReturnAddress((UINT32)FspInitParams->ContinuationFunc);\r
119 \r
120 //\r
121 // Give control back to the boot loader framework caller after FspInit is done\r
122 // It is done throught the continuation function\r
123 //\r
124 SetFspMeasurePoint (FSP_PERF_ID_API_FSPINIT_EXIT);\r
125 } else {\r
126 //\r
127 // FspMemoryInit API is used, so return directly\r
128 //\r
c8ec22a2 129\r
d5fb1edf
JY
130 //\r
131 // This is the end of the FspSiliconInit API\r
132 // Give control back to the boot loader\r
133 //\r
134 DEBUG ((DEBUG_INFO | DEBUG_INIT, "FspSiliconInitApi() - End\n"));\r
135 SetFspApiReturnStatus (EFI_SUCCESS);\r
136 }\r
c8ec22a2 137\r
c8ec22a2
JY
138 Pei2LoaderSwitchStack();\r
139}\r
140\r
141/**\r
9da59186
JY
142 This function handle NotifyPhase API call from the BootLoader.\r
143 It gives control back to the BootLoader after it is handled. If the\r
c8ec22a2
JY
144 Notification code is a ReadyToBoot event, this function will return\r
145 and FSP continues the remaining execution until it reaches the DxeIpl.\r
146\r
147**/\r
148VOID\r
149FspWaitForNotify (\r
150 VOID\r
151 )\r
152{\r
153 EFI_STATUS Status;\r
8e89d9ce
JY
154 UINT32 NotificationValue;\r
155 UINT32 NotificationCount;\r
c8ec22a2
JY
156 UINT8 Count;\r
157\r
8e89d9ce
JY
158 NotificationCount = 0;\r
159 while (NotificationCount < sizeof(mFspNotifySequence) / sizeof(UINT32)) {\r
c8ec22a2 160\r
8e89d9ce 161 Count = (UINT8)((NotificationCount << 1) & 0x07);\r
c8ec22a2
JY
162 SetFspMeasurePoint (FSP_PERF_ID_API_NOTIFY_POSTPCI_ENTRY + Count);\r
163\r
8e89d9ce
JY
164 NotificationValue = ((NOTIFY_PHASE_PARAMS *)(UINTN)GetFspApiParameter ())->Phase;\r
165 DEBUG ((DEBUG_INFO, "FSP Got Notification. Notification Value : 0x%08X\n", NotificationValue));\r
c8ec22a2 166\r
8e89d9ce 167 if (mFspNotifySequence[NotificationCount] != NotificationValue) {\r
c8ec22a2
JY
168 //\r
169 // Notify code does not follow the predefined order\r
170 //\r
d5fb1edf 171 DEBUG ((DEBUG_INFO, "Unsupported FSP Notification Value\n"));\r
c8ec22a2
JY
172 SetFspApiReturnStatus(EFI_UNSUPPORTED);\r
173 } else {\r
174 //\r
175 // Process Notification and Give control back to the boot loader framework caller\r
176 //\r
8e89d9ce 177 Status = FspNotificationHandler (NotificationValue);\r
d5fb1edf 178 DEBUG ((DEBUG_INFO, "FSP Notification Handler Returns : 0x%08X\n", Status));\r
c8ec22a2
JY
179 SetFspApiReturnStatus(Status);\r
180 if (!EFI_ERROR(Status)) {\r
8e89d9ce 181 NotificationCount++;\r
c8ec22a2 182 SetFspApiReturnStatus(EFI_SUCCESS);\r
8e89d9ce 183 if (NotificationValue == EnumInitPhaseReadyToBoot) {\r
c8ec22a2
JY
184 break;\r
185 }\r
186 }\r
187 }\r
188 SetFspMeasurePoint (FSP_PERF_ID_API_NOTIFY_POSTPCI_EXIT + Count);\r
189 Pei2LoaderSwitchStack();\r
190 }\r
191\r
192 //\r
193 // Control goes back to the PEI Core and it dispatches further PEIMs.\r
194 // DXEIPL is the final one to transfer control back to the boot loader.\r
195 //\r
196}\r
197\r