]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/PCD/Dxe/Service.c
update code to pass K8.
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Dxe / Service.c
1 /** @file
2 Help functions used by PCD DXE driver.
3
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "Service.h"
16
17 PCD_DATABASE * mPcdDatabase;
18
19 LIST_ENTRY *mCallbackFnTable;
20
21 /**
22 Get the PCD entry pointer in PCD database.
23
24 This routine will visit PCD database to find the PCD entry according to given
25 token number. The given token number is autogened by build tools and it will be
26 translated to local token number. Local token number contains PCD's type and
27 offset of PCD entry in PCD database.
28
29 @param TokenNumber Token's number, it is autogened by build tools
30 @param GetSize The size of token's value
31
32 @return PCD entry pointer in PCD database
33
34 **/
35 VOID *
36 GetWorker (
37 IN UINTN TokenNumber,
38 IN UINTN GetSize
39 )
40 {
41 UINT32 *LocalTokenNumberTable;
42 EFI_GUID *GuidTable;
43 UINT16 *StringTable;
44 EFI_GUID *Guid;
45 UINT16 *Name;
46 VARIABLE_HEAD *VariableHead;
47 UINT8 *VaraiableDefaultBuffer;
48 UINT8 *Data;
49 VPD_HEAD *VpdHead;
50 UINT8 *PcdDb;
51 VOID *RetPtr;
52 UINTN MaxSize;
53 UINTN TmpTokenNumber;
54 UINTN DataSize;
55 EFI_STATUS Status;
56 UINT32 LocalTokenNumber;
57 UINT32 Offset;
58 UINT16 StringTableIdx;
59 BOOLEAN IsPeiDb;
60
61 //
62 // Aquire lock to prevent reentrance from TPL_CALLBACK level
63 //
64 EfiAcquireLock (&mPcdDatabaseLock);
65
66 RetPtr = NULL;
67 //
68 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
69 // We have to decrement TokenNumber by 1 to make it usable
70 // as the array index.
71 //
72 TokenNumber--;
73
74 TmpTokenNumber = TokenNumber;
75
76 //
77 // PCD_TOTAL_TOKEN_NUMBER is a auto-generated constant.
78 // It could be zero. EBC compiler is very choosy. It may
79 // report warning. So we add 1 in each size of the
80 // comparison.
81 //
82 ASSERT (TokenNumber + 1 < PCD_TOTAL_TOKEN_NUMBER + 1);
83
84 ASSERT ((GetSize == DxePcdGetSize (TokenNumber + 1)) || (GetSize == 0));
85
86 // EBC compiler is very choosy. It may report warning about comparison
87 // between UINTN and 0 . So we add 1 in each size of the
88 // comparison.
89 IsPeiDb = (BOOLEAN) ((TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1) ? TRUE : FALSE);
90
91 LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable :
92 mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
93
94 TokenNumber = IsPeiDb ? TokenNumber :
95 TokenNumber - PEI_LOCAL_TOKEN_NUMBER;
96
97 LocalTokenNumber = LocalTokenNumberTable[TokenNumber];
98
99 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
100 if (GetSize == 0) {
101 GetPtrTypeSize (TmpTokenNumber, &MaxSize);
102 } else {
103 MaxSize = GetSize;
104 }
105 LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, MaxSize, IsPeiDb);
106 }
107
108 PcdDb = IsPeiDb ? ((UINT8 *) &mPcdDatabase->PeiDb) : ((UINT8 *) &mPcdDatabase->DxeDb);
109
110 if (IsPeiDb) {
111 StringTable = (UINT16 *) (&mPcdDatabase->PeiDb.Init.StringTable[0]);
112 } else {
113 StringTable = (UINT16 *) (&mPcdDatabase->DxeDb.Init.StringTable[0]);
114 }
115
116
117 Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
118
119 switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
120 case PCD_TYPE_VPD:
121 VpdHead = (VPD_HEAD *) ((UINT8 *) PcdDb + Offset);
122 RetPtr = (VOID *) (UINTN) (FixedPcdGet32(PcdVpdBaseAddress) + VpdHead->Offset);
123 break;
124
125 case PCD_TYPE_HII:
126 if (IsPeiDb) {
127 GuidTable = (EFI_GUID *) (&mPcdDatabase->PeiDb.Init.GuidTable[0]);
128 } else {
129 GuidTable = (EFI_GUID *) (&mPcdDatabase->DxeDb.Init.GuidTable[0]);
130 }
131
132 VariableHead = (VARIABLE_HEAD *) (PcdDb + Offset);
133
134 Guid = GuidTable + VariableHead->GuidTableIndex;
135 Name = StringTable + VariableHead->StringIndex;
136 VaraiableDefaultBuffer = (UINT8 *) PcdDb + VariableHead->DefaultValueOffset;
137
138 Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
139 if (Status == EFI_SUCCESS) {
140 if (GetSize == 0) {
141 //
142 // It is a pointer type. So get the MaxSize reserved for
143 // this PCD entry.
144 //
145 GetPtrTypeSize (TmpTokenNumber, &GetSize);
146 }
147 CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset, GetSize);
148 FreePool (Data);
149 }
150 //
151 // If the operation is successful, we copy the data
152 // to the default value buffer in the PCD Database.
153 // So that we can free the Data allocated in GetHiiVariable.
154 //
155 //
156 // If the operation is not successful,
157 // Return 1) either the default value specified by Platform Integrator
158 // 2) Or the value Set by a PCD set operation.
159 //
160 RetPtr = (VOID *) VaraiableDefaultBuffer;
161 break;
162
163 case PCD_TYPE_STRING:
164 StringTableIdx = (UINT16) *((UINT8 *) PcdDb + Offset);
165 RetPtr = (VOID *) (StringTable + StringTableIdx);
166 break;
167
168 case PCD_TYPE_DATA:
169 RetPtr = (VOID *) ((UINT8 *) PcdDb + Offset);
170 break;
171
172 default:
173 ASSERT (FALSE);
174 break;
175
176 }
177
178 EfiReleaseLock (&mPcdDatabaseLock);
179
180 return RetPtr;
181
182 }
183
184 /**
185 Register the callback function for a PCD entry.
186
187 This routine will register a callback function to a PCD entry by given token number
188 and token space guid.
189
190 @param TokenNumber PCD token's number, it is autogened by build tools.
191 @param Guid PCD token space's guid,
192 if not NULL, this PCD is dynamicEx type PCD.
193 @param CallBackFunction Callback function pointer
194
195 @return EFI_SUCCESS Always success for registering callback function.
196
197 **/
198 EFI_STATUS
199 DxeRegisterCallBackWorker (
200 IN UINTN TokenNumber,
201 IN CONST EFI_GUID *Guid, OPTIONAL
202 IN PCD_PROTOCOL_CALLBACK CallBackFunction
203 )
204 {
205 CALLBACK_FN_ENTRY *FnTableEntry;
206 LIST_ENTRY *ListHead;
207 LIST_ENTRY *ListNode;
208
209 if (Guid != NULL) {
210 TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) TokenNumber);
211 }
212
213 //
214 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
215 // We have to decrement TokenNumber by 1 to make it usable
216 // as the array index.
217 //
218 TokenNumber--;
219
220 ListHead = &mCallbackFnTable[TokenNumber];
221 ListNode = GetFirstNode (ListHead);
222
223 while (ListNode != ListHead) {
224 FnTableEntry = CR_FNENTRY_FROM_LISTNODE(ListNode, CALLBACK_FN_ENTRY, Node);
225
226 if (FnTableEntry->CallbackFn == CallBackFunction) {
227 //
228 // We only allow a Callback function to be register once
229 // for a TokenNumber. So just return EFI_SUCCESS
230 //
231 return EFI_SUCCESS;
232 }
233 ListNode = GetNextNode (ListHead, ListNode);
234 }
235
236 FnTableEntry = AllocatePool (sizeof(CALLBACK_FN_ENTRY));
237 ASSERT (FnTableEntry != NULL);
238
239 FnTableEntry->CallbackFn = CallBackFunction;
240 InsertTailList (ListHead, &FnTableEntry->Node);
241
242 return EFI_SUCCESS;
243 }
244
245 /**
246 UnRegister the callback function for a PCD entry.
247
248 This routine will unregister a callback function to a PCD entry by given token number
249 and token space guid.
250
251 @param TokenNumber PCD token's number, it is autogened by build tools.
252 @param Guid PCD token space's guid.
253 if not NULL, this PCD is dynamicEx type PCD.
254 @param CallBackFunction Callback function pointer
255
256 @retval EFI_SUCCESS Callback function is success to be unregister.
257 @retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
258 **/
259 EFI_STATUS
260 DxeUnRegisterCallBackWorker (
261 IN UINTN TokenNumber,
262 IN CONST EFI_GUID *Guid, OPTIONAL
263 IN PCD_PROTOCOL_CALLBACK CallBackFunction
264 )
265 {
266 CALLBACK_FN_ENTRY *FnTableEntry;
267 LIST_ENTRY *ListHead;
268 LIST_ENTRY *ListNode;
269
270 if (Guid != NULL) {
271 TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) TokenNumber);
272 }
273
274 //
275 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
276 // We have to decrement TokenNumber by 1 to make it usable
277 // as the array index.
278 //
279 TokenNumber--;
280
281 ListHead = &mCallbackFnTable[TokenNumber];
282 ListNode = GetFirstNode (ListHead);
283
284 while (ListNode != ListHead) {
285 FnTableEntry = CR_FNENTRY_FROM_LISTNODE(ListNode, CALLBACK_FN_ENTRY, Node);
286
287 if (FnTableEntry->CallbackFn == CallBackFunction) {
288 //
289 // We only allow a Callback function to be register once
290 // for a TokenNumber. So we can safely remove the Node from
291 // the Link List and return EFI_SUCCESS.
292 //
293 RemoveEntryList (ListNode);
294 FreePool (FnTableEntry);
295
296 return EFI_SUCCESS;
297 }
298 ListNode = GetNextNode (ListHead, ListNode);
299 }
300
301 return EFI_INVALID_PARAMETER;
302 }
303
304 /**
305 Get next token number in given token space.
306
307 This routine is used for dynamicEx type PCD. It will firstly scan token space
308 table to get token space according to given token space guid. Then scan given
309 token number in found token space, if found, then return next token number in
310 this token space.
311
312 @param Guid Token space guid. Next token number will be scaned in
313 this token space.
314 @param TokenNumber Token number.
315 If PCD_INVALID_TOKEN_NUMBER, return first token number in
316 token space table.
317 If not PCD_INVALID_TOKEN_NUMBER, return next token number
318 in token space table.
319 @param GuidTable Token space guid table. It will be used for scan token space
320 by given token space guid.
321 @param SizeOfGuidTable The size of guid table.
322 @param ExMapTable DynamicEx token number mapping table.
323 @param SizeOfExMapTable The size of dynamicEx token number mapping table.
324
325 @retval EFI_NOT_FOUND Can not given token space or token number.
326 @retval EFI_SUCCESS Success to get next token number.
327
328 **/
329 EFI_STATUS
330 ExGetNextTokeNumber (
331 IN CONST EFI_GUID *Guid,
332 IN OUT UINTN *TokenNumber,
333 IN EFI_GUID *GuidTable,
334 IN UINTN SizeOfGuidTable,
335 IN DYNAMICEX_MAPPING *ExMapTable,
336 IN UINTN SizeOfExMapTable
337 )
338 {
339 EFI_GUID *MatchGuid;
340 UINTN Index;
341 UINTN GuidTableIdx;
342 BOOLEAN Found;
343
344 //
345 // Scan token space guid
346 //
347 MatchGuid = ScanGuid (GuidTable, SizeOfGuidTable, Guid);
348 if (MatchGuid == NULL) {
349 return EFI_NOT_FOUND;
350 }
351
352 //
353 // Find the token space table in dynamicEx mapping table.
354 //
355 Found = FALSE;
356 GuidTableIdx = MatchGuid - GuidTable;
357 for (Index = 0; Index < SizeOfExMapTable; Index++) {
358 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {
359 Found = TRUE;
360 break;
361 }
362 }
363
364 if (Found) {
365 //
366 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
367 // token number in found token space.
368 //
369 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {
370 *TokenNumber = ExMapTable[Index].ExTokenNumber;
371 return EFI_SUCCESS;
372 }
373
374 for ( ; Index < SizeOfExMapTable; Index++) {
375 if (ExMapTable[Index].ExTokenNumber == *TokenNumber) {
376 Index ++;
377 if (Index == SizeOfExMapTable) {
378 //
379 // Exceed the length of ExMap Table
380 //
381 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
382 return EFI_SUCCESS;
383 } else if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {
384 //
385 // Found the next match
386 //
387 *TokenNumber = ExMapTable[Index].ExTokenNumber;
388 return EFI_SUCCESS;
389 } else {
390 //
391 // Guid has been changed. It is the next Token Space Guid.
392 // We should flag no more TokenNumber.
393 //
394 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
395 return EFI_SUCCESS;
396 }
397 }
398 }
399 }
400
401 return EFI_NOT_FOUND;
402 }
403
404
405 /**
406 Initialize the PCD database in DXE phase.
407
408 PCD database in DXE phase also contains PCD database in PEI phase which is copied
409 from GUID Hob.
410
411 **/
412 VOID
413 BuildPcdDxeDataBase (
414 VOID
415 )
416 {
417 PEI_PCD_DATABASE *PeiDatabase;
418 EFI_HOB_GUID_TYPE *GuidHob;
419 UINTN Index;
420
421 mPcdDatabase = AllocateZeroPool (sizeof(PCD_DATABASE));
422 ASSERT (mPcdDatabase != NULL);
423
424 GuidHob = GetFirstGuidHob (&gPcdDataBaseHobGuid);
425 if (GuidHob != NULL) {
426
427 //
428 // We will copy over the PEI phase's PCD Database.
429 //
430 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
431 // should not be included at all. So the GuidHob could
432 // be NULL. If it is NULL, we just copy over the DXE Default
433 // Value to PCD Database.
434 //
435
436 PeiDatabase = (PEI_PCD_DATABASE *) GET_GUID_HOB_DATA (GuidHob);
437 //
438 // Copy PCD Entries refereneced in PEI phase to PCD DATABASE
439 //
440 CopyMem (&mPcdDatabase->PeiDb, PeiDatabase, sizeof (PEI_PCD_DATABASE));
441 }
442
443 //
444 // Copy PCD Entries with default value to PCD DATABASE
445 //
446 CopyMem (&mPcdDatabase->DxeDb.Init, &gDXEPcdDbInit, sizeof(DXE_PCD_DATABASE_INIT));
447
448
449 //
450 // Initialized the Callback Function Table
451 //
452
453 mCallbackFnTable = AllocateZeroPool (PCD_TOTAL_TOKEN_NUMBER * sizeof (LIST_ENTRY));
454 ASSERT(mCallbackFnTable != NULL);
455
456 // EBC compiler is very choosy. It may report warning about comparison
457 // between UINTN and 0 . So we add 1 in each size of the
458 // comparison.
459 for (Index = 0; Index + 1 < PCD_TOTAL_TOKEN_NUMBER + 1; Index++) {
460 InitializeListHead (&mCallbackFnTable[Index]);
461 }
462 }
463
464 /**
465 Get Variable which contains HII type PCD entry.
466
467 @param VariableGuid Variable's guid
468 @param VariableName Variable's unicode name string
469 @param VariableData Variable's data pointer,
470 @param VariableSize Variable's size.
471
472 @return the status of gRT->GetVariable
473 **/
474 EFI_STATUS
475 GetHiiVariable (
476 IN EFI_GUID *VariableGuid,
477 IN UINT16 *VariableName,
478 OUT UINT8 **VariableData,
479 OUT UINTN *VariableSize
480 )
481 {
482 UINTN Size;
483 EFI_STATUS Status;
484 UINT8 *Buffer;
485
486 Size = 0;
487 Buffer = NULL;
488
489 //
490 // Firstly get the real size of HII variable
491 //
492 Status = gRT->GetVariable (
493 (UINT16 *)VariableName,
494 VariableGuid,
495 NULL,
496 &Size,
497 Buffer
498 );
499
500 //
501 // Allocate buffer to hold whole variable data according to variable size.
502 //
503 if (Status == EFI_BUFFER_TOO_SMALL) {
504 Buffer = (UINT8 *) AllocatePool (Size);
505
506 ASSERT (Buffer != NULL);
507
508 Status = gRT->GetVariable (
509 VariableName,
510 VariableGuid,
511 NULL,
512 &Size,
513 Buffer
514 );
515
516 ASSERT (Status == EFI_SUCCESS);
517 *VariableData = Buffer;
518 *VariableSize = Size;
519 }
520
521 return Status;
522 }
523
524 /**
525 Find the local token number according to system SKU ID.
526
527 @param LocalTokenNumber PCD token number
528 @param Size The size of PCD entry.
529 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
530 If False, the PCD entry is initialized in DXE phase.
531
532 @return Token number according to system SKU ID.
533
534 **/
535 UINT32
536 GetSkuEnabledTokenNumber (
537 UINT32 LocalTokenNumber,
538 UINTN Size,
539 BOOLEAN IsPeiDb
540 )
541 {
542 SKU_HEAD *SkuHead;
543 SKU_ID *SkuIdTable;
544 INTN Index;
545 UINT8 *Value;
546 SKU_ID *PhaseSkuIdTable;
547 UINT8 *PcdDb;
548
549 ASSERT ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0);
550
551 PcdDb = IsPeiDb ? (UINT8 *) &mPcdDatabase->PeiDb : (UINT8 *) &mPcdDatabase->DxeDb;
552
553 SkuHead = (SKU_HEAD *) (PcdDb + (LocalTokenNumber & PCD_DATABASE_OFFSET_MASK));
554 Value = (UINT8 *) (PcdDb + SkuHead->SkuDataStartOffset);
555
556 PhaseSkuIdTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.SkuIdTable :
557 mPcdDatabase->DxeDb.Init.SkuIdTable;
558
559 SkuIdTable = &PhaseSkuIdTable[SkuHead->SkuIdTableOffset];
560
561 //
562 // Find the current system's SKU ID entry in SKU ID table.
563 //
564 for (Index = 0; Index < SkuIdTable[0]; Index++) {
565 if (mPcdDatabase->PeiDb.Init.SystemSkuId == SkuIdTable[Index + 1]) {
566 break;
567 }
568 }
569 ASSERT (Index < SkuIdTable[0]);
570
571 switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
572 case PCD_TYPE_VPD:
573 Value = (UINT8 *) &(((VPD_HEAD *) Value)[Index]);
574 return (UINT32) ((Value - PcdDb) | PCD_TYPE_VPD);
575
576 case PCD_TYPE_HII:
577 Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[Index]);
578 return (UINT32) ((Value - PcdDb) | PCD_TYPE_HII);
579
580 case PCD_TYPE_STRING:
581 Value = (UINT8 *) &(((STRING_HEAD *) Value)[Index]);
582 return (UINT32) ((Value - PcdDb) | PCD_TYPE_STRING);
583
584 case PCD_TYPE_DATA:
585 Value += Size * Index;
586 return (UINT32) (Value - PcdDb);
587
588 default:
589 ASSERT (FALSE);
590 }
591
592 ASSERT (FALSE);
593
594 return 0;
595
596 }
597
598 /**
599 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
600 has registered callback function.
601
602 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
603 type PCD.
604 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
605 PCD.
606 @param TokenNumber PCD token number generated by build tools.
607 @param Data Value want to be set for this PCD entry
608 @param Size The size of value
609
610 **/
611 VOID
612 InvokeCallbackOnSet (
613 UINT32 ExTokenNumber,
614 CONST EFI_GUID *Guid, OPTIONAL
615 UINTN TokenNumber,
616 VOID *Data,
617 UINTN Size
618 )
619 {
620 CALLBACK_FN_ENTRY *FnTableEntry;
621 LIST_ENTRY *ListHead;
622 LIST_ENTRY *ListNode;
623
624 //
625 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
626 // We have to decrement TokenNumber by 1 to make it usable
627 // as the array index.
628 //
629 TokenNumber--;
630
631 ListHead = &mCallbackFnTable[TokenNumber];
632 ListNode = GetFirstNode (ListHead);
633
634 while (ListNode != ListHead) {
635 FnTableEntry = CR_FNENTRY_FROM_LISTNODE(ListNode, CALLBACK_FN_ENTRY, Node);
636
637 FnTableEntry->CallbackFn(Guid,
638 (Guid == NULL) ? TokenNumber : ExTokenNumber,
639 Data,
640 Size);
641
642 ListNode = GetNextNode (ListHead, ListNode);
643 }
644
645 return;
646 }
647
648
649 /**
650 Wrapper function for setting non-pointer type value for a PCD entry.
651
652 @param TokenNumber Pcd token number autogenerated by build tools.
653 @param Data Value want to be set for PCD entry
654 @param Size Size of value.
655
656 @return status of SetWorker.
657
658 **/
659 EFI_STATUS
660 SetValueWorker (
661 IN UINTN TokenNumber,
662 IN VOID *Data,
663 IN UINTN Size
664 )
665 {
666 return SetWorker (TokenNumber, Data, &Size, FALSE);
667 }
668
669
670 /**
671 Set value for an PCD entry
672
673 @param TokenNumber Pcd token number autogenerated by build tools.
674 @param Data Value want to be set for PCD entry
675 @param Size Size of value.
676 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
677 If False, the type of PCD entry's value is not Pointer.
678
679 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
680 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
681 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
682 range of UINT8, UINT16, UINT32, UINT64
683 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
684 **/
685 EFI_STATUS
686 SetWorker (
687 IN UINTN TokenNumber,
688 IN VOID *Data,
689 IN OUT UINTN *Size,
690 IN BOOLEAN PtrType
691 )
692 {
693 UINT32 *LocalTokenNumberTable;
694 BOOLEAN IsPeiDb;
695 UINT32 LocalTokenNumber;
696 EFI_GUID *GuidTable;
697 UINT16 *StringTable;
698 EFI_GUID *Guid;
699 UINT16 *Name;
700 UINTN VariableOffset;
701 VOID *InternalData;
702 VARIABLE_HEAD *VariableHead;
703 UINTN Offset;
704 UINT8 *PcdDb;
705 EFI_STATUS Status;
706 UINTN MaxSize;
707 UINTN TmpTokenNumber;
708
709 //
710 // Aquire lock to prevent reentrance from TPL_CALLBACK level
711 //
712 EfiAcquireLock (&mPcdDatabaseLock);
713
714 //
715 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
716 // We have to decrement TokenNumber by 1 to make it usable
717 // as the array index.
718 //
719 TokenNumber--;
720
721 TmpTokenNumber = TokenNumber;
722
723 //
724 // EBC compiler is very choosy. It may report warning about comparison
725 // between UINTN and 0 . So we add 1 in each size of the
726 // comparison.
727 //
728 ASSERT (TokenNumber + 1 < PCD_TOTAL_TOKEN_NUMBER + 1);
729
730 if (!PtrType) {
731 ASSERT (*Size == DxePcdGetSize (TokenNumber + 1));
732 }
733
734 //
735 // EBC compiler is very choosy. It may report warning about comparison
736 // between UINTN and 0 . So we add 1 in each size of the
737 // comparison.
738 //
739 IsPeiDb = (BOOLEAN) ((TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1) ? TRUE : FALSE);
740
741 LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable :
742 mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
743
744 //
745 // EBC compiler is very choosy. It may report warning about comparison
746 // between UINTN and 0 . So we add 1 in each size of the
747 // comparison.
748 //
749 if ((TokenNumber + 1 < PEI_NEX_TOKEN_NUMBER + 1) ||
750 (TokenNumber + 1 >= PEI_LOCAL_TOKEN_NUMBER + 1 || TokenNumber + 1 < (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER + 1))) {
751 InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, *Size);
752 }
753
754 TokenNumber = IsPeiDb ? TokenNumber
755 : TokenNumber - PEI_LOCAL_TOKEN_NUMBER;
756
757 LocalTokenNumber = LocalTokenNumberTable[TokenNumber];
758
759 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
760 if (PtrType) {
761 GetPtrTypeSize (TmpTokenNumber, &MaxSize);
762 } else {
763 MaxSize = *Size;
764 }
765 LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, MaxSize, IsPeiDb);
766 }
767
768 Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
769
770 PcdDb = IsPeiDb ? ((UINT8 *) &mPcdDatabase->PeiDb) : ((UINT8 *) &mPcdDatabase->DxeDb);
771
772 if (IsPeiDb) {
773 StringTable = (UINT16 *) (&mPcdDatabase->PeiDb.Init.StringTable[0]);
774 } else {
775 StringTable = (UINT16 *) (&mPcdDatabase->DxeDb.Init.StringTable[0]);
776 }
777
778
779 InternalData = PcdDb + Offset;
780
781 switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
782 case PCD_TYPE_VPD:
783 ASSERT (FALSE);
784 Status = EFI_INVALID_PARAMETER;
785 break;
786
787 case PCD_TYPE_STRING:
788 if (SetPtrTypeSize (TmpTokenNumber, Size)) {
789 CopyMem (StringTable + *((UINT16 *)InternalData), Data, *Size);
790 Status = EFI_SUCCESS;
791 } else {
792 Status = EFI_INVALID_PARAMETER;
793 }
794 break;
795
796 case PCD_TYPE_HII:
797 if (PtrType) {
798 if (!SetPtrTypeSize (TmpTokenNumber, Size)) {
799 Status = EFI_INVALID_PARAMETER;
800 break;
801 }
802 }
803
804 if (IsPeiDb) {
805 GuidTable = (EFI_GUID *) (&mPcdDatabase->PeiDb.Init.GuidTable[0]);
806 } else {
807 GuidTable = (EFI_GUID *) (&mPcdDatabase->DxeDb.Init.GuidTable[0]);
808 }
809
810 VariableHead = (VARIABLE_HEAD *) (PcdDb + Offset);
811
812 Guid = GuidTable + VariableHead->GuidTableIndex;
813 Name = StringTable + VariableHead->StringIndex;
814 VariableOffset = VariableHead->Offset;
815
816 Status = SetHiiVariable (Guid, Name, Data, *Size, VariableOffset);
817
818 if (EFI_NOT_FOUND == Status) {
819 CopyMem (PcdDb + VariableHead->DefaultValueOffset, Data, *Size);
820 Status = EFI_SUCCESS;
821 }
822 break;
823
824 case PCD_TYPE_DATA:
825 if (PtrType) {
826 if (SetPtrTypeSize (TmpTokenNumber, Size)) {
827 CopyMem (InternalData, Data, *Size);
828 Status = EFI_SUCCESS;
829 } else {
830 Status = EFI_INVALID_PARAMETER;
831 }
832 break;
833 }
834
835 Status = EFI_SUCCESS;
836 switch (*Size) {
837 case sizeof(UINT8):
838 *((UINT8 *) InternalData) = *((UINT8 *) Data);
839 break;
840
841 case sizeof(UINT16):
842 *((UINT16 *) InternalData) = *((UINT16 *) Data);
843 break;
844
845 case sizeof(UINT32):
846 *((UINT32 *) InternalData) = *((UINT32 *) Data);
847 break;
848
849 case sizeof(UINT64):
850 *((UINT64 *) InternalData) = *((UINT64 *) Data);
851 break;
852
853 default:
854 ASSERT (FALSE);
855 Status = EFI_NOT_FOUND;
856 break;
857 }
858 break;
859
860 default:
861 ASSERT (FALSE);
862 Status = EFI_NOT_FOUND;
863 break;
864 }
865
866 EfiReleaseLock (&mPcdDatabaseLock);
867
868 return Status;
869 }
870
871 /**
872 Wrapper function for get PCD value for dynamic-ex PCD.
873
874 @param Guid Token space guid for dynamic-ex PCD.
875 @param ExTokenNumber Token number for dynamic-ex PCD.
876 @param GetSize The size of dynamic-ex PCD value.
877
878 @return PCD entry in PCD database.
879
880 **/
881 VOID *
882 ExGetWorker (
883 IN CONST EFI_GUID *Guid,
884 IN UINTN ExTokenNumber,
885 IN UINTN GetSize
886 )
887 {
888 return GetWorker(GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber), GetSize);
889 }
890
891 /**
892 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
893
894 @param ExTokenNumber Token number for dynamic-ex PCD.
895 @param Guid Token space guid for dynamic-ex PCD.
896 @param Data Value want to be set.
897 @param SetSize The size of value.
898
899 @return status of ExSetWorker().
900
901 **/
902 EFI_STATUS
903 ExSetValueWorker (
904 IN UINTN ExTokenNumber,
905 IN CONST EFI_GUID *Guid,
906 IN VOID *Data,
907 IN UINTN SetSize
908 )
909 {
910 return ExSetWorker (ExTokenNumber, Guid, Data, &SetSize, FALSE);
911 }
912
913 /**
914 Set value for a dynamic PCD entry.
915
916 This routine find the local token number according to dynamic-ex PCD's token
917 space guid and token number firstly, and invoke callback function if this PCD
918 entry registered callback function. Finally, invoken general SetWorker to set
919 PCD value.
920
921 @param ExTokenNumber Dynamic-ex PCD token number.
922 @param Guid Token space guid for dynamic-ex PCD.
923 @param Data PCD value want to be set
924 @param SetSize Size of value.
925 @param PtrType If TRUE, this PCD entry is pointer type.
926 If FALSE, this PCD entry is not pointer type.
927
928 @return status of SetWorker().
929
930 **/
931 EFI_STATUS
932 ExSetWorker (
933 IN UINTN ExTokenNumber,
934 IN CONST EFI_GUID *Guid,
935 IN VOID *Data,
936 IN OUT UINTN *SetSize,
937 IN BOOLEAN PtrType
938 )
939 {
940 UINTN TokenNumber;
941
942 TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber);
943
944 InvokeCallbackOnSet ((UINT32) ExTokenNumber, Guid, TokenNumber, Data, *SetSize);
945
946 return SetWorker (TokenNumber, Data, SetSize, PtrType);
947
948 }
949
950 /**
951 Set value for HII-type PCD.
952
953 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
954 HII-type PCD is to visit this variable.
955
956 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
957 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
958 @param Data Value want to be set.
959 @param DataSize Size of value
960 @param Offset Value offset of HII-type PCD in variable.
961
962 @return status of GetVariable()/SetVariable().
963
964 **/
965 EFI_STATUS
966 SetHiiVariable (
967 IN EFI_GUID *VariableGuid,
968 IN UINT16 *VariableName,
969 IN CONST VOID *Data,
970 IN UINTN DataSize,
971 IN UINTN Offset
972 )
973 {
974 UINTN Size;
975 VOID *Buffer;
976 EFI_STATUS Status;
977 UINT32 Attribute;
978
979 Size = 0;
980
981 Status = gRT->GetVariable (
982 (UINT16 *)VariableName,
983 VariableGuid,
984 NULL,
985 &Size,
986 NULL
987 );
988
989 if (Status == EFI_BUFFER_TOO_SMALL) {
990
991 Buffer = AllocatePool (Size);
992
993 ASSERT (Buffer != NULL);
994
995 Status = gRT->GetVariable (
996 VariableName,
997 VariableGuid,
998 &Attribute,
999 &Size,
1000 Buffer
1001 );
1002
1003 ASSERT_EFI_ERROR (Status);
1004
1005 CopyMem ((UINT8 *)Buffer + Offset, Data, DataSize);
1006
1007 Status = gRT->SetVariable (
1008 VariableName,
1009 VariableGuid,
1010 Attribute,
1011 Size,
1012 Buffer
1013 );
1014
1015 FreePool (Buffer);
1016 return Status;
1017
1018 }
1019
1020 //
1021 // If we drop to here, we don't have a Variable entry in
1022 // the variable service yet. So, we will save the data
1023 // in the PCD Database's volatile area.
1024 //
1025 return Status;
1026 }
1027
1028 /**
1029 Get local token number according to dynamic-ex PCD's {token space guid:token number}
1030
1031 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1032 in DEC file. PCD database maintain a mapping table that translate pair of {token
1033 space guid: token number} to local token number.
1034
1035 @param Guid Token space guid for dynamic-ex PCD entry.
1036 @param ExTokenNumber Dynamic-ex PCD token number.
1037
1038 @return local token number for dynamic-ex PCD.
1039
1040 **/
1041 UINTN
1042 GetExPcdTokenNumber (
1043 IN CONST EFI_GUID *Guid,
1044 IN UINT32 ExTokenNumber
1045 )
1046 {
1047 UINT32 Index;
1048 DYNAMICEX_MAPPING *ExMap;
1049 EFI_GUID *GuidTable;
1050 EFI_GUID *MatchGuid;
1051 UINTN MatchGuidIdx;
1052
1053 if (!PEI_DATABASE_EMPTY) {
1054 ExMap = mPcdDatabase->PeiDb.Init.ExMapTable;
1055 GuidTable = mPcdDatabase->PeiDb.Init.GuidTable;
1056
1057 MatchGuid = ScanGuid (GuidTable, sizeof(mPcdDatabase->PeiDb.Init.GuidTable), Guid);
1058
1059 if (MatchGuid != NULL) {
1060
1061 MatchGuidIdx = MatchGuid - GuidTable;
1062
1063 for (Index = 0; Index < PEI_EXMAPPING_TABLE_SIZE; Index++) {
1064 if ((ExTokenNumber == ExMap[Index].ExTokenNumber) &&
1065 (MatchGuidIdx == ExMap[Index].ExGuidIndex)) {
1066 return ExMap[Index].LocalTokenNumber;
1067 }
1068 }
1069 }
1070 }
1071
1072 ExMap = mPcdDatabase->DxeDb.Init.ExMapTable;
1073 GuidTable = mPcdDatabase->DxeDb.Init.GuidTable;
1074
1075 MatchGuid = ScanGuid (GuidTable, sizeof(mPcdDatabase->DxeDb.Init.GuidTable), Guid);
1076 //
1077 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1078 // error in the BUILD system.
1079 //
1080 ASSERT (MatchGuid != NULL);
1081
1082 MatchGuidIdx = MatchGuid - GuidTable;
1083
1084 for (Index = 0; Index < DXE_EXMAPPING_TABLE_SIZE; Index++) {
1085 if ((ExTokenNumber == ExMap[Index].ExTokenNumber) &&
1086 (MatchGuidIdx == ExMap[Index].ExGuidIndex)) {
1087 return ExMap[Index].LocalTokenNumber;
1088 }
1089 }
1090
1091 ASSERT (FALSE);
1092
1093 return 0;
1094 }
1095
1096 /**
1097 Get SKU ID table from PCD database.
1098
1099 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1100 @param IsPeiPcd If TRUE,
1101
1102 @return Pointer to SKU ID array table
1103
1104 **/
1105 SKU_ID *
1106 GetSkuIdArray (
1107 IN UINTN LocalTokenNumberTableIdx,
1108 IN BOOLEAN IsPeiPcd
1109 )
1110 {
1111 SKU_HEAD *SkuHead;
1112 UINTN LocalTokenNumber;
1113 UINT8 *Database;
1114
1115 if (IsPeiPcd) {
1116 LocalTokenNumber = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];
1117 Database = (UINT8 *) &mPcdDatabase->PeiDb;
1118 } else {
1119 LocalTokenNumber = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable[LocalTokenNumberTableIdx - PEI_LOCAL_TOKEN_NUMBER];
1120 Database = (UINT8 *) &mPcdDatabase->DxeDb;
1121 }
1122
1123 ASSERT ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) != 0);
1124
1125 SkuHead = (SKU_HEAD *) ((UINT8 *)Database + (LocalTokenNumber & PCD_DATABASE_OFFSET_MASK));
1126
1127 return (SKU_ID *) (Database + SkuHead->SkuIdTableOffset);
1128
1129 }
1130
1131
1132 /**
1133 Get index of PCD entry in size table.
1134
1135 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1136 @param LocalTokenNumberTable Pointer to local token number table in PCD database.
1137 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1138 If FALSE, the pcd entry is initialized in DXE phase.
1139
1140 @return index of PCD entry in size table.
1141
1142 **/
1143 UINTN
1144 GetSizeTableIndexA (
1145 IN UINTN LocalTokenNumberTableIdx,
1146 IN UINT32 *LocalTokenNumberTable,
1147 IN BOOLEAN IsPeiDb
1148 )
1149 {
1150 UINTN Index;
1151 UINTN SizeTableIdx;
1152 UINTN LocalTokenNumber;
1153 SKU_ID *SkuIdTable;
1154
1155 SizeTableIdx = 0;
1156
1157 for (Index=0; Index<LocalTokenNumberTableIdx; Index++) {
1158 LocalTokenNumber = LocalTokenNumberTable[Index];
1159
1160 if ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER) {
1161 //
1162 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1163 // PCD entry.
1164 //
1165 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1166 //
1167 // We have only one entry for VPD enabled PCD entry:
1168 // 1) MAX Size.
1169 // We consider current size is equal to MAX size.
1170 //
1171 SizeTableIdx++;
1172 } else {
1173 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
1174 //
1175 // We have only two entry for Non-Sku enabled PCD entry:
1176 // 1) MAX SIZE
1177 // 2) Current Size
1178 //
1179 SizeTableIdx += 2;
1180 } else {
1181 //
1182 // We have these entry for SKU enabled PCD entry
1183 // 1) MAX SIZE
1184 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1185 //
1186 SkuIdTable = GetSkuIdArray (Index, IsPeiDb);
1187 SizeTableIdx += (UINTN)*SkuIdTable + 1;
1188 }
1189 }
1190 }
1191
1192 }
1193
1194 return SizeTableIdx;
1195 }
1196
1197
1198
1199 /**
1200 Wrapper function of getting index of PCD entry in size table.
1201
1202 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1203 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1204 If FALSE, the pcd entry is initialized in DXE phase.
1205
1206 @return index of PCD entry in size table.
1207 **/
1208 UINTN
1209 GetSizeTableIndex (
1210 IN UINTN LocalTokenNumberTableIdx,
1211 IN BOOLEAN IsPeiDb
1212 )
1213 {
1214 UINT32 *LocalTokenNumberTable;
1215
1216 if (IsPeiDb) {
1217 LocalTokenNumberTable = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable;
1218 } else {
1219 LocalTokenNumberTable = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
1220 }
1221 return GetSizeTableIndexA (LocalTokenNumberTableIdx,
1222 LocalTokenNumberTable,
1223 IsPeiDb);
1224 }
1225
1226 /**
1227 Get size of POINTER type PCD value.
1228
1229 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1230 @param MaxSize Maxmium size of POINTER type PCD value.
1231
1232 @return size of POINTER type PCD value.
1233
1234 **/
1235 UINTN
1236 GetPtrTypeSize (
1237 IN UINTN LocalTokenNumberTableIdx,
1238 OUT UINTN *MaxSize
1239 )
1240 {
1241 INTN SizeTableIdx;
1242 UINTN LocalTokenNumber;
1243 SKU_ID *SkuIdTable;
1244 SIZE_INFO *SizeTable;
1245 UINTN Index;
1246 BOOLEAN IsPeiDb;
1247 UINT32 *LocalTokenNumberTable;
1248
1249 // EBC compiler is very choosy. It may report warning about comparison
1250 // between UINTN and 0 . So we add 1 in each size of the
1251 // comparison.
1252 IsPeiDb = (BOOLEAN) (LocalTokenNumberTableIdx + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
1253
1254
1255 if (IsPeiDb) {
1256 LocalTokenNumberTable = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable;
1257 SizeTable = mPcdDatabase->PeiDb.Init.SizeTable;
1258 } else {
1259 LocalTokenNumberTableIdx -= PEI_LOCAL_TOKEN_NUMBER;
1260 LocalTokenNumberTable = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
1261 SizeTable = mPcdDatabase->DxeDb.Init.SizeTable;
1262 }
1263
1264 LocalTokenNumber = LocalTokenNumberTable[LocalTokenNumberTableIdx];
1265
1266 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
1267
1268 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, IsPeiDb);
1269
1270 *MaxSize = SizeTable[SizeTableIdx];
1271 //
1272 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1273 // PCD entry.
1274 //
1275 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1276 //
1277 // We have only one entry for VPD enabled PCD entry:
1278 // 1) MAX Size.
1279 // We consider current size is equal to MAX size.
1280 //
1281 return *MaxSize;
1282 } else {
1283 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
1284 //
1285 // We have only two entry for Non-Sku enabled PCD entry:
1286 // 1) MAX SIZE
1287 // 2) Current Size
1288 //
1289 return SizeTable[SizeTableIdx + 1];
1290 } else {
1291 //
1292 // We have these entry for SKU enabled PCD entry
1293 // 1) MAX SIZE
1294 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1295 //
1296 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, IsPeiDb);
1297 for (Index = 0; Index < SkuIdTable[0]; Index++) {
1298 if (SkuIdTable[1 + Index] == mPcdDatabase->PeiDb.Init.SystemSkuId) {
1299 return SizeTable[SizeTableIdx + 1 + Index];
1300 }
1301 }
1302 return SizeTable[SizeTableIdx + 1];
1303 }
1304 }
1305 }
1306
1307 /**
1308 Set size of POINTER type PCD value. The size should not exceed the maximum size
1309 of this PCD value.
1310
1311 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1312 @param CurrentSize Size of POINTER type PCD value.
1313
1314 @retval TRUE Success to set size of PCD value.
1315 @retval FALSE Fail to set size of PCD value.
1316 **/
1317 BOOLEAN
1318 SetPtrTypeSize (
1319 IN UINTN LocalTokenNumberTableIdx,
1320 IN OUT UINTN *CurrentSize
1321 )
1322 {
1323 INTN SizeTableIdx;
1324 UINTN LocalTokenNumber;
1325 SKU_ID *SkuIdTable;
1326 SIZE_INFO *SizeTable;
1327 UINTN Index;
1328 UINTN MaxSize;
1329 BOOLEAN IsPeiDb;
1330 UINT32 *LocalTokenNumberTable;
1331
1332 //
1333 // EBC compiler is very choosy. It may report warning about comparison
1334 // between UINTN and 0 . So we add 1 in each size of the
1335 // comparison.
1336 //
1337 IsPeiDb = (BOOLEAN) (LocalTokenNumberTableIdx + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
1338
1339 if (IsPeiDb) {
1340 LocalTokenNumberTable = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable;
1341 SizeTable = mPcdDatabase->PeiDb.Init.SizeTable;
1342 } else {
1343 LocalTokenNumberTableIdx -= PEI_LOCAL_TOKEN_NUMBER;
1344 LocalTokenNumberTable = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
1345 SizeTable = mPcdDatabase->DxeDb.Init.SizeTable;
1346 }
1347
1348 LocalTokenNumber = LocalTokenNumberTable[LocalTokenNumberTableIdx];
1349
1350 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
1351
1352 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, IsPeiDb);
1353
1354 MaxSize = SizeTable[SizeTableIdx];
1355 //
1356 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1357 // PCD entry.
1358 //
1359 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1360 //
1361 // We shouldn't come here as we don't support SET for VPD
1362 //
1363 ASSERT (FALSE);
1364 return FALSE;
1365 } else {
1366 if ((*CurrentSize > MaxSize) ||
1367 (*CurrentSize == MAX_ADDRESS)) {
1368 *CurrentSize = MaxSize;
1369 return FALSE;
1370 }
1371
1372 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
1373 //
1374 // We have only two entry for Non-Sku enabled PCD entry:
1375 // 1) MAX SIZE
1376 // 2) Current Size
1377 //
1378 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
1379 return TRUE;
1380 } else {
1381 //
1382 // We have these entry for SKU enabled PCD entry
1383 // 1) MAX SIZE
1384 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1385 //
1386 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, IsPeiDb);
1387 for (Index = 0; Index < SkuIdTable[0]; Index++) {
1388 if (SkuIdTable[1 + Index] == mPcdDatabase->PeiDb.Init.SystemSkuId) {
1389 SizeTable[SizeTableIdx + 1 + Index] = (SIZE_INFO) *CurrentSize;
1390 return TRUE;
1391 }
1392 }
1393 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
1394 return TRUE;
1395 }
1396 }
1397 }