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