Fix typo.
[mirror_edk2.git] / IntelFspWrapperPkg / Library / BaseFspApiLib / FspApiLib.c
CommitLineData
a33a2f62
JY
1/** @file\r
2 Provide FSP API related function.\r
3\r
4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiPei.h>\r
16\r
17#include <Guid/FspHeaderFile.h>\r
18\r
19#include <Library/FspApiLib.h>\r
20#include <Library/BaseMemoryLib.h>\r
21\r
22/**\r
23 Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to\r
24 long mode.\r
25\r
26 @param[in] Function The 32bit code entry to be executed.\r
27 @param[in] Param1 The first parameter to pass to 32bit code.\r
28\r
29 @return FSP_STATUS.\r
30**/\r
31FSP_STATUS\r
32Execute32BitCode (\r
33 IN UINT64 Function,\r
34 IN UINT64 Param1\r
35 );\r
36\r
37/**\r
38 Find FSP header pointer.\r
39\r
40 @param[in] FlashFvFspBase Flash address of FSP FV.\r
41\r
42 @return FSP header pointer.\r
43**/\r
44FSP_INFO_HEADER *\r
45EFIAPI\r
46FspFindFspHeader (\r
47 IN EFI_PHYSICAL_ADDRESS FlashFvFspBase\r
48 )\r
49{\r
50 UINT8 *CheckPointer;\r
51\r
52 CheckPointer = (UINT8 *) (UINTN) FlashFvFspBase;\r
53\r
54 if (((EFI_FIRMWARE_VOLUME_HEADER *)CheckPointer)->Signature != EFI_FVH_SIGNATURE) {\r
55 return NULL;\r
56 }\r
57\r
58 if (((EFI_FIRMWARE_VOLUME_HEADER *)CheckPointer)->ExtHeaderOffset != 0) {\r
59 CheckPointer = CheckPointer + ((EFI_FIRMWARE_VOLUME_HEADER *)CheckPointer)->ExtHeaderOffset;\r
60 CheckPointer = CheckPointer + ((EFI_FIRMWARE_VOLUME_EXT_HEADER *)CheckPointer)->ExtHeaderSize;\r
61 CheckPointer = (UINT8 *) ALIGN_POINTER (CheckPointer, 8);\r
62 } else {\r
63 CheckPointer = CheckPointer + ((EFI_FIRMWARE_VOLUME_HEADER *)CheckPointer)->HeaderLength;\r
64 }\r
65\r
66 if (!CompareGuid (&((EFI_FFS_FILE_HEADER *)CheckPointer)->Name, &gFspHeaderFileGuid)) {\r
67 return NULL;\r
68 }\r
69\r
70 CheckPointer = CheckPointer + sizeof (EFI_FFS_FILE_HEADER);\r
71\r
72 if (((EFI_RAW_SECTION *)CheckPointer)->Type != EFI_SECTION_RAW) {\r
73 return NULL;\r
74 }\r
75\r
76 CheckPointer = CheckPointer + sizeof (EFI_RAW_SECTION);\r
77\r
78 return (FSP_INFO_HEADER *)CheckPointer;\r
79}\r
80\r
81/**\r
82 Call FSP API - FspInit.\r
83\r
84 @param[in] FspHeader FSP header pointer.\r
85 @param[in] FspInitParams Address pointer to the FSP_INIT_PARAMS structure.\r
86\r
87 @return FSP status returned by FspInit API.\r
88**/\r
89FSP_STATUS\r
90EFIAPI\r
91CallFspInit (\r
92 IN FSP_INFO_HEADER *FspHeader,\r
93 IN FSP_INIT_PARAMS *FspInitParams\r
94 )\r
95{\r
96 FSP_FSP_INIT FspInitApi;\r
97 FSP_STATUS FspStatus;\r
98\r
99 FspInitApi = (FSP_FSP_INIT)(UINTN)(FspHeader->ImageBase + FspHeader->FspInitEntryOffset);\r
100 FspStatus = Execute32BitCode ((UINTN)FspInitApi, (UINTN)FspInitParams);\r
101\r
102 return FspStatus;\r
103}\r
104\r
105/**\r
106 Call FSP API - FspNotifyPhase.\r
107\r
108 @param[in] FspHeader FSP header pointer.\r
109 @param[in] NotifyPhaseParams Address pointer to the NOTIFY_PHASE_PARAMS structure.\r
110\r
111 @return FSP status returned by FspNotifyPhase API.\r
112**/\r
113FSP_STATUS\r
114EFIAPI\r
115CallFspNotifyPhase (\r
116 IN FSP_INFO_HEADER *FspHeader,\r
117 IN NOTIFY_PHASE_PARAMS *NotifyPhaseParams\r
118 )\r
119{\r
8e89d9ce 120 FSP_NOTIFY_PHASE NotifyPhaseApi;\r
a33a2f62
JY
121 FSP_STATUS FspStatus;\r
122\r
8e89d9ce 123 NotifyPhaseApi = (FSP_NOTIFY_PHASE)(UINTN)(FspHeader->ImageBase + FspHeader->NotifyPhaseEntryOffset);\r
a33a2f62
JY
124 FspStatus = Execute32BitCode ((UINTN)NotifyPhaseApi, (UINTN)NotifyPhaseParams);\r
125\r
126 return FspStatus;\r
127}\r