1 /** @file
2   Entry point to the Standalone MM Foundation when initialized during the SEC
3   phase on ARM platforms
4 
5 Copyright (c) 2017 - 2018, ARM Ltd. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7 
8 **/
9 
10 #ifndef __STANDALONEMMCORE_ENTRY_POINT_H__
11 #define __STANDALONEMMCORE_ENTRY_POINT_H__
12 
13 #include <Library/PeCoffLib.h>
14 #include <Library/FvLib.h>
15 
16 #define CPU_INFO_FLAG_PRIMARY_CPU  0x00000001
17 
18 typedef struct {
19   UINT8  Type;       /* type of the structure */
20   UINT8  Version;    /* version of this structure */
21   UINT16 Size;      /* size of this structure in bytes */
22   UINT32 Attr;      /* attributes: unused bits SBZ */
23 } EFI_PARAM_HEADER;
24 
25 typedef struct {
26   UINT64 Mpidr;
27   UINT32 LinearId;
28   UINT32 Flags;
29 } EFI_SECURE_PARTITION_CPU_INFO;
30 
31 typedef struct {
32   EFI_PARAM_HEADER              Header;
33   UINT64                        SpMemBase;
34   UINT64                        SpMemLimit;
35   UINT64                        SpImageBase;
36   UINT64                        SpStackBase;
37   UINT64                        SpHeapBase;
38   UINT64                        SpNsCommBufBase;
39   UINT64                        SpSharedBufBase;
40   UINT64                        SpImageSize;
41   UINT64                        SpPcpuStackSize;
42   UINT64                        SpHeapSize;
43   UINT64                        SpNsCommBufSize;
44   UINT64                        SpPcpuSharedBufSize;
45   UINT32                        NumSpMemRegions;
46   UINT32                        NumCpus;
47   EFI_SECURE_PARTITION_CPU_INFO *CpuInfo;
48 } EFI_SECURE_PARTITION_BOOT_INFO;
49 
50 typedef
51 EFI_STATUS
52 (*PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT) (
53   IN UINTN EventId,
54   IN UINTN CpuNumber,
55   IN UINTN NsCommBufferAddr
56   );
57 
58 typedef struct {
59   PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *ArmTfCpuDriverEpPtr;
60 } ARM_TF_CPU_DRIVER_EP_DESCRIPTOR;
61 
62 typedef RETURN_STATUS (*REGION_PERMISSION_UPDATE_FUNC) (
63   IN  EFI_PHYSICAL_ADDRESS      BaseAddress,
64   IN  UINT64                    Length
65   );
66 
67 /**
68   Privileged firmware assigns RO & Executable attributes to all memory occupied
69   by the Boot Firmware Volume. This function sets the correct permissions of
70   sections in the Standalone MM Core module to be able to access RO and RW data
71   and make further progress in the boot process.
72 
73   @param  ImageContext           Pointer to PE/COFF image context
74   @param  ImageBase              Base of image in memory
75   @param  SectionHeaderOffset    Offset of PE/COFF image section header
76   @param  NumberOfSections       Number of Sections
77   @param  TextUpdater            Function to change code permissions
78   @param  ReadOnlyUpdater        Function to change RO permissions
79   @param  ReadWriteUpdater       Function to change RW permissions
80 
81 **/
82 EFI_STATUS
83 EFIAPI
84 UpdateMmFoundationPeCoffPermissions (
85   IN  CONST PE_COFF_LOADER_IMAGE_CONTEXT      *ImageContext,
86   IN  EFI_PHYSICAL_ADDRESS                    ImageBase,
87   IN  UINT32                                  SectionHeaderOffset,
88   IN  CONST  UINT16                           NumberOfSections,
89   IN  REGION_PERMISSION_UPDATE_FUNC           TextUpdater,
90   IN  REGION_PERMISSION_UPDATE_FUNC           ReadOnlyUpdater,
91   IN  REGION_PERMISSION_UPDATE_FUNC           ReadWriteUpdater
92   );
93 
94 
95 /**
96   Privileged firmware assigns RO & Executable attributes to all memory occupied
97   by the Boot Firmware Volume. This function locates the section information of
98   the Standalone MM Core module to be able to change permissions of the
99   individual sections later in the boot process.
100 
101   @param  TeData                 Pointer to PE/COFF image data
102   @param  ImageContext           Pointer to PE/COFF image context
103   @param  ImageBase              Pointer to ImageBase variable
104   @param  SectionHeaderOffset    Offset of PE/COFF image section header
105   @param  NumberOfSections       Number of Sections
106 
107 **/
108 EFI_STATUS
109 EFIAPI
110 GetStandaloneMmCorePeCoffSections (
111   IN        VOID                            *TeData,
112   IN  OUT   PE_COFF_LOADER_IMAGE_CONTEXT    *ImageContext,
113       OUT   EFI_PHYSICAL_ADDRESS            *ImageBase,
114   IN  OUT   UINT32                          *SectionHeaderOffset,
115   IN  OUT   UINT16                          *NumberOfSections
116   );
117 
118 
119 /**
120   Privileged firmware assigns RO & Executable attributes to all memory occupied
121   by the Boot Firmware Volume. This function locates the Standalone MM Core
122   module PE/COFF image in the BFV and returns this information.
123 
124   @param  BfvAddress             Base Address of Boot Firmware Volume
125   @param  TeData                 Pointer to address for allocating memory for
126                                  PE/COFF image data
127   @param  TeDataSize             Pointer to size of PE/COFF image data
128 
129 **/
130 EFI_STATUS
131 EFIAPI
132 LocateStandaloneMmCorePeCoffData (
133   IN        EFI_FIRMWARE_VOLUME_HEADER      *BfvAddress,
134   IN  OUT   VOID                            **TeData,
135   IN  OUT   UINTN                           *TeDataSize
136   );
137 
138 
139 /**
140   Use the boot information passed by privileged firmware to populate a HOB list
141   suitable for consumption by the MM Core and drivers.
142 
143   @param  CpuDriverEntryPoint    Address of MM CPU driver entrypoint
144   @param  PayloadBootInfo        Boot information passed by privileged firmware
145 
146 **/
147 VOID *
148 EFIAPI
149 CreateHobListFromBootInfo (
150   IN  OUT  PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint,
151   IN       EFI_SECURE_PARTITION_BOOT_INFO     *PayloadBootInfo
152   );
153 
154 
155 /**
156   The entry point of Standalone MM Foundation.
157 
158   @param  SharedBufAddress  Pointer to the Buffer between SPM and SP.
159   @param  cookie1.
160   @param  cookie2.
161 **/
162 VOID
163 EFIAPI
164 _ModuleEntryPoint (
165   IN VOID    *SharedBufAddress,
166   IN UINT64  SharedBufSize,
167   IN UINT64  cookie1,
168   IN UINT64  cookie2
169   );
170 
171 
172 /**
173   Auto generated function that calls the library constructors for all of the module's dependent libraries.
174 
175   This function must be called by _ModuleEntryPoint().
176   This function calls the set of library constructors for the set of library instances
177   that a module depends on.  This includes library instances that a module depends on
178   directly and library instances that a module depends on indirectly through other
179   libraries. This function is auto generated by build tools and those build tools are
180   responsible for collecting the set of library instances, determine which ones have
181   constructors, and calling the library constructors in the proper order based upon
182   each of the library instances own dependencies.
183 
184   @param  ImageHandle  The image handle of the DXE Core.
185   @param  SystemTable  A pointer to the EFI System Table.
186 
187 **/
188 VOID
189 EFIAPI
190 ProcessLibraryConstructorList (
191   IN EFI_HANDLE             ImageHandle,
192   IN EFI_MM_SYSTEM_TABLE  *MmSystemTable
193   );
194 
195 
196 /**
197   Auto generated function that calls a set of module entry points.
198 
199   This function must be called by _ModuleEntryPoint().
200   This function calls the set of module entry points.
201   This function is auto generated by build tools and those build tools are responsible
202   for collecting the module entry points and calling them in a specified order.
203 
204   @param  HobStart  Pointer to the beginning of the HOB List passed in from the PEI Phase.
205 
206 **/
207 VOID
208 EFIAPI
209 ProcessModuleEntryPointList (
210   IN VOID  *HobStart
211   );
212 
213 #endif
214