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