From c094abe5852057ef47941d8de3af20b2286cd822 Mon Sep 17 00:00:00 2001 From: qwang12 Date: Mon, 12 Mar 2007 07:47:33 +0000 Subject: 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 --- EdkModulePkg/Bus/Pci/IdeBus/Dxe/idebus.c | 43 ++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'EdkModulePkg/Bus/Pci') 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; } // -- cgit v1.2.3