]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciIo.c
Clean up meta data and code scrub for PCI Bus module.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / PciBusDxe / PciIo.c
index ddf2ea8f12e007eae60f17f9471866ea33cef4a3..3cf7318faab71042364b4191f95e4bf61e23cd88 100644 (file)
@@ -1,5 +1,5 @@
-/**@file\r
-  Implement all interfaces for EFI_PCI_IO_PROTOCOL.\r
+/** @file\r
+  Implements all interfaces for EFI_PCI_IO_PROTOCOL.\r
   \r
 Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
@@ -15,24 +15,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "PciBus.h"\r
 \r
-//\r
-// Internal use only\r
-//\r
-STATIC\r
-EFI_STATUS\r
-ReportErrorStatusCode (\r
-  IN PCI_IO_DEVICE               *PciIoDevice,\r
-  IN EFI_STATUS_CODE_VALUE       Code\r
-  );\r
-\r
-//\r
-// PCI I/O Support Function Prototypes\r
-//\r
-//\r
 //\r
 // Pci Io Protocol Interface\r
 //\r
-static EFI_PCI_IO_PROTOCOL  PciIoInterface = {\r
+EFI_PCI_IO_PROTOCOL  mPciIoInterface = {\r
   PciIoPollMem,\r
   PciIoPollIo,\r
   {\r
@@ -62,12 +48,29 @@ static EFI_PCI_IO_PROTOCOL  PciIoInterface = {
 };\r
 \r
 /**\r
-  report a error Status code of PCI bus driver controller\r
+  report a error Status code of PCI bus driver controller.\r
   \r
-  @param PciIoDevice Pci device instance\r
-  @param Code        status code\r
+  @param PciIoDevice Pci device instance.\r
+  @param Code        status code.\r
+\r
+**/\r
+EFI_STATUS\r
+ReportErrorStatusCode (\r
+  IN PCI_IO_DEVICE               *PciIoDevice,\r
+  IN EFI_STATUS_CODE_VALUE       Code\r
+  );\r
+\r
+//\r
+// PCI I/O Support Function Prototypes\r
+//\r
+//\r
+\r
+/**\r
+  report a error Status code of PCI bus driver controller.\r
+  \r
+  @param PciIoDevice Pci device instance.\r
+  @param Code        status code.\r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ReportErrorStatusCode (\r
   IN PCI_IO_DEVICE               *PciIoDevice,\r
@@ -82,19 +85,17 @@ ReportErrorStatusCode (
 }\r
 \r
 /**\r
-  Initializes a PCI I/O Instance\r
+  Initializes a PCI I/O Instance.\r
   \r
-  @param PciIoDevice  Pci device instance\r
+  @param PciIoDevice  Pci device instance.\r
   \r
-  @retval EFI_SUCCESS  Success operation\r
 **/\r
