public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Brijesh Singh <brijesh.singh@amd.com>,
	Eric Dong <eric.dong@intel.com>, Star Zeng <star.zeng@intel.com>
Subject: [PATCH 1/4] MdeModulePkg/UhciDxe: unmap BM common buffers when exiting boot services
Date: Sun,  3 Sep 2017 21:54:46 +0200	[thread overview]
Message-ID: <20170903195449.30261-2-lersek@redhat.com> (raw)
In-Reply-To: <20170903195449.30261-1-lersek@redhat.com>

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 <brijesh.singh@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 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/UhciDxe/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;
 
   Uhc = (USB_HC_DEV *) Context;
 
@@ -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 != NULL) {
+    Uhc->PciIo->Unmap (Uhc->PciIo, Uhc->FrameMapping);
+  }
+
+  //
+  // Unmap the memory pool.
+  //
+  MemPool = Uhc->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




  reply	other threads:[~2017-09-03 19:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-03 19:54 [PATCH 0/4] MdeModulePkg: some PCI HC drivers: unmap common buffers at ExitBootServices() Laszlo Ersek
2017-09-03 19:54 ` Laszlo Ersek [this message]
2017-09-03 19:54 ` [PATCH 2/4] MdeModulePkg/EhciDxe: unmap BM common buffers when exiting boot services Laszlo Ersek
2017-09-03 19:54 ` [PATCH 3/4] MdeModulePkg/XhciDxe: " Laszlo Ersek
2017-09-03 19:54 ` [PATCH 4/4] MdeModulePkg/AtaAtapiPassThru: unmap common buffers at ExitBootServices() Laszlo Ersek
2017-09-04 10:36 ` [PATCH 0/4] MdeModulePkg: some PCI HC drivers: " Zeng, Star
2017-09-04 21:19   ` Laszlo Ersek
2017-09-05  2:18     ` Yao, Jiewen
2017-09-05  9:15       ` Laszlo Ersek
2017-09-05 13:44         ` Yao, Jiewen
2017-09-05 17:57           ` Laszlo Ersek
2017-09-06  4:37             ` Yao, Jiewen
2017-09-06 12:14               ` Laszlo Ersek
2017-09-06 15:39                 ` Brijesh Singh
2017-09-07  4:46                   ` Yao, Jiewen
2017-09-07 11:46                     ` Laszlo Ersek
2017-09-07 14:40                       ` Brijesh Singh
2017-09-07 14:48                         ` Yao, Jiewen
2017-09-07 16:40                           ` Laszlo Ersek
2017-09-07  4:34                 ` Yao, Jiewen
2017-09-07 12:11                   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170903195449.30261-2-lersek@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox