3 Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Fat File System driver routines that support EFI driver model
28 IN EFI_HANDLE ImageHandle
,
29 IN EFI_SYSTEM_TABLE
*SystemTable
35 IN EFI_HANDLE ImageHandle
40 FatDriverBindingSupported (
41 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
42 IN EFI_HANDLE Controller
,
43 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
48 FatDriverBindingStart (
49 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
50 IN EFI_HANDLE Controller
,
51 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
56 FatDriverBindingStop (
57 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
58 IN EFI_HANDLE Controller
,
59 IN UINTN NumberOfChildren
,
60 IN EFI_HANDLE
*ChildHandleBuffer
64 // DriverBinding protocol instance
66 EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding
= {
67 FatDriverBindingSupported
,
68 FatDriverBindingStart
,
78 IN EFI_HANDLE ImageHandle
,
79 IN EFI_SYSTEM_TABLE
*SystemTable
85 Register Driver Binding protocol for this driver.
89 ImageHandle - Handle for the image of this driver.
90 SystemTable - Pointer to the EFI System Table.
94 EFI_SUCCESS - Driver loaded.
95 other - Driver not loaded.
102 // Initialize the EFI Driver Library
104 Status
= EfiLibInstallDriverBindingComponentName2 (
112 ASSERT_EFI_ERROR (Status
);
120 IN EFI_HANDLE ImageHandle
126 Unload function for this image. Uninstall DriverBinding protocol.
130 ImageHandle - Handle for the image of this driver.
134 EFI_SUCCESS - Driver unloaded successfully.
135 other - Driver can not unloaded.
140 EFI_HANDLE
*DeviceHandleBuffer
;
141 UINTN DeviceHandleCount
;
144 Status
= gBS
->LocateHandleBuffer (
151 if (!EFI_ERROR (Status
)) {
152 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
153 Status
= gBS
->DisconnectController (
154 DeviceHandleBuffer
[Index
],
160 if (DeviceHandleBuffer
!= NULL
) {
161 FreePool (DeviceHandleBuffer
);
170 FatDriverBindingSupported (
171 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
172 IN EFI_HANDLE ControllerHandle
,
173 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
179 Test to see if this driver can add a file system to ControllerHandle.
180 ControllerHandle must support both Disk IO and Block IO protocols.
184 This - Protocol instance pointer.
185 ControllerHandle - Handle of device to test.
186 RemainingDevicePath - Not used.
190 EFI_SUCCESS - This driver supports this device.
191 EFI_ALREADY_STARTED - This driver is already running on this device.
192 other - This driver does not support this device.
197 EFI_DISK_IO_PROTOCOL
*DiskIo
;
200 // Open the IO Abstraction(s) needed to perform the supported test
202 Status
= gBS
->OpenProtocol (
204 &gEfiDiskIoProtocolGuid
,
206 This
->DriverBindingHandle
,
208 EFI_OPEN_PROTOCOL_BY_DRIVER
211 if (EFI_ERROR (Status
)) {
215 // Close the I/O Abstraction(s) used to perform the supported test
219 &gEfiDiskIoProtocolGuid
,
220 This
->DriverBindingHandle
,
225 // Open the IO Abstraction(s) needed to perform the supported test
227 Status
= gBS
->OpenProtocol (
229 &gEfiBlockIoProtocolGuid
,
231 This
->DriverBindingHandle
,
233 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
241 FatDriverBindingStart (
242 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
243 IN EFI_HANDLE ControllerHandle
,
244 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
250 Start this driver on ControllerHandle by opening a Block IO and Disk IO
251 protocol, reading Device Path. Add a Simple File System protocol to
252 ControllerHandle if the media contains a valid file system.
256 This - Protocol instance pointer.
257 ControllerHandle - Handle of device to bind driver to.
258 RemainingDevicePath - Not used.
262 EFI_SUCCESS - This driver is added to DeviceHandle.
263 EFI_ALREADY_STARTED - This driver is already running on DeviceHandle.
264 EFI_OUT_OF_RESOURCES - Can not allocate the memory.
265 other - This driver does not support this device.
270 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
271 EFI_DISK_IO_PROTOCOL
*DiskIo
;
272 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
278 // If caller has already acquired the lock, cannot lock it again.
280 Status
= FatAcquireLockOrFail ();
281 if (!EFI_ERROR (Status
)) {
285 Status
= InitializeUnicodeCollationSupport (This
->DriverBindingHandle
);
286 if (EFI_ERROR (Status
)) {
290 // Open our required BlockIo and DiskIo
292 Status
= gBS
->OpenProtocol (
294 &gEfiBlockIoProtocolGuid
,
296 This
->DriverBindingHandle
,
298 EFI_OPEN_PROTOCOL_GET_PROTOCOL
300 if (EFI_ERROR (Status
)) {
304 Status
= gBS
->OpenProtocol (
306 &gEfiDiskIoProtocolGuid
,
308 This
->DriverBindingHandle
,
310 EFI_OPEN_PROTOCOL_BY_DRIVER
312 if (EFI_ERROR (Status
)) {
316 Status
= gBS
->OpenProtocol (
318 &gEfiDiskIo2ProtocolGuid
,
320 This
->DriverBindingHandle
,
322 EFI_OPEN_PROTOCOL_BY_DRIVER
324 if (EFI_ERROR (Status
)) {
329 // Allocate Volume structure. In FatAllocateVolume(), Resources
330 // are allocated with protocol installed and cached initialized
332 Status
= FatAllocateVolume (ControllerHandle
, DiskIo
, DiskIo2
, BlockIo
);
335 // When the media changes on a device it will Reinstall the BlockIo interaface.
336 // This will cause a call to our Stop(), and a subsequent reentrant call to our
337 // Start() successfully. We should leave the device open when this happen.
339 if (EFI_ERROR (Status
)) {
340 Status
= gBS
->OpenProtocol (
342 &gEfiSimpleFileSystemProtocolGuid
,
344 This
->DriverBindingHandle
,
346 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
348 if (EFI_ERROR (Status
)) {
351 &gEfiDiskIoProtocolGuid
,
352 This
->DriverBindingHandle
,
357 &gEfiDiskIo2ProtocolGuid
,
358 This
->DriverBindingHandle
,
366 // Unlock if locked by myself.
376 FatDriverBindingStop (
377 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
378 IN EFI_HANDLE ControllerHandle
,
379 IN UINTN NumberOfChildren
,
380 IN EFI_HANDLE
*ChildHandleBuffer
385 Stop this driver on ControllerHandle.
388 This - Protocol instance pointer.
389 ControllerHandle - Handle of device to stop driver on.
390 NumberOfChildren - Not used.
391 ChildHandleBuffer - Not used.
394 EFI_SUCCESS - This driver is removed DeviceHandle.
395 other - This driver was not removed from this device.
400 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*FileSystem
;
402 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
406 // Get our context back
408 Status
= gBS
->OpenProtocol (
410 &gEfiSimpleFileSystemProtocolGuid
,
411 (VOID
**) &FileSystem
,
412 This
->DriverBindingHandle
,
414 EFI_OPEN_PROTOCOL_GET_PROTOCOL
417 if (!EFI_ERROR (Status
)) {
418 Volume
= VOLUME_FROM_VOL_INTERFACE (FileSystem
);
419 DiskIo2
= Volume
->DiskIo2
;
420 Status
= FatAbandonVolume (Volume
);
423 if (!EFI_ERROR (Status
)) {
424 if (DiskIo2
!= NULL
) {
425 Status
= gBS
->CloseProtocol (
427 &gEfiDiskIo2ProtocolGuid
,
428 This
->DriverBindingHandle
,
431 ASSERT_EFI_ERROR (Status
);
433 Status
= gBS
->CloseProtocol (
435 &gEfiDiskIoProtocolGuid
,
436 This
->DriverBindingHandle
,
439 ASSERT_EFI_ERROR (Status
);