From 509daa658b79b21eb1ccd6230065867e22707a42 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Thu, 7 Sep 2017 21:04:29 +0200 Subject: [PATCH] MdeModulePkg/AtaAtapiPassThru: unmap DMA buffers after disabling BM DMA In AtaAtapiPassThruStop(), if the device has been operating in AHCI mode, we unmap the DMA buffers and then disable the device (including bus master DMA). The order of these actions is wrong; we shouldn't unmap DMA buffers until bus master DMA is turned off. Reverse the steps. Cc: Ard Biesheuvel Cc: Brijesh Singh Cc: Eric Dong Cc: Jiewen Yao Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Jiewen Yao Reviewed-by: Star Zeng Reviewed-by: Ard Biesheuvel --- .../Ata/AtaAtapiPassThru/AtaAtapiPassThru.c | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c index b7fdb8dd48..a48b295d26 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c @@ -913,12 +913,22 @@ AtaAtapiPassThruStop ( // DestroyDeviceInfoList (Instance); + PciIo = Instance->PciIo; + + // + // Disable this ATA host controller. + // + PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationDisable, + Instance->EnabledPciAttributes, + NULL + ); + // // If the current working mode is AHCI mode, then pre-allocated resource // for AHCI initialization should be released. // - PciIo = Instance->PciIo; - if (Instance->Mode == EfiAtaAhciMode) { AhciRegisters = &Instance->AhciRegisters; PciIo->Unmap ( @@ -950,16 +960,6 @@ AtaAtapiPassThruStop ( ); } - // - // Disable this ATA host controller. - // - PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationDisable, - Instance->EnabledPciAttributes, - NULL - ); - // // Restore original PCI attributes //