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