From nobody Thu May 2 18:47:34 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1504468499183705.741888030629; Sun, 3 Sep 2017 12:54:59 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9B90421E74928; Sun, 3 Sep 2017 12:52:09 -0700 (PDT) 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 57B2821E2BE36 for ; Sun, 3 Sep 2017 12:52:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00D0083F3D; Sun, 3 Sep 2017 19:54:55 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-188.rdu2.redhat.com [10.10.120.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5F3B5D75C; Sun, 3 Sep 2017 19:54:53 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 00D0083F3D Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com From: Laszlo Ersek To: edk2-devel-01 Date: Sun, 3 Sep 2017 21:54:46 +0200 Message-Id: <20170903195449.30261-2-lersek@redhat.com> In-Reply-To: <20170903195449.30261-1-lersek@redhat.com> References: <20170903195449.30261-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sun, 03 Sep 2017 19:54:55 +0000 (UTC) Subject: [edk2] [PATCH 1/4] MdeModulePkg/UhciDxe: unmap BM common buffers when exiting boot services 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: , Cc: Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Section 7.7 Adding the Exit Boot Services feature in Driver Writer's Guide for UEFI 2.3.1 (v1.01) writes, > Examples from the EDK II that use this feature are the PCI device > drivers for USB Host Controllers. Some USB Host Controllers are PCI Bus > Masters that continuously access a memory buffer to poll for operation > requests. Access to this memory buffer by a USB Host Controller may be > required to boot an operation system, but this activity must be > terminated when the OS calls ExitBootServices() . The typical action in > the Exit Boot Services Event for these types of drivers is to disable > the PCI bus master and place the USB Host Controller into a halted > state. UhcExitBootService() already resets the host controller, which causes the host controller to forget about all common buffers configured previously. However, if the system has a component that translates device addresses to system memory addresses (such as an IOMMU), then the translations put in place when the common buffers were originally mapped should also be undone, before handing control to the OS. UhciDxe maps two kinds of common buffers: (1) The Frame List is initially mapped in UhciDriverBindingStart() UhciInitFrameList() and it is unmapped and mapped again, for an unspecified number of times, in Uhci2Reset() UhciDestoryFrameList() UhciInitFrameList() (2) Memory blocks in the USB Host Controller memory pool are first added in UhciDriverBindingStart() UhciAllocateDev() UsbHcInitMemPool() UsbHcAllocMemBlock() and then for an unspecified number of times in UsbHcAllocateMem() UsbHcAllocMemBlock() whenever the pool has to be extended. Both kinds of common buffers are unmapped in the following call tree: UhciDriverBindingStop() UhciCleanDevUp() UhciDestoryFrameList() <- UhciFreeDev() UsbHcFreeMemPool() UsbHcFreeMemBlock() <- The common buffers should be unmapped at ExitBootServices() the same way. In that context however, we must not free memory (because that could alter the UEFI memory map, which is forbidden for ExitBootServices() notification functions). So call PciIo->Unmap() without calling PciIo->FreeBuffer(). Cc: Brijesh Singh Cc: Eric Dong Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c b/MdeModulePkg/Bus/Pci/Uhc= iDxe/Uhci.c index 1fcc8b5f320f..cd9407faf22a 100644 --- a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c +++ b/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c @@ -1594,7 +1594,9 @@ UhcExitBootService ( VOID *Context ) { - USB_HC_DEV *Uhc; + USB_HC_DEV *Uhc; + USBHC_MEM_POOL *MemPool; + USBHC_MEM_BLOCK *MemBlock; =20 Uhc =3D (USB_HC_DEV *) Context; =20 @@ -1608,6 +1610,27 @@ UhcExitBootService ( // UhciSetRegBit (Uhc->PciIo, USBCMD_OFFSET, USBCMD_HCRESET); gBS->Stall (UHC_ROOT_PORT_RECOVERY_STALL); + + // + // Unmap the frame list. + // + if (Uhc->FrameBase !=3D NULL) { + Uhc->PciIo->Unmap (Uhc->PciIo, Uhc->FrameMapping); + } + + // + // Unmap the memory pool. + // + MemPool =3D Uhc->MemPool; + if (MemPool !=3D NULL) { + for (MemBlock =3D MemPool->Head; + MemBlock !=3D NULL; + MemBlock =3D MemBlock->Next) { + if (MemBlock->BufHost !=3D NULL) { + MemPool->PciIo->Unmap (MemPool->PciIo, MemBlock->Mapping); + } + } + } } =20 /** --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 18:47:34 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1504468501914249.87624372166863; Sun, 3 Sep 2017 12:55:01 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DF1CD21E7492C; Sun, 3 Sep 2017 12:52:10 -0700 (PDT) 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 1834921E2BE36 for ; Sun, 3 Sep 2017 12:52:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FD5A356C9; Sun, 3 Sep 2017 19:54:56 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-188.rdu2.redhat.com [10.10.120.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F2765D75E; Sun, 3 Sep 2017 19:54:55 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9FD5A356C9 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com From: Laszlo Ersek To: edk2-devel-01 Date: Sun, 3 Sep 2017 21:54:47 +0200 Message-Id: <20170903195449.30261-3-lersek@redhat.com> In-Reply-To: <20170903195449.30261-1-lersek@redhat.com> References: <20170903195449.30261-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 03 Sep 2017 19:54:56 +0000 (UTC) Subject: [edk2] [PATCH 2/4] MdeModulePkg/EhciDxe: unmap BM common buffers when exiting boot services 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: , Cc: Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Section 7.7 Adding the Exit Boot Services feature in Driver Writer's Guide for UEFI 2.3.1 (v1.01) writes, > Examples from the EDK II that use this feature are the PCI device > drivers for USB Host Controllers. Some USB Host Controllers are PCI Bus > Masters that continuously access a memory buffer to poll for operation > requests. Access to this memory buffer by a USB Host Controller may be > required to boot an operation system, but this activity must be > terminated when the OS calls ExitBootServices() . The typical action in > the Exit Boot Services Event for these types of drivers is to disable > the PCI bus master and place the USB Host Controller into a halted > state. EhcExitBootService() already resets the host controller, which causes the host controller to forget about all common buffers configured previously. However, if the system has a component that translates device addresses to system memory addresses (such as an IOMMU), then the translations put in place when the common buffers were originally mapped should also be undone, before handing control to the OS. EhciDxe maps two kinds of common buffers: (1) The Frame List is initially mapped in EhcDriverBindingStart() EhcInitHC() EhcInitSched() and it is unmapped and mapped again, for an unspecified number of times, in EhcReset() EhcFreeSched() EhcInitHC() EhcInitSched() (2) Memory blocks in the USB Host Controller memory pool are first added in UhciDriverBindingStart() EhcInitHC() EhcInitSched() UsbHcInitMemPool() UsbHcAllocMemBlock() then for an unspecified number of times in UsbHcAllocateMem() UsbHcAllocMemBlock() whenever the pool has to be extended. Memory blocks are also unmapped and mapped again in EhcReset() EhcFreeSched() UsbHcFreeMemPool() UsbHcFreeMemBlock() EhcInitHC() EhcInitSched() UsbHcInitMemPool() UsbHcAllocMemBlock() Both kinds of common buffers are unmapped in the following call tree: EhcDriverBindingStop() EhcFreeSched() <- UsbHcFreeMemPool() UsbHcFreeMemBlock() The common buffers should be unmapped at ExitBootServices() the same way. In that context however, we must not free memory (because that could alter the UEFI memory map, which is forbidden for ExitBootServices() notification functions). So call PciIo->Unmap() without calling PciIo->FreeBuffer(). Cc: Brijesh Singh Cc: Eric Dong Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/Ehc= iDxe/Ehci.c index 5173a9d599c5..441366244c9a 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c @@ -1644,7 +1644,9 @@ EhcExitBootService ( ) =20 { - USB2_HC_DEV *Ehc; + USB2_HC_DEV *Ehc; + USBHC_MEM_POOL *MemPool; + USBHC_MEM_BLOCK *MemBlock; =20 Ehc =3D (USB2_HC_DEV *) Context; =20 @@ -1652,6 +1654,27 @@ EhcExitBootService ( // Reset the Host Controller // EhcResetHC (Ehc, EHC_RESET_TIMEOUT); + + // + // Unmap the frame list. + // + if (Ehc->PeriodFrame !=3D NULL) { + Ehc->PciIo->Unmap (Ehc->PciIo, Ehc->PeriodFrameMap); + } + + // + // Unmap the memory pool. + // + MemPool =3D Ehc->MemPool; + if (MemPool !=3D NULL) { + for (MemBlock =3D MemPool->Head; + MemBlock !=3D NULL; + MemBlock =3D MemBlock->Next) { + if (MemBlock->BufHost !=3D NULL) { + MemPool->PciIo->Unmap (MemPool->PciIo, MemBlock->Mapping); + } + } + } } =20 =20 --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 18:47:34 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 150446850482181.08236308399239; Sun, 3 Sep 2017 12:55:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 254B621E7492B; Sun, 3 Sep 2017 12:52:13 -0700 (PDT) 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 0B77A21E2BE36 for ; Sun, 3 Sep 2017 12:52:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA79F883B1; Sun, 3 Sep 2017 19:54:58 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-188.rdu2.redhat.com [10.10.120.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A9385D75C; Sun, 3 Sep 2017 19:54:57 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AA79F883B1 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com From: Laszlo Ersek To: edk2-devel-01 Date: Sun, 3 Sep 2017 21:54:48 +0200 Message-Id: <20170903195449.30261-4-lersek@redhat.com> In-Reply-To: <20170903195449.30261-1-lersek@redhat.com> References: <20170903195449.30261-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 03 Sep 2017 19:54:58 +0000 (UTC) Subject: [edk2] [PATCH 3/4] MdeModulePkg/XhciDxe: unmap BM common buffers when exiting boot services 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: , Cc: Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Section 7.7 Adding the Exit Boot Services feature in Driver Writer's Guide for UEFI 2.3.1 (v1.01) writes, > Examples from the EDK II that use this feature are the PCI device > drivers for USB Host Controllers. Some USB Host Controllers are PCI Bus > Masters that continuously access a memory buffer to poll for operation > requests. Access to this memory buffer by a USB Host Controller may be > required to boot an operation system, but this activity must be > terminated when the OS calls ExitBootServices() . The typical action in > the Exit Boot Services Event for these types of drivers is to disable > the PCI bus master and place the USB Host Controller into a halted > state. XhcExitBootService() already halts the host controller, which causes the host controller to forget about all common buffers configured previously. However, if the system has a component that translates device addresses to system memory addresses (such as an IOMMU), then the translations put in place when the common buffers were originally mapped should also be undone, before handing control to the OS. XhciDxe maps three kinds of common buffers: (1) The Scratchpad Buffer Array, and (2) the Scratchpad Buffers pointed-to by elements of the Scratchpad Buffer Array, are initially mapped in XhcDriverBindingStart() XhcInitSched() UsbHcAllocateAlignedPages() and they are unmapped and mapped again, for an unspecified number of times, in XhcReset() XhcFreeSched() UsbHcFreeAlignedPages() XhcInitSched() UsbHcAllocateAlignedPages() (3) Memory blocks in the USB Host Controller memory pool are first added in XhcDriverBindingStart() XhcInitSched() UsbHcInitMemPool() UsbHcAllocMemBlock() and then for an unspecified number of times in UsbHcAllocateMem() UsbHcAllocMemBlock() whenever the pool has to be extended. Memory blocks are also unmapped and mapped again in XhcReset() XhcFreeSched() UsbHcFreeMemPool() UsbHcFreeMemBlock() XhcInitSched() UsbHcInitMemPool() UsbHcAllocMemBlock() All three kinds of common buffers are unmapped in the following call tree: XhcDriverBindingStop() XhcFreeSched() UsbHcFreeAlignedPages() <- UsbHcFreeMemPool() UsbHcFreeMemBlock() <- The common buffers should be unmapped at ExitBootServices() the same way. In that context however, we must not free memory (because that could alter the UEFI memory map, which is forbidden for ExitBootServices() notification functions). So call PciIo->Unmap() without calling PciIo->FreeBuffer(). Cc: Brijesh Singh Cc: Eric Dong Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/Xhc= iDxe/Xhci.c index c884f4c3146c..d2a04492510f 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -1859,6 +1859,9 @@ XhcExitBootService ( { USB_XHCI_INSTANCE *Xhc; EFI_PCI_IO_PROTOCOL *PciIo; + UINT32 Index; + USBHC_MEM_POOL *MemPool; + USBHC_MEM_BLOCK *MemBlock; =20 Xhc =3D (USB_XHCI_INSTANCE*) Context; PciIo =3D Xhc->PciIo; @@ -1885,6 +1888,34 @@ XhcExitBootService ( Xhc->OriginalPciAttributes, NULL ); + + // + // Unmap Scratchpad Buffers and Scratchpad Buffer Array. + // + if (Xhc->MaxScratchpadBufs > 0) { + for (Index =3D 0; Index < Xhc->MaxScratchpadBufs; Index++) { + if ((VOID *)(UINTN)Xhc->ScratchEntry[Index] !=3D NULL) { + PciIo->Unmap (PciIo, (VOID *)Xhc->ScratchEntryMap[Index]); + } + } + if (Xhc->ScratchBuf !=3D NULL) { + PciIo->Unmap (PciIo, Xhc->ScratchMap); + } + } + + // + // Unmap the memory pool. + // + MemPool =3D Xhc->MemPool; + if (MemPool !=3D NULL) { + for (MemBlock =3D MemPool->Head; + MemBlock !=3D NULL; + MemBlock =3D MemBlock->Next) { + if (MemBlock->BufHost !=3D NULL) { + MemPool->PciIo->Unmap (MemPool->PciIo, MemBlock->Mapping); + } + } + } } =20 /** --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 18:47:34 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1504468508465312.8956963848111; Sun, 3 Sep 2017 12:55:08 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 612FC21E74936; Sun, 3 Sep 2017 12:52:15 -0700 (PDT) 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 B442521E2BE36 for ; Sun, 3 Sep 2017 12:52:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56A14883B9; Sun, 3 Sep 2017 19:55:00 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-188.rdu2.redhat.com [10.10.120.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 146815D75C; Sun, 3 Sep 2017 19:54:58 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 56A14883B9 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com From: Laszlo Ersek To: edk2-devel-01 Date: Sun, 3 Sep 2017 21:54:49 +0200 Message-Id: <20170903195449.30261-5-lersek@redhat.com> In-Reply-To: <20170903195449.30261-1-lersek@redhat.com> References: <20170903195449.30261-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 03 Sep 2017 19:55:00 +0000 (UTC) Subject: [edk2] [PATCH 4/4] MdeModulePkg/AtaAtapiPassThru: unmap common buffers 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: , Cc: Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The AtaAtapiPassThru() driver maps three system memory regions for Bus Master Common Buffer operation on the following call path, if the controller being bound has PCI_CLASS_MASS_STORAGE_SATADPA class code: AtaAtapiPassThruStart() EnumerateAttachedDevice() AhciModeInitialization() AhciCreateTransferDescriptor() The regions are unmapped when the controller is unbound, in AtaAtapiPassThruStop(). The common buffers should also be de-programmed when we exit the boot services and the OS gains ownership of the system memory. Introduce an ExitBootServices() notification function that - resets the controller so that it forgets the device addresses for the common buffers, - unmaps the common buffers so that device-to-RAM address translations (in a potential IOMMU or another translator) are torn down. ExitBootServices() notification functions must not alter the UEFI memory map, thus call only PciIo->Unmap(), and not PciIo->FreeBuffer(). (Unlike AtaAtapiPassThruStop() does.) Cc: Brijesh Singh Cc: Eric Dong Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h | 18 ++++++ MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h | 5 ++ MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c | 67 ++++++++++++= +++++++- 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h b/MdeModulePk= g/Bus/Ata/AtaAtapiPassThru/AhciMode.h index 809bcc307fc4..d085597fbdfe 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h @@ -367,5 +367,23 @@ AhciStopCommand ( IN UINT64 Timeout ); =20 +/** + Do AHCI HBA reset. + + @param PciIo The PCI IO protocol instance. + @param Timeout The timeout value of reset, uses 100ns as a u= nit. + + @retval EFI_DEVICE_ERROR AHCI controller is failed to complete hardware + reset. + @retval EFI_TIMEOUT The reset operation is time out. + @retval EFI_SUCCESS AHCI controller is reset successfully. + +**/ +EFI_STATUS +EFIAPI +AhciReset ( + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN UINT64 Timeout + ); #endif =20 diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h b/Mde= ModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h index 4f327dc30b60..e51c66f392d2 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h @@ -120,6 +120,11 @@ typedef struct { // EFI_EVENT TimerEvent; LIST_ENTRY NonBlockingTaskList; + + // + // For resetting AHCI and unmapping CommonBuffer DMA at ExitBootServices= (). + // + EFI_EVENT ExitBootEvent; } ATA_ATAPI_PASS_THRU_INSTANCE; =20 // diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c b/Mde= ModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c index 795443ef74f6..6972349b2b8f 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c @@ -103,7 +103,8 @@ ATA_ATAPI_PASS_THRU_INSTANCE gAtaAtapiPassThruInstanceT= emplate =3D { { // NonBlocking TaskList NULL, NULL - } + }, + NULL, // ExitBootEvent }; =20 ATAPI_DEVICE_PATH mAtapiDevicePathTemplate =3D { @@ -477,6 +478,50 @@ InitializeAtaAtapiPassThru ( return Status; } =20 +/** + If operating in AHCI mode, then reset the HBA and unmap CommonBuffer 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; + EFI_AHCI_REGISTERS *AhciRegisters; + + Instance =3D Context; + + if (Instance->Mode =3D=3D EfiAtaAhciMode) { + PciIo =3D Instance->PciIo; + AhciRegisters =3D &Instance->AhciRegisters; + // + // De-program common buffer references from the HBA by resetting the H= BA. + // + AhciReset (PciIo, EFI_AHCI_BUS_RESET_TIMEOUT); + // + // Unmap long-lived common buffers. + // + if (AhciRegisters->AhciRFis !=3D NULL) { + PciIo->Unmap (PciIo, AhciRegisters->MapRFis); + } + if (AhciRegisters->AhciCmdList !=3D NULL) { + PciIo->Unmap (PciIo, AhciRegisters->MapCmdList); + } + if (AhciRegisters->AhciCommandTable !=3D NULL) { + PciIo->Unmap (PciIo, AhciRegisters->MapCommandTable); + } + } +} + /** Tests to see if this driver supports a given controller. If a child devi= ce is provided, it further tests to see if this driver supports creating a handle for th= e specified child device. @@ -755,6 +800,17 @@ AtaAtapiPassThruStart ( InitializeListHead(&Instance->DeviceList); InitializeListHead(&Instance->NonBlockingTaskList); =20 + Status =3D gBS->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, + TPL_CALLBACK, + AtaPassThruExitBootServices, + Instance, + &Instance->ExitBootEvent + ); + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + Instance->TimerEvent =3D NULL; =20 Status =3D gBS->CreateEvent ( @@ -808,6 +864,10 @@ ErrorExit: gBS->CloseEvent (Instance->TimerEvent); } =20 + if ((Instance !=3D NULL) && (Instance->ExitBootEvent !=3D NULL)) { + gBS->CloseEvent (Instance->ExitBootEvent); + } + // // Remove all inserted ATA devices. // @@ -912,6 +972,11 @@ AtaAtapiPassThruStop ( // DestroyDeviceInfoList (Instance); =20 + if (Instance->ExitBootEvent !=3D NULL) { + gBS->CloseEvent (Instance->ExitBootEvent); + Instance->ExitBootEvent =3D NULL; + } + // // If the current working mode is AHCI mode, then pre-allocated resource // for AHCI initialization should be released. --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel