1 /*++ 2 3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> 4 This program and the accompanying materials 5 are licensed and made available under the terms and conditions of the BSD License 6 which accompanies this distribution. The full text of the license may be found at 7 http://opensource.org/licenses/bsd-license.php 8 9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 12 Module Name: 13 14 DeviceIo.h 15 16 Abstract: 17 18 Private Data definition for Device IO driver 19 20 --*/ 21 22 #ifndef _DEVICE_IO_H 23 #define _DEVICE_IO_H 24 25 26 27 #define DEVICE_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('d', 'e', 'v', 'I') 28 29 #define MAX_COMMON_BUFFER 0x00000000FFFFFFFF 30 31 typedef struct { 32 UINTN Signature; 33 EFI_HANDLE Handle; 34 EFI_DEVICE_IO_PROTOCOL DeviceIo; 35 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo; 36 EFI_DEVICE_PATH_PROTOCOL *DevicePath; 37 UINT16 PrimaryBus; 38 UINT16 SubordinateBus; 39 } DEVICE_IO_PRIVATE_DATA; 40 41 #define DEVICE_IO_PRIVATE_DATA_FROM_THIS(a) CR (a, DEVICE_IO_PRIVATE_DATA, DeviceIo, DEVICE_IO_PRIVATE_DATA_SIGNATURE) 42 43 EFI_STATUS 44 DeviceIoConstructor ( 45 IN EFI_HANDLE Handle, 46 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo, 47 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, 48 IN UINT16 PrimaryBus, 49 IN UINT16 SubordinateBus 50 ) 51 /*++ 52 53 Routine Description: 54 55 Initialize and install a Device IO protocol on a empty device path handle. 56 57 Arguments: 58 59 Handle - Handle of PCI RootBridge IO instance 60 PciRootBridgeIo - PCI RootBridge IO instance 61 DevicePath - Device Path of PCI RootBridge IO instance 62 PrimaryBus - Primary Bus 63 SubordinateBus - Subordinate Bus 64 65 Returns: 66 67 EFI_SUCCESS - This driver is added to ControllerHandle. 68 EFI_ALREADY_STARTED - This driver is already running on ControllerHandle. 69 Others - This driver does not support this device. 70 71 --*/ 72 ; 73 74 EFI_STATUS 75 EFIAPI 76 DeviceIoMemRead ( 77 IN EFI_DEVICE_IO_PROTOCOL *This, 78 IN EFI_IO_WIDTH Width, 79 IN UINT64 Address, 80 IN UINTN Count, 81 IN OUT VOID *Buffer 82 ) 83 /*++ 84 85 Routine Description: 86 87 Perform reading memory mapped I/O space of device. 88 89 Arguments: 90 91 This - A pointer to EFI_DEVICE_IO protocol instance. 92 Width - Width of I/O operations. 93 Address - The base address of I/O operations. 94 Count - The number of I/O operations to perform. 95 Bytes moves is Width size * Count, starting at Address. 96 Buffer - The destination buffer to store results. 97 98 Returns: 99 100 EFI_SUCCESS - The data was read from the device. 101 EFI_INVALID_PARAMETER - Width is invalid. 102 EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources. 103 104 --*/ 105 ; 106 107 EFI_STATUS 108 EFIAPI 109 DeviceIoMemWrite ( 110 IN EFI_DEVICE_IO_PROTOCOL *This, 111 IN EFI_IO_WIDTH Width, 112 IN UINT64 Address, 113 IN UINTN Count, 114 IN OUT VOID *Buffer 115 ) 116 /*++ 117 118 Routine Description: 119 120 Perform writing memory mapped I/O space of device. 121 122 Arguments: 123 124 This - A pointer to EFI_DEVICE_IO protocol instance. 125 Width - Width of I/O operations. 126 Address - The base address of I/O operations. 127 Count - The number of I/O operations to perform. 128 Bytes moves is Width size * Count, starting at Address. 129 Buffer - The source buffer of data to be written. 130 131 Returns: 132 133 EFI_SUCCESS - The data was written to the device. 134 EFI_INVALID_PARAMETER - Width is invalid. 135 EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources. 136 137 --*/ 138 ; 139 140 EFI_STATUS 141 EFIAPI 142 DeviceIoIoRead ( 143 IN EFI_DEVICE_IO_PROTOCOL *This, 144 IN EFI_IO_WIDTH Width, 145 IN UINT64 Address, 146 IN UINTN Count, 147 IN OUT VOID *Buffer 148 ) 149 /*++ 150 151 Routine Description: 152 153 Perform reading I/O space of device. 154 155 Arguments: 156 157 This - A pointer to EFI_DEVICE_IO protocol instance. 158 Width - Width of I/O operations. 159 Address - The base address of I/O operations. 160 Count - The number of I/O operations to perform. 161 Bytes moves is Width size * Count, starting at Address. 162 Buffer - The destination buffer to store results. 163 164 Returns: 165 166 EFI_SUCCESS - The data was read from the device. 167 EFI_INVALID_PARAMETER - Width is invalid. 168 EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources. 169 170 --*/ 171 ; 172 173 EFI_STATUS 174 EFIAPI 175 DeviceIoIoWrite ( 176 IN EFI_DEVICE_IO_PROTOCOL *This, 177 IN EFI_IO_WIDTH Width, 178 IN UINT64 Address, 179 IN UINTN Count, 180 IN OUT VOID *Buffer 181 ) 182 /*++ 183 184 Routine Description: 185 186 Perform writing I/O space of device. 187 188 Arguments: 189 190 This - A pointer to EFI_DEVICE_IO protocol instance. 191 Width - Width of I/O operations. 192 Address - The base address of I/O operations. 193 Count - The number of I/O operations to perform. 194 Bytes moves is Width size * Count, starting at Address. 195 Buffer - The source buffer of data to be written. 196 197 Returns: 198 199 EFI_SUCCESS - The data was written to the device. 200 EFI_INVALID_PARAMETER - Width is invalid. 201 EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources. 202 203 --*/ 204 ; 205 206 EFI_STATUS 207 EFIAPI 208 DeviceIoPciRead ( 209 IN EFI_DEVICE_IO_PROTOCOL *This, 210 IN EFI_IO_WIDTH Width, 211 IN UINT64 Address, 212 IN UINTN Count, 213 IN OUT VOID *Buffer 214 ) 215 /*++ 216 217 Routine Description: 218 219 Perform reading PCI configuration space of device 220 221 Arguments: 222 223 This - A pointer to EFI_DEVICE_IO protocol instance. 224 Width - Width of I/O operations. 225 Address - The base address of I/O operations. 226 Count - The number of I/O operations to perform. 227 Bytes moves is Width size * Count, starting at Address. 228 Buffer - The destination buffer to store results. 229 230 Returns: 231 232 EFI_SUCCESS - The data was read from the device. 233 EFI_INVALID_PARAMETER - Width is invalid. 234 EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources. 235 236 --*/ 237 ; 238 239 EFI_STATUS 240 EFIAPI 241 DeviceIoPciWrite ( 242 IN EFI_DEVICE_IO_PROTOCOL *This, 243 IN EFI_IO_WIDTH Width, 244 IN UINT64 Address, 245 IN UINTN Count, 246 IN OUT VOID *Buffer 247 ) 248 /*++ 249 250 Routine Description: 251 252 Perform writing PCI configuration space of device. 253 254 Arguments: 255 256 This - A pointer to EFI_DEVICE_IO protocol instance. 257 Width - Width of I/O operations. 258 Address - The base address of I/O operations. 259 Count - The number of I/O operations to perform. 260 Bytes moves is Width size * Count, starting at Address. 261 Buffer - The source buffer of data to be written. 262 263 Returns: 264 265 EFI_SUCCESS - The data was written to the device. 266 EFI_INVALID_PARAMETER - Width is invalid. 267 EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources. 268 269 --*/ 270 ; 271 272 EFI_STATUS 273 EFIAPI 274 DeviceIoPciDevicePath ( 275 IN EFI_DEVICE_IO_PROTOCOL *This, 276 IN UINT64 Address, 277 IN OUT EFI_DEVICE_PATH_PROTOCOL **PciDevicePath 278 ) 279 /*++ 280 281 Routine Description: 282 283 Append a PCI device path node to another device path. 284 285 Arguments: 286 287 This - A pointer to EFI_DEVICE_IO_PROTOCOL. 288 Address - PCI bus,device, function. 289 PciDevicePath - PCI device path. 290 291 Returns: 292 293 Pointer to the appended PCI device path. 294 295 --*/ 296 ; 297 298 EFI_STATUS 299 EFIAPI 300 DeviceIoMap ( 301 IN EFI_DEVICE_IO_PROTOCOL *This, 302 IN EFI_IO_OPERATION_TYPE Operation, 303 IN EFI_PHYSICAL_ADDRESS *HostAddress, 304 IN OUT UINTN *NumberOfBytes, 305 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, 306 OUT VOID **Mapping 307 ) 308 /*++ 309 310 Routine Description: 311 312 Provides the device-specific addresses needed to access system memory. 313 314 Arguments: 315 316 This - A pointer to the EFI_DEVICE_IO_INTERFACE instance. 317 Operation - Indicates if the bus master is going to read or write to system memory. 318 HostAddress - The system memory address to map to the device. 319 NumberOfBytes - On input the number of bytes to map. On output the number of bytes 320 that were mapped. 321 DeviceAddress - The resulting map address for the bus master device to use to access the 322 hosts HostAddress. 323 Mapping - A resulting value to pass to Unmap(). 324 325 Returns: 326 327 EFI_SUCCESS - The range was mapped for the returned NumberOfBytes. 328 EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined. 329 EFI_UNSUPPORTED - The HostAddress cannot be mapped as a common buffer. 330 EFI_DEVICE_ERROR - The system hardware could not map the requested address. 331 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources. 332 333 --*/ 334 ; 335 336 EFI_STATUS 337 EFIAPI 338 DeviceIoUnmap ( 339 IN EFI_DEVICE_IO_PROTOCOL *This, 340 IN VOID *Mapping 341 ) 342 /*++ 343 344 Routine Description: 345 346 Completes the Map() operation and releases any corresponding resources. 347 348 Arguments: 349 350 This - A pointer to the EFI_DEVICE_IO_INTERFACE instance. 351 Mapping - The mapping value returned from Map(). 352 353 Returns: 354 355 EFI_SUCCESS - The range was unmapped. 356 EFI_DEVICE_ERROR - The data was not committed to the target system memory. 357 358 --*/ 359 ; 360 361 EFI_STATUS 362 EFIAPI 363 DeviceIoAllocateBuffer ( 364 IN EFI_DEVICE_IO_PROTOCOL *This, 365 IN EFI_ALLOCATE_TYPE Type, 366 IN EFI_MEMORY_TYPE MemoryType, 367 IN UINTN Pages, 368 IN OUT EFI_PHYSICAL_ADDRESS *HostAddress 369 ) 370 /*++ 371 372 Routine Description: 373 374 Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping. 375 376 Arguments: 377 378 This - A pointer to the EFI_DEVICE_IO_INTERFACE instance. 379 Type - The type allocation to perform. 380 MemoryType - The type of memory to allocate, EfiBootServicesData or 381 EfiRuntimeServicesData. 382 Pages - The number of pages to allocate. 383 HostAddress - A pointer to store the base address of the allocated range. 384 385 Returns: 386 387 EFI_SUCCESS - The requested memory pages were allocated. 388 EFI_OUT_OF_RESOURCES - The memory pages could not be allocated. 389 EFI_INVALID_PARAMETER - The requested memory type is invalid. 390 EFI_UNSUPPORTED - The requested PhysicalAddress is not supported on 391 this platform. 392 393 --*/ 394 ; 395 396 EFI_STATUS 397 EFIAPI 398 DeviceIoFlush ( 399 IN EFI_DEVICE_IO_PROTOCOL *This 400 ) 401 /*++ 402 403 Routine Description: 404 405 Flushes any posted write data to the device. 406 407 Arguments: 408 409 This - A pointer to the EFI_DEVICE_IO_INTERFACE instance. 410 411 Returns: 412 413 EFI_SUCCESS - The buffers were flushed. 414 EFI_DEVICE_ERROR - The buffers were not flushed due to a hardware error. 415 416 --*/ 417 ; 418 419 EFI_STATUS 420 EFIAPI 421 DeviceIoFreeBuffer ( 422 IN EFI_DEVICE_IO_PROTOCOL *This, 423 IN UINTN Pages, 424 IN EFI_PHYSICAL_ADDRESS HostAddress 425 ) 426 /*++ 427 428 Routine Description: 429 430 Frees pages that were allocated with AllocateBuffer(). 431 432 Arguments: 433 434 This - A pointer to the EFI_DEVICE_IO_INTERFACE instance. 435 Pages - The number of pages to free. 436 HostAddress - The base address of the range to free. 437 438 Returns: 439 440 EFI_SUCCESS - The requested memory pages were freed. 441 EFI_NOT_FOUND - The requested memory pages were not allocated with 442 AllocateBuffer(). 443 EFI_INVALID_PARAMETER - HostAddress is not page aligned or Pages is invalid. 444 445 --*/ 446 ; 447 448 #endif 449 450