From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 529B521D492F8 for ; Thu, 7 Sep 2017 15:38:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 80D4580B29; Thu, 7 Sep 2017 22:41:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 80D4580B29 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-54.rdu2.redhat.com [10.10.120.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 112225D967; Thu, 7 Sep 2017 22:41:24 +0000 (UTC) From: Laszlo Ersek To: edk2-devel-01 Cc: Ard Biesheuvel , Brijesh Singh , Eric Dong , Jiewen Yao , Star Zeng Date: Fri, 8 Sep 2017 00:41:09 +0200 Message-Id: <20170907224116.895-4-lersek@redhat.com> In-Reply-To: <20170907224116.895-1-lersek@redhat.com> References: <20170907224116.895-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 07 Sep 2017 22:41:26 +0000 (UTC) Subject: [PATCH 03/10] MdeModulePkg/AtaAtapiPassThru: disable the device at ExitBootServices() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Sep 2017 22:38:35 -0000 The AtaAtapiPassThru driver maps three system memory regions for Bus Master Common Buffer operation on the following call path, if the controller has PCI_CLASS_MASS_STORAGE_SATADPA class code: AtaAtapiPassThruStart() EnumerateAttachedDevice() AhciModeInitialization() AhciCreateTransferDescriptor() The device is disabled (including Bus Master DMA) when the controller is unbound, in AtaAtapiPassThruStop(). Then the regions are unmapped. The former step should also be done when we exit the boot services, and the OS gains ownership of system memory. 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 --- MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h | 6 ++ MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c | 59 +++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h index 85e5a5553953..8d6eac706c0b 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h @@ -119,10 +119,16 @@ typedef struct { // // For Non-blocking. // EFI_EVENT TimerEvent; LIST_ENTRY NonBlockingTaskList; + + // + // For disabling the device (especially Bus Master DMA) at + // ExitBootServices(). + // + EFI_EVENT ExitBootEvent; } ATA_ATAPI_PASS_THRU_INSTANCE; // // Task for Non-blocking mode. // diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c index a48b295d26aa..09064dda18b7 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c @@ -102,11 +102,12 @@ ATA_ATAPI_PASS_THRU_INSTANCE gAtaAtapiPassThruInstanceTemplate = { 0, // PreviousLun NULL, // Timer event { // NonBlocking TaskList NULL, NULL - } + }, + NULL, // ExitBootEvent }; ATAPI_DEVICE_PATH mAtapiDevicePathTemplate = { { MESSAGING_DEVICE_PATH, @@ -476,10 +477,42 @@ InitializeAtaAtapiPassThru ( ASSERT_EFI_ERROR (Status); return Status; } +/** + Disable the device (especially Bus Master DMA) when exiting the boot + services. + + @param[in] Event Event for which this notification function is being + called. + @param[in] Context Pointer to the ATA_ATAPI_PASS_THRU_INSTANCE that + represents the HBA. +**/ +VOID +EFIAPI +AtaPassThruExitBootServices ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + ATA_ATAPI_PASS_THRU_INSTANCE *Instance; + EFI_PCI_IO_PROTOCOL *PciIo; + + DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context)); + + Instance = Context; + PciIo = Instance->PciIo; + + PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationDisable, + Instance->EnabledPciAttributes, + NULL + ); +} + /** Tests to see if this driver supports a given controller. If a child device is provided, it further tests to see if this driver supports creating a handle for the specified child device. This function checks to see if the driver specified by This supports the device specified by @@ -755,10 +788,21 @@ AtaAtapiPassThruStart ( Instance->AtaPassThru.Mode = &Instance->AtaPassThruMode; Instance->ExtScsiPassThru.Mode = &Instance->ExtScsiPassThruMode; InitializeListHead(&Instance->DeviceList); InitializeListHead(&Instance->NonBlockingTaskList); + Status = gBS->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, + TPL_CALLBACK, + AtaPassThruExitBootServices, + Instance, + &Instance->ExitBootEvent + ); + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + Instance->TimerEvent = NULL; Status = gBS->CreateEvent ( EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_NOTIFY, @@ -808,10 +852,14 @@ ErrorExit: if ((Instance != NULL) && (Instance->TimerEvent != NULL)) { gBS->CloseEvent (Instance->TimerEvent); } + if ((Instance != NULL) && (Instance->ExitBootEvent != NULL)) { + gBS->CloseEvent (Instance->ExitBootEvent); + } + // // Remove all inserted ATA devices. // DestroyDeviceInfoList(Instance); @@ -906,10 +954,19 @@ AtaAtapiPassThruStop ( if (Instance->TimerEvent != NULL) { gBS->CloseEvent (Instance->TimerEvent); Instance->TimerEvent = NULL; } DestroyAsynTaskList (Instance, FALSE); + + // + // Close event signaled at gBS->ExitBootServices(). + // + if (Instance->ExitBootEvent != NULL) { + gBS->CloseEvent (Instance->ExitBootEvent); + Instance->ExitBootEvent = NULL; + } + // // Free allocated resource // DestroyDeviceInfoList (Instance); -- 2.14.1.3.gb7cf6e02401b