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