summaryrefslogtreecommitdiff
path: root/ReferenceCode/Chipset/SystemAgent/MemoryInit/Pei/MemoryInit.h
blob: f8071fca507fe67ce8c7343e4ce462e78469b66a (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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/** @file
  Memory Initialization PEIM.

@copyright
  Copyright (c) 1999 - 2012 Intel Corporation. All rights reserved.
  This software and associated documentation (if any) is furnished
  under a license and may only be used or copied in accordance
  with the terms of the license. Except as permitted by such
  license, no part of this software or documentation may be
  reproduced, stored in a retrieval system, or transmitted in any
  form or by any means without the express written consent of
  Intel Corporation.

  This file contains an 'Intel Peripheral Driver' and uniquely
  identified as "Intel Reference Module" and is
  licensed for Intel CPUs and chipsets under the terms of your
  license agreement with Intel or your vendor.  This file may
  be modified by the user, subject to additional terms of the
  license agreement

**/
#ifndef _MemoryInit_h_
#define _MemoryInit_h_

#include "EdkIIGluePeim.h"
#include EFI_PPI_DEPENDENCY (SaPlatformPolicy)
#include "MemInfoHob.h"
///
/// These header files are from MRC
///
#include "MrcTypes.h"
#include "MrcApi.h"
#include "MrcGlobal.h"
#include "MrcGeneral.h"
#include "MrcStartMemoryConfiguration.h"

#include EFI_GUID_DEFINITION (SaDataHob)
#ifdef SSA_FLAG
#include "SsaCallbackPeim.h"
#endif // SSA_FLAG


///
/// SMRAM range definitions
///
#define MC_ABSEG_HSEG_PHYSICAL_START  0x000A0000
#define MC_ABSEG_HSEG_LENGTH          0x00020000
#define MC_ABSEG_CPU_START            0x000A0000
#define MC_HSEG_CPU_START             0xFEDA0000

///
/// See NonDistributed\ReferenceCode\Txt\BiosAcm\Txt.h
///
#define TXT_PUBLIC_BASE 0xFED30000

///
/// Maximum number of memory ranges supported by the memory controller
///
#define MAX_RANGES  (SA_MC_MAX_ROWS + 8)
#define MEM_EQU_4GB 0x100000000ULL

///
/// TPM Status and Time-out
///
#define TPM_STATUS_REG_ADDRESS  0xfed40000
#define TPM_TIME_OUT            750

#define PLATFORM_ID_MOBILE      1

///
/// Memory range types
///
typedef enum {
  DualChannelDdrMainMemory,
  DualChannelDdrSmramCacheable,
  DualChannelDdrSmramNonCacheable,
  DualChannelDdrGraphicsMemoryCacheable,
  DualChannelDdrGraphicsMemoryNonCacheable,
  DualChannelDdrReservedMemory,
  DualChannelDdrMaxMemoryRangeType
} PEI_DUAL_CHANNEL_DDR_MEMORY_RANGE_TYPE;

///
/// Memory map range information
///
#pragma pack(push, 1)
typedef struct {
  UINT8                                   RowNumber;
  EFI_PHYSICAL_ADDRESS                    PhysicalAddress;
  EFI_PHYSICAL_ADDRESS                    CpuAddress;
  EFI_PHYSICAL_ADDRESS                    RangeLength;
  PEI_DUAL_CHANNEL_DDR_MEMORY_RANGE_TYPE  Type;
} PEI_DUAL_CHANNEL_DDR_MEMORY_MAP_RANGE;
#pragma pack(pop)

/**
@brief
  Main starting point for system memory initialization.
    1. Get SysBootMode and MrcBootMode
    2. Locate SaPlatformPolicy PPI
    3. Locate S3DataPtr from SaPlatformPolicy.
    4. SaveDataValid := TRUE if S3DataPtr is not NULL.
    5. If SysBootMode is BOOT_ON_S3_RESUME and S3Data is not valid:
    -> ASSERT.
    6. If MrcBootMode is Warm boot, but S3 data is not valid :
    -> change MrcBootMode to Cold boot.
    7. If MrcBootMode is Cold boot:
    -> Run MRC code
    -> Save S3 Restore Data
    Else
    -> Run MRC_S3Resume
    8. Run MRC_Done().
    9. Install EFI memory HOBs.

  @param[in] FfsHeader        - Not used.
  @param[in] PeiServices      - General purpose services available to every PEIM.

  @retval EFI_SUCCESS      - Memory initialization completed successfully.
  @retval EFI_NOT_READY    - Cannot locate SA Platform Policy.
  @retval EFI_NOT_FOUND    - No S3 data in S3 Boot Mode.
  @retval EFI_DEVICE_ERROR - MemoryInit failed or IOSAV Memory test failed.
**/
extern
EFI_STATUS
PeimMemoryInit (
  IN EFI_FFS_FILE_HEADER *FfsHeader,
  IN EFI_PEI_SERVICES    **PeiServices
  );


/**
@brief
  This function installs memory for all paths except S3 resume.

  @param[in] Inputs      - MRC input structure.
  @param[in] PeiServices - PEI Services table.
  @param[in] SysBootMode - The specific boot path that is being followed.

  @retval EFI_SUCCESS          The function completed successfully.
  @retval EFI_OUT_OF_RESOURCES Out of Resources.
**/
extern
EFI_STATUS
InstallEfiMemory (
  IN const MrcInput *const Inputs,
  IN EFI_PEI_SERVICES      **PeiServices,
  IN EFI_BOOT_MODE         SysBootMode
  );

/**
@brief
  This function installs memory for the S3 resume path.

  @param[in] Inputs           - Mrc input data structure
  @param[in] PeiServices      - PEI services table.
  @param[in] VariableServices - Pointer to EFI Variable PPI

  @retval EFI_SUCCESS          - The function completed successfully.
  @retval EFI_OUT_OF_RESOURCES - Out of Resources.
**/
extern
EFI_STATUS
InstallS3Memory (
  IN const MrcInput *const      Inputs,
  IN EFI_PEI_SERVICES           **PeiServices,
  IN PEI_READ_ONLY_VARIABLE_PPI *VariableServices
);

/**
@brief
  Determine the memory size desired based on HOB memory information.

  @param[in]      PeiServices - PEI Services table.
  @param[in, out] Size        - The memory size to return.

  @retval Nothing.
**/
extern
void
RetrieveRequiredMemorySize (
  IN  EFI_PEI_SERVICES **PeiServices,
  OUT UINTN            *Size
  );

/**
@brief
  Determine the Total DPR memory size needed based on the DPR directory in the SA Data HOB.

  @param[in]      PeiServices - PEI Services table.
  @param[in, out] Size        - The memory size in MB to return.

  @retval Nothing.
**/
extern
void
CalculateTotalDprMemorySize (
  IN     EFI_PEI_SERVICES  **PeiServices,
  IN OUT UINT8             *Size
  );

/**
@brief
  Calculates the bases for each technology consuming the DPR region
  and updates the SA Data HOB with the appropriate values in the Dpr
  directory

  @param[in] PeiServices    - PEI Services table.
  @param[in] Base           - The memory base to return.
  @param[in] TotalDprSizeMB - The total DPR size in MB

  @retval Nothing.
**/
extern
VOID
UpdateDprHobInfo (
  IN EFI_PEI_SERVICES      **PeiServices,
  IN EFI_PHYSICAL_ADDRESS  Base,
  IN UINT8                 TotalDprSizeMB
  );

/**
@brief
  Determine the memory size desired by GDXC

  @param[in]      PeiServices - PEI Services table.
  @param[in, out] MotSize     - The MOT memory size
  @param[in, out] GdxcSize    - The GDXC memory size

  @retval Nothing.
**/
extern
void
RetrieveGdxcMemorySize (
  IN  EFI_PEI_SERVICES **PeiServices,
  OUT UINT64            *MotSize,
  OUT UINT64            *GdxcSize
  );

/**
@brief
  This function returns the memory ranges to be enabled, along with information
  describing how the range should be used. The MemoryMap buffer will be filled in and
  NumRanges will contain the actual number of memory ranges that are to be enabled.

  @param[in]      PeiServices - PEI Services Table.
  @param[in, out] MemoryMap   - Buffer to record details of the memory ranges to be enabled.
  @param[in, out] NumRanges   - On input, this contains the maximum number of memory ranges that
                                can be described in the MemoryMap buffer.

  @retval EFI_SUCCESS          - The function completed successfully.
  @retval EFI_BUFFER_TOO_SMALL - The specified number of ranges is too large.
**/
extern
EFI_STATUS
GetMemoryMap (
  IN     EFI_PEI_SERVICES                      **PeiServices,
  IN OUT PEI_DUAL_CHANNEL_DDR_MEMORY_MAP_RANGE *MemoryMap,
  IN OUT UINT8                                 *NumRanges
  );

/**
@brief
  This function returns a pointer to the allocated hand off buffer.

  @param[in]      PeiServices - A pointer to the EFI PEI services table
  @param[in, out] Hob         - A pointer to where to store the pointer to the allocated data buffer.
  @param[in]      Size        - The size of the buffer to get.

  @retval EFI_SUCCESS - Hob is successfully built.
  @retval Others      - Error occured while creating the Hob.
**/
extern
EFI_STATUS
MrcGetHobForDataStorage (
  IN     EFI_PEI_SERVICES       **PeiServices,
  IN OUT HOB_SAVE_MEMORY_DATA   **Hob,
  IN     UINT16                 BlockSize
  );

/**
@brief
  A small memory test to quickly point out severe memory issues.

  @param[in] Inputs - Pointer to the MRC Input data structure

  @retval mrcFail on failure, otherwise mrcSuccess.
**/
extern
MrcStatus
BasicMemoryTest (
  IN const MrcInput *const Inputs
  );

#ifndef TXT_SUPPORT_FLAG
/**
@brief
  Determines whether or not the platform has executed a TXT launch by
  examining the TPM Establishment bit.

  @param[in] PeiServices - General purpose services available to every PEIM.

  @retval TRUE        - If the TPM establishment bit is asserted.
  @retval FALSE       - If the TPM establishment bit is unasserted.
**/
extern
BOOLEAN
IsEstablishmentBitAsserted (
  IN EFI_PEI_SERVICES **PeiServices
  );

/**
@brief
  Unlock memory when security is set and TxT is not enabled.

  @param[in] MrcData     - Mrc global data.
  @param[in] PeiServices - PEI Services Table.

  @retval Nothing
**/
extern
void
UnlockMemory (
  IN const MrcParameters *const MrcData,
  IN EFI_PEI_SERVICES           **PeiServices
  );
#endif /// TXT_SUPPORT_FLAG
/**
@brief
  Determine whether a cold reset of the platform is required.
  Note that the memory configuration saved data must be valid.

  @param[in] MrcData             - The MRC "global data" area.
  @param[in] SaPlatformPolicyPpi - SA Platform Policy structure.

  @retval TRUE if cold reset is required, otherwise returns FALSE.
**/
extern
BOOLEAN
ColdBootRequired (
  IN const MrcParameters *const MrcData,
  IN SA_PLATFORM_POLICY_PPI     *SaPlatformPolicyPpi
  );

/**
@brief
  Set up the MRC input data structure.

  @param[in]  SysBootMode         - Boot mode of the system.
  @param[in]  BootMode            - Boot mode of the Mrc.
  @param[out] Inputs              - Pointer to the Mrc Input data structure.
  @param[in]  PeiServices         - PEI Services Table.
  @param[in]  SaPlatformPolicyPpi - SA Platform Policy structure.

  @retval Always returns mrcSuccess.
**/
extern
MrcBootMode
MrcSetupMrcData (
  IN  const EFI_BOOT_MODE           SysBootMode,
  IN  const MrcBootMode             BootMode,
  OUT MrcInput *const               Inputs,
  IN  EFI_PEI_SERVICES **const      PeiServices,
  IN  SA_PLATFORM_POLICY_PPI *const SaPlatformPolicyPpi
  );

/**
@brief
  Check to see if user defined profile is selected and if it is, then copy the
  timing settings for this profile to the timing override structure. If user
  defined profile is not selected, then set the timing override structure to 0.

  Note that even though we set timings on a DIMM by DIMM basis, the controller
  may force DIMM timings to be the same for all DIMMs in a channel.

  @param[in, out] Inputs              - The MRC Input data structure.
  @param[in]      SaPlatformPolicyPpi - The Peim to Peim interface of SaPlatformPolicy.

  @retval Nothing.
**/
extern
void
CheckForTimingOverride (
  IN OUT MrcInput *const               Inputs,
  IN     SA_PLATFORM_POLICY_PPI *const SaPlatformPolicyPpi
  );


#endif