]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Protocol/SerialIo.h
MdePkg: Extend SERIAL_IO with DeviceTypeGuid
[mirror_edk2.git] / MdePkg / Include / Protocol / SerialIo.h
1 /** @file
2 Serial IO protocol as defined in the UEFI 2.0 specification.
3
4 Abstraction of a basic serial device. Targeted at 16550 UART, but
5 could be much more generic.
6
7 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #ifndef __SERIAL_IO_PROTOCOL_H__
13 #define __SERIAL_IO_PROTOCOL_H__
14
15 #define EFI_SERIAL_IO_PROTOCOL_GUID \
16 { \
17 0xBB25CF6F, 0xF1D4, 0x11D2, {0x9A, 0x0C, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0xFD } \
18 }
19
20 ///
21 /// Protocol GUID defined in EFI1.1.
22 ///
23 #define SERIAL_IO_PROTOCOL EFI_SERIAL_IO_PROTOCOL_GUID
24
25 typedef struct _EFI_SERIAL_IO_PROTOCOL EFI_SERIAL_IO_PROTOCOL;
26
27
28 ///
29 /// Backward-compatible with EFI1.1.
30 ///
31 typedef EFI_SERIAL_IO_PROTOCOL SERIAL_IO_INTERFACE;
32
33 ///
34 /// Parity type that is computed or checked as each character is transmitted or received. If the
35 /// device does not support parity, the value is the default parity value.
36 ///
37 typedef enum {
38 DefaultParity,
39 NoParity,
40 EvenParity,
41 OddParity,
42 MarkParity,
43 SpaceParity
44 } EFI_PARITY_TYPE;
45
46 ///
47 /// Stop bits type
48 ///
49 typedef enum {
50 DefaultStopBits,
51 OneStopBit,
52 OneFiveStopBits,
53 TwoStopBits
54 } EFI_STOP_BITS_TYPE;
55
56 //
57 // define for Control bits, grouped by read only, write only, and read write
58 //
59 //
60 // Read Only
61 //
62 #define EFI_SERIAL_CLEAR_TO_SEND 0x00000010
63 #define EFI_SERIAL_DATA_SET_READY 0x00000020
64 #define EFI_SERIAL_RING_INDICATE 0x00000040
65 #define EFI_SERIAL_CARRIER_DETECT 0x00000080
66 #define EFI_SERIAL_INPUT_BUFFER_EMPTY 0x00000100
67 #define EFI_SERIAL_OUTPUT_BUFFER_EMPTY 0x00000200
68
69 //
70 // Write Only
71 //
72 #define EFI_SERIAL_REQUEST_TO_SEND 0x00000002
73 #define EFI_SERIAL_DATA_TERMINAL_READY 0x00000001
74
75 //
76 // Read Write
77 //
78 #define EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE 0x00001000
79 #define EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE 0x00002000
80 #define EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE 0x00004000
81
82 //
83 // Serial IO Member Functions
84 //
85 /**
86 Reset the serial device.
87
88 @param This Protocol instance pointer.
89
90 @retval EFI_SUCCESS The device was reset.
91 @retval EFI_DEVICE_ERROR The serial device could not be reset.
92
93 **/
94 typedef
95 EFI_STATUS
96 (EFIAPI *EFI_SERIAL_RESET)(
97 IN EFI_SERIAL_IO_PROTOCOL *This
98 );
99
100 /**
101 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
102 data bits, and stop bits on a serial device.
103
104 @param This Protocol instance pointer.
105 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
106 device's default interface speed.
107 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
108 serial interface. A ReceiveFifoDepth value of 0 will use
109 the device's default FIFO depth.
110 @param Timeout The requested time out for a single character in microseconds.
111 This timeout applies to both the transmit and receive side of the
112 interface. A Timeout value of 0 will use the device's default time
113 out value.
114 @param Parity The type of parity to use on this serial device. A Parity value of
115 DefaultParity will use the device's default parity value.
116 @param DataBits The number of data bits to use on the serial device. A DataBits
117 vaule of 0 will use the device's default data bit setting.
118 @param StopBits The number of stop bits to use on this serial device. A StopBits
119 value of DefaultStopBits will use the device's default number of
120 stop bits.
121
122 @retval EFI_SUCCESS The device was reset.
123 @retval EFI_INVALID_PARAMETER One or more attributes has an unsupported value.
124 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
125
126 **/
127 typedef
128 EFI_STATUS
129 (EFIAPI *EFI_SERIAL_SET_ATTRIBUTES)(
130 IN EFI_SERIAL_IO_PROTOCOL *This,
131 IN UINT64 BaudRate,
132 IN UINT32 ReceiveFifoDepth,
133 IN UINT32 Timeout,
134 IN EFI_PARITY_TYPE Parity,
135 IN UINT8 DataBits,
136 IN EFI_STOP_BITS_TYPE StopBits
137 );
138
139 /**
140 Set the control bits on a serial device
141
142 @param This Protocol instance pointer.
143 @param Control Set the bits of Control that are settable.
144
145 @retval EFI_SUCCESS The new control bits were set on the serial device.
146 @retval EFI_UNSUPPORTED The serial device does not support this operation.
147 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
148
149 **/
150 typedef
151 EFI_STATUS
152 (EFIAPI *EFI_SERIAL_SET_CONTROL_BITS)(
153 IN EFI_SERIAL_IO_PROTOCOL *This,
154 IN UINT32 Control
155 );
156
157 /**
158 Retrieves the status of thecontrol bits on a serial device
159
160 @param This Protocol instance pointer.
161 @param Control A pointer to return the current Control signals from the serial device.
162
163 @retval EFI_SUCCESS The control bits were read from the serial device.
164 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
165
166 **/
167 typedef
168 EFI_STATUS
169 (EFIAPI *EFI_SERIAL_GET_CONTROL_BITS)(
170 IN EFI_SERIAL_IO_PROTOCOL *This,
171 OUT UINT32 *Control
172 );
173
174 /**
175 Writes data to a serial device.
176
177 @param This Protocol instance pointer.
178 @param BufferSize On input, the size of the Buffer. On output, the amount of
179 data actually written.
180 @param Buffer The buffer of data to write
181
182 @retval EFI_SUCCESS The data was written.
183 @retval EFI_DEVICE_ERROR The device reported an error.
184 @retval EFI_TIMEOUT The data write was stopped due to a timeout.
185
186 **/
187 typedef
188 EFI_STATUS
189 (EFIAPI *EFI_SERIAL_WRITE)(
190 IN EFI_SERIAL_IO_PROTOCOL *This,
191 IN OUT UINTN *BufferSize,
192 IN VOID *Buffer
193 );
194
195 /**
196 Writes data to a serial device.
197
198 @param This Protocol instance pointer.
199 @param BufferSize On input, the size of the Buffer. On output, the amount of
200 data returned in Buffer.
201 @param Buffer The buffer to return the data into.
202
203 @retval EFI_SUCCESS The data was read.
204 @retval EFI_DEVICE_ERROR The device reported an error.
205 @retval EFI_TIMEOUT The data write was stopped due to a timeout.
206
207 **/
208 typedef
209 EFI_STATUS
210 (EFIAPI *EFI_SERIAL_READ)(
211 IN EFI_SERIAL_IO_PROTOCOL *This,
212 IN OUT UINTN *BufferSize,
213 OUT VOID *Buffer
214 );
215
216 /**
217 @par Data Structure Description:
218 The data values in SERIAL_IO_MODE are read-only and are updated by the code
219 that produces the SERIAL_IO_PROTOCOL member functions.
220
221 @param ControlMask
222 A mask for the Control bits that the device supports. The device
223 must always support the Input Buffer Empty control bit.
224
225 @param TimeOut
226 If applicable, the number of microseconds to wait before timing out
227 a Read or Write operation.
228
229 @param BaudRate
230 If applicable, the current baud rate setting of the device; otherwise,
231 baud rate has the value of zero to indicate that device runs at the
232 device's designed speed.
233
234 @param ReceiveFifoDepth
235 The number of characters the device will buffer on input
236
237 @param DataBits
238 The number of characters the device will buffer on input
239
240 @param Parity
241 If applicable, this is the EFI_PARITY_TYPE that is computed or
242 checked as each character is transmitted or reveived. If the device
243 does not support parity the value is the default parity value.
244
245 @param StopBits
246 If applicable, the EFI_STOP_BITS_TYPE number of stop bits per
247 character. If the device does not support stop bits the value is
248 the default stop bit values.
249
250 **/
251 typedef struct {
252 UINT32 ControlMask;
253
254 //
255 // current Attributes
256 //
257 UINT32 Timeout;
258 UINT64 BaudRate;
259 UINT32 ReceiveFifoDepth;
260 UINT32 DataBits;
261 UINT32 Parity;
262 UINT32 StopBits;
263 } EFI_SERIAL_IO_MODE;
264
265 #define EFI_SERIAL_IO_PROTOCOL_REVISION 0x00010000
266 #define EFI_SERIAL_IO_PROTOCOL_REVISION1p1 0x00010001
267 #define SERIAL_IO_INTERFACE_REVISION EFI_SERIAL_IO_PROTOCOL_REVISION
268
269 ///
270 /// The Serial I/O protocol is used to communicate with UART-style serial devices.
271 /// These can be standard UART serial ports in PC-AT systems, serial ports attached
272 /// to a USB interface, or potentially any character-based I/O device.
273 ///
274 struct _EFI_SERIAL_IO_PROTOCOL {
275 ///
276 /// The revision to which the EFI_SERIAL_IO_PROTOCOL adheres. All future revisions
277 /// must be backwards compatible. If a future version is not backwards compatible,
278 /// it is not the same GUID.
279 ///
280 UINT32 Revision;
281 EFI_SERIAL_RESET Reset;
282 EFI_SERIAL_SET_ATTRIBUTES SetAttributes;
283 EFI_SERIAL_SET_CONTROL_BITS SetControl;
284 EFI_SERIAL_GET_CONTROL_BITS GetControl;
285 EFI_SERIAL_WRITE Write;
286 EFI_SERIAL_READ Read;
287 ///
288 /// Pointer to SERIAL_IO_MODE data.
289 ///
290 EFI_SERIAL_IO_MODE *Mode;
291 ///
292 /// Pointer to a GUID identifying the device connected to the serial port.
293 /// This field is NULL when the protocol is installed by the serial port
294 /// driver and may be populated by a platform driver for a serial port
295 /// with a known device attached. The field will remain NULL if there is
296 /// no platform serial device identification information available.
297 ///
298 CONST EFI_GUID *DeviceTypeGuid; // Revision 1.1
299 };
300
301 extern EFI_GUID gEfiSerialIoProtocolGuid;
302
303 #endif