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