]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxePcdLib/DxePcdLib.c
f14a74652978bb38f6c1af867ab4294c7faa6e77
[mirror_edk2.git] / MdePkg / Library / DxePcdLib / DxePcdLib.c
1 /** @file
2 Implementation of PcdLib class library for DXE phase.
3
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13
14 **/
15
16
17 #include <PiDxe.h>
18
19 #include <Protocol/Pcd.h>
20 #include <Protocol/PiPcd.h>
21 #include <Protocol/PcdInfo.h>
22 #include <Protocol/PiPcdInfo.h>
23
24 #include <Library/PcdLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/UefiBootServicesTableLib.h>
27 #include <Library/BaseMemoryLib.h>
28
29 PCD_PROTOCOL *mPcd = NULL;
30 EFI_PCD_PROTOCOL *mPiPcd = NULL;
31 GET_PCD_INFO_PROTOCOL *mPcdInfo = NULL;
32 EFI_GET_PCD_INFO_PROTOCOL *mPiPcdInfo = NULL;
33
34 /**
35 Retrieves the PI PCD protocol from the handle database.
36
37 @retval EFI_PCD_PROTOCOL * The pointer to the EFI_PCD_PROTOCOL.
38 **/
39 EFI_PCD_PROTOCOL *
40 EFIAPI
41 GetPiPcdProtocol (
42 VOID
43 )
44 {
45 EFI_STATUS Status;
46
47 if (mPiPcd == NULL) {
48 //
49 // PI Pcd protocol defined in PI 1.2 vol3 should be installed before the module
50 // access DynamicEx type PCD.
51 //
52 Status = gBS->LocateProtocol (&gEfiPcdProtocolGuid, NULL, (VOID **) &mPiPcd);
53 ASSERT_EFI_ERROR (Status);
54 ASSERT (mPiPcd != NULL);
55 }
56 return mPiPcd;
57 }
58
59 /**
60 Retrieves the PCD protocol from the handle database.
61
62 @retval PCD_PROTOCOL * The pointer to the PCD_PROTOCOL.
63 **/
64 PCD_PROTOCOL *
65 EFIAPI
66 GetPcdProtocol (
67 VOID
68 )
69 {
70 EFI_STATUS Status;
71
72 if (mPcd == NULL) {
73 //
74 // PCD protocol need to be installed before the module access Dynamic type PCD.
75 // But dynamic type PCD is not required in PI 1.2 specification.
76 //
77 Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd);
78 ASSERT_EFI_ERROR (Status);
79 ASSERT (mPcd != NULL);
80 }
81 return mPcd;
82 }
83
84 /**
85 Retrieves the PI PCD info protocol from the handle database.
86
87 @retval EFI_GET_PCD_INFO_PROTOCOL * The pointer to the EFI_GET_PCD_INFO_PROTOCOL defined in PI 1.2.1 Vol 3.
88 **/
89 EFI_GET_PCD_INFO_PROTOCOL *
90 GetPiPcdInfoProtocolPointer (
91 VOID
92 )
93 {
94 EFI_STATUS Status;
95
96 if (mPiPcdInfo == NULL) {
97 Status = gBS->LocateProtocol (&gEfiGetPcdInfoProtocolGuid, NULL, (VOID **)&mPiPcdInfo);
98 ASSERT_EFI_ERROR (Status);
99 ASSERT (mPiPcdInfo != NULL);
100 }
101 return mPiPcdInfo;
102 }
103
104 /**
105 Retrieves the PCD info protocol from the handle database.
106
107 @retval GET_PCD_INFO_PROTOCOL * The pointer to the GET_PCD_INFO_PROTOCOL.
108 **/
109 GET_PCD_INFO_PROTOCOL *
110 GetPcdInfoProtocolPointer (
111 VOID
112 )
113 {
114 EFI_STATUS Status;
115
116 if (mPcdInfo == NULL) {
117 Status = gBS->LocateProtocol (&gGetPcdInfoProtocolGuid, NULL, (VOID **)&mPcdInfo);
118 ASSERT_EFI_ERROR (Status);
119 ASSERT (mPcdInfo != NULL);
120 }
121 return mPcdInfo;
122 }
123
124 /**
125 This function provides a means by which SKU support can be established in the PCD infrastructure.
126
127 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
128 If SkuId >= PCD_MAX_SKU_ID, then ASSERT().
129
130 @param SkuId The SKU value that will be used when the PCD service retrieves and sets values
131 associated with a PCD token.
132
133 @return Return the SKU ID that just be set.
134
135 **/
136 UINTN
137 EFIAPI
138 LibPcdSetSku (
139 IN UINTN SkuId
140 )
141 {
142 ASSERT (SkuId < PCD_MAX_SKU_ID);
143
144 GetPcdProtocol()->SetSku (SkuId);
145
146 return SkuId;
147 }
148
149
150
151 /**
152 This function provides a means by which to retrieve a value for a given PCD token.
153
154 Returns the 8-bit value for the token specified by TokenNumber.
155
156 @param[in] TokenNumber The PCD token number to retrieve a current value for.
157
158 @return Returns the 8-bit value for the token specified by TokenNumber.
159
160 **/
161 UINT8
162 EFIAPI
163 LibPcdGet8 (
164 IN UINTN TokenNumber
165 )
166 {
167 return GetPcdProtocol()->Get8 (TokenNumber);
168 }
169
170
171
172 /**
173 This function provides a means by which to retrieve a value for a given PCD token.
174
175 Returns the 16-bit value for the token specified by TokenNumber.
176
177 @param[in] TokenNumber The PCD token number to retrieve a current value for.
178
179 @return Returns the 16-bit value for the token specified by TokenNumber.
180
181 **/
182 UINT16
183 EFIAPI
184 LibPcdGet16 (
185 IN UINTN TokenNumber
186 )
187 {
188 return GetPcdProtocol()->Get16 (TokenNumber);
189 }
190
191
192
193 /**
194 This function provides a means by which to retrieve a value for a given PCD token.
195
196 Returns the 32-bit value for the token specified by TokenNumber.
197
198 @param[in] TokenNumber The PCD token number to retrieve a current value for.
199
200 @return Returns the 32-bit value for the token specified by TokenNumber.
201
202 **/
203 UINT32
204 EFIAPI
205 LibPcdGet32 (
206 IN UINTN TokenNumber
207 )
208 {
209 return GetPcdProtocol()->Get32 (TokenNumber);
210 }
211
212
213
214 /**
215 This function provides a means by which to retrieve a value for a given PCD token.
216
217 Returns the 64-bit value for the token specified by TokenNumber.
218
219 @param[in] TokenNumber The PCD token number to retrieve a current value for.
220
221 @return Returns the 64-bit value for the token specified by TokenNumber.
222
223 **/
224 UINT64
225 EFIAPI
226 LibPcdGet64 (
227 IN UINTN TokenNumber
228 )
229 {
230 return GetPcdProtocol()->Get64 (TokenNumber);
231 }
232
233
234
235 /**
236 This function provides a means by which to retrieve a value for a given PCD token.
237
238 Returns the pointer to the buffer of the token specified by TokenNumber.
239
240 @param[in] TokenNumber The PCD token number to retrieve a current value for.
241
242 @return Returns the pointer to the token specified by TokenNumber.
243
244 **/
245 VOID *
246 EFIAPI
247 LibPcdGetPtr (
248 IN UINTN TokenNumber
249 )
250 {
251 return GetPcdProtocol()->GetPtr (TokenNumber);
252 }
253
254
255
256 /**
257 This function provides a means by which to retrieve a value for a given PCD token.
258
259 Returns the Boolean value of the token specified by TokenNumber.
260
261 @param[in] TokenNumber The PCD token number to retrieve a current value for.
262
263 @return Returns the Boolean value of the token specified by TokenNumber.
264
265 **/
266 BOOLEAN
267 EFIAPI
268 LibPcdGetBool (
269 IN UINTN TokenNumber
270 )
271 {
272 return GetPcdProtocol()->GetBool (TokenNumber);
273 }
274
275
276
277 /**
278 This function provides a means by which to retrieve the size of a given PCD token.
279
280 @param[in] TokenNumber The PCD token number to retrieve a current value for.
281
282 @return Returns the size of the token specified by TokenNumber.
283
284 **/
285 UINTN
286 EFIAPI
287 LibPcdGetSize (
288 IN UINTN TokenNumber
289 )
290 {
291 return GetPcdProtocol()->GetSize (TokenNumber);
292 }
293
294
295
296 /**
297 This function provides a means by which to retrieve a value for a given PCD token.
298
299 Returns the 8-bit value for the token specified by TokenNumber and Guid.
300
301 If Guid is NULL, then ASSERT().
302
303 @param[in] Guid The pointer to a 128-bit unique value that designates
304 which namespace to retrieve a value from.
305 @param[in] TokenNumber The PCD token number to retrieve a current value for.
306
307 @return Return the UINT8.
308
309 **/
310 UINT8
311 EFIAPI
312 LibPcdGetEx8 (
313 IN CONST GUID *Guid,
314 IN UINTN TokenNumber
315 )
316 {
317 ASSERT (Guid != NULL);
318
319 return GetPiPcdProtocol()->Get8 (Guid, TokenNumber);
320 }
321
322
323 /**
324 This function provides a means by which to retrieve a value for a given PCD token.
325
326 Returns the 16-bit value for the token specified by TokenNumber and Guid.
327
328 If Guid is NULL, then ASSERT().
329
330 @param[in] Guid The pointer to a 128-bit unique value that designates
331 which namespace to retrieve a value from.
332 @param[in] TokenNumber The PCD token number to retrieve a current value for.
333
334 @return Return the UINT16.
335
336 **/
337 UINT16
338 EFIAPI
339 LibPcdGetEx16 (
340 IN CONST GUID *Guid,
341 IN UINTN TokenNumber
342 )
343 {
344 ASSERT (Guid != NULL);
345
346 return GetPiPcdProtocol()->Get16 (Guid, TokenNumber);
347 }
348
349
350 /**
351 Returns the 32-bit value for the token specified by TokenNumber and Guid.
352 If Guid is NULL, then ASSERT().
353
354 @param[in] Guid The pointer to a 128-bit unique value that designates
355 which namespace to retrieve a value from.
356 @param[in] TokenNumber The PCD token number to retrieve a current value for.
357
358 @return Return the UINT32.
359
360 **/
361 UINT32
362 EFIAPI
363 LibPcdGetEx32 (
364 IN CONST GUID *Guid,
365 IN UINTN TokenNumber
366 )
367 {
368 ASSERT (Guid != NULL);
369
370 return GetPiPcdProtocol()->Get32 (Guid, TokenNumber);
371 }
372
373
374
375 /**
376 This function provides a means by which to retrieve a value for a given PCD token.
377
378 Returns the 64-bit value for the token specified by TokenNumber and Guid.
379
380 If Guid is NULL, then ASSERT().
381
382 @param[in] Guid The pointer to a 128-bit unique value that designates
383 which namespace to retrieve a value from.
384 @param[in] TokenNumber The PCD token number to retrieve a current value for.
385
386 @return Return the UINT64.
387
388 **/
389 UINT64
390 EFIAPI
391 LibPcdGetEx64 (
392 IN CONST GUID *Guid,
393 IN UINTN TokenNumber
394 )
395 {
396 ASSERT (Guid != NULL);
397
398 return GetPiPcdProtocol()->Get64 (Guid, TokenNumber);
399 }
400
401
402
403 /**
404 This function provides a means by which to retrieve a value for a given PCD token.
405
406 Returns the pointer to the buffer of token specified by TokenNumber and Guid.
407
408 If Guid is NULL, then ASSERT().
409
410 @param[in] Guid The pointer to a 128-bit unique value that designates
411 which namespace to retrieve a value from.
412 @param[in] TokenNumber The PCD token number to retrieve a current value for.
413
414 @return Return the VOID* pointer.
415
416 **/
417 VOID *
418 EFIAPI
419 LibPcdGetExPtr (
420 IN CONST GUID *Guid,
421 IN UINTN TokenNumber
422 )
423 {
424 ASSERT (Guid != NULL);
425
426 return GetPiPcdProtocol()->GetPtr (Guid, TokenNumber);
427 }
428
429
430
431 /**
432 This function provides a means by which to retrieve a value for a given PCD token.
433
434 Returns the Boolean value of the token specified by TokenNumber and Guid.
435
436 If Guid is NULL, then ASSERT().
437
438 @param[in] Guid The pointer to a 128-bit unique value that designates
439 which namespace to retrieve a value from.
440 @param[in] TokenNumber The PCD token number to retrieve a current value for.
441
442 @return Return the BOOLEAN.
443
444 **/
445 BOOLEAN
446 EFIAPI
447 LibPcdGetExBool (
448 IN CONST GUID *Guid,
449 IN UINTN TokenNumber
450 )
451 {
452 ASSERT (Guid != NULL);
453
454 return GetPiPcdProtocol()->GetBool (Guid, TokenNumber);
455 }
456
457
458
459 /**
460 This function provides a means by which to retrieve the size of a given PCD token.
461
462 Returns the size of the token specified by TokenNumber and Guid.
463
464 If Guid is NULL, then ASSERT().
465
466 @param[in] Guid The pointer to a 128-bit unique value that designates
467 which namespace to retrieve a value from.
468 @param[in] TokenNumber The PCD token number to retrieve a current value for.
469
470 @return Return the size.
471
472 **/
473 UINTN
474 EFIAPI
475 LibPcdGetExSize (
476 IN CONST GUID *Guid,
477 IN UINTN TokenNumber
478 )
479 {
480 ASSERT (Guid != NULL);
481
482 return GetPiPcdProtocol()->GetSize (Guid, TokenNumber);
483 }
484
485
486
487 /**
488 This function provides a means by which to set a value for a given PCD token.
489
490 Sets the 8-bit value for the token specified by TokenNumber
491 to the value specified by Value. Value is returned.
492
493 @param[in] TokenNumber The PCD token number to set a current value for.
494 @param[in] Value The 8-bit value to set.
495
496 @return Return the value that was set.
497
498 **/
499 UINT8
500 EFIAPI
501 LibPcdSet8 (
502 IN UINTN TokenNumber,
503 IN UINT8 Value
504 )
505 {
506 EFI_STATUS Status;
507
508 Status = GetPcdProtocol()->Set8 (TokenNumber, Value);
509 ASSERT_EFI_ERROR (Status);
510
511 return Value;
512 }
513
514
515
516 /**
517 This function provides a means by which to set a value for a given PCD token.
518
519 Sets the 16-bit value for the token specified by TokenNumber
520 to the value specified by Value. Value is returned.
521
522 @param[in] TokenNumber The PCD token number to set a current value for.
523 @param[in] Value The 16-bit value to set.
524
525 @return Return the value that was set.
526
527 **/
528 UINT16
529 EFIAPI
530 LibPcdSet16 (
531 IN UINTN TokenNumber,
532 IN UINT16 Value
533 )
534 {
535 EFI_STATUS Status;
536
537 Status = GetPcdProtocol()->Set16 (TokenNumber, Value);
538 ASSERT_EFI_ERROR (Status);
539
540 return Value;
541 }
542
543
544
545 /**
546 This function provides a means by which to set a value for a given PCD token.
547
548 Sets the 32-bit value for the token specified by TokenNumber
549 to the value specified by Value. Value is returned.
550
551 @param[in] TokenNumber The PCD token number to set a current value for.
552 @param[in] Value The 32-bit value to set.
553
554 @return Return the value that was set.
555
556 **/
557 UINT32
558 EFIAPI
559 LibPcdSet32 (
560 IN UINTN TokenNumber,
561 IN UINT32 Value
562 )
563 {
564 EFI_STATUS Status;
565
566 Status = GetPcdProtocol()->Set32 (TokenNumber, Value);
567 ASSERT_EFI_ERROR (Status);
568
569 return Value;
570 }
571
572
573
574 /**
575 This function provides a means by which to set a value for a given PCD token.
576
577 Sets the 64-bit value for the token specified by TokenNumber
578 to the value specified by Value. Value is returned.
579
580 @param[in] TokenNumber The PCD token number to set a current value for.
581 @param[in] Value The 64-bit value to set.
582
583 @return Return the value that was set.
584
585 **/
586 UINT64
587 EFIAPI
588 LibPcdSet64 (
589 IN UINTN TokenNumber,
590 IN UINT64 Value
591 )
592 {
593 EFI_STATUS Status;
594
595 Status = GetPcdProtocol()->Set64 (TokenNumber, Value);
596 ASSERT_EFI_ERROR (Status);
597
598 return Value;
599 }
600
601
602
603 /**
604 This function provides a means by which to set a value for a given PCD token.
605
606 Sets a buffer for the token specified by TokenNumber to the value
607 specified by Buffer and SizeOfBuffer. Buffer is returned.
608 If SizeOfBuffer is greater than the maximum size support by TokenNumber,
609 then set SizeOfBuffer to the maximum size supported by TokenNumber and
610 return NULL to indicate that the set operation was not actually performed.
611
612 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
613 maximum size supported by TokenName and NULL must be returned.
614
615 If SizeOfBuffer is NULL, then ASSERT().
616 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
617
618 @param[in] TokenNumber The PCD token number to set a current value for.
619 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
620 @param[in] Buffer A pointer to the buffer to set.
621
622 @return Return the pointer for the buffer been set.
623
624 **/
625 VOID *
626 EFIAPI
627 LibPcdSetPtr (
628 IN UINTN TokenNumber,
629 IN OUT UINTN *SizeOfBuffer,
630 IN CONST VOID *Buffer
631 )
632 {
633 EFI_STATUS Status;
634
635 ASSERT (SizeOfBuffer != NULL);
636
637 if (*SizeOfBuffer > 0) {
638 ASSERT (Buffer != NULL);
639 }
640
641 Status = GetPcdProtocol()->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);
642 if (EFI_ERROR (Status)) {
643 return NULL;
644 }
645
646 return (VOID *)Buffer;
647 }
648
649
650
651 /**
652 This function provides a means by which to set a value for a given PCD token.
653
654 Sets the Boolean value for the token specified by TokenNumber
655 to the value specified by Value. Value is returned.
656
657 @param[in] TokenNumber The PCD token number to set a current value for.
658 @param[in] Value The boolean value to set.
659
660 @return Return the value that was set.
661
662 **/
663 BOOLEAN
664 EFIAPI
665 LibPcdSetBool (
666 IN UINTN TokenNumber,
667 IN BOOLEAN Value
668 )
669 {
670 EFI_STATUS Status;
671
672 Status = GetPcdProtocol()->SetBool (TokenNumber, Value);
673 ASSERT_EFI_ERROR (Status);
674
675 return Value;
676 }
677
678
679
680 /**
681 This function provides a means by which to set a value for a given PCD token.
682
683 Sets the 8-bit value for the token specified by TokenNumber and
684 Guid to the value specified by Value. Value is returned.
685
686 If Guid is NULL, then ASSERT().
687
688 @param[in] Guid The pointer to a 128-bit unique value that
689 designates which namespace to set a value from.
690 @param[in] TokenNumber The PCD token number to set a current value for.
691 @param[in] Value The 8-bit value to set.
692
693 @return Return the value that was set.
694
695 **/
696 UINT8
697 EFIAPI
698 LibPcdSetEx8 (
699 IN CONST GUID *Guid,
700 IN UINTN TokenNumber,
701 IN UINT8 Value
702 )
703 {
704 EFI_STATUS Status;
705
706 ASSERT (Guid != NULL);
707
708 Status = GetPiPcdProtocol()->Set8 (Guid, TokenNumber, Value);
709 ASSERT_EFI_ERROR (Status);
710
711 return Value;
712 }
713
714
715
716 /**
717 This function provides a means by which to set a value for a given PCD token.
718
719 Sets the 16-bit value for the token specified by TokenNumber and
720 Guid to the value specified by Value. Value is returned.
721
722 If Guid is NULL, then ASSERT().
723
724 @param[in] Guid The pointer to a 128-bit unique value that
725 designates which namespace to set a value from.
726 @param[in] TokenNumber The PCD token number to set a current value for.
727 @param[in] Value The 16-bit value to set.
728
729 @return Return the value that was set.
730
731 **/
732 UINT16
733 EFIAPI
734 LibPcdSetEx16 (
735 IN CONST GUID *Guid,
736 IN UINTN TokenNumber,
737 IN UINT16 Value
738 )
739 {
740 EFI_STATUS Status;
741
742 ASSERT (Guid != NULL);
743
744 Status = GetPiPcdProtocol()->Set16 (Guid, TokenNumber, Value);
745 ASSERT_EFI_ERROR (Status);
746
747 return Value;
748 }
749
750
751
752 /**
753 This function provides a means by which to set a value for a given PCD token.
754
755 Sets the 32-bit value for the token specified by TokenNumber and
756 Guid to the value specified by Value. Value is returned.
757
758 If Guid is NULL, then ASSERT().
759
760 @param[in] Guid The pointer to a 128-bit unique value that
761 designates which namespace to set a value from.
762 @param[in] TokenNumber The PCD token number to set a current value for.
763 @param[in] Value The 32-bit value to set.
764
765 @return Return the value that was set.
766
767 **/
768 UINT32
769 EFIAPI
770 LibPcdSetEx32 (
771 IN CONST GUID *Guid,
772 IN UINTN TokenNumber,
773 IN UINT32 Value
774 )
775 {
776 EFI_STATUS Status;
777
778 ASSERT (Guid != NULL);
779
780 Status = GetPiPcdProtocol()->Set32 (Guid, TokenNumber, Value);
781 ASSERT_EFI_ERROR (Status);
782
783 return Value;
784 }
785
786
787
788 /**
789 This function provides a means by which to set a value for a given PCD token.
790
791 Sets the 64-bit value for the token specified by TokenNumber and
792 Guid to the value specified by Value. Value is returned.
793 If Guid is NULL, then ASSERT().
794
795 @param[in] Guid The pointer to a 128-bit unique value that
796 designates which namespace to set a value from.
797 @param[in] TokenNumber The PCD token number to set a current value for.
798 @param[in] Value The 64-bit value to set.
799
800 @return Return the value that was set.
801
802 **/
803 UINT64
804 EFIAPI
805 LibPcdSetEx64 (
806 IN CONST GUID *Guid,
807 IN UINTN TokenNumber,
808 IN UINT64 Value
809 )
810 {
811 EFI_STATUS Status;
812
813 ASSERT (Guid != NULL);
814
815 Status = GetPiPcdProtocol()->Set64 (Guid, TokenNumber, Value);
816 ASSERT_EFI_ERROR (Status);
817
818 return Value;
819 }
820
821
822
823 /**
824 This function provides a means by which to set a value for a given PCD token.
825
826 Sets a buffer for the token specified by TokenNumber to the value specified by
827 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
828 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
829 supported by TokenNumber and return NULL to indicate that the set operation
830 was not actually performed.
831
832 If Guid is NULL, then ASSERT().
833 If SizeOfBuffer is NULL, then ASSERT().
834 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
835
836 @param[in] Guid The pointer to a 128-bit unique value that
837 designates which namespace to set a value from.
838 @param[in] TokenNumber The PCD token number to set a current value for.
839 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
840 @param[in] Buffer A pointer to the buffer to set.
841
842 @return Return the pointer to the buffer been set.
843
844 **/
845 VOID *
846 EFIAPI
847 LibPcdSetExPtr (
848 IN CONST GUID *Guid,
849 IN UINTN TokenNumber,
850 IN OUT UINTN *SizeOfBuffer,
851 IN VOID *Buffer
852 )
853 {
854 EFI_STATUS Status;
855
856 ASSERT (Guid != NULL);
857
858 ASSERT (SizeOfBuffer != NULL);
859
860 if (*SizeOfBuffer > 0) {
861 ASSERT (Buffer != NULL);
862 }
863
864 Status = GetPiPcdProtocol()->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);
865 if (EFI_ERROR (Status)) {
866 return NULL;
867 }
868
869 return Buffer;
870 }
871
872
873
874 /**
875 This function provides a means by which to set a value for a given PCD token.
876
877 Sets the Boolean value for the token specified by TokenNumber and
878 Guid to the value specified by Value. Value is returned.
879
880 If Guid is NULL, then ASSERT().
881
882 @param[in] Guid The pointer to a 128-bit unique value that
883 designates which namespace to set a value from.
884 @param[in] TokenNumber The PCD token number to set a current value for.
885 @param[in] Value The Boolean value to set.
886
887 @return Return the value that was set.
888
889 **/
890 BOOLEAN
891 EFIAPI
892 LibPcdSetExBool (
893 IN CONST GUID *Guid,
894 IN UINTN TokenNumber,
895 IN BOOLEAN Value
896 )
897 {
898 EFI_STATUS Status;
899
900 ASSERT (Guid != NULL);
901
902 Status = GetPiPcdProtocol()->SetBool (Guid, TokenNumber, Value);
903 ASSERT_EFI_ERROR (Status);
904
905 return Value;
906 }
907
908
909
910 /**
911 Set up a notification function that is called when a specified token is set.
912
913 When the token specified by TokenNumber and Guid is set,
914 then notification function specified by NotificationFunction is called.
915 If Guid is NULL, then the default token space is used.
916 If NotificationFunction is NULL, then ASSERT().
917
918 @param[in] Guid The pointer to a 128-bit unique value that designates which
919 namespace to set a value from. If NULL, then the default
920 token space is used.
921 @param[in] TokenNumber The PCD token number to monitor.
922 @param[in] NotificationFunction The function to call when the token
923 specified by Guid and TokenNumber is set.
924
925 **/
926 VOID
927 EFIAPI
928 LibPcdCallbackOnSet (
929 IN CONST GUID *Guid, OPTIONAL
930 IN UINTN TokenNumber,
931 IN PCD_CALLBACK NotificationFunction
932 )
933 {
934 EFI_STATUS Status;
935
936 ASSERT (NotificationFunction != NULL);
937
938 Status = GetPiPcdProtocol()->CallbackOnSet (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);
939 ASSERT_EFI_ERROR (Status);
940
941 return;
942 }
943
944
945
946 /**
947 Disable a notification function that was established with LibPcdCallbackonSet().
948
949 Disable a notification function that was previously established with LibPcdCallbackOnSet().
950 If NotificationFunction is NULL, then ASSERT().
951 If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber,
952 and NotificationFunction, then ASSERT().
953
954 @param[in] Guid Specify the GUID token space.
955 @param[in] TokenNumber Specify the token number.
956 @param[in] NotificationFunction The callback function to be unregistered.
957
958 **/
959 VOID
960 EFIAPI
961 LibPcdCancelCallback (
962 IN CONST GUID *Guid, OPTIONAL
963 IN UINTN TokenNumber,
964 IN PCD_CALLBACK NotificationFunction
965 )
966 {
967 EFI_STATUS Status;
968
969 ASSERT (NotificationFunction != NULL);
970
971 Status = GetPiPcdProtocol()->CancelCallback (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);
972 ASSERT_EFI_ERROR (Status);
973
974 return;
975 }
976
977
978
979 /**
980 Retrieves the next token in a token space.
981
982 Retrieves the next PCD token number from the token space specified by Guid.
983 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
984 then the first token number is returned. Otherwise, the token number that
985 follows TokenNumber in the token space is returned. If TokenNumber is the last
986 token number in the token space, then 0 is returned.
987
988 If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().
989
990 @param[in] Guid The pointer to a 128-bit unique value that designates which namespace
991 to set a value from. If NULL, then the default token space is used.
992 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
993 token number.
994
995 @return The next valid token number.
996
997 **/
998 UINTN
999 EFIAPI
1000 LibPcdGetNextToken (
1001 IN CONST GUID *Guid, OPTIONAL
1002 IN UINTN TokenNumber
1003 )
1004 {
1005 EFI_STATUS Status;
1006
1007 Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);
1008 ASSERT (!EFI_ERROR (Status) || TokenNumber == 0);
1009
1010 return TokenNumber;
1011 }
1012
1013
1014
1015 /**
1016 Used to retrieve the list of available PCD token space GUIDs.
1017
1018 Returns the PCD token space GUID that follows TokenSpaceGuid in the list of token spaces
1019 in the platform.
1020 If TokenSpaceGuid is NULL, then a pointer to the first PCD token spaces returned.
1021 If TokenSpaceGuid is the last PCD token space GUID in the list, then NULL is returned.
1022
1023 @param TokenSpaceGuid The pointer to the a PCD token space GUID.
1024
1025 @return The next valid token namespace.
1026
1027 **/
1028 GUID *
1029 EFIAPI
1030 LibPcdGetNextTokenSpace (
1031 IN CONST GUID *TokenSpaceGuid
1032 )
1033 {
1034 GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid);
1035
1036 return (GUID *)TokenSpaceGuid;
1037 }
1038
1039
1040 /**
1041 Sets a value of a patchable PCD entry that is type pointer.
1042
1043 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1044 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
1045 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
1046 NULL to indicate that the set operation was not actually performed.
1047 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1048 MaximumDatumSize and NULL must be returned.
1049
1050 If PatchVariable is NULL, then ASSERT().
1051 If SizeOfBuffer is NULL, then ASSERT().
1052 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1053
1054 @param[in] PatchVariable A pointer to the global variable in a module that is
1055 the target of the set operation.
1056 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1057 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1058 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1059
1060 @return Return the pointer to the buffer been set.
1061
1062 **/
1063 VOID *
1064 EFIAPI
1065 LibPatchPcdSetPtr (
1066 IN VOID *PatchVariable,
1067 IN UINTN MaximumDatumSize,
1068 IN OUT UINTN *SizeOfBuffer,
1069 IN CONST VOID *Buffer
1070 )
1071 {
1072 ASSERT (PatchVariable != NULL);
1073 ASSERT (SizeOfBuffer != NULL);
1074
1075 if (*SizeOfBuffer > 0) {
1076 ASSERT (Buffer != NULL);
1077 }
1078
1079 if ((*SizeOfBuffer > MaximumDatumSize) ||
1080 (*SizeOfBuffer == MAX_ADDRESS)) {
1081 *SizeOfBuffer = MaximumDatumSize;
1082 return NULL;
1083 }
1084
1085 CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1086
1087 return (VOID *) Buffer;
1088 }
1089
1090 /**
1091 Retrieve additional information associated with a PCD token.
1092
1093 This includes information such as the type of value the TokenNumber is associated with as well as possible
1094 human readable name that is associated with the token.
1095
1096 If TokenNumber is not in the default token space specified, then ASSERT().
1097
1098 @param[in] TokenNumber The PCD token number.
1099 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
1100 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
1101 **/
1102 VOID
1103 EFIAPI
1104 LibPcdGetInfo (
1105 IN UINTN TokenNumber,
1106 OUT PCD_INFO *PcdInfo
1107 )
1108 {
1109 EFI_STATUS Status;
1110
1111 Status = GetPcdInfoProtocolPointer()->GetInfo (TokenNumber, (EFI_PCD_INFO *) PcdInfo);
1112 ASSERT_EFI_ERROR (Status);
1113 }
1114
1115 /**
1116 Retrieve additional information associated with a PCD token.
1117
1118 This includes information such as the type of value the TokenNumber is associated with as well as possible
1119 human readable name that is associated with the token.
1120
1121 If TokenNumber is not in the token space specified by Guid, then ASSERT().
1122
1123 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1124 @param[in] TokenNumber The PCD token number.
1125 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
1126 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
1127 **/
1128 VOID
1129 EFIAPI
1130 LibPcdGetInfoEx (
1131 IN CONST GUID *Guid,
1132 IN UINTN TokenNumber,
1133 OUT PCD_INFO *PcdInfo
1134 )
1135 {
1136 EFI_STATUS Status;
1137
1138 Status = GetPiPcdInfoProtocolPointer()->GetInfo (Guid, TokenNumber, (EFI_PCD_INFO *) PcdInfo);
1139 ASSERT_EFI_ERROR (Status);
1140 }
1141
1142 /**
1143 Retrieve the currently set SKU Id.
1144
1145 If the sku id got >= PCD_MAX_SKU_ID, then ASSERT().
1146
1147 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the
1148 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU
1149 Id is returned.
1150 **/
1151 UINTN
1152 EFIAPI
1153 LibPcdGetSku (
1154 VOID
1155 )
1156 {
1157 UINTN SkuId;
1158
1159 SkuId = GetPiPcdInfoProtocolPointer()->GetSku ();
1160 ASSERT (SkuId < PCD_MAX_SKU_ID);
1161
1162 return SkuId;
1163 }
1164