]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/PCD/Dxe/Pcd.c
Make PcdPeim/PcdDxe driver also produce EFI_PCD_PPI/EFI_PCD_PROTOCOL defined in PI...
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Dxe / Pcd.c
1 /** @file
2 PCD DXE driver manage all PCD entry initialized in PEI phase and DXE phase, and
3 produce the implementation of PCD protocol.
4
5 Copyright (c) 2006 - 2009, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "Service.h"
17
18 //
19 // Just pre-allocate a memory buffer that is big enough to
20 // host all distinct TokenSpace guid in both
21 // PEI ExMap and DXE ExMap.
22 //
23 EFI_GUID *TmpTokenSpaceBuffer[PEI_EXMAPPING_TABLE_SIZE + DXE_EXMAPPING_TABLE_SIZE] = { 0 };
24
25 ///
26 /// PCD database lock.
27 ///
28 EFI_LOCK mPcdDatabaseLock = EFI_INITIALIZE_LOCK_VARIABLE(TPL_NOTIFY);
29
30 PCD_PROTOCOL mPcdInstance = {
31 DxePcdSetSku,
32
33 DxePcdGet8,
34 DxePcdGet16,
35 DxePcdGet32,
36 DxePcdGet64,
37 DxePcdGetPtr,
38 DxePcdGetBool,
39 DxePcdGetSize,
40
41 DxePcdGet8Ex,
42 DxePcdGet16Ex,
43 DxePcdGet32Ex,
44 DxePcdGet64Ex,
45 DxePcdGetPtrEx,
46 DxePcdGetBoolEx,
47 DxePcdGetSizeEx,
48
49 DxePcdSet8,
50 DxePcdSet16,
51 DxePcdSet32,
52 DxePcdSet64,
53 DxePcdSetPtr,
54 DxePcdSetBool,
55
56 DxePcdSet8Ex,
57 DxePcdSet16Ex,
58 DxePcdSet32Ex,
59 DxePcdSet64Ex,
60 DxePcdSetPtrEx,
61 DxePcdSetBoolEx,
62
63 DxeRegisterCallBackOnSet,
64 DxeUnRegisterCallBackOnSet,
65 DxePcdGetNextToken,
66 DxePcdGetNextTokenSpace
67 };
68
69 EFI_PCD_PROTOCOL mEfiPcdInstance = {
70 DxePcdSetSku,
71 DxePcdGet8Ex,
72 DxePcdGet16Ex,
73 DxePcdGet32Ex,
74 DxePcdGet64Ex,
75 DxePcdGetPtrEx,
76 DxePcdGetBoolEx,
77 DxePcdGetSizeEx,
78 DxePcdSet8Ex,
79 DxePcdSet16Ex,
80 DxePcdSet32Ex,
81 DxePcdSet64Ex,
82 DxePcdSetPtrEx,
83 DxePcdSetBoolEx,
84 (EFI_PCD_PROTOCOL_CALLBACK_ON_SET) DxeRegisterCallBackOnSet,
85 (EFI_PCD_PROTOCOL_CANCEL_CALLBACK) DxeUnRegisterCallBackOnSet,
86 DxePcdGetNextToken,
87 DxePcdGetNextTokenSpace
88 };
89
90 //
91 // Static global to reduce the code size
92 //
93 EFI_HANDLE mNewHandle = NULL;
94
95 /**
96 Main entry for PCD DXE driver.
97
98 This routine initialize the PCD database and install PCD_PROTOCOL.
99
100 @param ImageHandle Image handle for PCD DXE driver.
101 @param SystemTable Pointer to SystemTable.
102
103 @return Status of gBS->InstallProtocolInterface()
104
105 **/
106 EFI_STATUS
107 EFIAPI
108 PcdDxeInit (
109 IN EFI_HANDLE ImageHandle,
110 IN EFI_SYSTEM_TABLE *SystemTable
111 )
112 {
113 EFI_STATUS Status;
114
115 //
116 // Make sure the Pcd Protocol is not already installed in the system
117 //
118
119 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gPcdProtocolGuid);
120
121 BuildPcdDxeDataBase ();
122
123 Status = gBS->InstallProtocolInterface (
124 &mNewHandle,
125 &gPcdProtocolGuid,
126 EFI_NATIVE_INTERFACE,
127 &mPcdInstance
128 );
129
130
131 //
132 // Also install gEfiPcdProtocolGuid which is only support dynamic-ex type
133 // PCD.
134 //
135 mNewHandle = NULL;
136 Status = gBS->InstallProtocolInterface (
137 &mNewHandle,
138 &gEfiPcdProtocolGuid,
139 EFI_NATIVE_INTERFACE,
140 &mEfiPcdInstance
141 );
142
143 ASSERT_EFI_ERROR (Status);
144
145 return EFI_SUCCESS;
146
147 }
148
149 /**
150 Sets the SKU value for subsequent calls to set or get PCD token values.
151
152 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
153 SetSku() is normally called only once by the system.
154
155 For each item (token), the database can hold a single value that applies to all SKUs,
156 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
157 SKU-specific values are called SKU enabled.
158
159 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
160 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
161 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
162 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
163 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
164 set for that Id, the results are unpredictable.
165
166 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
167 set values associated with a PCD token.
168
169 **/
170 VOID
171 EFIAPI
172 DxePcdSetSku (
173 IN UINTN SkuId
174 )
175 {
176 mPcdDatabase->PeiDb.Init.SystemSkuId = (SKU_ID) SkuId;
177
178 return;
179 }
180
181 /**
182 Retrieves an 8-bit value for a given PCD token.
183
184 Retrieves the current byte-sized value for a PCD token number.
185 If the TokenNumber is invalid, the results are unpredictable.
186
187 @param[in] TokenNumber The PCD token number.
188
189 @return The UINT8 value.
190
191 **/
192 UINT8
193 EFIAPI
194 DxePcdGet8 (
195 IN UINTN TokenNumber
196 )
197 {
198 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));
199 }
200
201 /**
202 Retrieves an 16-bit value for a given PCD token.
203
204 Retrieves the current 16-bits value for a PCD token number.
205 If the TokenNumber is invalid, the results are unpredictable.
206
207 @param[in] TokenNumber The PCD token number.
208
209 @return The UINT16 value.
210
211 **/
212 UINT16
213 EFIAPI
214 DxePcdGet16 (
215 IN UINTN TokenNumber
216 )
217 {
218 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));
219 }
220
221 /**
222 Retrieves an 32-bit value for a given PCD token.
223
224 Retrieves the current 32-bits value for a PCD token number.
225 If the TokenNumber is invalid, the results are unpredictable.
226
227 @param[in] TokenNumber The PCD token number.
228
229 @return The UINT32 value.
230
231 **/
232 UINT32
233 EFIAPI
234 DxePcdGet32 (
235 IN UINTN TokenNumber
236 )
237 {
238 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));
239 }
240
241 /**
242 Retrieves an 64-bit value for a given PCD token.
243
244 Retrieves the current 64-bits value for a PCD token number.
245 If the TokenNumber is invalid, the results are unpredictable.
246
247 @param[in] TokenNumber The PCD token number.
248
249 @return The UINT64 value.
250
251 **/
252 UINT64
253 EFIAPI
254 DxePcdGet64 (
255 IN UINTN TokenNumber
256 )
257 {
258 return ReadUnaligned64(GetWorker (TokenNumber, sizeof (UINT64)));
259 }
260
261 /**
262 Retrieves a pointer to a value for a given PCD token.
263
264 Retrieves the current pointer to the buffer for a PCD token number.
265 Do not make any assumptions about the alignment of the pointer that
266 is returned by this function call. If the TokenNumber is invalid,
267 the results are unpredictable.
268
269 @param[in] TokenNumber The PCD token number.
270
271 @return The pointer to the buffer to be retrived.
272
273 **/
274 VOID *
275 EFIAPI
276 DxePcdGetPtr (
277 IN UINTN TokenNumber
278 )
279 {
280 return GetWorker (TokenNumber, 0);
281 }
282
283 /**
284 Retrieves a Boolean value for a given PCD token.
285
286 Retrieves the current boolean value for a PCD token number.
287 Do not make any assumptions about the alignment of the pointer that
288 is returned by this function call. If the TokenNumber is invalid,
289 the results are unpredictable.
290
291 @param[in] TokenNumber The PCD token number.
292
293 @return The Boolean value.
294
295 **/
296 BOOLEAN
297 EFIAPI
298 DxePcdGetBool (
299 IN UINTN TokenNumber
300 )
301 {
302 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));
303 }
304
305 /**
306 Retrieves the size of the value for a given PCD token.
307
308 Retrieves the current size of a particular PCD token.
309 If the TokenNumber is invalid, the results are unpredictable.
310
311 @param[in] TokenNumber The PCD token number.
312
313 @return The size of the value for the PCD token.
314
315 **/
316 UINTN
317 EFIAPI
318 DxePcdGetSize (
319 IN UINTN TokenNumber
320 )
321 {
322 UINTN Size;
323 UINT32 *LocalTokenNumberTable;
324 BOOLEAN IsPeiDb;
325 UINTN MaxSize;
326 UINTN TmpTokenNumber;
327 //
328 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
329 // We have to decrement TokenNumber by 1 to make it usable
330 // as the array index.
331 //
332 TokenNumber--;
333
334 //
335 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
336 //
337 TmpTokenNumber = TokenNumber;
338
339 // EBC compiler is very choosy. It may report warning about comparison
340 // between UINTN and 0 . So we add 1 in each size of the
341 // comparison.
342 ASSERT (TokenNumber + 1 < PCD_TOTAL_TOKEN_NUMBER + 1);
343
344 // EBC compiler is very choosy. It may report warning about comparison
345 // between UINTN and 0 . So we add 1 in each size of the
346 // comparison.
347 IsPeiDb = (BOOLEAN) (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
348
349 TokenNumber = IsPeiDb ? TokenNumber :
350 (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);
351
352 LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable
353 : mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
354
355 Size = (LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;
356
357 if (Size == 0) {
358 //
359 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
360 //
361 return GetPtrTypeSize (TmpTokenNumber, &MaxSize);
362 } else {
363 return Size;
364 }
365
366 }
367
368 /**
369 Retrieves an 8-bit value for a given PCD token.
370
371 Retrieves the 8-bit value of a particular PCD token.
372 If the TokenNumber is invalid or the token space
373 specified by Guid does not exist, the results are
374 unpredictable.
375
376 @param[in] Guid The token space for the token number.
377 @param[in] ExTokenNumber The PCD token number.
378
379 @return The size 8-bit value for the PCD token.
380
381 **/
382 UINT8
383 EFIAPI
384 DxePcdGet8Ex (
385 IN CONST EFI_GUID *Guid,
386 IN UINTN ExTokenNumber
387 )
388 {
389 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT8)));
390 }
391
392 /**
393 Retrieves an 16-bit value for a given PCD token.
394
395 Retrieves the 16-bit value of a particular PCD token.
396 If the TokenNumber is invalid or the token space
397 specified by Guid does not exist, the results are
398 unpredictable.
399
400 @param[in] Guid The token space for the token number.
401 @param[in] ExTokenNumber The PCD token number.
402
403 @return The size 16-bit value for the PCD token.
404
405 **/
406 UINT16
407 EFIAPI
408 DxePcdGet16Ex (
409 IN CONST EFI_GUID *Guid,
410 IN UINTN ExTokenNumber
411 )
412 {
413 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT16)));
414 }
415
416 /**
417 Retrieves an 32-bit value for a given PCD token.
418
419 Retrieves the 32-bit value of a particular PCD token.
420 If the TokenNumber is invalid or the token space
421 specified by Guid does not exist, the results are
422 unpredictable.
423
424 @param[in] Guid The token space for the token number.
425 @param[in] ExTokenNumber The PCD token number.
426
427 @return The size 32-bit value for the PCD token.
428
429 **/
430 UINT32
431 EFIAPI
432 DxePcdGet32Ex (
433 IN CONST EFI_GUID *Guid,
434 IN UINTN ExTokenNumber
435 )
436 {
437 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT32)));
438 }
439
440 /**
441 Retrieves an 64-bit value for a given PCD token.
442
443 Retrieves the 64-bit value of a particular PCD token.
444 If the TokenNumber is invalid or the token space
445 specified by Guid does not exist, the results are
446 unpredictable.
447
448 @param[in] Guid The token space for the token number.
449 @param[in] ExTokenNumber The PCD token number.
450
451 @return The size 64-bit value for the PCD token.
452
453 **/
454 UINT64
455 EFIAPI
456 DxePcdGet64Ex (
457 IN CONST EFI_GUID *Guid,
458 IN UINTN ExTokenNumber
459 )
460 {
461 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT64)));
462 }
463
464 /**
465 Retrieves a pointer to a value for a given PCD token.
466
467 Retrieves the current pointer to the buffer for a PCD token number.
468 Do not make any assumptions about the alignment of the pointer that
469 is returned by this function call. If the TokenNumber is invalid,
470 the results are unpredictable.
471
472 @param[in] Guid The token space for the token number.
473 @param[in] ExTokenNumber The PCD token number.
474
475 @return The pointer to the buffer to be retrived.
476
477 **/
478 VOID *
479 EFIAPI
480 DxePcdGetPtrEx (
481 IN CONST EFI_GUID *Guid,
482 IN UINTN ExTokenNumber
483 )
484 {
485 return ExGetWorker (Guid, ExTokenNumber, 0);
486 }
487
488 /**
489 Retrieves an Boolean value for a given PCD token.
490
491 Retrieves the Boolean value of a particular PCD token.
492 If the TokenNumber is invalid or the token space
493 specified by Guid does not exist, the results are
494 unpredictable.
495
496 @param[in] Guid The token space for the token number.
497 @param[in] ExTokenNumber The PCD token number.
498
499 @return The size Boolean value for the PCD token.
500
501 **/
502 BOOLEAN
503 EFIAPI
504 DxePcdGetBoolEx (
505 IN CONST EFI_GUID *Guid,
506 IN UINTN ExTokenNumber
507 )
508 {
509 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof(BOOLEAN)));
510 }
511
512 /**
513 Retrieves the size of the value for a given PCD token.
514
515 Retrieves the current size of a particular PCD token.
516 If the TokenNumber is invalid, the results are unpredictable.
517
518 @param[in] Guid The token space for the token number.
519 @param[in] ExTokenNumber The PCD token number.
520
521 @return The size of the value for the PCD token.
522
523 **/
524 UINTN
525 EFIAPI
526 DxePcdGetSizeEx (
527 IN CONST EFI_GUID *Guid,
528 IN UINTN ExTokenNumber
529 )
530 {
531 return DxePcdGetSize(GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber));
532 }
533
534 /**
535 Sets an 8-bit value for a given PCD token.
536
537 When the PCD service sets a value, it will check to ensure that the
538 size of the value being set is compatible with the Token's existing definition.
539 If it is not, an error will be returned.
540
541 @param[in] TokenNumber The PCD token number.
542 @param[in] Value The value to set for the PCD token.
543
544 @retval EFI_SUCCESS Procedure returned successfully.
545 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
546 being set was incompatible with a call to this function.
547 Use GetSize() to retrieve the size of the target data.
548 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
549
550 **/
551 EFI_STATUS
552 EFIAPI
553 DxePcdSet8 (
554 IN UINTN TokenNumber,
555 IN UINT8 Value
556 )
557 {
558 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
559 }
560
561 /**
562 Sets an 16-bit value for a given PCD token.
563
564 When the PCD service sets a value, it will check to ensure that the
565 size of the value being set is compatible with the Token's existing definition.
566 If it is not, an error will be returned.
567
568 @param[in] TokenNumber The PCD token number.
569 @param[in] Value The value to set for the PCD token.
570
571 @retval EFI_SUCCESS Procedure returned successfully.
572 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
573 being set was incompatible with a call to this function.
574 Use GetSize() to retrieve the size of the target data.
575 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
576
577 **/
578 EFI_STATUS
579 EFIAPI
580 DxePcdSet16 (
581 IN UINTN TokenNumber,
582 IN UINT16 Value
583 )
584 {
585 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
586 }
587
588 /**
589 Sets an 32-bit value for a given PCD token.
590
591 When the PCD service sets a value, it will check to ensure that the
592 size of the value being set is compatible with the Token's existing definition.
593 If it is not, an error will be returned.
594
595 @param[in] TokenNumber The PCD token number.
596 @param[in] Value The value to set for the PCD token.
597
598 @retval EFI_SUCCESS Procedure returned successfully.
599 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
600 being set was incompatible with a call to this function.
601 Use GetSize() to retrieve the size of the target data.
602 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
603
604 **/
605 EFI_STATUS
606 EFIAPI
607 DxePcdSet32 (
608 IN UINTN TokenNumber,
609 IN UINT32 Value
610 )
611 {
612 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
613 }
614
615 /**
616 Sets an 64-bit value for a given PCD token.
617
618 When the PCD service sets a value, it will check to ensure that the
619 size of the value being set is compatible with the Token's existing definition.
620 If it is not, an error will be returned.
621
622 @param[in] TokenNumber The PCD token number.
623 @param[in] Value The value to set for the PCD token.
624
625 @retval EFI_SUCCESS Procedure returned successfully.
626 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
627 being set was incompatible with a call to this function.
628 Use GetSize() to retrieve the size of the target data.
629 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
630
631 **/
632 EFI_STATUS
633 EFIAPI
634 DxePcdSet64 (
635 IN UINTN TokenNumber,
636 IN UINT64 Value
637 )
638 {
639 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
640 }
641
642 /**
643 Sets a value of a specified size for a given PCD token.
644
645 When the PCD service sets a value, it will check to ensure that the
646 size of the value being set is compatible with the Token's existing definition.
647 If it is not, an error will be returned.
648
649 @param[in] TokenNumber The PCD token number.
650 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
651 On input, if the SizeOfValue is greater than the maximum size supported
652 for this TokenNumber then the output value of SizeOfValue will reflect
653 the maximum size supported for this TokenNumber.
654 @param[in] Buffer The buffer to set for the PCD token.
655
656 @retval EFI_SUCCESS Procedure returned successfully.
657 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
658 being set was incompatible with a call to this function.
659 Use GetSize() to retrieve the size of the target data.
660 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
661
662 **/
663 EFI_STATUS
664 EFIAPI
665 DxePcdSetPtr (
666 IN UINTN TokenNumber,
667 IN OUT UINTN *SizeOfBuffer,
668 IN VOID *Buffer
669 )
670 {
671 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);
672 }
673
674 /**
675 Sets an Boolean value for a given PCD token.
676
677 When the PCD service sets a value, it will check to ensure that the
678 size of the value being set is compatible with the Token's existing definition.
679 If it is not, an error will be returned.
680
681 @param[in] TokenNumber The PCD token number.
682 @param[in] Value The value to set for the PCD token.
683
684 @retval EFI_SUCCESS Procedure returned successfully.
685 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
686 being set was incompatible with a call to this function.
687 Use GetSize() to retrieve the size of the target data.
688 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
689
690 **/
691 EFI_STATUS
692 EFIAPI
693 DxePcdSetBool (
694 IN UINTN TokenNumber,
695 IN BOOLEAN Value
696 )
697 {
698 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
699 }
700
701 /**
702 Sets an 8-bit value for a given PCD token.
703
704 When the PCD service sets a value, it will check to ensure that the
705 size of the value being set is compatible with the Token's existing definition.
706 If it is not, an error will be returned.
707
708 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
709 @param[in] ExTokenNumber The PCD token number.
710 @param[in] Value The value to set for the PCD token.
711
712 @retval EFI_SUCCESS Procedure returned successfully.
713 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
714 being set was incompatible with a call to this function.
715 Use GetSize() to retrieve the size of the target data.
716 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
717
718 **/
719 EFI_STATUS
720 EFIAPI
721 DxePcdSet8Ex (
722 IN CONST EFI_GUID *Guid,
723 IN UINTN ExTokenNumber,
724 IN UINT8 Value
725 )
726 {
727 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
728 }
729
730 /**
731 Sets an 16-bit value for a given PCD token.
732
733 When the PCD service sets a value, it will check to ensure that the
734 size of the value being set is compatible with the Token's existing definition.
735 If it is not, an error will be returned.
736
737 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
738 @param[in] ExTokenNumber The PCD token number.
739 @param[in] Value The value to set for the PCD token.
740
741 @retval EFI_SUCCESS Procedure returned successfully.
742 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
743 being set was incompatible with a call to this function.
744 Use GetSize() to retrieve the size of the target data.
745 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
746
747 **/
748 EFI_STATUS
749 EFIAPI
750 DxePcdSet16Ex (
751 IN CONST EFI_GUID *Guid,
752 IN UINTN ExTokenNumber,
753 IN UINT16 Value
754 )
755 {
756 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
757 }
758
759 /**
760 Sets an 32-bit value for a given PCD token.
761
762 When the PCD service sets a value, it will check to ensure that the
763 size of the value being set is compatible with the Token's existing definition.
764 If it is not, an error will be returned.
765
766 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
767 @param[in] ExTokenNumber The PCD token number.
768 @param[in] Value The value to set for the PCD token.
769
770 @retval EFI_SUCCESS Procedure returned successfully.
771 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
772 being set was incompatible with a call to this function.
773 Use GetSize() to retrieve the size of the target data.
774 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
775
776 **/
777 EFI_STATUS
778 EFIAPI
779 DxePcdSet32Ex (
780 IN CONST EFI_GUID *Guid,
781 IN UINTN ExTokenNumber,
782 IN UINT32 Value
783 )
784 {
785 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
786 }
787
788 /**
789 Sets an 64-bit value for a given PCD token.
790
791 When the PCD service sets a value, it will check to ensure that the
792 size of the value being set is compatible with the Token's existing definition.
793 If it is not, an error will be returned.
794
795 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
796 @param[in] ExTokenNumber The PCD token number.
797 @param[in] Value The value to set for the PCD token.
798
799 @retval EFI_SUCCESS Procedure returned successfully.
800 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
801 being set was incompatible with a call to this function.
802 Use GetSize() to retrieve the size of the target data.
803 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
804
805 **/
806 EFI_STATUS
807 EFIAPI
808 DxePcdSet64Ex (
809 IN CONST EFI_GUID *Guid,
810 IN UINTN ExTokenNumber,
811 IN UINT64 Value
812 )
813 {
814 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
815 }
816
817 /**
818 Sets a value of a specified size for a given PCD token.
819
820 When the PCD service sets a value, it will check to ensure that the
821 size of the value being set is compatible with the Token's existing definition.
822 If it is not, an error will be returned.
823
824 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
825 @param[in] ExTokenNumber The PCD token number.
826 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
827 On input, if the SizeOfValue is greater than the maximum size supported
828 for this TokenNumber then the output value of SizeOfValue will reflect
829 the maximum size supported for this TokenNumber.
830 @param[in] Buffer The buffer to set for the PCD token.
831
832 @retval EFI_SUCCESS Procedure returned successfully.
833 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
834 being set was incompatible with a call to this function.
835 Use GetSize() to retrieve the size of the target data.
836 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
837
838 **/
839 EFI_STATUS
840 EFIAPI
841 DxePcdSetPtrEx (
842 IN CONST EFI_GUID *Guid,
843 IN UINTN ExTokenNumber,
844 IN OUT UINTN *SizeOfBuffer,
845 IN VOID *Buffer
846 )
847 {
848 return ExSetWorker(ExTokenNumber, Guid, Buffer, SizeOfBuffer, TRUE);
849 }
850
851 /**
852 Sets an Boolean value for a given PCD token.
853
854 When the PCD service sets a value, it will check to ensure that the
855 size of the value being set is compatible with the Token's existing definition.
856 If it is not, an error will be returned.
857
858 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
859 @param[in] ExTokenNumber The PCD token number.
860 @param[in] Value The value to set for the PCD token.
861
862 @retval EFI_SUCCESS Procedure returned successfully.
863 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
864 being set was incompatible with a call to this function.
865 Use GetSize() to retrieve the size of the target data.
866 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
867
868 **/
869 EFI_STATUS
870 EFIAPI
871 DxePcdSetBoolEx (
872 IN CONST EFI_GUID *Guid,
873 IN UINTN ExTokenNumber,
874 IN BOOLEAN Value
875 )
876 {
877 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
878 }
879
880 /**
881 Specifies a function to be called anytime the value of a designated token is changed.
882
883 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
884 @param[in] TokenNumber The PCD token number.
885 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
886
887 @retval EFI_SUCCESS The PCD service has successfully established a call event
888 for the CallBackToken requested.
889 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
890
891 **/
892 EFI_STATUS
893 EFIAPI
894 DxeRegisterCallBackOnSet (
895 IN CONST EFI_GUID *Guid, OPTIONAL
896 IN UINTN TokenNumber,
897 IN PCD_PROTOCOL_CALLBACK CallBackFunction
898 )
899 {
900 EFI_STATUS Status;
901
902 if (CallBackFunction == NULL) {
903 return EFI_INVALID_PARAMETER;
904 }
905 //
906 // Aquire lock to prevent reentrance from TPL_CALLBACK level
907 //
908 EfiAcquireLock (&mPcdDatabaseLock);
909
910 Status = DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);
911
912 EfiReleaseLock (&mPcdDatabaseLock);
913
914 return Status;
915 }
916
917 /**
918 Cancels a previously set callback function for a particular PCD token number.
919
920 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
921 @param[in] TokenNumber The PCD token number.
922 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
923
924 @retval EFI_SUCCESS The PCD service has successfully established a call event
925 for the CallBackToken requested.
926 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
927
928 **/
929 EFI_STATUS
930 EFIAPI
931 DxeUnRegisterCallBackOnSet (
932 IN CONST EFI_GUID *Guid, OPTIONAL
933 IN UINTN TokenNumber,
934 IN PCD_PROTOCOL_CALLBACK CallBackFunction
935 )
936 {
937 EFI_STATUS Status;
938
939 if (CallBackFunction == NULL) {
940 return EFI_INVALID_PARAMETER;
941 }
942
943 //
944 // Aquire lock to prevent reentrance from TPL_CALLBACK level
945 //
946 EfiAcquireLock (&mPcdDatabaseLock);
947
948 Status = DxeUnRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);
949
950 EfiReleaseLock (&mPcdDatabaseLock);
951
952 return Status;
953 }
954
955 /**
956 Retrieves the next valid token number in a given namespace.
957
958 This is useful since the PCD infrastructure contains a sparse list of token numbers,
959 and one cannot a priori know what token numbers are valid in the database.
960
961 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
962 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
963 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
964 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
965 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
966 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
967 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
968 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
969
970
971 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token.
972 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is
973 being made to retrieve tokens from the default token space.
974 @param[in,out] TokenNumber
975 A pointer to the PCD token number to use to find the subsequent token number.
976
977 @retval EFI_SUCCESS The PCD service retrieved the next valid token number. Or the input token number
978 is already the last valid token number in the PCD database.
979 In the later case, *TokenNumber is updated with the value of 0.
980 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
981
982 **/
983 EFI_STATUS
984 EFIAPI
985 DxePcdGetNextToken (
986 IN CONST EFI_GUID *Guid, OPTIONAL
987 IN OUT UINTN *TokenNumber
988 )
989 {
990 EFI_STATUS Status;
991 BOOLEAN PeiExMapTableEmpty;
992 BOOLEAN DxeExMapTableEmpty;
993
994 Status = EFI_NOT_FOUND;
995 PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;
996 DxeExMapTableEmpty = DXE_EXMAP_TABLE_EMPTY;
997
998 //
999 // Scan the local token space
1000 //
1001 if (Guid == NULL) {
1002 // EBC compiler is very choosy. It may report warning about comparison
1003 // between UINTN and 0 . So we add 1 in each size of the
1004 // comparison.
1005 if (((*TokenNumber + 1 > PEI_NEX_TOKEN_NUMBER + 1) && (*TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1)) ||
1006 ((*TokenNumber + 1 > (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER + 1)))) {
1007 return EFI_NOT_FOUND;
1008 }
1009
1010 (*TokenNumber)++;
1011 if ((*TokenNumber + 1 > PEI_NEX_TOKEN_NUMBER + 1) &&
1012 (*TokenNumber <= PEI_LOCAL_TOKEN_NUMBER)) {
1013 //
1014 // The first Non-Ex type Token Number for DXE PCD
1015 // database is PEI_LOCAL_TOKEN_NUMBER
1016 //
1017 *TokenNumber = PEI_LOCAL_TOKEN_NUMBER;
1018 } else if (*TokenNumber + 1 > DXE_NEX_TOKEN_NUMBER + PEI_LOCAL_TOKEN_NUMBER + 1) {
1019 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
1020 }
1021 return EFI_SUCCESS;
1022 }
1023
1024 if (PeiExMapTableEmpty && DxeExMapTableEmpty) {
1025 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
1026 return EFI_NOT_FOUND;
1027 }
1028
1029 if (!PeiExMapTableEmpty) {
1030 Status = ExGetNextTokeNumber (
1031 Guid,
1032 TokenNumber,
1033 mPcdDatabase->PeiDb.Init.GuidTable,
1034 sizeof(mPcdDatabase->PeiDb.Init.GuidTable),
1035 mPcdDatabase->PeiDb.Init.ExMapTable,
1036 sizeof(mPcdDatabase->PeiDb.Init.ExMapTable)
1037 );
1038 }
1039
1040 if (Status == EFI_SUCCESS) {
1041 return Status;
1042 }
1043
1044 if (!DxeExMapTableEmpty) {
1045 Status = ExGetNextTokeNumber (
1046 Guid,
1047 TokenNumber,
1048 mPcdDatabase->DxeDb.Init.GuidTable,
1049 sizeof(mPcdDatabase->DxeDb.Init.GuidTable),
1050 mPcdDatabase->DxeDb.Init.ExMapTable,
1051 sizeof(mPcdDatabase->DxeDb.Init.ExMapTable)
1052 );
1053 }
1054
1055 return Status;
1056 }
1057
1058 /**
1059 Get all token space guid table which is different with given token space guid.
1060
1061 @param ExMapTableSize The size of guid table
1062 @param ExMapTable Token space guid table that want to be scaned.
1063 @param GuidTable Guid table
1064
1065 @return all token space guid table which is different with given token space guid.
1066
1067 **/
1068 EFI_GUID **
1069 GetDistinctTokenSpace (
1070 IN OUT UINTN *ExMapTableSize,
1071 IN DYNAMICEX_MAPPING *ExMapTable,
1072 IN EFI_GUID *GuidTable
1073 )
1074 {
1075 EFI_GUID **DistinctTokenSpace;
1076 UINTN OldGuidIndex;
1077 UINTN TsIdx;
1078 UINTN Idx;
1079
1080
1081 DistinctTokenSpace = AllocateZeroPool (*ExMapTableSize * sizeof (EFI_GUID *));
1082 ASSERT (DistinctTokenSpace != NULL);
1083
1084 TsIdx = 0;
1085 OldGuidIndex = ExMapTable[0].ExGuidIndex;
1086 DistinctTokenSpace[TsIdx] = &GuidTable[OldGuidIndex];
1087 for (Idx = 1; Idx < *ExMapTableSize; Idx++) {
1088 if (ExMapTable[Idx].ExGuidIndex != OldGuidIndex) {
1089 OldGuidIndex = ExMapTable[Idx].ExGuidIndex;
1090 DistinctTokenSpace[++TsIdx] = &GuidTable[OldGuidIndex];
1091 }
1092 }
1093
1094 //
1095 // The total number of Distinct Token Space
1096 // is TsIdx + 1 because we use TsIdx as a index
1097 // to the DistinctTokenSpace[]
1098 //
1099 *ExMapTableSize = TsIdx + 1;
1100 return DistinctTokenSpace;
1101
1102 }
1103
1104 /**
1105 Get next token space in PCD database according to given token space guid.
1106
1107 @param Guid Given token space guid. If NULL, then Guid will be set to
1108 the first PCD token space in PCD database, If not NULL, then
1109 Guid will be set to next PCD token space.
1110
1111 @retval EFI_UNSUPPORTED
1112 @retval EFI_NOT_FOUND If PCD database has no token space table or can not find given
1113 token space in PCD database.
1114 @retval EFI_SUCCESS Success to get next token space guid.
1115 **/
1116 EFI_STATUS
1117 EFIAPI
1118 DxePcdGetNextTokenSpace (
1119 IN OUT CONST EFI_GUID **Guid
1120 )
1121 {
1122 UINTN Idx;
1123 UINTN Idx2;
1124 UINTN Idx3;
1125 UINTN PeiTokenSpaceTableSize;
1126 UINTN DxeTokenSpaceTableSize;
1127 EFI_GUID **PeiTokenSpaceTable;
1128 EFI_GUID **DxeTokenSpaceTable;
1129 BOOLEAN Match;
1130 BOOLEAN PeiExMapTableEmpty;
1131 BOOLEAN DxeExMapTableEmpty;
1132
1133 ASSERT (Guid != NULL);
1134
1135 PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;
1136 DxeExMapTableEmpty = DXE_EXMAP_TABLE_EMPTY;
1137
1138 if (PeiExMapTableEmpty && DxeExMapTableEmpty) {
1139 if (*Guid != NULL) {
1140 return EFI_NOT_FOUND;
1141 } else {
1142 return EFI_SUCCESS;
1143 }
1144 }
1145
1146
1147 if (TmpTokenSpaceBuffer[0] == NULL) {
1148 PeiTokenSpaceTableSize = 0;
1149
1150 if (!PeiExMapTableEmpty) {
1151 PeiTokenSpaceTableSize = PEI_EXMAPPING_TABLE_SIZE;
1152 PeiTokenSpaceTable = GetDistinctTokenSpace (&PeiTokenSpaceTableSize,
1153 mPcdDatabase->PeiDb.Init.ExMapTable,
1154 mPcdDatabase->PeiDb.Init.GuidTable
1155 );
1156 CopyMem (TmpTokenSpaceBuffer, PeiTokenSpaceTable, sizeof (EFI_GUID*) * PeiTokenSpaceTableSize);
1157 }
1158
1159 if (!DxeExMapTableEmpty) {
1160 DxeTokenSpaceTableSize = DXE_EXMAPPING_TABLE_SIZE;
1161 DxeTokenSpaceTable = GetDistinctTokenSpace (&DxeTokenSpaceTableSize,
1162 mPcdDatabase->DxeDb.Init.ExMapTable,
1163 mPcdDatabase->DxeDb.Init.GuidTable
1164 );
1165
1166 //
1167 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1168 //
1169 for (Idx2 = 0, Idx3 = PeiTokenSpaceTableSize; Idx2 < DxeTokenSpaceTableSize; Idx2++) {
1170 Match = FALSE;
1171 for (Idx = 0; Idx < PeiTokenSpaceTableSize; Idx++) {
1172 if (CompareGuid (TmpTokenSpaceBuffer[Idx], DxeTokenSpaceTable[Idx2])) {
1173 Match = TRUE;
1174 break;
1175 }
1176 }
1177 if (!Match) {
1178 TmpTokenSpaceBuffer[Idx3++] = DxeTokenSpaceTable[Idx2];
1179 }
1180 }
1181 }
1182 }
1183
1184 if (*Guid == NULL) {
1185 *Guid = TmpTokenSpaceBuffer[0];
1186 return EFI_SUCCESS;
1187 }
1188
1189 for (Idx = 0; Idx < (PEI_EXMAPPING_TABLE_SIZE + DXE_EXMAPPING_TABLE_SIZE); Idx++) {
1190 if(CompareGuid (*Guid, TmpTokenSpaceBuffer[Idx])) {
1191 Idx++;
1192 *Guid = TmpTokenSpaceBuffer[Idx];
1193 return EFI_SUCCESS;
1194 }
1195 }
1196
1197 return EFI_NOT_FOUND;
1198 }
1199
1200