]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/PCD/Pei/Pcd.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Pcd.c
1 /** @file
2 All Pcd Ppi services are implemented here.
3
4 Copyright (c) 2006 - 2018, 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 DEBUG ((DEBUG_INFO, "PcdPei - SkuId 0x%lx is to be set.\n", (SKU_ID) SkuId));
479
480 PeiPcdDb = GetPcdDatabase();
481
482 if (SkuId == PeiPcdDb->SystemSkuId) {
483 //
484 // The input SKU Id is equal to current SKU Id, return directly.
485 //
486 DEBUG ((DEBUG_INFO, "PcdPei - SkuId is same to current system Sku.\n"));
487 return;
488 }
489
490 if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {
491 DEBUG ((DEBUG_ERROR, "PcdPei - The SKU Id could be changed only once."));
492 DEBUG ((
493 DEBUG_ERROR,
494 "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",
495 PeiPcdDb->SystemSkuId,
496 (SKU_ID) SkuId
497 ));
498 ASSERT (FALSE);
499 return;
500 }
501
502 SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);
503 for (Index = 0; Index < SkuIdTable[0]; Index++) {
504 if (SkuId == SkuIdTable[Index + 1]) {
505 DEBUG ((DEBUG_INFO, "PcdPei - SkuId is found in SkuId table.\n"));
506 break;
507 }
508 }
509
510 if (Index < SkuIdTable[0]) {
511 //
512 // Get full PCD database from PcdPeim FileHandle
513 //
514 Instance = 0;
515 FileHandle = NULL;
516 while (TRUE) {
517 //
518 // Traverse all firmware volume instances
519 //
520 Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);
521 //
522 // Error should not happen
523 //
524 ASSERT_EFI_ERROR (Status);
525
526 //
527 // Find PcdDb file from the beginning in this firmware volume.
528 //
529 FileHandle = NULL;
530 Status = PeiServicesFfsFindFileByName (&gEfiCallerIdGuid, VolumeHandle, &FileHandle);
531 if (!EFI_ERROR (Status)) {
532 //
533 // Find PcdPeim FileHandle in this volume
534 //
535 break;
536 }
537 //
538 // We cannot find PcdPeim in this firmware volume, then search the next volume.
539 //
540 Instance++;
541 }
542
543 //
544 // Find the delta data between the different Skus
545 //
546 Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);
547 ASSERT_EFI_ERROR (Status);
548 Length = PeiPcdDb->LengthForAllSkus;
549 Index = (PeiPcdDb->Length + 7) & (~7);
550 SkuDelta = NULL;
551 while (Index < Length) {
552 SkuDelta = (PCD_DATABASE_SKU_DELTA *) ((UINT8 *) PcdDb + Index);
553 if (SkuDelta->SkuId == SkuId && SkuDelta->SkuIdCompared == 0) {
554 break;
555 }
556 Index = (Index + SkuDelta->Length + 7) & (~7);
557 }
558
559 //
560 // Patch the delta data into current PCD database
561 //
562 if (Index < Length && SkuDelta != NULL) {
563 SkuDeltaData = (PCD_DATA_DELTA *) (SkuDelta + 1);
564 while ((UINT8 *) SkuDeltaData < (UINT8 *) SkuDelta + SkuDelta->Length) {
565 *((UINT8 *) PeiPcdDb + SkuDeltaData->Offset) = (UINT8) SkuDeltaData->Value;
566 SkuDeltaData ++;
567 }
568 PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;
569 DEBUG ((DEBUG_INFO, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID) SkuId));
570 return;
571 }
572 }
573
574 //
575 // Invalid input SkuId, the default SKU Id will be still used for the system.
576 //
577 DEBUG ((DEBUG_ERROR, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));
578
579 return;
580 }
581
582 /**
583 Retrieves an 8-bit value for a given PCD token.
584
585 Retrieves the current byte-sized value for a PCD token number.
586 If the TokenNumber is invalid, the results are unpredictable.
587
588 @param[in] TokenNumber The PCD token number.
589
590 @return The UINT8 value.
591
592 **/
593 UINT8
594 EFIAPI
595 PeiPcdGet8 (
596 IN UINTN TokenNumber
597 )
598 {
599 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));
600 }
601
602 /**
603 Retrieves an 16-bit value for a given PCD token.
604
605 Retrieves the current 16-bits value for a PCD token number.
606 If the TokenNumber is invalid, the results are unpredictable.
607
608 @param[in] TokenNumber The PCD token number.
609
610 @return The UINT16 value.
611
612 **/
613 UINT16
614 EFIAPI
615 PeiPcdGet16 (
616 IN UINTN TokenNumber
617 )
618 {
619 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));
620 }
621
622 /**
623 Retrieves an 32-bit value for a given PCD token.
624
625 Retrieves the current 32-bits value for a PCD token number.
626 If the TokenNumber is invalid, the results are unpredictable.
627
628 @param[in] TokenNumber The PCD token number.
629
630 @return The UINT32 value.
631
632 **/
633 UINT32
634 EFIAPI
635 PeiPcdGet32 (
636 IN UINTN TokenNumber
637 )
638 {
639 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));
640 }
641
642 /**
643 Retrieves an 64-bit value for a given PCD token.
644
645 Retrieves the current 64-bits value for a PCD token number.
646 If the TokenNumber is invalid, the results are unpredictable.
647
648 @param[in] TokenNumber The PCD token number.
649
650 @return The UINT64 value.
651
652 **/
653 UINT64
654 EFIAPI
655 PeiPcdGet64 (
656 IN UINTN TokenNumber
657 )
658 {
659 return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));
660 }
661
662 /**
663 Retrieves a pointer to a value for a given PCD token.
664
665 Retrieves the current pointer to the buffer for a PCD token number.
666 Do not make any assumptions about the alignment of the pointer that
667 is returned by this function call. If the TokenNumber is invalid,
668 the results are unpredictable.
669
670 @param[in] TokenNumber The PCD token number.
671
672 @return The pointer to the buffer to be retrieved.
673
674 **/
675 VOID *
676 EFIAPI
677 PeiPcdGetPtr (
678 IN UINTN TokenNumber
679 )
680 {
681 return GetWorker (TokenNumber, 0);
682 }
683
684 /**
685 Retrieves a Boolean value for a given PCD token.
686
687 Retrieves the current boolean value for a PCD token number.
688 Do not make any assumptions about the alignment of the pointer that
689 is returned by this function call. If the TokenNumber is invalid,
690 the results are unpredictable.
691
692 @param[in] TokenNumber The PCD token number.
693
694 @return The Boolean value.
695
696 **/
697 BOOLEAN
698 EFIAPI
699 PeiPcdGetBool (
700 IN UINTN TokenNumber
701 )
702 {
703 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));
704 }
705
706 /**
707 Retrieves the size of the value for a given PCD token.
708
709 Retrieves the current size of a particular PCD token.
710 If the TokenNumber is invalid, the results are unpredictable.
711
712 @param[in] TokenNumber The PCD token number.
713
714 @return The size of the value for the PCD token.
715
716 **/
717 UINTN
718 EFIAPI
719 PeiPcdGetSize (
720 IN UINTN TokenNumber
721 )
722 {
723 PEI_PCD_DATABASE *PeiPcdDb;
724 UINTN Size;
725 UINTN MaxSize;
726 UINT32 LocalTokenCount;
727
728 PeiPcdDb = GetPcdDatabase ();
729 LocalTokenCount = PeiPcdDb->LocalTokenCount;
730 //
731 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
732 // We have to decrement TokenNumber by 1 to make it usable
733 // as the array index.
734 //
735 TokenNumber--;
736
737 // EBC compiler is very choosy. It may report warning about comparison
738 // between UINTN and 0 . So we add 1 in each size of the
739 // comparison.
740 ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));
741
742 Size = (*((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber) & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;
743
744 if (Size == 0) {
745 //
746 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
747 //
748 return GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);
749 } else {
750 return Size;
751 }
752
753 }
754
755 /**
756 Retrieves an 8-bit value for a given PCD token.
757
758 Retrieves the 8-bit value of a particular PCD token.
759 If the TokenNumber is invalid or the token space
760 specified by Guid does not exist, the results are
761 unpredictable.
762
763 @param[in] Guid The token space for the token number.
764 @param[in] ExTokenNumber The PCD token number.
765
766 @return The size 8-bit value for the PCD token.
767
768 **/
769 UINT8
770 EFIAPI
771 PeiPcdGet8Ex (
772 IN CONST EFI_GUID *Guid,
773 IN UINTN ExTokenNumber
774 )
775 {
776 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));
777 }
778
779 /**
780 Retrieves an 16-bit value for a given PCD token.
781
782 Retrieves the 16-bit value of a particular PCD token.
783 If the TokenNumber is invalid or the token space
784 specified by Guid does not exist, the results are
785 unpredictable.
786
787 @param[in] Guid The token space for the token number.
788 @param[in] ExTokenNumber The PCD token number.
789
790 @return The size 16-bit value for the PCD token.
791
792 **/
793 UINT16
794 EFIAPI
795 PeiPcdGet16Ex (
796 IN CONST EFI_GUID *Guid,
797 IN UINTN ExTokenNumber
798 )
799 {
800 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));
801 }
802
803 /**
804 Retrieves an 32-bit value for a given PCD token.
805
806 Retrieves the 32-bit value of a particular PCD token.
807 If the TokenNumber is invalid or the token space
808 specified by Guid does not exist, the results are
809 unpredictable.
810
811 @param[in] Guid The token space for the token number.
812 @param[in] ExTokenNumber The PCD token number.
813
814 @return The size 32-bit value for the PCD token.
815
816 **/
817 UINT32
818 EFIAPI
819 PeiPcdGet32Ex (
820 IN CONST EFI_GUID *Guid,
821 IN UINTN ExTokenNumber
822 )
823 {
824 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));
825 }
826
827 /**
828 Retrieves an 64-bit value for a given PCD token.
829
830 Retrieves the 64-bit value of a particular PCD token.
831 If the TokenNumber is invalid or the token space
832 specified by Guid does not exist, the results are
833 unpredictable.
834
835 @param[in] Guid The token space for the token number.
836 @param[in] ExTokenNumber The PCD token number.
837
838 @return The size 64-bit value for the PCD token.
839
840 **/
841 UINT64
842 EFIAPI
843 PeiPcdGet64Ex (
844 IN CONST EFI_GUID *Guid,
845 IN UINTN ExTokenNumber
846 )
847 {
848 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));
849 }
850
851 /**
852 Retrieves a pointer to a value for a given PCD token.
853
854 Retrieves the current pointer to the buffer for a PCD token number.
855 Do not make any assumptions about the alignment of the pointer that
856 is returned by this function call. If the TokenNumber is invalid,
857 the results are unpredictable.
858
859 @param[in] Guid The token space for the token number.
860 @param[in] ExTokenNumber The PCD token number.
861
862 @return The pointer to the buffer to be retrieved.
863
864 **/
865 VOID *
866 EFIAPI
867 PeiPcdGetPtrEx (
868 IN CONST EFI_GUID *Guid,
869 IN UINTN ExTokenNumber
870 )
871 {
872 return ExGetWorker (Guid, ExTokenNumber, 0);
873 }
874
875 /**
876 Retrieves an Boolean value for a given PCD token.
877
878 Retrieves the Boolean value of a particular PCD token.
879 If the TokenNumber is invalid or the token space
880 specified by Guid does not exist, the results are
881 unpredictable.
882
883 @param[in] Guid The token space for the token number.
884 @param[in] ExTokenNumber The PCD token number.
885
886 @return The size Boolean value for the PCD token.
887
888 **/
889 BOOLEAN
890 EFIAPI
891 PeiPcdGetBoolEx (
892 IN CONST EFI_GUID *Guid,
893 IN UINTN ExTokenNumber
894 )
895 {
896 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));
897 }
898
899 /**
900 Retrieves the size of the value for a given PCD token.
901
902 Retrieves the current size of a particular PCD token.
903 If the TokenNumber is invalid, the results are unpredictable.
904
905 @param[in] Guid The token space for the token number.
906 @param[in] ExTokenNumber The PCD token number.
907
908 @return The size of the value for the PCD token.
909
910 **/
911 UINTN
912 EFIAPI
913 PeiPcdGetSizeEx (
914 IN CONST EFI_GUID *Guid,
915 IN UINTN ExTokenNumber
916 )
917 {
918 return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));
919 }
920
921 /**
922 Sets an 8-bit value for a given PCD token.
923
924 When the PCD service sets a value, it will check to ensure that the
925 size of the value being set is compatible with the Token's existing definition.
926 If it is not, an error will be returned.
927
928 @param[in] TokenNumber The PCD token number.
929 @param[in] Value The value to set for the PCD token.
930
931 @retval EFI_SUCCESS Procedure returned successfully.
932 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
933 being set was incompatible with a call to this function.
934 Use GetSize() to retrieve the size of the target data.
935 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
936
937 **/
938 EFI_STATUS
939 EFIAPI
940 PeiPcdSet8 (
941 IN UINTN TokenNumber,
942 IN UINT8 Value
943 )
944 {
945 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
946 }
947
948 /**
949 Sets an 16-bit value for a given PCD token.
950
951 When the PCD service sets a value, it will check to ensure that the
952 size of the value being set is compatible with the Token's existing definition.
953 If it is not, an error will be returned.
954
955 @param[in] TokenNumber The PCD token number.
956 @param[in] Value The value to set for the PCD token.
957
958 @retval EFI_SUCCESS Procedure returned successfully.
959 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
960 being set was incompatible with a call to this function.
961 Use GetSize() to retrieve the size of the target data.
962 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
963
964 **/
965 EFI_STATUS
966 EFIAPI
967 PeiPcdSet16 (
968 IN UINTN TokenNumber,
969 IN UINT16 Value
970 )
971 {
972 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
973 }
974
975 /**
976 Sets an 32-bit value for a given PCD token.
977
978 When the PCD service sets a value, it will check to ensure that the
979 size of the value being set is compatible with the Token's existing definition.
980 If it is not, an error will be returned.
981
982 @param[in] TokenNumber The PCD token number.
983 @param[in] Value The value to set for the PCD token.
984
985 @retval EFI_SUCCESS Procedure returned successfully.
986 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
987 being set was incompatible with a call to this function.
988 Use GetSize() to retrieve the size of the target data.
989 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
990
991 **/
992 EFI_STATUS
993 EFIAPI
994 PeiPcdSet32 (
995 IN UINTN TokenNumber,
996 IN UINT32 Value
997 )
998 {
999 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
1000 }
1001
1002 /**
1003 Sets an 64-bit value for a given PCD token.
1004
1005 When the PCD service sets a value, it will check to ensure that the
1006 size of the value being set is compatible with the Token's existing definition.
1007 If it is not, an error will be returned.
1008
1009 @param[in] TokenNumber The PCD token number.
1010 @param[in] Value The value to set for the PCD token.
1011
1012 @retval EFI_SUCCESS Procedure returned successfully.
1013 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1014 being set was incompatible with a call to this function.
1015 Use GetSize() to retrieve the size of the target data.
1016 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1017
1018 **/
1019 EFI_STATUS
1020 EFIAPI
1021 PeiPcdSet64 (
1022 IN UINTN TokenNumber,
1023 IN UINT64 Value
1024 )
1025 {
1026 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
1027 }
1028
1029 /**
1030 Sets a value of a specified size for a given PCD token.
1031
1032 When the PCD service sets a value, it will check to ensure that the
1033 size of the value being set is compatible with the Token's existing definition.
1034 If it is not, an error will be returned.
1035
1036 @param[in] TokenNumber The PCD token number.
1037 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
1038 On input, if the SizeOfValue is greater than the maximum size supported
1039 for this TokenNumber then the output value of SizeOfValue will reflect
1040 the maximum size supported for this TokenNumber.
1041 @param[in] Buffer The buffer to set for the PCD token.
1042
1043 @retval EFI_SUCCESS Procedure returned successfully.
1044 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1045 being set was incompatible with a call to this function.
1046 Use GetSize() to retrieve the size of the target data.
1047 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1048
1049 **/
1050 EFI_STATUS
1051 EFIAPI
1052 PeiPcdSetPtr (
1053 IN UINTN TokenNumber,
1054 IN OUT UINTN *SizeOfBuffer,
1055 IN VOID *Buffer
1056 )
1057 {
1058 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);
1059 }
1060
1061 /**
1062 Sets an Boolean value for a given PCD token.
1063
1064 When the PCD service sets a value, it will check to ensure that the
1065 size of the value being set is compatible with the Token's existing definition.
1066 If it is not, an error will be returned.
1067
1068 @param[in] TokenNumber The PCD token number.
1069 @param[in] Value The value to set for the PCD token.
1070
1071 @retval EFI_SUCCESS Procedure returned successfully.
1072 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1073 being set was incompatible with a call to this function.
1074 Use GetSize() to retrieve the size of the target data.
1075 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1076
1077 **/
1078 EFI_STATUS
1079 EFIAPI
1080 PeiPcdSetBool (
1081 IN UINTN TokenNumber,
1082 IN BOOLEAN Value
1083 )
1084 {
1085 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
1086 }
1087
1088 /**
1089 Sets an 8-bit value for a given PCD token.
1090
1091 When the PCD service sets a value, it will check to ensure that the
1092 size of the value being set is compatible with the Token's existing definition.
1093 If it is not, an error will be returned.
1094
1095 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1096 @param[in] ExTokenNumber The PCD token number.
1097 @param[in] Value The value to set for the PCD token.
1098
1099 @retval EFI_SUCCESS Procedure returned successfully.
1100 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1101 being set was incompatible with a call to this function.
1102 Use GetSize() to retrieve the size of the target data.
1103 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1104
1105 **/
1106 EFI_STATUS
1107 EFIAPI
1108 PeiPcdSet8Ex (
1109 IN CONST EFI_GUID *Guid,
1110 IN UINTN ExTokenNumber,
1111 IN UINT8 Value
1112 )
1113 {
1114 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
1115 }
1116
1117 /**
1118 Sets an 16-bit value for a given PCD token.
1119
1120 When the PCD service sets a value, it will check to ensure that the
1121 size of the value being set is compatible with the Token's existing definition.
1122 If it is not, an error will be returned.
1123
1124 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1125 @param[in] ExTokenNumber The PCD token number.
1126 @param[in] Value The value to set for the PCD token.
1127
1128 @retval EFI_SUCCESS Procedure returned successfully.
1129 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1130 being set was incompatible with a call to this function.
1131 Use GetSize() to retrieve the size of the target data.
1132 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1133
1134 **/
1135 EFI_STATUS
1136 EFIAPI
1137 PeiPcdSet16Ex (
1138 IN CONST EFI_GUID *Guid,
1139 IN UINTN ExTokenNumber,
1140 IN UINT16 Value
1141 )
1142 {
1143 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
1144 }
1145
1146 /**
1147 Sets an 32-bit value for a given PCD token.
1148
1149 When the PCD service sets a value, it will check to ensure that the
1150 size of the value being set is compatible with the Token's existing definition.
1151 If it is not, an error will be returned.
1152
1153 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1154 @param[in] ExTokenNumber The PCD token number.
1155 @param[in] Value The value to set for the PCD token.
1156
1157 @retval EFI_SUCCESS Procedure returned successfully.
1158 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1159 being set was incompatible with a call to this function.
1160 Use GetSize() to retrieve the size of the target data.
1161 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1162
1163 **/
1164 EFI_STATUS
1165 EFIAPI
1166 PeiPcdSet32Ex (
1167 IN CONST EFI_GUID *Guid,
1168 IN UINTN ExTokenNumber,
1169 IN UINT32 Value
1170 )
1171 {
1172 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
1173 }
1174
1175 /**
1176 Sets an 64-bit value for a given PCD token.
1177
1178 When the PCD service sets a value, it will check to ensure that the
1179 size of the value being set is compatible with the Token's existing definition.
1180 If it is not, an error will be returned.
1181
1182 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1183 @param[in] ExTokenNumber The PCD token number.
1184 @param[in] Value The value to set for the PCD token.
1185
1186 @retval EFI_SUCCESS Procedure returned successfully.
1187 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1188 being set was incompatible with a call to this function.
1189 Use GetSize() to retrieve the size of the target data.
1190 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1191
1192 **/
1193 EFI_STATUS
1194 EFIAPI
1195 PeiPcdSet64Ex (
1196 IN CONST EFI_GUID *Guid,
1197 IN UINTN ExTokenNumber,
1198 IN UINT64 Value
1199 )
1200 {
1201 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
1202 }
1203
1204 /**
1205 Sets a value of a specified size for a given PCD token.
1206
1207 When the PCD service sets a value, it will check to ensure that the
1208 size of the value being set is compatible with the Token's existing definition.
1209 If it is not, an error will be returned.
1210
1211 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1212 @param[in] ExTokenNumber The PCD token number.
1213 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
1214 On input, if the SizeOfValue is greater than the maximum size supported
1215 for this TokenNumber then the output value of SizeOfValue will reflect
1216 the maximum size supported for this TokenNumber.
1217 @param[in] Value The buffer to set for the PCD token.
1218
1219 @retval EFI_SUCCESS Procedure returned successfully.
1220 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1221 being set was incompatible with a call to this function.
1222 Use GetSize() to retrieve the size of the target data.
1223 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1224
1225 **/
1226 EFI_STATUS
1227 EFIAPI
1228 PeiPcdSetPtrEx (
1229 IN CONST EFI_GUID *Guid,
1230 IN UINTN ExTokenNumber,
1231 IN OUT UINTN *SizeOfBuffer,
1232 IN VOID *Value
1233 )
1234 {
1235 return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);
1236 }
1237
1238 /**
1239 Sets an Boolean value for a given PCD token.
1240
1241 When the PCD service sets a value, it will check to ensure that the
1242 size of the value being set is compatible with the Token's existing definition.
1243 If it is not, an error will be returned.
1244
1245 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1246 @param [in] ExTokenNumber The PCD token number.
1247 @param [in] Value The value to set for the PCD token.
1248
1249 @retval EFI_SUCCESS Procedure returned successfully.
1250 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1251 being set was incompatible with a call to this function.
1252 Use GetSize() to retrieve the size of the target data.
1253 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1254
1255 **/
1256 EFI_STATUS
1257 EFIAPI
1258 PeiPcdSetBoolEx (
1259 IN CONST EFI_GUID *Guid,
1260 IN UINTN ExTokenNumber,
1261 IN BOOLEAN Value
1262 )
1263 {
1264 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
1265 }
1266
1267 /**
1268 Specifies a function to be called anytime the value of a designated token is changed.
1269
1270 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1271 @param[in] ExTokenNumber The PCD token number.
1272 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1273
1274 @retval EFI_SUCCESS The PCD service has successfully established a call event
1275 for the CallBackToken requested.
1276 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1277
1278 **/
1279 EFI_STATUS
1280 EFIAPI
1281 PeiRegisterCallBackOnSet (
1282 IN CONST EFI_GUID *Guid, OPTIONAL
1283 IN UINTN ExTokenNumber,
1284 IN PCD_PPI_CALLBACK CallBackFunction
1285 )
1286 {
1287 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {
1288 return EFI_UNSUPPORTED;
1289 }
1290
1291 if (CallBackFunction == NULL) {
1292 return EFI_INVALID_PARAMETER;
1293 }
1294
1295 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);
1296 }
1297
1298 /**
1299 Cancels a previously set callback function for a particular PCD token number.
1300
1301 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1302 @param[in] ExTokenNumber The PCD token number.
1303 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1304
1305 @retval EFI_SUCCESS The PCD service has successfully established a call event
1306 for the CallBackToken requested.
1307 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1308
1309 **/
1310 EFI_STATUS
1311 EFIAPI
1312 PcdUnRegisterCallBackOnSet (
1313 IN CONST EFI_GUID *Guid, OPTIONAL
1314 IN UINTN ExTokenNumber,
1315 IN PCD_PPI_CALLBACK CallBackFunction
1316 )
1317 {
1318 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {
1319 return EFI_UNSUPPORTED;
1320 }
1321
1322 if (CallBackFunction == NULL) {
1323 return EFI_INVALID_PARAMETER;
1324 }
1325
1326 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);
1327 }
1328
1329 /**
1330 Retrieves the next valid token number in a given namespace.
1331
1332 This is useful since the PCD infrastructure contains a sparse list of token numbers,
1333 and one cannot a priori know what token numbers are valid in the database.
1334
1335 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
1336 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
1337 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
1338 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
1339 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
1340 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
1341 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1342 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1343
1344
1345 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1346 This is an optional parameter that may be NULL. If this parameter is NULL, then a request
1347 is being made to retrieve tokens from the default token space.
1348 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
1349
1350 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
1351 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.
1352
1353 **/
1354 EFI_STATUS
1355 EFIAPI
1356 PeiPcdGetNextToken (
1357 IN CONST EFI_GUID *Guid, OPTIONAL
1358 IN OUT UINTN *TokenNumber
1359 )
1360 {
1361 UINTN GuidTableIdx;
1362 PEI_PCD_DATABASE *PeiPcdDb;
1363 EFI_GUID *MatchGuid;
1364 EFI_GUID *GuidTable;
1365 DYNAMICEX_MAPPING *ExMapTable;
1366 UINTN Index;
1367 BOOLEAN Found;
1368 BOOLEAN PeiExMapTableEmpty;
1369 UINTN PeiNexTokenNumber;
1370
1371 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {
1372 return EFI_UNSUPPORTED;
1373 }
1374
1375 PeiPcdDb = GetPcdDatabase ();
1376 PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount;
1377 GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);
1378
1379 if (PeiPcdDb->ExTokenCount == 0) {
1380 PeiExMapTableEmpty = TRUE;
1381 } else {
1382 PeiExMapTableEmpty = FALSE;
1383 }
1384 if (Guid == NULL) {
1385 if (*TokenNumber > PeiNexTokenNumber) {
1386 return EFI_NOT_FOUND;
1387 }
1388 (*TokenNumber)++;
1389 if (*TokenNumber > PeiNexTokenNumber) {
1390 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
1391 return EFI_NOT_FOUND;
1392 }
1393 return EFI_SUCCESS;
1394 } else {
1395 if (PeiExMapTableEmpty) {
1396 return EFI_NOT_FOUND;
1397 }
1398
1399 MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid);
1400
1401 if (MatchGuid == NULL) {
1402 return EFI_NOT_FOUND;
1403 }
1404
1405 GuidTableIdx = MatchGuid - GuidTable;
1406
1407 ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);
1408
1409 Found = FALSE;
1410 //
1411 // Locate the GUID in ExMapTable first.
1412 //
1413 for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {
1414 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {
1415 Found = TRUE;
1416 break;
1417 }
1418 }
1419
1420 if (Found) {
1421 //
1422 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
1423 // token number in found token space.
1424 //
1425 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {
1426 *TokenNumber = ExMapTable[Index].ExTokenNumber;
1427 return EFI_SUCCESS;
1428 }
1429
1430 for ( ; Index < PeiPcdDb->ExTokenCount; Index++) {
1431 if ((ExMapTable[Index].ExTokenNumber == *TokenNumber) && (ExMapTable[Index].ExGuidIndex == GuidTableIdx)) {
1432 break;
1433 }
1434 }
1435
1436 while (Index < PeiPcdDb->ExTokenCount) {
1437 Index++;
1438 if (Index == PeiPcdDb->ExTokenCount) {
1439 //
1440 // Exceed the length of ExMap Table
1441 //
1442 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
1443 return EFI_NOT_FOUND;
1444 } else if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {
1445 //
1446 // Found the next match
1447 //
1448 *TokenNumber = ExMapTable[Index].ExTokenNumber;
1449 return EFI_SUCCESS;
1450 }
1451 }
1452 }
1453 }
1454
1455 return EFI_NOT_FOUND;
1456 }
1457
1458 /**
1459 Retrieves the next valid PCD token namespace for a given namespace.
1460
1461 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid
1462 token namespaces on a platform.
1463
1464 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token
1465 namespace from which the search will start. On output, it designates the next valid
1466 token namespace on the platform. If *Guid is NULL, then the GUID of the first token
1467 space of the current platform is returned. If the search cannot locate the next valid
1468 token namespace, an error is returned and the value of *Guid is undefined.
1469
1470 @retval EFI_SUCCESS The PCD service retrieved the value requested.
1471 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.
1472
1473 **/
1474 EFI_STATUS
1475 EFIAPI
1476 PeiPcdGetNextTokenSpace (
1477 IN OUT CONST EFI_GUID **Guid
1478 )
1479 {
1480 UINTN GuidTableIdx;
1481 EFI_GUID *MatchGuid;
1482 PEI_PCD_DATABASE *PeiPcdDb;
1483 DYNAMICEX_MAPPING *ExMapTable;
1484 UINTN Index;
1485 UINTN Index2;
1486 BOOLEAN Found;
1487 BOOLEAN PeiExMapTableEmpty;
1488 EFI_GUID *GuidTable;
1489
1490 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {
1491 return EFI_UNSUPPORTED;
1492 }
1493
1494 ASSERT (Guid != NULL);
1495
1496 PeiPcdDb = GetPcdDatabase ();
1497
1498 if (PeiPcdDb->ExTokenCount == 0) {
1499 PeiExMapTableEmpty = TRUE;
1500 } else {
1501 PeiExMapTableEmpty = FALSE;
1502 }
1503
1504 if (PeiExMapTableEmpty) {
1505 return EFI_NOT_FOUND;
1506 }
1507
1508 ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);
1509 GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);
1510
1511 if (*Guid == NULL) {
1512 //
1513 // return the first Token Space Guid.
1514 //
1515 *Guid = GuidTable + ExMapTable[0].ExGuidIndex;
1516 return EFI_SUCCESS;
1517 }
1518
1519 MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(GuidTable[0]), *Guid);
1520
1521 if (MatchGuid == NULL) {
1522 return EFI_NOT_FOUND;
1523 }
1524
1525 GuidTableIdx = MatchGuid - GuidTable;
1526
1527 Found = FALSE;
1528 for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {
1529 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {
1530 Found = TRUE;
1531 break;
1532 }
1533 }
1534
1535 if (Found) {
1536 Index++;
1537 for ( ; Index < PeiPcdDb->ExTokenCount; Index++ ) {
1538 if (ExMapTable[Index].ExGuidIndex != GuidTableIdx) {
1539 Found = FALSE;
1540 for (Index2 = 0 ; Index2 < Index; Index2++) {
1541 if (ExMapTable[Index2].ExGuidIndex == ExMapTable[Index].ExGuidIndex) {
1542 //
1543 // This token namespace should have been found and output at preceding getting.
1544 //
1545 Found = TRUE;
1546 break;
1547 }
1548 }
1549 if (!Found) {
1550 *Guid = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + ExMapTable[Index].ExGuidIndex;
1551 return EFI_SUCCESS;
1552 }
1553 }
1554 }
1555 *Guid = NULL;
1556 }
1557
1558 return EFI_NOT_FOUND;
1559
1560 }
1561
1562 /**
1563 Get PCD value's size for POINTER type PCD.
1564
1565 The POINTER type PCD's value will be stored into a buffer in specified size.
1566 The max size of this PCD's value is described in PCD's definition in DEC file.
1567
1568 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1569 @param MaxSize Maximum size of PCD's value
1570 @param Database Pcd database in PEI phase.
1571
1572 @return PCD value's size for POINTER type PCD.
1573
1574 **/
1575 UINTN
1576 GetPtrTypeSize (
1577 IN UINTN LocalTokenNumberTableIdx,
1578 OUT UINTN *MaxSize,
1579 IN PEI_PCD_DATABASE *Database
1580 )
1581 {
1582 INTN SizeTableIdx;
1583 UINTN LocalTokenNumber;
1584 SIZE_INFO *SizeTable;
1585
1586 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);
1587
1588 LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);
1589
1590 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
1591
1592 SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);
1593
1594 *MaxSize = SizeTable[SizeTableIdx];
1595 //
1596 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1597 // PCD entry.
1598 //
1599 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1600 //
1601 // We have only two entry for VPD enabled PCD entry:
1602 // 1) MAX Size.
1603 // 2) Current Size
1604 // We consider current size is equal to MAX size.
1605 //
1606 return *MaxSize;
1607 } else {
1608 //
1609 // We have only two entry for Non-Sku enabled PCD entry:
1610 // 1) MAX SIZE
1611 // 2) Current Size
1612 //
1613 return SizeTable[SizeTableIdx + 1];
1614 }
1615 }
1616
1617 /**
1618 Set PCD value's size for POINTER type PCD.
1619
1620 The POINTER type PCD's value will be stored into a buffer in specified size.
1621 The max size of this PCD's value is described in PCD's definition in DEC file.
1622
1623 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1624 @param CurrentSize Maximum size of PCD's value
1625 @param Database Pcd database in PEI phase.
1626
1627 @retval TRUE Success to set PCD's value size, which is not exceed maximum size
1628 @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size
1629
1630 **/
1631 BOOLEAN
1632 SetPtrTypeSize (
1633 IN UINTN LocalTokenNumberTableIdx,
1634 IN OUT UINTN *CurrentSize,
1635 IN PEI_PCD_DATABASE *Database
1636 )
1637 {
1638 INTN SizeTableIdx;
1639 UINTN LocalTokenNumber;
1640 SIZE_INFO *SizeTable;
1641 UINTN MaxSize;
1642
1643 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);
1644
1645 LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);
1646
1647 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
1648
1649 SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);
1650
1651 MaxSize = SizeTable[SizeTableIdx];
1652 //
1653 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1654 // PCD entry.
1655 //
1656 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1657 //
1658 // We shouldn't come here as we don't support SET for VPD
1659 //
1660 ASSERT (FALSE);
1661 return FALSE;
1662 } else {
1663 if ((*CurrentSize > MaxSize) ||
1664 (*CurrentSize == MAX_ADDRESS)) {
1665 *CurrentSize = MaxSize;
1666 return FALSE;
1667 }
1668
1669 //
1670 // We have only two entry for Non-Sku enabled PCD entry:
1671 // 1) MAX SIZE
1672 // 2) Current Size
1673 //
1674 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
1675 return TRUE;
1676 }
1677
1678 }