2 Include for ISA Floppy Driver
3 Define the data structure and so on
5 Copyright (c) 2006 - 2007, Intel Corporation.<BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <FrameworkPei.h>
22 #include <Protocol/BlockIo.h>
23 #include <Protocol/IsaIo.h>
24 #include <Protocol/DevicePath.h>
26 #include <Library/TimerLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/BaseLib.h>
30 #include <Library/UefiLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/ReportStatusCodeLib.h>
36 // Driver Binding Externs
38 extern EFI_DRIVER_BINDING_PROTOCOL gFdcControllerDriver
;
39 extern EFI_COMPONENT_NAME_PROTOCOL gIsaFloppyComponentName
;
44 #define STALL_1_SECOND 1000000
45 #define STALL_1_MSECOND 1000
53 // Internal Data Structures
55 #define FDC_BLK_IO_DEV_SIGNATURE EFI_SIGNATURE_32 ('F', 'B', 'I', 'O')
56 #define FLOPPY_CONTROLLER_CONTEXT_SIGNATURE EFI_SIGNATURE_32 ('F', 'D', 'C', 'C')
67 BOOLEAN FddResetPerformed
;
68 EFI_STATUS FddResetStatus
;
69 BOOLEAN NeedRecalibrate
;
72 } FLOPPY_CONTROLLER_CONTEXT
;
77 EFI_BLOCK_IO_PROTOCOL BlkIo
;
78 EFI_BLOCK_IO_MEDIA BlkMedia
;
80 EFI_ISA_IO_PROTOCOL
*IsaIo
;
85 UINT8 PresentCylinderNumber
;
89 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
90 FLOPPY_CONTROLLER_CONTEXT
*ControllerState
;
92 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
95 #include "ComponentName.h"
97 #define FDD_BLK_IO_FROM_THIS(a) CR (a, FDC_BLK_IO_DEV, BlkIo, FDC_BLK_IO_DEV_SIGNATURE)
98 #define FLOPPY_CONTROLLER_FROM_LIST_ENTRY(a) \
100 FLOPPY_CONTROLLER_CONTEXT, \
102 FLOPPY_CONTROLLER_CONTEXT_SIGNATURE \
105 #define DISK_1440K_EOT 0x12
106 #define DISK_1440K_GPL 0x1b
107 #define DISK_1440K_DTL 0xff
108 #define DISK_1440K_NUMBER 0x02
109 #define DISK_1440K_MAXTRACKNUM 0x4f
110 #define DISK_1440K_BYTEPERSECTOR 512
122 } FDD_COMMAND_PACKET1
;
127 } FDD_COMMAND_PACKET2
;
166 // 0x3F2 Digital Output Register
168 #define FDC_REGISTER_DOR 2
171 // 0x3F4 Main Status Register
173 #define FDC_REGISTER_MSR 4
176 // 0x3F5 Data Register
178 #define FDC_REGISTER_DTR 5
181 // 0x3F7 Configuration Control Register(data rate select)
183 #define FDC_REGISTER_CCR 7
186 // 0x3F7 Digital Input Register(diskchange)
188 #define FDC_REGISTER_DIR 7
193 // FDC Register Bit Definitions
196 // Digital Out Register(WO)
199 // Select Drive: 0=A 1=B
201 #define SELECT_DRV BIT0
206 #define RESET_FDC BIT2
211 #define INT_DMA_ENABLE BIT3
214 // Turn On Drive A Motor
216 #define DRVA_MOTOR_ON BIT4
219 // Turn On Drive B Motor
221 #define DRVB_MOTOR_ON BIT5
224 // Main Status Register(RO)
252 // Request For Master
257 // Configuration Control Register(WO)
262 #define CCR_DRC (BIT0 | BIT1)
265 // Digital Input Register(RO)
272 // #define CCR_DCL BIT7 // Diskette change
276 #define DRC_500KBS 0x0
281 #define DRC_300KBS 0x01
286 #define DRC_250KBS 0x02
291 #define READ_DATA_CMD 0x06
292 #define WRITE_DATA_CMD 0x05
293 #define WRITE_DEL_DATA_CMD 0x09
294 #define READ_DEL_DATA_CMD 0x0C
295 #define READ_TRACK_CMD 0x02
296 #define READ_ID_CMD 0x0A
297 #define FORMAT_TRACK_CMD 0x0D
298 #define SCAN_EQU_CMD 0x11
299 #define SCAN_LOW_EQU_CMD 0x19
300 #define SCAN_HIGH_EQU_CMD 0x1D
301 #define SEEK_CMD 0x0F
302 #define RECALIBRATE_CMD 0x07
303 #define SENSE_INT_STATUS_CMD 0x08
304 #define SPECIFY_CMD 0x03
305 #define SENSE_DRV_STATUS_CMD 0x04
308 // CMD_MT: Multi_Track Selector
309 // when set , this flag selects the multi-track operating mode.
310 // In this mode, the FDC treats a complete cylinder under head0 and 1
316 // CMD_MFM: MFM/FM Mode Selector
317 // A one selects the double density(MFM) mode
318 // A zero selects single density (FM) mode
324 // When set to 1, sectors containing a deleted data address mark will
325 // automatically be skipped during the execution of Read Data.
326 // When set to 0, the sector is read or written the same as the read and
332 // FDC Status Register Bit Definitions
340 #define STS0_IC (BIT7 | BIT6)
343 // Seek End: the FDC completed a seek or recalibrate command
353 // Not Ready(unused), this bit is always 0
358 // Head Address: the current head address
363 // STS0_US1 & STS0_US0: Drive Select(the current selected drive)
368 #define STS0_US1 BIT1
373 #define STS0_US0 BIT0
387 // Data Error: The FDC detected a CRC error in either the ID field or
388 // data field of a sector
393 // Overrun/Underrun: Becomes set if FDC does not receive CPU or DMA service
394 // within the required time interval
412 // Missing Address Mark
422 // Data Error in Data Field: The FDC detected a CRC error in the data field
427 // Wrong Cylinder: The track address from sector ID field is different from
428 // the track address maintained inside FDC
438 // Missing Address Mark in Data Field
458 // STS3_US1 & STS3_US0 : Drive Select
460 #define STS3_US1 BIT1
461 #define STS3_US0 BIT0
464 // Status Register 0 Interrupt Code Description
467 // Normal Termination of Command
472 // Abnormal Termination of Command
482 // Abnormal Termination caused by Polling
489 extern EFI_DRIVER_BINDING_PROTOCOL gFdcControllerDriver
;
492 // EFI Driver Binding Protocol Functions
496 FdcControllerDriverSupported (
497 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
498 IN EFI_HANDLE Controller
,
499 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
505 GC_TODO: Add function description
509 This - GC_TODO: add argument description
510 Controller - GC_TODO: add argument description
511 RemainingDevicePath - GC_TODO: add argument description
515 GC_TODO: add return values
522 FdcControllerDriverStart (
523 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
524 IN EFI_HANDLE Controller
,
525 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
531 GC_TODO: Add function description
535 This - GC_TODO: add argument description
536 Controller - GC_TODO: add argument description
537 RemainingDevicePath - GC_TODO: add argument description
541 GC_TODO: add return values
548 FdcControllerDriverStop (
549 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
550 IN EFI_HANDLE Controller
,
551 IN UINTN NumberOfChildren
,
552 IN EFI_HANDLE
*ChildHandleBuffer
558 GC_TODO: Add function description
562 This - GC_TODO: add argument description
563 Controller - GC_TODO: add argument description
564 NumberOfChildren - GC_TODO: add argument description
565 ChildHandleBuffer - GC_TODO: add argument description
569 GC_TODO: add return values
575 // EFI Block I/O Protocol Functions
580 IN EFI_BLOCK_IO_PROTOCOL
*This
,
581 IN BOOLEAN ExtendedVerification
587 GC_TODO: Add function description
591 This - GC_TODO: add argument description
592 ExtendedVerification - GC_TODO: add argument description
596 GC_TODO: add return values
604 IN EFI_BLOCK_IO_PROTOCOL
*This
610 GC_TODO: Add function description
614 This - GC_TODO: add argument description
618 GC_TODO: add return values
626 IN EFI_BLOCK_IO_PROTOCOL
*This
,
636 GC_TODO: Add function description
640 This - GC_TODO: add argument description
641 MediaId - GC_TODO: add argument description
642 LBA - GC_TODO: add argument description
643 BufferSize - GC_TODO: add argument description
644 Buffer - GC_TODO: add argument description
648 GC_TODO: add return values
656 IN EFI_BLOCK_IO_PROTOCOL
*This
,
666 GC_TODO: Add function description
670 This - GC_TODO: add argument description
671 MediaId - GC_TODO: add argument description
672 LBA - GC_TODO: add argument description
673 BufferSize - GC_TODO: add argument description
674 Buffer - GC_TODO: add argument description
678 GC_TODO: add return values
684 // Prototypes of internal functions
688 IN FDC_BLK_IO_DEV
*FdcDev
694 GC_TODO: Add function description
698 FdcDev - GC_TODO: add argument description
702 GC_TODO: add return values
709 IN FDC_BLK_IO_DEV
*FdcDev
715 GC_TODO: Add function description
719 FdcDev - GC_TODO: add argument description
723 GC_TODO: add return values
730 IN FDC_BLK_IO_DEV
*FdcDev
736 GC_TODO: Add function description
740 FdcDev - GC_TODO: add argument description
744 GC_TODO: add return values
751 IN FDC_BLK_IO_DEV
*FdcDev
757 GC_TODO: Add function description
761 FdcDev - GC_TODO: add argument description
765 GC_TODO: add return values
772 IN FDC_BLK_IO_DEV
*FdcDev
778 GC_TODO: Add function description
782 FdcDev - GC_TODO: add argument description
786 GC_TODO: add return values
793 IN FDC_BLK_IO_DEV
*FdcDev
799 GC_TODO: Add function description
803 FdcDev - GC_TODO: add argument description
807 GC_TODO: add return values
814 IN FDC_BLK_IO_DEV
*FdcDev
820 GC_TODO: Add function description
824 FdcDev - GC_TODO: add argument description
828 GC_TODO: add return values
835 IN FDC_BLK_IO_DEV
*FdcDev
841 GC_TODO: Add function description
845 FdcDev - GC_TODO: add argument description
849 GC_TODO: add return values
856 IN FDC_BLK_IO_DEV
*FdcDev
,
863 GC_TODO: Add function description
867 FdcDev - GC_TODO: add argument description
868 Lba - GC_TODO: add argument description
872 GC_TODO: add return values
879 IN FDC_BLK_IO_DEV
*FdcDev
,
880 IN OUT UINT8
*StatusRegister0
,
881 IN OUT UINT8
*PresentCylinderNumber
887 GC_TODO: Add function description
891 FdcDev - GC_TODO: add argument description
892 StatusRegister0 - GC_TODO: add argument description
893 PresentCylinderNumber - GC_TODO: add argument description
897 GC_TODO: add return values
904 IN FDC_BLK_IO_DEV
*FdcDev
,
911 GC_TODO: Add function description
915 FdcDev - GC_TODO: add argument description
916 Lba - GC_TODO: add argument description
920 GC_TODO: add return values
927 IN FDC_BLK_IO_DEV
*FdcDev
933 GC_TODO: Add function description
937 FdcDev - GC_TODO: add argument description
941 GC_TODO: add return values
948 IN FDC_BLK_IO_DEV
*FdcDev
954 GC_TODO: Add function description
958 FdcDev - GC_TODO: add argument description
962 GC_TODO: add return values
968 ReadWriteDataSector (
969 IN FDC_BLK_IO_DEV
*FdcDev
,
970 IN VOID
*HostAddress
,
972 IN UINTN NumberOfBlocks
,
979 GC_TODO: Add function description
983 FdcDev - GC_TODO: add argument description
984 HostAddress - GC_TODO: add argument description
985 Lba - GC_TODO: add argument description
986 NumberOfBlocks - GC_TODO: add argument description
987 Read - GC_TODO: add argument description
991 GC_TODO: add return values
998 IN FDC_BLK_IO_DEV
*FdcDev
,
1000 IN FDD_COMMAND_PACKET1
*Command
1004 Routine Description:
1006 GC_TODO: Add function description
1010 FdcDev - GC_TODO: add argument description
1011 Lba - GC_TODO: add argument description
1012 Command - GC_TODO: add argument description
1016 GC_TODO: add return values
1023 IN FDC_BLK_IO_DEV
*FdcDev
,
1028 Routine Description:
1030 GC_TODO: Add function description
1034 FdcDev - GC_TODO: add argument description
1035 Pointer - GC_TODO: add argument description
1039 GC_TODO: add return values
1046 IN FDC_BLK_IO_DEV
*FdcDev
,
1051 Routine Description:
1053 GC_TODO: Add function description
1057 FdcDev - GC_TODO: add argument description
1058 Pointer - GC_TODO: add argument description
1062 GC_TODO: add return values
1068 FddWaitForBSYClear (
1069 IN FDC_BLK_IO_DEV
*FdcDev
,
1070 IN UINTN TimeoutInSeconds
1074 Routine Description:
1076 GC_TODO: Add function description
1080 FdcDev - GC_TODO: add argument description
1081 TimeoutInSeconds - GC_TODO: add argument description
1085 GC_TODO: add return values
1092 IN FDC_BLK_IO_DEV
*FdcDev
,
1094 IN UINTN TimeoutInSeconds
1098 Routine Description:
1100 GC_TODO: Add function description
1104 FdcDev - GC_TODO: add argument description
1105 Dio - GC_TODO: add argument description
1106 TimeoutInSeconds - GC_TODO: add argument description
1110 GC_TODO: add return values
1117 IN FDD_RESULT_PACKET
*Result
,
1118 IN OUT FDC_BLK_IO_DEV
*FdcDev
1122 Routine Description:
1124 GC_TODO: Add function description
1128 Result - GC_TODO: add argument description
1129 FdcDev - GC_TODO: add argument description
1133 GC_TODO: add return values
1140 IN UINT8 StatusRegister3
1144 Routine Description:
1146 GC_TODO: Add function description
1150 StatusRegister3 - GC_TODO: add argument description
1154 GC_TODO: add return values
1160 GetTransferBlockCount (
1161 IN FDC_BLK_IO_DEV
*FdcDev
,
1163 IN UINTN NumberOfBlocks
1167 Routine Description:
1169 GC_TODO: Add function description
1173 FdcDev - GC_TODO: add argument description
1174 LBA - GC_TODO: add argument description
1175 NumberOfBlocks - GC_TODO: add argument description
1179 GC_TODO: add return values
1192 Routine Description:
1194 GC_TODO: Add function description
1198 Event - GC_TODO: add argument description
1199 Context - GC_TODO: add argument description
1203 GC_TODO: add return values
1210 IN FDC_BLK_IO_DEV
*FdcDev
,
1215 Routine Description:
1217 GC_TODO: Add function description
1221 FdcDev - GC_TODO: add argument description
1222 Offset - GC_TODO: add argument description
1226 GC_TODO: add return values
1233 IN FDC_BLK_IO_DEV
*FdcDev
,
1239 Routine Description:
1241 GC_TODO: Add function description
1245 FdcDev - GC_TODO: add argument description
1246 Offset - GC_TODO: add argument description
1247 Data - GC_TODO: add argument description
1251 GC_TODO: add return values
1257 FddReadWriteBlocks (
1258 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1261 IN UINTN BufferSize
,
1262 IN BOOLEAN Operation
,
1267 Routine Description:
1269 GC_TODO: Add function description
1273 This - GC_TODO: add argument description
1274 MediaId - GC_TODO: add argument description
1275 LBA - GC_TODO: add argument description
1276 BufferSize - GC_TODO: add argument description
1277 Operation - GC_TODO: add argument description
1278 Buffer - GC_TODO: add argument description
1282 GC_TODO: add return values
1289 IN FDC_BLK_IO_DEV
*FdcDev
1293 Routine Description:
1295 GC_TODO: Add function description
1299 FdcDev - GC_TODO: add argument description
1303 GC_TODO: add return values