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