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