]>
Commit | Line | Data |
---|---|---|
10590588 | 1 | /*++\r |
2 | \r | |
b1f700a8 HT |
3 | Copyright (c) 2005 - 2006, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
10590588 | 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 Support Function Prototypes\r | |
28 | //\r | |
29 | \r | |
30 | EFI_STATUS\r | |
31 | EFIAPI\r | |
32 | PciBusEntryPoint (\r | |
33 | IN EFI_HANDLE ImageHandle,\r | |
34 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
35 | );\r | |
36 | \r | |
37 | EFI_STATUS\r | |
38 | EFIAPI\r | |
39 | PciBusDriverBindingSupported (\r | |
40 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
41 | IN EFI_HANDLE Controller,\r | |
42 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
43 | );\r | |
44 | \r | |
45 | EFI_STATUS\r | |
46 | EFIAPI\r | |
47 | PciBusDriverBindingStart (\r | |
48 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
49 | IN EFI_HANDLE Controller,\r | |
50 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
51 | );\r | |
52 | \r | |
53 | EFI_STATUS\r | |
54 | EFIAPI\r | |
55 | PciBusDriverBindingStop (\r | |
56 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
57 | IN EFI_HANDLE Controller,\r | |
58 | IN UINTN NumberOfChildren,\r | |
59 | IN EFI_HANDLE *ChildHandleBuffer\r | |
60 | );\r | |
61 | \r | |
62 | \r | |
63 | //\r | |
64 | // PCI Bus Driver Global Variables\r | |
65 | //\r | |
66 | \r | |
67 | EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding = {\r | |
68 | PciBusDriverBindingSupported,\r | |
69 | PciBusDriverBindingStart,\r | |
70 | PciBusDriverBindingStop,\r | |
71 | 0xa,\r | |
72 | NULL,\r | |
73 | NULL\r | |
74 | };\r | |
75 | \r | |
76 | BOOLEAN gFullEnumeration;\r | |
e56dd2ce | 77 | \r |
78 | UINT64 gAllOne = 0xFFFFFFFFFFFFFFFFULL;\r | |
79 | UINT64 gAllZero = 0;\r | |
10590588 | 80 | \r |
81 | //\r | |
82 | // PCI Bus Driver Support Functions\r | |
83 | //\r | |
84 | EFI_STATUS\r | |
85 | EFIAPI\r | |
86 | PciBusEntryPoint (\r | |
87 | IN EFI_HANDLE ImageHandle,\r | |
88 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
89 | )\r | |
90 | /*++\r | |
91 | \r | |
92 | Routine Description:\r | |
93 | \r | |
94 | Initialize the global variables\r | |
95 | publish the driver binding protocol\r | |
96 | \r | |
97 | Arguments:\r | |
98 | \r | |
99 | IN EFI_HANDLE ImageHandle,\r | |
100 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
101 | \r | |
102 | Returns:\r | |
103 | \r | |
104 | EFI_SUCCESS \r | |
105 | EFI_DEVICE_ERROR \r | |
106 | \r | |
107 | --*/\r | |
108 | {\r | |
109 | EFI_STATUS Status;\r | |
110 | \r | |
111 | //\r | |
112 | // Initialize the EFI Driver Library\r | |
113 | //\r | |
114 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
115 | ImageHandle,\r | |
116 | SystemTable,\r | |
117 | &gPciBusDriverBinding,\r | |
118 | ImageHandle,\r | |
119 | &gPciBusComponentName,\r | |
120 | &gPciBusComponentName2\r | |
121 | );\r | |
122 | ASSERT_EFI_ERROR (Status);\r | |
123 | \r | |
124 | InitializePciDevicePool ();\r | |
125 | \r | |
126 | gFullEnumeration = TRUE;\r | |
127 | \r | |
128 | return Status;\r | |
129 | }\r | |
130 | \r | |
131 | EFI_STATUS\r | |
132 | EFIAPI\r | |
133 | PciBusDriverBindingSupported (\r | |
134 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
135 | IN EFI_HANDLE Controller,\r | |
136 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
137 | )\r | |
138 | /*++\r | |
139 | \r | |
140 | Routine Description:\r | |
141 | \r | |
142 | Check to see if pci bus driver supports the given controller\r | |
143 | \r | |
144 | Arguments:\r | |
145 | \r | |
146 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
147 | IN EFI_HANDLE Controller,\r | |
148 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
149 | \r | |
150 | Returns:\r | |
151 | \r | |
152 | EFI_SUCCESS\r | |
153 | \r | |
154 | --*/\r | |
155 | {\r | |
156 | EFI_STATUS Status;\r | |
157 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
158 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r | |
159 | EFI_DEV_PATH_PTR Node;\r | |
160 | \r | |
161 | if (RemainingDevicePath != NULL) {\r | |
162 | Node.DevPath = RemainingDevicePath;\r | |
163 | if (Node.DevPath->Type != HARDWARE_DEVICE_PATH ||\r | |
164 | Node.DevPath->SubType != HW_PCI_DP ||\r | |
165 | DevicePathNodeLength(Node.DevPath) != sizeof(PCI_DEVICE_PATH)) {\r | |
166 | return EFI_UNSUPPORTED;\r | |
167 | }\r | |
168 | }\r | |
169 | //\r | |
170 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
171 | //\r | |
172 | Status = gBS->OpenProtocol (\r | |
173 | Controller,\r | |
174 | &gEfiDevicePathProtocolGuid,\r | |
175 | (VOID **) &ParentDevicePath,\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 | &gEfiDevicePathProtocolGuid,\r | |
191 | This->DriverBindingHandle,\r | |
192 | Controller\r | |
193 | );\r | |
194 | \r | |
195 | Status = gBS->OpenProtocol (\r | |
196 | Controller,\r | |
197 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
198 | (VOID **) &PciRootBridgeIo,\r | |
199 | This->DriverBindingHandle,\r | |
200 | Controller,\r | |
201 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
202 | );\r | |
203 | if (Status == EFI_ALREADY_STARTED) {\r | |
204 | return EFI_SUCCESS;\r | |
205 | }\r | |
206 | \r | |
207 | if (EFI_ERROR (Status)) {\r | |
208 | return Status;\r | |
209 | }\r | |
210 | \r | |
211 | gBS->CloseProtocol (\r | |
212 | Controller,\r | |
213 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
214 | This->DriverBindingHandle,\r | |
215 | Controller\r | |
216 | );\r | |
217 | \r | |
218 | return EFI_SUCCESS;\r | |
219 | }\r | |
220 | \r | |
221 | EFI_STATUS\r | |
222 | EFIAPI\r | |
223 | PciBusDriverBindingStart (\r | |
224 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
225 | IN EFI_HANDLE Controller,\r | |
226 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
227 | )\r | |
228 | /*++\r | |
229 | \r | |
230 | Routine Description:\r | |
231 | \r | |
232 | Start to management the controller passed in\r | |
233 | \r | |
234 | Arguments:\r | |
235 | \r | |
236 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
237 | IN EFI_HANDLE Controller,\r | |
238 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
239 | \r | |
240 | Returns:\r | |
241 | \r | |
242 | \r | |
243 | --*/\r | |
244 | {\r | |
245 | EFI_STATUS Status;\r | |
246 | \r | |
247 | //\r | |
248 | // Enumerate the entire host bridge\r | |
249 | // After enumeration, a database that records all the device information will be created\r | |
250 | //\r | |
251 | //\r | |
252 | Status = PciEnumerator (Controller);\r | |
253 | \r | |
254 | if (EFI_ERROR (Status)) {\r | |
255 | return Status;\r | |
256 | }\r | |
257 | \r | |
258 | //\r | |
259 | // Enable PCI device specified by remaining device path. BDS or other driver can call the\r | |
260 | // start more than once.\r | |
261 | //\r | |
262 | \r | |
263 | StartPciDevices (Controller, RemainingDevicePath);\r | |
264 | \r | |
265 | return EFI_SUCCESS;\r | |
266 | }\r | |
267 | \r | |
268 | EFI_STATUS\r | |
269 | EFIAPI\r | |
270 | PciBusDriverBindingStop (\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 | |
276 | /*++\r | |
277 | \r | |
278 | Routine Description:\r | |
279 | \r | |
280 | Stop one or more children created at start of pci bus driver\r | |
281 | if all the the children get closed, close the protocol\r | |
282 | \r | |
283 | Arguments:\r | |
284 | \r | |
285 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
286 | IN EFI_HANDLE Controller,\r | |
287 | IN UINTN NumberOfChildren,\r | |
288 | IN EFI_HANDLE *ChildHandleBuffer\r | |
289 | \r | |
290 | Returns:\r | |
291 | \r | |
292 | \r | |
293 | --*/\r | |
294 | {\r | |
295 | EFI_STATUS Status;\r | |
296 | UINTN Index;\r | |
297 | BOOLEAN AllChildrenStopped;\r | |
298 | \r | |
299 | if (NumberOfChildren == 0) {\r | |
300 | //\r | |
301 | // Close the bus driver\r | |
302 | //\r | |
303 | gBS->CloseProtocol (\r | |
304 | Controller,\r | |
305 | &gEfiDevicePathProtocolGuid,\r | |
306 | This->DriverBindingHandle,\r | |
307 | Controller\r | |
308 | );\r | |
309 | gBS->CloseProtocol (\r | |
310 | Controller,\r | |
311 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
312 | This->DriverBindingHandle,\r | |
313 | Controller\r | |
314 | );\r | |
315 | \r | |
316 | DestroyRootBridgeByHandle (\r | |
317 | Controller\r | |
318 | );\r | |
319 | \r | |
320 | return EFI_SUCCESS;\r | |
321 | }\r | |
322 | \r | |
323 | //\r | |
324 | // Stop all the children\r | |
325 | //\r | |
326 | \r | |
327 | AllChildrenStopped = TRUE;\r | |
328 | \r | |
329 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
330 | \r | |
331 | //\r | |
332 | // De register all the pci device\r | |
333 | //\r | |
334 | Status = DeRegisterPciDevice (Controller, ChildHandleBuffer[Index]);\r | |
335 | \r | |
336 | if (EFI_ERROR (Status)) {\r | |
337 | AllChildrenStopped = FALSE;\r | |
338 | }\r | |
339 | }\r | |
340 | \r | |
341 | if (!AllChildrenStopped) {\r | |
342 | return EFI_DEVICE_ERROR;\r | |
343 | }\r | |
344 | \r | |
345 | return EFI_SUCCESS;\r | |
346 | }\r |