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