]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.h
2df1fb0b94168ccc320b3faac841c19c68c882c4
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciEnumerator.h
1 /** @file
2 PCI bus enumeration logic function declaration for PCI bus module.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _EFI_PCI_ENUMERATOR_H_
16 #define _EFI_PCI_ENUMERATOR_H_
17
18 #include "PciResourceSupport.h"
19
20 /**
21 This routine is used to enumerate entire pci bus system
22 in a given platform.
23
24 @param Controller Parent controller handle.
25 @param HostBridgeHandle Host bridge handle.
26
27 @retval EFI_SUCCESS PCI enumeration finished successfully.
28 @retval other Some error occurred when enumerating the pci bus system.
29
30 **/
31 EFI_STATUS
32 PciEnumerator (
33 IN EFI_HANDLE Controller,
34 IN EFI_HANDLE HostBridgeHandle
35 );
36
37 /**
38 Enumerate PCI root bridge.
39
40 @param PciResAlloc Pointer to protocol instance of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL.
41 @param RootBridgeDev Instance of root bridge device.
42
43 @retval EFI_SUCCESS Successfully enumerated root bridge.
44 @retval other Failed to enumerate root bridge.
45
46 **/
47 EFI_STATUS
48 PciRootBridgeEnumerator (
49 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *PciResAlloc,
50 IN PCI_IO_DEVICE *RootBridgeDev
51 );
52
53 /**
54 This routine is used to process all PCI devices' Option Rom
55 on a certain root bridge.
56
57 @param Bridge Given parent's root bridge.
58 @param RomBase Base address of ROM driver loaded from.
59 @param MaxLength Maximum rom size.
60
61 **/
62 VOID
63 ProcessOptionRom (
64 IN PCI_IO_DEVICE *Bridge,
65 IN UINT64 RomBase,
66 IN UINT64 MaxLength
67 );
68
69 /**
70 This routine is used to assign bus number to the given PCI bus system
71
72 @param Bridge Parent root bridge instance.
73 @param StartBusNumber Number of beginning.
74 @param SubBusNumber The number of sub bus.
75
76 @retval EFI_SUCCESS Successfully assigned bus number.
77 @retval EFI_DEVICE_ERROR Failed to assign bus number.
78
79 **/
80 EFI_STATUS
81 PciAssignBusNumber (
82 IN PCI_IO_DEVICE *Bridge,
83 IN UINT8 StartBusNumber,
84 OUT UINT8 *SubBusNumber
85 );
86
87 /**
88 This routine is used to determine the root bridge attribute by interfacing
89 the host bridge resource allocation protocol.
90
91 @param PciResAlloc Protocol instance of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
92 @param RootBridgeDev Root bridge instance
93
94 @retval EFI_SUCCESS Successfully got root bridge's attribute.
95 @retval other Failed to get attribute.
96
97 **/
98 EFI_STATUS
99 DetermineRootBridgeAttributes (
100 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *PciResAlloc,
101 IN PCI_IO_DEVICE *RootBridgeDev
102 );
103
104 /**
105 Get Max Option Rom size on specified bridge.
106
107 @param Bridge Given bridge device instance.
108
109 @return Max size of option rom needed.
110
111 **/
112 UINT64
113 GetMaxOptionRomSize (
114 IN PCI_IO_DEVICE *Bridge
115 );
116
117 /**
118 Process attributes of devices on this host bridge
119
120 @param PciResAlloc Protocol instance of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL.
121
122 @retval EFI_SUCCESS Successfully process attribute.
123 @retval EFI_NOT_FOUND Can not find the specific root bridge device.
124 @retval other Failed to determine the root bridge device's attribute.
125
126 **/
127 EFI_STATUS
128 PciHostBridgeDeviceAttribute (
129 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *PciResAlloc
130 );
131
132 /**
133 Get resource allocation status from the ACPI resource descriptor.
134
135 @param AcpiConfig Point to Acpi configuration table.
136 @param IoResStatus Return the status of I/O resource.
137 @param Mem32ResStatus Return the status of 32-bit Memory resource.
138 @param PMem32ResStatus Return the status of 32-bit Prefetchable Memory resource.
139 @param Mem64ResStatus Return the status of 64-bit Memory resource.
140 @param PMem64ResStatus Return the status of 64-bit Prefetchable Memory resource.
141
142 **/
143 VOID
144 GetResourceAllocationStatus (
145 VOID *AcpiConfig,
146 OUT UINT64 *IoResStatus,
147 OUT UINT64 *Mem32ResStatus,
148 OUT UINT64 *PMem32ResStatus,
149 OUT UINT64 *Mem64ResStatus,
150 OUT UINT64 *PMem64ResStatus
151 );
152
153 /**
154 Remove a PCI device from device pool and mark its bar.
155
156 @param PciDevice Instance of Pci device.
157
158 @retval EFI_SUCCESS Successfully remove the PCI device.
159 @retval EFI_ABORTED Pci device is a root bridge or a PCI-PCI bridge.
160
161 **/
162 EFI_STATUS
163 RejectPciDevice (
164 IN PCI_IO_DEVICE *PciDevice
165 );
166
167 /**
168 Determine whethter a PCI device can be rejected.
169
170 @param PciResNode Pointer to Pci resource node instance.
171
172 @retval TRUE The PCI device can be rejected.
173 @retval TRUE The PCI device cannot be rejected.
174
175 **/
176 BOOLEAN
177 IsRejectiveDevice (
178 IN PCI_RESOURCE_NODE *PciResNode
179 );
180
181 /**
182 Compare two resource nodes and get the larger resource consumer.
183
184 @param PciResNode1 resource node 1 want to be compared
185 @param PciResNode2 resource node 2 want to be compared
186
187 @return Larger resource node.
188
189 **/
190 PCI_RESOURCE_NODE *
191 GetLargerConsumerDevice (
192 IN PCI_RESOURCE_NODE *PciResNode1,
193 IN PCI_RESOURCE_NODE *PciResNode2
194 );
195
196 /**
197 Get the max resource consumer in the host resource pool.
198
199 @param ResPool Pointer to resource pool node.
200
201 @return The max resource consumer in the host resource pool.
202
203 **/
204 PCI_RESOURCE_NODE *
205 GetMaxResourceConsumerDevice (
206 IN PCI_RESOURCE_NODE *ResPool
207 );
208
209 /**
210 Adjust host bridge allocation so as to reduce resource requirement
211
212 @param IoPool Pointer to instance of I/O resource Node.
213 @param Mem32Pool Pointer to instance of 32-bit memory resource Node.
214 @param PMem32Pool Pointer to instance of 32-bit Prefetchable memory resource node.
215 @param Mem64Pool Pointer to instance of 64-bit memory resource node.
216 @param PMem64Pool Pointer to instance of 64-bit Prefetchable memory resource node.
217 @param IoResStatus Status of I/O resource Node.
218 @param Mem32ResStatus Status of 32-bit memory resource Node.
219 @param PMem32ResStatus Status of 32-bit Prefetchable memory resource node.
220 @param Mem64ResStatus Status of 64-bit memory resource node.
221 @param PMem64ResStatus Status of 64-bit Prefetchable memory resource node.
222
223 @retval EFI_SUCCESS Successfully adjusted resource on host bridge.
224 @retval EFI_ABORTED Host bridge hasn't this resource type or no resource be adjusted.
225
226 **/
227 EFI_STATUS
228 PciHostBridgeAdjustAllocation (
229 IN PCI_RESOURCE_NODE *IoPool,
230 IN PCI_RESOURCE_NODE *Mem32Pool,
231 IN PCI_RESOURCE_NODE *PMem32Pool,
232 IN PCI_RESOURCE_NODE *Mem64Pool,
233 IN PCI_RESOURCE_NODE *PMem64Pool,
234 IN UINT64 IoResStatus,
235 IN UINT64 Mem32ResStatus,
236 IN UINT64 PMem32ResStatus,
237 IN UINT64 Mem64ResStatus,
238 IN UINT64 PMem64ResStatus
239 );
240
241 /**
242 Summary requests for all resource type, and construct ACPI resource
243 requestor instance.
244
245 @param Bridge detecting bridge
246 @param IoNode Pointer to instance of I/O resource Node
247 @param Mem32Node Pointer to instance of 32-bit memory resource Node
248 @param PMem32Node Pointer to instance of 32-bit Pmemory resource node
249 @param Mem64Node Pointer to instance of 64-bit memory resource node
250 @param PMem64Node Pointer to instance of 64-bit Pmemory resource node
251 @param Config Output buffer holding new constructed APCI resource requestor
252
253 @retval EFI_SUCCESS Successfully constructed ACPI resource.
254 @retval EFI_OUT_OF_RESOURCES No memory available.
255
256 **/
257 EFI_STATUS
258 ConstructAcpiResourceRequestor (
259 IN PCI_IO_DEVICE *Bridge,
260 IN PCI_RESOURCE_NODE *IoNode,
261 IN PCI_RESOURCE_NODE *Mem32Node,
262 IN PCI_RESOURCE_NODE *PMem32Node,
263 IN PCI_RESOURCE_NODE *Mem64Node,
264 IN PCI_RESOURCE_NODE *PMem64Node,
265 OUT VOID **Config
266 );
267
268 /**
269 Get resource base from an acpi configuration descriptor.
270
271 @param Config An acpi configuration descriptor.
272 @param IoBase Output of I/O resource base address.
273 @param Mem32Base Output of 32-bit memory base address.
274 @param PMem32Base Output of 32-bit prefetchable memory base address.
275 @param Mem64Base Output of 64-bit memory base address.
276 @param PMem64Base Output of 64-bit prefetchable memory base address.
277
278 **/
279 VOID
280 GetResourceBase (
281 IN VOID *Config,
282 OUT UINT64 *IoBase,
283 OUT UINT64 *Mem32Base,
284 OUT UINT64 *PMem32Base,
285 OUT UINT64 *Mem64Base,
286 OUT UINT64 *PMem64Base
287 );
288
289 /**
290 Enumerate pci bridge, allocate resource and determine attribute
291 for devices on this bridge.
292
293 @param BridgeDev Pointer to instance of bridge device.
294
295 @retval EFI_SUCCESS Successfully enumerated PCI bridge.
296 @retval other Failed to enumerate.
297
298 **/
299 EFI_STATUS
300 PciBridgeEnumerator (
301 IN PCI_IO_DEVICE *BridgeDev
302 );
303
304 /**
305 Allocate all kinds of resource for PCI bridge.
306
307 @param Bridge Pointer to bridge instance.
308
309 @retval EFI_SUCCESS Successfully allocated resource for PCI bridge.
310 @retval other Failed to allocate resource for bridge.
311
312 **/
313 EFI_STATUS
314 PciBridgeResourceAllocator (
315 IN PCI_IO_DEVICE *Bridge
316 );
317
318 /**
319 Get resource base address for a pci bridge device.
320
321 @param Bridge Given Pci driver instance.
322 @param IoBase Output for base address of I/O type resource.
323 @param Mem32Base Output for base address of 32-bit memory type resource.
324 @param PMem32Base Ooutput for base address of 32-bit Pmemory type resource.
325 @param Mem64Base Output for base address of 64-bit memory type resource.
326 @param PMem64Base Output for base address of 64-bit Pmemory type resource.
327
328 @retval EFI_SUCCESS Successfully got resource base address.
329 @retval EFI_OUT_OF_RESOURCES PCI bridge is not available.
330
331 **/
332 EFI_STATUS
333 GetResourceBaseFromBridge (
334 IN PCI_IO_DEVICE *Bridge,
335 OUT UINT64 *IoBase,
336 OUT UINT64 *Mem32Base,
337 OUT UINT64 *PMem32Base,
338 OUT UINT64 *Mem64Base,
339 OUT UINT64 *PMem64Base
340 );
341
342 /**
343 Process Option Rom on this host bridge
344
345 @param PciResAlloc Pointer to instance of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL.
346
347 @retval EFI_NOT_FOUND Can not find the root bridge instance.
348 @retval EFI_SUCCESS Success process.
349 **/
350 EFI_STATUS
351 PciHostBridgeP2CProcess (
352 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *PciResAlloc
353 );
354
355 /**
356 These are the notifications from the PCI bus driver that it is about to enter a certain
357 phase of the PCI enumeration process.
358
359 This member function can be used to notify the host bridge driver to perform specific actions,
360 including any chipset-specific initialization, so that the chipset is ready to enter the next phase.
361 Eight notification points are defined at this time. See belows:
362 EfiPciHostBridgeBeginEnumeration Resets the host bridge PCI apertures and internal data
363 structures. The PCI enumerator should issue this notification
364 before starting a fresh enumeration process. Enumeration cannot
365 be restarted after sending any other notification such as
366 EfiPciHostBridgeBeginBusAllocation.
367 EfiPciHostBridgeBeginBusAllocation The bus allocation phase is about to begin. No specific action is
368 required here. This notification can be used to perform any
369 chipset-specific programming.
370 EfiPciHostBridgeEndBusAllocation The bus allocation and bus programming phase is complete. No
371 specific action is required here. This notification can be used to
372 perform any chipset-specific programming.
373 EfiPciHostBridgeBeginResourceAllocation
374 The resource allocation phase is about to begin. No specific
375 action is required here. This notification can be used to perform
376 any chipset-specific programming.
377 EfiPciHostBridgeAllocateResources Allocates resources per previously submitted requests for all the PCI
378 root bridges. These resource settings are returned on the next call to
379 GetProposedResources(). Before calling NotifyPhase() with a Phase of
380 EfiPciHostBridgeAllocateResource, the PCI bus enumerator is responsible
381 for gathering I/O and memory requests for
382 all the PCI root bridges and submitting these requests using
383 SubmitResources(). This function pads the resource amount
384 to suit the root bridge hardware, takes care of dependencies between
385 the PCI root bridges, and calls the Global Coherency Domain (GCD)
386 with the allocation request. In the case of padding, the allocated range
387 could be bigger than what was requested.
388 EfiPciHostBridgeSetResources Programs the host bridge hardware to decode previously allocated
389 resources (proposed resources) for all the PCI root bridges. After the
390 hardware is programmed, reassigning resources will not be supported.
391 The bus settings are not affected.
392 EfiPciHostBridgeFreeResources Deallocates resources that were previously allocated for all the PCI
393 root bridges and resets the I/O and memory apertures to their initial
394 state. The bus settings are not affected. If the request to allocate
395 resources fails, the PCI enumerator can use this notification to
396 deallocate previous resources, adjust the requests, and retry
397 allocation.
398 EfiPciHostBridgeEndResourceAllocation The resource allocation phase is completed. No specific action is
399 required here. This notification can be used to perform any chipsetspecific
400 programming.
401
402 @param[in] PciResAlloc The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
403 @param[in] Phase The phase during enumeration
404
405 @retval EFI_NOT_READY This phase cannot be entered at this time. For example, this error
406 is valid for a Phase of EfiPciHostBridgeAllocateResources if
407 SubmitResources() has not been called for one or more
408 PCI root bridges before this call
409 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. This error is valid
410 for a Phase of EfiPciHostBridgeSetResources.
411 @retval EFI_INVALID_PARAMETER Invalid phase parameter
412 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
413 This error is valid for a Phase of EfiPciHostBridgeAllocateResources if the
414 previously submitted resource requests cannot be fulfilled or
415 were only partially fulfilled.
416 @retval EFI_SUCCESS The notification was accepted without any errors.
417
418 **/
419 EFI_STATUS
420 NotifyPhase (
421 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *PciResAlloc,
422 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
423 );
424
425 /**
426 Provides the hooks from the PCI bus driver to every PCI controller (device/function) at various
427 stages of the PCI enumeration process that allow the host bridge driver to preinitialize individual
428 PCI controllers before enumeration.
429
430 This function is called during the PCI enumeration process. No specific action is expected from this
431 member function. It allows the host bridge driver to preinitialize individual PCI controllers before
432 enumeration.
433
434 @param Bridge Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
435 @param Bus The bus number of the pci device.
436 @param Device The device number of the pci device.
437 @param Func The function number of the pci device.
438 @param Phase The phase of the PCI device enumeration.
439
440 @retval EFI_SUCCESS The requested parameters were returned.
441 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
442 @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined in
443 EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.
444 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. The PCI enumerator should
445 not enumerate this device, including its child devices if it is a PCI-to-PCI
446 bridge.
447
448 **/
449 EFI_STATUS
450 PreprocessController (
451 IN PCI_IO_DEVICE *Bridge,
452 IN UINT8 Bus,
453 IN UINT8 Device,
454 IN UINT8 Func,
455 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
456 );
457
458 /**
459 This function allows the PCI bus driver to be notified to act as requested when a hot-plug event has
460 happened on the hot-plug controller. Currently, the operations include add operation and remove operation..
461
462 @param This A pointer to the hot plug request protocol.
463 @param Operation The operation the PCI bus driver is requested to make.
464 @param Controller The handle of the hot-plug controller.
465 @param RemainingDevicePath The remaining device path for the PCI-like hot-plug device.
466 @param NumberOfChildren The number of child handles.
467 For a add operation, it is an output parameter.
468 For a remove operation, it's an input parameter.
469 @param ChildHandleBuffer The buffer which contains the child handles.
470
471 @retval EFI_INVALID_PARAMETER Operation is not a legal value.
472 Controller is NULL or not a valid handle.
473 NumberOfChildren is NULL.
474 ChildHandleBuffer is NULL while Operation is add.
475 @retval EFI_OUT_OF_RESOURCES There are no enough resources to start the devices.
476 @retval EFI_NOT_FOUND Can not find bridge according to controller handle.
477 @retval EFI_SUCCESS The handles for the specified device have been created or destroyed
478 as requested, and for an add operation, the new handles are
479 returned in ChildHandleBuffer.
480 **/
481 EFI_STATUS
482 EFIAPI
483 PciHotPlugRequestNotify (
484 IN EFI_PCI_HOTPLUG_REQUEST_PROTOCOL * This,
485 IN EFI_PCI_HOTPLUG_OPERATION Operation,
486 IN EFI_HANDLE Controller,
487 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL,
488 IN OUT UINT8 *NumberOfChildren,
489 IN OUT EFI_HANDLE * ChildHandleBuffer
490 );
491
492 /**
493 Search hostbridge according to given handle
494
495 @param RootBridgeHandle Host bridge handle.
496
497 @retval TRUE Found host bridge handle.
498 @retval FALSE Not found hot bridge handle.
499
500 **/
501 BOOLEAN
502 SearchHostBridgeHandle (
503 IN EFI_HANDLE RootBridgeHandle
504 );
505
506 /**
507 Add host bridge handle to global variable for enumerating.
508
509 @param HostBridgeHandle Host bridge handle.
510
511 @retval EFI_SUCCESS Successfully added host bridge.
512 @retval EFI_ABORTED Host bridge is NULL, or given host bridge
513 has been in host bridge list.
514
515 **/
516 EFI_STATUS
517 AddHostBridgeEnumerator (
518 IN EFI_HANDLE HostBridgeHandle
519 );
520
521 #endif