Path: blob/main/sys/contrib/edk2/Include/Protocol/DeviceIo.h
96339 views
/** @file1Device IO protocol as defined in the EFI 1.10 specification.23Device IO is used to abstract hardware access to devices. It includes4memory mapped IO, IO, PCI Config space, and DMA.56Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>7SPDX-License-Identifier: BSD-2-Clause-Patent89**/1011#ifndef __DEVICE_IO_H__12#define __DEVICE_IO_H__1314#define EFI_DEVICE_IO_PROTOCOL_GUID \15{ \160xaf6ac311, 0x84c3, 0x11d2, {0x8e, 0x3c, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \17}1819typedef struct _EFI_DEVICE_IO_PROTOCOL EFI_DEVICE_IO_PROTOCOL;2021///22/// Protocol GUID name defined in EFI1.1.23///24#define DEVICE_IO_PROTOCOL EFI_DEVICE_IO_PROTOCOL_GUID2526///27/// Protocol defined in EFI1.1.28///29typedef EFI_DEVICE_IO_PROTOCOL EFI_DEVICE_IO_INTERFACE;3031///32/// Device IO Access Width33///34typedef enum {35IO_UINT8 = 0,36IO_UINT16 = 1,37IO_UINT32 = 2,38IO_UINT64 = 3,39//40// Below enumerations are added in "Extensible Firmware Interface Specification,41// Version 1.10, Specification Update, Version 001".42//43MMIO_COPY_UINT8 = 4,44MMIO_COPY_UINT16 = 5,45MMIO_COPY_UINT32 = 6,46MMIO_COPY_UINT64 = 747} EFI_IO_WIDTH;4849/**50Enables a driver to access device registers in the appropriate memory or I/O space.5152@param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.53@param Width Signifies the width of the I/O operations.54@param Address The base address of the I/O operations.55@param Count The number of I/O operations to perform.56@param Buffer For read operations, the destination buffer to store the results. For write57operations, the source buffer to write data from. If58Width is MMIO_COPY_UINT8, MMIO_COPY_UINT16,59MMIO_COPY_UINT32, or MMIO_COPY_UINT64, then60Buffer is interpreted as a base address of an I/O operation such as Address.6162@retval EFI_SUCCESS The data was read from or written to the device.63@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.64@retval EFI_INVALID_PARAMETER Width is invalid.6566**/67typedef68EFI_STATUS69(EFIAPI *EFI_DEVICE_IO)(70IN EFI_DEVICE_IO_PROTOCOL *This,71IN EFI_IO_WIDTH Width,72IN UINT64 Address,73IN UINTN Count,74IN OUT VOID *Buffer75);7677typedef struct {78EFI_DEVICE_IO Read;79EFI_DEVICE_IO Write;80} EFI_IO_ACCESS;8182/**83Provides an EFI Device Path for a PCI device with the given PCI configuration space address.8485@param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.86@param PciAddress The PCI configuration space address of the device whose Device Path87is going to be returned.88@param PciDevicePath A pointer to the pointer for the EFI Device Path for PciAddress.89Memory for the Device Path is allocated from the pool.9091@retval EFI_SUCCESS The PciDevicePath returns a pointer to a valid EFI Device Path.92@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.93@retval EFI_UNSUPPORTED The PciAddress does not map to a valid EFI Device Path.9495**/96typedef97EFI_STATUS98(EFIAPI *EFI_PCI_DEVICE_PATH)(99IN EFI_DEVICE_IO_PROTOCOL *This,100IN UINT64 PciAddress,101IN OUT EFI_DEVICE_PATH_PROTOCOL **PciDevicePath102);103104typedef enum {105///106/// A read operation from system memory by a bus master.107///108EfiBusMasterRead,109110///111/// A write operation to system memory by a bus master.112///113EfiBusMasterWrite,114115///116/// Provides both read and write access to system memory117/// by both the processor and a bus master. The buffer is118/// coherent from both the processor's and the bus master's119/// point of view.120///121EfiBusMasterCommonBuffer122} EFI_IO_OPERATION_TYPE;123124/**125Provides the device-specific addresses needed to access system memory.126127@param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.128@param Operation Indicates if the bus master is going to read or write to system memory.129@param HostAddress The system memory address to map to the device.130@param NumberOfBytes On input, the number of bytes to map.131On output, the number of bytes that were mapped.132@param DeviceAddress The resulting map address for the bus master device to use to access the133hosts HostAddress.134@param Mapping A resulting value to pass to Unmap().135136@retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.137@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.138@retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.139@retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.140@retval EFI_DEVICE_ERROR The system hardware could not map the requested address.141142**/143typedef144EFI_STATUS145(EFIAPI *EFI_IO_MAP)(146IN EFI_DEVICE_IO_PROTOCOL *This,147IN EFI_IO_OPERATION_TYPE Operation,148IN EFI_PHYSICAL_ADDRESS *HostAddress,149IN OUT UINTN *NumberOfBytes,150OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,151OUT VOID **Mapping152);153154/**155Completes the Map() operation and releases any corresponding resources.156157@param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.158@param Mapping A resulting value to pass to Unmap().159160@retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.161@retval EFI_DEVICE_ERROR The system hardware could not map the requested address.162163**/164typedef165EFI_STATUS166(EFIAPI *EFI_IO_UNMAP)(167IN EFI_DEVICE_IO_PROTOCOL *This,168IN VOID *Mapping169);170171/**172Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping.173174@param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.175@param Type The type allocation to perform.176@param MemoryType The type of memory to allocate, EfiBootServicesData or177EfiRuntimeServicesData.178@param Pages The number of pages to allocate.179@param HostAddress A pointer to store the base address of the allocated range.180181@retval EFI_SUCCESS The requested memory pages were allocated.182@retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.183@retval EFI_INVALID_PARAMETER The requested memory type is invalid.184@retval EFI_UNSUPPORTED The requested HostAddress is not supported on185this platform.186187**/188typedef189EFI_STATUS190(EFIAPI *EFI_IO_ALLOCATE_BUFFER)(191IN EFI_DEVICE_IO_PROTOCOL *This,192IN EFI_ALLOCATE_TYPE Type,193IN EFI_MEMORY_TYPE MemoryType,194IN UINTN Pages,195IN OUT EFI_PHYSICAL_ADDRESS *HostAddress196);197198/**199Flushes any posted write data to the device.200201@param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.202203@retval EFI_SUCCESS The buffers were flushed.204@retval EFI_DEVICE_ERROR The buffers were not flushed due to a hardware error.205206**/207typedef208EFI_STATUS209(EFIAPI *EFI_IO_FLUSH)(210IN EFI_DEVICE_IO_PROTOCOL *This211);212213/**214Frees pages that were allocated with AllocateBuffer().215216@param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.217@param Pages The number of pages to free.218@param HostAddress The base address of the range to free.219220@retval EFI_SUCCESS The requested memory pages were allocated.221@retval EFI_NOT_FOUND The requested memory pages were not allocated with222AllocateBuffer().223@retval EFI_INVALID_PARAMETER HostAddress is not page aligned or Pages is invalid.224225**/226typedef227EFI_STATUS228(EFIAPI *EFI_IO_FREE_BUFFER)(229IN EFI_DEVICE_IO_PROTOCOL *This,230IN UINTN Pages,231IN EFI_PHYSICAL_ADDRESS HostAddress232);233234///235/// This protocol provides the basic Memory, I/O, and PCI interfaces that236/// are used to abstract accesses to devices.237///238struct _EFI_DEVICE_IO_PROTOCOL {239///240/// Allows reads and writes to memory mapped I/O space.241///242EFI_IO_ACCESS Mem;243///244/// Allows reads and writes to I/O space.245///246EFI_IO_ACCESS Io;247///248/// Allows reads and writes to PCI configuration space.249///250EFI_IO_ACCESS Pci;251EFI_IO_MAP Map;252EFI_PCI_DEVICE_PATH PciDevicePath;253EFI_IO_UNMAP Unmap;254EFI_IO_ALLOCATE_BUFFER AllocateBuffer;255EFI_IO_FLUSH Flush;256EFI_IO_FREE_BUFFER FreeBuffer;257};258259extern EFI_GUID gEfiDeviceIoProtocolGuid;260261#endif262263264