-EFI_STATUS\r
+VOID\r
 InitializePciIoInstance (\r
   PCI_IO_DEVICE  *PciIoDevice\r
   )\r
 {\r
-  CopyMem (&PciIoDevice->PciIo, &PciIoInterface, sizeof (EFI_PCI_IO_PROTOCOL));\r
-  return EFI_SUCCESS;\r
+  CopyMem (&PciIoDevice->PciIo, &mPciIoInterface, sizeof (EFI_PCI_IO_PROTOCOL));\r
 }\r
 \r
 /**\r
@@ -283,7 +284,9 @@ PciIoPollMem (
           \r
   @param  This                  A pointer to the EFI_PCI_IO_PROTOCOL.\r
   @param  Width                 Signifies the width of the memory or I/O operations.\r
-  @param  Address               The base address of the memory or I/O operations.  \r
+  @param  BarIndex              The BAR index of the standard PCI Configuration header to use as the\r
+                                base address for the memory or I/O operation to perform.                    \r
+  @param  Offset                The offset within the selected BAR to start the memory or I/O operation.                                \r
   @param  Mask                  Mask used for the polling criteria.\r
   @param  Value                 The comparison value used for the polling exit criteria.\r
   @param  Delay                 The number of 100 ns units to poll.\r
@@ -833,7 +836,7 @@ PciIoMap (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (PciIoDevice->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) {\r
+  if ((PciIoDevice->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) != 0) {\r
     Operation = (EFI_PCI_IO_PROTOCOL_OPERATION) (Operation + EfiPciOperationBusMasterRead64);\r
   }\r
 \r
@@ -921,14 +924,14 @@ PciIoAllocateBuffer (
   EFI_STATUS    Status;\r
   PCI_IO_DEVICE *PciIoDevice;\r
 \r
-  if (Attributes &\r
-      (~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE | EFI_PCI_ATTRIBUTE_MEMORY_CACHED))) {\r
+  if ((Attributes &\r
+      (~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE | EFI_PCI_ATTRIBUTE_MEMORY_CACHED))) != 0){\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (PciIoDevice->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) {\r
+  if ((PciIoDevice->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) != 0) {\r
     Attributes |= EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE;\r
   }\r
 \r
@@ -1148,7 +1151,7 @@ ModifyRootBridgeAttributes (
   //\r
   // Call the PCI Root Bridge to attempt to modify the attributes\r
   //\r
-  if (NewPciRootBridgeAttributes ^ PciRootBridgeAttributes) {\r
+  if ((NewPciRootBridgeAttributes ^ PciRootBridgeAttributes) != 0) {\r
 \r
     Status = PciIoDevice->PciRootBridgeIo->SetAttributes (\r
                                             PciIoDevice->PciRootBridgeIo,\r
@@ -1202,7 +1205,7 @@ SupportPaletteSnoopAttributes (
   //\r
   Temp = ActiveVGADeviceOnTheSameSegment (PciIoDevice);\r
 \r
-  if (!Temp) {\r
+  if (Temp == NULL) {\r
     //\r
     // If there is no VGA device on the segement, set\r
     // this graphics card to decode the palette range\r
@@ -1224,13 +1227,13 @@ SupportPaletteSnoopAttributes (
   //\r
   if (Temp->Parent == PciIoDevice->Parent) {\r
 \r
-    PciReadCommandRegister (Temp, &VGACommand);\r
+    PCI_READ_COMMAND_REGISTER (Temp, &VGACommand);\r
 \r
     //\r
     // If they are on the same bus, either one can\r
     // be set to snoop, the other set to decode\r
     //\r
-    if (VGACommand & EFI_PCI_COMMAND_VGA_PALETTE_SNOOP) {\r
+    if ((VGACommand & EFI_PCI_COMMAND_VGA_PALETTE_SNOOP) != 0) {\r
       //\r
       // VGA has set to snoop, so GFX can be only set to disable snoop\r
       //\r
@@ -1260,7 +1263,7 @@ SupportPaletteSnoopAttributes (
     // GFX should be set to decode\r
     //\r
     if (Operation == EfiPciIoAttributeOperationDisable) {\r
-      PciEnableCommandRegister (Temp, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP);\r
+      PCI_ENABLE_COMMAND_REGISTER (Temp, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP);\r
       Temp->Attributes |= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP;\r
     } else {\r
       return EFI_UNSUPPORTED;\r
@@ -1271,7 +1274,7 @@ SupportPaletteSnoopAttributes (
     // GFX should be set to snoop\r
     //\r
     if (Operation == EfiPciIoAttributeOperationEnable) {\r
-      PciDisableCommandRegister (Temp, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP);\r
+      PCI_DISABLE_COMMAND_REGISTER (Temp, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP);\r
       Temp->Attributes &= (~EFI_PCI_COMMAND_VGA_PALETTE_SNOOP);\r
     } else {\r
       return EFI_UNSUPPORTED;\r
@@ -1401,7 +1404,7 @@ PciIoAttributes (
   //\r
   // For Root Bridge, just call RootBridgeIo to set attributes;\r
   //\r
-  if (!PciIoDevice->Parent) {\r
+  if (PciIoDevice->Parent == NULL) {\r
     Status = ModifyRootBridgeAttributes (PciIoDevice, Attributes, Operation);\r
     return Status;\r
   }\r
@@ -1412,14 +1415,14 @@ PciIoAttributes (
   //\r
   // Check VGA and VGA16, they can not be set at the same time\r
   //\r
-  if (((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO)         &&\r
-       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO_16))         ||\r
-      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO)         &&\r
-       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16)) ||\r
-      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO) &&\r
-       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO_16))         ||\r
-      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO) &&\r
-       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16)) ) {\r
+  if (((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO) != 0         &&\r
+       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO_16) != 0)         ||\r
+      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO) != 0         &&\r
+       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16) != 0) ||\r
+      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO) != 0 &&\r
+       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO_16) != 0)         ||\r
+      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO) != 0 &&\r
+       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16) != 0) ) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -1428,19 +1431,19 @@ PciIoAttributes (
   //\r
   if (IS_PCI_BRIDGE (&PciIoDevice->Pci) || IS_CARDBUS_BRIDGE (&PciIoDevice->Pci)) {\r
 \r
-    if (Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) {\r
+    if ((Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) != 0) {\r
       BridgeControl |= EFI_PCI_BRIDGE_CONTROL_VGA;\r
     }\r
 \r
-    if (Attributes & EFI_PCI_IO_ATTRIBUTE_ISA_IO) {\r
+    if ((Attributes & EFI_PCI_IO_ATTRIBUTE_ISA_IO) != 0) {\r
       BridgeControl |= EFI_PCI_BRIDGE_CONTROL_ISA;\r
     }\r
 \r
-    if (Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO | EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16)) {\r
+    if ((Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO | EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16)) != 0) {\r
       Command |= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO;\r
     }\r
 \r
-    if (Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) {\r
+    if ((Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) != 0) {\r
       BridgeControl |= EFI_PCI_BRIDGE_CONTROL_VGA_16;\r
     }\r
 \r
@@ -1449,10 +1452,10 @@ PciIoAttributes (
     // Do with the attributes on VGA\r
     // Only for VGA's legacy resource, we just can enable once.\r
     //\r
-    if (Attributes &\r
+    if ((Attributes &\r
         (EFI_PCI_IO_ATTRIBUTE_VGA_IO    |\r
          EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 |\r
-         EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY)) {\r
+         EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY)) != 0) {\r
       //\r
       // Check if a VGA has been enabled before enabling a new one\r
       //\r
@@ -1461,7 +1464,7 @@ PciIoAttributes (
         // Check if there have been an active VGA device on the same segment\r
         //\r
         Temp = ActiveVGADeviceOnTheSameSegment (PciIoDevice);\r
-        if (Temp && Temp != PciIoDevice) {\r
+        if (Temp != NULL && Temp != PciIoDevice) {\r
           //\r
           // An active VGA has been detected, so can not enable another\r
           //\r
@@ -1473,7 +1476,7 @@ PciIoAttributes (
     //\r
     // Do with the attributes on GFX\r
     //\r
-    if (Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO | EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16)) {\r
+    if ((Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO | EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16)) != 0) {\r
 \r
       if (Operation == EfiPciIoAttributeOperationEnable) {\r
         //\r
@@ -1503,15 +1506,15 @@ PciIoAttributes (
     }\r
   }\r
 \r
-  if (Attributes & EFI_PCI_IO_ATTRIBUTE_IO) {\r
+  if ((Attributes & EFI_PCI_IO_ATTRIBUTE_IO) != 0) {\r
     Command |= EFI_PCI_COMMAND_IO_SPACE;\r
   }\r
 \r
-  if (Attributes & EFI_PCI_IO_ATTRIBUTE_MEMORY) {\r
+  if ((Attributes & EFI_PCI_IO_ATTRIBUTE_MEMORY) != 0) {\r
     Command |= EFI_PCI_COMMAND_MEMORY_SPACE;\r
   }\r
 \r
-  if (Attributes & EFI_PCI_IO_ATTRIBUTE_BUS_MASTER) {\r
+  if ((Attributes & EFI_PCI_IO_ATTRIBUTE_BUS_MASTER) != 0) {\r
     Command |= EFI_PCI_COMMAND_BUS_MASTER;\r
   }\r
   //\r
@@ -1530,9 +1533,9 @@ PciIoAttributes (
     //\r
     // Enable relevant attributes to command register and bridge control register\r
     //\r
-    Status = PciEnableCommandRegister (PciIoDevice, Command);\r
-    if (BridgeControl) {\r
-      Status = PciEnableBridgeControlRegister (PciIoDevice, BridgeControl);\r
+    Status = PCI_ENABLE_COMMAND_REGISTER (PciIoDevice, Command);\r
+    if (BridgeControl != 0) {\r
+      Status = PCI_ENABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice, BridgeControl);\r
     }\r
 \r
     PciIoDevice->Attributes |= Attributes;\r
@@ -1551,9 +1554,9 @@ PciIoAttributes (
     //\r
     // Disable relevant attributes to command register and bridge control register\r
     //\r
-    Status = PciDisableCommandRegister (PciIoDevice, Command);\r
-    if (BridgeControl) {\r
-      Status = PciDisableBridgeControlRegister (PciIoDevice, BridgeControl);\r
+    Status = PCI_DISABLE_COMMAND_REGISTER (PciIoDevice, Command);\r
+    if (BridgeControl != 0) {\r
+      Status = PCI_DISABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice, BridgeControl);\r
     }\r
 \r
     PciIoDevice->Attributes &= (~Attributes);\r
@@ -1840,7 +1843,7 @@ UpStreamBridgesAttributes (
 \r
   Parent = PciIoDevice->Parent;\r
 \r
-  while (Parent && IS_PCI_BRIDGE (&Parent->Pci)) {\r
+  while (Parent != NULL && IS_PCI_BRIDGE (&Parent->Pci)) {\r
 \r
     //\r
     // Get the PciIo Protocol\r