]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxePcdLib/DxePcdLib.c
MdePkg PcdLib: Except for SizeOfBuffer is greater than the maximum size supported...
[mirror_edk2.git] / MdePkg / Library / DxePcdLib / DxePcdLib.c
1 /** @file
2 Implementation of PcdLib class library for DXE phase.
3
4 Copyright (c) 2006 - 2014, 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 If the set operation was not correctly performed, then ASSERT().
494
495 @param[in] TokenNumber The PCD token number to set a current value for.
496 @param[in] Value The 8-bit value to set.
497
498 @return Return the value that was set.
499
500 **/
501 UINT8
502 EFIAPI
503 LibPcdSet8 (
504 IN UINTN TokenNumber,
505 IN UINT8 Value
506 )
507 {
508 EFI_STATUS Status;
509
510 Status = GetPcdProtocol()->Set8 (TokenNumber, Value);
511 ASSERT_EFI_ERROR (Status);
512
513 return Value;
514 }
515
516
517
518 /**
519 This function provides a means by which to set a value for a given PCD token.
520
521 Sets the 16-bit value for the token specified by TokenNumber
522 to the value specified by Value. Value is returned.
523
524 If the set operation was not correctly performed, then ASSERT().
525
526 @param[in] TokenNumber The PCD token number to set a current value for.
527 @param[in] Value The 16-bit value to set.
528
529 @return Return the value that was set.
530
531 **/
532 UINT16
533 EFIAPI
534 LibPcdSet16 (
535 IN UINTN TokenNumber,
536 IN UINT16 Value
537 )
538 {
539 EFI_STATUS Status;
540
541 Status = GetPcdProtocol()->Set16 (TokenNumber, Value);
542 ASSERT_EFI_ERROR (Status);
543
544 return Value;
545 }
546
547
548
549 /**
550 This function provides a means by which to set a value for a given PCD token.
551
552 Sets the 32-bit value for the token specified by TokenNumber
553 to the value specified by Value. Value is returned.
554
555 If the set operation was not correctly performed, then ASSERT().
556
557 @param[in] TokenNumber The PCD token number to set a current value for.
558 @param[in] Value The 32-bit value to set.
559
560 @return Return the value that was set.
561
562 **/
563 UINT32
564 EFIAPI
565 LibPcdSet32 (
566 IN UINTN TokenNumber,
567 IN UINT32 Value
568 )
569 {
570 EFI_STATUS Status;
571
572 Status = GetPcdProtocol()->Set32 (TokenNumber, Value);
573 ASSERT_EFI_ERROR (Status);
574
575 return Value;
576 }
577
578
579
580 /**
581 This function provides a means by which to set a value for a given PCD token.
582
583 Sets the 64-bit value for the token specified by TokenNumber
584 to the value specified by Value. Value is returned.
585
586 If the set operation was not correctly performed, then ASSERT().
587
588 @param[in] TokenNumber The PCD token number to set a current value for.
589 @param[in] Value The 64-bit value to set.
590
591 @return Return the value that was set.
592
593 **/
594 UINT64
595 EFIAPI
596 LibPcdSet64 (
597 IN UINTN TokenNumber,
598 IN UINT64 Value
599 )
600 {
601 EFI_STATUS Status;
602
603 Status = GetPcdProtocol()->Set64 (TokenNumber, Value);
604 ASSERT_EFI_ERROR (Status);
605
606 return Value;
607 }
608
609
610
611 /**
612 This function provides a means by which to set a value for a given PCD token.
613
614 Sets a buffer for the token specified by TokenNumber to the value
615 specified by Buffer and SizeOfBuffer. Buffer is returned.
616 If SizeOfBuffer is greater than the maximum size support by TokenNumber,
617 then set SizeOfBuffer to the maximum size supported by TokenNumber and
618 return NULL to indicate that the set operation was not actually performed,
619 or ASSERT() if the set operation was not correctly performed.
620
621 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
622 maximum size supported by TokenName and NULL must be returned.
623
624 If SizeOfBuffer is NULL, then ASSERT().
625 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
626
627 @param[in] TokenNumber The PCD token number to set a current value for.
628 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
629 @param[in] Buffer A pointer to the buffer to set.
630
631 @return Return the pointer for the buffer been set.
632
633 **/
634 VOID *
635 EFIAPI
636 LibPcdSetPtr (
637 IN UINTN TokenNumber,
638 IN OUT UINTN *SizeOfBuffer,
639 IN CONST VOID *Buffer
640 )
641 {
642 EFI_STATUS Status;
643 UINTN InputSizeOfBuffer;
644
645 ASSERT (SizeOfBuffer != NULL);
646
647 if (*SizeOfBuffer > 0) {
648 ASSERT (Buffer != NULL);
649 }
650
651 InputSizeOfBuffer = *SizeOfBuffer;
652 Status = GetPcdProtocol()->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);
653 if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {
654 return NULL;
655 }
656 ASSERT_EFI_ERROR (Status);
657
658 return (VOID *)Buffer;
659 }
660
661
662
663 /**
664 This function provides a means by which to set a value for a given PCD token.
665
666 Sets the Boolean value for the token specified by TokenNumber
667 to the value specified by Value. Value is returned.
668
669 If the set operation was not correctly performed, then ASSERT().
670
671 @param[in] TokenNumber The PCD token number to set a current value for.
672 @param[in] Value The boolean value to set.
673
674 @return Return the value that was set.
675
676 **/
677 BOOLEAN
678 EFIAPI
679 LibPcdSetBool (
680 IN UINTN TokenNumber,
681 IN BOOLEAN Value
682 )
683 {
684 EFI_STATUS Status;
685
686 Status = GetPcdProtocol()->SetBool (TokenNumber, Value);
687 ASSERT_EFI_ERROR (Status);
688
689 return Value;
690 }
691
692
693
694 /**
695 This function provides a means by which to set a value for a given PCD token.
696
697 Sets the 8-bit value for the token specified by TokenNumber and
698 Guid to the value specified by Value. Value is returned.
699
700 If Guid is NULL, then ASSERT().
701 If the set operation was not correctly performed, then ASSERT().
702
703 @param[in] Guid The pointer to a 128-bit unique value that
704 designates which namespace to set a value from.
705 @param[in] TokenNumber The PCD token number to set a current value for.
706 @param[in] Value The 8-bit value to set.
707
708 @return Return the value that was set.
709
710 **/
711 UINT8
712 EFIAPI
713 LibPcdSetEx8 (
714 IN CONST GUID *Guid,
715 IN UINTN TokenNumber,
716 IN UINT8 Value
717 )
718 {
719 EFI_STATUS Status;
720
721 ASSERT (Guid != NULL);
722
723 Status = GetPiPcdProtocol()->Set8 (Guid, TokenNumber, Value);
724 ASSERT_EFI_ERROR (Status);
725
726 return Value;
727 }
728
729
730
731 /**
732 This function provides a means by which to set a value for a given PCD token.
733
734 Sets the 16-bit value for the token specified by TokenNumber and
735 Guid to the value specified by Value. Value is returned.
736
737 If Guid is NULL, then ASSERT().
738 If the set operation was not correctly performed, then ASSERT().
739
740 @param[in] Guid The pointer to a 128-bit unique value that
741 designates which namespace to set a value from.
742 @param[in] TokenNumber The PCD token number to set a current value for.
743 @param[in] Value The 16-bit value to set.
744
745 @return Return the value that was set.
746
747 **/
748 UINT16
749 EFIAPI
750 LibPcdSetEx16 (
751 IN CONST GUID *Guid,
752 IN UINTN TokenNumber,
753 IN UINT16 Value
754 )
755 {
756 EFI_STATUS Status;
757
758 ASSERT (Guid != NULL);
759
760 Status = GetPiPcdProtocol()->Set16 (Guid, TokenNumber, Value);
761 ASSERT_EFI_ERROR (Status);
762
763 return Value;
764 }
765
766
767
768 /**
769 This function provides a means by which to set a value for a given PCD token.
770
771 Sets the 32-bit value for the token specified by TokenNumber and
772 Guid to the value specified by Value. Value is returned.
773
774 If Guid is NULL, then ASSERT().
775 If the set operation was not correctly performed, then ASSERT().
776
777 @param[in] Guid The 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 32-bit value to set.
781
782 @return Return the value that was set.
783
784 **/
785 UINT32
786 EFIAPI
787 LibPcdSetEx32 (
788 IN CONST GUID *Guid,
789 IN UINTN TokenNumber,
790 IN UINT32 Value
791 )
792 {
793 EFI_STATUS Status;
794
795 ASSERT (Guid != NULL);
796
797 Status = GetPiPcdProtocol()->Set32 (Guid, TokenNumber, Value);
798 ASSERT_EFI_ERROR (Status);
799
800 return Value;
801 }
802
803
804
805 /**
806 This function provides a means by which to set a value for a given PCD token.
807
808 Sets the 64-bit value for the token specified by TokenNumber and
809 Guid to the value specified by Value. Value is returned.
810
811 If Guid is NULL, then ASSERT().
812 If the set operation was not correctly performed, then ASSERT().
813
814 @param[in] Guid The pointer to a 128-bit unique value that
815 designates which namespace to set a value from.
816 @param[in] TokenNumber The PCD token number to set a current value for.
817 @param[in] Value The 64-bit value to set.
818
819 @return Return the value that was set.
820
821 **/
822 UINT64
823 EFIAPI
824 LibPcdSetEx64 (
825 IN CONST GUID *Guid,
826 IN UINTN TokenNumber,
827 IN UINT64 Value
828 )
829 {
830 EFI_STATUS Status;
831
832 ASSERT (Guid != NULL);
833
834 Status = GetPiPcdProtocol()->Set64 (Guid, TokenNumber, Value);
835 ASSERT_EFI_ERROR (Status);
836
837 return Value;
838 }
839
840
841
842 /**
843 This function provides a means by which to set a value for a given PCD token.
844
845 Sets a buffer for the token specified by TokenNumber to the value specified by
846 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
847 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
848 supported by TokenNumber and return NULL to indicate that the set operation
849 was not actually performed, or ASSERT() if the set operation was not corretly performed.
850
851 If Guid is NULL, then ASSERT().
852 If SizeOfBuffer is NULL, then ASSERT().
853 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
854
855 @param[in] Guid The pointer to a 128-bit unique value that
856 designates which namespace to set a value from.
857 @param[in] TokenNumber The PCD token number to set a current value for.
858 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
859 @param[in] Buffer A pointer to the buffer to set.
860
861 @return Return the pointer to the buffer been set.
862
863 **/
864 VOID *
865 EFIAPI
866 LibPcdSetExPtr (
867 IN CONST GUID *Guid,
868 IN UINTN TokenNumber,
869 IN OUT UINTN *SizeOfBuffer,
870 IN VOID *Buffer
871 )
872 {
873 EFI_STATUS Status;
874 UINTN InputSizeOfBuffer;
875
876 ASSERT (Guid != NULL);
877
878 ASSERT (SizeOfBuffer != NULL);
879
880 if (*SizeOfBuffer > 0) {
881 ASSERT (Buffer != NULL);
882 }
883
884 InputSizeOfBuffer = *SizeOfBuffer;
885 Status = GetPiPcdProtocol()->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);
886 if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {
887 return NULL;
888 }
889 ASSERT_EFI_ERROR (Status);
890
891 return Buffer;
892 }
893
894
895
896 /**
897 This function provides a means by which to set a value for a given PCD token.
898
899 Sets the Boolean value for the token specified by TokenNumber and
900 Guid to the value specified by Value. Value is returned.
901
902 If Guid is NULL, then ASSERT().
903 If the set operation was not correctly performed, then ASSERT().
904
905 @param[in] Guid The pointer to a 128-bit unique value that
906 designates which namespace to set a value from.
907 @param[in] TokenNumber The PCD token number to set a current value for.
908 @param[in] Value The Boolean value to set.
909
910 @return Return the value that was set.
911
912 **/
913 BOOLEAN
914 EFIAPI
915 LibPcdSetExBool (
916 IN CONST GUID *Guid,
917 IN UINTN TokenNumber,
918 IN BOOLEAN Value
919 )
920 {
921 EFI_STATUS Status;
922
923 ASSERT (Guid != NULL);
924
925 Status = GetPiPcdProtocol()->SetBool (Guid, TokenNumber, Value);
926 ASSERT_EFI_ERROR (Status);
927
928 return Value;
929 }
930
931
932
933 /**
934 Set up a notification function that is called when a specified token is set.
935
936 When the token specified by TokenNumber and Guid is set,
937 then notification function specified by NotificationFunction is called.
938 If Guid is NULL, then the default token space is used.
939 If NotificationFunction is NULL, then ASSERT().
940
941 @param[in] Guid The pointer to a 128-bit unique value that designates which
942 namespace to set a value from. If NULL, then the default
943 token space is used.
944 @param[in] TokenNumber The PCD token number to monitor.
945 @param[in] NotificationFunction The function to call when the token
946 specified by Guid and TokenNumber is set.
947
948 **/
949 VOID
950 EFIAPI
951 LibPcdCallbackOnSet (
952 IN CONST GUID *Guid, OPTIONAL
953 IN UINTN TokenNumber,
954 IN PCD_CALLBACK NotificationFunction
955 )
956 {
957 EFI_STATUS Status;
958
959 ASSERT (NotificationFunction != NULL);
960
961 Status = GetPiPcdProtocol()->CallbackOnSet (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);
962 ASSERT_EFI_ERROR (Status);
963
964 return;
965 }
966
967
968
969 /**
970 Disable a notification function that was established with LibPcdCallbackonSet().
971
972 Disable a notification function that was previously established with LibPcdCallbackOnSet().
973 If NotificationFunction is NULL, then ASSERT().
974 If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber,
975 and NotificationFunction, then ASSERT().
976
977 @param[in] Guid Specify the GUID token space.
978 @param[in] TokenNumber Specify the token number.
979 @param[in] NotificationFunction The callback function to be unregistered.
980
981 **/
982 VOID
983 EFIAPI
984 LibPcdCancelCallback (
985 IN CONST GUID *Guid, OPTIONAL
986 IN UINTN TokenNumber,
987 IN PCD_CALLBACK NotificationFunction
988 )
989 {
990 EFI_STATUS Status;
991
992 ASSERT (NotificationFunction != NULL);
993
994 Status = GetPiPcdProtocol()->CancelCallback (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);
995 ASSERT_EFI_ERROR (Status);
996
997 return;
998 }
999
1000
1001
1002 /**
1003 Retrieves the next token in a token space.
1004
1005 Retrieves the next PCD token number from the token space specified by Guid.
1006 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
1007 then the first token number is returned. Otherwise, the token number that
1008 follows TokenNumber in the token space is returned. If TokenNumber is the last
1009 token number in the token space, then 0 is returned.
1010
1011 If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().
1012
1013 @param[in] Guid The pointer to a 128-bit unique value that designates which namespace
1014 to set a value from. If NULL, then the default token space is used.
1015 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
1016 token number.
1017
1018 @return The next valid token number.
1019
1020 **/
1021 UINTN
1022 EFIAPI
1023 LibPcdGetNextToken (
1024 IN CONST GUID *Guid, OPTIONAL
1025 IN UINTN TokenNumber
1026 )
1027 {
1028 EFI_STATUS Status;
1029
1030 Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);
1031 ASSERT (!EFI_ERROR (Status) || TokenNumber == 0);
1032
1033 return TokenNumber;
1034 }
1035
1036
1037
1038 /**
1039 Used to retrieve the list of available PCD token space GUIDs.
1040
1041 Returns the PCD token space GUID that follows TokenSpaceGuid in the list of token spaces
1042 in the platform.
1043 If TokenSpaceGuid is NULL, then a pointer to the first PCD token spaces returned.
1044 If TokenSpaceGuid is the last PCD token space GUID in the list, then NULL is returned.
1045
1046 @param TokenSpaceGuid The pointer to the a PCD token space GUID.
1047
1048 @return The next valid token namespace.
1049
1050 **/
1051 GUID *
1052 EFIAPI
1053 LibPcdGetNextTokenSpace (
1054 IN CONST GUID *TokenSpaceGuid
1055 )
1056 {
1057 GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid);
1058
1059 return (GUID *)TokenSpaceGuid;
1060 }
1061
1062
1063 /**
1064 Sets a value of a patchable PCD entry that is type pointer.
1065
1066 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1067 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
1068 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
1069 NULL to indicate that the set operation was not actually performed.
1070 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1071 MaximumDatumSize and NULL must be returned.
1072
1073 If PatchVariable is NULL, then ASSERT().
1074 If SizeOfBuffer is NULL, then ASSERT().
1075 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1076
1077 @param[in] PatchVariable A pointer to the global variable in a module that is
1078 the target of the set operation.
1079 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1080 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1081 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1082
1083 @return Return the pointer to the buffer been set.
1084
1085 **/
1086 VOID *
1087 EFIAPI
1088 LibPatchPcdSetPtr (
1089 IN VOID *PatchVariable,
1090 IN UINTN MaximumDatumSize,
1091 IN OUT UINTN *SizeOfBuffer,
1092 IN CONST VOID *Buffer
1093 )
1094 {
1095 ASSERT (PatchVariable != NULL);
1096 ASSERT (SizeOfBuffer != NULL);
1097
1098 if (*SizeOfBuffer > 0) {
1099 ASSERT (Buffer != NULL);
1100 }
1101
1102 if ((*SizeOfBuffer > MaximumDatumSize) ||
1103 (*SizeOfBuffer == MAX_ADDRESS)) {
1104 *SizeOfBuffer = MaximumDatumSize;
1105 return NULL;
1106 }
1107
1108 CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1109
1110 return (VOID *) Buffer;
1111 }
1112
1113 /**
1114 Retrieve additional information associated with a PCD token.
1115
1116 This includes information such as the type of value the TokenNumber is associated with as well as possible
1117 human readable name that is associated with the token.
1118
1119 If TokenNumber is not in the default token space specified, then ASSERT().
1120
1121 @param[in] TokenNumber The PCD token number.
1122 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
1123 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
1124 **/
1125 VOID
1126 EFIAPI
1127 LibPcdGetInfo (
1128 IN UINTN TokenNumber,
1129 OUT PCD_INFO *PcdInfo
1130 )
1131 {
1132 EFI_STATUS Status;
1133
1134 Status = GetPcdInfoProtocolPointer()->GetInfo (TokenNumber, (EFI_PCD_INFO *) PcdInfo);
1135 ASSERT_EFI_ERROR (Status);
1136 }
1137
1138 /**
1139 Retrieve additional information associated with a PCD token.
1140
1141 This includes information such as the type of value the TokenNumber is associated with as well as possible
1142 human readable name that is associated with the token.
1143
1144 If TokenNumber is not in the token space specified by Guid, then ASSERT().
1145
1146 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1147 @param[in] TokenNumber The PCD token number.
1148 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
1149 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
1150 **/
1151 VOID
1152 EFIAPI
1153 LibPcdGetInfoEx (
1154 IN CONST GUID *Guid,
1155 IN UINTN TokenNumber,
1156 OUT PCD_INFO *PcdInfo
1157 )
1158 {
1159 EFI_STATUS Status;
1160
1161 Status = GetPiPcdInfoProtocolPointer()->GetInfo (Guid, TokenNumber, (EFI_PCD_INFO *) PcdInfo);
1162 ASSERT_EFI_ERROR (Status);
1163 }
1164
1165 /**
1166 Retrieve the currently set SKU Id.
1167
1168 If the sku id got >= PCD_MAX_SKU_ID, then ASSERT().
1169
1170 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the
1171 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU
1172 Id is returned.
1173 **/
1174 UINTN
1175 EFIAPI
1176 LibPcdGetSku (
1177 VOID
1178 )
1179 {
1180 UINTN SkuId;
1181
1182 SkuId = GetPiPcdInfoProtocolPointer()->GetSku ();
1183 ASSERT (SkuId < PCD_MAX_SKU_ID);
1184
1185 return SkuId;
1186 }
1187