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
;
75 BOOLEAN NoExtendedConfigSpace
;
77 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
78 CHAR16
*DevicePathStr
;
79 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL RootBridgeIo
;
81 BOOLEAN ResourceSubmitted
;
83 } PCI_ROOT_BRIDGE_INSTANCE
;
85 #define ROOT_BRIDGE_FROM_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, RootBridgeIo, PCI_ROOT_BRIDGE_SIGNATURE)
87 #define ROOT_BRIDGE_FROM_LINK(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Link, PCI_ROOT_BRIDGE_SIGNATURE)
90 Construct the Pci Root Bridge instance.
92 @param Bridge The root bridge instance.
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
103 // Protocol Member Function Prototypes
107 Poll an address in memory mapped space until an exit condition is met
110 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
111 @param Width - Width of the memory operation.
112 @param Address - The base address of the memory operation.
113 @param Mask - Mask used for polling criteria.
114 @param Value - Comparison value used for polling exit criteria.
115 @param Delay - Number of 100ns units to poll.
116 @param Result - Pointer to the last value read from memory location.
118 @retval EFI_SUCCESS - Success.
119 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
120 @retval EFI_TIMEOUT - Delay expired before a match occurred.
121 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
126 RootBridgeIoPollMem (
127 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
128 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
139 Poll an address in I/O space until an exit condition is met
142 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
143 @param Width - Width of I/O operation.
144 @param Address - The base address of the I/O operation.
145 @param Mask - Mask used for polling criteria.
146 @param Value - Comparison value used for polling exit criteria.
147 @param Delay - Number of 100ns units to poll.
148 @param Result - Pointer to the last value read from memory location.
150 @retval EFI_SUCCESS - Success.
151 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
152 @retval EFI_TIMEOUT - Delay expired before a match occurred.
153 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
159 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
160 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
171 Allow read from memory mapped I/O space.
173 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
174 @param Width - The width of memory operation.
175 @param Address - Base address of the memory operation.
176 @param Count - Number of memory opeartion to perform.
177 @param Buffer - The destination buffer to store data.
179 @retval EFI_SUCCESS - Success.
180 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
181 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
186 RootBridgeIoMemRead (
187 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
188 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
197 Allow write to memory mapped I/O space.
199 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
200 @param Width - The width of memory operation.
201 @param Address - Base address of the memory operation.
202 @param Count - Number of memory opeartion to perform.
203 @param Buffer - The source buffer to write data from.
205 @retval EFI_SUCCESS - Success.
206 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
207 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
212 RootBridgeIoMemWrite (
213 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
214 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
223 Enable a PCI driver to read PCI controller registers in the
224 PCI root bridge I/O space.
226 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
227 @param Width - Signifies the width of the memory operation.
228 @param UserAddress - The base address of the I/O operation.
229 @param Count - The number of I/O operations to perform.
230 @param UserBuffer - The destination buffer to store the results.
232 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
233 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
234 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
240 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
241 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
242 IN UINT64 UserAddress
,
244 IN OUT VOID
*UserBuffer
250 Enable a PCI driver to write to PCI controller registers in the
251 PCI root bridge I/O space.
253 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
254 @param Width - Signifies the width of the memory operation.
255 @param UserAddress - The base address of the I/O operation.
256 @param Count - The number of I/O operations to perform.
257 @param UserBuffer - The source buffer to write data from.
259 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
260 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
261 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
266 RootBridgeIoIoWrite (
267 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
268 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
269 IN UINT64 UserAddress
,
271 IN OUT VOID
*UserBuffer
277 Copy one region of PCI root bridge memory space to be copied to
278 another region of PCI root bridge memory space.
280 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
281 @param Width - Signifies the width of the memory operation.
282 @param DestAddress - Destination address of the memory operation.
283 @param SrcAddress - Source address of the memory operation.
284 @param Count - Number of memory operations to perform.
286 @retval EFI_SUCCESS - The data was copied successfully.
287 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
288 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
293 RootBridgeIoCopyMem (
294 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
295 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
296 IN UINT64 DestAddress
,
297 IN UINT64 SrcAddress
,
304 Allows read from PCI configuration space.
306 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
307 @param Width - Signifies the width of the memory operation.
308 @param Address - The address within the PCI configuration space
309 for the PCI controller.
310 @param Count - The number of PCI configuration operations
312 @param Buffer - The destination buffer to store the results.
314 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
315 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
316 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
321 RootBridgeIoPciRead (
322 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
323 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
332 Allows write to PCI configuration space.
334 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
335 @param Width - Signifies the width of the memory operation.
336 @param Address - The address within the PCI configuration space
337 for the PCI controller.
338 @param Count - The number of PCI configuration operations
340 @param Buffer - The source buffer to get the results.
342 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
343 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
344 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
349 RootBridgeIoPciWrite (
350 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
351 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
359 Provides the PCI controller-specific address needed to access
360 system memory for DMA.
362 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
363 @param Operation Indicate if the bus master is going to read or write
365 @param HostAddress The system memory address to map on the PCI controller.
366 @param NumberOfBytes On input the number of bytes to map.
367 On output the number of bytes that were mapped.
368 @param DeviceAddress The resulting map address for the bus master PCI
369 controller to use to access the system memory's HostAddress.
370 @param Mapping The value to pass to Unmap() when the bus master DMA
371 operation is complete.
373 @retval EFI_SUCCESS Success.
374 @retval EFI_INVALID_PARAMETER Invalid parameters found.
375 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
376 @retval EFI_DEVICE_ERROR The System hardware could not map the requested address.
377 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of resources.
382 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
383 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
,
384 IN VOID
*HostAddress
,
385 IN OUT UINTN
*NumberOfBytes
,
386 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
392 Completes the Map() operation and releases any corresponding resources.
394 The Unmap() function completes the Map() operation and releases any
395 corresponding resources.
396 If the operation was an EfiPciOperationBusMasterWrite or
397 EfiPciOperationBusMasterWrite64, the data is committed to the target system
399 Any resources used for the mapping are freed.
401 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
402 @param[in] Mapping The mapping value returned from Map().
404 @retval EFI_SUCCESS The range was unmapped.
405 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
406 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
411 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
417 Allocates pages that are suitable for an EfiPciOperationBusMasterCommonBuffer
418 or EfiPciOperationBusMasterCommonBuffer64 mapping.
420 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
421 @param Type This parameter is not used and must be ignored.
422 @param MemoryType The type of memory to allocate, EfiBootServicesData or
423 EfiRuntimeServicesData.
424 @param Pages The number of pages to allocate.
425 @param HostAddress A pointer to store the base system memory address of the
427 @param Attributes The requested bit mask of attributes for the allocated
428 range. Only the attributes
429 EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE,
430 EFI_PCI_ATTRIBUTE_MEMORY_CACHED, and
431 EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE may be used with this
434 @retval EFI_SUCCESS The requested memory pages were allocated.
435 @retval EFI_INVALID_PARAMETER MemoryType is invalid.
436 @retval EFI_INVALID_PARAMETER HostAddress is NULL.
437 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal
438 attribute bits are MEMORY_WRITE_COMBINE,
439 MEMORY_CACHED, and DUAL_ADDRESS_CYCLE.
440 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
444 RootBridgeIoAllocateBuffer (
445 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
446 IN EFI_ALLOCATE_TYPE Type
,
447 IN EFI_MEMORY_TYPE MemoryType
,
449 OUT VOID
**HostAddress
,
456 Free memory allocated in AllocateBuffer.
458 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
460 @param Pages - Number of pages to free.
461 @param HostAddress - The base system memory address of the
464 @retval EFI_SUCCESS - Requested memory pages were freed.
465 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
470 RootBridgeIoFreeBuffer (
471 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
473 OUT VOID
*HostAddress
479 Flushes all PCI posted write transactions from a PCI host
480 bridge to system memory.
482 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
484 @retval EFI_SUCCESS - PCI posted write transactions were flushed
485 @retval from PCI host bridge to system memory.
486 @retval EFI_DEVICE_ERROR - Fail due to hardware error.
492 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
497 Gets the attributes that a PCI root bridge supports setting with
498 SetAttributes(), and the attributes that a PCI root bridge is currently
501 The GetAttributes() function returns the mask of attributes that this PCI
502 root bridge supports and the mask of attributes that the PCI root bridge is
505 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
506 @param Supported A pointer to the mask of attributes that this PCI root
507 bridge supports setting with SetAttributes().
508 @param Attributes A pointer to the mask of attributes that this PCI root
509 bridge is currently using.
511 @retval EFI_SUCCESS If Supports is not NULL, then the attributes
512 that the PCI root bridge supports is returned
513 in Supports. If Attributes is not NULL, then
514 the attributes that the PCI root bridge is
515 currently using is returned in Attributes.
516 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.
520 RootBridgeIoGetAttributes (
521 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
522 OUT UINT64
*Supported
,
523 OUT UINT64
*Attributes
529 Sets the attributes for a resource range on a PCI root bridge.
531 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
532 @param Attributes - The mask of attributes to set.
533 @param ResourceBase - Pointer to the base address of the resource range
534 to be modified by the attributes specified by Attributes.
535 @param ResourceLength - Pointer to the length of the resource range to be modified.
537 @retval EFI_SUCCESS - Success.
538 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
539 @retval EFI_OUT_OF_RESOURCES - Not enough resources to set the attributes upon.
544 RootBridgeIoSetAttributes (
545 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
546 IN UINT64 Attributes
,
547 IN OUT UINT64
*ResourceBase
,
548 IN OUT UINT64
*ResourceLength
554 Retrieves the current resource settings of this PCI root bridge
555 in the form of a set of ACPI 2.0 resource descriptor.
557 @param This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
558 @param Resources - Pointer to the ACPI 2.0 resource descriptor that
559 describe the current configuration of this PCI root
562 @retval EFI_SUCCESS - Success.
563 @retval EFI_UNSUPPORTED - Current configuration of the PCI root bridge
564 @retval could not be retrieved.
569 RootBridgeIoConfiguration (
570 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
576 extern EFI_METRONOME_ARCH_PROTOCOL
*mMetronome
;
577 extern EFI_CPU_IO2_PROTOCOL
*mCpuIo
;