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