Browse Source

NetworkPkg/SnpDxe: Add PCD to remove ExitBootServices event from SNP driver.

Patch addresses Bugzilla #1974.

During ExitBootServices stage, drivers should not call any
functions known to use Memory Allocation Services. One of such
functions (as per UEFI spec) is UNDI->Shutdown().

Since UNDI drivers during ExitBootServices phase are expected
to put the adapter to such a state that it will not perform any DMA
operations, there is no need to interface UNDI by SNP driver during
that phase.

Finally, since ExitBootServices event notification function in SNP
only calls UNDI->Shutdown() and Stop() functions, there is no need
to create this event at all. Adding PCD to control creation of event
reacting to ExitBootServices() call so that systems with UNDIs relying
on SNP to call their Shutdown() and Stop() can still work.

Change-Id: Idd76f26d2e8ff7cf88b2d75e2d524c74211f2e89
Reviewed-by: Siyuan Fu <siyuan.fu@intel.com>
Signed-off-by: Maciej Rabeda <maciej.rabeda@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Rabeda, Maciej 4 years ago
parent
commit
61bb6eeb4d
4 changed files with 35 additions and 20 deletions
  1. 7 0
      NetworkPkg/NetworkPkg.dec
  2. 22 18
      NetworkPkg/SnpDxe/Snp.c
  3. 2 1
      NetworkPkg/SnpDxe/Snp.h
  4. 4 1
      NetworkPkg/SnpDxe/SnpDxe.inf

+ 7 - 0
NetworkPkg/NetworkPkg.dec

@@ -109,6 +109,13 @@
   # @Prompt TFTP block size.
   gEfiNetworkPkgTokenSpaceGuid.PcdTftpBlockSize|0x0|UINT64|0x1000000B
 
+  ## Indicates whether SnpDxe driver will create an event that will be notified
+  # upon gBS->ExitBootServices() call.
+  # TRUE - Event being triggered upon ExitBootServices call will be created
+  # FALSE - Event being triggered upon ExitBootServices call will NOT be created
+  # @Prompt Indicates whether SnpDxe creates event for ExitBootServices() call.
+  gEfiNetworkPkgTokenSpaceGuid.PcdSnpCreateExitBootServicesEvent|TRUE|BOOLEAN|0x1000000C
+
 [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
   ## IPv6 DHCP Unique Identifier (DUID) Type configuration (From RFCs 3315 and 6355).
   # 01 = DUID Based on Link-layer Address Plus Time [DUID-LLT]

+ 22 - 18
NetworkPkg/SnpDxe/Snp.c

@@ -1,7 +1,7 @@
 /** @file
   Implementation of driver entry point and driver binding protocol.
 
-Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -647,19 +647,21 @@ SimpleNetworkDriverStart (
   PxeShutdown (Snp);
   PxeStop (Snp);
 
-  //
-  // Create EXIT_BOOT_SERIVES Event
-  //
-  Status = gBS->CreateEventEx (
-                  EVT_NOTIFY_SIGNAL,
-                  TPL_NOTIFY,
-                  SnpNotifyExitBootServices,
-                  Snp,
-                  &gEfiEventExitBootServicesGuid,
-                  &Snp->ExitBootServicesEvent
-                  );
-  if (EFI_ERROR (Status)) {
-    goto Error_DeleteSNP;
+  if (FixedPcdGetBool (PcdSnpCreateExitBootServicesEvent)) {
+    //
+    // Create EXIT_BOOT_SERIVES Event
+    //
+    Status = gBS->CreateEventEx (
+                    EVT_NOTIFY_SIGNAL,
+                    TPL_NOTIFY,
+                    SnpNotifyExitBootServices,
+                    Snp,
+                    &gEfiEventExitBootServicesGuid,
+                    &Snp->ExitBootServicesEvent
+                    );
+    if (EFI_ERROR (Status)) {
+      goto Error_DeleteSNP;
+    }
   }
 
   //
@@ -778,10 +780,12 @@ SimpleNetworkDriverStop (
     return Status;
   }
 
-  //
-  // Close EXIT_BOOT_SERIVES Event
-  //
-  gBS->CloseEvent (Snp->ExitBootServicesEvent);
+  if (FixedPcdGetBool (PcdSnpCreateExitBootServicesEvent)) {
+    //
+    // Close EXIT_BOOT_SERIVES Event
+    //
+    gBS->CloseEvent (Snp->ExitBootServicesEvent);
+  }
 
   Status = gBS->CloseProtocol (
                   Controller,

+ 2 - 1
NetworkPkg/SnpDxe/Snp.h

@@ -1,7 +1,7 @@
 /** @file
     Declaration of strctures and functions for SnpDxe driver.
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -26,6 +26,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/UefiLib.h>
 #include <Library/MemoryAllocationLib.h>
 #include <Library/PrintLib.h>
+#include <Library/PcdLib.h>
 
 #include <IndustryStandard/Pci.h>
 #include <IndustryStandard/Acpi.h>

+ 4 - 1
NetworkPkg/SnpDxe/SnpDxe.inf

@@ -4,7 +4,7 @@
 #  This module produces Simple Network Protocol upon EFI Network Interface
 #  Identifier Protocol, to provide a packet level interface to a network adapter.
 #
-#  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -73,5 +73,8 @@
   gEfiNetworkInterfaceIdentifierProtocolGuid_31 ## TO_START
   gEfiPciIoProtocolGuid                         ## TO_START
 
+[Pcd]
+  gEfiNetworkPkgTokenSpaceGuid.PcdSnpCreateExitBootServicesEvent   ## CONSUMES
+
 [UserExtensions.TianoCore."ExtraFiles"]
   SnpDxeExtra.uni