IsaFloppy.h revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Include file for ISA 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.
**/
#ifndef _ISA_FLOPPY_H_
#define _ISA_FLOPPY_H_
#include <Uefi.h>
#include <Protocol/DevicePath.h>
#include <Guid/StatusCodeDataTypeId.h>
#include <Library/TimerLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/ReportStatusCodeLib.h>
#define STALL_1_SECOND 1000000
#define STALL_1_MSECOND 1000
#define DATA_IN 1
#define DATA_OUT 0
#define READ 0
#define WRITE 1
//
// Internal Data Structures
//
typedef enum {
FdcDisk0 = 0,
FdcDisk1 = 1,
FdcMaxDisk = 2
} EFI_FDC_DISK;
typedef struct {
typedef struct {
#include "ComponentName.h"
#define FLOPPY_CONTROLLER_FROM_LIST_ENTRY(a) \
CR (a, \
Link, \
)
#define DISK_1440K_EOT 0x12
#define DISK_1440K_GPL 0x1b
#define DISK_1440K_DTL 0xff
#define DISK_1440K_NUMBER 0x02
#define DISK_1440K_MAXTRACKNUM 0x4f
#define DISK_1440K_BYTEPERSECTOR 512
typedef struct {
typedef struct {
typedef struct {
typedef struct {
} FDD_SEEK_CMD;
typedef struct {
} FDD_SCAN_CMD;
typedef struct {
//
// FDC Registers
//
//
// Digital Output Register address offset
//
#define FDC_REGISTER_DOR 2
//
// Main Status Register address offset
//
#define FDC_REGISTER_MSR 4
//
// Data Register address offset
//
#define FDC_REGISTER_DTR 5
//
// Configuration Control Register(data rate select) address offset
//
#define FDC_REGISTER_CCR 7
//
// Digital Input Register(diskchange) address offset
//
#define FDC_REGISTER_DIR 7
//
// FDC Register Bit Definitions
//
//
// Digital Out Register(WO)
//
//
// Select Drive: 0=A 1=B
//
#define SELECT_DRV BIT0
//
// Reset FDC
//
//
// Enable Int & DMA
//
#define INT_DMA_ENABLE BIT3
//
// Turn On Drive A Motor
//
#define DRVA_MOTOR_ON BIT4
//
// Turn On Drive B Motor
//
#define DRVB_MOTOR_ON BIT5
//
// Main Status Register(RO)
//
//
// Drive A Busy
//
//
// Drive B Busy
//
//
// FDC Busy
//
//
// Non-DMA Mode
//
//
//
//
// Request For Master
//
//
// Configuration Control Register(WO)
//
//
// Data Rate select
//
//
// Digital Input Register(RO)
//
//
// Disk change line
//
//
// #define CCR_DCL BIT7 // Diskette change
//
// 500K
//
#define DRC_500KBS 0x0
//
// 300K
//
#define DRC_300KBS 0x01
//
// 250K
//
#define DRC_250KBS 0x02
//
// FDC Command Code
//
#define READ_DATA_CMD 0x06
#define WRITE_DATA_CMD 0x05
#define WRITE_DEL_DATA_CMD 0x09
#define READ_DEL_DATA_CMD 0x0C
#define READ_TRACK_CMD 0x02
#define READ_ID_CMD 0x0A
#define FORMAT_TRACK_CMD 0x0D
#define SCAN_EQU_CMD 0x11
#define SCAN_LOW_EQU_CMD 0x19
#define SCAN_HIGH_EQU_CMD 0x1D
#define SEEK_CMD 0x0F
#define RECALIBRATE_CMD 0x07
#define SENSE_INT_STATUS_CMD 0x08
#define SPECIFY_CMD 0x03
#define SENSE_DRV_STATUS_CMD 0x04
//
// CMD_MT: Multi_Track Selector
// when set , this flag selects the multi-track operating mode.
// In this mode, the FDC treats a complete cylinder under head0 and 1
// as a single track
//
//
// A one selects the double density(MFM) mode
// A zero selects single density (FM) mode
//
//
// CMD_SK: Skip Flag
// When set to 1, sectors containing a deleted data address mark will
// automatically be skipped during the execution of Read Data.
// When set to 0, the sector is read or written the same as the read and
// write commands.
//
//
// FDC Status Register Bit Definitions
//
//
// Status Register 0
//
//
// Interrupt Code
//
//
// Seek End: the FDC completed a seek or recalibrate command
//
//
// Equipment Check
//
//
// Not Ready(unused), this bit is always 0
//
//
// Head Address: the current head address
//
//
// STS0_US1 & STS0_US0: Drive Select(the current selected drive)
//
//
// Unit Select1
//
//
// Unit Select0
//
//
// Status Register 1
//
//
// End of Cylinder
//
//
// BIT6 is unused
//
//
// Data Error: The FDC detected a CRC error in either the ID field or
// data field of a sector
//
//
// within the required time interval
//
//
// BIT3 is unused
//
//
// No data
//
//
// Not Writable
//
//
// Missing Address Mark
//
//
// Control Mark
//
//
// Data Error in Data Field: The FDC detected a CRC error in the data field
//
//
// Wrong Cylinder: The track address from sector ID field is different from
// the track address maintained inside FDC
//
//
// Bad Cylinder
//
//
// Missing Address Mark in Data Field
//
//
// Write Protected
//
//
// Track 0
//
//
// Head Address
//
//
// STS3_US1 & STS3_US0 : Drive Select
//
//
// Status Register 0 Interrupt Code Description
//
//
// Normal Termination of Command
//
#define IC_NT 0x0
//
// Abnormal Termination of Command
//
#define IC_AT 0x40
//
// Invalid Command
//
#define IC_IC 0x80
//
// Abnormal Termination caused by Polling
//
#define IC_ATRC 0xC0
//
// EFI Driver Binding Protocol Functions
//
/**
Test controller is a floppy disk drive device
@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_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.
**/
);
/**
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.
**/
);
/**
Stop this driver on ControllerHandle.
@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 Block I/O Protocol Functions
//
/**
Reset the Floppy Logic Drive, call the FddReset function.
@param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
@param ExtendedVerification BOOLEAN: Indicate that the driver may perform a more
exhaustive verification operation of the device during
reset, now this par is ignored in this driver
@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
**/
FdcReset (
);
/**
Flush block via fdd controller.
@param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
@return EFI_SUCCESS
**/
);
/**
Read the requested number of blocks from the device.
@param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
@param MediaId UINT32: The media id that the read request is for
@param Lba EFI_LBA: The starting logic block address to read from on the device
@param BufferSize UINTN: The size of the Buffer in bytes
@param Buffer VOID *: A pointer to the destination buffer for the data
@retval EFI_SUCCESS: The data was read correctly from the device
@retval EFI_DEVICE_ERROR:The device reported an error while attempting to perform
the read operation
@retval EFI_NO_MEDIA: There is no media in the device
@retval EFI_MEDIA_CHANGED: The MediaId is not for the current media
@retval EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the
intrinsic block size of the device
@retval EFI_INVALID_PARAMETER:The read request contains LBAs that are not valid,
or the buffer is not on proper alignment
**/
);
/**
Write a specified number of blocks to the device.
@param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
@param MediaId UINT32: The media id that the write request is for
@param Lba EFI_LBA: The starting logic block address to be written
@param BufferSize UINTN: The size in bytes in Buffer
@param Buffer VOID *: A pointer to the source buffer for the data
@retval EFI_SUCCESS: The data were written correctly to the device
@retval EFI_WRITE_PROTECTED: The device can not be written to
@retval EFI_NO_MEDIA: There is no media in the device
@retval EFI_MEDIA_CHANGED: The MediaId is not for the current media
@retval EFI_DEVICE_ERROR: The device reported an error while attempting to perform
the write operation
@retval EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the
intrinsic block size of the device
@retval EFI_INVALID_PARAMETER:The write request contains LBAs that are not valid,
or the buffer is not on proper alignment
**/
);
//
// Prototypes of internal functions
//
/**
Detect the floppy drive is presented or not.
@param FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure FDC_BLK_IO_DEV
@retval EFI_SUCCESS Drive is presented
@retval EFI_NOT_FOUND Drive is not presented
**/
);
/**
Do recalibrate and see the drive is presented or not.
Set the media parameters.
@param FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure FDC_BLK_IO_DEV
@return the drive is presented or not
**/
);
/**
Reset the Floppy Logic Drive.
@param FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure 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 (
);
/**
Turn the drive's motor on.
The drive's motor must be on before any command can be executed.
@param FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure FDC_BLK_IO_DEV
@retval EFI_SUCCESS: Turn the drive's motor on successfully
@retval EFI_DEVICE_ERROR: The drive is busy, so can not turn motor on
@retval EFI_INVALID_PARAMETER: Fail to Set timer(Cancel timer)
**/
MotorOn (
);
/**
Set a Timer and when Timer goes off, turn the motor off.
@param FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure FDC_BLK_IO_DEV
@retval EFI_SUCCESS: Set the Timer successfully
@retval EFI_INVALID_PARAMETER: Fail to Set the timer
**/
MotorOff (
);
/**
Detect the disk in the drive is changed or not.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure 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
**/
);
/**
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 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 the head of floppy drive to track 0.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV
@retval EFI_SUCCESS: Execute the Recalibrate operation successfully
@retval EFI_DEVICE_ERROR: Fail to execute the Recalibrate operation
**/
);
/**
Set the head of floppy drive to the new cylinder.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure 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 (
);
/**
Do the Sense Interrupt Status command, this command resets the interrupt signal.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure 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
**/
);
/**
Do the Sense Drive Status command.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure 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
**/
);
/**
Update the disk media properties and if necessary reinstall Block I/O interface.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV
@retval EFI_SUCCESS: Do the operation successfully
@retval EFI_DEVICE_ERROR: Fail to the operation
**/
);
/**
Set the data rate and so on.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV
@retval EFI_SUCCESS success to set the data rate
**/
Setup (
);
/**
Read or Write a number of blocks in the same cylinder.
@param FdcDev A pointer to Data Structure 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
**/
);
/**
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 (
);
/**
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
**/
);
/**
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
**/
);
/**
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
**/
);
/**
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
**/
);
/**
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 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
**/
);
/**
Calculate the number of block in the same cylinder according to Lba.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure 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
**/
);
/**
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
**/
);
/**
Read I/O port for FDC.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV
@param Offset The offset address of port
**/
);
/**
Write I/O port for FDC.
@param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV
@param Offset The offset address of port
@param Data Value written to port
**/
);
/**
Read or Write a number of blocks to floppy device.
@param This Pointer to instance of EFI_BLOCK_IO_PROTOCOL
@param Lba The starting logic block address to read from on the device
@param BufferSize The size of the Buffer in bytes
@param Operation - GC_TODO: add argument description
@param Buffer - GC_TODO: add argument description
@retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
@retval EFI_SUCCESS - 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_NO_MEDIA - GC_TODO: Add description for return value
@retval EFI_MEDIA_CHANGED - GC_TODO: Add description for return value
@retval EFI_WRITE_PROTECTED - GC_TODO: Add description for return value
@retval EFI_BAD_BUFFER_SIZE - GC_TODO: Add description for return value
@retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
@retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
@retval EFI_SUCCESS - 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
**/
);
/**
Common interface for free cache.
@param FdcDev Pointer of FDC_BLK_IO_DEV instance
**/
);
#endif