3 Copyright (c) 2005 - 2014, 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 VOID
*ComponentName2
;
146 Status
= gBS
->LocateHandleBuffer (
153 if (EFI_ERROR (Status
)) {
157 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
158 Status
= EfiTestManagedDevice (DeviceHandleBuffer
[Index
], ImageHandle
, &gEfiDiskIoProtocolGuid
);
159 if (!EFI_ERROR (Status
)) {
160 Status
= gBS
->DisconnectController (
161 DeviceHandleBuffer
[Index
],
165 if (EFI_ERROR (Status
)) {
171 if (Index
== DeviceHandleCount
) {
173 // Driver is stopped successfully.
175 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiComponentNameProtocolGuid
, &ComponentName
);
176 if (EFI_ERROR (Status
)) {
177 ComponentName
= NULL
;
180 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiComponentName2ProtocolGuid
, &ComponentName2
);
181 if (EFI_ERROR (Status
)) {
182 ComponentName2
= NULL
;
185 if (ComponentName
== NULL
) {
186 if (ComponentName2
== NULL
) {
187 Status
= gBS
->UninstallMultipleProtocolInterfaces (
189 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
193 Status
= gBS
->UninstallMultipleProtocolInterfaces (
195 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
196 &gEfiComponentName2ProtocolGuid
, ComponentName2
,
201 if (ComponentName2
== NULL
) {
202 Status
= gBS
->UninstallMultipleProtocolInterfaces (
204 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
205 &gEfiComponentNameProtocolGuid
, ComponentName
,
209 Status
= gBS
->UninstallMultipleProtocolInterfaces (
211 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
212 &gEfiComponentNameProtocolGuid
, ComponentName
,
213 &gEfiComponentName2ProtocolGuid
, ComponentName2
,
220 if (DeviceHandleBuffer
!= NULL
) {
221 FreePool (DeviceHandleBuffer
);
229 FatDriverBindingSupported (
230 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
231 IN EFI_HANDLE ControllerHandle
,
232 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
238 Test to see if this driver can add a file system to ControllerHandle.
239 ControllerHandle must support both Disk IO and Block IO protocols.
243 This - Protocol instance pointer.
244 ControllerHandle - Handle of device to test.
245 RemainingDevicePath - Not used.
249 EFI_SUCCESS - This driver supports this device.
250 EFI_ALREADY_STARTED - This driver is already running on this device.
251 other - This driver does not support this device.
256 EFI_DISK_IO_PROTOCOL
*DiskIo
;
259 // Open the IO Abstraction(s) needed to perform the supported test
261 Status
= gBS
->OpenProtocol (
263 &gEfiDiskIoProtocolGuid
,
265 This
->DriverBindingHandle
,
267 EFI_OPEN_PROTOCOL_BY_DRIVER
270 if (EFI_ERROR (Status
)) {
274 // Close the I/O Abstraction(s) used to perform the supported test
278 &gEfiDiskIoProtocolGuid
,
279 This
->DriverBindingHandle
,
284 // Open the IO Abstraction(s) needed to perform the supported test
286 Status
= gBS
->OpenProtocol (
288 &gEfiBlockIoProtocolGuid
,
290 This
->DriverBindingHandle
,
292 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
300 FatDriverBindingStart (
301 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
302 IN EFI_HANDLE ControllerHandle
,
303 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
309 Start this driver on ControllerHandle by opening a Block IO and Disk IO
310 protocol, reading Device Path. Add a Simple File System protocol to
311 ControllerHandle if the media contains a valid file system.
315 This - Protocol instance pointer.
316 ControllerHandle - Handle of device to bind driver to.
317 RemainingDevicePath - Not used.
321 EFI_SUCCESS - This driver is added to DeviceHandle.
322 EFI_ALREADY_STARTED - This driver is already running on DeviceHandle.
323 EFI_OUT_OF_RESOURCES - Can not allocate the memory.
324 other - This driver does not support this device.
329 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
330 EFI_DISK_IO_PROTOCOL
*DiskIo
;
331 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
337 // If caller has already acquired the lock, cannot lock it again.
339 Status
= FatAcquireLockOrFail ();
340 if (!EFI_ERROR (Status
)) {
344 Status
= InitializeUnicodeCollationSupport (This
->DriverBindingHandle
);
345 if (EFI_ERROR (Status
)) {
349 // Open our required BlockIo and DiskIo
351 Status
= gBS
->OpenProtocol (
353 &gEfiBlockIoProtocolGuid
,
355 This
->DriverBindingHandle
,
357 EFI_OPEN_PROTOCOL_GET_PROTOCOL
359 if (EFI_ERROR (Status
)) {
363 Status
= gBS
->OpenProtocol (
365 &gEfiDiskIoProtocolGuid
,
367 This
->DriverBindingHandle
,
369 EFI_OPEN_PROTOCOL_BY_DRIVER
371 if (EFI_ERROR (Status
)) {
375 Status
= gBS
->OpenProtocol (
377 &gEfiDiskIo2ProtocolGuid
,
379 This
->DriverBindingHandle
,
381 EFI_OPEN_PROTOCOL_BY_DRIVER
383 if (EFI_ERROR (Status
)) {
388 // Allocate Volume structure. In FatAllocateVolume(), Resources
389 // are allocated with protocol installed and cached initialized
391 Status
= FatAllocateVolume (ControllerHandle
, DiskIo
, DiskIo2
, BlockIo
);
394 // When the media changes on a device it will Reinstall the BlockIo interaface.
395 // This will cause a call to our Stop(), and a subsequent reentrant call to our
396 // Start() successfully. We should leave the device open when this happen.
398 if (EFI_ERROR (Status
)) {
399 Status
= gBS
->OpenProtocol (
401 &gEfiSimpleFileSystemProtocolGuid
,
403 This
->DriverBindingHandle
,
405 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
407 if (EFI_ERROR (Status
)) {
410 &gEfiDiskIoProtocolGuid
,
411 This
->DriverBindingHandle
,
416 &gEfiDiskIo2ProtocolGuid
,
417 This
->DriverBindingHandle
,
425 // Unlock if locked by myself.
435 FatDriverBindingStop (
436 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
437 IN EFI_HANDLE ControllerHandle
,
438 IN UINTN NumberOfChildren
,
439 IN EFI_HANDLE
*ChildHandleBuffer
444 Stop this driver on ControllerHandle.
447 This - Protocol instance pointer.
448 ControllerHandle - Handle of device to stop driver on.
449 NumberOfChildren - Not used.
450 ChildHandleBuffer - Not used.
453 EFI_SUCCESS - This driver is removed DeviceHandle.
454 other - This driver was not removed from this device.
459 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*FileSystem
;
461 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
465 // Get our context back
467 Status
= gBS
->OpenProtocol (
469 &gEfiSimpleFileSystemProtocolGuid
,
470 (VOID
**) &FileSystem
,
471 This
->DriverBindingHandle
,
473 EFI_OPEN_PROTOCOL_GET_PROTOCOL
476 if (!EFI_ERROR (Status
)) {
477 Volume
= VOLUME_FROM_VOL_INTERFACE (FileSystem
);
478 DiskIo2
= Volume
->DiskIo2
;
479 Status
= FatAbandonVolume (Volume
);
482 if (!EFI_ERROR (Status
)) {
483 if (DiskIo2
!= NULL
) {
484 Status
= gBS
->CloseProtocol (
486 &gEfiDiskIo2ProtocolGuid
,
487 This
->DriverBindingHandle
,
490 ASSERT_EFI_ERROR (Status
);
492 Status
= gBS
->CloseProtocol (
494 &gEfiDiskIoProtocolGuid
,
495 This
->DriverBindingHandle
,
498 ASSERT_EFI_ERROR (Status
);