VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.c@ 108794

Last change on this file since 108794 was 108794, checked in by vboxsync, 3 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1/** @file
2A driver allocates common SMM communication buffer in EfiReservedMemoryType.
3
4This driver allocates common SMM communication buffer in EfiReservedMemoryType,
5then it publishes the information to EFI configuration table with
6gEdkiiPiSmmCommunicationRegionTableGuid.
7Any other driver or application can get the table and know the common
8communication buffer.
9
10Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
11SPDX-License-Identifier: BSD-2-Clause-Patent
12
13**/
14
15#include <PiDxe.h>
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/HobLib.h>
23#include <Library/UefiLib.h>
24#include <Guid/MmCommBuffer.h>
25#include <Guid/PiSmmCommunicationRegionTable.h>
26
27#define DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES 4
28
29/**
30 Entry Point for SMM communication buffer driver.
31
32 @param[in] ImageHandle Image handle of this driver.
33 @param[in] SystemTable A Pointer to the EFI System Table.
34
35 @retval EFI_SUCEESS
36 @return Others Some error occurs.
37**/
38EFI_STATUS
39EFIAPI
40SmmCommunicationBufferEntryPoint (
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;
48 EFI_MEMORY_DESCRIPTOR *Entry;
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}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette