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