]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/NvmExpressPei: Avoid updating the module-level variable
authorHao Wu <hao.a.wu@intel.com>
Mon, 27 Aug 2018 08:51:45 +0000 (16:51 +0800)
committerHao Wu <hao.a.wu@intel.com>
Fri, 22 Feb 2019 00:20:07 +0000 (08:20 +0800)
This commit is out of the scope for BZ-1409. The commit will remove the
call of RegisterForShadow() at the entry point of the driver. By doing so,
the driver is now possible to be executed without being re-loaded into
permanent memory.

Thus, this commit will update the NvmExpressPei driver to avoid updating
the content of a global variable.

Cc: Jian J Wang <jian.j.wang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
MdeModulePkg/Bus/Pci/NvmExpressPei/DmaMem.c
MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.h

index 51b48d38dd6c81b87eeb079453476363d8a797be..cb629c16b076cbfb0972bf57d504d12f47b777a6 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The DMA memory help function.\r
 \r
-  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions\r
 \r
 #include "NvmExpressPei.h"\r
 \r
-EDKII_IOMMU_PPI  *mIoMmu;\r
+/**\r
+  Get IOMMU PPI.\r
+\r
+  @return Pointer to IOMMU PPI.\r
+\r
+**/\r
+EDKII_IOMMU_PPI *\r
+GetIoMmu (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  EDKII_IOMMU_PPI    *IoMmu;\r
+\r
+  IoMmu  = NULL;\r
+  Status = PeiServicesLocatePpi (\r
+             &gEdkiiIoMmuPpiGuid,\r
+             0,\r
+             NULL,\r
+             (VOID **) &IoMmu\r
+             );\r
+  if (!EFI_ERROR (Status) && (IoMmu != NULL)) {\r
+    return IoMmu;\r
+  }\r
+\r
+  return NULL;\r
+}\r
 \r
 /**\r
   Provides the controller-specific addresses required to access system memory from a\r
@@ -46,18 +72,21 @@ IoMmuMap (
   OUT VOID                  **Mapping\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINT64      Attribute;\r
-\r
-  if (mIoMmu != NULL) {\r
-    Status = mIoMmu->Map (\r
-                       mIoMmu,\r
-                       Operation,\r
-                       HostAddress,\r
-                       NumberOfBytes,\r
-                       DeviceAddress,\r
-                       Mapping\r
-                       );\r
+  EFI_STATUS         Status;\r
+  UINT64             Attribute;\r
+  EDKII_IOMMU_PPI    *IoMmu;\r
+\r
+  IoMmu = GetIoMmu ();\r
+\r
+  if (IoMmu != NULL) {\r
+    Status = IoMmu->Map (\r
+                     IoMmu,\r
+                     Operation,\r
+                     HostAddress,\r
+                     NumberOfBytes,\r
+                     DeviceAddress,\r
+                     Mapping\r
+                     );\r
     if (EFI_ERROR (Status)) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
@@ -78,11 +107,11 @@ IoMmuMap (
       ASSERT(FALSE);\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-    Status = mIoMmu->SetAttribute (\r
-                       mIoMmu,\r
-                       *Mapping,\r
-                       Attribute\r
-                       );\r
+    Status = IoMmu->SetAttribute (\r
+                      IoMmu,\r
+                      *Mapping,\r
+                      Attribute\r
+                      );\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -108,11 +137,14 @@ IoMmuUnmap (
   IN VOID                  *Mapping\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS         Status;\r
+  EDKII_IOMMU_PPI    *IoMmu;\r
+\r
+  IoMmu = GetIoMmu ();\r
 \r
-  if (mIoMmu != NULL) {\r
-    Status = mIoMmu->SetAttribute (mIoMmu, Mapping, 0);\r
-    Status = mIoMmu->Unmap (mIoMmu, Mapping);\r
+  if (IoMmu != NULL) {\r
+    Status = IoMmu->SetAttribute (IoMmu, Mapping, 0);\r
+    Status = IoMmu->Unmap (IoMmu, Mapping);\r
   } else {\r
     Status = EFI_SUCCESS;\r
   }\r
@@ -148,39 +180,42 @@ IoMmuAllocateBuffer (
   EFI_STATUS            Status;\r
   UINTN                 NumberOfBytes;\r
   EFI_PHYSICAL_ADDRESS  HostPhyAddress;\r
+  EDKII_IOMMU_PPI       *IoMmu;\r
 \r
   *HostAddress = NULL;\r
   *DeviceAddress = 0;\r
 \r
-  if (mIoMmu != NULL) {\r
-    Status = mIoMmu->AllocateBuffer (\r
-                       mIoMmu,\r
-                       EfiBootServicesData,\r
-                       Pages,\r
-                       HostAddress,\r
-                       0\r
-                       );\r
+  IoMmu = GetIoMmu ();\r
+\r
+  if (IoMmu != NULL) {\r
+    Status = IoMmu->AllocateBuffer (\r
+                      IoMmu,\r
+                      EfiBootServicesData,\r
+                      Pages,\r
+                      HostAddress,\r
+                      0\r
+                      );\r
     if (EFI_ERROR (Status)) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
     NumberOfBytes = EFI_PAGES_TO_SIZE(Pages);\r
-    Status = mIoMmu->Map (\r
-                       mIoMmu,\r
-                       EdkiiIoMmuOperationBusMasterCommonBuffer,\r
-                       *HostAddress,\r
-                       &NumberOfBytes,\r
-                       DeviceAddress,\r
-                       Mapping\r
-                       );\r
+    Status = IoMmu->Map (\r
+                      IoMmu,\r
+                      EdkiiIoMmuOperationBusMasterCommonBuffer,\r
+                      *HostAddress,\r
+                      &NumberOfBytes,\r
+                      DeviceAddress,\r
+                      Mapping\r
+                      );\r
     if (EFI_ERROR (Status)) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    Status = mIoMmu->SetAttribute (\r
-                       mIoMmu,\r
-                       *Mapping,\r
-                       EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE\r
-                       );\r
+    Status = IoMmu->SetAttribute (\r
+                      IoMmu,\r
+                      *Mapping,\r
+                      EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE\r
+                      );\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -219,31 +254,17 @@ IoMmuFreeBuffer (
   IN VOID                   *Mapping\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS         Status;\r
+  EDKII_IOMMU_PPI    *IoMmu;\r
 \r
-  if (mIoMmu != NULL) {\r
-    Status = mIoMmu->SetAttribute (mIoMmu, Mapping, 0);\r
-    Status = mIoMmu->Unmap (mIoMmu, Mapping);\r
-    Status = mIoMmu->FreeBuffer (mIoMmu, Pages, HostAddress);\r
+  IoMmu = GetIoMmu ();\r
+\r
+  if (IoMmu != NULL) {\r
+    Status = IoMmu->SetAttribute (IoMmu, Mapping, 0);\r
+    Status = IoMmu->Unmap (IoMmu, Mapping);\r
+    Status = IoMmu->FreeBuffer (IoMmu, Pages, HostAddress);\r
   } else {\r
     Status = EFI_SUCCESS;\r
   }\r
   return Status;\r
 }\r
-\r
-/**\r
-  Initialize IOMMU.\r
-**/\r
-VOID\r
-IoMmuInit (\r
-  VOID\r
-  )\r
-{\r
-  PeiServicesLocatePpi (\r
-    &gEdkiiIoMmuPpiGuid,\r
-    0,\r
-    NULL,\r
-    (VOID **)&mIoMmu\r
-    );\r
-}\r
-\r
index fabec37e3665dfcb2d2977df258d123ee90b8fc0..2fe73e942c688123893b4c51fecc1c714dfcd472 100644 (file)
@@ -2,7 +2,7 @@
   The NvmExpressPei driver is used to manage non-volatile memory subsystem\r
   which follows NVM Express specification at PEI phase.\r
 \r
