]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[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
9d510e61 11SPDX-License-Identifier: BSD-2-Clause-Patent\r
6e4e6ffd
JY
12\r
13**/\r
14\r
15#include <PiDxe.h>\r
16#include <Library/UefiBootServicesTableLib.h>\r
17#include <Library/UefiRuntimeServicesTableLib.h>\r
18#include <Library/BaseLib.h>\r
19#include <Library/BaseMemoryLib.h>\r
20#include <Library/MemoryAllocationLib.h>\r
21#include <Library/DebugLib.h>\r
22#include <Library/UefiLib.h>\r
6e4e6ffd
JY
23#include <Guid/PiSmmCommunicationRegionTable.h>\r
24\r
25#define DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES 4\r
26\r
27/**\r
28 Entry Point for SMM communication buffer driver.\r
29\r
30 @param[in] ImageHandle Image handle of this driver.\r
31 @param[in] SystemTable A Pointer to the EFI System Table.\r
32\r
33 @retval EFI_SUCEESS\r
34 @return Others Some error occurs.\r
35**/\r
36EFI_STATUS\r
37EFIAPI\r
38SmmCommunicationBufferEntryPoint (\r
39 IN EFI_HANDLE ImageHandle,\r
40 IN EFI_SYSTEM_TABLE *SystemTable\r
41 )\r
42{\r
43 EFI_STATUS Status;\r
44 UINT32 DescriptorSize;\r
45 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable;\r
46 EFI_MEMORY_DESCRIPTOR *Entry;\r
47\r
48 DescriptorSize = sizeof(EFI_MEMORY_DESCRIPTOR);\r
49 //\r
50 // Make sure Size != sizeof(EFI_MEMORY_DESCRIPTOR). This will\r
51 // prevent people from having pointer math bugs in their code.\r
52 // now you have to use *DescriptorSize to make things work.\r
53 //\r
54 DescriptorSize += sizeof(UINT64) - (DescriptorSize % sizeof (UINT64));\r
55\r
56 //\r
57 // Allocate and fill PiSmmCommunicationRegionTable\r
58 //\r
59 PiSmmCommunicationRegionTable = AllocateReservedPool (sizeof(EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);\r
60 ASSERT(PiSmmCommunicationRegionTable != NULL);\r
61 ZeroMem (PiSmmCommunicationRegionTable, sizeof(EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);\r
62\r
63 PiSmmCommunicationRegionTable->Version = EDKII_PI_SMM_COMMUNICATION_REGION_TABLE_VERSION;\r
64 PiSmmCommunicationRegionTable->NumberOfEntries = 1;\r
65 PiSmmCommunicationRegionTable->DescriptorSize = DescriptorSize;\r
66 Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);\r
67 Entry->Type = EfiConventionalMemory;\r
68 Entry->PhysicalStart = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedPages (DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES);\r
69 ASSERT(Entry->PhysicalStart != 0);\r
70 Entry->VirtualStart = 0;\r
71 Entry->NumberOfPages = DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES;\r
72 Entry->Attribute = 0;\r
73\r
74 DEBUG ((EFI_D_INFO, "PiSmmCommunicationRegionTable:(0x%x)\n", PiSmmCommunicationRegionTable));\r
75 DEBUG ((EFI_D_INFO, " Version - 0x%x\n", PiSmmCommunicationRegionTable->Version));\r
76 DEBUG ((EFI_D_INFO, " NumberOfEntries - 0x%x\n", PiSmmCommunicationRegionTable->NumberOfEntries));\r
77 DEBUG ((EFI_D_INFO, " DescriptorSize - 0x%x\n", PiSmmCommunicationRegionTable->DescriptorSize));\r
78 DEBUG ((EFI_D_INFO, "Entry:(0x%x)\n", Entry));\r
79 DEBUG ((EFI_D_INFO, " Type - 0x%x\n", Entry->Type));\r
80 DEBUG ((EFI_D_INFO, " PhysicalStart - 0x%lx\n", Entry->PhysicalStart));\r
81 DEBUG ((EFI_D_INFO, " VirtualStart - 0x%lx\n", Entry->VirtualStart));\r
82 DEBUG ((EFI_D_INFO, " NumberOfPages - 0x%lx\n", Entry->NumberOfPages));\r
83 DEBUG ((EFI_D_INFO, " Attribute - 0x%lx\n", Entry->Attribute));\r
84\r
85 //\r
86 // Publish this table, so that other driver can use the buffer.\r
87 //\r
88 Status = gBS->InstallConfigurationTable (&gEdkiiPiSmmCommunicationRegionTableGuid, PiSmmCommunicationRegionTable);\r
89 ASSERT_EFI_ERROR (Status);\r
90\r
91 return Status;\r
92}\r