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?
89 IN EFI_BLOCK_IO_PROTOCOL
*This
,
93 FDC_BLK_IO_DEV
*FdcDev
;
95 FdcDev
= FDD_BLK_IO_FROM_THIS (This
);
97 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
99 ((Read
) ? EFI_P_EC_INPUT_ERROR
: EFI_P_EC_OUTPUT_ERROR
) | EFI_PERIPHERAL_REMOVABLE_MEDIA
,
105 Read the requested number of blocks from the device
107 @param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
108 @param MediaId UINT32: The media id that the read request is for
109 @param LBA EFI_LBA: The starting logic block address to read from on the device
110 @param BufferSize UINTN: The size of the Buffer in bytes
111 @param Buffer VOID *: A pointer to the destination buffer for the data
113 @retval EFI_SUCCESS: The data was read correctly from the device
114 @retval EFI_DEVICE_ERROR:The device reported an error while attempting to perform
116 @retval EFI_NO_MEDIA: There is no media in the device
117 @retval EFI_MEDIA_CHANGED: The MediaId is not for the current media
118 @retval EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the
119 intrinsic block size of the device
120 @retval EFI_INVALID_PARAMETER:The read request contains LBAs that are not valid,
121 or the buffer is not on proper alignment
127 IN EFI_BLOCK_IO_PROTOCOL
*This
,
136 Status
= FddReadWriteBlocks (This
, MediaId
, LBA
, BufferSize
, READ
, Buffer
);
138 if (EFI_ERROR (Status
)) {
139 FddReportStatus (This
, TRUE
);
146 Write a specified number of blocks to the device
148 @param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
149 @param MediaId UINT32: The media id that the write request is for
150 @param LBA EFI_LBA: The starting logic block address to be written
151 @param BufferSize UINTN: The size in bytes in Buffer
152 @param Buffer VOID *: A pointer to the source buffer for the data
154 @retval EFI_SUCCESS: The data were written correctly to the device
155 @retval EFI_WRITE_PROTECTED: The device can not be written to
156 @retval EFI_NO_MEDIA: There is no media in the device
157 @retval EFI_MEDIA_CHANGED: The MediaId is not for the current media
158 @retval EFI_DEVICE_ERROR: The device reported an error while attempting to perform
160 @retval EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the
161 intrinsic block size of the device
162 @retval EFI_INVALID_PARAMETER:The write request contains LBAs that are not valid,
163 or the buffer is not on proper alignment
168 IN EFI_BLOCK_IO_PROTOCOL
*This
,
177 Status
= FddReadWriteBlocks (This
, MediaId
, LBA
, BufferSize
, WRITE
, Buffer
);
179 if (EFI_ERROR (Status
)) {
180 FddReportStatus (This
, FALSE
);
187 Read or Write a number of blocks to floppy device
189 @param This Pointer to instance of EFI_BLOCK_IO_PROTOCOL
190 @param MediaId The media id of read/write request
191 @param LBA The starting logic block address to read from on the device
192 @param BufferSize The size of the Buffer in bytes
193 @param Operation - GC_TODO: add argument description
194 Buffer - GC_TODO: add argument description
196 @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
197 @retval EFI_SUCCESS - GC_TODO: Add description for return value
198 @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
199 @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
200 @retval EFI_NO_MEDIA - GC_TODO: Add description for return value
201 @retval EFI_MEDIA_CHANGED - GC_TODO: Add description for return value
202 @retval EFI_WRITE_PROTECTED - GC_TODO: Add description for return value
203 @retval EFI_BAD_BUFFER_SIZE - GC_TODO: Add description for return value
204 @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
205 @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
206 @retval EFI_SUCCESS - GC_TODO: Add description for return value
207 @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
208 @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value
209 @retval EFI_SUCCESS - GC_TODO: Add description for return value
214 IN EFI_BLOCK_IO_PROTOCOL
*This
,
218 IN BOOLEAN Operation
,
222 EFI_BLOCK_IO_MEDIA
*Media
;
223 FDC_BLK_IO_DEV
*FdcDev
;
225 UINTN NumberOfBlocks
;
229 // EFI_STATUS CacheStatus;
235 // Get the intrinsic block size
238 BlockSize
= Media
->BlockSize
;
239 FdcDev
= FDD_BLK_IO_FROM_THIS (This
);
241 if (Operation
== WRITE
) {
243 FdcFreeCache (FdcDev
);
247 // Check the Parameter is valid
249 if (Buffer
== NULL
) {
250 return EFI_INVALID_PARAMETER
;
253 if (BufferSize
== 0) {
257 // Set the drive motor on
259 Status
= MotorOn (FdcDev
);
260 if (EFI_ERROR (Status
)) {
261 return EFI_DEVICE_ERROR
;
264 // Check to see if media can be detected
266 Status
= DetectMedia (FdcDev
);
267 if (EFI_ERROR (Status
)) {
269 FdcFreeCache (FdcDev
);
270 return EFI_DEVICE_ERROR
;
273 // Check to see if media is present
275 if (!(Media
->MediaPresent
)) {
277 FdcFreeCache (FdcDev
);
281 gBS->FreePool (FdcDev->Cache);
282 FdcDev->Cache = NULL;
288 // Check to see if media has been changed
290 if (MediaId
!= Media
->MediaId
) {
292 FdcFreeCache (FdcDev
);
293 return EFI_MEDIA_CHANGED
;
296 if (Operation
== WRITE
) {
297 if (Media
->ReadOnly
) {
299 return EFI_WRITE_PROTECTED
;
303 // Check the parameters for this read/write operation
305 if (BufferSize
% BlockSize
!= 0) {
307 return EFI_BAD_BUFFER_SIZE
;
310 if (LBA
> Media
->LastBlock
) {
312 return EFI_INVALID_PARAMETER
;
315 if (((BufferSize
/ BlockSize
) + LBA
- 1) > Media
->LastBlock
) {
317 return EFI_INVALID_PARAMETER
;
320 if (Operation
== READ
) {
322 // See if the data that is being read is already in the cache
325 if (LBA
== 0 && BufferSize
== BlockSize
) {
327 CopyMem ((UINT8
*) Buffer
, (UINT8
*) FdcDev
->Cache
, BlockSize
);
333 // Set up Floppy Disk Controller
335 Status
= Setup (FdcDev
);
336 if (EFI_ERROR (Status
)) {
338 return EFI_DEVICE_ERROR
;
341 NumberOfBlocks
= BufferSize
/ BlockSize
;
346 // read blocks in the same cylinder.
347 // in a cylinder , there are 18 * 2 = 36 blocks
349 BlockCount
= GetTransferBlockCount (FdcDev
, LBA
, NumberOfBlocks
);
350 while ((BlockCount
!= 0) && !EFI_ERROR (Status
)) {
351 Status
= ReadWriteDataSector (FdcDev
, Buffer
, LBA
, BlockCount
, Operation
);
352 if (EFI_ERROR (Status
)) {
355 return EFI_DEVICE_ERROR
;
359 NumberOfBlocks
-= BlockCount
;
360 Buffer
= (VOID
*) ((UINTN
) Buffer
+ BlockCount
* BlockSize
);
361 BlockCount
= GetTransferBlockCount (FdcDev
, LBA
, NumberOfBlocks
);
367 // Turn the motor off
371 if (Operation
== READ
) {
373 // Cache the data read
375 if (LBA0
== 0 && !FdcDev
->Cache
) {
376 FdcDev
->Cache
= AllocateCopyPool (BlockSize
, Buffer
);
385 Common interface for free cache
387 @param FdcDec Pointer of FDC_BLK_IO_DEV instance
392 IN FDC_BLK_IO_DEV
*FdcDev
396 gBS
->FreePool (FdcDev
->Cache
);
397 FdcDev
->Cache
= NULL
;