]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxePcdLib/DxePcdLib.c
follow up the comments from code review.
[mirror_edk2.git] / MdePkg / Library / DxePcdLib / DxePcdLib.c
1 /** @file
2 Implementation of PcdLib class library for DXE phase.
3
4 Copyright (c) 2006, Intel Corporation<BR>
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
16
17 #include <PiDxe.h>
18
19 #include <Protocol/Pcd.h>
20
21 #include <Library/PcdLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/BaseMemoryLib.h>
25
26 PCD_PROTOCOL *mPcd = NULL;
27
28
29 /**
30 The constructor function caches the PCD_PROTOCOL pointer.
31
32 @param[in] ImageHandle The firmware allocated handle for the EFI image.
33 @param[in] SystemTable A pointer to the EFI System Table.
34
35 @retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
36
37 **/
38 EFI_STATUS
39 EFIAPI
40 PcdLibConstructor (
41 IN EFI_HANDLE ImageHandle,
42 IN EFI_SYSTEM_TABLE *SystemTable
43 )
44 {
45 EFI_STATUS Status;
46
47 //
48 // PCD protocol has not been installed, but a module needs to access a
49 // dynamic PCD entry.
50 //
51 Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd);
52 ASSERT_EFI_ERROR (Status);
53 ASSERT (mPcd!= NULL);
54
55 return Status;
56 }
57
58
59 /**
60 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
61 If SkuId is not less than PCD_MAX_SKU_ID, then ASSERT().
62
63 @param[in] SkuId System SKU ID. The SKU value that will be used when the PCD service will retrieve and
64 set values.
65
66 @retval SKU_ID Return the SKU ID that just be set.
67
68 **/
69 UINTN
70 EFIAPI
71 LibPcdSetSku (
72 IN UINTN SkuId
73 )
74 {
75 ASSERT (SkuId < PCD_MAX_SKU_ID);
76
77 mPcd->SetSku (SkuId);
78
79 return SkuId;
80 }
81
82
83
84 /**
85 Returns the 8-bit value for the token specified by TokenNumber.
86
87 @param[in] TokenNumber The PCD token number to retrieve a current value for.
88
89 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
90
91 **/
92 UINT8
93 EFIAPI
94 LibPcdGet8 (
95 IN UINTN TokenNumber
96 )
97 {
98 return mPcd->Get8 (TokenNumber);
99 }
100
101
102
103 /**
104 Returns the 16-bit value for the token specified by TokenNumber.
105
106 @param[in] TokenNumber The PCD token number to retrieve a current value for.
107
108 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
109
110 **/
111 UINT16
112 EFIAPI
113 LibPcdGet16 (
114 IN UINTN TokenNumber
115 )
116 {
117 return mPcd->Get16 (TokenNumber);
118 }
119
120
121
122 /**
123 Returns the 32-bit value for the token specified by TokenNumber.
124
125 @param[in] TokenNumber The PCD token number to retrieve a current value for.
126
127 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
128
129 **/
130 UINT32
131 EFIAPI
132 LibPcdGet32 (
133 IN UINTN TokenNumber
134 )
135 {
136 return mPcd->Get32 (TokenNumber);
137 }
138
139
140
141 /**
142 Returns the 64-bit value for the token specified by TokenNumber.
143
144 @param[in] TokenNumber The PCD token number to retrieve a current value for.
145
146 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
147
148 **/
149 UINT64
150 EFIAPI
151 LibPcdGet64 (
152 IN UINTN TokenNumber
153 )
154 {
155 return mPcd->Get64 (TokenNumber);
156 }
157
158
159
160 /**
161 Returns the pointer to the buffer of the token specified by TokenNumber.
162
163 @param[in] TokenNumber The PCD token number to retrieve a current value for.
164
165 @retval VOID* Returns the pointer to the token specified by TokenNumber.
166
167 **/
168 VOID *
169 EFIAPI
170 LibPcdGetPtr (
171 IN UINTN TokenNumber
172 )
173 {
174 return mPcd->GetPtr (TokenNumber);
175 }
176
177
178
179 /**
180 Returns the Boolean value of the token specified by TokenNumber.
181
182 @param[in] TokenNumber The PCD token number to retrieve a current value for.
183
184 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
185
186 **/
187 BOOLEAN
188 EFIAPI
189 LibPcdGetBool (
190 IN UINTN TokenNumber
191 )
192 {
193 return mPcd->GetBool (TokenNumber);
194 }
195
196
197
198 /**
199 Returns the size of the token specified by TokenNumber.
200
201 @param[in] TokenNumber The PCD token number to retrieve a current value for.
202
203 @retval UINTN Returns the size of the token specified by TokenNumber.
204
205 **/
206 UINTN
207 EFIAPI
208 LibPcdGetSize (
209 IN UINTN TokenNumber
210 )
211 {
212 return mPcd->GetSize (TokenNumber);
213 }
214
215
216
217 /**
218 Returns the 8-bit value for the token specified by TokenNumber and Guid.
219 If Guid is NULL, then ASSERT().
220
221 @param[in] Guid Pointer to a 128-bit unique value that designates
222 which namespace to retrieve a value from.
223 @param[in] TokenNumber The PCD token number to retrieve a current value for.
224
225 @retval UINT8 Return the UINT8.
226
227 **/
228 UINT8
229 EFIAPI
230 LibPcdGetEx8 (
231 IN CONST GUID *Guid,
232 IN UINTN TokenNumber
233 )
234 {
235 ASSERT (Guid != NULL);
236
237 return mPcd->Get8Ex (Guid, TokenNumber);
238 }
239
240
241 /**
242 Returns the 16-bit value for the token specified by TokenNumber and Guid.
243 If Guid is NULL, then ASSERT().
244
245 @param[in] Guid Pointer to a 128-bit unique value that designates
246 which namespace to retrieve a value from.
247 @param[in] TokenNumber The PCD token number to retrieve a current value for.
248
249 @retval UINT16 Return the UINT16.
250
251 **/
252 UINT16
253 EFIAPI
254 LibPcdGetEx16 (
255 IN CONST GUID *Guid,
256 IN UINTN TokenNumber
257 )
258 {
259 ASSERT (Guid != NULL);
260
261 return mPcd->Get16Ex (Guid, TokenNumber);
262 }
263
264
265 /**
266 Returns the 32-bit value for the token specified by TokenNumber and Guid.
267 If Guid is NULL, then ASSERT().
268
269 @param[in] Guid Pointer to a 128-bit unique value that designates
270 which namespace to retrieve a value from.
271 @param[in] TokenNumber The PCD token number to retrieve a current value for.
272
273 @retval UINT32 Return the UINT32.
274
275 **/
276 UINT32
277 EFIAPI
278 LibPcdGetEx32 (
279 IN CONST GUID *Guid,
280 IN UINTN TokenNumber
281 )
282 {
283 ASSERT (Guid != NULL);
284
285 return mPcd->Get32Ex (Guid, TokenNumber);
286 }
287
288
289
290 /**
291 Returns the 64-bit value for the token specified by TokenNumber and Guid.
292 If Guid is NULL, then ASSERT().
293
294 @param[in] Guid Pointer to a 128-bit unique value that designates
295 which namespace to retrieve a value from.
296 @param[in] TokenNumber The PCD token number to retrieve a current value for.
297
298 @retval UINT64 Return the UINT64.
299
300 **/
301 UINT64
302 EFIAPI
303 LibPcdGetEx64 (
304 IN CONST GUID *Guid,
305 IN UINTN TokenNumber
306 )
307 {
308 ASSERT (Guid != NULL);
309
310 return mPcd->Get64Ex (Guid, TokenNumber);
311 }
312
313
314
315 /**
316 Returns the pointer to the token specified by TokenNumber and Guid.
317 If Guid is NULL, then ASSERT().
318
319 @param[in] Guid Pointer to a 128-bit unique value that designates
320 which namespace to retrieve a value from.
321 @param[in] TokenNumber The PCD token number to retrieve a current value for.
322
323 @retval VOID* Return the VOID* pointer.
324
325 **/
326 VOID *
327 EFIAPI
328 LibPcdGetExPtr (
329 IN CONST GUID *Guid,
330 IN UINTN TokenNumber
331 )
332 {
333 ASSERT (Guid != NULL);
334
335 return mPcd->GetPtrEx (Guid, TokenNumber);
336 }
337
338
339
340 /**
341 Returns the Boolean value of the token specified by TokenNumber and Guid.
342 If Guid is NULL, then ASSERT().
343
344 @param[in] Guid Pointer to a 128-bit unique value that designates
345 which namespace to retrieve a value from.
346 @param[in] TokenNumber The PCD token number to retrieve a current value for.
347
348 @retval BOOLEAN Return the BOOLEAN.
349
350 **/
351 BOOLEAN
352 EFIAPI
353 LibPcdGetExBool (
354 IN CONST GUID *Guid,
355 IN UINTN TokenNumber
356 )
357 {
358 ASSERT (Guid != NULL);
359
360 return mPcd->GetBoolEx (Guid, TokenNumber);
361 }
362
363
364
365 /**
366 Returns the size of the token specified by TokenNumber and Guid.
367 If Guid is NULL, then ASSERT().
368
369 @param[in] Guid Pointer to a 128-bit unique value that designates
370 which namespace to retrieve a value from.
371 @param[in] TokenNumber The PCD token number to retrieve a current value for.
372
373 @retval UINTN Return the size.
374
375 **/
376 UINTN
377 EFIAPI
378 LibPcdGetExSize (
379 IN CONST GUID *Guid,
380 IN UINTN TokenNumber
381 )
382 {
383 ASSERT (Guid != NULL);
384
385 return mPcd->GetSizeEx (Guid, TokenNumber);
386 }
387
388
389
390 /**
391 Sets the 8-bit value for the token specified by TokenNumber
392 to the value specified by Value. Value is returned.
393 If fail to set pcd value, then ASSERT_EFI_ERROR().
394
395 @param[in] TokenNumber The PCD token number to set a current value for.
396 @param[in] Value The 8-bit value to set.
397
398 @retval UINT8 Return the value been set.
399
400 **/
401 UINT8
402 EFIAPI
403 LibPcdSet8 (
404 IN UINTN TokenNumber,
405 IN UINT8 Value
406 )
407 {
408 EFI_STATUS Status;
409
410 Status = mPcd->Set8 (TokenNumber, Value);
411
412 ASSERT_EFI_ERROR (Status);
413
414 return Value;
415 }
416
417
418
419 /**
420 Sets the 16-bit value for the token specified by TokenNumber
421 to the value specified by Value. Value is returned.
422 If fail to set pcd value, then ASSERT_EFI_ERROR().
423
424 @param[in] TokenNumber The PCD token number to set a current value for.
425 @param[in] Value The 16-bit value to set.
426
427 @retval UINT16 Return the value been set.
428
429 **/
430 UINT16
431 EFIAPI
432 LibPcdSet16 (
433 IN UINTN TokenNumber,
434 IN UINT16 Value
435 )
436 {
437 EFI_STATUS Status;
438
439 Status = mPcd->Set16 (TokenNumber, Value);
440
441 ASSERT_EFI_ERROR (Status);
442
443 return Value;
444 }
445
446
447
448 /**
449 Sets the 32-bit value for the token specified by TokenNumber
450 to the value specified by Value. Value is returned.
451 If fail to set pcd value, then ASSERT_EFI_ERROR().
452
453 @param[in] TokenNumber The PCD token number to set a current value for.
454 @param[in] Value The 32-bit value to set.
455
456 @retval UINT32 Return the value been set.
457
458 **/
459 UINT32
460 EFIAPI
461 LibPcdSet32 (
462 IN UINTN TokenNumber,
463 IN UINT32 Value
464 )
465 {
466 EFI_STATUS Status;
467 Status = mPcd->Set32 (TokenNumber, Value);
468
469 ASSERT_EFI_ERROR (Status);
470
471 return Value;
472 }
473
474
475
476 /**
477 Sets the 64-bit value for the token specified by TokenNumber
478 to the value specified by Value. Value is returned.
479 If fail to set pcd value, then ASSERT_EFI_ERROR().
480
481 @param[in] TokenNumber The PCD token number to set a current value for.
482 @param[in] Value The 64-bit value to set.
483
484 @retval UINT64 Return the value been set.
485
486 **/
487 UINT64
488 EFIAPI
489 LibPcdSet64 (
490 IN UINTN TokenNumber,
491 IN UINT64 Value
492 )
493 {
494 EFI_STATUS Status;
495
496 Status = mPcd->Set64 (TokenNumber, Value);
497
498 ASSERT_EFI_ERROR (Status);
499
500 return Value;
501 }
502
503
504
505 /**
506 Sets a buffer for the token specified by TokenNumber to
507 the value specified by Buffer and SizeOfBuffer. Buffer to
508 be set is returned. The content of the buffer could be
509 overwritten if a Callback on SET is registered with this
510 TokenNumber.
511
512 If SizeOfBuffer is greater than the maximum
513 size support by TokenNumber, then set SizeOfBuffer to the
514 maximum size supported by TokenNumber and return NULL to
515 indicate that the set operation was not actually performed.
516
517 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
518
519 @param[in] TokenNumber The PCD token number to set a current value for.
520 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
521 In out, returns actual size of buff is set.
522 @param[in] Buffer A pointer to the buffer to set.
523
524 @retval VOID* Return the pointer for the buffer been set.
525
526 **/
527 VOID *
528 EFIAPI
529 LibPcdSetPtr (
530 IN UINTN TokenNumber,
531 IN OUT UINTN *SizeOfBuffer,
532 IN VOID *Buffer
533 )
534 {
535 EFI_STATUS Status;
536
537 ASSERT (SizeOfBuffer != NULL);
538
539 if (*SizeOfBuffer > 0) {
540 ASSERT (Buffer != NULL);
541 }
542
543 Status = mPcd->SetPtr (TokenNumber, SizeOfBuffer, Buffer);
544
545 if (EFI_ERROR (Status)) {
546 return NULL;
547 }
548
549 return Buffer;
550 }
551
552
553
554 /**
555 Sets the Boolean value for the token specified by TokenNumber
556 to the value specified by Value. Value is returned.
557 If fail to set pcd value, then ASSERT_EFI_ERROR().
558
559 @param[in] TokenNumber The PCD token number to set a current value for.
560 @param[in] Value The boolean value to set.
561
562 @retval BOOLEAN Return the value been set.
563
564 **/
565 BOOLEAN
566 EFIAPI
567 LibPcdSetBool (
568 IN UINTN TokenNumber,
569 IN BOOLEAN Value
570 )
571 {
572 EFI_STATUS Status;
573
574 Status = mPcd->SetBool (TokenNumber, Value);
575
576 ASSERT_EFI_ERROR (Status);
577
578 return Value;
579 }
580
581
582
583 /**
584 Sets the 8-bit value for the token specified by TokenNumber and
585 Guid to the value specified by Value. Value is returned.
586 If Guid is NULL, then ASSERT().
587 If fail to set pcd value, then ASSERT_EFI_ERROR().
588
589 @param[in] Guid Pointer to a 128-bit unique value that
590 designates which namespace to set a value from.
591 @param[in] TokenNumber The PCD token number to set a current value for.
592 @param[in] Value The 8-bit value to set.
593
594 @retval UINT8 Return the value been set.
595
596 **/
597 UINT8
598 EFIAPI
599 LibPcdSetEx8 (
600 IN CONST GUID *Guid,
601 IN UINTN TokenNumber,
602 IN UINT8 Value
603 )
604 {
605 EFI_STATUS Status;
606
607 ASSERT (Guid != NULL);
608
609 Status = mPcd->Set8Ex (Guid, TokenNumber, Value);
610
611 ASSERT_EFI_ERROR (Status);
612
613 return Value;
614 }
615
616
617
618 /**
619 Sets the 16-bit value for the token specified by TokenNumber and
620 Guid to the value specified by Value. Value is returned.
621 If Guid is NULL, then ASSERT().
622 If fail to set pcd value, then ASSERT_EFI_ERROR().
623
624 @param[in] Guid Pointer to a 128-bit unique value that
625 designates which namespace to set a value from.
626 @param[in] TokenNumber The PCD token number to set a current value for.
627 @param[in] Value The 16-bit value to set.
628
629 @retval UINT16 Return the value been set.
630
631 **/
632 UINT16
633 EFIAPI
634 LibPcdSetEx16 (
635 IN CONST GUID *Guid,
636 IN UINTN TokenNumber,
637 IN UINT16 Value
638 )
639 {
640 EFI_STATUS Status;
641
642 ASSERT (Guid != NULL);
643
644 Status = mPcd->Set16Ex (Guid, TokenNumber, Value);
645
646 ASSERT_EFI_ERROR (Status);
647
648 return Value;
649 }
650
651
652
653 /**
654 Sets the 32-bit value for the token specified by TokenNumber and
655 Guid to the value specified by Value. Value is returned.
656 If Guid is NULL, then ASSERT().
657 If fail to set pcd value, then ASSERT_EFI_ERROR().
658
659 @param[in] Guid Pointer to a 128-bit unique value that
660 designates which namespace to set a value from.
661 @param[in] TokenNumber The PCD token number to set a current value for.
662 @param[in] Value The 32-bit value to set.
663
664 @retval UINT32 Return the value been set.
665
666 **/
667 UINT32
668 EFIAPI
669 LibPcdSetEx32 (
670 IN CONST GUID *Guid,
671 IN UINTN TokenNumber,
672 IN UINT32 Value
673 )
674 {
675 EFI_STATUS Status;
676
677 ASSERT (Guid != NULL);
678
679 Status = mPcd->Set32Ex (Guid, TokenNumber, Value);
680
681 ASSERT_EFI_ERROR (Status);
682
683 return Value;
684 }
685
686
687
688 /**
689 Sets the 64-bit value for the token specified by TokenNumber and
690 Guid to the value specified by Value. Value is returned.
691 If Guid is NULL, then ASSERT().
692
693 @param[in] Guid Pointer to a 128-bit unique value that
694 designates which namespace to set a value from.
695 @param[in] TokenNumber The PCD token number to set a current value for.
696 @param[in] Value The 64-bit value to set.
697
698 @retval UINT64 Return the value been set.
699
700 **/
701 UINT64
702 EFIAPI
703 LibPcdSetEx64 (
704 IN CONST GUID *Guid,
705 IN UINTN TokenNumber,
706 IN UINT64 Value
707 )
708 {
709 EFI_STATUS Status;
710
711 ASSERT (Guid != NULL);
712
713 Status = mPcd->Set64Ex (Guid, TokenNumber, Value);
714
715 ASSERT_EFI_ERROR (Status);
716
717 return Value;
718 }
719
720
721
722 /**
723 Sets a buffer for the token specified by TokenNumber to the value specified by
724 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
725 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
726 supported by TokenNumber and return NULL to indicate that the set operation
727 was not actually performed.
728
729 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
730
731 @param[in] Guid Pointer to a 128-bit unique value that
732 designates which namespace to set a value from.
733 @param[in] TokenNumber The PCD token number to set a current value for.
734 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
735 In out, returns actual size of buffer is set.
736 @param[in] Buffer A pointer to the buffer to set.
737
738 @retval VOID * Return the pinter to the buffer been set.
739
740 **/
741 VOID *
742 EFIAPI
743 LibPcdSetExPtr (
744 IN CONST GUID *Guid,
745 IN UINTN TokenNumber,
746 IN OUT UINTN *SizeOfBuffer,
747 IN VOID *Buffer
748 )
749 {
750 EFI_STATUS Status;
751
752 ASSERT (Guid != NULL);
753
754 ASSERT (SizeOfBuffer != NULL);
755
756 if (*SizeOfBuffer > 0) {
757 ASSERT (Buffer != NULL);
758 }
759
760 Status = mPcd->SetPtrEx (Guid, TokenNumber, SizeOfBuffer, Buffer);
761
762 if (EFI_ERROR (Status)) {
763 return NULL;
764 }
765
766 return Buffer;
767 }
768
769
770
771 /**
772 Sets the Boolean value for the token specified by TokenNumber and
773 Guid to the value specified by Value. Value is returned.
774 If Guid is NULL, then ASSERT().
775 If fail to set pcd value, then ASSERT_EFI_ERROR().
776
777 @param[in] Guid Pointer to a 128-bit unique value that
778 designates which namespace to set a value from.
779 @param[in] TokenNumber The PCD token number to set a current value for.
780 @param[in] Value The Boolean value to set.
781
782 @retval Boolean Return the value been set.
783
784 **/
785 BOOLEAN
786 EFIAPI
787 LibPcdSetExBool (
788 IN CONST GUID *Guid,
789 IN UINTN TokenNumber,
790 IN BOOLEAN Value
791 )
792 {
793 EFI_STATUS Status;
794
795 ASSERT (Guid != NULL);
796
797 Status = mPcd->SetBoolEx (Guid, TokenNumber, Value);
798
799 ASSERT_EFI_ERROR (Status);
800
801 return Value;
802 }
803
804
805
806 /**
807 When the token specified by TokenNumber and Guid is set,
808 then notification function specified by NotificationFunction is called.
809 If Guid is NULL, then the default token space is used.
810 If NotificationFunction is NULL, then ASSERT().
811 If fail to set callback function, then ASSERT_EFI_ERROR().
812
813 @param[in] Guid Pointer to a 128-bit unique value that designates which
814 namespace to set a value from. If NULL, then the default
815 token space is used.
816 @param[in] TokenNumber The PCD token number to monitor.
817 @param[in] NotificationFunction The function to call when the token
818 specified by Guid and TokenNumber is set.
819
820 @retval VOID
821
822 **/
823 VOID
824 EFIAPI
825 LibPcdCallbackOnSet (
826 IN CONST GUID *Guid, OPTIONAL
827 IN UINTN TokenNumber,
828 IN PCD_CALLBACK NotificationFunction
829 )
830 {
831 EFI_STATUS Status;
832
833 ASSERT (NotificationFunction != NULL);
834
835 Status = mPcd->CallbackOnSet (Guid, TokenNumber, NotificationFunction);
836
837 ASSERT_EFI_ERROR (Status);
838
839 return;
840 }
841
842
843
844 /**
845 Disable a notification function that was established with LibPcdCallbackonSet().
846 If NotificationFunction is NULL, then ASSERT().
847 If fail to cancel callback function, then ASSERT_EFI_ERROR().
848
849 @param[in] Guid Specify the GUID token space.
850 @param[in] TokenNumber Specify the token number.
851 @param[in] NotificationFunction The callback function to be unregistered.
852
853 @retval VOID
854
855 **/
856 VOID
857 EFIAPI
858 LibPcdCancelCallback (
859 IN CONST GUID *Guid, OPTIONAL
860 IN UINTN TokenNumber,
861 IN PCD_CALLBACK NotificationFunction
862 )
863 {
864 EFI_STATUS Status;
865
866 ASSERT (NotificationFunction != NULL);
867
868 Status = mPcd->CancelCallback (Guid, TokenNumber, NotificationFunction);
869
870 ASSERT_EFI_ERROR (Status);
871
872 return;
873 }
874
875
876
877 /**
878 Retrieves the next PCD token number from the token space specified by Guid.
879 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
880 then the first token number is returned. Otherwise, the token number that
881 follows TokenNumber in the token space is returned. If TokenNumber is the last
882 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
883 is not in the token space specified by Guid, then ASSERT().
884 If Fail to get next token, then ASSERT_EFI_ERROR().
885
886 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
887 to set a value from. If NULL, then the default token space is used.
888 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
889 token number.
890
891 @retval UINTN The next valid token number.
892
893 **/
894 UINTN
895 EFIAPI
896 LibPcdGetNextToken (
897 IN CONST GUID *Guid, OPTIONAL
898 IN UINTN TokenNumber
899 )
900 {
901 EFI_STATUS Status;
902
903 Status = mPcd->GetNextToken (Guid, &TokenNumber);
904
905 ASSERT_EFI_ERROR (Status);
906
907 return TokenNumber;
908 }
909
910
911
912 /**
913 Retrieves the next PCD token space from a token space specified by Guid.
914 Guid of NULL is reserved to mark the default local token namespace on the current
915 platform. If Guid is NULL, then the GUID of the first non-local token space of the
916 current platform is returned. If Guid is the last non-local token space,
917 then NULL is returned.
918
919 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
920 If fail to get next token space, then ASSERT_EFI_ERROR().
921
922 @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace
923 to start the search.
924
925 @retval CONST GUID * The next valid token namespace.
926
927 **/
928 GUID *
929 EFIAPI
930 LibPcdGetNextTokenSpace (
931 IN CONST GUID *Guid
932 )
933 {
934 EFI_STATUS Status;
935
936 Status = mPcd->GetNextTokenSpace (&Guid);
937
938 ASSERT_EFI_ERROR (Status);
939
940 return (GUID *) Guid;
941 }
942
943
944 /**
945 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
946 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
947 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
948 NULL to indicate that the set operation was not actually performed.
949 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
950 MaximumDatumSize and NULL must be returned.
951
952 If PatchVariable is NULL, then ASSERT().
953 If SizeOfBuffer is NULL, then ASSERT().
954 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
955
956 @param[in] PatchVariable A pointer to the global variable in a module that is
957 the target of the set operation.
958 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
959 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
960 In out, returns actual size of buffer is set.
961 @param[in] Buffer A pointer to the buffer to used to set the target variable.
962
963 **/
964 VOID *
965 EFIAPI
966 LibPatchPcdSetPtr (
967 IN VOID *PatchVariable,
968 IN UINTN MaximumDatumSize,
969 IN OUT UINTN *SizeOfBuffer,
970 IN CONST VOID *Buffer
971 )
972 {
973 ASSERT (PatchVariable != NULL);
974 ASSERT (SizeOfBuffer != NULL);
975
976 if (*SizeOfBuffer > 0) {
977 ASSERT (Buffer != NULL);
978 }
979
980 if ((*SizeOfBuffer > MaximumDatumSize) ||
981 (*SizeOfBuffer == MAX_ADDRESS)) {
982 *SizeOfBuffer = MaximumDatumSize;
983 return NULL;
984 }
985
986 CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
987
988 return (VOID *) Buffer;
989 }
990
991
992