]> git.proxmox.com Git - mirror_edk2.git/blame - 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
e386b444 1/** @file\r
2Implementation of PcdLib class library for DXE phase.\r
3\r
419db80b 4Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
19388d29 5This program and the accompanying materials \r
e386b444 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
e386b444 14**/\r
15\r
c892d846 16\r
c7d265a9 17#include <PiDxe.h>\r
c892d846 18\r
c7d265a9 19#include <Protocol/Pcd.h>\r
ec735bb2 20#include <Protocol/PiPcd.h>\r
96d6d004
SZ
21#include <Protocol/PcdInfo.h>\r
22#include <Protocol/PiPcdInfo.h>\r
c892d846 23\r
c7d265a9 24#include <Library/PcdLib.h>\r
25#include <Library/DebugLib.h>\r
26#include <Library/UefiBootServicesTableLib.h>\r
27#include <Library/BaseMemoryLib.h>\r
e386b444 28\r
96d6d004
SZ
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
e386b444 33\r
25366245 34/**\r
b35a5f73 35 Retrieves the PI PCD protocol from the handle database.\r
96d6d004
SZ
36\r
37 @retval EFI_PCD_PROTOCOL * The pointer to the EFI_PCD_PROTOCOL.\r
b35a5f73 38**/\r
39EFI_PCD_PROTOCOL *\r
40EFIAPI\r
41GetPiPcdProtocol (\r
42 VOID\r
43 )\r
44{\r
45 EFI_STATUS Status;\r
a3ac242b 46\r
b35a5f73 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
e386b444 58\r
b35a5f73 59/**\r
60 Retrieves the PCD protocol from the handle database.\r
96d6d004
SZ
61\r
62 @retval PCD_PROTOCOL * The pointer to the PCD_PROTOCOL.\r
e386b444 63**/\r
b35a5f73 64PCD_PROTOCOL *\r
25366245 65EFIAPI\r
b35a5f73 66GetPcdProtocol (\r
67 VOID\r
e386b444 68 )\r
69{\r
70 EFI_STATUS Status;\r
71\r
b35a5f73 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
e386b444 82}\r
83\r
96d6d004
SZ
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
e386b444 123\r
124/**\r
518db1d9 125 This function provides a means by which SKU support can be established in the PCD infrastructure.\r
126\r
e386b444 127 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.\r
c00bdbb1 128 If SkuId >= PCD_MAX_SKU_ID, then ASSERT(). \r
518db1d9 129\r
c00bdbb1 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
e386b444 132\r
c00bdbb1 133 @return Return the SKU ID that just be set.\r
e386b444 134\r
135**/\r
136UINTN\r
137EFIAPI\r
138LibPcdSetSku (\r
518db1d9 139 IN UINTN SkuId\r
e386b444 140 )\r
141{\r
ef64f703 142 ASSERT (SkuId < PCD_MAX_SKU_ID);\r
e386b444 143\r
b35a5f73 144 GetPcdProtocol()->SetSku (SkuId);\r
e386b444 145\r
146 return SkuId;\r
147}\r
148\r
149\r
150\r
151/**\r
518db1d9 152 This function provides a means by which to retrieve a value for a given PCD token.\r
153 \r
e386b444 154 Returns the 8-bit value for the token specified by TokenNumber. \r
155\r
518db1d9 156 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
e386b444 157\r
f73e0ad2 158 @return Returns the 8-bit value for the token specified by TokenNumber. \r
e386b444 159\r
160**/\r
161UINT8\r
162EFIAPI\r
163LibPcdGet8 (\r
164 IN UINTN TokenNumber\r
165 )\r
166{\r
b35a5f73 167 return GetPcdProtocol()->Get8 (TokenNumber);\r
e386b444 168}\r
169\r
170\r
171\r
172/**\r
518db1d9 173 This function provides a means by which to retrieve a value for a given PCD token.\r
174 \r
e386b444 175 Returns the 16-bit value for the token specified by TokenNumber. \r
176\r
518db1d9 177 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
e386b444 178\r
f73e0ad2 179 @return Returns the 16-bit value for the token specified by TokenNumber. \r
e386b444 180\r
181**/\r
182UINT16\r
183EFIAPI\r
184LibPcdGet16 (\r
185 IN UINTN TokenNumber\r
186 )\r
187{\r
b35a5f73 188 return GetPcdProtocol()->Get16 (TokenNumber);\r
e386b444 189}\r
190\r
191\r
192\r
193/**\r
518db1d9 194 This function provides a means by which to retrieve a value for a given PCD token.\r
195 \r
e386b444 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
f73e0ad2 200 @return Returns the 32-bit value for the token specified by TokenNumber.\r
e386b444 201\r
202**/\r
203UINT32\r
204EFIAPI\r
205LibPcdGet32 (\r
206 IN UINTN TokenNumber\r
207 )\r
208{\r
b35a5f73 209 return GetPcdProtocol()->Get32 (TokenNumber);\r
e386b444 210}\r
211\r
212\r
213\r
214/**\r
518db1d9 215 This function provides a means by which to retrieve a value for a given PCD token.\r
216 \r
e386b444 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
f73e0ad2 221 @return Returns the 64-bit value for the token specified by TokenNumber.\r
e386b444 222\r
223**/\r
224UINT64\r
225EFIAPI\r
226LibPcdGet64 (\r
227 IN UINTN TokenNumber\r
228 )\r
229{\r
b35a5f73 230 return GetPcdProtocol()->Get64 (TokenNumber);\r
e386b444 231}\r
232\r
233\r
234\r
235/**\r
518db1d9 236 This function provides a means by which to retrieve a value for a given PCD token.\r
237 \r
e386b444 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
f73e0ad2 242 @return Returns the pointer to the token specified by TokenNumber.\r
e386b444 243\r
244**/\r
245VOID *\r
246EFIAPI\r
247LibPcdGetPtr (\r
248 IN UINTN TokenNumber\r
249 )\r
250{\r
b35a5f73 251 return GetPcdProtocol()->GetPtr (TokenNumber);\r
e386b444 252}\r
253\r
254\r
255\r
256/**\r
518db1d9 257 This function provides a means by which to retrieve a value for a given PCD token.\r
258 \r
e386b444 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
f73e0ad2 263 @return Returns the Boolean value of the token specified by TokenNumber. \r
e386b444 264\r
265**/\r
266BOOLEAN \r
267EFIAPI\r
268LibPcdGetBool (\r
269 IN UINTN TokenNumber\r
270 )\r
271{\r
b35a5f73 272 return GetPcdProtocol()->GetBool (TokenNumber);\r
e386b444 273}\r
274\r
275\r
276\r
277/**\r
518db1d9 278 This function provides a means by which to retrieve the size of a given PCD token.\r
e386b444 279\r
280 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
281\r
f73e0ad2 282 @return Returns the size of the token specified by TokenNumber. \r
e386b444 283\r
284**/\r
285UINTN\r
286EFIAPI\r
287LibPcdGetSize (\r
288 IN UINTN TokenNumber\r
289 )\r
290{\r
b35a5f73 291 return GetPcdProtocol()->GetSize (TokenNumber);\r
e386b444 292}\r
293\r
294\r
295\r
296/**\r
518db1d9 297 This function provides a means by which to retrieve a value for a given PCD token.\r
298 \r
e386b444 299 Returns the 8-bit value for the token specified by TokenNumber and Guid.\r
518db1d9 300 \r
e386b444 301 If Guid is NULL, then ASSERT(). \r
302\r
2fc59a00 303 @param[in] Guid The pointer to a 128-bit unique value that designates \r
c00bdbb1 304 which namespace to retrieve a value from.\r
305 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
e386b444 306\r
f73e0ad2 307 @return Return the UINT8.\r
e386b444 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
b35a5f73 319 return GetPiPcdProtocol()->Get8 (Guid, TokenNumber);\r
e386b444 320}\r
321\r
322\r
323/**\r
518db1d9 324 This function provides a means by which to retrieve a value for a given PCD token.\r
325\r
e386b444 326 Returns the 16-bit value for the token specified by TokenNumber and Guid.\r
518db1d9 327 \r
e386b444 328 If Guid is NULL, then ASSERT(). \r
329\r
2fc59a00 330 @param[in] Guid The pointer to a 128-bit unique value that designates \r
c00bdbb1 331 which namespace to retrieve a value from.\r
332 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
e386b444 333\r
f73e0ad2 334 @return Return the UINT16.\r
e386b444 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
b35a5f73 346 return GetPiPcdProtocol()->Get16 (Guid, TokenNumber);\r
e386b444 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
2fc59a00 354 @param[in] Guid The pointer to a 128-bit unique value that designates \r
c00bdbb1 355 which namespace to retrieve a value from.\r
356 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
e386b444 357\r
f73e0ad2 358 @return Return the UINT32.\r
e386b444 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
b35a5f73 370 return GetPiPcdProtocol()->Get32 (Guid, TokenNumber);\r
e386b444 371}\r
372\r
373\r
374\r
375/**\r
518db1d9 376 This function provides a means by which to retrieve a value for a given PCD token.\r
377 \r
e386b444 378 Returns the 64-bit value for the token specified by TokenNumber and Guid.\r
518db1d9 379 \r
e386b444 380 If Guid is NULL, then ASSERT(). \r
381\r
2fc59a00 382 @param[in] Guid The pointer to a 128-bit unique value that designates \r
518db1d9 383 which namespace to retrieve a value from.\r
384 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
e386b444 385\r
f73e0ad2 386 @return Return the UINT64.\r
e386b444 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
b35a5f73 398 return GetPiPcdProtocol()->Get64 (Guid, TokenNumber);\r
e386b444 399}\r
400\r
401\r
402\r
403/**\r
518db1d9 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
e386b444 408 If Guid is NULL, then ASSERT(). \r
409\r
2fc59a00 410 @param[in] Guid The pointer to a 128-bit unique value that designates \r
518db1d9 411 which namespace to retrieve a value from.\r
412 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
e386b444 413\r
f73e0ad2 414 @return Return the VOID* pointer.\r
e386b444 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
b35a5f73 426 return GetPiPcdProtocol()->GetPtr (Guid, TokenNumber);\r
e386b444 427}\r
428\r
429\r
430\r
431/**\r
518db1d9 432 This function provides a means by which to retrieve a value for a given PCD token.\r
433 \r
e386b444 434 Returns the Boolean value of the token specified by TokenNumber and Guid. \r
518db1d9 435 \r
e386b444 436 If Guid is NULL, then ASSERT(). \r
437\r
2fc59a00 438 @param[in] Guid The pointer to a 128-bit unique value that designates \r
518db1d9 439 which namespace to retrieve a value from.\r
440 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
e386b444 441\r
f73e0ad2 442 @return Return the BOOLEAN.\r
e386b444 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
b35a5f73 454 return GetPiPcdProtocol()->GetBool (Guid, TokenNumber);\r
e386b444 455}\r
456\r
457\r
458\r
459/**\r
518db1d9 460 This function provides a means by which to retrieve the size of a given PCD token.\r
461 \r
e386b444 462 Returns the size of the token specified by TokenNumber and Guid. \r
518db1d9 463 \r
e386b444 464 If Guid is NULL, then ASSERT(). \r
465\r
2fc59a00 466 @param[in] Guid The pointer to a 128-bit unique value that designates \r
518db1d9 467 which namespace to retrieve a value from.\r
468 @param[in] TokenNumber The PCD token number to retrieve a current value for.\r
e386b444 469\r
f73e0ad2 470 @return Return the size.\r
e386b444 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
b35a5f73 482 return GetPiPcdProtocol()->GetSize (Guid, TokenNumber);\r
e386b444 483}\r
484\r
485\r
486\r
487/**\r
518db1d9 488 This function provides a means by which to set a value for a given PCD token.\r
489 \r
e386b444 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
518db1d9 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
e386b444 495\r
58380e9c 496 @return Return the value that was set.\r
e386b444 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
b35a5f73 508 Status = GetPcdProtocol()->Set8 (TokenNumber, Value);\r
e386b444 509 ASSERT_EFI_ERROR (Status);\r
510 \r
511 return Value;\r
512}\r
513\r
514\r
515\r
516/**\r
518db1d9 517 This function provides a means by which to set a value for a given PCD token.\r
518 \r
e386b444 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
518db1d9 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
e386b444 524\r
58380e9c 525 @return Return the value that was set.\r
e386b444 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
b35a5f73 537 Status = GetPcdProtocol()->Set16 (TokenNumber, Value);\r
e386b444 538 ASSERT_EFI_ERROR (Status);\r
539 \r
540 return Value;\r
541}\r
542\r
543\r
544\r
545/**\r
518db1d9 546 This function provides a means by which to set a value for a given PCD token.\r
547 \r
e386b444 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
518db1d9 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
e386b444 553\r
58380e9c 554 @return Return the value that was set.\r
e386b444 555\r
556**/\r
557UINT32\r
558EFIAPI\r
559LibPcdSet32 (\r
560 IN UINTN TokenNumber,\r
518db1d9 561 IN UINT32 Value\r
e386b444 562 )\r
563{\r
564 EFI_STATUS Status;\r
ec735bb2 565 \r
b35a5f73 566 Status = GetPcdProtocol()->Set32 (TokenNumber, Value);\r
e386b444 567 ASSERT_EFI_ERROR (Status);\r
568\r
569 return Value;\r
570}\r
571\r
572\r
573\r
574/**\r
518db1d9 575 This function provides a means by which to set a value for a given PCD token.\r
576 \r
e386b444 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
518db1d9 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
e386b444 582\r
58380e9c 583 @return Return the value that was set.\r
e386b444 584\r
585**/\r
586UINT64\r
587EFIAPI\r
588LibPcdSet64 (\r
589 IN UINTN TokenNumber,\r
518db1d9 590 IN UINT64 Value\r
e386b444 591 )\r
592{\r
593 EFI_STATUS Status;\r
594\r
b35a5f73 595 Status = GetPcdProtocol()->Set64 (TokenNumber, Value);\r
e386b444 596 ASSERT_EFI_ERROR (Status);\r
597\r
598 return Value;\r
599}\r
600\r
601\r
602\r
603/**\r
518db1d9 604 This function provides a means by which to set a value for a given PCD token.\r
e386b444 605 \r
518db1d9 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
e386b444 614 \r
518db1d9 615 If SizeOfBuffer is NULL, then ASSERT().\r
71f36e0f 616 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().\r
e386b444 617 \r
2a254b90 618 @param[in] TokenNumber The PCD token number to set a current value for.\r
63e4dba9 619 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.\r
2a254b90 620 @param[in] Buffer A pointer to the buffer to set.\r
e386b444 621\r
f73e0ad2 622 @return Return the pointer for the buffer been set.\r
e386b444 623\r
624**/\r
e386b444 625VOID *\r
626EFIAPI\r
627LibPcdSetPtr (\r
64735d24 628 IN UINTN TokenNumber,\r
629 IN OUT UINTN *SizeOfBuffer,\r
b52f6a1a 630 IN CONST VOID *Buffer\r
e386b444 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
b35a5f73 641 Status = GetPcdProtocol()->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);\r
e386b444 642 if (EFI_ERROR (Status)) {\r
643 return NULL;\r
644 }\r
645\r
b35a5f73 646 return (VOID *)Buffer;\r
e386b444 647}\r
648\r
649\r
650\r
651/**\r
518db1d9 652 This function provides a means by which to set a value for a given PCD token.\r
653 \r
e386b444 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
518db1d9 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
e386b444 659\r
58380e9c 660 @return Return the value that was set.\r
e386b444 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
b35a5f73 672 Status = GetPcdProtocol()->SetBool (TokenNumber, Value);\r
e386b444 673 ASSERT_EFI_ERROR (Status);\r
674\r
675 return Value;\r
676}\r
677\r
678\r
679\r
680/**\r
518db1d9 681 This function provides a means by which to set a value for a given PCD token.\r
682 \r
e386b444 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
518db1d9 685 \r
e386b444 686 If Guid is NULL, then ASSERT().\r
687 \r
2fc59a00 688 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 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
e386b444 692\r
58380e9c 693 @return Return the value that was set.\r
e386b444 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
b35a5f73 708 Status = GetPiPcdProtocol()->Set8 (Guid, TokenNumber, Value);\r
e386b444 709 ASSERT_EFI_ERROR (Status);\r
710\r
711 return Value;\r
712}\r
713\r
714\r
715\r
716/**\r
518db1d9 717 This function provides a means by which to set a value for a given PCD token.\r
718 \r
e386b444 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
518db1d9 721 \r
e386b444 722 If Guid is NULL, then ASSERT().\r
723 \r
2fc59a00 724 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 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
e386b444 728\r
58380e9c 729 @return Return the value that was set.\r
e386b444 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
b35a5f73 744 Status = GetPiPcdProtocol()->Set16 (Guid, TokenNumber, Value);\r
e386b444 745 ASSERT_EFI_ERROR (Status);\r
746\r
747 return Value;\r
748}\r
749\r
750\r
751\r
752/**\r
518db1d9 753 This function provides a means by which to set a value for a given PCD token.\r
754 \r
e386b444 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
518db1d9 757 \r
e386b444 758 If Guid is NULL, then ASSERT().\r
759 \r
2fc59a00 760 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 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
e386b444 764\r
58380e9c 765 @return Return the value that was set.\r
e386b444 766\r
767**/\r
768UINT32\r
769EFIAPI\r
770LibPcdSetEx32 (\r
771 IN CONST GUID *Guid,\r
772 IN UINTN TokenNumber,\r
518db1d9 773 IN UINT32 Value\r
e386b444 774 )\r
775{\r
776 EFI_STATUS Status;\r
777\r
778 ASSERT (Guid != NULL);\r
779\r
b35a5f73 780 Status = GetPiPcdProtocol()->Set32 (Guid, TokenNumber, Value);\r
e386b444 781 ASSERT_EFI_ERROR (Status);\r
782\r
783 return Value;\r
784}\r
785\r
786\r
787\r
788/**\r
518db1d9 789 This function provides a means by which to set a value for a given PCD token.\r
790 \r
e386b444 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
2fc59a00 795 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 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
e386b444 799\r
58380e9c 800 @return Return the value that was set.\r
e386b444 801\r
802**/\r
803UINT64\r
804EFIAPI\r
805LibPcdSetEx64 (\r
806 IN CONST GUID *Guid,\r
807 IN UINTN TokenNumber,\r
518db1d9 808 IN UINT64 Value\r
e386b444 809 )\r
810{\r
811 EFI_STATUS Status;\r
812\r
813 ASSERT (Guid != NULL);\r
814\r
b35a5f73 815 Status = GetPiPcdProtocol()->Set64 (Guid, TokenNumber, Value);\r
e386b444 816 ASSERT_EFI_ERROR (Status);\r
817\r
818 return Value;\r
819}\r
820\r
821\r
822\r
823/**\r
518db1d9 824 This function provides a means by which to set a value for a given PCD token.\r
825 \r
e386b444 826 Sets a buffer for the token specified by TokenNumber to the value specified by \r
ef64f703 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
e386b444 829 supported by TokenNumber and return NULL to indicate that the set operation \r
830 was not actually performed. \r
831 \r
518db1d9 832 If Guid is NULL, then ASSERT().\r
833 If SizeOfBuffer is NULL, then ASSERT().\r
ef64f703 834 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().\r
e386b444 835 \r
2fc59a00 836 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 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
e386b444 841\r
b35a5f73 842 @return Return the pointer to the buffer been set.\r
e386b444 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
b35a5f73 864 Status = GetPiPcdProtocol()->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);\r
e386b444 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
518db1d9 875 This function provides a means by which to set a value for a given PCD token.\r
876 \r
e386b444 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
518db1d9 879 \r
e386b444 880 If Guid is NULL, then ASSERT().\r
881 \r
2fc59a00 882 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 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
e386b444 886\r
58380e9c 887 @return Return the value that was set.\r
e386b444 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
b35a5f73 902 Status = GetPiPcdProtocol()->SetBool (Guid, TokenNumber, Value);\r
e386b444 903 ASSERT_EFI_ERROR (Status);\r
904\r
905 return Value;\r
906}\r
907\r
908\r
909\r
910/**\r
518db1d9 911 Set up a notification function that is called when a specified token is set.\r
912 \r
e386b444 913 When the token specified by TokenNumber and Guid is set, \r
914 then notification function specified by NotificationFunction is called. \r
c00bdbb1 915 If Guid is NULL, then the default token space is used.\r
518db1d9 916 If NotificationFunction is NULL, then ASSERT().\r
917\r
2fc59a00 918 @param[in] Guid The pointer to a 128-bit unique value that designates which \r
c00bdbb1 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
518db1d9 922 @param[in] NotificationFunction The function to call when the token \r
923 specified by Guid and TokenNumber is set.\r
924\r
e386b444 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
b35a5f73 938 Status = GetPiPcdProtocol()->CallbackOnSet (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);\r
e386b444 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
518db1d9 948 \r
c00bdbb1 949 Disable a notification function that was previously established with LibPcdCallbackOnSet().\r
e386b444 950 If NotificationFunction is NULL, then ASSERT().\r
518db1d9 951 If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber, \r
952 and NotificationFunction, then ASSERT().\r
ef64f703 953 \r
c00bdbb1 954 @param[in] Guid Specify the GUID token space.\r
955 @param[in] TokenNumber Specify the token number.\r
e386b444 956 @param[in] NotificationFunction The callback function to be unregistered.\r
957\r
e386b444 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
b35a5f73 971 Status = GetPiPcdProtocol()->CancelCallback (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);\r
e386b444 972 ASSERT_EFI_ERROR (Status);\r
973\r
974 return;\r
975}\r
976\r
977\r
978\r
979/**\r
518db1d9 980 Retrieves the next token in a token space.\r
981 \r
e386b444 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
518db1d9 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
e386b444 989\r
2fc59a00 990 @param[in] Guid The pointer to a 128-bit unique value that designates which namespace \r
2a254b90 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
e386b444 994\r
f73e0ad2 995 @return The next valid token number.\r
e386b444 996\r
997**/\r
518db1d9 998UINTN \r
e386b444 999EFIAPI\r
1000LibPcdGetNextToken (\r
518db1d9 1001 IN CONST GUID *Guid, OPTIONAL\r
1002 IN UINTN TokenNumber\r
e386b444 1003 )\r
1004{\r
da660118
SZ
1005 EFI_STATUS Status;\r
1006\r
1007 Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);\r
1008 ASSERT (!EFI_ERROR (Status) || TokenNumber == 0);\r
e386b444 1009\r
1010 return TokenNumber;\r
1011}\r
1012\r
1013\r
1014\r
1015/**\r
64735d24 1016 Used to retrieve the list of available PCD token space GUIDs.\r
1017 \r
c00bdbb1 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
e386b444 1022 \r
58380e9c 1023 @param TokenSpaceGuid The pointer to the a PCD token space GUID.\r
e386b444 1024\r
f73e0ad2 1025 @return The next valid token namespace.\r
e386b444 1026\r
1027**/\r
c00bdbb1 1028GUID *\r
e386b444 1029EFIAPI\r
1030LibPcdGetNextTokenSpace (\r
64735d24 1031 IN CONST GUID *TokenSpaceGuid\r
e386b444 1032 )\r
1033{\r
419db80b 1034 GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid);\r
e386b444 1035\r
b35a5f73 1036 return (GUID *)TokenSpaceGuid;\r
e386b444 1037}\r
1038\r
1039\r
1040/**\r
518db1d9 1041 Sets a value of a patchable PCD entry that is type pointer.\r
1042 \r
e386b444 1043 Sets the PCD entry specified by PatchVariable to the value specified by Buffer \r
ef64f703 1044 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than \r
1045 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return \r
e386b444 1046 NULL to indicate that the set operation was not actually performed. \r
ef64f703 1047 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to \r
e386b444 1048 MaximumDatumSize and NULL must be returned.\r
1049 \r
1050 If PatchVariable is NULL, then ASSERT().\r
ef64f703 1051 If SizeOfBuffer is NULL, then ASSERT().\r
1052 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().\r
e386b444 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
518db1d9 1059 \r
9638ba6d 1060 @return Return the pointer to the buffer been set.\r
518db1d9 1061\r
e386b444 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
96d6d004
SZ
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
e386b444 1097\r
96d6d004
SZ
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
e386b444 1164\r