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