• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 Implementation of PcdLib class library for PEI phase.
3 
4 Copyright (c) 2006 - 2016, 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 
18 
19 #include <PiPei.h>
20 
21 #include <Ppi/Pcd.h>
22 #include <Ppi/PiPcd.h>
23 #include <Ppi/PcdInfo.h>
24 #include <Ppi/PiPcdInfo.h>
25 
26 #include <Library/PeiServicesLib.h>
27 #include <Library/PcdLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/BaseMemoryLib.h>
30 
31 /**
32   Retrieve the PCD_PPI pointer.
33 
34   This function is to locate PCD_PPI PPI via PeiService.
35   If fail to locate PCD_PPI, then ASSERT_EFI_ERROR().
36 
37   @retval PCD_PPI * The pointer to the PCD_PPI.
38 
39 **/
40 PCD_PPI  *
GetPcdPpiPointer(VOID)41 GetPcdPpiPointer (
42   VOID
43   )
44 {
45   EFI_STATUS        Status;
46   PCD_PPI           *PcdPpi;
47 
48   Status = PeiServicesLocatePpi (&gPcdPpiGuid, 0, NULL, (VOID **)&PcdPpi);
49   ASSERT_EFI_ERROR (Status);
50 
51   return PcdPpi;
52 }
53 
54 /**
55   Retrieve the pointer of EFI_PEI_PCD_PPI defined in PI 1.2 Vol 3.
56 
57   This function is to locate EFI_PEI_PCD_PPI PPI via PeiService.
58   If fail to locate EFI_PEI_PCD_PPI, then ASSERT_EFI_ERROR().
59 
60   @retval EFI_PEI_PCD_PPI * The pointer to the EFI_PEI_PCD_PPI.
61 
62 **/
63 EFI_PEI_PCD_PPI *
GetPiPcdPpiPointer(VOID)64 GetPiPcdPpiPointer (
65   VOID
66   )
67 {
68   EFI_STATUS        Status;
69   EFI_PEI_PCD_PPI   *PiPcdPpi;
70 
71   Status = PeiServicesLocatePpi (&gEfiPeiPcdPpiGuid, 0, NULL, (VOID **)&PiPcdPpi);
72   ASSERT_EFI_ERROR (Status);
73 
74   return PiPcdPpi;
75 }
76 
77 /**
78   Retrieve the GET_PCD_INFO_PPI pointer.
79 
80   This function is to locate GET_PCD_INFO_PPI PPI via PeiService.
81   If fail to locate GET_PCD_INFO_PPI, then ASSERT_EFI_ERROR().
82 
83   @retval GET_PCD_INFO_PPI * The pointer to the GET_PCD_INFO_PPI.
84 
85 **/
86 GET_PCD_INFO_PPI *
GetPcdInfoPpiPointer(VOID)87 GetPcdInfoPpiPointer (
88   VOID
89   )
90 {
91   EFI_STATUS            Status;
92   GET_PCD_INFO_PPI      *PcdInfoPpi;
93 
94   Status = PeiServicesLocatePpi (&gGetPcdInfoPpiGuid, 0, NULL, (VOID **)&PcdInfoPpi);
95   ASSERT_EFI_ERROR (Status);
96 
97   return PcdInfoPpi;
98 }
99 
100 /**
101   Retrieve the pointer of EFI_GET_PCD_INFO_PPI defined in PI 1.2.1 Vol 3.
102 
103   This function is to locate EFI_GET_PCD_INFO_PPI PPI via PeiService.
104   If fail to locate EFI_GET_PCD_INFO_PPI, then ASSERT_EFI_ERROR().
105 
106   @retval EFI_GET_PCD_INFO_PPI * The pointer to the EFI_GET_PCD_INFO_PPI.
107 
108 **/
109 EFI_GET_PCD_INFO_PPI *
GetPiPcdInfoPpiPointer(VOID)110 GetPiPcdInfoPpiPointer (
111   VOID
112   )
113 {
114   EFI_STATUS            Status;
115   EFI_GET_PCD_INFO_PPI  *PiPcdInfoPpi;
116 
117   Status = PeiServicesLocatePpi (&gEfiGetPcdInfoPpiGuid, 0, NULL, (VOID **)&PiPcdInfoPpi);
118   ASSERT_EFI_ERROR (Status);
119 
120   return PiPcdInfoPpi;
121 }
122 
123 /**
124   This function provides a means by which SKU support can be established in the PCD infrastructure.
125 
126   Sets the current SKU in the PCD database to the value specified by SkuId.  SkuId is returned.
127 
128   @param  SkuId   The SKU value that will be used when the PCD service retrieves
129                   and sets values associated with a PCD token.
130 
131   @return  Return the SKU ID that just be set.
132 
133 **/
134 UINTN
135 EFIAPI
LibPcdSetSku(IN UINTN SkuId)136 LibPcdSetSku (
137   IN UINTN   SkuId
138   )
139 {
140   GetPiPcdPpiPointer()->SetSku (SkuId);
141 
142   return SkuId;
143 }
144 
145 
146 
147 /**
148   This function provides a means by which to retrieve a value for a given PCD token.
149 
150   Returns the 8-bit value for the token specified by TokenNumber.
151 
152   @param[in]  TokenNumber The PCD token number to retrieve a current value for.
153 
154   @return Returns the 8-bit value for the token specified by TokenNumber.
155 
156 **/
157 UINT8
158 EFIAPI
LibPcdGet8(IN UINTN TokenNumber)159 LibPcdGet8 (
160   IN UINTN             TokenNumber
161   )
162 {
163   return (GetPcdPpiPointer ())->Get8 (TokenNumber);
164 }
165 
166 
167 
168 /**
169   This function provides a means by which to retrieve a value for a given PCD token.
170 
171   Returns the 16-bit value for the token specified by TokenNumber.
172 
173   @param[in]  TokenNumber The PCD token number to retrieve a current value for.
174 
175   @return Returns the 16-bit value for the token specified by TokenNumber.
176 
177 **/
178 UINT16
179 EFIAPI
LibPcdGet16(IN UINTN TokenNumber)180 LibPcdGet16 (
181   IN UINTN             TokenNumber
182   )
183 {
184   return (GetPcdPpiPointer ())->Get16 (TokenNumber);
185 }
186 
187 
188 
189 /**
190   This function provides a means by which to retrieve a value for a given PCD token.
191 
192   Returns the 32-bit value for the token specified by TokenNumber.
193 
194   @param[in]  TokenNumber The PCD token number to retrieve a current value for.
195 
196   @return Returns the 32-bit value for the token specified by TokenNumber.
197 
198 **/
199 UINT32
200 EFIAPI
LibPcdGet32(IN UINTN TokenNumber)201 LibPcdGet32 (
202   IN UINTN             TokenNumber
203   )
204 {
205   return (GetPcdPpiPointer ())->Get32 (TokenNumber);
206 }
207 
208 
209 
210 /**
211   This function provides a means by which to retrieve a value for a given PCD token.
212 
213   Returns the 64-bit value for the token specified by TokenNumber.
214 
215   @param[in]  TokenNumber The PCD token number to retrieve a current value for.
216 
217   @return Returns the 64-bit value for the token specified by TokenNumber.
218 
219 **/
220 UINT64
221 EFIAPI
LibPcdGet64(IN UINTN TokenNumber)222 LibPcdGet64 (
223   IN UINTN             TokenNumber
224   )
225 {
226   return (GetPcdPpiPointer ())->Get64 (TokenNumber);
227 }
228 
229 
230 
231 /**
232   This function provides a means by which to retrieve a value for a given PCD token.
233 
234   Returns the pointer to the buffer of the token specified by TokenNumber.
235 
236   @param[in]  TokenNumber The PCD token number to retrieve a current value for.
237 
238   @return Returns the pointer to the token specified by TokenNumber.
239 
240 **/
241 VOID *
242 EFIAPI
LibPcdGetPtr(IN UINTN TokenNumber)243 LibPcdGetPtr (
244   IN UINTN             TokenNumber
245   )
246 {
247   return (GetPcdPpiPointer ())->GetPtr (TokenNumber);
248 }
249 
250 
251 
252 /**
253   This function provides a means by which to retrieve a value for a given PCD token.
254 
255   Returns the Boolean value of the token specified by TokenNumber.
256 
257   @param[in]  TokenNumber The PCD token number to retrieve a current value for.
258 
259   @return Returns the Boolean value of the token specified by TokenNumber.
260 
261 **/
262 BOOLEAN
263 EFIAPI
LibPcdGetBool(IN UINTN TokenNumber)264 LibPcdGetBool (
265   IN UINTN             TokenNumber
266   )
267 {
268   return (GetPcdPpiPointer ())->GetBool (TokenNumber);
269 }
270 
271 
272 
273 /**
274   This function provides a means by which to retrieve the size of a given PCD token.
275 
276   @param[in]  TokenNumber The PCD token number to retrieve a current value for.
277 
278   @return Returns the size of the token specified by TokenNumber.
279 
280 **/
281 UINTN
282 EFIAPI
LibPcdGetSize(IN UINTN TokenNumber)283 LibPcdGetSize (
284   IN UINTN             TokenNumber
285   )
286 {
287   return (GetPcdPpiPointer ())->GetSize (TokenNumber);
288 }
289 
290 
291 
292 /**
293   This function provides a means by which to retrieve a value for a given PCD token.
294 
295   Returns the 8-bit value for the token specified by TokenNumber and Guid.
296 
297   If Guid is NULL, then ASSERT().
298 
299   @param[in]  Guid         The pointer to a 128-bit unique value that designates
300                            which namespace to retrieve a value from.
301   @param[in]  TokenNumber  The PCD token number to retrieve a current value for.
302 
303   @return Return the UINT8.
304 
305 **/
306 UINT8
307 EFIAPI
LibPcdGetEx8(IN CONST GUID * Guid,IN UINTN TokenNumber)308 LibPcdGetEx8 (
309   IN CONST GUID        *Guid,
310   IN UINTN             TokenNumber
311   )
312 {
313   ASSERT (Guid != NULL);
314 
315   return (GetPiPcdPpiPointer ())->Get8 (Guid, TokenNumber);
316 }
317 
318 
319 
320 /**
321   This function provides a means by which to retrieve a value for a given PCD token.
322 
323   Returns the 16-bit value for the token specified by TokenNumber and Guid.
324 
325   If Guid is NULL, then ASSERT().
326 
327   @param[in]  Guid         The pointer to a 128-bit unique value that designates
328                            which namespace to retrieve a value from.
329   @param[in]  TokenNumber  The PCD token number to retrieve a current value for.
330 
331   @return Return the UINT16.
332 
333 **/
334 UINT16
335 EFIAPI
LibPcdGetEx16(IN CONST GUID * Guid,IN UINTN TokenNumber)336 LibPcdGetEx16 (
337   IN CONST GUID        *Guid,
338   IN UINTN             TokenNumber
339   )
340 {
341 
342   ASSERT (Guid != NULL);
343 
344   return (GetPiPcdPpiPointer ())->Get16 (Guid, TokenNumber);
345 }
346 
347 
348 
349 /**
350   Returns the 32-bit value for the token specified by TokenNumber and Guid.
351   If Guid is NULL, then ASSERT().
352 
353   @param[in]  Guid         The pointer to a 128-bit unique value that designates
354                            which namespace to retrieve a value from.
355   @param[in]  TokenNumber  The PCD token number to retrieve a current value for.
356 
357   @return Return the UINT32.
358 
359 **/
360 UINT32
361 EFIAPI
LibPcdGetEx32(IN CONST GUID * Guid,IN UINTN TokenNumber)362 LibPcdGetEx32 (
363   IN CONST GUID        *Guid,
364   IN UINTN             TokenNumber
365   )
366 {
367   ASSERT (Guid != NULL);
368 
369   return (GetPiPcdPpiPointer ())->Get32 (Guid, TokenNumber);
370 }
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   return (GetPiPcdPpiPointer ())->Get64 (Guid, TokenNumber);
398 }
399 
400 
401 
402 /**
403   This function provides a means by which to retrieve a value for a given PCD token.
404 
405   Returns the pointer to the buffer of token specified by TokenNumber and Guid.
406 
407   If Guid is NULL, then ASSERT().
408 
409   @param[in]  Guid          The pointer to a 128-bit unique value that designates
410                             which namespace to retrieve a value from.
411   @param[in]  TokenNumber   The PCD token number to retrieve a current value for.
412 
413   @return Return the VOID* pointer.
414 
415 **/
416 VOID *
417 EFIAPI
LibPcdGetExPtr(IN CONST GUID * Guid,IN UINTN TokenNumber)418 LibPcdGetExPtr (
419   IN CONST GUID        *Guid,
420   IN UINTN             TokenNumber
421   )
422 {
423   ASSERT (Guid != NULL);
424 
425   return (GetPiPcdPpiPointer ())->GetPtr (Guid, TokenNumber);
426 }
427 
428 
429 
430 /**
431   This function provides a means by which to retrieve a value for a given PCD token.
432 
433   Returns the Boolean value of the token specified by TokenNumber and Guid.
434 
435   If Guid is NULL, then ASSERT().
436 
437   @param[in]  Guid          The pointer to a 128-bit unique value that designates
438                             which namespace to retrieve a value from.
439   @param[in]  TokenNumber   The PCD token number to retrieve a current value for.
440 
441   @return Return the BOOLEAN.
442 
443 **/
444 BOOLEAN
445 EFIAPI
LibPcdGetExBool(IN CONST GUID * Guid,IN UINTN TokenNumber)446 LibPcdGetExBool (
447   IN CONST GUID        *Guid,
448   IN UINTN             TokenNumber
449   )
450 {
451   ASSERT (Guid != NULL);
452   return (GetPiPcdPpiPointer ())->GetBool (Guid, TokenNumber);
453 }
454 
455 
456 
457 /**
458   This function provides a means by which to retrieve the size of a given PCD token.
459 
460   Returns the size of the token specified by TokenNumber and Guid.
461 
462   If Guid is NULL, then ASSERT().
463 
464   @param[in]  Guid          The pointer to a 128-bit unique value that designates
465                             which namespace to retrieve a value from.
466   @param[in]  TokenNumber   The PCD token number to retrieve a current value for.
467 
468   @return Return the size.
469 
470 **/
471 UINTN
472 EFIAPI
LibPcdGetExSize(IN CONST GUID * Guid,IN UINTN TokenNumber)473 LibPcdGetExSize (
474   IN CONST GUID        *Guid,
475   IN UINTN             TokenNumber
476   )
477 {
478   ASSERT (Guid != NULL);
479   return (GetPiPcdPpiPointer ())->GetSize (Guid, TokenNumber);
480 }
481 
482 
483 
484 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
485 /**
486   This function provides a means by which to set a value for a given PCD token.
487 
488   Sets the 8-bit value for the token specified by TokenNumber
489   to the value specified by Value.  Value is returned.
490 
491   @param[in]  TokenNumber   The PCD token number to set a current value for.
492   @param[in]  Value         The 8-bit value to set.
493 
494   @return Return the value that was set.
495 
496 **/
497 UINT8
498 EFIAPI
LibPcdSet8(IN UINTN TokenNumber,IN UINT8 Value)499 LibPcdSet8 (
500   IN UINTN             TokenNumber,
501   IN UINT8             Value
502   )
503 {
504   (GetPcdPpiPointer ())->Set8 (TokenNumber, Value);
505 
506   return Value;
507 }
508 
509 
510 
511 /**
512   This function provides a means by which to set a value for a given PCD token.
513 
514   Sets the 16-bit value for the token specified by TokenNumber
515   to the value specified by Value.  Value is returned.
516 
517   @param[in]  TokenNumber   The PCD token number to set a current value for.
518   @param[in]  Value         The 16-bit value to set.
519 
520   @return Return the value that was set.
521 
522 **/
523 UINT16
524 EFIAPI
LibPcdSet16(IN UINTN TokenNumber,IN UINT16 Value)525 LibPcdSet16 (
526   IN UINTN             TokenNumber,
527   IN UINT16            Value
528   )
529 {
530   (GetPcdPpiPointer ())->Set16 (TokenNumber, Value);
531 
532   return Value;
533 }
534 
535 
536 
537 /**
538   This function provides a means by which to set a value for a given PCD token.
539 
540   Sets the 32-bit value for the token specified by TokenNumber
541   to the value specified by Value.  Value is returned.
542 
543   @param[in]  TokenNumber   The PCD token number to set a current value for.
544   @param[in]  Value         The 32-bit value to set.
545 
546   @return Return the value that was set.
547 
548 **/
549 UINT32
550 EFIAPI
LibPcdSet32(IN UINTN TokenNumber,IN UINT32 Value)551 LibPcdSet32 (
552   IN UINTN             TokenNumber,
553   IN UINT32            Value
554   )
555 {
556   (GetPcdPpiPointer ())->Set32 (TokenNumber, Value);
557 
558   return Value;
559 }
560 
561 
562 
563 /**
564   This function provides a means by which to set a value for a given PCD token.
565 
566   Sets the 64-bit value for the token specified by TokenNumber
567   to the value specified by Value.  Value is returned.
568 
569   @param[in]  TokenNumber   The PCD token number to set a current value for.
570   @param[in]  Value         The 64-bit value to set.
571 
572   @return Return the value that was set.
573 
574 **/
575 UINT64
576 EFIAPI
LibPcdSet64(IN UINTN TokenNumber,IN UINT64 Value)577 LibPcdSet64 (
578   IN UINTN             TokenNumber,
579   IN UINT64            Value
580   )
581 {
582   (GetPcdPpiPointer ())->Set64 (TokenNumber, Value);
583 
584   return Value;
585 }
586 
587 
588 
589 /**
590   This function provides a means by which to set a value for a given PCD token.
591 
592   Sets a buffer for the token specified by TokenNumber to the value
593   specified by Buffer and SizeOfBuffer.  Buffer is returned.
594   If SizeOfBuffer is greater than the maximum size support by TokenNumber,
595   then set SizeOfBuffer to the maximum size supported by TokenNumber and
596   return NULL to indicate that the set operation was not actually performed.
597 
598   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
599   maximum size supported by TokenName and NULL must be returned.
600 
601   If SizeOfBuffer is NULL, then ASSERT().
602   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
603 
604   @param[in]      TokenNumber   The PCD token number to set a current value for.
605   @param[in, out] SizeOfBuffer  The size, in bytes, of Buffer.
606   @param[in]      Buffer        A pointer to the buffer to set.
607 
608   @return Return the pointer for the buffer been set.
609 
610 **/
611 VOID *
612 EFIAPI
LibPcdSetPtr(IN UINTN TokenNumber,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)613 LibPcdSetPtr (
614   IN        UINTN             TokenNumber,
615   IN OUT    UINTN             *SizeOfBuffer,
616   IN CONST  VOID              *Buffer
617   )
618 {
619   EFI_STATUS Status;
620   UINTN      InputSizeOfBuffer;
621 
622   ASSERT (SizeOfBuffer != NULL);
623 
624   if (*SizeOfBuffer > 0) {
625     ASSERT (Buffer != NULL);
626   }
627 
628   InputSizeOfBuffer = *SizeOfBuffer;
629   Status = (GetPcdPpiPointer ())->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);
630   if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {
631     return NULL;
632   }
633 
634   return (VOID *) Buffer;
635 }
636 
637 
638 
639 /**
640   This function provides a means by which to set a value for a given PCD token.
641 
642   Sets the Boolean value for the token specified by TokenNumber
643   to the value specified by Value.  Value is returned.
644 
645   @param[in]  TokenNumber   The PCD token number to set a current value for.
646   @param[in]  Value         The boolean value to set.
647 
648   @return Return the value that was set.
649 
650 **/
651 BOOLEAN
652 EFIAPI
LibPcdSetBool(IN UINTN TokenNumber,IN BOOLEAN Value)653 LibPcdSetBool (
654   IN UINTN             TokenNumber,
655   IN BOOLEAN           Value
656   )
657 {
658   (GetPcdPpiPointer ())->SetBool (TokenNumber, Value);
659 
660   return Value;
661 }
662 
663 
664 
665 /**
666   This function provides a means by which to set a value for a given PCD token.
667 
668   Sets the 8-bit value for the token specified by TokenNumber and
669   Guid to the value specified by Value. Value is returned.
670 
671   If Guid is NULL, then ASSERT().
672 
673   @param[in]  Guid          The pointer to a 128-bit unique value that
674                             designates which namespace to set a value from.
675   @param[in]  TokenNumber   The PCD token number to set a current value for.
676   @param[in]  Value         The 8-bit value to set.
677 
678   @return Return the value that was set.
679 
680 **/
681 UINT8
682 EFIAPI
LibPcdSetEx8(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT8 Value)683 LibPcdSetEx8 (
684   IN CONST GUID        *Guid,
685   IN UINTN             TokenNumber,
686   IN UINT8             Value
687   )
688 {
689   ASSERT (Guid != NULL);
690 
691   (GetPiPcdPpiPointer ())->Set8 (Guid, TokenNumber, Value);
692 
693   return Value;
694 }
695 
696 
697 
698 /**
699   This function provides a means by which to set a value for a given PCD token.
700 
701   Sets the 16-bit value for the token specified by TokenNumber and
702   Guid to the value specified by Value. Value is returned.
703 
704   If Guid is NULL, then ASSERT().
705 
706   @param[in]  Guid          The pointer to a 128-bit unique value that
707                             designates which namespace to set a value from.
708   @param[in]  TokenNumber   The PCD token number to set a current value for.
709   @param[in]  Value         The 16-bit value to set.
710 
711   @return Return the value that was set.
712 
713 **/
714 UINT16
715 EFIAPI
LibPcdSetEx16(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT16 Value)716 LibPcdSetEx16 (
717   IN CONST GUID        *Guid,
718   IN UINTN             TokenNumber,
719   IN UINT16            Value
720   )
721 {
722   ASSERT (Guid != NULL);
723 
724   (GetPiPcdPpiPointer ())->Set16 (Guid, TokenNumber, Value);
725 
726   return Value;
727 }
728 
729 
730 
731 /**
732   This function provides a means by which to set a value for a given PCD token.
733 
734   Sets the 32-bit value for the token specified by TokenNumber and
735   Guid to the value specified by Value. Value is returned.
736 
737   If Guid is NULL, then ASSERT().
738 
739   @param[in]  Guid          The pointer to a 128-bit unique value that
740                             designates which namespace to set a value from.
741   @param[in]  TokenNumber   The PCD token number to set a current value for.
742   @param[in]  Value         The 32-bit value to set.
743 
744   @return Return the value that was set.
745 
746 **/
747 UINT32
748 EFIAPI
LibPcdSetEx32(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT32 Value)749 LibPcdSetEx32 (
750   IN CONST GUID        *Guid,
751   IN UINTN             TokenNumber,
752   IN UINT32            Value
753   )
754 {
755   ASSERT (Guid != NULL);
756 
757   (GetPiPcdPpiPointer ())->Set32 (Guid, TokenNumber, Value);
758 
759   return Value;
760 }
761 
762 
763 
764 /**
765   This function provides a means by which to set a value for a given PCD token.
766 
767   Sets the 64-bit value for the token specified by TokenNumber and
768   Guid to the value specified by Value. Value is returned.
769 
770   If Guid is NULL, then ASSERT().
771 
772   @param[in]  Guid          The pointer to a 128-bit unique value that
773                             designates which namespace to set a value from.
774   @param[in]  TokenNumber   The PCD token number to set a current value for.
775   @param[in]  Value         The 64-bit value to set.
776 
777   @return Return the value that was set.
778 
779 **/
780 UINT64
781 EFIAPI
LibPcdSetEx64(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT64 Value)782 LibPcdSetEx64 (
783   IN CONST GUID        *Guid,
784   IN UINTN             TokenNumber,
785   IN UINT64            Value
786   )
787 {
788   ASSERT (Guid != NULL);
789 
790   (GetPiPcdPpiPointer ())->Set64 (Guid, TokenNumber, Value);
791 
792   return Value;
793 }
794 
795 
796 
797 /**
798   This function provides a means by which to set a value for a given PCD token.
799 
800   Sets a buffer for the token specified by TokenNumber to the value specified by
801   Buffer and SizeOfBuffer.  Buffer is returned.  If SizeOfBuffer is greater than
802   the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
803   supported by TokenNumber and return NULL to indicate that the set operation
804   was not actually performed.
805 
806   If Guid is NULL, then ASSERT().
807   If SizeOfBuffer is NULL, then ASSERT().
808   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
809 
810   @param[in]  Guid              The pointer to a 128-bit unique value that
811                                 designates which namespace to set a value from.
812   @param[in]  TokenNumber       The PCD token number to set a current value for.
813   @param[in, out] SizeOfBuffer  The size, in bytes, of Buffer.
814   @param[in]  Buffer            A pointer to the buffer to set.
815 
816   @return Return the pinter to the buffer been set.
817 
818 **/
819 VOID *
820 EFIAPI
LibPcdSetExPtr(IN CONST GUID * Guid,IN UINTN TokenNumber,IN OUT UINTN * SizeOfBuffer,IN VOID * Buffer)821 LibPcdSetExPtr (
822   IN      CONST GUID        *Guid,
823   IN      UINTN             TokenNumber,
824   IN OUT  UINTN             *SizeOfBuffer,
825   IN      VOID              *Buffer
826   )
827 {
828   EFI_STATUS      Status;
829   UINTN           InputSizeOfBuffer;
830 
831   ASSERT (SizeOfBuffer != NULL);
832   if (*SizeOfBuffer > 0) {
833     ASSERT (Buffer != NULL);
834   }
835   ASSERT (Guid != NULL);
836 
837   InputSizeOfBuffer = *SizeOfBuffer;
838   Status = (GetPiPcdPpiPointer ())->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);
839   if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {
840     return NULL;
841   }
842 
843   return Buffer;
844 }
845 
846 
847 
848 /**
849   This function provides a means by which to set a value for a given PCD token.
850 
851   Sets the Boolean value for the token specified by TokenNumber and
852   Guid to the value specified by Value. Value is returned.
853 
854   If Guid is NULL, then ASSERT().
855 
856   @param[in]  Guid          The pointer to a 128-bit unique value that
857                             designates which namespace to set a value from.
858   @param[in]  TokenNumber   The PCD token number to set a current value for.
859   @param[in]  Value         The Boolean value to set.
860 
861   @return Return the value that was set.
862 
863 **/
864 BOOLEAN
865 EFIAPI
LibPcdSetExBool(IN CONST GUID * Guid,IN UINTN TokenNumber,IN BOOLEAN Value)866 LibPcdSetExBool (
867   IN CONST GUID        *Guid,
868   IN UINTN             TokenNumber,
869   IN BOOLEAN           Value
870   )
871 {
872   ASSERT (Guid != NULL);
873 
874   (GetPiPcdPpiPointer ())->SetBool (Guid, TokenNumber, Value);
875 
876   return Value;
877 }
878 #endif
879 
880 /**
881   This function provides a means by which to set a value for a given PCD token.
882 
883   Sets the 8-bit value for the token specified by TokenNumber
884   to the value specified by Value.
885 
886   @param[in] TokenNumber    The PCD token number to set a current value for.
887   @param[in] Value          The 8-bit value to set.
888 
889   @return The status of the set operation.
890 
891 **/
892 RETURN_STATUS
893 EFIAPI
LibPcdSet8S(IN UINTN TokenNumber,IN UINT8 Value)894 LibPcdSet8S (
895   IN UINTN          TokenNumber,
896   IN UINT8          Value
897   )
898 {
899   return (GetPcdPpiPointer ())->Set8 (TokenNumber, Value);
900 }
901 
902 /**
903   This function provides a means by which to set a value for a given PCD token.
904 
905   Sets the 16-bit value for the token specified by TokenNumber
906   to the value specified by Value.
907 
908   @param[in] TokenNumber    The PCD token number to set a current value for.
909   @param[in] Value          The 16-bit value to set.
910 
911   @return The status of the set operation.
912 
913 **/
914 RETURN_STATUS
915 EFIAPI
LibPcdSet16S(IN UINTN TokenNumber,IN UINT16 Value)916 LibPcdSet16S (
917   IN UINTN          TokenNumber,
918   IN UINT16         Value
919   )
920 {
921   return (GetPcdPpiPointer ())->Set16 (TokenNumber, Value);
922 }
923 
924 /**
925   This function provides a means by which to set a value for a given PCD token.
926 
927   Sets the 32-bit value for the token specified by TokenNumber
928   to the value specified by Value.
929 
930   @param[in] TokenNumber    The PCD token number to set a current value for.
931   @param[in] Value          The 32-bit value to set.
932 
933   @return The status of the set operation.
934 
935 **/
936 RETURN_STATUS
937 EFIAPI
LibPcdSet32S(IN UINTN TokenNumber,IN UINT32 Value)938 LibPcdSet32S (
939   IN UINTN          TokenNumber,
940   IN UINT32         Value
941   )
942 {
943   return (GetPcdPpiPointer ())->Set32 (TokenNumber, Value);
944 }
945 
946 /**
947   This function provides a means by which to set a value for a given PCD token.
948 
949   Sets the 64-bit value for the token specified by TokenNumber
950   to the value specified by Value.
951 
952   @param[in] TokenNumber    The PCD token number to set a current value for.
953   @param[in] Value          The 64-bit value to set.
954 
955   @return The status of the set operation.
956 
957 **/
958 RETURN_STATUS
959 EFIAPI
LibPcdSet64S(IN UINTN TokenNumber,IN UINT64 Value)960 LibPcdSet64S (
961   IN UINTN          TokenNumber,
962   IN UINT64         Value
963   )
964 {
965   return (GetPcdPpiPointer ())->Set64 (TokenNumber, Value);
966 }
967 
968 /**
969   This function provides a means by which to set a value for a given PCD token.
970 
971   Sets a buffer for the token specified by TokenNumber to the value specified
972   by Buffer and SizeOfBuffer. If SizeOfBuffer is greater than the maximum size
973   support by TokenNumber, then set SizeOfBuffer to the maximum size supported by
974   TokenNumber and return EFI_INVALID_PARAMETER to indicate that the set operation
975   was not actually performed.
976 
977   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
978   maximum size supported by TokenName and EFI_INVALID_PARAMETER must be returned.
979 
980   If SizeOfBuffer is NULL, then ASSERT().
981   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
982 
983   @param[in]      TokenNumber   The PCD token number to set a current value for.
984   @param[in, out] SizeOfBuffer  The size, in bytes, of Buffer.
985   @param[in]      Buffer        A pointer to the buffer to set.
986 
987   @return The status of the set operation.
988 
989 **/
990 RETURN_STATUS
991 EFIAPI
LibPcdSetPtrS(IN UINTN TokenNumber,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)992 LibPcdSetPtrS (
993   IN       UINTN    TokenNumber,
994   IN OUT   UINTN    *SizeOfBuffer,
995   IN CONST VOID     *Buffer
996   )
997 {
998   ASSERT (SizeOfBuffer != NULL);
999 
1000   if (*SizeOfBuffer > 0) {
1001     ASSERT (Buffer != NULL);
1002   }
1003 
1004   return (GetPcdPpiPointer ())->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);
1005 }
1006 
1007 /**
1008   This function provides a means by which to set a value for a given PCD token.
1009 
1010   Sets the boolean value for the token specified by TokenNumber
1011   to the value specified by Value.
1012 
1013   @param[in] TokenNumber    The PCD token number to set a current value for.
1014   @param[in] Value          The boolean value to set.
1015 
1016   @return The status of the set operation.
1017 
1018 **/
1019 RETURN_STATUS
1020 EFIAPI
LibPcdSetBoolS(IN UINTN TokenNumber,IN BOOLEAN Value)1021 LibPcdSetBoolS (
1022   IN UINTN          TokenNumber,
1023   IN BOOLEAN        Value
1024   )
1025 {
1026   return (GetPcdPpiPointer ())->SetBool (TokenNumber, Value);
1027 }
1028 
1029 /**
1030   This function provides a means by which to set a value for a given PCD token.
1031 
1032   Sets the 8-bit value for the token specified by TokenNumber
1033   to the value specified by Value.
1034 
1035   If Guid is NULL, then ASSERT().
1036 
1037   @param[in] Guid           The pointer to a 128-bit unique value that
1038                             designates which namespace to set a value from.
1039   @param[in] TokenNumber    The PCD token number to set a current value for.
1040   @param[in] Value          The 8-bit value to set.
1041 
1042   @return The status of the set operation.
1043 
1044 **/
1045 RETURN_STATUS
1046 EFIAPI
LibPcdSetEx8S(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT8 Value)1047 LibPcdSetEx8S (
1048   IN CONST GUID     *Guid,
1049   IN UINTN          TokenNumber,
1050   IN UINT8          Value
1051   )
1052 {
1053   ASSERT (Guid != NULL);
1054 
1055   return (GetPiPcdPpiPointer ())->Set8 (Guid, TokenNumber, Value);
1056 }
1057 
1058 /**
1059   This function provides a means by which to set a value for a given PCD token.
1060 
1061   Sets the 16-bit value for the token specified by TokenNumber
1062   to the value specified by Value.
1063 
1064   If Guid is NULL, then ASSERT().
1065 
1066   @param[in] Guid           The pointer to a 128-bit unique value that
1067                             designates which namespace to set a value from.
1068   @param[in] TokenNumber    The PCD token number to set a current value for.
1069   @param[in] Value          The 16-bit value to set.
1070 
1071   @return The status of the set operation.
1072 
1073 **/
1074 RETURN_STATUS
1075 EFIAPI
LibPcdSetEx16S(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT16 Value)1076 LibPcdSetEx16S (
1077   IN CONST GUID     *Guid,
1078   IN UINTN          TokenNumber,
1079   IN UINT16         Value
1080   )
1081 {
1082   ASSERT (Guid != NULL);
1083 
1084   return (GetPiPcdPpiPointer ())->Set16 (Guid, TokenNumber, Value);
1085 }
1086 
1087 /**
1088   This function provides a means by which to set a value for a given PCD token.
1089 
1090   Sets the 32-bit value for the token specified by TokenNumber
1091   to the value specified by Value.
1092 
1093   If Guid is NULL, then ASSERT().
1094 
1095   @param[in] Guid           The pointer to a 128-bit unique value that
1096                             designates which namespace to set a value from.
1097   @param[in] TokenNumber    The PCD token number to set a current value for.
1098   @param[in] Value          The 32-bit value to set.
1099 
1100   @return The status of the set operation.
1101 
1102 **/
1103 RETURN_STATUS
1104 EFIAPI
LibPcdSetEx32S(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT32 Value)1105 LibPcdSetEx32S (
1106   IN CONST GUID     *Guid,
1107   IN UINTN          TokenNumber,
1108   IN UINT32         Value
1109   )
1110 {
1111   ASSERT (Guid != NULL);
1112 
1113   return (GetPiPcdPpiPointer ())->Set32 (Guid, TokenNumber, Value);
1114 }
1115 
1116 /**
1117   This function provides a means by which to set a value for a given PCD token.
1118 
1119   Sets the 64-bit value for the token specified by TokenNumber
1120   to the value specified by Value.
1121 
1122   If Guid is NULL, then ASSERT().
1123 
1124   @param[in] Guid           The pointer to a 128-bit unique value that
1125                             designates which namespace to set a value from.
1126   @param[in] TokenNumber    The PCD token number to set a current value for.
1127   @param[in] Value          The 64-bit value to set.
1128 
1129   @return The status of the set operation.
1130 
1131 **/
1132 RETURN_STATUS
1133 EFIAPI
LibPcdSetEx64S(IN CONST GUID * Guid,IN UINTN TokenNumber,IN UINT64 Value)1134 LibPcdSetEx64S (
1135   IN CONST GUID     *Guid,
1136   IN UINTN          TokenNumber,
1137   IN UINT64         Value
1138   )
1139 {
1140   ASSERT (Guid != NULL);
1141 
1142   return (GetPiPcdPpiPointer ())->Set64 (Guid, TokenNumber, Value);
1143 }
1144 
1145 /**
1146   This function provides a means by which to set a value for a given PCD token.
1147 
1148   Sets a buffer for the token specified by TokenNumber to the value specified by
1149   Buffer and SizeOfBuffer. If SizeOfBuffer is greater than the maximum size
1150   support by TokenNumber, then set SizeOfBuffer to the maximum size supported by
1151   TokenNumber and return EFI_INVALID_PARAMETER to indicate that the set operation
1152   was not actually performed.
1153 
1154   If Guid is NULL, then ASSERT().
1155   If SizeOfBuffer is NULL, then ASSERT().
1156   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1157 
1158   @param[in]      Guid          Pointer to a 128-bit unique value that
1159                                 designates which namespace to set a value from.
1160   @param[in]      TokenNumber   The PCD token number to set a current value for.
1161   @param[in, out] SizeOfBuffer  The size, in bytes, of Buffer.
1162   @param[in]      Buffer        A pointer to the buffer to set.
1163 
1164   @return The status of the set operation.
1165 
1166 **/
1167 RETURN_STATUS
1168 EFIAPI
LibPcdSetExPtrS(IN CONST GUID * Guid,IN UINTN TokenNumber,IN OUT UINTN * SizeOfBuffer,IN VOID * Buffer)1169 LibPcdSetExPtrS (
1170   IN CONST GUID     *Guid,
1171   IN       UINTN    TokenNumber,
1172   IN OUT   UINTN    *SizeOfBuffer,
1173   IN       VOID     *Buffer
1174   )
1175 {
1176   ASSERT (Guid != NULL);
1177 
1178   ASSERT (SizeOfBuffer != NULL);
1179 
1180   if (*SizeOfBuffer > 0) {
1181     ASSERT (Buffer != NULL);
1182   }
1183 
1184   return (GetPiPcdPpiPointer ())->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);
1185 }
1186 
1187 /**
1188   This function provides a means by which to set a value for a given PCD token.
1189 
1190   Sets the boolean value for the token specified by TokenNumber
1191   to the value specified by Value.
1192 
1193   If Guid is NULL, then ASSERT().
1194 
1195   @param[in] Guid           The pointer to a 128-bit unique value that
1196                             designates which namespace to set a value from.
1197   @param[in] TokenNumber    The PCD token number to set a current value for.
1198   @param[in] Value          The boolean value to set.
1199 
1200   @return The status of the set operation.
1201 
1202 **/
1203 RETURN_STATUS
1204 EFIAPI
LibPcdSetExBoolS(IN CONST GUID * Guid,IN UINTN TokenNumber,IN BOOLEAN Value)1205 LibPcdSetExBoolS (
1206   IN CONST GUID     *Guid,
1207   IN UINTN          TokenNumber,
1208   IN BOOLEAN        Value
1209   )
1210 {
1211   ASSERT (Guid != NULL);
1212 
1213   return (GetPiPcdPpiPointer ())->SetBool (Guid, TokenNumber, Value);
1214 }
1215 
1216 /**
1217   Set up a notification function that is called when a specified token is set.
1218 
1219   When the token specified by TokenNumber and Guid is set,
1220   then notification function specified by NotificationFunction is called.
1221   If Guid is NULL, then the default token space is used.
1222   If NotificationFunction is NULL, then ASSERT().
1223 
1224   @param[in]  Guid                  The pointer to a 128-bit unique value that
1225                                     designates which namespace to set a value from.
1226                                     If NULL, then the default token space is used.
1227   @param[in]  TokenNumber           The PCD token number to monitor.
1228   @param[in]  NotificationFunction  The function to call when the token
1229                                     specified by Guid and TokenNumber is set.
1230 
1231 **/
1232 VOID
1233 EFIAPI
LibPcdCallbackOnSet(IN CONST GUID * Guid,OPTIONAL IN UINTN TokenNumber,IN PCD_CALLBACK NotificationFunction)1234 LibPcdCallbackOnSet (
1235   IN CONST GUID               *Guid,       OPTIONAL
1236   IN UINTN                    TokenNumber,
1237   IN PCD_CALLBACK             NotificationFunction
1238   )
1239 {
1240   EFI_STATUS Status;
1241 
1242   ASSERT (NotificationFunction != NULL);
1243 
1244   Status = (GetPiPcdPpiPointer ())->CallbackOnSet (Guid, TokenNumber, (EFI_PEI_PCD_PPI_CALLBACK) NotificationFunction);
1245 
1246   ASSERT_EFI_ERROR (Status);
1247 
1248   return;
1249 }
1250 
1251 
1252 
1253 /**
1254   Disable a notification function that was established with LibPcdCallbackonSet().
1255 
1256   Disable a notification function that was previously established with LibPcdCallbackOnSet().
1257   If NotificationFunction is NULL, then ASSERT().
1258   If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber,
1259   and NotificationFunction, then ASSERT().
1260 
1261   @param[in]  Guid                 Specify the GUID token space.
1262   @param[in]  TokenNumber          Specify the token number.
1263   @param[in]  NotificationFunction The callback function to be unregistered.
1264 
1265 **/
1266 VOID
1267 EFIAPI
LibPcdCancelCallback(IN CONST GUID * Guid,OPTIONAL IN UINTN TokenNumber,IN PCD_CALLBACK NotificationFunction)1268 LibPcdCancelCallback (
1269   IN CONST GUID               *Guid,       OPTIONAL
1270   IN UINTN                    TokenNumber,
1271   IN PCD_CALLBACK             NotificationFunction
1272   )
1273 {
1274   EFI_STATUS Status;
1275 
1276   ASSERT (NotificationFunction != NULL);
1277 
1278   Status = (GetPiPcdPpiPointer ())->CancelCallback (Guid, TokenNumber, (EFI_PEI_PCD_PPI_CALLBACK) NotificationFunction);
1279 
1280   ASSERT_EFI_ERROR (Status);
1281 
1282   return;
1283 }
1284 
1285 
1286 
1287 /**
1288   Retrieves the next token in a token space.
1289 
1290   Retrieves the next PCD token number from the token space specified by Guid.
1291   If Guid is NULL, then the default token space is used.  If TokenNumber is 0,
1292   then the first token number is returned.  Otherwise, the token number that
1293   follows TokenNumber in the token space is returned.  If TokenNumber is the last
1294   token number in the token space, then 0 is returned.
1295 
1296   If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().
1297 
1298   @param[in]  Guid        The pointer to a 128-bit unique value that designates which namespace
1299                           to set a value from.  If NULL, then the default token space is used.
1300   @param[in]  TokenNumber The previous PCD token number.  If 0, then retrieves the first PCD
1301                           token number.
1302 
1303   @return The next valid token number.
1304 
1305 **/
1306 UINTN
1307 EFIAPI
LibPcdGetNextToken(IN CONST GUID * Guid,OPTIONAL IN UINTN TokenNumber)1308 LibPcdGetNextToken (
1309   IN CONST GUID               *Guid,       OPTIONAL
1310   IN UINTN                    TokenNumber
1311   )
1312 {
1313   EFI_STATUS    Status;
1314 
1315   Status = (GetPiPcdPpiPointer ())->GetNextToken (Guid, &TokenNumber);
1316   ASSERT (!EFI_ERROR (Status) || TokenNumber == 0);
1317 
1318   return TokenNumber;
1319 }
1320 
1321 
1322 /**
1323   Used to retrieve the list of available PCD token space GUIDs.
1324 
1325   Returns the PCD token space GUID that follows TokenSpaceGuid in the list of token spaces
1326   in the platform.
1327   If TokenSpaceGuid is NULL, then a pointer to the first PCD token spaces returned.
1328   If TokenSpaceGuid is the last PCD token space GUID in the list, then NULL is returned.
1329 
1330   @param  TokenSpaceGuid  The pointer to the a PCD token space GUID
1331 
1332   @return The next valid token namespace.
1333 
1334 **/
1335 GUID *
1336 EFIAPI
LibPcdGetNextTokenSpace(IN CONST GUID * TokenSpaceGuid)1337 LibPcdGetNextTokenSpace (
1338   IN CONST GUID  *TokenSpaceGuid
1339   )
1340 {
1341   (GetPiPcdPpiPointer ())->GetNextTokenSpace (&TokenSpaceGuid);
1342 
1343   return (GUID *) TokenSpaceGuid;
1344 }
1345 
1346 
1347 
1348 /**
1349   Sets a value of a patchable PCD entry that is type pointer.
1350 
1351   Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1352   and SizeOfBuffer.  Buffer is returned.  If SizeOfBuffer is greater than
1353   MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
1354   NULL to indicate that the set operation was not actually performed.
1355   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1356   MaximumDatumSize and NULL must be returned.
1357 
1358   If PatchVariable is NULL, then ASSERT().
1359   If SizeOfBuffer is NULL, then ASSERT().
1360   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1361 
1362   @param[out] PatchVariable     A pointer to the global variable in a module that is
1363                                 the target of the set operation.
1364   @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.
1365   @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.
1366   @param[in] Buffer             A pointer to the buffer to used to set the target variable.
1367 
1368   @return Return the pointer to the buffer been set.
1369 
1370 **/
1371 VOID *
1372 EFIAPI
LibPatchPcdSetPtr(OUT VOID * PatchVariable,IN UINTN MaximumDatumSize,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)1373 LibPatchPcdSetPtr (
1374   OUT       VOID        *PatchVariable,
1375   IN        UINTN       MaximumDatumSize,
1376   IN OUT    UINTN       *SizeOfBuffer,
1377   IN CONST  VOID        *Buffer
1378   )
1379 {
1380   ASSERT (PatchVariable != NULL);
1381   ASSERT (SizeOfBuffer  != NULL);
1382 
1383   if (*SizeOfBuffer > 0) {
1384     ASSERT (Buffer != NULL);
1385   }
1386 
1387   if ((*SizeOfBuffer > MaximumDatumSize) ||
1388       (*SizeOfBuffer == MAX_ADDRESS)) {
1389     *SizeOfBuffer = MaximumDatumSize;
1390     return NULL;
1391   }
1392 
1393   CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1394 
1395   return (VOID *) Buffer;
1396 }
1397 
1398 /**
1399   Sets a value of a patchable PCD entry that is type pointer.
1400 
1401   Sets the PCD entry specified by PatchVariable to the value specified
1402   by Buffer and SizeOfBuffer. If SizeOfBuffer is greater than MaximumDatumSize,
1403   then set SizeOfBuffer to MaximumDatumSize and return RETURN_INVALID_PARAMETER
1404   to indicate that the set operation was not actually performed.
1405   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1406   MaximumDatumSize and RETURN_INVALID_PARAMETER must be returned.
1407 
1408   If PatchVariable is NULL, then ASSERT().
1409   If SizeOfBuffer is NULL, then ASSERT().
1410   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1411 
1412   @param[out] PatchVariable     A pointer to the global variable in a module that is
1413                                 the target of the set operation.
1414   @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.
1415   @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.
1416   @param[in] Buffer             A pointer to the buffer to used to set the target variable.
1417 
1418   @return The status of the set operation.
1419 
1420 **/
1421 RETURN_STATUS
1422 EFIAPI
LibPatchPcdSetPtrS(OUT VOID * PatchVariable,IN UINTN MaximumDatumSize,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)1423 LibPatchPcdSetPtrS (
1424   OUT      VOID     *PatchVariable,
1425   IN       UINTN    MaximumDatumSize,
1426   IN OUT   UINTN    *SizeOfBuffer,
1427   IN CONST VOID     *Buffer
1428   )
1429 {
1430   ASSERT (PatchVariable != NULL);
1431   ASSERT (SizeOfBuffer  != NULL);
1432 
1433   if (*SizeOfBuffer > 0) {
1434     ASSERT (Buffer != NULL);
1435   }
1436 
1437   if ((*SizeOfBuffer > MaximumDatumSize) ||
1438       (*SizeOfBuffer == MAX_ADDRESS)) {
1439     *SizeOfBuffer = MaximumDatumSize;
1440     return RETURN_INVALID_PARAMETER;
1441   }
1442 
1443   CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1444 
1445   return RETURN_SUCCESS;
1446 }
1447 
1448 
1449 /**
1450   Sets a value and size of a patchable PCD entry that is type pointer.
1451 
1452   Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1453   and SizeOfBuffer.  Buffer is returned.  If SizeOfBuffer is greater than
1454   MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
1455   NULL to indicate that the set operation was not actually performed.
1456   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1457   MaximumDatumSize and NULL must be returned.
1458 
1459   If PatchVariable is NULL, then ASSERT().
1460   If SizeOfPatchVariable is NULL, then ASSERT().
1461   If SizeOfBuffer is NULL, then ASSERT().
1462   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1463 
1464   @param[out] PatchVariable     A pointer to the global variable in a module that is
1465                                 the target of the set operation.
1466   @param[out] SizeOfPatchVariable A pointer to the size, in bytes, of PatchVariable.
1467   @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.
1468   @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.
1469   @param[in] Buffer             A pointer to the buffer to used to set the target variable.
1470 
1471   @return Return the pointer to the buffer been set.
1472 
1473 **/
1474 VOID *
1475 EFIAPI
LibPatchPcdSetPtrAndSize(OUT VOID * PatchVariable,OUT UINTN * SizeOfPatchVariable,IN UINTN MaximumDatumSize,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)1476 LibPatchPcdSetPtrAndSize (
1477   OUT       VOID        *PatchVariable,
1478   OUT       UINTN       *SizeOfPatchVariable,
1479   IN        UINTN       MaximumDatumSize,
1480   IN OUT    UINTN       *SizeOfBuffer,
1481   IN CONST  VOID        *Buffer
1482   )
1483 {
1484   ASSERT (PatchVariable != NULL);
1485   ASSERT (SizeOfPatchVariable != NULL);
1486   ASSERT (SizeOfBuffer  != NULL);
1487 
1488   if (*SizeOfBuffer > 0) {
1489     ASSERT (Buffer != NULL);
1490   }
1491 
1492   if ((*SizeOfBuffer > MaximumDatumSize) ||
1493       (*SizeOfBuffer == MAX_ADDRESS)) {
1494     *SizeOfBuffer = MaximumDatumSize;
1495     return NULL;
1496   }
1497 
1498   CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1499   *SizeOfPatchVariable = *SizeOfBuffer;
1500 
1501   return (VOID *) Buffer;
1502 }
1503 
1504 /**
1505   Sets a value and size of a patchable PCD entry that is type pointer.
1506 
1507   Sets the PCD entry specified by PatchVariable to the value specified
1508   by Buffer and SizeOfBuffer. If SizeOfBuffer is greater than MaximumDatumSize,
1509   then set SizeOfBuffer to MaximumDatumSize and return RETURN_INVALID_PARAMETER
1510   to indicate that the set operation was not actually performed.
1511   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1512   MaximumDatumSize and RETURN_INVALID_PARAMETER must be returned.
1513 
1514   If PatchVariable is NULL, then ASSERT().
1515   If SizeOfPatchVariable is NULL, then ASSERT().
1516   If SizeOfBuffer is NULL, then ASSERT().
1517   If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1518 
1519   @param[out] PatchVariable     A pointer to the global variable in a module that is
1520                                 the target of the set operation.
1521   @param[out] SizeOfPatchVariable A pointer to the size, in bytes, of PatchVariable.
1522   @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.
1523   @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.
1524   @param[in] Buffer             A pointer to the buffer to used to set the target variable.
1525 
1526   @return The status of the set operation.
1527 
1528 **/
1529 RETURN_STATUS
1530 EFIAPI
LibPatchPcdSetPtrAndSizeS(OUT VOID * PatchVariable,OUT UINTN * SizeOfPatchVariable,IN UINTN MaximumDatumSize,IN OUT UINTN * SizeOfBuffer,IN CONST VOID * Buffer)1531 LibPatchPcdSetPtrAndSizeS (
1532   OUT      VOID     *PatchVariable,
1533   OUT      UINTN    *SizeOfPatchVariable,
1534   IN       UINTN    MaximumDatumSize,
1535   IN OUT   UINTN    *SizeOfBuffer,
1536   IN CONST VOID     *Buffer
1537   )
1538 {
1539   ASSERT (PatchVariable != NULL);
1540   ASSERT (SizeOfPatchVariable != NULL);
1541   ASSERT (SizeOfBuffer  != NULL);
1542 
1543   if (*SizeOfBuffer > 0) {
1544     ASSERT (Buffer != NULL);
1545   }
1546 
1547   if ((*SizeOfBuffer > MaximumDatumSize) ||
1548       (*SizeOfBuffer == MAX_ADDRESS)) {
1549     *SizeOfBuffer = MaximumDatumSize;
1550     return RETURN_INVALID_PARAMETER;
1551   }
1552 
1553   CopyMem (PatchVariable, Buffer, *SizeOfBuffer);
1554   *SizeOfPatchVariable = *SizeOfBuffer;
1555 
1556   return RETURN_SUCCESS;
1557 }
1558 
1559 /**
1560   Retrieve additional information associated with a PCD token.
1561 
1562   This includes information such as the type of value the TokenNumber is associated with as well as possible
1563   human readable name that is associated with the token.
1564 
1565   If TokenNumber is not in the default token space specified, then ASSERT().
1566 
1567   @param[in]    TokenNumber The PCD token number.
1568   @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.
1569                             The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
1570 **/
1571 VOID
1572 EFIAPI
LibPcdGetInfo(IN UINTN TokenNumber,OUT PCD_INFO * PcdInfo)1573 LibPcdGetInfo (
1574   IN        UINTN           TokenNumber,
1575   OUT       PCD_INFO        *PcdInfo
1576   )
1577 {
1578   EFI_STATUS Status;
1579 
1580   Status = GetPcdInfoPpiPointer()->GetInfo (TokenNumber, (EFI_PCD_INFO *) PcdInfo);
1581   ASSERT_EFI_ERROR (Status);
1582 }
1583 
1584 /**
1585   Retrieve additional information associated with a PCD token.
1586 
1587   This includes information such as the type of value the TokenNumber is associated with as well as possible
1588   human readable name that is associated with the token.
1589 
1590   If TokenNumber is not in the token space specified by Guid, then ASSERT().
1591 
1592   @param[in]    Guid        The 128-bit unique value that designates the namespace from which to extract the value.
1593   @param[in]    TokenNumber The PCD token number.
1594   @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.
1595                             The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
1596 **/
1597 VOID
1598 EFIAPI
LibPcdGetInfoEx(IN CONST GUID * Guid,IN UINTN TokenNumber,OUT PCD_INFO * PcdInfo)1599 LibPcdGetInfoEx (
1600   IN CONST  GUID            *Guid,
1601   IN        UINTN           TokenNumber,
1602   OUT       PCD_INFO        *PcdInfo
1603   )
1604 {
1605   EFI_STATUS Status;
1606 
1607   Status = GetPiPcdInfoPpiPointer()->GetInfo (Guid, TokenNumber, (EFI_PCD_INFO *) PcdInfo);
1608   ASSERT_EFI_ERROR (Status);
1609 }
1610 
1611 /**
1612   Retrieve the currently set SKU Id.
1613 
1614   @return   The currently set SKU Id. If the platform has not set at a SKU Id, then the
1615             default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU
1616             Id is returned.
1617 **/
1618 UINTN
1619 EFIAPI
LibPcdGetSku(VOID)1620 LibPcdGetSku (
1621   VOID
1622   )
1623 {
1624   return GetPiPcdInfoPpiPointer()->GetSku ();
1625 }
1626