Greg Hartman | 76d05dc | 2016-11-23 15:51:27 -0800 | [diff] [blame] | 1 | /** @file |
| 2 | PCI Root Bridge I/O protocol as defined in the UEFI 2.0 specification. |
| 3 | |
| 4 | PCI Root Bridge I/O protocol is used by PCI Bus Driver to perform PCI Memory, PCI I/O, |
| 5 | and PCI Configuration cycles on a PCI Root Bridge. It also provides services to perform |
| 6 | defferent types of bus mastering DMA |
| 7 | |
| 8 | Copyright (c) 2006 - 2008, Intel Corporation |
| 9 | All rights reserved. This program and the accompanying materials |
| 10 | are licensed and made available under the terms and conditions of the BSD License |
| 11 | which accompanies this distribution. The full text of the license may be found at |
| 12 | http://opensource.org/licenses/bsd-license.php |
| 13 | |
| 14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, |
| 15 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. |
| 16 | |
| 17 | **/ |
| 18 | |
| 19 | #ifndef __PCI_ROOT_BRIDGE_IO_H__ |
| 20 | #define __PCI_ROOT_BRIDGE_IO_H__ |
| 21 | |
| 22 | #define EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID \ |
| 23 | { \ |
| 24 | 0x2f707ebb, 0x4a1a, 0x11d4, {0x9a, 0x38, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ |
| 25 | } |
| 26 | |
| 27 | typedef struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL; |
| 28 | |
| 29 | typedef enum { |
| 30 | EfiPciWidthUint8, |
| 31 | EfiPciWidthUint16, |
| 32 | EfiPciWidthUint32, |
| 33 | EfiPciWidthUint64, |
| 34 | EfiPciWidthFifoUint8, |
| 35 | EfiPciWidthFifoUint16, |
| 36 | EfiPciWidthFifoUint32, |
| 37 | EfiPciWidthFifoUint64, |
| 38 | EfiPciWidthFillUint8, |
| 39 | EfiPciWidthFillUint16, |
| 40 | EfiPciWidthFillUint32, |
| 41 | EfiPciWidthFillUint64, |
| 42 | EfiPciWidthMaximum |
| 43 | } EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH; |
| 44 | |
| 45 | typedef enum { |
| 46 | EfiPciOperationBusMasterRead, |
| 47 | EfiPciOperationBusMasterWrite, |
| 48 | EfiPciOperationBusMasterCommonBuffer, |
| 49 | EfiPciOperationBusMasterRead64, |
| 50 | EfiPciOperationBusMasterWrite64, |
| 51 | EfiPciOperationBusMasterCommonBuffer64, |
| 52 | EfiPciOperationMaximum |
| 53 | } EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION; |
| 54 | |
| 55 | #define EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001 |
| 56 | #define EFI_PCI_ATTRIBUTE_ISA_IO 0x0002 |
| 57 | #define EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO 0x0004 |
| 58 | #define EFI_PCI_ATTRIBUTE_VGA_MEMORY 0x0008 |
| 59 | #define EFI_PCI_ATTRIBUTE_VGA_IO 0x0010 |
| 60 | #define EFI_PCI_ATTRIBUTE_IDE_PRIMARY_IO 0x0020 |
| 61 | #define EFI_PCI_ATTRIBUTE_IDE_SECONDARY_IO 0x0040 |
| 62 | #define EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080 |
| 63 | #define EFI_PCI_ATTRIBUTE_MEMORY_CACHED 0x0800 |
| 64 | #define EFI_PCI_ATTRIBUTE_MEMORY_DISABLE 0x1000 |
| 65 | #define EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000 |
| 66 | |
| 67 | #define EFI_PCI_ATTRIBUTE_VALID_FOR_ALLOCATE_BUFFER (EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE | EFI_PCI_ATTRIBUTE_MEMORY_CACHED | EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE) |
| 68 | |
| 69 | #define EFI_PCI_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER (~EFI_PCI_ATTRIBUTE_VALID_FOR_ALLOCATE_BUFFER) |
| 70 | |
| 71 | #define EFI_PCI_ADDRESS(bus, dev, func, reg) \ |
| 72 | ((UINT64) ((((UINTN) bus) << 24) + (((UINTN) dev) << 16) + (((UINTN) func) << 8) + ((UINTN) reg))) |
| 73 | |
| 74 | typedef struct { |
| 75 | UINT8 Register; |
| 76 | UINT8 Function; |
| 77 | UINT8 Device; |
| 78 | UINT8 Bus; |
| 79 | UINT32 ExtendedRegister; |
| 80 | } EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS; |
| 81 | |
| 82 | /** |
| 83 | Reads from the I/O space of a PCI Root Bridge. Returns when either the polling exit criteria is |
| 84 | satisfied or after a defined duration. |
| 85 | |
| 86 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 87 | @param Width Signifies the width of the memory or I/O operations. |
| 88 | @param Address The base address of the memory or I/O operations. |
| 89 | @param Mask Mask used for the polling criteria. |
| 90 | @param Value The comparison value used for the polling exit criteria. |
| 91 | @param Delay The number of 100 ns units to poll. |
| 92 | @param Result Pointer to the last value read from the memory location. |
| 93 | |
| 94 | @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria. |
| 95 | @retval EFI_TIMEOUT Delay expired before a match occurred. |
| 96 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. |
| 97 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. |
| 98 | |
| 99 | **/ |
| 100 | typedef |
| 101 | EFI_STATUS |
| 102 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM)( |
| 103 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 104 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, |
| 105 | IN UINT64 Address, |
| 106 | IN UINT64 Mask, |
| 107 | IN UINT64 Value, |
| 108 | IN UINT64 Delay, |
| 109 | OUT UINT64 *Result |
| 110 | ); |
| 111 | |
| 112 | /** |
| 113 | Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space. |
| 114 | |
| 115 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 116 | @param Width Signifies the width of the memory operations. |
| 117 | @param Address The base address of the memory operations. |
| 118 | @param Count The number of memory operations to perform. |
| 119 | @param Buffer For read operations, the destination buffer to store the results. For write |
| 120 | operations, the source buffer to write data from. |
| 121 | |
| 122 | @retval EFI_SUCCESS The data was read from or written to the PCI root bridge. |
| 123 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. |
| 124 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. |
| 125 | |
| 126 | **/ |
| 127 | typedef |
| 128 | EFI_STATUS |
| 129 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM)( |
| 130 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 131 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, |
| 132 | IN UINT64 Address, |
| 133 | IN UINTN Count, |
| 134 | IN OUT VOID *Buffer |
| 135 | ); |
| 136 | |
| 137 | typedef struct { |
| 138 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM Read; |
| 139 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM Write; |
| 140 | } EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS; |
| 141 | |
| 142 | /** |
| 143 | Enables a PCI driver to copy one region of PCI root bridge memory space to another region of PCI |
| 144 | root bridge memory space. |
| 145 | |
| 146 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance. |
| 147 | @param Width Signifies the width of the memory operations. |
| 148 | @param DestAddress The destination address of the memory operation. |
| 149 | @param SrcAddress The source address of the memory operation. |
| 150 | @param Count The number of memory operations to perform. |
| 151 | |
| 152 | @retval EFI_SUCCESS The data was copied from one memory region to another memory region. |
| 153 | @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge. |
| 154 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. |
| 155 | |
| 156 | **/ |
| 157 | typedef |
| 158 | EFI_STATUS |
| 159 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_COPY_MEM)( |
| 160 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 161 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, |
| 162 | IN UINT64 DestAddress, |
| 163 | IN UINT64 SrcAddress, |
| 164 | IN UINTN Count |
| 165 | ); |
| 166 | |
| 167 | /** |
| 168 | Provides the PCI controller-Cspecific addresses required to access system memory from a |
| 169 | DMA bus master. |
| 170 | |
| 171 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 172 | @param Operation Indicates if the bus master is going to read or write to system memory. |
| 173 | @param HostAddress The system memory address to map to the PCI controller. |
| 174 | @param NumberOfBytes On input the number of bytes to map. On output the number of bytes |
| 175 | that were mapped. |
| 176 | @param DeviceAddress The resulting map address for the bus master PCI controller to use to |
| 177 | access the hosts HostAddress. |
| 178 | @param Mapping A resulting value to pass to Unmap(). |
| 179 | |
| 180 | @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes. |
| 181 | @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer. |
| 182 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. |
| 183 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. |
| 184 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested address. |
| 185 | |
| 186 | **/ |
| 187 | typedef |
| 188 | EFI_STATUS |
| 189 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_MAP)( |
| 190 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 191 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation, |
| 192 | IN VOID *HostAddress, |
| 193 | IN OUT UINTN *NumberOfBytes, |
| 194 | OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, |
| 195 | OUT VOID **Mapping |
| 196 | ); |
| 197 | |
| 198 | /** |
| 199 | Completes the Map() operation and releases any corresponding resources. |
| 200 | |
| 201 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 202 | @param Mapping The mapping value returned from Map(). |
| 203 | |
| 204 | @retval EFI_SUCCESS The range was unmapped. |
| 205 | @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map(). |
| 206 | @retval EFI_DEVICE_ERROR The data was not committed to the target system memory. |
| 207 | |
| 208 | **/ |
| 209 | typedef |
| 210 | EFI_STATUS |
| 211 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_UNMAP)( |
| 212 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 213 | IN VOID *Mapping |
| 214 | ); |
| 215 | |
| 216 | /** |
| 217 | Allocates pages that are suitable for an EfiPciOperationBusMasterCommonBuffer or |
| 218 | EfiPciOperationBusMasterCommonBuffer64 mapping. |
| 219 | |
| 220 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 221 | @param Type This parameter is not used and must be ignored. |
| 222 | @param MemoryType The type of memory to allocate, EfiBootServicesData or |
| 223 | EfiRuntimeServicesData. |
| 224 | @param Pages The number of pages to allocate. |
| 225 | @param HostAddress A pointer to store the base system memory address of the |
| 226 | allocated range. |
| 227 | @param Attributes The requested bit mask of attributes for the allocated range. |
| 228 | |
| 229 | @retval EFI_SUCCESS The requested memory pages were allocated. |
| 230 | @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are |
| 231 | MEMORY_WRITE_COMBINE and MEMORY_CACHED. |
| 232 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. |
| 233 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. |
| 234 | |
| 235 | **/ |
| 236 | typedef |
| 237 | EFI_STATUS |
| 238 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ALLOCATE_BUFFER)( |
| 239 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 240 | IN EFI_ALLOCATE_TYPE Type, |
| 241 | IN EFI_MEMORY_TYPE MemoryType, |
| 242 | IN UINTN Pages, |
| 243 | IN OUT VOID **HostAddress, |
| 244 | IN UINT64 Attributes |
| 245 | ); |
| 246 | |
| 247 | /** |
| 248 | Frees memory that was allocated with AllocateBuffer(). |
| 249 | |
| 250 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 251 | @param Pages The number of pages to free. |
| 252 | @param HostAddress The base system memory address of the allocated range. |
| 253 | |
| 254 | @retval EFI_SUCCESS The requested memory pages were freed. |
| 255 | @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages |
| 256 | was not allocated with AllocateBuffer(). |
| 257 | |
| 258 | **/ |
| 259 | typedef |
| 260 | EFI_STATUS |
| 261 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FREE_BUFFER)( |
| 262 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 263 | IN UINTN Pages, |
| 264 | IN VOID *HostAddress |
| 265 | ); |
| 266 | |
| 267 | /** |
| 268 | Flushes all PCI posted write transactions from a PCI host bridge to system memory. |
| 269 | |
| 270 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 271 | |
| 272 | @retval EFI_SUCCESS The PCI posted write transactions were flushed from the PCI host |
| 273 | bridge to system memory. |
| 274 | @retval EFI_DEVICE_ERROR The PCI posted write transactions were not flushed from the PCI |
| 275 | host bridge due to a hardware error. |
| 276 | |
| 277 | **/ |
| 278 | typedef |
| 279 | EFI_STATUS |
| 280 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FLUSH)( |
| 281 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This |
| 282 | ); |
| 283 | |
| 284 | /** |
| 285 | Gets the attributes that a PCI root bridge supports setting with SetAttributes(), and the |
| 286 | attributes that a PCI root bridge is currently using. |
| 287 | |
| 288 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 289 | @param Supports A pointer to the mask of attributes that this PCI root bridge supports |
| 290 | setting with SetAttributes(). |
| 291 | @param Attributes A pointer to the mask of attributes that this PCI root bridge is currently |
| 292 | using. |
| 293 | |
| 294 | @retval EFI_SUCCESS If Supports is not NULL, then the attributes that the PCI root |
| 295 | bridge supports is returned in Supports. If Attributes is |
| 296 | not NULL, then the attributes that the PCI root bridge is currently |
| 297 | using is returned in Attributes. |
| 298 | @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL. |
| 299 | |
| 300 | |
| 301 | **/ |
| 302 | typedef |
| 303 | EFI_STATUS |
| 304 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GET_ATTRIBUTES)( |
| 305 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 306 | OUT UINT64 *Supports, |
| 307 | OUT UINT64 *Attributes |
| 308 | ); |
| 309 | |
| 310 | /** |
| 311 | Sets attributes for a resource range on a PCI root bridge. |
| 312 | |
| 313 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 314 | @param Attributes The mask of attributes to set. |
| 315 | @param ResourceBase A pointer to the base address of the resource range to be modified by the |
| 316 | attributes specified by Attributes. |
| 317 | @param ResourceLength A pointer to the length of the resource range to be modified by the |
| 318 | attributes specified by Attributes. |
| 319 | |
| 320 | @retval EFI_SUCCESS The set of attributes specified by Attributes for the resource |
| 321 | range specified by ResourceBase and ResourceLength |
| 322 | were set on the PCI root bridge, and the actual resource range is |
| 323 | returned in ResuourceBase and ResourceLength. |
| 324 | @retval EFI_UNSUPPORTED A bit is set in Attributes that is not supported by the PCI Root |
| 325 | Bridge. |
| 326 | @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the attributes on the |
| 327 | resource range specified by BaseAddress and Length. |
| 328 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. |
| 329 | |
| 330 | **/ |
| 331 | typedef |
| 332 | EFI_STATUS |
| 333 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_SET_ATTRIBUTES)( |
| 334 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 335 | IN UINT64 Attributes, |
| 336 | IN OUT UINT64 *ResourceBase, |
| 337 | IN OUT UINT64 *ResourceLength |
| 338 | ); |
| 339 | |
| 340 | /** |
| 341 | Retrieves the current resource settings of this PCI root bridge in the form of a set of ACPI 2.0 |
| 342 | resource descriptors. |
| 343 | |
| 344 | @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. |
| 345 | @param Resources A pointer to the ACPI 2.0 resource descriptors that describe the current |
| 346 | configuration of this PCI root bridge. |
| 347 | |
| 348 | @retval EFI_SUCCESS The current configuration of this PCI root bridge was returned in |
| 349 | Resources. |
| 350 | @retval EFI_UNSUPPORTED The current configuration of this PCI root bridge could not be |
| 351 | retrieved. |
| 352 | |
| 353 | **/ |
| 354 | typedef |
| 355 | EFI_STATUS |
| 356 | (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_CONFIGURATION)( |
| 357 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, |
| 358 | OUT VOID **Resources |
| 359 | ); |
| 360 | |
| 361 | /// |
| 362 | /// Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are |
| 363 | /// used to abstract accesses to PCI controllers behind a PCI Root Bridge Controller. |
| 364 | /// |
| 365 | struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL { |
| 366 | /// |
| 367 | /// The EFI_HANDLE of the PCI Host Bridge of which this PCI Root Bridge is a member. |
| 368 | /// |
| 369 | EFI_HANDLE ParentHandle; |
| 370 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM PollMem; |
| 371 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM PollIo; |
| 372 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Mem; |
| 373 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Io; |
| 374 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Pci; |
| 375 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_COPY_MEM CopyMem; |
| 376 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_MAP Map; |
| 377 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_UNMAP Unmap; |
| 378 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer; |
| 379 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FREE_BUFFER FreeBuffer; |
| 380 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FLUSH Flush; |
| 381 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GET_ATTRIBUTES GetAttributes; |
| 382 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_SET_ATTRIBUTES SetAttributes; |
| 383 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_CONFIGURATION Configuration; |
| 384 | |
| 385 | /// |
| 386 | /// The segment number that this PCI root bridge resides. |
| 387 | /// |
| 388 | UINT32 SegmentNumber; |
| 389 | }; |
| 390 | |
| 391 | extern EFI_GUID gEfiPciRootBridgeIoProtocolGuid; |
| 392 | |
| 393 | #endif |