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