VirtualBox

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

Last change on this file since 99404 was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 3.9 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/UefiLib.h>
23#include <Guid/PiSmmCommunicationRegionTable.h>
24
25#define DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES 4
26
27/**
28 Entry Point for SMM communication buffer driver.
29
30 @param[in] ImageHandle Image handle of this driver.
31 @param[in] SystemTable A Pointer to the EFI System Table.
32
33 @retval EFI_SUCEESS
34 @return Others Some error occurs.
35**/
36EFI_STATUS
37EFIAPI
38SmmCommunicationBufferEntryPoint (
39 IN EFI_HANDLE ImageHandle,
40 IN EFI_SYSTEM_TABLE *SystemTable
41 )
42{
43 EFI_STATUS Status;
44 UINT32 DescriptorSize;
45 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable;
46 EFI_MEMORY_DESCRIPTOR *Entry;
47
48 DescriptorSize = sizeof (EFI_MEMORY_DESCRIPTOR);
49 //
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.
53 //
54 DescriptorSize += sizeof (UINT64) - (DescriptorSize % sizeof (UINT64));
55
56 //
57 // Allocate and fill PiSmmCommunicationRegionTable
58 //
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);
62
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;
72 Entry->Attribute = 0;
73
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));
84
85 //
86 // Publish this table, so that other driver can use the buffer.
87 //
88 Status = gBS->InstallConfigurationTable (&gEdkiiPiSmmCommunicationRegionTableGuid, PiSmmCommunicationRegionTable);
89 ASSERT_EFI_ERROR (Status);
90
91 return Status;
92}
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