]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/pcibus.c
1. Remove USB HC Protocol installing from Uhci module. It only installs USB2 HC protocol.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / PciBusDxe / pcibus.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 // PCI Bus Driver Global Variables
19 //
20
21 EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding = {
22 PciBusDriverBindingSupported,
23 PciBusDriverBindingStart,
24 PciBusDriverBindingStop,
25 0xa,
26 NULL,
27 NULL
28 };
29
30 EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL *gEfiIncompatiblePciDeviceSupport = NULL;
31 EFI_HANDLE gPciHostBrigeHandles[PCI_MAX_HOST_BRIDGE_NUM];
32 UINTN gPciHostBridgeNumber;
33 BOOLEAN gFullEnumeration;
34 UINT64 gAllOne = 0xFFFFFFFFFFFFFFFFULL;
35 UINT64 gAllZero = 0;
36
37 EFI_PCI_PLATFORM_PROTOCOL *gPciPlatformProtocol;
38
39 //
40 // PCI Bus Driver Support Functions
41 //
42 EFI_STATUS
43 EFIAPI
44 PciBusEntryPoint (
45 IN EFI_HANDLE ImageHandle,
46 IN EFI_SYSTEM_TABLE *SystemTable
47 )
48 /*++
49
50 Routine Description:
51
52 Initialize the global variables
53 publish the driver binding protocol
54
55 Arguments:
56
57 IN EFI_HANDLE ImageHandle,
58 IN EFI_SYSTEM_TABLE *SystemTable
59
60 Returns:
61
62 EFI_SUCCESS
63 EFI_DEVICE_ERROR
64
65 --*/
66 // TODO: ImageHandle - add argument and description to function comment
67 // TODO: SystemTable - add argument and description to function comment
68 {
69 EFI_STATUS Status;
70
71 InitializePciDevicePool ();
72
73 gFullEnumeration = TRUE;
74
75 gPciHostBridgeNumber = 0;
76
77 //
78 // Install driver model protocol(s).
79 //
80 Status = EfiLibInstallDriverBindingComponentName2 (
81 ImageHandle,
82 SystemTable,
83 &gPciBusDriverBinding,
84 ImageHandle,
85 &gPciBusComponentName,
86 &gPciBusComponentName2
87 );
88 ASSERT_EFI_ERROR (Status);
89
90 InstallHotPlugRequestProtocol (&Status);
91
92 return Status;
93 }
94
95 EFI_STATUS
96 EFIAPI
97 PciBusDriverBindingSupported (
98 IN EFI_DRIVER_BINDING_PROTOCOL *This,
99 IN EFI_HANDLE Controller,
100 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
101 )
102 /*++
103
104 Routine Description:
105
106 Check to see if pci bus driver supports the given controller
107
108 Arguments:
109
110 IN EFI_DRIVER_BINDING_PROTOCOL *This,
111 IN EFI_HANDLE Controller,
112 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
113
114 Returns:
115
116 EFI_SUCCESS
117
118 --*/
119 // TODO: This - add argument and description to function comment
120 // TODO: Controller - add argument and description to function comment
121 // TODO: RemainingDevicePath - add argument and description to function comment
122 // TODO: EFI_UNSUPPORTED - add return value to function comment
123 {
124 EFI_STATUS Status;
125 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
126 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
127 EFI_DEV_PATH_PTR Node;
128
129 if (RemainingDevicePath != NULL) {
130 Node.DevPath = RemainingDevicePath;
131 if (Node.DevPath->Type != HARDWARE_DEVICE_PATH ||
132 Node.DevPath->SubType != HW_PCI_DP ||
133 DevicePathNodeLength(Node.DevPath) != sizeof(PCI_DEVICE_PATH)) {
134 return EFI_UNSUPPORTED;
135 }
136 }
137 //
138 // Open the IO Abstraction(s) needed to perform the supported test
139 //
140 Status = gBS->OpenProtocol (
141 Controller,
142 &gEfiDevicePathProtocolGuid,
143 (VOID **) &ParentDevicePath,
144 This->DriverBindingHandle,
145 Controller,
146 EFI_OPEN_PROTOCOL_BY_DRIVER
147 );
148 if (Status == EFI_ALREADY_STARTED) {
149 return EFI_SUCCESS;
150 }
151
152 if (EFI_ERROR (Status)) {
153 return Status;
154 }
155
156 gBS->CloseProtocol (
157 Controller,
158 &gEfiDevicePathProtocolGuid,
159 This->DriverBindingHandle,
160 Controller
161 );
162
163 Status = gBS->OpenProtocol (
164 Controller,
165 &gEfiPciRootBridgeIoProtocolGuid,
166 (VOID **) &PciRootBridgeIo,
167 This->DriverBindingHandle,
168 Controller,
169 EFI_OPEN_PROTOCOL_BY_DRIVER
170 );
171 if (Status == EFI_ALREADY_STARTED) {
172 return EFI_SUCCESS;
173 }
174
175 if (EFI_ERROR (Status)) {
176 return Status;
177 }
178
179 gBS->CloseProtocol (
180 Controller,
181 &gEfiPciRootBridgeIoProtocolGuid,
182 This->DriverBindingHandle,
183 Controller
184 );
185
186 return EFI_SUCCESS;
187 }
188
189 EFI_STATUS
190 EFIAPI
191 PciBusDriverBindingStart (
192 IN EFI_DRIVER_BINDING_PROTOCOL *This,
193 IN EFI_HANDLE Controller,
194 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
195 )
196 /*++
197
198 Routine Description:
199
200 Start to management the controller passed in
201
202 Arguments:
203
204 IN EFI_DRIVER_BINDING_PROTOCOL *This,
205 IN EFI_HANDLE Controller,
206 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
207
208 Returns:
209
210
211 --*/
212 // TODO: This - add argument and description to function comment
213 // TODO: Controller - add argument and description to function comment
214 // TODO: RemainingDevicePath - add argument and description to function comment
215 // TODO: EFI_SUCCESS - add return value to function comment
216 {
217 EFI_STATUS Status;
218
219 Status = gBS->LocateProtocol (
220 &gEfiIncompatiblePciDeviceSupportProtocolGuid,
221 NULL,
222 (VOID **) &gEfiIncompatiblePciDeviceSupport
223 );
224
225 //
226 // If PCI Platform protocol is available, get it now.
227 // If the platform implements this, it must be installed before BDS phase
228 //
229 gPciPlatformProtocol = NULL;
230 gBS->LocateProtocol (
231 &gEfiPciPlatformProtocolGuid,
232 NULL,
233 (VOID **) &gPciPlatformProtocol
234 );
235
236 gFullEnumeration = (BOOLEAN) ((SearchHostBridgeHandle (Controller) ? FALSE : TRUE));
237
238 //
239 // Enumerate the entire host bridge
240 // After enumeration, a database that records all the device information will be created
241 //
242 //
243 Status = PciEnumerator (Controller);
244
245 if (EFI_ERROR (Status)) {
246 return Status;
247 }
248
249 //
250 // Enable PCI device specified by remaining device path. BDS or other driver can call the
251 // start more than once.
252 //
253
254 StartPciDevices (Controller, RemainingDevicePath);
255
256 return EFI_SUCCESS;
257 }
258
259 EFI_STATUS
260 EFIAPI
261 PciBusDriverBindingStop (
262 IN EFI_DRIVER_BINDING_PROTOCOL *This,
263 IN EFI_HANDLE Controller,
264 IN UINTN NumberOfChildren,
265 IN EFI_HANDLE *ChildHandleBuffer
266 )
267 /*++
268
269 Routine Description:
270
271 Stop one or more children created at start of pci bus driver
272 if all the the children get closed, close the protocol
273
274 Arguments:
275
276 IN EFI_DRIVER_BINDING_PROTOCOL *This,
277 IN EFI_HANDLE Controller,
278 IN UINTN NumberOfChildren,
279 IN EFI_HANDLE *ChildHandleBuffer
280
281 Returns:
282
283
284 --*/
285 // TODO: This - add argument and description to function comment
286 // TODO: Controller - add argument and description to function comment
287 // TODO: NumberOfChildren - add argument and description to function comment
288 // TODO: ChildHandleBuffer - add argument and description to function comment
289 // TODO: EFI_SUCCESS - add return value to function comment
290 // TODO: EFI_DEVICE_ERROR - add return value to function comment
291 // TODO: EFI_SUCCESS - add return value to function comment
292 {
293 EFI_STATUS Status;
294 UINTN Index;
295 BOOLEAN AllChildrenStopped;
296
297 if (NumberOfChildren == 0) {
298 //
299 // Close the bus driver
300 //
301 gBS->CloseProtocol (
302 Controller,
303 &gEfiDevicePathProtocolGuid,
304 This->DriverBindingHandle,
305 Controller
306 );
307 gBS->CloseProtocol (
308 Controller,
309 &gEfiPciRootBridgeIoProtocolGuid,
310 This->DriverBindingHandle,
311 Controller
312 );
313
314 DestroyRootBridgeByHandle (
315 Controller
316 );
317
318 return EFI_SUCCESS;
319 }
320
321 //
322 // Stop all the children
323 //
324
325 AllChildrenStopped = TRUE;
326
327 for (Index = 0; Index < NumberOfChildren; Index++) {
328
329 //
330 // De register all the pci device
331 //
332 Status = DeRegisterPciDevice (Controller, ChildHandleBuffer[Index]);
333
334 if (EFI_ERROR (Status)) {
335 AllChildrenStopped = FALSE;
336 }
337 }
338
339 if (!AllChildrenStopped) {
340 return EFI_DEVICE_ERROR;
341 }
342
343 return EFI_SUCCESS;
344 }