]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.c
MdeModulePkg: Add new driver to publish EDKII_PI_SMM_COMMUNICATION_REGION_TABLE.
[mirror_edk2.git] / MdeModulePkg / Universal / SmmCommunicationBufferDxe / SmmCommunicationBufferDxe.c
CommitLineData
6e4e6ffd
JY
1/** @file\r
2A driver allocates common SMM communication buffer in EfiReservedMemoryType.\r
3\r
4This driver allocates common SMM communication buffer in EfiReservedMemoryType,\r
5then it publishes the information to EFI configuration table with\r
6gEdkiiPiSmmCommunicationRegionTableGuid.\r
7Any other driver or application can get the table and know the common\r
8communication buffer.\r
9\r
10Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
11This program and the accompanying materials\r
12are licensed and made available under the terms and conditions of the BSD License\r
13which accompanies this distribution. The full text of the license may be found at\r
14http://opensource.org/licenses/bsd-license.php\r
15\r
16THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
17WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
18\r
19**/\r
20\r
21#include <PiDxe.h>\r
22#include <Library/UefiBootServicesTableLib.h>\r
23#include <Library/UefiRuntimeServicesTableLib.h>\r
24#include <Library/BaseLib.h>\r
25#include <Library/BaseMemoryLib.h>\r
26#include <Library/MemoryAllocationLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/UefiLib.h>\r
29#include <Library/PcdLib.h>\r
30#include <Guid/PiSmmCommunicationRegionTable.h>\r
31\r
32#define DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES 4\r
33\r
34/**\r
35 Entry Point for SMM communication buffer driver.\r
36\r
37 @param[in] ImageHandle Image handle of this driver.\r
38 @param[in] SystemTable A Pointer to the EFI System Table.\r
39\r
40 @retval EFI_SUCEESS\r
41 @return Others Some error occurs.\r
42**/\r
43EFI_STATUS\r
44EFIAPI\r
45SmmCommunicationBufferEntryPoint (\r
46 IN EFI_HANDLE ImageHandle,\r
47 IN EFI_SYSTEM_TABLE *SystemTable\r
48 )\r
49{\r
50 EFI_STATUS Status;\r
51 UINT32 DescriptorSize;\r
52 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable;\r
53 EFI_MEMORY_DESCRIPTOR *Entry;\r
54\r
55 DescriptorSize = sizeof(EFI_MEMORY_DESCRIPTOR);\r
56 //\r
57 // Make sure Size != sizeof(EFI_MEMORY_DESCRIPTOR). This will\r
58 // prevent people from having pointer math bugs in their code.\r
59 // now you have to use *DescriptorSize to make things work.\r
60 //\r
61 DescriptorSize += sizeof(UINT64) - (DescriptorSize % sizeof (UINT64));\r
62\r
63 //\r
64 // Allocate and fill PiSmmCommunicationRegionTable\r
65 //\r
66 PiSmmCommunicationRegionTable = AllocateReservedPool (sizeof(EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);\r
67 ASSERT(PiSmmCommunicationRegionTable != NULL);\r
68 ZeroMem (PiSmmCommunicationRegionTable, sizeof(EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);\r
69\r
70 PiSmmCommunicationRegionTable->Version = EDKII_PI_SMM_COMMUNICATION_REGION_TABLE_VERSION;\r
71 PiSmmCommunicationRegionTable->NumberOfEntries = 1;\r
72 PiSmmCommunicationRegionTable->DescriptorSize = DescriptorSize;\r
73 Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);\r
74 Entry->Type = EfiConventionalMemory;\r
75 Entry->PhysicalStart = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedPages (DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES);\r
76 ASSERT(Entry->PhysicalStart != 0);\r
77 Entry->VirtualStart = 0;\r
78 Entry->NumberOfPages = DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES;\r
79 Entry->Attribute = 0;\r
80\r
81 DEBUG ((EFI_D_INFO, "PiSmmCommunicationRegionTable:(0x%x)\n", PiSmmCommunicationRegionTable));\r
82 DEBUG ((EFI_D_INFO, " Version - 0x%x\n", PiSmmCommunicationRegionTable->Version));\r
83 DEBUG ((EFI_D_INFO, " NumberOfEntries - 0x%x\n", PiSmmCommunicationRegionTable->NumberOfEntries));\r
84 DEBUG ((EFI_D_INFO, " DescriptorSize - 0x%x\n", PiSmmCommunicationRegionTable->DescriptorSize));\r
85 DEBUG ((EFI_D_INFO, "Entry:(0x%x)\n", Entry));\r
86 DEBUG ((EFI_D_INFO, " Type - 0x%x\n", Entry->Type));\r
87 DEBUG ((EFI_D_INFO, " PhysicalStart - 0x%lx\n", Entry->PhysicalStart));\r
88 DEBUG ((EFI_D_INFO, " VirtualStart - 0x%lx\n", Entry->VirtualStart));\r
89 DEBUG ((EFI_D_INFO, " NumberOfPages - 0x%lx\n", Entry->NumberOfPages));\r
90 DEBUG ((EFI_D_INFO, " Attribute - 0x%lx\n", Entry->Attribute));\r
91\r
92 //\r
93 // Publish this table, so that other driver can use the buffer.\r
94 //\r
95 Status = gBS->InstallConfigurationTable (&gEdkiiPiSmmCommunicationRegionTableGuid, PiSmmCommunicationRegionTable);\r
96 ASSERT_EFI_ERROR (Status);\r
97\r
98 return Status;\r
99}\r