3 Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
18 Include for ISA Floppy Driver
19 Define the data structure and so on
29 #include <FrameworkPei.h>
31 // The protocols, PPI and GUID defintions for this module
33 #include <Protocol/BlockIo.h>
34 #include <Protocol/IsaIo.h>
35 #include <Protocol/DevicePath.h>
37 // The Library classes this module consumes
39 #include <Library/TimerLib.h>
40 #include <Library/DebugLib.h>
41 #include <Library/UefiDriverEntryPoint.h>
42 #include <Library/BaseLib.h>
43 #include <Library/UefiLib.h>
44 #include <Library/BaseMemoryLib.h>
45 #include <Library/MemoryAllocationLib.h>
46 #include <Library/UefiBootServicesTableLib.h>
47 #include <Library/ReportStatusCodeLib.h>
49 // Driver Binding Externs
51 extern EFI_DRIVER_BINDING_PROTOCOL gFdcControllerDriver
;
52 extern EFI_COMPONENT_NAME_PROTOCOL gIsaFloppyComponentName
;
57 #define STALL_1_SECOND 1000000
58 #define STALL_1_MSECOND 1000
66 // Internal Data Structures
68 #define FDC_BLK_IO_DEV_SIGNATURE EFI_SIGNATURE_32 ('F', 'B', 'I', 'O')
69 #define FLOPPY_CONTROLLER_CONTEXT_SIGNATURE EFI_SIGNATURE_32 ('F', 'D', 'C', 'C')
80 BOOLEAN FddResetPerformed
;
81 EFI_STATUS FddResetStatus
;
82 BOOLEAN NeedRecalibrate
;
85 } FLOPPY_CONTROLLER_CONTEXT
;
90 EFI_BLOCK_IO_PROTOCOL BlkIo
;
91 EFI_BLOCK_IO_MEDIA BlkMedia
;
93 EFI_ISA_IO_PROTOCOL
*IsaIo
;
98 UINT8 PresentCylinderNumber
;
102 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
103 FLOPPY_CONTROLLER_CONTEXT
*ControllerState
;
105 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
108 #include "ComponentName.h"
110 #define FDD_BLK_IO_FROM_THIS(a) CR (a, FDC_BLK_IO_DEV, BlkIo, FDC_BLK_IO_DEV_SIGNATURE)
111 #define FLOPPY_CONTROLLER_FROM_LIST_ENTRY(a) \
113 FLOPPY_CONTROLLER_CONTEXT, \
115 FLOPPY_CONTROLLER_CONTEXT_SIGNATURE \
118 #define DISK_1440K_EOT 0x12
119 #define DISK_1440K_GPL 0x1b
120 #define DISK_1440K_DTL 0xff
121 #define DISK_1440K_NUMBER 0x02
122 #define DISK_1440K_MAXTRACKNUM 0x4f
123 #define DISK_1440K_BYTEPERSECTOR 512
135 } FDD_COMMAND_PACKET1
;
140 } FDD_COMMAND_PACKET2
;
179 // 0x3F2 Digital Output Register
181 #define FDC_REGISTER_DOR 2
184 // 0x3F4 Main Status Register
186 #define FDC_REGISTER_MSR 4
189 // 0x3F5 Data Register
191 #define FDC_REGISTER_DTR 5
194 // 0x3F7 Configuration Control Register(data rate select)
196 #define FDC_REGISTER_CCR 7
199 // 0x3F7 Digital Input Register(diskchange)
201 #define FDC_REGISTER_DIR 7
206 // FDC Register Bit Definitions
209 // Digital Out Register(WO)
212 // Select Drive: 0=A 1=B
214 #define SELECT_DRV BIT0
219 #define RESET_FDC BIT2
224 #define INT_DMA_ENABLE BIT3
227 // Turn On Drive A Motor
229 #define DRVA_MOTOR_ON BIT4
232 // Turn On Drive B Motor
234 #define DRVB_MOTOR_ON BIT5
237 // Main Status Register(RO)
265 // Request For Master
270 // Configuration Control Register(WO)
275 #define CCR_DRC (BIT0 | BIT1)
278 // Digital Input Register(RO)
285 // #define CCR_DCL BIT7 // Diskette change
289 #define DRC_500KBS 0x0
294 #define DRC_300KBS 0x01
299 #define DRC_250KBS 0x02
304 #define READ_DATA_CMD 0x06
305 #define WRITE_DATA_CMD 0x05
306 #define WRITE_DEL_DATA_CMD 0x09
307 #define READ_DEL_DATA_CMD 0x0C
308 #define READ_TRACK_CMD 0x02
309 #define READ_ID_CMD 0x0A
310 #define FORMAT_TRACK_CMD 0x0D
311 #define SCAN_EQU_CMD 0x11
312 #define SCAN_LOW_EQU_CMD 0x19
313 #define SCAN_HIGH_EQU_CMD 0x1D
314 #define SEEK_CMD 0x0F
315 #define RECALIBRATE_CMD 0x07
316 #define SENSE_INT_STATUS_CMD 0x08
317 #define SPECIFY_CMD 0x03
318 #define SENSE_DRV_STATUS_CMD 0x04
321 // CMD_MT: Multi_Track Selector
322 // when set , this flag selects the multi-track operating mode.
323 // In this mode, the FDC treats a complete cylinder under head0 and 1
329 // CMD_MFM: MFM/FM Mode Selector
330 // A one selects the double density(MFM) mode
331 // A zero selects single density (FM) mode
337 // When set to 1, sectors containing a deleted data address mark will
338 // automatically be skipped during the execution of Read Data.
339 // When set to 0, the sector is read or written the same as the read and
345 // FDC Status Register Bit Definitions
353 #define STS0_IC (BIT7 | BIT6)
356 // Seek End: the FDC completed a seek or recalibrate command
366 // Not Ready(unused), this bit is always 0
371 // Head Address: the current head address
376 // STS0_US1 & STS0_US0: Drive Select(the current selected drive)
381 #define STS0_US1 BIT1
386 #define STS0_US0 BIT0
400 // Data Error: The FDC detected a CRC error in either the ID field or
401 // data field of a sector
406 // Overrun/Underrun: Becomes set if FDC does not receive CPU or DMA service
407 // within the required time interval
425 // Missing Address Mark
435 // Data Error in Data Field: The FDC detected a CRC error in the data field
440 // Wrong Cylinder: The track address from sector ID field is different from
441 // the track address maintained inside FDC
451 // Missing Address Mark in Data Field
471 // STS3_US1 & STS3_US0 : Drive Select
473 #define STS3_US1 BIT1
474 #define STS3_US0 BIT0
477 // Status Register 0 Interrupt Code Description
480 // Normal Termination of Command
485 // Abnormal Termination of Command
495 // Abnormal Termination caused by Polling
502 extern EFI_DRIVER_BINDING_PROTOCOL gFdcControllerDriver
;
505 // EFI Driver Binding Protocol Functions
509 FdcControllerDriverSupported (
510 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
511 IN EFI_HANDLE Controller
,
512 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
518 GC_TODO: Add function description
522 This - GC_TODO: add argument description
523 Controller - GC_TODO: add argument description
524 RemainingDevicePath - GC_TODO: add argument description
528 GC_TODO: add return values
535 FdcControllerDriverStart (
536 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
537 IN EFI_HANDLE Controller
,
538 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
544 GC_TODO: Add function description
548 This - GC_TODO: add argument description
549 Controller - GC_TODO: add argument description
550 RemainingDevicePath - GC_TODO: add argument description
554 GC_TODO: add return values
561 FdcControllerDriverStop (
562 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
563 IN EFI_HANDLE Controller
,
564 IN UINTN NumberOfChildren
,
565 IN EFI_HANDLE
*ChildHandleBuffer
571 GC_TODO: Add function description
575 This - GC_TODO: add argument description
576 Controller - GC_TODO: add argument description
577 NumberOfChildren - GC_TODO: add argument description
578 ChildHandleBuffer - GC_TODO: add argument description
582 GC_TODO: add return values
588 // EFI Block I/O Protocol Functions
593 IN EFI_BLOCK_IO_PROTOCOL
*This
,
594 IN BOOLEAN ExtendedVerification
600 GC_TODO: Add function description
604 This - GC_TODO: add argument description
605 ExtendedVerification - GC_TODO: add argument description
609 GC_TODO: add return values
617 IN EFI_BLOCK_IO_PROTOCOL
*This
623 GC_TODO: Add function description
627 This - GC_TODO: add argument description
631 GC_TODO: add return values
639 IN EFI_BLOCK_IO_PROTOCOL
*This
,
649 GC_TODO: Add function description
653 This - GC_TODO: add argument description
654 MediaId - GC_TODO: add argument description
655 LBA - GC_TODO: add argument description
656 BufferSize - GC_TODO: add argument description
657 Buffer - GC_TODO: add argument description
661 GC_TODO: add return values
669 IN EFI_BLOCK_IO_PROTOCOL
*This
,
679 GC_TODO: Add function description
683 This - GC_TODO: add argument description
684 MediaId - GC_TODO: add argument description
685 LBA - GC_TODO: add argument description
686 BufferSize - GC_TODO: add argument description
687 Buffer - GC_TODO: add argument description
691 GC_TODO: add return values
697 // Prototypes of internal functions
701 IN FDC_BLK_IO_DEV
*FdcDev
707 GC_TODO: Add function description
711 FdcDev - GC_TODO: add argument description
715 GC_TODO: add return values
722 IN FDC_BLK_IO_DEV
*FdcDev
728 GC_TODO: Add function description
732 FdcDev - GC_TODO: add argument description
736 GC_TODO: add return values
743 IN FDC_BLK_IO_DEV
*FdcDev
749 GC_TODO: Add function description
753 FdcDev - GC_TODO: add argument description
757 GC_TODO: add return values
764 IN FDC_BLK_IO_DEV
*FdcDev
770 GC_TODO: Add function description
774 FdcDev - GC_TODO: add argument description
778 GC_TODO: add return values
785 IN FDC_BLK_IO_DEV
*FdcDev
791 GC_TODO: Add function description
795 FdcDev - GC_TODO: add argument description
799 GC_TODO: add return values
806 IN FDC_BLK_IO_DEV
*FdcDev
812 GC_TODO: Add function description
816 FdcDev - GC_TODO: add argument description
820 GC_TODO: add return values
827 IN FDC_BLK_IO_DEV
*FdcDev
833 GC_TODO: Add function description
837 FdcDev - GC_TODO: add argument description
841 GC_TODO: add return values
848 IN FDC_BLK_IO_DEV
*FdcDev
854 GC_TODO: Add function description
858 FdcDev - GC_TODO: add argument description
862 GC_TODO: add return values
869 IN FDC_BLK_IO_DEV
*FdcDev
,
876 GC_TODO: Add function description
880 FdcDev - GC_TODO: add argument description
881 Lba - GC_TODO: add argument description
885 GC_TODO: add return values
892 IN FDC_BLK_IO_DEV
*FdcDev
,
893 IN OUT UINT8
*StatusRegister0
,
894 IN OUT UINT8
*PresentCylinderNumber
900 GC_TODO: Add function description
904 FdcDev - GC_TODO: add argument description
905 StatusRegister0 - GC_TODO: add argument description
906 PresentCylinderNumber - GC_TODO: add argument description
910 GC_TODO: add return values
917 IN FDC_BLK_IO_DEV
*FdcDev
,
924 GC_TODO: Add function description
928 FdcDev - GC_TODO: add argument description
929 Lba - GC_TODO: add argument description
933 GC_TODO: add return values
940 IN FDC_BLK_IO_DEV
*FdcDev
946 GC_TODO: Add function description
950 FdcDev - GC_TODO: add argument description
954 GC_TODO: add return values
961 IN FDC_BLK_IO_DEV
*FdcDev
967 GC_TODO: Add function description
971 FdcDev - GC_TODO: add argument description
975 GC_TODO: add return values
981 ReadWriteDataSector (
982 IN FDC_BLK_IO_DEV
*FdcDev
,
983 IN VOID
*HostAddress
,
985 IN UINTN NumberOfBlocks
,
992 GC_TODO: Add function description
996 FdcDev - GC_TODO: add argument description
997 HostAddress - GC_TODO: add argument description
998 Lba - GC_TODO: add argument description
999 NumberOfBlocks - GC_TODO: add argument description
1000 Read - GC_TODO: add argument description
1004 GC_TODO: add return values
1011 IN FDC_BLK_IO_DEV
*FdcDev
,
1013 IN FDD_COMMAND_PACKET1
*Command
1017 Routine Description:
1019 GC_TODO: Add function description
1023 FdcDev - GC_TODO: add argument description
1024 Lba - GC_TODO: add argument description
1025 Command - GC_TODO: add argument description
1029 GC_TODO: add return values
1036 IN FDC_BLK_IO_DEV
*FdcDev
,
1041 Routine Description:
1043 GC_TODO: Add function description
1047 FdcDev - GC_TODO: add argument description
1048 Pointer - GC_TODO: add argument description
1052 GC_TODO: add return values
1059 IN FDC_BLK_IO_DEV
*FdcDev
,
1064 Routine Description:
1066 GC_TODO: Add function description
1070 FdcDev - GC_TODO: add argument description
1071 Pointer - GC_TODO: add argument description
1075 GC_TODO: add return values
1081 FddWaitForBSYClear (
1082 IN FDC_BLK_IO_DEV
*FdcDev
,
1083 IN UINTN TimeoutInSeconds
1087 Routine Description:
1089 GC_TODO: Add function description
1093 FdcDev - GC_TODO: add argument description
1094 TimeoutInSeconds - GC_TODO: add argument description
1098 GC_TODO: add return values
1105 IN FDC_BLK_IO_DEV
*FdcDev
,
1107 IN UINTN TimeoutInSeconds
1111 Routine Description:
1113 GC_TODO: Add function description
1117 FdcDev - GC_TODO: add argument description
1118 Dio - GC_TODO: add argument description
1119 TimeoutInSeconds - GC_TODO: add argument description
1123 GC_TODO: add return values
1130 IN FDD_RESULT_PACKET
*Result
,
1131 IN OUT FDC_BLK_IO_DEV
*FdcDev
1135 Routine Description:
1137 GC_TODO: Add function description
1141 Result - GC_TODO: add argument description
1142 FdcDev - GC_TODO: add argument description
1146 GC_TODO: add return values
1153 IN UINT8 StatusRegister3
1157 Routine Description:
1159 GC_TODO: Add function description
1163 StatusRegister3 - GC_TODO: add argument description
1167 GC_TODO: add return values
1173 GetTransferBlockCount (
1174 IN FDC_BLK_IO_DEV
*FdcDev
,
1176 IN UINTN NumberOfBlocks
1180 Routine Description:
1182 GC_TODO: Add function description
1186 FdcDev - GC_TODO: add argument description
1187 LBA - GC_TODO: add argument description
1188 NumberOfBlocks - GC_TODO: add argument description
1192 GC_TODO: add return values
1205 Routine Description:
1207 GC_TODO: Add function description
1211 Event - GC_TODO: add argument description
1212 Context - GC_TODO: add argument description
1216 GC_TODO: add return values
1223 IN FDC_BLK_IO_DEV
*FdcDev
,
1228 Routine Description:
1230 GC_TODO: Add function description
1234 FdcDev - GC_TODO: add argument description
1235 Offset - GC_TODO: add argument description
1239 GC_TODO: add return values
1246 IN FDC_BLK_IO_DEV
*FdcDev
,
1252 Routine Description:
1254 GC_TODO: Add function description
1258 FdcDev - GC_TODO: add argument description
1259 Offset - GC_TODO: add argument description
1260 Data - GC_TODO: add argument description
1264 GC_TODO: add return values
1270 FddReadWriteBlocks (
1271 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1274 IN UINTN BufferSize
,
1275 IN BOOLEAN Operation
,
1280 Routine Description:
1282 GC_TODO: Add function description
1286 This - GC_TODO: add argument description
1287 MediaId - GC_TODO: add argument description
1288 LBA - GC_TODO: add argument description
1289 BufferSize - GC_TODO: add argument description
1290 Operation - GC_TODO: add argument description
1291 Buffer - GC_TODO: add argument description
1295 GC_TODO: add return values
1302 IN FDC_BLK_IO_DEV
*FdcDev
1306 Routine Description:
1308 GC_TODO: Add function description
1312 FdcDev - GC_TODO: add argument description
1316 GC_TODO: add return values