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