• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 Private functions used by PCD DXE driver.
3 
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #ifndef _PCD_DXE_SERVICE_H_
16 #define _PCD_DXE_SERVICE_H_
17 
18 #include <PiDxe.h>
19 #include <Guid/PcdDataBaseHobGuid.h>
20 #include <Guid/PcdDataBaseSignatureGuid.h>
21 #include <Protocol/Pcd.h>
22 #include <Protocol/PiPcd.h>
23 #include <Protocol/PcdInfo.h>
24 #include <Protocol/PiPcdInfo.h>
25 #include <Protocol/VarCheck.h>
26 #include <Protocol/VariableLock.h>
27 #include <Library/BaseLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/UefiLib.h>
30 #include <Library/UefiDriverEntryPoint.h>
31 #include <Library/PcdLib.h>
32 #include <Library/HobLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/UefiRuntimeServicesTableLib.h>
37 
38 //
39 // Please make sure the PCD Serivce DXE Version is consistent with
40 // the version of the generated DXE PCD Database by build tool.
41 //
42 #define PCD_SERVICE_DXE_VERSION      6
43 
44 //
45 // PCD_DXE_SERVICE_DRIVER_VERSION is defined in Autogen.h.
46 //
47 #if (PCD_SERVICE_DXE_VERSION != PCD_DXE_SERVICE_DRIVER_VERSION)
48   #error "Please make sure the version of PCD DXE Service and the generated PCD DXE Database match."
49 #endif
50 
51 /**
52   Retrieve additional information associated with a PCD token in the default token space.
53 
54   This includes information such as the type of value the TokenNumber is associated with as well as possible
55   human readable name that is associated with the token.
56 
57   @param[in]    TokenNumber The PCD token number.
58   @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.
59                             The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
60 
61   @retval  EFI_SUCCESS      The PCD information was returned successfully.
62   @retval  EFI_NOT_FOUND    The PCD service could not find the requested token number.
63 **/
64 EFI_STATUS
65 EFIAPI
66 DxeGetPcdInfoGetInfo (
67   IN        UINTN           TokenNumber,
68   OUT       EFI_PCD_INFO    *PcdInfo
69   );
70 
71 /**
72   Retrieve additional information associated with a PCD token.
73 
74   This includes information such as the type of value the TokenNumber is associated with as well as possible
75   human readable name that is associated with the token.
76 
77   @param[in]    Guid        The 128-bit unique value that designates the namespace from which to extract the value.
78   @param[in]    TokenNumber The PCD token number.
79   @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.
80                             The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
81 
82   @retval  EFI_SUCCESS      The PCD information was returned successfully.
83   @retval  EFI_NOT_FOUND    The PCD service could not find the requested token number.
84 **/
85 EFI_STATUS
86 EFIAPI
87 DxeGetPcdInfoGetInfoEx (
88   IN CONST  EFI_GUID        *Guid,
89   IN        UINTN           TokenNumber,
90   OUT       EFI_PCD_INFO    *PcdInfo
91   );
92 
93 /**
94   Retrieve the currently set SKU Id.
95 
96   @return   The currently set SKU Id. If the platform has not set at a SKU Id, then the
97             default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU
98             Id is returned.
99 **/
100 UINTN
101 EFIAPI
102 DxeGetPcdInfoGetSku (
103   VOID
104   );
105 
106 //
107 // Protocol Interface function declaration.
108 //
109 /**
110   Sets the SKU value for subsequent calls to set or get PCD token values.
111 
112   SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
113   SetSku() is normally called only once by the system.
114 
115   For each item (token), the database can hold a single value that applies to all SKUs,
116   or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
117   SKU-specific values are called SKU enabled.
118 
119   The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
120   For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
121   single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
122   last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
123   the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
124   set for that Id, the results are unpredictable.
125 
126   @param[in]  SkuId The SKU value that will be used when the PCD service will retrieve and
127               set values associated with a PCD token.
128 
129 **/
130 VOID
131 EFIAPI
132 DxePcdSetSku (
133   IN  UINTN                  SkuId
134   );
135 
136 /**
137   Retrieves an 8-bit value for a given PCD token.
138 
139   Retrieves the current byte-sized value for a PCD token number.
140   If the TokenNumber is invalid, the results are unpredictable.
141 
142   @param[in]  TokenNumber The PCD token number.
143 
144   @return The UINT8 value.
145 
146 **/
147 UINT8
148 EFIAPI
149 DxePcdGet8 (
150   IN UINTN             TokenNumber
151   );
152 
153 /**
154   Retrieves an 16-bit value for a given PCD token.
155 
156   Retrieves the current 16-bits value for a PCD token number.
157   If the TokenNumber is invalid, the results are unpredictable.
158 
159   @param[in]  TokenNumber The PCD token number.
160 
161   @return The UINT16 value.
162 
163 **/
164 UINT16
165 EFIAPI
166 DxePcdGet16 (
167   IN UINTN             TokenNumber
168   );
169 
170 /**
171   Retrieves an 32-bit value for a given PCD token.
172 
173   Retrieves the current 32-bits value for a PCD token number.
174   If the TokenNumber is invalid, the results are unpredictable.
175 
176   @param[in]  TokenNumber The PCD token number.
177 
178   @return The UINT32 value.
179 
180 **/
181 UINT32
182 EFIAPI
183 DxePcdGet32 (
184   IN UINTN             TokenNumber
185   );
186 
187 /**
188   Retrieves an 64-bit value for a given PCD token.
189 
190   Retrieves the current 64-bits value for a PCD token number.
191   If the TokenNumber is invalid, the results are unpredictable.
192 
193   @param[in]  TokenNumber The PCD token number.
194 
195   @return The UINT64 value.
196 
197 **/
198 UINT64
199 EFIAPI
200 DxePcdGet64 (
201   IN UINTN             TokenNumber
202   );
203 
204 /**
205   Retrieves a pointer to a value for a given PCD token.
206 
207   Retrieves the current pointer to the buffer for a PCD token number.
208   Do not make any assumptions about the alignment of the pointer that
209   is returned by this function call.  If the TokenNumber is invalid,
210   the results are unpredictable.
211 
212   @param[in]  TokenNumber The PCD token number.
213 
214   @return The pointer to the buffer to be retrieved.
215 
216 **/
217 VOID *
218 EFIAPI
219 DxePcdGetPtr (
220   IN UINTN             TokenNumber
221   );
222 
223 /**
224   Retrieves a Boolean value for a given PCD token.
225 
226   Retrieves the current boolean value for a PCD token number.
227   Do not make any assumptions about the alignment of the pointer that
228   is returned by this function call.  If the TokenNumber is invalid,
229   the results are unpredictable.
230 
231   @param[in]  TokenNumber The PCD token number.
232 
233   @return The Boolean value.
234 
235 **/
236 BOOLEAN
237 EFIAPI
238 DxePcdGetBool (
239   IN UINTN             TokenNumber
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 DxePcdGetSize (
256   IN UINTN             TokenNumber
257   );
258 
259 /**
260   Retrieves an 8-bit value for a given PCD token.
261 
262   Retrieves the 8-bit value of a particular PCD token.
263   If the TokenNumber is invalid or the token space
264   specified by Guid does not exist, the results are
265   unpredictable.
266 
267   @param[in]  Guid The token space for the token number.
268   @param[in]  TokenNumber The PCD token number.
269 
270   @return The size 8-bit value for the PCD token.
271 
272 **/
273 UINT8
274 EFIAPI
275 DxePcdGet8Ex (
276   IN CONST EFI_GUID        *Guid,
277   IN UINTN             TokenNumber
278   );
279 
280 /**
281   Retrieves an 16-bit value for a given PCD token.
282 
283   Retrieves the 16-bit value of a particular PCD token.
284   If the TokenNumber is invalid or the token space
285   specified by Guid does not exist, the results are
286   unpredictable.
287 
288   @param[in]  Guid The token space for the token number.
289   @param[in]  TokenNumber The PCD token number.
290 
291   @return The size 16-bit value for the PCD token.
292 
293 **/
294 UINT16
295 EFIAPI
296 DxePcdGet16Ex (
297   IN CONST EFI_GUID        *Guid,
298   IN UINTN             TokenNumber
299   );
300 
301 /**
302   Retrieves an 32-bit value for a given PCD token.
303 
304   Retrieves the 32-bit value of a particular PCD token.
305   If the TokenNumber is invalid or the token space
306   specified by Guid does not exist, the results are
307   unpredictable.
308 
309   @param[in]  Guid The token space for the token number.
310   @param[in]  TokenNumber The PCD token number.
311 
312   @return The size 32-bit value for the PCD token.
313 
314 **/
315 UINT32
316 EFIAPI
317 DxePcdGet32Ex (
318   IN CONST EFI_GUID        *Guid,
319   IN UINTN             TokenNumber
320   );
321 
322 /**
323   Retrieves an 64-bit value for a given PCD token.
324 
325   Retrieves the 64-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]  TokenNumber The PCD token number.
332 
333   @return The size 64-bit value for the PCD token.
334 
335 **/
336 UINT64
337 EFIAPI
338 DxePcdGet64Ex (
339   IN CONST EFI_GUID        *Guid,
340   IN UINTN             TokenNumber
341   );
342 
343 /**
344   Retrieves a pointer to a value for a given PCD token.
345 
346   Retrieves the current pointer to the buffer for a PCD token number.
347   Do not make any assumptions about the alignment of the pointer that
348   is returned by this function call.  If the TokenNumber is invalid,
349   the results are unpredictable.
350 
351   @param[in]  Guid The token space for the token number.
352   @param[in]  TokenNumber The PCD token number.
353 
354   @return The pointer to the buffer to be retrieved.
355 
356 **/
357 VOID *
358 EFIAPI
359 DxePcdGetPtrEx (
360   IN CONST EFI_GUID        *Guid,
361   IN UINTN             TokenNumber
362   );
363 
364 /**
365   Retrieves an Boolean value for a given PCD token.
366 
367   Retrieves the Boolean value of a particular PCD token.
368   If the TokenNumber is invalid or the token space
369   specified by Guid does not exist, the results are
370   unpredictable.
371 
372   @param[in]  Guid The token space for the token number.
373   @param[in]  TokenNumber The PCD token number.
374 
375   @return The size Boolean value for the PCD token.
376 
377 **/
378 BOOLEAN
379 EFIAPI
380 DxePcdGetBoolEx (
381   IN CONST EFI_GUID        *Guid,
382   IN UINTN             TokenNumber
383   );
384 
385 /**
386   Retrieves the size of the value for a given PCD token.
387 
388   Retrieves the current size of a particular PCD token.
389   If the TokenNumber is invalid, the results are unpredictable.
390 
391   @param[in]  Guid The token space for the token number.
392   @param[in]  TokenNumber The PCD token number.
393 
394   @return The size of the value for the PCD token.
395 
396 **/
397 UINTN
398 EFIAPI
399 DxePcdGetSizeEx (
400   IN CONST EFI_GUID        *Guid,
401   IN UINTN             TokenNumber
402   );
403 
404 /**
405   Sets an 8-bit value for a given PCD token.
406 
407   When the PCD service sets a value, it will check to ensure that the
408   size of the value being set is compatible with the Token's existing definition.
409   If it is not, an error will be returned.
410 
411   @param[in]  TokenNumber The PCD token number.
412   @param[in]  Value The value to set for the PCD token.
413 
414   @retval EFI_SUCCESS  Procedure returned successfully.
415   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
416                                   being set was incompatible with a call to this function.
417                                   Use GetSize() to retrieve the size of the target data.
418   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
419 
420 **/
421 EFI_STATUS
422 EFIAPI
423 DxePcdSet8 (
424   IN UINTN             TokenNumber,
425   IN UINT8             Value
426   );
427 
428 /**
429   Sets an 16-bit value for a given PCD token.
430 
431   When the PCD service sets a value, it will check to ensure that the
432   size of the value being set is compatible with the Token's existing definition.
433   If it is not, an error will be returned.
434 
435   @param[in]  TokenNumber The PCD token number.
436   @param[in]  Value The value to set for the PCD token.
437 
438   @retval EFI_SUCCESS  Procedure returned successfully.
439   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
440                                   being set was incompatible with a call to this function.
441                                   Use GetSize() to retrieve the size of the target data.
442   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
443 
444 **/
445 EFI_STATUS
446 EFIAPI
447 DxePcdSet16 (
448   IN UINTN             TokenNumber,
449   IN UINT16             Value
450   );
451 
452 /**
453   Sets an 32-bit value for a given PCD token.
454 
455   When the PCD service sets a value, it will check to ensure that the
456   size of the value being set is compatible with the Token's existing definition.
457   If it is not, an error will be returned.
458 
459   @param[in]  TokenNumber The PCD token number.
460   @param[in]  Value The value to set for the PCD token.
461 
462   @retval EFI_SUCCESS  Procedure returned successfully.
463   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
464                                   being set was incompatible with a call to this function.
465                                   Use GetSize() to retrieve the size of the target data.
466   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
467 
468 **/
469 EFI_STATUS
470 EFIAPI
471 DxePcdSet32 (
472   IN UINTN             TokenNumber,
473   IN UINT32             Value
474   );
475 
476 /**
477   Sets an 64-bit value for a given PCD token.
478 
479   When the PCD service sets a value, it will check to ensure that the
480   size of the value being set is compatible with the Token's existing definition.
481   If it is not, an error will be returned.
482 
483   @param[in]  TokenNumber The PCD token number.
484   @param[in]  Value The value to set for the PCD token.
485 
486   @retval EFI_SUCCESS  Procedure returned successfully.
487   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
488                                   being set was incompatible with a call to this function.
489                                   Use GetSize() to retrieve the size of the target data.
490   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
491 
492 **/
493 EFI_STATUS
494 EFIAPI
495 DxePcdSet64 (
496   IN UINTN             TokenNumber,
497   IN UINT64            Value
498   );
499 
500 
501 /**
502   Sets a value of a specified size for a given PCD token.
503 
504   When the PCD service sets a value, it will check to ensure that the
505   size of the value being set is compatible with the Token's existing definition.
506   If it is not, an error will be returned.
507 
508   @param[in]  TokenNumber The PCD token number.
509   @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
510                               On input, if the SizeOfValue is greater than the maximum size supported
511                               for this TokenNumber then the output value of SizeOfValue will reflect
512                               the maximum size supported for this TokenNumber.
513   @param[in]  Buffer The buffer to set for the PCD token.
514 
515   @retval EFI_SUCCESS  Procedure returned successfully.
516   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
517                                   being set was incompatible with a call to this function.
518                                   Use GetSize() to retrieve the size of the target data.
519   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
520 
521 **/
522 EFI_STATUS
523 EFIAPI
524 DxePcdSetPtr (
525   IN        UINTN             TokenNumber,
526   IN OUT    UINTN             *SizeOfBuffer,
527   IN        VOID              *Buffer
528   );
529 
530 /**
531   Sets an Boolean value for a given PCD token.
532 
533   When the PCD service sets a value, it will check to ensure that the
534   size of the value being set is compatible with the Token's existing definition.
535   If it is not, an error will be returned.
536 
537   @param[in]  TokenNumber The PCD token number.
538   @param[in]  Value The value to set for the PCD token.
539 
540   @retval EFI_SUCCESS  Procedure returned successfully.
541   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
542                                   being set was incompatible with a call to this function.
543                                   Use GetSize() to retrieve the size of the target data.
544   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
545 
546 **/
547 EFI_STATUS
548 EFIAPI
549 DxePcdSetBool (
550   IN UINTN             TokenNumber,
551   IN BOOLEAN           Value
552   );
553 
554 
555 /**
556   Sets an 8-bit value for a given PCD token.
557 
558   When the PCD service sets a value, it will check to ensure that the
559   size of the value being set is compatible with the Token's existing definition.
560   If it is not, an error will be returned.
561 
562   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.
563   @param[in]  TokenNumber The PCD token number.
564   @param[in]  Value The value to set for the PCD token.
565 
566   @retval EFI_SUCCESS  Procedure returned successfully.
567   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
568                                   being set was incompatible with a call to this function.
569                                   Use GetSize() to retrieve the size of the target data.
570   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
571 
572 **/
573 EFI_STATUS
574 EFIAPI
575 DxePcdSet8Ex (
576   IN CONST EFI_GUID        *Guid,
577   IN UINTN             TokenNumber,
578   IN UINT8             Value
579   );
580 
581 /**
582   Sets an 16-bit value for a given PCD token.
583 
584   When the PCD service sets a value, it will check to ensure that the
585   size of the value being set is compatible with the Token's existing definition.
586   If it is not, an error will be returned.
587 
588   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.
589   @param[in]  TokenNumber The PCD token number.
590   @param[in]  Value The value to set for the PCD token.
591 
592   @retval EFI_SUCCESS  Procedure returned successfully.
593   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
594                                   being set was incompatible with a call to this function.
595                                   Use GetSize() to retrieve the size of the target data.
596   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
597 
598 **/
599 EFI_STATUS
600 EFIAPI
601 DxePcdSet16Ex (
602   IN CONST EFI_GUID        *Guid,
603   IN UINTN             TokenNumber,
604   IN UINT16            Value
605   );
606 
607 /**
608   Sets an 32-bit value for a given PCD token.
609 
610   When the PCD service sets a value, it will check to ensure that the
611   size of the value being set is compatible with the Token's existing definition.
612   If it is not, an error will be returned.
613 
614   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.
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 DxePcdSet32Ex (
628   IN CONST EFI_GUID        *Guid,
629   IN UINTN             TokenNumber,
630   IN UINT32             Value
631   );
632 
633 /**
634   Sets an 64-bit value for a given PCD token.
635 
636   When the PCD service sets a value, it will check to ensure that the
637   size of the value being set is compatible with the Token's existing definition.
638   If it is not, an error will be returned.
639 
640   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.
641   @param[in]  TokenNumber The PCD token number.
642   @param[in]  Value The value to set for the PCD token.
643 
644   @retval EFI_SUCCESS  Procedure returned successfully.
645   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
646                                   being set was incompatible with a call to this function.
647                                   Use GetSize() to retrieve the size of the target data.
648   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
649 
650 **/
651 EFI_STATUS
652 EFIAPI
653 DxePcdSet64Ex (
654   IN CONST EFI_GUID        *Guid,
655   IN UINTN             TokenNumber,
656   IN UINT64            Value
657   );
658 
659 /**
660   Sets a value of a specified size for a given PCD token.
661 
662   When the PCD service sets a value, it will check to ensure that the
663   size of the value being set is compatible with the Token's existing definition.
664   If it is not, an error will be returned.
665 
666   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.
667   @param[in]  TokenNumber The PCD token number.
668   @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
669                               On input, if the SizeOfValue is greater than the maximum size supported
670                               for this TokenNumber then the output value of SizeOfValue will reflect
671                               the maximum size supported for this TokenNumber.
672   @param[in]  Buffer The buffer to set for the PCD token.
673 
674   @retval EFI_SUCCESS  Procedure returned successfully.
675   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
676                                   being set was incompatible with a call to this function.
677                                   Use GetSize() to retrieve the size of the target data.
678   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
679 
680 **/
681 EFI_STATUS
682 EFIAPI
683 DxePcdSetPtrEx (
684   IN        CONST EFI_GUID    *Guid,
685   IN        UINTN             TokenNumber,
686   IN OUT    UINTN             *SizeOfBuffer,
687   IN        VOID              *Buffer
688   );
689 
690 /**
691   Sets an Boolean value for a given PCD token.
692 
693   When the PCD service sets a value, it will check to ensure that the
694   size of the value being set is compatible with the Token's existing definition.
695   If it is not, an error will be returned.
696 
697   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.
698   @param[in]  TokenNumber The PCD token number.
699   @param[in]  Value The value to set for the PCD token.
700 
701   @retval EFI_SUCCESS  Procedure returned successfully.
702   @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
703                                   being set was incompatible with a call to this function.
704                                   Use GetSize() to retrieve the size of the target data.
705   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
706 
707 **/
708 EFI_STATUS
709 EFIAPI
710 DxePcdSetBoolEx (
711   IN CONST EFI_GUID    *Guid,
712   IN UINTN             TokenNumber,
713   IN BOOLEAN           Value
714   );
715 
716 /**
717   Specifies a function to be called anytime the value of a designated token is changed.
718 
719   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.
720   @param[in]  TokenNumber The PCD token number.
721   @param[in]  CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
722 
723   @retval EFI_SUCCESS  The PCD service has successfully established a call event
724                         for the CallBackToken requested.
725   @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
726 
727 **/
728 EFI_STATUS
729 EFIAPI
730 DxeRegisterCallBackOnSet (
731   IN  CONST EFI_GUID          *Guid, OPTIONAL
732   IN  UINTN                   TokenNumber,
733   IN  PCD_PROTOCOL_CALLBACK   CallBackFunction
734   );
735 
736 /**
737   Cancels a previously set callback function for a particular PCD token number.
738 
739   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.
740   @param[in]  TokenNumber The PCD token number.
741   @param[in]  CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
742 
743   @retval EFI_SUCCESS  The PCD service has successfully established a call event
744                         for the CallBackToken requested.
745   @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
746 
747 **/
748 EFI_STATUS
749 EFIAPI
750 DxeUnRegisterCallBackOnSet (
751   IN  CONST EFI_GUID          *Guid, OPTIONAL
752   IN  UINTN                   TokenNumber,
753   IN  PCD_PROTOCOL_CALLBACK   CallBackFunction
754   );
755 
756 /**
757   Retrieves the next valid token number in a given namespace.
758 
759   This is useful since the PCD infrastructure contains a sparse list of token numbers,
760   and one cannot a priori know what token numbers are valid in the database.
761 
762   If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
763   If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
764   If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
765   If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
766   The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
767   If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
768   If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
769   If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
770 
771 
772   @param[in]      Guid    The 128-bit unique value that designates the namespace from which to retrieve the next token.
773                           This is an optional parameter that may be NULL.  If this parameter is NULL, then a request is
774                           being made to retrieve tokens from the default token space.
775   @param[in, out] TokenNumber
776                           A pointer to the PCD token number to use to find the subsequent token number.
777 
778   @retval EFI_SUCCESS   The PCD service retrieved the next valid token number. Or the input token number
779                         is already the last valid token number in the PCD database.
780                         In the later case, *TokenNumber is updated with the value of 0.
781   @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
782 
783 **/
784 EFI_STATUS
785 EFIAPI
786 DxePcdGetNextToken (
787   IN CONST EFI_GUID               *Guid, OPTIONAL
788   IN OUT   UINTN                  *TokenNumber
789   );
790 
791 /**
792   Get next token space in PCD database according to given token space guid.
793 
794   @param Guid            Given token space guid. If NULL, then Guid will be set to
795                          the first PCD token space in PCD database, If not NULL, then
796                          Guid will be set to next PCD token space.
797 
798   @retval EFI_NOT_FOUND   If PCD database has no token space table or can not find given
799                           token space in PCD database.
800   @retval EFI_SUCCESS     Success to get next token space guid.
801 **/
802 EFI_STATUS
803 EFIAPI
804 DxePcdGetNextTokenSpace (
805   IN OUT CONST EFI_GUID               **Guid
806   );
807 
808 typedef struct {
809   LIST_ENTRY              Node;
810   PCD_PROTOCOL_CALLBACK   CallbackFn;
811 } CALLBACK_FN_ENTRY;
812 
813 #define CR_FNENTRY_FROM_LISTNODE(Record, Type, Field) BASE_CR(Record, Type, Field)
814 
815 //
816 // Internal Functions
817 //
818 
819 /**
820   Retrieve additional information associated with a PCD token.
821 
822   This includes information such as the type of value the TokenNumber is associated with as well as possible
823   human readable name that is associated with the token.
824 
825   @param[in]    Guid        The 128-bit unique value that designates the namespace from which to extract the value.
826   @param[in]    TokenNumber The PCD token number.
827   @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.
828                             The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
829 
830   @retval  EFI_SUCCESS      The PCD information was returned successfully
831   @retval  EFI_NOT_FOUND    The PCD service could not find the requested token number.
832 **/
833 EFI_STATUS
834 DxeGetPcdInfo (
835   IN CONST  EFI_GUID        *Guid,
836   IN        UINTN           TokenNumber,
837   OUT       EFI_PCD_INFO    *PcdInfo
838   );
839 
840 /**
841   Wrapper function for setting non-pointer type value for a PCD entry.
842 
843   @param TokenNumber     Pcd token number autogenerated by build tools.
844   @param Data            Value want to be set for PCD entry
845   @param Size            Size of value.
846 
847   @return status of SetWorker.
848 
849 **/
850 EFI_STATUS
851 SetValueWorker (
852   IN UINTN                   TokenNumber,
853   IN VOID                    *Data,
854   IN UINTN                   Size
855   );
856 
857 /**
858   Set value for an PCD entry
859 
860   @param TokenNumber     Pcd token number autogenerated by build tools.
861   @param Data            Value want to be set for PCD entry
862   @param Size            Size of value.
863   @param PtrType         If TRUE, the type of PCD entry's value is Pointer.
864                          If False, the type of PCD entry's value is not Pointer.
865 
866   @retval EFI_INVALID_PARAMETER  If this PCD type is VPD, VPD PCD can not be set.
867   @retval EFI_INVALID_PARAMETER  If Size can not be set to size table.
868   @retval EFI_INVALID_PARAMETER  If Size of non-Ptr type PCD does not match the size information in PCD database.
869   @retval EFI_NOT_FOUND          If value type of PCD entry is intergrate, but not in
870                                  range of UINT8, UINT16, UINT32, UINT64
871   @retval EFI_NOT_FOUND          Can not find the PCD type according to token number.
872 **/
873 EFI_STATUS
874 SetWorker (
875   IN          UINTN                     TokenNumber,
876   IN          VOID                      *Data,
877   IN OUT      UINTN                     *Size,
878   IN          BOOLEAN                   PtrType
879   );
880 
881 /**
882   Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
883 
884   @param ExTokenNumber   Token number for dynamic-ex PCD.
885   @param Guid            Token space guid for dynamic-ex PCD.
886   @param Data            Value want to be set.
887   @param SetSize         The size of value.
888 
889   @return status of ExSetWorker().
890 
891 **/
892 EFI_STATUS
893 ExSetValueWorker (
894   IN          UINTN                ExTokenNumber,
895   IN          CONST EFI_GUID       *Guid,
896   IN          VOID                 *Data,
897   IN          UINTN                SetSize
898   );
899 
900 /**
901   Set value for a dynamic PCD entry.
902 
903   This routine find the local token number according to dynamic-ex PCD's token
904   space guid and token number firstly, and invoke callback function if this PCD
905   entry registered callback function. Finally, invoken general SetWorker to set
906   PCD value.
907 
908   @param ExTokenNumber   Dynamic-ex PCD token number.
909   @param Guid            Token space guid for dynamic-ex PCD.
910   @param Data            PCD value want to be set
911   @param SetSize         Size of value.
912   @param PtrType         If TRUE, this PCD entry is pointer type.
913                          If FALSE, this PCD entry is not pointer type.
914 
915   @return status of SetWorker().
916 
917 **/
918 EFI_STATUS
919 ExSetWorker (
920   IN      UINTN                ExTokenNumber,
921   IN      CONST EFI_GUID       *Guid,
922   IN      VOID                 *Data,
923   IN OUT  UINTN                *Size,
924   IN      BOOLEAN              PtrType
925   );
926 
927 /**
928   Get the PCD entry pointer in PCD database.
929 
930   This routine will visit PCD database to find the PCD entry according to given
931   token number. The given token number is autogened by build tools and it will be
932   translated to local token number. Local token number contains PCD's type and
933   offset of PCD entry in PCD database.
934 
935   @param TokenNumber     Token's number, it is autogened by build tools
936   @param GetSize         The size of token's value
937 
938   @return PCD entry pointer in PCD database
939 
940 **/
941 VOID *
942 GetWorker (
943   IN UINTN             TokenNumber,
944   IN UINTN             GetSize
945   );
946 
947 /**
948   Wrapper function for get PCD value for dynamic-ex PCD.
949 
950   @param Guid            Token space guid for dynamic-ex PCD.
951   @param ExTokenNumber   Token number for dynamic-ex PCD.
952   @param GetSize         The size of dynamic-ex PCD value.
953 
954   @return PCD entry in PCD database.
955 
956 **/
957 VOID *
958 ExGetWorker (
959   IN CONST EFI_GUID         *Guid,
960   IN UINTN                  ExTokenNumber,
961   IN UINTN                  GetSize
962   );
963 
964 /**
965   Find the local token number according to system SKU ID.
966 
967   @param LocalTokenNumber PCD token number
968   @param Size             The size of PCD entry.
969   @param IsPeiDb          If TRUE, the PCD entry is initialized in PEI phase.
970                           If False, the PCD entry is initialized in DXE phase.
971 
972   @return Token number according to system SKU ID.
973 
974 **/
975 UINT32
976 GetSkuEnabledTokenNumber (
977   UINT32 LocalTokenNumber,
978   UINTN  Size,
979   BOOLEAN IsPeiDb
980   );
981 
982 /**
983   Get Variable which contains HII type PCD entry.
984 
985   @param VariableGuid    Variable's guid
986   @param VariableName    Variable's unicode name string
987   @param VariableData    Variable's data pointer,
988   @param VariableSize    Variable's size.
989 
990   @return the status of gRT->GetVariable
991 **/
992 EFI_STATUS
993 GetHiiVariable (
994   IN  EFI_GUID      *VariableGuid,
995   IN  UINT16        *VariableName,
996   OUT UINT8          **VariableData,
997   OUT UINTN         *VariableSize
998   );
999 
1000 /**
1001   Set value for HII-type PCD.
1002 
1003   A HII-type PCD's value is stored in a variable. Setting/Getting the value of
1004   HII-type PCD is to visit this variable.
1005 
1006   @param VariableGuid    Guid of variable which stored value of a HII-type PCD.
1007   @param VariableName    Unicode name of variable which stored value of a HII-type PCD.
1008   @param SetAttributes   Attributes bitmask to set for the variable.
1009   @param Data            Value want to be set.
1010   @param DataSize        Size of value
1011   @param Offset          Value offset of HII-type PCD in variable.
1012 
1013   @return status of GetVariable()/SetVariable().
1014 
1015 **/
1016 EFI_STATUS
1017 SetHiiVariable (
1018   IN  EFI_GUID     *VariableGuid,
1019   IN  UINT16       *VariableName,
1020   IN  UINT32       SetAttributes,
1021   IN  CONST VOID   *Data,
1022   IN  UINTN        DataSize,
1023   IN  UINTN        Offset
1024   );
1025 
1026 /**
1027   Register the callback function for a PCD entry.
1028 
1029   This routine will register a callback function to a PCD entry by given token number
1030   and token space guid.
1031 
1032   @param TokenNumber        PCD token's number, it is autogened by build tools.
1033   @param Guid               PCD token space's guid,
1034                             if not NULL, this PCD is dynamicEx type PCD.
1035   @param CallBackFunction   Callback function pointer
1036 
1037   @return EFI_SUCCESS Always success for registering callback function.
1038 
1039 **/
1040 EFI_STATUS
1041 DxeRegisterCallBackWorker (
1042   IN  UINTN                   TokenNumber,
1043   IN  CONST EFI_GUID          *Guid, OPTIONAL
1044   IN  PCD_PROTOCOL_CALLBACK   CallBackFunction
1045   );
1046 
1047 /**
1048   UnRegister the callback function for a PCD entry.
1049 
1050   This routine will unregister a callback function to a PCD entry by given token number
1051   and token space guid.
1052 
1053   @param TokenNumber        PCD token's number, it is autogened by build tools.
1054   @param Guid               PCD token space's guid.
1055                             if not NULL, this PCD is dynamicEx type PCD.
1056   @param CallBackFunction   Callback function pointer
1057 
1058   @retval EFI_SUCCESS               Callback function is success to be unregister.
1059   @retval EFI_INVALID_PARAMETER     Can not find the PCD entry by given token number.
1060 **/
1061 EFI_STATUS
1062 DxeUnRegisterCallBackWorker (
1063   IN  UINTN                   TokenNumber,
1064   IN  CONST EFI_GUID          *Guid, OPTIONAL
1065   IN  PCD_PROTOCOL_CALLBACK   CallBackFunction
1066   );
1067 
1068 /**
1069   Initialize the PCD database in DXE phase.
1070 
1071   PCD database in DXE phase also contains PCD database in PEI phase which is copied
1072   from GUID Hob.
1073 
1074 **/
1075 VOID
1076 BuildPcdDxeDataBase (
1077   VOID
1078   );
1079 
1080 /**
1081   Get Token Number according to dynamic-ex PCD's {token space guid:token number}
1082 
1083   A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1084   in DEC file. PCD database maintain a mapping table that translate pair of {token
1085   space guid: token number} to Token Number.
1086 
1087   @param Guid            Token space guid for dynamic-ex PCD entry.
1088   @param ExTokenNumber   Dynamic-ex PCD token number.
1089 
1090   @return Token Number for dynamic-ex PCD.
1091 
1092 **/
1093 UINTN
1094 GetExPcdTokenNumber (
1095   IN CONST EFI_GUID             *Guid,
1096   IN UINT32                     ExTokenNumber
1097   );
1098 
1099 /**
1100   Get next token number in given token space.
1101 
1102   This routine is used for dynamicEx type PCD. It will firstly scan token space
1103   table to get token space according to given token space guid. Then scan given
1104   token number in found token space, if found, then return next token number in
1105   this token space.
1106 
1107   @param Guid            Token space guid. Next token number will be scaned in
1108                          this token space.
1109   @param TokenNumber     Token number.
1110                          If PCD_INVALID_TOKEN_NUMBER, return first token number in
1111                          token space table.
1112                          If not PCD_INVALID_TOKEN_NUMBER, return next token number
1113                          in token space table.
1114   @param GuidTable       Token space guid table. It will be used for scan token space
1115                          by given token space guid.
1116   @param SizeOfGuidTable The size of guid table.
1117   @param ExMapTable      DynamicEx token number mapping table.
1118   @param SizeOfExMapTable The size of dynamicEx token number mapping table.
1119 
1120   @retval EFI_NOT_FOUND  Can not given token space or token number.
1121   @retval EFI_SUCCESS    Success to get next token number.
1122 
1123 **/
1124 EFI_STATUS
1125 ExGetNextTokeNumber (
1126   IN      CONST EFI_GUID    *Guid,
1127   IN OUT  UINTN             *TokenNumber,
1128   IN      EFI_GUID          *GuidTable,
1129   IN      UINTN             SizeOfGuidTable,
1130   IN      DYNAMICEX_MAPPING *ExMapTable,
1131   IN      UINTN             SizeOfExMapTable
1132   );
1133 
1134 /**
1135   Get size of POINTER type PCD value.
1136 
1137   @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1138   @param MaxSize                  Maximum size of POINTER type PCD value.
1139 
1140   @return size of POINTER type PCD value.
1141 
1142 **/
1143 UINTN
1144 GetPtrTypeSize (
1145   IN    UINTN             LocalTokenNumberTableIdx,
1146   OUT   UINTN             *MaxSize
1147   );
1148 
1149 /**
1150   Set size of POINTER type PCD value. The size should not exceed the maximum size
1151   of this PCD value.
1152 
1153   @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1154   @param CurrentSize              Size of POINTER type PCD value.
1155 
1156   @retval TRUE  Success to set size of PCD value.
1157   @retval FALSE Fail to set size of PCD value.
1158 **/
1159 BOOLEAN
1160 SetPtrTypeSize (
1161   IN          UINTN             LocalTokenNumberTableIdx,
1162   IN    OUT   UINTN             *CurrentSize
1163   );
1164 
1165 /**
1166   VariableLockProtocol callback
1167   to lock the variables referenced by DynamicHii PCDs with RO property set in *.dsc.
1168 
1169   @param[in] Event      Event whose notification function is being invoked.
1170   @param[in] Context    Pointer to the notification function's context.
1171 
1172 **/
1173 VOID
1174 EFIAPI
1175 VariableLockCallBack (
1176   IN EFI_EVENT          Event,
1177   IN VOID               *Context
1178   );
1179 
1180 extern  PCD_DATABASE   mPcdDatabase;
1181 
1182 extern  UINT32         mPcdTotalTokenCount;
1183 extern  UINT32         mPeiLocalTokenCount;
1184 extern  UINT32         mDxeLocalTokenCount;
1185 extern  UINT32         mPeiNexTokenCount;
1186 extern  UINT32         mDxeNexTokenCount;
1187 extern  UINT32         mPeiExMapppingTableSize;
1188 extern  UINT32         mDxeExMapppingTableSize;
1189 extern  UINT32         mPeiGuidTableSize;
1190 extern  UINT32         mDxeGuidTableSize;
1191 
1192 extern  BOOLEAN        mPeiExMapTableEmpty;
1193 extern  BOOLEAN        mDxeExMapTableEmpty;
1194 extern  BOOLEAN        mPeiDatabaseEmpty;
1195 
1196 extern  EFI_GUID     **TmpTokenSpaceBuffer;
1197 extern  UINTN          TmpTokenSpaceBufferCount;
1198 
1199 extern EFI_LOCK mPcdDatabaseLock;
1200 
1201 #endif
1202 
1203