3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #ifndef _EFI_PCI_BUS_H_
13 #define _EFI_PCI_BUS_H_
17 #include <Protocol/LoadedImage.h>
18 #include <Protocol/PciHostBridgeResourceAllocation.h>
19 #include <Protocol/PciIo.h>
20 #include <Protocol/LoadFile2.h>
21 #include <Protocol/PciRootBridgeIo.h>
22 #include <Protocol/PciHotPlugRequest.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/PciPlatform.h>
25 #include <Protocol/PciHotPlugInit.h>
26 #include <Protocol/Decompress.h>
27 #include <Protocol/BusSpecificDriverOverride.h>
28 #include <Protocol/IncompatiblePciDeviceSupport.h>
29 #include <Protocol/PciOverride.h>
30 #include <Protocol/PciEnumerationComplete.h>
32 #include <Library/DebugLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/BaseLib.h>
35 #include <Library/UefiLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/ReportStatusCodeLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/DevicePathLib.h>
41 #include <Library/PcdLib.h>
42 #include <Library/PeCoffLib.h>
44 #include <IndustryStandard/Pci.h>
45 #include <IndustryStandard/PeImage.h>
46 #include <IndustryStandard/Acpi.h>
48 typedef struct _PCI_IO_DEVICE PCI_IO_DEVICE
;
49 typedef struct _PCI_BAR PCI_BAR
;
51 #define EFI_PCI_RID(Bus, Device, Function) (((UINT32)Bus << 8) + ((UINT32)Device << 3) + (UINT32)Function)
52 #define EFI_PCI_BUS_OF_RID(RID) ((UINT32)RID >> 8)
54 #define EFI_PCI_IOV_POLICY_ARI 0x0001
55 #define EFI_PCI_IOV_POLICY_SRIOV 0x0002
56 #define EFI_PCI_IOV_POLICY_MRIOV 0x0004
59 PciBarTypeUnknown
= 0,
72 #define VGABASE1 0x3B0
73 #define VGALIMIT1 0x3BB
75 #define VGABASE2 0x3C0
76 #define VGALIMIT2 0x3DF
79 #define ISALIMIT 0x3FF
95 // defined in PCI Card Specification, 8.0
97 #define PCI_CARD_MEMORY_BASE_0 0x1C
98 #define PCI_CARD_MEMORY_LIMIT_0 0x20
99 #define PCI_CARD_MEMORY_BASE_1 0x24
100 #define PCI_CARD_MEMORY_LIMIT_1 0x28
101 #define PCI_CARD_IO_BASE_0_LOWER 0x2C
102 #define PCI_CARD_IO_BASE_0_UPPER 0x2E
103 #define PCI_CARD_IO_LIMIT_0_LOWER 0x30
104 #define PCI_CARD_IO_LIMIT_0_UPPER 0x32
105 #define PCI_CARD_IO_BASE_1_LOWER 0x34
106 #define PCI_CARD_IO_BASE_1_UPPER 0x36
107 #define PCI_CARD_IO_LIMIT_1_LOWER 0x38
108 #define PCI_CARD_IO_LIMIT_1_UPPER 0x3A
109 #define PCI_CARD_BRIDGE_CONTROL 0x3E
111 #define PCI_CARD_PREFETCHABLE_MEMORY_0_ENABLE BIT8
112 #define PCI_CARD_PREFETCHABLE_MEMORY_1_ENABLE BIT9
116 #define PPB_IO_RANGE 2
117 #define PPB_MEM32_RANGE 3
118 #define PPB_PMEM32_RANGE 4
119 #define PPB_PMEM64_RANGE 5
120 #define PPB_MEM64_RANGE 0xFF
128 #define EFI_BRIDGE_IO32_DECODE_SUPPORTED 0x0001
129 #define EFI_BRIDGE_PMEM32_DECODE_SUPPORTED 0x0002
130 #define EFI_BRIDGE_PMEM64_DECODE_SUPPORTED 0x0004
131 #define EFI_BRIDGE_IO16_DECODE_SUPPORTED 0x0008
132 #define EFI_BRIDGE_PMEM_MEM_COMBINE_SUPPORTED 0x0010
133 #define EFI_BRIDGE_MEM64_DECODE_SUPPORTED 0x0020
134 #define EFI_BRIDGE_MEM32_DECODE_SUPPORTED 0x0040
136 #define PCI_MAX_HOST_BRIDGE_NUM 0x0010
139 // Define option for attribute
141 #define EFI_SET_SUPPORTS 0
142 #define EFI_SET_ATTRIBUTES 1
144 #define PCI_IO_DEVICE_SIGNATURE SIGNATURE_32 ('p', 'c', 'i', 'o')
146 struct _PCI_IO_DEVICE
{
149 EFI_PCI_IO_PROTOCOL PciIo
;
152 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL PciDriverOverride
;
153 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
154 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
155 EFI_LOAD_FILE2_PROTOCOL LoadFile2
;
158 // PCI configuration space header type
163 // Bus number, Device number, Function number
167 UINT8 FunctionNumber
;
170 // BAR for this PCI Device
172 PCI_BAR PciBar
[PCI_MAX_BAR
];
175 // The bridge device this pci device is subject to
177 PCI_IO_DEVICE
*Parent
;
180 // A linked list for children Pci Device if it is bridge device
182 LIST_ENTRY ChildList
;
185 // TRUE if the PCI bus driver creates the handle for this PCI device
190 // TRUE if the PCI bus driver successfully allocates the resource required by
196 // The attribute this PCI device currently set
201 // The attributes this PCI device actually supports
206 // The resource decode the bridge supports
211 // TRUE if the ROM image is from the PCI Option ROM BAR
216 // The OptionRom Size
221 // The OptionRom Size
226 // TRUE if all OpROM (in device or in platform specific position) have been processed
228 BOOLEAN AllOpRomProcessed
;
231 // TRUE if there is any EFI driver in the OptionRom
236 // A list tracking reserved resource on a bridge device
238 LIST_ENTRY ReservedResourceList
;
241 // A list tracking image handle of platform specific overriding driver
243 LIST_ENTRY OptionRomDriverList
;
245 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*ResourcePaddingDescriptors
;
246 EFI_HPC_PADDING_ATTRIBUTES PaddingAttributes
;
253 UINT8 PciExpressCapabilityOffset
;
254 UINT32 AriCapabilityOffset
;
255 UINT32 SrIovCapabilityOffset
;
256 UINT32 MrIovCapabilityOffset
;
257 PCI_BAR VfPciBar
[PCI_MAX_BAR
];
258 UINT32 SystemPageSize
;
260 UINT16 ReservedBusNum
;
263 // Per PCI to PCI Bridge spec, I/O window is 4K aligned,
264 // but some chipsets support non-standard I/O window alignments less than 4K.
265 // This field is used to support this case.
267 UINT16 BridgeIoAlignment
;
270 #define PCI_IO_DEVICE_FROM_PCI_IO_THIS(a) \
271 CR (a, PCI_IO_DEVICE, PciIo, PCI_IO_DEVICE_SIGNATURE)
273 #define PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS(a) \
274 CR (a, PCI_IO_DEVICE, PciDriverOverride, PCI_IO_DEVICE_SIGNATURE)
276 #define PCI_IO_DEVICE_FROM_LINK(a) \
277 CR (a, PCI_IO_DEVICE, Link, PCI_IO_DEVICE_SIGNATURE)
279 #define PCI_IO_DEVICE_FROM_LOAD_FILE2_THIS(a) \
280 CR (a, PCI_IO_DEVICE, LoadFile2, PCI_IO_DEVICE_SIGNATURE)
287 extern EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL
*gEfiIncompatiblePciDeviceSupport
;
288 extern EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding
;
289 extern EFI_COMPONENT_NAME_PROTOCOL gPciBusComponentName
;
290 extern EFI_COMPONENT_NAME2_PROTOCOL gPciBusComponentName2
;
291 extern BOOLEAN gFullEnumeration
;
292 extern UINTN gPciHostBridgeNumber
;
293 extern EFI_HANDLE gPciHostBrigeHandles
[PCI_MAX_HOST_BRIDGE_NUM
];
294 extern UINT64 gAllOne
;
295 extern UINT64 gAllZero
;
296 extern EFI_PCI_PLATFORM_PROTOCOL
*gPciPlatformProtocol
;
297 extern EFI_PCI_OVERRIDE_PROTOCOL
*gPciOverrideProtocol
;
298 extern BOOLEAN mReserveIsaAliases
;
299 extern BOOLEAN mReserveVgaAliases
;
302 Macro that checks whether device is a GFX device.
304 @param _p Specified device.
306 @retval TRUE Device is a GFX device.
307 @retval FALSE Device is not a GFX device.
310 #define IS_PCI_GFX(_p) IS_CLASS2 (_p, PCI_CLASS_DISPLAY, PCI_CLASS_DISPLAY_OTHER)
313 Test to see if this driver supports ControllerHandle. Any ControllerHandle
314 than contains a gEfiPciRootBridgeIoProtocolGuid protocol can be supported.
316 @param This Protocol instance pointer.
317 @param Controller Handle of device to test.
318 @param RemainingDevicePath Optional parameter use to pick a specific child
321 @retval EFI_SUCCESS This driver supports this device.
322 @retval EFI_ALREADY_STARTED This driver is already running on this device.
323 @retval other This driver does not support this device.
328 PciBusDriverBindingSupported (
329 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
330 IN EFI_HANDLE Controller
,
331 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
335 Start this driver on ControllerHandle and enumerate Pci bus and start
336 all device under PCI bus.
338 @param This Protocol instance pointer.
339 @param Controller Handle of device to bind driver to.
340 @param RemainingDevicePath Optional parameter use to pick a specific child
343 @retval EFI_SUCCESS This driver is added to ControllerHandle.
344 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
345 @retval other This driver does not support this device.
350 PciBusDriverBindingStart (
351 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
352 IN EFI_HANDLE Controller
,
353 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
357 Stop this driver on ControllerHandle. Support stopping any child handles
358 created by this driver.
360 @param This Protocol instance pointer.
361 @param Controller Handle of device to stop driver on.
362 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
363 children is zero stop the entire bus driver.
364 @param ChildHandleBuffer List of Child Handles to Stop.
366 @retval EFI_SUCCESS This driver is removed ControllerHandle.
367 @retval other This driver was not removed from this device.
372 PciBusDriverBindingStop (
373 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
374 IN EFI_HANDLE Controller
,
375 IN UINTN NumberOfChildren
,
376 IN EFI_HANDLE
*ChildHandleBuffer