Import PCD dxe and PCD pei modules.
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Pcd.c
CommitLineData
80408db0 1/** @file PCD PEIM\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12\r
13Module Name: Pcd.c\r
14\r
15**/\r
16\r
17//\r
18// Include common header file for this module.\r
19//\r
20#include "CommonHeader.h"\r
21\r
22#include "Service.h"\r
23\r
24\r
25PCD_PPI mPcdPpiInstance = {\r
26 PeiPcdSetSku,\r
27\r
28 PeiPcdGet8,\r
29 PeiPcdGet16, \r
30 PeiPcdGet32, \r
31 PeiPcdGet64, \r
32 PeiPcdGetPtr, \r
33 PeiPcdGetBool, \r
34 PeiPcdGetSize,\r
35\r
36 PeiPcdGet8Ex,\r
37 PeiPcdGet16Ex, \r
38 PeiPcdGet32Ex, \r
39 PeiPcdGet64Ex, \r
40 PeiPcdGetPtrEx, \r
41 PeiPcdGetBoolEx, \r
42 PeiPcdGetSizeEx,\r
43 \r
44 PeiPcdSet8,\r
45 PeiPcdSet16, \r
46 PeiPcdSet32, \r
47 PeiPcdSet64, \r
48 PeiPcdSetPtr, \r
49 PeiPcdSetBool, \r
50\r
51 PeiPcdSet8Ex,\r
52 PeiPcdSet16Ex, \r
53 PeiPcdSet32Ex, \r
54 PeiPcdSet64Ex, \r
55 PeiPcdSetPtrEx, \r
56 PeiPcdSetBoolEx,\r
57\r
58 PeiRegisterCallBackOnSet,\r
59 PcdUnRegisterCallBackOnSet,\r
60 PeiPcdGetNextToken,\r
61 PeiPcdGetNextTokenSpace\r
62};\r
63\r
64\r
65\r
66STATIC EFI_PEI_PPI_DESCRIPTOR mPpiPCD = {\r
67 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
68 &gPcdPpiGuid,\r
69 &mPcdPpiInstance\r
70};\r
71\r
72\r
73\r
74EFI_STATUS\r
75EFIAPI\r
76PcdPeimInit (\r
77 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
78 IN EFI_PEI_SERVICES **PeiServices\r
79 )\r
80{\r
81 EFI_STATUS Status;\r
82\r
83 BuildPcdDatabase ();\r
84 \r
85 Status = PeiServicesInstallPpi (&mPpiPCD);\r
86\r
87 ASSERT_EFI_ERROR (Status);\r
88 \r
89 return EFI_SUCCESS;\r
90}\r
91\r
92VOID\r
93EFIAPI\r
94PeiPcdSetSku (\r
95 IN UINTN SkuId\r
96 )\r
97{\r
98\r
99 GetPcdDatabase()->Init.SystemSkuId = (SKU_ID) SkuId;\r
100\r
101 return;\r
102}\r
103\r
104\r
105\r
106UINT8\r
107EFIAPI\r
108PeiPcdGet8 (\r
109 IN UINTN TokenNumber\r
110 )\r
111{\r
112 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
113}\r
114\r
115\r
116\r
117UINT16\r
118EFIAPI\r
119PeiPcdGet16 (\r
120 IN UINTN TokenNumber\r
121 )\r
122{\r
123 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
124}\r
125\r
126\r
127\r
128UINT32\r
129EFIAPI\r
130PeiPcdGet32 (\r
131 IN UINTN TokenNumber\r
132 )\r
133{\r
134 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
135}\r
136\r
137\r
138\r
139UINT64\r
140EFIAPI\r
141PeiPcdGet64 (\r
142 IN UINTN TokenNumber\r
143 )\r
144{\r
145 return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r
146}\r
147\r
148\r
149\r
150VOID *\r
151EFIAPI\r
152PeiPcdGetPtr (\r
153 IN UINTN TokenNumber\r
154 )\r
155{\r
156 return GetWorker (TokenNumber, 0);\r
157}\r
158\r
159\r
160\r
161BOOLEAN\r
162EFIAPI\r
163PeiPcdGetBool (\r
164 IN UINTN TokenNumber\r
165 )\r
166{\r
167 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
168}\r
169\r
170\r
171\r
172UINTN\r
173EFIAPI\r
174PeiPcdGetSize (\r
175 IN UINTN TokenNumber\r
176 )\r
177{\r
178 PEI_PCD_DATABASE *PeiPcdDb;\r
179 UINTN Size;\r
180 UINTN MaxSize;\r
181\r
182 //\r
183 // If DebugAssertEnabled is TRUE, we still need to provide the GET size\r
184 // function as GetWorker and SetWoker need this function to do ASSERT.\r
185 //\r
186 if ((!FeaturePcdGet(PcdPeiPcdDatabaseGetSizeEnabled)) &&\r
187 (!DebugAssertEnabled ())) {\r
188 return 0;\r
189 }\r
190\r
191 PeiPcdDb = GetPcdDatabase ();\r
192 //\r
193 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
194 // We have to decrement TokenNumber by 1 to make it usable\r
195 // as the array index.\r
196 //\r
197 TokenNumber--;\r
198\r
199 // EBC compiler is very choosy. It may report warning about comparison\r
200 // between UINTN and 0 . So we add 1 in each size of the \r
201 // comparison.\r
202 ASSERT (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);\r
203\r
204 Size = (PeiPcdDb->Init.LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
205\r
206 if (Size == 0) {\r
207 //\r
208 // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r
209 //\r
210 return GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);\r
211 } else {\r
212 return Size;\r
213 }\r
214\r
215}\r
216\r
217\r
218\r
219UINT8\r
220EFIAPI\r
221PeiPcdGet8Ex (\r
222 IN CONST EFI_GUID *Guid,\r
223 IN UINTN ExTokenNumber\r
224 )\r
225{\r
226 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r
227}\r
228\r
229\r
230\r
231UINT16\r
232EFIAPI\r
233PeiPcdGet16Ex (\r
234 IN CONST EFI_GUID *Guid,\r
235 IN UINTN ExTokenNumber\r
236 )\r
237{\r
238 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r
239}\r
240\r
241\r
242\r
243UINT32\r
244EFIAPI\r
245PeiPcdGet32Ex (\r
246 IN CONST EFI_GUID *Guid,\r
247 IN UINTN ExTokenNumber\r
248 )\r
249{\r
250 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r
251}\r
252\r
253\r
254\r
255UINT64\r
256EFIAPI\r
257PeiPcdGet64Ex (\r
258 IN CONST EFI_GUID *Guid,\r
259 IN UINTN ExTokenNumber\r
260 )\r
261{\r
262 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r
263}\r
264\r
265\r
266\r
267VOID *\r
268EFIAPI\r
269PeiPcdGetPtrEx (\r
270 IN CONST EFI_GUID *Guid,\r
271 IN UINTN ExTokenNumber\r
272 )\r
273{\r
274 return ExGetWorker (Guid, ExTokenNumber, 0);\r
275}\r
276\r
277\r
278\r
279BOOLEAN\r
280EFIAPI\r
281PeiPcdGetBoolEx (\r
282 IN CONST EFI_GUID *Guid,\r
283 IN UINTN ExTokenNumber\r
284 )\r
285{\r
286 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r
287}\r
288\r
289\r
290\r
291UINTN\r
292EFIAPI\r
293PeiPcdGetSizeEx (\r
294 IN CONST EFI_GUID *Guid,\r
295 IN UINTN ExTokenNumber\r
296 )\r
297{\r
298 if ((!FeaturePcdGet (PcdPeiPcdDatabaseGetSizeEnabled)) || !FeaturePcdGet (PcdPeiPcdDatabaseExEnabled)) {\r
299 return 0;\r
300 }\r
301\r
302 return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));\r
303}\r
304\r
305\r
306\r
307EFI_STATUS\r
308EFIAPI\r
309PeiPcdSet8 (\r
310 IN UINTN TokenNumber,\r
311 IN UINT8 Value\r
312 )\r
313{\r
314 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
315}\r
316\r
317\r
318\r
319EFI_STATUS\r
320EFIAPI\r
321PeiPcdSet16 (\r
322 IN UINTN TokenNumber,\r
323 IN UINT16 Value\r
324 )\r
325{\r
326 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
327}\r
328\r
329\r
330\r
331EFI_STATUS\r
332EFIAPI\r
333PeiPcdSet32 (\r
334 IN UINTN TokenNumber,\r
335 IN UINT32 Value\r
336 )\r
337{\r
338 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
339}\r
340\r
341\r
342\r
343EFI_STATUS\r
344EFIAPI\r
345PeiPcdSet64 (\r
346 IN UINTN TokenNumber,\r
347 IN UINT64 Value\r
348 )\r
349{\r
350 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
351}\r
352\r
353\r
354EFI_STATUS\r
355EFIAPI\r
356PeiPcdSetPtr (\r
357 IN UINTN TokenNumber,\r
358 IN OUT UINTN *SizeOfBuffer,\r
359 IN VOID *Buffer\r
360 )\r
361{\r
362 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
363}\r
364\r
365\r
366\r
367EFI_STATUS\r
368EFIAPI\r
369PeiPcdSetBool (\r
370 IN UINTN TokenNumber,\r
371 IN BOOLEAN Value\r
372 )\r
373{\r
374 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
375}\r
376\r
377\r
378\r
379EFI_STATUS\r
380EFIAPI\r
381PeiPcdSet8Ex (\r
382 IN CONST EFI_GUID *Guid,\r
383 IN UINTN ExTokenNumber,\r
384 IN UINT8 Value\r
385 )\r
386{\r
387 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
388}\r
389\r
390\r
391\r
392EFI_STATUS\r
393EFIAPI\r
394PeiPcdSet16Ex (\r
395 IN CONST EFI_GUID *Guid,\r
396 IN UINTN ExTokenNumber,\r
397 IN UINT16 Value\r
398 )\r
399{\r
400 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
401}\r
402\r
403\r
404\r
405EFI_STATUS\r
406EFIAPI\r
407PeiPcdSet32Ex (\r
408 IN CONST EFI_GUID *Guid,\r
409 IN UINTN ExTokenNumber,\r
410 IN UINT32 Value\r
411 )\r
412{\r
413 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
414}\r
415\r
416\r
417\r
418EFI_STATUS\r
419EFIAPI\r
420PeiPcdSet64Ex (\r
421 IN CONST EFI_GUID *Guid,\r
422 IN UINTN ExTokenNumber,\r
423 IN UINT64 Value\r
424 )\r
425{\r
426 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
427}\r
428\r
429\r
430\r
431EFI_STATUS\r
432EFIAPI\r
433PeiPcdSetPtrEx (\r
434 IN CONST EFI_GUID *Guid,\r
435 IN UINTN ExTokenNumber,\r
436 IN UINTN *SizeOfBuffer,\r
437 IN VOID *Value\r
438 )\r
439{\r
440 return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);\r
441}\r
442\r
443\r
444\r
445EFI_STATUS\r
446EFIAPI\r
447PeiPcdSetBoolEx (\r
448 IN CONST EFI_GUID *Guid,\r
449 IN UINTN ExTokenNumber,\r
450 IN BOOLEAN Value\r
451 )\r
452{\r
453 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
454}\r
455\r
456\r
457\r
458\r
459EFI_STATUS\r
460EFIAPI\r
461PeiRegisterCallBackOnSet (\r
462 IN CONST EFI_GUID *Guid, OPTIONAL\r
463 IN UINTN ExTokenNumber,\r
464 IN PCD_PPI_CALLBACK CallBackFunction\r
465 )\r
466{\r
467 if (!FeaturePcdGet(PcdPeiPcdDatabaseCallbackOnSetEnabled)) {\r
468 return EFI_UNSUPPORTED;\r
469 }\r
470\r
471 ASSERT (CallBackFunction != NULL);\r
472 \r
473 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);\r
474}\r
475\r
476\r
477\r
478EFI_STATUS\r
479EFIAPI\r
480PcdUnRegisterCallBackOnSet (\r
481 IN CONST EFI_GUID *Guid, OPTIONAL\r
482 IN UINTN ExTokenNumber,\r
483 IN PCD_PPI_CALLBACK CallBackFunction\r
484 )\r
485{\r
486 if (!FeaturePcdGet(PcdPeiPcdDatabaseCallbackOnSetEnabled)) {\r
487 return EFI_UNSUPPORTED;\r
488 }\r
489\r
490 ASSERT (CallBackFunction != NULL);\r
491 \r
492 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);\r
493}\r
494\r
495\r
496\r
497EFI_STATUS\r
498EFIAPI\r
499PeiPcdGetNextToken (\r
500 IN CONST EFI_GUID *Guid, OPTIONAL\r
501 IN OUT UINTN *TokenNumber\r
502 )\r
503{\r
504 UINTN GuidTableIdx;\r
505 PEI_PCD_DATABASE *PeiPcdDb;\r
506 EFI_GUID *MatchGuid;\r
507 DYNAMICEX_MAPPING *ExMapTable;\r
508 UINTN i;\r
509 BOOLEAN Found;\r
510 BOOLEAN PeiExMapTableEmpty;\r
511\r
512 if (!FeaturePcdGet (PcdPeiPcdDatabaseTraverseEnabled)) {\r
513 return EFI_UNSUPPORTED;\r
514 }\r
515\r
516 PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;\r
517\r
518 if (Guid == NULL) {\r
519 if (*TokenNumber > PEI_NEX_TOKEN_NUMBER) {\r
520 return EFI_NOT_FOUND;\r
521 }\r
522 (*TokenNumber)++;\r
523 if (*TokenNumber > PEI_NEX_TOKEN_NUMBER) {\r
524 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
525 }\r
526 return EFI_SUCCESS;\r
527 } else {\r
528 if (PeiExMapTableEmpty) {\r
529 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
530 return EFI_SUCCESS;\r
531 }\r
532 \r
533 //\r
534 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order\r
535 // 1) ExGuid\r
536 // 2) ExTokenNumber\r
537 //\r
538 PeiPcdDb = GetPcdDatabase ();\r
539 \r
540 MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), Guid);\r
541\r
542 if (MatchGuid == NULL) {\r
543 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
544 return EFI_NOT_FOUND;\r
545 }\r
546\r
547 GuidTableIdx = MatchGuid - PeiPcdDb->Init.GuidTable;\r
548\r
549 ExMapTable = PeiPcdDb->Init.ExMapTable;\r
550\r
551 Found = FALSE;\r
552 //\r
553 // Locate the GUID in ExMapTable first.\r
554 //\r
555 for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {\r
556 if (ExMapTable[i].ExGuidIndex == GuidTableIdx) {\r
557 Found = TRUE;\r
558 break;\r
559 }\r
560 }\r
561\r
562 if (Found) {\r
563 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r
564 *TokenNumber = ExMapTable[i].ExTokenNumber;\r
565 return EFI_SUCCESS;\r
566 }\r
567\r
568 for ( ; i < PEI_EXMAPPING_TABLE_SIZE; i++) {\r
569 if (ExMapTable[i].ExTokenNumber == *TokenNumber) {\r
570 i++;\r
571 if (i == PEI_EXMAPPING_TABLE_SIZE) {\r
572 //\r
573 // Exceed the length of ExMap Table\r
574 //\r
575 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
576 return EFI_SUCCESS;\r
577 }\r
578 if (ExMapTable[i].ExGuidIndex == GuidTableIdx) {\r
579 *TokenNumber = ExMapTable[i].ExTokenNumber;\r
580 return EFI_SUCCESS;\r
581 } else {\r
582 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
583 return EFI_SUCCESS;\r
584 }\r
585 }\r
586 }\r
587 return EFI_NOT_FOUND;\r
588 }\r
589 }\r
590\r
591 return EFI_NOT_FOUND;\r
592}\r
593\r
594\r
595\r
596EFI_STATUS\r
597EFIAPI\r
598PeiPcdGetNextTokenSpace (\r
599 IN OUT CONST EFI_GUID **Guid\r
600 )\r
601{\r
602 UINTN GuidTableIdx;\r
603 EFI_GUID *MatchGuid;\r
604 PEI_PCD_DATABASE *PeiPcdDb;\r
605 DYNAMICEX_MAPPING *ExMapTable;\r
606 UINTN i;\r
607 BOOLEAN Found;\r
608 BOOLEAN PeiExMapTableEmpty;\r
609\r
610 if (!FeaturePcdGet (PcdPeiPcdDatabaseTraverseEnabled)) {\r
611 return EFI_UNSUPPORTED;\r
612 }\r
613\r
614 ASSERT (Guid != NULL);\r
615\r
616 PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;\r
617\r
618 if (PeiExMapTableEmpty) {\r
619 if (*Guid != NULL) {\r
620 return EFI_NOT_FOUND;\r
621 } else {\r
622 return EFI_SUCCESS;\r
623 }\r
624 }\r
625\r
626 //\r
627 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order\r
628 // 1) ExGuid\r
629 // 2) ExTokenNumber\r
630 //\r
631 PeiPcdDb = GetPcdDatabase ();\r
632\r
633 ExMapTable = PeiPcdDb->Init.ExMapTable;\r
634\r
635 if (*Guid == NULL) {\r
636 //\r
637 // return the first Token Space Guid.\r
638 //\r
639 *Guid = &PeiPcdDb->Init.GuidTable[ExMapTable[0].ExGuidIndex];\r
640 return EFI_SUCCESS;\r
641 }\r
642\r
643 MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), *Guid);\r
644\r
645 if (MatchGuid == NULL) {\r
646 return EFI_NOT_FOUND;\r
647 }\r
648 \r
649 GuidTableIdx = MatchGuid - PeiPcdDb->Init.GuidTable;\r
650\r
651 Found = FALSE;\r
652 for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {\r
653 if (ExMapTable[i].ExGuidIndex == GuidTableIdx) {\r
654 Found = TRUE;\r
655 break;\r
656 }\r
657 }\r
658\r
659 if (Found) {\r
660 i++;\r
661 for ( ; i < PEI_EXMAPPING_TABLE_SIZE; i++ ) {\r
662 if (ExMapTable[i].ExGuidIndex != GuidTableIdx ) {\r
663 *Guid = &PeiPcdDb->Init.GuidTable[ExMapTable[i].ExGuidIndex];\r
664 return EFI_SUCCESS;\r
665 }\r
666 }\r
667 *Guid = NULL;\r
668 return EFI_SUCCESS;\r
669 }\r
670\r
671 return EFI_NOT_FOUND;\r
672\r
673}\r
674\r
675UINTN\r
676GetPtrTypeSize (\r
677 IN UINTN LocalTokenNumberTableIdx,\r
678 OUT UINTN *MaxSize,\r
679 IN PEI_PCD_DATABASE *Database\r
680 )\r
681{\r
682 INTN SizeTableIdx;\r
683 UINTN LocalTokenNumber;\r
684 SKU_ID *SkuIdTable;\r
685 SIZE_INFO *SizeTable;\r
686 UINTN i;\r
687\r
688 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
689\r
690 LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];\r
691\r
692 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
693 \r
694 SizeTable = Database->Init.SizeTable;\r
695\r
696 *MaxSize = SizeTable[SizeTableIdx];\r
697 //\r
698 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
699 // PCD entry.\r
700 //\r
701 if (LocalTokenNumber & PCD_TYPE_VPD) {\r
702 //\r
703 // We have only one entry for VPD enabled PCD entry:\r
704 // 1) MAX Size.\r
705 // We consider current size is equal to MAX size.\r
706 //\r
707 return *MaxSize;\r
708 } else {\r
709 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {\r
710 //\r
711 // We have only two entry for Non-Sku enabled PCD entry:\r
712 // 1) MAX SIZE\r
713 // 2) Current Size\r
714 //\r
715 return SizeTable[SizeTableIdx + 1];\r
716 } else {\r
717 //\r
718 // We have these entry for SKU enabled PCD entry\r
719 // 1) MAX SIZE\r
720 // 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
721 //\r
722 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
723 for (i = 0; i < SkuIdTable[0]; i++) {\r
724 if (SkuIdTable[1 + i] == Database->Init.SystemSkuId) {\r
725 return SizeTable[SizeTableIdx + 1 + i];\r
726 }\r
727 }\r
728 return SizeTable[SizeTableIdx + 1];\r
729 }\r
730 }\r
731}\r
732\r
733\r
734\r
735BOOLEAN\r
736SetPtrTypeSize (\r
737 IN UINTN LocalTokenNumberTableIdx,\r
738 IN OUT UINTN *CurrentSize,\r
739 IN PEI_PCD_DATABASE *Database\r
740 )\r
741{\r
742 INTN SizeTableIdx;\r
743 UINTN LocalTokenNumber;\r
744 SKU_ID *SkuIdTable;\r
745 SIZE_INFO *SizeTable;\r
746 UINTN i;\r
747 UINTN MaxSize;\r
748 \r
749 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
750\r
751 LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];\r
752\r
753 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
754 \r
755 SizeTable = Database->Init.SizeTable;\r
756\r
757 MaxSize = SizeTable[SizeTableIdx];\r
758 //\r
759 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
760 // PCD entry.\r
761 //\r
762 if (LocalTokenNumber & PCD_TYPE_VPD) {\r
763 //\r
764 // We shouldn't come here as we don't support SET for VPD\r
765 //\r
766 ASSERT (FALSE);\r
767 return FALSE;\r
768 } else {\r
769 if ((*CurrentSize > MaxSize) ||\r
770 (*CurrentSize == MAX_ADDRESS)) {\r
771 *CurrentSize = MaxSize;\r
772 return FALSE;\r
773 } \r
774 \r
775 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {\r
776 //\r
777 // We have only two entry for Non-Sku enabled PCD entry:\r
778 // 1) MAX SIZE\r
779 // 2) Current Size\r
780 //\r
781 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r
782 return TRUE;\r
783 } else {\r
784 //\r
785 // We have these entry for SKU enabled PCD entry\r
786 // 1) MAX SIZE\r
787 // 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
788 //\r
789 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
790 for (i = 0; i < SkuIdTable[0]; i++) {\r
791 if (SkuIdTable[1 + i] == Database->Init.SystemSkuId) {\r
792 SizeTable[SizeTableIdx + 1 + i] = (SIZE_INFO) *CurrentSize;\r
793 return TRUE;\r
794 }\r
795 }\r
796 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r
797 return TRUE;\r
798 }\r
799 }\r
800\r
801}\r