]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/PCD/Pei/Pcd.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Pcd.c
1 /** @file
2 PCD PEIM manage PCD database to manage all dynamic PCD in PEI phase. PCD PEIM
3 also produce PCD_PPI.
4
5 Copyright (c) 2006, 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 PCD_PPI mPcdPpiInstance = {
19 PeiPcdSetSku,
20
21 PeiPcdGet8,
22 PeiPcdGet16,
23 PeiPcdGet32,
24 PeiPcdGet64,
25 PeiPcdGetPtr,
26 PeiPcdGetBool,
27 PeiPcdGetSize,
28
29 PeiPcdGet8Ex,
30 PeiPcdGet16Ex,
31 PeiPcdGet32Ex,
32 PeiPcdGet64Ex,
33 PeiPcdGetPtrEx,
34 PeiPcdGetBoolEx,
35 PeiPcdGetSizeEx,
36
37 PeiPcdSet8,
38 PeiPcdSet16,
39 PeiPcdSet32,
40 PeiPcdSet64,
41 PeiPcdSetPtr,
42 PeiPcdSetBool,
43
44 PeiPcdSet8Ex,
45 PeiPcdSet16Ex,
46 PeiPcdSet32Ex,
47 PeiPcdSet64Ex,
48 PeiPcdSetPtrEx,
49 PeiPcdSetBoolEx,
50
51 PeiRegisterCallBackOnSet,
52 PcdUnRegisterCallBackOnSet,
53 PeiPcdGetNextToken,
54 PeiPcdGetNextTokenSpace
55 };
56
57 EFI_PEI_PPI_DESCRIPTOR mPpiPCD = {
58 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
59 &gPcdPpiGuid,
60 &mPcdPpiInstance
61 };
62
63 /**
64 Main entry for PCD PEIM driver.
65
66 This routine initialize the PCD database for PEI phase and install PCD_PPI.
67
68 @param FfsHeader Pointer to PEIM FFS header image
69 @param PeiServices Pointer to EFI_PEI_SERVICES
70
71 @return Status of install PCD_PPI
72
73 **/
74 EFI_STATUS
75 EFIAPI
76 PcdPeimInit (
77 IN EFI_FFS_FILE_HEADER *FfsHeader,
78 IN EFI_PEI_SERVICES **PeiServices
79 )
80 {
81 BuildPcdDatabase ();
82
83 return PeiServicesInstallPpi (&mPpiPCD);
84 }
85
86 /**
87 Sets the SKU value for subsequent calls to set or get PCD token values.
88
89 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
90 SetSku() is normally called only once by the system.
91
92 For each item (token), the database can hold a single value that applies to all SKUs,
93 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
94 SKU-specific values are called SKU enabled.
95
96 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
97 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
98 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
99 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
100 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
101 set for that Id, the results are unpredictable.
102
103 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
104 set values associated with a PCD token.
105
106 @retval VOID
107
108 **/
109 VOID
110 EFIAPI
111 PeiPcdSetSku (
112 IN UINTN SkuId
113 )
114 {
115
116 GetPcdDatabase()->Init.SystemSkuId = (SKU_ID) SkuId;
117
118 return;
119 }
120
121 /**
122 Retrieves an 8-bit value for a given PCD token.
123
124 Retrieves the current byte-sized value for a PCD token number.
125 If the TokenNumber is invalid, the results are unpredictable.
126
127 @param[in] TokenNumber The PCD token number.
128
129 @return The UINT8 value.
130
131 **/
132 UINT8
133 EFIAPI
134 PeiPcdGet8 (
135 IN UINTN TokenNumber
136 )
137 {
138 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));
139 }
140
141 /**
142 Retrieves an 16-bit value for a given PCD token.
143
144 Retrieves the current 16-bits value for a PCD token number.
145 If the TokenNumber is invalid, the results are unpredictable.
146
147 @param[in] TokenNumber The PCD token number.
148
149 @return The UINT16 value.
150
151 **/
152 UINT16
153 EFIAPI
154 PeiPcdGet16 (
155 IN UINTN TokenNumber
156 )
157 {
158 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));
159 }
160
161 /**
162 Retrieves an 32-bit value for a given PCD token.
163
164 Retrieves the current 32-bits value for a PCD token number.
165 If the TokenNumber is invalid, the results are unpredictable.
166
167 @param[in] TokenNumber The PCD token number.
168
169 @return The UINT32 value.
170
171 **/
172 UINT32
173 EFIAPI
174 PeiPcdGet32 (
175 IN UINTN TokenNumber
176 )
177 {
178 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));
179 }
180
181 /**
182 Retrieves an 64-bit value for a given PCD token.
183
184 Retrieves the current 64-bits 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 UINT64 value.
190
191 **/
192 UINT64
193 EFIAPI
194 PeiPcdGet64 (
195 IN UINTN TokenNumber
196 )
197 {
198 return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));
199 }
200
201 /**
202 Retrieves a pointer to a value for a given PCD token.
203
204 Retrieves the current pointer to the buffer for a PCD token number.
205 Do not make any assumptions about the alignment of the pointer that
206 is returned by this function call. If the TokenNumber is invalid,
207 the results are unpredictable.
208
209 @param[in] TokenNumber The PCD token number.
210
211 @return The pointer to the buffer to be retrived.
212
213 **/
214 VOID *
215 EFIAPI
216 PeiPcdGetPtr (
217 IN UINTN TokenNumber
218 )
219 {
220 return GetWorker (TokenNumber, 0);
221 }
222
223 /**
224 Retrieves a Boolean value for a given PCD token.
225
226 Retrieves the current boolean value for a PCD token number.
227 Do not make any assumptions about the alignment of the pointer that
228 is returned by this function call. If the TokenNumber is invalid,
229 the results are unpredictable.
230
231 @param[in] TokenNumber The PCD token number.
232
233 @return The Boolean value.
234
235 **/
236 BOOLEAN
237 EFIAPI
238 PeiPcdGetBool (
239 IN UINTN TokenNumber
240 )
241 {
242 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));
243 }
244
245 /**
246 Retrieves the size of the value for a given PCD token.
247
248 Retrieves the current size of a particular PCD token.
249 If the TokenNumber is invalid, the results are unpredictable.
250
251 @param[in] TokenNumber The PCD token number.
252
253 @return The size of the value for the PCD token.
254
255 **/
256 UINTN
257 EFIAPI
258 PeiPcdGetSize (
259 IN UINTN TokenNumber
260 )
261 {
262 PEI_PCD_DATABASE *PeiPcdDb;
263 UINTN Size;
264 UINTN MaxSize;
265
266 //
267 // If DebugAssertEnabled is TRUE, we still need to provide the GET size
268 // function as GetWorker and SetWoker need this function to do ASSERT.
269 //
270 if ((!FeaturePcdGet(PcdPeiPcdDatabaseGetSizeEnabled)) &&
271 (!DebugAssertEnabled ())) {
272 return 0;
273 }
274
275 PeiPcdDb = GetPcdDatabase ();
276 //
277 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
278 // We have to decrement TokenNumber by 1 to make it usable
279 // as the array index.
280 //
281 TokenNumber--;
282
283 // EBC compiler is very choosy. It may report warning about comparison
284 // between UINTN and 0 . So we add 1 in each size of the
285 // comparison.
286 ASSERT (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
287
288 Size = (PeiPcdDb->Init.LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;
289
290 if (Size == 0) {
291 //
292 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
293 //
294 return GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);
295 } else {
296 return Size;
297 }
298
299 }
300
301 /**
302 Retrieves an 8-bit value for a given PCD token.
303
304 Retrieves the 8-bit value of a particular PCD token.
305 If the TokenNumber is invalid or the token space
306 specified by Guid does not exist, the results are
307 unpredictable.
308
309 @param[in] Guid The token space for the token number.
310 @param[in] ExTokenNumber The PCD token number.
311
312 @return The size 8-bit value for the PCD token.
313
314 **/
315 UINT8
316 EFIAPI
317 PeiPcdGet8Ex (
318 IN CONST EFI_GUID *Guid,
319 IN UINTN ExTokenNumber
320 )
321 {
322 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));
323 }
324
325 /**
326 Retrieves an 16-bit value for a given PCD token.
327
328 Retrieves the 16-bit value of a particular PCD token.
329 If the TokenNumber is invalid or the token space
330 specified by Guid does not exist, the results are
331 unpredictable.
332
333 @param[in] Guid The token space for the token number.
334 @param[in] ExTokenNumber The PCD token number.
335
336 @return The size 16-bit value for the PCD token.
337
338 **/
339 UINT16
340 EFIAPI
341 PeiPcdGet16Ex (
342 IN CONST EFI_GUID *Guid,
343 IN UINTN ExTokenNumber
344 )
345 {
346 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));
347 }
348
349 /**
350 Retrieves an 32-bit value for a given PCD token.
351
352 Retrieves the 32-bit value of a particular PCD token.
353 If the TokenNumber is invalid or the token space
354 specified by Guid does not exist, the results are
355 unpredictable.
356
357 @param[in] Guid The token space for the token number.
358 @param[in] ExTokenNumber The PCD token number.
359
360 @return The size 32-bit value for the PCD token.
361
362 **/
363 UINT32
364 EFIAPI
365 PeiPcdGet32Ex (
366 IN CONST EFI_GUID *Guid,
367 IN UINTN ExTokenNumber
368 )
369 {
370 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));
371 }
372
373 /**
374 Retrieves an 64-bit value for a given PCD token.
375
376 Retrieves the 64-bit value of a particular PCD token.
377 If the TokenNumber is invalid or the token space
378 specified by Guid does not exist, the results are
379 unpredictable.
380
381 @param[in] Guid The token space for the token number.
382 @param[in] ExTokenNumber The PCD token number.
383
384 @return The size 64-bit value for the PCD token.
385
386 **/
387 UINT64
388 EFIAPI
389 PeiPcdGet64Ex (
390 IN CONST EFI_GUID *Guid,
391 IN UINTN ExTokenNumber
392 )
393 {
394 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));
395 }
396
397 /**
398 Retrieves a pointer to a value for a given PCD token.
399
400 Retrieves the current pointer to the buffer for a PCD token number.
401 Do not make any assumptions about the alignment of the pointer that
402 is returned by this function call. If the TokenNumber is invalid,
403 the results are unpredictable.
404
405 @param[in] Guid The token space for the token number.
406 @param[in] ExTokenNumber The PCD token number.
407
408 @return The pointer to the buffer to be retrived.
409
410 **/
411 VOID *
412 EFIAPI
413 PeiPcdGetPtrEx (
414 IN CONST EFI_GUID *Guid,
415 IN UINTN ExTokenNumber
416 )
417 {
418 return ExGetWorker (Guid, ExTokenNumber, 0);
419 }
420
421 /**
422 Retrieves an Boolean value for a given PCD token.
423
424 Retrieves the Boolean value of a particular PCD token.
425 If the TokenNumber is invalid or the token space
426 specified by Guid does not exist, the results are
427 unpredictable.
428
429 @param[in] Guid The token space for the token number.
430 @param[in] ExTokenNumber The PCD token number.
431
432 @return The size Boolean value for the PCD token.
433
434 **/
435 BOOLEAN
436 EFIAPI
437 PeiPcdGetBoolEx (
438 IN CONST EFI_GUID *Guid,
439 IN UINTN ExTokenNumber
440 )
441 {
442 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));
443 }
444
445 /**
446 Retrieves the size of the value for a given PCD token.
447
448 Retrieves the current size of a particular PCD token.
449 If the TokenNumber is invalid, the results are unpredictable.
450
451 @param[in] Guid The token space for the token number.
452 @param[in] ExTokenNumber The PCD token number.
453
454 @return The size of the value for the PCD token.
455
456 **/
457 UINTN
458 EFIAPI
459 PeiPcdGetSizeEx (
460 IN CONST EFI_GUID *Guid,
461 IN UINTN ExTokenNumber
462 )
463 {
464 if ((!FeaturePcdGet (PcdPeiPcdDatabaseGetSizeEnabled)) || !FeaturePcdGet (PcdPeiPcdDatabaseExEnabled)) {
465 return 0;
466 }
467
468 return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));
469 }
470
471 /**
472 Sets an 8-bit value for a given PCD token.
473
474 When the PCD service sets a value, it will check to ensure that the
475 size of the value being set is compatible with the Token's existing definition.
476 If it is not, an error will be returned.
477
478 @param[in] TokenNumber The PCD token number.
479 @param[in] Value The value to set for the PCD token.
480
481 @retval EFI_SUCCESS Procedure returned successfully.
482 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
483 being set was incompatible with a call to this function.
484 Use GetSize() to retrieve the size of the target data.
485 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
486
487 **/
488 EFI_STATUS
489 EFIAPI
490 PeiPcdSet8 (
491 IN UINTN TokenNumber,
492 IN UINT8 Value
493 )
494 {
495 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
496 }
497
498 /**
499 Sets an 16-bit value for a given PCD token.
500
501 When the PCD service sets a value, it will check to ensure that the
502 size of the value being set is compatible with the Token's existing definition.
503 If it is not, an error will be returned.
504
505 @param[in] TokenNumber The PCD token number.
506 @param[in] Value The value to set for the PCD token.
507
508 @retval EFI_SUCCESS Procedure returned successfully.
509 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
510 being set was incompatible with a call to this function.
511 Use GetSize() to retrieve the size of the target data.
512 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
513
514 **/
515 EFI_STATUS
516 EFIAPI
517 PeiPcdSet16 (
518 IN UINTN TokenNumber,
519 IN UINT16 Value
520 )
521 {
522 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
523 }
524
525 /**
526 Sets an 32-bit value for a given PCD token.
527
528 When the PCD service sets a value, it will check to ensure that the
529 size of the value being set is compatible with the Token's existing definition.
530 If it is not, an error will be returned.
531
532 @param[in] TokenNumber The PCD token number.
533 @param[in] Value The value to set for the PCD token.
534
535 @retval EFI_SUCCESS Procedure returned successfully.
536 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
537 being set was incompatible with a call to this function.
538 Use GetSize() to retrieve the size of the target data.
539 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
540
541 **/
542 EFI_STATUS
543 EFIAPI
544 PeiPcdSet32 (
545 IN UINTN TokenNumber,
546 IN UINT32 Value
547 )
548 {
549 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
550 }
551
552 /**
553 Sets an 64-bit value for a given PCD token.
554
555 When the PCD service sets a value, it will check to ensure that the
556 size of the value being set is compatible with the Token's existing definition.
557 If it is not, an error will be returned.
558
559 @param[in] TokenNumber The PCD token number.
560 @param[in] Value The value to set for the PCD token.
561
562 @retval EFI_SUCCESS Procedure returned successfully.
563 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
564 being set was incompatible with a call to this function.
565 Use GetSize() to retrieve the size of the target data.
566 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
567
568 **/
569 EFI_STATUS
570 EFIAPI
571 PeiPcdSet64 (
572 IN UINTN TokenNumber,
573 IN UINT64 Value
574 )
575 {
576 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
577 }
578
579 /**
580 Sets a value of a specified size for a given PCD token.
581
582 When the PCD service sets a value, it will check to ensure that the
583 size of the value being set is compatible with the Token's existing definition.
584 If it is not, an error will be returned.
585
586 @param[in] TokenNumber The PCD token number.
587 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
588 On input, if the SizeOfValue is greater than the maximum size supported
589 for this TokenNumber then the output value of SizeOfValue will reflect
590 the maximum size supported for this TokenNumber.
591 @param[in] Buffer The buffer to set for the PCD token.
592
593 @retval EFI_SUCCESS Procedure returned successfully.
594 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
595 being set was incompatible with a call to this function.
596 Use GetSize() to retrieve the size of the target data.
597 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
598
599 **/
600 EFI_STATUS
601 EFIAPI
602 PeiPcdSetPtr (
603 IN UINTN TokenNumber,
604 IN OUT UINTN *SizeOfBuffer,
605 IN VOID *Buffer
606 )
607 {
608 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);
609 }
610
611 /**
612 Sets an Boolean value for a given PCD token.
613
614 When the PCD service sets a value, it will check to ensure that the
615 size of the value being set is compatible with the Token's existing definition.
616 If it is not, an error will be returned.
617
618 @param[in] TokenNumber The PCD token number.
619 @param[in] Value The value to set for the PCD token.
620
621 @retval EFI_SUCCESS Procedure returned successfully.
622 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
623 being set was incompatible with a call to this function.
624 Use GetSize() to retrieve the size of the target data.
625 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
626
627 **/
628 EFI_STATUS
629 EFIAPI
630 PeiPcdSetBool (
631 IN UINTN TokenNumber,
632 IN BOOLEAN Value
633 )
634 {
635 return SetValueWorker (TokenNumber, &Value, sizeof (Value));
636 }
637
638 /**
639 Sets an 8-bit value for a given PCD token.
640
641 When the PCD service sets a value, it will check to ensure that the
642 size of the value being set is compatible with the Token's existing definition.
643 If it is not, an error will be returned.
644
645 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
646 @param[in] ExTokenNumber The PCD token number.
647 @param[in] Value The value to set for the PCD token.
648
649 @retval EFI_SUCCESS Procedure returned successfully.
650 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
651 being set was incompatible with a call to this function.
652 Use GetSize() to retrieve the size of the target data.
653 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
654
655 **/
656 EFI_STATUS
657 EFIAPI
658 PeiPcdSet8Ex (
659 IN CONST EFI_GUID *Guid,
660 IN UINTN ExTokenNumber,
661 IN UINT8 Value
662 )
663 {
664 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
665 }
666
667 /**
668 Sets an 16-bit value for a given PCD token.
669
670 When the PCD service sets a value, it will check to ensure that the
671 size of the value being set is compatible with the Token's existing definition.
672 If it is not, an error will be returned.
673
674 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
675 @param[in] ExTokenNumber The PCD token number.
676 @param[in] Value The value to set for the PCD token.
677
678 @retval EFI_SUCCESS Procedure returned successfully.
679 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
680 being set was incompatible with a call to this function.
681 Use GetSize() to retrieve the size of the target data.
682 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
683
684 **/
685 EFI_STATUS
686 EFIAPI
687 PeiPcdSet16Ex (
688 IN CONST EFI_GUID *Guid,
689 IN UINTN ExTokenNumber,
690 IN UINT16 Value
691 )
692 {
693 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
694 }
695
696 /**
697 Sets an 32-bit value for a given PCD token.
698
699 When the PCD service sets a value, it will check to ensure that the
700 size of the value being set is compatible with the Token's existing definition.
701 If it is not, an error will be returned.
702
703 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
704 @param[in] ExTokenNumber The PCD token number.
705 @param[in] Value The value to set for the PCD token.
706
707 @retval EFI_SUCCESS Procedure returned successfully.
708 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
709 being set was incompatible with a call to this function.
710 Use GetSize() to retrieve the size of the target data.
711 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
712
713 **/
714 EFI_STATUS
715 EFIAPI
716 PeiPcdSet32Ex (
717 IN CONST EFI_GUID *Guid,
718 IN UINTN ExTokenNumber,
719 IN UINT32 Value
720 )
721 {
722 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
723 }
724
725 /**
726 Sets an 64-bit value for a given PCD token.
727
728 When the PCD service sets a value, it will check to ensure that the
729 size of the value being set is compatible with the Token's existing definition.
730 If it is not, an error will be returned.
731
732 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
733 @param[in] ExTokenNumber The PCD token number.
734 @param[in] Value The value to set for the PCD token.
735
736 @retval EFI_SUCCESS Procedure returned successfully.
737 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
738 being set was incompatible with a call to this function.
739 Use GetSize() to retrieve the size of the target data.
740 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
741
742 **/
743 EFI_STATUS
744 EFIAPI
745 PeiPcdSet64Ex (
746 IN CONST EFI_GUID *Guid,
747 IN UINTN ExTokenNumber,
748 IN UINT64 Value
749 )
750 {
751 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
752 }
753
754 /**
755 Sets a value of a specified size for a given PCD token.
756
757 When the PCD service sets a value, it will check to ensure that the
758 size of the value being set is compatible with the Token's existing definition.
759 If it is not, an error will be returned.
760
761 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
762 @param[in] ExTokenNumber The PCD token number.
763 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
764 On input, if the SizeOfValue is greater than the maximum size supported
765 for this TokenNumber then the output value of SizeOfValue will reflect
766 the maximum size supported for this TokenNumber.
767 @param[in] Value The buffer to set for the PCD token.
768
769 @retval EFI_SUCCESS Procedure returned successfully.
770 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
771 being set was incompatible with a call to this function.
772 Use GetSize() to retrieve the size of the target data.
773 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
774
775 **/
776 EFI_STATUS
777 EFIAPI
778 PeiPcdSetPtrEx (
779 IN CONST EFI_GUID *Guid,
780 IN UINTN ExTokenNumber,
781 IN OUT UINTN *SizeOfBuffer,
782 IN VOID *Value
783 )
784 {
785 return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);
786 }
787
788 /**
789 Sets an Boolean 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 PeiPcdSetBoolEx (
809 IN CONST EFI_GUID *Guid,
810 IN UINTN ExTokenNumber,
811 IN BOOLEAN Value
812 )
813 {
814 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
815 }
816
817 /**
818 Specifies a function to be called anytime the value of a designated token is changed.
819
820 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
821 @param[in] ExTokenNumber The PCD token number.
822 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
823
824 @retval EFI_SUCCESS The PCD service has successfully established a call event
825 for the CallBackToken requested.
826 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
827
828 **/
829 EFI_STATUS
830 EFIAPI
831 PeiRegisterCallBackOnSet (
832 IN CONST EFI_GUID *Guid, OPTIONAL
833 IN UINTN ExTokenNumber,
834 IN PCD_PPI_CALLBACK CallBackFunction
835 )
836 {
837 if (!FeaturePcdGet(PcdPeiPcdDatabaseCallbackOnSetEnabled)) {
838 return EFI_UNSUPPORTED;
839 }
840
841 ASSERT (CallBackFunction != NULL);
842
843 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);
844 }
845
846 /**
847 Cancels a previously set callback function for a particular PCD token number.
848
849 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
850 @param[in] ExTokenNumber The PCD token number.
851 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
852
853 @retval EFI_SUCCESS The PCD service has successfully established a call event
854 for the CallBackToken requested.
855 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
856
857 **/
858 EFI_STATUS
859 EFIAPI
860 PcdUnRegisterCallBackOnSet (
861 IN CONST EFI_GUID *Guid, OPTIONAL
862 IN UINTN ExTokenNumber,
863 IN PCD_PPI_CALLBACK CallBackFunction
864 )
865 {
866 if (!FeaturePcdGet(PcdPeiPcdDatabaseCallbackOnSetEnabled)) {
867 return EFI_UNSUPPORTED;
868 }
869
870 ASSERT (CallBackFunction != NULL);
871
872 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);
873 }
874
875 /**
876 Retrieves the next valid PCD token for a given namespace.
877
878 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
879 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
880 If the input token namespace or token number does not exist on the platform,
881 an error is returned and the value of *TokenNumber is undefined. To retrieve the "first" token,
882 have the pointer reference a TokenNumber value of 0. If the input token number is 0 and
883 there is no valid token number for this token namespace, *TokenNumber will be assigned to
884 0 and the function return EFI_SUCCESS. If the token number is the last valid token number,
885 *TokenNumber will be assigned to 0 and the function return EFI_SUCCESS.
886
887 @retval EFI_SUCCESS The PCD service retrieved the next valid token number. Or the input token number
888 is already the last valid token number in the PCD database.
889 In the later case, *TokenNumber is updated with the value of 0.
890 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
891
892 **/
893 EFI_STATUS
894 EFIAPI
895 PeiPcdGetNextToken (
896 IN CONST EFI_GUID *Guid, OPTIONAL
897 IN OUT UINTN *TokenNumber
898 )
899 {
900 UINTN GuidTableIdx;
901 PEI_PCD_DATABASE *PeiPcdDb;
902 EFI_GUID *MatchGuid;
903 DYNAMICEX_MAPPING *ExMapTable;
904 UINTN Index;
905 BOOLEAN Found;
906 BOOLEAN PeiExMapTableEmpty;
907
908 if (!FeaturePcdGet (PcdPeiPcdDatabaseTraverseEnabled)) {
909 return EFI_UNSUPPORTED;
910 }
911
912 PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;
913
914 if (Guid == NULL) {
915 if (*TokenNumber > PEI_NEX_TOKEN_NUMBER) {
916 return EFI_NOT_FOUND;
917 }
918 (*TokenNumber)++;
919 if (*TokenNumber > PEI_NEX_TOKEN_NUMBER) {
920 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
921 }
922 return EFI_SUCCESS;
923 } else {
924 if (PeiExMapTableEmpty) {
925 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
926 return EFI_SUCCESS;
927 }
928
929 //
930 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
931 // 1) ExGuid
932 // 2) ExTokenNumber
933 //
934 PeiPcdDb = GetPcdDatabase ();
935
936 MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), Guid);
937
938 if (MatchGuid == NULL) {
939 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
940 return EFI_NOT_FOUND;
941 }
942
943 GuidTableIdx = MatchGuid - PeiPcdDb->Init.GuidTable;
944
945 ExMapTable = PeiPcdDb->Init.ExMapTable;
946
947 Found = FALSE;
948 //
949 // Locate the GUID in ExMapTable first.
950 //
951 for (Index = 0; Index < PEI_EXMAPPING_TABLE_SIZE; Index++) {
952 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {
953 Found = TRUE;
954 break;
955 }
956 }
957
958 if (Found) {
959 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {
960 *TokenNumber = ExMapTable[Index].ExTokenNumber;
961 return EFI_SUCCESS;
962 }
963
964 for ( ; Index < PEI_EXMAPPING_TABLE_SIZE; Index++) {
965 if (ExMapTable[Index].ExTokenNumber == *TokenNumber) {
966 Index++;
967 if (Index == PEI_EXMAPPING_TABLE_SIZE) {
968 //
969 // Exceed the length of ExMap Table
970 //
971 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
972 return EFI_SUCCESS;
973 }
974 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {
975 *TokenNumber = ExMapTable[Index].ExTokenNumber;
976 return EFI_SUCCESS;
977 } else {
978 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
979 return EFI_SUCCESS;
980 }
981 }
982 }
983 return EFI_NOT_FOUND;
984 }
985 }
986
987 return EFI_NOT_FOUND;
988 }
989
990 /**
991 Retrieves the next valid PCD token namespace for a given namespace.
992
993 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates
994 a known token namespace from which the search will start. On output,
995 it designates the next valid token namespace on the platform. If the input
996 token namespace does not exist on the platform, an error is returned and
997 the value of *Guid is undefined. If *Guid is NULL, then the GUID of the
998 first token space of the current platform is assigned to *Guid the function
999 return EFI_SUCCESS. If *Guid is NULL and there is no namespace exist in
1000 the platform other than the default (NULL) tokennamespace, *Guid is unchanged
1001 and the function return EFI_SUCCESS. If this input token namespace is the last
1002 namespace on the platform, *Guid will be assigned to NULL and the function return
1003 EFI_SUCCESS.
1004
1005 @retval EFI_SUCCESS The PCD service retrieved the next valid token space Guid.
1006 Or the input token space Guid is already the last valid token space Guid
1007 in the PCD database. In the later case, *Guid is updated with the value of NULL.
1008 @retval EFI_NOT_FOUND If the input token namespace does not exist on the platform.
1009
1010 **/
1011 EFI_STATUS
1012 EFIAPI
1013 PeiPcdGetNextTokenSpace (
1014 IN OUT CONST EFI_GUID **Guid
1015 )
1016 {
1017 UINTN GuidTableIdx;
1018 EFI_GUID *MatchGuid;
1019 PEI_PCD_DATABASE *PeiPcdDb;
1020 DYNAMICEX_MAPPING *ExMapTable;
1021 UINTN Index;
1022 BOOLEAN Found;
1023 BOOLEAN PeiExMapTableEmpty;
1024
1025 if (!FeaturePcdGet (PcdPeiPcdDatabaseTraverseEnabled)) {
1026 return EFI_UNSUPPORTED;
1027 }
1028
1029 ASSERT (Guid != NULL);
1030
1031 PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;
1032
1033 if (PeiExMapTableEmpty) {
1034 if (*Guid != NULL) {
1035 return EFI_NOT_FOUND;
1036 } else {
1037 return EFI_SUCCESS;
1038 }
1039 }
1040
1041 //
1042 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
1043 // 1) ExGuid
1044 // 2) ExTokenNumber
1045 //
1046 PeiPcdDb = GetPcdDatabase ();
1047
1048 ExMapTable = PeiPcdDb->Init.ExMapTable;
1049
1050 if (*Guid == NULL) {
1051 //
1052 // return the first Token Space Guid.
1053 //
1054 *Guid = &PeiPcdDb->Init.GuidTable[ExMapTable[0].ExGuidIndex];
1055 return EFI_SUCCESS;
1056 }
1057
1058 MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), *Guid);
1059
1060 if (MatchGuid == NULL) {
1061 return EFI_NOT_FOUND;
1062 }
1063
1064 GuidTableIdx = MatchGuid - PeiPcdDb->Init.GuidTable;
1065
1066 Found = FALSE;
1067 for (Index = 0; Index < PEI_EXMAPPING_TABLE_SIZE; Index++) {
1068 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {
1069 Found = TRUE;
1070 break;
1071 }
1072 }
1073
1074 if (Found) {
1075 Index++;
1076 for ( ; Index < PEI_EXMAPPING_TABLE_SIZE; Index++ ) {
1077 if (ExMapTable[Index].ExGuidIndex != GuidTableIdx ) {
1078 *Guid = &PeiPcdDb->Init.GuidTable[ExMapTable[Index].ExGuidIndex];
1079 return EFI_SUCCESS;
1080 }
1081 }
1082 *Guid = NULL;
1083 return EFI_SUCCESS;
1084 }
1085
1086 return EFI_NOT_FOUND;
1087
1088 }
1089
1090 /**
1091 Get PCD value's size for POINTER type PCD.
1092
1093 The POINTER type PCD's value will be stored into a buffer in specificed size.
1094 The max size of this PCD's value is described in PCD's definition in DEC file.
1095
1096 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1097 @param MaxSize Maxmium size of PCD's value
1098 @param Database Pcd database in PEI phase.
1099
1100 @return PCD value's size for POINTER type PCD.
1101
1102 **/
1103 UINTN
1104 GetPtrTypeSize (
1105 IN UINTN LocalTokenNumberTableIdx,
1106 OUT UINTN *MaxSize,
1107 IN PEI_PCD_DATABASE *Database
1108 )
1109 {
1110 INTN SizeTableIdx;
1111 UINTN LocalTokenNumber;
1112 SKU_ID *SkuIdTable;
1113 SIZE_INFO *SizeTable;
1114 UINTN Index;
1115
1116 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);
1117
1118 LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];
1119
1120 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
1121
1122 SizeTable = Database->Init.SizeTable;
1123
1124 *MaxSize = SizeTable[SizeTableIdx];
1125 //
1126 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1127 // PCD entry.
1128 //
1129 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1130 //
1131 // We have only one entry for VPD enabled PCD entry:
1132 // 1) MAX Size.
1133 // We consider current size is equal to MAX size.
1134 //
1135 return *MaxSize;
1136 } else {
1137 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
1138 //
1139 // We have only two entry for Non-Sku enabled PCD entry:
1140 // 1) MAX SIZE
1141 // 2) Current Size
1142 //
1143 return SizeTable[SizeTableIdx + 1];
1144 } else {
1145 //
1146 // We have these entry for SKU enabled PCD entry
1147 // 1) MAX SIZE
1148 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1149 //
1150 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);
1151 for (Index = 0; Index < SkuIdTable[0]; Index++) {
1152 if (SkuIdTable[1 + Index] == Database->Init.SystemSkuId) {
1153 return SizeTable[SizeTableIdx + 1 + Index];
1154 }
1155 }
1156 return SizeTable[SizeTableIdx + 1];
1157 }
1158 }
1159 }
1160
1161 /**
1162 Set PCD value's size for POINTER type PCD.
1163
1164 The POINTER type PCD's value will be stored into a buffer in specificed size.
1165 The max size of this PCD's value is described in PCD's definition in DEC file.
1166
1167 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1168 @param CurrentSize Maxmium size of PCD's value
1169 @param Database Pcd database in PEI phase.
1170
1171 @retval TRUE Success to set PCD's value size, which is not exceed maxmium size
1172 @retval FALSE Fail to set PCD's value size, which maybe exceed maxmium size
1173
1174 **/
1175 BOOLEAN
1176 SetPtrTypeSize (
1177 IN UINTN LocalTokenNumberTableIdx,
1178 IN OUT UINTN *CurrentSize,
1179 IN PEI_PCD_DATABASE *Database
1180 )
1181 {
1182 INTN SizeTableIdx;
1183 UINTN LocalTokenNumber;
1184 SKU_ID *SkuIdTable;
1185 SIZE_INFO *SizeTable;
1186 UINTN Index;
1187 UINTN MaxSize;
1188
1189 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);
1190
1191 LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];
1192
1193 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
1194
1195 SizeTable = Database->Init.SizeTable;
1196
1197 MaxSize = SizeTable[SizeTableIdx];
1198 //
1199 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1200 // PCD entry.
1201 //
1202 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1203 //
1204 // We shouldn't come here as we don't support SET for VPD
1205 //
1206 ASSERT (FALSE);
1207 return FALSE;
1208 } else {
1209 if ((*CurrentSize > MaxSize) ||
1210 (*CurrentSize == MAX_ADDRESS)) {
1211 *CurrentSize = MaxSize;
1212 return FALSE;
1213 }
1214
1215 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
1216 //
1217 // We have only two entry for Non-Sku enabled PCD entry:
1218 // 1) MAX SIZE
1219 // 2) Current Size
1220 //
1221 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
1222 return TRUE;
1223 } else {
1224 //
1225 // We have these entry for SKU enabled PCD entry
1226 // 1) MAX SIZE
1227 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1228 //
1229 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);
1230 for (Index = 0; Index < SkuIdTable[0]; Index++) {
1231 if (SkuIdTable[1 + Index] == Database->Init.SystemSkuId) {
1232 SizeTable[SizeTableIdx + 1 + Index] = (SIZE_INFO) *CurrentSize;
1233 return TRUE;
1234 }
1235 }
1236 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
1237 return TRUE;
1238 }
1239 }
1240
1241 }