3 Copyright (c) 2006, Intel Corporation. All rights reserved. <BR>
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
19 1. Support two types diskette drive
20 1.44M drive and 2.88M drive (and now only support 1.44M)
21 2. Support two diskette drives
22 3. Use DMA channel 2 to transfer data
23 4. Do not use interrupt
24 5. Support diskette change line signal and write protect
26 Implement the Block IO interface
32 #include "IsaFloppy.h"
37 IN EFI_BLOCK_IO_PROTOCOL
*This
,
38 IN BOOLEAN ExtendedVerification
42 Routine Description: Reset the Floppy Logic Drive, call the FddReset function
44 This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
45 ExtendedVerification BOOLEAN: Indicate that the driver may perform a more
46 exhaustive verification operation of the device during
47 reset, now this par is ignored in this driver
49 EFI_SUCCESS: The Floppy Logic Drive is reset
50 EFI_DEVICE_ERROR: The Floppy Logic Drive is not functioning correctly
54 // GC_TODO: function comment is missing 'Arguments:'
55 // GC_TODO: This - add argument and description to function comment
56 // GC_TODO: ExtendedVerification - add argument and description to function comment
58 FDC_BLK_IO_DEV
*FdcDev
;
61 // Reset the Floppy Disk Controller
63 FdcDev
= FDD_BLK_IO_FROM_THIS (This
);
65 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
67 EFI_P_PC_RESET
| EFI_PERIPHERAL_REMOVABLE_MEDIA
,
71 return FddReset (FdcDev
);
77 IN EFI_BLOCK_IO_PROTOCOL
*This
83 This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
88 // GC_TODO: function comment is missing 'Arguments:'
89 // GC_TODO: This - add argument and description to function comment
100 IN EFI_BLOCK_IO_PROTOCOL
*This
,
107 GC_TODO: Add function description
111 This - GC_TODO: add argument description
112 Read - GC_TODO: add argument description
116 GC_TODO: add return values
120 FDC_BLK_IO_DEV
*FdcDev
;
122 FdcDev
= FDD_BLK_IO_FROM_THIS (This
);
124 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
126 ((Read
) ? EFI_P_EC_INPUT_ERROR
: EFI_P_EC_OUTPUT_ERROR
) | EFI_PERIPHERAL_REMOVABLE_MEDIA
,
134 IN EFI_BLOCK_IO_PROTOCOL
*This
,
142 Routine Description: Read the requested number of blocks from the device
144 This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
145 MediaId UINT32: The media id that the read request is for
146 LBA EFI_LBA: The starting logic block address to read from on the device
147 BufferSize UINTN: The size of the Buffer in bytes
148 Buffer VOID *: A pointer to the destination buffer for the data
150 EFI_SUCCESS: The data was read correctly from the device
151 EFI_DEVICE_ERROR:The device reported an error while attempting to perform
153 EFI_NO_MEDIA: There is no media in the device
154 EFI_MEDIA_CHANGED: The MediaId is not for the current media
155 EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the
156 intrinsic block size of the device
157 EFI_INVALID_PARAMETER:The read request contains LBAs that are not valid,
158 or the buffer is not on proper alignment
161 // GC_TODO: function comment is missing 'Arguments:'
162 // GC_TODO: This - add argument and description to function comment
163 // GC_TODO: MediaId - add argument and description to function comment
164 // GC_TODO: LBA - add argument and description to function comment
165 // GC_TODO: BufferSize - add argument and description to function comment
166 // GC_TODO: Buffer - add argument and description to function comment
170 Status
= FddReadWriteBlocks (This
, MediaId
, LBA
, BufferSize
, READ
, Buffer
);
172 if (EFI_ERROR (Status
)) {
173 FddReportStatus (This
, TRUE
);
182 IN EFI_BLOCK_IO_PROTOCOL
*This
,
190 Routine Description: Write a specified number of blocks to the device
192 This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface
193 MediaId UINT32: The media id that the write request is for
194 LBA EFI_LBA: The starting logic block address to be written
195 BufferSize UINTN: The size in bytes in Buffer
196 Buffer VOID *: A pointer to the source buffer for the data
198 EFI_SUCCESS: The data were written correctly to the device
199 EFI_WRITE_PROTECTED: The device can not be written to
200 EFI_NO_MEDIA: There is no media in the device
201 EFI_MEDIA_CHANGED: The MediaId is not for the current media
202 EFI_DEVICE_ERROR: The device reported an error while attempting to perform
204 EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the
205 intrinsic block size of the device
206 EFI_INVALID_PARAMETER:The write request contains LBAs that are not valid,
207 or the buffer is not on proper alignment
210 // GC_TODO: function comment is missing 'Arguments:'
211 // GC_TODO: function comment is missing 'Returns:'
212 // GC_TODO: This - add argument and description to function comment
213 // GC_TODO: MediaId - add argument and description to function comment
214 // GC_TODO: LBA - add argument and description to function comment
215 // GC_TODO: BufferSize - add argument and description to function comment
216 // GC_TODO: Buffer - add argument and description to function comment
220 Status
= FddReadWriteBlocks (This
, MediaId
, LBA
, BufferSize
, WRITE
, Buffer
);
222 if (EFI_ERROR (Status
)) {
223 FddReportStatus (This
, FALSE
);
231 IN EFI_BLOCK_IO_PROTOCOL
*This
,
235 IN BOOLEAN Operation
,
242 GC_TODO: Add function description
246 This - GC_TODO: add argument description
247 MediaId - GC_TODO: add argument description
248 LBA - GC_TODO: add argument description
249 BufferSize - GC_TODO: add argument description
250 Operation - GC_TODO: add argument description
251 Buffer - GC_TODO: add argument description
255 EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
256 EFI_SUCCESS - GC_TODO: Add description for return value
257 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
258 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
259 EFI_NO_MEDIA - GC_TODO: Add description for return value
260 EFI_MEDIA_CHANGED - GC_TODO: Add description for return value
261 EFI_WRITE_PROTECTED - GC_TODO: Add description for return value
262 EFI_BAD_BUFFER_SIZE - GC_TODO: Add description for return value
263 EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
264 EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
265 EFI_SUCCESS - GC_TODO: Add description for return value
266 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
267 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
268 EFI_SUCCESS - GC_TODO: Add description for return value
272 EFI_BLOCK_IO_MEDIA
*Media
;
273 FDC_BLK_IO_DEV
*FdcDev
;
275 UINTN NumberOfBlocks
;
279 // EFI_STATUS CacheStatus;
285 // Get the intrinsic block size
288 BlockSize
= Media
->BlockSize
;
289 FdcDev
= FDD_BLK_IO_FROM_THIS (This
);
291 if (Operation
== WRITE
) {
293 FdcFreeCache (FdcDev
);
297 // Check the Parameter is valid
299 if (Buffer
== NULL
) {
300 return EFI_INVALID_PARAMETER
;
303 if (BufferSize
== 0) {
307 // Set the drive motor on
309 Status
= MotorOn (FdcDev
);
310 if (EFI_ERROR (Status
)) {
311 return EFI_DEVICE_ERROR
;
314 // Check to see if media can be detected
316 Status
= DetectMedia (FdcDev
);
317 if (EFI_ERROR (Status
)) {
319 FdcFreeCache (FdcDev
);
320 return EFI_DEVICE_ERROR
;
323 // Check to see if media is present
325 if (!(Media
->MediaPresent
)) {
327 FdcFreeCache (FdcDev
);
331 gBS->FreePool (FdcDev->Cache);
332 FdcDev->Cache = NULL;
338 // Check to see if media has been changed
340 if (MediaId
!= Media
->MediaId
) {
342 FdcFreeCache (FdcDev
);
343 return EFI_MEDIA_CHANGED
;
346 if (Operation
== WRITE
) {
347 if (Media
->ReadOnly
) {
349 return EFI_WRITE_PROTECTED
;
353 // Check the parameters for this read/write operation
355 if (BufferSize
% BlockSize
!= 0) {
357 return EFI_BAD_BUFFER_SIZE
;
360 if (LBA
> Media
->LastBlock
) {
362 return EFI_INVALID_PARAMETER
;
365 if (((BufferSize
/ BlockSize
) + LBA
- 1) > Media
->LastBlock
) {
367 return EFI_INVALID_PARAMETER
;
370 if (Operation
== READ
) {
372 // See if the data that is being read is already in the cache
375 if (LBA
== 0 && BufferSize
== BlockSize
) {
377 CopyMem ((UINT8
*) Buffer
, (UINT8
*) FdcDev
->Cache
, BlockSize
);
383 // Set up Floppy Disk Controller
385 Status
= Setup (FdcDev
);
386 if (EFI_ERROR (Status
)) {
388 return EFI_DEVICE_ERROR
;
391 NumberOfBlocks
= BufferSize
/ BlockSize
;
396 // read blocks in the same cylinder.
397 // in a cylinder , there are 18 * 2 = 36 blocks
399 BlockCount
= GetTransferBlockCount (FdcDev
, LBA
, NumberOfBlocks
);
400 while ((BlockCount
!= 0) && !EFI_ERROR (Status
)) {
401 Status
= ReadWriteDataSector (FdcDev
, Buffer
, LBA
, BlockCount
, Operation
);
402 if (EFI_ERROR (Status
)) {
405 return EFI_DEVICE_ERROR
;
409 NumberOfBlocks
-= BlockCount
;
410 Buffer
= (VOID
*) ((UINTN
) Buffer
+ BlockCount
* BlockSize
);
411 BlockCount
= GetTransferBlockCount (FdcDev
, LBA
, NumberOfBlocks
);
417 // Turn the motor off
421 if (Operation
== READ
) {
423 // Cache the data read
425 if (LBA0
== 0 && !FdcDev
->Cache
) {
426 FdcDev
->Cache
= AllocateCopyPool (BlockSize
, Buffer
);
436 IN FDC_BLK_IO_DEV
*FdcDev
442 GC_TODO: Add function description
446 FdcDev - GC_TODO: add argument description
450 GC_TODO: add return values
455 gBS
->FreePool (FdcDev
->Cache
);
456 FdcDev
->Cache
= NULL
;