1 /** @file
2   This file is SampleCode for Intel PEI Platform Policy initialization.
3 
4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #include "PeiPolicyInit.h"
10 
11 /**
12   Performs silicon post-mem policy initialization.
13 
14   The meaning of Policy is defined by silicon code.
15   It could be the raw data, a handle, a PPI, etc.
16 
17   The returned data must be used as input data for SiliconPolicyDonePostMem(),
18   and SiliconPolicyUpdateLib.SiliconPolicyUpdatePostMem().
19 
20   1) In FSP path, the input Policy should be FspsUpd.
21   Value of FspsUpd has been initialized by FSP binary default value.
22   Only a subset of FspsUpd needs to be updated for different silicon sku.
23   The return data is same FspsUpd.
24 
25   2) In non-FSP path, the input policy could be NULL.
26   The return data is the initialized policy.
27 
28   @param[in, out] Policy       Pointer to policy.
29 
30   @return the initialized policy.
31 **/
32 VOID *
33 EFIAPI
SiliconPolicyInitPostMem(IN OUT VOID * Policy)34 SiliconPolicyInitPostMem (
35   IN OUT VOID *Policy
36   )
37 {
38   EFI_STATUS                            Status;
39   SI_POLICY_PPI                         *SiPolicyPpi;
40   PEI_SI_DEFAULT_POLICY_INIT_PPI        *PeiSiDefaultPolicyInitPpi;
41 
42   DEBUG ((DEBUG_INFO, "Silicon PEI Policy Initialization Start in Post-Memory...\n"));
43 
44   ASSERT (Policy == NULL);
45 
46   //
47   // Locate Policy init PPI to install default silicon policy
48   //
49   Status = PeiServicesLocatePpi (
50              &gSiDefaultPolicyInitPpiGuid,
51              0,
52              NULL,
53              (VOID **) &PeiSiDefaultPolicyInitPpi
54              );
55   ASSERT_EFI_ERROR (Status);
56   if (PeiSiDefaultPolicyInitPpi != NULL) {
57     Status = PeiSiDefaultPolicyInitPpi->PeiPolicyInit ();
58     ASSERT_EFI_ERROR (Status);
59     if (Status == EFI_SUCCESS) {
60       Status = PeiServicesLocatePpi (
61                  &gSiPolicyPpiGuid,
62                  0,
63                  NULL,
64                  (VOID **) &SiPolicyPpi
65                  );
66       ASSERT_EFI_ERROR (Status);
67     }
68   }
69 
70   return SiPolicyPpi;
71 }
72 
73 /*
74   The silicon post-mem policy is finalized.
75   Silicon code can do initialization based upon the policy data.
76 
77   The input Policy must be returned by SiliconPolicyInitPostMem().
78 
79   @param[in] Policy       Pointer to policy.
80 
81   @retval EFI_SUCCESS The policy is handled consumed by silicon code.
82 */
83 EFI_STATUS
84 EFIAPI
SiliconPolicyDonePostMem(IN VOID * Policy)85 SiliconPolicyDonePostMem (
86   IN VOID *Policy
87   )
88 {
89   EFI_STATUS                   Status;
90   SI_POLICY_PPI                *SiPolicyPpi;
91 
92   SiPolicyPpi = Policy;
93 
94   //
95   // Install SiPolicyPpi.
96   // While installed, RC assumes the Policy is ready and finalized. So please
97   // update and override any setting before calling this function.
98   //
99   Status = SiInstallPolicyReadyPpi ();
100   ASSERT_EFI_ERROR (Status);
101 
102   DEBUG ((DEBUG_INFO, "Silicon PEI Policy Initialization Done in Post-Memory\n"));
103 
104   return Status;
105 }
106