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