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