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