summaryrefslogtreecommitdiff
path: root/EdkModulePkg
diff options
context:
space:
mode:
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>2007-03-12 07:47:33 +0000
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>2007-03-12 07:47:33 +0000
commitc094abe5852057ef47941d8de3af20b2286cd822 (patch)
tree523f3c7a15cf60c0d02734861ae3447b2b2b854c /EdkModulePkg
parent90a98f29c5db0a9e008c6779866ba6f1ada45cae (diff)
downloadedk2-platforms-c094abe5852057ef47941d8de3af20b2286cd822.tar.xz
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
Diffstat (limited to 'EdkModulePkg')
-rw-r--r--EdkModulePkg/Bus/Pci/IdeBus/Dxe/idebus.c43
-rw-r--r--EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c62
-rw-r--r--EdkModulePkg/Bus/Usb/UsbMassStorage/Dxe/UsbMassStorage.c34
3 files changed, 103 insertions, 36 deletions
diff --git a/EdkModulePkg/Bus/Pci/IdeBus/Dxe/idebus.c b/EdkModulePkg/Bus/Pci/IdeBus/Dxe/idebus.c
index 42d71b5c22..c1c14052f1 100644
--- a/EdkModulePkg/Bus/Pci/IdeBus/Dxe/idebus.c
+++ b/EdkModulePkg/Bus/Pci/IdeBus/Dxe/idebus.c
@@ -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;
}
//
diff --git a/EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c b/EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c
index a3f4d6a3b6..9eac2c474d 100644
--- a/EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c
+++ b/EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c
@@ -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;
}
diff --git a/EdkModulePkg/Bus/Usb/UsbMassStorage/Dxe/UsbMassStorage.c b/EdkModulePkg/Bus/Usb/UsbMassStorage/Dxe/UsbMassStorage.c
index 951ab0a186..9caa006715 100644
--- a/EdkModulePkg/Bus/Usb/UsbMassStorage/Dxe/UsbMassStorage.c
+++ b/EdkModulePkg/Bus/Usb/UsbMassStorage/Dxe/UsbMassStorage.c
@@ -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;
}