]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
Code scrub for PCI Bus module and PciIncompatibleDeviceSupportLib module.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / PciBusDxe / PciOptionRomSupport.c
index 788bbe52ee9da4e311c47cfd0669acc9cde08765..9365847eb55e3178fb063292dd823b2256217d65 100644 (file)
@@ -1,4 +1,5 @@
 /** @file\r
+  PCI Rom supporting funtions implementation for PCI Bus module.\r
 \r
 Copyright (c) 2006 - 2009, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
@@ -12,24 +13,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "PciBus.h"\r
-#include "PciResourceSupport.h"\r
-\r
-#include <IndustryStandard/Pci23.h>\r
 \r
 /**\r
   Load the EFI Image from Option ROM\r
-  \r
-  @param PciIoDevice   PCI IO Device\r
+\r
+  @param PciIoDevice   PCI IO device instance.\r
   @param FilePath      The file path of the EFI Image\r
-  @param BufferSize    On input the size of Buffer in bytes. On output with a return \r
-                       code of EFI_SUCCESS, the amount of data transferred to Buffer. \r
-                       On output with a return code of EFI_BUFFER_TOO_SMALL, \r
-                       the size of Buffer required to retrieve the requested file. \r
-  @param Buffer        The memory buffer to transfer the file to. If Buffer is NULL, \r
+  @param BufferSize    On input the size of Buffer in bytes. On output with a return\r
+                       code of EFI_SUCCESS, the amount of data transferred to Buffer.\r
+                       On output with a return code of EFI_BUFFER_TOO_SMALL,\r
+                       the size of Buffer required to retrieve the requested file.\r
+  @param Buffer        The memory buffer to transfer the file to. If Buffer is NULL,\r
                        then no the size of the requested file is returned in BufferSize.\r
 \r
-  @retval EFI_SUCCESS           The file was loaded. \r
-  @retval EFI_UNSUPPORTED       BootPolicy is TRUE.\r
+  @retval EFI_SUCCESS           The file was loaded.\r
+  @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or\r
+                                BufferSize is NULL.\r
+  @retval EFI_NOT_FOUND         Not found PCI Option Rom on PCI device.\r
+  @retval EFI_DEVICE_ERROR      Failed to decompress PCI Option Rom image.\r
   @retval EFI_BUFFER_TOO_SMALL  The BufferSize is too small to read the current directory entry.\r
                                 BufferSize has been updated with the size needed to complete the request.\r
 **/\r
@@ -65,7 +66,7 @@ LocalLoadFile2 (
       ) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   EfiRomHeader = (EFI_PCI_EXPANSION_ROM_HEADER *) (\r
       (UINT8 *) PciIoDevice->PciIo.RomImage + EfiOpRomImageNode->StartingOffset\r
       );\r
@@ -73,11 +74,11 @@ LocalLoadFile2 (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  \r
+\r
   Pcir = (PCI_DATA_STRUCTURE *) ((UINT8 *) EfiRomHeader + EfiRomHeader->PcirOffset);\r
 \r
-  \r
-  if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) && \r
+\r
+  if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) &&\r
       (EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE) &&\r
       ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||\r
        (EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER)) &&\r
@@ -118,19 +119,19 @@ LocalLoadFile2 (
                              );\r
       if (EFI_ERROR (Status)) {\r
         return EFI_DEVICE_ERROR;\r
-      } \r
-      \r
+      }\r
+\r
       if (Buffer == NULL || *BufferSize < DestinationSize) {\r
         *BufferSize = DestinationSize;\r
         return EFI_BUFFER_TOO_SMALL;\r
-      }      \r
+      }\r
 \r
       *BufferSize = DestinationSize;\r
       Scratch = AllocatePool (ScratchSize);\r
       if (Scratch == NULL) {\r
         return EFI_DEVICE_ERROR;\r
       }\r
