2 The PCI Root Bridge header file.
4 Copyright (c) 2013-2015 Intel Corporation.
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.
17 #ifndef _PCI_ROOT_BRIDGE_H_
18 #define _PCI_ROOT_BRIDGE_H_
21 #include <IndustryStandard/Acpi.h>
22 #include <IndustryStandard/Pci.h>
23 #include <PciHostResource.h>
26 // Driver Consumed Protocol Prototypes
28 #include <Protocol/Metronome.h>
29 #include <Protocol/CpuIo2.h>
30 #include <Protocol/DevicePath.h>
31 #include <Protocol/Runtime.h>
32 #include <Protocol/PciRootBridgeIo.h>
33 #include <Library/UefiLib.h>
34 #include <Library/DebugLib.h>
35 #include <Library/DevicePathLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/DxeServicesTableLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/BaseLib.h>
43 // Define the region of memory used for DMA memory
45 #define DMA_MEMORY_TOP 0x0000000001FFFFFFULL
48 // The number of PCI root bridges
50 #define ROOT_BRIDGE_COUNT 1
53 // The default latency for controllers
55 #define DEFAULT_PCI_LATENCY 0x20
58 // Define resource status constant
61 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
;
64 EFI_PHYSICAL_ADDRESS HostAddress
;
65 EFI_PHYSICAL_ADDRESS MappedHostAddress
;
69 ACPI_HID_DEVICE_PATH AcpiDevicePath
;
70 EFI_DEVICE_PATH_PROTOCOL EndDevicePath
;
71 } EFI_PCI_ROOT_BRIDGE_DEVICE_PATH
;
73 #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('e', '2', 'p', 'b')
79 UINT64 RootBridgeAllocAttrib
;
82 PCI_RES_NODE ResAllocNode
[6];
83 PCI_ROOT_BRIDGE_RESOURCE_APERTURE Aperture
;
90 BOOLEAN BusNumberAssigned
;
92 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
93 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL Io
;
94 } PCI_ROOT_BRIDGE_INSTANCE
;
97 // Driver Instance Data Macros
99 #define DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Io, PCI_ROOT_BRIDGE_SIGNATURE)
101 #define DRIVER_INSTANCE_FROM_LIST_ENTRY(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Link, PCI_ROOT_BRIDGE_SIGNATURE)
104 SimpleIioRootBridgeConstructor (
105 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*Protocol
,
106 IN EFI_HANDLE HostBridgeHandle
,
107 IN PCI_ROOT_BRIDGE_RESOURCE_APERTURE
*ResAppeture
,
108 IN UINT64 AllocAttributes
114 Construct the Pci Root Bridge Io protocol.
118 Protocol - Protocol to initialize.
119 HostBridgeHandle - Handle to the HostBridge.
120 ResAppeture - Resource apperture of the root bridge.
121 AllocAttributes - Attribute of resouce allocated.
125 EFI_SUCCESS - Success.
132 // Protocol Member Function Prototypes
136 RootBridgeIoPollMem (
137 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
138 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
149 Poll an address in memory mapped space until an exit condition is met
154 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
155 Width - Width of the memory operation.
156 Address - The base address of the memory operation.
157 Mask - Mask used for polling criteria.
158 Value - Comparison value used for polling exit criteria.
159 Delay - Number of 100ns units to poll.
160 Result - Pointer to the last value read from memory location.
164 EFI_SUCCESS - Success.
165 EFI_INVALID_PARAMETER - Invalid parameter found.
166 EFI_TIMEOUT - Delay expired before a match occurred.
167 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
175 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
176 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
187 Poll an address in I/O space until an exit condition is met
192 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
193 Width - Width of I/O operation.
194 Address - The base address of the I/O operation.
195 Mask - Mask used for polling criteria.
196 Value - Comparison value used for polling exit criteria.
197 Delay - Number of 100ns units to poll.
198 Result - Pointer to the last value read from memory location.
202 EFI_SUCCESS - Success.
203 EFI_INVALID_PARAMETER - Invalid parameter found.
204 EFI_TIMEOUT - Delay expired before a match occurred.
205 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
212 RootBridgeIoMemRead (
213 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
214 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
223 Allow read from memory mapped I/O space.
227 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
228 Width - The width of memory operation.
229 Address - Base address of the memory operation.
230 Count - Number of memory opeartion to perform.
231 Buffer - The destination buffer to store data.
235 EFI_SUCCESS - Success.
236 EFI_INVALID_PARAMETER - Invalid parameter found.
237 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
244 RootBridgeIoMemWrite (
245 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
246 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
255 Allow write to memory mapped I/O space.
259 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
260 Width - The width of memory operation.
261 Address - Base address of the memory operation.
262 Count - Number of memory opeartion to perform.
263 Buffer - The source buffer to write data from.
267 EFI_SUCCESS - Success.
268 EFI_INVALID_PARAMETER - Invalid parameter found.
269 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
277 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
278 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
279 IN UINT64 UserAddress
,
281 IN OUT VOID
*UserBuffer
287 Enable a PCI driver to read PCI controller registers in the
288 PCI root bridge I/O space.
292 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
293 Width - Signifies the width of the memory operation.
294 UserAddress - The base address of the I/O operation.
295 Count - The number of I/O operations to perform.
296 UserBuffer - The destination buffer to store the results.
300 EFI_SUCCESS - The data was read from the PCI root bridge.
301 EFI_INVALID_PARAMETER - Invalid parameters found.
302 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
309 RootBridgeIoIoWrite (
310 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
311 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
312 IN UINT64 UserAddress
,
314 IN OUT VOID
*UserBuffer
320 Enable a PCI driver to write to PCI controller registers in the
321 PCI root bridge I/O space.
325 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
326 Width - Signifies the width of the memory operation.
327 UserAddress - The base address of the I/O operation.
328 Count - The number of I/O operations to perform.
329 UserBuffer - The source buffer to write data from.
333 EFI_SUCCESS - The data was written to the PCI root bridge.
334 EFI_INVALID_PARAMETER - Invalid parameters found.
335 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
342 RootBridgeIoCopyMem (
343 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
344 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
345 IN UINT64 DestAddress
,
346 IN UINT64 SrcAddress
,
353 Copy one region of PCI root bridge memory space to be copied to
354 another region of PCI root bridge memory space.
358 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
359 Width - Signifies the width of the memory operation.
360 DestAddress - Destination address of the memory operation.
361 SrcAddress - Source address of the memory operation.
362 Count - Number of memory operations to perform.
366 EFI_SUCCESS - The data was copied successfully.
367 EFI_INVALID_PARAMETER - Invalid parameters found.
368 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
375 RootBridgeIoPciRead (
376 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
377 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
386 Allows read from PCI configuration space.
390 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
391 Width - Signifies the width of the memory operation.
392 Address - The address within the PCI configuration space
393 for the PCI controller.
394 Count - The number of PCI configuration operations
396 Buffer - The destination buffer to store the results.
400 EFI_SUCCESS - The data was read from the PCI root bridge.
401 EFI_INVALID_PARAMETER - Invalid parameters found.
402 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
409 RootBridgeIoPciWrite (
410 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
411 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
420 Allows write to PCI configuration space.
424 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
425 Width - Signifies the width of the memory operation.
426 Address - The address within the PCI configuration space
427 for the PCI controller.
428 Count - The number of PCI configuration operations
430 Buffer - The source buffer to get the results.
434 EFI_SUCCESS - The data was written to the PCI root bridge.
435 EFI_INVALID_PARAMETER - Invalid parameters found.
436 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
444 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
445 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation
,
446 IN VOID
*HostAddress
,
447 IN OUT UINTN
*NumberOfBytes
,
448 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
455 Provides the PCI controller-specific address needed to access
456 system memory for DMA.
460 This - A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
461 Operation - Indicate if the bus master is going to read or write
463 HostAddress - The system memory address to map on the PCI controller.
464 NumberOfBytes - On input the number of bytes to map.
465 On output the number of bytes that were mapped.
466 DeviceAddress - The resulting map address for the bus master PCI
467 controller to use to access the system memory's HostAddress.
468 Mapping - The value to pass to Unmap() when the bus master DMA
469 operation is complete.
473 EFI_SUCCESS - Success.
474 EFI_INVALID_PARAMETER - Invalid parameters found.
475 EFI_UNSUPPORTED - The HostAddress cannot be mapped as a common
477 EFI_DEVICE_ERROR - The System hardware could not map the requested
479 EFI_OUT_OF_RESOURCES - The request could not be completed due to
488 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
495 Completes the Map() operation and releases any corresponding resources.
499 This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
500 Mapping - The value returned from Map() operation.
504 EFI_SUCCESS - The range was unmapped successfully.
505 EFI_INVALID_PARAMETER - Mapping is not a value that was returned
507 EFI_DEVICE_ERROR - The data was not committed to the target
515 RootBridgeIoAllocateBuffer (
516 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
517 IN EFI_ALLOCATE_TYPE Type
,
518 IN EFI_MEMORY_TYPE MemoryType
,
520 OUT VOID
**HostAddress
,
527 Allocates pages that are suitable for a common buffer mapping.
531 This - Pointer to EFI_ROOT_BRIDGE_IO_PROTOCOL instance.
532 Type - Not used and can be ignored.
533 MemoryType - Type of memory to allocate.
534 Pages - Number of pages to allocate.
535 HostAddress - Pointer to store the base system memory address
536 of the allocated range.
537 Attributes - Requested bit mask of attributes of the allocated
542 EFI_SUCCESS - The requested memory range were allocated.
543 EFI_INVALID_PARAMETER - Invalid parameter found.
544 EFI_UNSUPPORTED - Attributes is unsupported.
551 RootBridgeIoFreeBuffer (
552 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
554 OUT VOID
*HostAddress
560 Free memory allocated in AllocateBuffer.
564 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
566 Pages - Number of pages to free.
567 HostAddress - The base system memory address of the
572 EFI_SUCCESS - Requested memory pages were freed.
573 EFI_INVALID_PARAMETER - Invalid parameter found.
581 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
587 Flushes all PCI posted write transactions from a PCI host
588 bridge to system memory.
592 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
596 EFI_SUCCESS - PCI posted write transactions were flushed
597 from PCI host bridge to system memory.
598 EFI_DEVICE_ERROR - Fail due to hardware error.
605 RootBridgeIoGetAttributes (
606 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
607 OUT UINT64
*Supported
,
608 OUT UINT64
*Attributes
614 Get the attributes that a PCI root bridge supports and
615 the attributes the PCI root bridge is currently using.
619 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
621 Supports - A pointer to the mask of attributes that
622 this PCI root bridge supports.
623 Attributes - A pointer to the mask of attributes that
624 this PCI root bridge is currently using.
627 EFI_SUCCESS - Success.
628 EFI_INVALID_PARAMETER - Invalid parameter found.
632 // GC_TODO: Supported - add argument and description to function comment
634 // GC_TODO: Supported - add argument and description to function comment
636 // GC_TODO: Supported - add argument and description to function comment
642 RootBridgeIoSetAttributes (
643 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
644 IN UINT64 Attributes
,
645 IN OUT UINT64
*ResourceBase
,
646 IN OUT UINT64
*ResourceLength
652 Sets the attributes for a resource range on a PCI root bridge.
656 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
657 Attributes - The mask of attributes to set.
658 ResourceBase - Pointer to the base address of the resource range
659 to be modified by the attributes specified by Attributes.
660 ResourceLength - Pointer to the length of the resource range to be modified.
663 EFI_SUCCESS - Success.
664 EFI_INVALID_PARAMETER - Invalid parameter found.
665 EFI_OUT_OF_RESOURCES - Not enough resources to set the attributes upon.
672 RootBridgeIoConfiguration (
673 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
680 Retrieves the current resource settings of this PCI root bridge
681 in the form of a set of ACPI 2.0 resource descriptor.
685 This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
686 Resources - Pointer to the ACPI 2.0 resource descriptor that
687 describe the current configuration of this PCI root
692 EFI_SUCCESS - Success.
693 EFI_UNSUPPORTED - Current configuration of the PCI root bridge
694 could not be retrieved.