3 The PCI Root Bridge header file.
5 Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef _PCI_ROOT_BRIDGE_H_
11 #define _PCI_ROOT_BRIDGE_H_
14 #include <IndustryStandard/Acpi.h>
15 #include <IndustryStandard/Pci.h>
18 // Driver Consumed Protocol Prototypes
20 #include <Protocol/CpuIo2.h>
21 #include <Protocol/DevicePath.h>
22 #include <Protocol/PciRootBridgeIo.h>
23 #include <Library/DebugLib.h>
24 #include <Library/DevicePathLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/DxeServicesTableLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/BaseLib.h>
29 #include <Library/PciSegmentLib.h>
30 #include <Library/UefiLib.h>
31 #include <Library/TimerLib.h>
32 #include "PciHostResource.h"
41 #define MAP_INFO_SIGNATURE SIGNATURE_32 ('_', 'm', 'a', 'p')
45 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
;
48 EFI_PHYSICAL_ADDRESS HostAddress
;
49 EFI_PHYSICAL_ADDRESS MappedHostAddress
;
51 #define MAP_INFO_FROM_LINK(a) CR (a, MAP_INFO, Link, MAP_INFO_SIGNATURE)
53 #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('_', 'p', 'r', 'b')
59 UINT64 AllocationAttributes
;
62 PCI_RES_NODE ResAllocNode
[TypeMax
];
63 PCI_ROOT_BRIDGE_APERTURE Bus
;
64 PCI_ROOT_BRIDGE_APERTURE Io
;
65 PCI_ROOT_BRIDGE_APERTURE Mem
;
66 PCI_ROOT_BRIDGE_APERTURE PMem
;
67 PCI_ROOT_BRIDGE_APERTURE MemAbove4G
;
68 PCI_ROOT_BRIDGE_APERTURE PMemAbove4G
;
70 BOOLEAN NoExtendedConfigSpace
;
72 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
73 CHAR16
*DevicePathStr
;
74 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL RootBridgeIo
;
76 BOOLEAN ResourceSubmitted
;
78 } PCI_ROOT_BRIDGE_INSTANCE
;
80 #define ROOT_BRIDGE_FROM_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, RootBridgeIo, PCI_ROOT_BRIDGE_SIGNATURE)
82 #define ROOT_BRIDGE_FROM_LINK(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Link, PCI_ROOT_BRIDGE_SIGNATURE)
85 Construct the Pci Root Bridge instance.
87 @param Bridge The root bridge instance.
89 @return The pointer to PCI_ROOT_BRIDGE_INSTANCE just created
90 or NULL if creation fails.
92 PCI_ROOT_BRIDGE_INSTANCE
*
94 IN PCI_ROOT_BRIDGE
*Bridge
98 // Protocol Member Function Prototypes
102 Poll an address in memory mapped space until an exit condition is met
105 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
106 @param Width - Width of the memory operation.
107 @param Address - The base address of the memory operation.
108 @param Mask - Mask used for polling criteria.
109 @param Value - Comparison value used for polling exit criteria.
110 @param Delay - Number of 100ns units to poll.
111 @param Result - Pointer to the last value read from memory location.
113 @retval EFI_SUCCESS - Success.
114 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
115 @retval EFI_TIMEOUT - Delay expired before a match occurred.
116 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
121 RootBridgeIoPollMem (
122 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
123 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
134 Poll an address in I/O space until an exit condition is met
137 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
138 @param Width - Width of I/O operation.
139 @param Address - The base address of the I/O operation.
140 @param Mask - Mask used for polling criteria.
141 @param Value - Comparison value used for polling exit criteria.
142 @param Delay - Number of 100ns units to poll.
143 @param Result - Pointer to the last value read from memory location.
145 @retval EFI_SUCCESS - Success.
146 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
147 @retval EFI_TIMEOUT - Delay expired before a match occurred.
148 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
154 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
155 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
166 Allow read from memory mapped I/O space.
168 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
169 @param Width - The width of memory operation.
170 @param Address - Base address of the memory operation.
171 @param Count - Number of memory opeartion to perform.
172 @param Buffer - The destination buffer to store data.
174 @retval EFI_SUCCESS - Success.
175 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
176 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
181 RootBridgeIoMemRead (
182 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
183 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
192 Allow write to memory mapped I/O space.
194 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
195 @param Width - The width of memory operation.
196 @param Address - Base address of the memory operation.
197 @param Count - Number of memory opeartion to perform.
198 @param Buffer - The source buffer to write data from.
200 @retval EFI_SUCCESS - Success.
201 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
202 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
207 RootBridgeIoMemWrite (
208 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
209 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
218 Enable a PCI driver to read PCI controller registers in the
219 PCI root bridge I/O space.
221 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
222 @param Width - Signifies the width of the memory operation.
223 @param UserAddress - The base address of the I/O operation.
224 @param Count - The number of I/O operations to perform.
225 @param UserBuffer - The destination buffer to store the results.
227 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
228 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
229 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
235 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
236 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
237 IN UINT64 UserAddress
,
239 IN OUT VOID
*UserBuffer
245 Enable a PCI driver to write to PCI controller registers in the
246 PCI root bridge I/O space.
248 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
249 @param Width - Signifies the width of the memory operation.
250 @param UserAddress - The base address of the I/O operation.
251 @param Count - The number of I/O operations to perform.
252 @param UserBuffer - The source buffer to write data from.
254 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
255 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
256 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
261 RootBridgeIoIoWrite (
262 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
263 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
264 IN UINT64 UserAddress
,
266 IN OUT VOID
*UserBuffer
272 Copy one region of PCI root bridge memory space to be copied to
273 another region of PCI root bridge memory space.
275 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
276 @param Width - Signifies the width of the memory operation.
277 @param DestAddress - Destination address of the memory operation.
278 @param SrcAddress - Source address of the memory operation.
279 @param Count - Number of memory operations to perform.
281 @retval EFI_SUCCESS - The data was copied successfully.
282 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
283 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
288 RootBridgeIoCopyMem (
289 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
290 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
291 IN UINT64 DestAddress
,
292 IN UINT64 SrcAddress
,
299 Allows read from PCI configuration space.
301 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
302 @param Width - Signifies the width of the memory operation.
303 @param Address - The address within the PCI configuration space
304 for the PCI controller.
305 @param Count - The number of PCI configuration operations
307 @param Buffer - The destination buffer to store the results.
309 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
310 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
311 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
316 RootBridgeIoPciRead (
317 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
318 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
327 Allows write to PCI configuration space.
329 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
330 @param Width - Signifies the width of the memory operation.
331 @param Address - The address within the PCI configuration space
332 for the PCI controller.
333 @param Count - The number of PCI configuration operations
335 @param Buffer - The source buffer to get the results.
337 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
338 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
339 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
344 RootBridgeIoPciWrite (
345 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
346 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
354 Provides the PCI controller-specific address needed to access
355 system memory for DMA.
357 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
358 @param Operation Indicate if the bus master is going to read or write
360 @param HostAddress The system memory address to map on the PCI controller.
361 @param NumberOfBytes On input the number of bytes to map.
362 On output the number of bytes that were mapped.
363 @param DeviceAddress The resulting map address for the bus master PCI
364 controller to use to access the system memory's HostAddress.
365 @param Mapping The value to pass to Unmap() when the bus master DMA
366 operation is complete.
368 @retval EFI_SUCCESS Success.
369 @retval EFI_INVALID_PARAMETER Invalid parameters found.
370 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
371 @retval EFI_DEVICE_ERROR The System hardware could not map the requested address.
372 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of resources.
377 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
378 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
,
379 IN VOID
*HostAddress
,
380 IN OUT UINTN
*NumberOfBytes
,
381 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
387 Completes the Map() operation and releases any corresponding resources.
389 The Unmap() function completes the Map() operation and releases any
390 corresponding resources.
391 If the operation was an EfiPciOperationBusMasterWrite or
392 EfiPciOperationBusMasterWrite64, the data is committed to the target system
394 Any resources used for the mapping are freed.
396 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
397 @param[in] Mapping The mapping value returned from Map().
399 @retval EFI_SUCCESS The range was unmapped.
400 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
401 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
406 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
412 Allocates pages that are suitable for an EfiPciOperationBusMasterCommonBuffer
413 or EfiPciOperationBusMasterCommonBuffer64 mapping.
415 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
416 @param Type This parameter is not used and must be ignored.
417 @param MemoryType The type of memory to allocate, EfiBootServicesData or
418 EfiRuntimeServicesData.
419 @param Pages The number of pages to allocate.
420 @param HostAddress A pointer to store the base system memory address of the
422 @param Attributes The requested bit mask of attributes for the allocated
423 range. Only the attributes
424 EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE,
425 EFI_PCI_ATTRIBUTE_MEMORY_CACHED, and
426 EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE may be used with this
429 @retval EFI_SUCCESS The requested memory pages were allocated.
430 @retval EFI_INVALID_PARAMETER MemoryType is invalid.
431 @retval EFI_INVALID_PARAMETER HostAddress is NULL.
432 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal
433 attribute bits are MEMORY_WRITE_COMBINE,
434 MEMORY_CACHED, and DUAL_ADDRESS_CYCLE.
435 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
439 RootBridgeIoAllocateBuffer (
440 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
441 IN EFI_ALLOCATE_TYPE Type
,
442 IN EFI_MEMORY_TYPE MemoryType
,
444 OUT VOID
**HostAddress
,
451 Free memory allocated in AllocateBuffer.
453 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
455 @param Pages - Number of pages to free.
456 @param HostAddress - The base system memory address of the
459 @retval EFI_SUCCESS - Requested memory pages were freed.
460 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
465 RootBridgeIoFreeBuffer (
466 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
468 OUT VOID
*HostAddress
474 Flushes all PCI posted write transactions from a PCI host
475 bridge to system memory.
477 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
479 @retval EFI_SUCCESS - PCI posted write transactions were flushed
480 @retval from PCI host bridge to system memory.
481 @retval EFI_DEVICE_ERROR - Fail due to hardware error.
487 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
492 Gets the attributes that a PCI root bridge supports setting with
493 SetAttributes(), and the attributes that a PCI root bridge is currently
496 The GetAttributes() function returns the mask of attributes that this PCI
497 root bridge supports and the mask of attributes that the PCI root bridge is
500 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
501 @param Supported A pointer to the mask of attributes that this PCI root
502 bridge supports setting with SetAttributes().
503 @param Attributes A pointer to the mask of attributes that this PCI root
504 bridge is currently using.
506 @retval EFI_SUCCESS If Supports is not NULL, then the attributes
507 that the PCI root bridge supports is returned
508 in Supports. If Attributes is not NULL, then
509 the attributes that the PCI root bridge is
510 currently using is returned in Attributes.
511 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.
515 RootBridgeIoGetAttributes (
516 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
517 OUT UINT64
*Supported
,
518 OUT UINT64
*Attributes
524 Sets the attributes for a resource range on a PCI root bridge.
526 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
527 @param Attributes - The mask of attributes to set.
528 @param ResourceBase - Pointer to the base address of the resource range
529 to be modified by the attributes specified by Attributes.
530 @param ResourceLength - Pointer to the length of the resource range to be modified.
532 @retval EFI_SUCCESS - Success.
533 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
534 @retval EFI_OUT_OF_RESOURCES - Not enough resources to set the attributes upon.
539 RootBridgeIoSetAttributes (
540 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
541 IN UINT64 Attributes
,
542 IN OUT UINT64
*ResourceBase
,
543 IN OUT UINT64
*ResourceLength
549 Retrieves the current resource settings of this PCI root bridge
550 in the form of a set of ACPI resource descriptor.
552 @param This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
553 @param Resources - Pointer to the resource descriptor that
554 describe the current configuration of this PCI root
557 @retval EFI_SUCCESS - Success.
558 @retval EFI_UNSUPPORTED - Current configuration of the PCI root bridge
559 @retval could not be retrieved.
564 RootBridgeIoConfiguration (
565 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
570 extern EFI_CPU_IO2_PROTOCOL
*mCpuIo
;