]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxePcdLib/DxePcdLib.c
Initial import.
[mirror_edk2.git] / MdePkg / Library / DxePcdLib / DxePcdLib.c
1 /** @file
2 Implementation of PcdLib class library for DXE phase.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13
14 Module Name: DxePcdLib.c
15
16 **/
17
18 static PCD_PROTOCOL *mPcd;
19
20 /**
21 The constructor function caches the PCD_PROTOCOL pointer.
22
23 @param[in] ImageHandle The firmware allocated handle for the EFI image.
24 @param[in] SystemTable A pointer to the EFI System Table.
25
26 @retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
27
28 **/
29 EFI_STATUS
30 EFIAPI
31 PcdLibConstructor (
32 IN EFI_HANDLE ImageHandle,
33 IN EFI_SYSTEM_TABLE *SystemTable
34 )
35 {
36 EFI_STATUS Status;
37
38 Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd);
39 ASSERT_EFI_ERROR (Status);
40
41 return EFI_SUCCESS;
42 }
43
44
45 /**
46 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
47
48 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
49 set values associated with a PCD token.
50
51 @retval UINTN Return the SKU ID that just be set.
52
53 **/
54 UINTN
55 EFIAPI
56 LibPcdSetSku (
57 IN UINTN SkuId
58 )
59 {
60 EFI_STATUS Status;
61
62 Status = mPcd->SetSku (SkuId);
63 ASSERT_EFI_ERROR (Status);
64
65 return SkuId;
66 }
67
68
69
70 /**
71 Returns the 8-bit value for the token specified by TokenNumber.
72
73 @param[in] The PCD token number to retrieve a current value for.
74
75 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
76
77 **/
78 UINT8
79 EFIAPI
80 LibPcdGet8 (
81 IN UINTN TokenNumber
82 )
83 {
84 return mPcd->Get8 (TokenNumber);
85 }
86
87
88
89 /**
90 Returns the 16-bit value for the token specified by TokenNumber.
91
92 @param[in] The PCD token number to retrieve a current value for.
93
94 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
95
96 **/
97 UINT16
98 EFIAPI
99 LibPcdGet16 (
100 IN UINTN TokenNumber
101 )
102 {
103 return mPcd->Get16 (TokenNumber);
104 }
105
106
107
108 /**
109 Returns the 32-bit value for the token specified by TokenNumber.
110
111 @param[in] TokenNumber The PCD token number to retrieve a current value for.
112
113 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
114
115 **/
116 UINT32
117 EFIAPI
118 LibPcdGet32 (
119 IN UINTN TokenNumber
120 )
121 {
122 return mPcd->Get32 (TokenNumber);
123 }
124
125
126
127 /**
128 Returns the 64-bit value for the token specified by TokenNumber.
129
130 @param[in] TokenNumber The PCD token number to retrieve a current value for.
131
132 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
133
134 **/
135 UINT64
136 EFIAPI
137 LibPcdGet64 (
138 IN UINTN TokenNumber
139 )
140 {
141 return mPcd->Get64 (TokenNumber);
142 }
143
144
145
146 /**
147 Returns the pointer to the buffer of the token specified by TokenNumber.
148
149 @param[in] TokenNumber The PCD token number to retrieve a current value for.
150
151 @retval VOID* Returns the pointer to the token specified by TokenNumber.
152
153 **/
154 VOID *
155 EFIAPI
156 LibPcdGetPtr (
157 IN UINTN TokenNumber
158 )
159 {
160 return mPcd->GetPtr (TokenNumber);
161 }
162
163
164
165 /**
166 Returns the Boolean value of the token specified by TokenNumber.
167
168 @param[in] TokenNumber The PCD token number to retrieve a current value for.
169
170 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
171
172 **/
173 BOOLEAN
174 EFIAPI
175 LibPcdGetBool (
176 IN UINTN TokenNumber
177 )
178 {
179 return mPcd->GetBool (TokenNumber);
180 }
181
182
183
184 /**
185 Returns the size of the token specified by TokenNumber.
186
187 @param[in] TokenNumber The PCD token number to retrieve a current value for.
188
189 @retval UINTN Returns the size of the token specified by TokenNumber.
190
191 **/
192 UINTN
193 EFIAPI
194 LibPcdGetSize (
195 IN UINTN TokenNumber
196 )
197 {
198 return mPcd->GetSize (TokenNumber);
199 }
200
201
202
203 /**
204 Returns the 8-bit value for the token specified by TokenNumber and Guid.
205 If Guid is NULL, then ASSERT().
206
207 @param[in] Guid Pointer to a 128-bit unique value that designates
208 which namespace to retrieve a value from.
209 @param[in] TokenNumber The PCD token number to retrieve a current value for.
210
211 @retval UINT8 Return the UINT8.
212
213 **/
214 UINT8
215 EFIAPI
216 LibPcdGetEx8 (
217 IN CONST GUID *Guid,
218 IN UINTN TokenNumber
219 )
220 {
221 ASSERT (Guid != NULL);
222
223 return mPcd->Get8Ex (Guid, TokenNumber);
224 }
225
226
227 /**
228 Returns the 16-bit value for the token specified by TokenNumber and Guid.
229 If Guid is NULL, then ASSERT().
230
231 @param[in] Guid Pointer to a 128-bit unique value that designates
232 which namespace to retrieve a value from.
233 @param[in] TokenNumber The PCD token number to retrieve a current value for.
234
235 @retval UINT16 Return the UINT16.
236
237 **/
238 UINT16
239 EFIAPI
240 LibPcdGetEx16 (
241 IN CONST GUID *Guid,
242 IN UINTN TokenNumber
243 )
244 {
245 ASSERT (Guid != NULL);
246
247 return mPcd->Get16Ex (Guid, TokenNumber);
248 }
249
250
251 /**
252 Returns the 32-bit value for the token specified by TokenNumber and Guid.
253 If Guid is NULL, then ASSERT().
254
255 @param[in] Guid Pointer to a 128-bit unique value that designates
256 which namespace to retrieve a value from.
257 @param[in] TokenNumber The PCD token number to retrieve a current value for.
258
259 @retval UINT32 Return the UINT32.
260
261 **/
262 UINT32
263 EFIAPI
264 LibPcdGetEx32 (
265 IN CONST GUID *Guid,
266 IN UINTN TokenNumber
267 )
268 {
269 ASSERT (Guid != NULL);
270
271 return mPcd->Get32Ex (Guid, TokenNumber);
272 }
273
274
275
276 /**
277 Returns the 64-bit value for the token specified by TokenNumber and Guid.
278 If Guid is NULL, then ASSERT().
279
280 @param[in] Guid Pointer to a 128-bit unique value that designates
281 which namespace to retrieve a value from.
282 @param[in] TokenNumber The PCD token number to retrieve a current value for.
283
284 @retval UINT64 Return the UINT64.
285
286 **/
287 UINT64
288 EFIAPI
289 LibPcdGetEx64 (
290 IN CONST GUID *Guid,
291 IN UINTN TokenNumber
292 )
293 {
294 ASSERT (Guid != NULL);
295
296 return mPcd->Get64Ex (Guid, TokenNumber);
297 }
298
299
300
301 /**
302 Returns the pointer to the token specified by TokenNumber and Guid.
303 If Guid is NULL, then ASSERT().
304
305 @param[in] Guid Pointer to a 128-bit unique value that designates
306 which namespace to retrieve a value from.
307 @param[in] TokenNumber The PCD token number to retrieve a current value for.
308
309 @retval VOID* Return the VOID* pointer.
310
311 **/
312 VOID *
313 EFIAPI
314 LibPcdGetExPtr (
315 IN CONST GUID *Guid,
316 IN UINTN TokenNumber
317 )
318 {
319 ASSERT (Guid != NULL);
320
321 return mPcd->GetPtrEx (Guid, TokenNumber);
322 }
323
324
325
326 /**
327 Returns the Boolean value of the token specified by TokenNumber and Guid.
328 If Guid is NULL, then ASSERT().
329
330 @param[in] Guid Pointer to a 128-bit unique value that designates
331 which namespace to retrieve a value from.
332 @param[in] TokenNumber The PCD token number to retrieve a current value for.
333
334 @retval BOOLEAN Return the BOOLEAN.
335
336 **/
337 BOOLEAN
338 EFIAPI
339 LibPcdGetExBool (
340 IN CONST GUID *Guid,
341 IN UINTN TokenNumber
342 )
343 {
344 ASSERT (Guid != NULL);
345
346 return mPcd->GetBoolEx (Guid, TokenNumber);
347 }
348
349
350
351 /**
352 Returns the size of the token specified by TokenNumber and Guid.
353 If Guid is NULL, then ASSERT().
354
355 @param[in] Guid Pointer to a 128-bit unique value that designates
356 which namespace to retrieve a value from.
357 @param[in] TokenNumber The PCD token number to retrieve a current value for.
358
359 @retval UINTN Return the size.
360
361 **/
362 UINTN
363 EFIAPI
364 LibPcdGetExSize (
365 IN CONST GUID *Guid,
366 IN UINTN TokenNumber
367 )
368 {
369 ASSERT (Guid != NULL);
370
371 return mPcd->GetSizeEx (Guid, TokenNumber);
372 }
373
374
375
376 /**
377 Sets the 8-bit value for the token specified by TokenNumber
378 to the value specified by Value. Value is returned.
379
380 @param[in] TokenNumber The PCD token number to set a current value for.
381 @param[in] Value The 8-bit value to set.
382
383 @retval UINT8 Return the value been set.
384
385 **/
386 UINT8
387 EFIAPI
388 LibPcdSet8 (
389 IN UINTN TokenNumber,
390 IN UINT8 Value
391 )
392 {
393 EFI_STATUS Status;
394
395 Status = mPcd->Set8 (TokenNumber, Value);
396
397 ASSERT_EFI_ERROR (Status);
398
399 return Value;
400 }
401
402
403
404 /**
405 Sets the 16-bit value for the token specified by TokenNumber
406 to the value specified by Value. Value is returned.
407
408 @param[in] TokenNumber The PCD token number to set a current value for.
409 @param[in] Value The 16-bit value to set.
410
411 @retval UINT16 Return the value been set.
412
413 **/
414 UINT16
415 EFIAPI
416 LibPcdSet16 (
417 IN UINTN TokenNumber,
418 IN UINT16 Value
419 )
420 {
421 EFI_STATUS Status;
422
423 Status = mPcd->Set16 (TokenNumber, Value);
424
425 ASSERT_EFI_ERROR (Status);
426
427 return Value;
428 }
429
430
431
432 /**
433 Sets the 32-bit value for the token specified by TokenNumber
434 to the value specified by Value. Value is returned.
435
436 @param[in] TokenNumber The PCD token number to set a current value for.
437 @param[in] Value The 32-bit value to set.
438
439 @retval UINT32 Return the value been set.
440
441 **/
442 UINT32
443 EFIAPI
444 LibPcdSet32 (
445 IN UINTN TokenNumber,
446 IN UINT32 Value
447 )
448 {
449 EFI_STATUS Status;
450 Status = mPcd->Set32 (TokenNumber, Value);
451
452 ASSERT_EFI_ERROR (Status);
453
454 return Value;
455 }
456
457
458
459 /**
460 Sets the 64-bit value for the token specified by TokenNumber
461 to the value specified by Value. Value is returned.
462
463 @param[in] TokenNumber The PCD token number to set a current value for.
464 @param[in] Value The 64-bit value to set.
465
466 @retval UINT64 Return the value been set.
467
468 **/
469 UINT64
470 EFIAPI
471 LibPcdSet64 (
472 IN UINTN TokenNumber,
473 IN UINT64 Value
474 )
475 {
476 EFI_STATUS Status;
477
478 Status = mPcd->Set64 (TokenNumber, Value);
479
480 ASSERT_EFI_ERROR (Status);
481
482 return Value;
483 }
484
485
486
487 /**
488 Sets a buffer for the token specified by TokenNumber to
489 the value specified by Value. Value is returned.
490 If Value is NULL, then ASSERT().
491
492 @param[in] TokenNumber The PCD token number to set a current value for.
493 @param[in] Value A pointer to the buffer to set.
494
495 @retval VOID* Return the pointer for the buffer been set.
496
497 **/
498 VOID *
499 EFIAPI
500 LibPcdSetPtr (
501 IN UINTN TokenNumber,
502 IN CONST VOID *Value
503 )
504 {
505 EFI_STATUS Status;
506
507 ASSERT (Value != NULL);
508
509 Status = mPcd->SetPtr (TokenNumber, Value);
510
511 ASSERT_EFI_ERROR (Status);
512
513 return (VOID *)Value;
514 }
515
516
517
518 /**
519 Sets the Boolean value for the token specified by TokenNumber
520 to the value specified by Value. Value is returned.
521
522 @param[in] TokenNumber The PCD token number to set a current value for.
523 @param[in] Value The boolean value to set.
524
525 @retval BOOLEAN Return the value been set.
526
527 **/
528 BOOLEAN
529 EFIAPI
530 LibPcdSetBool (
531 IN UINTN TokenNumber,
532 IN BOOLEAN Value
533 )
534 {
535 EFI_STATUS Status;
536
537 Status = mPcd->SetBool (TokenNumber, Value);
538
539 ASSERT_EFI_ERROR (Status);
540
541 return Value;
542 }
543
544
545
546 /**
547 Sets the 8-bit value for the token specified by TokenNumber and
548 Guid to the value specified by Value. Value is returned.
549 If Guid is NULL, then ASSERT().
550
551 @param[in] Guid Pointer to a 128-bit unique value that
552 designates which namespace to set a value from.
553 @param[in] TokenNumber The PCD token number to set a current value for.
554 @param[in] Value The 8-bit value to set.
555
556 @retval UINT8 Return the value been set.
557
558 **/
559 UINT8
560 EFIAPI
561 LibPcdSetEx8 (
562 IN CONST GUID *Guid,
563 IN UINTN TokenNumber,
564 IN UINT8 Value
565 )
566 {
567 EFI_STATUS Status;
568
569 ASSERT (Guid != NULL);
570
571 Status = mPcd->Set8Ex (Guid, TokenNumber, Value);
572
573 ASSERT_EFI_ERROR (Status);
574
575 return Value;
576 }
577
578
579
580 /**
581 Sets the 16-bit value for the token specified by TokenNumber and
582 Guid to the value specified by Value. Value is returned.
583 If Guid is NULL, then ASSERT().
584
585 @param[in] Guid Pointer to a 128-bit unique value that
586 designates which namespace to set a value from.
587 @param[in] TokenNumber The PCD token number to set a current value for.
588 @param[in] Value The 16-bit value to set.
589
590 @retval UINT8 Return the value been set.
591
592 **/
593 UINT16
594 EFIAPI
595 LibPcdSetEx16 (
596 IN CONST GUID *Guid,
597 IN UINTN TokenNumber,
598 IN UINT16 Value
599 )
600 {
601 EFI_STATUS Status;
602
603 ASSERT (Guid != NULL);
604
605 Status = mPcd->Set16Ex (Guid, TokenNumber, Value);
606
607 ASSERT_EFI_ERROR (Status);
608
609 return Value;
610 }
611
612
613
614 /**
615 Sets the 32-bit value for the token specified by TokenNumber and
616 Guid to the value specified by Value. Value is returned.
617 If Guid is NULL, then ASSERT().
618
619 @param[in] Guid Pointer to a 128-bit unique value that
620 designates which namespace to set a value from.
621 @param[in] TokenNumber The PCD token number to set a current value for.
622 @param[in] Value The 32-bit value to set.
623
624 @retval UINT32 Return the value been set.
625
626 **/
627 UINT32
628 EFIAPI
629 LibPcdSetEx32 (
630 IN CONST GUID *Guid,
631 IN UINTN TokenNumber,
632 IN UINT32 Value
633 )
634 {
635 EFI_STATUS Status;
636
637 ASSERT (Guid != NULL);
638
639 Status = mPcd->Set32Ex (Guid, TokenNumber, Value);
640
641 ASSERT_EFI_ERROR (Status);
642
643 return Value;
644 }
645
646
647
648 /**
649 Sets the 64-bit value for the token specified by TokenNumber and
650 Guid to the value specified by Value. Value is returned.
651 If Guid is NULL, then ASSERT().
652
653 @param[in] Guid Pointer to a 128-bit unique value that
654 designates which namespace to set a value from.
655 @param[in] TokenNumber The PCD token number to set a current value for.
656 @param[in] Value The 64-bit value to set.
657
658 @retval UINT64 Return the value been set.
659
660 **/
661 UINT64
662 EFIAPI
663 LibPcdSetEx64 (
664 IN CONST GUID *Guid,
665 IN UINTN TokenNumber,
666 IN UINT64 Value
667 )
668 {
669 EFI_STATUS Status;
670
671 ASSERT (Guid != NULL);
672
673 Status = mPcd->Set64Ex (Guid, TokenNumber, Value);
674
675 ASSERT_EFI_ERROR (Status);
676
677 return Value;
678 }
679
680
681
682 /**
683 Sets a buffer for the token specified by TokenNumber and
684 Guid to the value specified by Value. Value is returned.
685 If Guid is NULL, then ASSERT().
686 If Value is NULL, then ASSERT().
687
688 @param[in] Guid Pointer to a 128-bit unique value that
689 designates which namespace to set a value from.
690 @param[in] TokenNumber The PCD token number to set a current value for.
691 @param[in] Value The 8-bit value to set.
692
693 @retval VOID * Return the value been set.
694
695 **/
696 VOID *
697 EFIAPI
698 LibPcdSetExPtr (
699 IN CONST GUID *Guid,
700 IN UINTN TokenNumber,
701 IN CONST VOID *Value
702 )
703 {
704 EFI_STATUS Status;
705
706 ASSERT (Guid != NULL);
707 ASSERT (Value != NULL);
708
709 Status = mPcd->SetPtrEx (Guid, TokenNumber, Value);
710
711 ASSERT_EFI_ERROR (Status);
712
713 return (VOID *)Value;
714 }
715
716
717
718 /**
719 Sets the Boolean value for the token specified by TokenNumber and
720 Guid to the value specified by Value. Value is returned.
721 If Guid is NULL, then ASSERT().
722
723 @param[in] Guid Pointer to a 128-bit unique value that
724 designates which namespace to set a value from.
725 @param[in] TokenNumber The PCD token number to set a current value for.
726 @param[in] Value The Boolean value to set.
727
728 @retval Boolean Return the value been set.
729
730 **/
731 BOOLEAN
732 EFIAPI
733 LibPcdSetExBool (
734 IN CONST GUID *Guid,
735 IN UINTN TokenNumber,
736 IN BOOLEAN Value
737 )
738 {
739 EFI_STATUS Status;
740
741 ASSERT (Guid != NULL);
742
743 Status = mPcd->SetBoolEx (Guid, TokenNumber, Value);
744
745 ASSERT_EFI_ERROR (Status);
746
747 return Value;
748 }
749
750
751
752 /**
753 When the token specified by TokenNumber and Guid is set,
754 then notification function specified by NotificationFunction is called.
755 If Guid is NULL, then the default token space is used.
756 If NotificationFunction is NULL, then ASSERT().
757
758 @param[in] Guid Pointer to a 128-bit unique value that designates which
759 namespace to set a value from. If NULL, then the default
760 token space is used.
761 @param[in] TokenNumber The PCD token number to monitor.
762 @param[in] NotificationFunction The function to call when the token
763 specified by Guid and TokenNumber is set.
764
765 @retval VOID
766
767 **/
768 VOID
769 EFIAPI
770 LibPcdCallbackOnSet (
771 IN CONST GUID *Guid, OPTIONAL
772 IN UINTN TokenNumber,
773 IN PCD_CALLBACK NotificationFunction
774 )
775 {
776 EFI_STATUS Status;
777
778 ASSERT (NotificationFunction != NULL);
779
780 Status = mPcd->CallbackOnSet (TokenNumber, Guid, NotificationFunction);
781
782 ASSERT_EFI_ERROR (Status);
783
784 return;
785 }
786
787
788
789 /**
790 Disable a notification function that was established with LibPcdCallbackonSet().
791 If NotificationFunction is NULL, then ASSERT().
792
793 @param[in] Guid Specify the GUID token space.
794 @param[in] TokenNumber Specify the token number.
795 @param[in] NotificationFunction The callback function to be unregistered.
796
797 @retval VOID
798
799 **/
800 VOID
801 EFIAPI
802 LibPcdCancelCallback (
803 IN CONST GUID *Guid, OPTIONAL
804 IN UINTN TokenNumber,
805 IN PCD_CALLBACK NotificationFunction
806 )
807 {
808 EFI_STATUS Status;
809
810 ASSERT (NotificationFunction != NULL);
811
812 Status = mPcd->CancelCallback (TokenNumber, Guid, NotificationFunction);
813
814 ASSERT_EFI_ERROR (Status);
815
816 return;
817 }
818
819
820
821 /**
822 Retrieves the next PCD token number from the token space specified by Guid.
823 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
824 then the first token number is returned. Otherwise, the token number that
825 follows TokenNumber in the token space is returned. If TokenNumber is the last
826 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
827 is not in the token space specified by Guid, then ASSERT().
828
829 @param[in] Pointer to a 128-bit unique value that designates which namespace
830 to set a value from. If NULL, then the default token space is used.
831 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
832 token number.
833
834 @retval UINTN The next valid token number.
835
836 **/
837 UINTN
838 EFIAPI
839 LibPcdGetNextToken (
840 IN CONST GUID *Guid, OPTIONAL
841 IN OUT UINTN *TokenNumber
842 )
843 {
844 EFI_STATUS Status;
845
846 Status = mPcd->GetNextToken (Guid, TokenNumber);
847
848 ASSERT_EFI_ERROR (Status);
849
850 return (*TokenNumber);
851 }
852