]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/SmmAccess/SmmAccess2Dxe.c
OvmfPkg/Csm/LegacyBiosDxe: Fix Legacy16GetTableAddress call for E820 data
[mirror_edk2.git] / OvmfPkg / SmmAccess / SmmAccess2Dxe.c
CommitLineData
c5b7c805
LE
1/** @file\r
2\r
3 A DXE_DRIVER providing SMRAM access by producing EFI_SMM_ACCESS2_PROTOCOL.\r
4\r
5 Q35 TSEG is expected to have been verified and set up by the SmmAccessPei\r
6 driver.\r
7\r
8 Copyright (C) 2013, 2015, Red Hat, Inc.<BR>\r
9 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
10\r
b26f0cf9 11 SPDX-License-Identifier: BSD-2-Clause-Patent\r
c5b7c805
LE
12\r
13**/\r
14\r
15#include <Library/DebugLib.h>\r
16#include <Library/PcdLib.h>\r
17#include <Library/UefiBootServicesTableLib.h>\r
18#include <Protocol/SmmAccess2.h>\r
19\r
20#include "SmramInternal.h"\r
21\r
22/**\r
23 Opens the SMRAM area to be accessible by a boot-service driver.\r
24\r
25 This function "opens" SMRAM so that it is visible while not inside of SMM.\r
26 The function should return EFI_UNSUPPORTED if the hardware does not support\r
27 hiding of SMRAM. The function should return EFI_DEVICE_ERROR if the SMRAM\r
28 configuration is locked.\r
29\r
30 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.\r
31\r
32 @retval EFI_SUCCESS The operation was successful.\r
33 @retval EFI_UNSUPPORTED The system does not support opening and closing of\r
34 SMRAM.\r
35 @retval EFI_DEVICE_ERROR SMRAM cannot be opened, perhaps because it is\r
36 locked.\r
37**/\r
38STATIC\r
39EFI_STATUS\r
40EFIAPI\r
41SmmAccess2DxeOpen (\r
42 IN EFI_SMM_ACCESS2_PROTOCOL *This\r
43 )\r
44{\r
45 return SmramAccessOpen (&This->LockState, &This->OpenState);\r
46}\r
47\r
48/**\r
49 Inhibits access to the SMRAM.\r
50\r
51 This function "closes" SMRAM so that it is not visible while outside of SMM.\r
52 The function should return EFI_UNSUPPORTED if the hardware does not support\r
53 hiding of SMRAM.\r
54\r
55 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.\r
56\r
57 @retval EFI_SUCCESS The operation was successful.\r
58 @retval EFI_UNSUPPORTED The system does not support opening and closing of\r
59 SMRAM.\r
60 @retval EFI_DEVICE_ERROR SMRAM cannot be closed.\r
61**/\r
62STATIC\r
63EFI_STATUS\r
64EFIAPI\r
65SmmAccess2DxeClose (\r
66 IN EFI_SMM_ACCESS2_PROTOCOL *This\r
67 )\r
68{\r
69 return SmramAccessClose (&This->LockState, &This->OpenState);\r
70}\r
71\r
72/**\r
73 Inhibits access to the SMRAM.\r
74\r
75 This function prohibits access to the SMRAM region. This function is usually\r
76 implemented such that it is a write-once operation.\r
77\r
78 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.\r
79\r
80 @retval EFI_SUCCESS The device was successfully locked.\r
81 @retval EFI_UNSUPPORTED The system does not support locking of SMRAM.\r
82**/\r
83STATIC\r
84EFI_STATUS\r
85EFIAPI\r
86SmmAccess2DxeLock (\r
87 IN EFI_SMM_ACCESS2_PROTOCOL *This\r
88 )\r
89{\r
90 return SmramAccessLock (&This->LockState, &This->OpenState);\r
91}\r
92\r
93/**\r
94 Queries the memory controller for the possible regions that will support\r
95 SMRAM.\r
96\r
97 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.\r
98 @param[in,out] SmramMapSize A pointer to the size, in bytes, of the\r
99 SmramMemoryMap buffer.\r
100 @param[in,out] SmramMap A pointer to the buffer in which firmware\r
101 places the current memory map.\r
102\r
103 @retval EFI_SUCCESS The chipset supported the given resource.\r
104 @retval EFI_BUFFER_TOO_SMALL The SmramMap parameter was too small. The\r
105 current buffer size needed to hold the memory\r
106 map is returned in SmramMapSize.\r
107**/\r
108STATIC\r
109EFI_STATUS\r
110EFIAPI\r
111SmmAccess2DxeGetCapabilities (\r
112 IN CONST EFI_SMM_ACCESS2_PROTOCOL *This,\r
113 IN OUT UINTN *SmramMapSize,\r
114 IN OUT EFI_SMRAM_DESCRIPTOR *SmramMap\r
115 )\r
116{\r
117 return SmramAccessGetCapabilities (This->LockState, This->OpenState,\r
118 SmramMapSize, SmramMap);\r
119}\r
120\r
121//\r
122// LockState and OpenState will be filled in by the entry point.\r
123//\r
124STATIC EFI_SMM_ACCESS2_PROTOCOL mAccess2 = {\r
125 &SmmAccess2DxeOpen,\r
126 &SmmAccess2DxeClose,\r
127 &SmmAccess2DxeLock,\r
128 &SmmAccess2DxeGetCapabilities\r
129};\r
130\r
131//\r
132// Entry point of this driver.\r
133//\r
134EFI_STATUS\r
135EFIAPI\r
136SmmAccess2DxeEntryPoint (\r
137 IN EFI_HANDLE ImageHandle,\r
138 IN EFI_SYSTEM_TABLE *SystemTable\r
139 )\r
140{\r
141 //\r
142 // This module should only be included if SMRAM support is required.\r
143 //\r
144 ASSERT (FeaturePcdGet (PcdSmmSmramRequire));\r
145\r
1372f8d3 146 InitQ35TsegMbytes ();\r
c5b7c805
LE
147 GetStates (&mAccess2.LockState, &mAccess2.OpenState);\r
148 return gBS->InstallMultipleProtocolInterfaces (&ImageHandle,\r
149 &gEfiSmmAccess2ProtocolGuid, &mAccess2,\r
150 NULL);\r
151}\r