38293252bc52b4be65e30c5ba28bb041fb6acf88
[mirror_edk2.git] / EdkModulePkg / Universal / PCD / Pei / Service.c
1 /** @file
2 Private functions used by PCD PEIM.
3
4 Copyright (c) 2006, 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 Module Name: Service.c
15
16 **/
17 #include "../Common/PcdCommon.h"
18 #include "Service.h"
19
20
21
22
23 /**
24 This function expand the StateByte
25
26 @param[out] StateByte The output StateByte information.
27 @param[in] Byte The StateByte.
28
29 @retval VOID
30 --*/
31 VOID
32 PcdImageExpandStateByte (
33 OUT PCD_STATEBYTE *StateByte,
34 IN UINT8 Byte
35 )
36 {
37 switch (Byte & PCD_STATEBYTE_DATUMTYPE) {
38 case PCD_BYTE8:
39 StateByte->DataType = PcdByte8;
40 break;
41 case PCD_BYTE16:
42 StateByte->DataType = PcdByte16;
43 break;
44 case PCD_BYTE32:
45 StateByte->DataType = PcdByte32;
46 break;
47 case PCD_BYTE64:
48 StateByte->DataType = PcdByte64;
49 break;
50 case PCD_POINTER:
51 StateByte->DataType = PcdPointer;
52 break;
53 case PCD_BOOLEAN:
54 StateByte->DataType = PcdBoolean;
55 break;
56 default:
57 ASSERT (FALSE);
58 }
59
60 StateByte->ExtendedGuidPresent = (BOOLEAN) ((Byte & PCD_STATEBYTE_EXTENDEDGUIDPRESENT) != 0);
61 StateByte->HiiEnable = (BOOLEAN) ((Byte & PCD_STATEBYTE_HIIENABLE) != 0);
62 StateByte->SkuDataArrayEnable = (BOOLEAN) ((Byte & PCD_STATEBYTE_SKUDATAARRAYENABLE) != 0);
63 StateByte->SkuEnable = (BOOLEAN) ((Byte & PCD_STATEBYTE_SKUENABLE) != 0);
64 StateByte->VpdEnable = (BOOLEAN) ((Byte & PCD_STATEBYTE_VPDENABLE) != 0);
65
66 }
67
68
69
70 /**
71 This function locates the <PCD_IMAGE> on the flash and
72 return a pointer to the Section Data on flash.
73
74 @param[in] VOID
75
76 @retval VOID
77 --*/
78 UINT8 *
79 LocatePcdImage (
80 VOID
81 )
82 {
83 EFI_STATUS Status;
84 EFI_FIRMWARE_VOLUME_HEADER *FvHdr;
85 EFI_FFS_FILE_HEADER *FfsHdr;
86 VOID *SectionData;
87
88 Status = PeiCoreFfsFindNextVolume (0, &FvHdr);
89 ASSERT_EFI_ERROR (Status);
90
91 do {
92 FfsHdr = NULL;
93 Status = PeiCoreFfsFindNextFile (EFI_FV_FILETYPE_FREEFORM, FvHdr, &FfsHdr);
94 if (Status == EFI_SUCCESS) {
95 if (CompareGuid (&gPcdImageFileGuid, &FfsHdr->Name)) {
96
97 Status = PeiCoreFfsFindSectionData (EFI_SECTION_RAW, FfsHdr, &SectionData);
98 ASSERT_EFI_ERROR (Status);
99
100 return (UINT8 *)SectionData;
101 }
102 }
103 } while (Status == EFI_SUCCESS);
104
105 ASSERT (FALSE);
106
107 return NULL;
108 }
109
110 /**
111 The function retrieves the PCD data value according to
112 TokenNumber and Guid space given.
113
114 @param[in] TokenNumber The token number.
115 @param[in] Guid The Guid space.
116 @param[in] Type The storage type.
117 @param[out] Data The output data.
118
119
120 @retval EFI_SUCESS If data value is found according to SKU_ID.
121 @retval EFI_NOT_FOUND If not such a value is found.
122
123 --*/
124 VOID
125 PeiGetPcdEntryWorker (
126 IN UINTN TokenNumber,
127 IN CONST EFI_GUID *Guid, OPTIONAL
128 IN PCD_DATA_TYPE Type,
129 OUT VOID *Data
130 )
131 {
132 PCD_DATABASE *Database;
133 EFI_HOB_GUID_TYPE *GuidHob;
134
135 ASSERT (Data != NULL);
136
137 GuidHob = GetFirstGuidHob (&gPcdDataBaseHobGuid);
138 ASSERT (GuidHob != NULL);
139
140 Database = GET_GUID_HOB_DATA (GuidHob);
141
142 GetPcdEntryWorker ( &Database->Info,
143 TokenNumber,
144 Guid,
145 Type,
146 Data
147 );
148
149
150 return;
151 }
152
153
154 /**
155 The function set the PCD data value according to
156 TokenNumber and Guid space given.
157
158 @param[in] Database The PCD Database Instance.
159 @param[in] TokenNumber The token number.
160 @param[in] Guid The Guid space.
161 @param[in] Type The storage type.
162 @param[in] Data The output data.
163
164
165 @retval EFI_SUCESS If data value is found according to SKU_ID.
166 @retval EFI_NOT_FOUND If not such a value is found.
167
168 --*/
169 EFI_STATUS
170 SetPcdEntryWorker (
171 IN CONST PCD_DATABASE *Database,
172 IN UINTN TokenNumber,
173 IN CONST EFI_GUID *Guid, OPTIONAL
174 IN PCD_DATA_TYPE Type,
175 IN VOID *Data
176 )
177 {
178 PCD_INDEX *PcdIndex;
179 EFI_STATUS Status;
180 PCD_PPI_CALLBACK *CallbackTable;
181 UINTN Idx;
182
183 ASSERT (Data != NULL);
184
185 //
186 // Find the PCD entry in list in memory first
187 //
188 PcdIndex = FindPcdIndex (TokenNumber, Guid, &Database->Info, &Idx);
189
190 ASSERT (PcdIndex != NULL);
191
192 ASSERT (PcdIndex->StateByte.DataType == Type);
193
194 //
195 // Invoke the callback function.
196 //
197 CallbackTable = (PCD_PPI_CALLBACK *)
198 GetAbsoluteAddress (Idx * Database->Info.MaxCallbackNum * sizeof(PCD_PPI_CALLBACK),
199 Database->Info.CallbackTableOffset,
200 &Database->Info
201 );
202
203 for (Idx = 0; Idx < Database->Info.MaxCallbackNum; Idx++) {
204 if (CallbackTable[Idx] != NULL) {
205 CallbackTable[Idx] (Guid,
206 PcdIndex->TokenNumber,
207 Data,
208 PcdIndex->DatumSize
209 );
210 }
211 }
212
213 Status = SetPcdData (PcdIndex, &Database->Info, Data);
214
215 return Status;
216 }
217
218
219
220 /**
221 (reviewed) The function set the PCD data value according to
222 TokenNumber and Guid space given.
223
224 @param[in] TokenNumber The token number.
225 @param[in] Guid The Guid space.
226 @param[in] Type The storage type.
227 @param[in] Data The output data.
228
229
230 @retval EFI_SUCESS If data value is found according to SKU_ID.
231 @retval EFI_NOT_FOUND If not such a value is found.
232
233 --*/
234 EFI_STATUS
235 PeiSetPcdEntryWorker (
236 IN UINTN TokenNumber,
237 IN CONST EFI_GUID *Guid, OPTIONAL
238 IN PCD_DATA_TYPE Type,
239 IN VOID *Data
240 )
241 {
242 PCD_DATABASE *Database;
243 EFI_HOB_GUID_TYPE *GuidHob;
244
245 ASSERT (Data != NULL);
246
247 GuidHob = GetFirstGuidHob (&gPcdDataBaseHobGuid);
248 ASSERT (GuidHob != NULL);
249
250 Database = GET_GUID_HOB_DATA (GuidHob);
251
252 SetPcdEntryWorker (Database,
253 TokenNumber,
254 Guid,
255 Type,
256 Data
257 );
258
259 return EFI_SUCCESS;
260 }
261
262
263
264 UINTN
265 PeiGetPcdEntrySizeWorker (
266 IN UINTN TokenNumber,
267 IN CONST EFI_GUID *Guid OPTIONAL
268 )
269 {
270 PCD_DATABASE *Database;
271 EFI_HOB_GUID_TYPE *GuidHob;
272
273 GuidHob = GetFirstGuidHob (&gPcdDataBaseHobGuid);
274 ASSERT (GuidHob != NULL);
275
276 Database = GET_GUID_HOB_DATA (GuidHob);
277
278 return GetPcdEntrySizeWorker (&Database->Info,
279 TokenNumber,
280 Guid
281 );
282
283 }
284
285
286
287 /**
288 The function registers the CallBackOnSet fucntion
289 according to TokenNumber and EFI_GUID space.
290
291 @param[in] TokenNumber The token number.
292 @param[in] Guid The GUID space.
293 @param[in] CallBackFunction The Callback function to be registered.
294
295 @retval EFI_SUCCESS If the Callback function is registered.
296 @retval EFI_NOT_FOUND If the PCD Entry is not found according to Token Number and GUID space.
297 --*/
298 EFI_STATUS
299 PeiRegisterCallBackWorker (
300 IN UINTN TokenNumber,
301 IN CONST EFI_GUID *Guid, OPTIONAL
302 IN PCD_PPI_CALLBACK CallBackFunction,
303 IN BOOLEAN Register
304 )
305 {
306 PCD_DATABASE *Database;
307 EFI_HOB_GUID_TYPE *GuidHob;
308 PCD_INDEX *PcdIndex;
309 UINTN Idx;
310 PCD_PPI_CALLBACK *CallbackTable;
311 PCD_PPI_CALLBACK Compare;
312 PCD_PPI_CALLBACK Assign;
313
314 GuidHob = GetFirstGuidHob (&gPcdDataBaseHobGuid);
315 ASSERT (GuidHob != NULL);
316
317 Database = GET_GUID_HOB_DATA (GuidHob);
318
319 PcdIndex = FindPcdIndex (TokenNumber, Guid, &Database->Info, NULL);
320
321 ASSERT (PcdIndex != NULL);
322
323 if (PcdIndex->StateByte.VpdEnable) {
324 return EFI_INVALID_PARAMETER;
325 }
326
327 Idx = ((UINTN) PcdIndex - Database->Info.CallbackTableOffset) / sizeof(PCD_INDEX);
328
329 CallbackTable = (PCD_PPI_CALLBACK *) GetAbsoluteAddress (
330 sizeof (PCD_PPI_CALLBACK) * Idx * Database->Info.MaxCallbackNum,
331 Database->Info.CallbackTableOffset,
332 &Database->Info
333 );
334
335 Compare = Register? NULL: CallBackFunction;
336 Assign = Register? CallBackFunction: NULL;
337
338 for (Idx = 0; Idx < Database->Info.MaxCallbackNum; Idx++) {
339 if (CallbackTable[Idx] == Compare) {
340 CallbackTable[Idx] = Assign;
341 return EFI_SUCCESS;
342 }
343 }
344
345 return Register? EFI_OUT_OF_RESOURCES : EFI_NOT_FOUND;
346
347 }
348
349
350
351 EFI_STATUS
352 PeiGetNextTokenWorker (
353 IN OUT UINTN *TokenNumber,
354 IN CONST EFI_GUID *Guid OPTIONAL
355 )
356 {
357 PCD_DATABASE *Database;
358 EFI_HOB_GUID_TYPE *GuidHob;
359
360 GuidHob = GetFirstGuidHob (&gPcdDataBaseHobGuid);
361 ASSERT (GuidHob != NULL);
362
363 Database = GET_GUID_HOB_DATA (GuidHob);
364
365 return GetNextTokenWorker (&Database->Info,
366 TokenNumber,
367 Guid
368 );
369
370 }
371
372
373
374 VOID
375 GetPcdImageInfo (
376 IN CONST UINT8 *PcdImageOnFlash,
377 OUT PCD_IMAGE_RECORD *ImageInfo
378 )
379 {
380 PCD_FFS_ENCODING *PcdFfsHdr;
381
382 PcdFfsHdr = (PCD_FFS_ENCODING *) PcdImageOnFlash;
383
384 ZeroMem (ImageInfo, sizeof (*ImageInfo));
385
386 ImageInfo->ImageStart = PcdImageOnFlash;
387
388 CopyMem (&ImageInfo->EntryCount, PcdFfsHdr->EntryCount, 3);
389
390 CopyMem (&ImageInfo->GlobalDatumLength, PcdFfsHdr->GlobalDatumLength, 1);
391 ASSERT (ImageInfo->GlobalDatumLength <= 3);
392
393 CopyMem (&ImageInfo->GlobalOffsetLength, PcdFfsHdr->GlobalOffsetLength, 1);
394 ASSERT (ImageInfo->GlobalOffsetLength <= 3);
395
396 CopyMem (&ImageInfo->GlobalTokenLength, PcdFfsHdr->GlobalTokenLength, 1);
397 ASSERT (ImageInfo->GlobalTokenLength <= 4);
398
399 CopyMem (&ImageInfo->GlobalGuidTabIdxLength, PcdFfsHdr->GuidLength, 1);
400 ASSERT (ImageInfo->GlobalGuidTabIdxLength <= 2);
401
402 CopyMem (&ImageInfo->GlobalStrTabIdxLength, PcdFfsHdr->GlobalStrTabIdxLength, 1);
403 ASSERT (ImageInfo->GlobalStrTabIdxLength <= 2);
404
405 CopyMem (&ImageInfo->ImageLength, PcdFfsHdr->ImageLength, 3);
406 CopyMem (&ImageInfo->IndexLength, PcdFfsHdr->PcdIndexLength, 3);
407 CopyMem (&ImageInfo->WholeDataDefaultLength, PcdFfsHdr->WholeDataBufferLength, 3);
408 CopyMem (&ImageInfo->DataDefaultLength, PcdFfsHdr->DataBufferLength, 3);
409 CopyMem (&ImageInfo->GuidTableLength, PcdFfsHdr->GuidTableLength, 3);
410
411 ImageInfo->StringTableLength = ImageInfo->ImageLength
412 - sizeof (PCD_FFS_ENCODING)
413 - ImageInfo->DataDefaultLength
414 - ImageInfo->IndexLength
415 - ImageInfo->GuidTableLength;
416
417 ImageInfo->DataDefaultStart = PcdImageOnFlash + sizeof (PCD_FFS_ENCODING);
418 ImageInfo->IndexStart = ImageInfo->DataDefaultStart + ImageInfo->DataDefaultLength;
419 ImageInfo->GuidTableStart = (CONST EFI_GUID *)(ImageInfo->IndexStart + ImageInfo->IndexLength);
420 ImageInfo->StringTableStart = (CONST UINT16 *) ((UINT8 *) ImageInfo->GuidTableStart + ImageInfo->GuidTableLength);
421
422 return;
423 }
424
425
426
427 /**
428 The function builds the PCD database based on the
429 PCD_IMAGE on the flash.
430
431 The layout of the PCD_DATABASE is as follows:
432
433 ---------------------------
434 | PCD_DATABASE_HEADER |
435 ---------------------------
436 | GUID_TABLE | Aligned on GUID (128 bits)
437 ---------------------------
438 | PCD_CALL_BACK_TABLE | Aligned on Pointer (32 bits or 64 bits)
439 ---------------------------
440 | PCD_INDEX_TABLE | Aligned on PCD_INDEX (see PCD_INDEX's declaration)
441 ---------------------------
442 | IMAGE_STRING_TABLE | Aligned on 16 Bits
443 ---------------------------
444 | IMAGE_PCD_INDEX | Unaligned
445 ---------------------------
446 | Data Defaults | Unaligned
447 ---------------------------
448 | Data Buffer |
449 | for entries without |
450 | defaults |
451 ---------------------------
452
453 @param[in] PcdImageOnFlash The PCD image on flash.
454
455 @retval VOID
456 --*/
457 UINTN
458 GetPcdDatabaseLen (
459 IN CONST UINT8 *PcdImageOnFlash,
460 OUT PCD_DATABASE_HEADER *Info,
461 OUT PCD_IMAGE_RECORD *ImageInfo
462 )
463 {
464 UINTN DatabaseLen;
465 UINTN DatabaseHeaderLength;
466 UINTN PcdIndexLength;
467 UINTN CallbackBufferLength;
468
469
470 GetPcdImageInfo (PcdImageOnFlash, ImageInfo);
471
472 Info->MaxCallbackNum = FixedPcdGet32(PcdMaxPcdCallBackNumber) ;
473
474 DatabaseHeaderLength = sizeof (PCD_DATABASE) - sizeof(UINT8);
475
476 PcdIndexLength = sizeof (PCD_INDEX) * ImageInfo->EntryCount;
477 CallbackBufferLength = sizeof (PCD_PPI_CALLBACK) * Info->MaxCallbackNum * ImageInfo->EntryCount;
478
479 Info->EntryCount = ImageInfo->EntryCount;
480 Info->GuidTableOffset = DatabaseHeaderLength;
481 Info->CallbackTableOffset = Info->GuidTableOffset + ImageInfo->GuidTableLength;
482 Info->PcdIndexOffset = Info->PcdIndexOffset + PcdIndexLength;
483 Info->ImageIndexOffset = Info->CallbackTableOffset + CallbackBufferLength;
484 Info->DataBufferOffset = Info->ImageIndexOffset + ImageInfo->DataDefaultLength;
485
486 Info->HiiGuidOffsetLength = ImageInfo->GlobalGuidTabIdxLength;
487 Info->HiiVariableOffsetLength = ImageInfo->GlobalStrTabIdxLength;
488 Info->ExtendedOffsetLength = ImageInfo->GlobalOffsetLength;
489
490 Info->SkuId = 0;
491
492 DatabaseLen = DatabaseHeaderLength
493 + ImageInfo->GuidTableLength
494 + PcdIndexLength
495 + CallbackBufferLength
496 + ImageInfo->IndexLength
497 + ImageInfo->WholeDataDefaultLength;
498
499 Info->DatabaseLen = DatabaseLen;
500
501 return DatabaseLen;
502 }
503
504
505 /**
506 The function constructs a single PCD_INDEX according a index in
507 <PCD_IMAGE>.
508
509 @param[in] ImageIndex The starting address of a PCD index defined in PCD spec 0.51.
510 @param[in] Index The output PCD_INDEX.
511 @param[in] ImageInfo The attributes of the PCD_IMAGE as this binary stream is highly
512 optimized for size.
513
514 @retval UINTN The length of the current PCD index.
515 **/
516 UINTN
517 BuildPcdIndex (
518 IN CONST UINT8 *ImageIndex,
519 OUT PCD_INDEX *Index,
520 IN CONST PCD_IMAGE_RECORD *ImageInfo
521 )
522 {
523 UINTN SkuCount;
524 CONST UINT8 *ImageIndexBackUp;
525
526 ImageIndexBackUp = ImageIndex;
527
528 //
529 // Token Number
530 //
531 CopyMem (&Index->TokenNumber,
532 ImageIndex,
533 ImageInfo->GlobalTokenLength
534 );
535
536 ImageIndex += ImageInfo->GlobalTokenLength;
537
538 //
539 // State Byte
540 //
541 PcdImageExpandStateByte (&Index->StateByte,
542 *ImageIndex
543 );
544
545 ImageIndex += 1;
546
547 //
548 // Dataum Size
549 //
550 CopyMem (&Index->DatumSize,
551 ImageIndex,
552 ImageInfo->GlobalDatumLength
553 );
554
555 ImageIndex += ImageInfo->GlobalDatumLength;
556
557 //
558 // SKU_DATA
559 //
560 if (Index->StateByte.SkuEnable) {
561 Index->SkuCount = *ImageIndex;
562 SkuCount = *ImageIndex;
563 ImageIndex++;
564 Index->SkuIdArray = (UINT32) ImageIndex - (UINT32) ImageInfo->IndexStart;
565 ImageIndex += Index->SkuCount;
566 } else {
567 //
568 // There is always a default SKU_ID of zero even
569 // if SKU is not enabled for this PCD entry.
570 //
571 //
572 SkuCount = 1;
573 }
574
575 //
576 // Extended Offset
577 //
578 CopyMem (&Index->ExtendedDataOffset,
579 ImageIndex,
580 ImageInfo->GlobalOffsetLength
581 );
582
583 ImageIndex += ImageInfo->GlobalOffsetLength * SkuCount;
584
585 //
586 // DynamicEX Guid Offset
587 //
588 if (Index->StateByte.ExtendedGuidPresent) {
589 CopyMem (&Index->DynamicExGuid,
590 ImageIndex,
591 ImageInfo->GlobalGuidTabIdxLength
592 );
593
594 ImageIndex += ImageInfo->GlobalGuidTabIdxLength;
595 }
596
597 //
598 // HII_DATA
599 //
600 if (Index->StateByte.HiiEnable) {
601 Index->HiiData = (UINT32) ImageIndex - (UINT32) ImageInfo->IndexStart;
602 ImageIndex += ((ImageInfo->GlobalStrTabIdxLength + ImageInfo->GlobalGuidTabIdxLength) * SkuCount);
603 }
604
605 return (UINTN) (ImageIndex - ImageIndexBackUp);
606 }
607
608
609
610
611 /**
612 The function builds the PCD database based on the
613 PCD_IMAGE on the flash.
614
615 @param[in] Database The database instance.
616 @param[in] ImageIndex The starting address of a PCD index defined in PCD spec 0.51.
617 @param[in] ImageInfo The attributes of the PCD_IMAGE as this binary stream is highly
618 optimized for size.
619
620 @retval VOID
621 **/
622 VOID
623 BuildPcdDatabaseIndex (
624 PCD_DATABASE *Database,
625 UINT8 *ImageIndex,
626 PCD_IMAGE_RECORD *ImageInfo
627 )
628 {
629 UINTN Idx;
630 UINTN Len;
631 PCD_INDEX *IndexTable;
632
633 IndexTable = (PCD_INDEX *) GetAbsoluteAddress (0, Database->Info.PcdIndexOffset, Database);
634
635 for (Idx = 0; Idx < Database->Info.EntryCount; Idx++) {
636 Len = BuildPcdIndex (ImageIndex, &IndexTable[Idx], ImageInfo);
637 ImageIndex += Len;
638 }
639
640 return;
641 }
642
643
644 /**
645 The function builds the PCD database based on the
646 PCD_IMAGE on the flash.
647
648 @param[in] PcdImageOnFlash The PCD image on flash.
649
650 @retval VOID
651 --*/
652 VOID
653 BuildPcdDatabase (
654 UINT8 *PcdImageOnFlash
655 )
656 {
657 PCD_DATABASE *Database;
658 UINTN Len;
659 PCD_IMAGE_RECORD ImageInfo;
660 UINT8 *ImageIndex;
661 PCD_DATABASE_HEADER DatabaseHeader;
662
663 Len = GetPcdDatabaseLen(PcdImageOnFlash, &DatabaseHeader, &ImageInfo);
664
665 Database = BuildGuidHob (&gPcdDataBaseHobGuid, Len);
666 ASSERT (Database != NULL);
667
668 ZeroMem (Database, Len);
669
670 //
671 // Update Database header
672 //
673 CopyMem (&Database->Info, &DatabaseHeader, sizeof (DatabaseHeader));
674
675 //
676 // I need this to get the GuidTableOffset as we don't
677 // know if Database field of PCD_DATABASE starts from an aligned
678 // address. The compilor may add padding after PCD_DATABASE_HEADER field.
679 //
680 Database->Info.GuidTableOffset = ((UINTN) &Database->GuidTable) - (UINTN)Database;
681
682 //
683 // Copy Guid Table from Flash
684 //
685 CopyMem ((UINT8 *) Database + Database->Info.GuidTableOffset,
686 ImageInfo.GuidTableStart,
687 ImageInfo.GuidTableLength
688 );
689
690 //
691 // Copy ImageIndex from Flash
692 //
693 CopyMem ((UINT8 *) Database + Database->Info.ImageIndexOffset,
694 ImageInfo.IndexStart,
695 ImageInfo.IndexLength
696 );
697
698 //
699 // Copy Default Value
700 //
701 CopyMem ((UINT8 *) Database + Database->Info.DataBufferOffset,
702 ImageInfo.DataDefaultStart,
703 ImageInfo.DataDefaultLength
704 );
705
706 //
707 // Copy String Table
708 //
709 CopyMem ((UINT8 *) Database + Database->Info.StringTableOffset,
710 ImageInfo.StringTableStart,
711 ImageInfo.StringTableLength
712 );
713
714 ImageIndex = GetAbsoluteAddress (0, Database->Info.ImageIndexOffset, Database);
715
716 BuildPcdDatabaseIndex (Database, ImageIndex, &ImageInfo);
717
718 return;
719 }
720
721
722
723 /**
724 The function is provided by PCD PEIM and PCD DXE driver to
725 do the work of reading a HII variable from variable service.
726
727 @param[in] VariableGuid The Variable GUID.
728 @param[in] VariableName The Variable Name.
729 @param[out] VariableData The output data.
730 @param[out] VariableSize The size of the variable.
731
732 @retval EFI_SUCCESS Operation successful.
733 @retval EFI_SUCCESS Variablel not found.
734 --*/
735 EFI_STATUS
736 GetHiiVariable (
737 IN EFI_GUID *VariableGuid,
738 IN UINT16 *VariableName,
739 OUT VOID **VariableData,
740 OUT UINTN *VariableSize
741 )
742 {
743 UINTN Size;
744 EFI_STATUS Status;
745 VOID *Buffer;
746 EFI_PEI_READ_ONLY_VARIABLE_PPI *VariablePpi;
747
748 Status = PeiCoreLocatePpi (&gEfiPeiReadOnlyVariablePpiGuid, 0, NULL, &VariablePpi);
749 ASSERT_EFI_ERROR (Status);
750
751 Size = 0;
752
753 Status = VariablePpi->PeiGetVariable (
754 GetPeiServicesTablePointer (),
755 VariableName,
756 VariableGuid,
757 NULL,
758 &Size,
759 NULL
760 );
761 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
762
763 Status = PeiCoreAllocatePool (Size, &Buffer);
764 ASSERT_EFI_ERROR (Status);
765
766 // declare a local for STP.
767 //
768 Status = VariablePpi->PeiGetVariable (
769 GetPeiServicesTablePointer (),
770 (UINT16 *) VariableName,
771 VariableGuid,
772 NULL,
773 &Size,
774 Buffer
775 );
776 ASSERT_EFI_ERROR (Status);
777
778 *VariableSize = Size;
779 *VariableData = Buffer;
780
781 return EFI_SUCCESS;
782 }
783
784
785
786 /**
787 The function is provided by PCD PEIM and PCD DXE driver to
788 do the work of reading a HII variable from variable service.
789
790 @param[in] VariableGuid The Variable GUID.
791 @param[in] VariableName The Variable Name.
792 @param[in] Data The input data.
793 @param[out] VariableSize The size of the variable.
794 @param[in] Offset The offset of the variable data that a PCD entry will starts from.
795
796 @retval EFI_SUCCESS Operation successful.
797 @retval EFI_SUCCESS Variablel not found.
798 --*/
799 EFI_STATUS
800 SetHiiVariable (
801 IN EFI_GUID *VariableGuid,
802 IN UINT16 *VariableName,
803 IN CONST VOID *Data,
804 IN UINTN VariableSize,
805 IN UINTN Offset
806 )
807 {
808 ASSERT (FALSE);
809 return EFI_INVALID_PARAMETER;
810 }
811
812