From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.13637.1589208948960819546 for ; Mon, 11 May 2020 07:55:49 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 96FC41045; Mon, 11 May 2020 07:55:48 -0700 (PDT) Received: from e123331-lin.nice.arm.com (unknown [10.37.8.255]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 162423F68F; Mon, 11 May 2020 07:55:46 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Pete Batard , Jared McNeill , Andrei Warkentin , Samer El-Haj-Mahmoud , Jeremy Linton Subject: [PATCH edk2-platforms v4 5/9] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() Date: Mon, 11 May 2020 16:55:23 +0200 Message-Id: <20200511145527.23453-6-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200511145527.23453-1-ard.biesheuvel@arm.com> References: <20200511145527.23453-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 --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 4 +++ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 35 +++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index 248164249c6e..9b3dc5e62ecf 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -44,6 +44,7 @@ [LibraryClasses] IoLib MemoryAllocationLib NetLib + UefiBootServicesTableLib UefiDriverEntryPoint UefiLib @@ -52,6 +53,9 @@ [Protocols] gEfiDevicePathProtocolGuid ## BY_START gEfiSimpleNetworkProtocolGuid ## BY_START +[Guids] + gEfiEventExitBootServicesGuid + [FixedPcd] gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index ddfbc0806c07..c43bdbe1d6da 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 dacb3ac7d762..00fbfbc109bb 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -74,6 +74,23 @@ GenetDriverBindingSupported ( return EFI_SUCCESS; } +/** + 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. @@ -171,6 +188,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); @@ -182,12 +210,14 @@ GenetDriverBindingStart ( &gBcmGenetPlatformDeviceProtocolGuid, This->DriverBindingHandle, ControllerHandle); - goto FreeDevice; + goto FreeEvent; } Genet->ControllerHandle = ControllerHandle; return EFI_SUCCESS; +FreeEvent: + gBS->CloseEvent (Genet->ExitBootServicesEvent); FreeDevice: DEBUG ((DEBUG_WARN, "%a: Returning %r\n", __FUNCTION__, Status)); FreePool (Genet); @@ -248,6 +278,9 @@ GenetDriverBindingStop ( return Status; } + Status = gBS->CloseEvent (Genet->ExitBootServicesEvent); + ASSERT_EFI_ERROR (Status); + GenetDmaFree (Genet); Status = gBS->CloseProtocol (ControllerHandle, -- 2.17.1