3 The PCI Root Bridge header file.
5 Copyright (c) 1999 - 2016, 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 <Library/DebugLib.h>
31 #include <Library/DevicePathLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/DxeServicesTableLib.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/BaseLib.h>
36 #include <Library/PciSegmentLib.h>
37 #include "PciHostResource.h"
46 #define MAP_INFO_SIGNATURE SIGNATURE_32 ('_', 'm', 'a', 'p')
50 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
;
53 EFI_PHYSICAL_ADDRESS HostAddress
;
54 EFI_PHYSICAL_ADDRESS MappedHostAddress
;
56 #define MAP_INFO_FROM_LINK(a) CR (a, MAP_INFO, Link, MAP_INFO_SIGNATURE)
58 #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('_', 'p', 'r', 'b')
64 UINT64 AllocationAttributes
;
67 PCI_RES_NODE ResAllocNode
[TypeMax
];
68 PCI_ROOT_BRIDGE_APERTURE Bus
;
69 PCI_ROOT_BRIDGE_APERTURE Io
;
70 PCI_ROOT_BRIDGE_APERTURE Mem
;
71 PCI_ROOT_BRIDGE_APERTURE PMem
;
72 PCI_ROOT_BRIDGE_APERTURE MemAbove4G
;
73 PCI_ROOT_BRIDGE_APERTURE PMemAbove4G
;
76 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
77 CHAR16
*DevicePathStr
;
78 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL RootBridgeIo
;
80 BOOLEAN ResourceSubmitted
;
82 } PCI_ROOT_BRIDGE_INSTANCE
;
84 #define ROOT_BRIDGE_FROM_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, RootBridgeIo, PCI_ROOT_BRIDGE_SIGNATURE)
86 #define ROOT_BRIDGE_FROM_LINK(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Link, PCI_ROOT_BRIDGE_SIGNATURE)
89 Construct the Pci Root Bridge instance.
91 @param Bridge The root bridge instance.
92 @param HostBridgeHandle Handle to the HostBridge.
94 @return The pointer to PCI_ROOT_BRIDGE_INSTANCE just created
95 or NULL if creation fails.
97 PCI_ROOT_BRIDGE_INSTANCE
*
99 IN PCI_ROOT_BRIDGE
*Bridge
,
100 IN EFI_HANDLE HostBridgeHandle
104 // Protocol Member Function Prototypes
108 Poll an address in memory mapped space until an exit condition is met
111 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
112 @param Width - Width of the memory operation.
113 @param Address - The base address of the memory operation.
114 @param Mask - Mask used for polling criteria.
115 @param Value - Comparison value used for polling exit criteria.
116 @param Delay - Number of 100ns units to poll.
117 @param Result - Pointer to the last value read from memory location.
119 @retval EFI_SUCCESS - Success.
120 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
121 @retval EFI_TIMEOUT - Delay expired before a match occurred.
122 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
127 RootBridgeIoPollMem (
128 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
129 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
140 Poll an address in I/O space until an exit condition is met
143 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
144 @param Width - Width of I/O operation.
145 @param Address - The base address of the I/O operation.
146 @param Mask - Mask used for polling criteria.
147 @param Value - Comparison value used for polling exit criteria.
148 @param Delay - Number of 100ns units to poll.
149 @param Result - Pointer to the last value read from memory location.
151 @retval EFI_SUCCESS - Success.
152 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
153 @retval EFI_TIMEOUT - Delay expired before a match occurred.
154 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
160 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
161 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
172 Allow read from memory mapped I/O space.
174 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
175 @param Width - The width of memory operation.
176 @param Address - Base address of the memory operation.
177 @param Count - Number of memory opeartion to perform.
178 @param Buffer - The destination buffer to store data.
180 @retval EFI_SUCCESS - Success.
181 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
182 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
187 RootBridgeIoMemRead (
188 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
189 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
198 Allow write to memory mapped I/O space.
200 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
201 @param Width - The width of memory operation.
202 @param Address - Base address of the memory operation.
203 @param Count - Number of memory opeartion to perform.
204 @param Buffer - The source buffer to write data from.
206 @retval EFI_SUCCESS - Success.
207 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
208 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
213 RootBridgeIoMemWrite (
214 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
215 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
224 Enable a PCI driver to read PCI controller registers in the
225 PCI root bridge I/O space.
227 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
228 @param Width - Signifies the width of the memory operation.
229 @param UserAddress - The base address of the I/O operation.
230 @param Count - The number of I/O operations to perform.
231 @param UserBuffer - The destination buffer to store the results.
233 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
234 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
235 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
241 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
242 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
243 IN UINT64 UserAddress
,
245 IN OUT VOID
*UserBuffer
251 Enable a PCI driver to write to PCI controller registers in the
252 PCI root bridge I/O space.
254 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
255 @param Width - Signifies the width of the memory operation.
256 @param UserAddress - The base address of the I/O operation.
257 @param Count - The number of I/O operations to perform.
258 @param UserBuffer - The source buffer to write data from.
260 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
261 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
262 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
267 RootBridgeIoIoWrite (
268 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
269 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
270 IN UINT64 UserAddress
,
272 IN OUT VOID
*UserBuffer
278 Copy one region of PCI root bridge memory space to be copied to
279 another region of PCI root bridge memory space.
281 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
282 @param Width - Signifies the width of the memory operation.
283 @param DestAddress - Destination address of the memory operation.
284 @param SrcAddress - Source address of the memory operation.
285 @param Count - Number of memory operations to perform.
287 @retval EFI_SUCCESS - The data was copied successfully.
288 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
289 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
294 RootBridgeIoCopyMem (
295 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
296 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
297 IN UINT64 DestAddress
,
298 IN UINT64 SrcAddress
,
305 Allows read from PCI configuration space.
307 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
308 @param Width - Signifies the width of the memory operation.
309 @param Address - The address within the PCI configuration space
310 for the PCI controller.
311 @param Count - The number of PCI configuration operations
313 @param Buffer - The destination buffer to store the results.
315 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
316 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
317 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
322 RootBridgeIoPciRead (
323 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
324 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
333 Allows write to PCI configuration space.
335 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
336 @param Width - Signifies the width of the memory operation.
337 @param Address - The address within the PCI configuration space
338 for the PCI controller.
339 @param Count - The number of PCI configuration operations
341 @param Buffer - The source buffer to get the results.
343 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
344 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
345 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
350 RootBridgeIoPciWrite (
351 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
352 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
360 Provides the PCI controller-specific address needed to access
361 system memory for DMA.
363 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
364 @param Operation Indicate if the bus master is going to read or write
366 @param HostAddress The system memory address to map on the PCI controller.
367 @param NumberOfBytes On input the number of bytes to map.
368 On output the number of bytes that were mapped.
369 @param DeviceAddress The resulting map address for the bus master PCI
370 controller to use to access the system memory's HostAddress.
371 @param Mapping The value to pass to Unmap() when the bus master DMA
372 operation is complete.
374 @retval EFI_SUCCESS Success.
375 @retval EFI_INVALID_PARAMETER Invalid parameters found.
376 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
377 @retval EFI_DEVICE_ERROR The System hardware could not map the requested address.
378 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of resources.
383 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
384 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
,
385 IN VOID
*HostAddress
,
386 IN OUT UINTN
*NumberOfBytes
,
387 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
393 Completes the Map() operation and releases any corresponding resources.
395 The Unmap() function completes the Map() operation and releases any
396 corresponding resources.
397 If the operation was an EfiPciOperationBusMasterWrite or
398 EfiPciOperationBusMasterWrite64, the data is committed to the target system
400 Any resources used for the mapping are freed.
402 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
403 @param[in] Mapping The mapping value returned from Map().
405 @retval EFI_SUCCESS The range was unmapped.
406 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
407 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
412 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
418 Allocates pages that are suitable for an EfiPciOperationBusMasterCommonBuffer
419 or EfiPciOperationBusMasterCommonBuffer64 mapping.
421 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
422 @param Type This parameter is not used and must be ignored.
423 @param MemoryType The type of memory to allocate, EfiBootServicesData or
424 EfiRuntimeServicesData.
425 @param Pages The number of pages to allocate.
426 @param HostAddress A pointer to store the base system memory address of the
428 @param Attributes The requested bit mask of attributes for the allocated
429 range. Only the attributes
430 EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE,
431 EFI_PCI_ATTRIBUTE_MEMORY_CACHED, and
432 EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE may be used with this
435 @retval EFI_SUCCESS The requested memory pages were allocated.
436 @retval EFI_INVALID_PARAMETER MemoryType is invalid.
437 @retval EFI_INVALID_PARAMETER HostAddress is NULL.
438 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal
439 attribute bits are MEMORY_WRITE_COMBINE,
440 MEMORY_CACHED, and DUAL_ADDRESS_CYCLE.
441 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
445 RootBridgeIoAllocateBuffer (
446 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
447 IN EFI_ALLOCATE_TYPE Type
,
448 IN EFI_MEMORY_TYPE MemoryType
,
450 OUT VOID
**HostAddress
,
457 Free memory allocated in AllocateBuffer.
459 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
461 @param Pages - Number of pages to free.
462 @param HostAddress - The base system memory address of the
465 @retval EFI_SUCCESS - Requested memory pages were freed.
466 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
471 RootBridgeIoFreeBuffer (
472 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
474 OUT VOID
*HostAddress
480 Flushes all PCI posted write transactions from a PCI host
481 bridge to system memory.
483 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
485 @retval EFI_SUCCESS - PCI posted write transactions were flushed
486 @retval from PCI host bridge to system memory.
487 @retval EFI_DEVICE_ERROR - Fail due to hardware error.
493 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
498 Gets the attributes that a PCI root bridge supports setting with
499 SetAttributes(), and the attributes that a PCI root bridge is currently
502 The GetAttributes() function returns the mask of attributes that this PCI
503 root bridge supports and the mask of attributes that the PCI root bridge is
506 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
507 @param Supported A pointer to the mask of attributes that this PCI root
508 bridge supports setting with SetAttributes().
509 @param Attributes A pointer to the mask of attributes that this PCI root
510 bridge is currently using.
512 @retval EFI_SUCCESS If Supports is not NULL, then the attributes
513 that the PCI root bridge supports is returned
514 in Supports. If Attributes is not NULL, then
515 the attributes that the PCI root bridge is
516 currently using is returned in Attributes.
517 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.
521 RootBridgeIoGetAttributes (
522 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
523 OUT UINT64
*Supported
,
524 OUT UINT64
*Attributes
530 Sets the attributes for a resource range on a PCI root bridge.
532 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
533 @param Attributes - The mask of attributes to set.
534 @param ResourceBase - Pointer to the base address of the resource range
535 to be modified by the attributes specified by Attributes.
536 @param ResourceLength - Pointer to the length of the resource range to be modified.
538 @retval EFI_SUCCESS - Success.
539 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
540 @retval EFI_OUT_OF_RESOURCES - Not enough resources to set the attributes upon.
545 RootBridgeIoSetAttributes (
546 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
547 IN UINT64 Attributes
,
548 IN OUT UINT64
*ResourceBase
,
549 IN OUT UINT64
*ResourceLength
555 Retrieves the current resource settings of this PCI root bridge
556 in the form of a set of ACPI 2.0 resource descriptor.
558 @param This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
559 @param Resources - Pointer to the ACPI 2.0 resource descriptor that
560 describe the current configuration of this PCI root
563 @retval EFI_SUCCESS - Success.
564 @retval EFI_UNSUPPORTED - Current configuration of the PCI root bridge
565 @retval could not be retrieved.
570 RootBridgeIoConfiguration (
571 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
577 extern EFI_METRONOME_ARCH_PROTOCOL
*mMetronome
;
578 extern EFI_CPU_IO2_PROTOCOL
*mCpuIo
;