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