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