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