]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciHostBridgeDxe / PciRootBridgeIo.c
index 2c373e41de4d24a92ad9e9def016505a704a40d6..d304fae4222affa08619a29b6b8aaaa944c5932f 100644 (file)
@@ -3,13 +3,7 @@
   PCI Root Bridge Io Protocol code.\r
 \r
 Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -17,10 +11,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "PciRootBridge.h"\r
 #include "PciHostResource.h"\r
 \r
-extern EDKII_IOMMU_PROTOCOL        *mIoMmuProtocol;\r
-\r
 #define NO_MAPPING  (VOID *) (UINTN) -1\r
 \r
+#define RESOURCE_VALID(Resource) ((Resource)->Base <= (Resource)->Limit)\r
+\r
 //\r
 // Lookup table for increment values based on transfer widths\r
 //\r
@@ -122,25 +116,25 @@ CreateRootBridge (
   //\r
   // Make sure Mem and MemAbove4G apertures are valid\r
   //\r
-  if (Bridge->Mem.Base <= Bridge->Mem.Limit) {\r
+  if (RESOURCE_VALID (&Bridge->Mem)) {\r
     ASSERT (Bridge->Mem.Limit < SIZE_4GB);\r
     if (Bridge->Mem.Limit >= SIZE_4GB) {\r
       return NULL;\r
     }\r
   }\r
-  if (Bridge->MemAbove4G.Base <= Bridge->MemAbove4G.Limit) {\r
+  if (RESOURCE_VALID (&Bridge->MemAbove4G)) {\r
     ASSERT (Bridge->MemAbove4G.Base >= SIZE_4GB);\r
     if (Bridge->MemAbove4G.Base < SIZE_4GB) {\r
       return NULL;\r
     }\r
   }\r
-  if (Bridge->PMem.Base <= Bridge->PMem.Limit) {\r
+  if (RESOURCE_VALID (&Bridge->PMem)) {\r
     ASSERT (Bridge->PMem.Limit < SIZE_4GB);\r
     if (Bridge->PMem.Limit >= SIZE_4GB) {\r
       return NULL;\r
     }\r
   }\r
-  if (Bridge->PMemAbove4G.Base <= Bridge->PMemAbove4G.Limit) {\r
+  if (RESOURCE_VALID (&Bridge->PMemAbove4G)) {\r
     ASSERT (Bridge->PMemAbove4G.Base >= SIZE_4GB);\r
     if (Bridge->PMemAbove4G.Base < SIZE_4GB) {\r
       return NULL;\r
@@ -157,11 +151,9 @@ CreateRootBridge (
       // support separate windows for Non-prefetchable and Prefetchable\r
       // memory.\r
       //\r
-      ASSERT (Bridge->PMem.Base > Bridge->PMem.Limit);\r
-      ASSERT (Bridge->PMemAbove4G.Base > Bridge->PMemAbove4G.Limit);\r
-      if ((Bridge->PMem.Base <= Bridge->PMem.Limit) ||\r
-          (Bridge->PMemAbove4G.Base <= Bridge->PMemAbove4G.Limit)\r
-          ) {\r
+      ASSERT (!RESOURCE_VALID (&Bridge->PMem));\r
+      ASSERT (!RESOURCE_VALID (&Bridge->PMemAbove4G));\r
+      if (RESOURCE_VALID (&Bridge->PMem) || RESOURCE_VALID (&Bridge->PMemAbove4G)) {\r
         return NULL;\r
       }\r
     }\r
@@ -171,11 +163,9 @@ CreateRootBridge (
       // If this bit is not set, then the PCI Root Bridge does not support\r
       // 64 bit memory windows.\r
       //\r
-      ASSERT (Bridge->MemAbove4G.Base > Bridge->MemAbove4G.Limit);\r
-      ASSERT (Bridge->PMemAbove4G.Base > Bridge->PMemAbove4G.Limit);\r
-      if ((Bridge->MemAbove4G.Base <= Bridge->MemAbove4G.Limit) ||\r
-          (Bridge->PMemAbove4G.Base <= Bridge->PMemAbove4G.Limit)\r
-          ) {\r
+      ASSERT (!RESOURCE_VALID (&Bridge->MemAbove4G));\r
+      ASSERT (!RESOURCE_VALID (&Bridge->PMemAbove4G));\r
+      if (RESOURCE_VALID (&Bridge->MemAbove4G) || RESOURCE_VALID (&Bridge->PMemAbove4G)) {\r
         return NULL;\r
       }\r
     }\r
@@ -413,12 +403,18 @@ RootBridgeIoCheckParameter (
     // By comparing the Address against Limit we know which range to be used\r
     // for checking\r
     //\r
-    if (Address + Length <= RootBridge->Mem.Limit + 1) {\r
-      Base = RootBridge->Mem.Base;\r
+    if ((Address >= RootBridge->Mem.Base) && (Address + Length <= RootBridge->Mem.Limit + 1)) {\r
+      Base  = RootBridge->Mem.Base;\r
       Limit = RootBridge->Mem.Limit;\r
-    } else {\r
-      Base = RootBridge->MemAbove4G.Base;\r
+    } else if ((Address >= RootBridge->PMem.Base) && (Address + Length <= RootBridge->PMem.Limit + 1)) {\r
+      Base  = RootBridge->PMem.Base;\r
+      Limit = RootBridge->PMem.Limit;\r
+    } else if ((Address >= RootBridge->MemAbove4G.Base) && (Address + Length <= RootBridge->MemAbove4G.Limit + 1)) {\r
+      Base  = RootBridge->MemAbove4G.Base;\r
       Limit = RootBridge->MemAbove4G.Limit;\r
+    } else {\r
+      Base  = RootBridge->PMemAbove4G.Base;\r
+      Limit = RootBridge->PMemAbove4G.Limit;\r
     }\r
   } else {\r
     PciRbAddr = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS*) &Address;\r
@@ -1265,7 +1261,7 @@ RootBridgeIoMap (
 \r
   RootBridge = ROOT_BRIDGE_FROM_THIS (This);\r
 \r
-  if (mIoMmuProtocol != NULL) {\r
+  if (mIoMmu != NULL) {\r
     if (!RootBridge->DmaAbove4G) {\r
       //\r
       // Clear 64bit support\r
@@ -1274,14 +1270,14 @@ RootBridgeIoMap (
         Operation = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION) (Operation - EfiPciOperationBusMasterRead64);\r
       }\r
     }\r
-    Status = mIoMmuProtocol->Map (\r
-                               mIoMmuProtocol,\r
-                               (EDKII_IOMMU_OPERATION) Operation,\r
-                               HostAddress,\r
-                               NumberOfBytes,\r
-                               DeviceAddress,\r
-                               Mapping\r
-                               );\r
+    Status = mIoMmu->Map (\r
+                       mIoMmu,\r
+                       (EDKII_IOMMU_OPERATION) Operation,\r
+                       HostAddress,\r
+                       NumberOfBytes,\r
+                       DeviceAddress,\r
+                       Mapping\r
+                       );\r
     return Status;\r
   }\r
 \r
@@ -1409,11 +1405,11 @@ RootBridgeIoUnmap (
   PCI_ROOT_BRIDGE_INSTANCE *RootBridge;\r
   EFI_STATUS                Status;\r
 \r
-  if (mIoMmuProtocol != NULL) {\r
-    Status = mIoMmuProtocol->Unmap (\r
-                               mIoMmuProtocol,\r
-                               Mapping\r
-                               );\r
+  if (mIoMmu != NULL) {\r
+    Status = mIoMmu->Unmap (\r
+                       mIoMmu,\r
+                       Mapping\r
+                       );\r
     return Status;\r
   }\r
 \r
@@ -1535,21 +1531,21 @@ RootBridgeIoAllocateBuffer (
 \r
   RootBridge = ROOT_BRIDGE_FROM_THIS (This);\r
 \r
-  if (mIoMmuProtocol != NULL) {\r
+  if (mIoMmu != NULL) {\r
     if (!RootBridge->DmaAbove4G) {\r
       //\r
       // Clear DUAL_ADDRESS_CYCLE\r
       //\r
       Attributes &= ~((UINT64) EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE);\r
     }\r
-    Status = mIoMmuProtocol->AllocateBuffer (\r
-                               mIoMmuProtocol,\r
-                               Type,\r
-                               MemoryType,\r
-                               Pages,\r
-                               HostAddress,\r
-                               Attributes\r
-                               );\r
+    Status = mIoMmu->AllocateBuffer (\r
+                       mIoMmu,\r
+                       Type,\r
+                       MemoryType,\r
+                       Pages,\r
+                       HostAddress,\r
+                       Attributes\r
+                       );\r
     return Status;\r
   }\r
 \r
@@ -1599,12 +1595,12 @@ RootBridgeIoFreeBuffer (
 {\r
   EFI_STATUS                Status;\r
 \r
-  if (mIoMmuProtocol != NULL) {\r
-    Status = mIoMmuProtocol->FreeBuffer (\r
-                               mIoMmuProtocol,\r
-                               Pages,\r
-                               HostAddress\r
-                               );\r
+  if (mIoMmu != NULL) {\r
+    Status = mIoMmu->FreeBuffer (\r
+                       mIoMmu,\r
+                       Pages,\r
+                       HostAddress\r
+                       );\r
     return Status;\r
   }\r
 \r