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