• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <Library/PcdLib.h>
30 #include <Guid/PiSmmCommunicationRegionTable.h>
31 
32 #define DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES  4
33 
34 /**
35   Entry Point for SMM communication buffer driver.
36 
37   @param[in] ImageHandle  Image handle of this driver.
38   @param[in] SystemTable  A Pointer to the EFI System Table.
39 
40   @retval EFI_SUCEESS
41   @return Others          Some error occurs.
42 **/
43 EFI_STATUS
44 EFIAPI
SmmCommunicationBufferEntryPoint(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)45 SmmCommunicationBufferEntryPoint (
46   IN EFI_HANDLE        ImageHandle,
47   IN EFI_SYSTEM_TABLE  *SystemTable
48   )
49 {
50   EFI_STATUS                               Status;
51   UINT32                                   DescriptorSize;
52   EDKII_PI_SMM_COMMUNICATION_REGION_TABLE  *PiSmmCommunicationRegionTable;
53   EFI_MEMORY_DESCRIPTOR                    *Entry;
54 
55   DescriptorSize = sizeof(EFI_MEMORY_DESCRIPTOR);
56   //
57   // Make sure Size != sizeof(EFI_MEMORY_DESCRIPTOR). This will
58   // prevent people from having pointer math bugs in their code.
59   // now you have to use *DescriptorSize to make things work.
60   //
61   DescriptorSize += sizeof(UINT64) - (DescriptorSize % sizeof (UINT64));
62 
63   //
64   // Allocate and fill PiSmmCommunicationRegionTable
65   //
66   PiSmmCommunicationRegionTable = AllocateReservedPool (sizeof(EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);
67   ASSERT(PiSmmCommunicationRegionTable != NULL);
68   ZeroMem (PiSmmCommunicationRegionTable, sizeof(EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);
69 
70   PiSmmCommunicationRegionTable->Version         = EDKII_PI_SMM_COMMUNICATION_REGION_TABLE_VERSION;
71   PiSmmCommunicationRegionTable->NumberOfEntries = 1;
72   PiSmmCommunicationRegionTable->DescriptorSize  = DescriptorSize;
73   Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);
74   Entry->Type          = EfiConventionalMemory;
75   Entry->PhysicalStart = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedPages (DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES);
76   ASSERT(Entry->PhysicalStart != 0);
77   Entry->VirtualStart  = 0;
78   Entry->NumberOfPages = DEFAULT_COMMON_PI_SMM_COMMUNIATION_REGION_PAGES;
79   Entry->Attribute     = 0;
80 
81   DEBUG ((EFI_D_INFO, "PiSmmCommunicationRegionTable:(0x%x)\n", PiSmmCommunicationRegionTable));
82   DEBUG ((EFI_D_INFO, "  Version         - 0x%x\n", PiSmmCommunicationRegionTable->Version));
83   DEBUG ((EFI_D_INFO, "  NumberOfEntries - 0x%x\n", PiSmmCommunicationRegionTable->NumberOfEntries));
84   DEBUG ((EFI_D_INFO, "  DescriptorSize  - 0x%x\n", PiSmmCommunicationRegionTable->DescriptorSize));
85   DEBUG ((EFI_D_INFO, "Entry:(0x%x)\n", Entry));
86   DEBUG ((EFI_D_INFO, "  Type            - 0x%x\n", Entry->Type));
87   DEBUG ((EFI_D_INFO, "  PhysicalStart   - 0x%lx\n", Entry->PhysicalStart));
88   DEBUG ((EFI_D_INFO, "  VirtualStart    - 0x%lx\n", Entry->VirtualStart));
89   DEBUG ((EFI_D_INFO, "  NumberOfPages   - 0x%lx\n", Entry->NumberOfPages));
90   DEBUG ((EFI_D_INFO, "  Attribute       - 0x%lx\n", Entry->Attribute));
91 
92   //
93   // Publish this table, so that other driver can use the buffer.
94   //
95   Status = gBS->InstallConfigurationTable (&gEdkiiPiSmmCommunicationRegionTableGuid, PiSmmCommunicationRegionTable);
96   ASSERT_EFI_ERROR (Status);
97 
98   return Status;
99 }
100