]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c
MdeModulePkg/PciBus: Correct typos
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciDeviceSupport.c
index 004f2a3b5bb14986409977fb7b2d92366387355b..764845252faa8ec609899a3a86f4df8d88e590eb 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
-  Supporting functions implementaion for PCI devices management.\r
+  Supporting functions implementation for PCI devices management.\r
 \r
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2018 Hewlett Packard Enterprise Development LP<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
@@ -20,72 +21,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 LIST_ENTRY  mPciDevicePool;\r
 \r
-/**\r
- Disable Bus Master Enable bit in all devices in the list.\r
-\r
- @param Devices  A device list.\r
-**/\r
-VOID\r
-DisableBmeOnTree (\r
-  IN LIST_ENTRY      *Devices\r
-  )\r
-{\r
-  LIST_ENTRY      *Link;\r
-  PCI_IO_DEVICE   *PciIoDevice;\r
-  UINT16           Command;\r
-\r
-  for ( Link = GetFirstNode (Devices)\r
-      ; !IsNull (Devices, Link)\r
-      ; Link = GetNextNode (Devices, Link)\r
-      ) {\r
-    PciIoDevice = PCI_IO_DEVICE_FROM_LINK (Link);\r
-    //\r
-    // Turn off all children's Bus Master, if any\r
-    //\r
-    DisableBmeOnTree (&PciIoDevice->ChildList);\r
-\r
-    //\r
-    // If this is a device that supports BME, disable BME on this device.\r
-    //\r
-    if ((PciIoDevice->Supports & EFI_PCI_IO_ATTRIBUTE_BUS_MASTER) != 0) {\r
-      PCI_READ_COMMAND_REGISTER(PciIoDevice, &Command);\r
-      if ((Command & EFI_PCI_COMMAND_BUS_MASTER) != 0) {\r
-        Command &= ~EFI_PCI_COMMAND_BUS_MASTER;\r
-        PCI_SET_COMMAND_REGISTER (PciIoDevice, Command);\r
-        DEBUG ((\r
-          DEBUG_INFO,"  %02x   %02x      %02x         %04x\n",\r
-          PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber,\r
-          Command\r
-          ));\r
-      }\r
-    }\r
-  }\r
-}\r
-\r
-/**\r
-  Exit Boot Services Event notification handler.\r
-\r
-  Disable Bus Master on any that were enabled during BDS.\r
-\r
-  @param[in]  Event     Event whose notification function is being invoked.\r
-  @param[in]  Context   Pointer to the notification function's context.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-OnExitBootServices (\r
-  IN      EFI_EVENT                 Event,\r
-  IN      VOID                      *Context\r
-  )\r
-{\r
-  DEBUG ((\r
-    DEBUG_INFO,\r
-    "PciBus: Disable Bus Master of all devices...\n"\r
-    "  Bus# Device# Function#  NewCommand\n"\r
-    ));\r
-  DisableBmeOnTree(&mPciDevicePool);\r
-}\r
-\r
 /**\r
   Initialize the PCI devices pool.\r
 \r
@@ -95,27 +30,7 @@ InitializePciDevicePool (
   VOID\r
   )\r
 {\r
-  EFI_EVENT   ExitBootServicesEvent;\r
-  EFI_STATUS  Status;\r
-\r
   InitializeListHead (&mPciDevicePool);\r
-\r
-  //\r
-  // DisableBME on ExitBootServices should be synchonized with any IOMMU ExitBootServices routine.\r
-  // DisableBME should be run before the IOMMU protections are disabled.\r
-  // One way to do this is to ensure that the IOMMU ExitBootServices callback runs at TPL_CALLBACK.\r
-  //\r
-  Status = gBS->CreateEventEx (\r
-                  EVT_NOTIFY_SIGNAL,\r
-                  TPL_NOTIFY,\r
-                  OnExitBootServices,\r
-                  NULL,\r
-                  &gEfiEventExitBootServicesGuid,\r
-                  &ExitBootServicesEvent\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_ERROR, "PciBus: Unable to hook ExitBootServices event - %r\n", Status));\r
-  }\r
 }\r
 \r
 /**\r
@@ -151,7 +66,7 @@ InsertPciDevice (
 }\r
 \r
 /**\r
-  Destroy root bridge and remove it from deivce tree.\r
+  Destroy root bridge and remove it from device tree.\r
 \r
   @param RootBridge     The bridge want to be removed.\r
 \r
@@ -171,7 +86,7 @@ DestroyRootBridge (
 \r
   All direct or indirect allocated resource for this node will be freed.\r
 \r
-  @param PciIoDevice  A pointer to the PCI_IO_DEVICE to be destoried.\r
+  @param PciIoDevice  A pointer to the PCI_IO_DEVICE to be destroyed.\r
 \r
 **/\r
 VOID\r
