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
;
61 // AtaIdentifyPointer is used for accommodating returned IDENTIFY data of
62 // the ATA Identify command
64 AtaIdentifyPointer
= (EFI_IDENTIFY_DATA
*) AllocateZeroPool (sizeof (EFI_IDENTIFY_DATA
));
67 // use ATA PIO Data In protocol to send ATA Identify command
68 // and receive data from device
70 DeviceSelect
= (UINT8
) ((IdeDev
->Device
) << 4);
71 Status
= AtaPioDataIn (
73 (VOID
*) AtaIdentifyPointer
,
74 sizeof (EFI_IDENTIFY_DATA
),
75 ATA_CMD_IDENTIFY_DRIVE
,
83 // If ATA Identify command succeeds, then according to the received
85 // identify the device type ( ATA or not ).
86 // If ATA device, fill the information in IdeDev.
87 // If not ATA device, return IDE_DEVICE_ERROR
89 if (!EFI_ERROR (Status
)) {
91 IdeDev
->pIdData
= AtaIdentifyPointer
;
94 // Print ATA Module Name
96 PrintAtaModuleName (IdeDev
);
99 // bit 15 of pAtaIdentify->config is used to identify whether device is
100 // ATA device or ATAPI device.
101 // if 0, means ATA device; if 1, means ATAPI device.
103 if ((AtaIdentifyPointer
->AtaData
.config
& 0x8000) == 0x00) {
105 // Detect if support S.M.A.R.T. If yes, enable it as default
107 AtaSMARTSupport (IdeDev
);
110 // Check whether this device needs 48-bit addressing (ATAPI-6 ata device)
112 Status
= AtaAtapi6Identify (IdeDev
);
113 if (!EFI_ERROR (Status
)) {
115 // It's a disk with >120GB capacity, initialized in AtaAtapi6Identify()
120 // This is a hard disk <= 120GB capacity, treat it as normal hard disk
122 IdeDev
->Type
= IdeHardDisk
;
125 // Block Media Information:
126 // Media->LogicalPartition , Media->WriteCaching will be filled
127 // in the DiscoverIdeDevcie() function.
129 IdeDev
->BlkIo
.Media
->IoAlign
= 4;
130 IdeDev
->BlkIo
.Media
->MediaId
= 1;
131 IdeDev
->BlkIo
.Media
->RemovableMedia
= FALSE
;
132 IdeDev
->BlkIo
.Media
->MediaPresent
= TRUE
;
133 IdeDev
->BlkIo
.Media
->ReadOnly
= FALSE
;
134 IdeDev
->BlkIo
.Media
->BlockSize
= 0x200;
137 // Calculate device capacity
139 Capacity
= ((UINT32
)AtaIdentifyPointer
->AtaData
.user_addressable_sectors_hi
<< 16) |
140 AtaIdentifyPointer
->AtaData
.user_addressable_sectors_lo
;
141 IdeDev
->BlkIo
.Media
->LastBlock
= Capacity
- 1;
148 gBS
->FreePool (AtaIdentifyPointer
);
150 // Make sure the pIdData will not be freed again.
152 IdeDev
->pIdData
= NULL
;
154 return EFI_DEVICE_ERROR
;
159 This function is called by ATAIdentify() to identity whether this disk
160 supports ATA/ATAPI6 48bit addressing, ie support >120G capacity
163 pointer pointing to IDE_BLK_IO_DEV data structure, used
164 to record all the information of the IDE device.
166 @retval EFI_SUCCESS The disk specified by IdeDev is a Atapi6 supported one
167 and 48-bit addressing must be used
169 @retval EFI_UNSUPPORTED The disk dosn't not support Atapi6 or it supports but
170 the capacity is below 120G, 48bit addressing is not
174 This function must be called after DEVICE_IDENTITY command has been
175 successfully returned
180 IN IDE_BLK_IO_DEV
*IdeDev
186 EFI_IDENTIFY_DATA
*Atapi6IdentifyStruct
;
188 if (IdeDev
->pIdData
== NULL
) {
189 return EFI_UNSUPPORTED
;
192 Atapi6IdentifyStruct
= IdeDev
->pIdData
;
194 if ((Atapi6IdentifyStruct
->AtapiData
.cmd_set_support_83
& BIT10
) == 0) {
196 // The device dosn't support 48 bit addressing
198 return EFI_UNSUPPORTED
;
202 // 48 bit address feature set is supported, get maximum capacity
204 Capacity
= Atapi6IdentifyStruct
->AtapiData
.max_user_lba_for_48bit_addr
[0];
205 for (Index
= 1; Index
< 4; Index
++) {
207 // Lower byte goes first: word[100] is the lowest word, word[103] is highest
209 TmpLba
= Atapi6IdentifyStruct
->AtapiData
.max_user_lba_for_48bit_addr
[Index
];
210 Capacity
|= LShiftU64 (TmpLba
, 16 * Index
);
213 if (Capacity
> MAX_28BIT_ADDRESSING_CAPACITY
) {
215 // Capacity exceeds 120GB. 48-bit addressing is really needed
217 IdeDev
->Type
= Ide48bitAddressingHardDisk
;
220 // Fill block media information:Media->LogicalPartition ,
221 // Media->WriteCaching will be filledin the DiscoverIdeDevcie() function.
223 IdeDev
->BlkIo
.Media
->IoAlign
= 4;
224 IdeDev
->BlkIo
.Media
->MediaId
= 1;
225 IdeDev
->BlkIo
.Media
->RemovableMedia
= FALSE
;
226 IdeDev
->BlkIo
.Media
->MediaPresent
= TRUE
;
227 IdeDev
->BlkIo
.Media
->ReadOnly
= FALSE
;
228 IdeDev
->BlkIo
.Media
->BlockSize
= 0x200;
229 IdeDev
->BlkIo
.Media
->LastBlock
= Capacity
- 1;
234 return EFI_UNSUPPORTED
;
238 This function is called by ATAIdentify() or ATAPIIdentify()
239 to print device's module name.
242 pointer pointing to IDE_BLK_IO_DEV data structure, used
243 to record all the information of the IDE device.
248 IN IDE_BLK_IO_DEV
*IdeDev
251 if (IdeDev
->pIdData
== NULL
) {
255 SwapStringChars (IdeDev
->ModelName
, IdeDev
->pIdData
->AtaData
.ModelName
, 40);
256 IdeDev
->ModelName
[40] = 0x00;
260 This function is used to send out ATA commands conforms to the
261 PIO Data In Protocol.
264 pointer pointing to IDE_BLK_IO_DEV data structure, used
265 to record all the information of the IDE device.
268 buffer contained data transferred from device to host.
271 data size in byte unit of the buffer.
273 @param[in] AtaCommand
274 value of the Command Register
277 value of the Head/Device Register
279 @param[in] SectorCount
280 value of the Sector Count Register
282 @param[in] SectorNumber
283 value of the Sector Number Register
285 @param[in] CylinderLsb
286 value of the low byte of the Cylinder Register
288 @param[in] CylinderMsb
289 value of the high byte of the Cylinder Register
291 @retval EFI_SUCCESS send out the ATA command and device send required
294 @retval EFI_DEVICE_ERROR command sent failed.
299 IN IDE_BLK_IO_DEV
*IdeDev
,
304 IN UINT8 SectorCount
,
305 IN UINT8 SectorNumber
,
306 IN UINT8 CylinderLsb
,
315 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
316 if (EFI_ERROR (Status
)) {
317 return EFI_DEVICE_ERROR
;
321 // e0:1110,0000-- bit7 and bit5 are reserved bits.
322 // bit6 set means LBA mode
326 IdeDev
->IoPort
->Head
,
327 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0 | Head
)
331 // All ATAPI device's ATA commands can be issued regardless of the
334 if (IdeDev
->Type
== IdeHardDisk
) {
336 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
337 if (EFI_ERROR (Status
)) {
338 return EFI_DEVICE_ERROR
;
342 // set all the command parameters
343 // Before write to all the following registers, BSY and DRQ must be 0.
345 Status
= DRQClear2 (IdeDev
, ATATIMEOUT
);
346 if (EFI_ERROR (Status
)) {
347 return EFI_DEVICE_ERROR
;
350 if (AtaCommand
== ATA_CMD_SET_FEATURES
) {
351 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, 0x03);
354 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount
);
355 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, SectorNumber
);
356 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, CylinderLsb
);
357 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, CylinderMsb
);
360 // send command via Command Register
362 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
364 Buffer16
= (UINT16
*) Buffer
;
367 // According to PIO data in protocol, host can perform a series of reads to
368 // the data register after each time device set DRQ ready;
369 // The data size of "a series of read" is command specific.
370 // For most ATA command, data size received from device will not exceed
371 // 1 sector, hence the data size for "a series of read" can be the whole data
372 // size of one command request.
373 // For ATA command such as Read Sector command, the data size of one ATA
374 // command request is often larger than 1 sector, according to the
375 // Read Sector command, the data size of "a series of read" is exactly 1
377 // Here for simplification reason, we specify the data size for
378 // "a series of read" to 1 sector (256 words) if data size of one ATA command
379 // request is larger than 256 words.
384 // used to record bytes of currently transfered data
388 while (WordCount
< ByteCount
/ 2) {
390 // Poll DRQ bit set, data transfer can be performed only when DRQ is ready.
392 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
393 if (EFI_ERROR (Status
)) {
394 return EFI_DEVICE_ERROR
;
397 Status
= CheckErrorStatus (IdeDev
);
398 if (EFI_ERROR (Status
)) {
399 return EFI_DEVICE_ERROR
;
403 // Get the byte count for one series of read
405 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
406 Increment
= ByteCount
/ 2 - WordCount
;
409 IDEReadPortWMultiple (
411 IdeDev
->IoPort
->Data
,
416 WordCount
+= Increment
;
417 Buffer16
+= Increment
;
421 DRQClear (IdeDev
, ATATIMEOUT
);
423 return CheckErrorStatus (IdeDev
);
427 This function is used to send out ATA commands conforms to the
428 PIO Data Out Protocol.
431 pointer pointing to IDE_BLK_IO_DEV data structure, used
432 to record all the information of the IDE device.
434 @param *Buffer buffer contained data transferred from host to device.
435 @param ByteCount data size in byte unit of the buffer.
436 @param AtaCommand value of the Command Register
437 @param Head value of the Head/Device Register
438 @param SectorCount value of the Sector Count Register
439 @param SectorNumber value of the Sector Number Register
440 @param CylinderLsb value of the low byte of the Cylinder Register
441 @param CylinderMsb value of the high byte of the Cylinder Register
443 @retval EFI_SUCCESS send out the ATA command and device received required
446 @retval EFI_DEVICE_ERROR command sent failed.
451 IN IDE_BLK_IO_DEV
*IdeDev
,
456 IN UINT8 SectorCount
,
457 IN UINT8 SectorNumber
,
458 IN UINT8 CylinderLsb
,
467 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
468 if (EFI_ERROR (Status
)) {
469 return EFI_DEVICE_ERROR
;
473 // select device via Head/Device register.
474 // Before write Head/Device register, BSY and DRQ must be 0.
476 Status
= DRQClear2 (IdeDev
, ATATIMEOUT
);
477 if (EFI_ERROR (Status
)) {
478 return EFI_DEVICE_ERROR
;
482 // e0:1110,0000-- bit7 and bit5 are reserved bits.
483 // bit6 set means LBA mode
487 IdeDev
->IoPort
->Head
,
488 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0 | Head
)
491 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
492 if (EFI_ERROR (Status
)) {
493 return EFI_DEVICE_ERROR
;
497 // set all the command parameters
498 // Before write to all the following registers, BSY and DRQ must be 0.
500 Status
= DRQClear2 (IdeDev
, ATATIMEOUT
);
501 if (EFI_ERROR (Status
)) {
502 return EFI_DEVICE_ERROR
;
505 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount
);
506 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, SectorNumber
);
507 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, CylinderLsb
);
508 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, CylinderMsb
);
511 // send command via Command Register
513 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
515 Buffer16
= (UINT16
*) Buffer
;
518 // According to PIO data out protocol, host can perform a series of
519 // writes to the data register after each time device set DRQ ready;
520 // The data size of "a series of read" is command specific.
521 // For most ATA command, data size written to device will not exceed 1 sector,
522 // hence the data size for "a series of write" can be the data size of one
524 // For ATA command such as Write Sector command, the data size of one
525 // ATA command request is often larger than 1 sector, according to the
526 // Write Sector command, the data size of "a series of read" is exactly
528 // Here for simplification reason, we specify the data size for
529 // "a series of write" to 1 sector (256 words) if data size of one ATA command
530 // request is larger than 256 words.
535 while (WordCount
< ByteCount
/ 2) {
538 // DRQReady2-- read Alternate Status Register to determine the DRQ bit
539 // data transfer can be performed only when DRQ is ready.
541 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
542 if (EFI_ERROR (Status
)) {
543 return EFI_DEVICE_ERROR
;
546 Status
= CheckErrorStatus (IdeDev
);
547 if (EFI_ERROR (Status
)) {
548 return EFI_DEVICE_ERROR
;
552 // Check the remaining byte count is less than 512 bytes
554 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
555 Increment
= ByteCount
/ 2 - WordCount
;
558 // perform a series of write without check DRQ ready
561 IDEWritePortWMultiple (
563 IdeDev
->IoPort
->Data
,
567 WordCount
+= Increment
;
568 Buffer16
+= Increment
;
572 DRQClear (IdeDev
, ATATIMEOUT
);
574 return CheckErrorStatus (IdeDev
);
578 This function is used to analyze the Status Register and print out
579 some debug information and if there is ERR bit set in the Status
580 Register, the Error Register's value is also be parsed and print out.
583 pointer pointing to IDE_BLK_IO_DEV data structure, used
584 to record all the information of the IDE device.
586 @retval EFI_SUCCESS No err information in the Status Register.
587 @retval EFI_DEVICE_ERROR Any err information in the Status Register.
592 IN IDE_BLK_IO_DEV
*IdeDev
595 UINT8 StatusRegister
;
598 StatusRegister
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Status
);
602 if (StatusRegister
& ATA_STSREG_DWF
) {
605 "CheckErrorStatus()-- %02x : Error : Write Fault\n",
610 if (StatusRegister
& ATA_STSREG_CORR
) {
613 "CheckErrorStatus()-- %02x : Error : Corrected Data\n",
618 if (StatusRegister
& ATA_STSREG_ERR
) {
619 ErrorRegister
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Error
);
621 if (ErrorRegister
& ATA_ERRREG_BBK
) {
624 "CheckErrorStatus()-- %02x : Error : Bad Block Detected\n",
629 if (ErrorRegister
& ATA_ERRREG_UNC
) {
632 "CheckErrorStatus()-- %02x : Error : Uncorrectable Data\n",
637 if (ErrorRegister
& ATA_ERRREG_MC
) {
640 "CheckErrorStatus()-- %02x : Error : Media Change\n",
645 if (ErrorRegister
& ATA_ERRREG_ABRT
) {
648 "CheckErrorStatus()-- %02x : Error : Abort\n",
653 if (ErrorRegister
& ATA_ERRREG_TK0NF
) {
656 "CheckErrorStatus()-- %02x : Error : Track 0 Not Found\n",
661 if (ErrorRegister
& ATA_ERRREG_AMNF
) {
664 "CheckErrorStatus()-- %02x : Error : Address Mark Not Found\n",
672 if ((StatusRegister
& (ATA_STSREG_ERR
| ATA_STSREG_DWF
| ATA_STSREG_CORR
)) == 0) {
676 return EFI_DEVICE_ERROR
;
681 This function is called by the AtaBlkIoReadBlocks() to perform
682 reading from media in block unit.
685 pointer pointing to IDE_BLK_IO_DEV data structure, used
686 to record all the information of the IDE device.
688 @param[in] *DataBuffer
689 A pointer to the destination buffer for the data.
692 The starting logical block address to read from
695 @param[in] NumberOfBlocks
696 The number of transfer data blocks.
698 @return return status is fully dependent on the return status
699 of AtaPioDataIn() function.
704 IN IDE_BLK_IO_DEV
*IdeDev
,
707 IN UINTN NumberOfBlocks
711 UINTN BlocksRemaining
;
726 // Using ATA Read Sector(s) command (opcode=0x20) with PIO DATA IN protocol
728 AtaCommand
= ATA_CMD_READ_SECTORS
;
731 BlocksRemaining
= NumberOfBlocks
;
733 Lba32
= (UINT32
) Lba
;
735 Status
= EFI_SUCCESS
;
737 while (BlocksRemaining
> 0) {
740 // in ATA-3 spec, LBA is in 28 bit width
742 Lba0
= (UINT8
) Lba32
;
743 Lba1
= (UINT8
) (Lba32
>> 8);
744 Lba2
= (UINT8
) (Lba32
>> 16);
746 // low 4 bit of Lba3 stands for LBA bit24~bit27.
748 Lba3
= (UINT8
) ((Lba32
>> 24) & 0x0f);
750 if (BlocksRemaining
>= 0x100) {
753 // SectorCount8 is sent to Sector Count register, 0x00 means 256
754 // sectors to be read
758 // SectorCount is used to record the number of sectors to be read
763 SectorCount8
= (UINT8
) BlocksRemaining
;
764 SectorCount
= (UINT16
) BlocksRemaining
;
768 // ByteCount is the number of bytes that will be read
770 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
773 // call AtaPioDataIn() to send Read Sector Command and receive data read
775 Status
= AtaPioDataIn (
786 if (EFI_ERROR (Status
)) {
790 Lba32
+= SectorCount
;
791 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
792 BlocksRemaining
-= SectorCount
;
799 This function is called by the AtaBlkIoWriteBlocks() to perform
800 writing onto media in block unit.
803 pointer pointing to IDE_BLK_IO_DEV data structure,used
804 to record all the information of the IDE device.
806 @param[in] *BufferData
807 A pointer to the source buffer for the data.
810 The starting logical block address to write onto
813 @param[in] NumberOfBlocks
814 The number of transfer data blocks.
816 @return return status is fully dependent on the return status
817 of AtaPioDataOut() function.
822 IN IDE_BLK_IO_DEV
*IdeDev
,
825 IN UINTN NumberOfBlocks
829 UINTN BlocksRemaining
;
844 // Using Write Sector(s) command (opcode=0x30) with PIO DATA OUT protocol
846 AtaCommand
= ATA_CMD_WRITE_SECTORS
;
848 BlocksRemaining
= NumberOfBlocks
;
850 Lba32
= (UINT32
) Lba
;
852 Status
= EFI_SUCCESS
;
854 while (BlocksRemaining
> 0) {
856 Lba0
= (UINT8
) Lba32
;
857 Lba1
= (UINT8
) (Lba32
>> 8);
858 Lba2
= (UINT8
) (Lba32
>> 16);
859 Lba3
= (UINT8
) ((Lba32
>> 24) & 0x0f);
861 if (BlocksRemaining
>= 0x100) {
864 // SectorCount8 is sent to Sector Count register, 0x00 means 256 sectors
869 // SectorCount is used to record the number of sectors to be written
874 SectorCount8
= (UINT8
) BlocksRemaining
;
875 SectorCount
= (UINT16
) BlocksRemaining
;
878 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
880 Status
= AtaPioDataOut (
891 if (EFI_ERROR (Status
)) {
895 Lba32
+= SectorCount
;
896 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
897 BlocksRemaining
-= SectorCount
;
904 This function is used to implement the Soft Reset on the specified
905 device. But, the ATA Soft Reset mechanism is so strong a reset method
906 that it will force resetting on both devices connected to the
909 It is called by IdeBlkIoReset(), a interface function of Block
912 This function can also be used by the ATAPI device to perform reset when
913 ATAPI Reset command is failed.
916 pointer pointing to IDE_BLK_IO_DEV data structure, used
917 to record all the information of the IDE device.
919 @retval EFI_SUCCESS Soft reset completes successfully.
920 @retval EFI_DEVICE_ERROR Any step during the reset process is failed.
923 The registers initial values after ATA soft reset are different
924 to the ATA device and ATAPI device.
929 IN IDE_BLK_IO_DEV
*IdeDev
937 // set SRST bit to initiate soft reset
939 DeviceControl
|= ATA_CTLREG_SRST
;
944 DeviceControl
|= BIT1
;
946 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);
949 // SRST should assert for at least 5 us, we use 10 us for
950 // better compatibility
955 // Enable interrupt to support UDMA, and clear SRST bit
958 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);
961 // Wait for at least 2 ms to check BSY status, we use 10 ms
962 // for better compatibility
966 // slave device needs at most 31s to clear BSY
968 if (WaitForBSYClear (IdeDev
, 31000) == EFI_TIMEOUT
) {
969 return EFI_DEVICE_ERROR
;
976 This function is the ATA implementation for ReadBlocks in the
977 Block I/O Protocol interface.
979 @param[in] *IdeBlkIoDevice
980 Indicates the calling context.
983 The media id that the read request is for.
986 The starting logical block address to read from
989 @param[in] BufferSize
990 The size of the Buffer in bytes. This must be a
991 multiple of the intrinsic block size of the device.
994 A pointer to the destination buffer for the data.
995 The caller is responsible for either having implicit
996 or explicit ownership of the memory that data is read into.
998 @retval EFI_SUCCESS Read Blocks successfully.
999 @retval EFI_DEVICE_ERROR Read Blocks failed.
1000 @retval EFI_NO_MEDIA There is no media in the device.
1001 @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.
1003 @retval EFI_BAD_BUFFER_SIZE
1004 The BufferSize parameter is not a multiple of the
1005 intrinsic block size of the device.
1007 @retval EFI_INVALID_PARAMETER
1008 The read request contains LBAs that are not valid,
1009 or the data buffer is not valid.
1012 If Read Block error because of device error, this function will call
1013 AtaSoftReset() function to reset device.
1017 AtaBlkIoReadBlocks (
1018 IN IDE_BLK_IO_DEV
*IdeBlkIoDevice
,
1021 IN UINTN BufferSize
,
1025 EFI_BLOCK_IO_MEDIA
*Media
;
1027 UINTN NumberOfBlocks
;
1030 if (Buffer
== NULL
) {
1031 return EFI_INVALID_PARAMETER
;
1034 if (BufferSize
== 0) {
1038 Status
= EFI_SUCCESS
;
1041 // Get the intrinsic block size
1043 Media
= IdeBlkIoDevice
->BlkIo
.Media
;
1044 BlockSize
= Media
->BlockSize
;
1046 NumberOfBlocks
= BufferSize
/ BlockSize
;
1048 if (MediaId
!= Media
->MediaId
) {
1049 return EFI_MEDIA_CHANGED
;
1052 if (BufferSize
% BlockSize
!= 0) {
1053 return EFI_BAD_BUFFER_SIZE
;
1056 if (!(Media
->MediaPresent
)) {
1057 return EFI_NO_MEDIA
;
1060 if (LBA
> Media
->LastBlock
) {
1061 return EFI_INVALID_PARAMETER
;
1064 if ((LBA
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1065 return EFI_INVALID_PARAMETER
;
1068 if ((Media
->IoAlign
> 1) && (((UINTN
) Buffer
& (Media
->IoAlign
- 1)) != 0)) {
1069 return EFI_INVALID_PARAMETER
;
1072 Status
= EFI_SUCCESS
;
1073 if (IdeBlkIoDevice
->Type
== Ide48bitAddressingHardDisk
) {
1075 // For ATA/ATAPI-6 device(capcity > 120GB), use ATA-6 read block mechanism
1077 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1078 Status
= AtaUdmaReadExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1080 Status
= AtaReadSectorsExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1084 // For ATA-3 compatible device, use ATA-3 read block mechanism
1086 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1087 Status
= AtaUdmaRead (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1089 Status
= AtaReadSectors (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1093 if (EFI_ERROR (Status
)) {
1094 AtaSoftReset (IdeBlkIoDevice
);
1095 return EFI_DEVICE_ERROR
;
1103 This function is the ATA implementation for WriteBlocks in the
1104 Block I/O Protocol interface.
1106 @param[in] *IdeBlkIoDevice
1107 Indicates the calling context.
1110 The media id that the write request is for.
1113 The starting logical block address to write onto
1116 @param[in] BufferSize
1117 The size of the Buffer in bytes. This must be a
1118 multiple of the intrinsic block size of the device.
1121 A pointer to the source buffer for the data.
1122 The caller is responsible for either having implicit
1123 or explicit ownership of the memory that data is
1126 @retval EFI_SUCCESS Write Blocks successfully.
1127 @retval EFI_DEVICE_ERROR Write Blocks failed.
1128 @retval EFI_NO_MEDIA There is no media in the device.
1129 @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.
1131 @retval EFI_BAD_BUFFER_SIZE
1132 The BufferSize parameter is not a multiple of the
1133 intrinsic block size of the device.
1135 @retval EFI_INVALID_PARAMETER
1136 The write request contains LBAs that are not valid,
1137 or the data buffer is not valid.
1140 If Write Block error because of device error, this function will call
1141 AtaSoftReset() function to reset device.
1145 AtaBlkIoWriteBlocks (
1146 IN IDE_BLK_IO_DEV
*IdeBlkIoDevice
,
1149 IN UINTN BufferSize
,
1154 EFI_BLOCK_IO_MEDIA
*Media
;
1156 UINTN NumberOfBlocks
;
1159 if (Buffer
== NULL
) {
1160 return EFI_INVALID_PARAMETER
;
1163 if (BufferSize
== 0) {
1167 Status
= EFI_SUCCESS
;
1170 // Get the intrinsic block size
1172 Media
= IdeBlkIoDevice
->BlkIo
.Media
;
1173 BlockSize
= Media
->BlockSize
;
1174 NumberOfBlocks
= BufferSize
/ BlockSize
;
1176 if (MediaId
!= Media
->MediaId
) {
1177 return EFI_MEDIA_CHANGED
;
1180 if (BufferSize
% BlockSize
!= 0) {
1181 return EFI_BAD_BUFFER_SIZE
;
1184 if (LBA
> Media
->LastBlock
) {
1185 return EFI_INVALID_PARAMETER
;
1188 if ((LBA
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1189 return EFI_INVALID_PARAMETER
;
1192 if ((Media
->IoAlign
> 1) && (((UINTN
) Buffer
& (Media
->IoAlign
- 1)) != 0)) {
1193 return EFI_INVALID_PARAMETER
;
1196 Status
= EFI_SUCCESS
;
1197 if (IdeBlkIoDevice
->Type
== Ide48bitAddressingHardDisk
) {
1199 // For ATA/ATAPI-6 device(capcity > 120GB), use ATA-6 write block mechanism
1201 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1202 Status
= AtaUdmaWriteExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1204 Status
= AtaWriteSectorsExt (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1208 // For ATA-3 compatible device, use ATA-3 write block mechanism
1210 if (IdeBlkIoDevice
->UdmaMode
.Valid
) {
1211 Status
= AtaUdmaWrite (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1213 Status
= AtaWriteSectors (IdeBlkIoDevice
, Buffer
, LBA
, NumberOfBlocks
);
1217 if (EFI_ERROR (Status
)) {
1218 AtaSoftReset (IdeBlkIoDevice
);
1219 return EFI_DEVICE_ERROR
;
1226 This function is called by the AtaBlkIoReadBlocks() to perform
1227 reading from media in block unit. The function has been enhanced to
1228 support >120GB access and transfer at most 65536 blocks per command
1231 pointer pointing to IDE_BLK_IO_DEV data structure, used
1232 to record all the information of the IDE device.
1234 @param[in] *DataBuffer A pointer to the destination buffer for the data.
1235 @param[in] StartLba The starting logical block address to read from
1236 on the device media.
1237 @param[in] NumberOfBlocks The number of transfer data blocks.
1239 @return return status is fully dependent on the return status
1240 of AtaPioDataInExt() function.
1245 IN IDE_BLK_IO_DEV
*IdeDev
,
1246 IN VOID
*DataBuffer
,
1247 IN EFI_LBA StartLba
,
1248 IN UINTN NumberOfBlocks
1252 UINTN BlocksRemaining
;
1260 // Using ATA "Read Sectors Ext" command(opcode=0x24) with PIO DATA IN protocol
1262 AtaCommand
= ATA_CMD_READ_SECTORS_EXT
;
1263 Buffer
= DataBuffer
;
1264 BlocksRemaining
= NumberOfBlocks
;
1266 Status
= EFI_SUCCESS
;
1268 while (BlocksRemaining
> 0) {
1270 if (BlocksRemaining
>= 0x10000) {
1272 // SectorCount is used to record the number of sectors to be read
1273 // Max 65536 sectors can be transfered at a time.
1275 SectorCount
= 0xffff;
1277 SectorCount
= (UINT16
) BlocksRemaining
;
1281 // ByteCount is the number of bytes that will be read
1283 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
1286 // call AtaPioDataInExt() to send Read Sector Command and receive data read
1288 Status
= AtaPioDataInExt (
1296 if (EFI_ERROR (Status
)) {
1300 Lba64
+= SectorCount
;
1301 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
1302 BlocksRemaining
-= SectorCount
;
1309 This function is called by the AtaBlkIoWriteBlocks() to perform
1310 writing onto media in block unit. The function has been enhanced to
1311 support >120GB access and transfer at most 65536 blocks per command
1314 pointer pointing to IDE_BLK_IO_DEV data structure,used
1315 to record all the information of the IDE device.
1317 @param[in] *DataBuffer
1318 A pointer to the source buffer for the data.
1321 The starting logical block address to write onto
1324 @param[in] NumberOfBlocks
1325 The number of transfer data blocks.
1327 @return status is fully dependent on the return status
1328 of AtaPioDataOutExt() function.
1332 AtaWriteSectorsExt (
1333 IN IDE_BLK_IO_DEV
*IdeDev
,
1334 IN VOID
*DataBuffer
,
1335 IN EFI_LBA StartLba
,
1336 IN UINTN NumberOfBlocks
1341 UINTN BlocksRemaining
;
1348 // Using ATA "Write Sectors Ext" cmd(opcode=0x24) with PIO DATA OUT protocol
1350 AtaCommand
= ATA_CMD_WRITE_SECTORS_EXT
;
1352 Buffer
= DataBuffer
;
1353 BlocksRemaining
= NumberOfBlocks
;
1355 Status
= EFI_SUCCESS
;
1357 while (BlocksRemaining
> 0) {
1359 if (BlocksRemaining
>= 0x10000) {
1361 // SectorCount is used to record the number of sectors to be written.
1362 // Max 65536 sectors can be transfered at a time.
1364 SectorCount
= 0xffff;
1366 SectorCount
= (UINT16
) BlocksRemaining
;
1370 // ByteCount is the number of bytes that will be written
1372 ByteCount
= SectorCount
* (IdeDev
->BlkIo
.Media
->BlockSize
);
1375 // Call AtaPioDataOutExt() to send "Write Sectors Ext" Command
1377 Status
= AtaPioDataOutExt (
1385 if (EFI_ERROR (Status
)) {
1389 Lba64
+= SectorCount
;
1390 Buffer
= ((UINT8
*) Buffer
+ ByteCount
);
1391 BlocksRemaining
-= SectorCount
;
1398 This function is used to send out ATA commands conforms to the
1399 PIO Data In Protocol, supporting ATA/ATAPI-6 standard
1401 Comparing with ATA-3 data in protocol, we have two differents here:<BR>
1402 1. Do NOT wait for DRQ clear before sending command into IDE device.(the
1403 wait will frequently fail... cause writing function return error)
1405 2. Do NOT wait for DRQ clear after all data readed.(the wait greatly
1406 slow down writing performance by 100 times!)
1408 @param[in] *IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used
1409 to record all the information of the IDE device.
1411 @param[in,out] *Buffer buffer contained data transferred from device to host.
1412 @param[in] ByteCount data size in byte unit of the buffer.
1413 @param[in] AtaCommand value of the Command Register
1414 @param[in] StartLba the start LBA of this transaction
1415 @param[in] SectorCount the count of sectors to be transfered
1417 @retval EFI_SUCCESS send out the ATA command and device send required
1420 @retval EFI_DEVICE_ERROR command sent failed.
1425 IN IDE_BLK_IO_DEV
*IdeDev
,
1426 IN OUT VOID
*Buffer
,
1427 IN UINT32 ByteCount
,
1428 IN UINT8 AtaCommand
,
1429 IN EFI_LBA StartLba
,
1430 IN UINT16 SectorCount
1443 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
1444 if (EFI_ERROR (Status
)) {
1445 return EFI_DEVICE_ERROR
;
1449 // Select device, set bit6 as 1 to indicate LBA mode is used
1451 DevSel
= (UINT8
) (IdeDev
->Device
<< 4);
1455 IdeDev
->IoPort
->Head
,
1460 // Wait for DRDY singnal asserting. ATAPI device needn't wait
1462 if ( (IdeDev
->Type
== IdeHardDisk
) ||
1463 (IdeDev
->Type
== Ide48bitAddressingHardDisk
)) {
1465 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
1466 if (EFI_ERROR (Status
)) {
1467 return EFI_DEVICE_ERROR
;
1472 // Fill feature register if needed
1474 if (AtaCommand
== ATA_CMD_SET_FEATURES
) {
1475 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, 0x03);
1479 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
1481 SectorCount8
= (UINT8
) (SectorCount
>> 8);
1482 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1484 SectorCount8
= (UINT8
) SectorCount
;
1485 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1488 // Fill the start LBA registers, which are also two-byte FIFO
1490 LbaLow
= (UINT8
) RShiftU64 (StartLba
, 24);
1491 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 32);
1492 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 40);
1493 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1494 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1495 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1497 LbaLow
= (UINT8
) StartLba
;
1498 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 8);
1499 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 16);
1500 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1501 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1502 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1505 // Send command via Command Register, invoking the processing of this command
1507 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
1509 Buffer16
= (UINT16
*) Buffer
;
1512 // According to PIO data in protocol, host can perform a series of reads to
1513 // the data register after each time device set DRQ ready;
1522 // used to record bytes of currently transfered data
1526 while (WordCount
< ByteCount
/ 2) {
1528 // Poll DRQ bit set, data transfer can be performed only when DRQ is ready.
1530 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
1531 if (EFI_ERROR (Status
)) {
1532 return EFI_DEVICE_ERROR
;
1535 Status
= CheckErrorStatus (IdeDev
);
1536 if (EFI_ERROR (Status
)) {
1537 return EFI_DEVICE_ERROR
;
1541 // Get the byte count for one series of read
1543 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
1544 Increment
= ByteCount
/ 2 - WordCount
;
1547 IDEReadPortWMultiple (
1549 IdeDev
->IoPort
->Data
,
1554 WordCount
+= Increment
;
1555 Buffer16
+= Increment
;
1559 return CheckErrorStatus (IdeDev
);
1563 This function is used to send out ATA commands conforms to the
1564 PIO Data Out Protocol, supporting ATA/ATAPI-6 standard
1566 Comparing with ATA-3 data out protocol, we have two differents here:<BR>
1567 1. Do NOT wait for DRQ clear before sending command into IDE device.(the
1568 wait will frequently fail... cause writing function return error)
1570 2. Do NOT wait for DRQ clear after all data readed.(the wait greatly
1571 slow down writing performance by 100 times!)
1574 pointer pointing to IDE_BLK_IO_DEV data structure, used
1575 to record all the information of the IDE device.
1577 @param[in] *Buffer buffer contained data transferred from host to device.
1578 @param[in] ByteCount data size in byte unit of the buffer.
1579 @param[in] AtaCommand value of the Command Register
1580 @param[in] StartLba the start LBA of this transaction
1581 @param[in] SectorCount the count of sectors to be transfered
1583 @retval EFI_SUCCESS send out the ATA command and device receive required
1586 @retval EFI_DEVICE_ERROR command sent failed.
1591 IN IDE_BLK_IO_DEV
*IdeDev
,
1593 IN UINT32 ByteCount
,
1594 IN UINT8 AtaCommand
,
1595 IN EFI_LBA StartLba
,
1596 IN UINT16 SectorCount
1609 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
1610 if (EFI_ERROR (Status
)) {
1611 return EFI_DEVICE_ERROR
;
1615 // Select device. Set bit6 as 1 to indicate LBA mode is used
1617 DevSel
= (UINT8
) (IdeDev
->Device
<< 4);
1621 IdeDev
->IoPort
->Head
,
1626 // Wait for DRDY singnal asserting.
1628 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
1629 if (EFI_ERROR (Status
)) {
1630 return EFI_DEVICE_ERROR
;
1634 // Fill feature register if needed
1636 if (AtaCommand
== ATA_CMD_SET_FEATURES
) {
1637 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, 0x03);
1641 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
1643 SectorCount8
= (UINT8
) (SectorCount
>> 8);
1644 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1646 SectorCount8
= (UINT8
) SectorCount
;
1647 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1650 // Fill the start LBA registers, which are also two-byte FIFO
1652 LbaLow
= (UINT8
) RShiftU64 (StartLba
, 24);
1653 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 32);
1654 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 40);
1655 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1656 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1657 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1659 LbaLow
= (UINT8
) StartLba
;
1660 LbaMid
= (UINT8
) RShiftU64 (StartLba
, 8);
1661 LbaHigh
= (UINT8
) RShiftU64 (StartLba
, 16);
1662 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1663 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1664 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1667 // Send command via Command Register, invoking the processing of this command
1669 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
1671 Buffer16
= (UINT16
*) Buffer
;
1674 // According to PIO Data Out protocol, host can perform a series of writes to
1675 // the data register after each time device set DRQ ready;
1680 // used to record bytes of currently transfered data
1684 while (WordCount
< ByteCount
/ 2) {
1686 // Poll DRQ bit set, data transfer can be performed only when DRQ is ready.
1688 Status
= DRQReady2 (IdeDev
, ATATIMEOUT
);
1689 if (EFI_ERROR (Status
)) {
1690 return EFI_DEVICE_ERROR
;
1693 Status
= CheckErrorStatus (IdeDev
);
1694 if (EFI_ERROR (Status
)) {
1695 return EFI_DEVICE_ERROR
;
1699 // Write data into device by one series of writing to data register
1701 if ((WordCount
+ Increment
) > ByteCount
/ 2) {
1702 Increment
= ByteCount
/ 2 - WordCount
;
1705 IDEWritePortWMultiple (
1707 IdeDev
->IoPort
->Data
,
1712 WordCount
+= Increment
;
1713 Buffer16
+= Increment
;
1720 return CheckErrorStatus (IdeDev
);
1725 Enable SMART of the disk if supported
1728 pointer pointing to IDE_BLK_IO_DEV data structure,used
1729 to record all the information of the IDE device.
1734 IN IDE_BLK_IO_DEV
*IdeDev
1738 BOOLEAN SMARTSupported
;
1740 EFI_IDENTIFY_DATA
*TmpAtaIdentifyPointer
;
1746 // Detect if the device supports S.M.A.R.T.
1748 if ((IdeDev
->pIdData
->AtaData
.command_set_supported_83
& 0xc000) != 0x4000) {
1750 // Data in word 82 is not valid (bit15 shall be zero and bit14 shall be to one)
1754 if ((IdeDev
->pIdData
->AtaData
.command_set_supported_82
& 0x0001) != 0x0001) {
1756 // S.M.A.R.T is not supported by the device
1758 SMARTSupported
= FALSE
;
1760 SMARTSupported
= TRUE
;
1764 if (!SMARTSupported
) {
1766 // Report nonsupport status code
1768 REPORT_STATUS_CODE (
1769 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1770 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_NOTSUPPORTED
)
1774 // Enable this feature
1776 REPORT_STATUS_CODE (
1778 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_ENABLE
)
1781 Device
= (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0);
1782 Status
= AtaNonDataCommandIn (
1786 ATA_SMART_ENABLE_OPERATION
,
1793 // Detect if this feature is enabled
1795 TmpAtaIdentifyPointer
= (EFI_IDENTIFY_DATA
*) AllocateZeroPool (sizeof (EFI_IDENTIFY_DATA
));
1797 DeviceSelect
= (UINT8
) ((IdeDev
->Device
) << 4);
1798 Status
= AtaPioDataIn (
1800 (VOID
*) TmpAtaIdentifyPointer
,
1801 sizeof (EFI_IDENTIFY_DATA
),
1802 ATA_CMD_IDENTIFY_DRIVE
,
1809 if (EFI_ERROR (Status
)) {
1810 gBS
->FreePool (TmpAtaIdentifyPointer
);
1815 // Check if the feature is enabled
1817 if ((TmpAtaIdentifyPointer
->AtaData
.command_set_feature_enb_85
& 0x0001) == 0x0001) {
1821 AtaNonDataCommandIn (
1825 ATA_SMART_RETURN_STATUS
,
1831 LBAMid
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
);
1832 LBAHigh
= IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
);
1834 if ((LBAMid
== 0x4f) && (LBAHigh
== 0xc2)) {
1836 // The threshold exceeded condition is not detected by the device
1838 REPORT_STATUS_CODE (
1840 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_UNDERTHRESHOLD
)
1843 } else if ((LBAMid
== 0xf4) && (LBAHigh
== 0x2c)) {
1845 // The threshold exceeded condition is detected by the device
1847 REPORT_STATUS_CODE (
1849 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_OVERTHRESHOLD
)
1855 // Report disabled status code
1857 REPORT_STATUS_CODE (
1858 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1859 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_ATA_BUS_SMART_DISABLED
)
1863 gBS
->FreePool (TmpAtaIdentifyPointer
);
1870 Send ATA Ext command into device with NON_DATA protocol
1872 @param IdeDev Standard IDE device private data structure
1873 @param AtaCommand The ATA command to be sent
1874 @param Device The value in Device register
1875 @param Feature The value in Feature register
1876 @param SectorCount The value in SectorCount register
1877 @param LbaAddress The LBA address in 48-bit mode
1879 @retval EFI_SUCCESS Reading succeed
1880 @retval EFI_DEVICE_ERROR Error executing commands on this device
1884 AtaCommandIssueExt (
1885 IN IDE_BLK_IO_DEV
*IdeDev
,
1886 IN UINT8 AtaCommand
,
1889 IN UINT16 SectorCount
,
1890 IN EFI_LBA LbaAddress
1900 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
1901 if (EFI_ERROR (Status
)) {
1902 return EFI_DEVICE_ERROR
;
1906 // Select device (bit4), set LBA mode(bit6) (use 0xe0 for compatibility)
1910 IdeDev
->IoPort
->Head
,
1911 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0)
1915 // ATA commands for ATA device must be issued when DRDY is set
1917 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
1918 if (EFI_ERROR (Status
)) {
1919 return EFI_DEVICE_ERROR
;
1923 // Pass parameter into device register block
1925 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Head
, Device
);
1928 // Fill the feature register, which is a two-byte FIFO. Need write twice.
1930 Feature8
= (UINT8
) (Feature
>> 8);
1931 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, Feature8
);
1933 Feature8
= (UINT8
) Feature
;
1934 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, Feature8
);
1937 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
1939 SectorCount8
= (UINT8
) (SectorCount
>> 8);
1940 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1942 SectorCount8
= (UINT8
) SectorCount
;
1943 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
1946 // Fill the start LBA registers, which are also two-byte FIFO
1948 LbaLow
= (UINT8
) RShiftU64 (LbaAddress
, 24);
1949 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1950 LbaLow
= (UINT8
) LbaAddress
;
1951 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, LbaLow
);
1953 LbaMid
= (UINT8
) RShiftU64 (LbaAddress
, 32);
1954 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1955 LbaMid
= (UINT8
) RShiftU64 (LbaAddress
, 8);
1956 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, LbaMid
);
1958 LbaHigh
= (UINT8
) RShiftU64 (LbaAddress
, 40);
1959 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1960 LbaHigh
= (UINT8
) RShiftU64 (LbaAddress
, 16);
1961 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, LbaHigh
);
1964 // Work around for Segate 160G disk writing
1969 // Send command via Command Register
1971 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
1974 // Stall at least 400ns
1982 Send ATA Ext command into device with NON_DATA protocol
1984 @param IdeDev Standard IDE device private data structure
1985 @param AtaCommand The ATA command to be sent
1986 @param Device The value in Device register
1987 @param Feature The value in Feature register
1988 @param SectorCount The value in SectorCount register
1989 @param LbaAddress The LBA address in 48-bit mode
1991 @retval EFI_SUCCESS Reading succeed
1992 @retval EFI_DEVICE_ERROR Error executing commands on this device
1997 IN IDE_BLK_IO_DEV
*IdeDev
,
1998 IN UINT8 AtaCommand
,
2001 IN UINT16 SectorCount
,
2002 IN EFI_LBA LbaAddress
2013 Status
= WaitForBSYClear (IdeDev
, ATATIMEOUT
);
2014 if (EFI_ERROR (Status
)) {
2015 return EFI_DEVICE_ERROR
;
2019 // Select device (bit4), set LBA mode(bit6) (use 0xe0 for compatibility)
2023 IdeDev
->IoPort
->Head
,
2024 (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0)
2028 // ATA commands for ATA device must be issued when DRDY is set
2030 Status
= DRDYReady (IdeDev
, ATATIMEOUT
);
2031 if (EFI_ERROR (Status
)) {
2032 return EFI_DEVICE_ERROR
;
2035 Lba0
= (UINT8
) LbaAddress
;
2036 Lba1
= (UINT8
) RShiftU64 (LbaAddress
, 8);
2037 Lba2
= (UINT8
) RShiftU64 (LbaAddress
, 16);
2038 Lba3
= (UINT8
) RShiftU64 (LbaAddress
, 24);
2039 Device
= (UINT8
) (Device
| Lba3
);
2042 // Pass parameter into device register block
2044 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Head
, Device
);
2047 // Fill the feature register, which is a two-byte FIFO. Need write twice.
2049 Feature8
= (UINT8
) Feature
;
2050 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg1
.Feature
, Feature8
);
2053 // Fill the sector count register, which is a two-byte FIFO. Need write twice.
2055 SectorCount8
= (UINT8
) SectorCount
;
2056 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorCount
, SectorCount8
);
2059 // Fill the start LBA registers, which are also two-byte FIFO
2062 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->SectorNumber
, Lba0
);
2063 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderLsb
, Lba1
);
2064 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->CylinderMsb
, Lba2
);
2067 // Send command via Command Register
2069 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Reg
.Command
, AtaCommand
);
2072 // Stall at least 400ns
2080 This function is called by the AtaBlkIoReadBlocks() to perform
2081 reading from media in block unit. The function has been enhanced to
2082 support >120GB access and transfer at most 65536 blocks per command
2084 @param[in] *IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used
2085 to record all the information of the IDE device.
2087 @param[in] *DataBuffer A pointer to the destination buffer for the data.
2089 @param[in] StartLba The starting logical block address to read from
2090 on the device media.
2092 @param[in] NumberOfBlocks The number of transfer data blocks.
2094 @return The device status of UDMA operation. If the operation is
2095 successful, return EFI_SUCCESS.
2097 TODO: EFI_UNSUPPORTED - add return value to function comment
2098 TODO: EFI_DEVICE_ERROR - add return value to function comment
2099 TODO: EFI_DEVICE_ERROR - add return value to function comment
2100 TODO: EFI_DEVICE_ERROR - add return value to function comment
2104 IN IDE_BLK_IO_DEV
*IdeDev
,
2105 IN VOID
*DataBuffer
,
2106 IN EFI_LBA StartLba
,
2107 IN UINTN NumberOfBlocks
2110 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaReadExtOp
);
2114 This function is called by the AtaBlkIoReadBlocks() to perform
2115 reading from media in block unit. The function has been enhanced to
2116 support >120GB access and transfer at most 65536 blocks per command
2119 pointer pointing to IDE_BLK_IO_DEV data structure, used
2120 to record all the information of the IDE device.
2122 @param[in] *DataBuffer A pointer to the destination buffer for the data.
2123 @param[in] StartLba The starting logical block address to read from
2124 on the device media.
2125 @param[in] NumberOfBlocks The number of transfer data blocks.
2127 @return The device status of UDMA operation. If the operation is
2128 successful, return EFI_SUCCESS.
2130 TODO: EFI_UNSUPPORTED - add return value to function comment
2131 TODO: EFI_DEVICE_ERROR - add return value to function comment
2132 TODO: EFI_DEVICE_ERROR - add return value to function comment
2133 TODO: EFI_DEVICE_ERROR - add return value to function comment
2137 IN IDE_BLK_IO_DEV
*IdeDev
,
2138 IN VOID
*DataBuffer
,
2139 IN EFI_LBA StartLba
,
2140 IN UINTN NumberOfBlocks
2143 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaReadOp
);
2147 This function is called by the AtaBlkIoWriteBlocks() to perform
2148 writing to media in block unit. The function has been enhanced to
2149 support >120GB access and transfer at most 65536 blocks per command
2151 @param[in] *IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used
2152 to record all the information of the IDE device.
2154 @param[in] *DataBuffer A pointer to the source buffer for the data.
2156 @param[in] StartLba The starting logical block address to write to
2157 on the device media.
2159 @param[in] NumberOfBlocks The number of transfer data blocks.
2161 @return The device status of UDMA operation. If the operation is
2162 successful, return EFI_SUCCESS.
2164 TODO: EFI_UNSUPPORTED - add return value to function comment
2165 TODO: EFI_DEVICE_ERROR - add return value to function comment
2166 TODO: EFI_DEVICE_ERROR - add return value to function comment
2170 IN IDE_BLK_IO_DEV
*IdeDev
,
2171 IN VOID
*DataBuffer
,
2172 IN EFI_LBA StartLba
,
2173 IN UINTN NumberOfBlocks
2176 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaWriteExtOp
);
2180 This function is called by the AtaBlkIoWriteBlocks() to perform
2181 writing to media in block unit. The function has been enhanced to
2182 support >120GB access and transfer at most 65536 blocks per command
2185 pointer pointing to IDE_BLK_IO_DEV data structure, used
2186 to record all the information of the IDE device.
2188 @param[in] *DataBuffer
2189 A pointer to the source buffer for the data.
2192 The starting logical block address to write to
2193 on the device media.
2195 @param[in] NumberOfBlocks
2196 The number of transfer data blocks.
2198 @return The device status of UDMA operation. If the operation is
2199 successful, return EFI_SUCCESS.
2201 TODO: EFI_UNSUPPORTED - add return value to function comment
2202 TODO: EFI_DEVICE_ERROR - add return value to function comment
2203 TODO: EFI_DEVICE_ERROR - add return value to function comment
2207 IN IDE_BLK_IO_DEV
*IdeDev
,
2208 IN VOID
*DataBuffer
,
2209 IN EFI_LBA StartLba
,
2210 IN UINTN NumberOfBlocks
2213 return DoAtaUdma (IdeDev
, DataBuffer
, StartLba
, NumberOfBlocks
, AtaUdmaWriteOp
);
2217 Perform an ATA Udma operation (Read, ReadExt, Write, WriteExt).
2220 pointer pointing to IDE_BLK_IO_DEV data structure, used
2221 to record all the information of the IDE device.
2223 @param[in] *DataBuffer
2224 A pointer to the source buffer for the data.
2227 The starting logical block address to write to
2228 on the device media.
2230 @param[in] NumberOfBlocks
2231 The number of transfer data blocks.
2234 The perform operations could be AtaUdmaReadOp, AtaUdmaReadExOp,
2235 AtaUdmaWriteOp, AtaUdmaWriteExOp
2237 @return The device status of UDMA operation. If the operation is
2238 successful, return EFI_SUCCESS.
2243 IN IDE_BLK_IO_DEV
*IdeDev
,
2244 IN VOID
*DataBuffer
,
2245 IN EFI_LBA StartLba
,
2246 IN UINTN NumberOfBlocks
,
2247 IN ATA_UDMA_OPERATION UdmaOp
2250 IDE_DMA_PRD
*PrdAddr
;
2251 IDE_DMA_PRD
*UsedPrdAddr
;
2252 IDE_DMA_PRD
*TempPrdAddr
;
2253 UINT8 RegisterValue
;
2255 UINT64 IoPortForBmic
;
2256 UINT64 IoPortForBmis
;
2257 UINT64 IoPortForBmid
;
2261 UINTN ByteAvailable
;
2263 UINTN RemainBlockNum
;
2264 UINT8 DeviceControl
;
2269 EFI_PHYSICAL_ADDRESS DeviceAddress
;
2270 UINTN MaxDmaCommandSectors
;
2271 EFI_PCI_IO_PROTOCOL_OPERATION PciIoProtocolOp
;
2276 MaxDmaCommandSectors
= ATAPI_MAX_DMA_CMD_SECTORS
;
2277 PciIoProtocolOp
= EfiPciIoOperationBusMasterWrite
;
2278 AtaCommand
= ATA_CMD_READ_DMA
;
2280 case AtaUdmaReadExtOp
:
2281 MaxDmaCommandSectors
= ATAPI_MAX_DMA_EXT_CMD_SECTORS
;
2282 PciIoProtocolOp
= EfiPciIoOperationBusMasterWrite
;
2283 AtaCommand
= ATA_CMD_READ_DMA_EXT
;
2285 case AtaUdmaWriteOp
:
2286 MaxDmaCommandSectors
= ATAPI_MAX_DMA_CMD_SECTORS
;
2287 PciIoProtocolOp
= EfiPciIoOperationBusMasterRead
;
2288 AtaCommand
= ATA_CMD_WRITE_DMA
;
2290 case AtaUdmaWriteExtOp
:
2291 MaxDmaCommandSectors
= ATAPI_MAX_DMA_EXT_CMD_SECTORS
;
2292 PciIoProtocolOp
= EfiPciIoOperationBusMasterRead
;
2293 AtaCommand
= ATA_CMD_WRITE_DMA_EXT
;
2296 return EFI_UNSUPPORTED
;
2301 // Channel and device differential
2303 Device
= (UINT8
) ((IdeDev
->Device
<< 4) | 0xe0);
2306 // Enable interrupt to support UDMA and Select device
2309 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);
2311 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Head
, Device
);
2313 if (IdePrimary
== IdeDev
->Channel
) {
2314 IoPortForBmic
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMICP_OFFSET
;
2315 IoPortForBmis
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMISP_OFFSET
;
2316 IoPortForBmid
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMIDP_OFFSET
;
2318 if (IdeSecondary
== IdeDev
->Channel
) {
2319 IoPortForBmic
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMICS_OFFSET
;
2320 IoPortForBmis
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMISS_OFFSET
;
2321 IoPortForBmid
= IdeDev
->IoPort
->BusMasterBaseAddr
+ BMIDS_OFFSET
;
2323 return EFI_UNSUPPORTED
;
2327 RemainBlockNum
= NumberOfBlocks
;
2328 while (RemainBlockNum
> 0) {
2330 if (RemainBlockNum
>= MaxDmaCommandSectors
) {
2332 // SectorCount is used to record the number of sectors to be read
2333 // Max 65536 sectors can be transfered at a time.
2335 NumberOfBlocks
= MaxDmaCommandSectors
;
2336 RemainBlockNum
-= MaxDmaCommandSectors
;
2338 NumberOfBlocks
= (UINT16
) RemainBlockNum
;
2343 // Calculate the number of PRD table to make sure the memory region
2344 // not cross 64K boundary
2346 ByteCount
= NumberOfBlocks
* IdeDev
->BlkIo
.Media
->BlockSize
;
2347 PrdTableNum
= ((ByteCount
>> 16) + 1) + 1;
2352 PageCount
= EFI_SIZE_TO_PAGES (2 * PrdTableNum
* sizeof (IDE_DMA_PRD
));
2353 Status
= IdeDev
->PciIo
->AllocateBuffer (
2356 EfiBootServicesData
,
2361 if (EFI_ERROR (Status
)) {
2362 return EFI_OUT_OF_RESOURCES
;
2364 ZeroMem ((VOID
*) ((UINTN
) MemPage
), EFI_PAGES_TO_SIZE (PageCount
));
2366 PrdAddr
= (IDE_DMA_PRD
*) ((UINTN
) MemPage
);
2368 // To make sure PRD is allocated in one 64K page
2370 if (((UINTN
) PrdAddr
& 0x0FFFF) > (((UINTN
) PrdAddr
+ PrdTableNum
* sizeof (IDE_DMA_PRD
) - 1) & 0x0FFFF)) {
2371 UsedPrdAddr
= (IDE_DMA_PRD
*) ((UINTN
) ((UINT8
*) PrdAddr
+ 0x10000) & 0xFFFF0000);
2373 if ((UINTN
) PrdAddr
& 0x03) {
2374 UsedPrdAddr
= (IDE_DMA_PRD
*) ((UINTN
) ((UINT8
*) PrdAddr
+ 0x04) & 0xFFFFFFFC);
2376 UsedPrdAddr
= PrdAddr
;
2381 // Build the PRD table
2383 Status
= IdeDev
->PciIo
->Map (
2391 if (EFI_ERROR (Status
)) {
2392 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2393 return EFI_OUT_OF_RESOURCES
;
2395 PrdBuffer
= (VOID
*) ((UINTN
) DeviceAddress
);
2396 TempPrdAddr
= UsedPrdAddr
;
2399 ByteAvailable
= 0x10000 - ((UINTN
) PrdBuffer
& 0xFFFF);
2401 if (ByteCount
<= ByteAvailable
) {
2402 TempPrdAddr
->RegionBaseAddr
= (UINT32
) ((UINTN
) PrdBuffer
);
2403 TempPrdAddr
->ByteCount
= (UINT16
) ByteCount
;
2404 TempPrdAddr
->EndOfTable
= 0x8000;
2408 TempPrdAddr
->RegionBaseAddr
= (UINT32
) ((UINTN
) PrdBuffer
);
2409 TempPrdAddr
->ByteCount
= (UINT16
) ByteAvailable
;
2411 ByteCount
-= ByteAvailable
;
2412 PrdBuffer
+= ByteAvailable
;
2417 // Set the base address to BMID register
2419 IdeDev
->PciIo
->Io
.Write (
2421 EfiPciIoWidthUint32
,
2422 EFI_PCI_IO_PASS_THROUGH_BAR
,
2429 // Set BMIC register to identify the operation direction
2431 IdeDev
->PciIo
->Io
.Read (
2434 EFI_PCI_IO_PASS_THROUGH_BAR
,
2440 if (UdmaOp
== AtaUdmaReadExtOp
|| UdmaOp
== AtaUdmaReadOp
) {
2441 RegisterValue
|= BMIC_nREAD
;
2443 RegisterValue
&= ~((UINT8
) BMIC_nREAD
);
2446 IdeDev
->PciIo
->Io
.Write (
2449 EFI_PCI_IO_PASS_THROUGH_BAR
,
2456 // Read BMIS register and clear ERROR and INTR bit
2458 IdeDev
->PciIo
->Io
.Read (
2461 EFI_PCI_IO_PASS_THROUGH_BAR
,
2467 RegisterValue
|= (BMIS_INTERRUPT
| BMIS_ERROR
);
2469 IdeDev
->PciIo
->Io
.Write (
2472 EFI_PCI_IO_PASS_THROUGH_BAR
,
2478 if (UdmaOp
== AtaUdmaWriteExtOp
|| UdmaOp
== AtaUdmaReadExtOp
) {
2479 Status
= AtaCommandIssueExt (
2484 (UINT16
) NumberOfBlocks
,
2488 Status
= AtaCommandIssue (
2493 (UINT16
) NumberOfBlocks
,
2498 if (EFI_ERROR (Status
)) {
2499 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2500 IdeDev
->PciIo
->Unmap (IdeDev
->PciIo
, Map
);
2501 return EFI_DEVICE_ERROR
;
2505 // Set START bit of BMIC register
2507 IdeDev
->PciIo
->Io
.Read (
2510 EFI_PCI_IO_PASS_THROUGH_BAR
,
2516 RegisterValue
|= BMIC_START
;
2518 IdeDev
->PciIo
->Io
.Write (
2521 EFI_PCI_IO_PASS_THROUGH_BAR
,
2528 // Check the INTERRUPT and ERROR bit of BMIS
2529 // Max transfer number of sectors for one command is 65536(32Mbyte),
2530 // it will cost 1 second to transfer these data in UDMA mode 2(33.3MBps).
2531 // So set the variable Count to 2000, for about 2 second timeout time.
2536 IdeDev
->PciIo
->Io
.Read (
2539 EFI_PCI_IO_PASS_THROUGH_BAR
,
2544 if ((RegisterValue
& (BMIS_INTERRUPT
| BMIS_ERROR
)) || (Count
== 0)) {
2545 if ((RegisterValue
& BMIS_ERROR
) || (Count
== 0)) {
2547 // Clear START bit of BMIC register before return EFI_DEVICE_ERROR
2549 IdeDev
->PciIo
->Io
.Read (
2552 EFI_PCI_IO_PASS_THROUGH_BAR
,
2558 RegisterValue
&= ~((UINT8
)BMIC_START
);
2560 IdeDev
->PciIo
->Io
.Write (
2563 EFI_PCI_IO_PASS_THROUGH_BAR
,
2568 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2569 IdeDev
->PciIo
->Unmap (IdeDev
->PciIo
, Map
);
2570 return EFI_DEVICE_ERROR
;
2579 IdeDev
->PciIo
->FreeBuffer (IdeDev
->PciIo
, PageCount
, MemPage
);
2580 IdeDev
->PciIo
->Unmap (IdeDev
->PciIo
, Map
);
2582 // Read Status Register of IDE device to clear interrupt
2584 RegisterValue
= IDEReadPortB(IdeDev
->PciIo
,IdeDev
->IoPort
->Reg
.Status
);
2586 // Clear START bit of BMIC register
2588 IdeDev
->PciIo
->Io
.Read (
2591 EFI_PCI_IO_PASS_THROUGH_BAR
,
2597 RegisterValue
&= ~((UINT8
) BMIC_START
);
2599 IdeDev
->PciIo
->Io
.Write (
2602 EFI_PCI_IO_PASS_THROUGH_BAR
,
2608 if (RegisterValue
& BMIS_ERROR
) {
2609 return EFI_DEVICE_ERROR
;
2612 DataBuffer
= (UINT8
*) DataBuffer
+ NumberOfBlocks
* IdeDev
->BlkIo
.Media
->BlockSize
;
2613 StartLba
+= NumberOfBlocks
;
2617 // Disable interrupt of Select device
2619 IDEReadPortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
);
2620 DeviceControl
|= ATA_CTLREG_IEN_L
;
2621 IDEWritePortB (IdeDev
->PciIo
, IdeDev
->IoPort
->Alt
.DeviceControl
, DeviceControl
);