]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciDriverOverride.c
Update PCI Bus Driver to use the PeCoffLib instead of paring the PE/COFF image itself
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / PciBusDxe / PciDriverOverride.c
index f05c5b198c6bdbb0aa85d9bd375d952ab039e8f0..6ec208453e91be79d93edf1dfd97651a4f864fd1 100644 (file)
@@ -1,4 +1,4 @@
-/**@file\r
+/** @file\r
 \r
 Copyright (c) 2006, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
@@ -12,57 +12,39 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 \r
-#include "pcibus.h"\r
+#include "PciBus.h"\r
 \r
+/**\r
+  Initializes a PCI Driver Override Instance.\r
+\r
+  @param  PciIoDevice   Device instance.\r
+\r
+  @retval EFI_SUCCESS Operation success.\r
+**/\r
 EFI_STATUS\r
 InitializePciDriverOverrideInstance (\r
   PCI_IO_DEVICE  *PciIoDevice\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Initializes a PCI Driver Override Instance\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-// TODO:    PciIoDevice - add argument and description to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
 {\r
   PciIoDevice->PciDriverOverride.GetDriver = GetDriver;\r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Get a overriding driver image.\r
+  @param  This                Pointer to instance of EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL.\r
+  @param  DriverImageHandle   Override driver image.\r
+  \r
+  @retval EFI_SUCCESS                 Success to get driver image handle.\r
+  @retval EFI_NOT_FOUND               can not find override driver image.\r
+  @retval EFI_INVALID_PARAMETER       Invalid parameter.\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 GetDriver (\r
   IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL              *This,\r
   IN OUT EFI_HANDLE                                         *DriverImageHandle\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Get a overriding driver image\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    DriverImageHandle - add argument and description to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
-// TODO:    EFI_NOT_FOUND - add return value to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
-// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
 {\r
   PCI_IO_DEVICE             *PciIoDevice;\r
   LIST_ENTRY                *CurrentLink;\r
@@ -72,7 +54,7 @@ Returns:
 \r
   CurrentLink = PciIoDevice->OptionRomDriverList.ForwardLink;\r
 \r
-  while (CurrentLink && CurrentLink != &PciIoDevice->OptionRomDriverList) {\r
+  while (CurrentLink != NULL && CurrentLink != &PciIoDevice->OptionRomDriverList) {\r
 \r
     Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink);\r
 \r
@@ -103,36 +85,24 @@ Returns:
   return EFI_INVALID_PARAMETER;\r
 }\r
 \r
+/**\r
+  Add an overriding driver image\r
+  \r
+  @param PciIoDevice        Instance of PciIo device.\r
+  @param DriverImageHandle  new added driver image.\r
+  \r
+  @retval EFI_OUT_OF_RESOURCES no memory resource for new driver instance.\r
+  @retval EFI_SUCCESS       Success add driver.\r
+**/\r
 EFI_STATUS\r
 AddDriver (\r
   IN PCI_IO_DEVICE     *PciIoDevice,\r
   IN EFI_HANDLE        DriverImageHandle\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Add a overriding driver image\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-// TODO:    PciIoDevice - add argument and description to function comment\r
-// TODO:    DriverImageHandle - add argument and description to function comment\r
-// TODO:    EFI_OUT_OF_RESOURCES - add return value to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
 {\r
   EFI_STATUS                    Status;\r
-  EFI_IMAGE_DOS_HEADER          *DosHdr;\r
-  EFI_IMAGE_NT_HEADERS          *PeHdr;\r
   EFI_LOADED_IMAGE_PROTOCOL     *LoadedImage;\r
+  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;\r
   PCI_DRIVER_OVERRIDE_LIST      *Node;\r
 \r
   Status = gBS->HandleProtocol (DriverImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);\r
@@ -152,15 +122,21 @@ Returns:
 \r
   PciIoDevice->BusOverride  = TRUE;\r
 \r
-  DosHdr                    = (EFI_IMAGE_DOS_HEADER *) LoadedImage->ImageBase;\r
-  if (DosHdr->e_magic != EFI_IMAGE_DOS_SIGNATURE) {\r
+  ImageContext.Handle    = LoadedImage->ImageBase;\r
+  ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
+\r
+  //\r
+  // Get information about the image \r
+  //\r
+  Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  PeHdr = (EFI_IMAGE_NT_HEADERS *) ((UINTN) LoadedImage->ImageBase + DosHdr->e_lfanew);\r
-\r
-  if (PeHdr->FileHeader.Machine != EFI_IMAGE_MACHINE_EBC) {\r
+  if (ImageContext.Machine != EFI_IMAGE_MACHINE_EBC) {\r
     return EFI_SUCCESS;\r
   }\r
+\r
   return EFI_SUCCESS;\r
 }\r
+\r