]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxePcdLib/DxePcdLib.c
MdePkg PcdLib: Except for SizeOfBuffer is greater than the maximum size supported...
[mirror_edk2.git] / MdePkg / Library / DxePcdLib / DxePcdLib.c
CommitLineData
e386b444 1/** @file\r
2Implementation of PcdLib class library for DXE phase.\r
3\r
0befb08d 4Copyright (c) 2006 - 2014, 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
0befb08d
SZ
492\r
493 If the set operation was not correctly performed, then ASSERT().\r
494\r
518db1d9 495 @param[in] TokenNumber The PCD token number to set a current value for.\r
496 @param[in] Value The 8-bit value to set.\r
e386b444 497\r
58380e9c 498 @return Return the value that was set.\r
e386b444 499\r
500**/\r
501UINT8\r
502EFIAPI\r
503LibPcdSet8 (\r
504 IN UINTN TokenNumber,\r
505 IN UINT8 Value\r
506 )\r
507{\r
508 EFI_STATUS Status;\r
509\r
b35a5f73 510 Status = GetPcdProtocol()->Set8 (TokenNumber, Value);\r
e386b444 511 ASSERT_EFI_ERROR (Status);\r
512 \r
513 return Value;\r
514}\r
515\r
516\r
517\r
518/**\r
518db1d9 519 This function provides a means by which to set a value for a given PCD token.\r
520 \r
e386b444 521 Sets the 16-bit value for the token specified by TokenNumber \r
522 to the value specified by Value. Value is returned.\r
0befb08d
SZ
523\r
524 If the set operation was not correctly performed, then ASSERT().\r
525\r
518db1d9 526 @param[in] TokenNumber The PCD token number to set a current value for.\r
527 @param[in] Value The 16-bit value to set.\r
e386b444 528\r
58380e9c 529 @return Return the value that was set.\r
e386b444 530\r
531**/\r
532UINT16\r
533EFIAPI\r
534LibPcdSet16 (\r
535 IN UINTN TokenNumber,\r
536 IN UINT16 Value\r
537 )\r
538{\r
539 EFI_STATUS Status;\r
540\r
b35a5f73 541 Status = GetPcdProtocol()->Set16 (TokenNumber, Value);\r
e386b444 542 ASSERT_EFI_ERROR (Status);\r
543 \r
544 return Value;\r
545}\r
546\r
547\r
548\r
549/**\r
518db1d9 550 This function provides a means by which to set a value for a given PCD token.\r
551 \r
e386b444 552 Sets the 32-bit value for the token specified by TokenNumber \r
553 to the value specified by Value. Value is returned.\r
0befb08d
SZ
554\r
555 If the set operation was not correctly performed, then ASSERT().\r
556\r
518db1d9 557 @param[in] TokenNumber The PCD token number to set a current value for.\r
558 @param[in] Value The 32-bit value to set.\r
e386b444 559\r
58380e9c 560 @return Return the value that was set.\r
e386b444 561\r
562**/\r
563UINT32\r
564EFIAPI\r
565LibPcdSet32 (\r
566 IN UINTN TokenNumber,\r
518db1d9 567 IN UINT32 Value\r
e386b444 568 )\r
569{\r
570 EFI_STATUS Status;\r
ec735bb2 571 \r
b35a5f73 572 Status = GetPcdProtocol()->Set32 (TokenNumber, Value);\r
e386b444 573 ASSERT_EFI_ERROR (Status);\r
574\r
575 return Value;\r
576}\r
577\r
578\r
579\r
580/**\r
518db1d9 581 This function provides a means by which to set a value for a given PCD token.\r
582 \r
e386b444 583 Sets the 64-bit value for the token specified by TokenNumber \r
584 to the value specified by Value. Value is returned.\r
0befb08d
SZ
585\r
586 If the set operation was not correctly performed, then ASSERT().\r
e386b444 587 \r
518db1d9 588 @param[in] TokenNumber The PCD token number to set a current value for.\r
589 @param[in] Value The 64-bit value to set.\r
e386b444 590\r
58380e9c 591 @return Return the value that was set.\r
e386b444 592\r
593**/\r
594UINT64\r
595EFIAPI\r
596LibPcdSet64 (\r
597 IN UINTN TokenNumber,\r
518db1d9 598 IN UINT64 Value\r
e386b444 599 )\r
600{\r
601 EFI_STATUS Status;\r
602\r
b35a5f73 603 Status = GetPcdProtocol()->Set64 (TokenNumber, Value);\r
e386b444 604 ASSERT_EFI_ERROR (Status);\r
605\r
606 return Value;\r
607}\r
608\r
609\r
610\r
611/**\r
518db1d9 612 This function provides a means by which to set a value for a given PCD token.\r
e386b444 613 \r
518db1d9 614 Sets a buffer for the token specified by TokenNumber to the value \r
615 specified by Buffer and SizeOfBuffer. Buffer is returned. \r
616 If SizeOfBuffer is greater than the maximum size support by TokenNumber, \r
617 then set SizeOfBuffer to the maximum size supported by TokenNumber and \r
0befb08d
SZ
618 return NULL to indicate that the set operation was not actually performed,\r
619 or ASSERT() if the set operation was not correctly performed.\r
518db1d9 620\r
621 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the \r
622 maximum size supported by TokenName and NULL must be returned.\r
e386b444 623 \r
518db1d9 624 If SizeOfBuffer is NULL, then ASSERT().\r
71f36e0f 625 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().\r
e386b444 626 \r
2a254b90 627 @param[in] TokenNumber The PCD token number to set a current value for.\r
63e4dba9 628 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.\r
2a254b90 629 @param[in] Buffer A pointer to the buffer to set.\r
e386b444 630\r
f73e0ad2 631 @return Return the pointer for the buffer been set.\r
e386b444 632\r
633**/\r
e386b444 634VOID *\r
635EFIAPI\r
636LibPcdSetPtr (\r
64735d24 637 IN UINTN TokenNumber,\r
638 IN OUT UINTN *SizeOfBuffer,\r
b52f6a1a 639 IN CONST VOID *Buffer\r
e386b444 640 )\r
641{\r
642 EFI_STATUS Status;\r
0befb08d 643 UINTN InputSizeOfBuffer;\r
e386b444 644\r
645 ASSERT (SizeOfBuffer != NULL);\r
646\r
647 if (*SizeOfBuffer > 0) {\r
648 ASSERT (Buffer != NULL);\r
649 }\r
650\r
0befb08d 651 InputSizeOfBuffer = *SizeOfBuffer;\r
b35a5f73 652 Status = GetPcdProtocol()->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);\r
0befb08d 653 if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {\r
e386b444 654 return NULL;\r
655 }\r
0befb08d 656 ASSERT_EFI_ERROR (Status);\r
e386b444 657\r
b35a5f73 658 return (VOID *)Buffer;\r
e386b444 659}\r
660\r
661\r
662\r
663/**\r
518db1d9 664 This function provides a means by which to set a value for a given PCD token.\r
665 \r
e386b444 666 Sets the Boolean value for the token specified by TokenNumber \r
667 to the value specified by Value. Value is returned.\r
0befb08d
SZ
668\r
669 If the set operation was not correctly performed, then ASSERT().\r
670\r
518db1d9 671 @param[in] TokenNumber The PCD token number to set a current value for.\r
672 @param[in] Value The boolean value to set.\r
e386b444 673\r
58380e9c 674 @return Return the value that was set.\r
e386b444 675\r
676**/\r
677BOOLEAN\r
678EFIAPI\r
679LibPcdSetBool (\r
680 IN UINTN TokenNumber,\r
681 IN BOOLEAN Value\r
682 )\r
683{\r
684 EFI_STATUS Status;\r
685\r
b35a5f73 686 Status = GetPcdProtocol()->SetBool (TokenNumber, Value);\r
e386b444 687 ASSERT_EFI_ERROR (Status);\r
688\r
689 return Value;\r
690}\r
691\r
692\r
693\r
694/**\r
518db1d9 695 This function provides a means by which to set a value for a given PCD token.\r
696 \r
e386b444 697 Sets the 8-bit value for the token specified by TokenNumber and \r
698 Guid to the value specified by Value. Value is returned.\r
0befb08d 699\r
e386b444 700 If Guid is NULL, then ASSERT().\r
0befb08d
SZ
701 If the set operation was not correctly performed, then ASSERT().\r
702\r
2fc59a00 703 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 704 designates which namespace to set a value from.\r
705 @param[in] TokenNumber The PCD token number to set a current value for.\r
706 @param[in] Value The 8-bit value to set.\r
e386b444 707\r
58380e9c 708 @return Return the value that was set.\r
e386b444 709\r
710**/\r
711UINT8\r
712EFIAPI\r
713LibPcdSetEx8 (\r
714 IN CONST GUID *Guid,\r
715 IN UINTN TokenNumber,\r
716 IN UINT8 Value\r
717 )\r
718{\r
719 EFI_STATUS Status;\r
720\r
721 ASSERT (Guid != NULL);\r
722\r
b35a5f73 723 Status = GetPiPcdProtocol()->Set8 (Guid, TokenNumber, Value);\r
e386b444 724 ASSERT_EFI_ERROR (Status);\r
725\r
726 return Value;\r
727}\r
728\r
729\r
730\r
731/**\r
518db1d9 732 This function provides a means by which to set a value for a given PCD token.\r
733 \r
e386b444 734 Sets the 16-bit value for the token specified by TokenNumber and \r
735 Guid to the value specified by Value. Value is returned.\r
0befb08d 736\r
e386b444 737 If Guid is NULL, then ASSERT().\r
0befb08d
SZ
738 If the set operation was not correctly performed, then ASSERT().\r
739\r
2fc59a00 740 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 741 designates which namespace to set a value from.\r
742 @param[in] TokenNumber The PCD token number to set a current value for.\r
743 @param[in] Value The 16-bit value to set.\r
e386b444 744\r
58380e9c 745 @return Return the value that was set.\r
e386b444 746\r
747**/\r
748UINT16\r
749EFIAPI\r
750LibPcdSetEx16 (\r
751 IN CONST GUID *Guid,\r
752 IN UINTN TokenNumber,\r
753 IN UINT16 Value\r
754 )\r
755{\r
756 EFI_STATUS Status;\r
757\r
758 ASSERT (Guid != NULL);\r
759\r
b35a5f73 760 Status = GetPiPcdProtocol()->Set16 (Guid, TokenNumber, Value);\r
e386b444 761 ASSERT_EFI_ERROR (Status);\r
762\r
763 return Value;\r
764}\r
765\r
766\r
767\r
768/**\r
518db1d9 769 This function provides a means by which to set a value for a given PCD token.\r
770 \r
e386b444 771 Sets the 32-bit value for the token specified by TokenNumber and \r
772 Guid to the value specified by Value. Value is returned.\r
0befb08d 773\r
e386b444 774 If Guid is NULL, then ASSERT().\r
0befb08d
SZ
775 If the set operation was not correctly performed, then ASSERT().\r
776\r
2fc59a00 777 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 778 designates which namespace to set a value from.\r
779 @param[in] TokenNumber The PCD token number to set a current value for.\r
780 @param[in] Value The 32-bit value to set.\r
e386b444 781\r
58380e9c 782 @return Return the value that was set.\r
e386b444 783\r
784**/\r
785UINT32\r
786EFIAPI\r
787LibPcdSetEx32 (\r
788 IN CONST GUID *Guid,\r
789 IN UINTN TokenNumber,\r
518db1d9 790 IN UINT32 Value\r
e386b444 791 )\r
792{\r
793 EFI_STATUS Status;\r
794\r
795 ASSERT (Guid != NULL);\r
796\r
b35a5f73 797 Status = GetPiPcdProtocol()->Set32 (Guid, TokenNumber, Value);\r
e386b444 798 ASSERT_EFI_ERROR (Status);\r
799\r
800 return Value;\r
801}\r
802\r
803\r
804\r
805/**\r
518db1d9 806 This function provides a means by which to set a value for a given PCD token.\r
807 \r
e386b444 808 Sets the 64-bit value for the token specified by TokenNumber and \r
809 Guid to the value specified by Value. Value is returned.\r
0befb08d 810\r
e386b444 811 If Guid is NULL, then ASSERT().\r
0befb08d
SZ
812 If the set operation was not correctly performed, then ASSERT().\r
813\r
2fc59a00 814 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 815 designates which namespace to set a value from.\r
816 @param[in] TokenNumber The PCD token number to set a current value for.\r
817 @param[in] Value The 64-bit value to set.\r
e386b444 818\r
58380e9c 819 @return Return the value that was set.\r
e386b444 820\r
821**/\r
822UINT64\r
823EFIAPI\r
824LibPcdSetEx64 (\r
825 IN CONST GUID *Guid,\r
826 IN UINTN TokenNumber,\r
518db1d9 827 IN UINT64 Value\r
e386b444 828 )\r
829{\r
830 EFI_STATUS Status;\r
831\r
832 ASSERT (Guid != NULL);\r
833\r
b35a5f73 834 Status = GetPiPcdProtocol()->Set64 (Guid, TokenNumber, Value);\r
e386b444 835 ASSERT_EFI_ERROR (Status);\r
836\r
837 return Value;\r
838}\r
839\r
840\r
841\r
842/**\r
518db1d9 843 This function provides a means by which to set a value for a given PCD token.\r
844 \r
e386b444 845 Sets a buffer for the token specified by TokenNumber to the value specified by \r
ef64f703 846 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than \r
847 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size \r
e386b444 848 supported by TokenNumber and return NULL to indicate that the set operation \r
0befb08d 849 was not actually performed, or ASSERT() if the set operation was not corretly performed.\r
e386b444 850 \r
518db1d9 851 If Guid is NULL, then ASSERT().\r
852 If SizeOfBuffer is NULL, then ASSERT().\r
ef64f703 853 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().\r
e386b444 854 \r
2fc59a00 855 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 856 designates which namespace to set a value from.\r
857 @param[in] TokenNumber The PCD token number to set a current value for.\r
858 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.\r
859 @param[in] Buffer A pointer to the buffer to set.\r
e386b444 860\r
b35a5f73 861 @return Return the pointer to the buffer been set.\r
e386b444 862\r
863**/\r
864VOID *\r
865EFIAPI\r
866LibPcdSetExPtr (\r
867 IN CONST GUID *Guid,\r
868 IN UINTN TokenNumber,\r
869 IN OUT UINTN *SizeOfBuffer,\r
870 IN VOID *Buffer\r
871 )\r
872{\r
873 EFI_STATUS Status;\r
0befb08d 874 UINTN InputSizeOfBuffer;\r
e386b444 875\r
876 ASSERT (Guid != NULL);\r
877\r
878 ASSERT (SizeOfBuffer != NULL);\r
879\r
880 if (*SizeOfBuffer > 0) {\r
881 ASSERT (Buffer != NULL);\r
882 }\r
883\r
0befb08d 884 InputSizeOfBuffer = *SizeOfBuffer;\r
b35a5f73 885 Status = GetPiPcdProtocol()->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);\r
0befb08d 886 if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {\r
e386b444 887 return NULL;\r
888 }\r
0befb08d 889 ASSERT_EFI_ERROR (Status);\r
e386b444 890\r
891 return Buffer;\r
892}\r
893\r
894\r
895\r
896/**\r
518db1d9 897 This function provides a means by which to set a value for a given PCD token.\r
898 \r
e386b444 899 Sets the Boolean value for the token specified by TokenNumber and \r
900 Guid to the value specified by Value. Value is returned.\r
0befb08d 901\r
e386b444 902 If Guid is NULL, then ASSERT().\r
0befb08d
SZ
903 If the set operation was not correctly performed, then ASSERT().\r
904\r
2fc59a00 905 @param[in] Guid The pointer to a 128-bit unique value that \r
518db1d9 906 designates which namespace to set a value from.\r
907 @param[in] TokenNumber The PCD token number to set a current value for.\r
908 @param[in] Value The Boolean value to set.\r
e386b444 909\r
58380e9c 910 @return Return the value that was set.\r
e386b444 911\r
912**/\r
913BOOLEAN\r
914EFIAPI\r
915LibPcdSetExBool (\r
916 IN CONST GUID *Guid,\r
917 IN UINTN TokenNumber,\r
918 IN BOOLEAN Value\r
919 )\r
920{\r
921 EFI_STATUS Status;\r
922\r
923 ASSERT (Guid != NULL);\r
924\r
b35a5f73 925 Status = GetPiPcdProtocol()->SetBool (Guid, TokenNumber, Value);\r
e386b444 926 ASSERT_EFI_ERROR (Status);\r
927\r
928 return Value;\r
929}\r
930\r
931\r
932\r
933/**\r
518db1d9 934 Set up a notification function that is called when a specified token is set.\r
935 \r
e386b444 936 When the token specified by TokenNumber and Guid is set, \r
937 then notification function specified by NotificationFunction is called. \r
c00bdbb1 938 If Guid is NULL, then the default token space is used.\r
518db1d9 939 If NotificationFunction is NULL, then ASSERT().\r
940\r
2fc59a00 941 @param[in] Guid The pointer to a 128-bit unique value that designates which \r
c00bdbb1 942 namespace to set a value from. If NULL, then the default \r
943 token space is used.\r
944 @param[in] TokenNumber The PCD token number to monitor.\r
518db1d9 945 @param[in] NotificationFunction The function to call when the token \r
946 specified by Guid and TokenNumber is set.\r
947\r
e386b444 948**/\r
949VOID\r
950EFIAPI\r
951LibPcdCallbackOnSet (\r
952 IN CONST GUID *Guid, OPTIONAL\r
953 IN UINTN TokenNumber,\r
954 IN PCD_CALLBACK NotificationFunction\r
955 )\r
956{\r
957 EFI_STATUS Status;\r
958\r
959 ASSERT (NotificationFunction != NULL);\r
960\r
b35a5f73 961 Status = GetPiPcdProtocol()->CallbackOnSet (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);\r
e386b444 962 ASSERT_EFI_ERROR (Status);\r
963\r
964 return;\r
965}\r
966\r
967\r
968\r
969/**\r
970 Disable a notification function that was established with LibPcdCallbackonSet().\r
518db1d9 971 \r
c00bdbb1 972 Disable a notification function that was previously established with LibPcdCallbackOnSet().\r
e386b444 973 If NotificationFunction is NULL, then ASSERT().\r
518db1d9 974 If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber, \r
975 and NotificationFunction, then ASSERT().\r
ef64f703 976 \r
c00bdbb1 977 @param[in] Guid Specify the GUID token space.\r
978 @param[in] TokenNumber Specify the token number.\r
e386b444 979 @param[in] NotificationFunction The callback function to be unregistered.\r
980\r
e386b444 981**/\r
982VOID\r
983EFIAPI\r
984LibPcdCancelCallback (\r
985 IN CONST GUID *Guid, OPTIONAL\r
986 IN UINTN TokenNumber,\r
987 IN PCD_CALLBACK NotificationFunction\r
988 )\r
989{\r
990 EFI_STATUS Status;\r
991\r
992 ASSERT (NotificationFunction != NULL);\r
993 \r
b35a5f73 994 Status = GetPiPcdProtocol()->CancelCallback (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);\r
e386b444 995 ASSERT_EFI_ERROR (Status);\r
996\r
997 return;\r
998}\r
999\r
1000\r
1001\r
1002/**\r
518db1d9 1003 Retrieves the next token in a token space.\r
1004 \r
e386b444 1005 Retrieves the next PCD token number from the token space specified by Guid. \r
1006 If Guid is NULL, then the default token space is used. If TokenNumber is 0, \r
1007 then the first token number is returned. Otherwise, the token number that \r
1008 follows TokenNumber in the token space is returned. If TokenNumber is the last \r
518db1d9 1009 token number in the token space, then 0 is returned. \r
1010 \r
1011 If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().\r
e386b444 1012\r
2fc59a00 1013 @param[in] Guid The pointer to a 128-bit unique value that designates which namespace \r
2a254b90 1014 to set a value from. If NULL, then the default token space is used.\r
1015 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD \r
1016 token number.\r
e386b444 1017\r
f73e0ad2 1018 @return The next valid token number.\r
e386b444 1019\r
1020**/\r
518db1d9 1021UINTN \r
e386b444 1022EFIAPI\r
1023LibPcdGetNextToken (\r
518db1d9 1024 IN CONST GUID *Guid, OPTIONAL\r
1025 IN UINTN TokenNumber\r
e386b444 1026 )\r
1027{\r
da660118
SZ
1028 EFI_STATUS Status;\r
1029\r
1030 Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);\r
1031 ASSERT (!EFI_ERROR (Status) || TokenNumber == 0);\r
e386b444 1032\r
1033 return TokenNumber;\r
1034}\r
1035\r
1036\r
1037\r
1038/**\r
64735d24 1039 Used to retrieve the list of available PCD token space GUIDs.\r
1040 \r
c00bdbb1 1041 Returns the PCD token space GUID that follows TokenSpaceGuid in the list of token spaces\r
1042 in the platform.\r
1043 If TokenSpaceGuid is NULL, then a pointer to the first PCD token spaces returned.\r
1044 If TokenSpaceGuid is the last PCD token space GUID in the list, then NULL is returned.\r
e386b444 1045 \r
58380e9c 1046 @param TokenSpaceGuid The pointer to the a PCD token space GUID.\r
e386b444 1047\r
f73e0ad2 1048 @return The next valid token namespace.\r
e386b444 1049\r
1050**/\r
c00bdbb1 1051GUID *\r
e386b444 1052EFIAPI\r
1053LibPcdGetNextTokenSpace (\r
64735d24 1054 IN CONST GUID *TokenSpaceGuid\r
e386b444 1055 )\r
1056{\r
419db80b 1057 GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid);\r
e386b444 1058\r
b35a5f73 1059 return (GUID *)TokenSpaceGuid;\r
e386b444 1060}\r
1061\r
1062\r
1063/**\r
518db1d9 1064 Sets a value of a patchable PCD entry that is type pointer.\r
1065 \r
e386b444 1066 Sets the PCD entry specified by PatchVariable to the value specified by Buffer \r
ef64f703 1067 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than \r
1068 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return \r
e386b444 1069 NULL to indicate that the set operation was not actually performed. \r
ef64f703 1070 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to \r
e386b444 1071 MaximumDatumSize and NULL must be returned.\r
1072 \r
1073 If PatchVariable is NULL, then ASSERT().\r
ef64f703 1074 If SizeOfBuffer is NULL, then ASSERT().\r
1075 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().\r
e386b444 1076\r
1077 @param[in] PatchVariable A pointer to the global variable in a module that is \r
1078 the target of the set operation.\r
1079 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.\r
1080 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.\r
1081 @param[in] Buffer A pointer to the buffer to used to set the target variable.\r
518db1d9 1082 \r
9638ba6d 1083 @return Return the pointer to the buffer been set.\r
518db1d9 1084\r
e386b444 1085**/\r
1086VOID *\r
1087EFIAPI\r
1088LibPatchPcdSetPtr (\r
1089 IN VOID *PatchVariable,\r
1090 IN UINTN MaximumDatumSize,\r
1091 IN OUT UINTN *SizeOfBuffer,\r
1092 IN CONST VOID *Buffer\r
1093 )\r
1094{\r
1095 ASSERT (PatchVariable != NULL);\r
1096 ASSERT (SizeOfBuffer != NULL);\r
1097 \r
1098 if (*SizeOfBuffer > 0) {\r
1099 ASSERT (Buffer != NULL);\r
1100 }\r
1101\r
1102 if ((*SizeOfBuffer > MaximumDatumSize) ||\r
1103 (*SizeOfBuffer == MAX_ADDRESS)) {\r
1104 *SizeOfBuffer = MaximumDatumSize;\r
1105 return NULL;\r
1106 }\r
1107 \r
1108 CopyMem (PatchVariable, Buffer, *SizeOfBuffer);\r
1109 \r
1110 return (VOID *) Buffer;\r
1111}\r
1112\r
96d6d004
SZ
1113/**\r
1114 Retrieve additional information associated with a PCD token.\r
1115\r
1116 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
1117 human readable name that is associated with the token.\r
1118\r
1119 If TokenNumber is not in the default token space specified, then ASSERT().\r
e386b444 1120\r
96d6d004
SZ
1121 @param[in] TokenNumber The PCD token number.\r
1122 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
1123 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
1124**/\r
1125VOID\r
1126EFIAPI\r
1127LibPcdGetInfo (\r
1128 IN UINTN TokenNumber,\r
1129 OUT PCD_INFO *PcdInfo\r
1130 )\r
1131{\r
1132 EFI_STATUS Status;\r
1133\r
1134 Status = GetPcdInfoProtocolPointer()->GetInfo (TokenNumber, (EFI_PCD_INFO *) PcdInfo);\r
1135 ASSERT_EFI_ERROR (Status);\r
1136}\r
1137\r
1138/**\r
1139 Retrieve additional information associated with a PCD token.\r
1140\r
1141 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
1142 human readable name that is associated with the token.\r
1143\r
1144 If TokenNumber is not in the token space specified by Guid, then ASSERT().\r
1145\r
1146 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1147 @param[in] TokenNumber The PCD token number.\r
1148 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
1149 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
1150**/\r
1151VOID\r
1152EFIAPI\r
1153LibPcdGetInfoEx (\r
1154 IN CONST GUID *Guid,\r
1155 IN UINTN TokenNumber,\r
1156 OUT PCD_INFO *PcdInfo\r
1157 )\r
1158{\r
1159 EFI_STATUS Status;\r
1160\r
1161 Status = GetPiPcdInfoProtocolPointer()->GetInfo (Guid, TokenNumber, (EFI_PCD_INFO *) PcdInfo);\r
1162 ASSERT_EFI_ERROR (Status);\r
1163}\r
1164\r
1165/**\r
1166 Retrieve the currently set SKU Id.\r
1167\r
1168 If the sku id got >= PCD_MAX_SKU_ID, then ASSERT().\r
1169\r
1170 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the\r
1171 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r
1172 Id is returned.\r
1173**/\r
1174UINTN\r
1175EFIAPI\r
1176LibPcdGetSku (\r
1177 VOID\r
1178 )\r
1179{\r
1180 UINTN SkuId;\r
1181\r
1182 SkuId = GetPiPcdInfoProtocolPointer()->GetSku ();\r
1183 ASSERT (SkuId < PCD_MAX_SKU_ID);\r
1184\r
1185 return SkuId;\r
1186}\r
e386b444 1187\r