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