2 Copyright (c) 2006 - 2007 Intel Corporation. <BR>
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 @par Revision Reference:
12 2002-6: Add Atapi6 enhancement, support >120GB hard disk, including
13 update - ATAIdentity() func
14 update - AtaBlockIoReadBlocks() func
15 update - AtaBlockIoWriteBlocks() func
16 add - AtaAtapi6Identify() func
17 add - AtaReadSectorsExt() func
18 add - AtaWriteSectorsExt() func
19 add - AtaPioDataInExt() func
20 add - AtaPioDataOutExt() func
27 Sends out an ATA Identify Command to the specified device.
29 This function is called by DiscoverIdeDevice() during its device
30 identification. It sends out the ATA Identify Command to the
31 specified device. Only ATA device responses to this command. If
32 the command succeeds, it returns the Identify data structure which
33 contains information about the device. This function extracts the
34 information it needs to fill the IDE_BLK_IO_DEV data structure,
35 including device type, media block size, media capacity, and etc.
38 pointer pointing to IDE_BLK_IO_DEV data structure,used
39 to record all the information of the IDE device.
41 @retval EFI_SUCCESS Identify ATA device successfully.
43 @retval EFI_DEVICE_ERROR ATA Identify Device Command failed or
44 device is not ATA device.
47 parameter IdeDev will be updated in this function.
52 IN IDE_BLK_IO_DEV
*IdeDev
56 EFI_IDENTIFY_DATA
*AtaIdentifyPointer
;
62 // AtaIdentifyPointer is used for accommodating returned IDENTIFY data of
63 // the ATA Identify command
65 AtaIdentifyPointer
= (EFI_IDENTIFY_DATA
*) AllocateZeroPool (sizeof (EFI_IDENTIFY_DATA
));
68 // use ATA PIO Data In protocol to send ATA Identify command
69 // and receive data from device
71 DeviceSelect
= (UINT8
) ((IdeDev
->Device
) << 4);
76 Status
= AtaPioDataIn (
78 (VOID
*) AtaIdentifyPointer
,
79 sizeof (EFI_IDENTIFY_DATA
),
80 ATA_CMD_IDENTIFY_DRIVE
,
88 // If ATA Identify command succeeds, then according to the received
90 // identify the device type ( ATA or not ).
91 // If ATA device, fill the information in IdeDev.
92 // If not ATA device, return IDE_DEVICE_ERROR
94 if (!EFI_ERROR (Status
)) {
96 IdeDev
->pIdData
= AtaIdentifyPointer
;
99 // Print ATA Module Name
101 PrintAtaModuleName (IdeDev
);
104 // bit 15 of pAtaIdentify->config is used to identify whether device is
105 // ATA device or ATAPI device.
106 // if 0, means ATA device; if 1, means ATAPI device.
108 if ((AtaIdentifyPointer
->AtaData
.config
& 0x8000) == 0x00) {
110 // Detect if support S.M.A.R.T. If yes, enable it as default
112 AtaSMARTSupport (IdeDev
);
115 // Check whether this device needs 48-bit addressing (ATAPI-6 ata device)
117 Status
= AtaAtapi6Identify (IdeDev
);
118 if (!EFI_ERROR (Status
)) {
120 // It's a disk with >120GB capacity, initialized in AtaAtapi6Identify()
123 } else if (Status
== EFI_DEVICE_ERROR
) {
125 // Some disk with big capacity (>200GB) is slow when being identified
126 // and will return all zero for word83.
127 // We try twice at first. If it fails, we do a SoftRest and try again.
132 // Do a SoftRest before the third attempt.
134 AtaSoftReset (IdeDev
);
139 // This is a hard disk <= 120GB capacity, treat it as normal hard disk
141 IdeDev
->Type
= IdeHardDisk
;
144 // Block Media Information:
145 // Media->LogicalPartition , Media->WriteCaching will be filled
146 // in the DiscoverIdeDevcie() function.
148 IdeDev
->BlkIo
.Media
->IoAlign
= 4;
149 IdeDev
->BlkIo
.Media
->MediaId
= 1;
150 IdeDev
->BlkIo
.Media
->RemovableMedia
= FALSE
;
151 IdeDev
->BlkIo
.Media
->MediaPresent
= TRUE
;
152 IdeDev
->BlkIo
.Media
->ReadOnly
= FALSE
;
153 IdeDev
->BlkIo
.Media
->BlockSize
= 0x200;
156 // Calculate device capacity
158 Capacity
= ((UINT32
)AtaIdentifyPointer
->AtaData
.user_addressable_sectors_hi
<< 16) |
159 AtaIdentifyPointer
->AtaData
.user_addressable_sectors_lo
;
160 IdeDev
->BlkIo
.Media
->LastBlock
= Capacity
- 1;
169 gBS
->FreePool (AtaIdentifyPointer
);
171 // Make sure the pIdData will not be freed again.
173 IdeDev
->pIdData
= NULL
;
175 return EFI_DEVICE_ERROR
;
180 This function is called by ATAIdentify() to identity whether this disk
181 supports ATA/ATAPI6 48bit addressing, ie support >120G capacity
184 pointer pointing to IDE_BLK_IO_DEV data structure, used
185 to record all the information of the IDE device.
187 @retval EFI_SUCCESS The disk specified by IdeDev is a Atapi6 supported one
188 and 48-bit addressing must be used
190 @retval EFI_UNSUPPORTED The disk dosn't not support Atapi6 or it supports but
191 the capacity is below 120G, 48bit addressing is not needed
193 @retval EFI_DEVICE_ERROR The identify data in IdeDev is incorrect
195 @retval EFI_INVALID_PARAMETER The identify data in IdeDev is NULL.
198 This function must be called after DEVICE_IDENTITY command has been
199 successfully returned
204 IN IDE_BLK_IO_DEV
*IdeDev
210 EFI_IDENTIFY_DATA
*Atapi6IdentifyStruct
;
212 if (IdeDev
->pIdData
== NULL
) {
213 return EFI_INVALID_PARAMETER
;
216 Atapi6IdentifyStruct
= IdeDev
->pIdData
;
218 if ((Atapi6IdentifyStruct
->AtapiData
.cmd_set_support_83
& (BIT15
| BIT14
)) != 0x4000) {
220 // Per ATA-6 spec, word83: bit15 is zero and bit14 is one
222 return EFI_DEVICE_ERROR
;
225 if ((Atapi6IdentifyStruct
->AtapiData
.cmd_set_support_83
& BIT10
) == 0) {
227 // The device dosn't support 48 bit addressing
229 return EFI_UNSUPPORTED
;
233 // 48 bit address feature set is supported, get maximum capacity
235 Capacity
= Atapi6IdentifyStruct
->AtapiData
.max_user_lba_for_48bit_addr
[0];
236 for (Index
= 1; Index
< 4; Index
++) {
238 // Lower byte goes first: word[100] is the lowest word, word[103] is highest
240 TmpLba
= Atapi6IdentifyStruct
->AtapiData
.max_user_lba_for_48bit_addr
[Index
];
241 Capacity
|= LShiftU64 (TmpLba
, 16 * Index
);
244 if (Capacity
> MAX_28BIT_ADDRESSING_CAPACITY
) {
246 // Capacity exceeds 120GB. 48-bit addressing is really needed
248 IdeDev
->Type
= Ide48bitAddressingHardDisk
;
251 // Fill block media information:Media->LogicalPartition ,
252 // Media->WriteCaching will be filledin the DiscoverIdeDevcie() function.
254 IdeDev
->BlkIo
.Media
->IoAlign
= 4;
255 IdeDev
->BlkIo
.Media
->MediaId
= 1;
256 IdeDev
->BlkIo
.Media
->RemovableMedia
= FALSE
;
257 IdeDev
->BlkIo
.Media
->MediaPresent
= TRUE
;
258 IdeDev
->BlkIo
.Media
->ReadOnly
= FALSE
;
259 IdeDev
->BlkIo
.Media
->BlockSize
= 0x200;
260 IdeDev
->BlkIo
.Media
->LastBlock
= Capacity
- 1;
265 return EFI_UNSUPPORTED
;
269 This function is called by ATAIdentify() or ATAPIIdentify()
270 to print device's module name.
273 pointer pointing to IDE_BLK_IO_DEV data structure, used
274 to record all the information of the IDE device.
279 IN IDE_BLK_IO_DEV
*IdeDev
282 if (IdeDev
->pIdData
== NULL
) {
286 SwapStringChars (IdeDev
->ModelName
, IdeDev
->pIdData
->AtaData
.ModelName
, 40);
287 IdeDev
->ModelName
[40] = 0x00;
291 This function is used to send out ATA commands conforms to the
292 PIO Data In Protocol.
295 pointer pointing to IDE_BLK_IO_DEV data structure, used
296 to record all the information of the IDE device.
299 buffer contained data transferred from device to host.
302 data size in byte unit of the buffer.
304 @param[in] AtaCommand
305 value of the Command Register
308 value of the Head/Device Register
310 @param[in] SectorCount
311 value of the Sector Count Register
313 @param[in] SectorNumber
314 value of the Sector Number Register
316 @param[in] CylinderLsb
317 value of the low byte of the Cylinder Register
319 @param[in] CylinderMsb
320 value of the high byte of the Cylinder Register
322 @retval EFI_SUCCESS send out the ATA command and device send required
325 @retval EFI_DEVICE_ERROR command sent failed.
330 IN IDE_BLK_IO_DEV
*IdeDev
,
335 IN UINT8 SectorCount
,
336 IN UINT8 SectorNumber
,
337 IN UINT8 CylinderLsb
,
346 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
347 if (EFI_ERROR (Status
)) {
348 return EFI_DEVICE_ERROR
;
352 // e0:1110,0000-- bit7 and bit5 are reserved bits.
353 // bit6 set means LBA mode
357 IdeDev
->IoPort
->Head
,
358 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0 | Head
)
362 // All ATAPI device's ATA commands can be issued regardless of the
365 if (IdeDev
->Type
== IdeHardDisk
) {
367 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
368 if (EFI_ERROR (Status
)) {
369 return EFI_DEVICE_ERROR
;
373 // set all the command parameters
374 // Before write to all the following registers, BSY and DRQ must be 0.
376 Status
= DRQClear2 (IdeDev
, ATATIMEOUT
);
377 if (EFI_ERROR (Status
)) {
378 return EFI_DEVICE_ERROR
;
381 if (AtaCommand
== ATA_CMD_SET_FEATURES
) {
382 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, 0x03);
385 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount
);
386 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, SectorNumber
);
387 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, CylinderLsb
);
388 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, CylinderMsb
);
391 // send command via Command Register
393 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
395 Buffer16
= (UINT16
*) Buffer
;
398 // According to PIO data in protocol, host can perform a series of reads to
399 // the data register after each time device set DRQ ready;
400 // The data size of "a series of read" is command specific.
401 // For most ATA command, data size received from device will not exceed
402 // 1 sector, hence the data size for "a series of read" can be the whole data
403 // size of one command request.
404 // For ATA command such as Read Sector command, the data size of one ATA
405 // command request is often larger than 1 sector, according to the
406 // Read Sector command, the data size of "a series of read" is exactly 1
408 // Here for simplification reason, we specify the data size for
409 // "a series of read" to 1 sector (256 words) if data size of one ATA command
410 // request is larger than 256 words.
415 // used to record bytes of currently transfered data
419 while (WordCount
< ByteCount
/ 2) {
421 // Poll DRQ bit set, data transfer can be performed only when DRQ is ready.
423 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
424 if (EFI_ERROR (Status
)) {
425 return EFI_DEVICE_ERROR
;
428 Status
= CheckErrorStatus (IdeDev
);
429 if (EFI_ERROR (Status
)) {
430 return EFI_DEVICE_ERROR
;
434 // Get the byte count for one series of read
436 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
437 Increment
= ByteCount
/ 2 - WordCount
;
440 IDEReadPortWMultiple (
442 IdeDev
->IoPort
->Data
,
447 WordCount
+= Increment
;
448 Buffer16
+= Increment
;
452 DRQClear (IdeDev
, ATATIMEOUT
);
454 return CheckErrorStatus (IdeDev
);
458 This function is used to send out ATA commands conforms to the
459 PIO Data Out Protocol.
462 pointer pointing to IDE_BLK_IO_DEV data structure, used
463 to record all the information of the IDE device.
465 @param *Buffer buffer contained data transferred from host to device.
466 @param ByteCount data size in byte unit of the buffer.
467 @param AtaCommand value of the Command Register
468 @param Head value of the Head/Device Register
469 @param SectorCount value of the Sector Count Register
470 @param SectorNumber value of the Sector Number Register
471 @param CylinderLsb value of the low byte of the Cylinder Register
472 @param CylinderMsb value of the high byte of the Cylinder Register
474 @retval EFI_SUCCESS send out the ATA command and device received required
477 @retval EFI_DEVICE_ERROR command sent failed.
482 IN IDE_BLK_IO_DEV
*IdeDev
,
487 IN UINT8 SectorCount
,
488 IN UINT8 SectorNumber
,
489 IN UINT8 CylinderLsb
,
498 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
499 if (EFI_ERROR (Status
)) {
500 return EFI_DEVICE_ERROR
;
504 // select device via Head/Device register.
505 // Before write Head/Device register, BSY and DRQ must be 0.
507 Status
= DRQClear2 (IdeDev
, ATATIMEOUT
);
508 if (EFI_ERROR (Status
)) {
509 return EFI_DEVICE_ERROR
;
513 // e0:1110,0000-- bit7 and bit5 are reserved bits.
514 // bit6 set means LBA mode
518 IdeDev
->IoPort
->Head
,
519 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0 | Head
)
522 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
523 if (EFI_ERROR (Status
)) {
524 return EFI_DEVICE_ERROR
;
528 // set all the command parameters
529 // Before write to all the following registers, BSY and DRQ must be 0.
531 Status
= DRQClear2 (IdeDev
, ATATIMEOUT
);
532 if (EFI_ERROR (Status
)) {
533 return EFI_DEVICE_ERROR
;
536 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount
);
537 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, SectorNumber
);
538 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, CylinderLsb
);
539 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, CylinderMsb
);
542 // send command via Command Register
544 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
546 Buffer16
= (UINT16
*) Buffer
;
549 // According to PIO data out protocol, host can perform a series of
550 // writes to the data register after each time device set DRQ ready;
551 // The data size of "a series of read" is command specific.
552 // For most ATA command, data size written to device will not exceed 1 sector,
553 // hence the data size for "a series of write" can be the data size of one
555 // For ATA command such as Write Sector command, the data size of one
556 // ATA command request is often larger than 1 sector, according to the
557 // Write Sector command, the data size of "a series of read" is exactly
559 // Here for simplification reason, we specify the data size for
560 // "a series of write" to 1 sector (256 words) if data size of one ATA command
561 // request is larger than 256 words.
566 while (WordCount
< ByteCount
/ 2) {
569 // DRQReady2-- read Alternate Status Register to determine the DRQ bit
570 // data transfer can be performed only when DRQ is ready.
572 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
573 if (EFI_ERROR (Status
)) {
574 return EFI_DEVICE_ERROR
;
577 Status
= CheckErrorStatus (IdeDev
);
578 if (EFI_ERROR (Status
)) {
579 return EFI_DEVICE_ERROR
;
583 // Check the remaining byte count is less than 512 bytes
585 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
586 Increment
= ByteCount
/ 2 - WordCount
;
589 // perform a series of write without check DRQ ready
592 IDEWritePortWMultiple (
594 IdeDev
->IoPort
->Data
,
598 WordCount
+= Increment
;
599 Buffer16
+= Increment
;
603 DRQClear (IdeDev
, ATATIMEOUT
);
605 return CheckErrorStatus (IdeDev
);
609 This function is used to analyze the Status Register and print out
610 some debug information and if there is ERR bit set in the Status
611 Register, the Error Register's value is also be parsed and print out.
614 pointer pointing to IDE_BLK_IO_DEV data structure, used
615 to record all the information of the IDE device.
617 @retval EFI_SUCCESS No err information in the Status Register.
618 @retval EFI_DEVICE_ERROR Any err information in the Status Register.
623 IN IDE_BLK_IO_DEV
*IdeDev
626 UINT8 StatusRegister
;
629 StatusRegister
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Status
);
633 if (StatusRegister
& ATA_STSREG_DWF
) {
636 "CheckErrorStatus()-- %02x : Error : Write Fault\n",
641 if (StatusRegister
& ATA_STSREG_CORR
) {
644 "CheckErrorStatus()-- %02x : Error : Corrected Data\n",
649 if (StatusRegister
& ATA_STSREG_ERR
) {
650 ErrorRegister
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Error
);
652 if (ErrorRegister
& ATA_ERRREG_BBK
) {
655 "CheckErrorStatus()-- %02x : Error : Bad Block Detected\n",
660 if (ErrorRegister
& ATA_ERRREG_UNC
) {
663 "CheckErrorStatus()-- %02x : Error : Uncorrectable Data\n",
668 if (ErrorRegister
& ATA_ERRREG_MC
) {
671 "CheckErrorStatus()-- %02x : Error : Media Change\n",
676 if (ErrorRegister
& ATA_ERRREG_ABRT
) {
679 "CheckErrorStatus()-- %02x : Error : Abort\n",
684 if (ErrorRegister
& ATA_ERRREG_TK0NF
) {
687 "CheckErrorStatus()-- %02x : Error : Track 0 Not Found\n",
692 if (ErrorRegister
& ATA_ERRREG_AMNF
) {
695 "CheckErrorStatus()-- %02x : Error : Address Mark Not Found\n",
703 if ((StatusRegister
& (ATA_STSREG_ERR
| ATA_STSREG_DWF
| ATA_STSREG_CORR
)) == 0) {
707 return EFI_DEVICE_ERROR
;
712 This function is called by the AtaBlkIoReadBlocks() to perform
713 reading from media in block unit.
716 pointer pointing to IDE_BLK_IO_DEV data structure, used
717 to record all the information of the IDE device.
719 @param[in] *DataBuffer
720 A pointer to the destination buffer for the data.
723 The starting logical block address to read from
726 @param[in] NumberOfBlocks
727 The number of transfer data blocks.
729 @return return status is fully dependent on the return status
730 of AtaPioDataIn() function.
735 IN IDE_BLK_IO_DEV
*IdeDev
,
738 IN UINTN NumberOfBlocks
742 UINTN BlocksRemaining
;
757 // Using ATA Read Sector(s) command (opcode=0x20) with PIO DATA IN protocol
759 AtaCommand
= ATA_CMD_READ_SECTORS
;
762 BlocksRemaining
= NumberOfBlocks
;
764 Lba32
= (UINT32
) Lba
;
766 Status
= EFI_SUCCESS
;
768 while (BlocksRemaining
> 0) {
771 // in ATA-3 spec, LBA is in 28 bit width
773 Lba0
= (UINT8
) Lba32
;
774 Lba1
= (UINT8
) (Lba32
>> 8);
775 Lba2
= (UINT8
) (Lba32
>> 16);
777 // low 4 bit of Lba3 stands for LBA bit24~bit27.
779 Lba3
= (UINT8
) ((Lba32
>> 24) & 0x0f);
781 if (BlocksRemaining
>= 0x100) {
784 // SectorCount8 is sent to Sector Count register, 0x00 means 256
785 // sectors to be read
789 // SectorCount is used to record the number of sectors to be read
794 SectorCount8
= (UINT8
) BlocksRemaining
;
795 SectorCount
= (UINT16
) BlocksRemaining
;
799 // ByteCount is the number of bytes that will be read
801 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
804 // call AtaPioDataIn() to send Read Sector Command and receive data read
806 Status
= AtaPioDataIn (
817 if (EFI_ERROR (Status
)) {
821 Lba32
+= SectorCount
;
822 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
823 BlocksRemaining
-= SectorCount
;
830 This function is called by the AtaBlkIoWriteBlocks() to perform
831 writing onto media in block unit.
834 pointer pointing to IDE_BLK_IO_DEV data structure,used
835 to record all the information of the IDE device.
837 @param[in] *BufferData
838 A pointer to the source buffer for the data.
841 The starting logical block address to write onto
844 @param[in] NumberOfBlocks
845 The number of transfer data blocks.
847 @return return status is fully dependent on the return status
848 of AtaPioDataOut() function.
853 IN IDE_BLK_IO_DEV
*IdeDev
,
856 IN UINTN NumberOfBlocks
860 UINTN BlocksRemaining
;
875 // Using Write Sector(s) command (opcode=0x30) with PIO DATA OUT protocol
877 AtaCommand
= ATA_CMD_WRITE_SECTORS
;
879 BlocksRemaining
= NumberOfBlocks
;
881 Lba32
= (UINT32
) Lba
;
883 Status
= EFI_SUCCESS
;
885 while (BlocksRemaining
> 0) {
887 Lba0
= (UINT8
) Lba32
;
888 Lba1
= (UINT8
) (Lba32
>> 8);
889 Lba2
= (UINT8
) (Lba32
>> 16);
890 Lba3
= (UINT8
) ((Lba32
>> 24) & 0x0f);
892 if (BlocksRemaining
>= 0x100) {
895 // SectorCount8 is sent to Sector Count register, 0x00 means 256 sectors
900 // SectorCount is used to record the number of sectors to be written
905 SectorCount8
= (UINT8
) BlocksRemaining
;
906 SectorCount
= (UINT16
) BlocksRemaining
;
909 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
911 Status
= AtaPioDataOut (
922 if (EFI_ERROR (Status
)) {
926 Lba32
+= SectorCount
;
927 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
928 BlocksRemaining
-= SectorCount
;
935 This function is used to implement the Soft Reset on the specified
936 device. But, the ATA Soft Reset mechanism is so strong a reset method
937 that it will force resetting on both devices connected to the
940 It is called by IdeBlkIoReset(), a interface function of Block
943 This function can also be used by the ATAPI device to perform reset when
944 ATAPI Reset command is failed.
947 pointer pointing to IDE_BLK_IO_DEV data structure, used
948 to record all the information of the IDE device.
950 @retval EFI_SUCCESS Soft reset completes successfully.
951 @retval EFI_DEVICE_ERROR Any step during the reset process is failed.
954 The registers initial values after ATA soft reset are different
955 to the ATA device and ATAPI device.
960 IN IDE_BLK_IO_DEV
*IdeDev
968 // set SRST bit to initiate soft reset
970 DeviceControl
|= ATA_CTLREG_SRST
;
975 DeviceControl
|= BIT1
;
977 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);
980 // SRST should assert for at least 5 us, we use 10 us for
981 // better compatibility
986 // Enable interrupt to support UDMA, and clear SRST bit
989 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);
992 // Wait for at least 2 ms to check BSY status, we use 10 ms
993 // for better compatibility
997 // slave device needs at most 31s to clear BSY
999 if (WaitForBSYClear (IdeDev
, 31000) == EFI_TIMEOUT
) {
1000 return EFI_DEVICE_ERROR
;
1007 This function is the ATA implementation for ReadBlocks in the
1008 Block I/O Protocol interface.
1010 @param[in] *IdeBlkIoDevice
1011 Indicates the calling context.
1014 The media id that the read request is for.
1017 The starting logical block address to read from
1020 @param[in] BufferSize
1021 The size of the Buffer in bytes. This must be a
1022 multiple of the intrinsic block size of the device.
1025 A pointer to the destination buffer for the data.
1026 The caller is responsible for either having implicit
1027 or explicit ownership of the memory that data is read into.
1029 @retval EFI_SUCCESS Read Blocks successfully.
1030 @retval EFI_DEVICE_ERROR Read Blocks failed.
1031 @retval EFI_NO_MEDIA There is no media in the device.
1032 @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.
1034 @retval EFI_BAD_BUFFER_SIZE
1035 The BufferSize parameter is not a multiple of the
1036 intrinsic block size of the device.
1038 @retval EFI_INVALID_PARAMETER
1039 The read request contains LBAs that are not valid,
1040 or the data buffer is not valid.
1043 If Read Block error because of device error, this function will call
1044 AtaSoftReset() function to reset device.
1048 AtaBlkIoReadBlocks (
1049 IN IDE_BLK_IO_DEV
*IdeBlkIoDevice
,
1052 IN UINTN BufferSize
,
1056 EFI_BLOCK_IO_MEDIA
*Media
;
1058 UINTN NumberOfBlocks
;
1061 if (Buffer
== NULL
) {
1062 return EFI_INVALID_PARAMETER
;
1065 if (BufferSize
== 0) {
1069 Status
= EFI_SUCCESS
;
1072 // Get the intrinsic block size
1074 Media
= IdeBlkIoDevice
->BlkIo
.Media
;
1075 BlockSize
= Media
->BlockSize
;
1077 NumberOfBlocks
= BufferSize
/ BlockSize
;
1079 if (MediaId
!= Media
->MediaId
) {
1080 return EFI_MEDIA_CHANGED
;
1083 if (BufferSize
% BlockSize
!= 0) {
1084 return EFI_BAD_BUFFER_SIZE
;
1087 if (!(Media
->MediaPresent
)) {
1088 return EFI_NO_MEDIA
;
1091 if (LBA
> Media
->LastBlock
) {
1092 return EFI_INVALID_PARAMETER
;
1095 if ((LBA
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1096 return EFI_INVALID_PARAMETER
;
1099 if ((Media
->IoAlign
> 1) && (((UINTN
) Buffer
& (Media
->IoAlign
- 1)) != 0)) {
1100 return EFI_INVALID_PARAMETER
;
1103 Status
= EFI_SUCCESS
;
1104 if (IdeBlkIoDevice
->Type
== Ide48bitAddressingHardDisk
) {
1106 // For ATA/ATAPI-6 device(capcity > 120GB), use ATA-6 read block mechanism
1108 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1109 Status
= AtaUdmaReadExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1111 Status
= AtaReadSectorsExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1115 // For ATA-3 compatible device, use ATA-3 read block mechanism
1117 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1118 Status
= AtaUdmaRead (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1120 Status
= AtaReadSectors (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1124 if (EFI_ERROR (Status
)) {
1125 AtaSoftReset (IdeBlkIoDevice
);
1126 return EFI_DEVICE_ERROR
;
1134 This function is the ATA implementation for WriteBlocks in the
1135 Block I/O Protocol interface.
1137 @param[in] *IdeBlkIoDevice
1138 Indicates the calling context.
1141 The media id that the write request is for.
1144 The starting logical block address to write onto
1147 @param[in] BufferSize
1148 The size of the Buffer in bytes. This must be a
1149 multiple of the intrinsic block size of the device.
1152 A pointer to the source buffer for the data.
1153 The caller is responsible for either having implicit
1154 or explicit ownership of the memory that data is
1157 @retval EFI_SUCCESS Write Blocks successfully.
1158 @retval EFI_DEVICE_ERROR Write Blocks failed.
1159 @retval EFI_NO_MEDIA There is no media in the device.
1160 @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.
1162 @retval EFI_BAD_BUFFER_SIZE
1163 The BufferSize parameter is not a multiple of the
1164 intrinsic block size of the device.
1166 @retval EFI_INVALID_PARAMETER
1167 The write request contains LBAs that are not valid,
1168 or the data buffer is not valid.
1171 If Write Block error because of device error, this function will call
1172 AtaSoftReset() function to reset device.
1176 AtaBlkIoWriteBlocks (
1177 IN IDE_BLK_IO_DEV
*IdeBlkIoDevice
,
1180 IN UINTN BufferSize
,
1185 EFI_BLOCK_IO_MEDIA
*Media
;
1187 UINTN NumberOfBlocks
;
1190 if (Buffer
== NULL
) {
1191 return EFI_INVALID_PARAMETER
;
1194 if (BufferSize
== 0) {
1198 Status
= EFI_SUCCESS
;
1201 // Get the intrinsic block size
1203 Media
= IdeBlkIoDevice
->BlkIo
.Media
;
1204 BlockSize
= Media
->BlockSize
;
1205 NumberOfBlocks
= BufferSize
/ BlockSize
;
1207 if (MediaId
!= Media
->MediaId
) {
1208 return EFI_MEDIA_CHANGED
;
1211 if (BufferSize
% BlockSize
!= 0) {
1212 return EFI_BAD_BUFFER_SIZE
;
1215 if (LBA
> Media
->LastBlock
) {
1216 return EFI_INVALID_PARAMETER
;
1219 if ((LBA
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1220 return EFI_INVALID_PARAMETER
;
1223 if ((Media
->IoAlign
> 1) && (((UINTN
) Buffer
& (Media
->IoAlign
- 1)) != 0)) {
1224 return EFI_INVALID_PARAMETER
;
1227 Status
= EFI_SUCCESS
;
1228 if (IdeBlkIoDevice
->Type
== Ide48bitAddressingHardDisk
) {
1230 // For ATA/ATAPI-6 device(capcity > 120GB), use ATA-6 write block mechanism
1232 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1233 Status
= AtaUdmaWriteExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1235 Status
= AtaWriteSectorsExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1239 // For ATA-3 compatible device, use ATA-3 write block mechanism
1241 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1242 Status
= AtaUdmaWrite (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1244 Status
= AtaWriteSectors (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1248 if (EFI_ERROR (Status
)) {
1249 AtaSoftReset (IdeBlkIoDevice
);
1250 return EFI_DEVICE_ERROR
;
1257 This function is called by the AtaBlkIoReadBlocks() to perform
1258 reading from media in block unit. The function has been enhanced to
1259 support >120GB access and transfer at most 65536 blocks per command
1262 pointer pointing to IDE_BLK_IO_DEV data structure, used
1263 to record all the information of the IDE device.
1265 @param[in] *DataBuffer A pointer to the destination buffer for the data.
1266 @param[in] StartLba The starting logical block address to read from
1267 on the device media.
1268 @param[in] NumberOfBlocks The number of transfer data blocks.
1270 @return return status is fully dependent on the return status
1271 of AtaPioDataInExt() function.
1276 IN IDE_BLK_IO_DEV
*IdeDev
,
1277 IN VOID
*DataBuffer
,
1278 IN EFI_LBA StartLba
,
1279 IN UINTN NumberOfBlocks
1283 UINTN BlocksRemaining
;
1291 // Using ATA "Read Sectors Ext" command(opcode=0x24) with PIO DATA IN protocol
1293 AtaCommand
= ATA_CMD_READ_SECTORS_EXT
;
1294 Buffer
= DataBuffer
;
1295 BlocksRemaining
= NumberOfBlocks
;
1297 Status
= EFI_SUCCESS
;
1299 while (BlocksRemaining
> 0) {
1301 if (BlocksRemaining
>= 0x10000) {
1303 // SectorCount is used to record the number of sectors to be read
1304 // Max 65536 sectors can be transfered at a time.
1306 SectorCount
= 0xffff;
1308 SectorCount
= (UINT16
) BlocksRemaining
;
1312 // ByteCount is the number of bytes that will be read
1314 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
1317 // call AtaPioDataInExt() to send Read Sector Command and receive data read
1319 Status
= AtaPioDataInExt (
1327 if (EFI_ERROR (Status
)) {
1331 Lba64
+= SectorCount
;
1332 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
1333 BlocksRemaining
-= SectorCount
;
1340 This function is called by the AtaBlkIoWriteBlocks() to perform
1341 writing onto media in block unit. The function has been enhanced to
1342 support >120GB access and transfer at most 65536 blocks per command
1345 pointer pointing to IDE_BLK_IO_DEV data structure,used
1346 to record all the information of the IDE device.
1348 @param[in] *DataBuffer
1349 A pointer to the source buffer for the data.
1352 The starting logical block address to write onto
1355 @param[in] NumberOfBlocks
1356 The number of transfer data blocks.
1358 @return status is fully dependent on the return status
1359 of AtaPioDataOutExt() function.
1363 AtaWriteSectorsExt (
1364 IN IDE_BLK_IO_DEV
*IdeDev
,
1365 IN VOID
*DataBuffer
,
1366 IN EFI_LBA StartLba
,
1367 IN UINTN NumberOfBlocks
1372 UINTN BlocksRemaining
;
1379 // Using ATA "Write Sectors Ext" cmd(opcode=0x24) with PIO DATA OUT protocol
1381 AtaCommand
= ATA_CMD_WRITE_SECTORS_EXT
;
1383 Buffer
= DataBuffer
;
1384 BlocksRemaining
= NumberOfBlocks
;
1386 Status
= EFI_SUCCESS
;
1388 while (BlocksRemaining
> 0) {
1390 if (BlocksRemaining
>= 0x10000) {
1392 // SectorCount is used to record the number of sectors to be written.
1393 // Max 65536 sectors can be transfered at a time.
1395 SectorCount
= 0xffff;
1397 SectorCount
= (UINT16
) BlocksRemaining
;
1401 // ByteCount is the number of bytes that will be written
1403 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
1406 // Call AtaPioDataOutExt() to send "Write Sectors Ext" Command
1408 Status
= AtaPioDataOutExt (
1416 if (EFI_ERROR (Status
)) {
1420 Lba64
+= SectorCount
;
1421 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
1422 BlocksRemaining
-= SectorCount
;
1429 This function is used to send out ATA commands conforms to the
1430 PIO Data In Protocol, supporting ATA/ATAPI-6 standard
1432 Comparing with ATA-3 data in protocol, we have two differents here:<BR>
1433 1. Do NOT wait for DRQ clear before sending command into IDE device.(the
1434 wait will frequently fail... cause writing function return error)
1436 2. Do NOT wait for DRQ clear after all data readed.(the wait greatly
1437 slow down writing performance by 100 times!)
1439 @param[in] *IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used
1440 to record all the information of the IDE device.
1442 @param[in,out] *Buffer buffer contained data transferred from device to host.
1443 @param[in] ByteCount data size in byte unit of the buffer.
1444 @param[in] AtaCommand value of the Command Register
1445 @param[in] StartLba the start LBA of this transaction
1446 @param[in] SectorCount the count of sectors to be transfered
1448 @retval EFI_SUCCESS send out the ATA command and device send required
1451 @retval EFI_DEVICE_ERROR command sent failed.
1456 IN IDE_BLK_IO_DEV
*IdeDev
,
1457 IN OUT VOID
*Buffer
,
1458 IN UINT32 ByteCount
,
1459 IN UINT8 AtaCommand
,
1460 IN EFI_LBA StartLba
,
1461 IN UINT16 SectorCount
1474 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
1475 if (EFI_ERROR (Status
)) {
1476 return EFI_DEVICE_ERROR
;
1480 // Select device, set bit6 as 1 to indicate LBA mode is used
1482 DevSel
= (UINT8
) (IdeDev
->Device
<< 4);
1486 IdeDev
->IoPort
->Head
,
1491 // Wait for DRDY singnal asserting. ATAPI device needn't wait
1493 if ( (IdeDev
->Type
== IdeHardDisk
) ||
1494 (IdeDev
->Type
== Ide48bitAddressingHardDisk
)) {
1496 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
1497 if (EFI_ERROR (Status
)) {
1498 return EFI_DEVICE_ERROR
;
1503 // Fill feature register if needed
1505 if (AtaCommand
== ATA_CMD_SET_FEATURES
) {
1506 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, 0x03);
1510 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
1512 SectorCount8
= (UINT8
) (SectorCount
>> 8);
1513 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1515 SectorCount8
= (UINT8
) SectorCount
;
1516 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1519 // Fill the start LBA registers, which are also two-byte FIFO
1521 LbaLow
= (UINT8
) RShiftU64 (StartLba
, 24);
1522 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 32);
1523 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 40);
1524 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1525 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1526 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1528 LbaLow
= (UINT8
) StartLba
;
1529 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 8);
1530 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 16);
1531 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1532 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1533 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1536 // Send command via Command Register, invoking the processing of this command
1538 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
1540 Buffer16
= (UINT16
*) Buffer
;
1543 // According to PIO data in protocol, host can perform a series of reads to
1544 // the data register after each time device set DRQ ready;
1553 // used to record bytes of currently transfered data
1557 while (WordCount
< ByteCount
/ 2) {
1559 // Poll DRQ bit set, data transfer can be performed only when DRQ is ready.
1561 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
1562 if (EFI_ERROR (Status
)) {
1563 return EFI_DEVICE_ERROR
;
1566 Status
= CheckErrorStatus (IdeDev
);
1567 if (EFI_ERROR (Status
)) {
1568 return EFI_DEVICE_ERROR
;
1572 // Get the byte count for one series of read
1574 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
1575 Increment
= ByteCount
/ 2 - WordCount
;
1578 IDEReadPortWMultiple (
1580 IdeDev
->IoPort
->Data
,
1585 WordCount
+= Increment
;
1586 Buffer16
+= Increment
;
1590 return CheckErrorStatus (IdeDev
);
1594 This function is used to send out ATA commands conforms to the
1595 PIO Data Out Protocol, supporting ATA/ATAPI-6 standard
1597 Comparing with ATA-3 data out protocol, we have two differents here:<BR>
1598 1. Do NOT wait for DRQ clear before sending command into IDE device.(the
1599 wait will frequently fail... cause writing function return error)
1601 2. Do NOT wait for DRQ clear after all data readed.(the wait greatly
1602 slow down writing performance by 100 times!)
1605 pointer pointing to IDE_BLK_IO_DEV data structure, used
1606 to record all the information of the IDE device.
1608 @param[in] *Buffer buffer contained data transferred from host to device.
1609 @param[in] ByteCount data size in byte unit of the buffer.
1610 @param[in] AtaCommand value of the Command Register
1611 @param[in] StartLba the start LBA of this transaction
1612 @param[in] SectorCount the count of sectors to be transfered
1614 @retval EFI_SUCCESS send out the ATA command and device receive required
1617 @retval EFI_DEVICE_ERROR command sent failed.
1622 IN IDE_BLK_IO_DEV
*IdeDev
,
1624 IN UINT32 ByteCount
,
1625 IN UINT8 AtaCommand
,
1626 IN EFI_LBA StartLba
,
1627 IN UINT16 SectorCount
1640 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
1641 if (EFI_ERROR (Status
)) {
1642 return EFI_DEVICE_ERROR
;
1646 // Select device. Set bit6 as 1 to indicate LBA mode is used
1648 DevSel
= (UINT8
) (IdeDev
->Device
<< 4);
1652 IdeDev
->IoPort
->Head
,
1657 // Wait for DRDY singnal asserting.
1659 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
1660 if (EFI_ERROR (Status
)) {
1661 return EFI_DEVICE_ERROR
;
1665 // Fill feature register if needed
1667 if (AtaCommand
== ATA_CMD_SET_FEATURES
) {
1668 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, 0x03);
1672 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
1674 SectorCount8
= (UINT8
) (SectorCount
>> 8);
1675 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1677 SectorCount8
= (UINT8
) SectorCount
;
1678 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1681 // Fill the start LBA registers, which are also two-byte FIFO
1683 LbaLow
= (UINT8
) RShiftU64 (StartLba
, 24);
1684 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 32);
1685 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 40);
1686 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1687 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1688 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1690 LbaLow
= (UINT8
) StartLba
;
1691 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 8);
1692 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 16);
1693 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1694 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1695 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1698 // Send command via Command Register, invoking the processing of this command
1700 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
1702 Buffer16
= (UINT16
*) Buffer
;
1705 // According to PIO Data Out protocol, host can perform a series of writes to
1706 // the data register after each time device set DRQ ready;
1711 // used to record bytes of currently transfered data
1715 while (WordCount
< ByteCount
/ 2) {
1717 // Poll DRQ bit set, data transfer can be performed only when DRQ is ready.
1719 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
1720 if (EFI_ERROR (Status
)) {
1721 return EFI_DEVICE_ERROR
;
1724 Status
= CheckErrorStatus (IdeDev
);
1725 if (EFI_ERROR (Status
)) {
1726 return EFI_DEVICE_ERROR
;
1730 // Write data into device by one series of writing to data register
1732 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
1733 Increment
= ByteCount
/ 2 - WordCount
;
1736 IDEWritePortWMultiple (
1738 IdeDev
->IoPort
->Data
,
1743 WordCount
+= Increment
;
1744 Buffer16
+= Increment
;
1751 return CheckErrorStatus (IdeDev
);
1756 Enable SMART of the disk if supported
1759 pointer pointing to IDE_BLK_IO_DEV data structure,used
1760 to record all the information of the IDE device.
1765 IN IDE_BLK_IO_DEV
*IdeDev
1769 BOOLEAN SMARTSupported
;
1771 EFI_IDENTIFY_DATA
*TmpAtaIdentifyPointer
;
1777 // Detect if the device supports S.M.A.R.T.
1779 if ((IdeDev
->pIdData
->AtaData
.command_set_supported_83
& 0xc000) != 0x4000) {
1781 // Data in word 82 is not valid (bit15 shall be zero and bit14 shall be to one)
1785 if ((IdeDev
->pIdData
->AtaData
.command_set_supported_82
& 0x0001) != 0x0001) {
1787 // S.M.A.R.T is not supported by the device
1789 SMARTSupported
= FALSE
;
1791 SMARTSupported
= TRUE
;
1795 if (!SMARTSupported
) {
1797 // Report nonsupport status code
1799 REPORT_STATUS_CODE (
1800 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1801 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_NOTSUPPORTED
)
1805 // Enable this feature
1807 REPORT_STATUS_CODE (
1809 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_ENABLE
)
1812 Device
= (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0);
1813 Status
= AtaNonDataCommandIn (
1817 ATA_SMART_ENABLE_OPERATION
,
1824 // Detect if this feature is enabled
1826 TmpAtaIdentifyPointer
= (EFI_IDENTIFY_DATA
*) AllocateZeroPool (sizeof (EFI_IDENTIFY_DATA
));
1828 DeviceSelect
= (UINT8
) ((IdeDev
->Device
) << 4);
1829 Status
= AtaPioDataIn (
1831 (VOID
*) TmpAtaIdentifyPointer
,
1832 sizeof (EFI_IDENTIFY_DATA
),
1833 ATA_CMD_IDENTIFY_DRIVE
,
1840 if (EFI_ERROR (Status
)) {
1841 gBS
->FreePool (TmpAtaIdentifyPointer
);
1846 // Check if the feature is enabled
1848 if ((TmpAtaIdentifyPointer
->AtaData
.command_set_feature_enb_85
& 0x0001) == 0x0001) {
1852 AtaNonDataCommandIn (
1856 ATA_SMART_RETURN_STATUS
,
1862 LBAMid
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
);
1863 LBAHigh
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
);
1865 if ((LBAMid
== 0x4f) && (LBAHigh
== 0xc2)) {
1867 // The threshold exceeded condition is not detected by the device
1869 REPORT_STATUS_CODE (
1871 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_UNDERTHRESHOLD
)
1874 } else if ((LBAMid
== 0xf4) && (LBAHigh
== 0x2c)) {
1876 // The threshold exceeded condition is detected by the device
1878 REPORT_STATUS_CODE (
1880 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_OVERTHRESHOLD
)
1886 // Report disabled status code
1888 REPORT_STATUS_CODE (
1889 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1890 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_DISABLED
)
1894 gBS
->FreePool (TmpAtaIdentifyPointer
);
1901 Send ATA Ext command into device with NON_DATA protocol
1903 @param IdeDev Standard IDE device private data structure
1904 @param AtaCommand The ATA command to be sent
1905 @param Device The value in Device register
1906 @param Feature The value in Feature register
1907 @param SectorCount The value in SectorCount register
1908 @param LbaAddress The LBA address in 48-bit mode
1910 @retval EFI_SUCCESS Reading succeed
1911 @retval EFI_DEVICE_ERROR Error executing commands on this device
1915 AtaCommandIssueExt (
1916 IN IDE_BLK_IO_DEV
*IdeDev
,
1917 IN UINT8 AtaCommand
,
1920 IN UINT16 SectorCount
,
1921 IN EFI_LBA LbaAddress
1931 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
1932 if (EFI_ERROR (Status
)) {
1933 return EFI_DEVICE_ERROR
;
1937 // Select device (bit4), set LBA mode(bit6) (use 0xe0 for compatibility)
1941 IdeDev
->IoPort
->Head
,
1942 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0)
1946 // ATA commands for ATA device must be issued when DRDY is set
1948 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
1949 if (EFI_ERROR (Status
)) {
1950 return EFI_DEVICE_ERROR
;
1954 // Pass parameter into device register block
1956 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Head
, Device
);
1959 // Fill the feature register, which is a two-byte FIFO. Need write twice.
1961 Feature8
= (UINT8
) (Feature
>> 8);
1962 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, Feature8
);
1964 Feature8
= (UINT8
) Feature
;
1965 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, Feature8
);
1968 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
1970 SectorCount8
= (UINT8
) (SectorCount
>> 8);
1971 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1973 SectorCount8
= (UINT8
) SectorCount
;
1974 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1977 // Fill the start LBA registers, which are also two-byte FIFO
1979 LbaLow
= (UINT8
) RShiftU64 (LbaAddress
, 24);
1980 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1981 LbaLow
= (UINT8
) LbaAddress
;
1982 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1984 LbaMid
= (UINT8
) RShiftU64 (LbaAddress
, 32);
1985 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1986 LbaMid
= (UINT8
) RShiftU64 (LbaAddress
, 8);
1987 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1989 LbaHigh
= (UINT8
) RShiftU64 (LbaAddress
, 40);
1990 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1991 LbaHigh
= (UINT8
) RShiftU64 (LbaAddress
, 16);
1992 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1995 // Work around for Segate 160G disk writing
2000 // Send command via Command Register
2002 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
2005 // Stall at least 400ns
2013 Send ATA Ext command into device with NON_DATA protocol
2015 @param IdeDev Standard IDE device private data structure
2016 @param AtaCommand The ATA command to be sent
2017 @param Device The value in Device register
2018 @param Feature The value in Feature register
2019 @param SectorCount The value in SectorCount register
2020 @param LbaAddress The LBA address in 48-bit mode
2022 @retval EFI_SUCCESS Reading succeed
2023 @retval EFI_DEVICE_ERROR Error executing commands on this device
2028 IN IDE_BLK_IO_DEV
*IdeDev
,
2029 IN UINT8 AtaCommand
,
2032 IN UINT16 SectorCount
,
2033 IN EFI_LBA LbaAddress
2044 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
2045 if (EFI_ERROR (Status
)) {
2046 return EFI_DEVICE_ERROR
;
2050 // Select device (bit4), set LBA mode(bit6) (use 0xe0 for compatibility)
2054 IdeDev
->IoPort
->Head
,
2055 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0)
2059 // ATA commands for ATA device must be issued when DRDY is set
2061 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
2062 if (EFI_ERROR (Status
)) {
2063 return EFI_DEVICE_ERROR
;
2066 Lba0
= (UINT8
) LbaAddress
;
2067 Lba1
= (UINT8
) RShiftU64 (LbaAddress
, 8);
2068 Lba2
= (UINT8
) RShiftU64 (LbaAddress
, 16);
2069 Lba3
= (UINT8
) RShiftU64 (LbaAddress
, 24);
2070 Device
= (UINT8
) (Device
| Lba3
);
2073 // Pass parameter into device register block
2075 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Head
, Device
);
2078 // Fill the feature register, which is a two-byte FIFO. Need write twice.
2080 Feature8
= (UINT8
) Feature
;
2081 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, Feature8
);
2084 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
2086 SectorCount8
= (UINT8
) SectorCount
;
2087 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
2090 // Fill the start LBA registers, which are also two-byte FIFO
2093 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, Lba0
);
2094 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, Lba1
);
2095 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, Lba2
);
2098 // Send command via Command Register
2100 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
2103 // Stall at least 400ns
2111 This function is called by the AtaBlkIoReadBlocks() to perform
2112 reading from media in block unit. The function has been enhanced to
2113 support >120GB access and transfer at most 65536 blocks per command
2115 @param[in] *IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used
2116 to record all the information of the IDE device.
2118 @param[in] *DataBuffer A pointer to the destination buffer for the data.
2120 @param[in] StartLba The starting logical block address to read from
2121 on the device media.
2123 @param[in] NumberOfBlocks The number of transfer data blocks.
2125 @return The device status of UDMA operation. If the operation is
2126 successful, return EFI_SUCCESS.
2128 TODO: EFI_UNSUPPORTED - add return value to function comment
2129 TODO: EFI_DEVICE_ERROR - add return value to function comment
2130 TODO: EFI_DEVICE_ERROR - add return value to function comment
2131 TODO: EFI_DEVICE_ERROR - add return value to function comment
2135 IN IDE_BLK_IO_DEV
*IdeDev
,
2136 IN VOID
*DataBuffer
,
2137 IN EFI_LBA StartLba
,
2138 IN UINTN NumberOfBlocks
2141 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaReadExtOp
);
2145 This function is called by the AtaBlkIoReadBlocks() to perform
2146 reading from media in block unit. The function has been enhanced to
2147 support >120GB access and transfer at most 65536 blocks per command
2150 pointer pointing to IDE_BLK_IO_DEV data structure, used
2151 to record all the information of the IDE device.
2153 @param[in] *DataBuffer A pointer to the destination buffer for the data.
2154 @param[in] StartLba The starting logical block address to read from
2155 on the device media.
2156 @param[in] NumberOfBlocks The number of transfer data blocks.
2158 @return The device status of UDMA operation. If the operation is
2159 successful, return EFI_SUCCESS.
2161 TODO: EFI_UNSUPPORTED - add return value to function comment
2162 TODO: EFI_DEVICE_ERROR - add return value to function comment
2163 TODO: EFI_DEVICE_ERROR - add return value to function comment
2164 TODO: EFI_DEVICE_ERROR - add return value to function comment
2168 IN IDE_BLK_IO_DEV
*IdeDev
,
2169 IN VOID
*DataBuffer
,
2170 IN EFI_LBA StartLba
,
2171 IN UINTN NumberOfBlocks
2174 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaReadOp
);
2178 This function is called by the AtaBlkIoWriteBlocks() to perform
2179 writing to media in block unit. The function has been enhanced to
2180 support >120GB access and transfer at most 65536 blocks per command
2182 @param[in] *IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used
2183 to record all the information of the IDE device.
2185 @param[in] *DataBuffer A pointer to the source buffer for the data.
2187 @param[in] StartLba The starting logical block address to write to
2188 on the device media.
2190 @param[in] NumberOfBlocks The number of transfer data blocks.
2192 @return The device status of UDMA operation. If the operation is
2193 successful, return EFI_SUCCESS.
2195 TODO: EFI_UNSUPPORTED - add return value to function comment
2196 TODO: EFI_DEVICE_ERROR - add return value to function comment
2197 TODO: EFI_DEVICE_ERROR - add return value to function comment
2201 IN IDE_BLK_IO_DEV
*IdeDev
,
2202 IN VOID
*DataBuffer
,
2203 IN EFI_LBA StartLba
,
2204 IN UINTN NumberOfBlocks
2207 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaWriteExtOp
);
2211 This function is called by the AtaBlkIoWriteBlocks() to perform
2212 writing to media in block unit. The function has been enhanced to
2213 support >120GB access and transfer at most 65536 blocks per command
2216 pointer pointing to IDE_BLK_IO_DEV data structure, used
2217 to record all the information of the IDE device.
2219 @param[in] *DataBuffer
2220 A pointer to the source buffer for the data.
2223 The starting logical block address to write to
2224 on the device media.
2226 @param[in] NumberOfBlocks
2227 The number of transfer data blocks.
2229 @return The device status of UDMA operation. If the operation is
2230 successful, return EFI_SUCCESS.
2232 TODO: EFI_UNSUPPORTED - add return value to function comment
2233 TODO: EFI_DEVICE_ERROR - add return value to function comment
2234 TODO: EFI_DEVICE_ERROR - add return value to function comment
2238 IN IDE_BLK_IO_DEV
*IdeDev
,
2239 IN VOID
*DataBuffer
,
2240 IN EFI_LBA StartLba
,
2241 IN UINTN NumberOfBlocks
2244 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaWriteOp
);
2248 Perform an ATA Udma operation (Read, ReadExt, Write, WriteExt).
2251 pointer pointing to IDE_BLK_IO_DEV data structure, used
2252 to record all the information of the IDE device.
2254 @param[in] *DataBuffer
2255 A pointer to the source buffer for the data.
2258 The starting logical block address to write to
2259 on the device media.
2261 @param[in] NumberOfBlocks
2262 The number of transfer data blocks.
2265 The perform operations could be AtaUdmaReadOp, AtaUdmaReadExOp,
2266 AtaUdmaWriteOp, AtaUdmaWriteExOp
2268 @return The device status of UDMA operation. If the operation is
2269 successful, return EFI_SUCCESS.
2274 IN IDE_BLK_IO_DEV
*IdeDev
,
2275 IN VOID
*DataBuffer
,
2276 IN EFI_LBA StartLba
,
2277 IN UINTN NumberOfBlocks
,
2278 IN ATA_UDMA_OPERATION UdmaOp
2281 IDE_DMA_PRD
*PrdAddr
;
2282 IDE_DMA_PRD
*UsedPrdAddr
;
2283 IDE_DMA_PRD
*TempPrdAddr
;
2284 UINT8 RegisterValue
;
2286 UINT64 IoPortForBmic
;
2287 UINT64 IoPortForBmis
;
2288 UINT64 IoPortForBmid
;
2292 UINTN ByteAvailable
;
2294 UINTN RemainBlockNum
;
2295 UINT8 DeviceControl
;
2300 EFI_PHYSICAL_ADDRESS DeviceAddress
;
2301 UINTN MaxDmaCommandSectors
;
2302 EFI_PCI_IO_PROTOCOL_OPERATION PciIoProtocolOp
;
2307 MaxDmaCommandSectors
= ATAPI_MAX_DMA_CMD_SECTORS
;
2308 PciIoProtocolOp
= EfiPciIoOperationBusMasterWrite
;
2309 AtaCommand
= ATA_CMD_READ_DMA
;
2311 case AtaUdmaReadExtOp
:
2312 MaxDmaCommandSectors
= ATAPI_MAX_DMA_EXT_CMD_SECTORS
;
2313 PciIoProtocolOp
= EfiPciIoOperationBusMasterWrite
;
2314 AtaCommand
= ATA_CMD_READ_DMA_EXT
;
2316 case AtaUdmaWriteOp
:
2317 MaxDmaCommandSectors
= ATAPI_MAX_DMA_CMD_SECTORS
;
2318 PciIoProtocolOp
= EfiPciIoOperationBusMasterRead
;
2319 AtaCommand
= ATA_CMD_WRITE_DMA
;
2321 case AtaUdmaWriteExtOp
:
2322 MaxDmaCommandSectors
= ATAPI_MAX_DMA_EXT_CMD_SECTORS
;
2323 PciIoProtocolOp
= EfiPciIoOperationBusMasterRead
;
2324 AtaCommand
= ATA_CMD_WRITE_DMA_EXT
;
2327 return EFI_UNSUPPORTED
;
2334 Device
= (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0);
2335 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Head
, Device
);
2338 // Enable interrupt to support UDMA
2341 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);
2343 if (IdePrimary
== IdeDev
->Channel
) {
2344 IoPortForBmic
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMICP_OFFSET
;
2345 IoPortForBmis
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMISP_OFFSET
;
2346 IoPortForBmid
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMIDP_OFFSET
;
2348 if (IdeSecondary
== IdeDev
->Channel
) {
2349 IoPortForBmic
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMICS_OFFSET
;
2350 IoPortForBmis
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMISS_OFFSET
;
2351 IoPortForBmid
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMIDS_OFFSET
;
2353 return EFI_UNSUPPORTED
;
2358 // Read BMIS register and clear ERROR and INTR bit
2360 IdeDev
->PciIo
->Io
.Read (
2363 EFI_PCI_IO_PASS_THROUGH_BAR
,
2369 RegisterValue
|= (BMIS_INTERRUPT
| BMIS_ERROR
);
2371 IdeDev
->PciIo
->Io
.Write (
2374 EFI_PCI_IO_PASS_THROUGH_BAR
,
2380 Status
= EFI_SUCCESS
;
2382 RemainBlockNum
= NumberOfBlocks
;
2383 while (RemainBlockNum
> 0) {
2385 if (RemainBlockNum
>= MaxDmaCommandSectors
) {
2387 // SectorCount is used to record the number of sectors to be read
2388 // Max 65536 sectors can be transfered at a time.
2390 NumberOfBlocks
= MaxDmaCommandSectors
;
2391 RemainBlockNum
-= MaxDmaCommandSectors
;
2393 NumberOfBlocks
= (UINT16
) RemainBlockNum
;
2398 // Calculate the number of PRD table to make sure the memory region
2399 // not cross 64K boundary
2401 ByteCount
= NumberOfBlocks
* IdeDev
->BlkIo
.Media
->BlockSize
;
2402 PrdTableNum
= ((ByteCount
>> 16) + 1) + 1;
2407 PageCount
= EFI_SIZE_TO_PAGES (2 * PrdTableNum
* sizeof (IDE_DMA_PRD
));
2408 Status
= IdeDev
->PciIo
->AllocateBuffer (
2411 EfiBootServicesData
,
2416 if (EFI_ERROR (Status
)) {
2417 return EFI_OUT_OF_RESOURCES
;
2419 ZeroMem ((VOID
*) ((UINTN
) MemPage
), EFI_PAGES_TO_SIZE (PageCount
));
2421 PrdAddr
= (IDE_DMA_PRD
*) ((UINTN
) MemPage
);
2423 // To make sure PRD is allocated in one 64K page
2425 if (((UINTN
) PrdAddr
& 0x0FFFF) > (((UINTN
) PrdAddr
+ PrdTableNum
* sizeof (IDE_DMA_PRD
) - 1) & 0x0FFFF)) {
2426 UsedPrdAddr
= (IDE_DMA_PRD
*) ((UINTN
) ((UINT8
*) PrdAddr
+ 0x10000) & 0xFFFF0000);
2428 if ((UINTN
) PrdAddr
& 0x03) {
2429 UsedPrdAddr
= (IDE_DMA_PRD
*) ((UINTN
) ((UINT8
*) PrdAddr
+ 0x04) & 0xFFFFFFFC);
2431 UsedPrdAddr
= PrdAddr
;
2436 // Build the PRD table
2438 Status
= IdeDev
->PciIo
->Map (
2446 if (EFI_ERROR (Status
)) {
2447 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2448 return EFI_OUT_OF_RESOURCES
;
2450 PrdBuffer
= (VOID
*) ((UINTN
) DeviceAddress
);
2451 TempPrdAddr
= UsedPrdAddr
;
2454 ByteAvailable
= 0x10000 - ((UINTN
) PrdBuffer
& 0xFFFF);
2456 if (ByteCount
<= ByteAvailable
) {
2457 TempPrdAddr
->RegionBaseAddr
= (UINT32
) ((UINTN
) PrdBuffer
);
2458 TempPrdAddr
->ByteCount
= (UINT16
) ByteCount
;
2459 TempPrdAddr
->EndOfTable
= 0x8000;
2463 TempPrdAddr
->RegionBaseAddr
= (UINT32
) ((UINTN
) PrdBuffer
);
2464 TempPrdAddr
->ByteCount
= (UINT16
) ByteAvailable
;
2466 ByteCount
-= ByteAvailable
;
2467 PrdBuffer
+= ByteAvailable
;
2472 // Set the base address to BMID register
2474 IdeDev
->PciIo
->Io
.Write (
2476 EfiPciIoWidthUint32
,
2477 EFI_PCI_IO_PASS_THROUGH_BAR
,
2484 // Set BMIC register to identify the operation direction
2486 IdeDev
->PciIo
->Io
.Read (
2489 EFI_PCI_IO_PASS_THROUGH_BAR
,
2495 if (UdmaOp
== AtaUdmaReadExtOp
|| UdmaOp
== AtaUdmaReadOp
) {
2496 RegisterValue
|= BMIC_nREAD
;
2498 RegisterValue
&= ~((UINT8
) BMIC_nREAD
);
2501 IdeDev
->PciIo
->Io
.Write (
2504 EFI_PCI_IO_PASS_THROUGH_BAR
,
2510 if (UdmaOp
== AtaUdmaWriteExtOp
|| UdmaOp
== AtaUdmaReadExtOp
) {
2511 Status
= AtaCommandIssueExt (
2516 (UINT16
) NumberOfBlocks
,
2520 Status
= AtaCommandIssue (
2525 (UINT16
) NumberOfBlocks
,
2530 if (EFI_ERROR (Status
)) {
2531 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2532 IdeDev
->PciIo
->Unmap (IdeDev
->PciIo
, Map
);
2533 return EFI_DEVICE_ERROR
;
2537 // Set START bit of BMIC register
2539 IdeDev
->PciIo
->Io
.Read (
2542 EFI_PCI_IO_PASS_THROUGH_BAR
,
2548 RegisterValue
|= BMIC_START
;
2550 IdeDev
->PciIo
->Io
.Write (
2553 EFI_PCI_IO_PASS_THROUGH_BAR
,
2560 // Check the INTERRUPT and ERROR bit of BMIS
2561 // Max transfer number of sectors for one command is 65536(32Mbyte),
2562 // it will cost 1 second to transfer these data in UDMA mode 2(33.3MBps).
2563 // So set the variable Count to 2000, for about 2 second timeout time.
2565 Status
= EFI_SUCCESS
;
2569 IdeDev
->PciIo
->Io
.Read (
2572 EFI_PCI_IO_PASS_THROUGH_BAR
,
2577 if ((RegisterValue
& (BMIS_INTERRUPT
| BMIS_ERROR
)) || (Count
== 0)) {
2578 if ((RegisterValue
& BMIS_ERROR
) || (Count
== 0)) {
2579 Status
= EFI_DEVICE_ERROR
;
2589 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2590 IdeDev
->PciIo
->Unmap (IdeDev
->PciIo
, Map
);
2592 // Read BMIS register and clear ERROR and INTR bit
2594 IdeDev
->PciIo
->Io
.Read (
2597 EFI_PCI_IO_PASS_THROUGH_BAR
,
2603 RegisterValue
|= (BMIS_INTERRUPT
| BMIS_ERROR
);
2605 IdeDev
->PciIo
->Io
.Write (
2608 EFI_PCI_IO_PASS_THROUGH_BAR
,
2614 // Read Status Register of IDE device to clear interrupt
2616 RegisterValue
= IDEReadPortB(IdeDev
->PciIo
,IdeDev
->IoPort
->Reg
.Status
);
2618 // Clear START bit of BMIC register
2620 IdeDev
->PciIo
->Io
.Read (
2623 EFI_PCI_IO_PASS_THROUGH_BAR
,
2629 RegisterValue
&= ~((UINT8
) BMIC_START
);
2631 IdeDev
->PciIo
->Io
.Write (
2634 EFI_PCI_IO_PASS_THROUGH_BAR
,
2640 if (RegisterValue
& BMIS_ERROR
) {
2641 return EFI_DEVICE_ERROR
;
2644 if (EFI_ERROR (Status
)) {
2647 DataBuffer
= (UINT8
*) DataBuffer
+ NumberOfBlocks
* IdeDev
->BlkIo
.Media
->BlockSize
;
2648 StartLba
+= NumberOfBlocks
;
2652 // Disable interrupt of Select device
2654 IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
);
2655 DeviceControl
|= ATA_CTLREG_IEN_L
;
2656 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);