summaryrefslogtreecommitdiff
path: root/Platform/BroxtonPlatformPkg/Common/FspSupport/Library/BaseFspPlatformInfoLibSample/FspPlatformInfoLibSample.c
blob: 5eae2165dd385a8b917224678eb4230b6d360690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/** @file
  Sample to provide FSP platform information related function.

  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>

  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php.

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include <PiPei.h>
#include <Library/PeiServicesLib.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/FspWrapperApiLib.h>
#include <Library/PcdLib.h>
#include <Library/HobLib.h>
#include <Library/FspCommonLib.h>
#include <Guid/PlatformInfo.h>
#include <Guid/AcpiVariable.h>
#include <Guid/AcpiVariableCompatibility.h>
#include <Library/FspPlatformInfoLib.h>
#include <Ppi/DramPolicyPpi.h>
#include <FspmUpd.h>
#include <FspsUpd.h>
#include <BoardFunctionsPei.h>

#define  CAR_BASE_ADDR  0xFEF00000

STATIC
EFI_STATUS
UpdateSilicionInitUpd (
  IN EFI_PEI_SERVICES  **PeiServices,
  IN FSPS_UPD          *FspsUpd
  )
{
  return EFI_SUCCESS;
}


/**
  Get current boot mode.

  @note At this point, memory is ready, PeiServices are NOT available to use.
  Platform can get some data from chipset register.

  @return   BootMode     current boot mode.

**/
UINT32
EFIAPI
GetBootMode (
  VOID
  )
{
  return BOOT_WITH_FULL_CONFIGURATION;
}


/**
  Get NVS buffer parameter.

  @note At this point, memory is NOT ready, PeiServices are available to use.

  @return   NvsBuffer    NVS buffer parameter.

**/
VOID *
EFIAPI
GetNvsBuffer (
  VOID
  )
{
  return NULL;
}


/**
  This function overrides the default configurations in the UPD data region.
  @note At this point, memory is NOT ready, PeiServices are available to use.

  @param[in,out] FspUpdRgnPtr   A pointer to the UPD data region data structure.

  @return        FspUpdRgnPtr   A pointer to the UPD data region data structure.

**/
VOID *
EFIAPI
UpdateFspUpdConfigs (
  IN CONST EFI_PEI_SERVICES  **PeiServices,
  IN OUT VOID        *FspUpdRgnPtr
  )
{
  FSP_INFO_HEADER             *pFspHeader = NULL;
  UINT32                      FspUpdRgnSize;
  FSPM_UPD                    *FspmUpd = NULL;
  EFI_BOOT_MODE               BootMode;
  UINT64                      StackSize;
  EFI_PHYSICAL_ADDRESS        StackBase;
  UPDATE_FSPM_UPD_FUNC        UpdateFspmUpdFunc;

  DEBUG ((DEBUG_INFO, "UpdateFspUpdConfigs\n"));
  if (NULL == FspUpdRgnPtr)
    return NULL;

  if (PcdGet32 (PcdFlashFvSecondFspBase) == 0) {
    pFspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));
  } else {
    pFspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvSecondFspBase));
  }
  DEBUG ((DEBUG_INFO, "pFspHeader = %x\n", pFspHeader));
  if (NULL == pFspHeader) {
    return NULL;
  }

  DEBUG ((DEBUG_INFO, "pFspHeader->CfgRegionOffset = %08x\n", pFspHeader->CfgRegionOffset));
  FspUpdRgnSize = pFspHeader->CfgRegionSize;
  CopyMem (FspUpdRgnPtr, (void *) (pFspHeader->ImageBase + pFspHeader->CfgRegionOffset), FspUpdRgnSize);
  FspmUpd = (FSPM_UPD *)FspUpdRgnPtr;
  DEBUG ((DEBUG_INFO, "GetFspFspmUpdDataPointer - 0x%x\n", FspmUpd));

  FspmUpd->FspmConfig.SerialDebugPortDevice     = 2;
  FspmUpd->FspmConfig.SerialDebugPortType       = 2;// Skip the serial port init since we already did it
  FspmUpd->FspmConfig.SerialDebugPortStrideSize = 2;
  FspmUpd->FspmConfig.SerialDebugPortAddress    = 0;
  FspmUpd->FspmConfig.PreMemGpioTableEntryNum   = 0;
  FspmUpd->FspmConfig.PreMemGpioTablePtr        = 0;

  FspmUpd->FspmArchUpd.BootLoaderTolumSize = GetBootLoaderTolumSize ();
  DEBUG((DEBUG_INFO, "BootLoaderTolumSize - 0x%x\n", FspmUpd->FspmArchUpd.BootLoaderTolumSize));

  PeiServicesGetBootMode (&BootMode);
  FspmUpd->FspmArchUpd.BootMode = (UINT8) BootMode;
  DEBUG((DEBUG_INFO, "BootMode - 0x%x\n", FspmUpd->FspmArchUpd.BootMode));

  GetStackInfo (BootMode, FALSE, &StackSize, &StackBase);
  DEBUG ((DEBUG_INFO, "StackBase - 0x%x\n", StackBase));
  DEBUG ((DEBUG_INFO, "StackSize - 0x%x\n", StackSize));
  FspmUpd->FspmArchUpd.StackBase = (VOID *) (UINTN) StackBase;
  FspmUpd->FspmArchUpd.StackSize = (UINTN) StackSize;

  DEBUG ((DEBUG_INFO, "***** Calling UpdateFspmUpd ***** \n"));
  UpdateFspmUpdFunc = (UPDATE_FSPM_UPD_FUNC) (UINTN) PcdGet64 (PcdUpdateFspmUpdFunc);
  UpdateFspmUpdFunc(PeiServices, (FSPM_UPD *) FspmUpd);

  return (VOID *) FspmUpd;
}


