TianoCore EDK2 master
Loading...
Searching...
No Matches
SmmCommunicationBufferDxe.c
Go to the documentation of this file.
1
15#include <PiDxe.h>
18#include <Library/BaseLib.h>
21#include <Library/DebugLib.h>
22#include <Library/HobLib.h>
23#include <Library/UefiLib.h>
24#include <Guid/MmCommBuffer.h>
26
27#define DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES 4
28
39EFIAPI
41 IN EFI_HANDLE ImageHandle,
42 IN EFI_SYSTEM_TABLE *SystemTable
43 )
44{
45 EFI_STATUS Status;
46 UINT32 DescriptorSize;
47 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable;
49 EFI_HOB_GUID_TYPE *GuidHob;
50 MM_COMM_BUFFER *MmCommBuffer;
51
52 DescriptorSize = sizeof (EFI_MEMORY_DESCRIPTOR);
53
54 //
55 // Make sure Size != sizeof(EFI_MEMORY_DESCRIPTOR). This will
56 // prevent people from having pointer math bugs in their code.
57 // now you have to use *DescriptorSize to make things work.
58 //
59 DescriptorSize += sizeof (UINT64) - (DescriptorSize % sizeof (UINT64));
60
61 //
62 // Allocate and fill PiSmmCommunicationRegionTable
63 //
64 PiSmmCommunicationRegionTable = AllocateReservedPool (sizeof (EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);
65 ASSERT (PiSmmCommunicationRegionTable != NULL);
66 ZeroMem (PiSmmCommunicationRegionTable, sizeof (EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);
67
68 PiSmmCommunicationRegionTable->Version = EDKII_PI_SMM_COMMUNICATION_REGION_TABLE_VERSION;
69 PiSmmCommunicationRegionTable->NumberOfEntries = 1;
70 PiSmmCommunicationRegionTable->DescriptorSize = DescriptorSize;
71 Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);
72 Entry->Type = EfiConventionalMemory;
73
74 GuidHob = GetFirstGuidHob (&gMmCommBufferHobGuid);
75
76 if (GuidHob == NULL) {
77 Entry->PhysicalStart = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedPages (DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES);
78 Entry->NumberOfPages = DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES;
79 } else {
80 MmCommBuffer = GET_GUID_HOB_DATA (GuidHob);
81 Entry->PhysicalStart = MmCommBuffer->PhysicalStart;
82 Entry->NumberOfPages = MmCommBuffer->NumberOfPages;
83 }
84
85 ASSERT (Entry->PhysicalStart != 0);
86 Entry->VirtualStart = 0;
87 Entry->Attribute = 0;
88
89 DEBUG ((DEBUG_INFO, "PiSmmCommunicationRegionTable:(0x%x)\n", PiSmmCommunicationRegionTable));
90 DEBUG ((DEBUG_INFO, " Version - 0x%x\n", PiSmmCommunicationRegionTable->Version));
91 DEBUG ((DEBUG_INFO, " NumberOfEntries - 0x%x\n", PiSmmCommunicationRegionTable->NumberOfEntries));
92 DEBUG ((DEBUG_INFO, " DescriptorSize - 0x%x\n", PiSmmCommunicationRegionTable->DescriptorSize));
93 DEBUG ((DEBUG_INFO, "Entry:(0x%x)\n", Entry));
94 DEBUG ((DEBUG_INFO, " Type - 0x%x\n", Entry->Type));
95 DEBUG ((DEBUG_INFO, " PhysicalStart - 0x%lx\n", Entry->PhysicalStart));
96 DEBUG ((DEBUG_INFO, " VirtualStart - 0x%lx\n", Entry->VirtualStart));
97 DEBUG ((DEBUG_INFO, " NumberOfPages - 0x%lx\n", Entry->NumberOfPages));
98 DEBUG ((DEBUG_INFO, " Attribute - 0x%lx\n", Entry->Attribute));
99
100 //
101 // Publish this table, so that other driver can use the buffer.
102 //
103 Status = gBS->InstallConfigurationTable (&gEdkiiPiSmmCommunicationRegionTableGuid, PiSmmCommunicationRegionTable);
104 ASSERT_EFI_ERROR (Status);
105
106 return Status;
107}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateReservedPool(IN UINTN AllocationSize)
VOID *EFIAPI AllocateReservedPages(IN UINTN Pages)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI SmmCommunicationBufferEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
@ EfiConventionalMemory
EFI_PHYSICAL_ADDRESS PhysicalStart
Definition: MmCommBuffer.h:31
UINT64 NumberOfPages
Definition: MmCommBuffer.h:36