2 A driver allocates common SMM communication buffer in EfiReservedMemoryType.
4 This driver allocates common SMM communication buffer in EfiReservedMemoryType,
5 then it publishes the information to EFI configuration table with
6 gEdkiiPiSmmCommunicationRegionTableGuid.
7 Any other driver or application can get the table and know the common
10 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
11 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Library/UefiBootServicesTableLib.h>
17 #include <Library/UefiRuntimeServicesTableLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/UefiLib.h>
23 #include <Guid/PiSmmCommunicationRegionTable.h>
25 #define DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES 4
28 Entry Point for SMM communication buffer driver.
30 @param[in] ImageHandle Image handle of this driver.
31 @param[in] SystemTable A Pointer to the EFI System Table.
34 @return Others Some error occurs.
38 SmmCommunicationBufferEntryPoint (
39 IN EFI_HANDLE ImageHandle
,
40 IN EFI_SYSTEM_TABLE
*SystemTable
44 UINT32 DescriptorSize
;
45 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
*PiSmmCommunicationRegionTable
;
46 EFI_MEMORY_DESCRIPTOR
*Entry
;
48 DescriptorSize
= sizeof (EFI_MEMORY_DESCRIPTOR
);
50 // Make sure Size != sizeof(EFI_MEMORY_DESCRIPTOR). This will
51 // prevent people from having pointer math bugs in their code.
52 // now you have to use *DescriptorSize to make things work.
54 DescriptorSize
+= sizeof (UINT64
) - (DescriptorSize
% sizeof (UINT64
));
57 // Allocate and fill PiSmmCommunicationRegionTable
59 PiSmmCommunicationRegionTable
= AllocateReservedPool (sizeof (EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
) + DescriptorSize
);
60 ASSERT (PiSmmCommunicationRegionTable
!= NULL
);
61 ZeroMem (PiSmmCommunicationRegionTable
, sizeof (EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
) + DescriptorSize
);
63 PiSmmCommunicationRegionTable
->Version
= EDKII_PI_SMM_COMMUNICATION_REGION_TABLE_VERSION
;
64 PiSmmCommunicationRegionTable
->NumberOfEntries
= 1;
65 PiSmmCommunicationRegionTable
->DescriptorSize
= DescriptorSize
;
66 Entry
= (EFI_MEMORY_DESCRIPTOR
*)(PiSmmCommunicationRegionTable
+ 1);
67 Entry
->Type
= EfiConventionalMemory
;
68 Entry
->PhysicalStart
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)AllocateReservedPages (DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES
);
69 ASSERT (Entry
->PhysicalStart
!= 0);
70 Entry
->VirtualStart
= 0;
71 Entry
->NumberOfPages
= DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES
;
74 DEBUG ((DEBUG_INFO
, "PiSmmCommunicationRegionTable:(0x%x)\n", PiSmmCommunicationRegionTable
));
75 DEBUG ((DEBUG_INFO
, " Version - 0x%x\n", PiSmmCommunicationRegionTable
->Version
));
76 DEBUG ((DEBUG_INFO
, " NumberOfEntries - 0x%x\n", PiSmmCommunicationRegionTable
->NumberOfEntries
));
77 DEBUG ((DEBUG_INFO
, " DescriptorSize - 0x%x\n", PiSmmCommunicationRegionTable
->DescriptorSize
));
78 DEBUG ((DEBUG_INFO
, "Entry:(0x%x)\n", Entry
));
79 DEBUG ((DEBUG_INFO
, " Type - 0x%x\n", Entry
->Type
));
80 DEBUG ((DEBUG_INFO
, " PhysicalStart - 0x%lx\n", Entry
->PhysicalStart
));
81 DEBUG ((DEBUG_INFO
, " VirtualStart - 0x%lx\n", Entry
->VirtualStart
));
82 DEBUG ((DEBUG_INFO
, " NumberOfPages - 0x%lx\n", Entry
->NumberOfPages
));
83 DEBUG ((DEBUG_INFO
, " Attribute - 0x%lx\n", Entry
->Attribute
));
86 // Publish this table, so that other driver can use the buffer.
88 Status
= gBS
->InstallConfigurationTable (&gEdkiiPiSmmCommunicationRegionTableGuid
, PiSmmCommunicationRegionTable
);
89 ASSERT_EFI_ERROR (Status
);