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