]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Protocol/DeviceIo.h
Clean up: update "EFI" to "UEFI" if applicable.
[mirror_edk2.git] / MdePkg / Include / Protocol / DeviceIo.h
1 /** @file
2 Device IO protocol as defined in the EFI 1.10 specification.
3
4 Device IO is used to abstract hardware access to devices. It includes
5 memory mapped IO, IO, PCI Config space, and DMA.
6
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #ifndef __DEVICE_IO_H__
19 #define __DEVICE_IO_H__
20
21 #define EFI_DEVICE_IO_PROTOCOL_GUID \
22 { \
23 0xaf6ac311, 0x84c3, 0x11d2, {0x8e, 0x3c, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
24 }
25
26 typedef struct _EFI_DEVICE_IO_PROTOCOL EFI_DEVICE_IO_PROTOCOL;
27
28 //
29 // Protocol GUID name defined in EFI1.1.
30 //
31 #define DEVICE_IO_PROTOCOL EFI_DEVICE_IO_PROTOCOL_GUID
32
33 //
34 // Protocol defined in EFI1.1.
35 //
36 typedef EFI_DEVICE_IO_PROTOCOL EFI_DEVICE_IO_INTERFACE;
37
38 typedef enum {
39 IO_UINT8,
40 IO_UINT16,
41 IO_UINT32,
42 IO_UINT64,
43 MMIO_COPY_UINT8,
44 MMIO_COPY_UINT16,
45 MMIO_COPY_UINT32,
46 MMIO_COPY_UINT64
47 } EFI_IO_WIDTH;
48
49 /**
50 Enables a driver to access device registers in the appropriate memory or I/O space.
51
52 @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 write
57 operations, the source buffer to write data from.
58
59 @retval EFI_SUCCESS The data was read from or written to the device.
60 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
61 @retval EFI_INVALID_PARAMETER Width is invalid.
62
63 **/
64 typedef
65 EFI_STATUS
66 (EFIAPI *EFI_DEVICE_IO) (
67 IN EFI_DEVICE_IO_PROTOCOL *This,
68 IN EFI_IO_WIDTH Width,
69 IN UINT64 Address,
70 IN UINTN Count,
71 IN OUT VOID *Buffer
72 );
73
74 typedef struct {
75 EFI_DEVICE_IO Read;
76 EFI_DEVICE_IO Write;
77 } EFI_IO_ACCESS;
78
79 /**
80 Provides an EFI Device Path for a PCI device with the given PCI configuration space address.
81
82 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
83 @param PciAddress The PCI configuration space address of the device whose Device Path
84 is going to be returned.
85 @param PciDevicePath A pointer to the pointer for the EFI Device Path for PciAddress.
86 Memory for the Device Path is allocated from the pool.
87
88 @retval EFI_SUCCESS The PciDevicePath returns a pointer to a valid EFI Device Path.
89 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
90 @retval EFI_UNSUPPORTED The PciAddress does not map to a valid EFI Device Path.
91
92 **/
93 typedef
94 EFI_STATUS
95 (EFIAPI *EFI_PCI_DEVICE_PATH) (
96 IN EFI_DEVICE_IO_PROTOCOL *This,
97 IN UINT64 PciAddress,
98 IN OUT EFI_DEVICE_PATH_PROTOCOL **PciDevicePath
99 );
100
101 typedef enum {
102 EfiBusMasterRead,
103 EfiBusMasterWrite,
104 EfiBusMasterCommonBuffer
105 } EFI_IO_OPERATION_TYPE;
106
107 /**
108 Provides the device-specific addresses needed to access system memory.
109
110 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
111 @param Operation Indicates if the bus master is going to read or write to system memory.
112 @param HostAddress The system memory address to map to the device.
113 @param NumberOfBytes On input the number of bytes to map.
114 @param DeviceAddress The resulting map address for the bus master device to use to access the
115 hosts HostAddress.
116 @param Mapping A resulting value to pass to Unmap().
117
118 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
119 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
120 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
121 @retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.
122 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
123
124 **/
125 typedef
126 EFI_STATUS
127 (EFIAPI *EFI_IO_MAP) (
128 IN EFI_DEVICE_IO_PROTOCOL *This,
129 IN EFI_IO_OPERATION_TYPE Operation,
130 IN EFI_PHYSICAL_ADDRESS *HostAddress,
131 IN OUT UINTN *NumberOfBytes,
132 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
133 OUT VOID **Mapping
134 );
135
136 /**
137 Completes the Map() operation and releases any corresponding resources.
138
139 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
140 @param Mapping A resulting value to pass to Unmap().
141
142 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
143 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
144
145 **/
146 typedef
147 EFI_STATUS
148 (EFIAPI *EFI_IO_UNMAP) (
149 IN EFI_DEVICE_IO_PROTOCOL *This,
150 IN VOID *Mapping
151 );
152
153 /**
154 Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping.
155
156 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
157 @param Type The type allocation to perform.
158 @param MemoryType The type of memory to allocate, EfiBootServicesData or
159 EfiRuntimeServicesData.
160 @param Pages The number of pages to allocate.
161 @param HostAddress A pointer to store the base address of the allocated range.
162
163 @retval EFI_SUCCESS The requested memory pages were allocated.
164 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
165 @retval EFI_INVALID_PARAMETER The requested memory type is invalid.
166 @retval EFI_UNSUPPORTED The requested HostAddress is not supported on
167 this platform.
168
169 **/
170 typedef
171 EFI_STATUS
172 (EFIAPI *EFI_IO_ALLOCATE_BUFFER) (
173 IN EFI_DEVICE_IO_PROTOCOL *This,
174 IN EFI_ALLOCATE_TYPE Type,
175 IN EFI_MEMORY_TYPE MemoryType,
176 IN UINTN Pages,
177 IN OUT EFI_PHYSICAL_ADDRESS *HostAddress
178 );
179
180 /**
181 Flushes any posted write data to the device.
182
183 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
184
185 @retval EFI_SUCCESS The buffers were flushed.
186 @retval EFI_DEVICE_ERROR The buffers were not flushed due to a hardware error.
187
188 **/
189 typedef
190 EFI_STATUS
191 (EFIAPI *EFI_IO_FLUSH) (
192 IN EFI_DEVICE_IO_PROTOCOL *This
193 );
194
195 /**
196 Frees pages that were allocated with AllocateBuffer().
197
198 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
199 @param Pages The number of pages to free.
200 @param HostAddress The base address of the range to free.
201
202 @retval EFI_SUCCESS The requested memory pages were allocated.
203 @retval EFI_NOT_FOUND The requested memory pages were not allocated with
204 AllocateBuffer().
205 @retval EFI_INVALID_PARAMETER HostAddress is not page aligned or Pages is invalid.
206
207 **/
208 typedef
209 EFI_STATUS
210 (EFIAPI *EFI_IO_FREE_BUFFER) (
211 IN EFI_DEVICE_IO_PROTOCOL *This,
212 IN UINTN Pages,
213 IN EFI_PHYSICAL_ADDRESS HostAddress
214 );
215
216 struct _EFI_DEVICE_IO_PROTOCOL {
217 EFI_IO_ACCESS Mem;
218 EFI_IO_ACCESS Io;
219 EFI_IO_ACCESS Pci;
220 EFI_IO_MAP Map;
221 EFI_PCI_DEVICE_PATH PciDevicePath;
222 EFI_IO_UNMAP Unmap;
223 EFI_IO_ALLOCATE_BUFFER AllocateBuffer;
224 EFI_IO_FLUSH Flush;
225 EFI_IO_FREE_BUFFER FreeBuffer;
226 };
227
228 extern EFI_GUID gEfiDeviceIoProtocolGuid;
229
230 #endif