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