]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Protocol/DeviceIo.h
Code have been checked with spec
[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 - 2008, 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 @param DeviceAddress The resulting map address for the bus master device to use to access the
139 hosts HostAddress.
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_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
144 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
145 @retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.
146 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
147
148 **/
149 typedef
150 EFI_STATUS
151 (EFIAPI *EFI_IO_MAP)(
152 IN EFI_DEVICE_IO_PROTOCOL *This,
153 IN EFI_IO_OPERATION_TYPE Operation,
154 IN EFI_PHYSICAL_ADDRESS *HostAddress,
155 IN OUT UINTN *NumberOfBytes,
156 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
157 OUT VOID **Mapping
158 );
159
160 /**
161 Completes the Map() operation and releases any corresponding resources.
162
163 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
164 @param Mapping A resulting value to pass to Unmap().
165
166 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
167 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
168
169 **/
170 typedef
171 EFI_STATUS
172 (EFIAPI *EFI_IO_UNMAP)(
173 IN EFI_DEVICE_IO_PROTOCOL *This,
174 IN VOID *Mapping
175 );
176
177 /**
178 Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping.
179
180 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
181 @param Type The type allocation to perform.
182 @param MemoryType The type of memory to allocate, EfiBootServicesData or
183 EfiRuntimeServicesData.
184 @param Pages The number of pages to allocate.
185 @param HostAddress A pointer to store the base address of the allocated range.
186
187 @retval EFI_SUCCESS The requested memory pages were allocated.
188 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
189 @retval EFI_INVALID_PARAMETER The requested memory type is invalid.
190 @retval EFI_UNSUPPORTED The requested HostAddress is not supported on
191 this platform.
192
193 **/
194 typedef
195 EFI_STATUS
196 (EFIAPI *EFI_IO_ALLOCATE_BUFFER)(
197 IN EFI_DEVICE_IO_PROTOCOL *This,
198 IN EFI_ALLOCATE_TYPE Type,
199 IN EFI_MEMORY_TYPE MemoryType,
200 IN UINTN Pages,
201 IN OUT EFI_PHYSICAL_ADDRESS *HostAddress
202 );
203
204 /**
205 Flushes any posted write data to the device.
206
207 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
208
209 @retval EFI_SUCCESS The buffers were flushed.
210 @retval EFI_DEVICE_ERROR The buffers were not flushed due to a hardware error.
211
212 **/
213 typedef
214 EFI_STATUS
215 (EFIAPI *EFI_IO_FLUSH)(
216 IN EFI_DEVICE_IO_PROTOCOL *This
217 );
218
219 /**
220 Frees pages that were allocated with AllocateBuffer().
221
222 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
223 @param Pages The number of pages to free.
224 @param HostAddress The base address of the range to free.
225
226 @retval EFI_SUCCESS The requested memory pages were allocated.
227 @retval EFI_NOT_FOUND The requested memory pages were not allocated with
228 AllocateBuffer().
229 @retval EFI_INVALID_PARAMETER HostAddress is not page aligned or Pages is invalid.
230
231 **/
232 typedef
233 EFI_STATUS
234 (EFIAPI *EFI_IO_FREE_BUFFER)(
235 IN EFI_DEVICE_IO_PROTOCOL *This,
236 IN UINTN Pages,
237 IN EFI_PHYSICAL_ADDRESS HostAddress
238 );
239
240 ///
241 /// This protocol provides the basic Memory, I/O, and PCI interfaces that
242 /// are used to abstract accesses to devices.
243 ///
244 struct _EFI_DEVICE_IO_PROTOCOL {
245 ///
246 /// Allows reads and writes to memory mapped I/O space.
247 ///
248 EFI_IO_ACCESS Mem;
249 ///
250 /// Allows reads and writes to I/O space.
251 ///
252 EFI_IO_ACCESS Io;
253 ///
254 /// Allows reads and writes to PCI configuration space.
255 ///
256 EFI_IO_ACCESS Pci;
257 EFI_IO_MAP Map;
258 EFI_PCI_DEVICE_PATH PciDevicePath;
259 EFI_IO_UNMAP Unmap;
260 EFI_IO_ALLOCATE_BUFFER AllocateBuffer;
261 EFI_IO_FLUSH Flush;
262 EFI_IO_FREE_BUFFER FreeBuffer;
263 };
264
265 extern EFI_GUID gEfiDeviceIoProtocolGuid;
266
267 #endif