📄 ide.c
字号:
UINTN IN TimeoutInMilliSeconds
used to designate the timeout for the DRQ ready.
Returns:
EFI_SUCCESS
DRQ bit set within the time out.
EFI_TIMEOUT
DRQ bit not set within the time out.
EFI_ABORTED
DRQ bit not set caused by the command abort.
Notes:
Read Status Register will clear interrupt status.
--*/
// TODO: function comment is missing 'Routine Description:'
// TODO: function comment is missing 'Arguments:'
// TODO: IdeDev - add argument and description to function comment
// TODO: TimeoutInMilliSeconds - add argument and description to function comment
{
UINT32 Delay;
UINT8 StatusRegister;
UINT8 ErrorRegister;
Delay = (UINT32) (((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 30) + 1);
do {
//
// read Status Register will clear interrupt
//
StatusRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Reg.Status);
//
// BSY==0,DRQ==1
//
if ((StatusRegister & (BSY | DRQ)) == DRQ) {
break;
}
if ((StatusRegister & (BSY | ERR)) == ERR) {
ErrorRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Reg1.Error);
if ((ErrorRegister & ABRT_ERR) == ABRT_ERR) {
return EFI_ABORTED;
}
}
//
// Stall for 30 us
//
gBS->Stall (30);
Delay--;
} while (Delay);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}
EFI_STATUS
DRQReady2 (
IN IDE_BLK_IO_DEV *IdeDev,
IN UINTN TimeoutInMilliSeconds
)
/*++
Name: DRQReady2
Purpose:
This function is used to poll for the DRQ bit set in the
Alternate Status Register. DRQ is set when the device is ready to
transfer data. So this function is called after the command
is sent to the device and before required data is transferred.
Parameters:
IDE_BLK_IO_DEV IN *IdeDev
pointer pointing to IDE_BLK_IO_DEV data structure, used
to record all the information of the IDE device.
UINTN IN TimeoutInMilliSeconds
used to designate the timeout for the DRQ ready.
Returns:
EFI_SUCCESS
DRQ bit set within the time out.
EFI_TIMEOUT
DRQ bit not set within the time out.
EFI_ABORTED
DRQ bit not set caused by the command abort.
Notes:
Read Alternate Status Register will not clear interrupt status.
--*/
// TODO: function comment is missing 'Routine Description:'
// TODO: function comment is missing 'Arguments:'
// TODO: IdeDev - add argument and description to function comment
// TODO: TimeoutInMilliSeconds - add argument and description to function comment
{
UINT32 Delay;
UINT8 AltRegister;
UINT8 ErrorRegister;
Delay = (UINT32) (((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 30) + 1);
do {
//
// Read Alternate Status Register will not clear interrupt status
//
AltRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Alt.AltStatus);
//
// BSY == 0 , DRQ == 1
//
if ((AltRegister & (BSY | DRQ)) == DRQ) {
break;
}
if ((AltRegister & (BSY | ERR)) == ERR) {
ErrorRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Reg1.Error);
if ((ErrorRegister & ABRT_ERR) == ABRT_ERR) {
return EFI_ABORTED;
}
}
//
// Stall for 30 us
//
gBS->Stall (30);
Delay--;
} while (Delay);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}
EFI_STATUS
WaitForBSYClear (
IN IDE_BLK_IO_DEV *IdeDev,
IN UINTN TimeoutInMilliSeconds
)
/*++
Name:
WaitForBSYClear
Purpose:
This function is used to poll for the BSY bit clear in the
Status Register. BSY is clear when the device is not busy.
Every command must be sent after device is not busy.
Parameters:
IDE_BLK_IO_DEV IN *IdeDev
pointer pointing to IDE_BLK_IO_DEV data structure, used
to record all the information of the IDE device.
UINTN IN TimeoutInMilliSeconds
used to designate the timeout for the DRQ ready.
Returns:
EFI_SUCCESS
BSY bit clear within the time out.
EFI_TIMEOUT
BSY bit not clear within the time out.
Notes:
Read Status Register will clear interrupt status.
--*/
// TODO: function comment is missing 'Routine Description:'
// TODO: function comment is missing 'Arguments:'
// TODO: IdeDev - add argument and description to function comment
// TODO: TimeoutInMilliSeconds - add argument and description to function comment
{
UINT32 Delay;
UINT8 StatusRegister;
Delay = (UINT32) (((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 30) + 1);
do {
StatusRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Reg.Status);
if ((StatusRegister & BSY) == 0x00) {
break;
}
//
// Stall for 30 us
//
gBS->Stall (30);
Delay--;
} while (Delay);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}
//
// WaitForBSYClear2
//
EFI_STATUS
WaitForBSYClear2 (
IN IDE_BLK_IO_DEV *IdeDev,
IN UINTN TimeoutInMilliSeconds
)
/*++
Name:
WaitForBSYClear2
Purpose:
This function is used to poll for the BSY bit clear in the
Alternate Status Register. BSY is clear when the device is not busy.
Every command must be sent after device is not busy.
Parameters:
IDE_BLK_IO_DEV IN *IdeDev
pointer pointing to IDE_BLK_IO_DEV data structure, used
to record all the information of the IDE device.
UINTN IN TimeoutInMilliSeconds
used to designate the timeout for the DRQ ready.
Returns:
EFI_SUCCESS
BSY bit clear within the time out.
EFI_TIMEOUT
BSY bit not clear within the time out.
Notes:
Read Alternate Status Register will not clear interrupt status.
--*/
// TODO: function comment is missing 'Routine Description:'
// TODO: function comment is missing 'Arguments:'
// TODO: IdeDev - add argument and description to function comment
// TODO: TimeoutInMilliSeconds - add argument and description to function comment
{
UINT32 Delay;
UINT8 AltRegister;
Delay = (UINT32) (((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 30) + 1);
do {
AltRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Alt.AltStatus);
if ((AltRegister & BSY) == 0x00) {
break;
}
gBS->Stall (30);
Delay--;
} while (Delay);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}
//
// DRDYReady
//
EFI_STATUS
DRDYReady (
IN IDE_BLK_IO_DEV *IdeDev,
IN UINTN DelayInMilliSeconds
)
/*++
Name:
DRDYReady
Purpose:
This function is used to poll for the DRDY bit set in the
Status Register. DRDY bit is set when the device is ready
to accept command. Most ATA commands must be sent after
DRDY set except the ATAPI Packet Command.
Parameters:
IDE_BLK_IO_DEV IN *IdeDev
pointer pointing to IDE_BLK_IO_DEV data structure, used
to record all the information of the IDE device.
UINTN IN TimeoutInMilliSeconds
used to designate the timeout for the DRQ ready.
Returns:
EFI_SUCCESS
DRDY bit set within the time out.
EFI_TIMEOUT
DRDY bit not set within the time out.
Notes:
Read Status Register will clear interrupt status.
--*/
// TODO: function comment is missing 'Routine Description:'
// TODO: function comment is missing 'Arguments:'
// TODO: IdeDev - add argument and description to function comment
// TODO: DelayInMilliSeconds - add argument and description to function comment
// TODO: EFI_ABORTED - add return value to function comment
{
UINT32 Delay;
UINT8 StatusRegister;
UINT8 ErrorRegister;
Delay = (UINT32) (((DelayInMilliSeconds * STALL_1_MILLI_SECOND) / 30) + 1);
do {
StatusRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Reg.Status);
//
// BSY == 0 , DRDY == 1
//
if ((StatusRegister & (DRDY | BSY)) == DRDY) {
break;
}
if ((StatusRegister & (BSY | ERR)) == ERR) {
ErrorRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Reg1.Error);
if ((ErrorRegister & ABRT_ERR) == ABRT_ERR) {
return EFI_ABORTED;
}
}
gBS->Stall (30);
Delay--;
} while (Delay);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}
//
// DRDYReady2
//
EFI_STATUS
DRDYReady2 (
IN IDE_BLK_IO_DEV *IdeDev,
IN UINTN DelayInMilliSeconds
)
/*++
Name:
DRDYReady2
Purpose:
This function is used to poll for the DRDY bit set in the
Alternate Status Register. DRDY bit is set when the device is ready
to accept command. Most ATA commands must be sent after
DRDY set except the ATAPI Packet Command.
Parameters:
IDE_BLK_IO_DEV IN *IdeDev
pointer pointing to IDE_BLK_IO_DEV data structure, used
to record all the information of the IDE device.
UINTN IN TimeoutInMilliSeconds
used to designate the timeout for the DRQ ready.
Returns:
EFI_SUCCESS
DRDY bit set within the time out.
EFI_TIMEOUT
DRDY bit not set within the time out.
Notes:
Read Alternate Status Register will clear interrupt status.
--*/
// TODO: function comment is missing 'Routine Description:'
// TODO: function comment is missing 'Arguments:'
// TODO: IdeDev - add argument and description to function comment
// TODO: DelayInMilliSeconds - add argument and description to function comment
// TODO: EFI_ABORTED - add return value to function comment
{
UINT32 Delay;
UINT8 AltRegister;
UINT8 ErrorRegister;
Delay = (UINT32) (((DelayInMilliSeconds * STALL_1_MILLI_SECOND) / 30) + 1);
do {
AltRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Alt.AltStatus);
//
// BSY == 0 , DRDY == 1
//
if ((AltRegister & (DRDY | BSY)) == DRDY) {
break;
}
if ((AltRegister & (BSY | ERR)) == ERR) {
ErrorRegister = IDEReadPortB (IdeDev->PciIo, IdeDev->IoPort->Reg1.Error);
if ((ErrorRegister & ABRT_ERR) == ABRT_ERR) {
return EFI_ABORTED;
}
}
gBS->Stall (30);
Delay--;
} while (Delay);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}
//
// SwapStringChars
//
VOID
SwapStringChars (
IN CHAR8 *Destination,
IN CHAR8 *Source,
IN UINT32 Size
)
/*++
Name:
SwapStringChars
Purpose:
This function is a helper function used to change the char order in a
string. It is designed specially for the PrintAtaModuleName() function.
After the IDE device is detected, the IDE driver gets the device module
name by sending ATA command called ATA Identify Command or ATAPI
Identify Command to the specified IDE device. The module name returned
is a string of ASCII characters: the first character is bit8--bit15
of the first word, the second character is bit0--bit7 of the first word
and so on. Thus the string can not be print directly before it is
preprocessed by this func to change the order of characters in
each word in the string.
Parameters:
CHAR8 IN *Destination
Indicates the destination string.
CHAR8 IN *Source
Indicates the source string.
UINT8 IN Size
the length of the string
Returns:
none
Notes:
--*/
// TODO: function comment is missing 'Routine Description:'
// TODO: function comment is missing 'Arguments:'
// TODO: Destination - add argument and description to function comment
// TODO: Source - add argument and description to function comment
// TODO: Size - add argument and description to function comment
{
UINT32 Index;
CHAR8 Temp;
for (Index = 0; Index < Size; Index += 2) {
Temp = Source[Index + 1];
Destination[Index + 1] = Source[Index];
Destination[Index] = Temp;
}
}
//
// ReleaseIdeResources
//
VOID
ReleaseIdeResources (
IN IDE_BLK_IO_DEV *IdeBlkIoDevice
)
/*++
Routing Description:
Release resources of an IDE device before stopping it.
Arguments:
IdeBlkIoDevice -- Standard IDE device private data structure
Returns:
NONE
---*/
// TODO: function comment is missing 'Routine Description:'
{
if (IdeBlkIoDevice == NULL) {
return ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -