1 /** @file
2   Sample to provide FSP wrapper platform sec 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 <Ppi/SecPlatformInformation.h>
18 #include <Ppi/SecPerformance.h>
19 #include <Ppi/TemporaryRamSupport.h>
20 
21 #include <Library/LocalApicLib.h>
22 
23 /**
24   This interface conveys state information out of the Security (SEC) phase into PEI.
25 
26   @param[in]     PeiServices               Pointer to the PEI Services Table.
27   @param[in,out] StructureSize             Pointer to the variable describing size of the input buffer.
28   @param[out]    PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
29 
30   @retval EFI_SUCCESS           The data was successfully returned.
31   @retval EFI_BUFFER_TOO_SMALL  The buffer was too small.
32 
33 **/
34 EFI_STATUS
35 EFIAPI
36 SecPlatformInformation (
37   IN CONST EFI_PEI_SERVICES                     **PeiServices,
38   IN OUT   UINT64                               *StructureSize,
39      OUT   EFI_SEC_PLATFORM_INFORMATION_RECORD  *PlatformInformationRecord
40   );
41 
42 /**
43   This interface conveys performance information out of the Security (SEC) phase into PEI.
44 
45   This service is published by the SEC phase. The SEC phase handoff has an optional
46   EFI_PEI_PPI_DESCRIPTOR list as its final argument when control is passed from SEC into the
47   PEI Foundation. As such, if the platform supports collecting performance data in SEC,
48   this information is encapsulated into the data structure abstracted by this service.
49   This information is collected for the boot-strap processor (BSP) on IA-32.
50 
51   @param[in]  PeiServices  The pointer to the PEI Services Table.
52   @param[in]  This         The pointer to this instance of the PEI_SEC_PERFORMANCE_PPI.
53   @param[out] Performance  The pointer to performance data collected in SEC phase.
54 
55   @retval EFI_SUCCESS  The data was successfully returned.
56 
57 **/
58 EFI_STATUS
59 EFIAPI
60 SecGetPerformance (
61   IN CONST EFI_PEI_SERVICES          **PeiServices,
62   IN       PEI_SEC_PERFORMANCE_PPI   *This,
63   OUT      FIRMWARE_SEC_PERFORMANCE  *Performance
64   );
65 
66 /**
67   This service of the TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into
68   permanent memory.
69 
70   @param[in] PeiServices            Pointer to the PEI Services Table.
71   @param[in] TemporaryMemoryBase    Source Address in temporary memory from which the SEC or PEIM will copy the
72                                     Temporary RAM contents.
73   @param[in] PermanentMemoryBase    Destination Address in permanent memory into which the SEC or PEIM will copy the
74                                     Temporary RAM contents.
75   @param[in] CopySize               Amount of memory to migrate from temporary to permanent memory.
76 
77   @retval EFI_SUCCESS           The data was successfully returned.
78   @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when
79                                 TemporaryMemoryBase > PermanentMemoryBase.
80 
81 **/
82 EFI_STATUS
83 EFIAPI
84 SecTemporaryRamSupport (
85   IN CONST EFI_PEI_SERVICES   **PeiServices,
86   IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,
87   IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,
88   IN UINTN                    CopySize
89   );
90 
91 EFI_SEC_PLATFORM_INFORMATION_PPI  mSecPlatformInformationPpi = {
92   SecPlatformInformation
93 };
94 
95 PEI_SEC_PERFORMANCE_PPI  mSecPerformancePpi = {
96   SecGetPerformance
97 };
98 
99 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI gSecTemporaryRamSupportPpi = {
100   SecTemporaryRamSupport
101 };
102 
103 EFI_PEI_PPI_DESCRIPTOR  mPeiSecPlatformPpi[] = {
104   {
105     EFI_PEI_PPI_DESCRIPTOR_PPI,
106     &gEfiSecPlatformInformationPpiGuid,
107     &mSecPlatformInformationPpi
108   },
109   {
110     EFI_PEI_PPI_DESCRIPTOR_PPI,
111     &gPeiSecPerformancePpiGuid,
112     &mSecPerformancePpi
113   },
114   {
115     EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
116     &gEfiTemporaryRamSupportPpiGuid,
117     &gSecTemporaryRamSupportPpi
118   },
119 };
120 
121 /**
122   A developer supplied function to perform platform specific operations.
123 
124   It's a developer supplied function to perform any operations appropriate to a
125   given platform. It's invoked just before passing control to PEI core by SEC
126   core. Platform developer may modify the SecCoreData passed to PEI Core.
127   It returns a platform specific PPI list that platform wishes to pass to PEI core.
128   The Generic SEC core module will merge this list to join the final list passed to
129   PEI core.
130 
131   @param[in,out] SecCoreData           The same parameter as passing to PEI core. It
132                                        could be overridden by this function.
133 
134   @return The platform specific PPI list to be passed to PEI core or
135           NULL if there is no need of such platform specific PPI list.
136 
137 **/
138 EFI_PEI_PPI_DESCRIPTOR *
139 EFIAPI
SecPlatformMain(IN OUT EFI_SEC_PEI_HAND_OFF * SecCoreData)140 SecPlatformMain (
141   IN OUT   EFI_SEC_PEI_HAND_OFF        *SecCoreData
142   )
143 {
144   EFI_PEI_PPI_DESCRIPTOR      *PpiList;
145 
146   InitializeApicTimer (0, (UINT32) -1, TRUE, 5);
147 
148   PpiList = &mPeiSecPlatformPpi[0];
149 
150   return PpiList;
151 }
152