/** @file
Internal floppy disk controller programming functions for the floppy driver.
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "IsaFloppy.h"
/**
Detect whether a floppy drive is present or not.
@param[in] FdcDev A pointer to the FDC_BLK_IO_DEV
@retval EFI_SUCCESS The floppy disk drive is present
@retval EFI_NOT_FOUND The floppy disk drive is not present
**/
)
{
return EFI_NOT_FOUND;
}
return EFI_SUCCESS;
}
/**
Do recalibrate and check if the drive is present or not
and set the media parameters if the driver is present.
@param[in] FdcDev A pointer to the FDC_BLK_IO_DEV
@retval EFI_SUCCESS The floppy disk drive is present
@retval EFI_DEVICE_ERROR The floppy disk drive is not present
**/
)
{
//
// Set Floppy Disk Controller's motor on
//
return EFI_DEVICE_ERROR;
}
return EFI_DEVICE_ERROR;
}
//
// Set Media Parameter
//
//
// Check Media
//
if (Status == EFI_NO_MEDIA) {
} else if ((Status != EFI_MEDIA_CHANGED) &&
(Status != EFI_SUCCESS)) {
return Status;
}
//
// Check Disk Write Protected
//
if (Status == EFI_WRITE_PROTECTED) {
} else if (Status == EFI_SUCCESS) {
} else {
return EFI_DEVICE_ERROR;
}
//
// Set Media Default Type
//
return EFI_SUCCESS;
}
/**
Reset the Floppy Logic Drive.
@param FdcDev FDC_BLK_IO_DEV * : A pointer to the FDC_BLK_IO_DEV
@retval EFI_SUCCESS: The Floppy Logic Drive is reset
@retval EFI_DEVICE_ERROR: The Floppy Logic Drive is not functioning correctly and
can not be reset
**/
FddReset (
)
{
//
// Report reset progress code
//
);
//
// Reset specified Floppy Logic Drive according to FdcDev -> Disk
// Set Digital Output Register(DOR) to do reset work
// bit0 & bit1 of DOR : Drive Select
// bit2 : Reset bit
// bit3 : DMA and Int bit
// Reset : a "0" written to bit2 resets the FDC, this reset will remain
// active until
// a "1" is written to this bit.
// Reset step 1:
// use bit0 & bit1 to select the logic drive
// write "0" to bit2
//
Data = 0x0;
//
// wait some time,at least 120us
//
MicroSecondDelay (500);
//
// Reset step 2:
// write "1" to bit2
// write "1" to bit3 : enable DMA
//
Data |= 0x0C;
//
// Experience value
//
MicroSecondDelay (2000);
//
// wait specified floppy logic drive is not busy
//
return EFI_DEVICE_ERROR;
}
//
// Set the Transfer Data Rate
//
//
// Experience value
//
MicroSecondDelay (100);
//
// Issue Sense interrupt command for each drive (total 4 drives)
//
return EFI_DEVICE_ERROR;
}
}
//
// issue Specify command
//
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
Turn the floppy disk drive's motor on.
The drive's motor must be on before any command can be executed.
@param[in] FdcDev A pointer to the FDC_BLK_IO_DEV
@retval EFI_SUCCESS The drive's motor was turned on successfully
@retval EFI_DEVICE_ERROR The drive is busy, so can not turn motor on
**/
MotorOn (
)
{
//
// Control of the floppy drive motors is a big pain. If motor is off, you have
// to turn it on first. But you can not leave the motor on all the time, since
// that would wear out the disk. On the other hand, if you turn the motor off
// after each operation, the system performance will be awful. The compromise
// used in this driver is to leave the motor on for 2 seconds after
// each operation. If a new operation is started in that interval(2s),
// the motor need not be turned on again. If no new operation is started,
// a timer goes off and the motor is turned off
//
//
// Cancel the timer
//
//
// Get the motor status
//
) {
return EFI_SUCCESS;
}
//
// The drive's motor is off, so need turn it on
// first look at command and drive are busy or not
//
return EFI_DEVICE_ERROR;
}
//
// for drive A: 1CH, drive B: 2DH
//
DorData = 0x0C;
//
// drive A
//
DorData |= DRVA_MOTOR_ON;
} else {
//
// drive B
//
DorData |= DRVB_MOTOR_ON;
}
//
// Experience value
//
MicroSecondDelay (4000);
return EFI_SUCCESS;
}
/**
Set a Timer and when Timer goes off, turn the motor off.
@param[in] FdcDev A pointer to the FDC_BLK_IO_DEV
@retval EFI_SUCCESS Set the Timer successfully
@retval EFI_INVALID_PARAMETER Fail to Set the timer
**/
MotorOff (
)
{
//
// Set the timer : 2s
//
}
/**
Detect whether the disk in the drive is changed or not.
@param[in] FdcDev A pointer to FDC_BLK_IO_DEV
@retval EFI_SUCCESS No disk media change
@retval EFI_DEVICE_ERROR Fail to do the recalibrate or seek operation
@retval EFI_NO_MEDIA No disk in the drive
@retval EFI_MEDIA_CHANGED There is a new disk in the drive
**/
)
{
//
// Check change line
//
//
// Io delay
//
MicroSecondDelay (50);
//
// disk change line is active
//
if (FdcDev->PresentCylinderNumber != 0) {
} else {
}
return EFI_DEVICE_ERROR;
//
// Fail to do the seek or recalibrate operation
//
}
//
// Io delay
//
MicroSecondDelay (50);
return EFI_NO_MEDIA;
}
return EFI_MEDIA_CHANGED;
}
return EFI_SUCCESS;
}
/**
Do the Specify command, this command sets DMA operation
and the initial values for each of the three internal
times: HUT, SRT and HLT.
@param[in] FdcDev Pointer to instance of FDC_BLK_IO_DEV
@retval EFI_SUCCESS Execute the Specify command successfully
@retval EFI_DEVICE_ERROR Fail to execute the command
**/
Specify (
)
{
//
// set SRT, HUT
//
//
// 0xdf;
//
// set HLT and DMA
//
return EFI_DEVICE_ERROR;
}
}
return EFI_SUCCESS;
}
/**
Set the head of floppy drive to track 0.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV
@retval EFI_SUCCESS: Execute the Recalibrate operation successfully
@retval EFI_DEVICE_ERROR: Fail to execute the Recalibrate operation
**/
)
{
Count = 2;
while (Count > 0) {
//
// drive select
//
Command.DiskHeadSel = 0;
//
// 0
//
} else {
//
// 1
//
}
return EFI_DEVICE_ERROR;
}
}
//
// Experience value
//
MicroSecondDelay (250000);
//
// need modify according to 1.44M or 2.88M
//
return EFI_DEVICE_ERROR;
}
FdcDev->PresentCylinderNumber = 0;
return EFI_SUCCESS;
} else {
Count--;
if (Count == 0) {
return EFI_DEVICE_ERROR;
}
}
}
//
// end while
//
return EFI_SUCCESS;
}
/**
Set the head of floppy drive to the new cylinder.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV
@param Lba EFI_LBA : The logic block address want to seek
@retval EFI_SUCCESS: Execute the Seek operation successfully
@retval EFI_DEVICE_ERROR: Fail to execute the Seek operation
**/
Seek (
)
{
return EFI_DEVICE_ERROR;
}
}
//
// Calculate cylinder based on Lba and EOT
//
//
// if the destination cylinder is the present cylinder, unnecessary to do the
// seek operation
//
return EFI_SUCCESS;
}
//
// Calculate the head : 0 or 1
//
Command.DiskHeadSel = 0;
//
// 0
//
} else {
//
// 1
//
}
return EFI_DEVICE_ERROR;
}
}
//
// Io delay
//
MicroSecondDelay (100);
//
// Calculate waiting time
//
} else {
}
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
} else {
return EFI_DEVICE_ERROR;
}
}
/**
Do the Sense Interrupt Status command, this command
resets the interrupt signal.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV
@param StatusRegister0 UINT8 *: Be used to save Status Register 0 read from FDC
@param PresentCylinderNumber UINT8 *: Be used to save present cylinder number
read from FDC
@retval EFI_SUCCESS: Execute the Sense Interrupt Status command successfully
@retval EFI_DEVICE_ERROR: Fail to execute the command
**/
)
{
return EFI_DEVICE_ERROR;
}
return EFI_DEVICE_ERROR;
}
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
Do the Sense Drive Status command.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV
@param Lba EFI_LBA : Logic block address
@retval EFI_SUCCESS: Execute the Sense Drive Status command successfully
@retval EFI_DEVICE_ERROR: Fail to execute the command
@retval EFI_WRITE_PROTECTED:The disk is write protected
**/
)
{
//
// Sense Drive Status command obtains drive status information,
// it has not execution phase and goes directly to the result phase from the
// command phase, Status Register 3 contains the drive status information
//
Command.DiskHeadSel = 0;
} else {
}
return EFI_DEVICE_ERROR;
}
}
return EFI_DEVICE_ERROR;
}
//
// Io delay
//
MicroSecondDelay (50);
//
// Check Status Register 3 to get drive status information
//
return CheckStatus3 (StatusRegister3);
}
/**
Update the disk media properties and if necessary reinstall Block I/O interface.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV
@retval EFI_SUCCESS: Do the operation successfully
@retval EFI_DEVICE_ERROR: Fail to the operation
**/
)
{
//
// Check disk change
//
if (Status == EFI_MEDIA_CHANGED) {
} else if (Status == EFI_NO_MEDIA) {
} else if (Status != EFI_SUCCESS) {
return Status;
//
// EFI_DEVICE_ERROR
//
}
//
// Check disk write protected
//
if (Status == EFI_WRITE_PROTECTED) {
} else {
}
}
}
}
if (Reset) {
);
return Status;
}
}
return EFI_SUCCESS;
}
/**
Set the data rate and so on.
@param FdcDev A pointer to FDC_BLK_IO_DEV
@retval EFI_SUCCESS success to set the data rate
**/
Setup (
)
{
//
// Set data rate 500kbs
//
//
// Io delay
//
MicroSecondDelay (50);
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
Read or Write a number of blocks in the same cylinder.
@param FdcDev A pointer to FDC_BLK_IO_DEV
@param HostAddress device address
@param Lba The starting logic block address to read from on the device
@param NumberOfBlocks The number of block wanted to be read or write
@param Read Operation type: read or write
@retval EFI_SUCCESS Success operate
**/
)
{
return EFI_DEVICE_ERROR;
}
//
// Map Dma
//
} else {
}
Index = 0;
break;
}
Index++;
}
return EFI_DEVICE_ERROR;
}
);
return Status1;
}
//
// Allocate Read or Write command packet
//
} else {
}
//
// Write command bytes to FDC
//
return EFI_DEVICE_ERROR;
}
}
//
// wait for some time
//
do {
break;
}
MicroSecondDelay (50);
} while (Times > 0);
if (Times == 0) {
return EFI_TIMEOUT;
}
//
// Read result bytes from FDC
//
return EFI_DEVICE_ERROR;
}
}
//
// Flush before Unmap
//
return Status1;
}
}
//
// Unmap Dma
//
return Status1;
}
}
/**
Fill in FDD command's parameter.
@param FdcDev Pointer to instance of FDC_BLK_IO_DEV
@param Lba The starting logic block address to read from on the device
@param Command FDD command
**/
FillPara (
)
{
//
// Get EndOfTrack from the Para table
//
//
// Fill the command parameter
//
Command->DiskHeadSel = 0;
} else {
}
}
/**
Read result byte from Data Register of FDC.
@param FdcDev Pointer to instance of FDC_BLK_IO_DEV
@param Pointer Buffer to store the byte read from FDC
@retval EFI_SUCCESS Read result byte from FDC successfully
@retval EFI_DEVICE_ERROR The FDC is not ready to be read
**/
)
{
//
// wait for 1ms and detect the FDC is ready to be read
//
return EFI_DEVICE_ERROR;
//
// is not ready
//
}
//
// Io delay
//
MicroSecondDelay (50);
return EFI_SUCCESS;
}
/**
Write command byte to Data Register of FDC.
@param FdcDev Pointer to instance of FDC_BLK_IO_DEV
@param Pointer Be used to save command byte written to FDC
@retval EFI_SUCCESS: Write command byte to FDC successfully
@retval EFI_DEVICE_ERROR: The FDC is not ready to be written
**/
)
{
//
// wait for 1ms and detect the FDC is ready to be written
//
//
// Not ready
//
return EFI_DEVICE_ERROR;
}
//
// Io delay
//
MicroSecondDelay (50);
return EFI_SUCCESS;
}
/**
Detect the specified floppy logic drive is busy or not within a period of time.
@param FdcDev Indicate it is drive A or drive B
@param TimeoutInSeconds the time period for waiting
@retval EFI_SUCCESS: The drive and command are not busy
@retval EFI_TIMEOUT: The drive or command is still busy after a period time that
set by TimeoutInSeconds
**/
)
{
//
// How to determine drive and command are busy or not: by the bits of
// Main Status Register
// bit0: Drive 0 busy (drive A)
// bit1: Drive 1 busy (drive B)
// bit4: Command busy
//
//
// set mask: for drive A set bit0 & bit4; for drive B set bit1 & bit4
//
do {
break;
//
// not busy
//
}
MicroSecondDelay (50);
} while (Delay > 0);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}
/**
Routine Description: Determine whether FDC is ready to write or read.
@param FdcDev Pointer to instance of FDC_BLK_IO_DEV
@param Dio BOOLEAN: Indicate the FDC is waiting to write or read
@param TimeoutInSeconds UINTN: The time period for waiting
@retval EFI_SUCCESS: FDC is ready to write or read
@retval EFI_NOT_READY: FDC is not ready within the specified time period
**/
)
{
//
// Before writing to FDC or reading from FDC, the Host must examine
// the bit7(RQM) and bit6(DIO) of the Main Status Register.
// That is to say:
// command bytes can not be written to Data Register
// unless RQM is 1 and DIO is 0
// result bytes can not be read from Data Register
// unless RQM is 1 and DIO is 1
//
//
// in order to compare bit6
//
do {
break;
//
// FDC is ready
//
}
MicroSecondDelay (50);
//
// Stall for 50 us
//
} while (Delay > 0);
if (Delay == 0) {
return EFI_NOT_READY;
//
// FDC is not ready within the specified time period
//
}
return EFI_SUCCESS;
}
/**
Set FDC control structure's attribute according to result.
@param Result Point to result structure
@param FdcDev FDC control structure
@retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
@retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
@retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
@retval EFI_SUCCESS - GC_TODO: Add description for return value
**/
)
{
//
// Check Status Register0
//
//
// seek error
//
}
return EFI_DEVICE_ERROR;
}
//
// Check Status Register1
//
return EFI_DEVICE_ERROR;
}
//
// Check Status Register2
//
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
Check the drive status information.
@param StatusRegister3 the value of Status Register 3
@retval EFI_SUCCESS The disk is not write protected
@retval EFI_WRITE_PROTECTED: The disk is write protected
**/
)
{
if ((StatusRegister3 & STS3_WP) != 0) {
return EFI_WRITE_PROTECTED;
}
return EFI_SUCCESS;
}
/**
Calculate the number of block in the same cylinder according to LBA.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV
@param LBA EFI_LBA: The starting logic block address
@param NumberOfBlocks UINTN: The number of blocks
@return The number of blocks in the same cylinder which the starting
logic block address is LBA
**/
)
{
//
// Calculate the number of block in the same cylinder
//
if (SectorsInTrack < NumberOfBlocks) {
return SectorsInTrack;
} else {
return NumberOfBlocks;
}
}
/**
When the Timer(2s) off, turn the drive's motor off.
@param Event EFI_EVENT: Event(the timer) whose notification function is being
invoked
@param Context VOID *: Pointer to the notification function's context
**/
)
{
//
// Get the motor status
//
) {
return ;
}
//
// the motor is on, so need motor off
//
Data = 0x0C;
MicroSecondDelay (500);
}
/**
Read an I/O port of FDC.
@param[in] FdcDev A pointer to FDC_BLK_IO_DEV.
@param[in] Offset The address offset of the I/O port.
@retval 8-bit data read from the I/O port.
**/
)
{
1,
&Data
);
return Data;
}
/**
Write an I/O port of FDC.
@param[in] FdcDev A pointer to FDC_BLK_IO_DEV
@param[in] Offset The address offset of the I/O port
@param[in] Data 8-bit Value written to the I/O port
**/
)
{
1,
&Data
);
}