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