Add a lock to protect the critical region in Service APIs for gEfiBlockIoProtocolGuid Protocol to prevent re-entrance of the same API from from different TPL level.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2443 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2007-03-12 07:47:33 +00:00
parent 90a98f29c5
commit c094abe585
3 changed files with 103 additions and 36 deletions

View File

@ -1035,6 +1035,9 @@ IDEBlkIoReset (
{
IDE_BLK_IO_DEV *IdeBlkIoDevice;
EFI_STATUS Status;
EFI_TPL OldTpl;
OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);
IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (This);
//
@ -1047,11 +1050,13 @@ IDEBlkIoReset (
//
if (IdeBlkIoDevice->Type == IdeHardDisk ||
IdeBlkIoDevice->Type == Ide48bitAddressingHardDisk) {
return AtaSoftReset (IdeBlkIoDevice);
Status = AtaSoftReset (IdeBlkIoDevice);
goto Done;
}
if (IdeBlkIoDevice->Type == IdeUnknown) {
return EFI_DEVICE_ERROR;
Status = EFI_DEVICE_ERROR;
goto Done;
}
//
@ -1062,6 +1067,8 @@ IDEBlkIoReset (
Status = AtaSoftReset (IdeBlkIoDevice);
}
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}
@ -1089,6 +1096,10 @@ IDEBlkIoReadBlocks (
// TODO: EFI_DEVICE_ERROR - add return value to function comment
{
IDE_BLK_IO_DEV *IdeBlkIoDevice;
EFI_STATUS Status;
EFI_TPL OldTpl;
OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);
IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (This);
@ -1102,23 +1113,25 @@ IDEBlkIoReadBlocks (
//
if (IdeBlkIoDevice->Type == IdeHardDisk ||
IdeBlkIoDevice->Type == Ide48bitAddressingHardDisk) {
return AtaBlkIoReadBlocks (
Status = AtaBlkIoReadBlocks (
IdeBlkIoDevice,
MediaId,
LBA,
BufferSize,
Buffer
);
goto Done;
}
if (IdeBlkIoDevice->Type == IdeUnknown) {
return EFI_DEVICE_ERROR;
Status = EFI_DEVICE_ERROR;
goto Done;
}
//
// for ATAPI device, using ATAPI read block's mechanism
//
return AtapiBlkIoReadBlocks (
Status = AtapiBlkIoReadBlocks (
IdeBlkIoDevice,
MediaId,
LBA,
@ -1126,6 +1139,10 @@ IDEBlkIoReadBlocks (
Buffer
);
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
@ -1152,7 +1169,11 @@ IDEBlkIoWriteBlocks (
// TODO: EFI_DEVICE_ERROR - add return value to function comment
{
IDE_BLK_IO_DEV *IdeBlkIoDevice;
EFI_STATUS Status;
EFI_TPL OldTpl;
OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);
IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (This);
//
// Requery IDE IO resources in case of the switch of native and legacy modes
@ -1165,29 +1186,35 @@ IDEBlkIoWriteBlocks (
if (IdeBlkIoDevice->Type == IdeHardDisk ||
IdeBlkIoDevice->Type == Ide48bitAddressingHardDisk) {
return AtaBlkIoWriteBlocks (
Status = AtaBlkIoWriteBlocks (
IdeBlkIoDevice,
MediaId,
LBA,
BufferSize,
Buffer
);
goto Done;
}
if (IdeBlkIoDevice->Type == IdeUnknown) {
return EFI_DEVICE_ERROR;
Status = EFI_DEVICE_ERROR;
goto Done;
}
//
// for ATAPI device, using ATAPI write block's mechanism
//
return AtapiBlkIoWriteBlocks (
Status = AtapiBlkIoWriteBlocks (
IdeBlkIoDevice,
MediaId,
LBA,
BufferSize,
Buffer
);
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}
//

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2006, Intel Corporation
Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -332,17 +332,22 @@ Returns:
{
SCSI_DISK_DEV *ScsiDiskDevice;
EFI_STATUS Status;
EFI_TPL OldTpl;
OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);
ScsiDiskDevice = SCSI_DISK_DEV_FROM_THIS (This);
Status = ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo);
if (!ExtendedVerification) {
return Status;
goto Done;
}
Status = ScsiDiskDevice->ScsiIo->ResetBus (ScsiDiskDevice->ScsiIo);
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}
@ -389,6 +394,7 @@ Returns:
UINTN BlockSize;
UINTN NumberOfBlocks;
BOOLEAN MediaChange;
EFI_TPL OldTpl;
MediaChange = FALSE;
if (!Buffer) {
@ -399,13 +405,16 @@ Returns:
return EFI_SUCCESS;
}
OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);
ScsiDiskDevice = SCSI_DISK_DEV_FROM_THIS (This);
if (!IsDeviceFixed (ScsiDiskDevice)) {
Status = ScsiDiskDetectMedia (ScsiDiskDevice, FALSE, &MediaChange);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
Status = EFI_DEVICE_ERROR;
goto Done;
}
if (MediaChange) {
@ -426,27 +435,33 @@ Returns:
NumberOfBlocks = BufferSize / BlockSize;
if (!(Media->MediaPresent)) {
return EFI_NO_MEDIA;
Status = EFI_NO_MEDIA;
goto Done;
}
if (MediaId != Media->MediaId) {
return EFI_MEDIA_CHANGED;
Status = EFI_MEDIA_CHANGED;
goto Done;
}
if (BufferSize % BlockSize != 0) {
return EFI_BAD_BUFFER_SIZE;
Status = EFI_BAD_BUFFER_SIZE;
goto Done;
}
if (LBA > Media->LastBlock) {
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if ((LBA + NumberOfBlocks - 1) > Media->LastBlock) {
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if ((Media->IoAlign > 1) && (((UINTN) Buffer & (Media->IoAlign - 1)) != 0)) {
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
//
@ -455,6 +470,8 @@ Returns:
//
Status = ScsiDiskReadSectors (ScsiDiskDevice, Buffer, LBA, NumberOfBlocks);
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}
@ -501,6 +518,7 @@ Returns:
UINTN BlockSize;
UINTN NumberOfBlocks;
BOOLEAN MediaChange;
EFI_TPL OldTpl;
MediaChange = FALSE;
if (!Buffer) {
@ -511,13 +529,16 @@ Returns:
return EFI_SUCCESS;
}
OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);
ScsiDiskDevice = SCSI_DISK_DEV_FROM_THIS (This);
if (!IsDeviceFixed (ScsiDiskDevice)) {
Status = ScsiDiskDetectMedia (ScsiDiskDevice, FALSE, &MediaChange);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
Status = EFI_DEVICE_ERROR;
goto Done;
}
if (MediaChange) {
@ -538,27 +559,33 @@ Returns:
NumberOfBlocks = BufferSize / BlockSize;
if (!(Media->MediaPresent)) {
return EFI_NO_MEDIA;
Status = EFI_NO_MEDIA;
goto Done;
}
if (MediaId != Media->MediaId) {
return EFI_MEDIA_CHANGED;
Status = EFI_MEDIA_CHANGED;
goto Done;
}
if (BufferSize % BlockSize != 0) {
return EFI_BAD_BUFFER_SIZE;
Status = EFI_BAD_BUFFER_SIZE;
goto Done;
}
if (LBA > Media->LastBlock) {
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if ((LBA + NumberOfBlocks - 1) > Media->LastBlock) {
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if ((Media->IoAlign > 1) && (((UINTN) Buffer & (Media->IoAlign - 1)) != 0)) {
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
//
// if all the parameters are valid, then perform read sectors command
@ -566,6 +593,9 @@ Returns:
//
Status = ScsiDiskWriteSectors (ScsiDiskDevice, Buffer, LBA, NumberOfBlocks);
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2006, Intel Corporation
Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -350,6 +350,9 @@ USBFloppyReset (
USB_FLOPPY_DEV *UsbFloppyDevice;
EFI_USB_ATAPI_PROTOCOL *UsbAtapiInterface;
EFI_STATUS Status;
EFI_TPL OldTpl;
OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);
UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (This);
@ -360,6 +363,8 @@ USBFloppyReset (
//
Status = UsbAtapiInterface->UsbAtapiReset (UsbAtapiInterface, ExtendedVerification);
gBS->RestoreTPL (OldTpl);
return Status;
}
@ -404,6 +409,7 @@ USBFloppyReadBlocks (
UINTN BlockSize;
UINTN NumberOfBlocks;
BOOLEAN MediaChange;
EFI_TPL OldTpl;
Status = EFI_SUCCESS;
MediaChange = FALSE;
@ -412,16 +418,16 @@ USBFloppyReadBlocks (
//
// Check parameters
//
if (!Buffer) {
Status = EFI_INVALID_PARAMETER;
goto Done;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize == 0) {
Status = EFI_SUCCESS;
goto Done;
return EFI_SUCCESS;
}
OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);
UsbFloppyTestUnitReady (UsbFloppyDevice);
Status = UsbFloppyDetectMedia (UsbFloppyDevice, &MediaChange);
@ -485,6 +491,7 @@ USBFloppyReadBlocks (
if (EFI_ERROR (Status)) {
This->Reset (This, TRUE);
Status = EFI_DEVICE_ERROR;
goto Done;
}
if (NumberOfBlocks > BLOCK_UNIT) {
@ -499,6 +506,7 @@ USBFloppyReadBlocks (
}
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}
@ -546,6 +554,7 @@ USBFloppyWriteBlocks (
UINTN BlockSize;
UINTN NumberOfBlocks;
BOOLEAN MediaChange;
EFI_TPL OldTpl;
Status = EFI_SUCCESS;
MediaChange = FALSE;
@ -555,16 +564,16 @@ USBFloppyWriteBlocks (
//
// Check parameters
//
if (!Buffer) {
Status = EFI_INVALID_PARAMETER;
goto Done;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize == 0) {
Status = EFI_SUCCESS;
goto Done;
return EFI_SUCCESS;
}
OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);
UsbFloppyTestUnitReady (UsbFloppyDevice);
Status = UsbFloppyDetectMedia (UsbFloppyDevice, &MediaChange);
@ -633,6 +642,7 @@ USBFloppyWriteBlocks (
if (EFI_ERROR (Status)) {
This->Reset (This, TRUE);
Status = EFI_DEVICE_ERROR;
goto Done;
}
if (NumberOfBlocks > BLOCK_UNIT) {
@ -647,7 +657,7 @@ USBFloppyWriteBlocks (
}
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}