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 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) 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 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) From: Laszlo Ersek To: edk2-devel-01 Cc: Brijesh Singh , Eric Dong , Star Zeng 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: [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: , X-List-Received-Date: Sun, 03 Sep 2017 19:52:10 -0000 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/EhciDxe/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 ( ) { - USB2_HC_DEV *Ehc; + USB2_HC_DEV *Ehc; + USBHC_MEM_POOL *MemPool; + USBHC_MEM_BLOCK *MemBlock; Ehc = (USB2_HC_DEV *) Context; @@ -1652,6 +1654,27 @@ EhcExitBootService ( // Reset the Host Controller // EhcResetHC (Ehc, EHC_RESET_TIMEOUT); + + // + // Unmap the frame list. + // + if (Ehc->PeriodFrame != NULL) { + Ehc->PciIo->Unmap (Ehc->PciIo, Ehc->PeriodFrameMap); + } + + // + // Unmap the memory pool. + // + MemPool = Ehc->MemPool; + if (MemPool != NULL) { + for (MemBlock = MemPool->Head; + MemBlock != NULL; + MemBlock = MemBlock->Next) { + if (MemBlock->BufHost != NULL) { + MemPool->PciIo->Unmap (MemPool->PciIo, MemBlock->Mapping); + } + } + } } -- 2.14.1.3.gb7cf6e02401b