TianoCore EDK2 master
Loading...
Searching...
No Matches
PlatformId.c
Go to the documentation of this file.
1
10#include <Base.h>
11#include <Guid/TcgEventHob.h>
14#include <Library/BaseLib.h>
15#include <Library/DebugLib.h>
16#include <Library/HobLib.h>
18#include <Library/PrintLib.h>
20
21#define DPREFIX "sp800155evts: "
22
30VOID
32 IN CONST EFI_PEI_SERVICES **PeiServices,
33 IN UINT8 *Evt,
34 IN UINTN EvtSize
35 )
36{
37 EFI_STATUS Status;
38 VOID *Hob;
39 EFI_HOB_GUID_TYPE *GuidHob;
40 UINT8 *EvtDest;
41
42 Status = (*PeiServices)->CreateHob (
43 PeiServices,
44 EFI_HOB_TYPE_GUID_EXTENSION,
45 sizeof (EFI_HOB_GUID_TYPE) + (UINT16)EvtSize,
46 &Hob
47 );
48 if (EFI_ERROR (Status)) {
49 DEBUG ((DEBUG_ERROR, DPREFIX "GUID HOB creation failed, skipping\n"));
50 return;
51 }
52
53 GuidHob = (EFI_HOB_GUID_TYPE *)Hob;
54 CopyGuid (&GuidHob->Name, &gTcg800155PlatformIdEventHobGuid);
55 EvtDest = (UINT8 *)GET_GUID_HOB_DATA (Hob);
56 CopyMem (EvtDest, Evt, EvtSize);
57 // Fill the remaining HOB padding bytes with 0s.
58 SetMem (EvtDest + EvtSize, GET_GUID_HOB_DATA_SIZE (Hob) - EvtSize, 0);
59}
60
66BOOLEAN
68 IN CONST EFI_PEI_SERVICES **PeiServices,
69 IN CONST CHAR8 *Path
70 )
71{
72 EFI_STATUS Status;
73 UINTN NumPages;
75 FIRMWARE_CONFIG_ITEM FdtItem;
76 UINTN FdtSize;
77 UINT8 *Evt;
78
79 Status = QemuFwCfgFindFile (Path, &FdtItem, &FdtSize);
80 if (EFI_ERROR (Status)) {
81 return FALSE;
82 }
83
84 if (FdtSize > MAX_UINT16 - sizeof (EFI_HOB_GUID_TYPE)) {
85 DEBUG ((DEBUG_ERROR, DPREFIX "Eventdata too large for HOB, skipping\n"));
86 return TRUE;
87 }
88
89 NumPages = EFI_SIZE_TO_PAGES (FdtSize);
90 Status = (*PeiServices)->AllocatePages (
91 PeiServices,
93 NumPages,
94 &Pages
95 );
96 if (EFI_ERROR (Status)) {
97 return TRUE;
98 }
99
100 Evt = (UINT8 *)(UINTN)Pages;
101 QemuFwCfgSelectItem (FdtItem);
102 QemuFwCfgReadBytes (FdtSize, Evt);
103 PlatformIdRegisterSp800155 (PeiServices, Evt, FdtSize);
104
105 Status = (*PeiServices)->FreePages (PeiServices, Pages, NumPages);
106 ASSERT_EFI_ERROR (Status);
107 return TRUE;
108}
109
110VOID
112 IN CONST EFI_PEI_SERVICES **PeiServices
113 )
114{
115 UINTN Index;
116 CHAR8 Path[64];
117
118 for (Index = 0; ; Index++) {
119 AsciiSPrint (Path, sizeof (Path), "opt/org.tianocode/sp800155evt/%d", Index);
120 if (!PlatformIdRegisterEvent (PeiServices, Path)) {
121 break;
122 }
123 }
124}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
VOID PlatformIdInitialization(IN CONST EFI_PEI_SERVICES **PeiServices)
Definition: PlatformId.c:111
STATIC VOID PlatformIdRegisterSp800155(IN CONST EFI_PEI_SERVICES **PeiServices, IN UINT8 *Evt, IN UINTN EvtSize)
Definition: PlatformId.c:31
BOOLEAN PlatformIdRegisterEvent(IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST CHAR8 *Path)
Definition: PlatformId.c:67
RETURN_STATUS EFIAPI QemuFwCfgFindFile(IN CONST CHAR8 *Name, OUT FIRMWARE_CONFIG_ITEM *Item, OUT UINTN *Size)
Definition: QemuFwCfgLib.c:250
VOID EFIAPI QemuFwCfgReadBytes(IN UINTN Size, IN VOID *Buffer OPTIONAL)
Definition: QemuFwCfgNull.c:66
VOID EFIAPI QemuFwCfgSelectItem(IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem)
Definition: QemuFwCfgLib.c:33
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
@ EfiBootServicesData
EFI_GUID Name
Definition: PiHob.h:347