-  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions\r
@@ -214,13 +214,6 @@ NvmExpressPeimEntry (
   PEI_NVME_CONTROLLER_PRIVATE_DATA         *Private;\r
   EFI_PHYSICAL_ADDRESS                     DeviceAddress;\r
 \r
-  //\r
-  // Shadow this PEIM to run from memory\r
-  //\r
-  if (!EFI_ERROR (PeiServicesRegisterForShadow (FileHandle))) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
   //\r
   // Locate the NVME host controller PPI\r
   //\r
@@ -235,8 +228,6 @@ NvmExpressPeimEntry (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  IoMmuInit ();\r
-\r
   Controller = 0;\r
   MmioBase   = 0;\r
   while (TRUE) {\r
index 0bd62c24596533fae9330af605ae016f3162cdf6..0135eca6f0489d848442108a4e3cdacfc956359c 100644 (file)
@@ -2,7 +2,7 @@
   The NvmExpressPei driver is used to manage non-volatile memory subsystem\r
   which follows NVM Express specification at PEI phase.\r
 \r
-  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions\r
@@ -147,13 +147,9 @@ struct _PEI_NVME_CONTROLLER_PRIVATE_DATA {
   CR (a, PEI_NVME_CONTROLLER_PRIVATE_DATA, EndOfPeiNotifyList, NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)\r
 \r
 \r
-/**\r
-  Initialize IOMMU.\r
-**/\r
-VOID\r
-IoMmuInit (\r
-  VOID\r
-  );\r
+//\r
+// Internal functions\r
+//\r
 \r
 /**\r
   Allocates pages that are suitable for an OperationBusMasterCommonBuffer or\r