]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Protocol/DeviceIo.h
99a48cdccbf5249e15389e82a9e8249b1d22009e
[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 - 2009, 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 ///
39 /// Device IO Access Width
40 ///
41 typedef enum {
42 IO_UINT8 = 0,
43 IO_UINT16 = 1,
44 IO_UINT32 = 2,
45 IO_UINT64 = 3,
46 //
47 // Below enumerations are added in "Extensible Firmware Interface Specification,
48 // Version 1.10, Specification Update, Version 001".
49 //
50 MMIO_COPY_UINT8 = 4,
51 MMIO_COPY_UINT16 = 5,
52 MMIO_COPY_UINT32 = 6,
53 MMIO_COPY_UINT64 = 7
54 } EFI_IO_WIDTH;
55
56 /**
57 Enables a driver to access device registers in the appropriate memory or I/O space.
58
59 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
60 @param Width Signifies the width of the I/O operations.
61 @param Address The base address of the I/O operations.
62 @param Count The number of I/O operations to perform.
63 @param Buffer For read operations, the destination buffer to store the results. For write
64 operations, the source buffer to write data from. If
65 Width is MMIO_COPY_UINT8, MMIO_COPY_UINT16,
66 MMIO_COPY_UINT32, or MMIO_COPY_UINT64, then
67 Buffer is interpreted as a base address of an I/O operation such as Address.
68
69 @retval EFI_SUCCESS The data was read from or written to the device.
70 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
71 @retval EFI_INVALID_PARAMETER Width is invalid.
72
73 **/
74 typedef
75 EFI_STATUS
76 (EFIAPI *EFI_DEVICE_IO)(
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 typedef struct {
85 EFI_DEVICE_IO Read;
86 EFI_DEVICE_IO Write;
87 } EFI_IO_ACCESS;
88
89 /**
90 Provides an EFI Device Path for a PCI device with the given PCI configuration space address.
91
92 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
93 @param PciAddress The PCI configuration space address of the device whose Device Path
94 is going to be returned.
95 @param PciDevicePath A pointer to the pointer for the EFI Device Path for PciAddress.
96 Memory for the Device Path is allocated from the pool.
97
98 @retval EFI_SUCCESS The PciDevicePath returns a pointer to a valid EFI Device Path.
99 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
100 @retval EFI_UNSUPPORTED The PciAddress does not map to a valid EFI Device Path.
101
102 **/
103 typedef
104 EFI_STATUS
105 (EFIAPI *EFI_PCI_DEVICE_PATH)(
106 IN EFI_DEVICE_IO_PROTOCOL *This,
107 IN UINT64 PciAddress,
108 IN OUT EFI_DEVICE_PATH_PROTOCOL **PciDevicePath
109 );
110
111 typedef enum {
112 ///
113 /// A read operation from system memory by a bus master.
114 ///
115 EfiBusMasterRead,
116
117 ///
118 /// A write operation to system memory by a bus master.
119 ///
120 EfiBusMasterWrite,
121
122 ///
123 /// Provides both read and write access to system memory
124 /// by both the processor and a bus master. The buffer is
125 /// coherent from both the processor's and the bus master's
126 /// point of view.
127 ///
128 EfiBusMasterCommonBuffer
129 } EFI_IO_OPERATION_TYPE;
130
131 /**
132 Provides the device-specific addresses needed to access system memory.
133
134 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
135 @param Operation Indicates if the bus master is going to read or write to system memory.
136 @param HostAddress The system memory address to map to the device.
137 @param NumberOfBytes On input, the number of bytes to map.
138 On output, the number of bytes that were mapped.
139 @param DeviceAddress The resulting map address for the bus master device to use to access the
140 hosts HostAddress.
141 @param Mapping A resulting value to pass to Unmap().
142
143 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
144 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
145 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
146 @retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.
147 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
148
149 **/
150 typedef
151 EFI_STATUS
152 (EFIAPI *EFI_IO_MAP)(
153 IN EFI_DEVICE_IO_PROTOCOL *This,
154 IN EFI_IO_OPERATION_TYPE Operation,
155 IN EFI_PHYSICAL_ADDRESS *HostAddress,
156 IN OUT UINTN *NumberOfBytes,
157 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
158 OUT VOID **Mapping
159 );
160
161 /**
162 Completes the Map() operation and releases any corresponding resources.
163
164 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
165 @param Mapping A resulting value to pass to Unmap().
166
167 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
168 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
169
170 **/
171 typedef
172 EFI_STATUS
173 (EFIAPI *EFI_IO_UNMAP)(
174 IN EFI_DEVICE_IO_PROTOCOL *This,
175 IN VOID *Mapping
176 );
177
178 /**
179 Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping.
180
181 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
182 @param Type The type allocation to perform.
183 @param MemoryType The type of memory to allocate, EfiBootServicesData or
184 EfiRuntimeServicesData.
185 @param Pages The number of pages to allocate.
186 @param HostAddress A pointer to store the base address of the allocated range.
187
188 @retval EFI_SUCCESS The requested memory pages were allocated.
189 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
190 @retval EFI_INVALID_PARAMETER The requested memory type is invalid.
191 @retval EFI_UNSUPPORTED The requested HostAddress is not supported on
192 this platform.
193
194 **/
195 typedef
196 EFI_STATUS
197 (EFIAPI *EFI_IO_ALLOCATE_BUFFER)(
198 IN EFI_DEVICE_IO_PROTOCOL *This,
199 IN EFI_ALLOCATE_TYPE Type,
200 IN EFI_MEMORY_TYPE MemoryType,
201 IN UINTN Pages,
202 IN OUT EFI_PHYSICAL_ADDRESS *HostAddress
203 );
204
205 /**
206 Flushes any posted write data to the device.
207
208 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
209
210 @retval EFI_SUCCESS The buffers were flushed.
211 @retval EFI_DEVICE_ERROR The buffers were not flushed due to a hardware error.
212
213 **/
214 typedef
215 EFI_STATUS
216 (EFIAPI *EFI_IO_FLUSH)(
217 IN EFI_DEVICE_IO_PROTOCOL *This
218 );
219
220 /**
221 Frees pages that were allocated with AllocateBuffer().
222
223 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
224 @param Pages The number of pages to free.
225 @param HostAddress The base address of the range to free.
226
227 @retval EFI_SUCCESS The requested memory pages were allocated.
228 @retval EFI_NOT_FOUND The requested memory pages were not allocated with
229 AllocateBuffer().
230 @retval EFI_INVALID_PARAMETER HostAddress is not page aligned or Pages is invalid.
231
232 **/
233 typedef
234 EFI_STATUS
235 (EFIAPI *EFI_IO_FREE_BUFFER)(
236 IN EFI_DEVICE_IO_PROTOCOL *This,
237 IN UINTN Pages,
238 IN EFI_PHYSICAL_ADDRESS HostAddress
239 );
240
241 ///
242 /// This protocol provides the basic Memory, I/O, and PCI interfaces that
243 /// are used to abstract accesses to devices.
244 ///
245 struct _EFI_DEVICE_IO_PROTOCOL {
246 ///
247 /// Allows reads and writes to memory mapped I/O space.
248 ///
249 EFI_IO_ACCESS Mem;
250 ///
251 /// Allows reads and writes to I/O space.
252 ///
253 EFI_IO_ACCESS Io;
254 ///
255 /// Allows reads and writes to PCI configuration space.
256 ///
257 EFI_IO_ACCESS Pci;
258 EFI_IO_MAP Map;
259 EFI_PCI_DEVICE_PATH PciDevicePath;
260 EFI_IO_UNMAP Unmap;
261 EFI_IO_ALLOCATE_BUFFER AllocateBuffer;
262 EFI_IO_FLUSH Flush;
263 EFI_IO_FREE_BUFFER FreeBuffer;
264 };
265
266 extern EFI_GUID gEfiDeviceIoProtocolGuid;
267
268 #endif