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