]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciDriverOverride.c
1. EDK_RELEASE_VERSION removed;
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / PciBusDxe / PciDriverOverride.c
CommitLineData
97404058 1/** @file\r
ead42efc 2\r
3db51098 3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
ead42efc 11\r
3db51098 12**/\r
ead42efc 13\r
ead42efc 14\r
03417d8d 15#include "PciBus.h"\r
ead42efc 16\r
bcd70414 17/**\r
97404058 18 Initializes a PCI Driver Override Instance.\r
ead42efc 19\r
97404058 20 @param PciIoDevice Device instance.\r
ead42efc 21\r
bcd70414 22**/\r
8e6b0dcb 23VOID\r
a3b8e257 24InitializePciDriverOverrideInstance (\r
25 PCI_IO_DEVICE *PciIoDevice\r
26 )\r
ead42efc 27{\r
28 PciIoDevice->PciDriverOverride.GetDriver = GetDriver;\r
ead42efc 29}\r
30\r
a3b8e257 31/**\r
97404058 32 Get a overriding driver image.\r
33 @param This Pointer to instance of EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL.\r
34 @param DriverImageHandle Override driver image.\r
a3b8e257 35 \r
97404058 36 @retval EFI_SUCCESS Success to get driver image handle.\r
37 @retval EFI_NOT_FOUND can not find override driver image.\r
38 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
a3b8e257 39**/\r
ead42efc 40EFI_STATUS\r
41EFIAPI\r
42GetDriver (\r
43 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,\r
44 IN OUT EFI_HANDLE *DriverImageHandle\r
45 )\r
ead42efc 46{\r
47 PCI_IO_DEVICE *PciIoDevice;\r
48 LIST_ENTRY *CurrentLink;\r
49 PCI_DRIVER_OVERRIDE_LIST *Node;\r
50\r
51 PciIoDevice = PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This);\r
52\r
53 CurrentLink = PciIoDevice->OptionRomDriverList.ForwardLink;\r
54\r
97404058 55 while (CurrentLink != NULL && CurrentLink != &PciIoDevice->OptionRomDriverList) {\r
ead42efc 56\r
57 Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink);\r
58\r
59 if (*DriverImageHandle == NULL) {\r
60\r
61 *DriverImageHandle = Node->DriverImageHandle;\r
62 return EFI_SUCCESS;\r
63 }\r
64\r
65 if (*DriverImageHandle == Node->DriverImageHandle) {\r
66\r
67 if (CurrentLink->ForwardLink == &PciIoDevice->OptionRomDriverList ||\r
68 CurrentLink->ForwardLink == NULL) {\r
69 return EFI_NOT_FOUND;\r
70 }\r
71\r
72 //\r
73 // Get next node\r
74 //\r
75 Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink->ForwardLink);\r
76 *DriverImageHandle = Node->DriverImageHandle;\r
77 return EFI_SUCCESS;\r
78 }\r
79\r
80 CurrentLink = CurrentLink->ForwardLink;\r
81 }\r
82\r
83 return EFI_INVALID_PARAMETER;\r
84}\r
85\r
a3b8e257 86/**\r
87 Add an overriding driver image\r
88 \r
eeefcb9d 89 @param PciIoDevice Instance of PciIo device.\r
90 @param DriverImageHandle new added driver image.\r
a3b8e257 91 \r
eeefcb9d 92 @retval EFI_OUT_OF_RESOURCES no memory resource for new driver instance.\r
93 @retval EFI_SUCCESS Success add driver.\r
a3b8e257 94**/\r
ead42efc 95EFI_STATUS\r
96AddDriver (\r
97 IN PCI_IO_DEVICE *PciIoDevice,\r
98 IN EFI_HANDLE DriverImageHandle\r
99 )\r
ead42efc 100{\r
101 EFI_STATUS Status;\r
ead42efc 102 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
2fb718b0 103 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r
ead42efc 104 PCI_DRIVER_OVERRIDE_LIST *Node;\r
105\r
106 Status = gBS->HandleProtocol (DriverImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);\r
107 if (EFI_ERROR (Status)) {\r
108 return Status;\r
109 }\r
110\r
111 Node = AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST));\r
112 if (Node == NULL) {\r
113 return EFI_OUT_OF_RESOURCES;\r
114 }\r
115\r
116 Node->Signature = DRIVER_OVERRIDE_SIGNATURE;\r
117 Node->DriverImageHandle = DriverImageHandle;\r
118\r
119 InsertTailList (&PciIoDevice->OptionRomDriverList, &(Node->Link));\r
120\r
121 PciIoDevice->BusOverride = TRUE;\r
122\r
2fb718b0 123 ImageContext.Handle = LoadedImage->ImageBase;\r
124 ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
125\r
126 //\r
127 // Get information about the image \r
128 //\r
129 Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
130 if (EFI_ERROR (Status)) {\r
ead42efc 131 return EFI_SUCCESS;\r
132 }\r
133\r
2fb718b0 134 if (ImageContext.Machine != EFI_IMAGE_MACHINE_EBC) {\r
ead42efc 135 return EFI_SUCCESS;\r
136 }\r
2fb718b0 137\r
ead42efc 138 return EFI_SUCCESS;\r
139}\r
a3b8e257 140\r