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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
/** @file
This file provides services for Pei SA policy default initialization.
Copyright (c) 2014 - 2016, 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 "PeiSaPolicyLibrary.h"
//
// @todo: Remove the duplicate definition of the GUIDs and make it a location function.
// Because mBxtSaIpBlocks' initializer must be a constant, we need to define those GUID for it.
//
#define SA_MISC_CONFIG_GUID { 0xc5c9145f, 0x61fb, 0x4abe, { 0x88, 0x0a, 0xf2, 0x56, 0x89, 0x9f, 0x40, 0xb0}}
#define GRAPHICS_CONFIG_GUID { 0x0319c56b, 0xc43a, 0x42f1, { 0x80, 0xbe, 0xca, 0x5b, 0xd1, 0xd5, 0xc9, 0x28}}
#define MEMORY_CONFIG_GUID { 0x26cf084c, 0xc9db, 0x41bb, { 0x92, 0xc6, 0xd1, 0x97, 0xb8, 0xa1, 0xe4, 0xbf}}
#define IPU_CONFIG_GUID { 0x67eeefd0, 0x9e42, 0x48c8, { 0xbd, 0xab, 0xfd, 0x0d, 0x23, 0x69, 0x88, 0x0b}}
#define SA_PRE_MEM_CONFIG_GUID { 0x7200eef0, 0xbe7f, 0x4061, { 0x93, 0xe3, 0x3c, 0xd0, 0x36, 0x7c, 0xe1, 0x51}}
#if (ENBDT_PF_ENABLE == 1)
#define HYBRID_GRAPHICS_CONFIG_GUID { 0x0b7e694d, 0xb909, 0x4097, { 0x9c, 0x03, 0x5e, 0x72, 0x84, 0x89, 0xf7, 0x09}}
#endif
GLOBAL_REMOVE_IF_UNREFERENCED CONFIG_BLOCK_HEADER mBxtSaIpBlocks[] = {
// Block GUID Block Size, Revision
{SA_MISC_CONFIG_GUID, sizeof (SA_MISC_CONFIG), SA_MISC_CONFIG_REVISION, {0, 0, 0}},
{GRAPHICS_CONFIG_GUID, sizeof (GRAPHICS_CONFIG), GRAPHICS_CONFIG_REVISION, {0, 0, 0}},
{IPU_CONFIG_GUID, sizeof (IPU_CONFIG), IPU_CONFIG_REVISION, {0, 0, 0}},
#if (ENBDT_PF_ENABLE == 1)
{HYBRID_GRAPHICS_CONFIG_GUID, sizeof (HYBRID_GRAPHICS_CONFIG), HYBRID_GRAPHICS_CONFIG_REVISION, {0, 0, 0}},
#endif
{MEMORY_CONFIG_GUID, sizeof (MEMORY_CONFIGURATION), MEMORY_CONFIG_REVISION, {0, 0, 0}}
};
GLOBAL_REMOVE_IF_UNREFERENCED CONFIG_BLOCK_HEADER mBxtSaIpPreMemBlocks[] = {
// Block GUID Block Size, Revision
{SA_PRE_MEM_CONFIG_GUID, sizeof (SA_PRE_MEM_CONFIG), SA_PRE_MEM_CONFIG_REVISION, { 0, 0, 0}}
};
//
// Function call to Load defaults for Individial IP Blocks
//
EFI_STATUS
EFIAPI
LoadSaMiscDefault (
IN VOID *ConfigBlockPointer
)
{
SA_MISC_CONFIG *MiscConfig;
MiscConfig = ConfigBlockPointer;
DEBUG ((DEBUG_INFO, "MiscConfig->Header.Guid = %g\n", MiscConfig->Header.Guid));
DEBUG ((DEBUG_INFO, "MiscConfig->Header.Size = 0x%x\n", MiscConfig->Header.Size));
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
LoadIpuDefault (
IN VOID *ConfigBlockPointer
)
{
IPU_CONFIG *IpuPolicy;
IpuPolicy = ConfigBlockPointer;
DEBUG ((DEBUG_INFO, "IpuPolicy->Header.Guid = %g\n", IpuPolicy->Header.Guid));
DEBUG ((DEBUG_INFO, "IpuPolicy->Header.Size = 0x%x\n", IpuPolicy->Header.Size));
IpuPolicy->SaIpuEnable = 1;
IpuPolicy->IpuMmAdr = 0xCF000000;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
LoadGraphicsDefault (
IN VOID *ConfigBlockPointer
)
{
GRAPHICS_CONFIG *GtConfig;
GtConfig = ConfigBlockPointer;
//
// Initialize the Graphics configuration
//
GtConfig->GmAdr = 0xA0000000;
GtConfig->GttMmAdr = 0xBF000000;
GtConfig->EnableRenderStandby = 1;
GtConfig->PavpEnable = 1;
GtConfig->PmSupport = 1;
GtConfig->PavpPr3 = 1;
GtConfig->PeiGraphicsPeimInit = 0;
//
// Initialize the CdClock to 675 Mhz
//
GtConfig->CdClock = 3;
return EFI_SUCCESS;
}
#if (ENBDT_PF_ENABLE == 1)
EFI_STATUS
EFIAPI
LoadHybridGraphicsDefault (
IN VOID *ConfigBlockPointer
)
{
HYBRID_GRAPHICS_CONFIG *HgConfig;
HgConfig = ConfigBlockPointer;
//
// Initialize the Hybrid Graphics configuration
//
HgConfig->HgEnabled = 0x0;
HgConfig->HgDelayAfterPwrEn = 300;
HgConfig->HgDelayAfterHoldReset = 100;
return EFI_SUCCESS;
}
#endif
EFI_STATUS
EFIAPI
LoadSaPreMemDefault (
IN VOID *ConfigBlockPointer
)
{
SA_PRE_MEM_CONFIG *SaPreMemConfig;
SaPreMemConfig = ConfigBlockPointer;
//
// Initialize the Graphics configuration
//
SaPreMemConfig->GttSize = 3;
SaPreMemConfig->IgdDvmt50PreAlloc = 2;
SaPreMemConfig->InternalGraphics = 1;
SaPreMemConfig->PrimaryDisplay = 0;
SaPreMemConfig->ApertureSize = 2;
return EFI_SUCCESS;
}
/**
Initialize default settings for each SA Config block.
@param[in] ConfigBlockPointer The buffer pointer that will be initialized as specific config block.
@param[in] BlockId Request to initialize defaults of specified config block by given Block ID.
@retval EFI_SUCCESS The given buffer has contained the defaults of requested config block.
@retval EFI_NOT_FOUND Block ID is not defined so no default Config block will be initialized.
**/
EFI_STATUS
EFIAPI
LoadConfigBlockDefault (
IN VOID *ConfigBlockPointer,
IN EFI_GUID BlockGuid
)
{
if (CompareGuid (&BlockGuid, &gSaMiscConfigGuid)) {
LoadSaMiscDefault (ConfigBlockPointer);
} else {
if (CompareGuid (&BlockGuid, &gGraphicsConfigGuid)) {
LoadGraphicsDefault (ConfigBlockPointer);
} else {
if (CompareGuid (&BlockGuid, &gIpuConfigGuid)) {
LoadIpuDefault (ConfigBlockPointer);
} else {
if (CompareGuid (&BlockGuid, &gSaPreMemConfigGuid)) {
LoadSaPreMemDefault (ConfigBlockPointer);
}
#if (ENBDT_PF_ENABLE == 1)
else {
if (CompareGuid (&BlockGuid, &gHybridGraphicsConfigGuid)) {
LoadHybridGraphicsDefault (ConfigBlockPointer);
}
#endif
else {
return EFI_NOT_FOUND;
}
#if (ENBDT_PF_ENABLE == 1)
}
#endif
}
}
}
return EFI_SUCCESS;
}
/**
Creates the Pre-Mem Config Blocks for SA Policy.
It allocates and zero out buffer, and fills in the Intel default settings.
@param[in, out] SiSaPolicyPpi The pointer to get SI/SA Policy PPI instance.
@retval EFI_SUCCESS The policy default is initialized.
@retval EFI_OUT_OF_RESOURCES Insufficient resources to create buffer.
**/
EFI_STATUS
EFIAPI
SaCreatePreMemConfigBlocks(
IN OUT SI_SA_POLICY_PPI **SiSaPolicyPpi
)
{
UINT32 TotalBlockSize;
UINT16 TotalBlockCount;
UINT16 BlockCount;
VOID *ConfigBlockPointer;
EFI_STATUS Status;
SI_SA_POLICY_PPI *SaInitPolicy;
UINT32 ConfigBlockHdrSize;
UINT32 RequiredSize;
SaInitPolicy = NULL;
TotalBlockCount = sizeof (mBxtSaIpPreMemBlocks) / sizeof (CONFIG_BLOCK_HEADER);
DEBUG ((DEBUG_INFO, "TotalBlockCount = 0x%x\n", TotalBlockCount));
TotalBlockSize = 0;
for (BlockCount = 0; BlockCount < TotalBlockCount; BlockCount++) {
TotalBlockSize += (UINT32) mBxtSaIpPreMemBlocks[BlockCount].Size;
DEBUG ((DEBUG_INFO, "TotalBlockSize after adding Block[0x%x]= 0x%x\n", BlockCount, TotalBlockSize));
}
DEBUG ((DEBUG_INFO, "TotalBlockSize Final = 0x%x\n", TotalBlockSize));
ConfigBlockHdrSize = GetSizeOfConfigBlockTableHeaders ((UINT16) TotalBlockCount);
RequiredSize = ConfigBlockHdrSize + TotalBlockSize;
Status = CreateConfigBlockTable ((VOID *) &SaInitPolicy, TotalBlockCount, RequiredSize);
ASSERT_EFI_ERROR (Status);
//
// Initialize Policy Revision
//
SaInitPolicy->TableHeader.Header.Revision = SA_POLICY_PPI_REVISION;
//
// Initialize ConfigBlockPointer to NULL
//
ConfigBlockPointer = NULL;
//
// Loop to identify each config block from mBxtSaIpPreMemBlocks[] Table and add each of them
//
for (BlockCount = 0; BlockCount < TotalBlockCount; BlockCount++) {
ConfigBlockPointer = (VOID *) &mBxtSaIpPreMemBlocks[BlockCount];
Status = AddConfigBlock ((VOID *) SaInitPolicy, (VOID *) &ConfigBlockPointer);
ASSERT_EFI_ERROR (Status);
LoadConfigBlockDefault ((VOID *) ConfigBlockPointer, mBxtSaIpPreMemBlocks[BlockCount].Guid);
}
//
// Assignment for returning SaInitPolicy config block base address
//
*SiSaPolicyPpi = SaInitPolicy;
return EFI_SUCCESS;
}
/**
Creates the Config Blocks for SA Policy.
It allocates and zero out buffer, and fills in the Intel default settings.
@param[in, out] SiSaPolicyPpi The pointer to get SI/SA Policy PPI instance.
@retval EFI_SUCCESS The policy default is initialized.
@retval EFI_OUT_OF_RESOURCES Insufficient resources to create buffer.
**/
EFI_STATUS
EFIAPI
CreateConfigBlocks (
IN OUT SI_SA_POLICY_PPI **SiSaPolicyPpi
)
{
UINT32 TotalBlockSize;
UINT16 TotalBlockCount;
UINT16 BlockCount;
VOID *ConfigBlockPointer;
EFI_STATUS Status;
SI_SA_POLICY_PPI *SaInitPolicy;
UINT32 ConfigBlockHdrSize;
UINT32 RequiredSize;
SaInitPolicy = NULL;
TotalBlockCount = sizeof (mBxtSaIpBlocks) / sizeof (CONFIG_BLOCK_HEADER);
DEBUG ((DEBUG_INFO, "TotalBlockCount = 0x%x\n", TotalBlockCount));
TotalBlockSize = 0;
for (BlockCount = 0 ; BlockCount < TotalBlockCount; BlockCount++) {
TotalBlockSize += (UINT32 )mBxtSaIpBlocks[BlockCount].Size;
DEBUG ((DEBUG_INFO, "TotalBlockSize after adding Block[0x%x]= 0x%x\n", BlockCount, TotalBlockSize));
}
DEBUG ((DEBUG_INFO, "TotalBlockSize Final = 0x%x\n", TotalBlockSize));
ConfigBlockHdrSize = GetSizeOfConfigBlockTableHeaders ((UINT16) TotalBlockCount);
RequiredSize = ConfigBlockHdrSize + TotalBlockSize;
Status = CreateConfigBlockTable ((VOID *) &SaInitPolicy, TotalBlockCount, RequiredSize);
ASSERT_EFI_ERROR (Status);
//
// Initialize Policy Revision
//
SaInitPolicy->TableHeader.Header.Revision = SA_POLICY_PPI_REVISION;
//
// Initialize ConfigBlockPointer to NULL
//
ConfigBlockPointer = NULL;
//
// Loop to identify each config block from mBxtSaIpBlocks[] Table and add each of them
//
for (BlockCount = 0 ; BlockCount < TotalBlockCount; BlockCount++) {
ConfigBlockPointer = (VOID *) &mBxtSaIpBlocks[BlockCount];
Status = AddConfigBlock ((VOID *) SaInitPolicy, (VOID *) &ConfigBlockPointer);
ASSERT_EFI_ERROR (Status);
LoadConfigBlockDefault ((VOID *) ConfigBlockPointer, mBxtSaIpBlocks[BlockCount].Guid);
}
//
// Assignment for returning SaInitPolicy config block base address
//
*SiSaPolicyPpi = SaInitPolicy;
return EFI_SUCCESS;
}
/**
Install PPI SiSaPolicyPpi.
While installed, RC assumes the Policy is ready and finalized. So please update and override
any setting before calling this function.
@param[in] SiSaPolicyPpi Pointer of policy structure.
@retval EFI_SUCCESS The policy is installed.
@retval EFI_OUT_OF_RESOURCES Insufficient resources to create buffer.
**/
EFI_STATUS
EFIAPI
SiSaInstallPolicyPpi (
IN SI_SA_POLICY_PPI *SiSaPolicyPpi
)
{
EFI_STATUS Status;
EFI_PEI_PPI_DESCRIPTOR *SiSaInstallPolicyPpiDesc;
SiSaInstallPolicyPpiDesc = (EFI_PEI_PPI_DESCRIPTOR *) AllocateZeroPool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
ASSERT (SiSaInstallPolicyPpiDesc != NULL);
if (SiSaInstallPolicyPpiDesc == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Initialize the PPI
//
SiSaInstallPolicyPpiDesc->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
SiSaInstallPolicyPpiDesc->Guid = &gSiSaPolicyPpiGuid;
SiSaInstallPolicyPpiDesc->Ppi = SiSaPolicyPpi;
//
// Install PEI SA Policy PPI
//
Status = PeiServicesInstallPpi (SiSaInstallPolicyPpiDesc);
ASSERT_EFI_ERROR (Status);
return Status;
}
/**
SaInstallPreMemPolicyPpi installs Sa Pre Mem PolicyPpi.
While installed, RC assumes the Policy is ready and finalized. So please update and override
any setting before calling this function.
@param[in] SaPreMemPolicyPpi The pointer to SA PREMEM Policy PPI instance.
@retval EFI_SUCCESS The policy is installed.
@retval EFI_OUT_OF_RESOURCES Insufficient resources to create buffer.
**/
EFI_STATUS
EFIAPI
SaInstallPreMemPolicyPpi (
IN SI_SA_POLICY_PPI *SaPolicyPpi
)
{
EFI_STATUS Status;
EFI_PEI_PPI_DESCRIPTOR *SaPreMemPolicyPpiDesc;
SaPreMemPolicyPpiDesc = (EFI_PEI_PPI_DESCRIPTOR *) AllocateZeroPool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
if (SaPreMemPolicyPpiDesc == NULL) {
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
SaPreMemPolicyPpiDesc->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
SaPreMemPolicyPpiDesc->Guid = &gSiSaPreMemPolicyPpiGuid;
SaPreMemPolicyPpiDesc->Ppi = SaPolicyPpi;
//
// Install PREMEM Policy PPI
//
Status = PeiServicesInstallPpi (SaPreMemPolicyPpiDesc);
ASSERT_EFI_ERROR (Status);
return Status;
}
|