Add in support for GetNextTokenNumber API.
[mirror_edk2.git] / EdkModulePkg / Universal / PCD / Dxe / Service.c
CommitLineData
878ddf1f 1/** @file\r
2Private functions used by PCD DXE driver.s\r
3\r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13\r
14Module Name: Service.c\r
15\r
16**/\r
878ddf1f 17#include "Service.h"\r
18\r
878ddf1f 19\r
52e1905d 20//\r
21// Build Tool will generate DXE_PCD_DB_INIT_VALUE in Autogen.h\r
22// Compression Algorithm will take care of the size optimization.\r
23//\r
878ddf1f 24\r
4c114006 25PCD_DATABASE * mPcdDatabase;\r
878ddf1f 26\r
4c114006 27LIST_ENTRY mCallbackFnTable[PCD_TOTAL_TOKEN_NUMBER];\r
878ddf1f 28\r
52e1905d 29VOID *\r
30GetWorkerByLocalTokenNumber (\r
31 UINT32 LocalTokenNumber,\r
32 BOOLEAN IsPeiDb,\r
33 UINTN Size\r
34 ) \r
878ddf1f 35{\r
52e1905d 36 UINT32 Offset;\r
37 EFI_GUID *GuidTable;\r
38 UINT16 *StringTable;\r
39 EFI_GUID *Guid;\r
40 UINT16 *Name;\r
41 VARIABLE_HEAD *VariableHead;\r
42 EFI_STATUS Status;\r
43 UINTN DataSize;\r
44 VOID *Data;\r
45 VPD_HEAD *VpdHead;\r
46 UINT8 *PcdDb;\r
47 UINT16 StringTableIdx; \r
48\r
49 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {\r
50 LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size, IsPeiDb);\r
51 }\r
52\r
4c114006 53 PcdDb = IsPeiDb ? ((UINT8 *) &mPcdDatabase->PeiDb) : ((UINT8 *) &mPcdDatabase->DxeDb);\r
54 StringTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.StringTable :\r
55 mPcdDatabase->DxeDb.Init.StringTable;\r
52e1905d 56 \r
57 Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;\r
58 \r
59 switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {\r
60 case PCD_TYPE_VPD:\r
61 VpdHead = (VPD_HEAD *) ((UINT8 *) PcdDb + Offset);\r
62 return (VOID *) (FixedPcdGet32(PcdVpdBaseAddress) + VpdHead->Offset);\r
63 \r
64 case PCD_TYPE_HII:\r
4c114006 65 GuidTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.GuidTable :\r
66 mPcdDatabase->DxeDb.Init.GuidTable;\r
52e1905d 67 \r
68 VariableHead = (VARIABLE_HEAD *) (PcdDb + Offset);\r
69 \r
70 Guid = &(GuidTable[VariableHead->GuidTableIndex]);\r
71 Name = &(StringTable[VariableHead->StringIndex]);\r
878ddf1f 72\r
52e1905d 73 Status = GetHiiVariable (Guid, Name, &Data, &DataSize);\r
74 ASSERT_EFI_ERROR (Status);\r
75 ASSERT (DataSize >= (UINTN) (VariableHead->Offset + Size));\r
878ddf1f 76\r
52e1905d 77 return (UINT8 *) Data + VariableHead->Offset;\r
878ddf1f 78\r
52e1905d 79 case PCD_TYPE_STRING:\r
80 StringTableIdx = (UINT16) *((UINT8 *) PcdDb + Offset);\r
81 return (VOID *) &StringTable[StringTableIdx];\r
878ddf1f 82\r
52e1905d 83 case PCD_TYPE_DATA:\r
84 return (VOID *) ((UINT8 *) PcdDb + Offset);\r
85 break;\r
878ddf1f 86\r
52e1905d 87 default:\r
88 ASSERT (FALSE);\r
89 break;\r
90 \r
91 }\r
878ddf1f 92\r
52e1905d 93 ASSERT (FALSE);\r
94 \r
95 return NULL;\r
96}\r
97 \r
98VOID *\r
99GetWorker (\r
100 UINTN TokenNumber\r
878ddf1f 101 )\r
102{\r
52e1905d 103 UINT32 *LocalTokenNumberTable;\r
104 UINT16 *SizeTable;\r
105 BOOLEAN IsPeiDb;\r
878ddf1f 106\r
52e1905d 107 ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);\r
108 \r
109 IsPeiDb = (TokenNumber <= PEI_LOCAL_TOKEN_NUMBER) ? TRUE : FALSE;\r
878ddf1f 110\r
4c114006 111 LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable : \r
112 mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;\r
878ddf1f 113\r
4c114006 114 SizeTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.SizeTable: \r
115 mPcdDatabase->DxeDb.Init.SizeTable;\r
878ddf1f 116\r
52e1905d 117 TokenNumber = IsPeiDb ? TokenNumber :\r
118 TokenNumber - PEI_LOCAL_TOKEN_NUMBER;\r
119 return GetWorkerByLocalTokenNumber (LocalTokenNumberTable[TokenNumber], IsPeiDb, SizeTable[TokenNumber]);\r
120}\r
878ddf1f 121\r
878ddf1f 122\r
123\r
52e1905d 124EFI_STATUS\r
125DxeRegisterCallBackWorker (\r
126 IN UINTN TokenNumber,\r
127 IN CONST GUID *Guid, OPTIONAL\r
4c114006 128 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
52e1905d 129)\r
130{\r
4c114006 131 CALLBACK_FN_ENTRY *FnTableEntry;\r
132 EX_PCD_ENTRY_ATTRIBUTE ExAttr;\r
133 LIST_ENTRY *ListHead;\r
134 LIST_ENTRY *ListNode;\r
135\r
136 if (Guid != NULL) {\r
137 GetExPcdTokenAttributes (Guid, TokenNumber, &ExAttr);\r
138 TokenNumber = ExAttr.LocalTokenNumberAlias;\r
139 }\r
140\r
141 ListHead = &mCallbackFnTable[TokenNumber];\r
142 ListNode = GetFirstNode (ListHead);\r
143\r
144 while (ListNode != ListHead) {\r
145 FnTableEntry = CR_FNENTRY_FROM_LISTNODE(ListNode, CALLBACK_FN_ENTRY, Node);\r
146\r
147 if (FnTableEntry->CallbackFn == CallBackFunction) {\r
148 //\r
149 // We only allow a Callback function to be register once\r
150 // for a TokenNumber. So just return EFI_SUCCESS\r
151 //\r
152 return EFI_SUCCESS;\r
153 }\r
154 ListNode = GetNextNode (ListHead, ListNode);\r
155 }\r
156\r
157 FnTableEntry = AllocatePool (sizeof(CALLBACK_FN_ENTRY));\r
158 ASSERT (FnTableEntry != NULL);\r
159\r
160 FnTableEntry->CallbackFn = CallBackFunction;\r
161 InsertTailList (ListHead, &FnTableEntry->Node);\r
52e1905d 162 \r
163 return EFI_SUCCESS;\r
878ddf1f 164}\r
165\r
166\r
4c114006 167\r
168\r
52e1905d 169EFI_STATUS\r
4c114006 170DxeUnRegisterCallBackWorker (\r
171 IN UINTN TokenNumber,\r
172 IN CONST GUID *Guid, OPTIONAL\r
173 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
174)\r
175{\r
176 CALLBACK_FN_ENTRY *FnTableEntry;\r
177 EX_PCD_ENTRY_ATTRIBUTE ExAttr;\r
178 LIST_ENTRY *ListHead;\r
179 LIST_ENTRY *ListNode;\r
180\r
181 if (Guid != NULL) {\r
182 GetExPcdTokenAttributes (Guid, TokenNumber, &ExAttr);\r
183 TokenNumber = ExAttr.LocalTokenNumberAlias;\r
184 }\r
185\r
186 ListHead = &mCallbackFnTable[TokenNumber];\r
187 ListNode = GetFirstNode (ListHead);\r
188\r
189 while (ListNode != ListHead) {\r
190 FnTableEntry = CR_FNENTRY_FROM_LISTNODE(ListNode, CALLBACK_FN_ENTRY, Node);\r
191\r
192 if (FnTableEntry->CallbackFn == CallBackFunction) {\r
193 //\r
194 // We only allow a Callback function to be register once\r
195 // for a TokenNumber. So we can safely remove the Node from\r
196 // the Link List and return EFI_SUCCESS.\r
197 //\r
198 RemoveEntryList (ListNode);\r
199 FreePool (FnTableEntry);\r
200 \r
201 return EFI_SUCCESS;\r
202 }\r
203 ListNode = GetNextNode (ListHead, ListNode);\r
204 }\r
205\r
206 return EFI_INVALID_PARAMETER;\r
207}\r
208\r
209\r
210\r
211PCD_TOKEN_NUMBER\r
212ExGetNextTokeNumber (\r
213 IN CONST EFI_GUID *Guid,\r
214 IN PCD_TOKEN_NUMBER TokenNumber,\r
215 IN EFI_GUID *GuidTable,\r
216 IN UINTN SizeOfGuidTable,\r
217 IN DYNAMICEX_MAPPING *ExMapTable,\r
218 IN UINTN SizeOfExMapTable\r
878ddf1f 219 )\r
220{\r
4c114006 221 EFI_GUID *MatchGuid;\r
222 UINTN Idx;\r
223 UINTN GuidTableIdx;\r
224 BOOLEAN Found;\r
225\r
226 MatchGuid = ScanGuid (GuidTable, SizeOfGuidTable, Guid);\r
227 if (MatchGuid == NULL) {\r
228 return PCD_INVALID_TOKEN_NUMBER;\r
229 }\r
230\r
231 Found = FALSE;\r
232 GuidTableIdx = MatchGuid - GuidTable;\r
233 for (Idx = 0; Idx < SizeOfExMapTable; Idx++) {\r
234 if (ExMapTable[Idx].ExGuidIndex == GuidTableIdx) {\r
235 Found = TRUE;\r
236 break;\r
237 }\r
238 }\r
239\r
240 if (Found) {\r
241 if (TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r
242 return ExMapTable[Idx].ExTokenNumber;\r
243 }\r
244 \r
245 for ( ; Idx < SizeOfExMapTable; Idx++) {\r
246 if (ExMapTable[Idx].ExTokenNumber == TokenNumber) {\r
247 Idx++;\r
248 if (Idx == SizeOfExMapTable) {\r
249 //\r
250 // Exceed the length of ExMap Table\r
251 //\r
252 return PCD_INVALID_TOKEN_NUMBER;\r
253 } else if (ExMapTable[Idx].ExGuidIndex == GuidTableIdx) {\r
254 //\r
255 // Found the next match\r
256 //\r
257 return ExMapTable[Idx].ExTokenNumber;\r
258 } else {\r
259 //\r
260 // Guid has been changed. It is the next Token Space Guid.\r
261 // We should flag no more TokenNumber.\r
262 //\r
263 return PCD_INVALID_TOKEN_NUMBER;\r
264 }\r
265 }\r
266 }\r
267 }\r
268 \r
269 return PCD_INVALID_TOKEN_NUMBER;\r
878ddf1f 270}\r
4c114006 271 \r
878ddf1f 272\r
273\r
274\r
52e1905d 275VOID\r
276BuildPcdDxeDataBase (\r
277 VOID\r
278)\r
878ddf1f 279{\r
52e1905d 280 PEI_PCD_DATABASE *PeiDatabase;\r
281 EFI_HOB_GUID_TYPE *GuidHob;\r
4c114006 282 UINTN Idx;\r
878ddf1f 283\r
4c114006 284 mPcdDatabase = AllocateZeroPool (sizeof(PCD_DATABASE));\r
285 ASSERT (mPcdDatabase != NULL);\r
878ddf1f 286\r
52e1905d 287 GuidHob = GetFirstGuidHob (&gPcdDataBaseHobGuid);\r
288 ASSERT (GuidHob != NULL);\r
878ddf1f 289\r
52e1905d 290 PeiDatabase = (PEI_PCD_DATABASE *) GET_GUID_HOB_DATA (GuidHob);\r
291 //\r
292 // Copy PCD Entries refereneced in PEI phase to PCD DATABASE\r
293 //\r
4c114006 294 CopyMem (&mPcdDatabase->PeiDb, PeiDatabase, sizeof (PEI_PCD_DATABASE));\r
52e1905d 295\r
296 //\r
297 // Copy PCD Entries with default value to PCD DATABASE\r
298 //\r
4c114006 299 CopyMem (&mPcdDatabase->DxeDb.Init, &gDXEPcdDbInit, sizeof(DXE_PCD_DATABASE_INIT));\r
300\r
301\r
302 //\r
303 // Initialized the Callback Function Table\r
304 //\r
305 for (Idx = 0; Idx < PCD_TOTAL_TOKEN_NUMBER; Idx++) {\r
306 InitializeListHead (&mCallbackFnTable[Idx]);\r
307 }\r
52e1905d 308 \r
309 return;\r
878ddf1f 310}\r
311\r
312\r
313\r
52e1905d 314EFI_STATUS\r
315GetHiiVariable (\r
316 IN EFI_GUID *VariableGuid,\r
317 IN UINT16 *VariableName,\r
318 OUT VOID ** VariableData,\r
319 OUT UINTN *VariableSize\r
878ddf1f 320 )\r
321{\r
52e1905d 322 UINTN Size;\r
323 EFI_STATUS Status;\r
324 VOID *Buffer;\r
878ddf1f 325\r
52e1905d 326 Status = EfiGetVariable (\r
327 (UINT16 *)VariableName,\r
328 VariableGuid,\r
329 NULL,\r
330 &Size,\r
331 NULL\r
332 );\r
333 ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
878ddf1f 334\r
52e1905d 335 Buffer = AllocatePool (Size);\r
878ddf1f 336\r
52e1905d 337 ASSERT (Buffer != NULL);\r
878ddf1f 338\r
52e1905d 339 Status = EfiGetVariable (\r
340 VariableName,\r
341 VariableGuid,\r
342 NULL,\r
343 &Size,\r
344 Buffer\r
345 );\r
878ddf1f 346\r
52e1905d 347 return Status;\r
878ddf1f 348\r
878ddf1f 349}\r
350\r
351\r
52e1905d 352UINT32\r
353GetSkuEnabledTokenNumber (\r
354 UINT32 LocalTokenNumber,\r
355 UINTN Size,\r
356 BOOLEAN IsPeiDb\r
357 ) \r
358{\r
359 SKU_HEAD *SkuHead;\r
360 SKU_ID *SkuIdTable;\r
361 INTN i;\r
362 UINT8 *Value;\r
363 SKU_ID *PhaseSkuIdTable;\r
364 UINT8 *PcdDb;\r
878ddf1f 365\r
52e1905d 366 ASSERT ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0);\r
878ddf1f 367\r
4c114006 368 PcdDb = IsPeiDb ? (UINT8 *) &mPcdDatabase->PeiDb : (UINT8 *) &mPcdDatabase->DxeDb;\r
878ddf1f 369\r
52e1905d 370 SkuHead = (SKU_HEAD *) (PcdDb + (LocalTokenNumber & PCD_DATABASE_OFFSET_MASK));\r
371 Value = (UINT8 *) (PcdDb + SkuHead->SkuDataStartOffset); \r
878ddf1f 372\r
4c114006 373 PhaseSkuIdTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.SkuIdTable :\r
374 mPcdDatabase->DxeDb.Init.SkuIdTable;\r
52e1905d 375 \r
376 SkuIdTable = &PhaseSkuIdTable[SkuHead->SkuIdTableOffset];\r
377 \r
378 for (i = 0; i < SkuIdTable[0]; i++) {\r
4c114006 379 if (mPcdDatabase->PeiDb.Init.SystemSkuId == SkuIdTable[i + 1]) {\r
52e1905d 380 break;\r
878ddf1f 381 }\r
878ddf1f 382 }\r
52e1905d 383 ASSERT (i < SkuIdTable[0]);\r
878ddf1f 384\r
52e1905d 385 switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {\r
386 case PCD_TYPE_VPD:\r
387 Value = (UINT8 *) &(((VPD_HEAD *) Value)[i]);\r
388 return ((Value - PcdDb) | PCD_TYPE_VPD);\r
878ddf1f 389\r
52e1905d 390 case PCD_TYPE_HII:\r
391 Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[i]);\r
392 return ((Value - PcdDb) | PCD_TYPE_HII);\r
393 \r
394 case PCD_TYPE_DATA:\r
395 Value += Size * i;\r
396 return (Value - PcdDb);\r
397 \r
398 default:\r
399 ASSERT (FALSE);\r
400 }\r
401\r
402 ASSERT (FALSE);\r
403\r
404 return 0;\r
878ddf1f 405 \r
406}\r
407\r
878ddf1f 408\r
878ddf1f 409\r
878ddf1f 410\r
878ddf1f 411\r
52e1905d 412VOID\r
413InvokeCallbackOnSet (\r
414 UINT32 ExTokenNumber,\r
415 CONST EFI_GUID *Guid, OPTIONAL\r
416 UINTN TokenNumber,\r
417 VOID *Data,\r
418 UINTN Size\r
419 )\r
420{\r
4c114006 421 CALLBACK_FN_ENTRY *FnTableEntry;\r
422 LIST_ENTRY *ListHead;\r
423 LIST_ENTRY *ListNode;\r
424\r
425 ListHead = &mCallbackFnTable[TokenNumber];\r
426 ListNode = GetFirstNode (ListHead);\r
427\r
428 while (ListNode != ListHead) {\r
429 FnTableEntry = CR_FNENTRY_FROM_LISTNODE(ListNode, CALLBACK_FN_ENTRY, Node);\r
430\r
431 FnTableEntry->CallbackFn(Guid, \r
432 (Guid == NULL) ? TokenNumber : ExTokenNumber,\r
433 Data,\r
434 Size);\r
435 \r
436 ListNode = GetNextNode (ListHead, ListNode);\r
437 }\r
438 \r
52e1905d 439 return;\r
878ddf1f 440}\r
441\r
442\r
443\r
52e1905d 444\r
878ddf1f 445EFI_STATUS\r
52e1905d 446SetWorker (\r
0653eb89 447 PCD_TOKEN_NUMBER TokenNumber,\r
448 VOID *Data,\r
449 UINTN Size,\r
450 BOOLEAN PtrType\r
878ddf1f 451 )\r
452{\r
52e1905d 453 UINT32 *LocalTokenNumberTable;\r
454 BOOLEAN IsPeiDb;\r
878ddf1f 455\r
878ddf1f 456\r
52e1905d 457 ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);\r
878ddf1f 458\r
52e1905d 459 if (PtrType) {\r
460 ASSERT (Size <= DxePcdGetSize (TokenNumber));\r
461 } else {\r
462 ASSERT (Size == DxePcdGetSize (TokenNumber));\r
878ddf1f 463 }\r
878ddf1f 464 \r
52e1905d 465 IsPeiDb = (TokenNumber <= PEI_LOCAL_TOKEN_NUMBER) ? TRUE : FALSE;\r
878ddf1f 466\r
4c114006 467 LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable : \r
468 mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;\r
878ddf1f 469\r
0653eb89 470 InvokeCallbackOnSet (0, NULL, TokenNumber, Data, Size);\r
471\r
52e1905d 472 TokenNumber = IsPeiDb ? TokenNumber\r
473 : TokenNumber - PEI_LOCAL_TOKEN_NUMBER;\r
878ddf1f 474 \r
52e1905d 475 return SetWorkerByLocalTokenNumber (LocalTokenNumberTable[TokenNumber], Data, Size, PtrType, IsPeiDb);\r
878ddf1f 476\r
52e1905d 477}\r
878ddf1f 478\r
878ddf1f 479\r
878ddf1f 480\r
481\r
482\r
52e1905d 483VOID *\r
484ExGetWorker (\r
485 IN CONST EFI_GUID *Guid,\r
486 IN UINTN ExTokenNumber,\r
487 IN UINTN GetSize\r
488 ) \r
878ddf1f 489{\r
52e1905d 490 EX_PCD_ENTRY_ATTRIBUTE Attr;\r
878ddf1f 491\r
52e1905d 492 GetExPcdTokenAttributes (Guid, ExTokenNumber, &Attr);\r
878ddf1f 493\r
52e1905d 494 ASSERT ((GetSize == Attr.Size) || (GetSize == 0));\r
878ddf1f 495\r
52e1905d 496 return GetWorkerByLocalTokenNumber (Attr.LocalTokenNumberAlias,\r
497 Attr.IsPeiDb,\r
498 Attr.Size\r
499 );\r
878ddf1f 500}\r
501\r
502\r
503\r
52e1905d 504\r
505\r
878ddf1f 506EFI_STATUS\r
52e1905d 507ExSetWorker (\r
0653eb89 508 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
52e1905d 509 IN CONST EFI_GUID *Guid,\r
510 VOID *Data,\r
511 UINTN SetSize,\r
512 BOOLEAN PtrType\r
878ddf1f 513 )\r
514{\r
52e1905d 515 EX_PCD_ENTRY_ATTRIBUTE Attr;\r
878ddf1f 516\r
52e1905d 517 GetExPcdTokenAttributes (Guid, ExTokenNumber, &Attr);\r
878ddf1f 518\r
52e1905d 519 ASSERT (!PtrType && (SetSize == Attr.Size));\r
878ddf1f 520\r
52e1905d 521 ASSERT (PtrType && (SetSize <= Attr.Size));\r
878ddf1f 522\r
52e1905d 523 InvokeCallbackOnSet (ExTokenNumber, Guid, Attr.TokenNumber, Data, Attr.Size);\r
878ddf1f 524\r
52e1905d 525 SetWorkerByLocalTokenNumber (Attr.LocalTokenNumberAlias, Data, Attr.Size, PtrType, Attr.IsPeiDb);\r
878ddf1f 526\r
52e1905d 527 return EFI_SUCCESS;\r
528 \r
529}\r
878ddf1f 530\r
878ddf1f 531\r
878ddf1f 532\r
878ddf1f 533\r
52e1905d 534EFI_STATUS\r
535SetWorkerByLocalTokenNumber (\r
536 UINT32 LocalTokenNumber,\r
537 VOID *Data,\r
538 UINTN Size,\r
539 BOOLEAN PtrType,\r
540 BOOLEAN IsPeiDb\r
541 )\r
542{\r
543 EFI_GUID *GuidTable;\r
544 UINT16 *StringTable;\r
545 EFI_GUID *Guid;\r
546 UINT16 *Name;\r
547 VOID *InternalData;\r
548 VARIABLE_HEAD *VariableHead;\r
549 UINTN Offset;\r
550 UINT8 *PcdDb;\r
551\r
552\r
553 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {\r
554 LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size, IsPeiDb);\r
555 }\r
878ddf1f 556\r
52e1905d 557 Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;\r
878ddf1f 558\r
4c114006 559 PcdDb = IsPeiDb ? ((UINT8 *) &mPcdDatabase->PeiDb) : ((UINT8 *) &mPcdDatabase->DxeDb);\r
878ddf1f 560\r
4c114006 561 StringTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.StringTable :\r
562 mPcdDatabase->DxeDb.Init.StringTable;\r
52e1905d 563 \r
564 InternalData = PcdDb + Offset;\r
878ddf1f 565\r
52e1905d 566 switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {\r
567 case PCD_TYPE_VPD:\r
568 ASSERT (FALSE);\r
569 return EFI_INVALID_PARAMETER;\r
570 \r
571 case PCD_TYPE_STRING:\r
572 CopyMem (&StringTable[*((UINT16 *)InternalData)], Data, Size);\r
573 break;\r
878ddf1f 574\r
52e1905d 575 case PCD_TYPE_HII:\r
576 //\r
577 // Bug Bug: Please implement this\r
578 //\r
4c114006 579 GuidTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.GuidTable :\r
580 mPcdDatabase->DxeDb.Init.GuidTable;\r
52e1905d 581 \r
582 VariableHead = (VARIABLE_HEAD *) (PcdDb + Offset);\r
583 \r
584 Guid = &(GuidTable[VariableHead->GuidTableIndex]);\r
585 Name = &(StringTable[VariableHead->StringIndex]);\r
878ddf1f 586\r
52e1905d 587 return EFI_SUCCESS;\r
878ddf1f 588\r
52e1905d 589 case PCD_TYPE_DATA:\r
590 if (PtrType) {\r
591 CopyMem (InternalData, Data, Size);\r
592 return EFI_SUCCESS;\r
593 }\r
878ddf1f 594\r
52e1905d 595 switch (Size) {\r
596 case sizeof(UINT8):\r
597 *((UINT8 *) InternalData) = *((UINT8 *) Data);\r
598 return EFI_SUCCESS;\r
878ddf1f 599\r
52e1905d 600 case sizeof(UINT16):\r
601 *((UINT16 *) InternalData) = *((UINT16 *) Data);\r
602 return EFI_SUCCESS;\r
603\r
604 case sizeof(UINT32):\r
605 *((UINT32 *) InternalData) = *((UINT32 *) Data);\r
606 return EFI_SUCCESS;\r
607\r
608 case sizeof(UINT64):\r
609 *((UINT64 *) InternalData) = *((UINT64 *) Data);\r
610 return EFI_SUCCESS;\r
878ddf1f 611\r
52e1905d 612 default:\r
613 ASSERT (FALSE);\r
614 return EFI_NOT_FOUND;\r
615 }\r
616\r
617 default:\r
618 ASSERT (FALSE);\r
619 break;\r
620 }\r
621 \r
622 ASSERT (FALSE);\r
623 return EFI_NOT_FOUND;\r
878ddf1f 624}\r
625\r
626\r
627\r
628EFI_STATUS\r
629SetHiiVariable (\r
630 IN EFI_GUID *VariableGuid,\r
631 IN UINT16 *VariableName,\r
632 IN CONST VOID *Data,\r
633 IN UINTN DataSize,\r
634 IN UINTN Offset\r
635 )\r
636{\r
52e1905d 637 UINTN Size;\r
638 VOID *Buffer;\r
639 EFI_STATUS Status;\r
640 UINT32 Attribute;\r
878ddf1f 641\r
642 Size = 0;\r
643\r
644 Status = EfiGetVariable (\r
645 (UINT16 *)VariableName,\r
646 VariableGuid,\r
52e1905d 647 &Attribute,\r
878ddf1f 648 &Size,\r
649 NULL\r
650 );\r
651\r
652 ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
653\r
654 Buffer = AllocatePool (Size);\r
655\r
656 ASSERT (Buffer != NULL);\r
657\r
658 Status = EfiGetVariable (\r
659 VariableName,\r
660 VariableGuid,\r
52e1905d 661 &Attribute,\r
878ddf1f 662 &Size,\r
663 Buffer\r
664 );\r
665\r
666\r
667 CopyMem ((UINT8 *)Buffer + Offset, Data, DataSize);\r
668\r
669 return EfiSetVariable (\r
670 VariableName,\r
671 VariableGuid,\r
52e1905d 672 Attribute,\r
878ddf1f 673 Size,\r
674 Buffer\r
675 );\r
676\r
677}\r
678\r
52e1905d 679\r
680\r
681\r
682\r
683VOID\r
684GetExPcdTokenAttributes (\r
685 IN CONST EFI_GUID *Guid,\r
0653eb89 686 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
52e1905d 687 OUT EX_PCD_ENTRY_ATTRIBUTE *ExAttr\r
688 )\r
689{\r
690 UINT32 i;\r
691 DYNAMICEX_MAPPING *ExMap;\r
692 EFI_GUID *GuidTable;\r
693 UINT16 *SizeTable;\r
694\r
4c114006 695 ExMap = mPcdDatabase->PeiDb.Init.ExMapTable;\r
696 GuidTable = mPcdDatabase->PeiDb.Init.GuidTable;\r
697 SizeTable = mPcdDatabase->PeiDb.Init.SizeTable;\r
52e1905d 698 \r
699 for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {\r
700 if ((ExTokenNumber == ExMap[i].ExTokenNumber) &&\r
701 CompareGuid (Guid, (CONST EFI_GUID *) &GuidTable[ExMap[i].ExGuidIndex])\r
702 ) {\r
703\r
704 ExAttr->IsPeiDb = TRUE;\r
705 ExAttr->Size = SizeTable[i + PEI_NEX_TOKEN_NUMBER];\r
706 ExAttr->TokenNumber = i + PEI_NEX_TOKEN_NUMBER;\r
707 ExAttr->LocalTokenNumberAlias = ExMap[i].LocalTokenNumber;\r
708 return;\r
709\r
710 }\r
711 }\r
712 \r
4c114006 713 ExMap = mPcdDatabase->DxeDb.Init.ExMapTable;\r
714 GuidTable = mPcdDatabase->DxeDb.Init.GuidTable;\r
715 SizeTable = mPcdDatabase->DxeDb.Init.SizeTable;\r
52e1905d 716 \r
717 for (i = 0; i < DXE_EXMAPPING_TABLE_SIZE; i++) {\r
718 if ((ExTokenNumber == ExMap[i].ExTokenNumber) &&\r
719 CompareGuid (Guid, (CONST EFI_GUID *) &GuidTable[ExMap[i].ExGuidIndex])\r
720 ) {\r
721\r
722 ExAttr->IsPeiDb = FALSE;\r
723 ExAttr->Size = SizeTable[i + DXE_NEX_TOKEN_NUMBER];\r
0653eb89 724 ExAttr->TokenNumber = i + PEI_LOCAL_TOKEN_NUMBER;\r
52e1905d 725 ExAttr->LocalTokenNumberAlias = ExMap[i].LocalTokenNumber;\r
726 return;\r
727\r
728 }\r
729 }\r
730\r
731 ASSERT (FALSE);\r
732\r
733 return;\r
734}\r
735\r