VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/SmmAccess/SmmAccess2Dxe.c@ 101297

Last change on this file since 101297 was 99404, checked in by vboxsync, 23 months ago

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

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

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