2 Entry point to a EFI/DXE driver.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 EFI_BOOT_SERVICES
*mBS
;
18 This function returns the size, in bytes,
19 of the device path data structure specified by DevicePath.
20 If DevicePath is NULL, then 0 is returned.
22 @param DevicePath A pointer to a device path data structure.
24 @return The size of a device path in bytes.
30 SmmGetDevicePathSize (
31 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
34 CONST EFI_DEVICE_PATH_PROTOCOL
*Start
;
36 if (DevicePath
== NULL
) {
41 // Search for the end of the device path structure
44 while (!EfiIsDevicePathEnd (DevicePath
)) {
45 DevicePath
= EfiNextDevicePathNode (DevicePath
);
49 // Compute the size and add back in the size of the end device path structure
51 return ((UINTN
) DevicePath
- (UINTN
) Start
) + sizeof (EFI_DEVICE_PATH_PROTOCOL
);
55 This function appends the device path SecondDevicePath
56 to every device path instance in FirstDevicePath.
58 @param FirstDevicePath A pointer to a device path data structure.
60 @param SecondDevicePath A pointer to a device path data structure.
62 @return A pointer to the new device path is returned.
63 NULL is returned if space for the new device path could not be allocated from pool.
64 It is up to the caller to free the memory used by FirstDevicePath and SecondDevicePath
65 if they are no longer needed.
68 EFI_DEVICE_PATH_PROTOCOL
*
71 IN CONST EFI_DEVICE_PATH_PROTOCOL
*FirstDevicePath
,
72 IN CONST EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath
79 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
80 EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
;
82 ASSERT (FirstDevicePath
!= NULL
&& SecondDevicePath
!= NULL
);
85 // Allocate space for the combined device path. It only has one end node of
86 // length EFI_DEVICE_PATH_PROTOCOL
88 Size1
= SmmGetDevicePathSize (FirstDevicePath
);
89 Size2
= SmmGetDevicePathSize (SecondDevicePath
);
90 Size
= Size1
+ Size2
- sizeof (EFI_DEVICE_PATH_PROTOCOL
);
92 Status
= mBS
->AllocatePool (EfiBootServicesData
, Size
, (VOID
**) &NewDevicePath
);
94 if (EFI_SUCCESS
== Status
) {
95 mBS
->CopyMem ((VOID
*) NewDevicePath
, (VOID
*) FirstDevicePath
, Size1
);
97 // Over write Src1 EndNode and do the copy
99 DevicePath2
= (EFI_DEVICE_PATH_PROTOCOL
*) ((CHAR8
*) NewDevicePath
+ (Size1
- sizeof (EFI_DEVICE_PATH_PROTOCOL
)));
100 mBS
->CopyMem ((VOID
*) DevicePath2
, (VOID
*) SecondDevicePath
, Size2
);
103 return NewDevicePath
;
107 Unload function that is registered in the LoadImage protocol. It un-installs
108 protocols produced and deallocates pool used by the driver. Called by the core
109 when unloading the driver.
111 @param ImageHandle ImageHandle of the unloaded driver
113 @return Status of the ProcessModuleUnloadList.
118 _DriverUnloadHandler (
119 EFI_HANDLE ImageHandle
125 // Call the unload handlers for all the modules
127 Status
= ProcessModuleUnloadList (ImageHandle
);
130 // If the driver specific unload handler does not return an error, then call all of the
131 // library destructors. If the unload handler returned an error, then the driver can not be
132 // unloaded, and the library destructors should not be called
134 if (!EFI_ERROR (Status
)) {
135 ProcessLibraryDestructorList (ImageHandle
, gST
);
139 // Return the status from the driver specific unload handler
145 Enrty point to DXE SMM Driver.
147 @param ImageHandle ImageHandle of the loaded driver.
148 @param SystemTable Pointer to the EFI System Table.
150 @retval EFI_SUCCESS One or more of the drivers returned a success code.
151 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
157 IN EFI_HANDLE ImageHandle
,
158 IN EFI_SYSTEM_TABLE
*SystemTable
162 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
163 EFI_SMM_BASE_PROTOCOL
*SmmBase
;
165 EFI_DEVICE_PATH_PROTOCOL
*CompleteFilePath
;
166 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
170 // Cache a pointer to the Boot Services Table
172 mBS
= SystemTable
->BootServices
;
175 // Retrieve the Loaded Image Protocol
177 Status
= mBS
->HandleProtocol (
179 &gEfiLoadedImageProtocolGuid
,
182 ASSERT_EFI_ERROR (Status
);
185 // Retrieve SMM Base Protocol
187 Status
= mBS
->LocateProtocol (
188 &gEfiSmmBaseProtocolGuid
,
192 ASSERT_EFI_ERROR (Status
);
195 // Check to see if we are already in SMM
197 SmmBase
->InSmm (SmmBase
, &InSmm
);
204 // Retrieve the Device Path Protocol from the DeviceHandle tha this driver was loaded from
206 Status
= mBS
->HandleProtocol (
207 LoadedImage
->DeviceHandle
,
208 &gEfiDevicePathProtocolGuid
,
209 (VOID
*)&ImageDevicePath
211 ASSERT_EFI_ERROR (Status
);
214 // Build the full device path to the currently execuing image
216 CompleteFilePath
= SmmAppendDevicePath (ImageDevicePath
, LoadedImage
->FilePath
);
219 // Load the image in memory to SMRAM; it will automatically generate the
222 Status
= SmmBase
->Register (SmmBase
, CompleteFilePath
, NULL
, 0, &Handle
, FALSE
);
223 ASSERT_EFI_ERROR (Status
);
228 // Call constructor for all libraries
230 ProcessLibraryConstructorList (ImageHandle
, SystemTable
);
233 // Optionally install the unload handler
235 if (_gDriverUnloadImageCount
> 0) {
236 Status
= mBS
->HandleProtocol (
238 &gEfiLoadedImageProtocolGuid
,
239 (VOID
**)&LoadedImage
241 ASSERT_EFI_ERROR (Status
);
242 LoadedImage
->Unload
= _DriverUnloadHandler
;
246 // Call the list of driver entry points
248 Status
= ProcessModuleEntryPointList (ImageHandle
, SystemTable
);
249 if (EFI_ERROR (Status
)) {
250 ProcessLibraryDestructorList (ImageHandle
, SystemTable
);
257 Enrty point wrapper of DXE SMM Driver.
259 @param ImageHandle ImageHandle of the loaded driver.
260 @param SystemTable Pointer to the EFI System Table.
262 @retval EFI_SUCCESS One or more of the drivers returned a success code.
263 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
269 IN EFI_HANDLE ImageHandle
,
270 IN EFI_SYSTEM_TABLE
*SystemTable
273 return _ModuleEntryPoint (ImageHandle
, SystemTable
);