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