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