@@ -191,6 +106,10 @@ FreePciDevice (
     FreePool (PciIoDevice->DevicePath);\r
   }\r
 \r
+  if (PciIoDevice->BusNumberRanges != NULL) {\r
+    FreePool (PciIoDevice->BusNumberRanges);\r
+  }\r
+\r
   FreePool (PciIoDevice);\r
 }\r
 \r
@@ -236,7 +155,7 @@ DestroyPciDeviceTree (
 \r
   @param  Controller    Root bridge handle.\r
 \r
-  @retval EFI_SUCCESS   Destory all devcie nodes successfully.\r
+  @retval EFI_SUCCESS   Destroy all device nodes successfully.\r
   @retval EFI_NOT_FOUND Cannot find any PCI device under specified\r
                         root bridge.\r
 \r
@@ -297,7 +216,6 @@ RegisterPciDevice (
   EFI_STATUS          Status;\r
   VOID                *PlatformOpRomBuffer;\r
   UINTN               PlatformOpRomSize;\r
-  UINT8               PciExpressCapRegOffset;\r
   EFI_PCI_IO_PROTOCOL *PciIo;\r
   UINT8               Data8;\r
   BOOLEAN             HasEfiImage;\r
@@ -317,27 +235,13 @@ RegisterPciDevice (
     return Status;\r
   }\r
 \r
-  //\r
-  // Detect if PCI Express Device\r
-  //\r
-  PciExpressCapRegOffset = 0;\r
-  Status = LocateCapabilityRegBlock (\r
-             PciIoDevice,\r
-             EFI_PCI_CAPABILITY_ID_PCIEXP,\r
-             &PciExpressCapRegOffset,\r
-             NULL\r
-             );\r
-  if (!EFI_ERROR (Status)) {\r
-    PciIoDevice->IsPciExp = TRUE;\r
-  }\r
-\r
   //\r
   // Force Interrupt line to "Unknown" or "No Connection"\r
   //\r
   PciIo = &(PciIoDevice->PciIo);\r
   Data8 = PCI_INT_LINE_UNKNOWN;\r
   PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, 0x3C, 1, &Data8);\r
\r
+\r
   //\r
   // Process OpRom\r
   //\r
@@ -355,7 +259,7 @@ RegisterPciDevice (
                                        );\r
       if (!EFI_ERROR (Status)) {\r
         PciIoDevice->EmbeddedRom    = FALSE;\r
-        PciIoDevice->RomSize        = PlatformOpRomSize;\r
+        PciIoDevice->RomSize        = (UINT32) PlatformOpRomSize;\r
         PciIoDevice->PciIo.RomSize  = PlatformOpRomSize;\r
         PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer;\r
         //\r
@@ -381,7 +285,7 @@ RegisterPciDevice (
                                        );\r
       if (!EFI_ERROR (Status)) {\r
         PciIoDevice->EmbeddedRom    = FALSE;\r
-        PciIoDevice->RomSize        = PlatformOpRomSize;\r
+        PciIoDevice->RomSize        = (UINT32) PlatformOpRomSize;\r
         PciIoDevice->PciIo.RomSize  = PlatformOpRomSize;\r
         PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer;\r
         //\r
@@ -397,7 +301,7 @@ RegisterPciDevice (
           PciIoDevice->PciIo.RomImage,\r
           PciIoDevice->PciIo.RomSize\r
           );\r
-      }   \r
+      }\r
     }\r
   }\r
 \r
@@ -797,12 +701,7 @@ StartPciDevicesOnBridge (
                              0,\r
                              &Supports\r
                              );\r
