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