/**
  Get BootLoader Tolum size.

  @note At this point, memory is NOT ready, PeiServices are available to use.

  @return   BootLoader    Tolum size.

**/
UINT32
EFIAPI
GetBootLoaderTolumSize (
  VOID
  )
{
  return 0;
}


/**
  Get TempRamExit parameter.

  @note At this point, memory is ready, PeiServices are available to use.

  @return   TempRamExit parameter.

**/
VOID *
EFIAPI
GetTempRamExitParam (
  VOID
  )
{
  return NULL;
}


/**
  Get FspSiliconInit parameter.

  @note At this point, memory is ready, PeiServices are available to use.

  @return   FspSiliconInit parameter.

**/
VOID *
EFIAPI
GetFspSiliconInitParam (
  VOID
  )
{
  return 0;
}


/**
  Get S3 PEI memory information.

  @note At this point, memory is ready, and PeiServices are available to use.
  Platform can get some data from SMRAM directly.

  @param[out]  S3PeiMemSize   PEI memory size to be installed in S3 phase.
  @param[out]  S3PeiMemBase   PEI memory base to be installed in S3 phase.

  @return      If S3 PEI memory information is got successfully.

**/
EFI_STATUS
EFIAPI
GetS3MemoryInfo (
  OUT UINT64               *S3PeiMemSize,
  OUT EFI_PHYSICAL_ADDRESS *S3PeiMemBase
  )
{
  ACPI_VARIABLE_SET               *AcpiVariableSet;
  EFI_PEI_HOB_POINTERS            GuidHob;
  EFI_PHYSICAL_ADDRESS            *AcpiVariableAddress;

  GuidHob.Raw = GetHobList ();
  AcpiVariableAddress = NULL;

  if (GuidHob.Raw != NULL) {
    if ((GuidHob.Raw = GetNextGuidHob (&gEfiAcpiVariableCompatiblityGuid, GuidHob.Raw)) != NULL) {
      AcpiVariableAddress = GET_GUID_HOB_DATA (GuidHob.Guid);
    }
  }

  DEBUG ((DEBUG_INFO, "InstallS3Memory() read AcpiVariableAddress\n"));
  if (AcpiVariableAddress != NULL) {
    DEBUG ((DEBUG_INFO, "0x%08x\n",(UINT32) ((UINTN) AcpiVariableAddress)));
    DEBUG ((DEBUG_INFO, "* 0x%08x\n",(UINT32) ((UINTN) *AcpiVariableAddress)));
    AcpiVariableSet = (ACPI_VARIABLE_SET *) ((UINTN) *AcpiVariableAddress);
    *S3PeiMemSize = (UINTN) (AcpiVariableSet->AcpiReservedMemorySize);
    *S3PeiMemBase = (UINTN) (AcpiVariableSet->AcpiReservedMemoryBase);
  } else {
    AcpiVariableSet = NULL;
    DEBUG ((DEBUG_INFO, " is NULL\n"));
  }

  return EFI_SUCCESS;
}


/**
  Get stack information according to boot mode.

  @note If BootMode is BOOT_ON_S3_RESUME or BOOT_ON_FLASH_UPDATE,
  this stack should be in some reserved memory space.

  @note If FspInitDone is TRUE, memory is ready, but no PeiServices there.
  Platform can get some data from SMRAM directly.
  @note If FspInitDone is FALSE, memory is NOT ready, but PeiServices are available to use.
  Platform can get some data from variable via VariablePpi.

  @param[in]  BootMode     Current boot mode.
  @param[in]  FspInitDone  If FspInit is called.
  @param[out] StackSize    Stack size to be used in PEI phase.
  @param[out] StackBase    Stack base to be used in PEI phase.

  @return    If Stack information is got successfully.
**/
EFI_STATUS
EFIAPI
GetStackInfo (
  IN  UINT32               BootMode,
  IN  BOOLEAN              FspInitDone,
  OUT UINT64               *StackSize,
  OUT EFI_PHYSICAL_ADDRESS *StackBase
  )
{
  *StackBase = PcdGet32 (PcdFspStackBase);
  *StackSize = PcdGet32 (PcdFspStackSize);

  if (BootMode == BOOT_ON_S3_RESUME) {
    if (!FspInitDone) {
    } else {
    }
  } else if (BootMode == BOOT_ON_FLASH_UPDATE) {
    if (!FspInitDone) {
    } else {
    }
  }

  return EFI_SUCCESS;
}