]>
Commit | Line | Data |
---|---|---|
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 | |
28 | EFI_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 | |
34 | EFI_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 | |
41 | UINT32 mFspNotfifySequence[] = {\r | |
42 | EnumInitPhaseAfterPciEnumeration,\r | |
43 | EnumInitPhaseReadyToBoot\r | |
44 | };\r | |
45 | \r | |
46 | /**\r | |
47 | Install FSP notification.\r | |
48 | \r | |
49 | @param[in] NotificatonCode FSP notification code\r | |
50 | \r | |
51 | @retval EFI_SUCCESS Notify FSP successfully\r | |
52 | @retval EFI_INVALID_PARAMETER NotificatonCode is invalid\r | |
53 | \r | |
54 | **/\r | |
55 | EFI_STATUS\r | |
56 | EFIAPI\r | |
57 | FspNotificationHandler (\r | |
58 | IN UINT32 NotificatonCode\r | |
59 | )\r | |
60 | {\r | |
61 | EFI_STATUS Status;\r | |
62 | \r | |
63 | Status = EFI_SUCCESS;\r | |
64 | \r | |
65 | switch (NotificatonCode) {\r | |
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 | |
95 | VOID\r | |
96 | EFIAPI\r | |
97 | FspInitDone (\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 | |
131 | VOID\r | |
132 | FspWaitForNotify (\r | |
133 | VOID\r | |
134 | )\r | |
135 | {\r | |
136 | EFI_STATUS Status;\r | |
137 | UINT32 NotificatonValue;\r | |
138 | UINT32 NotificatonCount;\r | |
139 | UINT8 Count;\r | |
140 | \r | |
141 | NotificatonCount = 0;\r | |
142 | while (NotificatonCount < sizeof(mFspNotfifySequence) / sizeof(UINT32)) {\r | |
143 | \r | |
144 | Count = (NotificatonCount << 1) & 0x07;\r | |
145 | SetFspMeasurePoint (FSP_PERF_ID_API_NOTIFY_POSTPCI_ENTRY + Count);\r | |
146 | \r | |
147 | NotificatonValue = ((NOTIFY_PHASE_PARAMS *)(UINTN)GetFspApiParameter ())->Phase;\r | |
148 | DEBUG ((DEBUG_INFO, "FSP Got Notification. Notification Value : 0x%08X\n", NotificatonValue));\r | |
149 | \r | |
150 | if (mFspNotfifySequence[NotificatonCount] != NotificatonValue) {\r | |
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 | |
159 | Status = FspNotificationHandler (NotificatonValue);\r | |
160 | SetFspApiReturnStatus(Status);\r | |
161 | if (!EFI_ERROR(Status)) {\r | |
162 | NotificatonCount++;\r | |
163 | SetFspApiReturnStatus(EFI_SUCCESS);\r | |
164 | if (NotificatonValue == EnumInitPhaseReadyToBoot) {\r | |
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 |