1 /** @file
2 
3   Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
4 
5 
6   This program and the accompanying materials are licensed and made available under
7 
8   the terms and conditions of the BSD License that accompanies this distribution.
9 
10   The full text of the license may be found at
11 
12   http://opensource.org/licenses/bsd-license.php.
13 
14 
15 
16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 
18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 
20 
21 
22 
23 Module Name:
24 
25   PlatformInfoInit.c
26 
27 Abstract:
28   Platform Info Driver.
29 
30 --*/
31 
32 #include "PlatformEarlyInit.h"
33 
34 #define LEN_64M       0x4000000
35 
36 //
37 // Default PCI32 resource size
CheckOsSelection(IN CONST EFI_PEI_SERVICES ** PeiServices,IN SYSTEM_CONFIGURATION * SystemConfiguration)38 //
39 #define RES_MEM32_MIN_LEN   0x38000000
40 
41 #define RES_IO_BASE   0x0D00
42 #define RES_IO_LIMIT  0xFFFF
43 
44 #define MemoryCeilingVariable   L"MemCeil."
45 
46 EFI_STATUS
47 CheckOsSelection (
48   IN CONST EFI_PEI_SERVICES          **PeiServices,
49   IN SYSTEM_CONFIGURATION            *SystemConfiguration
50   )
51 {
52   EFI_STATUS                   Status;
53   EFI_PEI_READ_ONLY_VARIABLE2_PPI   *Variable;
54   UINTN                        VariableSize;
55   EFI_OS_SELECTION_HOB         *OsSelectionHob;
56   UINT8                        OsSelection;
57   UINT8                        *LpssDataHobPtr;
58   UINT8                        *LpssDataVarPtr;
59   UINTN                        i;
60 
61   Status = (*PeiServices)->LocatePpi (
62                              PeiServices,
63                              &gEfiPeiReadOnlyVariable2PpiGuid,
64                              0,
65                              NULL,
66                                       (void **)&Variable
67                              );
68   if (!EFI_ERROR(Status)) {
69     VariableSize = sizeof (OsSelection);
70     Status = Variable->GetVariable (
71                          Variable,
72                          L"OsSelection",
73                          &gOsSelectionVariableGuid,
74                          NULL,
75                          &VariableSize,
76                          &OsSelection
77                          );
78 
79     if (!EFI_ERROR(Status) && (SystemConfiguration->ReservedO != OsSelection)) {
80       //
81       // Build HOB for OsSelection
82       //
83       OsSelectionHob = BuildGuidHob (&gOsSelectionVariableGuid, sizeof (EFI_OS_SELECTION_HOB));
84       ASSERT (OsSelectionHob != NULL);
85 
86       OsSelectionHob->OsSelectionChanged = TRUE;
87       OsSelectionHob->OsSelection        = OsSelection;
88       SystemConfiguration->ReservedO   = OsSelectionHob->OsSelection;
89 
90       //
91       // Load LPSS and SCC defalut configurations
92       //
93       OsSelectionHob->LpssData.LpsseMMCEnabled            = FALSE;
94       OsSelectionHob->LpssData.LpssSdioEnabled            = TRUE;
95       OsSelectionHob->LpssData.LpssSdcardEnabled          = TRUE;
96       OsSelectionHob->LpssData.LpssSdCardSDR25Enabled     = FALSE;
97       OsSelectionHob->LpssData.LpssSdCardDDR50Enabled     = TRUE;
98       OsSelectionHob->LpssData.LpssMipiHsi                = FALSE;
99       OsSelectionHob->LpssData.LpsseMMC45Enabled          = TRUE;
100       OsSelectionHob->LpssData.LpsseMMC45DDR50Enabled     = TRUE;
101       OsSelectionHob->LpssData.LpsseMMC45HS200Enabled     = FALSE;
102       OsSelectionHob->LpssData.LpsseMMC45RetuneTimerValue = 8;
103       OsSelectionHob->LpssData.eMMCBootMode               = 1;     // Auto Detect
104 
105 
106       SystemConfiguration->Lpe       = OsSelectionHob->Lpe;
107       SystemConfiguration->PchAzalia = SystemConfiguration->PchAzalia;
108       LpssDataHobPtr = &OsSelectionHob->LpssData.LpssPciModeEnabled;
109       LpssDataVarPtr = &SystemConfiguration->LpssPciModeEnabled;
110 
111       for (i = 0; i < sizeof(EFI_PLATFORM_LPSS_DATA); i++) {
112         *LpssDataVarPtr = *LpssDataHobPtr;
113         LpssDataVarPtr++;
114         LpssDataHobPtr++;
115       }
116     }
117   }
118 
119   return EFI_SUCCESS;
120 }
121 
122 
123 EFI_STATUS
124 PlatformInfoUpdate (
125   IN CONST EFI_PEI_SERVICES          **PeiServices,
126   IN OUT EFI_PLATFORM_INFO_HOB *PlatformInfoHob,
127   IN SYSTEM_CONFIGURATION      *SystemConfiguration
128   )
129 {
130   EFI_STATUS                   Status;
131   EFI_PEI_READ_ONLY_VARIABLE2_PPI   *Variable;
132   UINTN                        VariableSize;
133   UINT32                       MemoryCeiling;
134 
135   //
136   // Checking PCI32 resource from previous boot to determine the memory ceiling
137   //
138   Status = (*PeiServices)->LocatePpi (
139                              PeiServices,
140                              &gEfiPeiReadOnlyVariable2PpiGuid,
141                              0,
142                              NULL,
143                                       (void **)&Variable
144                              );
145   if (!EFI_ERROR(Status)) {
146     //
147     // Get the memory ceiling
148     //
149     VariableSize = sizeof(MemoryCeiling);
150     Status = Variable->GetVariable (
151                          Variable,
152                          MemoryCeilingVariable,
153                          &gEfiGlobalVariableGuid,
154                          NULL,
155                          &VariableSize,
156                          &MemoryCeiling
157                          );
158     if(!EFI_ERROR(Status)) {
159       //
160       // Set the new PCI32 resource Base if the variable available
161       //
162       PlatformInfoHob->PciData.PciResourceMem32Base = MemoryCeiling;
163       PlatformInfoHob->MemData.MemMaxTolm = MemoryCeiling;
164       PlatformInfoHob->MemData.MemTolm = MemoryCeiling;
165 
166       //
167       // Platform PCI MMIO Size in unit of 1MB
168       //
169       PlatformInfoHob->MemData.MmioSize = 0x1000 - (UINT16)(PlatformInfoHob->MemData.MemMaxTolm >> 20);
170     }
171   }
172 
173   return EFI_SUCCESS;
174 }
InitializePlatform(IN CONST EFI_PEI_SERVICES ** PeiServices,IN EFI_PLATFORM_INFO_HOB * PlatformInfoHob,IN SYSTEM_CONFIGURATION * SystemConfiguration)175 
176 /**
177   Initialize the platform related info hob according to the
178   pre-determine value or setup option
179 
180   @retval EFI_SUCCESS    Memory initialization completed successfully.
181   @retval Others         All other error conditions encountered result in an ASSERT.
182 **/
183 EFI_STATUS
184 InitializePlatform (
185   IN CONST EFI_PEI_SERVICES       **PeiServices,
186   IN EFI_PLATFORM_INFO_HOB        *PlatformInfoHob,
187   IN SYSTEM_CONFIGURATION         *SystemConfiguration
188 )
189 {
190 //
191 // -- cchew10 need to update here.
192 //
193   return EFI_SUCCESS;
194 }
195 
196