1 /** @file 2 3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> 4 Copyright (c) 2013 - 2014, ARM Ltd. All rights reserved.<BR> 5 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 10 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. 13 14 **/ 15 16 #ifndef _PCI_ROOT_BRIDGE_H_ 17 #define _PCI_ROOT_BRIDGE_H_ 18 19 #include <PiDxe.h> 20 21 #include <Library/BaseLib.h> 22 #include <Library/BaseMemoryLib.h> 23 #include <Library/DxeServicesTableLib.h> 24 #include <Library/IoLib.h> 25 #include <Library/MemoryAllocationLib.h> 26 #include <Library/PciLib.h> 27 #include <Library/UefiLib.h> 28 #include <Library/DmaLib.h> 29 30 #include <Protocol/EmbeddedExternalDevice.h> 31 #include <Protocol/DevicePath.h> 32 #include <Protocol/PciIo.h> 33 #include <Protocol/PciRootBridgeIo.h> 34 #include <Protocol/PciHostBridgeResourceAllocation.h> 35 36 #include <IndustryStandard/Pci23.h> 37 38 #include "ArmJunoDxeInternal.h" 39 40 #define EFI_RESOURCE_NONEXISTENT 0xFFFFFFFFFFFFFFFFULL 41 #define EFI_RESOURCE_LESS 0xFFFFFFFFFFFFFFFEULL 42 #define EFI_RESOURCE_SATISFIED 0x0000000000000000ULL 43 44 45 typedef struct { 46 ACPI_HID_DEVICE_PATH AcpiDevicePath; 47 EFI_DEVICE_PATH_PROTOCOL EndDevicePath; 48 } EFI_PCI_ROOT_BRIDGE_DEVICE_PATH; 49 50 51 #define ACPI_CONFIG_IO 0 52 #define ACPI_CONFIG_MMIO 1 53 #define ACPI_CONFIG_BUS 2 54 55 typedef struct { 56 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR Desc[3]; 57 EFI_ACPI_END_TAG_DESCRIPTOR EndDesc; 58 } ACPI_CONFIG_INFO; 59 60 61 #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('P', 'c', 'i', 'F') 62 63 typedef struct { 64 UINT32 Signature; 65 EFI_HANDLE Handle; 66 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL Io; 67 EFI_PCI_ROOT_BRIDGE_DEVICE_PATH DevicePath; 68 69 UINT8 StartBus; 70 UINT8 EndBus; 71 UINT16 Type; 72 UINT32 MemoryStart; 73 UINT32 MemorySize; 74 UINTN IoOffset; 75 UINT32 IoStart; 76 UINT32 IoSize; 77 UINT64 PciAttributes; 78 79 ACPI_CONFIG_INFO *Config; 80 81 } PCI_ROOT_BRIDGE; 82 83 84 #define INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS(a) CR (a, PCI_ROOT_BRIDGE, Io, PCI_ROOT_BRIDGE_SIGNATURE) 85 86 87 typedef union { 88 UINT8 volatile *Buffer; 89 UINT8 volatile *Ui8; 90 UINT16 volatile *Ui16; 91 UINT32 volatile *Ui32; 92 UINT64 volatile *Ui64; 93 UINTN volatile Ui; 94 } PTR; 95 96 97 98 EFI_STATUS 99 EFIAPI 100 PciRootBridgeIoPollMem ( 101 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 102 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 103 IN UINT64 Address, 104 IN UINT64 Mask, 105 IN UINT64 Value, 106 IN UINT64 Delay, 107 OUT UINT64 *Result 108 ); 109 110 EFI_STATUS 111 EFIAPI 112 PciRootBridgeIoPollIo ( 113 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 114 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 115 IN UINT64 Address, 116 IN UINT64 Mask, 117 IN UINT64 Value, 118 IN UINT64 Delay, 119 OUT UINT64 *Result 120 ); 121 122 EFI_STATUS 123 EFIAPI 124 PciRootBridgeIoMemRead ( 125 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 126 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 127 IN UINT64 Address, 128 IN UINTN Count, 129 IN OUT VOID *Buffer 130 ); 131 132 EFI_STATUS 133 EFIAPI 134 PciRootBridgeIoMemWrite ( 135 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 136 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 137 IN UINT64 Address, 138 IN UINTN Count, 139 IN OUT VOID *Buffer 140 ); 141 142 EFI_STATUS 143 EFIAPI 144 PciRootBridgeIoIoRead ( 145 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 146 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 147 IN UINT64 UserAddress, 148 IN UINTN Count, 149 IN OUT VOID *UserBuffer 150 ); 151 152 EFI_STATUS 153 EFIAPI 154 PciRootBridgeIoIoWrite ( 155 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 156 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 157 IN UINT64 UserAddress, 158 IN UINTN Count, 159 IN OUT VOID *UserBuffer 160 ); 161 162 EFI_STATUS 163 EFIAPI 164 PciRootBridgeIoCopyMem ( 165 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 166 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 167 IN UINT64 DestAddress, 168 IN UINT64 SrcAddress, 169 IN UINTN Count 170 ); 171 172 EFI_STATUS 173 EFIAPI 174 PciRootBridgeIoPciRead ( 175 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 176 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 177 IN UINT64 Address, 178 IN UINTN Count, 179 IN OUT VOID *Buffer 180 ); 181 182 EFI_STATUS 183 EFIAPI 184 PciRootBridgeIoPciWrite ( 185 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 186 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 187 IN UINT64 Address, 188 IN UINTN Count, 189 IN OUT VOID *Buffer 190 ); 191 192 EFI_STATUS 193 EFIAPI 194 PciRootBridgeIoMap ( 195 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 196 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation, 197 IN VOID *HostAddress, 198 IN OUT UINTN *NumberOfBytes, 199 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, 200 OUT VOID **Mapping 201 ); 202 203 EFI_STATUS 204 EFIAPI 205 PciRootBridgeIoUnmap ( 206 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 207 IN VOID *Mapping 208 ); 209 210 EFI_STATUS 211 EFIAPI 212 PciRootBridgeIoAllocateBuffer ( 213 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 214 IN EFI_ALLOCATE_TYPE Type, 215 IN EFI_MEMORY_TYPE MemoryType, 216 IN UINTN Pages, 217 OUT VOID **HostAddress, 218 IN UINT64 Attributes 219 ); 220 221 EFI_STATUS 222 EFIAPI 223 PciRootBridgeIoFreeBuffer ( 224 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 225 IN UINTN Pages, 226 OUT VOID *HostAddress 227 ); 228 229 EFI_STATUS 230 EFIAPI 231 PciRootBridgeIoFlush ( 232 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This 233 ); 234 235 EFI_STATUS 236 EFIAPI 237 PciRootBridgeIoGetAttributes ( 238 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 239 OUT UINT64 *Supported, 240 OUT UINT64 *Attributes 241 ); 242 243 EFI_STATUS 244 EFIAPI 245 PciRootBridgeIoSetAttributes ( 246 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 247 IN UINT64 Attributes, 248 IN OUT UINT64 *ResourceBase, 249 IN OUT UINT64 *ResourceLength 250 ); 251 252 EFI_STATUS 253 EFIAPI 254 PciRootBridgeIoConfiguration ( 255 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, 256 OUT VOID **Resources 257 ); 258 259 // 260 // Private Function Prototypes 261 // 262 EFI_STATUS 263 EFIAPI 264 PciRootBridgeIoMemRW ( 265 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, 266 IN UINTN Count, 267 IN BOOLEAN InStrideFlag, 268 IN PTR In, 269 IN BOOLEAN OutStrideFlag, 270 OUT PTR Out 271 ); 272 273 BOOLEAN 274 PciIoMemAddressValid ( 275 IN EFI_PCI_IO_PROTOCOL *This, 276 IN UINT64 Address 277 ); 278 279 EFI_STATUS 280 EmulatePciIoForEhci ( 281 INTN MvPciIfMaxIf 282 ); 283 284 #endif 285