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
196 This function must be called after DEVICE_IDENTITY command has been
197 successfully returned
202 IN IDE_BLK_IO_DEV
*IdeDev
208 EFI_IDENTIFY_DATA
*Atapi6IdentifyStruct
;
210 if (IdeDev
->pIdData
== NULL
) {
211 return EFI_UNSUPPORTED
;
214 Atapi6IdentifyStruct
= IdeDev
->pIdData
;
216 if ((Atapi6IdentifyStruct
->AtapiData
.cmd_set_support_83
& (BIT15
| BIT14
)) != 0x4000) {
218 // Per ATA-6 spec, word83: bit15 is zero and bit14 is one
220 return EFI_DEVICE_ERROR
;
223 if ((Atapi6IdentifyStruct
->AtapiData
.cmd_set_support_83
& BIT10
) == 0) {
225 // The device dosn't support 48 bit addressing
227 return EFI_UNSUPPORTED
;
231 // 48 bit address feature set is supported, get maximum capacity
233 Capacity
= Atapi6IdentifyStruct
->AtapiData
.max_user_lba_for_48bit_addr
[0];
234 for (Index
= 1; Index
< 4; Index
++) {
236 // Lower byte goes first: word[100] is the lowest word, word[103] is highest
238 TmpLba
= Atapi6IdentifyStruct
->AtapiData
.max_user_lba_for_48bit_addr
[Index
];
239 Capacity
|= LShiftU64 (TmpLba
, 16 * Index
);
242 if (Capacity
> MAX_28BIT_ADDRESSING_CAPACITY
) {
244 // Capacity exceeds 120GB. 48-bit addressing is really needed
246 IdeDev
->Type
= Ide48bitAddressingHardDisk
;
249 // Fill block media information:Media->LogicalPartition ,
250 // Media->WriteCaching will be filledin the DiscoverIdeDevcie() function.
252 IdeDev
->BlkIo
.Media
->IoAlign
= 4;
253 IdeDev
->BlkIo
.Media
->MediaId
= 1;
254 IdeDev
->BlkIo
.Media
->RemovableMedia
= FALSE
;
255 IdeDev
->BlkIo
.Media
->MediaPresent
= TRUE
;
256 IdeDev
->BlkIo
.Media
->ReadOnly
= FALSE
;
257 IdeDev
->BlkIo
.Media
->BlockSize
= 0x200;
258 IdeDev
->BlkIo
.Media
->LastBlock
= Capacity
- 1;
263 return EFI_UNSUPPORTED
;
267 This function is called by ATAIdentify() or ATAPIIdentify()
268 to print device's module name.
271 pointer pointing to IDE_BLK_IO_DEV data structure, used
272 to record all the information of the IDE device.
277 IN IDE_BLK_IO_DEV
*IdeDev
280 if (IdeDev
->pIdData
== NULL
) {
284 SwapStringChars (IdeDev
->ModelName
, IdeDev
->pIdData
->AtaData
.ModelName
, 40);
285 IdeDev
->ModelName
[40] = 0x00;
289 This function is used to send out ATA commands conforms to the
290 PIO Data In Protocol.
293 pointer pointing to IDE_BLK_IO_DEV data structure, used
294 to record all the information of the IDE device.
297 buffer contained data transferred from device to host.
300 data size in byte unit of the buffer.
302 @param[in] AtaCommand
303 value of the Command Register
306 value of the Head/Device Register
308 @param[in] SectorCount
309 value of the Sector Count Register
311 @param[in] SectorNumber
312 value of the Sector Number Register
314 @param[in] CylinderLsb
315 value of the low byte of the Cylinder Register
317 @param[in] CylinderMsb
318 value of the high byte of the Cylinder Register
320 @retval EFI_SUCCESS send out the ATA command and device send required
323 @retval EFI_DEVICE_ERROR command sent failed.
328 IN IDE_BLK_IO_DEV
*IdeDev
,
333 IN UINT8 SectorCount
,
334 IN UINT8 SectorNumber
,
335 IN UINT8 CylinderLsb
,
344 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
345 if (EFI_ERROR (Status
)) {
346 return EFI_DEVICE_ERROR
;
350 // e0:1110,0000-- bit7 and bit5 are reserved bits.
351 // bit6 set means LBA mode
355 IdeDev
->IoPort
->Head
,
356 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0 | Head
)
360 // All ATAPI device's ATA commands can be issued regardless of the
363 if (IdeDev
->Type
== IdeHardDisk
) {
365 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
366 if (EFI_ERROR (Status
)) {
367 return EFI_DEVICE_ERROR
;
371 // set all the command parameters
372 // Before write to all the following registers, BSY and DRQ must be 0.
374 Status
= DRQClear2 (IdeDev
, ATATIMEOUT
);
375 if (EFI_ERROR (Status
)) {
376 return EFI_DEVICE_ERROR
;
379 if (AtaCommand
== ATA_CMD_SET_FEATURES
) {
380 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, 0x03);
383 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount
);
384 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, SectorNumber
);
385 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, CylinderLsb
);
386 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, CylinderMsb
);
389 // send command via Command Register
391 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
393 Buffer16
= (UINT16
*) Buffer
;
396 // According to PIO data in protocol, host can perform a series of reads to
397 // the data register after each time device set DRQ ready;
398 // The data size of "a series of read" is command specific.
399 // For most ATA command, data size received from device will not exceed
400 // 1 sector, hence the data size for "a series of read" can be the whole data
401 // size of one command request.
402 // For ATA command such as Read Sector command, the data size of one ATA
403 // command request is often larger than 1 sector, according to the
404 // Read Sector command, the data size of "a series of read" is exactly 1
406 // Here for simplification reason, we specify the data size for
407 // "a series of read" to 1 sector (256 words) if data size of one ATA command
408 // request is larger than 256 words.
413 // used to record bytes of currently transfered data
417 while (WordCount
< ByteCount
/ 2) {
419 // Poll DRQ bit set, data transfer can be performed only when DRQ is ready.
421 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
422 if (EFI_ERROR (Status
)) {
423 return EFI_DEVICE_ERROR
;
426 Status
= CheckErrorStatus (IdeDev
);
427 if (EFI_ERROR (Status
)) {
428 return EFI_DEVICE_ERROR
;
432 // Get the byte count for one series of read
434 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
435 Increment
= ByteCount
/ 2 - WordCount
;
438 IDEReadPortWMultiple (
440 IdeDev
->IoPort
->Data
,
445 WordCount
+= Increment
;
446 Buffer16
+= Increment
;
450 DRQClear (IdeDev
, ATATIMEOUT
);
452 return CheckErrorStatus (IdeDev
);
456 This function is used to send out ATA commands conforms to the
457 PIO Data Out Protocol.
460 pointer pointing to IDE_BLK_IO_DEV data structure, used
461 to record all the information of the IDE device.
463 @param *Buffer buffer contained data transferred from host to device.
464 @param ByteCount data size in byte unit of the buffer.
465 @param AtaCommand value of the Command Register
466 @param Head value of the Head/Device Register
467 @param SectorCount value of the Sector Count Register
468 @param SectorNumber value of the Sector Number Register
469 @param CylinderLsb value of the low byte of the Cylinder Register
470 @param CylinderMsb value of the high byte of the Cylinder Register
472 @retval EFI_SUCCESS send out the ATA command and device received required
475 @retval EFI_DEVICE_ERROR command sent failed.
480 IN IDE_BLK_IO_DEV
*IdeDev
,
485 IN UINT8 SectorCount
,
486 IN UINT8 SectorNumber
,
487 IN UINT8 CylinderLsb
,
496 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
497 if (EFI_ERROR (Status
)) {
498 return EFI_DEVICE_ERROR
;
502 // select device via Head/Device register.
503 // Before write Head/Device register, BSY and DRQ must be 0.
505 Status
= DRQClear2 (IdeDev
, ATATIMEOUT
);
506 if (EFI_ERROR (Status
)) {
507 return EFI_DEVICE_ERROR
;
511 // e0:1110,0000-- bit7 and bit5 are reserved bits.
512 // bit6 set means LBA mode
516 IdeDev
->IoPort
->Head
,
517 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0 | Head
)
520 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
521 if (EFI_ERROR (Status
)) {
522 return EFI_DEVICE_ERROR
;
526 // set all the command parameters
527 // Before write to all the following registers, BSY and DRQ must be 0.
529 Status
= DRQClear2 (IdeDev
, ATATIMEOUT
);
530 if (EFI_ERROR (Status
)) {
531 return EFI_DEVICE_ERROR
;
534 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount
);
535 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, SectorNumber
);
536 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, CylinderLsb
);
537 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, CylinderMsb
);
540 // send command via Command Register
542 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
544 Buffer16
= (UINT16
*) Buffer
;
547 // According to PIO data out protocol, host can perform a series of
548 // writes to the data register after each time device set DRQ ready;
549 // The data size of "a series of read" is command specific.
550 // For most ATA command, data size written to device will not exceed 1 sector,
551 // hence the data size for "a series of write" can be the data size of one
553 // For ATA command such as Write Sector command, the data size of one
554 // ATA command request is often larger than 1 sector, according to the
555 // Write Sector command, the data size of "a series of read" is exactly
557 // Here for simplification reason, we specify the data size for
558 // "a series of write" to 1 sector (256 words) if data size of one ATA command
559 // request is larger than 256 words.
564 while (WordCount
< ByteCount
/ 2) {
567 // DRQReady2-- read Alternate Status Register to determine the DRQ bit
568 // data transfer can be performed only when DRQ is ready.
570 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
571 if (EFI_ERROR (Status
)) {
572 return EFI_DEVICE_ERROR
;
575 Status
= CheckErrorStatus (IdeDev
);
576 if (EFI_ERROR (Status
)) {
577 return EFI_DEVICE_ERROR
;
581 // Check the remaining byte count is less than 512 bytes
583 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
584 Increment
= ByteCount
/ 2 - WordCount
;
587 // perform a series of write without check DRQ ready
590 IDEWritePortWMultiple (
592 IdeDev
->IoPort
->Data
,
596 WordCount
+= Increment
;
597 Buffer16
+= Increment
;
601 DRQClear (IdeDev
, ATATIMEOUT
);
603 return CheckErrorStatus (IdeDev
);
607 This function is used to analyze the Status Register and print out
608 some debug information and if there is ERR bit set in the Status
609 Register, the Error Register's value is also be parsed and print out.
612 pointer pointing to IDE_BLK_IO_DEV data structure, used
613 to record all the information of the IDE device.
615 @retval EFI_SUCCESS No err information in the Status Register.
616 @retval EFI_DEVICE_ERROR Any err information in the Status Register.
621 IN IDE_BLK_IO_DEV
*IdeDev
624 UINT8 StatusRegister
;
627 StatusRegister
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Status
);
631 if (StatusRegister
& ATA_STSREG_DWF
) {
634 "CheckErrorStatus()-- %02x : Error : Write Fault\n",
639 if (StatusRegister
& ATA_STSREG_CORR
) {
642 "CheckErrorStatus()-- %02x : Error : Corrected Data\n",
647 if (StatusRegister
& ATA_STSREG_ERR
) {
648 ErrorRegister
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Error
);
650 if (ErrorRegister
& ATA_ERRREG_BBK
) {
653 "CheckErrorStatus()-- %02x : Error : Bad Block Detected\n",
658 if (ErrorRegister
& ATA_ERRREG_UNC
) {
661 "CheckErrorStatus()-- %02x : Error : Uncorrectable Data\n",
666 if (ErrorRegister
& ATA_ERRREG_MC
) {
669 "CheckErrorStatus()-- %02x : Error : Media Change\n",
674 if (ErrorRegister
& ATA_ERRREG_ABRT
) {
677 "CheckErrorStatus()-- %02x : Error : Abort\n",
682 if (ErrorRegister
& ATA_ERRREG_TK0NF
) {
685 "CheckErrorStatus()-- %02x : Error : Track 0 Not Found\n",
690 if (ErrorRegister
& ATA_ERRREG_AMNF
) {
693 "CheckErrorStatus()-- %02x : Error : Address Mark Not Found\n",
701 if ((StatusRegister
& (ATA_STSREG_ERR
| ATA_STSREG_DWF
| ATA_STSREG_CORR
)) == 0) {
705 return EFI_DEVICE_ERROR
;
710 This function is called by the AtaBlkIoReadBlocks() to perform
711 reading from media in block unit.
714 pointer pointing to IDE_BLK_IO_DEV data structure, used
715 to record all the information of the IDE device.
717 @param[in] *DataBuffer
718 A pointer to the destination buffer for the data.
721 The starting logical block address to read from
724 @param[in] NumberOfBlocks
725 The number of transfer data blocks.
727 @return return status is fully dependent on the return status
728 of AtaPioDataIn() function.
733 IN IDE_BLK_IO_DEV
*IdeDev
,
736 IN UINTN NumberOfBlocks
740 UINTN BlocksRemaining
;
755 // Using ATA Read Sector(s) command (opcode=0x20) with PIO DATA IN protocol
757 AtaCommand
= ATA_CMD_READ_SECTORS
;
760 BlocksRemaining
= NumberOfBlocks
;
762 Lba32
= (UINT32
) Lba
;
764 Status
= EFI_SUCCESS
;
766 while (BlocksRemaining
> 0) {
769 // in ATA-3 spec, LBA is in 28 bit width
771 Lba0
= (UINT8
) Lba32
;
772 Lba1
= (UINT8
) (Lba32
>> 8);
773 Lba2
= (UINT8
) (Lba32
>> 16);
775 // low 4 bit of Lba3 stands for LBA bit24~bit27.
777 Lba3
= (UINT8
) ((Lba32
>> 24) & 0x0f);
779 if (BlocksRemaining
>= 0x100) {
782 // SectorCount8 is sent to Sector Count register, 0x00 means 256
783 // sectors to be read
787 // SectorCount is used to record the number of sectors to be read
792 SectorCount8
= (UINT8
) BlocksRemaining
;
793 SectorCount
= (UINT16
) BlocksRemaining
;
797 // ByteCount is the number of bytes that will be read
799 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
802 // call AtaPioDataIn() to send Read Sector Command and receive data read
804 Status
= AtaPioDataIn (
815 if (EFI_ERROR (Status
)) {
819 Lba32
+= SectorCount
;
820 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
821 BlocksRemaining
-= SectorCount
;
828 This function is called by the AtaBlkIoWriteBlocks() to perform
829 writing onto media in block unit.
832 pointer pointing to IDE_BLK_IO_DEV data structure,used
833 to record all the information of the IDE device.
835 @param[in] *BufferData
836 A pointer to the source buffer for the data.
839 The starting logical block address to write onto
842 @param[in] NumberOfBlocks
843 The number of transfer data blocks.
845 @return return status is fully dependent on the return status
846 of AtaPioDataOut() function.
851 IN IDE_BLK_IO_DEV
*IdeDev
,
854 IN UINTN NumberOfBlocks
858 UINTN BlocksRemaining
;
873 // Using Write Sector(s) command (opcode=0x30) with PIO DATA OUT protocol
875 AtaCommand
= ATA_CMD_WRITE_SECTORS
;
877 BlocksRemaining
= NumberOfBlocks
;
879 Lba32
= (UINT32
) Lba
;
881 Status
= EFI_SUCCESS
;
883 while (BlocksRemaining
> 0) {
885 Lba0
= (UINT8
) Lba32
;
886 Lba1
= (UINT8
) (Lba32
>> 8);
887 Lba2
= (UINT8
) (Lba32
>> 16);
888 Lba3
= (UINT8
) ((Lba32
>> 24) & 0x0f);
890 if (BlocksRemaining
>= 0x100) {
893 // SectorCount8 is sent to Sector Count register, 0x00 means 256 sectors
898 // SectorCount is used to record the number of sectors to be written
903 SectorCount8
= (UINT8
) BlocksRemaining
;
904 SectorCount
= (UINT16
) BlocksRemaining
;
907 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
909 Status
= AtaPioDataOut (
920 if (EFI_ERROR (Status
)) {
924 Lba32
+= SectorCount
;
925 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
926 BlocksRemaining
-= SectorCount
;
933 This function is used to implement the Soft Reset on the specified
934 device. But, the ATA Soft Reset mechanism is so strong a reset method
935 that it will force resetting on both devices connected to the
938 It is called by IdeBlkIoReset(), a interface function of Block
941 This function can also be used by the ATAPI device to perform reset when
942 ATAPI Reset command is failed.
945 pointer pointing to IDE_BLK_IO_DEV data structure, used
946 to record all the information of the IDE device.
948 @retval EFI_SUCCESS Soft reset completes successfully.
949 @retval EFI_DEVICE_ERROR Any step during the reset process is failed.
952 The registers initial values after ATA soft reset are different
953 to the ATA device and ATAPI device.
958 IN IDE_BLK_IO_DEV
*IdeDev
966 // set SRST bit to initiate soft reset
968 DeviceControl
|= ATA_CTLREG_SRST
;
973 DeviceControl
|= BIT1
;
975 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);
978 // SRST should assert for at least 5 us, we use 10 us for
979 // better compatibility
984 // Enable interrupt to support UDMA, and clear SRST bit
987 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);
990 // Wait for at least 2 ms to check BSY status, we use 10 ms
991 // for better compatibility
995 // slave device needs at most 31s to clear BSY
997 if (WaitForBSYClear (IdeDev
, 31000) == EFI_TIMEOUT
) {
998 return EFI_DEVICE_ERROR
;
1005 This function is the ATA implementation for ReadBlocks in the
1006 Block I/O Protocol interface.
1008 @param[in] *IdeBlkIoDevice
1009 Indicates the calling context.
1012 The media id that the read request is for.
1015 The starting logical block address to read from
1018 @param[in] BufferSize
1019 The size of the Buffer in bytes. This must be a
1020 multiple of the intrinsic block size of the device.
1023 A pointer to the destination buffer for the data.
1024 The caller is responsible for either having implicit
1025 or explicit ownership of the memory that data is read into.
1027 @retval EFI_SUCCESS Read Blocks successfully.
1028 @retval EFI_DEVICE_ERROR Read Blocks failed.
1029 @retval EFI_NO_MEDIA There is no media in the device.
1030 @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.
1032 @retval EFI_BAD_BUFFER_SIZE
1033 The BufferSize parameter is not a multiple of the
1034 intrinsic block size of the device.
1036 @retval EFI_INVALID_PARAMETER
1037 The read request contains LBAs that are not valid,
1038 or the data buffer is not valid.
1041 If Read Block error because of device error, this function will call
1042 AtaSoftReset() function to reset device.
1046 AtaBlkIoReadBlocks (
1047 IN IDE_BLK_IO_DEV
*IdeBlkIoDevice
,
1050 IN UINTN BufferSize
,
1054 EFI_BLOCK_IO_MEDIA
*Media
;
1056 UINTN NumberOfBlocks
;
1059 if (Buffer
== NULL
) {
1060 return EFI_INVALID_PARAMETER
;
1063 if (BufferSize
== 0) {
1067 Status
= EFI_SUCCESS
;
1070 // Get the intrinsic block size
1072 Media
= IdeBlkIoDevice
->BlkIo
.Media
;
1073 BlockSize
= Media
->BlockSize
;
1075 NumberOfBlocks
= BufferSize
/ BlockSize
;
1077 if (MediaId
!= Media
->MediaId
) {
1078 return EFI_MEDIA_CHANGED
;
1081 if (BufferSize
% BlockSize
!= 0) {
1082 return EFI_BAD_BUFFER_SIZE
;
1085 if (!(Media
->MediaPresent
)) {
1086 return EFI_NO_MEDIA
;
1089 if (LBA
> Media
->LastBlock
) {
1090 return EFI_INVALID_PARAMETER
;
1093 if ((LBA
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1094 return EFI_INVALID_PARAMETER
;
1097 if ((Media
->IoAlign
> 1) && (((UINTN
) Buffer
& (Media
->IoAlign
- 1)) != 0)) {
1098 return EFI_INVALID_PARAMETER
;
1101 Status
= EFI_SUCCESS
;
1102 if (IdeBlkIoDevice
->Type
== Ide48bitAddressingHardDisk
) {
1104 // For ATA/ATAPI-6 device(capcity > 120GB), use ATA-6 read block mechanism
1106 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1107 Status
= AtaUdmaReadExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1109 Status
= AtaReadSectorsExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1113 // For ATA-3 compatible device, use ATA-3 read block mechanism
1115 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1116 Status
= AtaUdmaRead (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1118 Status
= AtaReadSectors (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1122 if (EFI_ERROR (Status
)) {
1123 AtaSoftReset (IdeBlkIoDevice
);
1124 return EFI_DEVICE_ERROR
;
1132 This function is the ATA implementation for WriteBlocks in the
1133 Block I/O Protocol interface.
1135 @param[in] *IdeBlkIoDevice
1136 Indicates the calling context.
1139 The media id that the write request is for.
1142 The starting logical block address to write onto
1145 @param[in] BufferSize
1146 The size of the Buffer in bytes. This must be a
1147 multiple of the intrinsic block size of the device.
1150 A pointer to the source buffer for the data.
1151 The caller is responsible for either having implicit
1152 or explicit ownership of the memory that data is
1155 @retval EFI_SUCCESS Write Blocks successfully.
1156 @retval EFI_DEVICE_ERROR Write Blocks failed.
1157 @retval EFI_NO_MEDIA There is no media in the device.
1158 @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.
1160 @retval EFI_BAD_BUFFER_SIZE
1161 The BufferSize parameter is not a multiple of the
1162 intrinsic block size of the device.
1164 @retval EFI_INVALID_PARAMETER
1165 The write request contains LBAs that are not valid,
1166 or the data buffer is not valid.
1169 If Write Block error because of device error, this function will call
1170 AtaSoftReset() function to reset device.
1174 AtaBlkIoWriteBlocks (
1175 IN IDE_BLK_IO_DEV
*IdeBlkIoDevice
,
1178 IN UINTN BufferSize
,
1183 EFI_BLOCK_IO_MEDIA
*Media
;
1185 UINTN NumberOfBlocks
;
1188 if (Buffer
== NULL
) {
1189 return EFI_INVALID_PARAMETER
;
1192 if (BufferSize
== 0) {
1196 Status
= EFI_SUCCESS
;
1199 // Get the intrinsic block size
1201 Media
= IdeBlkIoDevice
->BlkIo
.Media
;
1202 BlockSize
= Media
->BlockSize
;
1203 NumberOfBlocks
= BufferSize
/ BlockSize
;
1205 if (MediaId
!= Media
->MediaId
) {
1206 return EFI_MEDIA_CHANGED
;
1209 if (BufferSize
% BlockSize
!= 0) {
1210 return EFI_BAD_BUFFER_SIZE
;
1213 if (LBA
> Media
->LastBlock
) {
1214 return EFI_INVALID_PARAMETER
;
1217 if ((LBA
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1218 return EFI_INVALID_PARAMETER
;
1221 if ((Media
->IoAlign
> 1) && (((UINTN
) Buffer
& (Media
->IoAlign
- 1)) != 0)) {
1222 return EFI_INVALID_PARAMETER
;
1225 Status
= EFI_SUCCESS
;
1226 if (IdeBlkIoDevice
->Type
== Ide48bitAddressingHardDisk
) {
1228 // For ATA/ATAPI-6 device(capcity > 120GB), use ATA-6 write block mechanism
1230 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1231 Status
= AtaUdmaWriteExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1233 Status
= AtaWriteSectorsExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1237 // For ATA-3 compatible device, use ATA-3 write block mechanism
1239 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1240 Status
= AtaUdmaWrite (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1242 Status
= AtaWriteSectors (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1246 if (EFI_ERROR (Status
)) {
1247 AtaSoftReset (IdeBlkIoDevice
);
1248 return EFI_DEVICE_ERROR
;
1255 This function is called by the AtaBlkIoReadBlocks() to perform
1256 reading from media in block unit. The function has been enhanced to
1257 support >120GB access and transfer at most 65536 blocks per command
1260 pointer pointing to IDE_BLK_IO_DEV data structure, used
1261 to record all the information of the IDE device.
1263 @param[in] *DataBuffer A pointer to the destination buffer for the data.
1264 @param[in] StartLba The starting logical block address to read from
1265 on the device media.
1266 @param[in] NumberOfBlocks The number of transfer data blocks.
1268 @return return status is fully dependent on the return status
1269 of AtaPioDataInExt() function.
1274 IN IDE_BLK_IO_DEV
*IdeDev
,
1275 IN VOID
*DataBuffer
,
1276 IN EFI_LBA StartLba
,
1277 IN UINTN NumberOfBlocks
1281 UINTN BlocksRemaining
;
1289 // Using ATA "Read Sectors Ext" command(opcode=0x24) with PIO DATA IN protocol
1291 AtaCommand
= ATA_CMD_READ_SECTORS_EXT
;
1292 Buffer
= DataBuffer
;
1293 BlocksRemaining
= NumberOfBlocks
;
1295 Status
= EFI_SUCCESS
;
1297 while (BlocksRemaining
> 0) {
1299 if (BlocksRemaining
>= 0x10000) {
1301 // SectorCount is used to record the number of sectors to be read
1302 // Max 65536 sectors can be transfered at a time.
1304 SectorCount
= 0xffff;
1306 SectorCount
= (UINT16
) BlocksRemaining
;
1310 // ByteCount is the number of bytes that will be read
1312 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
1315 // call AtaPioDataInExt() to send Read Sector Command and receive data read
1317 Status
= AtaPioDataInExt (
1325 if (EFI_ERROR (Status
)) {
1329 Lba64
+= SectorCount
;
1330 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
1331 BlocksRemaining
-= SectorCount
;
1338 This function is called by the AtaBlkIoWriteBlocks() to perform
1339 writing onto media in block unit. The function has been enhanced to
1340 support >120GB access and transfer at most 65536 blocks per command
1343 pointer pointing to IDE_BLK_IO_DEV data structure,used
1344 to record all the information of the IDE device.
1346 @param[in] *DataBuffer
1347 A pointer to the source buffer for the data.
1350 The starting logical block address to write onto
1353 @param[in] NumberOfBlocks
1354 The number of transfer data blocks.
1356 @return status is fully dependent on the return status
1357 of AtaPioDataOutExt() function.
1361 AtaWriteSectorsExt (
1362 IN IDE_BLK_IO_DEV
*IdeDev
,
1363 IN VOID
*DataBuffer
,
1364 IN EFI_LBA StartLba
,
1365 IN UINTN NumberOfBlocks
1370 UINTN BlocksRemaining
;
1377 // Using ATA "Write Sectors Ext" cmd(opcode=0x24) with PIO DATA OUT protocol
1379 AtaCommand
= ATA_CMD_WRITE_SECTORS_EXT
;
1381 Buffer
= DataBuffer
;
1382 BlocksRemaining
= NumberOfBlocks
;
1384 Status
= EFI_SUCCESS
;
1386 while (BlocksRemaining
> 0) {
1388 if (BlocksRemaining
>= 0x10000) {
1390 // SectorCount is used to record the number of sectors to be written.
1391 // Max 65536 sectors can be transfered at a time.
1393 SectorCount
= 0xffff;
1395 SectorCount
= (UINT16
) BlocksRemaining
;
1399 // ByteCount is the number of bytes that will be written
1401 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
1404 // Call AtaPioDataOutExt() to send "Write Sectors Ext" Command
1406 Status
= AtaPioDataOutExt (
1414 if (EFI_ERROR (Status
)) {
1418 Lba64
+= SectorCount
;
1419 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
1420 BlocksRemaining
-= SectorCount
;
1427 This function is used to send out ATA commands conforms to the
1428 PIO Data In Protocol, supporting ATA/ATAPI-6 standard
1430 Comparing with ATA-3 data in protocol, we have two differents here:<BR>
1431 1. Do NOT wait for DRQ clear before sending command into IDE device.(the
1432 wait will frequently fail... cause writing function return error)
1434 2. Do NOT wait for DRQ clear after all data readed.(the wait greatly
1435 slow down writing performance by 100 times!)
1437 @param[in] *IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used
1438 to record all the information of the IDE device.
1440 @param[in,out] *Buffer buffer contained data transferred from device to host.
1441 @param[in] ByteCount data size in byte unit of the buffer.
1442 @param[in] AtaCommand value of the Command Register
1443 @param[in] StartLba the start LBA of this transaction
1444 @param[in] SectorCount the count of sectors to be transfered
1446 @retval EFI_SUCCESS send out the ATA command and device send required
1449 @retval EFI_DEVICE_ERROR command sent failed.
1454 IN IDE_BLK_IO_DEV
*IdeDev
,
1455 IN OUT VOID
*Buffer
,
1456 IN UINT32 ByteCount
,
1457 IN UINT8 AtaCommand
,
1458 IN EFI_LBA StartLba
,
1459 IN UINT16 SectorCount
1472 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
1473 if (EFI_ERROR (Status
)) {
1474 return EFI_DEVICE_ERROR
;
1478 // Select device, set bit6 as 1 to indicate LBA mode is used
1480 DevSel
= (UINT8
) (IdeDev
->Device
<< 4);
1484 IdeDev
->IoPort
->Head
,
1489 // Wait for DRDY singnal asserting. ATAPI device needn't wait
1491 if ( (IdeDev
->Type
== IdeHardDisk
) ||
1492 (IdeDev
->Type
== Ide48bitAddressingHardDisk
)) {
1494 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
1495 if (EFI_ERROR (Status
)) {
1496 return EFI_DEVICE_ERROR
;
1501 // Fill feature register if needed
1503 if (AtaCommand
== ATA_CMD_SET_FEATURES
) {
1504 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, 0x03);
1508 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
1510 SectorCount8
= (UINT8
) (SectorCount
>> 8);
1511 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1513 SectorCount8
= (UINT8
) SectorCount
;
1514 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1517 // Fill the start LBA registers, which are also two-byte FIFO
1519 LbaLow
= (UINT8
) RShiftU64 (StartLba
, 24);
1520 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 32);
1521 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 40);
1522 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1523 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1524 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1526 LbaLow
= (UINT8
) StartLba
;
1527 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 8);
1528 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 16);
1529 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1530 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1531 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1534 // Send command via Command Register, invoking the processing of this command
1536 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
1538 Buffer16
= (UINT16
*) Buffer
;
1541 // According to PIO data in protocol, host can perform a series of reads to
1542 // the data register after each time device set DRQ ready;
1551 // used to record bytes of currently transfered data
1555 while (WordCount
< ByteCount
/ 2) {
1557 // Poll DRQ bit set, data transfer can be performed only when DRQ is ready.
1559 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
1560 if (EFI_ERROR (Status
)) {
1561 return EFI_DEVICE_ERROR
;
1564 Status
= CheckErrorStatus (IdeDev
);
1565 if (EFI_ERROR (Status
)) {
1566 return EFI_DEVICE_ERROR
;
1570 // Get the byte count for one series of read
1572 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
1573 Increment
= ByteCount
/ 2 - WordCount
;
1576 IDEReadPortWMultiple (
1578 IdeDev
->IoPort
->Data
,
1583 WordCount
+= Increment
;
1584 Buffer16
+= Increment
;
1588 return CheckErrorStatus (IdeDev
);
1592 This function is used to send out ATA commands conforms to the
1593 PIO Data Out Protocol, supporting ATA/ATAPI-6 standard
1595 Comparing with ATA-3 data out protocol, we have two differents here:<BR>
1596 1. Do NOT wait for DRQ clear before sending command into IDE device.(the
1597 wait will frequently fail... cause writing function return error)
1599 2. Do NOT wait for DRQ clear after all data readed.(the wait greatly
1600 slow down writing performance by 100 times!)
1603 pointer pointing to IDE_BLK_IO_DEV data structure, used
1604 to record all the information of the IDE device.
1606 @param[in] *Buffer buffer contained data transferred from host to device.
1607 @param[in] ByteCount data size in byte unit of the buffer.
1608 @param[in] AtaCommand value of the Command Register
1609 @param[in] StartLba the start LBA of this transaction
1610 @param[in] SectorCount the count of sectors to be transfered
1612 @retval EFI_SUCCESS send out the ATA command and device receive required
1615 @retval EFI_DEVICE_ERROR command sent failed.
1620 IN IDE_BLK_IO_DEV
*IdeDev
,
1622 IN UINT32 ByteCount
,
1623 IN UINT8 AtaCommand
,
1624 IN EFI_LBA StartLba
,
1625 IN UINT16 SectorCount
1638 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
1639 if (EFI_ERROR (Status
)) {
1640 return EFI_DEVICE_ERROR
;
1644 // Select device. Set bit6 as 1 to indicate LBA mode is used
1646 DevSel
= (UINT8
) (IdeDev
->Device
<< 4);
1650 IdeDev
->IoPort
->Head
,
1655 // Wait for DRDY singnal asserting.
1657 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
1658 if (EFI_ERROR (Status
)) {
1659 return EFI_DEVICE_ERROR
;
1663 // Fill feature register if needed
1665 if (AtaCommand
== ATA_CMD_SET_FEATURES
) {
1666 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, 0x03);
1670 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
1672 SectorCount8
= (UINT8
) (SectorCount
>> 8);
1673 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1675 SectorCount8
= (UINT8
) SectorCount
;
1676 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1679 // Fill the start LBA registers, which are also two-byte FIFO
1681 LbaLow
= (UINT8
) RShiftU64 (StartLba
, 24);
1682 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 32);
1683 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 40);
1684 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1685 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1686 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1688 LbaLow
= (UINT8
) StartLba
;
1689 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 8);
1690 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 16);
1691 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1692 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1693 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1696 // Send command via Command Register, invoking the processing of this command
1698 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
1700 Buffer16
= (UINT16
*) Buffer
;
1703 // According to PIO Data Out protocol, host can perform a series of writes to
1704 // the data register after each time device set DRQ ready;
1709 // used to record bytes of currently transfered data
1713 while (WordCount
< ByteCount
/ 2) {
1715 // Poll DRQ bit set, data transfer can be performed only when DRQ is ready.
1717 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
1718 if (EFI_ERROR (Status
)) {
1719 return EFI_DEVICE_ERROR
;
1722 Status
= CheckErrorStatus (IdeDev
);
1723 if (EFI_ERROR (Status
)) {
1724 return EFI_DEVICE_ERROR
;
1728 // Write data into device by one series of writing to data register
1730 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
1731 Increment
= ByteCount
/ 2 - WordCount
;
1734 IDEWritePortWMultiple (
1736 IdeDev
->IoPort
->Data
,
1741 WordCount
+= Increment
;
1742 Buffer16
+= Increment
;
1749 return CheckErrorStatus (IdeDev
);
1754 Enable SMART of the disk if supported
1757 pointer pointing to IDE_BLK_IO_DEV data structure,used
1758 to record all the information of the IDE device.
1763 IN IDE_BLK_IO_DEV
*IdeDev
1767 BOOLEAN SMARTSupported
;
1769 EFI_IDENTIFY_DATA
*TmpAtaIdentifyPointer
;
1775 // Detect if the device supports S.M.A.R.T.
1777 if ((IdeDev
->pIdData
->AtaData
.command_set_supported_83
& 0xc000) != 0x4000) {
1779 // Data in word 82 is not valid (bit15 shall be zero and bit14 shall be to one)
1783 if ((IdeDev
->pIdData
->AtaData
.command_set_supported_82
& 0x0001) != 0x0001) {
1785 // S.M.A.R.T is not supported by the device
1787 SMARTSupported
= FALSE
;
1789 SMARTSupported
= TRUE
;
1793 if (!SMARTSupported
) {
1795 // Report nonsupport status code
1797 REPORT_STATUS_CODE (
1798 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1799 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_NOTSUPPORTED
)
1803 // Enable this feature
1805 REPORT_STATUS_CODE (
1807 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_ENABLE
)
1810 Device
= (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0);
1811 Status
= AtaNonDataCommandIn (
1815 ATA_SMART_ENABLE_OPERATION
,
1822 // Detect if this feature is enabled
1824 TmpAtaIdentifyPointer
= (EFI_IDENTIFY_DATA
*) AllocateZeroPool (sizeof (EFI_IDENTIFY_DATA
));
1826 DeviceSelect
= (UINT8
) ((IdeDev
->Device
) << 4);
1827 Status
= AtaPioDataIn (
1829 (VOID
*) TmpAtaIdentifyPointer
,
1830 sizeof (EFI_IDENTIFY_DATA
),
1831 ATA_CMD_IDENTIFY_DRIVE
,
1838 if (EFI_ERROR (Status
)) {
1839 gBS
->FreePool (TmpAtaIdentifyPointer
);
1844 // Check if the feature is enabled
1846 if ((TmpAtaIdentifyPointer
->AtaData
.command_set_feature_enb_85
& 0x0001) == 0x0001) {
1850 AtaNonDataCommandIn (
1854 ATA_SMART_RETURN_STATUS
,
1860 LBAMid
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
);
1861 LBAHigh
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
);
1863 if ((LBAMid
== 0x4f) && (LBAHigh
== 0xc2)) {
1865 // The threshold exceeded condition is not detected by the device
1867 REPORT_STATUS_CODE (
1869 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_UNDERTHRESHOLD
)
1872 } else if ((LBAMid
== 0xf4) && (LBAHigh
== 0x2c)) {
1874 // The threshold exceeded condition is detected by the device
1876 REPORT_STATUS_CODE (
1878 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_OVERTHRESHOLD
)
1884 // Report disabled status code
1886 REPORT_STATUS_CODE (
1887 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1888 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_DISABLED
)
1892 gBS
->FreePool (TmpAtaIdentifyPointer
);
1899 Send ATA Ext command into device with NON_DATA protocol
1901 @param IdeDev Standard IDE device private data structure
1902 @param AtaCommand The ATA command to be sent
1903 @param Device The value in Device register
1904 @param Feature The value in Feature register
1905 @param SectorCount The value in SectorCount register
1906 @param LbaAddress The LBA address in 48-bit mode
1908 @retval EFI_SUCCESS Reading succeed
1909 @retval EFI_DEVICE_ERROR Error executing commands on this device
1913 AtaCommandIssueExt (
1914 IN IDE_BLK_IO_DEV
*IdeDev
,
1915 IN UINT8 AtaCommand
,
1918 IN UINT16 SectorCount
,
1919 IN EFI_LBA LbaAddress
1929 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
1930 if (EFI_ERROR (Status
)) {
1931 return EFI_DEVICE_ERROR
;
1935 // Select device (bit4), set LBA mode(bit6) (use 0xe0 for compatibility)
1939 IdeDev
->IoPort
->Head
,
1940 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0)
1944 // ATA commands for ATA device must be issued when DRDY is set
1946 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
1947 if (EFI_ERROR (Status
)) {
1948 return EFI_DEVICE_ERROR
;
1952 // Pass parameter into device register block
1954 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Head
, Device
);
1957 // Fill the feature register, which is a two-byte FIFO. Need write twice.
1959 Feature8
= (UINT8
) (Feature
>> 8);
1960 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, Feature8
);
1962 Feature8
= (UINT8
) Feature
;
1963 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, Feature8
);
1966 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
1968 SectorCount8
= (UINT8
) (SectorCount
>> 8);
1969 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1971 SectorCount8
= (UINT8
) SectorCount
;
1972 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1975 // Fill the start LBA registers, which are also two-byte FIFO
1977 LbaLow
= (UINT8
) RShiftU64 (LbaAddress
, 24);
1978 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1979 LbaLow
= (UINT8
) LbaAddress
;
1980 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1982 LbaMid
= (UINT8
) RShiftU64 (LbaAddress
, 32);
1983 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1984 LbaMid
= (UINT8
) RShiftU64 (LbaAddress
, 8);
1985 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1987 LbaHigh
= (UINT8
) RShiftU64 (LbaAddress
, 40);
1988 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1989 LbaHigh
= (UINT8
) RShiftU64 (LbaAddress
, 16);
1990 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1993 // Work around for Segate 160G disk writing
1998 // Send command via Command Register
2000 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
2003 // Stall at least 400ns
2011 Send ATA Ext command into device with NON_DATA protocol
2013 @param IdeDev Standard IDE device private data structure
2014 @param AtaCommand The ATA command to be sent
2015 @param Device The value in Device register
2016 @param Feature The value in Feature register
2017 @param SectorCount The value in SectorCount register
2018 @param LbaAddress The LBA address in 48-bit mode
2020 @retval EFI_SUCCESS Reading succeed
2021 @retval EFI_DEVICE_ERROR Error executing commands on this device
2026 IN IDE_BLK_IO_DEV
*IdeDev
,
2027 IN UINT8 AtaCommand
,
2030 IN UINT16 SectorCount
,
2031 IN EFI_LBA LbaAddress
2042 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
2043 if (EFI_ERROR (Status
)) {
2044 return EFI_DEVICE_ERROR
;
2048 // Select device (bit4), set LBA mode(bit6) (use 0xe0 for compatibility)
2052 IdeDev
->IoPort
->Head
,
2053 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0)
2057 // ATA commands for ATA device must be issued when DRDY is set
2059 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
2060 if (EFI_ERROR (Status
)) {
2061 return EFI_DEVICE_ERROR
;
2064 Lba0
= (UINT8
) LbaAddress
;
2065 Lba1
= (UINT8
) RShiftU64 (LbaAddress
, 8);
2066 Lba2
= (UINT8
) RShiftU64 (LbaAddress
, 16);
2067 Lba3
= (UINT8
) RShiftU64 (LbaAddress
, 24);
2068 Device
= (UINT8
) (Device
| Lba3
);
2071 // Pass parameter into device register block
2073 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Head
, Device
);
2076 // Fill the feature register, which is a two-byte FIFO. Need write twice.
2078 Feature8
= (UINT8
) Feature
;
2079 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, Feature8
);
2082 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
2084 SectorCount8
= (UINT8
) SectorCount
;
2085 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
2088 // Fill the start LBA registers, which are also two-byte FIFO
2091 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, Lba0
);
2092 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, Lba1
);
2093 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, Lba2
);
2096 // Send command via Command Register
2098 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
2101 // Stall at least 400ns
2109 This function is called by the AtaBlkIoReadBlocks() to perform
2110 reading from media in block unit. The function has been enhanced to
2111 support >120GB access and transfer at most 65536 blocks per command
2113 @param[in] *IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used
2114 to record all the information of the IDE device.
2116 @param[in] *DataBuffer A pointer to the destination buffer for the data.
2118 @param[in] StartLba The starting logical block address to read from
2119 on the device media.
2121 @param[in] NumberOfBlocks The number of transfer data blocks.
2123 @return The device status of UDMA operation. If the operation is
2124 successful, return EFI_SUCCESS.
2126 TODO: EFI_UNSUPPORTED - add return value to function comment
2127 TODO: EFI_DEVICE_ERROR - add return value to function comment
2128 TODO: EFI_DEVICE_ERROR - add return value to function comment
2129 TODO: EFI_DEVICE_ERROR - add return value to function comment
2133 IN IDE_BLK_IO_DEV
*IdeDev
,
2134 IN VOID
*DataBuffer
,
2135 IN EFI_LBA StartLba
,
2136 IN UINTN NumberOfBlocks
2139 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaReadExtOp
);
2143 This function is called by the AtaBlkIoReadBlocks() to perform
2144 reading from media in block unit. The function has been enhanced to
2145 support >120GB access and transfer at most 65536 blocks per command
2148 pointer pointing to IDE_BLK_IO_DEV data structure, used
2149 to record all the information of the IDE device.
2151 @param[in] *DataBuffer A pointer to the destination buffer for the data.
2152 @param[in] StartLba The starting logical block address to read from
2153 on the device media.
2154 @param[in] NumberOfBlocks The number of transfer data blocks.
2156 @return The device status of UDMA operation. If the operation is
2157 successful, return EFI_SUCCESS.
2159 TODO: EFI_UNSUPPORTED - add return value to function comment
2160 TODO: EFI_DEVICE_ERROR - add return value to function comment
2161 TODO: EFI_DEVICE_ERROR - add return value to function comment
2162 TODO: EFI_DEVICE_ERROR - add return value to function comment
2166 IN IDE_BLK_IO_DEV
*IdeDev
,
2167 IN VOID
*DataBuffer
,
2168 IN EFI_LBA StartLba
,
2169 IN UINTN NumberOfBlocks
2172 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaReadOp
);
2176 This function is called by the AtaBlkIoWriteBlocks() to perform
2177 writing to media in block unit. The function has been enhanced to
2178 support >120GB access and transfer at most 65536 blocks per command
2180 @param[in] *IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used
2181 to record all the information of the IDE device.
2183 @param[in] *DataBuffer A pointer to the source buffer for the data.
2185 @param[in] StartLba The starting logical block address to write to
2186 on the device media.
2188 @param[in] NumberOfBlocks The number of transfer data blocks.
2190 @return The device status of UDMA operation. If the operation is
2191 successful, return EFI_SUCCESS.
2193 TODO: EFI_UNSUPPORTED - add return value to function comment
2194 TODO: EFI_DEVICE_ERROR - add return value to function comment
2195 TODO: EFI_DEVICE_ERROR - add return value to function comment
2199 IN IDE_BLK_IO_DEV
*IdeDev
,
2200 IN VOID
*DataBuffer
,
2201 IN EFI_LBA StartLba
,
2202 IN UINTN NumberOfBlocks
2205 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaWriteExtOp
);
2209 This function is called by the AtaBlkIoWriteBlocks() to perform
2210 writing to media in block unit. The function has been enhanced to
2211 support >120GB access and transfer at most 65536 blocks per command
2214 pointer pointing to IDE_BLK_IO_DEV data structure, used
2215 to record all the information of the IDE device.
2217 @param[in] *DataBuffer
2218 A pointer to the source buffer for the data.
2221 The starting logical block address to write to
2222 on the device media.
2224 @param[in] NumberOfBlocks
2225 The number of transfer data blocks.
2227 @return The device status of UDMA operation. If the operation is
2228 successful, return EFI_SUCCESS.
2230 TODO: EFI_UNSUPPORTED - add return value to function comment
2231 TODO: EFI_DEVICE_ERROR - add return value to function comment
2232 TODO: EFI_DEVICE_ERROR - add return value to function comment
2236 IN IDE_BLK_IO_DEV
*IdeDev
,
2237 IN VOID
*DataBuffer
,
2238 IN EFI_LBA StartLba
,
2239 IN UINTN NumberOfBlocks
2242 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaWriteOp
);
2246 Perform an ATA Udma operation (Read, ReadExt, Write, WriteExt).
2249 pointer pointing to IDE_BLK_IO_DEV data structure, used
2250 to record all the information of the IDE device.
2252 @param[in] *DataBuffer
2253 A pointer to the source buffer for the data.
2256 The starting logical block address to write to
2257 on the device media.
2259 @param[in] NumberOfBlocks
2260 The number of transfer data blocks.
2263 The perform operations could be AtaUdmaReadOp, AtaUdmaReadExOp,
2264 AtaUdmaWriteOp, AtaUdmaWriteExOp
2266 @return The device status of UDMA operation. If the operation is
2267 successful, return EFI_SUCCESS.
2272 IN IDE_BLK_IO_DEV
*IdeDev
,
2273 IN VOID
*DataBuffer
,
2274 IN EFI_LBA StartLba
,
2275 IN UINTN NumberOfBlocks
,
2276 IN ATA_UDMA_OPERATION UdmaOp
2279 IDE_DMA_PRD
*PrdAddr
;
2280 IDE_DMA_PRD
*UsedPrdAddr
;
2281 IDE_DMA_PRD
*TempPrdAddr
;
2282 UINT8 RegisterValue
;
2284 UINT64 IoPortForBmic
;
2285 UINT64 IoPortForBmis
;
2286 UINT64 IoPortForBmid
;
2290 UINTN ByteAvailable
;
2292 UINTN RemainBlockNum
;
2293 UINT8 DeviceControl
;
2298 EFI_PHYSICAL_ADDRESS DeviceAddress
;
2299 UINTN MaxDmaCommandSectors
;
2300 EFI_PCI_IO_PROTOCOL_OPERATION PciIoProtocolOp
;
2305 MaxDmaCommandSectors
= ATAPI_MAX_DMA_CMD_SECTORS
;
2306 PciIoProtocolOp
= EfiPciIoOperationBusMasterWrite
;
2307 AtaCommand
= ATA_CMD_READ_DMA
;
2309 case AtaUdmaReadExtOp
:
2310 MaxDmaCommandSectors
= ATAPI_MAX_DMA_EXT_CMD_SECTORS
;
2311 PciIoProtocolOp
= EfiPciIoOperationBusMasterWrite
;
2312 AtaCommand
= ATA_CMD_READ_DMA_EXT
;
2314 case AtaUdmaWriteOp
:
2315 MaxDmaCommandSectors
= ATAPI_MAX_DMA_CMD_SECTORS
;
2316 PciIoProtocolOp
= EfiPciIoOperationBusMasterRead
;
2317 AtaCommand
= ATA_CMD_WRITE_DMA
;
2319 case AtaUdmaWriteExtOp
:
2320 MaxDmaCommandSectors
= ATAPI_MAX_DMA_EXT_CMD_SECTORS
;
2321 PciIoProtocolOp
= EfiPciIoOperationBusMasterRead
;
2322 AtaCommand
= ATA_CMD_WRITE_DMA_EXT
;
2325 return EFI_UNSUPPORTED
;
2332 Device
= (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0);
2333 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Head
, Device
);
2336 // Enable interrupt to support UDMA
2339 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);
2341 if (IdePrimary
== IdeDev
->Channel
) {
2342 IoPortForBmic
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMICP_OFFSET
;
2343 IoPortForBmis
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMISP_OFFSET
;
2344 IoPortForBmid
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMIDP_OFFSET
;
2346 if (IdeSecondary
== IdeDev
->Channel
) {
2347 IoPortForBmic
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMICS_OFFSET
;
2348 IoPortForBmis
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMISS_OFFSET
;
2349 IoPortForBmid
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMIDS_OFFSET
;
2351 return EFI_UNSUPPORTED
;
2356 // Read BMIS register and clear ERROR and INTR bit
2358 IdeDev
->PciIo
->Io
.Read (
2361 EFI_PCI_IO_PASS_THROUGH_BAR
,
2367 RegisterValue
|= (BMIS_INTERRUPT
| BMIS_ERROR
);
2369 IdeDev
->PciIo
->Io
.Write (
2372 EFI_PCI_IO_PASS_THROUGH_BAR
,
2378 Status
= EFI_SUCCESS
;
2380 RemainBlockNum
= NumberOfBlocks
;
2381 while (RemainBlockNum
> 0) {
2383 if (RemainBlockNum
>= MaxDmaCommandSectors
) {
2385 // SectorCount is used to record the number of sectors to be read
2386 // Max 65536 sectors can be transfered at a time.
2388 NumberOfBlocks
= MaxDmaCommandSectors
;
2389 RemainBlockNum
-= MaxDmaCommandSectors
;
2391 NumberOfBlocks
= (UINT16
) RemainBlockNum
;
2396 // Calculate the number of PRD table to make sure the memory region
2397 // not cross 64K boundary
2399 ByteCount
= NumberOfBlocks
* IdeDev
->BlkIo
.Media
->BlockSize
;
2400 PrdTableNum
= ((ByteCount
>> 16) + 1) + 1;
2405 PageCount
= EFI_SIZE_TO_PAGES (2 * PrdTableNum
* sizeof (IDE_DMA_PRD
));
2406 Status
= IdeDev
->PciIo
->AllocateBuffer (
2409 EfiBootServicesData
,
2414 if (EFI_ERROR (Status
)) {
2415 return EFI_OUT_OF_RESOURCES
;
2417 ZeroMem ((VOID
*) ((UINTN
) MemPage
), EFI_PAGES_TO_SIZE (PageCount
));
2419 PrdAddr
= (IDE_DMA_PRD
*) ((UINTN
) MemPage
);
2421 // To make sure PRD is allocated in one 64K page
2423 if (((UINTN
) PrdAddr
& 0x0FFFF) > (((UINTN
) PrdAddr
+ PrdTableNum
* sizeof (IDE_DMA_PRD
) - 1) & 0x0FFFF)) {
2424 UsedPrdAddr
= (IDE_DMA_PRD
*) ((UINTN
) ((UINT8
*) PrdAddr
+ 0x10000) & 0xFFFF0000);
2426 if ((UINTN
) PrdAddr
& 0x03) {
2427 UsedPrdAddr
= (IDE_DMA_PRD
*) ((UINTN
) ((UINT8
*) PrdAddr
+ 0x04) & 0xFFFFFFFC);
2429 UsedPrdAddr
= PrdAddr
;
2434 // Build the PRD table
2436 Status
= IdeDev
->PciIo
->Map (
2444 if (EFI_ERROR (Status
)) {
2445 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2446 return EFI_OUT_OF_RESOURCES
;
2448 PrdBuffer
= (VOID
*) ((UINTN
) DeviceAddress
);
2449 TempPrdAddr
= UsedPrdAddr
;
2452 ByteAvailable
= 0x10000 - ((UINTN
) PrdBuffer
& 0xFFFF);
2454 if (ByteCount
<= ByteAvailable
) {
2455 TempPrdAddr
->RegionBaseAddr
= (UINT32
) ((UINTN
) PrdBuffer
);
2456 TempPrdAddr
->ByteCount
= (UINT16
) ByteCount
;
2457 TempPrdAddr
->EndOfTable
= 0x8000;
2461 TempPrdAddr
->RegionBaseAddr
= (UINT32
) ((UINTN
) PrdBuffer
);
2462 TempPrdAddr
->ByteCount
= (UINT16
) ByteAvailable
;
2464 ByteCount
-= ByteAvailable
;
2465 PrdBuffer
+= ByteAvailable
;
2470 // Set the base address to BMID register
2472 IdeDev
->PciIo
->Io
.Write (
2474 EfiPciIoWidthUint32
,
2475 EFI_PCI_IO_PASS_THROUGH_BAR
,
2482 // Set BMIC register to identify the operation direction
2484 IdeDev
->PciIo
->Io
.Read (
2487 EFI_PCI_IO_PASS_THROUGH_BAR
,
2493 if (UdmaOp
== AtaUdmaReadExtOp
|| UdmaOp
== AtaUdmaReadOp
) {
2494 RegisterValue
|= BMIC_nREAD
;
2496 RegisterValue
&= ~((UINT8
) BMIC_nREAD
);
2499 IdeDev
->PciIo
->Io
.Write (
2502 EFI_PCI_IO_PASS_THROUGH_BAR
,
2508 if (UdmaOp
== AtaUdmaWriteExtOp
|| UdmaOp
== AtaUdmaReadExtOp
) {
2509 Status
= AtaCommandIssueExt (
2514 (UINT16
) NumberOfBlocks
,
2518 Status
= AtaCommandIssue (
2523 (UINT16
) NumberOfBlocks
,
2528 if (EFI_ERROR (Status
)) {
2529 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2530 IdeDev
->PciIo
->Unmap (IdeDev
->PciIo
, Map
);
2531 return EFI_DEVICE_ERROR
;
2535 // Set START bit of BMIC register
2537 IdeDev
->PciIo
->Io
.Read (
2540 EFI_PCI_IO_PASS_THROUGH_BAR
,
2546 RegisterValue
|= BMIC_START
;
2548 IdeDev
->PciIo
->Io
.Write (
2551 EFI_PCI_IO_PASS_THROUGH_BAR
,
2558 // Check the INTERRUPT and ERROR bit of BMIS
2559 // Max transfer number of sectors for one command is 65536(32Mbyte),
2560 // it will cost 1 second to transfer these data in UDMA mode 2(33.3MBps).
2561 // So set the variable Count to 2000, for about 2 second timeout time.
2563 Status
= EFI_SUCCESS
;
2567 IdeDev
->PciIo
->Io
.Read (
2570 EFI_PCI_IO_PASS_THROUGH_BAR
,
2575 if ((RegisterValue
& (BMIS_INTERRUPT
| BMIS_ERROR
)) || (Count
== 0)) {
2576 if ((RegisterValue
& BMIS_ERROR
) || (Count
== 0)) {
2577 Status
= EFI_DEVICE_ERROR
;
2587 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2588 IdeDev
->PciIo
->Unmap (IdeDev
->PciIo
, Map
);
2590 // Read BMIS register and clear ERROR and INTR bit
2592 IdeDev
->PciIo
->Io
.Read (
2595 EFI_PCI_IO_PASS_THROUGH_BAR
,
2601 RegisterValue
|= (BMIS_INTERRUPT
| BMIS_ERROR
);
2603 IdeDev
->PciIo
->Io
.Write (
2606 EFI_PCI_IO_PASS_THROUGH_BAR
,
2612 // Read Status Register of IDE device to clear interrupt
2614 RegisterValue
= IDEReadPortB(IdeDev
->PciIo
,IdeDev
->IoPort
->Reg
.Status
);
2616 // Clear START bit of BMIC register
2618 IdeDev
->PciIo
->Io
.Read (
2621 EFI_PCI_IO_PASS_THROUGH_BAR
,
2627 RegisterValue
&= ~((UINT8
) BMIC_START
);
2629 IdeDev
->PciIo
->Io
.Write (
2632 EFI_PCI_IO_PASS_THROUGH_BAR
,
2638 if (RegisterValue
& BMIS_ERROR
) {
2639 return EFI_DEVICE_ERROR
;
2642 if (EFI_ERROR (Status
)) {
2645 DataBuffer
= (UINT8
*) DataBuffer
+ NumberOfBlocks
* IdeDev
->BlkIo
.Media
->BlockSize
;
2646 StartLba
+= NumberOfBlocks
;
2650 // Disable interrupt of Select device
2652 IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
);
2653 DeviceControl
|= ATA_CTLREG_IEN_L
;
2654 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);