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