2 The PCI Root Bridge header file.
4 Copyright (c) 2013-2015 Intel Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef _PCI_ROOT_BRIDGE_H_
12 #define _PCI_ROOT_BRIDGE_H_
15 #include <IndustryStandard/Acpi.h>
16 #include <IndustryStandard/Pci.h>
17 #include <PciHostResource.h>
20 // Driver Consumed Protocol Prototypes
22 #include <Protocol/Metronome.h>
23 #include <Protocol/CpuIo2.h>
24 #include <Protocol/DevicePath.h>
25 #include <Protocol/Runtime.h>
26 #include <Protocol/PciRootBridgeIo.h>
27 #include <Library/UefiLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/DevicePathLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/DxeServicesTableLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/BaseLib.h>
37 // Define the region of memory used for DMA memory
39 #define DMA_MEMORY_TOP 0x0000000001FFFFFFULL
42 // The number of PCI root bridges
44 #define ROOT_BRIDGE_COUNT 1
47 // The default latency for controllers
49 #define DEFAULT_PCI_LATENCY 0x20
52 // Define resource status constant
55 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
;
58 EFI_PHYSICAL_ADDRESS HostAddress
;
59 EFI_PHYSICAL_ADDRESS MappedHostAddress
;
63 ACPI_HID_DEVICE_PATH AcpiDevicePath
;
64 EFI_DEVICE_PATH_PROTOCOL EndDevicePath
;
65 } EFI_PCI_ROOT_BRIDGE_DEVICE_PATH
;
67 #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('e', '2', 'p', 'b')
73 UINT64 RootBridgeAllocAttrib
;
76 PCI_RES_NODE ResAllocNode
[6];
77 PCI_ROOT_BRIDGE_RESOURCE_APERTURE Aperture
;
84 BOOLEAN BusNumberAssigned
;
86 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
87 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL Io
;
88 } PCI_ROOT_BRIDGE_INSTANCE
;
91 // Driver Instance Data Macros
93 #define DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Io, PCI_ROOT_BRIDGE_SIGNATURE)
95 #define DRIVER_INSTANCE_FROM_LIST_ENTRY(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Link, PCI_ROOT_BRIDGE_SIGNATURE)
98 SimpleIioRootBridgeConstructor (
99 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*Protocol
,
100 IN EFI_HANDLE HostBridgeHandle
,
101 IN PCI_ROOT_BRIDGE_RESOURCE_APERTURE
*ResAppeture
,
102 IN UINT64 AllocAttributes
108 Construct the Pci Root Bridge Io protocol.
112 Protocol - Protocol to initialize.
113 HostBridgeHandle - Handle to the HostBridge.
114 ResAppeture - Resource apperture of the root bridge.
115 AllocAttributes - Attribute of resouce allocated.
119 EFI_SUCCESS - Success.
126 // Protocol Member Function Prototypes
130 RootBridgeIoPollMem (
131 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
132 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
143 Poll an address in memory mapped space until an exit condition is met
148 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
149 Width - Width of the memory operation.
150 Address - The base address of the memory operation.
151 Mask - Mask used for polling criteria.
152 Value - Comparison value used for polling exit criteria.
153 Delay - Number of 100ns units to poll.
154 Result - Pointer to the last value read from memory location.
158 EFI_SUCCESS - Success.
159 EFI_INVALID_PARAMETER - Invalid parameter found.
160 EFI_TIMEOUT - Delay expired before a match occurred.
161 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
169 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
170 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
181 Poll an address in I/O space until an exit condition is met
186 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
187 Width - Width of I/O operation.
188 Address - The base address of the I/O operation.
189 Mask - Mask used for polling criteria.
190 Value - Comparison value used for polling exit criteria.
191 Delay - Number of 100ns units to poll.
192 Result - Pointer to the last value read from memory location.
196 EFI_SUCCESS - Success.
197 EFI_INVALID_PARAMETER - Invalid parameter found.
198 EFI_TIMEOUT - Delay expired before a match occurred.
199 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
206 RootBridgeIoMemRead (
207 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
208 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
217 Allow read from memory mapped I/O space.
221 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
222 Width - The width of memory operation.
223 Address - Base address of the memory operation.
224 Count - Number of memory opeartion to perform.
225 Buffer - The destination buffer to store data.
229 EFI_SUCCESS - Success.
230 EFI_INVALID_PARAMETER - Invalid parameter found.
231 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
238 RootBridgeIoMemWrite (
239 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
240 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
249 Allow write to memory mapped I/O space.
253 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
254 Width - The width of memory operation.
255 Address - Base address of the memory operation.
256 Count - Number of memory opeartion to perform.
257 Buffer - The source buffer to write data from.
261 EFI_SUCCESS - Success.
262 EFI_INVALID_PARAMETER - Invalid parameter found.
263 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
271 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
272 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
273 IN UINT64 UserAddress
,
275 IN OUT VOID
*UserBuffer
281 Enable a PCI driver to read PCI controller registers in the
282 PCI root bridge I/O space.
286 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
287 Width - Signifies the width of the memory operation.
288 UserAddress - The base address of the I/O operation.
289 Count - The number of I/O operations to perform.
290 UserBuffer - The destination buffer to store the results.
294 EFI_SUCCESS - The data was read from the PCI root bridge.
295 EFI_INVALID_PARAMETER - Invalid parameters found.
296 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
303 RootBridgeIoIoWrite (
304 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
305 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
306 IN UINT64 UserAddress
,
308 IN OUT VOID
*UserBuffer
314 Enable a PCI driver to write to PCI controller registers in the
315 PCI root bridge I/O space.
319 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
320 Width - Signifies the width of the memory operation.
321 UserAddress - The base address of the I/O operation.
322 Count - The number of I/O operations to perform.
323 UserBuffer - The source buffer to write data from.
327 EFI_SUCCESS - The data was written to the PCI root bridge.
328 EFI_INVALID_PARAMETER - Invalid parameters found.
329 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
336 RootBridgeIoCopyMem (
337 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
338 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
339 IN UINT64 DestAddress
,
340 IN UINT64 SrcAddress
,
347 Copy one region of PCI root bridge memory space to be copied to
348 another region of PCI root bridge memory space.
352 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
353 Width - Signifies the width of the memory operation.
354 DestAddress - Destination address of the memory operation.
355 SrcAddress - Source address of the memory operation.
356 Count - Number of memory operations to perform.
360 EFI_SUCCESS - The data was copied successfully.
361 EFI_INVALID_PARAMETER - Invalid parameters found.
362 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
369 RootBridgeIoPciRead (
370 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
371 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
380 Allows read from PCI configuration space.
384 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
385 Width - Signifies the width of the memory operation.
386 Address - The address within the PCI configuration space
387 for the PCI controller.
388 Count - The number of PCI configuration operations
390 Buffer - The destination buffer to store the results.
394 EFI_SUCCESS - The data was read from the PCI root bridge.
395 EFI_INVALID_PARAMETER - Invalid parameters found.
396 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
403 RootBridgeIoPciWrite (
404 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
405 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
414 Allows write to PCI configuration space.
418 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
419 Width - Signifies the width of the memory operation.
420 Address - The address within the PCI configuration space
421 for the PCI controller.
422 Count - The number of PCI configuration operations
424 Buffer - The source buffer to get the results.
428 EFI_SUCCESS - The data was written to the PCI root bridge.
429 EFI_INVALID_PARAMETER - Invalid parameters found.
430 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
438 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
439 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
,
440 IN VOID
*HostAddress
,
441 IN OUT UINTN
*NumberOfBytes
,
442 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
449 Provides the PCI controller-specific address needed to access
450 system memory for DMA.
454 This - A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
455 Operation - Indicate if the bus master is going to read or write
457 HostAddress - The system memory address to map on the PCI controller.
458 NumberOfBytes - On input the number of bytes to map.
459 On output the number of bytes that were mapped.
460 DeviceAddress - The resulting map address for the bus master PCI
461 controller to use to access the system memory's HostAddress.
462 Mapping - The value to pass to Unmap() when the bus master DMA
463 operation is complete.
467 EFI_SUCCESS - Success.
468 EFI_INVALID_PARAMETER - Invalid parameters found.
469 EFI_UNSUPPORTED - The HostAddress cannot be mapped as a common
471 EFI_DEVICE_ERROR - The System hardware could not map the requested
473 EFI_OUT_OF_RESOURCES - The request could not be completed due to
482 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
489 Completes the Map() operation and releases any corresponding resources.
493 This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
494 Mapping - The value returned from Map() operation.
498 EFI_SUCCESS - The range was unmapped successfully.
499 EFI_INVALID_PARAMETER - Mapping is not a value that was returned
501 EFI_DEVICE_ERROR - The data was not committed to the target
509 RootBridgeIoAllocateBuffer (
510 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
511 IN EFI_ALLOCATE_TYPE Type
,
512 IN EFI_MEMORY_TYPE MemoryType
,
514 OUT VOID
**HostAddress
,
521 Allocates pages that are suitable for a common buffer mapping.
525 This - Pointer to EFI_ROOT_BRIDGE_IO_PROTOCOL instance.
526 Type - Not used and can be ignored.
527 MemoryType - Type of memory to allocate.
528 Pages - Number of pages to allocate.
529 HostAddress - Pointer to store the base system memory address
530 of the allocated range.
531 Attributes - Requested bit mask of attributes of the allocated
536 EFI_SUCCESS - The requested memory range were allocated.
537 EFI_INVALID_PARAMETER - Invalid parameter found.
538 EFI_UNSUPPORTED - Attributes is unsupported.
545 RootBridgeIoFreeBuffer (
546 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
548 OUT VOID
*HostAddress
554 Free memory allocated in AllocateBuffer.
558 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
560 Pages - Number of pages to free.
561 HostAddress - The base system memory address of the
566 EFI_SUCCESS - Requested memory pages were freed.
567 EFI_INVALID_PARAMETER - Invalid parameter found.
575 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
581 Flushes all PCI posted write transactions from a PCI host
582 bridge to system memory.
586 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
590 EFI_SUCCESS - PCI posted write transactions were flushed
591 from PCI host bridge to system memory.
592 EFI_DEVICE_ERROR - Fail due to hardware error.
599 RootBridgeIoGetAttributes (
600 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
601 OUT UINT64
*Supported
,
602 OUT UINT64
*Attributes
608 Get the attributes that a PCI root bridge supports and
609 the attributes the PCI root bridge is currently using.
613 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
615 Supports - A pointer to the mask of attributes that
616 this PCI root bridge supports.
617 Attributes - A pointer to the mask of attributes that
618 this PCI root bridge is currently using.
621 EFI_SUCCESS - Success.
622 EFI_INVALID_PARAMETER - Invalid parameter found.
626 // GC_TODO: Supported - add argument and description to function comment
628 // GC_TODO: Supported - add argument and description to function comment
630 // GC_TODO: Supported - add argument and description to function comment
636 RootBridgeIoSetAttributes (
637 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
638 IN UINT64 Attributes
,
639 IN OUT UINT64
*ResourceBase
,
640 IN OUT UINT64
*ResourceLength
646 Sets the attributes for a resource range on a PCI root bridge.
650 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
651 Attributes - The mask of attributes to set.
652 ResourceBase - Pointer to the base address of the resource range
653 to be modified by the attributes specified by Attributes.
654 ResourceLength - Pointer to the length of the resource range to be modified.
657 EFI_SUCCESS - Success.
658 EFI_INVALID_PARAMETER - Invalid parameter found.
659 EFI_OUT_OF_RESOURCES - Not enough resources to set the attributes upon.
666 RootBridgeIoConfiguration (
667 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
674 Retrieves the current resource settings of this PCI root bridge
675 in the form of a set of ACPI 2.0 resource descriptor.
679 This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
680 Resources - Pointer to the ACPI 2.0 resource descriptor that
681 describe the current configuration of this PCI root
686 EFI_SUCCESS - Success.
687 EFI_UNSUPPORTED - Current configuration of the PCI root bridge
688 could not be retrieved.