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 | SPDX-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 | **/
|
---|
36 | EFI_STATUS
|
---|
37 | EFIAPI
|
---|
38 | SmmCommunicationBufferEntryPoint (
|
---|
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 ((EFI_D_INFO, "PiSmmCommunicationRegionTable:(0x%x)\n", PiSmmCommunicationRegionTable));
|
---|
75 | DEBUG ((EFI_D_INFO, " Version - 0x%x\n", PiSmmCommunicationRegionTable->Version));
|
---|
76 | DEBUG ((EFI_D_INFO, " NumberOfEntries - 0x%x\n", PiSmmCommunicationRegionTable->NumberOfEntries));
|
---|
77 | DEBUG ((EFI_D_INFO, " DescriptorSize - 0x%x\n", PiSmmCommunicationRegionTable->DescriptorSize));
|
---|
78 | DEBUG ((EFI_D_INFO, "Entry:(0x%x)\n", Entry));
|
---|
79 | DEBUG ((EFI_D_INFO, " Type - 0x%x\n", Entry->Type));
|
---|
80 | DEBUG ((EFI_D_INFO, " PhysicalStart - 0x%lx\n", Entry->PhysicalStart));
|
---|
81 | DEBUG ((EFI_D_INFO, " VirtualStart - 0x%lx\n", Entry->VirtualStart));
|
---|
82 | DEBUG ((EFI_D_INFO, " NumberOfPages - 0x%lx\n", Entry->NumberOfPages));
|
---|
83 | DEBUG ((EFI_D_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 | }
|
---|