]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/pcibus.c
Coding style modification.
[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 // Start all the devices under the entire host bridge.
251 //
252 StartPciDevices (Controller);
253
254 return EFI_SUCCESS;
255 }
256
257 EFI_STATUS
258 EFIAPI
259 PciBusDriverBindingStop (
260 IN EFI_DRIVER_BINDING_PROTOCOL *This,
261 IN EFI_HANDLE Controller,
262 IN UINTN NumberOfChildren,
263 IN EFI_HANDLE *ChildHandleBuffer
264 )
265 /**
266
267 Routine Description:
268
269 Stop one or more children created at start of pci bus driver
270 if all the the children get closed, close the protocol
271
272 Arguments:
273
274 IN EFI_DRIVER_BINDING_PROTOCOL *This,
275 IN EFI_HANDLE Controller,
276 IN UINTN NumberOfChildren,
277 IN EFI_HANDLE *ChildHandleBuffer
278
279 Returns:
280
281
282 **/
283 // TODO: This - add argument and description to function comment
284 // TODO: Controller - add argument and description to function comment
285 // TODO: NumberOfChildren - add argument and description to function comment
286 // TODO: ChildHandleBuffer - add argument and description to function comment
287 // TODO: EFI_SUCCESS - add return value to function comment
288 // TODO: EFI_DEVICE_ERROR - add return value to function comment
289 // TODO: EFI_SUCCESS - add return value to function comment
290 {
291 EFI_STATUS Status;
292 UINTN Index;
293 BOOLEAN AllChildrenStopped;
294
295 if (NumberOfChildren == 0) {
296 //
297 // Close the bus driver
298 //
299 gBS->CloseProtocol (
300 Controller,
301 &gEfiDevicePathProtocolGuid,
302 This->DriverBindingHandle,
303 Controller
304 );
305 gBS->CloseProtocol (
306 Controller,
307 &gEfiPciRootBridgeIoProtocolGuid,
308 This->DriverBindingHandle,
309 Controller
310 );
311
312 DestroyRootBridgeByHandle (
313 Controller
314 );
315
316 return EFI_SUCCESS;
317 }
318
319 //
320 // Stop all the children
321 //
322
323 AllChildrenStopped = TRUE;
324
325 for (Index = 0; Index < NumberOfChildren; Index++) {
326
327 //
328 // De register all the pci device
329 //
330 Status = DeRegisterPciDevice (Controller, ChildHandleBuffer[Index]);
331
332 if (EFI_ERROR (Status)) {
333 AllChildrenStopped = FALSE;
334 }
335 }
336
337 if (!AllChildrenStopped) {
338 return EFI_DEVICE_ERROR;
339 }
340
341 return EFI_SUCCESS;
342 }