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