3 1. Support two types diskette drive
4 1.44M drive and 2.88M drive (and now only support 1.44M)
5 2. Support two diskette drives
6 3. Use DMA channel 2 to transfer data
7 4. Do not use interrupt
8 5. Support diskette change line signal and write protect
10 Implement the Block IO interface
12 Copyright (c) 2006 - 2007, Intel Corporation.<BR>
13 All rights reserved. This program and the accompanying materials
14 are licensed and made available under the terms and conditions of the BSD License
15 which accompanies this distribution. The full text of the license may be found at
16 http://opensource.org/licenses/bsd-license.php
18 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
19 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 #include "IsaFloppy.h"
27 Reset the Floppy Logic Drive, call the FddReset function
29 @param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
30 @param ExtendedVerification BOOLEAN: Indicate that the driver may perform a more
31 exhaustive verification operation of the device during
32 reset, now this par is ignored in this driver
33 @retval EFI_SUCCESS: The Floppy Logic Drive is reset
34 @retval EFI_DEVICE_ERROR: The Floppy Logic Drive is not functioning correctly
41 IN EFI_BLOCK_IO_PROTOCOL
*This
,
42 IN BOOLEAN ExtendedVerification
45 FDC_BLK_IO_DEV
*FdcDev
;
48 // Reset the Floppy Disk Controller
50 FdcDev
= FDD_BLK_IO_FROM_THIS (This
);
52 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
54 EFI_P_PC_RESET
| EFI_PERIPHERAL_REMOVABLE_MEDIA
,
58 return FddReset (FdcDev
);
62 Flush block via fdd controller
64 @param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
71 IN EFI_BLOCK_IO_PROTOCOL
*This
81 Common report status code interface
83 @param This Pointer of FDC_BLK_IO_DEV instance
84 @param Read Error type: read or write?
88 IN EFI_BLOCK_IO_PROTOCOL
*This
,
92 FDC_BLK_IO_DEV
*FdcDev
;
94 FdcDev
= FDD_BLK_IO_FROM_THIS (This
);
96 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
98 ((Read
) ? EFI_P_EC_INPUT_ERROR
: EFI_P_EC_OUTPUT_ERROR
) | EFI_PERIPHERAL_REMOVABLE_MEDIA
,
104 Read the requested number of blocks from the device
106 @param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
107 @param MediaId UINT32: The media id that the read request is for
108 @param LBA EFI_LBA: The starting logic block address to read from on the device
109 @param BufferSize UINTN: The size of the Buffer in bytes
110 @param Buffer VOID *: A pointer to the destination buffer for the data
112 @retval EFI_SUCCESS: The data was read correctly from the device
113 @retval EFI_DEVICE_ERROR:The device reported an error while attempting to perform
115 @retval EFI_NO_MEDIA: There is no media in the device
116 @retval EFI_MEDIA_CHANGED: The MediaId is not for the current media
117 @retval EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the
118 intrinsic block size of the device
119 @retval EFI_INVALID_PARAMETER:The read request contains LBAs that are not valid,
120 or the buffer is not on proper alignment
126 IN EFI_BLOCK_IO_PROTOCOL
*This
,
135 Status
= FddReadWriteBlocks (This
, MediaId
, LBA
, BufferSize
, READ
, Buffer
);
137 if (EFI_ERROR (Status
)) {
138 FddReportStatus (This
, TRUE
);
145 Write a specified number of blocks to the device
147 @param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
148 @param MediaId UINT32: The media id that the write request is for
149 @param LBA EFI_LBA: The starting logic block address to be written
150 @param BufferSize UINTN: The size in bytes in Buffer
151 @param Buffer VOID *: A pointer to the source buffer for the data
153 @retval EFI_SUCCESS: The data were written correctly to the device
154 @retval EFI_WRITE_PROTECTED: The device can not be written to
155 @retval EFI_NO_MEDIA: There is no media in the device
156 @retval EFI_MEDIA_CHANGED: The MediaId is not for the current media
157 @retval EFI_DEVICE_ERROR: The device reported an error while attempting to perform
159 @retval EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the
160 intrinsic block size of the device
161 @retval EFI_INVALID_PARAMETER:The write request contains LBAs that are not valid,
162 or the buffer is not on proper alignment
167 IN EFI_BLOCK_IO_PROTOCOL
*This
,
176 Status
= FddReadWriteBlocks (This
, MediaId
, LBA
, BufferSize
, WRITE
, Buffer
);
178 if (EFI_ERROR (Status
)) {
179 FddReportStatus (This
, FALSE
);
186 Read or Write a number of blocks to floppy device
188 @param This Pointer to instance of EFI_BLOCK_IO_PROTOCOL
189 @param MediaId The media id of read/write request
190 @param LBA The starting logic block address to read from on the device
191 @param BufferSize The size of the Buffer in bytes
192 @param Operation - GC_TODO: add argument description
193 @param Buffer - GC_TODO: add argument description
195 @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
196 @retval EFI_SUCCESS - GC_TODO: Add description for return value
197 @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
198 @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
199 @retval EFI_NO_MEDIA - GC_TODO: Add description for return value
200 @retval EFI_MEDIA_CHANGED - GC_TODO: Add description for return value
201 @retval EFI_WRITE_PROTECTED - GC_TODO: Add description for return value
202 @retval EFI_BAD_BUFFER_SIZE - GC_TODO: Add description for return value
203 @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
204 @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
205 @retval EFI_SUCCESS - GC_TODO: Add description for return value
206 @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
207 @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
208 @retval EFI_SUCCESS - GC_TODO: Add description for return value
213 IN EFI_BLOCK_IO_PROTOCOL
*This
,
217 IN BOOLEAN Operation
,
221 EFI_BLOCK_IO_MEDIA
*Media
;
222 FDC_BLK_IO_DEV
*FdcDev
;
224 UINTN NumberOfBlocks
;
228 // EFI_STATUS CacheStatus;
234 // Get the intrinsic block size
237 BlockSize
= Media
->BlockSize
;
238 FdcDev
= FDD_BLK_IO_FROM_THIS (This
);
240 if (Operation
== WRITE
) {
242 FdcFreeCache (FdcDev
);
246 // Check the Parameter is valid
248 if (Buffer
== NULL
) {
249 return EFI_INVALID_PARAMETER
;
252 if (BufferSize
== 0) {
256 // Set the drive motor on
258 Status
= MotorOn (FdcDev
);
259 if (EFI_ERROR (Status
)) {
260 return EFI_DEVICE_ERROR
;
263 // Check to see if media can be detected
265 Status
= DetectMedia (FdcDev
);
266 if (EFI_ERROR (Status
)) {
268 FdcFreeCache (FdcDev
);
269 return EFI_DEVICE_ERROR
;
272 // Check to see if media is present
274 if (!(Media
->MediaPresent
)) {
276 FdcFreeCache (FdcDev
);
280 gBS->FreePool (FdcDev->Cache);
281 FdcDev->Cache = NULL;
287 // Check to see if media has been changed
289 if (MediaId
!= Media
->MediaId
) {
291 FdcFreeCache (FdcDev
);
292 return EFI_MEDIA_CHANGED
;
295 if (Operation
== WRITE
) {
296 if (Media
->ReadOnly
) {
298 return EFI_WRITE_PROTECTED
;
302 // Check the parameters for this read/write operation
304 if (BufferSize
% BlockSize
!= 0) {
306 return EFI_BAD_BUFFER_SIZE
;
309 if (LBA
> Media
->LastBlock
) {
311 return EFI_INVALID_PARAMETER
;
314 if (((BufferSize
/ BlockSize
) + LBA
- 1) > Media
->LastBlock
) {
316 return EFI_INVALID_PARAMETER
;
319 if (Operation
== READ
) {
321 // See if the data that is being read is already in the cache
324 if (LBA
== 0 && BufferSize
== BlockSize
) {
326 CopyMem ((UINT8
*) Buffer
, (UINT8
*) FdcDev
->Cache
, BlockSize
);
332 // Set up Floppy Disk Controller
334 Status
= Setup (FdcDev
);
335 if (EFI_ERROR (Status
)) {
337 return EFI_DEVICE_ERROR
;
340 NumberOfBlocks
= BufferSize
/ BlockSize
;
345 // read blocks in the same cylinder.
346 // in a cylinder , there are 18 * 2 = 36 blocks
348 BlockCount
= GetTransferBlockCount (FdcDev
, LBA
, NumberOfBlocks
);
349 while ((BlockCount
!= 0) && !EFI_ERROR (Status
)) {
350 Status
= ReadWriteDataSector (FdcDev
, Buffer
, LBA
, BlockCount
, Operation
);
351 if (EFI_ERROR (Status
)) {
354 return EFI_DEVICE_ERROR
;
358 NumberOfBlocks
-= BlockCount
;
359 Buffer
= (VOID
*) ((UINTN
) Buffer
+ BlockCount
* BlockSize
);
360 BlockCount
= GetTransferBlockCount (FdcDev
, LBA
, NumberOfBlocks
);
366 // Turn the motor off
370 if (Operation
== READ
) {
372 // Cache the data read
374 if (LBA0
== 0 && !FdcDev
->Cache
) {
375 FdcDev
->Cache
= AllocateCopyPool (BlockSize
, Buffer
);
384 Common interface for free cache
386 @param FdcDev Pointer of FDC_BLK_IO_DEV instance
391 IN FDC_BLK_IO_DEV
*FdcDev
395 gBS
->FreePool (FdcDev
->Cache
);
396 FdcDev
->Cache
= NULL
;