]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/PCD/Dxe/Service.c
Adds ASSERT check in DxePcd driver when error status of read DynamicHii PCD is not...
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Dxe / Service.c
1 /** @file
2 Help functions used by PCD DXE driver.
3
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 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 STRING_HEAD 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 = *(STRING_HEAD*)((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 //
154 // If the operation is successful, we copy the data
155 // to the default value buffer in the PCD Database.
156 // So that we can free the Data allocated in GetHiiVariable.
157 //
158 CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset, GetSize);
159 FreePool (Data);
160 }
161 RetPtr = (VOID *) VaraiableDefaultBuffer;
162 } else {
163 VaraiableDefaultBuffer = (UINT8 *) PcdDb + VariableHead->DefaultValueOffset;
164
165 Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
166 if (Status == EFI_SUCCESS) {
167 if (GetSize == 0) {
168 //
169 // It is a pointer type. So get the MaxSize reserved for
170 // this PCD entry.
171 //
172 GetPtrTypeSize (TmpTokenNumber, &GetSize);
173 }
174 //
175 // If the operation is successful, we copy the data
176 // to the default value buffer in the PCD Database.
177 // So that we can free the Data allocated in GetHiiVariable.
178 //
179 CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset, GetSize);
180 FreePool (Data);
181 }
182 RetPtr = (VOID *) VaraiableDefaultBuffer;
183 }
184 break;
185
186 case PCD_TYPE_STRING:
187 StringTableIdx = *(STRING_HEAD*)((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 } else {
539 //
540 // Use Default Data only when variable is not found.
541 // For other error status, correct data can't be got, and trig ASSERT().
542 //
543 ASSERT (Status == EFI_NOT_FOUND);
544 }
545
546 return Status;
547 }
548
549 /**
550 Find the local token number according to system SKU ID.
551
552 @param LocalTokenNumber PCD token number
553 @param Size The size of PCD entry.
554 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
555 If False, the PCD entry is initialized in DXE phase.
556
557 @return Token number according to system SKU ID.
558
559 **/
560 UINT32
561 GetSkuEnabledTokenNumber (
562 UINT32 LocalTokenNumber,
563 UINTN Size,
564 BOOLEAN IsPeiDb
565 )
566 {
567 SKU_HEAD *SkuHead;
568 SKU_ID *SkuIdTable;
569 INTN Index;
570 UINT8 *Value;
571 SKU_ID *PhaseSkuIdTable;
572 UINT8 *PcdDb;
573
574 ASSERT ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0);
575
576 PcdDb = IsPeiDb ? (UINT8 *) &mPcdDatabase->PeiDb : (UINT8 *) &mPcdDatabase->DxeDb;
577
578 SkuHead = (SKU_HEAD *) (PcdDb + (LocalTokenNumber & PCD_DATABASE_OFFSET_MASK));
579 Value = (UINT8 *) (PcdDb + SkuHead->SkuDataStartOffset);
580
581 PhaseSkuIdTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.SkuIdTable :
582 mPcdDatabase->DxeDb.Init.SkuIdTable;
583
584 SkuIdTable = &PhaseSkuIdTable[SkuHead->SkuIdTableOffset];
585
586 //
587 // Find the current system's SKU ID entry in SKU ID table.
588 //
589 for (Index = 0; Index < SkuIdTable[0]; Index++) {
590 if (mPcdDatabase->PeiDb.Init.SystemSkuId == SkuIdTable[Index + 1]) {
591 break;
592 }
593 }
594 ASSERT (Index < SkuIdTable[0]);
595
596 switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
597 case PCD_TYPE_VPD:
598 Value = (UINT8 *) &(((VPD_HEAD *) Value)[Index]);
599 return (UINT32) ((Value - PcdDb) | PCD_TYPE_VPD);
600
601 case PCD_TYPE_HII:
602 Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[Index]);
603 return (UINT32) ((Value - PcdDb) | PCD_TYPE_HII);
604
605 case PCD_TYPE_STRING:
606 Value = (UINT8 *) &(((STRING_HEAD *) Value)[Index]);
607 return (UINT32) ((Value - PcdDb) | PCD_TYPE_STRING);
608
609 case PCD_TYPE_DATA:
610 Value += Size * Index;
611 return (UINT32) (Value - PcdDb);
612
613 default:
614 ASSERT (FALSE);
615 }
616
617 ASSERT (FALSE);
618
619 return 0;
620
621 }
622
623 /**
624 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
625 has registered callback function.
626
627 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
628 type PCD.
629 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
630 PCD.
631 @param TokenNumber PCD token number generated by build tools.
632 @param Data Value want to be set for this PCD entry
633 @param Size The size of value
634
635 **/
636 VOID
637 InvokeCallbackOnSet (
638 UINT32 ExTokenNumber,
639 CONST EFI_GUID *Guid, OPTIONAL
640 UINTN TokenNumber,
641 VOID *Data,
642 UINTN Size
643 )
644 {
645 CALLBACK_FN_ENTRY *FnTableEntry;
646 LIST_ENTRY *ListHead;
647 LIST_ENTRY *ListNode;
648
649 //
650 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
651 // We have to decrement TokenNumber by 1 to make it usable
652 // as the array index of mCallbackFnTable[].
653 //
654 ListHead = &mCallbackFnTable[TokenNumber - 1];
655 ListNode = GetFirstNode (ListHead);
656
657 while (ListNode != ListHead) {
658 FnTableEntry = CR_FNENTRY_FROM_LISTNODE (ListNode, CALLBACK_FN_ENTRY, Node);
659
660 FnTableEntry->CallbackFn(Guid,
661 (Guid == NULL) ? TokenNumber : ExTokenNumber,
662 Data,
663 Size);
664
665 ListNode = GetNextNode (ListHead, ListNode);
666 }
667
668 return;
669 }
670
671
672 /**
673 Wrapper function for setting non-pointer type value for a PCD entry.
674
675 @param TokenNumber Pcd token number autogenerated by build tools.
676 @param Data Value want to be set for PCD entry
677 @param Size Size of value.
678
679 @return status of SetWorker.
680
681 **/
682 EFI_STATUS
683 SetValueWorker (
684 IN UINTN TokenNumber,
685 IN VOID *Data,
686 IN UINTN Size
687 )
688 {
689 return SetWorker (TokenNumber, Data, &Size, FALSE);
690 }
691
692
693 /**
694 Set value for an PCD entry
695
696 @param TokenNumber Pcd token number autogenerated by build tools.
697 @param Data Value want to be set for PCD entry
698 @param Size Size of value.
699 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
700 If False, the type of PCD entry's value is not Pointer.
701
702 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
703 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
704 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
705 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
706 range of UINT8, UINT16, UINT32, UINT64
707 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
708 **/
709 EFI_STATUS
710 SetWorker (
711 IN UINTN TokenNumber,
712 IN VOID *Data,
713 IN OUT UINTN *Size,
714 IN BOOLEAN PtrType
715 )
716 {
717 UINT32 *LocalTokenNumberTable;
718 BOOLEAN IsPeiDb;
719 UINT32 LocalTokenNumber;
720 EFI_GUID *GuidTable;
721 UINT8 *StringTable;
722 EFI_GUID *Guid;
723 UINT16 *Name;
724 UINTN VariableOffset;
725 VOID *InternalData;
726 VARIABLE_HEAD *VariableHead;
727 UINTN Offset;
728 UINT8 *PcdDb;
729 EFI_STATUS Status;
730 UINTN MaxSize;
731 UINTN TmpTokenNumber;
732
733 //
734 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
735 // We have to decrement TokenNumber by 1 to make it usable
736 // as the array index.
737 //
738 TokenNumber--;
739
740 TmpTokenNumber = TokenNumber;
741
742 //
743 // EBC compiler is very choosy. It may report warning about comparison
744 // between UINTN and 0 . So we add 1 in each size of the
745 // comparison.
746 //
747 ASSERT (TokenNumber + 1 < PCD_TOTAL_TOKEN_NUMBER + 1);
748
749 if (PtrType) {
750 //
751 // Get MaxSize first, then check new size with max buffer size.
752 //
753 GetPtrTypeSize (TokenNumber, &MaxSize);
754 if (*Size > MaxSize) {
755 *Size = MaxSize;
756 return EFI_INVALID_PARAMETER;
757 }
758 } else {
759 if (*Size != DxePcdGetSize (TokenNumber + 1)) {
760 return EFI_INVALID_PARAMETER;
761 }
762 }
763
764 //
765 // EBC compiler is very choosy. It may report warning about comparison
766 // between UINTN and 0 . So we add 1 in each size of the
767 // comparison.
768 //
769 if ((TokenNumber + 1 < PEI_NEX_TOKEN_NUMBER + 1) ||
770 (TokenNumber + 1 >= PEI_LOCAL_TOKEN_NUMBER + 1 || TokenNumber + 1 < (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER + 1))) {
771 InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, *Size);
772 }
773
774 //
775 // Aquire lock to prevent reentrance from TPL_CALLBACK level
776 //
777 EfiAcquireLock (&mPcdDatabaseLock);
778
779 //
780 // EBC compiler is very choosy. It may report warning about comparison
781 // between UINTN and 0 . So we add 1 in each size of the
782 // comparison.
783 //
784 IsPeiDb = (BOOLEAN) ((TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1) ? TRUE : FALSE);
785
786 LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable :
787 mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
788
789 TokenNumber = IsPeiDb ? TokenNumber
790 : TokenNumber - PEI_LOCAL_TOKEN_NUMBER;
791
792 LocalTokenNumber = LocalTokenNumberTable[TokenNumber];
793
794 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
795 if (PtrType) {
796 GetPtrTypeSize (TmpTokenNumber, &MaxSize);
797 } else {
798 MaxSize = *Size;
799 }
800 LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, MaxSize, IsPeiDb);
801 }
802
803 Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
804
805 PcdDb = IsPeiDb ? ((UINT8 *) &mPcdDatabase->PeiDb) : ((UINT8 *) &mPcdDatabase->DxeDb);
806
807 if (IsPeiDb) {
808 StringTable = (UINT8 *) (&mPcdDatabase->PeiDb.Init.StringTable[0]);
809 } else {
810 StringTable = (UINT8 *) (&mPcdDatabase->DxeDb.Init.StringTable[0]);
811 }
812
813
814 InternalData = PcdDb + Offset;
815
816 switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
817 case PCD_TYPE_VPD:
818 ASSERT (FALSE);
819 Status = EFI_INVALID_PARAMETER;
820 break;
821
822 case PCD_TYPE_STRING:
823 if (SetPtrTypeSize (TmpTokenNumber, Size)) {
824 CopyMem (StringTable + *((STRING_HEAD *)InternalData), Data, *Size);
825 Status = EFI_SUCCESS;
826 } else {
827 Status = EFI_INVALID_PARAMETER;
828 }
829 break;
830
831 case PCD_TYPE_HII|PCD_TYPE_STRING:
832 case PCD_TYPE_HII:
833 if (PtrType) {
834 if (!SetPtrTypeSize (TmpTokenNumber, Size)) {
835 Status = EFI_INVALID_PARAMETER;
836 break;
837 }
838 }
839
840 if (IsPeiDb) {
841 GuidTable = (EFI_GUID *) (&mPcdDatabase->PeiDb.Init.GuidTable[0]);
842 } else {
843 GuidTable = (EFI_GUID *) (&mPcdDatabase->DxeDb.Init.GuidTable[0]);
844 }
845
846 VariableHead = (VARIABLE_HEAD *) (PcdDb + Offset);
847
848 Guid = GuidTable + VariableHead->GuidTableIndex;
849 Name = (UINT16*) (StringTable + VariableHead->StringIndex);
850 VariableOffset = VariableHead->Offset;
851 Status = SetHiiVariable (Guid, Name, Data, *Size, VariableOffset);
852
853 if (EFI_NOT_FOUND == Status) {
854 if ((LocalTokenNumber & PCD_TYPE_ALL_SET) == (PCD_TYPE_HII|PCD_TYPE_STRING)) {
855 CopyMem (
856 StringTable + *(STRING_HEAD *)(PcdDb + VariableHead->DefaultValueOffset),
857 Data,
858 *Size
859 );
860 } else {
861 CopyMem (PcdDb + VariableHead->DefaultValueOffset, Data, *Size);
862 }
863 Status = EFI_SUCCESS;
864 }
865 break;
866
867 case PCD_TYPE_DATA:
868 if (PtrType) {
869 if (SetPtrTypeSize (TmpTokenNumber, Size)) {
870 CopyMem (InternalData, Data, *Size);
871 Status = EFI_SUCCESS;
872 } else {
873 Status = EFI_INVALID_PARAMETER;
874 }
875 break;
876 }
877
878 Status = EFI_SUCCESS;
879 switch (*Size) {
880 case sizeof(UINT8):
881 *((UINT8 *) InternalData) = *((UINT8 *) Data);
882 break;
883
884 case sizeof(UINT16):
885 *((UINT16 *) InternalData) = *((UINT16 *) Data);
886 break;
887
888 case sizeof(UINT32):
889 *((UINT32 *) InternalData) = *((UINT32 *) Data);
890 break;
891
892 case sizeof(UINT64):
893 *((UINT64 *) InternalData) = *((UINT64 *) Data);
894 break;
895
896 default:
897 ASSERT (FALSE);
898 Status = EFI_NOT_FOUND;
899 break;
900 }
901 break;
902
903 default:
904 ASSERT (FALSE);
905 Status = EFI_NOT_FOUND;
906 break;
907 }
908
909 EfiReleaseLock (&mPcdDatabaseLock);
910
911 return Status;
912 }
913
914 /**
915 Wrapper function for get PCD value for dynamic-ex PCD.
916
917 @param Guid Token space guid for dynamic-ex PCD.
918 @param ExTokenNumber Token number for dynamic-ex PCD.
919 @param GetSize The size of dynamic-ex PCD value.
920
921 @return PCD entry in PCD database.
922
923 **/
924 VOID *
925 ExGetWorker (
926 IN CONST EFI_GUID *Guid,
927 IN UINTN ExTokenNumber,
928 IN UINTN GetSize
929 )
930 {
931 return GetWorker(GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber), GetSize);
932 }
933
934 /**
935 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
936
937 @param ExTokenNumber Token number for dynamic-ex PCD.
938 @param Guid Token space guid for dynamic-ex PCD.
939 @param Data Value want to be set.
940 @param SetSize The size of value.
941
942 @return status of ExSetWorker().
943
944 **/
945 EFI_STATUS
946 ExSetValueWorker (
947 IN UINTN ExTokenNumber,
948 IN CONST EFI_GUID *Guid,
949 IN VOID *Data,
950 IN UINTN SetSize
951 )
952 {
953 return ExSetWorker (ExTokenNumber, Guid, Data, &SetSize, FALSE);
954 }
955
956 /**
957 Set value for a dynamic PCD entry.
958
959 This routine find the local token number according to dynamic-ex PCD's token
960 space guid and token number firstly, and invoke callback function if this PCD
961 entry registered callback function. Finally, invoken general SetWorker to set
962 PCD value.
963
964 @param ExTokenNumber Dynamic-ex PCD token number.
965 @param Guid Token space guid for dynamic-ex PCD.
966 @param Data PCD value want to be set
967 @param SetSize Size of value.
968 @param PtrType If TRUE, this PCD entry is pointer type.
969 If FALSE, this PCD entry is not pointer type.
970
971 @return status of SetWorker().
972
973 **/
974 EFI_STATUS
975 ExSetWorker (
976 IN UINTN ExTokenNumber,
977 IN CONST EFI_GUID *Guid,
978 IN VOID *Data,
979 IN OUT UINTN *SetSize,
980 IN BOOLEAN PtrType
981 )
982 {
983 UINTN TokenNumber;
984
985 TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber);
986
987 InvokeCallbackOnSet ((UINT32) ExTokenNumber, Guid, TokenNumber, Data, *SetSize);
988
989 return SetWorker (TokenNumber, Data, SetSize, PtrType);
990
991 }
992
993 /**
994 Set value for HII-type PCD.
995
996 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
997 HII-type PCD is to visit this variable.
998
999 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
1000 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
1001 @param Data Value want to be set.
1002 @param DataSize Size of value
1003 @param Offset Value offset of HII-type PCD in variable.
1004
1005 @return status of GetVariable()/SetVariable().
1006
1007 **/
1008 EFI_STATUS
1009 SetHiiVariable (
1010 IN EFI_GUID *VariableGuid,
1011 IN UINT16 *VariableName,
1012 IN CONST VOID *Data,
1013 IN UINTN DataSize,
1014 IN UINTN Offset
1015 )
1016 {
1017 UINTN Size;
1018 VOID *Buffer;
1019 EFI_STATUS Status;
1020 UINT32 Attribute;
1021 UINTN SetSize;
1022
1023 Size = 0;
1024 SetSize = 0;
1025
1026 //
1027 // Try to get original variable size information.
1028 //
1029 Status = gRT->GetVariable (
1030 (UINT16 *)VariableName,
1031 VariableGuid,
1032 NULL,
1033 &Size,
1034 NULL
1035 );
1036
1037 if (Status == EFI_BUFFER_TOO_SMALL) {
1038 //
1039 // Patch new PCD's value to offset in given HII variable.
1040 //
1041 if (Size >= (DataSize + Offset)) {
1042 SetSize = Size;
1043 } else {
1044 SetSize = DataSize + Offset;
1045 }
1046 Buffer = AllocatePool (SetSize);
1047 ASSERT (Buffer != NULL);
1048
1049 Status = gRT->GetVariable (
1050 VariableName,
1051 VariableGuid,
1052 &Attribute,
1053 &Size,
1054 Buffer
1055 );
1056
1057 ASSERT_EFI_ERROR (Status);
1058
1059 CopyMem ((UINT8 *)Buffer + Offset, Data, DataSize);
1060
1061 Status = gRT->SetVariable (
1062 VariableName,
1063 VariableGuid,
1064 Attribute,
1065 SetSize,
1066 Buffer
1067 );
1068
1069 FreePool (Buffer);
1070 return Status;
1071 } else if (Status == EFI_NOT_FOUND) {
1072 //
1073 // If variable does not exist, a new variable need to be created.
1074 //
1075
1076 Size = Offset + DataSize;
1077
1078 Buffer = AllocateZeroPool (Size);
1079 ASSERT (Buffer != NULL);
1080
1081 CopyMem ((UINT8 *)Buffer + Offset, Data, DataSize);
1082
1083 Status = gRT->SetVariable (
1084 VariableName,
1085 VariableGuid,
1086 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
1087 Size,
1088 Buffer
1089 );
1090
1091 FreePool (Buffer);
1092 return Status;
1093 }
1094
1095 //
1096 // If we drop to here, the value is failed to be written in to variable area
1097 // So, we will save the data in the PCD Database's volatile area.
1098 //
1099 return Status;
1100 }
1101
1102 /**
1103 Get local token number according to dynamic-ex PCD's {token space guid:token number}
1104
1105 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1106 in DEC file. PCD database maintain a mapping table that translate pair of {token
1107 space guid: token number} to local token number.
1108
1109 @param Guid Token space guid for dynamic-ex PCD entry.
1110 @param ExTokenNumber Dynamic-ex PCD token number.
1111
1112 @return local token number for dynamic-ex PCD.
1113
1114 **/
1115 UINTN
1116 GetExPcdTokenNumber (
1117 IN CONST EFI_GUID *Guid,
1118 IN UINT32 ExTokenNumber
1119 )
1120 {
1121 UINT32 Index;
1122 DYNAMICEX_MAPPING *ExMap;
1123 EFI_GUID *GuidTable;
1124 EFI_GUID *MatchGuid;
1125 UINTN MatchGuidIdx;
1126
1127 if (!PEI_DATABASE_EMPTY) {
1128 ExMap = mPcdDatabase->PeiDb.Init.ExMapTable;
1129 GuidTable = mPcdDatabase->PeiDb.Init.GuidTable;
1130
1131 MatchGuid = ScanGuid (GuidTable, sizeof(mPcdDatabase->PeiDb.Init.GuidTable), Guid);
1132
1133 if (MatchGuid != NULL) {
1134
1135 MatchGuidIdx = MatchGuid - GuidTable;
1136
1137 for (Index = 0; Index < PEI_EXMAPPING_TABLE_SIZE; Index++) {
1138 if ((ExTokenNumber == ExMap[Index].ExTokenNumber) &&
1139 (MatchGuidIdx == ExMap[Index].ExGuidIndex)) {
1140 return ExMap[Index].LocalTokenNumber;
1141 }
1142 }
1143 }
1144 }
1145
1146 ExMap = mPcdDatabase->DxeDb.Init.ExMapTable;
1147 GuidTable = mPcdDatabase->DxeDb.Init.GuidTable;
1148
1149 MatchGuid = ScanGuid (GuidTable, sizeof(mPcdDatabase->DxeDb.Init.GuidTable), Guid);
1150 //
1151 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1152 // error in the BUILD system.
1153 //
1154 ASSERT (MatchGuid != NULL);
1155
1156 MatchGuidIdx = MatchGuid - GuidTable;
1157
1158 for (Index = 0; Index < DXE_EXMAPPING_TABLE_SIZE; Index++) {
1159 if ((ExTokenNumber == ExMap[Index].ExTokenNumber) &&
1160 (MatchGuidIdx == ExMap[Index].ExGuidIndex)) {
1161 return ExMap[Index].LocalTokenNumber;
1162 }
1163 }
1164
1165 ASSERT (FALSE);
1166
1167 return 0;
1168 }
1169
1170 /**
1171 Get SKU ID table from PCD database.
1172
1173 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1174 @param IsPeiPcd If TRUE,
1175
1176 @return Pointer to SKU ID array table
1177
1178 **/
1179 SKU_ID *
1180 GetSkuIdArray (
1181 IN UINTN LocalTokenNumberTableIdx,
1182 IN BOOLEAN IsPeiPcd
1183 )
1184 {
1185 SKU_HEAD *SkuHead;
1186 UINTN LocalTokenNumber;
1187 UINT8 *Database;
1188
1189 if (IsPeiPcd) {
1190 LocalTokenNumber = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];
1191 Database = (UINT8 *) &mPcdDatabase->PeiDb;
1192 } else {
1193 LocalTokenNumber = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable[LocalTokenNumberTableIdx - PEI_LOCAL_TOKEN_NUMBER];
1194 Database = (UINT8 *) &mPcdDatabase->DxeDb;
1195 }
1196
1197 ASSERT ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) != 0);
1198
1199 SkuHead = (SKU_HEAD *) ((UINT8 *)Database + (LocalTokenNumber & PCD_DATABASE_OFFSET_MASK));
1200
1201 return (SKU_ID *) (Database + SkuHead->SkuIdTableOffset);
1202
1203 }
1204
1205 /**
1206 Wrapper function of getting index of PCD entry in size table.
1207
1208 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1209 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1210 If FALSE, the pcd entry is initialized in DXE phase.
1211
1212 @return index of PCD entry in size table.
1213 **/
1214 UINTN
1215 GetSizeTableIndex (
1216 IN UINTN LocalTokenNumberTableIdx,
1217 IN BOOLEAN IsPeiDb
1218 )
1219 {
1220 UINT32 *LocalTokenNumberTable;
1221 UINTN LocalTokenNumber;
1222 UINTN Index;
1223 UINTN SizeTableIdx;
1224 SKU_ID *SkuIdTable;
1225
1226 if (IsPeiDb) {
1227 LocalTokenNumberTable = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable;
1228 } else {
1229 LocalTokenNumberTable = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
1230 }
1231
1232 SizeTableIdx = 0;
1233
1234 for (Index = 0; Index < LocalTokenNumberTableIdx; Index ++) {
1235 LocalTokenNumber = LocalTokenNumberTable[Index];
1236
1237 if ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER) {
1238 //
1239 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1240 // PCD entry.
1241 //
1242 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1243 //
1244 // We have only one entry for VPD enabled PCD entry:
1245 // 1) MAX Size.
1246 // We consider current size is equal to MAX size.
1247 //
1248 SizeTableIdx++;
1249 } else {
1250 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
1251 //
1252 // We have only two entry for Non-Sku enabled PCD entry:
1253 // 1) MAX SIZE
1254 // 2) Current Size
1255 //
1256 SizeTableIdx += 2;
1257 } else {
1258 //
1259 // We have these entry for SKU enabled PCD entry
1260 // 1) MAX SIZE
1261 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1262 //
1263 SkuIdTable = GetSkuIdArray (Index, IsPeiDb);
1264 SizeTableIdx += (UINTN)*SkuIdTable + 1;
1265 }
1266 }
1267 }
1268
1269 }
1270
1271 return SizeTableIdx;
1272 }
1273
1274 /**
1275 Get size of POINTER type PCD value.
1276
1277 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1278 @param MaxSize Maxmium size of POINTER type PCD value.
1279
1280 @return size of POINTER type PCD value.
1281
1282 **/
1283 UINTN
1284 GetPtrTypeSize (
1285 IN UINTN LocalTokenNumberTableIdx,
1286 OUT UINTN *MaxSize
1287 )
1288 {
1289 INTN SizeTableIdx;
1290 UINTN LocalTokenNumber;
1291 SKU_ID *SkuIdTable;
1292 SIZE_INFO *SizeTable;
1293 UINTN Index;
1294 BOOLEAN IsPeiDb;
1295 UINT32 *LocalTokenNumberTable;
1296
1297 // EBC compiler is very choosy. It may report warning about comparison
1298 // between UINTN and 0 . So we add 1 in each size of the
1299 // comparison.
1300 IsPeiDb = (BOOLEAN) (LocalTokenNumberTableIdx + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
1301
1302
1303 if (IsPeiDb) {
1304 LocalTokenNumberTable = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable;
1305 SizeTable = mPcdDatabase->PeiDb.Init.SizeTable;
1306 } else {
1307 LocalTokenNumberTableIdx -= PEI_LOCAL_TOKEN_NUMBER;
1308 LocalTokenNumberTable = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
1309 SizeTable = mPcdDatabase->DxeDb.Init.SizeTable;
1310 }
1311
1312 LocalTokenNumber = LocalTokenNumberTable[LocalTokenNumberTableIdx];
1313
1314 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
1315
1316 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, IsPeiDb);
1317
1318 *MaxSize = SizeTable[SizeTableIdx];
1319 //
1320 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1321 // PCD entry.
1322 //
1323 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1324 //
1325 // We have only one entry for VPD enabled PCD entry:
1326 // 1) MAX Size.
1327 // We consider current size is equal to MAX size.
1328 //
1329 return *MaxSize;
1330 } else {
1331 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
1332 //
1333 // We have only two entry for Non-Sku enabled PCD entry:
1334 // 1) MAX SIZE
1335 // 2) Current Size
1336 //
1337 return SizeTable[SizeTableIdx + 1];
1338 } else {
1339 //
1340 // We have these entry for SKU enabled PCD entry
1341 // 1) MAX SIZE
1342 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1343 //
1344 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, IsPeiDb);
1345 for (Index = 0; Index < SkuIdTable[0]; Index++) {
1346 if (SkuIdTable[1 + Index] == mPcdDatabase->PeiDb.Init.SystemSkuId) {
1347 return SizeTable[SizeTableIdx + 1 + Index];
1348 }
1349 }
1350 return SizeTable[SizeTableIdx + 1];
1351 }
1352 }
1353 }
1354
1355 /**
1356 Set size of POINTER type PCD value. The size should not exceed the maximum size
1357 of this PCD value.
1358
1359 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1360 @param CurrentSize Size of POINTER type PCD value.
1361
1362 @retval TRUE Success to set size of PCD value.
1363 @retval FALSE Fail to set size of PCD value.
1364 **/
1365 BOOLEAN
1366 SetPtrTypeSize (
1367 IN UINTN LocalTokenNumberTableIdx,
1368 IN OUT UINTN *CurrentSize
1369 )
1370 {
1371 INTN SizeTableIdx;
1372 UINTN LocalTokenNumber;
1373 SKU_ID *SkuIdTable;
1374 SIZE_INFO *SizeTable;
1375 UINTN Index;
1376 UINTN MaxSize;
1377 BOOLEAN IsPeiDb;
1378 UINT32 *LocalTokenNumberTable;
1379
1380 //
1381 // EBC compiler is very choosy. It may report warning about comparison
1382 // between UINTN and 0 . So we add 1 in each size of the
1383 // comparison.
1384 //
1385 IsPeiDb = (BOOLEAN) (LocalTokenNumberTableIdx + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
1386
1387 if (IsPeiDb) {
1388 LocalTokenNumberTable = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable;
1389 SizeTable = mPcdDatabase->PeiDb.Init.SizeTable;
1390 } else {
1391 LocalTokenNumberTableIdx -= PEI_LOCAL_TOKEN_NUMBER;
1392 LocalTokenNumberTable = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
1393 SizeTable = mPcdDatabase->DxeDb.Init.SizeTable;
1394 }
1395
1396 LocalTokenNumber = LocalTokenNumberTable[LocalTokenNumberTableIdx];
1397
1398 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
1399
1400 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, IsPeiDb);
1401
1402 MaxSize = SizeTable[SizeTableIdx];
1403 //
1404 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1405 // PCD entry.
1406 //
1407 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
1408 //
1409 // We shouldn't come here as we don't support SET for VPD
1410 //
1411 ASSERT (FALSE);
1412 return FALSE;
1413 } else {
1414 if ((*CurrentSize > MaxSize) ||
1415 (*CurrentSize == MAX_ADDRESS)) {
1416 *CurrentSize = MaxSize;
1417 return FALSE;
1418 }
1419
1420 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
1421 //
1422 // We have only two entry for Non-Sku enabled PCD entry:
1423 // 1) MAX SIZE
1424 // 2) Current Size
1425 //
1426 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
1427 return TRUE;
1428 } else {
1429 //
1430 // We have these entry for SKU enabled PCD entry
1431 // 1) MAX SIZE
1432 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1433 //
1434 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, IsPeiDb);
1435 for (Index = 0; Index < SkuIdTable[0]; Index++) {
1436 if (SkuIdTable[1 + Index] == mPcdDatabase->PeiDb.Init.SystemSkuId) {
1437 SizeTable[SizeTableIdx + 1 + Index] = (SIZE_INFO) *CurrentSize;
1438 return TRUE;
1439 }
1440 }
1441 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
1442 return TRUE;
1443 }
1444 }
1445 }