]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciDriverOverride.c
Correct all header files for doxygen format and correct the license issue for VgaClas...
[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 EFI_STATUS
18 InitializePciDriverOverrideInstance (
19 PCI_IO_DEVICE *PciIoDevice
20 )
21 /*++
22
23 Routine Description:
24
25 Initializes a PCI Driver Override Instance
26
27 Arguments:
28
29 Returns:
30
31 None
32
33 --*/
34 // TODO: PciIoDevice - add argument and description to function comment
35 // TODO: EFI_SUCCESS - add return value to function comment
36 {
37 PciIoDevice->PciDriverOverride.GetDriver = GetDriver;
38 return EFI_SUCCESS;
39 }
40
41 EFI_STATUS
42 EFIAPI
43 GetDriver (
44 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
45 IN OUT EFI_HANDLE *DriverImageHandle
46 )
47 /*++
48
49 Routine Description:
50
51 Get a overriding driver image
52
53 Arguments:
54
55 Returns:
56
57 None
58
59 --*/
60 // TODO: This - add argument and description to function comment
61 // TODO: DriverImageHandle - add argument and description to function comment
62 // TODO: EFI_SUCCESS - add return value to function comment
63 // TODO: EFI_NOT_FOUND - add return value to function comment
64 // TODO: EFI_SUCCESS - add return value to function comment
65 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
66 {
67 PCI_IO_DEVICE *PciIoDevice;
68 LIST_ENTRY *CurrentLink;
69 PCI_DRIVER_OVERRIDE_LIST *Node;
70
71 PciIoDevice = PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This);
72
73 CurrentLink = PciIoDevice->OptionRomDriverList.ForwardLink;
74
75 while (CurrentLink && CurrentLink != &PciIoDevice->OptionRomDriverList) {
76
77 Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink);
78
79 if (*DriverImageHandle == NULL) {
80
81 *DriverImageHandle = Node->DriverImageHandle;
82 return EFI_SUCCESS;
83 }
84
85 if (*DriverImageHandle == Node->DriverImageHandle) {
86
87 if (CurrentLink->ForwardLink == &PciIoDevice->OptionRomDriverList ||
88 CurrentLink->ForwardLink == NULL) {
89 return EFI_NOT_FOUND;
90 }
91
92 //
93 // Get next node
94 //
95 Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink->ForwardLink);
96 *DriverImageHandle = Node->DriverImageHandle;
97 return EFI_SUCCESS;
98 }
99
100 CurrentLink = CurrentLink->ForwardLink;
101 }
102
103 return EFI_INVALID_PARAMETER;
104 }
105
106 EFI_STATUS
107 AddDriver (
108 IN PCI_IO_DEVICE *PciIoDevice,
109 IN EFI_HANDLE DriverImageHandle
110 )
111 /*++
112
113 Routine Description:
114
115 Add a overriding driver image
116
117 Arguments:
118
119 Returns:
120
121 None
122
123 --*/
124 // TODO: PciIoDevice - add argument and description to function comment
125 // TODO: DriverImageHandle - add argument and description to function comment
126 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
127 // TODO: EFI_SUCCESS - add return value to function comment
128 // TODO: EFI_SUCCESS - add return value to function comment
129 // TODO: EFI_SUCCESS - add return value to function comment
130 // TODO: EFI_SUCCESS - add return value to function comment
131 {
132 EFI_STATUS Status;
133 EFI_IMAGE_DOS_HEADER *DosHdr;
134 EFI_IMAGE_NT_HEADERS *PeHdr;
135 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
136 PCI_DRIVER_OVERRIDE_LIST *Node;
137
138 Status = gBS->HandleProtocol (DriverImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
139 if (EFI_ERROR (Status)) {
140 return Status;
141 }
142
143 Node = AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST));
144 if (Node == NULL) {
145 return EFI_OUT_OF_RESOURCES;
146 }
147
148 Node->Signature = DRIVER_OVERRIDE_SIGNATURE;
149 Node->DriverImageHandle = DriverImageHandle;
150
151 InsertTailList (&PciIoDevice->OptionRomDriverList, &(Node->Link));
152
153 PciIoDevice->BusOverride = TRUE;
154
155 DosHdr = (EFI_IMAGE_DOS_HEADER *) LoadedImage->ImageBase;
156 if (DosHdr->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
157 return EFI_SUCCESS;
158 }
159
160 PeHdr = (EFI_IMAGE_NT_HEADERS *) ((UINTN) LoadedImage->ImageBase + DosHdr->e_lfanew);
161
162 if (PeHdr->FileHeader.Machine != EFI_IMAGE_MACHINE_EBC) {
163 return EFI_SUCCESS;
164 }
165 return EFI_SUCCESS;
166 }