From: "Ard Biesheuvel" <ard.biesheuvel@arm.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>,
Pete Batard <pete@akeo.ie>, Jared McNeill <jmcneill@invisible.ca>,
Andrei Warkentin <awarkentin@vmware.com>,
Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Subject: [PATCH edk2-platforms v3 5/5] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices()
Date: Mon, 11 May 2020 09:06:56 +0200 [thread overview]
Message-ID: <20200511070656.32141-6-ard.biesheuvel@arm.com> (raw)
In-Reply-To: <20200511070656.32141-1-ard.biesheuvel@arm.com>
When the OS takes over the machine, it calls ExitBootServices() in
order to shut down all resident services and event notifications so
that all asynchronous activity is stopped.
At this point, any DMA masters that are still active should be shut
down. This is especially important for network controllers, since
any activity on the network will trigger DMA writes into memory, which
will no longer be reserved for this purpose once the OS takes over.
So register for the ExitBootServices event, and shut down the controller
at this point if it was started before.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
---
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 4 +++
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 1 +
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 31 ++++++++++++++++++++
3 files changed, 36 insertions(+)
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
index 3cabc5936562..a287f0495ff9 100644
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
@@ -42,6 +42,7 @@ [LibraryClasses]
IoLib
MemoryAllocationLib
NetLib
+ UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib
@@ -50,6 +51,9 @@ [Protocols]
gEfiDevicePathProtocolGuid ## BY_START
gEfiSimpleNetworkProtocolGuid ## BY_START
+[Guids]
+ gEfiEventExitBootServicesGuid
+
[Pcd]
gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset
gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h
index 1dc7a51a1ca6..d03bf8daed58 100644
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h
@@ -203,6 +203,7 @@ typedef struct {
EFI_HANDLE ControllerHandle;
EFI_LOCK Lock;
+ EFI_EVENT ExitBootServicesEvent;
EFI_SIMPLE_NETWORK_PROTOCOL Snp;
EFI_SIMPLE_NETWORK_MODE SnpMode;
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c
index a6102421cc26..29753d8ac754 100644
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c
@@ -76,6 +76,23 @@ GenetDriverBindingSupported (
return Status;
}
+/**
+ Callback function to shut down the network device at ExitBootServices
+
+ @param Event Pointer to this event
+ @param Context Event handler private data
+
+**/
+STATIC
+VOID
+EFIAPI
+GenetNotifyExitBootServices (
+ EFI_EVENT Event,
+ VOID *Context
+ )
+{
+ GenetDisableTxRx ((GENET_PRIVATE_DATA *)Context);
+}
/**
Starts a device controller or a bus controller.
@@ -173,6 +190,17 @@ GenetDriverBindingStart (
CopyMem (&Genet->SnpMode.CurrentAddress, &Genet->Dev->MacAddress,
sizeof(EFI_MAC_ADDRESS));
+ Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
+ GenetNotifyExitBootServices, Genet,
+ &gEfiEventExitBootServicesGuid,
+ &Genet->ExitBootServicesEvent);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN,
+ "GenetDriverBindingStart: failed to register for ExitBootServices event - %r\n",
+ Status));
+ goto FreeDevice;
+ }
+
Status = gBS->InstallMultipleProtocolInterfaces (&ControllerHandle,
&gEfiSimpleNetworkProtocolGuid, &Genet->Snp,
NULL);
@@ -251,6 +279,9 @@ GenetDriverBindingStop (
return Status;
}
+ Status = gBS->CloseEvent (Genet->ExitBootServicesEvent);
+ ASSERT_EFI_ERROR (Status);
+
GenetDmaFree (Genet);
Status = gBS->CloseProtocol (ControllerHandle,
--
2.17.1
next prev parent reply other threads:[~2020-05-11 7:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-11 7:06 [PATCH edk2-platforms v3 0/5] BCM genet fixes Ard Biesheuvel
2020-05-11 7:06 ` [PATCH edk2-platforms v3 1/5] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Ard Biesheuvel
2020-05-11 7:06 ` [PATCH edk2-platforms v3 2/5] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Ard Biesheuvel
2020-05-11 7:06 ` [PATCH edk2-platforms v3 3/5] Silicon/Broadcom/BcmGenetDxe: fix multicast/broadcast handling Ard Biesheuvel
2020-05-11 7:06 ` [PATCH edk2-platforms v3 4/5] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA Ard Biesheuvel
2020-05-11 7:06 ` Ard Biesheuvel [this message]
2020-05-11 9:02 ` [PATCH edk2-platforms v3 0/5] BCM genet fixes Ard Biesheuvel
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=20200511070656.32141-6-ard.biesheuvel@arm.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