Isa Floppy driver code scrub.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8697 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
/**@file
|
||||
ISA Floppy Driver
|
||||
/** @file
|
||||
ISA Floppy Disk UEFI Driver conforming to the UEFI driver model
|
||||
|
||||
1. Support two types diskette drive
|
||||
1.44M drive and 2.88M drive (and now only support 1.44M)
|
||||
2. Support two diskette drives
|
||||
2. Support two diskette drives per floppy disk controller
|
||||
3. Use DMA channel 2 to transfer data
|
||||
4. Do not use interrupt
|
||||
5. Support diskette change line signal and write protect
|
||||
|
||||
conforming to EFI driver model
|
||||
|
||||
Copyright (c) 2006 - 2007, Intel Corporation.<BR>
|
||||
Copyright (c) 2006 - 2009, Intel Corporation.<BR>
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
@@ -22,7 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
#include "IsaFloppy.h"
|
||||
|
||||
LIST_ENTRY gControllerHead = INITIALIZE_LIST_HEAD_VARIABLE(gControllerHead);
|
||||
LIST_ENTRY mControllerHead = INITIALIZE_LIST_HEAD_VARIABLE (mControllerHead);
|
||||
|
||||
//
|
||||
// ISA Floppy Driver Binding Protocol
|
||||
@@ -38,14 +37,13 @@ EFI_DRIVER_BINDING_PROTOCOL gFdcControllerDriver = {
|
||||
|
||||
|
||||
/**
|
||||
The user Entry Point for module IsaFloppy. The user code starts with this function.
|
||||
The main Entry Point for this driver.
|
||||
|
||||
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
||||
@param[in] SystemTable A pointer to the EFI System Table.
|
||||
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
||||
@param[in] SystemTable A pointer to the EFI System Table.
|
||||
|
||||
@retval EFI_SUCCESS The entry point is executed successfully.
|
||||
@retval other Some error occurs when executing this entry point.
|
||||
|
||||
@retval EFI_SUCCESS The entry point is executed successfully.
|
||||
@retval other Some error occurs when executing this entry point.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
@@ -54,7 +52,7 @@ InitializeIsaFloppy(
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Install driver model protocol(s).
|
||||
@@ -69,19 +67,21 @@ InitializeIsaFloppy(
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Test controller is a Floppy Disk Controller
|
||||
Test if the controller is a floppy disk drive device
|
||||
|
||||
@param This Pointer of EFI_DRIVER_BINDING_PROTOCOL
|
||||
@param Controller driver's controller
|
||||
@param RemainingDevicePath children device path
|
||||
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
|
||||
@param[in] Controller The handle of the controller to test.
|
||||
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
|
||||
|
||||
@retval EFI_UNSUPPORTED controller is not floppy disk
|
||||
@retval EFI_SUCCESS controller is floppy disk
|
||||
@retval EFI_SUCCESS The device is supported by this driver.
|
||||
@retval EFI_ALREADY_STARTED The device is already being managed by this driver.
|
||||
@retval EFI_ACCESS_DENIED The device is already being managed by a different driver
|
||||
or an application that requires exclusive access.
|
||||
@retval EFI_UNSUPPORTED The device is is not supported by this driver.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
@@ -91,8 +91,35 @@ FdcControllerDriverSupported (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_ISA_IO_PROTOCOL *IsaIo;
|
||||
EFI_STATUS Status;
|
||||
EFI_ISA_IO_PROTOCOL *IsaIo;
|
||||
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
|
||||
|
||||
//
|
||||
// Ignore the parameter RemainingDevicePath because this is a device driver.
|
||||
//
|
||||
|
||||
//
|
||||
// Open the device path protocol
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
Controller,
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
(VOID **) &ParentDevicePath,
|
||||
This->DriverBindingHandle,
|
||||
Controller,
|
||||
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
gBS->CloseProtocol (
|
||||
Controller,
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
This->DriverBindingHandle,
|
||||
Controller
|
||||
);
|
||||
|
||||
//
|
||||
// Open the ISA I/O Protocol
|
||||
@@ -109,7 +136,7 @@ FdcControllerDriverSupported (
|
||||
return Status;
|
||||
}
|
||||
//
|
||||
// Use the ISA I/O Protocol to see if Controller is a Floppy Disk Controller
|
||||
// Use the ISA I/O Protocol to see if Controller is a floppy disk drive device
|
||||
//
|
||||
Status = EFI_SUCCESS;
|
||||
if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x604)) {
|
||||
@@ -129,13 +156,20 @@ FdcControllerDriverSupported (
|
||||
}
|
||||
|
||||
/**
|
||||
Create floppy control instance on controller.
|
||||
|
||||
@param This Pointer of EFI_DRIVER_BINDING_PROTOCOL
|
||||
@param Controller driver controller handle
|
||||
@param RemainingDevicePath Children's device path
|
||||
|
||||
@retval whether success to create floppy control instance.
|
||||
Start this driver on Controller.
|
||||
|
||||
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
|
||||
@param[in] ControllerHandle The handle of the controller to start. This handle
|
||||
must support a protocol interface that supplies
|
||||
an I/O abstraction to the driver.
|
||||
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
|
||||
This parameter is ignored by device drivers, and is optional for bus drivers.
|
||||
|
||||
@retval EFI_SUCCESS The device was started.
|
||||
@retval EFI_DEVICE_ERROR The device could not be started due to a device error.
|
||||
Currently not implemented.
|
||||
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
|
||||
@retval Others The driver failded to start the device.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
@@ -145,13 +179,13 @@ FdcControllerDriverStart (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
FDC_BLK_IO_DEV *FdcDev;
|
||||
EFI_ISA_IO_PROTOCOL *IsaIo;
|
||||
UINTN Index;
|
||||
LIST_ENTRY *List;
|
||||
BOOLEAN Found;
|
||||
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
|
||||
EFI_STATUS Status;
|
||||
FDC_BLK_IO_DEV *FdcDev;
|
||||
EFI_ISA_IO_PROTOCOL *IsaIo;
|
||||
UINTN Index;
|
||||
LIST_ENTRY *List;
|
||||
BOOLEAN Found;
|
||||
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
|
||||
|
||||
FdcDev = NULL;
|
||||
IsaIo = NULL;
|
||||
@@ -194,14 +228,14 @@ FdcControllerDriverStart (
|
||||
goto Done;
|
||||
}
|
||||
//
|
||||
// Allocate the Floppy Disk Controller's Device structure
|
||||
// Allocate the floppy device's Device structure
|
||||
//
|
||||
FdcDev = AllocateZeroPool (sizeof (FDC_BLK_IO_DEV));
|
||||
if (FdcDev == NULL) {
|
||||
goto Done;
|
||||
}
|
||||
//
|
||||
// Initialize the Floppy Disk Controller's Device structure
|
||||
// Initialize the floppy device's device structure
|
||||
//
|
||||
FdcDev->Signature = FDC_BLK_IO_DEV_SIGNATURE;
|
||||
FdcDev->Handle = Controller;
|
||||
@@ -212,10 +246,11 @@ FdcControllerDriverStart (
|
||||
FdcDev->ControllerState = NULL;
|
||||
FdcDev->DevicePath = ParentDevicePath;
|
||||
|
||||
ADD_FLOPPY_NAME (FdcDev);
|
||||
FdcDev->ControllerNameTable = NULL;
|
||||
AddName (FdcDev);
|
||||
|
||||
//
|
||||
// Look up the base address of the Floppy Disk Controller
|
||||
// Look up the base address of the Floppy Disk Controller which controls this floppy device
|
||||
//
|
||||
for (Index = 0; FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type != EfiIsaAcpiResourceEndOfList; Index++) {
|
||||
if (FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type == EfiIsaAcpiResourceIo) {
|
||||
@@ -223,11 +258,11 @@ FdcControllerDriverStart (
|
||||
}
|
||||
}
|
||||
//
|
||||
// Maintain the list of controller list
|
||||
// Maintain the list of floppy disk controllers
|
||||
//
|
||||
Found = FALSE;
|
||||
List = gControllerHead.ForwardLink;
|
||||
while (List != &gControllerHead) {
|
||||
List = mControllerHead.ForwardLink;
|
||||
while (List != &mControllerHead) {
|
||||
FdcDev->ControllerState = FLOPPY_CONTROLLER_FROM_LIST_ENTRY (List);
|
||||
if (FdcDev->BaseAddress == FdcDev->ControllerState->BaseAddress) {
|
||||
Found = TRUE;
|
||||
@@ -239,7 +274,7 @@ FdcControllerDriverStart (
|
||||
|
||||
if (!Found) {
|
||||
//
|
||||
// The Controller is new
|
||||
// A new floppy disk controller controlling this floppy disk drive is found
|
||||
//
|
||||
FdcDev->ControllerState = AllocatePool (sizeof (FLOPPY_CONTROLLER_CONTEXT));
|
||||
if (FdcDev->ControllerState == NULL) {
|
||||
@@ -252,10 +287,10 @@ FdcControllerDriverStart (
|
||||
FdcDev->ControllerState->BaseAddress = FdcDev->BaseAddress;
|
||||
FdcDev->ControllerState->NumberOfDrive = 0;
|
||||
|
||||
InsertTailList (&gControllerHead, &FdcDev->ControllerState->Link);
|
||||
InsertTailList (&mControllerHead, &FdcDev->ControllerState->Link);
|
||||
}
|
||||
//
|
||||
// Create a timer event for each Floppd Disk Controller.
|
||||
// Create a timer event for each floppy disk drive device.
|
||||
// This timer event is used to control the motor on and off
|
||||
//
|
||||
Status = gBS->CreateEvent (
|
||||
@@ -304,8 +339,9 @@ FdcControllerDriverStart (
|
||||
&FdcDev->BlkIo,
|
||||
NULL
|
||||
);
|
||||
|
||||
FdcDev->ControllerState->NumberOfDrive++;
|
||||
if (!EFI_ERROR (Status)) {
|
||||
FdcDev->ControllerState->NumberOfDrive++;
|
||||
}
|
||||
|
||||
Done:
|
||||
if (EFI_ERROR (Status)) {
|
||||
@@ -317,14 +353,19 @@ Done:
|
||||
);
|
||||
|
||||
//
|
||||
// Close the device path protocol
|
||||
// If a floppy drive device structure was allocated, then free it
|
||||
//
|
||||
gBS->CloseProtocol (
|
||||
Controller,
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
This->DriverBindingHandle,
|
||||
Controller
|
||||
);
|
||||
if (FdcDev != NULL) {
|
||||
if (FdcDev->Event != NULL) {
|
||||
//
|
||||
// Close the event for turning the motor off
|
||||
//
|
||||
gBS->CloseEvent (FdcDev->Event);
|
||||
}
|
||||
|
||||
FreeUnicodeStringTable (FdcDev->ControllerNameTable);
|
||||
FreePool (FdcDev);
|
||||
}
|
||||
|
||||
//
|
||||
// Close the ISA I/O Protocol
|
||||
@@ -337,38 +378,34 @@ Done:
|
||||
Controller
|
||||
);
|
||||
}
|
||||
//
|
||||
// If a Floppy Disk Controller Device structure was allocated, then free it
|
||||
//
|
||||
if (FdcDev != NULL) {
|
||||
if (FdcDev->Event != NULL) {
|
||||
//
|
||||
// Close the event for turning the motor off
|
||||
//
|
||||
gBS->CloseEvent (FdcDev->Event);
|
||||
}
|
||||
|
||||
FreeUnicodeStringTable (FdcDev->ControllerNameTable);
|
||||
gBS->FreePool (FdcDev);
|
||||
}
|
||||
//
|
||||
// Close the device path protocol
|
||||
//
|
||||
gBS->CloseProtocol (
|
||||
Controller,
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
This->DriverBindingHandle,
|
||||
Controller
|
||||
);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Stop this driver on ControllerHandle. Support stoping any child handles
|
||||
created by this driver.
|
||||
Stop this driver on ControllerHandle.
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
@param Controller Handle of device to stop driver on
|
||||
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
|
||||
children is zero stop the entire bus driver.
|
||||
@param ChildHandleBuffer List of Child Handles to Stop.
|
||||
|
||||
@retval EFI_SUCCESS This driver is removed ControllerHandle
|
||||
@retval other This driver was not removed from this device
|
||||
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
|
||||
@param[in] ControllerHandle A handle to the device being stopped. The handle must
|
||||
support a bus specific I/O protocol for the driver
|
||||
to use to stop the device.
|
||||
@param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
|
||||
@param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
|
||||
if NumberOfChildren is 0.
|
||||
|
||||
@retval EFI_SUCCESS The device was stopped.
|
||||
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
@@ -383,6 +420,10 @@ FdcControllerDriverStop (
|
||||
EFI_BLOCK_IO_PROTOCOL *BlkIo;
|
||||
FDC_BLK_IO_DEV *FdcDev;
|
||||
|
||||
//
|
||||
// Ignore NumberOfChildren since this is a device driver
|
||||
//
|
||||
|
||||
//
|
||||
// Get the Block I/O Protocol on Controller
|
||||
//
|
||||
@@ -398,7 +439,7 @@ FdcControllerDriverStop (
|
||||
return Status;
|
||||
}
|
||||
//
|
||||
// Get the Floppy Disk Controller's Device structure
|
||||
// Get the floppy drive device's Device structure
|
||||
//
|
||||
FdcDev = FDD_BLK_IO_FROM_THIS (BlkIo);
|
||||
|
||||
@@ -411,11 +452,6 @@ FdcControllerDriverStop (
|
||||
FdcDev->DevicePath
|
||||
);
|
||||
|
||||
//
|
||||
// Turn the motor off on the Floppy Disk Controller
|
||||
//
|
||||
FddTimerProc (FdcDev->Event, FdcDev);
|
||||
|
||||
//
|
||||
// Uninstall the Block I/O Protocol
|
||||
//
|
||||
@@ -427,6 +463,17 @@ FdcControllerDriverStop (
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Close the event for turning the motor off
|
||||
//
|
||||
gBS->CloseEvent (FdcDev->Event);
|
||||
|
||||
//
|
||||
// Turn the motor off on the floppy drive device
|
||||
//
|
||||
FddTimerProc (FdcDev->Event, FdcDev);
|
||||
|
||||
//
|
||||
// Close the device path protocol
|
||||
//
|
||||
@@ -452,21 +499,16 @@ FdcControllerDriverStop (
|
||||
//
|
||||
FdcDev->ControllerState->NumberOfDrive--;
|
||||
|
||||
//
|
||||
// Close the event for turning the motor off
|
||||
//
|
||||
gBS->CloseEvent (FdcDev->Event);
|
||||
|
||||
//
|
||||
// Free the cache if one was allocated
|
||||
//
|
||||
FdcFreeCache (FdcDev);
|
||||
|
||||
//
|
||||
// Free the Floppy Disk Controller's Device structure
|
||||
// Free the floppy drive device's device structure
|
||||
//
|
||||
FreeUnicodeStringTable (FdcDev->ControllerNameTable);
|
||||
gBS->FreePool (FdcDev);
|
||||
FreePool (FdcDev);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user