]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/PCD/Pei/Service.h
Add introduction of PCD database in PCD PEIM.
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Service.h
1 /** @file
2 The internal header file declares the private functions used by PeiPcd driver.
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 #ifndef _PEI_PCD_SERVICE_H_
16 #define _PEI_PCD_SERVICE_H_
17
18 #include <PiPei.h>
19 #include <Ppi/ReadOnlyVariable2.h>
20 #include <Ppi/Pcd.h>
21 #include <Guid/PcdDataBaseHobGuid.h>
22 #include <Library/DebugLib.h>
23 #include <Library/PeimEntryPoint.h>
24 #include <Library/BaseLib.h>
25 #include <Library/HobLib.h>
26 #include <Library/PeiServicesLib.h>
27 #include <Library/PcdLib.h>
28 #include <Library/BaseMemoryLib.h>
29
30
31 //
32 // Please make sure the PCD Serivce PEIM Version is consistent with
33 // the version of PCD Database generation tool
34 //
35 #define PCD_SERVICE_PEIM_VERSION 2
36
37 //
38 // PCD_PEI_DATABASE_GENTOOL_VERSION is defined in Autogen.h
39 // and generated by PCD Database generation tool.
40 //
41 //#if (PCD_SERVICE_PEIM_VERSION != PCD_PEI_SERVICE_DRIVER_AUTOGEN_VERSION )
42 // #error "Please make sure the version of PCD Service PEIM and PCD PEI Database Generation Tool matches"
43 //#endif
44
45 //
46 // PPI Interface Implementation Declaration.
47 //
48
49 /**
50 Sets the SKU value for subsequent calls to set or get PCD token values.
51
52 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
53 SetSku() is normally called only once by the system.
54
55 For each item (token), the database can hold a single value that applies to all SKUs,
56 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
57 SKU-specific values are called SKU enabled.
58
59 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
60 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
61 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
62 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
63 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
64 set for that Id, the results are unpredictable.
65
66 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
67 set values associated with a PCD token.
68
69 **/
70 VOID
71 EFIAPI
72 PeiPcdSetSku (
73 IN UINTN SkuId
74 );
75
76 /**
77 Retrieves an 8-bit value for a given PCD token.
78
79 Retrieves the current byte-sized value for a PCD token number.
80 If the TokenNumber is invalid, the results are unpredictable.
81
82 @param[in] TokenNumber The PCD token number.
83
84 @return The UINT8 value.
85
86 **/
87 UINT8
88 EFIAPI
89 PeiPcdGet8 (
90 IN UINTN TokenNumber
91 );
92
93 /**
94 Retrieves an 16-bit value for a given PCD token.
95
96 Retrieves the current 16-bits value for a PCD token number.
97 If the TokenNumber is invalid, the results are unpredictable.
98
99 @param[in] TokenNumber The PCD token number.
100
101 @return The UINT16 value.
102
103 **/
104 UINT16
105 EFIAPI
106 PeiPcdGet16 (
107 IN UINTN TokenNumber
108 );
109
110 /**
111 Retrieves an 32-bit value for a given PCD token.
112
113 Retrieves the current 32-bits value for a PCD token number.
114 If the TokenNumber is invalid, the results are unpredictable.
115
116 @param[in] TokenNumber The PCD token number.
117
118 @return The UINT32 value.
119
120 **/
121 UINT32
122 EFIAPI
123 PeiPcdGet32 (
124 IN UINTN TokenNumber
125 );
126
127 /**
128 Retrieves an 64-bit value for a given PCD token.
129
130 Retrieves the current 64-bits value for a PCD token number.
131 If the TokenNumber is invalid, the results are unpredictable.
132
133 @param[in] TokenNumber The PCD token number.
134
135 @return The UINT64 value.
136
137 **/
138 UINT64
139 EFIAPI
140 PeiPcdGet64 (
141 IN UINTN TokenNumber
142 );
143
144 /**
145 Retrieves a pointer to a value for a given PCD token.
146
147 Retrieves the current pointer to the buffer for a PCD token number.
148 Do not make any assumptions about the alignment of the pointer that
149 is returned by this function call. If the TokenNumber is invalid,
150 the results are unpredictable.
151
152 @param[in] TokenNumber The PCD token number.
153
154 @return The pointer to the buffer to be retrived.
155
156 **/
157 VOID *
158 EFIAPI
159 PeiPcdGetPtr (
160 IN UINTN TokenNumber
161 );
162
163 /**
164 Retrieves a Boolean value for a given PCD token.
165
166 Retrieves the current boolean value for a PCD token number.
167 Do not make any assumptions about the alignment of the pointer that
168 is returned by this function call. If the TokenNumber is invalid,
169 the results are unpredictable.
170
171 @param[in] TokenNumber The PCD token number.
172
173 @return The Boolean value.
174
175 **/
176 BOOLEAN
177 EFIAPI
178 PeiPcdGetBool (
179 IN UINTN TokenNumber
180 );
181
182 /**
183 Retrieves the size of the value for a given PCD token.
184
185 Retrieves the current size of a particular PCD token.
186 If the TokenNumber is invalid, the results are unpredictable.
187
188 @param[in] TokenNumber The PCD token number.
189
190 @return The size of the value for the PCD token.
191
192 **/
193 UINTN
194 EFIAPI
195 PeiPcdGetSize (
196 IN UINTN TokenNumber
197 );
198
199 /**
200 Retrieves an 8-bit value for a given PCD token.
201
202 Retrieves the 8-bit value of a particular PCD token.
203 If the TokenNumber is invalid or the token space
204 specified by Guid does not exist, the results are
205 unpredictable.
206
207 @param[in] Guid The token space for the token number.
208 @param[in] TokenNumber The PCD token number.
209
210 @return The size 8-bit value for the PCD token.
211
212 **/
213 UINT8
214 EFIAPI
215 PeiPcdGet8Ex (
216 IN CONST EFI_GUID *Guid,
217 IN UINTN TokenNumber
218 );
219
220 /**
221 Retrieves an 16-bit value for a given PCD token.
222
223 Retrieves the 16-bit value of a particular PCD token.
224 If the TokenNumber is invalid or the token space
225 specified by Guid does not exist, the results are
226 unpredictable.
227
228 @param[in] Guid The token space for the token number.
229 @param[in] TokenNumber The PCD token number.
230
231 @return The size 16-bit value for the PCD token.
232
233 **/
234 UINT16
235 EFIAPI
236 PeiPcdGet16Ex (
237 IN CONST EFI_GUID *Guid,
238 IN UINTN TokenNumber
239 );
240
241 /**
242 Retrieves an 32-bit value for a given PCD token.
243
244 Retrieves the 32-bit value of a particular PCD token.
245 If the TokenNumber is invalid or the token space
246 specified by Guid does not exist, the results are
247 unpredictable.
248
249 @param[in] Guid The token space for the token number.
250 @param[in] TokenNumber The PCD token number.
251
252 @return The size 32-bit value for the PCD token.
253
254 **/
255 UINT32
256 EFIAPI
257 PeiPcdGet32Ex (
258 IN CONST EFI_GUID *Guid,
259 IN UINTN TokenNumber
260 );
261
262 /**
263 Retrieves an 64-bit value for a given PCD token.
264
265 Retrieves the 64-bit value of a particular PCD token.
266 If the TokenNumber is invalid or the token space
267 specified by Guid does not exist, the results are
268 unpredictable.
269
270 @param[in] Guid The token space for the token number.
271 @param[in] TokenNumber The PCD token number.
272
273 @return The size 64-bit value for the PCD token.
274
275 **/
276 UINT64
277 EFIAPI
278 PeiPcdGet64Ex (
279 IN CONST EFI_GUID *Guid,
280 IN UINTN TokenNumber
281 );
282
283 /**
284 Retrieves a pointer to a value for a given PCD token.
285
286 Retrieves the current pointer to the buffer for a PCD token number.
287 Do not make any assumptions about the alignment of the pointer that
288 is returned by this function call. If the TokenNumber is invalid,
289 the results are unpredictable.
290
291 @param[in] Guid The token space for the token number.
292 @param[in] TokenNumber The PCD token number.
293
294 @return The pointer to the buffer to be retrived.
295
296 **/
297 VOID *
298 EFIAPI
299 PeiPcdGetPtrEx (
300 IN CONST EFI_GUID *Guid,
301 IN UINTN TokenNumber
302 );
303
304 /**
305 Retrieves an Boolean value for a given PCD token.
306
307 Retrieves the Boolean value of a particular PCD token.
308 If the TokenNumber is invalid or the token space
309 specified by Guid does not exist, the results are
310 unpredictable.
311
312 @param[in] Guid The token space for the token number.
313 @param[in] TokenNumber The PCD token number.
314
315 @return The size Boolean value for the PCD token.
316
317 **/
318 BOOLEAN
319 EFIAPI
320 PeiPcdGetBoolEx (
321 IN CONST EFI_GUID *Guid,
322 IN UINTN TokenNumber
323 );
324
325 /**
326 Retrieves the size of the value for a given PCD token.
327
328 Retrieves the current size of a particular PCD token.
329 If the TokenNumber is invalid, the results are unpredictable.
330
331 @param[in] Guid The token space for the token number.
332 @param[in] TokenNumber The PCD token number.
333
334 @return The size of the value for the PCD token.
335
336 **/
337 UINTN
338 EFIAPI
339 PeiPcdGetSizeEx (
340 IN CONST EFI_GUID *Guid,
341 IN UINTN TokenNumber
342 );
343
344 /**
345 Sets an 8-bit value for a given PCD token.
346
347 When the PCD service sets a value, it will check to ensure that the
348 size of the value being set is compatible with the Token's existing definition.
349 If it is not, an error will be returned.
350
351 @param[in] TokenNumber The PCD token number.
352 @param[in] Value The value to set for the PCD token.
353
354 @retval EFI_SUCCESS Procedure returned successfully.
355 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
356 being set was incompatible with a call to this function.
357 Use GetSize() to retrieve the size of the target data.
358 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
359
360 **/
361 EFI_STATUS
362 EFIAPI
363 PeiPcdSet8 (
364 IN UINTN TokenNumber,
365 IN UINT8 Value
366 );
367
368 /**
369 Sets an 16-bit value for a given PCD token.
370
371 When the PCD service sets a value, it will check to ensure that the
372 size of the value being set is compatible with the Token's existing definition.
373 If it is not, an error will be returned.
374
375 @param[in] TokenNumber The PCD token number.
376 @param[in] Value The value to set for the PCD token.
377
378 @retval EFI_SUCCESS Procedure returned successfully.
379 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
380 being set was incompatible with a call to this function.
381 Use GetSize() to retrieve the size of the target data.
382 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
383
384 **/
385 EFI_STATUS
386 EFIAPI
387 PeiPcdSet16 (
388 IN UINTN TokenNumber,
389 IN UINT16 Value
390 );
391
392 /**
393 Sets an 32-bit value for a given PCD token.
394
395 When the PCD service sets a value, it will check to ensure that the
396 size of the value being set is compatible with the Token's existing definition.
397 If it is not, an error will be returned.
398
399 @param[in] TokenNumber The PCD token number.
400 @param[in] Value The value to set for the PCD token.
401
402 @retval EFI_SUCCESS Procedure returned successfully.
403 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
404 being set was incompatible with a call to this function.
405 Use GetSize() to retrieve the size of the target data.
406 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
407
408 **/
409 EFI_STATUS
410 EFIAPI
411 PeiPcdSet32 (
412 IN UINTN TokenNumber,
413 IN UINT32 Value
414 );
415
416 /**
417 Sets an 64-bit value for a given PCD token.
418
419 When the PCD service sets a value, it will check to ensure that the
420 size of the value being set is compatible with the Token's existing definition.
421 If it is not, an error will be returned.
422
423 @param[in] TokenNumber The PCD token number.
424 @param[in] Value The value to set for the PCD token.
425
426 @retval EFI_SUCCESS Procedure returned successfully.
427 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
428 being set was incompatible with a call to this function.
429 Use GetSize() to retrieve the size of the target data.
430 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
431
432 **/
433 EFI_STATUS
434 EFIAPI
435 PeiPcdSet64 (
436 IN UINTN TokenNumber,
437 IN UINT64 Value
438 );
439
440 /**
441 Sets a value of a specified size for a given PCD token.
442
443 When the PCD service sets a value, it will check to ensure that the
444 size of the value being set is compatible with the Token's existing definition.
445 If it is not, an error will be returned.
446
447 @param[in] TokenNumber The PCD token number.
448 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
449 On input, if the SizeOfValue is greater than the maximum size supported
450 for this TokenNumber then the output value of SizeOfValue will reflect
451 the maximum size supported for this TokenNumber.
452 @param[in] Buffer The buffer to set for the PCD token.
453
454 @retval EFI_SUCCESS Procedure returned successfully.
455 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
456 being set was incompatible with a call to this function.
457 Use GetSize() to retrieve the size of the target data.
458 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
459
460 **/
461 EFI_STATUS
462 EFIAPI
463 PeiPcdSetPtr (
464 IN UINTN TokenNumber,
465 IN OUT UINTN *SizeOfBuffer,
466 IN VOID *Buffer
467 );
468
469 /**
470 Sets an Boolean value for a given PCD token.
471
472 When the PCD service sets a value, it will check to ensure that the
473 size of the value being set is compatible with the Token's existing definition.
474 If it is not, an error will be returned.
475
476 @param[in] TokenNumber The PCD token number.
477 @param[in] Value The value to set for the PCD token.
478
479 @retval EFI_SUCCESS Procedure returned successfully.
480 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
481 being set was incompatible with a call to this function.
482 Use GetSize() to retrieve the size of the target data.
483 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
484
485 **/
486 EFI_STATUS
487 EFIAPI
488 PeiPcdSetBool (
489 IN UINTN TokenNumber,
490 IN BOOLEAN Value
491 );
492
493 /**
494 Sets an 8-bit value for a given PCD token.
495
496 When the PCD service sets a value, it will check to ensure that the
497 size of the value being set is compatible with the Token's existing definition.
498 If it is not, an error will be returned.
499
500 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
501 @param[in] TokenNumber The PCD token number.
502 @param[in] Value The value to set for the PCD token.
503
504 @retval EFI_SUCCESS Procedure returned successfully.
505 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
506 being set was incompatible with a call to this function.
507 Use GetSize() to retrieve the size of the target data.
508 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
509
510 **/
511 EFI_STATUS
512 EFIAPI
513 PeiPcdSet8Ex (
514 IN CONST EFI_GUID *Guid,
515 IN UINTN TokenNumber,
516 IN UINT8 Value
517 );
518
519 /**
520 Sets an 16-bit value for a given PCD token.
521
522 When the PCD service sets a value, it will check to ensure that the
523 size of the value being set is compatible with the Token's existing definition.
524 If it is not, an error will be returned.
525
526 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
527 @param[in] TokenNumber The PCD token number.
528 @param[in] Value The value to set for the PCD token.
529
530 @retval EFI_SUCCESS Procedure returned successfully.
531 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
532 being set was incompatible with a call to this function.
533 Use GetSize() to retrieve the size of the target data.
534 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
535
536 **/
537 EFI_STATUS
538 EFIAPI
539 PeiPcdSet16Ex (
540 IN CONST EFI_GUID *Guid,
541 IN UINTN TokenNumber,
542 IN UINT16 Value
543 );
544
545 /**
546 Sets an 32-bit value for a given PCD token.
547
548 When the PCD service sets a value, it will check to ensure that the
549 size of the value being set is compatible with the Token's existing definition.
550 If it is not, an error will be returned.
551
552 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
553 @param[in] TokenNumber The PCD token number.
554 @param[in] Value The value to set for the PCD token.
555
556 @retval EFI_SUCCESS Procedure returned successfully.
557 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
558 being set was incompatible with a call to this function.
559 Use GetSize() to retrieve the size of the target data.
560 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
561
562 **/
563 EFI_STATUS
564 EFIAPI
565 PeiPcdSet32Ex (
566 IN CONST EFI_GUID *Guid,
567 IN UINTN TokenNumber,
568 IN UINT32 Value
569 );
570
571 /**
572 Sets an 64-bit value for a given PCD token.
573
574 When the PCD service sets a value, it will check to ensure that the
575 size of the value being set is compatible with the Token's existing definition.
576 If it is not, an error will be returned.
577
578 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
579 @param[in] TokenNumber The PCD token number.
580 @param[in] Value The value to set for the PCD token.
581
582 @retval EFI_SUCCESS Procedure returned successfully.
583 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
584 being set was incompatible with a call to this function.
585 Use GetSize() to retrieve the size of the target data.
586 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
587
588 **/
589 EFI_STATUS
590 EFIAPI
591 PeiPcdSet64Ex (
592 IN CONST EFI_GUID *Guid,
593 IN UINTN TokenNumber,
594 IN UINT64 Value
595 );
596
597 /**
598 Sets a value of a specified size for a given PCD token.
599
600 When the PCD service sets a value, it will check to ensure that the
601 size of the value being set is compatible with the Token's existing definition.
602 If it is not, an error will be returned.
603
604 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
605 @param[in] TokenNumber The PCD token number.
606 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
607 On input, if the SizeOfValue is greater than the maximum size supported
608 for this TokenNumber then the output value of SizeOfValue will reflect
609 the maximum size supported for this TokenNumber.
610 @param[in] Buffer The buffer to set for the PCD token.
611
612 @retval EFI_SUCCESS Procedure returned successfully.
613 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
614 being set was incompatible with a call to this function.
615 Use GetSize() to retrieve the size of the target data.
616 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
617
618 **/
619 EFI_STATUS
620 EFIAPI
621 PeiPcdSetPtrEx (
622 IN CONST EFI_GUID *Guid,
623 IN UINTN TokenNumber,
624 IN OUT UINTN *SizeOfBuffer,
625 IN VOID *Buffer
626 );
627
628 /**
629 Sets an Boolean value for a given PCD token.
630
631 When the PCD service sets a value, it will check to ensure that the
632 size of the value being set is compatible with the Token's existing definition.
633 If it is not, an error will be returned.
634
635 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
636 @param[in] TokenNumber The PCD token number.
637 @param[in] Value The value to set for the PCD token.
638
639 @retval EFI_SUCCESS Procedure returned successfully.
640 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
641 being set was incompatible with a call to this function.
642 Use GetSize() to retrieve the size of the target data.
643 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
644
645 **/
646 EFI_STATUS
647 EFIAPI
648 PeiPcdSetBoolEx (
649 IN CONST EFI_GUID *Guid,
650 IN UINTN TokenNumber,
651 IN BOOLEAN Value
652 );
653
654 /**
655 Specifies a function to be called anytime the value of a designated token is changed.
656
657 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
658 @param[in] TokenNumber The PCD token number.
659 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
660
661 @retval EFI_SUCCESS The PCD service has successfully established a call event
662 for the CallBackToken requested.
663 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
664
665 **/
666 EFI_STATUS
667 EFIAPI
668 PeiRegisterCallBackOnSet (
669 IN CONST EFI_GUID *Guid, OPTIONAL
670 IN UINTN TokenNumber,
671 IN PCD_PPI_CALLBACK CallBackFunction
672 );
673
674 /**
675 Cancels a previously set callback function for a particular PCD token number.
676
677 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
678 @param [in] TokenNumber The PCD token number.
679 @param [in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
680
681 @retval EFI_SUCCESS The PCD service has successfully established a call event
682 for the CallBackToken requested.
683 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
684
685 **/
686 EFI_STATUS
687 EFIAPI
688 PcdUnRegisterCallBackOnSet (
689 IN CONST EFI_GUID *Guid, OPTIONAL
690 IN UINTN TokenNumber,
691 IN PCD_PPI_CALLBACK CallBackFunction
692 );
693
694 /**
695 Retrieves the next valid PCD token for a given namespace.
696
697 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
698 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
699 If the input token namespace or token number does not exist on the platform,
700 an error is returned and the value of *TokenNumber is undefined. To retrieve the "first" token,
701 have the pointer reference a TokenNumber value of 0. If the input token number is 0 and
702 there is no valid token number for this token namespace, *TokenNumber will be assigned to
703 0 and the function return EFI_SUCCESS. If the token number is the last valid token number,
704 *TokenNumber will be assigned to 0 and the function return EFI_SUCCESS.
705
706 @retval EFI_SUCCESS The PCD service retrieved the next valid token number. Or the input token number
707 is already the last valid token number in the PCD database.
708 In the later case, *TokenNumber is updated with the value of 0.
709 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
710
711 **/
712 EFI_STATUS
713 EFIAPI
714 PeiPcdGetNextToken (
715 IN CONST EFI_GUID *Guid, OPTIONAL
716 IN OUT UINTN *TokenNumber
717 );
718
719 /**
720 Retrieves the next valid PCD token namespace for a given namespace.
721
722 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates
723 a known token namespace from which the search will start. On output,
724 it designates the next valid token namespace on the platform. If the input
725 token namespace does not exist on the platform, an error is returned and
726 the value of *Guid is undefined. If *Guid is NULL, then the GUID of the
727 first token space of the current platform is assigned to *Guid the function
728 return EFI_SUCCESS. If *Guid is NULL and there is no namespace exist in
729 the platform other than the default (NULL) tokennamespace, *Guid is unchanged
730 and the function return EFI_SUCCESS. If this input token namespace is the last
731 namespace on the platform, *Guid will be assigned to NULL and the function return
732 EFI_SUCCESS.
733
734 @retval EFI_SUCCESS The PCD service retrieved the next valid token space Guid.
735 Or the input token space Guid is already the last valid token space Guid
736 in the PCD database. In the later case, *Guid is updated with the value of NULL.
737 @retval EFI_NOT_FOUND If the input token namespace does not exist on the platform.
738
739 **/
740 EFI_STATUS
741 EFIAPI
742 PeiPcdGetNextTokenSpace (
743 IN OUT CONST EFI_GUID **Guid
744 );
745
746
747 /* Internal Function definitions */
748 /**
749 Get PCD database from GUID HOB in PEI phase.
750
751 @return Pointer to PCD database.
752
753 **/
754 PEI_PCD_DATABASE *
755 GetPcdDatabase (
756 VOID
757 );
758
759 /**
760 Wrapper function for setting non-pointer type value for a PCD entry.
761
762 @param TokenNumber Pcd token number autogenerated by build tools.
763 @param Data Value want to be set for PCD entry
764 @param Size Size of value.
765
766 @return status of SetWorker.
767
768 **/
769 EFI_STATUS
770 SetValueWorker (
771 IN UINTN TokenNumber,
772 IN VOID *Data,
773 IN UINTN Size
774 );
775
776 /**
777 Set value for an PCD entry
778
779 @param TokenNumber Pcd token number autogenerated by build tools.
780 @param Data Value want to be set for PCD entry
781 @param Size Size of value.
782 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
783 If False, the type of PCD entry's value is not Pointer.
784
785 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
786 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
787 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
788 range of UINT8, UINT16, UINT32, UINT64
789 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
790 **/
791 EFI_STATUS
792 SetWorker (
793 IN UINTN TokenNumber,
794 IN VOID *Data,
795 IN OUT UINTN *Size,
796 IN BOOLEAN PtrType
797 );
798
799 /**
800 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
801
802 @param ExTokenNumber Token number for dynamic-ex PCD.
803 @param Guid Token space guid for dynamic-ex PCD.
804 @param Data Value want to be set.
805 @param SetSize The size of value.
806
807 @return status of ExSetWorker().
808
809 **/
810 EFI_STATUS
811 ExSetValueWorker (
812 IN UINTN ExTokenNumber,
813 IN CONST EFI_GUID *Guid,
814 IN VOID *Data,
815 IN UINTN Size
816 );
817
818 /**
819 Set value for a dynamic PCD entry.
820
821 This routine find the local token number according to dynamic-ex PCD's token
822 space guid and token number firstly, and invoke callback function if this PCD
823 entry registered callback function. Finally, invoken general SetWorker to set
824 PCD value.
825
826 @param ExTokenNumber Dynamic-ex PCD token number.
827 @param Guid Token space guid for dynamic-ex PCD.
828 @param Data PCD value want to be set
829 @param SetSize Size of value.
830 @param PtrType If TRUE, this PCD entry is pointer type.
831 If FALSE, this PCD entry is not pointer type.
832
833 @return status of SetWorker().
834
835 **/
836 EFI_STATUS
837 ExSetWorker (
838 IN UINTN ExTokenNumber,
839 IN CONST EFI_GUID *Guid,
840 IN VOID *Data,
841 IN OUT UINTN *Size,
842 IN BOOLEAN PtrType
843 );
844
845 /**
846 Get the PCD entry pointer in PCD database.
847
848 This routine will visit PCD database to find the PCD entry according to given
849 token number. The given token number is autogened by build tools and it will be
850 translated to local token number. Local token number contains PCD's type and
851 offset of PCD entry in PCD database.
852
853 @param TokenNumber Token's number, it is autogened by build tools
854 @param GetSize The size of token's value
855
856 @return PCD entry pointer in PCD database
857
858 **/
859 VOID *
860 GetWorker (
861 IN UINTN TokenNumber,
862 IN UINTN GetSize
863 );
864
865 /**
866 Wrapper function for get PCD value for dynamic-ex PCD.
867
868 @param Guid Token space guid for dynamic-ex PCD.
869 @param ExTokenNumber Token number for dyanmic-ex PCD.
870 @param GetSize The size of dynamic-ex PCD value.
871
872 @return PCD entry in PCD database.
873
874 **/
875 VOID *
876 ExGetWorker (
877 IN CONST EFI_GUID *Guid,
878 IN UINTN ExTokenNumber,
879 IN UINTN GetSize
880 );
881
882 typedef struct {
883 UINTN TokenNumber;
884 UINTN Size;
885 UINT32 LocalTokenNumberAlias;
886 } EX_PCD_ENTRY_ATTRIBUTE;
887
888 /**
889 Get local token number according to dynamic-ex PCD's {token space guid:token number}
890
891 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
892 in DEC file. PCD database maintain a mapping table that translate pair of {token
893 space guid: token number} to local token number.
894
895 @param Guid Token space guid for dynamic-ex PCD entry.
896 @param ExTokenNumber Token number for dynamic-ex PCD.
897
898 @return local token number for dynamic-ex PCD.
899
900 **/
901 UINTN
902 GetExPcdTokenNumber (
903 IN CONST EFI_GUID *Guid,
904 IN UINTN ExTokenNumber
905 );
906
907 /**
908 The function registers the CallBackOnSet fucntion
909 according to TokenNumber and EFI_GUID space.
910
911 @param TokenNumber The token number.
912 @param Guid The GUID space.
913 @param CallBackFunction The Callback function to be registered.
914 @param Register To register or unregister the callback function.
915
916 @retval EFI_SUCCESS If the Callback function is registered.
917 @retval EFI_NOT_FOUND If the PCD Entry is not found according to Token Number and GUID space.
918 @retval EFI_OUT_OF_RESOURCES If the callback function can't be registered because there is not free
919 slot left in the CallbackFnTable.
920 **/
921 EFI_STATUS
922 PeiRegisterCallBackWorker (
923 IN UINTN TokenNumber,
924 IN CONST EFI_GUID *Guid, OPTIONAL
925 IN PCD_PPI_CALLBACK CallBackFunction,
926 IN BOOLEAN Register
927 );
928
929 /**
930 The function builds the PCD database.
931 **/
932 VOID
933 BuildPcdDatabase (
934 VOID
935 );
936
937 /**
938 Get SKU ID tabble from PCD database.
939
940 @param LocalTokenNumberTableIdx Index of local token number in token number table.
941 @param Database PCD Database in PEI phase
942
943 @return Pointer to SKU ID array table
944
945 **/
946 SKU_ID *
947 GetSkuIdArray (
948 IN UINTN LocalTokenNumberTableIdx,
949 IN PEI_PCD_DATABASE *Database
950 );
951
952 /**
953 Get index of PCD entry in size table.
954
955 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
956 @param Database Pointer to PCD database.
957
958 @return index of PCD entry in size table.
959
960 **/
961 UINTN
962 GetSizeTableIndex (
963 IN UINTN LocalTokenNumberTableIdx,
964 IN PEI_PCD_DATABASE *Database
965 );
966
967 /**
968 Get PCD value's size for POINTER type PCD.
969
970 The POINTER type PCD's value will be stored into a buffer in specificed size.
971 The max size of this PCD's value is described in PCD's definition in DEC file.
972
973 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
974 @param MaxSize Maxmium size of PCD's value
975 @param Database Pcd database in PEI phase.
976
977 @return PCD value's size for POINTER type PCD.
978
979 **/
980 UINTN
981 GetPtrTypeSize (
982 IN UINTN LocalTokenNumberTableIdx,
983 OUT UINTN *MaxSize,
984 IN PEI_PCD_DATABASE *Database
985 );
986
987 /**
988 Set PCD value's size for POINTER type PCD.
989
990 The POINTER type PCD's value will be stored into a buffer in specificed size.
991 The max size of this PCD's value is described in PCD's definition in DEC file.
992
993 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
994 @param CurrentSize Maxmium size of PCD's value
995 @param Database Pcd database in PEI phase.
996
997 @retval TRUE Success to set PCD's value size, which is not exceed maxmium size
998 @retval FALSE Fail to set PCD's value size, which maybe exceed maxmium size
999
1000 **/
1001 BOOLEAN
1002 SetPtrTypeSize (
1003 IN UINTN LocalTokenNumberTableIdx,
1004 IN OUT UINTN *CurrentSize,
1005 IN PEI_PCD_DATABASE *Database
1006 );
1007
1008 //
1009 // The init Database created by PCD Database generation tool
1010 //
1011 extern PEI_PCD_DATABASE_INIT gPEIPcdDbInit;
1012
1013 #endif
1014
1015 ////////////////////////////////////////////////////////////////////////////////
1016 // //
1017 // Introduction of PEI PCD database //
1018 // //
1019 ////////////////////////////////////////////////////////////////////////////////
1020 /**
1021 1, Introduction
1022 PEI PCD database hold all dynamic type PCD information used in PEI phase.
1023 The structure of PEI PCD database is generated by build tools according to
1024 dynamic PCD usage for specified platform.
1025
1026 2, Dynamic Type PCD
1027 Dynamic type PCD is designed for accessing setting which value is determined
1028 dynamic. In contrast, the value of static type PCD (FeatureFlag, FixedPcd,
1029 PatchablePcd) is fixed in final generated FD image in build time.
1030
1031 2.1 The "dynamic" determination means:
1032 a) The PCD value is produced by someone driver and consumed by other driver
1033 in execution time.
1034 b) The PCD value is set/get by user from FrontPage.
1035 c) The PCD value is produced by platform OEM specified area.
1036
1037 2.2 According to distribution mehod, dynamic PCD could be classfied as:
1038 a) Dynamic:
1039 This type PCD is used for module in source distribution which will be
1040 built in platform.
1041 b) DynamicEx:
1042 This type PCD is used for module in binary distribution which will be
1043 will not built.
1044
1045 2.3 According to storage method, dynamic PCD could be classfied as:
1046 a) Default Storage:
1047 - The value is stored in PCD database maintained by PCD database in boot
1048 time memory which is built as a guid hob in PEI phase.
1049 - This type is used for communication between PEIM/DXE driver, DXE/DXE
1050 driver. But all set/get value will be losted after boot-time memory
1051 is turn off.
1052 - [PcdsDynamicDefault]/[PcdsDynamicExDefault] is used as section name
1053 for this type PCD in platform DSC file.
1054
1055 b) Variable Storage:
1056 - The value is stored in variable area.
1057 - As default storage type, this type PCD could used for communication.
1058 But beside it, this type PCD could be used store the value associating
1059 with HII setting via variable technology.
1060 - In PEI phase, the PCD value could only be got but can not be set due
1061 to variable area is readonly for PEI phase.
1062 - [PcdsDynamicHii]/[PcdsDynamicExHii] is used as section name for this
1063 type PCD in platform DSC file.
1064
1065 c) OEM specificed storage area:
1066 - The value is stored in OEM specified area, the base address is specified
1067 by a FixedAtBuild PCD PcdVpdBaseAddress.
1068 - The area is read only for PEI and DXE phase.
1069 - [PcdsDynamicVpd]/[PcdsDynamicExVpd] is used as section name for this
1070 type PCD in platform DSC file.
1071
1072 Note: The default value of dynamic PCD are storaged in memory maintained
1073 by PEI/DXE PCD drvier.
1074
1075 2.4 When and how to use dynamic PCD
1076 Module developer do not care the used PCD is dynamic or static when writting
1077 source code/INF. Dynamic PCD and dynamic type is pointed by platform integrator
1078 in platform DSC file. Please ref section 2.3 to get matching between dynamic
1079 PCD type and section name in DSC file.
1080
1081 3, PCD database:
1082 Although dynamic PCD could be in different storage type as above description,
1083 but the basic information and default value for all dynamic PCD is hold
1084 by PCD database maintained by PEI/DXE driver.
1085
1086 As whole EFI BIOS boot path is divided into PEI/DXE phase, the PCD database
1087 also is divided into Pei/Dxe database maintaied by PcdPeim/PcdDxe driver separatly.
1088 To make PcdPeim's driver image smaller, PEI PCD database only hold all dynamic
1089 PCD information used in PEI phase or use in both PEI/DXE phase. And DXE PCD
1090 database contains all PCDs used in PEI/DXE phase in memory.
1091
1092 Build tool will generate PCD database into some C structure and variable for
1093 PEI/DXE PCD driver according to dynamic PCD section in platform DSC file.
1094
1095 3.1 PcdPeim and PcdDxe
1096 PEI PCD database is maintained by PcdPeim driver run from flash. PcdPeim driver
1097 build guid hob in temporary memory and copy auto-generated C structure
1098 to temporary memory for PEI PCD database.
1099 DXE PCD database is maintained by PcdDxe driver.At entry point of PcdDxe driver,
1100 a new PCD database is allocated in boot-time memory which including all
1101 PEI PCD and DXE PCD entry.
1102
1103 Pcd driver should run as early as possible before any other driver access
1104 dynamic PCD's value. PEI/DXE "Apriori File" mechanism make it possible by
1105 making PcdPeim/PcdDxe as first dispatching driver in PEI/DXE phase.
1106
1107 3.2 Token space Guid/Token number, Platform token, Local token number
1108 Dynamic PCD
1109 +-----------+ +---------+
1110 |TokenSpace | |Platform |
1111 | Guid | build tool | Token |
1112 | + +-------------->| Number |
1113 | Token | +---------+`._
1114 | Number | `.
1115 +-----------+ `. +------+
1116 `-|Local |
1117 |Token |
1118 DynamicEx PCD ,-|Number|
1119 +-----------+ ,-' +------+
1120 |TokenSpace | ,-'
1121 | Guid | _,-'
1122 | + +.'
1123 | Token |
1124 | Number |
1125 +-----------+
1126
1127
1128 3.2.1 Pair of Token space guid + Token number
1129 Any type PCD is identified by pair of "TokenSpaceGuid + TokeNumber". But it
1130 is not easy maintained by PCD driver, and hashed token number will make
1131 searching slowly.
1132
1133 3.2.2 Platform Token Number
1134 "Platform token number" concept is introduced for mapping to a pair of
1135 "TokenSpaceGuid + TokenNumber". The platform token number is generated by
1136 build tool in autogen.h and all of them are continual in a platform scope
1137 started from 1.(0 meaning invalid internal token number)
1138 With auto-generated "platform token number", PcdGet(PcdSampleDynamicPcd)
1139 in source code is translated to LibPcdGet(_PCD_TOKEN_PcdSampleDynamicPcd)
1140 in autogen.h.
1141 Notes: The mapping between pair of "tokenspace guid + token number" and
1142 "internal token number" need build tool establish, so "platform token number"
1143 mechanism is not suitable for binary module which use DynamicEx type PCD.
1144 To access a dynamicEx type PCD, pair of "token space guid/token number" all need
1145 to be specificed for PcdSet/PcdGet accessing macro.
1146
1147 3.2.3 Local Token Number
1148 To fast searching a PCD entry in PCD database, PCD driver translate
1149 platform token number to local token number via a mapping table.
1150 For binary DynamicEx type PCD, there is a another mapping table to translate
1151 "token space guid + token number" to local token number directly.
1152 Local token number is identifier for all internal interface in PCD PEI/DXE
1153 driver.
1154
1155 A local token number is a 32-bit value in following meaning:
1156 32 ------------- 28 ---------- 24 -------- 0
1157 | PCD type mask | Datum Type | Offset |
1158 +-----------------------------------------+
1159 where:
1160 PCd type mask: indicate Pcd type from following macro:
1161 PCD_TYPE_DATA
1162 PCD_TYPE_HII
1163 PCD_TYPE_VPD
1164 PCD_TYPE_SKU_ENABLED
1165 PCD_TYPE_STRING
1166 Datum Type : indicate PCD vaue type from following macro:
1167 PCD_DATUM_TYPE_POINTER
1168 PCD_DATUM_TYPE_UINT8
1169 PCD_DATUM_TYPE_UINT16
1170 PCD_DATUM_TYPE_UINT32
1171 PCD_DATUM_TYPE_UINT64
1172 Offset : indicate the related offset of PCD value in PCD database array.
1173 Based on local token number, PCD driver could fast determine PCD type, value
1174 type and get PCD entry from PCD database.
1175
1176 3.3 PCD Database C structure.
1177 PCD Database C structure is generated by build tools in PCD driver's autogen.h/
1178 autogen.c file. In generated C structure, following information is stored:
1179 - ExMapTable: This table is used translate a binary dynamicex type PCD's
1180 "tokenguid + token" to local token number.
1181 - LocalTokenNumberTable:
1182 This table stores all local token number in array, use "Internal
1183 token number" as array index to get PCD entry's offset fastly.
1184 - SizeTable: This table stores the size information for all PCD entry.
1185 - GuidTable: This table stores guid value for DynamicEx's token space,
1186 HII type PCD's variable.
1187 - SkuIdTable: TBD
1188 - SystemSkuId: TBD
1189 - PCD value structure:
1190 Every PCD has a value record in PCD database. For different
1191 datum type PCD has different record structure which will be
1192 introduced in 3.3.1
1193
1194 In a PCD database structure, there are two major area: Init and UnInit.
1195 Init area is use stored above PCD internal structure such as ExMapTable,
1196 LocalTokenNumberTable etc and the (default) value of PCD which has default
1197 value specified in platform DSC file.
1198 Unint area is used stored the value of PCD which has no default value in
1199 platform DSC file, the value of NULL, 0 specified in platform DSC file can
1200 be seemed as "no default value".
1201
1202 3.3.1 Simple Sample PCD Database C Structure
1203 A general sample of PCD database structue is as follows:
1204 typedef struct _PCD_DATABASE {
1205 typedef struct _PCD_DATABASE_INIT {
1206 //===== Following is PCD database internal maintain structures
1207 DYNAMICEX_MAPPING ExMapTable[PEI_EXMAPPING_TABLE_SIZE];
1208 UINT32 LocalTokenNumberTable[PEI_LOCAL_TOKEN_NUMBER_TABLE_SIZE];
1209 GUID GuidTable[PEI_GUID_TABLE_SIZE];
1210 SIZE_INFO SizeTable[PEI_SIZE_TABLE_SIZE];
1211 UINT8 SkuIdTable[PEI_SKUID_TABLE_SIZE];
1212 SKU_ID SystemSkuId;
1213
1214 //===== Following is value structure for PCD with default value
1215 ....
1216 ....
1217 ....
1218 } Init;
1219 typedef struct _PCD_DATABSE_UNINIT {
1220 //==== Following is value structure for PCD without default value
1221 ....
1222 ....
1223 } UnInit;
1224 }
1225
1226 3.3.2 PCD value structure in PCD database C structure
1227 The value's structure is generated by build tool in PCD database C structure.
1228 The PCDs in different datum type has different value structure.
1229
1230 3.3.2.1 UINT8/UINT16/UINT32/UINT64 datum type PCD
1231 The C structure for these datum type PCD is just a UINT8/UINT16/UINT32/UINT64
1232 data member in PCD database, For example:
1233 UINT16 PcdHardwareErrorRecordLevel_d3705011_bc19_4af7_be16_f68030378c15_VariableDefault_0;
1234 Above structure is generated by build tool, the member name is "PcdCName_Guidvalue"
1235 Member type is UINT16 according to PcdHardwareErrorRecordLevel declaration
1236 in DEC file.
1237
1238 3.3.2.2 VOID* datum type PCD
1239 The value of VOID* datum type PCD is a UINT8/UINT16 array in PCD database.
1240
1241 3.3.2.2.1 VOID* - string type
1242 If the default value for VOID* datum type PCD like L"xxx", the PCD is
1243 used for unicode string, and C structure of this datum type PCD is
1244 UINT16 string array in PCD database, for example:
1245 UINT16 StringTable[29];
1246 The number of 29 in above sample is max size of a unicode string.
1247
1248 If the default value for VOID* datum type PCD like "xxx", the PCD is
1249 used for ascii string, and C structure of this datum type PCD is
1250 UINT8 string array in PCD database, for example:
1251 UINT8 StringTable[20];
1252 The number of 20 in above sample is max size of a ascii string.
1253
1254 3.3.2.2.2 VOID* - byte array
1255 If the default value of VOID* datum type PCD like {'0x29', '0x01', '0xf2'}
1256 the PCD is used for byte array. The generated structrue is same as
1257 above ascii string table,
1258 UINT8 StringTable[13];
1259 The number of 13 in above sample is max size of byte array.
1260
1261 **/