]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/DxeSmmDriverEntryPoint/DriverEntryPoint.c
Fix unknown character in header comments which break build.
[mirror_edk2.git] / IntelFrameworkPkg / Library / DxeSmmDriverEntryPoint / DriverEntryPoint.c
CommitLineData
79964ac8 1/** @file\r
2 Entry point to a EFI/DXE driver.\r
3\r
4Copyright (c) 2006, Intel Corporation<BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
ed7748fe 15\r
564995cd 16#include <FrameworkSmm.h>\r
ed7748fe 17\r
564995cd 18#include <Protocol/LoadedImage.h>\r
19#include <Protocol/SmmBase.h>\r
20#include <Protocol/DevicePath.h>\r
ed7748fe 21\r
564995cd 22#include <Library/DxeSmmDriverEntryPoint.h>\r
79964ac8 23#include <Library/UefiBootServicesTableLib.h>\r
24#include <Library/DebugLib.h>\r
79964ac8 25\r
79964ac8 26\r
27EFI_BOOT_SERVICES *mBS;\r
28\r
29/**\r
30 This function returns the size, in bytes,\r
31 of the device path data structure specified by DevicePath.\r
32 If DevicePath is NULL, then 0 is returned.\r
33\r
34 @param DevicePath A pointer to a device path data structure.\r
35\r
36 @return The size of a device path in bytes.\r
37\r
38**/\r
39STATIC\r
40UINTN\r
41EFIAPI\r
42SmmGetDevicePathSize (\r
43 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
44 )\r
45{\r
46 CONST EFI_DEVICE_PATH_PROTOCOL *Start;\r
47\r
48 if (DevicePath == NULL) {\r
49 return 0;\r
50 }\r
51\r
52 //\r
53 // Search for the end of the device path structure\r
54 //\r
55 Start = DevicePath;\r
56 while (!EfiIsDevicePathEnd (DevicePath)) {\r
57 DevicePath = EfiNextDevicePathNode (DevicePath);\r
58 }\r
59\r
60 //\r
61 // Compute the size and add back in the size of the end device path structure\r
62 //\r
63 return ((UINTN) DevicePath - (UINTN) Start) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
64}\r
65\r
66/**\r
67 This function appends the device path SecondDevicePath\r
68 to every device path instance in FirstDevicePath.\r
69\r
70 @param FirstDevicePath A pointer to a device path data structure.\r
71\r
72 @param SecondDevicePath A pointer to a device path data structure.\r
73\r
74 @return A pointer to the new device path is returned.\r
75 NULL is returned if space for the new device path could not be allocated from pool.\r
76 It is up to the caller to free the memory used by FirstDevicePath and SecondDevicePath\r
77 if they are no longer needed.\r
78\r
79**/\r
80EFI_DEVICE_PATH_PROTOCOL *\r
81EFIAPI\r
82SmmAppendDevicePath (\r
83 IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,\r
84 IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath\r
85 )\r
86{\r
87 EFI_STATUS Status;\r
88 UINTN Size;\r
89 UINTN Size1;\r
90 UINTN Size2;\r
91 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
92 EFI_DEVICE_PATH_PROTOCOL *DevicePath2;\r
93\r
94 ASSERT (FirstDevicePath != NULL && SecondDevicePath != NULL);\r
95\r
96 //\r
97 // Allocate space for the combined device path. It only has one end node of\r
98 // length EFI_DEVICE_PATH_PROTOCOL\r
99 //\r
100 Size1 = SmmGetDevicePathSize (FirstDevicePath);\r
101 Size2 = SmmGetDevicePathSize (SecondDevicePath);\r
102 Size = Size1 + Size2 - sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
103\r
104 Status = mBS->AllocatePool (EfiBootServicesData, Size, (VOID **) &NewDevicePath);\r
105\r
106 if (EFI_SUCCESS == Status) {\r
107 mBS->CopyMem ((VOID *) NewDevicePath, (VOID *) FirstDevicePath, Size1);\r
108 //\r
109 // Over write Src1 EndNode and do the copy\r
110 //\r
111 DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath + (Size1 - sizeof (EFI_DEVICE_PATH_PROTOCOL)));\r
112 mBS->CopyMem ((VOID *) DevicePath2, (VOID *) SecondDevicePath, Size2);\r
113 }\r
114\r
115 return NewDevicePath;\r
116}\r
117\r
118/**\r
119 Unload function that is registered in the LoadImage protocol. It un-installs\r
120 protocols produced and deallocates pool used by the driver. Called by the core\r
121 when unloading the driver.\r
122\r
123 @param ImageHandle ImageHandle of the unloaded driver\r
124\r
125 @return Status of the ProcessModuleUnloadList.\r
126\r
127**/\r
128EFI_STATUS\r
129EFIAPI\r
130_DriverUnloadHandler (\r
131 EFI_HANDLE ImageHandle\r
132 )\r
133{\r
134 EFI_STATUS Status;\r
135\r
136 //\r
137 // Call the unload handlers for all the modules\r
138 //\r
139 Status = ProcessModuleUnloadList (ImageHandle);\r
140\r
141 //\r
142 // If the driver specific unload handler does not return an error, then call all of the\r
143 // library destructors. If the unload handler returned an error, then the driver can not be\r
144 // unloaded, and the library destructors should not be called\r
145 //\r
146 if (!EFI_ERROR (Status)) {\r
147 ProcessLibraryDestructorList (ImageHandle, gST);\r
148 }\r
149\r
150 //\r
151 // Return the status from the driver specific unload handler\r
152 //\r
153 return Status;\r
154}\r
155\r
156/**\r
157 Enrty point to DXE SMM Driver.\r
158\r
159 @param ImageHandle ImageHandle of the loaded driver.\r
160 @param SystemTable Pointer to the EFI System Table.\r
161\r
162 @retval EFI_SUCCESS One or more of the drivers returned a success code.\r
163 @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r
164\r
165**/\r
166EFI_STATUS\r
167EFIAPI\r
168_ModuleEntryPoint (\r
169 IN EFI_HANDLE ImageHandle,\r
170 IN EFI_SYSTEM_TABLE *SystemTable\r
171 )\r
172{\r
173 EFI_STATUS Status;\r
174 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
175 EFI_SMM_BASE_PROTOCOL *SmmBase;\r
176 BOOLEAN InSmm;\r
177 EFI_DEVICE_PATH_PROTOCOL *CompleteFilePath;\r
178 EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath;\r
179 EFI_HANDLE Handle;\r
180\r
181 //\r
182 // Cache a pointer to the Boot Services Table\r
183 //\r
184 mBS = SystemTable->BootServices;\r
185\r
186 //\r
187 // Retrieve the Loaded Image Protocol\r
188 //\r
189 Status = mBS->HandleProtocol (\r
190 ImageHandle,\r
191 &gEfiLoadedImageProtocolGuid,\r
192 (VOID*)&LoadedImage\r
193 );\r
194 ASSERT_EFI_ERROR (Status);\r
195\r
196 //\r
197 // Retrieve SMM Base Protocol\r
198 //\r
199 Status = mBS->LocateProtocol (\r
200 &gEfiSmmBaseProtocolGuid,\r
201 NULL,\r
202 (VOID **) &SmmBase\r
203 );\r
204 ASSERT_EFI_ERROR (Status);\r
205\r
206 //\r
207 // Check to see if we are already in SMM\r
208 //\r
209 SmmBase->InSmm (SmmBase, &InSmm);\r
210\r
211 //\r
212 //\r
213 //\r
214 if (!InSmm) {\r
215 //\r
216 // Retrieve the Device Path Protocol from the DeviceHandle tha this driver was loaded from\r
217 //\r
218 Status = mBS->HandleProtocol (\r
219 LoadedImage->DeviceHandle,\r
220 &gEfiDevicePathProtocolGuid,\r
221 (VOID*)&ImageDevicePath\r
222 );\r
223 ASSERT_EFI_ERROR (Status);\r
224\r
225 //\r
226 // Build the full device path to the currently execuing image\r
227 //\r
228 CompleteFilePath = SmmAppendDevicePath (ImageDevicePath, LoadedImage->FilePath);\r
229\r
230 //\r
231 // Load the image in memory to SMRAM; it will automatically generate the\r
232 // SMI.\r
233 //\r
234 Status = SmmBase->Register (SmmBase, CompleteFilePath, NULL, 0, &Handle, FALSE);\r
235 ASSERT_EFI_ERROR (Status);\r
236 return Status;\r
237 }\r
238\r
239 //\r
240 // Call constructor for all libraries\r
241 //\r
242 ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
243\r
244 //\r
245 // Optionally install the unload handler\r
246 //\r
247 if (_gDriverUnloadImageCount > 0) {\r
248 Status = mBS->HandleProtocol (\r
249 ImageHandle,\r
250 &gEfiLoadedImageProtocolGuid,\r
251 (VOID **)&LoadedImage\r
252 );\r
253 ASSERT_EFI_ERROR (Status);\r
254 LoadedImage->Unload = _DriverUnloadHandler;\r
255 }\r
256\r
257 //\r
258 // Call the list of driver entry points\r
259 //\r
260 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
261 if (EFI_ERROR (Status)) {\r
262 ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
263 }\r
264\r
265 return Status;\r
266}\r
267\r
268/**\r
269 Enrty point wrapper of DXE SMM Driver.\r
270\r
271 @param ImageHandle ImageHandle of the loaded driver.\r
272 @param SystemTable Pointer to the EFI System Table.\r
273\r
274 @retval EFI_SUCCESS One or more of the drivers returned a success code.\r
275 @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r
276\r
277**/\r
278EFI_STATUS\r
279EFIAPI\r
280EfiMain (\r
281 IN EFI_HANDLE ImageHandle,\r
282 IN EFI_SYSTEM_TABLE *SystemTable\r
283 )\r
284{\r
285 return _ModuleEntryPoint (ImageHandle, SystemTable);\r
286}\r