1 /** @file
2 Implementation of PcdLib class library for DXE phase.
3 
4 Copyright (c) 2006 - 2015, 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
GetPiPcdProtocol(VOID)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
GetPcdProtocol(VOID)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 *
GetPiPcdInfoProtocolPointer(VOID)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 *
GetPcdInfoProtocolPointer(VOID)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
LibPcdSetSku(IN UINTN SkuId)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
LibPcdGet8(IN UINTN TokenNumber)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
LibPcdGet16(IN UINTN TokenNumber)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
LibPcdGet32(IN UINTN TokenNumber)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
LibPcdGet64(IN UINTN TokenNumber)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
LibPcdGetPtr(IN UINTN TokenNumber)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
LibPcdGetBool(IN UINTN TokenNumber)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
LibPcdGetSize(IN UINTN TokenNumber)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
LibPcdGetEx8(IN CONST GUID * Guid,IN UINTN TokenNumber)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
LibPcdGetEx16(IN CONST GUID * Guid,IN UINTN TokenNumber)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
LibPcdGetEx32(IN CONST GUID * Guid,IN UINTN TokenNumber)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
LibPcdGetEx64(IN CONST GUID * Guid,IN UINTN TokenNumber)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
LibPcdGetExPtr(IN CONST GUID * Guid,IN UINTN TokenNumber)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
LibPcdGetExBool(IN CONST GUID * Guid,IN UINTN TokenNumber)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
LibPcdGetExSize(IN CONST GUID * Guid,IN UINTN TokenNumber)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 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
488 /**
489   This function provides a means by which to set a value for a given PCD token.
490 
491   Sets the 8-bit value for the token specified by TokenNumber
492   to the value specified by Value.  Value is returned.
493 
494   @param[in]  TokenNumber   The PCD token number to set a current value for.
495   @param[in]  Value         The 8-bit value to set.
496 
497   @return Return the value that was set.
498 
499 **/
500 UINT8
501 EFIAPI
LibPcdSet8(IN UINTN TokenNumber,IN UINT8 Value)502 LibPcdSet8 (
503   IN UINTN             TokenNumber,
504   IN UINT8             Value
505   )
506 {
507   GetPcdProtocol()->Set8 (TokenNumber, Value);
508 
509   return Value;
510 }
511 
512 
513 
514 /**
515   This function provides a means by which to set a value for a given PCD token.
516 
517   Sets the 16-bit value for the token specified by TokenNumber
518   to the value specified by Value.  Value is returned.
519 
520   @param[in]  TokenNumber   The PCD token number to set a current value for.
521   @param[in]  Value         The 16-bit value to set.
522 
523   @return Return the value that was set.
524 
525 **/
526 UINT16
527 EFIAPI
LibPcdSet16(IN UINTN TokenNumber,IN UINT16 Value)528 LibPcdSet16 (
529   IN UINTN             TokenNumber,
530   IN UINT16            Value
531   )
532 {
533   GetPcdProtocol()->Set16 (TokenNumber, Value);
534 
535   return Value;
536 }
537 
538 
539 
540 /**
541   This function provides a means by which to set a value for a given PCD token.
542 
543   Sets the 32-bit value for the token specified by TokenNumber
544   to the value specified by Value.  Value is returned.
545 
546   @param[in]  TokenNumber   The PCD token number to set a current value for.
547   @param[in]  Value         The 32-bit value to set.
548 
549   @return Return the value that was set.
550 
551 **/
552 UINT32
553 EFIAPI
LibPcdSet32(IN UINTN TokenNumber,IN UINT32 Value)554 LibPcdSet32 (
555   IN UINTN             TokenNumber,
556   IN UINT32            Value
557   )
558 {
559   GetPcdProtocol()->Set32 (TokenNumber, Value);
560 
561   return Value;
562 }
563 
564 
565 
566 /**
567   This function provides a means by which to set a value for a given PCD token.
568 
569   Sets the 64-bit value for the token specified by TokenNumber
570   to the value specified by Value.  Value is returned.
571 
572   @param[in]  TokenNumber   The PCD token number to set a current value for.
573   @param[in]  Value         The 64-bit value to set.
574 
575   @return Return the value that was set.
576 
577 **/
578 UINT64
579 EFIAPI
LibPcdSet64(IN UINTN TokenNumber,IN UINT64 Value)580 LibPcdSet64 (
581   IN UINTN             TokenNumber,
582   IN UINT64            Value
583   )
584 {
585   GetPcdProtocol()->Set64 (TokenNumber, Value);
586 
587   return Value;
588 }
589 
590 
591 
592 /**
593   This function provides a means by which to set a value for a given PCD token.
594 
595   Sets a buffer for the token specified by TokenNumber to the value
596   specified by Buffer and SizeOfBuffer.  Buffer is returned.
597   If SizeOfBuffer is greater than the maximum size support by TokenNumber,
598   then set SizeOfBuffer to the maximum size supported by TokenNumber and
599   return NULL to indicate that the set operation was not actually performed.
600 
601   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
602   maximum size supported by TokenName and NULL must be returned.
603 
604   If SizeOfBuffer is NULL, then ASSERT().
605   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
606 
607   @param[in]      TokenNumber   The PCD token number to set a current value for.
608   @param[in, out] SizeOfBuffer  The size, in bytes, of Buffer.
609   @param[in]      Buffer        A pointer to the buffer to set.
610 
611   @return Return the pointer for the buffer been set.
612 
613 **/
614 VOID *
615 EFIAPI
LibPcdSetPtr(IN UINTN TokenNumber,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)616 LibPcdSetPtr (
617   IN        UINTN             TokenNumber,
618   IN OUT    UINTN             *SizeOfBuffer,
619   IN CONST  VOID              *Buffer
620   )
621 {
622   EFI_STATUS Status;
623   UINTN      InputSizeOfBuffer;
624 
625   ASSERT (SizeOfBuffer != NULL);
626 
627   if (*SizeOfBuffer > 0) {
628     ASSERT (Buffer != NULL);
629   }
630 
631   InputSizeOfBuffer = *SizeOfBuffer;
632   Status = GetPcdProtocol()->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);
633   if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {
634     return NULL;
635   }
636 
637   return (VOID *)Buffer;
638 }
639 
640 
641 
642 /**
643   This function provides a means by which to set a value for a given PCD token.
644 
645   Sets the Boolean value for the token specified by TokenNumber
646   to the value specified by Value.  Value is returned.
647 
648   @param[in]  TokenNumber   The PCD token number to set a current value for.
649   @param[in]  Value         The boolean value to set.
650 
651   @return Return the value that was set.
652 
653 **/
654 BOOLEAN
655 EFIAPI
LibPcdSetBool(IN UINTN TokenNumber,IN BOOLEAN Value)656 LibPcdSetBool (
657   IN UINTN             TokenNumber,
658   IN BOOLEAN           Value
659   )
660 {
661   GetPcdProtocol()->SetBool (TokenNumber, Value);
662 
663   return Value;
664 }
665 
666 
667 
668 /**
669   This function provides a means by which to set a value for a given PCD token.
670 
671   Sets the 8-bit value for the token specified by TokenNumber and
672   Guid to the value specified by Value. Value is returned.
673 
674   If Guid is NULL, then ASSERT().
675 
676   @param[in]  Guid          The pointer to a 128-bit unique value that
677                             designates which namespace to set a value from.
678   @param[in]  TokenNumber   The PCD token number to set a current value for.
679   @param[in]  Value         The 8-bit value to set.
680 
681   @return Return the value that was set.
682 
683 **/
684 UINT8
685 EFIAPI
LibPcdSetEx8(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT8 Value)686 LibPcdSetEx8 (
687   IN CONST GUID        *Guid,
688   IN UINTN             TokenNumber,
689   IN UINT8             Value
690   )
691 {
692   ASSERT (Guid != NULL);
693 
694   GetPiPcdProtocol()->Set8 (Guid, TokenNumber, Value);
695 
696   return Value;
697 }
698 
699 
700 
701 /**
702   This function provides a means by which to set a value for a given PCD token.
703 
704   Sets the 16-bit value for the token specified by TokenNumber and
705   Guid to the value specified by Value. Value is returned.
706 
707   If Guid is NULL, then ASSERT().
708 
709   @param[in]  Guid          The pointer to a 128-bit unique value that
710                             designates which namespace to set a value from.
711   @param[in]  TokenNumber   The PCD token number to set a current value for.
712   @param[in]  Value         The 16-bit value to set.
713 
714   @return Return the value that was set.
715 
716 **/
717 UINT16
718 EFIAPI
LibPcdSetEx16(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT16 Value)719 LibPcdSetEx16 (
720   IN CONST GUID        *Guid,
721   IN UINTN             TokenNumber,
722   IN UINT16            Value
723   )
724 {
725   ASSERT (Guid != NULL);
726 
727   GetPiPcdProtocol()->Set16 (Guid, TokenNumber, Value);
728 
729   return Value;
730 }
731 
732 
733 
734 /**
735   This function provides a means by which to set a value for a given PCD token.
736 
737   Sets the 32-bit value for the token specified by TokenNumber and
738   Guid to the value specified by Value. Value is returned.
739 
740   If Guid is NULL, then ASSERT().
741 
742   @param[in]  Guid          The pointer to a 128-bit unique value that
743                             designates which namespace to set a value from.
744   @param[in]  TokenNumber   The PCD token number to set a current value for.
745   @param[in]  Value         The 32-bit value to set.
746 
747   @return Return the value that was set.
748 
749 **/
750 UINT32
751 EFIAPI
LibPcdSetEx32(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT32 Value)752 LibPcdSetEx32 (
753   IN CONST GUID        *Guid,
754   IN UINTN             TokenNumber,
755   IN UINT32            Value
756   )
757 {
758   ASSERT (Guid != NULL);
759 
760   GetPiPcdProtocol()->Set32 (Guid, TokenNumber, Value);
761 
762   return Value;
763 }
764 
765 
766 
767 /**
768   This function provides a means by which to set a value for a given PCD token.
769 
770   Sets the 64-bit value for the token specified by TokenNumber and
771   Guid to the value specified by Value. Value is returned.
772 
773   If Guid is NULL, then ASSERT().
774 
775   @param[in]  Guid          The pointer to a 128-bit unique value that
776                             designates which namespace to set a value from.
777   @param[in]  TokenNumber   The PCD token number to set a current value for.
778   @param[in]  Value         The 64-bit value to set.
779 
780   @return Return the value that was set.
781 
782 **/
783 UINT64
784 EFIAPI
LibPcdSetEx64(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT64 Value)785 LibPcdSetEx64 (
786   IN CONST GUID        *Guid,
787   IN UINTN             TokenNumber,
788   IN UINT64            Value
789   )
790 {
791   ASSERT (Guid != NULL);
792 
793   GetPiPcdProtocol()->Set64 (Guid, TokenNumber, Value);
794 
795   return Value;
796 }
797 
798 
799 
800 /**
801   This function provides a means by which to set a value for a given PCD token.
802 
803   Sets a buffer for the token specified by TokenNumber to the value specified by
804   Buffer and SizeOfBuffer.  Buffer is returned.  If SizeOfBuffer is greater than
805   the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
806   supported by TokenNumber and return NULL to indicate that the set operation
807   was not actually performed.
808 
809   If Guid is NULL, then ASSERT().
810   If SizeOfBuffer is NULL, then ASSERT().
811   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
812 
813   @param[in]  Guid              The pointer to a 128-bit unique value that
814                                 designates which namespace to set a value from.
815   @param[in]  TokenNumber       The PCD token number to set a current value for.
816   @param[in, out] SizeOfBuffer  The size, in bytes, of Buffer.
817   @param[in]  Buffer            A pointer to the buffer to set.
818 
819   @return Return the pointer to the buffer been set.
820 
821 **/
822 VOID *
823 EFIAPI
LibPcdSetExPtr(IN CONST GUID * Guid,IN UINTN TokenNumber,IN OUT UINTN * SizeOfBuffer,IN VOID * Buffer)824 LibPcdSetExPtr (
825   IN      CONST GUID        *Guid,
826   IN      UINTN             TokenNumber,
827   IN OUT  UINTN             *SizeOfBuffer,
828   IN      VOID              *Buffer
829   )
830 {
831   EFI_STATUS  Status;
832   UINTN       InputSizeOfBuffer;
833 
834   ASSERT (Guid != NULL);
835 
836   ASSERT (SizeOfBuffer != NULL);
837 
838   if (*SizeOfBuffer > 0) {
839     ASSERT (Buffer != NULL);
840   }
841 
842   InputSizeOfBuffer = *SizeOfBuffer;
843   Status = GetPiPcdProtocol()->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);
844   if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {
845     return NULL;
846   }
847 
848   return Buffer;
849 }
850 
851 
852 
853 /**
854   This function provides a means by which to set a value for a given PCD token.
855 
856   Sets the Boolean value for the token specified by TokenNumber and
857   Guid to the value specified by Value. Value is returned.
858 
859   If Guid is NULL, then ASSERT().
860 
861   @param[in]  Guid          The pointer to a 128-bit unique value that
862                             designates which namespace to set a value from.
863   @param[in]  TokenNumber   The PCD token number to set a current value for.
864   @param[in]  Value         The Boolean value to set.
865 
866   @return Return the value that was set.
867 
868 **/
869 BOOLEAN
870 EFIAPI
LibPcdSetExBool(IN CONST GUID * Guid,IN UINTN TokenNumber,IN BOOLEAN Value)871 LibPcdSetExBool (
872   IN CONST GUID        *Guid,
873   IN UINTN             TokenNumber,
874   IN BOOLEAN           Value
875   )
876 {
877   ASSERT (Guid != NULL);
878 
879   GetPiPcdProtocol()->SetBool (Guid, TokenNumber, Value);
880 
881   return Value;
882 }
883 #endif
884 
885 /**
886   This function provides a means by which to set a value for a given PCD token.
887 
888   Sets the 8-bit value for the token specified by TokenNumber
889   to the value specified by Value.
890 
891   @param[in] TokenNumber    The PCD token number to set a current value for.
892   @param[in] Value          The 8-bit value to set.
893 
894   @return The status of the set operation.
895 
896 **/
897 RETURN_STATUS
898 EFIAPI
LibPcdSet8S(IN UINTN TokenNumber,IN UINT8 Value)899 LibPcdSet8S (
900   IN UINTN          TokenNumber,
901   IN UINT8          Value
902   )
903 {
904   return GetPcdProtocol()->Set8 (TokenNumber, Value);
905 }
906 
907 /**
908   This function provides a means by which to set a value for a given PCD token.
909 
910   Sets the 16-bit value for the token specified by TokenNumber
911   to the value specified by Value.
912 
913   @param[in] TokenNumber    The PCD token number to set a current value for.
914   @param[in] Value          The 16-bit value to set.
915 
916   @return The status of the set operation.
917 
918 **/
919 RETURN_STATUS
920 EFIAPI
LibPcdSet16S(IN UINTN TokenNumber,IN UINT16 Value)921 LibPcdSet16S (
922   IN UINTN          TokenNumber,
923   IN UINT16         Value
924   )
925 {
926   return GetPcdProtocol()->Set16 (TokenNumber, Value);
927 }
928 
929 /**
930   This function provides a means by which to set a value for a given PCD token.
931 
932   Sets the 32-bit value for the token specified by TokenNumber
933   to the value specified by Value.
934 
935   @param[in] TokenNumber    The PCD token number to set a current value for.
936   @param[in] Value          The 32-bit value to set.
937 
938   @return The status of the set operation.
939 
940 **/
941 RETURN_STATUS
942 EFIAPI
LibPcdSet32S(IN UINTN TokenNumber,IN UINT32 Value)943 LibPcdSet32S (
944   IN UINTN          TokenNumber,
945   IN UINT32         Value
946   )
947 {
948   return GetPcdProtocol()->Set32 (TokenNumber, Value);
949 }
950 
951 /**
952   This function provides a means by which to set a value for a given PCD token.
953 
954   Sets the 64-bit value for the token specified by TokenNumber
955   to the value specified by Value.
956 
957   @param[in] TokenNumber    The PCD token number to set a current value for.
958   @param[in] Value          The 64-bit value to set.
959 
960   @return The status of the set operation.
961 
962 **/
963 RETURN_STATUS
964 EFIAPI
LibPcdSet64S(IN UINTN TokenNumber,IN UINT64 Value)965 LibPcdSet64S (
966   IN UINTN          TokenNumber,
967   IN UINT64         Value
968   )
969 {
970   return GetPcdProtocol()->Set64 (TokenNumber, Value);
971 }
972 
973 /**
974   This function provides a means by which to set a value for a given PCD token.
975 
976   Sets a buffer for the token specified by TokenNumber to the value specified
977   by Buffer and SizeOfBuffer. If SizeOfBuffer is greater than the maximum size
978   support by TokenNumber, then set SizeOfBuffer to the maximum size supported by
979   TokenNumber and return EFI_INVALID_PARAMETER to indicate that the set operation
980   was not actually performed.
981 
982   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
983   maximum size supported by TokenName and EFI_INVALID_PARAMETER must be returned.
984 
985   If SizeOfBuffer is NULL, then ASSERT().
986   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
987 
988   @param[in]      TokenNumber   The PCD token number to set a current value for.
989   @param[in, out] SizeOfBuffer  The size, in bytes, of Buffer.
990   @param[in]      Buffer        A pointer to the buffer to set.
991 
992   @return The status of the set operation.
993 
994 **/
995 RETURN_STATUS
996 EFIAPI
LibPcdSetPtrS(IN UINTN TokenNumber,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)997 LibPcdSetPtrS (
998   IN       UINTN    TokenNumber,
999   IN OUT   UINTN    *SizeOfBuffer,
1000   IN CONST VOID     *Buffer
1001   )
1002 {
1003   ASSERT (SizeOfBuffer != NULL);
1004 
1005   if (*SizeOfBuffer > 0) {
1006     ASSERT (Buffer != NULL);
1007   }
1008 
1009   return GetPcdProtocol()->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);
1010 }
1011 
1012 /**
1013   This function provides a means by which to set a value for a given PCD token.
1014 
1015   Sets the boolean value for the token specified by TokenNumber
1016   to the value specified by Value.
1017 
1018   @param[in] TokenNumber    The PCD token number to set a current value for.
1019   @param[in] Value          The boolean value to set.
1020 
1021   @return The status of the set operation.
1022 
1023 **/
1024 RETURN_STATUS
1025 EFIAPI
LibPcdSetBoolS(IN UINTN TokenNumber,IN BOOLEAN Value)1026 LibPcdSetBoolS (
1027   IN UINTN          TokenNumber,
1028   IN BOOLEAN        Value
1029   )
1030 {
1031   return GetPcdProtocol()->SetBool (TokenNumber, Value);
1032 }
1033 
1034 /**
1035   This function provides a means by which to set a value for a given PCD token.
1036 
1037   Sets the 8-bit value for the token specified by TokenNumber
1038   to the value specified by Value.
1039 
1040   If Guid is NULL, then ASSERT().
1041 
1042   @param[in] Guid           The pointer to a 128-bit unique value that
1043                             designates which namespace to set a value from.
1044   @param[in] TokenNumber    The PCD token number to set a current value for.
1045   @param[in] Value          The 8-bit value to set.
1046 
1047   @return The status of the set operation.
1048 
1049 **/
1050 RETURN_STATUS
1051 EFIAPI
LibPcdSetEx8S(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT8 Value)1052 LibPcdSetEx8S (
1053   IN CONST GUID     *Guid,
1054   IN UINTN          TokenNumber,
1055   IN UINT8          Value
1056   )
1057 {
1058   ASSERT (Guid != NULL);
1059 
1060   return GetPiPcdProtocol()->Set8 (Guid, TokenNumber, Value);
1061 }
1062 
1063 /**
1064   This function provides a means by which to set a value for a given PCD token.
1065 
1066   Sets the 16-bit value for the token specified by TokenNumber
1067   to the value specified by Value.
1068 
1069   If Guid is NULL, then ASSERT().
1070 
1071   @param[in] Guid           The pointer to a 128-bit unique value that
1072                             designates which namespace to set a value from.
1073   @param[in] TokenNumber    The PCD token number to set a current value for.
1074   @param[in] Value          The 16-bit value to set.
1075 
1076   @return The status of the set operation.
1077 
1078 **/
1079 RETURN_STATUS
1080 EFIAPI
LibPcdSetEx16S(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT16 Value)1081 LibPcdSetEx16S (
1082   IN CONST GUID     *Guid,
1083   IN UINTN          TokenNumber,
1084   IN UINT16         Value
1085   )
1086 {
1087   ASSERT (Guid != NULL);
1088 
1089   return GetPiPcdProtocol()->Set16 (Guid, TokenNumber, Value);
1090 }
1091 
1092 /**
1093   This function provides a means by which to set a value for a given PCD token.
1094 
1095   Sets the 32-bit value for the token specified by TokenNumber
1096   to the value specified by Value.
1097 
1098   If Guid is NULL, then ASSERT().
1099 
1100   @param[in] Guid           The pointer to a 128-bit unique value that
1101                             designates which namespace to set a value from.
1102   @param[in] TokenNumber    The PCD token number to set a current value for.
1103   @param[in] Value          The 32-bit value to set.
1104 
1105   @return The status of the set operation.
1106 
1107 **/
1108 RETURN_STATUS
1109 EFIAPI
LibPcdSetEx32S(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT32 Value)1110 LibPcdSetEx32S (
1111   IN CONST GUID     *Guid,
1112   IN UINTN          TokenNumber,
1113   IN UINT32         Value
1114   )
1115 {
1116   ASSERT (Guid != NULL);
1117 
1118   return GetPiPcdProtocol()->Set32 (Guid, TokenNumber, Value);
1119 }
1120 
1121 /**
1122   This function provides a means by which to set a value for a given PCD token.
1123 
1124   Sets the 64-bit value for the token specified by TokenNumber
1125   to the value specified by Value.
1126 
1127   If Guid is NULL, then ASSERT().
1128 
1129   @param[in] Guid           The pointer to a 128-bit unique value that
1130                             designates which namespace to set a value from.
1131   @param[in] TokenNumber    The PCD token number to set a current value for.
1132   @param[in] Value          The 64-bit value to set.
1133 
1134   @return The status of the set operation.
1135 
1136 **/
1137 RETURN_STATUS
1138 EFIAPI
LibPcdSetEx64S(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT64 Value)1139 LibPcdSetEx64S (
1140   IN CONST GUID     *Guid,
1141   IN UINTN          TokenNumber,
1142   IN UINT64         Value
1143   )
1144 {
1145   ASSERT (Guid != NULL);
1146 
1147   return GetPiPcdProtocol()->Set64 (Guid, TokenNumber, Value);
1148 }
1149 
1150 /**
1151   This function provides a means by which to set a value for a given PCD token.
1152 
1153   Sets a buffer for the token specified by TokenNumber to the value specified by
1154   Buffer and SizeOfBuffer. If SizeOfBuffer is greater than the maximum size
1155   support by TokenNumber, then set SizeOfBuffer to the maximum size supported by
1156   TokenNumber and return EFI_INVALID_PARAMETER to indicate that the set operation
1157   was not actually performed.
1158 
1159   If Guid is NULL, then ASSERT().
1160   If SizeOfBuffer is NULL, then ASSERT().
1161   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1162 
1163   @param[in]      Guid          Pointer to a 128-bit unique value that
1164                                 designates which namespace to set a value from.
1165   @param[in]      TokenNumber   The PCD token number to set a current value for.
1166   @param[in, out] SizeOfBuffer  The size, in bytes, of Buffer.
1167   @param[in]      Buffer        A pointer to the buffer to set.
1168 
1169   @return The status of the set operation.
1170 
1171 **/
1172 RETURN_STATUS
1173 EFIAPI
LibPcdSetExPtrS(IN CONST GUID * Guid,IN UINTN TokenNumber,IN OUT UINTN * SizeOfBuffer,IN VOID * Buffer)1174 LibPcdSetExPtrS (
1175   IN CONST GUID     *Guid,
1176   IN       UINTN    TokenNumber,
1177   IN OUT   UINTN    *SizeOfBuffer,
1178   IN       VOID     *Buffer
1179   )
1180 {
1181   ASSERT (Guid != NULL);
1182 
1183   ASSERT (SizeOfBuffer != NULL);
1184 
1185   if (*SizeOfBuffer > 0) {
1186     ASSERT (Buffer != NULL);
1187   }
1188 
1189   return GetPiPcdProtocol()->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);
1190 }
1191 
1192 /**
1193   This function provides a means by which to set a value for a given PCD token.
1194 
1195   Sets the boolean value for the token specified by TokenNumber
1196   to the value specified by Value.
1197 
1198   If Guid is NULL, then ASSERT().
1199 
1200   @param[in] Guid           The pointer to a 128-bit unique value that
1201                             designates which namespace to set a value from.
1202   @param[in] TokenNumber    The PCD token number to set a current value for.
1203   @param[in] Value          The boolean value to set.
1204 
1205   @return The status of the set operation.
1206 
1207 **/
1208 RETURN_STATUS
1209 EFIAPI
LibPcdSetExBoolS(IN CONST GUID * Guid,IN UINTN TokenNumber,IN BOOLEAN Value)1210 LibPcdSetExBoolS (
1211   IN CONST GUID     *Guid,
1212   IN UINTN          TokenNumber,
1213   IN BOOLEAN        Value
1214   )
1215 {
1216   ASSERT (Guid != NULL);
1217 
1218   return GetPiPcdProtocol()->SetBool (Guid, TokenNumber, Value);
1219 }
1220 
1221 /**
1222   Set up a notification function that is called when a specified token is set.
1223 
1224   When the token specified by TokenNumber and Guid is set,
1225   then notification function specified by NotificationFunction is called.
1226   If Guid is NULL, then the default token space is used.
1227   If NotificationFunction is NULL, then ASSERT().
1228 
1229   @param[in]  Guid                  The pointer to a 128-bit unique value that designates which
1230                                     namespace to set a value from.  If NULL, then the default
1231                                     token space is used.
1232   @param[in]  TokenNumber           The PCD token number to monitor.
1233   @param[in]  NotificationFunction  The function to call when the token
1234                                     specified by Guid and TokenNumber is set.
1235 
1236 **/
1237 VOID
1238 EFIAPI
LibPcdCallbackOnSet(IN CONST GUID * Guid,OPTIONAL IN UINTN TokenNumber,IN PCD_CALLBACK NotificationFunction)1239 LibPcdCallbackOnSet (
1240   IN CONST GUID               *Guid,       OPTIONAL
1241   IN UINTN                    TokenNumber,
1242   IN PCD_CALLBACK             NotificationFunction
1243   )
1244 {
1245   EFI_STATUS Status;
1246 
1247   ASSERT (NotificationFunction != NULL);
1248 
1249   Status = GetPiPcdProtocol()->CallbackOnSet (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);
1250   ASSERT_EFI_ERROR (Status);
1251 
1252   return;
1253 }
1254 
1255 
1256 
1257 /**
1258   Disable a notification function that was established with LibPcdCallbackonSet().
1259 
1260   Disable a notification function that was previously established with LibPcdCallbackOnSet().
1261   If NotificationFunction is NULL, then ASSERT().
1262   If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber,
1263   and NotificationFunction, then ASSERT().
1264 
1265   @param[in]  Guid                 Specify the GUID token space.
1266   @param[in]  TokenNumber          Specify the token number.
1267   @param[in]  NotificationFunction The callback function to be unregistered.
1268 
1269 **/
1270 VOID
1271 EFIAPI
LibPcdCancelCallback(IN CONST GUID * Guid,OPTIONAL IN UINTN TokenNumber,IN PCD_CALLBACK NotificationFunction)1272 LibPcdCancelCallback (
1273   IN CONST GUID               *Guid,       OPTIONAL
1274   IN UINTN                    TokenNumber,
1275   IN PCD_CALLBACK             NotificationFunction
1276   )
1277 {
1278   EFI_STATUS Status;
1279 
1280   ASSERT (NotificationFunction != NULL);
1281 
1282   Status = GetPiPcdProtocol()->CancelCallback (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);
1283   ASSERT_EFI_ERROR (Status);
1284 
1285   return;
1286 }
1287 
1288 
1289 
1290 /**
1291   Retrieves the next token in a token space.
1292 
1293   Retrieves the next PCD token number from the token space specified by Guid.
1294   If Guid is NULL, then the default token space is used.  If TokenNumber is 0,
1295   then the first token number is returned.  Otherwise, the token number that
1296   follows TokenNumber in the token space is returned.  If TokenNumber is the last
1297   token number in the token space, then 0 is returned.
1298 
1299   If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().
1300 
1301   @param[in]  Guid        The pointer to a 128-bit unique value that designates which namespace
1302                           to set a value from.  If NULL, then the default token space is used.
1303   @param[in]  TokenNumber The previous PCD token number.  If 0, then retrieves the first PCD
1304                           token number.
1305 
1306   @return The next valid token number.
1307 
1308 **/
1309 UINTN
1310 EFIAPI
LibPcdGetNextToken(IN CONST GUID * Guid,OPTIONAL IN UINTN TokenNumber)1311 LibPcdGetNextToken (
1312   IN CONST GUID               *Guid,       OPTIONAL
1313   IN UINTN                    TokenNumber
1314   )
1315 {
1316   EFI_STATUS    Status;
1317 
1318   Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);
1319   ASSERT (!EFI_ERROR (Status) || TokenNumber == 0);
1320 
1321   return TokenNumber;
1322 }
1323 
1324 
1325 
1326 /**
1327   Used to retrieve the list of available PCD token space GUIDs.
1328 
1329   Returns the PCD token space GUID that follows TokenSpaceGuid in the list of token spaces
1330   in the platform.
1331   If TokenSpaceGuid is NULL, then a pointer to the first PCD token spaces returned.
1332   If TokenSpaceGuid is the last PCD token space GUID in the list, then NULL is returned.
1333 
1334   @param  TokenSpaceGuid  The pointer to the a PCD token space GUID.
1335 
1336   @return The next valid token namespace.
1337 
1338 **/
1339 GUID *
1340 EFIAPI
LibPcdGetNextTokenSpace(IN CONST GUID * TokenSpaceGuid)1341 LibPcdGetNextTokenSpace (
1342   IN CONST GUID  *TokenSpaceGuid
1343   )
1344 {
1345   GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid);
1346 
1347   return (GUID *)TokenSpaceGuid;
1348 }
1349 
1350 
1351 /**
1352   Sets a value of a patchable PCD entry that is type pointer.
1353 
1354   Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1355   and SizeOfBuffer.  Buffer is returned.  If SizeOfBuffer is greater than
1356   MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
1357   NULL to indicate that the set operation was not actually performed.
1358   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1359   MaximumDatumSize and NULL must be returned.
1360 
1361   If PatchVariable is NULL, then ASSERT().
1362   If SizeOfBuffer is NULL, then ASSERT().
1363   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1364 
1365   @param[out] PatchVariable     A pointer to the global variable in a module that is
1366                                 the target of the set operation.
1367   @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.
1368   @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.
1369   @param[in] Buffer             A pointer to the buffer to used to set the target variable.
1370 
1371   @return Return the pointer to the buffer been set.
1372 
1373 **/
1374 VOID *
1375 EFIAPI
LibPatchPcdSetPtr(OUT VOID * PatchVariable,IN UINTN MaximumDatumSize,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)1376 LibPatchPcdSetPtr (
1377   OUT       VOID        *PatchVariable,
1378   IN        UINTN       MaximumDatumSize,
1379   IN OUT    UINTN       *SizeOfBuffer,
1380   IN CONST  VOID        *Buffer
1381   )
1382 {
1383   ASSERT (PatchVariable != NULL);
1384   ASSERT (SizeOfBuffer  != NULL);
1385 
1386   if (*SizeOfBuffer > 0) {
1387     ASSERT (Buffer != NULL);
1388   }
1389 
1390   if ((*SizeOfBuffer > MaximumDatumSize) ||
1391       (*SizeOfBuffer == MAX_ADDRESS)) {
1392     *SizeOfBuffer = MaximumDatumSize;
1393     return NULL;
1394   }
1395 
1396   CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1397 
1398   return (VOID *) Buffer;
1399 }
1400 
1401 /**
1402   Sets a value of a patchable PCD entry that is type pointer.
1403 
1404   Sets the PCD entry specified by PatchVariable to the value specified
1405   by Buffer and SizeOfBuffer. If SizeOfBuffer is greater than MaximumDatumSize,
1406   then set SizeOfBuffer to MaximumDatumSize and return RETURN_INVALID_PARAMETER
1407   to indicate that the set operation was not actually performed.
1408   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1409   MaximumDatumSize and RETURN_INVALID_PARAMETER must be returned.
1410 
1411   If PatchVariable is NULL, then ASSERT().
1412   If SizeOfBuffer is NULL, then ASSERT().
1413   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1414 
1415   @param[out] PatchVariable     A pointer to the global variable in a module that is
1416                                 the target of the set operation.
1417   @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.
1418   @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.
1419   @param[in] Buffer             A pointer to the buffer to used to set the target variable.
1420 
1421   @return The status of the set operation.
1422 
1423 **/
1424 RETURN_STATUS
1425 EFIAPI
LibPatchPcdSetPtrS(OUT VOID * PatchVariable,IN UINTN MaximumDatumSize,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)1426 LibPatchPcdSetPtrS (
1427   OUT       VOID     *PatchVariable,
1428   IN       UINTN    MaximumDatumSize,
1429   IN OUT   UINTN    *SizeOfBuffer,
1430   IN CONST VOID     *Buffer
1431   )
1432 {
1433   ASSERT (PatchVariable != NULL);
1434   ASSERT (SizeOfBuffer  != NULL);
1435 
1436   if (*SizeOfBuffer > 0) {
1437     ASSERT (Buffer != NULL);
1438   }
1439 
1440   if ((*SizeOfBuffer > MaximumDatumSize) ||
1441       (*SizeOfBuffer == MAX_ADDRESS)) {
1442     *SizeOfBuffer = MaximumDatumSize;
1443     return RETURN_INVALID_PARAMETER;
1444   }
1445 
1446   CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1447 
1448   return RETURN_SUCCESS;
1449 }
1450 
1451 
1452 /**
1453   Sets a value and size of a patchable PCD entry that is type pointer.
1454 
1455   Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1456   and SizeOfBuffer.  Buffer is returned.  If SizeOfBuffer is greater than
1457   MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
1458   NULL to indicate that the set operation was not actually performed.
1459   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1460   MaximumDatumSize and NULL must be returned.
1461 
1462   If PatchVariable is NULL, then ASSERT().
1463   If SizeOfPatchVariable is NULL, then ASSERT().
1464   If SizeOfBuffer is NULL, then ASSERT().
1465   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1466 
1467   @param[out] PatchVariable     A pointer to the global variable in a module that is
1468                                 the target of the set operation.
1469   @param[out] SizeOfPatchVariable A pointer to the size, in bytes, of PatchVariable.
1470   @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.
1471   @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.
1472   @param[in] Buffer             A pointer to the buffer to used to set the target variable.
1473 
1474   @return Return the pointer to the buffer been set.
1475 
1476 **/
1477 VOID *
1478 EFIAPI
LibPatchPcdSetPtrAndSize(OUT VOID * PatchVariable,OUT UINTN * SizeOfPatchVariable,IN UINTN MaximumDatumSize,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)1479 LibPatchPcdSetPtrAndSize (
1480   OUT       VOID        *PatchVariable,
1481   OUT       UINTN       *SizeOfPatchVariable,
1482   IN        UINTN       MaximumDatumSize,
1483   IN OUT    UINTN       *SizeOfBuffer,
1484   IN CONST  VOID        *Buffer
1485   )
1486 {
1487   ASSERT (PatchVariable != NULL);
1488   ASSERT (SizeOfPatchVariable != NULL);
1489   ASSERT (SizeOfBuffer  != NULL);
1490 
1491   if (*SizeOfBuffer > 0) {
1492     ASSERT (Buffer != NULL);
1493   }
1494 
1495   if ((*SizeOfBuffer > MaximumDatumSize) ||
1496       (*SizeOfBuffer == MAX_ADDRESS)) {
1497     *SizeOfBuffer = MaximumDatumSize;
1498     return NULL;
1499   }
1500 
1501   CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1502   *SizeOfPatchVariable = *SizeOfBuffer;
1503 
1504   return (VOID *) Buffer;
1505 }
1506 
1507 /**
1508   Sets a value and size of a patchable PCD entry that is type pointer.
1509 
1510   Sets the PCD entry specified by PatchVariable to the value specified
1511   by Buffer and SizeOfBuffer. If SizeOfBuffer is greater than MaximumDatumSize,
1512   then set SizeOfBuffer to MaximumDatumSize and return RETURN_INVALID_PARAMETER
1513   to indicate that the set operation was not actually performed.
1514   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1515   MaximumDatumSize and RETURN_INVALID_PARAMETER must be returned.
1516 
1517   If PatchVariable is NULL, then ASSERT().
1518   If SizeOfPatchVariable is NULL, then ASSERT().
1519   If SizeOfBuffer is NULL, then ASSERT().
1520   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1521 
1522   @param[out] PatchVariable     A pointer to the global variable in a module that is
1523                                 the target of the set operation.
1524   @param[out] SizeOfPatchVariable A pointer to the size, in bytes, of PatchVariable.
1525   @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.
1526   @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.
1527   @param[in] Buffer             A pointer to the buffer to used to set the target variable.
1528 
1529   @return The status of the set operation.
1530 
1531 **/
1532 RETURN_STATUS
1533 EFIAPI
LibPatchPcdSetPtrAndSizeS(OUT VOID * PatchVariable,OUT UINTN * SizeOfPatchVariable,IN UINTN MaximumDatumSize,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)1534 LibPatchPcdSetPtrAndSizeS (
1535   OUT      VOID     *PatchVariable,
1536   OUT      UINTN    *SizeOfPatchVariable,
1537   IN       UINTN    MaximumDatumSize,
1538   IN OUT   UINTN    *SizeOfBuffer,
1539   IN CONST VOID     *Buffer
1540   )
1541 {
1542   ASSERT (PatchVariable != NULL);
1543   ASSERT (SizeOfPatchVariable != NULL);
1544   ASSERT (SizeOfBuffer  != NULL);
1545 
1546   if (*SizeOfBuffer > 0) {
1547     ASSERT (Buffer != NULL);
1548   }
1549 
1550   if ((*SizeOfBuffer > MaximumDatumSize) ||
1551       (*SizeOfBuffer == MAX_ADDRESS)) {
1552     *SizeOfBuffer = MaximumDatumSize;
1553     return RETURN_INVALID_PARAMETER;
1554   }
1555 
1556   CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1557   *SizeOfPatchVariable = *SizeOfBuffer;
1558 
1559   return RETURN_SUCCESS;
1560 }
1561 
1562 /**
1563   Retrieve additional information associated with a PCD token.
1564 
1565   This includes information such as the type of value the TokenNumber is associated with as well as possible
1566   human readable name that is associated with the token.
1567 
1568   If TokenNumber is not in the default token space specified, then ASSERT().
1569 
1570   @param[in]    TokenNumber The PCD token number.
1571   @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.
1572                             The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
1573 **/
1574 VOID
1575 EFIAPI
LibPcdGetInfo(IN UINTN TokenNumber,OUT PCD_INFO * PcdInfo)1576 LibPcdGetInfo (
1577   IN        UINTN           TokenNumber,
1578   OUT       PCD_INFO        *PcdInfo
1579   )
1580 {
1581   EFI_STATUS Status;
1582 
1583   Status = GetPcdInfoProtocolPointer()->GetInfo (TokenNumber, (EFI_PCD_INFO *) PcdInfo);
1584   ASSERT_EFI_ERROR (Status);
1585 }
1586 
1587 /**
1588   Retrieve additional information associated with a PCD token.
1589 
1590   This includes information such as the type of value the TokenNumber is associated with as well as possible
1591   human readable name that is associated with the token.
1592 
1593   If TokenNumber is not in the token space specified by Guid, then ASSERT().
1594 
1595   @param[in]    Guid        The 128-bit unique value that designates the namespace from which to extract the value.
1596   @param[in]    TokenNumber The PCD token number.
1597   @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.
1598                             The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
1599 **/
1600 VOID
1601 EFIAPI
LibPcdGetInfoEx(IN CONST GUID * Guid,IN UINTN TokenNumber,OUT PCD_INFO * PcdInfo)1602 LibPcdGetInfoEx (
1603   IN CONST  GUID            *Guid,
1604   IN        UINTN           TokenNumber,
1605   OUT       PCD_INFO        *PcdInfo
1606   )
1607 {
1608   EFI_STATUS Status;
1609 
1610   Status = GetPiPcdInfoProtocolPointer()->GetInfo (Guid, TokenNumber, (EFI_PCD_INFO *) PcdInfo);
1611   ASSERT_EFI_ERROR (Status);
1612 }
1613 
1614 /**
1615   Retrieve the currently set SKU Id.
1616 
1617   If the sku id got >= PCD_MAX_SKU_ID, then ASSERT().
1618 
1619   @return   The currently set SKU Id. If the platform has not set at a SKU Id, then the
1620             default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU
1621             Id is returned.
1622 **/
1623 UINTN
1624 EFIAPI
LibPcdGetSku(VOID)1625 LibPcdGetSku (
1626   VOID
1627   )
1628 {
1629   UINTN SkuId;
1630 
1631   SkuId = GetPiPcdInfoProtocolPointer()->GetSku ();
1632   ASSERT (SkuId < PCD_MAX_SKU_ID);
1633 
1634   return SkuId;
1635 }
1636 
1637