3 The PCI Root Bridge header file.
5 Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _PCI_ROOT_BRIDGE_H_
17 #define _PCI_ROOT_BRIDGE_H_
20 #include <IndustryStandard/Acpi.h>
21 #include <IndustryStandard/Pci.h>
24 // Driver Consumed Protocol Prototypes
26 #include <Protocol/Metronome.h>
27 #include <Protocol/CpuIo2.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/PciRootBridgeIo.h>
30 #include <Protocol/IoMmu.h>
31 #include <Library/DebugLib.h>
32 #include <Library/DevicePathLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/DxeServicesTableLib.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/BaseLib.h>
37 #include <Library/PciSegmentLib.h>
38 #include <Library/UefiLib.h>
39 #include "PciHostResource.h"
48 #define MAP_INFO_SIGNATURE SIGNATURE_32 ('_', 'm', 'a', 'p')
52 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
;
55 EFI_PHYSICAL_ADDRESS HostAddress
;
56 EFI_PHYSICAL_ADDRESS MappedHostAddress
;
58 #define MAP_INFO_FROM_LINK(a) CR (a, MAP_INFO, Link, MAP_INFO_SIGNATURE)
60 #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('_', 'p', 'r', 'b')
66 UINT64 AllocationAttributes
;
69 PCI_RES_NODE ResAllocNode
[TypeMax
];
70 PCI_ROOT_BRIDGE_APERTURE Bus
;
71 PCI_ROOT_BRIDGE_APERTURE Io
;
72 PCI_ROOT_BRIDGE_APERTURE Mem
;
73 PCI_ROOT_BRIDGE_APERTURE PMem
;
74 PCI_ROOT_BRIDGE_APERTURE MemAbove4G
;
75 PCI_ROOT_BRIDGE_APERTURE PMemAbove4G
;
77 BOOLEAN NoExtendedConfigSpace
;
79 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
80 CHAR16
*DevicePathStr
;
81 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL RootBridgeIo
;
83 BOOLEAN ResourceSubmitted
;
85 } PCI_ROOT_BRIDGE_INSTANCE
;
87 #define ROOT_BRIDGE_FROM_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, RootBridgeIo, PCI_ROOT_BRIDGE_SIGNATURE)
89 #define ROOT_BRIDGE_FROM_LINK(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Link, PCI_ROOT_BRIDGE_SIGNATURE)
92 Construct the Pci Root Bridge instance.
94 @param Bridge The root bridge instance.
96 @return The pointer to PCI_ROOT_BRIDGE_INSTANCE just created
97 or NULL if creation fails.
99 PCI_ROOT_BRIDGE_INSTANCE
*
101 IN PCI_ROOT_BRIDGE
*Bridge
105 // Protocol Member Function Prototypes
109 Poll an address in memory mapped space until an exit condition is met
112 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
113 @param Width - Width of the memory operation.
114 @param Address - The base address of the memory operation.
115 @param Mask - Mask used for polling criteria.
116 @param Value - Comparison value used for polling exit criteria.
117 @param Delay - Number of 100ns units to poll.
118 @param Result - Pointer to the last value read from memory location.
120 @retval EFI_SUCCESS - Success.
121 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
122 @retval EFI_TIMEOUT - Delay expired before a match occurred.
123 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
128 RootBridgeIoPollMem (
129 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
130 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
141 Poll an address in I/O space until an exit condition is met
144 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
145 @param Width - Width of I/O operation.
146 @param Address - The base address of the I/O operation.
147 @param Mask - Mask used for polling criteria.
148 @param Value - Comparison value used for polling exit criteria.
149 @param Delay - Number of 100ns units to poll.
150 @param Result - Pointer to the last value read from memory location.
152 @retval EFI_SUCCESS - Success.
153 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
154 @retval EFI_TIMEOUT - Delay expired before a match occurred.
155 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
161 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
162 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
173 Allow read from memory mapped I/O space.
175 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
176 @param Width - The width of memory operation.
177 @param Address - Base address of the memory operation.
178 @param Count - Number of memory opeartion to perform.
179 @param Buffer - The destination buffer to store data.
181 @retval EFI_SUCCESS - Success.
182 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
183 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
188 RootBridgeIoMemRead (
189 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
190 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
199 Allow write to memory mapped I/O space.
201 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
202 @param Width - The width of memory operation.
203 @param Address - Base address of the memory operation.
204 @param Count - Number of memory opeartion to perform.
205 @param Buffer - The source buffer to write data from.
207 @retval EFI_SUCCESS - Success.
208 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
209 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
214 RootBridgeIoMemWrite (
215 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
216 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
225 Enable a PCI driver to read PCI controller registers in the
226 PCI root bridge I/O space.
228 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
229 @param Width - Signifies the width of the memory operation.
230 @param UserAddress - The base address of the I/O operation.
231 @param Count - The number of I/O operations to perform.
232 @param UserBuffer - The destination buffer to store the results.
234 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
235 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
236 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
242 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
243 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
244 IN UINT64 UserAddress
,
246 IN OUT VOID
*UserBuffer
252 Enable a PCI driver to write to PCI controller registers in the
253 PCI root bridge I/O space.
255 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
256 @param Width - Signifies the width of the memory operation.
257 @param UserAddress - The base address of the I/O operation.
258 @param Count - The number of I/O operations to perform.
259 @param UserBuffer - The source buffer to write data from.
261 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
262 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
263 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
268 RootBridgeIoIoWrite (
269 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
270 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
271 IN UINT64 UserAddress
,
273 IN OUT VOID
*UserBuffer
279 Copy one region of PCI root bridge memory space to be copied to
280 another region of PCI root bridge memory space.
282 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
283 @param Width - Signifies the width of the memory operation.
284 @param DestAddress - Destination address of the memory operation.
285 @param SrcAddress - Source address of the memory operation.
286 @param Count - Number of memory operations to perform.
288 @retval EFI_SUCCESS - The data was copied successfully.
289 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
290 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
295 RootBridgeIoCopyMem (
296 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
297 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
298 IN UINT64 DestAddress
,
299 IN UINT64 SrcAddress
,
306 Allows read from PCI configuration space.
308 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
309 @param Width - Signifies the width of the memory operation.
310 @param Address - The address within the PCI configuration space
311 for the PCI controller.
312 @param Count - The number of PCI configuration operations
314 @param Buffer - The destination buffer to store the results.
316 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
317 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
318 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
323 RootBridgeIoPciRead (
324 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
325 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
334 Allows write to PCI configuration space.
336 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
337 @param Width - Signifies the width of the memory operation.
338 @param Address - The address within the PCI configuration space
339 for the PCI controller.
340 @param Count - The number of PCI configuration operations
342 @param Buffer - The source buffer to get the results.
344 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
345 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
346 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
351 RootBridgeIoPciWrite (
352 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
353 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
361 Provides the PCI controller-specific address needed to access
362 system memory for DMA.
364 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
365 @param Operation Indicate if the bus master is going to read or write
367 @param HostAddress The system memory address to map on the PCI controller.
368 @param NumberOfBytes On input the number of bytes to map.
369 On output the number of bytes that were mapped.
370 @param DeviceAddress The resulting map address for the bus master PCI
371 controller to use to access the system memory's HostAddress.
372 @param Mapping The value to pass to Unmap() when the bus master DMA
373 operation is complete.
375 @retval EFI_SUCCESS Success.
376 @retval EFI_INVALID_PARAMETER Invalid parameters found.
377 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
378 @retval EFI_DEVICE_ERROR The System hardware could not map the requested address.
379 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of resources.
384 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
385 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
,
386 IN VOID
*HostAddress
,
387 IN OUT UINTN
*NumberOfBytes
,
388 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
394 Completes the Map() operation and releases any corresponding resources.
396 The Unmap() function completes the Map() operation and releases any
397 corresponding resources.
398 If the operation was an EfiPciOperationBusMasterWrite or
399 EfiPciOperationBusMasterWrite64, the data is committed to the target system
401 Any resources used for the mapping are freed.
403 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
404 @param[in] Mapping The mapping value returned from Map().
406 @retval EFI_SUCCESS The range was unmapped.
407 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
408 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
413 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
419 Allocates pages that are suitable for an EfiPciOperationBusMasterCommonBuffer
420 or EfiPciOperationBusMasterCommonBuffer64 mapping.
422 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
423 @param Type This parameter is not used and must be ignored.
424 @param MemoryType The type of memory to allocate, EfiBootServicesData or
425 EfiRuntimeServicesData.
426 @param Pages The number of pages to allocate.
427 @param HostAddress A pointer to store the base system memory address of the
429 @param Attributes The requested bit mask of attributes for the allocated
430 range. Only the attributes
431 EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE,
432 EFI_PCI_ATTRIBUTE_MEMORY_CACHED, and
433 EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE may be used with this
436 @retval EFI_SUCCESS The requested memory pages were allocated.
437 @retval EFI_INVALID_PARAMETER MemoryType is invalid.
438 @retval EFI_INVALID_PARAMETER HostAddress is NULL.
439 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal
440 attribute bits are MEMORY_WRITE_COMBINE,
441 MEMORY_CACHED, and DUAL_ADDRESS_CYCLE.
442 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
446 RootBridgeIoAllocateBuffer (
447 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
448 IN EFI_ALLOCATE_TYPE Type
,
449 IN EFI_MEMORY_TYPE MemoryType
,
451 OUT VOID
**HostAddress
,
458 Free memory allocated in AllocateBuffer.
460 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
462 @param Pages - Number of pages to free.
463 @param HostAddress - The base system memory address of the
466 @retval EFI_SUCCESS - Requested memory pages were freed.
467 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
472 RootBridgeIoFreeBuffer (
473 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
475 OUT VOID
*HostAddress
481 Flushes all PCI posted write transactions from a PCI host
482 bridge to system memory.
484 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
486 @retval EFI_SUCCESS - PCI posted write transactions were flushed
487 @retval from PCI host bridge to system memory.
488 @retval EFI_DEVICE_ERROR - Fail due to hardware error.
494 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
499 Gets the attributes that a PCI root bridge supports setting with
500 SetAttributes(), and the attributes that a PCI root bridge is currently
503 The GetAttributes() function returns the mask of attributes that this PCI
504 root bridge supports and the mask of attributes that the PCI root bridge is
507 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
508 @param Supported A pointer to the mask of attributes that this PCI root
509 bridge supports setting with SetAttributes().
510 @param Attributes A pointer to the mask of attributes that this PCI root
511 bridge is currently using.
513 @retval EFI_SUCCESS If Supports is not NULL, then the attributes
514 that the PCI root bridge supports is returned
515 in Supports. If Attributes is not NULL, then
516 the attributes that the PCI root bridge is
517 currently using is returned in Attributes.
518 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.
522 RootBridgeIoGetAttributes (
523 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
524 OUT UINT64
*Supported
,
525 OUT UINT64
*Attributes
531 Sets the attributes for a resource range on a PCI root bridge.
533 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
534 @param Attributes - The mask of attributes to set.
535 @param ResourceBase - Pointer to the base address of the resource range
536 to be modified by the attributes specified by Attributes.
537 @param ResourceLength - Pointer to the length of the resource range to be modified.
539 @retval EFI_SUCCESS - Success.
540 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
541 @retval EFI_OUT_OF_RESOURCES - Not enough resources to set the attributes upon.
546 RootBridgeIoSetAttributes (
547 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
548 IN UINT64 Attributes
,
549 IN OUT UINT64
*ResourceBase
,
550 IN OUT UINT64
*ResourceLength
556 Retrieves the current resource settings of this PCI root bridge
557 in the form of a set of ACPI resource descriptor.
559 @param This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
560 @param Resources - Pointer to the resource descriptor that
561 describe the current configuration of this PCI root
564 @retval EFI_SUCCESS - Success.
565 @retval EFI_UNSUPPORTED - Current configuration of the PCI root bridge
566 @retval could not be retrieved.
571 RootBridgeIoConfiguration (
572 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
578 extern EFI_METRONOME_ARCH_PROTOCOL
*mMetronome
;
579 extern EFI_CPU_IO2_PROTOCOL
*mCpuIo
;