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