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