]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciBus.c
CommitLineData
9060e3ec 1/** @file\r
2 Driver Binding functions for PCI Bus module.\r
3\r
4 Single PCI bus driver instance will manager all PCI Root Bridges in one EFI based firmware,\r
5 since all PCI Root Bridges' resources need to be managed together.\r
6 Supported() function will try to get PCI Root Bridge IO Protocol.\r
7 Start() function will get PCI Host Bridge Resource Allocation Protocol to manage all\r
8 PCI Root Bridges. So it means platform needs install PCI Root Bridge IO protocol for each\r
9 PCI Root Bus and install PCI Host Bridge Resource Allocation Protocol.\r
10\r
cd5ebaa0
HT
11Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
12This program and the accompanying materials\r
9060e3ec 13are licensed and made available under the terms and conditions of the BSD License\r
14which accompanies this distribution. The full text of the license may be found at\r
15http://opensource.org/licenses/bsd-license.php\r
16\r
17THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
19\r
20**/\r
21\r
22#include "PciBus.h"\r
23\r
24//\r
25// PCI Bus Driver Global Variables\r
26//\r
27EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding = {\r
28 PciBusDriverBindingSupported,\r
29 PciBusDriverBindingStart,\r
30 PciBusDriverBindingStop,\r
31 0xa,\r
32 NULL,\r
33 NULL\r
34};\r
35\r
36EFI_HANDLE gPciHostBrigeHandles[PCI_MAX_HOST_BRIDGE_NUM];\r
37EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL *gEfiIncompatiblePciDeviceSupport = NULL;\r
38UINTN gPciHostBridgeNumber = 0;\r
39BOOLEAN gFullEnumeration = TRUE;\r
40UINT64 gAllOne = 0xFFFFFFFFFFFFFFFFULL;\r
41UINT64 gAllZero = 0;\r
42\r
43EFI_PCI_PLATFORM_PROTOCOL *gPciPlatformProtocol;\r
44EFI_PCI_OVERRIDE_PROTOCOL *gPciOverrideProtocol;\r
45\r
46\r
47GLOBAL_REMOVE_IF_UNREFERENCED EFI_PCI_HOTPLUG_REQUEST_PROTOCOL mPciHotPlugRequest = {\r
48 PciHotPlugRequestNotify\r
49};\r
50\r
51/**\r
52 The Entry Point for PCI Bus module. The user code starts with this function.\r
53\r
54 Installs driver module protocols and. Creates virtual device handles for ConIn,\r
55 ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,\r
56 Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.\r
57 Installs Graphics Output protocol and/or UGA Draw protocol if needed.\r
58\r
59 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
60 @param[in] SystemTable A pointer to the EFI System Table.\r
61\r
62 @retval EFI_SUCCESS The entry point is executed successfully.\r
63 @retval other Some error occurred when executing this entry point.\r
64\r
65**/\r
66EFI_STATUS\r
67EFIAPI\r
68PciBusEntryPoint (\r
69 IN EFI_HANDLE ImageHandle,\r
70 IN EFI_SYSTEM_TABLE *SystemTable\r
71 )\r
72{\r
73 EFI_STATUS Status;\r
74 EFI_HANDLE Handle;\r
75\r
76 //\r
77 // Initializes PCI devices pool\r
78 //\r
79 InitializePciDevicePool ();\r
80\r
81 //\r
82 // Install driver model protocol(s).\r
83 //\r
84 Status = EfiLibInstallDriverBindingComponentName2 (\r
85 ImageHandle,\r
86 SystemTable,\r
87 &gPciBusDriverBinding,\r
88 ImageHandle,\r
89 &gPciBusComponentName,\r
90 &gPciBusComponentName2\r
91 );\r
92 ASSERT_EFI_ERROR (Status);\r
93\r
94 if (FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) {\r
95 //\r
96 // If Hot Plug is supported, install EFI PCI Hot Plug Request protocol.\r
97 //\r
98 Handle = NULL;\r
99 Status = gBS->InstallProtocolInterface (\r
100 &Handle,\r
101 &gEfiPciHotPlugRequestProtocolGuid,\r
102 EFI_NATIVE_INTERFACE,\r
103 &mPciHotPlugRequest\r
104 );\r
105 }\r
106\r
107 return Status;\r
108}\r
109\r
110/**\r
111 Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
112 than contains a gEfiPciRootBridgeIoProtocolGuid protocol can be supported.\r
113\r
114 @param This Protocol instance pointer.\r
115 @param Controller Handle of device to test.\r
116 @param RemainingDevicePath Optional parameter use to pick a specific child.\r
117 device to start.\r
118\r
119 @retval EFI_SUCCESS This driver supports this device.\r
120 @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
121 @retval other This driver does not support this device.\r
122\r
123**/\r
124EFI_STATUS\r
125EFIAPI\r
126PciBusDriverBindingSupported (\r
127 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
128 IN EFI_HANDLE Controller,\r
129 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
130 )\r
131{\r
132 EFI_STATUS Status;\r
133 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
134 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r
135 EFI_DEV_PATH_PTR Node;\r
136\r
137 //\r
138 // Check RemainingDevicePath validation\r
139 //\r
140 if (RemainingDevicePath != NULL) {\r
141 //\r
142 // Check if RemainingDevicePath is the End of Device Path Node, \r
143 // if yes, go on checking other conditions\r
144 //\r
145 if (!IsDevicePathEnd (RemainingDevicePath)) {\r
146 //\r
147 // If RemainingDevicePath isn't the End of Device Path Node,\r
148 // check its validation\r
149 //\r
150 Node.DevPath = RemainingDevicePath;\r
151 if (Node.DevPath->Type != HARDWARE_DEVICE_PATH ||\r
152 Node.DevPath->SubType != HW_PCI_DP ||\r
153 DevicePathNodeLength(Node.DevPath) != sizeof(PCI_DEVICE_PATH)) {\r
154 return EFI_UNSUPPORTED;\r
155 }\r
156 }\r
157 }\r
158\r
159 //\r
160 // Check if Pci Root Bridge IO protocol is installed by platform\r
161 //\r
162 Status = gBS->OpenProtocol (\r
163 Controller,\r
164 &gEfiPciRootBridgeIoProtocolGuid,\r
165 (VOID **) &PciRootBridgeIo,\r
166 This->DriverBindingHandle,\r
167 Controller,\r
168 EFI_OPEN_PROTOCOL_BY_DRIVER\r
169 );\r
170 if (Status == EFI_ALREADY_STARTED) {\r
171 return EFI_SUCCESS;\r
172 }\r
173\r
174 if (EFI_ERROR (Status)) {\r
175 return Status;\r
176 }\r
177\r
178 //\r
179 // Close the I/O Abstraction(s) used to perform the supported test\r
180 //\r
181 gBS->CloseProtocol (\r
182 Controller,\r
183 &gEfiPciRootBridgeIoProtocolGuid,\r
184 This->DriverBindingHandle,\r
185 Controller\r
186 );\r
187\r
188 //\r
189 // Open the EFI Device Path protocol needed to perform the supported test\r
190 //\r
191 Status = gBS->OpenProtocol (\r
192 Controller,\r
193 &gEfiDevicePathProtocolGuid,\r
194 (VOID **) &ParentDevicePath,\r
195 This->DriverBindingHandle,\r
196 Controller,\r
197 EFI_OPEN_PROTOCOL_BY_DRIVER\r
198 );\r
199 if (Status == EFI_ALREADY_STARTED) {\r
200 return EFI_SUCCESS;\r
201 }\r
202\r
203 if (EFI_ERROR (Status)) {\r
204 return Status;\r
205 }\r
206\r
207 //\r
208 // Close protocol, don't use device path protocol in the Support() function\r
209 //\r
210 gBS->CloseProtocol (\r
211 Controller,\r
212 &gEfiDevicePathProtocolGuid,\r
213 This->DriverBindingHandle,\r
214 Controller\r
215 );\r
216\r
217 return EFI_SUCCESS;\r
218}\r
219\r
220/**\r
221 Start this driver on ControllerHandle and enumerate Pci bus and start\r
222 all device under PCI bus.\r
223\r
224 @param This Protocol instance pointer.\r
225 @param Controller Handle of device to bind driver to.\r
226 @param RemainingDevicePath Optional parameter use to pick a specific child.\r
227 device to start.\r
228\r
229 @retval EFI_SUCCESS This driver is added to ControllerHandle.\r
230 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.\r
231 @retval other This driver does not support this device.\r
232\r
233**/\r
234EFI_STATUS\r
235EFIAPI\r
236PciBusDriverBindingStart (\r
237 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
238 IN EFI_HANDLE Controller,\r
239 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
240 )\r
241{\r
242 EFI_STATUS Status;\r
243\r
244 //\r
245 // Check RemainingDevicePath validation\r
246 //\r
247 if (RemainingDevicePath != NULL) {\r
248 //\r
249 // Check if RemainingDevicePath is the End of Device Path Node, \r
250 // if yes, return EFI_SUCCESS\r
251 //\r
252 if (IsDevicePathEnd (RemainingDevicePath)) {\r
253 return EFI_SUCCESS;\r
254 }\r
255 }\r
256\r
257 Status = gBS->LocateProtocol (\r
258 &gEfiIncompatiblePciDeviceSupportProtocolGuid,\r
259 NULL,\r
260 (VOID **) &gEfiIncompatiblePciDeviceSupport\r
261 );\r
262\r
263 //\r
264 // If PCI Platform protocol is available, get it now.\r
265 // If the platform implements this, it must be installed before BDS phase\r
266 //\r
267 gPciPlatformProtocol = NULL;\r
268 gBS->LocateProtocol (\r
269 &gEfiPciPlatformProtocolGuid,\r
270 NULL,\r
271 (VOID **) &gPciPlatformProtocol\r
272 );\r
273\r
274 //\r
275 // If PCI Platform protocol doesn't exist, try to Pci Override Protocol.\r
276 //\r
277 if (gPciPlatformProtocol == NULL) { \r
278 gPciOverrideProtocol = NULL;\r
279 gBS->LocateProtocol (\r
280 &gEfiPciOverrideProtocolGuid,\r
281 NULL,\r
282 (VOID **) &gPciOverrideProtocol\r
283 );\r
284 } \r
285\r
286 gFullEnumeration = (BOOLEAN) ((SearchHostBridgeHandle (Controller) ? FALSE : TRUE));\r
287\r
288 //\r
289 // Enumerate the entire host bridge\r
290 // After enumeration, a database that records all the device information will be created\r
291 //\r
292 //\r
293 Status = PciEnumerator (Controller);\r
294\r
295 if (EFI_ERROR (Status)) {\r
296 return Status;\r
297 }\r
298\r
299 //\r
300 // Start all the devices under the entire host bridge.\r
301 //\r
302 StartPciDevices (Controller);\r
303\r
304 return EFI_SUCCESS;\r
305}\r
306\r
307/**\r
308 Stop this driver on ControllerHandle. Support stoping any child handles\r
309 created by this driver.\r
310\r
311 @param This Protocol instance pointer.\r
312 @param Controller Handle of device to stop driver on.\r
313 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
314 children is zero stop the entire bus driver.\r
315 @param ChildHandleBuffer List of Child Handles to Stop.\r
316\r
317 @retval EFI_SUCCESS This driver is removed ControllerHandle.\r
318 @retval other This driver was not removed from this device.\r
319\r
320**/\r
321EFI_STATUS\r
322EFIAPI\r
323PciBusDriverBindingStop (\r
324 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
325 IN EFI_HANDLE Controller,\r
326 IN UINTN NumberOfChildren,\r
327 IN EFI_HANDLE *ChildHandleBuffer\r
328 )\r
329{\r
330 EFI_STATUS Status;\r
331 UINTN Index;\r
332 BOOLEAN AllChildrenStopped;\r
333\r
334 if (NumberOfChildren == 0) {\r
335 //\r
336 // Close the bus driver\r
337 //\r
338 gBS->CloseProtocol (\r
339 Controller,\r
340 &gEfiDevicePathProtocolGuid,\r
341 This->DriverBindingHandle,\r
342 Controller\r
343 );\r
344 gBS->CloseProtocol (\r
345 Controller,\r
346 &gEfiPciRootBridgeIoProtocolGuid,\r
347 This->DriverBindingHandle,\r
348 Controller\r
349 );\r
350\r
351 DestroyRootBridgeByHandle (\r
352 Controller\r
353 );\r
354\r
355 return EFI_SUCCESS;\r
356 }\r
357\r
358 //\r
359 // Stop all the children\r
360 //\r
361\r
362 AllChildrenStopped = TRUE;\r
363\r
364 for (Index = 0; Index < NumberOfChildren; Index++) {\r
365\r
366 //\r
367 // De register all the pci device\r
368 //\r
369 Status = DeRegisterPciDevice (Controller, ChildHandleBuffer[Index]);\r
370\r
371 if (EFI_ERROR (Status)) {\r
372 AllChildrenStopped = FALSE;\r
373 }\r
374 }\r
375\r
376 if (!AllChildrenStopped) {\r
377 return EFI_DEVICE_ERROR;\r
378 }\r
379\r
380 return EFI_SUCCESS;\r
381}\r
382\r