]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*++\r |
2 | \r | |
98419ef4 | 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 | |
878ddf1f | 11 | \r |
12 | Module Name:\r | |
13 | \r | |
14 | PciBus.c\r | |
98419ef4 | 15 | \r |
878ddf1f | 16 | Abstract:\r |
17 | \r | |
18 | PCI Bus Driver\r | |
19 | \r | |
20 | Revision History\r | |
98419ef4 | 21 | \r |
878ddf1f | 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 | |
30 | EFI_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 | |
878ddf1f | 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 | |
98419ef4 | 70 | EFI_SUCCESS\r |
71 | EFI_DEVICE_ERROR\r | |
878ddf1f | 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 | InstallHotPlugRequestProtocol (&Status);\r | |
86 | return Status;\r | |
87 | }\r | |
88 | \r | |
89 | EFI_STATUS\r | |
90 | EFIAPI\r | |
91 | PciBusDriverBindingSupported (\r | |
92 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
93 | IN EFI_HANDLE Controller,\r | |
94 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
95 | )\r | |
96 | /*++\r | |
97 | \r | |
98 | Routine Description:\r | |
99 | \r | |
100 | Check to see if pci bus driver supports the given controller\r | |
101 | \r | |
102 | Arguments:\r | |
98419ef4 | 103 | \r |
878ddf1f | 104 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
105 | IN EFI_HANDLE Controller,\r | |
106 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
107 | \r | |
108 | Returns:\r | |
109 | \r | |
110 | EFI_SUCCESS\r | |
111 | \r | |
112 | --*/\r | |
113 | // TODO: This - add argument and description to function comment\r | |
114 | // TODO: Controller - add argument and description to function comment\r | |
115 | // TODO: RemainingDevicePath - add argument and description to function comment\r | |
116 | // TODO: EFI_UNSUPPORTED - add return value to function comment\r | |
117 | {\r | |
118 | EFI_STATUS Status;\r | |
119 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
120 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r | |
121 | EFI_DEV_PATH_PTR Node;\r | |
122 | \r | |
123 | if (RemainingDevicePath != NULL) {\r | |
124 | Node.DevPath = RemainingDevicePath;\r | |
125 | if (Node.DevPath->Type != HARDWARE_DEVICE_PATH ||\r | |
126 | Node.DevPath->SubType != HW_PCI_DP ||\r | |
127 | DevicePathNodeLength(Node.DevPath) != sizeof(PCI_DEVICE_PATH)) {\r | |
128 | return EFI_UNSUPPORTED;\r | |
129 | }\r | |
130 | }\r | |
131 | //\r | |
132 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
133 | //\r | |
134 | Status = gBS->OpenProtocol (\r | |
135 | Controller,\r | |
136 | &gEfiDevicePathProtocolGuid,\r | |
137 | (VOID **) &ParentDevicePath,\r | |
138 | This->DriverBindingHandle,\r | |
139 | Controller,\r | |
140 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
141 | );\r | |
142 | if (Status == EFI_ALREADY_STARTED) {\r | |
143 | return EFI_SUCCESS;\r | |
144 | }\r | |
145 | \r | |
146 | if (EFI_ERROR (Status)) {\r | |
147 | return Status;\r | |
148 | }\r | |
149 | \r | |
150 | gBS->CloseProtocol (\r | |
151 | Controller,\r | |
152 | &gEfiDevicePathProtocolGuid,\r | |
153 | This->DriverBindingHandle,\r | |
154 | Controller\r | |
155 | );\r | |
156 | \r | |
157 | Status = gBS->OpenProtocol (\r | |
158 | Controller,\r | |
159 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
160 | (VOID **) &PciRootBridgeIo,\r | |
161 | This->DriverBindingHandle,\r | |
162 | Controller,\r | |
163 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
164 | );\r | |
165 | if (Status == EFI_ALREADY_STARTED) {\r | |
166 | return EFI_SUCCESS;\r | |
167 | }\r | |
168 | \r | |
169 | if (EFI_ERROR (Status)) {\r | |
170 | return Status;\r | |
171 | }\r | |
172 | \r | |
173 | gBS->CloseProtocol (\r | |
174 | Controller,\r | |
175 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
176 | This->DriverBindingHandle,\r | |
177 | Controller\r | |
178 | );\r | |
179 | \r | |
180 | return EFI_SUCCESS;\r | |
181 | }\r | |
182 | \r | |
183 | EFI_STATUS\r | |
184 | EFIAPI\r | |
185 | PciBusDriverBindingStart (\r | |
186 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
187 | IN EFI_HANDLE Controller,\r | |
188 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
189 | )\r | |
190 | /*++\r | |
191 | \r | |
192 | Routine Description:\r | |
193 | \r | |
194 | Start to management the controller passed in\r | |
195 | \r | |
196 | Arguments:\r | |
98419ef4 | 197 | \r |
878ddf1f | 198 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
199 | IN EFI_HANDLE Controller,\r | |
200 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
201 | \r | |
202 | Returns:\r | |
98419ef4 | 203 | \r |
878ddf1f | 204 | \r |
205 | --*/\r | |
206 | // TODO: This - add argument and description to function comment\r | |
207 | // TODO: Controller - add argument and description to function comment\r | |
208 | // TODO: RemainingDevicePath - add argument and description to function comment\r | |
209 | // TODO: EFI_SUCCESS - add return value to function comment\r | |
210 | {\r | |
211 | EFI_STATUS Status;\r | |
212 | \r | |
878ddf1f | 213 | //\r |
214 | // If PCI Platform protocol is available, get it now.\r | |
215 | // If the platform implements this, it must be installed before BDS phase\r | |
216 | //\r | |
217 | gPciPlatformProtocol = NULL;\r | |
218 | gBS->LocateProtocol (\r | |
219 | &gEfiPciPlatformProtocolGuid,\r | |
220 | NULL,\r | |
221 | (VOID **) &gPciPlatformProtocol\r | |
222 | );\r | |
223 | \r | |
224 | gFullEnumeration = (BOOLEAN) ((SearchHostBridgeHandle (Controller) ? FALSE : TRUE));\r | |
225 | \r | |
226 | //\r | |
227 | // Enumerate the entire host bridge\r | |
228 | // After enumeration, a database that records all the device information will be created\r | |
229 | //\r | |
230 | //\r | |
231 | Status = PciEnumerator (Controller);\r | |
232 | \r | |
233 | if (EFI_ERROR (Status)) {\r | |
234 | return Status;\r | |
235 | }\r | |
98419ef4 | 236 | \r |
878ddf1f | 237 | //\r |
238 | // Enable PCI device specified by remaining device path. BDS or other driver can call the\r | |
239 | // start more than once.\r | |
240 | //\r | |
98419ef4 | 241 | \r |
878ddf1f | 242 | StartPciDevices (Controller, RemainingDevicePath);\r |
243 | \r | |
244 | return EFI_SUCCESS;\r | |
245 | }\r | |
246 | \r | |
247 | EFI_STATUS\r | |
248 | EFIAPI\r | |
249 | PciBusDriverBindingStop (\r | |
250 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
251 | IN EFI_HANDLE Controller,\r | |
252 | IN UINTN NumberOfChildren,\r | |
253 | IN EFI_HANDLE *ChildHandleBuffer\r | |
254 | )\r | |
255 | /*++\r | |
256 | \r | |
257 | Routine Description:\r | |
258 | \r | |
259 | Stop one or more children created at start of pci bus driver\r | |
260 | if all the the children get closed, close the protocol\r | |
261 | \r | |
262 | Arguments:\r | |
98419ef4 | 263 | \r |
878ddf1f | 264 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
265 | IN EFI_HANDLE Controller,\r | |
266 | IN UINTN NumberOfChildren,\r | |
267 | IN EFI_HANDLE *ChildHandleBuffer\r | |
268 | \r | |
269 | Returns:\r | |
270 | \r | |
98419ef4 | 271 | \r |
878ddf1f | 272 | --*/\r |
273 | // TODO: This - add argument and description to function comment\r | |
274 | // TODO: Controller - add argument and description to function comment\r | |
275 | // TODO: NumberOfChildren - add argument and description to function comment\r | |
276 | // TODO: ChildHandleBuffer - add argument and description to function comment\r | |
277 | // TODO: EFI_SUCCESS - add return value to function comment\r | |
278 | // TODO: EFI_DEVICE_ERROR - add return value to function comment\r | |
279 | // TODO: EFI_SUCCESS - add return value to function comment\r | |
280 | {\r | |
281 | EFI_STATUS Status;\r | |
282 | UINTN Index;\r | |
283 | BOOLEAN AllChildrenStopped;\r | |
284 | \r | |
285 | if (NumberOfChildren == 0) {\r | |
286 | //\r | |
287 | // Close the bus driver\r | |
288 | //\r | |
289 | gBS->CloseProtocol (\r | |
290 | Controller,\r | |
291 | &gEfiDevicePathProtocolGuid,\r | |
292 | This->DriverBindingHandle,\r | |
293 | Controller\r | |
294 | );\r | |
295 | gBS->CloseProtocol (\r | |
296 | Controller,\r | |
297 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
298 | This->DriverBindingHandle,\r | |
299 | Controller\r | |
300 | );\r | |
301 | \r | |
302 | DestroyRootBridgeByHandle (\r | |
303 | Controller\r | |
304 | );\r | |
305 | \r | |
306 | return EFI_SUCCESS;\r | |
307 | }\r | |
308 | \r | |
309 | //\r | |
310 | // Stop all the children\r | |
311 | //\r | |
312 | \r | |
313 | AllChildrenStopped = TRUE;\r | |
314 | \r | |
315 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
316 | \r | |
317 | //\r | |
318 | // De register all the pci device\r | |
319 | //\r | |
320 | Status = DeRegisterPciDevice (Controller, ChildHandleBuffer[Index]);\r | |
321 | \r | |
322 | if (EFI_ERROR (Status)) {\r | |
323 | AllChildrenStopped = FALSE;\r | |
324 | }\r | |
325 | }\r | |
326 | \r | |
327 | if (!AllChildrenStopped) {\r | |
328 | return EFI_DEVICE_ERROR;\r | |
329 | }\r | |
330 | \r | |
331 | return EFI_SUCCESS;\r | |
332 | }\r |