-        //\r
-        // By default every bridge's IO and MMIO spaces are enabled.\r
-        // Bridge's Bus Master will be enabled when any device behind it requests\r
-        // to enable Bus Master.\r
-        //\r
-        Supports &= (UINT64) (EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY);\r
+        Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;\r
         PciIoDevice->PciIo.Attributes (\r
                              &(PciIoDevice->PciIo),\r
                              EfiPciIoAttributeOperationEnable,\r
@@ -854,12 +753,7 @@ StartPciDevicesOnBridge (
                              0,\r
                              &Supports\r
                              );\r
-        //\r
-        // By default every bridge's IO and MMIO spaces are enabled.\r
-        // Bridge's Bus Master will be enabled when any device behind it requests\r
-        // to enable Bus Master.\r
-        //\r
-        Supports &= (UINT64) (EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY);\r
+        Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;\r
         PciIoDevice->PciIo.Attributes (\r
                              &(PciIoDevice->PciIo),\r
                              EfiPciIoAttributeOperationEnable,\r
@@ -930,7 +824,7 @@ StartPciDevices (
 /**\r
   Create root bridge device.\r
 \r
-  @param RootBridgeHandle    Specified root bridge hanle.\r
+  @param RootBridgeHandle    Specified root bridge handle.\r
 \r
   @return The crated root bridge device instance, NULL means no\r
           root bridge device instance created.\r
@@ -1043,9 +937,9 @@ GetRootBridgeByHandle (
 }\r
 \r
 /**\r
-  Judege whether Pci device existed.\r
+  Judge whether Pci device existed.\r
 \r
-  @param Bridge       Parent bridege instance.\r
+  @param Bridge       Parent bridge instance.\r
   @param PciIoDevice  Device instance.\r
 \r
   @retval TRUE        Pci device existed.\r
@@ -1085,33 +979,33 @@ PciDeviceExisted (
 }\r
 \r
 /**\r
-  Get the active VGA device on the same segment.\r
+  Get the active VGA device on the specified Host Bridge.\r
 \r
-  @param VgaDevice    PCI IO instance for the VGA device.\r
+  @param HostBridgeHandle    Host Bridge handle.\r
 \r
-  @return The active VGA device on the same segment.\r
+  @return The active VGA device on the specified Host Bridge.\r
 \r
 **/\r
 PCI_IO_DEVICE *\r
-ActiveVGADeviceOnTheSameSegment (\r
-  IN PCI_IO_DEVICE        *VgaDevice\r
+LocateVgaDeviceOnHostBridge (\r
+  IN EFI_HANDLE           HostBridgeHandle\r
   )\r
 {\r
   LIST_ENTRY      *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
+  PCI_IO_DEVICE   *PciIoDevice;\r
 \r
   CurrentLink = mPciDevicePool.ForwardLink;\r
 \r
   while (CurrentLink != NULL && CurrentLink != &mPciDevicePool) {\r
 \r
-    Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
+    PciIoDevice = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
 \r
-    if (Temp->PciRootBridgeIo->SegmentNumber == VgaDevice->PciRootBridgeIo->SegmentNumber) {\r
+    if (PciIoDevice->PciRootBridgeIo->ParentHandle== HostBridgeHandle) {\r
 \r
-      Temp = ActiveVGADeviceOnTheRootBridge (Temp);\r
+      PciIoDevice = LocateVgaDevice (PciIoDevice);\r
 \r
-      if (Temp != NULL) {\r
-        return Temp;\r
+      if (PciIoDevice != NULL) {\r
+        return PciIoDevice;\r
       }\r
     }\r
 \r
@@ -1122,41 +1016,41 @@ ActiveVGADeviceOnTheSameSegment (
 }\r
 \r
 /**\r
-  Get the active VGA device on the root bridge.\r
+  Locate the active VGA device under the bridge.\r
 \r
-  @param RootBridge  PCI IO instance for the root bridge.\r
+  @param Bridge  PCI IO instance for the bridge.\r
 \r
   @return The active VGA device.\r
 \r
 **/\r
 PCI_IO_DEVICE *\r
-ActiveVGADeviceOnTheRootBridge (\r
-  IN PCI_IO_DEVICE        *RootBridge\r
+LocateVgaDevice (\r
+  IN PCI_IO_DEVICE        *Bridge\r
   )\r
 {\r
   LIST_ENTRY      *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
+  PCI_IO_DEVICE   *PciIoDevice;\r
 \r
-  CurrentLink = RootBridge->ChildList.ForwardLink;\r
+  CurrentLink = Bridge->ChildList.ForwardLink;\r
 \r
-  while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) {\r
+  while (CurrentLink != NULL && CurrentLink != &Bridge->ChildList) {\r
 \r
-    Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
+    PciIoDevice = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
 \r
-    if (IS_PCI_VGA(&Temp->Pci) &&\r
-        (Temp->Attributes &\r
+    if (IS_PCI_VGA(&PciIoDevice->Pci) &&\r
+        (PciIoDevice->Attributes &\r
          (EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY |\r
           EFI_PCI_IO_ATTRIBUTE_VGA_IO     |\r
           EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) != 0) {\r
-      return Temp;\r
+      return PciIoDevice;\r
     }\r
 \r
-    if (IS_PCI_BRIDGE (&Temp->Pci)) {\r
+    if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) {\r
 \r
-      Temp = ActiveVGADeviceOnTheRootBridge (Temp);\r
+      PciIoDevice = LocateVgaDevice (PciIoDevice);\r
 \r
-      if (Temp != NULL) {\r
-        return Temp;\r
+      if (PciIoDevice != NULL) {\r
+        return PciIoDevice;\r
       }\r
     }\r
 \r
@@ -1166,86 +1060,3 @@ ActiveVGADeviceOnTheRootBridge (
   return NULL;\r
 }\r
 \r
-\r
-/**\r
-  Get HPC PCI address according to its device path.\r
-\r
-  @param RootBridge           Root bridege Io instance.\r
-  @param RemainingDevicePath  Given searching device path.\r
-  @param PciAddress           Buffer holding searched result.\r
-\r
-  @retval EFI_SUCCESS         PCI address was stored in PciAddress\r
-  @retval EFI_NOT_FOUND       Can not find the specific device path.\r
-\r
-**/\r
-EFI_STATUS\r
-GetHpcPciAddressFromRootBridge (\r
-  IN  PCI_IO_DEVICE                    *RootBridge,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL         *RemainingDevicePath,\r
-  OUT UINT64                           *PciAddress\r
-  )\r
-{\r
-  EFI_DEV_PATH_PTR          Node;\r
-  PCI_IO_DEVICE             *Temp;\r
-  EFI_DEVICE_PATH_PROTOCOL  *CurrentDevicePath;\r
-  LIST_ENTRY                *CurrentLink;\r
-  BOOLEAN                   MisMatch;\r
-\r
-  MisMatch          = FALSE;\r
-\r
-  CurrentDevicePath = RemainingDevicePath;\r
-  Node.DevPath      = CurrentDevicePath;\r
-  Temp              = NULL;\r
-\r
-  while (!IsDevicePathEnd (CurrentDevicePath)) {\r
-\r
-    CurrentLink   = RootBridge->ChildList.ForwardLink;\r
-    Node.DevPath  = CurrentDevicePath;\r
-\r
-    while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) {\r
-      Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-\r
-      if (Node.Pci->Device   == Temp->DeviceNumber &&\r
-          Node.Pci->Function == Temp->FunctionNumber) {\r
-        RootBridge = Temp;\r
-        break;\r
-      }\r
-\r
-      CurrentLink = CurrentLink->ForwardLink;\r
-    }\r
-\r
-    //\r
-    // Check if we find the bridge\r
-    //\r
-    if (CurrentLink == &RootBridge->ChildList) {\r
-\r
-      MisMatch = TRUE;\r
-      break;\r
-\r
-    }\r
-\r
-    CurrentDevicePath = NextDevicePathNode (CurrentDevicePath);\r
-  }\r
-\r
-  if (MisMatch) {\r
-\r
-    CurrentDevicePath = NextDevicePathNode (CurrentDevicePath);\r
-\r
-    if (IsDevicePathEnd (CurrentDevicePath)) {\r
-      *PciAddress = EFI_PCI_ADDRESS (RootBridge->BusNumber, Node.Pci->Device, Node.Pci->Function, 0);\r
-      return EFI_SUCCESS;\r
-    }\r
-\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  if (Temp != NULL) {\r
-    *PciAddress = EFI_PCI_ADDRESS (Temp->BusNumber, Temp->DeviceNumber, Temp->FunctionNumber, 0);\r
-  } else {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-\r
-}\r
-\r