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