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