3 Copyright (c) 2006 - 2007, Intel Corporation<BR>
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this 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.
18 Include for ISA Floppy Driver
19 Define the data structure and so on
29 #include <FrameworkPei.h>
31 #include <Protocol/BlockIo.h>
32 #include <Protocol/IsaIo.h>
33 #include <Protocol/DevicePath.h>
35 #include <Library/TimerLib.h>
36 #include <Library/DebugLib.h>
37 #include <Library/UefiDriverEntryPoint.h>
38 #include <Library/BaseLib.h>
39 #include <Library/UefiLib.h>
40 #include <Library/BaseMemoryLib.h>
41 #include <Library/MemoryAllocationLib.h>
42 #include <Library/UefiBootServicesTableLib.h>
43 #include <Library/ReportStatusCodeLib.h>
45 // Driver Binding Externs
47 extern EFI_DRIVER_BINDING_PROTOCOL gFdcControllerDriver
;
48 extern EFI_COMPONENT_NAME_PROTOCOL gIsaFloppyComponentName
;
53 #define STALL_1_SECOND 1000000
54 #define STALL_1_MSECOND 1000
62 // Internal Data Structures
64 #define FDC_BLK_IO_DEV_SIGNATURE EFI_SIGNATURE_32 ('F', 'B', 'I', 'O')
65 #define FLOPPY_CONTROLLER_CONTEXT_SIGNATURE EFI_SIGNATURE_32 ('F', 'D', 'C', 'C')
76 BOOLEAN FddResetPerformed
;
77 EFI_STATUS FddResetStatus
;
78 BOOLEAN NeedRecalibrate
;
81 } FLOPPY_CONTROLLER_CONTEXT
;
86 EFI_BLOCK_IO_PROTOCOL BlkIo
;
87 EFI_BLOCK_IO_MEDIA BlkMedia
;
89 EFI_ISA_IO_PROTOCOL
*IsaIo
;
94 UINT8 PresentCylinderNumber
;
98 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
99 FLOPPY_CONTROLLER_CONTEXT
*ControllerState
;
101 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
104 #include "ComponentName.h"
106 #define FDD_BLK_IO_FROM_THIS(a) CR (a, FDC_BLK_IO_DEV, BlkIo, FDC_BLK_IO_DEV_SIGNATURE)
107 #define FLOPPY_CONTROLLER_FROM_LIST_ENTRY(a) \
109 FLOPPY_CONTROLLER_CONTEXT, \
111 FLOPPY_CONTROLLER_CONTEXT_SIGNATURE \
114 #define DISK_1440K_EOT 0x12
115 #define DISK_1440K_GPL 0x1b
116 #define DISK_1440K_DTL 0xff
117 #define DISK_1440K_NUMBER 0x02
118 #define DISK_1440K_MAXTRACKNUM 0x4f
119 #define DISK_1440K_BYTEPERSECTOR 512
131 } FDD_COMMAND_PACKET1
;
136 } FDD_COMMAND_PACKET2
;
175 // 0x3F2 Digital Output Register
177 #define FDC_REGISTER_DOR 2
180 // 0x3F4 Main Status Register
182 #define FDC_REGISTER_MSR 4
185 // 0x3F5 Data Register
187 #define FDC_REGISTER_DTR 5
190 // 0x3F7 Configuration Control Register(data rate select)
192 #define FDC_REGISTER_CCR 7
195 // 0x3F7 Digital Input Register(diskchange)
197 #define FDC_REGISTER_DIR 7
202 // FDC Register Bit Definitions
205 // Digital Out Register(WO)
208 // Select Drive: 0=A 1=B
210 #define SELECT_DRV BIT0
215 #define RESET_FDC BIT2
220 #define INT_DMA_ENABLE BIT3
223 // Turn On Drive A Motor
225 #define DRVA_MOTOR_ON BIT4
228 // Turn On Drive B Motor
230 #define DRVB_MOTOR_ON BIT5
233 // Main Status Register(RO)
261 // Request For Master
266 // Configuration Control Register(WO)
271 #define CCR_DRC (BIT0 | BIT1)
274 // Digital Input Register(RO)
281 // #define CCR_DCL BIT7 // Diskette change
285 #define DRC_500KBS 0x0
290 #define DRC_300KBS 0x01
295 #define DRC_250KBS 0x02
300 #define READ_DATA_CMD 0x06
301 #define WRITE_DATA_CMD 0x05
302 #define WRITE_DEL_DATA_CMD 0x09
303 #define READ_DEL_DATA_CMD 0x0C
304 #define READ_TRACK_CMD 0x02
305 #define READ_ID_CMD 0x0A
306 #define FORMAT_TRACK_CMD 0x0D
307 #define SCAN_EQU_CMD 0x11
308 #define SCAN_LOW_EQU_CMD 0x19
309 #define SCAN_HIGH_EQU_CMD 0x1D
310 #define SEEK_CMD 0x0F
311 #define RECALIBRATE_CMD 0x07
312 #define SENSE_INT_STATUS_CMD 0x08
313 #define SPECIFY_CMD 0x03
314 #define SENSE_DRV_STATUS_CMD 0x04
317 // CMD_MT: Multi_Track Selector
318 // when set , this flag selects the multi-track operating mode.
319 // In this mode, the FDC treats a complete cylinder under head0 and 1
325 // CMD_MFM: MFM/FM Mode Selector
326 // A one selects the double density(MFM) mode
327 // A zero selects single density (FM) mode
333 // When set to 1, sectors containing a deleted data address mark will
334 // automatically be skipped during the execution of Read Data.
335 // When set to 0, the sector is read or written the same as the read and
341 // FDC Status Register Bit Definitions
349 #define STS0_IC (BIT7 | BIT6)
352 // Seek End: the FDC completed a seek or recalibrate command
362 // Not Ready(unused), this bit is always 0
367 // Head Address: the current head address
372 // STS0_US1 & STS0_US0: Drive Select(the current selected drive)
377 #define STS0_US1 BIT1
382 #define STS0_US0 BIT0
396 // Data Error: The FDC detected a CRC error in either the ID field or
397 // data field of a sector
402 // Overrun/Underrun: Becomes set if FDC does not receive CPU or DMA service
403 // within the required time interval
421 // Missing Address Mark
431 // Data Error in Data Field: The FDC detected a CRC error in the data field
436 // Wrong Cylinder: The track address from sector ID field is different from
437 // the track address maintained inside FDC
447 // Missing Address Mark in Data Field
467 // STS3_US1 & STS3_US0 : Drive Select
469 #define STS3_US1 BIT1
470 #define STS3_US0 BIT0
473 // Status Register 0 Interrupt Code Description
476 // Normal Termination of Command
481 // Abnormal Termination of Command
491 // Abnormal Termination caused by Polling
498 extern EFI_DRIVER_BINDING_PROTOCOL gFdcControllerDriver
;
501 // EFI Driver Binding Protocol Functions
505 FdcControllerDriverSupported (
506 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
507 IN EFI_HANDLE Controller
,
508 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
514 GC_TODO: Add function description
518 This - GC_TODO: add argument description
519 Controller - GC_TODO: add argument description
520 RemainingDevicePath - GC_TODO: add argument description
524 GC_TODO: add return values
531 FdcControllerDriverStart (
532 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
533 IN EFI_HANDLE Controller
,
534 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
540 GC_TODO: Add function description
544 This - GC_TODO: add argument description
545 Controller - GC_TODO: add argument description
546 RemainingDevicePath - GC_TODO: add argument description
550 GC_TODO: add return values
557 FdcControllerDriverStop (
558 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
559 IN EFI_HANDLE Controller
,
560 IN UINTN NumberOfChildren
,
561 IN EFI_HANDLE
*ChildHandleBuffer
567 GC_TODO: Add function description
571 This - GC_TODO: add argument description
572 Controller - GC_TODO: add argument description
573 NumberOfChildren - GC_TODO: add argument description
574 ChildHandleBuffer - GC_TODO: add argument description
578 GC_TODO: add return values
584 // EFI Block I/O Protocol Functions
589 IN EFI_BLOCK_IO_PROTOCOL
*This
,
590 IN BOOLEAN ExtendedVerification
596 GC_TODO: Add function description
600 This - GC_TODO: add argument description
601 ExtendedVerification - GC_TODO: add argument description
605 GC_TODO: add return values
613 IN EFI_BLOCK_IO_PROTOCOL
*This
619 GC_TODO: Add function description
623 This - GC_TODO: add argument description
627 GC_TODO: add return values
635 IN EFI_BLOCK_IO_PROTOCOL
*This
,
645 GC_TODO: Add function description
649 This - GC_TODO: add argument description
650 MediaId - GC_TODO: add argument description
651 LBA - GC_TODO: add argument description
652 BufferSize - GC_TODO: add argument description
653 Buffer - GC_TODO: add argument description
657 GC_TODO: add return values
665 IN EFI_BLOCK_IO_PROTOCOL
*This
,
675 GC_TODO: Add function description
679 This - GC_TODO: add argument description
680 MediaId - GC_TODO: add argument description
681 LBA - GC_TODO: add argument description
682 BufferSize - GC_TODO: add argument description
683 Buffer - GC_TODO: add argument description
687 GC_TODO: add return values
693 // Prototypes of internal functions
697 IN FDC_BLK_IO_DEV
*FdcDev
703 GC_TODO: Add function description
707 FdcDev - GC_TODO: add argument description
711 GC_TODO: add return values
718 IN FDC_BLK_IO_DEV
*FdcDev
724 GC_TODO: Add function description
728 FdcDev - GC_TODO: add argument description
732 GC_TODO: add return values
739 IN FDC_BLK_IO_DEV
*FdcDev
745 GC_TODO: Add function description
749 FdcDev - GC_TODO: add argument description
753 GC_TODO: add return values
760 IN FDC_BLK_IO_DEV
*FdcDev
766 GC_TODO: Add function description
770 FdcDev - GC_TODO: add argument description
774 GC_TODO: add return values
781 IN FDC_BLK_IO_DEV
*FdcDev
787 GC_TODO: Add function description
791 FdcDev - GC_TODO: add argument description
795 GC_TODO: add return values
802 IN FDC_BLK_IO_DEV
*FdcDev
808 GC_TODO: Add function description
812 FdcDev - GC_TODO: add argument description
816 GC_TODO: add return values
823 IN FDC_BLK_IO_DEV
*FdcDev
829 GC_TODO: Add function description
833 FdcDev - GC_TODO: add argument description
837 GC_TODO: add return values
844 IN FDC_BLK_IO_DEV
*FdcDev
850 GC_TODO: Add function description
854 FdcDev - GC_TODO: add argument description
858 GC_TODO: add return values
865 IN FDC_BLK_IO_DEV
*FdcDev
,
872 GC_TODO: Add function description
876 FdcDev - GC_TODO: add argument description
877 Lba - GC_TODO: add argument description
881 GC_TODO: add return values
888 IN FDC_BLK_IO_DEV
*FdcDev
,
889 IN OUT UINT8
*StatusRegister0
,
890 IN OUT UINT8
*PresentCylinderNumber
896 GC_TODO: Add function description
900 FdcDev - GC_TODO: add argument description
901 StatusRegister0 - GC_TODO: add argument description
902 PresentCylinderNumber - GC_TODO: add argument description
906 GC_TODO: add return values
913 IN FDC_BLK_IO_DEV
*FdcDev
,
920 GC_TODO: Add function description
924 FdcDev - GC_TODO: add argument description
925 Lba - GC_TODO: add argument description
929 GC_TODO: add return values
936 IN FDC_BLK_IO_DEV
*FdcDev
942 GC_TODO: Add function description
946 FdcDev - GC_TODO: add argument description
950 GC_TODO: add return values
957 IN FDC_BLK_IO_DEV
*FdcDev
963 GC_TODO: Add function description
967 FdcDev - GC_TODO: add argument description
971 GC_TODO: add return values
977 ReadWriteDataSector (
978 IN FDC_BLK_IO_DEV
*FdcDev
,
979 IN VOID
*HostAddress
,
981 IN UINTN NumberOfBlocks
,
988 GC_TODO: Add function description
992 FdcDev - GC_TODO: add argument description
993 HostAddress - GC_TODO: add argument description
994 Lba - GC_TODO: add argument description
995 NumberOfBlocks - GC_TODO: add argument description
996 Read - GC_TODO: add argument description
1000 GC_TODO: add return values
1007 IN FDC_BLK_IO_DEV
*FdcDev
,
1009 IN FDD_COMMAND_PACKET1
*Command
1013 Routine Description:
1015 GC_TODO: Add function description
1019 FdcDev - GC_TODO: add argument description
1020 Lba - GC_TODO: add argument description
1021 Command - GC_TODO: add argument description
1025 GC_TODO: add return values
1032 IN FDC_BLK_IO_DEV
*FdcDev
,
1037 Routine Description:
1039 GC_TODO: Add function description
1043 FdcDev - GC_TODO: add argument description
1044 Pointer - GC_TODO: add argument description
1048 GC_TODO: add return values
1055 IN FDC_BLK_IO_DEV
*FdcDev
,
1060 Routine Description:
1062 GC_TODO: Add function description
1066 FdcDev - GC_TODO: add argument description
1067 Pointer - GC_TODO: add argument description
1071 GC_TODO: add return values
1077 FddWaitForBSYClear (
1078 IN FDC_BLK_IO_DEV
*FdcDev
,
1079 IN UINTN TimeoutInSeconds
1083 Routine Description:
1085 GC_TODO: Add function description
1089 FdcDev - GC_TODO: add argument description
1090 TimeoutInSeconds - GC_TODO: add argument description
1094 GC_TODO: add return values
1101 IN FDC_BLK_IO_DEV
*FdcDev
,
1103 IN UINTN TimeoutInSeconds
1107 Routine Description:
1109 GC_TODO: Add function description
1113 FdcDev - GC_TODO: add argument description
1114 Dio - GC_TODO: add argument description
1115 TimeoutInSeconds - GC_TODO: add argument description
1119 GC_TODO: add return values
1126 IN FDD_RESULT_PACKET
*Result
,
1127 IN OUT FDC_BLK_IO_DEV
*FdcDev
1131 Routine Description:
1133 GC_TODO: Add function description
1137 Result - GC_TODO: add argument description
1138 FdcDev - GC_TODO: add argument description
1142 GC_TODO: add return values
1149 IN UINT8 StatusRegister3
1153 Routine Description:
1155 GC_TODO: Add function description
1159 StatusRegister3 - GC_TODO: add argument description
1163 GC_TODO: add return values
1169 GetTransferBlockCount (
1170 IN FDC_BLK_IO_DEV
*FdcDev
,
1172 IN UINTN NumberOfBlocks
1176 Routine Description:
1178 GC_TODO: Add function description
1182 FdcDev - GC_TODO: add argument description
1183 LBA - GC_TODO: add argument description
1184 NumberOfBlocks - GC_TODO: add argument description
1188 GC_TODO: add return values
1201 Routine Description:
1203 GC_TODO: Add function description
1207 Event - GC_TODO: add argument description
1208 Context - GC_TODO: add argument description
1212 GC_TODO: add return values
1219 IN FDC_BLK_IO_DEV
*FdcDev
,
1224 Routine Description:
1226 GC_TODO: Add function description
1230 FdcDev - GC_TODO: add argument description
1231 Offset - GC_TODO: add argument description
1235 GC_TODO: add return values
1242 IN FDC_BLK_IO_DEV
*FdcDev
,
1248 Routine Description:
1250 GC_TODO: Add function description
1254 FdcDev - GC_TODO: add argument description
1255 Offset - GC_TODO: add argument description
1256 Data - GC_TODO: add argument description
1260 GC_TODO: add return values
1266 FddReadWriteBlocks (
1267 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1270 IN UINTN BufferSize
,
1271 IN BOOLEAN Operation
,
1276 Routine Description:
1278 GC_TODO: Add function description
1282 This - GC_TODO: add argument description
1283 MediaId - GC_TODO: add argument description
1284 LBA - GC_TODO: add argument description
1285 BufferSize - GC_TODO: add argument description
1286 Operation - GC_TODO: add argument description
1287 Buffer - GC_TODO: add argument description
1291 GC_TODO: add return values
1298 IN FDC_BLK_IO_DEV
*FdcDev
1302 Routine Description:
1304 GC_TODO: Add function description
1308 FdcDev - GC_TODO: add argument description
1312 GC_TODO: add return values