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