]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/PCD/Pei/Pcd.c
MdeModulePkg: Update PCD driver to support the optimized PcdDataBase
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Pcd.c
CommitLineData
fc547e08 1/** @file \r
5944a83b 2 All Pcd Ppi services are implemented here.\r
fc547e08 3 \r
2db48a1f 4Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
bfb4c2ba
CS
5(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
80408db0 13\r
80408db0 14**/\r
15\r
80408db0 16#include "Service.h"\r
17\r
17e7fa8f 18///\r
19/// Instance of PCD_PPI protocol is EDKII native implementation.\r
20/// This protocol instance support dynamic and dynamicEx type PCDs.\r
21///\r
80408db0 22PCD_PPI mPcdPpiInstance = {\r
23 PeiPcdSetSku,\r
24\r
25 PeiPcdGet8,\r
26 PeiPcdGet16, \r
27 PeiPcdGet32, \r
28 PeiPcdGet64, \r
29 PeiPcdGetPtr, \r
30 PeiPcdGetBool, \r
31 PeiPcdGetSize,\r
32\r
33 PeiPcdGet8Ex,\r
34 PeiPcdGet16Ex, \r
35 PeiPcdGet32Ex, \r
36 PeiPcdGet64Ex, \r
37 PeiPcdGetPtrEx, \r
38 PeiPcdGetBoolEx, \r
39 PeiPcdGetSizeEx,\r
40 \r
41 PeiPcdSet8,\r
42 PeiPcdSet16, \r
43 PeiPcdSet32, \r
44 PeiPcdSet64, \r
45 PeiPcdSetPtr, \r
46 PeiPcdSetBool, \r
47\r
48 PeiPcdSet8Ex,\r
49 PeiPcdSet16Ex, \r
50 PeiPcdSet32Ex, \r
51 PeiPcdSet64Ex, \r
52 PeiPcdSetPtrEx, \r
53 PeiPcdSetBoolEx,\r
54\r
55 PeiRegisterCallBackOnSet,\r
56 PcdUnRegisterCallBackOnSet,\r
57 PeiPcdGetNextToken,\r
58 PeiPcdGetNextTokenSpace\r
59};\r
60\r
17e7fa8f 61///\r
62/// Instance of EFI_PEI_PCD_PPI which is defined in PI 1.2 Vol 3.\r
63/// This PPI instance only support dyanmicEx type PCD.\r
64///\r
c896d682 65EFI_PEI_PCD_PPI mEfiPcdPpiInstance = {\r
66 PeiPcdSetSku,\r
67 \r
68 PeiPcdGet8Ex,\r
69 PeiPcdGet16Ex,\r
70 PeiPcdGet32Ex,\r
71 PeiPcdGet64Ex,\r
72 PeiPcdGetPtrEx,\r
73 PeiPcdGetBoolEx,\r
74 PeiPcdGetSizeEx,\r
75 PeiPcdSet8Ex,\r
76 PeiPcdSet16Ex,\r
77 PeiPcdSet32Ex,\r
78 PeiPcdSet64Ex,\r
79 PeiPcdSetPtrEx,\r
80 PeiPcdSetBoolEx,\r
81 (EFI_PEI_PCD_PPI_CALLBACK_ON_SET) PeiRegisterCallBackOnSet,\r
82 (EFI_PEI_PCD_PPI_CANCEL_CALLBACK) PcdUnRegisterCallBackOnSet,\r
83 PeiPcdGetNextToken,\r
84 PeiPcdGetNextTokenSpace\r
85};\r
86\r
96d6d004
SZ
87///\r
88/// Instance of GET_PCD_INFO_PPI protocol is EDKII native implementation.\r
89/// This protocol instance support dynamic and dynamicEx type PCDs.\r
90///\r
91GET_PCD_INFO_PPI mGetPcdInfoInstance = {\r
92 PeiGetPcdInfoGetInfo,\r
93 PeiGetPcdInfoGetInfoEx,\r
94 PeiGetPcdInfoGetSku\r
95};\r
96\r
97///\r
98/// Instance of EFI_GET_PCD_INFO_PPI which is defined in PI 1.2.1 Vol 3.\r
99/// This PPI instance only support dyanmicEx type PCD.\r
100///\r
101EFI_GET_PCD_INFO_PPI mEfiGetPcdInfoInstance = {\r
102 PeiGetPcdInfoGetInfoEx,\r
103 PeiGetPcdInfoGetSku\r
104};\r
105\r
17e7fa8f 106EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {\r
107 {\r
108 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
109 &gPcdPpiGuid,\r
110 &mPcdPpiInstance\r
111 },\r
112 {\r
113 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
114 &gEfiPeiPcdPpiGuid,\r
115 &mEfiPcdPpiInstance\r
116 }\r
c896d682 117};\r
118\r
96d6d004
SZ
119EFI_PEI_PPI_DESCRIPTOR mPpiList2[] = {\r
120 {\r
121 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
122 &gGetPcdInfoPpiGuid,\r
123 &mGetPcdInfoInstance\r
124 },\r
125 {\r
126 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
127 &gEfiGetPcdInfoPpiGuid,\r
128 &mEfiGetPcdInfoInstance\r
129 }\r
130};\r
131\r
219247e1
LG
132/**\r
133 Callback on SET PcdSetNvStoreDefaultId\r
134\r
135 Once PcdSetNvStoreDefaultId is set, the default NV storage will be found from\r
136 PcdNvStoreDefaultValueBuffer, and built into VariableHob.\r
137\r
138 @param[in] CallBackGuid The PCD token GUID being set.\r
139 @param[in] CallBackToken The PCD token number being set.\r
140 @param[in, out] TokenData A pointer to the token data being set.\r
141 @param[in] TokenDataSize The size, in bytes, of the data being set.\r
142\r
143**/\r
144VOID\r
145EFIAPI\r
146PcdSetNvStoreDefaultIdCallBack (\r
147 IN CONST EFI_GUID *CallBackGuid, OPTIONAL\r
148 IN UINTN CallBackToken,\r
149 IN OUT VOID *TokenData,\r
150 IN UINTN TokenDataSize\r
151 )\r
152{\r
153 EFI_STATUS Status;\r
154 UINT16 DefaultId;\r
155 SKU_ID SkuId;\r
156 UINTN FullSize;\r
157 UINTN Index;\r
158 UINT8 *DataBuffer;\r
159 UINT8 *VarStoreHobData;\r
160 UINT8 *BufferEnd;\r
161 BOOLEAN IsFound;\r
162 VARIABLE_STORE_HEADER *NvStoreBuffer;\r
163 PCD_DEFAULT_DATA *DataHeader;\r
164 PCD_DEFAULT_INFO *DefaultInfo;\r
165 PCD_DATA_DELTA *DeltaData;\r
166\r
167 DefaultId = *(UINT16 *) TokenData;\r
168 SkuId = GetPcdDatabase()->SystemSkuId;\r
169 IsFound = FALSE;\r
170\r
171 if (PeiPcdGetSizeEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer)) > sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {\r
172 DataBuffer = (UINT8 *) PeiPcdGetPtrEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer));\r
173 FullSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER *) DataBuffer)->Length;\r
174 DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER));\r
175 //\r
176 // The first section data includes NV storage default setting.\r
177 //\r
178 NvStoreBuffer = (VARIABLE_STORE_HEADER *) ((UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize);\r
179 VarStoreHobData = (UINT8 *) BuildGuidHob (&NvStoreBuffer->Signature, NvStoreBuffer->Size);\r
180 ASSERT (VarStoreHobData != NULL);\r
181 CopyMem (VarStoreHobData, NvStoreBuffer, NvStoreBuffer->Size);\r
182 //\r
183 // Find the matched SkuId and DefaultId in the first section\r
184 //\r
185 DefaultInfo = &(DataHeader->DefaultInfo[0]);\r
186 BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r
187 while ((UINT8 *) DefaultInfo < BufferEnd) {\r
188 if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {\r
189 IsFound = TRUE;\r
190 break;\r
191 }\r
192 DefaultInfo ++;\r
193 }\r
194 //\r
195 // Find the matched SkuId and DefaultId in the remaining section\r
196 //\r
197 Index = sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER) + ((DataHeader->DataSize + 7) & (~7));\r
198 DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);\r
199 while (!IsFound && Index < FullSize && DataHeader->DataSize != 0xFFFFFFFF) {\r
200 DefaultInfo = &(DataHeader->DefaultInfo[0]);\r
201 BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r
202 while ((UINT8 *) DefaultInfo < BufferEnd) {\r
203 if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {\r
204 IsFound = TRUE;\r
205 break;\r
206 }\r
207 DefaultInfo ++;\r
208 }\r
209 if (IsFound) {\r
210 DeltaData = (PCD_DATA_DELTA *) BufferEnd;\r
211 BufferEnd = (UINT8 *) DataHeader + DataHeader->DataSize;\r
212 while ((UINT8 *) DeltaData < BufferEnd) {\r
213 *(VarStoreHobData + DeltaData->Offset) = (UINT8) DeltaData->Value;\r
214 DeltaData ++;\r
215 }\r
216 break;\r
217 }\r
218 Index = (Index + DataHeader->DataSize + 7) & (~7) ;\r
219 DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);\r
220 }\r
221 }\r
222\r
223 Status = PcdUnRegisterCallBackOnSet (\r
224 &gEfiMdeModulePkgTokenSpaceGuid,\r
225 PcdToken(PcdSetNvStoreDefaultId),\r
226 PcdSetNvStoreDefaultIdCallBack\r
227 );\r
228 ASSERT_EFI_ERROR (Status);\r
229}\r
230\r
7c736265
LG
231/**\r
232 Report Pei PCD database of all SKUs as Guid HOB so that DxePcd can access it.\r
233\r
234 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
235 @param NotifyDescriptor Address of the notification descriptor data structure.\r
236 @param Ppi Address of the PPI that was installed.\r
237\r
238 @retval EFI_SUCCESS Successfully update the Boot records.\r
239**/\r
240EFI_STATUS\r
241EFIAPI\r
242EndOfPeiSignalPpiNotifyCallback (\r
243 IN EFI_PEI_SERVICES **PeiServices,\r
244 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
245 IN VOID *Ppi\r
246 )\r
247{\r
248 PEI_PCD_DATABASE *Database;\r
249 EFI_BOOT_MODE BootMode;\r
250 EFI_STATUS Status;\r
251 UINTN Instance;\r
252 EFI_PEI_FV_HANDLE VolumeHandle;\r
253 EFI_PEI_FILE_HANDLE FileHandle;\r
254 VOID *PcdDb;\r
255 UINT32 Length;\r
256 PEI_PCD_DATABASE *PeiPcdDb;\r
257\r
258 Status = PeiServicesGetBootMode(&BootMode);\r
259 ASSERT_EFI_ERROR (Status);\r
260\r
261 //\r
262 // Don't need to report it on S3 boot.\r
263 //\r
264 if (BootMode == BOOT_ON_S3_RESUME) {\r
265 return EFI_SUCCESS;\r
266 }\r
267\r
268 PeiPcdDb = GetPcdDatabase();\r
269 if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r
270 //\r
271 // SkuId has been set. Don't need to report it to DXE phase.\r
272 //\r
273 return EFI_SUCCESS;\r
274 }\r
275\r
276 //\r
277 // Get full PCD database from PcdPeim FileHandle\r
278 //\r
279 Instance = 0;\r
280 FileHandle = NULL;\r
281 while (TRUE) {\r
282 //\r
283 // Traverse all firmware volume instances\r
284 //\r
285 Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r
286 //\r
287 // Error should not happen\r
288 //\r
289 ASSERT_EFI_ERROR (Status);\r
290\r
291 //\r
292 // Find PcdDb file from the beginning in this firmware volume.\r
293 //\r
294 FileHandle = NULL;\r
295 Status = PeiServicesFfsFindFileByName (&gEfiCallerIdGuid, VolumeHandle, &FileHandle);\r
296 if (!EFI_ERROR (Status)) {\r
297 //\r
298 // Find PcdPeim FileHandle in this volume\r
299 //\r
300 break;\r
301 }\r
302 //\r
303 // We cannot find PcdPeim in this firmware volume, then search the next volume.\r
304 //\r
305 Instance++;\r
306 }\r
307\r
308 //\r
309 // Find PEI PcdDb and Build second PcdDB GuidHob\r
310 //\r
311 Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);\r
312 ASSERT_EFI_ERROR (Status);\r
313 Length = PeiPcdDb->LengthForAllSkus;\r
314 Database = BuildGuidHob (&gPcdDataBaseHobGuid, Length);\r
315 CopyMem (Database, PcdDb, Length);\r
316\r
317 return EFI_SUCCESS;\r
318}\r
319\r
320EFI_PEI_NOTIFY_DESCRIPTOR mEndOfPeiSignalPpiNotifyList[] = {\r
321 {\r
322 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
323 &gEfiEndOfPeiSignalPpiGuid,\r
324 EndOfPeiSignalPpiNotifyCallback\r
325 }\r
326};\r
327\r
fc547e08 328/**\r
329 Main entry for PCD PEIM driver.\r
330 \r
8a541f0a 331 This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.\r
80408db0 332\r
8bd22b8a
LG
333 @param FileHandle Handle of the file being invoked.\r
334 @param PeiServices Describes the list of possible PEI Services.\r
80408db0 335\r
fc547e08 336 @return Status of install PCD_PPI\r
337\r
338**/\r
80408db0 339EFI_STATUS\r
340EFIAPI\r
341PcdPeimInit (\r
8bd22b8a
LG
342 IN EFI_PEI_FILE_HANDLE FileHandle,\r
343 IN CONST EFI_PEI_SERVICES **PeiServices\r
80408db0 344 )\r
345{\r
a78d3a27 346 EFI_STATUS Status;\r
96d6d004 347\r
a78d3a27 348 BuildPcdDatabase (FileHandle);\r
80408db0 349\r
8a541f0a 350 //\r
17e7fa8f 351 // Install PCD_PPI and EFI_PEI_PCD_PPI.\r
8a541f0a 352 //\r
17e7fa8f 353 Status = PeiServicesInstallPpi (&mPpiList[0]);\r
8a541f0a 354 ASSERT_EFI_ERROR (Status);\r
96d6d004
SZ
355\r
356 //\r
85d0b97d 357 // Install GET_PCD_INFO_PPI and EFI_GET_PCD_INFO_PPI.\r
96d6d004 358 //\r
85d0b97d
SZ
359 Status = PeiServicesInstallPpi (&mPpiList2[0]);\r
360 ASSERT_EFI_ERROR (Status);\r
96d6d004 361\r
7c736265
LG
362 Status = PeiServicesNotifyPpi (&mEndOfPeiSignalPpiNotifyList[0]);\r
363 ASSERT_EFI_ERROR (Status);\r
364\r
219247e1
LG
365 Status = PeiRegisterCallBackOnSet (\r
366 &gEfiMdeModulePkgTokenSpaceGuid,\r
367 PcdToken(PcdSetNvStoreDefaultId),\r
368 PcdSetNvStoreDefaultIdCallBack\r
369 );\r
370 ASSERT_EFI_ERROR (Status);\r
371\r
8a541f0a 372 return Status;\r
80408db0 373}\r
374\r
96d6d004
SZ
375/**\r
376 Retrieve additional information associated with a PCD token in the default token space.\r
377\r
378 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
379 human readable name that is associated with the token.\r
380\r
381 @param[in] TokenNumber The PCD token number.\r
382 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
383 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
384\r
385 @retval EFI_SUCCESS The PCD information was returned successfully.\r
386 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
387**/\r
388EFI_STATUS\r
389EFIAPI\r
390PeiGetPcdInfoGetInfo (\r
391 IN UINTN TokenNumber,\r
392 OUT EFI_PCD_INFO *PcdInfo\r
393 )\r
394{\r
395 return PeiGetPcdInfo (NULL, TokenNumber, PcdInfo);\r
396}\r
397\r
398/**\r
399 Retrieve additional information associated with a PCD token.\r
400\r
401 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
402 human readable name that is associated with the token.\r
403\r
404 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
405 @param[in] TokenNumber The PCD token number.\r
406 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
407 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
408\r
409 @retval EFI_SUCCESS The PCD information was returned successfully.\r
410 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
411**/\r
412EFI_STATUS\r
413EFIAPI\r
414PeiGetPcdInfoGetInfoEx (\r
415 IN CONST EFI_GUID *Guid,\r
416 IN UINTN TokenNumber,\r
417 OUT EFI_PCD_INFO *PcdInfo\r
418 )\r
419{\r
420 return PeiGetPcdInfo (Guid, TokenNumber, PcdInfo);\r
421}\r
422\r
423/**\r
424 Retrieve the currently set SKU Id.\r
425\r
426 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the\r
427 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r
428 Id is returned.\r
429**/\r
430UINTN\r
431EFIAPI\r
432PeiGetPcdInfoGetSku (\r
433 VOID\r
434 )\r
435{\r
b6e89910 436 return (UINTN) GetPcdDatabase()->SystemSkuId;\r
96d6d004
SZ
437}\r
438\r
fc547e08 439/**\r
440 Sets the SKU value for subsequent calls to set or get PCD token values.\r
441\r
442 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values. \r
443 SetSku() is normally called only once by the system.\r
444\r
445 For each item (token), the database can hold a single value that applies to all SKUs, \r
446 or multiple values, where each value is associated with a specific SKU Id. Items with multiple, \r
447 SKU-specific values are called SKU enabled. \r
448 \r
120ca3ce 449 The SKU Id of zero is reserved as a default.\r
fc547e08 450 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the \r
451 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the \r
452 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token, \r
453 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been \r
454 set for that Id, the results are unpredictable.\r
455\r
456 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and \r
457 set values associated with a PCD token.\r
458\r
fc547e08 459**/\r
80408db0 460VOID\r
461EFIAPI\r
462PeiPcdSetSku (\r
463 IN UINTN SkuId\r
464 )\r
465{\r
85d0b97d
SZ
466 PEI_PCD_DATABASE *PeiPcdDb;\r
467 SKU_ID *SkuIdTable;\r
468 UINTN Index;\r
7c736265
LG
469 EFI_STATUS Status;\r
470 UINTN Instance;\r
471 EFI_PEI_FV_HANDLE VolumeHandle;\r
472 EFI_PEI_FILE_HANDLE FileHandle;\r
473 VOID *PcdDb;\r
474 UINT32 Length;\r
475 PCD_DATABASE_SKU_DELTA *SkuDelta;\r
476 PCD_DATA_DELTA *SkuDeltaData;\r
85d0b97d
SZ
477\r
478 PeiPcdDb = GetPcdDatabase();\r
2db48a1f
SZ
479\r
480 if (SkuId == PeiPcdDb->SystemSkuId) {\r
481 //\r
482 // The input SKU Id is equal to current SKU Id, return directly.\r
483 //\r
484 return;\r
485 }\r
486\r
487 if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r
488 DEBUG ((DEBUG_ERROR, "PcdPei - The SKU Id could be changed only once."));\r
489 DEBUG ((\r
490 DEBUG_ERROR,\r
491 "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r
492 PeiPcdDb->SystemSkuId,\r
493 (SKU_ID) SkuId\r
494 ));\r
495 ASSERT (FALSE);\r
496 return;\r
497 }\r
498\r
85d0b97d
SZ
499 SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r
500 for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
501 if (SkuId == SkuIdTable[Index + 1]) {\r
7c736265
LG
502 break;\r
503 }\r
504 }\r
505\r
506 if (Index < SkuIdTable[0]) {\r
507 //\r
508 // Get full PCD database from PcdPeim FileHandle\r
509 //\r
510 Instance = 0;\r
511 FileHandle = NULL;\r
512 while (TRUE) {\r
513 //\r
514 // Traverse all firmware volume instances\r
515 //\r
516 Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r
517 //\r
518 // Error should not happen\r
519 //\r
520 ASSERT_EFI_ERROR (Status);\r
521\r
522 //\r
523 // Find PcdDb file from the beginning in this firmware volume.\r
524 //\r
525 FileHandle = NULL;\r
526 Status = PeiServicesFfsFindFileByName (&gEfiCallerIdGuid, VolumeHandle, &FileHandle);\r
527 if (!EFI_ERROR (Status)) {\r
528 //\r
529 // Find PcdPeim FileHandle in this volume\r
530 //\r
531 break;\r
532 }\r
533 //\r
534 // We cannot find PcdPeim in this firmware volume, then search the next volume.\r
535 //\r
536 Instance++;\r
537 }\r
538\r
539 //\r
540 // Find the delta data between the different Skus\r
541 //\r
542 Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);\r
543 ASSERT_EFI_ERROR (Status);\r
544 Length = PeiPcdDb->LengthForAllSkus;\r
545 Index = (PeiPcdDb->Length + 7) & (~7);\r
546 SkuDelta = NULL;\r
547 while (Index < Length) {\r
548 SkuDelta = (PCD_DATABASE_SKU_DELTA *) ((UINT8 *) PcdDb + Index);\r
549 if (SkuDelta->SkuId == SkuId && SkuDelta->SkuIdCompared == 0) {\r
550 break;\r
551 }\r
552 Index = (Index + SkuDelta->Length + 7) & (~7);\r
553 }\r
554\r
555 //\r
556 // Patch the delta data into current PCD database\r
557 //\r
558 if (Index < Length && SkuDelta != NULL) {\r
559 SkuDeltaData = (PCD_DATA_DELTA *) (SkuDelta + 1);\r
560 while ((UINT8 *) SkuDeltaData < (UINT8 *) SkuDelta + SkuDelta->Length) {\r
561 *((UINT8 *) PeiPcdDb + SkuDeltaData->Offset) = (UINT8) SkuDeltaData->Value;\r
562 SkuDeltaData ++;\r
563 }\r
85d0b97d 564 PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;\r
7c736265 565 DEBUG ((DEBUG_INFO, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID) SkuId));\r
85d0b97d
SZ
566 return;\r
567 }\r
568 }\r
80408db0 569\r
85d0b97d 570 //\r
2db48a1f 571 // Invalid input SkuId, the default SKU Id will be still used for the system.\r
85d0b97d 572 //\r
2db48a1f 573 DEBUG ((EFI_D_INFO, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));\r
7c736265 574\r
80408db0 575 return;\r
576}\r
577\r
fc547e08 578/**\r
579 Retrieves an 8-bit value for a given PCD token.\r
80408db0 580\r
fc547e08 581 Retrieves the current byte-sized value for a PCD token number. \r
582 If the TokenNumber is invalid, the results are unpredictable.\r
583 \r
584 @param[in] TokenNumber The PCD token number. \r
80408db0 585\r
fc547e08 586 @return The UINT8 value.\r
587 \r
588**/\r
80408db0 589UINT8\r
590EFIAPI\r
591PeiPcdGet8 (\r
592 IN UINTN TokenNumber\r
593 )\r
594{\r
595 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
596}\r
597\r
fc547e08 598/**\r
599 Retrieves an 16-bit value for a given PCD token.\r
80408db0 600\r
fc547e08 601 Retrieves the current 16-bits value for a PCD token number. \r
602 If the TokenNumber is invalid, the results are unpredictable.\r
603 \r
604 @param[in] TokenNumber The PCD token number. \r
80408db0 605\r
fc547e08 606 @return The UINT16 value.\r
607 \r
608**/\r
80408db0 609UINT16\r
610EFIAPI\r
611PeiPcdGet16 (\r
612 IN UINTN TokenNumber\r
613 )\r
614{\r
615 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
616}\r
617\r
fc547e08 618/**\r
619 Retrieves an 32-bit value for a given PCD token.\r
80408db0 620\r
fc547e08 621 Retrieves the current 32-bits value for a PCD token number. \r
622 If the TokenNumber is invalid, the results are unpredictable.\r
623 \r
624 @param[in] TokenNumber The PCD token number. \r
80408db0 625\r
fc547e08 626 @return The UINT32 value.\r
627 \r
628**/\r
80408db0 629UINT32\r
630EFIAPI\r
631PeiPcdGet32 (\r
632 IN UINTN TokenNumber\r
633 )\r
634{\r
635 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
636}\r
637\r
fc547e08 638/**\r
639 Retrieves an 64-bit value for a given PCD token.\r
80408db0 640\r
fc547e08 641 Retrieves the current 64-bits value for a PCD token number. \r
642 If the TokenNumber is invalid, the results are unpredictable.\r
643 \r
644 @param[in] TokenNumber The PCD token number. \r
80408db0 645\r
fc547e08 646 @return The UINT64 value.\r
647 \r
648**/\r
80408db0 649UINT64\r
650EFIAPI\r
651PeiPcdGet64 (\r
652 IN UINTN TokenNumber\r
653 )\r
654{\r
655 return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r
656}\r
657\r
fc547e08 658/**\r
659 Retrieves a pointer to a value for a given PCD token.\r
660\r
661 Retrieves the current pointer to the buffer for a PCD token number. \r
662 Do not make any assumptions about the alignment of the pointer that \r
663 is returned by this function call. If the TokenNumber is invalid, \r
664 the results are unpredictable.\r
80408db0 665\r
fc547e08 666 @param[in] TokenNumber The PCD token number. \r
80408db0 667\r
3fd8027e 668 @return The pointer to the buffer to be retrieved.\r
fc547e08 669 \r
670**/\r
80408db0 671VOID *\r
672EFIAPI\r
673PeiPcdGetPtr (\r
674 IN UINTN TokenNumber\r
675 )\r
676{\r
677 return GetWorker (TokenNumber, 0);\r
678}\r
679\r
fc547e08 680/**\r
681 Retrieves a Boolean value for a given PCD token.\r
80408db0 682\r
fc547e08 683 Retrieves the current boolean value for a PCD token number. \r
684 Do not make any assumptions about the alignment of the pointer that \r
685 is returned by this function call. If the TokenNumber is invalid, \r
686 the results are unpredictable.\r
80408db0 687\r
fc547e08 688 @param[in] TokenNumber The PCD token number. \r
689\r
690 @return The Boolean value.\r
691 \r
692**/\r
80408db0 693BOOLEAN\r
694EFIAPI\r
695PeiPcdGetBool (\r
696 IN UINTN TokenNumber\r
697 )\r
698{\r
699 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
700}\r
701\r
fc547e08 702/**\r
703 Retrieves the size of the value for a given PCD token.\r
704\r
705 Retrieves the current size of a particular PCD token. \r
706 If the TokenNumber is invalid, the results are unpredictable.\r
80408db0 707\r
fc547e08 708 @param[in] TokenNumber The PCD token number. \r
80408db0 709\r
fc547e08 710 @return The size of the value for the PCD token.\r
711 \r
712**/\r
80408db0 713UINTN\r
714EFIAPI\r
715PeiPcdGetSize (\r
716 IN UINTN TokenNumber\r
717 )\r
718{\r
719 PEI_PCD_DATABASE *PeiPcdDb;\r
720 UINTN Size;\r
721 UINTN MaxSize;\r
419db80b 722 UINT32 LocalTokenCount;\r
80408db0 723\r
419db80b
BF
724 PeiPcdDb = GetPcdDatabase ();\r
725 LocalTokenCount = PeiPcdDb->LocalTokenCount;\r
80408db0 726 //\r
727 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
728 // We have to decrement TokenNumber by 1 to make it usable\r
729 // as the array index.\r
730 //\r
731 TokenNumber--;\r
732\r
733 // EBC compiler is very choosy. It may report warning about comparison\r
734 // between UINTN and 0 . So we add 1 in each size of the \r
735 // comparison.\r
419db80b 736 ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));\r
80408db0 737\r
419db80b 738 Size = (*((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber) & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
80408db0 739\r
740 if (Size == 0) {\r
741 //\r
742 // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r
743 //\r
744 return GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);\r
745 } else {\r
746 return Size;\r
747 }\r
748\r
749}\r
750\r
fc547e08 751/**\r
752 Retrieves an 8-bit value for a given PCD token.\r
80408db0 753\r
fc547e08 754 Retrieves the 8-bit value of a particular PCD token. \r
755 If the TokenNumber is invalid or the token space\r
756 specified by Guid does not exist, the results are \r
757 unpredictable.\r
80408db0 758\r
fc547e08 759 @param[in] Guid The token space for the token number.\r
760 @param[in] ExTokenNumber The PCD token number. \r
761\r
762 @return The size 8-bit value for the PCD token.\r
763 \r
764**/\r
80408db0 765UINT8\r
766EFIAPI\r
767PeiPcdGet8Ex (\r
768 IN CONST EFI_GUID *Guid,\r
769 IN UINTN ExTokenNumber\r
770 )\r
771{\r
772 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r
773}\r
774\r
fc547e08 775/**\r
776 Retrieves an 16-bit value for a given PCD token.\r
80408db0 777\r
fc547e08 778 Retrieves the 16-bit value of a particular PCD token. \r
779 If the TokenNumber is invalid or the token space\r
780 specified by Guid does not exist, the results are \r
781 unpredictable.\r
80408db0 782\r
fc547e08 783 @param[in] Guid The token space for the token number.\r
784 @param[in] ExTokenNumber The PCD token number. \r
785\r
786 @return The size 16-bit value for the PCD token.\r
787 \r
788**/\r
80408db0 789UINT16\r
790EFIAPI\r
791PeiPcdGet16Ex (\r
792 IN CONST EFI_GUID *Guid,\r
793 IN UINTN ExTokenNumber\r
794 )\r
795{\r
796 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r
797}\r
798\r
fc547e08 799/**\r
800 Retrieves an 32-bit value for a given PCD token.\r
801\r
802 Retrieves the 32-bit value of a particular PCD token. \r
803 If the TokenNumber is invalid or the token space\r
804 specified by Guid does not exist, the results are \r
805 unpredictable.\r
80408db0 806\r
fc547e08 807 @param[in] Guid The token space for the token number.\r
808 @param[in] ExTokenNumber The PCD token number. \r
80408db0 809\r
fc547e08 810 @return The size 32-bit value for the PCD token.\r
811 \r
812**/\r
80408db0 813UINT32\r
814EFIAPI\r
815PeiPcdGet32Ex (\r
816 IN CONST EFI_GUID *Guid,\r
817 IN UINTN ExTokenNumber\r
818 )\r
819{\r
820 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r
821}\r
822\r
fc547e08 823/**\r
824 Retrieves an 64-bit value for a given PCD token.\r
825\r
826 Retrieves the 64-bit value of a particular PCD token. \r
827 If the TokenNumber is invalid or the token space\r
828 specified by Guid does not exist, the results are \r
829 unpredictable.\r
80408db0 830\r
fc547e08 831 @param[in] Guid The token space for the token number.\r
832 @param[in] ExTokenNumber The PCD token number. \r
80408db0 833\r
fc547e08 834 @return The size 64-bit value for the PCD token.\r
835 \r
836**/\r
80408db0 837UINT64\r
838EFIAPI\r
839PeiPcdGet64Ex (\r
840 IN CONST EFI_GUID *Guid,\r
841 IN UINTN ExTokenNumber\r
842 )\r
843{\r
844 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r
845}\r
846\r
fc547e08 847/**\r
848 Retrieves a pointer to a value for a given PCD token.\r
80408db0 849\r
fc547e08 850 Retrieves the current pointer to the buffer for a PCD token number. \r
851 Do not make any assumptions about the alignment of the pointer that \r
852 is returned by this function call. If the TokenNumber is invalid, \r
853 the results are unpredictable.\r
80408db0 854\r
fc547e08 855 @param[in] Guid The token space for the token number.\r
856 @param[in] ExTokenNumber The PCD token number. \r
857\r
3fd8027e 858 @return The pointer to the buffer to be retrieved.\r
fc547e08 859 \r
860**/\r
80408db0 861VOID *\r
862EFIAPI\r
863PeiPcdGetPtrEx (\r
864 IN CONST EFI_GUID *Guid,\r
865 IN UINTN ExTokenNumber\r
866 )\r
867{\r
868 return ExGetWorker (Guid, ExTokenNumber, 0);\r
869}\r
870\r
fc547e08 871/**\r
872 Retrieves an Boolean value for a given PCD token.\r
873\r
874 Retrieves the Boolean value of a particular PCD token. \r
875 If the TokenNumber is invalid or the token space\r
876 specified by Guid does not exist, the results are \r
877 unpredictable.\r
80408db0 878\r
fc547e08 879 @param[in] Guid The token space for the token number.\r
880 @param[in] ExTokenNumber The PCD token number. \r
80408db0 881\r
fc547e08 882 @return The size Boolean value for the PCD token.\r
883 \r
884**/\r
80408db0 885BOOLEAN\r
886EFIAPI\r
887PeiPcdGetBoolEx (\r
888 IN CONST EFI_GUID *Guid,\r
889 IN UINTN ExTokenNumber\r
890 )\r
891{\r
892 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r
893}\r
894\r
fc547e08 895/**\r
896 Retrieves the size of the value for a given PCD token.\r
897\r
898 Retrieves the current size of a particular PCD token. \r
899 If the TokenNumber is invalid, the results are unpredictable.\r
80408db0 900\r
fc547e08 901 @param[in] Guid The token space for the token number.\r
902 @param[in] ExTokenNumber The PCD token number. \r
80408db0 903\r
fc547e08 904 @return The size of the value for the PCD token.\r
905 \r
906**/\r
80408db0 907UINTN\r
908EFIAPI\r
909PeiPcdGetSizeEx (\r
910 IN CONST EFI_GUID *Guid,\r
911 IN UINTN ExTokenNumber\r
912 )\r
913{\r
80408db0 914 return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));\r
915}\r
916\r
fc547e08 917/**\r
918 Sets an 8-bit value for a given PCD token.\r
80408db0 919\r
fc547e08 920 When the PCD service sets a value, it will check to ensure that the \r
921 size of the value being set is compatible with the Token's existing definition. \r
922 If it is not, an error will be returned.\r
80408db0 923\r
fc547e08 924 @param[in] TokenNumber The PCD token number. \r
925 @param[in] Value The value to set for the PCD token.\r
926\r
927 @retval EFI_SUCCESS Procedure returned successfully.\r
928 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
929 being set was incompatible with a call to this function. \r
930 Use GetSize() to retrieve the size of the target data.\r
931 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
932 \r
933**/\r
80408db0 934EFI_STATUS\r
935EFIAPI\r
936PeiPcdSet8 (\r
937 IN UINTN TokenNumber,\r
938 IN UINT8 Value\r
939 )\r
940{\r
941 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
942}\r
943\r
fc547e08 944/**\r
945 Sets an 16-bit value for a given PCD token.\r
946\r
947 When the PCD service sets a value, it will check to ensure that the \r
948 size of the value being set is compatible with the Token's existing definition. \r
949 If it is not, an error will be returned.\r
80408db0 950\r
fc547e08 951 @param[in] TokenNumber The PCD token number. \r
952 @param[in] Value The value to set for the PCD token.\r
80408db0 953\r
fc547e08 954 @retval EFI_SUCCESS Procedure returned successfully.\r
955 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
956 being set was incompatible with a call to this function. \r
957 Use GetSize() to retrieve the size of the target data.\r
958 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
959 \r
960**/\r
80408db0 961EFI_STATUS\r
962EFIAPI\r
963PeiPcdSet16 (\r
964 IN UINTN TokenNumber,\r
965 IN UINT16 Value\r
966 )\r
967{\r
968 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
969}\r
970\r
fc547e08 971/**\r
972 Sets an 32-bit value for a given PCD token.\r
80408db0 973\r
fc547e08 974 When the PCD service sets a value, it will check to ensure that the \r
975 size of the value being set is compatible with the Token's existing definition. \r
976 If it is not, an error will be returned.\r
80408db0 977\r
fc547e08 978 @param[in] TokenNumber The PCD token number. \r
979 @param[in] Value The value to set for the PCD token.\r
980\r
981 @retval EFI_SUCCESS Procedure returned successfully.\r
982 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
983 being set was incompatible with a call to this function. \r
984 Use GetSize() to retrieve the size of the target data.\r
985 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
986 \r
987**/\r
80408db0 988EFI_STATUS\r
989EFIAPI\r
990PeiPcdSet32 (\r
991 IN UINTN TokenNumber,\r
992 IN UINT32 Value\r
993 )\r
994{\r
995 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
996}\r
997\r
fc547e08 998/**\r
999 Sets an 64-bit value for a given PCD token.\r
1000\r
1001 When the PCD service sets a value, it will check to ensure that the \r
1002 size of the value being set is compatible with the Token's existing definition. \r
1003 If it is not, an error will be returned.\r
80408db0 1004\r
fc547e08 1005 @param[in] TokenNumber The PCD token number. \r
1006 @param[in] Value The value to set for the PCD token.\r
80408db0 1007\r
fc547e08 1008 @retval EFI_SUCCESS Procedure returned successfully.\r
1009 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1010 being set was incompatible with a call to this function. \r
1011 Use GetSize() to retrieve the size of the target data.\r
1012 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1013 \r
1014**/\r
80408db0 1015EFI_STATUS\r
1016EFIAPI\r
1017PeiPcdSet64 (\r
1018 IN UINTN TokenNumber,\r
1019 IN UINT64 Value\r
1020 )\r
1021{\r
1022 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
1023}\r
1024\r
fc547e08 1025/**\r
1026 Sets a value of a specified size for a given PCD token.\r
1027\r
1028 When the PCD service sets a value, it will check to ensure that the \r
1029 size of the value being set is compatible with the Token's existing definition. \r
1030 If it is not, an error will be returned.\r
1031\r
1032 @param[in] TokenNumber The PCD token number. \r
1033 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
1034 On input, if the SizeOfValue is greater than the maximum size supported \r
1035 for this TokenNumber then the output value of SizeOfValue will reflect \r
1036 the maximum size supported for this TokenNumber.\r
1037 @param[in] Buffer The buffer to set for the PCD token.\r
1038\r
1039 @retval EFI_SUCCESS Procedure returned successfully.\r
1040 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1041 being set was incompatible with a call to this function. \r
1042 Use GetSize() to retrieve the size of the target data.\r
1043 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1044 \r
1045**/\r
80408db0 1046EFI_STATUS\r
1047EFIAPI\r
1048PeiPcdSetPtr (\r
1049 IN UINTN TokenNumber,\r
1050 IN OUT UINTN *SizeOfBuffer,\r
1051 IN VOID *Buffer\r
1052 )\r
1053{\r
1054 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
1055}\r
1056\r
fc547e08 1057/**\r
1058 Sets an Boolean value for a given PCD token.\r
80408db0 1059\r
fc547e08 1060 When the PCD service sets a value, it will check to ensure that the \r
1061 size of the value being set is compatible with the Token's existing definition. \r
1062 If it is not, an error will be returned.\r
80408db0 1063\r
fc547e08 1064 @param[in] TokenNumber The PCD token number. \r
1065 @param[in] Value The value to set for the PCD token.\r
1066\r
1067 @retval EFI_SUCCESS Procedure returned successfully.\r
1068 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1069 being set was incompatible with a call to this function. \r
1070 Use GetSize() to retrieve the size of the target data.\r
1071 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1072 \r
1073**/\r
80408db0 1074EFI_STATUS\r
1075EFIAPI\r
1076PeiPcdSetBool (\r
1077 IN UINTN TokenNumber,\r
1078 IN BOOLEAN Value\r
1079 )\r
1080{\r
1081 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
1082}\r
1083\r
fc547e08 1084/**\r
1085 Sets an 8-bit value for a given PCD token.\r
80408db0 1086\r
fc547e08 1087 When the PCD service sets a value, it will check to ensure that the \r
1088 size of the value being set is compatible with the Token's existing definition. \r
1089 If it is not, an error will be returned.\r
80408db0 1090\r
fc547e08 1091 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1092 @param[in] ExTokenNumber The PCD token number. \r
1093 @param[in] Value The value to set for the PCD token.\r
1094\r
1095 @retval EFI_SUCCESS Procedure returned successfully.\r
1096 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1097 being set was incompatible with a call to this function. \r
1098 Use GetSize() to retrieve the size of the target data.\r
1099 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1100 \r
1101**/\r
80408db0 1102EFI_STATUS\r
1103EFIAPI\r
1104PeiPcdSet8Ex (\r
1105 IN CONST EFI_GUID *Guid,\r
1106 IN UINTN ExTokenNumber,\r
1107 IN UINT8 Value\r
1108 )\r
1109{\r
1110 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
1111}\r
1112\r
fc547e08 1113/**\r
1114 Sets an 16-bit value for a given PCD token.\r
1115\r
1116 When the PCD service sets a value, it will check to ensure that the \r
1117 size of the value being set is compatible with the Token's existing definition. \r
1118 If it is not, an error will be returned.\r
80408db0 1119\r
fc547e08 1120 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1121 @param[in] ExTokenNumber The PCD token number. \r
1122 @param[in] Value The value to set for the PCD token.\r
80408db0 1123\r
fc547e08 1124 @retval EFI_SUCCESS Procedure returned successfully.\r
1125 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1126 being set was incompatible with a call to this function. \r
1127 Use GetSize() to retrieve the size of the target data.\r
1128 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1129 \r
1130**/\r
80408db0 1131EFI_STATUS\r
1132EFIAPI\r
1133PeiPcdSet16Ex (\r
1134 IN CONST EFI_GUID *Guid,\r
1135 IN UINTN ExTokenNumber,\r
1136 IN UINT16 Value\r
1137 )\r
1138{\r
1139 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
1140}\r
1141\r
fc547e08 1142/**\r
1143 Sets an 32-bit value for a given PCD token.\r
1144\r
1145 When the PCD service sets a value, it will check to ensure that the \r
1146 size of the value being set is compatible with the Token's existing definition. \r
1147 If it is not, an error will be returned.\r
80408db0 1148\r
fc547e08 1149 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1150 @param[in] ExTokenNumber The PCD token number. \r
1151 @param[in] Value The value to set for the PCD token.\r
80408db0 1152\r
fc547e08 1153 @retval EFI_SUCCESS Procedure returned successfully.\r
1154 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1155 being set was incompatible with a call to this function. \r
1156 Use GetSize() to retrieve the size of the target data.\r
1157 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1158 \r
1159**/\r
80408db0 1160EFI_STATUS\r
1161EFIAPI\r
1162PeiPcdSet32Ex (\r
1163 IN CONST EFI_GUID *Guid,\r
1164 IN UINTN ExTokenNumber,\r
1165 IN UINT32 Value\r
1166 )\r
1167{\r
1168 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
1169}\r
1170\r
fc547e08 1171/**\r
1172 Sets an 64-bit value for a given PCD token.\r
80408db0 1173\r
fc547e08 1174 When the PCD service sets a value, it will check to ensure that the \r
1175 size of the value being set is compatible with the Token's existing definition. \r
1176 If it is not, an error will be returned.\r
80408db0 1177\r
fc547e08 1178 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1179 @param[in] ExTokenNumber The PCD token number. \r
1180 @param[in] Value The value to set for the PCD token.\r
1181\r
1182 @retval EFI_SUCCESS Procedure returned successfully.\r
1183 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1184 being set was incompatible with a call to this function. \r
1185 Use GetSize() to retrieve the size of the target data.\r
1186 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1187 \r
1188**/\r
80408db0 1189EFI_STATUS\r
1190EFIAPI\r
1191PeiPcdSet64Ex (\r
1192 IN CONST EFI_GUID *Guid,\r
1193 IN UINTN ExTokenNumber,\r
1194 IN UINT64 Value\r
1195 )\r
1196{\r
1197 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
1198}\r
1199\r
fc547e08 1200/**\r
1201 Sets a value of a specified size for a given PCD token.\r
1202\r
1203 When the PCD service sets a value, it will check to ensure that the \r
1204 size of the value being set is compatible with the Token's existing definition. \r
1205 If it is not, an error will be returned.\r
1206\r
1207 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1208 @param[in] ExTokenNumber The PCD token number. \r
1209 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
1210 On input, if the SizeOfValue is greater than the maximum size supported \r
1211 for this TokenNumber then the output value of SizeOfValue will reflect \r
1212 the maximum size supported for this TokenNumber.\r
1213 @param[in] Value The buffer to set for the PCD token.\r
1214\r
1215 @retval EFI_SUCCESS Procedure returned successfully.\r
1216 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1217 being set was incompatible with a call to this function. \r
1218 Use GetSize() to retrieve the size of the target data.\r
1219 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1220 \r
1221**/\r
80408db0 1222EFI_STATUS\r
1223EFIAPI\r
1224PeiPcdSetPtrEx (\r
fc547e08 1225 IN CONST EFI_GUID *Guid,\r
1226 IN UINTN ExTokenNumber,\r
1227 IN OUT UINTN *SizeOfBuffer,\r
1228 IN VOID *Value\r
80408db0 1229 )\r
1230{\r
1231 return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);\r
1232}\r
1233\r
fc547e08 1234/**\r
1235 Sets an Boolean value for a given PCD token.\r
1236\r
1237 When the PCD service sets a value, it will check to ensure that the \r
1238 size of the value being set is compatible with the Token's existing definition. \r
1239 If it is not, an error will be returned.\r
80408db0 1240\r
fc547e08 1241 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1242 @param [in] ExTokenNumber The PCD token number. \r
1243 @param [in] Value The value to set for the PCD token.\r
80408db0 1244\r
fc547e08 1245 @retval EFI_SUCCESS Procedure returned successfully.\r
1246 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1247 being set was incompatible with a call to this function. \r
1248 Use GetSize() to retrieve the size of the target data.\r
1249 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1250 \r
1251**/\r
80408db0 1252EFI_STATUS\r
1253EFIAPI\r
1254PeiPcdSetBoolEx (\r
1255 IN CONST EFI_GUID *Guid,\r
1256 IN UINTN ExTokenNumber,\r
1257 IN BOOLEAN Value\r
1258 )\r
1259{\r
1260 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
1261}\r
1262\r
fc547e08 1263/**\r
1264 Specifies a function to be called anytime the value of a designated token is changed.\r
80408db0 1265\r
fc547e08 1266 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1267 @param[in] ExTokenNumber The PCD token number. \r
1268 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
80408db0 1269\r
fc547e08 1270 @retval EFI_SUCCESS The PCD service has successfully established a call event \r
1271 for the CallBackToken requested.\r
1272 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
80408db0 1273\r
fc547e08 1274**/\r
80408db0 1275EFI_STATUS\r
1276EFIAPI\r
1277PeiRegisterCallBackOnSet (\r
1278 IN CONST EFI_GUID *Guid, OPTIONAL\r
1279 IN UINTN ExTokenNumber,\r
1280 IN PCD_PPI_CALLBACK CallBackFunction\r
1281 )\r
1282{\r
f806dd27 1283 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1284 return EFI_UNSUPPORTED;\r
1285 }\r
1286\r
e4a3922f 1287 if (CallBackFunction == NULL) {\r
1288 return EFI_INVALID_PARAMETER;\r
1289 }\r
1290\r
80408db0 1291 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);\r
1292}\r
1293\r
fc547e08 1294/**\r
1295 Cancels a previously set callback function for a particular PCD token number.\r
80408db0 1296\r
fc547e08 1297 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1298 @param[in] ExTokenNumber The PCD token number. \r
1299 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
80408db0 1300\r
fc547e08 1301 @retval EFI_SUCCESS The PCD service has successfully established a call event \r
1302 for the CallBackToken requested.\r
1303 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
1304\r
1305**/\r
80408db0 1306EFI_STATUS\r
1307EFIAPI\r
1308PcdUnRegisterCallBackOnSet (\r
1309 IN CONST EFI_GUID *Guid, OPTIONAL\r
1310 IN UINTN ExTokenNumber,\r
1311 IN PCD_PPI_CALLBACK CallBackFunction\r
1312 )\r
1313{\r
f806dd27 1314 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1315 return EFI_UNSUPPORTED;\r
1316 }\r
1317\r
e4a3922f 1318 if (CallBackFunction == NULL) {\r
1319 return EFI_INVALID_PARAMETER;\r
1320 }\r
1321\r
80408db0 1322 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);\r
1323}\r
1324\r
fc547e08 1325/**\r
90e06556 1326 Retrieves the next valid token number in a given namespace. \r
1327 \r
1328 This is useful since the PCD infrastructure contains a sparse list of token numbers, \r
1329 and one cannot a priori know what token numbers are valid in the database. \r
1330 \r
1331 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned. \r
1332 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned. \r
1333 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned. \r
1334 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned. \r
1335 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid. \r
1336 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned. \r
1337 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned. \r
1338 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r
1339\r
1340\r
1341 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value. \r
1342 This is an optional parameter that may be NULL. If this parameter is NULL, then a request \r
1343 is being made to retrieve tokens from the default token space.\r
1344 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.\r
1345 \r
419db80b
BF
1346 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.\r
1347 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.\r
fc547e08 1348\r
1349**/\r
80408db0 1350EFI_STATUS\r
1351EFIAPI\r
1352PeiPcdGetNextToken (\r
1353 IN CONST EFI_GUID *Guid, OPTIONAL\r
1354 IN OUT UINTN *TokenNumber\r
1355 )\r
1356{\r
1357 UINTN GuidTableIdx;\r
1358 PEI_PCD_DATABASE *PeiPcdDb;\r
1359 EFI_GUID *MatchGuid;\r
419db80b 1360 EFI_GUID *GuidTable;\r
80408db0 1361 DYNAMICEX_MAPPING *ExMapTable;\r
fc547e08 1362 UINTN Index;\r
80408db0 1363 BOOLEAN Found;\r
1364 BOOLEAN PeiExMapTableEmpty;\r
419db80b 1365 UINTN PeiNexTokenNumber; \r
80408db0 1366\r
f806dd27 1367 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1368 return EFI_UNSUPPORTED;\r
1369 }\r
1370\r
419db80b
BF
1371 PeiPcdDb = GetPcdDatabase ();\r
1372 PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount;\r
1373 GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r
80408db0 1374\r
419db80b
BF
1375 if (PeiPcdDb->ExTokenCount == 0) {\r
1376 PeiExMapTableEmpty = TRUE;\r
1377 } else {\r
1378 PeiExMapTableEmpty = FALSE;\r
1379 }\r
80408db0 1380 if (Guid == NULL) {\r
419db80b 1381 if (*TokenNumber > PeiNexTokenNumber) {\r
80408db0 1382 return EFI_NOT_FOUND;\r
1383 }\r
1384 (*TokenNumber)++;\r
419db80b 1385 if (*TokenNumber > PeiNexTokenNumber) {\r
80408db0 1386 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
419db80b 1387 return EFI_NOT_FOUND;\r
80408db0 1388 }\r
1389 return EFI_SUCCESS;\r
1390 } else {\r
1391 if (PeiExMapTableEmpty) {\r
419db80b 1392 return EFI_NOT_FOUND;\r
80408db0 1393 }\r
419db80b
BF
1394\r
1395 MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid);\r
80408db0 1396\r
1397 if (MatchGuid == NULL) {\r
80408db0 1398 return EFI_NOT_FOUND;\r
1399 }\r
1400\r
419db80b 1401 GuidTableIdx = MatchGuid - GuidTable;\r
80408db0 1402\r
419db80b 1403 ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r
80408db0 1404\r
1405 Found = FALSE;\r
1406 //\r
1407 // Locate the GUID in ExMapTable first.\r
1408 //\r
419db80b 1409 for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r
fc547e08 1410 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
80408db0 1411 Found = TRUE;\r
1412 break;\r
1413 }\r
1414 }\r
1415\r
1416 if (Found) {\r
bfb4c2ba
CS
1417 //\r
1418 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first\r
1419 // token number in found token space.\r
1420 //\r
80408db0 1421 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r
fc547e08 1422 *TokenNumber = ExMapTable[Index].ExTokenNumber;\r
80408db0 1423 return EFI_SUCCESS;\r
1424 }\r
1425\r
419db80b 1426 for ( ; Index < PeiPcdDb->ExTokenCount; Index++) {\r
bfb4c2ba 1427 if ((ExMapTable[Index].ExTokenNumber == *TokenNumber) && (ExMapTable[Index].ExGuidIndex == GuidTableIdx)) {\r
419db80b
BF
1428 break;\r
1429 }\r
1430 }\r
1431\r
1432 while (Index < PeiPcdDb->ExTokenCount) {\r
1433 Index++;\r
1434 if (Index == PeiPcdDb->ExTokenCount) {\r
1435 //\r
1436 // Exceed the length of ExMap Table\r
1437 //\r
1438 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
1439 return EFI_NOT_FOUND;\r
1440 } else if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
1441 //\r
1442 // Found the next match\r
1443 //\r
1444 *TokenNumber = ExMapTable[Index].ExTokenNumber;\r
1445 return EFI_SUCCESS;\r
80408db0 1446 }\r
1447 }\r
80408db0 1448 }\r
1449 }\r
1450\r
1451 return EFI_NOT_FOUND;\r
1452}\r
1453\r
fc547e08 1454/**\r
1455 Retrieves the next valid PCD token namespace for a given namespace.\r
1456\r
419db80b
BF
1457 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid\r
1458 token namespaces on a platform.\r
1459\r
1460 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token\r
1461 namespace from which the search will start. On output, it designates the next valid\r
1462 token namespace on the platform. If *Guid is NULL, then the GUID of the first token\r
1463 space of the current platform is returned. If the search cannot locate the next valid\r
1464 token namespace, an error is returned and the value of *Guid is undefined.\r
1465 \r
1466 @retval EFI_SUCCESS The PCD service retrieved the value requested.\r
1467 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.\r
80408db0 1468\r
fc547e08 1469**/\r
80408db0 1470EFI_STATUS\r
1471EFIAPI\r
1472PeiPcdGetNextTokenSpace (\r
1473 IN OUT CONST EFI_GUID **Guid\r
1474 )\r
1475{\r
1476 UINTN GuidTableIdx;\r
1477 EFI_GUID *MatchGuid;\r
1478 PEI_PCD_DATABASE *PeiPcdDb;\r
1479 DYNAMICEX_MAPPING *ExMapTable;\r
fc547e08 1480 UINTN Index;\r
419db80b 1481 UINTN Index2;\r
80408db0 1482 BOOLEAN Found;\r
1483 BOOLEAN PeiExMapTableEmpty;\r
419db80b 1484 EFI_GUID *GuidTable;\r
80408db0 1485\r
f806dd27 1486 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1487 return EFI_UNSUPPORTED;\r
1488 }\r
1489\r
1490 ASSERT (Guid != NULL);\r
1491\r
419db80b 1492 PeiPcdDb = GetPcdDatabase ();\r
80408db0 1493\r
419db80b
BF
1494 if (PeiPcdDb->ExTokenCount == 0) {\r
1495 PeiExMapTableEmpty = TRUE;\r
1496 } else {\r
1497 PeiExMapTableEmpty = FALSE;\r
1498 }\r
1499 \r
80408db0 1500 if (PeiExMapTableEmpty) {\r
419db80b 1501 return EFI_NOT_FOUND;\r
80408db0 1502 }\r
1503\r
419db80b
BF
1504 ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r
1505 GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r
1506 \r
80408db0 1507 if (*Guid == NULL) {\r
1508 //\r
1509 // return the first Token Space Guid.\r
1510 //\r
419db80b 1511 *Guid = GuidTable + ExMapTable[0].ExGuidIndex;\r
80408db0 1512 return EFI_SUCCESS;\r
1513 }\r
1514\r
419db80b 1515 MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(GuidTable[0]), *Guid);\r
80408db0 1516\r
1517 if (MatchGuid == NULL) {\r
1518 return EFI_NOT_FOUND;\r
1519 }\r
1520 \r
419db80b 1521 GuidTableIdx = MatchGuid - GuidTable;\r
80408db0 1522\r
1523 Found = FALSE;\r
419db80b 1524 for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r
fc547e08 1525 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
80408db0 1526 Found = TRUE;\r
1527 break;\r
1528 }\r
1529 }\r
1530\r
1531 if (Found) {\r
fc547e08 1532 Index++;\r
419db80b
BF
1533 for ( ; Index < PeiPcdDb->ExTokenCount; Index++ ) {\r
1534 if (ExMapTable[Index].ExGuidIndex != GuidTableIdx) {\r
1535 Found = FALSE;\r
1536 for (Index2 = 0 ; Index2 < Index; Index2++) {\r
1537 if (ExMapTable[Index2].ExGuidIndex == ExMapTable[Index].ExGuidIndex) {\r
1538 //\r
1539 // This token namespace should have been found and output at preceding getting.\r
1540 //\r
1541 Found = TRUE;\r
1542 break;\r
1543 }\r
1544 }\r
1545 if (!Found) {\r
1546 *Guid = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + ExMapTable[Index].ExGuidIndex;\r
1547 return EFI_SUCCESS;\r
1548 }\r
80408db0 1549 }\r
1550 }\r
1551 *Guid = NULL;\r
80408db0 1552 }\r
1553\r
1554 return EFI_NOT_FOUND;\r
1555\r
1556}\r
1557\r
fc547e08 1558/**\r
1559 Get PCD value's size for POINTER type PCD.\r
1560 \r
419db80b 1561 The POINTER type PCD's value will be stored into a buffer in specified size.\r
fc547e08 1562 The max size of this PCD's value is described in PCD's definition in DEC file.\r
1563\r
1564 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r
3fd8027e 1565 @param MaxSize Maximum size of PCD's value\r
fc547e08 1566 @param Database Pcd database in PEI phase.\r
1567\r
1568 @return PCD value's size for POINTER type PCD.\r
1569\r
1570**/\r
80408db0 1571UINTN\r
1572GetPtrTypeSize (\r
1573 IN UINTN LocalTokenNumberTableIdx,\r
1574 OUT UINTN *MaxSize,\r
1575 IN PEI_PCD_DATABASE *Database\r
1576 )\r
1577{\r
1578 INTN SizeTableIdx;\r
1579 UINTN LocalTokenNumber;\r
80408db0 1580 SIZE_INFO *SizeTable;\r
80408db0 1581\r
1582 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
1583\r
419db80b 1584 LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
80408db0 1585\r
1586 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
1587 \r
419db80b 1588 SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r
80408db0 1589\r
1590 *MaxSize = SizeTable[SizeTableIdx];\r
1591 //\r
1592 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
1593 // PCD entry.\r
1594 //\r
fc547e08 1595 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
80408db0 1596 //\r
419db80b 1597 // We have only two entry for VPD enabled PCD entry:\r
80408db0 1598 // 1) MAX Size.\r
419db80b 1599 // 2) Current Size\r
80408db0 1600 // We consider current size is equal to MAX size.\r
1601 //\r
1602 return *MaxSize;\r
1603 } else {\r
7c736265
LG
1604 //\r
1605 // We have only two entry for Non-Sku enabled PCD entry:\r
1606 // 1) MAX SIZE\r
1607 // 2) Current Size\r
1608 //\r
1609 return SizeTable[SizeTableIdx + 1];\r
80408db0 1610 }\r
1611}\r
1612\r
fc547e08 1613/**\r
1614 Set PCD value's size for POINTER type PCD.\r
1615 \r
419db80b 1616 The POINTER type PCD's value will be stored into a buffer in specified size.\r
fc547e08 1617 The max size of this PCD's value is described in PCD's definition in DEC file.\r
1618\r
1619 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r
3fd8027e 1620 @param CurrentSize Maximum size of PCD's value\r
fc547e08 1621 @param Database Pcd database in PEI phase.\r
80408db0 1622\r
3fd8027e 1623 @retval TRUE Success to set PCD's value size, which is not exceed maximum size\r
1624 @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size\r
80408db0 1625\r
fc547e08 1626**/\r
80408db0 1627BOOLEAN\r
1628SetPtrTypeSize (\r
1629 IN UINTN LocalTokenNumberTableIdx,\r
1630 IN OUT UINTN *CurrentSize,\r
1631 IN PEI_PCD_DATABASE *Database\r
1632 )\r
1633{\r
1634 INTN SizeTableIdx;\r
1635 UINTN LocalTokenNumber;\r
80408db0 1636 SIZE_INFO *SizeTable;\r
80408db0 1637 UINTN MaxSize;\r
1638 \r
1639 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
1640\r
419db80b 1641 LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
80408db0 1642\r
1643 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
419db80b
BF
1644\r
1645 SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r
80408db0 1646\r
1647 MaxSize = SizeTable[SizeTableIdx];\r
1648 //\r
1649 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
1650 // PCD entry.\r
1651 //\r
fc547e08 1652 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
80408db0 1653 //\r
1654 // We shouldn't come here as we don't support SET for VPD\r
1655 //\r
1656 ASSERT (FALSE);\r
1657 return FALSE;\r
1658 } else {\r
1659 if ((*CurrentSize > MaxSize) ||\r
1660 (*CurrentSize == MAX_ADDRESS)) {\r
1661 *CurrentSize = MaxSize;\r
1662 return FALSE;\r
5944a83b 1663 }\r
80408db0 1664 \r
7c736265
LG
1665 //\r
1666 // We have only two entry for Non-Sku enabled PCD entry:\r
1667 // 1) MAX SIZE\r
1668 // 2) Current Size\r
1669 //\r
1670 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r
1671 return TRUE;\r
80408db0 1672 }\r
1673\r
1674}\r