]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciDriverOverride.c
Code scrub for IdeBusDxe driver and PeiS3Lib.(undergoing)
[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 **/
23 VOID
24 InitializePciDriverOverrideInstance (
25 PCI_IO_DEVICE *PciIoDevice
26 )
27 {
28 PciIoDevice->PciDriverOverride.GetDriver = GetDriver;
29 }
30
31 /**
32 Get a overriding driver image.
33 @param This Pointer to instance of EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL.
34 @param DriverImageHandle Override driver image.
35
36 @retval EFI_SUCCESS Success to get driver image handle.
37 @retval EFI_NOT_FOUND can not find override driver image.
38 @retval EFI_INVALID_PARAMETER Invalid parameter.
39 **/
40 EFI_STATUS
41 EFIAPI
42 GetDriver (
43 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
44 IN OUT EFI_HANDLE *DriverImageHandle
45 )
46 {
47 PCI_IO_DEVICE *PciIoDevice;
48 LIST_ENTRY *CurrentLink;
49 PCI_DRIVER_OVERRIDE_LIST *Node;
50
51 PciIoDevice = PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This);
52
53 CurrentLink = PciIoDevice->OptionRomDriverList.ForwardLink;
54
55 while (CurrentLink != NULL && CurrentLink != &PciIoDevice->OptionRomDriverList) {
56
57 Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink);
58
59 if (*DriverImageHandle == NULL) {
60
61 *DriverImageHandle = Node->DriverImageHandle;
62 return EFI_SUCCESS;
63 }
64
65 if (*DriverImageHandle == Node->DriverImageHandle) {
66
67 if (CurrentLink->ForwardLink == &PciIoDevice->OptionRomDriverList ||
68 CurrentLink->ForwardLink == NULL) {
69 return EFI_NOT_FOUND;
70 }
71
72 //
73 // Get next node
74 //
75 Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink->ForwardLink);
76 *DriverImageHandle = Node->DriverImageHandle;
77 return EFI_SUCCESS;
78 }
79
80 CurrentLink = CurrentLink->ForwardLink;
81 }
82
83 return EFI_INVALID_PARAMETER;
84 }
85
86 /**
87 Add an overriding driver image
88
89 @param PciIoDevice Instance of PciIo device.
90 @param DriverImageHandle new added driver image.
91
92 @retval EFI_OUT_OF_RESOURCES no memory resource for new driver instance.
93 @retval EFI_SUCCESS Success add driver.
94 **/
95 EFI_STATUS
96 AddDriver (
97 IN PCI_IO_DEVICE *PciIoDevice,
98 IN EFI_HANDLE DriverImageHandle
99 )
100 {
101 EFI_STATUS Status;
102 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
103 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
104 PCI_DRIVER_OVERRIDE_LIST *Node;
105
106 Status = gBS->HandleProtocol (DriverImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
107 if (EFI_ERROR (Status)) {
108 return Status;
109 }
110
111 Node = AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST));
112 if (Node == NULL) {
113 return EFI_OUT_OF_RESOURCES;
114 }
115
116 Node->Signature = DRIVER_OVERRIDE_SIGNATURE;
117 Node->DriverImageHandle = DriverImageHandle;
118
119 InsertTailList (&PciIoDevice->OptionRomDriverList, &(Node->Link));
120
121 PciIoDevice->BusOverride = TRUE;
122
123 ImageContext.Handle = LoadedImage->ImageBase;
124 ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
125
126 //
127 // Get information about the image
128 //
129 Status = PeCoffLoaderGetImageInfo (&ImageContext);
130 if (EFI_ERROR (Status)) {
131 return EFI_SUCCESS;
132 }
133
134 if (ImageContext.Machine != EFI_IMAGE_MACHINE_EBC) {
135 return EFI_SUCCESS;
136 }
137
138 return EFI_SUCCESS;
139 }
140