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