]>
Commit | Line | Data |
---|---|---|
9e620719 | 1 | /** @file\r |
2 | SMM Access2 Protocol on SMM Access Protocol Thunk driver.\r | |
3 | \r | |
4 | Copyright (c) 2009 Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "SmmAccess2OnSmmAccessThunk.h"\r | |
16 | \r | |
17 | EFI_SMM_ACCESS2_PROTOCOL gSmmAccess2 = {\r | |
18 | SmmAccess2Open,\r | |
19 | SmmAccess2Close,\r | |
20 | SmmAccess2Lock,\r | |
21 | SmmAccess2GetCapabilities,\r | |
22 | FALSE,\r | |
23 | FALSE\r | |
24 | };\r | |
25 | \r | |
26 | EFI_SMM_ACCESS_PROTOCOL *mSmmAccess;\r | |
27 | UINTN mSmramRegionNumber;\r | |
28 | \r | |
29 | /**\r | |
30 | Opens the SMRAM area to be accessible by a boot-service driver.\r | |
31 | \r | |
32 | This function "opens" SMRAM so that it is visible while not inside of SMM. The function should \r | |
33 | return EFI_UNSUPPORTED if the hardware does not support hiding of SMRAM. The function \r | |
34 | should return EFI_DEVICE_ERROR if the SMRAM configuration is locked.\r | |
35 | \r | |
36 | @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.\r | |
37 | \r | |
38 | @retval EFI_SUCCESS The operation was successful.\r | |
39 | @retval EFI_UNSUPPORTED The system does not support opening and closing of SMRAM.\r | |
40 | @retval EFI_DEVICE_ERROR SMRAM cannot be opened, perhaps because it is locked.\r | |
41 | **/\r | |
42 | EFI_STATUS\r | |
43 | EFIAPI\r | |
44 | SmmAccess2Open (\r | |
45 | IN EFI_SMM_ACCESS2_PROTOCOL *This\r | |
46 | )\r | |
47 | {\r | |
48 | EFI_STATUS Status;\r | |
49 | UINTN DescriptorIndex;\r | |
50 | \r | |
51 | ///\r | |
52 | /// Open all SMRAM regions via SMM Access Protocol\r | |
53 | ///\r | |
54 | \r | |
55 | Status = EFI_SUCCESS;\r | |
56 | for (DescriptorIndex = 0; DescriptorIndex < mSmramRegionNumber && !EFI_ERROR (Status); DescriptorIndex++) {\r | |
57 | Status = mSmmAccess->Open (mSmmAccess, DescriptorIndex);\r | |
58 | }\r | |
59 | if (!EFI_ERROR (Status)) {\r | |
60 | gSmmAccess2.OpenState = TRUE;\r | |
61 | }\r | |
62 | return Status;\r | |
63 | }\r | |
64 | \r | |
65 | /**\r | |
66 | Inhibits access to the SMRAM.\r | |
67 | \r | |
68 | This function "closes" SMRAM so that it is not visible while outside of SMM. The function should \r | |
69 | return EFI_UNSUPPORTED if the hardware does not support hiding of SMRAM.\r | |
70 | \r | |
71 | @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.\r | |
72 | \r | |
73 | @retval EFI_SUCCESS The operation was successful.\r | |
74 | @retval EFI_UNSUPPORTED The system does not support opening and closing of SMRAM.\r | |
75 | @retval EFI_DEVICE_ERROR SMRAM cannot be closed.\r | |
76 | **/\r | |
77 | EFI_STATUS\r | |
78 | EFIAPI\r | |
79 | SmmAccess2Close (\r | |
80 | IN EFI_SMM_ACCESS2_PROTOCOL *This\r | |
81 | )\r | |
82 | {\r | |
83 | EFI_STATUS Status;\r | |
84 | UINTN DescriptorIndex;\r | |
85 | \r | |
86 | ///\r | |
87 | /// Close all SMRAM regions via SMM Access Protocol\r | |
88 | ///\r | |
89 | \r | |
90 | Status = EFI_SUCCESS;\r | |
91 | for (DescriptorIndex = 0; DescriptorIndex < mSmramRegionNumber && !EFI_ERROR (Status); DescriptorIndex++) {\r | |
92 | Status = mSmmAccess->Close (mSmmAccess, DescriptorIndex);\r | |
93 | }\r | |
94 | if (!EFI_ERROR (Status)) {\r | |
95 | gSmmAccess2.OpenState = FALSE;\r | |
96 | }\r | |
97 | return Status;\r | |
98 | }\r | |
99 | \r | |
100 | /**\r | |
101 | Inhibits access to the SMRAM.\r | |
102 | \r | |
103 | This function prohibits access to the SMRAM region. This function is usually implemented such \r | |
104 | that it is a write-once operation. \r | |
105 | \r | |
106 | @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.\r | |
107 | \r | |
108 | @retval EFI_SUCCESS The device was successfully locked.\r | |
109 | @retval EFI_UNSUPPORTED The system does not support locking of SMRAM.\r | |
110 | **/\r | |
111 | EFI_STATUS\r | |
112 | EFIAPI\r | |
113 | SmmAccess2Lock (\r | |
114 | IN EFI_SMM_ACCESS2_PROTOCOL *This\r | |
115 | )\r | |
116 | {\r | |
117 | EFI_STATUS Status;\r | |
118 | UINTN DescriptorIndex;\r | |
119 | \r | |
120 | ///\r | |
121 | /// Lock all SMRAM regions via SMM Access Protocol\r | |
122 | ///\r | |
123 | \r | |
124 | Status = EFI_SUCCESS;\r | |
125 | for (DescriptorIndex = 0; DescriptorIndex < mSmramRegionNumber && !EFI_ERROR (Status); DescriptorIndex++) {\r | |
126 | Status = mSmmAccess->Lock (mSmmAccess, DescriptorIndex);\r | |
127 | }\r | |
128 | if (!EFI_ERROR (Status)) {\r | |
129 | gSmmAccess2.LockState = TRUE;\r | |
130 | }\r | |
131 | return Status;\r | |
132 | }\r | |
133 | \r | |
134 | /**\r | |
135 | Queries the memory controller for the possible regions that will support SMRAM.\r | |
136 | \r | |
137 | @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.\r | |
138 | @param[in,out] SmramMapSize A pointer to the size, in bytes, of the SmramMemoryMap buffer.\r | |
139 | @param[in,out] SmramMap A pointer to the buffer in which firmware places the current memory map.\r | |
140 | \r | |
141 | @retval EFI_SUCCESS The chipset supported the given resource.\r | |
142 | @retval EFI_BUFFER_TOO_SMALL The SmramMap parameter was too small. The current buffer size \r | |
143 | needed to hold the memory map is returned in SmramMapSize.\r | |
144 | **/\r | |
145 | EFI_STATUS\r | |
146 | EFIAPI\r | |
147 | SmmAccess2GetCapabilities (\r | |
148 | IN CONST EFI_SMM_ACCESS2_PROTOCOL *This,\r | |
149 | IN OUT UINTN *SmramMapSize,\r | |
150 | IN OUT EFI_SMRAM_DESCRIPTOR *SmramMap\r | |
151 | )\r | |
152 | {\r | |
153 | return mSmmAccess->GetCapabilities (mSmmAccess, SmramMapSize, SmramMap);\r | |
154 | }\r | |
155 | \r | |
156 | /**\r | |
157 | Entry Point for SMM Access2 On SMM Access Thunk driver.\r | |
158 | \r | |
159 | @param[in] ImageHandle Image handle of this driver.\r | |
160 | @param[in] SystemTable A Pointer to the EFI System Table.\r | |
161 | \r | |
162 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
163 | @retval other Some error occurred when executing this entry point.\r | |
164 | **/\r | |
165 | EFI_STATUS\r | |
166 | EFIAPI\r | |
167 | SmmAccess2ThunkMain (\r | |
168 | IN EFI_HANDLE ImageHandle,\r | |
169 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
170 | )\r | |
171 | {\r | |
172 | EFI_STATUS Status;\r | |
173 | UINTN SmramMapSize;\r | |
174 | \r | |
175 | ///\r | |
176 | /// Locate SMM Access Protocol\r | |
177 | ///\r | |
178 | Status = gBS->LocateProtocol (&gEfiSmmAccessProtocolGuid, NULL, (VOID **)&mSmmAccess);\r | |
179 | ASSERT_EFI_ERROR (Status);\r | |
180 | \r | |
181 | ///\r | |
182 | /// Calculate number of SMRAM regions\r | |
183 | ///\r | |
184 | SmramMapSize = 0;\r | |
185 | Status = mSmmAccess->GetCapabilities (mSmmAccess, &SmramMapSize, NULL);\r | |
186 | ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r | |
187 | \r | |
188 | mSmramRegionNumber = SmramMapSize/sizeof (EFI_SMRAM_DESCRIPTOR);\r | |
189 | ASSERT (mSmramRegionNumber > 0);\r | |
190 | \r | |
191 | ///\r | |
192 | /// Assume all SMRAM regions have consistent OPEN and LOCK states\r | |
193 | ///\r | |
194 | gSmmAccess2.OpenState = mSmmAccess->OpenState;\r | |
195 | gSmmAccess2.LockState = mSmmAccess->LockState;\r | |
196 | \r | |
197 | ///\r | |
198 | /// Publish PI SMM Access2 Protocol\r | |
199 | ///\r | |
200 | Status = gBS->InstallProtocolInterface (\r | |
201 | &ImageHandle,\r | |
202 | &gEfiSmmAccess2ProtocolGuid,\r | |
203 | EFI_NATIVE_INTERFACE,\r | |
204 | &gSmmAccess2\r | |
205 | );\r | |
206 | return Status;\r | |
207 | }\r | |
208 | \r |