TianoCore EDK2 master
Loading...
Searching...
No Matches
DxePcdLib.c
Go to the documentation of this file.
1
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>
21
22PCD_PROTOCOL *mPcd = NULL;
23EFI_PCD_PROTOCOL *mPiPcd = NULL;
24GET_PCD_INFO_PROTOCOL *mPcdInfo = NULL;
26
33EFIAPI
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
59EFIAPI
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
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
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
132UINTN
133EFIAPI
135 IN UINTN SkuId
136 )
137{
138 GetPcdProtocol ()->SetSku (SkuId);
139
140 return SkuId;
141}
142
153UINT8
154EFIAPI
156 IN UINTN TokenNumber
157 )
158{
159 return GetPcdProtocol ()->Get8 (TokenNumber);
160}
161
172UINT16
173EFIAPI
175 IN UINTN TokenNumber
176 )
177{
178 return GetPcdProtocol ()->Get16 (TokenNumber);
179}
180
191UINT32
192EFIAPI
194 IN UINTN TokenNumber
195 )
196{
197 return GetPcdProtocol ()->Get32 (TokenNumber);
198}
199
210UINT64
211EFIAPI
213 IN UINTN TokenNumber
214 )
215{
216 return GetPcdProtocol ()->Get64 (TokenNumber);
217}
218
229VOID *
230EFIAPI
232 IN UINTN TokenNumber
233 )
234{
235 return GetPcdProtocol ()->GetPtr (TokenNumber);
236}
237
248BOOLEAN
249EFIAPI
251 IN UINTN TokenNumber
252 )
253{
254 return GetPcdProtocol ()->GetBool (TokenNumber);
255}
256
265UINTN
266EFIAPI
268 IN UINTN TokenNumber
269 )
270{
271 return GetPcdProtocol ()->GetSize (TokenNumber);
272}
273
288UINT8
289EFIAPI
291 IN CONST GUID *Guid,
292 IN UINTN TokenNumber
293 )
294{
295 ASSERT (Guid != NULL);
296
297 return GetPiPcdProtocol ()->Get8 (Guid, TokenNumber);
298}
299
314UINT16
315EFIAPI
317 IN CONST GUID *Guid,
318 IN UINTN TokenNumber
319 )
320{
321 ASSERT (Guid != NULL);
322
323 return GetPiPcdProtocol ()->Get16 (Guid, TokenNumber);
324}
325
337UINT32
338EFIAPI
340 IN CONST GUID *Guid,
341 IN UINTN TokenNumber
342 )
343{
344 ASSERT (Guid != NULL);
345
346 return GetPiPcdProtocol ()->Get32 (Guid, TokenNumber);
347}
348
363UINT64
364EFIAPI
366 IN CONST GUID *Guid,
367 IN UINTN TokenNumber
368 )
369{
370 ASSERT (Guid != NULL);
371
372 return GetPiPcdProtocol ()->Get64 (Guid, TokenNumber);
373}
374
389VOID *
390EFIAPI
392 IN CONST GUID *Guid,
393 IN UINTN TokenNumber
394 )
395{
396 ASSERT (Guid != NULL);
397
398 return GetPiPcdProtocol ()->GetPtr (Guid, TokenNumber);
399}
400
415BOOLEAN
416EFIAPI
418 IN CONST GUID *Guid,
419 IN UINTN TokenNumber
420 )
421{
422 ASSERT (Guid != NULL);
423
424 return GetPiPcdProtocol ()->GetBool (Guid, TokenNumber);
425}
426
441UINTN
442EFIAPI
444 IN CONST GUID *Guid,
445 IN UINTN TokenNumber
446 )
447{
448 ASSERT (Guid != NULL);
449
450 return GetPiPcdProtocol ()->GetSize (Guid, TokenNumber);
451}
452
465RETURN_STATUS
466EFIAPI
468 IN UINTN TokenNumber,
469 IN UINT8 Value
470 )
471{
472 return GetPcdProtocol ()->Set8 (TokenNumber, Value);
473}
474
487RETURN_STATUS
488EFIAPI
490 IN UINTN TokenNumber,
491 IN UINT16 Value
492 )
493{
494 return GetPcdProtocol ()->Set16 (TokenNumber, Value);
495}
496
509RETURN_STATUS
510EFIAPI
512 IN UINTN TokenNumber,
513 IN UINT32 Value
514 )
515{
516 return GetPcdProtocol ()->Set32 (TokenNumber, Value);
517}
518
531RETURN_STATUS
532EFIAPI
534 IN UINTN TokenNumber,
535 IN UINT64 Value
536 )
537{
538 return GetPcdProtocol ()->Set64 (TokenNumber, Value);
539}
540
563RETURN_STATUS
564EFIAPI
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
592RETURN_STATUS
593EFIAPI
595 IN UINTN TokenNumber,
596 IN BOOLEAN Value
597 )
598{
599 return GetPcdProtocol ()->SetBool (TokenNumber, Value);
600}
601
618RETURN_STATUS
619EFIAPI
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
647RETURN_STATUS
648EFIAPI
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
676RETURN_STATUS
677EFIAPI
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
705RETURN_STATUS
706EFIAPI
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
740RETURN_STATUS
741EFIAPI
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
776RETURN_STATUS
777EFIAPI
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
805VOID
806EFIAPI
808 IN CONST GUID *Guid OPTIONAL,
809 IN UINTN TokenNumber,
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
836VOID
837EFIAPI
839 IN CONST GUID *Guid OPTIONAL,
840 IN UINTN TokenNumber,
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
873UINTN
874EFIAPI
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
901GUID *
902EFIAPI
904 IN CONST GUID *TokenSpaceGuid
905 )
906{
907 GetPiPcdProtocol ()->GetNextTokenSpace (&TokenSpaceGuid);
908
909 return (GUID *)TokenSpaceGuid;
910}
911
935VOID *
936EFIAPI
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
986RETURN_STATUS
987EFIAPI
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;
1007 }
1008
1009 CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1010
1011 return RETURN_SUCCESS;
1012}
1013
1039VOID *
1040EFIAPI
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
1095RETURN_STATUS
1096EFIAPI
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;
1118 }
1119
1120 CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1121 *SizeOfPatchVariable = *SizeOfBuffer;
1122
1123 return RETURN_SUCCESS;
1124}
1125
1138VOID
1139EFIAPI
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
1164VOID
1165EFIAPI
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
1185UINTN
1186EFIAPI
1188 VOID
1189 )
1190{
1191 return GetPiPcdInfoProtocolPointer ()->GetSku ();
1192}
UINT64 UINTN
#define MAX_ADDRESS
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS EFIAPI NotificationFunction(IN EFI_KEY_DATA *KeyData)
Definition: DriverSample.c:117
VOID EFIAPI LibPcdCallbackOnSet(IN CONST GUID *Guid OPTIONAL, IN UINTN TokenNumber, IN PCD_CALLBACK NotificationFunction)
Definition: DxePcdLib.c:807
RETURN_STATUS EFIAPI LibPcdSetEx16S(IN CONST GUID *Guid, IN UINTN TokenNumber, IN UINT16 Value)
Definition: DxePcdLib.c:649
RETURN_STATUS EFIAPI LibPcdSet8S(IN UINTN TokenNumber, IN UINT8 Value)
Definition: DxePcdLib.c:467
RETURN_STATUS EFIAPI LibPatchPcdSetPtrS(OUT VOID *PatchVariable, IN UINTN MaximumDatumSize, IN OUT UINTN *SizeOfBuffer, IN CONST VOID *Buffer)
Definition: DxePcdLib.c:988
UINTN EFIAPI LibPcdGetNextToken(IN CONST GUID *Guid OPTIONAL, IN UINTN TokenNumber)
Definition: DxePcdLib.c:875
UINT32 EFIAPI LibPcdGetEx32(IN CONST GUID *Guid, IN UINTN TokenNumber)
Definition: DxePcdLib.c:339
UINT8 EFIAPI LibPcdGetEx8(IN CONST GUID *Guid, IN UINTN TokenNumber)
Definition: DxePcdLib.c:290
VOID EFIAPI LibPcdGetInfoEx(IN CONST GUID *Guid, IN UINTN TokenNumber, OUT PCD_INFO *PcdInfo)
Definition: DxePcdLib.c:1166
RETURN_STATUS EFIAPI LibPatchPcdSetPtrAndSizeS(OUT VOID *PatchVariable, OUT UINTN *SizeOfPatchVariable, IN UINTN MaximumDatumSize, IN OUT UINTN *SizeOfBuffer, IN CONST VOID *Buffer)
Definition: DxePcdLib.c:1097
UINT16 EFIAPI LibPcdGet16(IN UINTN TokenNumber)
Definition: DxePcdLib.c:174
UINT64 EFIAPI LibPcdGetEx64(IN CONST GUID *Guid, IN UINTN TokenNumber)
Definition: DxePcdLib.c:365
UINT16 EFIAPI LibPcdGetEx16(IN CONST GUID *Guid, IN UINTN TokenNumber)
Definition: DxePcdLib.c:316
RETURN_STATUS EFIAPI LibPcdSetExPtrS(IN CONST GUID *Guid, IN UINTN TokenNumber, IN OUT UINTN *SizeOfBuffer, IN VOID *Buffer)
Definition: DxePcdLib.c:742
VOID EFIAPI LibPcdGetInfo(IN UINTN TokenNumber, OUT PCD_INFO *PcdInfo)
Definition: DxePcdLib.c:1140
UINTN EFIAPI LibPcdGetSize(IN UINTN TokenNumber)
Definition: DxePcdLib.c:267
RETURN_STATUS EFIAPI LibPcdSetPtrS(IN UINTN TokenNumber, IN OUT UINTN *SizeOfBuffer, IN CONST VOID *Buffer)
Definition: DxePcdLib.c:565
UINT64 EFIAPI LibPcdGet64(IN UINTN TokenNumber)
Definition: DxePcdLib.c:212
GET_PCD_INFO_PROTOCOL * GetPcdInfoProtocolPointer(VOID)
Definition: DxePcdLib.c:106
UINTN EFIAPI LibPcdGetSku(VOID)
Definition: DxePcdLib.c:1187
GUID *EFIAPI LibPcdGetNextTokenSpace(IN CONST GUID *TokenSpaceGuid)
Definition: DxePcdLib.c:903
RETURN_STATUS EFIAPI LibPcdSetEx8S(IN CONST GUID *Guid, IN UINTN TokenNumber, IN UINT8 Value)
Definition: DxePcdLib.c:620
RETURN_STATUS EFIAPI LibPcdSetExBoolS(IN CONST GUID *Guid, IN UINTN TokenNumber, IN BOOLEAN Value)
Definition: DxePcdLib.c:778
RETURN_STATUS EFIAPI LibPcdSetEx64S(IN CONST GUID *Guid, IN UINTN TokenNumber, IN UINT64 Value)
Definition: DxePcdLib.c:707
VOID *EFIAPI LibPatchPcdSetPtrAndSize(OUT VOID *PatchVariable, OUT UINTN *SizeOfPatchVariable, IN UINTN MaximumDatumSize, IN OUT UINTN *SizeOfBuffer, IN CONST VOID *Buffer)
Definition: DxePcdLib.c:1041
UINT8 EFIAPI LibPcdGet8(IN UINTN TokenNumber)
Definition: DxePcdLib.c:155
EFI_GET_PCD_INFO_PROTOCOL * GetPiPcdInfoProtocolPointer(VOID)
Definition: DxePcdLib.c:85
VOID *EFIAPI LibPatchPcdSetPtr(OUT VOID *PatchVariable, IN UINTN MaximumDatumSize, IN OUT UINTN *SizeOfBuffer, IN CONST VOID *Buffer)
Definition: DxePcdLib.c:937
RETURN_STATUS EFIAPI LibPcdSet32S(IN UINTN TokenNumber, IN UINT32 Value)
Definition: DxePcdLib.c:511
RETURN_STATUS EFIAPI LibPcdSet16S(IN UINTN TokenNumber, IN UINT16 Value)
Definition: DxePcdLib.c:489
VOID EFIAPI LibPcdCancelCallback(IN CONST GUID *Guid OPTIONAL, IN UINTN TokenNumber, IN PCD_CALLBACK NotificationFunction)
Definition: DxePcdLib.c:838
UINT32 EFIAPI LibPcdGet32(IN UINTN TokenNumber)
Definition: DxePcdLib.c:193
RETURN_STATUS EFIAPI LibPcdSetEx32S(IN CONST GUID *Guid, IN UINTN TokenNumber, IN UINT32 Value)
Definition: DxePcdLib.c:678
VOID *EFIAPI LibPcdGetExPtr(IN CONST GUID *Guid, IN UINTN TokenNumber)
Definition: DxePcdLib.c:391
VOID *EFIAPI LibPcdGetPtr(IN UINTN TokenNumber)
Definition: DxePcdLib.c:231
PCD_PROTOCOL *EFIAPI GetPcdProtocol(VOID)
Definition: DxePcdLib.c:60
RETURN_STATUS EFIAPI LibPcdSet64S(IN UINTN TokenNumber, IN UINT64 Value)
Definition: DxePcdLib.c:533
UINTN EFIAPI LibPcdGetExSize(IN CONST GUID *Guid, IN UINTN TokenNumber)
Definition: DxePcdLib.c:443
UINTN EFIAPI LibPcdSetSku(IN UINTN SkuId)
Definition: DxePcdLib.c:134
EFI_PCD_PROTOCOL *EFIAPI GetPiPcdProtocol(VOID)
Definition: DxePcdLib.c:34
BOOLEAN EFIAPI LibPcdGetBool(IN UINTN TokenNumber)
Definition: DxePcdLib.c:250
RETURN_STATUS EFIAPI LibPcdSetBoolS(IN UINTN TokenNumber, IN BOOLEAN Value)
Definition: DxePcdLib.c:594
BOOLEAN EFIAPI LibPcdGetExBool(IN CONST GUID *Guid, IN UINTN TokenNumber)
Definition: DxePcdLib.c:417
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define RETURN_INVALID_PARAMETER
Definition: Base.h:1076
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
VOID(EFIAPI * PCD_CALLBACK)(IN CONST GUID *CallBackGuid OPTIONAL, IN UINTN CallBackToken, IN OUT VOID *TokenData, IN UINTN TokenDataSize)
Definition: PcdLib.h:1363
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_BOOT_SERVICES * gBS
EFI_GET_PCD_INFO_PROTOCOL_GET_SKU GetSku
Definition: PiPcdInfo.h:73
EFI_GET_PCD_INFO_PROTOCOL_GET_INFO GetInfo
Definition: PiPcdInfo.h:69
GET_PCD_INFO_PROTOCOL_GET_INFO GetInfo
Definition: PcdInfo.h:93
Definition: Base.h:213