-      \r
+\r
       Status = Decompress->Decompress (\r
                              Decompress,\r
                              ImageBuffer,\r
@@ -141,7 +142,7 @@ LocalLoadFile2 (
                              ScratchSize\r
                              );\r
       FreePool (Scratch);\r
-      \r
+\r
       if (EFI_ERROR (Status)) {\r
         return EFI_DEVICE_ERROR;\r
       }\r
@@ -154,13 +155,13 @@ LocalLoadFile2 (
 \r
 /**\r
   Initialize a PCI LoadFile2 instance.\r
-  \r
+\r
   @param PciIoDevice   PCI IO Device.\r
 \r
 **/\r
 VOID\r
 InitializePciLoadFile2 (\r
-  PCI_IO_DEVICE       *PciIoDevice\r
+  IN PCI_IO_DEVICE       *PciIoDevice\r
   )\r
 {\r
   PciIoDevice->LoadFile2.LoadFile = LoadFile2;\r
@@ -168,22 +169,26 @@ InitializePciLoadFile2 (
 \r
 /**\r
   Causes the driver to load a specified file.\r
-  \r
+\r
   @param This        Indicates a pointer to the calling context.\r
   @param FilePath    The device specific path of the file to load.\r
   @param BootPolicy  Should always be FALSE.\r
-  @param BufferSize  On input the size of Buffer in bytes. On output with a return \r
-                     code of EFI_SUCCESS, the amount of data transferred to Buffer. \r
-                     On output with a return code of EFI_BUFFER_TOO_SMALL, \r
-                     the size of Buffer required to retrieve the requested file. \r
-  @param Buffer      The memory buffer to transfer the file to. If Buffer is NULL, \r
-                    then no the size of the requested file is returned in BufferSize.\r
-\r
-  @retval EFI_SUCCESS           The file was loaded. \r
+  @param BufferSize  On input the size of Buffer in bytes. On output with a return\r
+                     code of EFI_SUCCESS, the amount of data transferred to Buffer.\r
+                     On output with a return code of EFI_BUFFER_TOO_SMALL,\r
+                     the size of Buffer required to retrieve the requested file.\r
+  @param Buffer      The memory buffer to transfer the file to. If Buffer is NULL,\r
+                     then no the size of the requested file is returned in BufferSize.\r
+\r
+  @retval EFI_SUCCESS           The file was loaded.\r
   @retval EFI_UNSUPPORTED       BootPolicy is TRUE.\r
+  @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or\r
+                                BufferSize is NULL.\r
+  @retval EFI_NOT_FOUND         Not found PCI Option Rom on PCI device.\r
+  @retval EFI_DEVICE_ERROR      Failed to decompress PCI Option Rom image.\r
   @retval EFI_BUFFER_TOO_SMALL  The BufferSize is too small to read the current directory entry.\r
                                 BufferSize has been updated with the size needed to complete the request.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -210,31 +215,14 @@ LoadFile2 (
            );\r
 }\r
 \r
-\r
-//\r
-// Module global for a template of the PCI option ROM Image Device Path Node\r
-//\r
-MEMMAP_DEVICE_PATH  mPciOptionRomImageDevicePathNodeTemplate = {\r
-  {\r
-    HARDWARE_DEVICE_PATH,\r
-    HW_MEMMAP_DP,\r
-    {\r
-      (UINT8) (sizeof (MEMMAP_DEVICE_PATH)),\r
-      (UINT8) ((sizeof (MEMMAP_DEVICE_PATH)) >> 8)\r
-    }\r
-  },\r
-  EfiMemoryMappedIO,\r
-  0,\r
-  0\r
-};\r
-\r
 /**\r
   Get Pci device's oprom infor bits.\r
-  \r
-  @param PciIoDevice Pci device instance\r
 \r
-  @retval EFI_NOT_FOUND Pci device has not oprom\r
-  @retval EFI_SUCCESS   Pci device has oprom\r
+  @param PciIoDevice    Pci device instance.\r
+\r
+  @retval EFI_NOT_FOUND Pci device has not Option Rom.\r
+  @retval EFI_SUCCESS   Pci device has Option Rom.\r
+\r
 **/\r
 EFI_STATUS\r
 GetOpRomInfo (\r
@@ -257,7 +245,7 @@ GetOpRomInfo (
   PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;\r
 \r
   //\r
-  // offset is 0x30 if is not ppb\r
+  // Offset is 0x30 if is not ppb\r
   //\r
 \r
   //\r
@@ -267,7 +255,7 @@ GetOpRomInfo (
 \r
   if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) {\r
     //\r
-    // if is ppb\r
+    // If is ppb\r
     //\r
 \r
     //\r
@@ -276,7 +264,7 @@ GetOpRomInfo (
     RomBarIndex = PCI_BRIDGE_ROMBAR;\r
   }\r
   //\r
-  // the bit0 is 0 to prevent the enabling of the Rom address decoder\r
+  // The bit0 is 0 to prevent the enabling of the Rom address decoder\r
   //\r
   AllOnes = 0xfffffffe;\r
   Address = EFI_PCI_ADDRESS (Bus, Device, Function, RomBarIndex);\r
@@ -290,11 +278,11 @@ GetOpRomInfo (
                                   &AllOnes\r
                                   );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
   //\r
-  // read back\r
+  // Read back\r
   //\r
   Status = PciRootBridgeIoRead (\r
                                   PciRootBridgeIo,\r
@@ -305,7 +293,7 @@ GetOpRomInfo (
                                   &AllOnes\r
                                   );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    return EFI_NOT_FOUND;\r
   }\r
   //\r
   // Bits [1, 10] are reserved\r
@@ -320,21 +308,20 @@ GetOpRomInfo (
 }\r
 \r
 /**\r
-\r
   Check if the RomImage contains EFI Images.\r
 \r
-  @param  RomImage  The ROM address of Image for check. \r
+  @param  RomImage  The ROM address of Image for check.\r
   @param  RomSize   Size of ROM for check.\r
 \r
   @retval TRUE     ROM contain EFI Image.\r
   @retval FALSE    ROM not contain EFI Image.\r
-  \r
+\r
 **/\r
 BOOLEAN\r
 ContainEfiImage (\r
   IN VOID            *RomImage,\r
   IN UINT64          RomSize\r
-  )  \r
+  )\r
 {\r
   PCI_EXPANSION_ROM_HEADER  *RomHeader;\r
   PCI_DATA_STRUCTURE        *RomPcir;\r
@@ -342,7 +329,7 @@ ContainEfiImage (
 \r
   FirstCheck = TRUE;\r
   RomHeader  = RomImage;\r
-  \r
+\r
   while ((UINT8 *) RomHeader < (UINT8 *) RomImage + RomSize) {\r
     if (RomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {\r
       if (FirstCheck) {\r
@@ -355,7 +342,7 @@ ContainEfiImage (
 \r
     FirstCheck = FALSE;\r
     RomPcir    = (PCI_DATA_STRUCTURE *) ((UINT8 *) RomHeader + RomHeader->PcirOffset);\r
-    \r
+\r
     if (RomPcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) {\r
       return TRUE;\r
     }\r
@@ -368,13 +355,14 @@ ContainEfiImage (
 \r
 \r
 /**\r
-  Load option rom image for specified PCI device\r
-  \r
-  @param PciDevice Pci device instance\r
-  @param RomBase   Base address of oprom.\r
-  \r
-  @retval EFI_OUT_OF_RESOURCES not enough memory to hold image\r
-  @retval EFI_SUCESS           Success\r
+  Load Option Rom image for specified PCI device.\r
+\r
+  @param PciDevice Pci device instance.\r
+  @param RomBase   Base address of Option Rom.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES No enough memory to hold image.\r
+  @retval EFI_SUCESS           Successfully loaded Option Rom.\r
+\r
 **/\r
 EFI_STATUS\r
 LoadOpRomImage (\r
@@ -543,17 +531,16 @@ LoadOpRomImage (
 }\r
 \r
 /**\r
-  enable/disable oprom decode\r
-  \r
-  @param PciDevice    pci device instance\r
+  Enable/Disable Option Rom decode.\r
+\r
+  @param PciDevice    Pci device instance.\r
   @param RomBarIndex  The BAR index of the standard PCI Configuration header to use as the\r
                       base address for resource range. The legal range for this field is 0..5.\r
-  @param RomBar       Base address of rom\r
+  @param RomBar       Base address of Option Rom.\r
   @param Enable       Flag for enable/disable decode.\r
-  \r
-  @retval EFI_SUCCESS Success\r
+\r
 **/\r
-EFI_STATUS\r
+VOID\r
 RomDecode (\r
   IN PCI_IO_DEVICE   *PciDevice,\r
   IN UINT8           RomBarIndex,\r
@@ -622,41 +609,41 @@ RomDecode (
                 );\r
 \r
   }\r
-\r
-  return EFI_SUCCESS;\r
-\r
 }\r
 \r
 /**\r
-  Process the oprom image.\r
-  \r
-  @param PciDevice Pci device instance\r
+  Load and start the Option Rom image.\r
+\r
+  @param PciDevice       Pci device instance.\r
+\r
+  @retval EFI_SUCCESS    Successfully loaded and started PCI Option Rom image.\r
+  @retval EFI_NOT_FOUND  Failed to process PCI Option Rom image.\r
+\r
 **/\r
 EFI_STATUS\r
 ProcessOpRomImage (\r
-  PCI_IO_DEVICE   *PciDevice\r
+  IN  PCI_IO_DEVICE   *PciDevice\r
   )\r
 {\r
-  UINT8                         Indicator;\r
-  UINT32                        ImageSize;\r
-  VOID                          *RomBar;\r
-  UINT8                         *RomBarOffset;\r
-  EFI_HANDLE                    ImageHandle;\r
-  EFI_STATUS                    Status;\r
-  EFI_STATUS                    RetStatus;\r
-  BOOLEAN                       FirstCheck;\r
-  EFI_PCI_EXPANSION_ROM_HEADER  *EfiRomHeader;\r
-  PCI_DATA_STRUCTURE            *Pcir;\r
-  EFI_DEVICE_PATH_PROTOCOL      *PciOptionRomImageDevicePath;\r
-\r
-  MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH  EfiOpRomImageNode;                            \r
-  VOID                          *Buffer;\r
-  UINTN                         BufferSize;\r
+  UINT8                                    Indicator;\r
+  UINT32                                   ImageSize;\r
+  VOID                                     *RomBar;\r
+  UINT8                                    *RomBarOffset;\r
+  EFI_HANDLE                               ImageHandle;\r
+  EFI_STATUS                               Status;\r
+  EFI_STATUS                               RetStatus;\r
+  BOOLEAN                                  FirstCheck;\r
+  EFI_PCI_EXPANSION_ROM_HEADER             *EfiRomHeader;\r
+  PCI_DATA_STRUCTURE                       *Pcir;\r
+  EFI_DEVICE_PATH_PROTOCOL                 *PciOptionRomImageDevicePath;\r
+  MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH  EfiOpRomImageNode;\r
+  VOID                                     *Buffer;\r
+  UINTN                                    BufferSize;\r
 \r
   Indicator = 0;\r
 \r
   //\r
-  // Get the Address of the Rom image\r
+  // Get the Address of the Option Rom image\r
   //\r
   RomBar        = PciDevice->PciIo.RomImage;\r
   RomBarOffset  = (UINT8 *) RomBar;\r
@@ -694,7 +681,6 @@ ProcessOpRomImage (
     //\r
     // load image and start image\r
     //\r
-\r
     BufferSize  = 0;\r
     Buffer      = NULL;\r
     Status      = EFI_SUCCESS;\r
@@ -749,6 +735,5 @@ ProcessOpRomImage (
   } while (((Indicator & 0x80) == 0x00) && ((UINTN) (RomBarOffset - (UINT8 *) RomBar) < PciDevice->RomSize));\r
 \r
   return RetStatus;\r
-\r
 }\r
 \r